Skip to content

Commit

Permalink
Config preferred sequencer via bool (#672)
Browse files Browse the repository at this point in the history
  • Loading branch information
neysofu authored Aug 18, 2023
1 parent 4bab2f5 commit 185dc6a
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 47 deletions.
2 changes: 1 addition & 1 deletion examples/demo-stf/src/genesis_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub fn create_demo_genesis_config<C: Context>(
amount: LOCKED_AMOUNT,
token_address,
},
preferred_sequencer: None,
is_preferred_sequencer: false,
};

let value_setter_config = ValueSetterConfig {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ fn priority_sequencer_flow() {
amount: LOCKED_AMOUNT,
token_address,
},
preferred_sequencer: Some(preferred_sequencer_da.as_ref().to_vec()),
is_preferred_sequencer: true,
};

let bank = sov_bank::Bank::<C>::default();
Expand Down Expand Up @@ -166,7 +166,7 @@ fn test_blobs_from_non_registered_sequencers_are_not_saved() {
amount: LOCKED_AMOUNT,
token_address,
},
preferred_sequencer: Some(preferred_sequencer_da.as_ref().to_vec()),
is_preferred_sequencer: true,
};

let bank = sov_bank::Bank::<C>::default();
Expand Down Expand Up @@ -234,7 +234,7 @@ fn test_blobs_no_deferred_without_preferred_sequencer() {
amount: LOCKED_AMOUNT,
token_address,
},
preferred_sequencer: None,
is_preferred_sequencer: false,
};

let bank = sov_bank::Bank::<C>::default();
Expand Down Expand Up @@ -303,7 +303,7 @@ fn deferred_blobs_are_first_after_preferred_sequencer_exit() {
amount: LOCKED_AMOUNT,
token_address,
},
preferred_sequencer: Some(preferred_sequencer_da.as_ref().to_vec()),
is_preferred_sequencer: true,
};

let bank = sov_bank::Bank::<C>::default();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,9 @@ impl<C: sov_modules_api::Context> SequencerRegistry<C> {
&config.seq_rollup_address,
working_set,
)?;
if let Some(preferred_sequencer) = &config.preferred_sequencer {
if &config.seq_da_address != preferred_sequencer {
anyhow::bail!("Preferred sequencer is not in list of allowed sequencers");
}
if config.is_preferred_sequencer {
self.preferred_sequencer
.set(preferred_sequencer, working_set);
.set(&config.seq_da_address, working_set);
}

Ok(())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ pub struct SequencerConfig<C: sov_modules_api::Context> {
// TODO: Replace with DA address generic, when AddressTrait is split
pub seq_da_address: Vec<u8>,
pub coins_to_lock: sov_bank::Coins<C>,
// TODO: Replace with DA address generic, when AddressTrait is split
pub preferred_sequencer: Option<Vec<u8>>,
pub is_preferred_sequencer: bool,
}

#[cfg_attr(feature = "native", derive(sov_modules_api::ModuleCallJsonSchema))]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ pub fn create_sequencer_config(
amount: LOCKED_AMOUNT,
token_address,
},
preferred_sequencer: None,
is_preferred_sequencer: false,
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ fn end_blob_hook_slash_preferred_sequencer() {
let registry = SequencerRegistry::<C>::default();
let mut sequencer_config = create_sequencer_config(seq_rollup_address, token_address);

sequencer_config.preferred_sequencer = Some(sequencer_config.seq_da_address.clone());
sequencer_config.is_preferred_sequencer = true;

let mut test_sequencer = TestSequencer {
bank,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ fn test_preferred_sequencer_returned_and_removed() {
let registry = SequencerRegistry::<C>::default();
let mut sequencer_config = create_sequencer_config(seq_rollup_address, token_address);

sequencer_config.preferred_sequencer = Some(sequencer_config.seq_da_address.clone());
sequencer_config.is_preferred_sequencer = true;

let mut test_sequencer = TestSequencer {
bank,
Expand All @@ -250,7 +250,7 @@ fn test_preferred_sequencer_returned_and_removed() {
test_sequencer.genesis(working_set);

assert_eq!(
test_sequencer.sequencer_config.preferred_sequencer,
Some(test_sequencer.sequencer_config.seq_da_address),
test_sequencer.registry.get_preferred_sequencer(working_set)
);

Expand All @@ -270,34 +270,3 @@ fn test_preferred_sequencer_returned_and_removed() {
.get_preferred_sequencer(working_set)
.is_none());
}

#[test]
fn test_preferred_sequencer_not_allowed_sequencers() {
let bank = sov_bank::Bank::<C>::default();
let (bank_config, seq_rollup_address) = create_bank_config();

let token_address = sov_bank::get_genesis_token_address::<C>(
&bank_config.tokens[0].token_name,
bank_config.tokens[0].salt,
);

let some_da_address = UNKNOWN_SEQUENCER_DA_ADDRESS.to_vec();

let registry = SequencerRegistry::<C>::default();
let mut sequencer_config = create_sequencer_config(seq_rollup_address, token_address);

sequencer_config.preferred_sequencer = Some(some_da_address);

let tmpdir = tempfile::tempdir().unwrap();
let working_set = &mut WorkingSet::new(ProverStorage::with_path(tmpdir.path()).unwrap());

bank.genesis(&bank_config, working_set).unwrap();
let genesis_result = registry.genesis(&sequencer_config, working_set);
assert!(genesis_result.is_err());

let message = genesis_result.err().unwrap().to_string();
assert_eq!(
"Preferred sequencer is not in list of allowed sequencers",
message
);
}

0 comments on commit 185dc6a

Please sign in to comment.