Skip to content

Commit

Permalink
Ground work for preferred sequencer
Browse files Browse the repository at this point in the history
  • Loading branch information
citizen-stig committed Jul 19, 2023
1 parent ef12744 commit 22105fb
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions examples/demo-stf/src/genesis_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ pub fn create_demo_genesis_config<C: Context>(
amount: LOCKED_AMOUNT,
token_address,
},
preferred_sequencer: None,
};

let value_setter_config = ValueSetterConfig {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub struct SequencerConfig<C: sov_modules_api::Context> {
pub seq_rollup_address: C::Address,
pub seq_da_address: Vec<u8>,
pub coins_to_lock: sov_bank::Coins<C>,
pub preferred_sequencer: Option<C::Address>,
}

#[derive(ModuleInfo)]
Expand All @@ -31,6 +32,12 @@ pub struct SequencerRegistry<C: sov_modules_api::Context> {
#[state]
pub(crate) allowed_sequencers: StateMap<Vec<u8>, C::Address>,

/// Optional preferred sequencer
/// If set, batches from this sequencer will be processed first in block,
/// So this sequencer can guarantee soft confirmation time for transactions
#[state]
pub(crate) preferred_sequencer: StateValue<C::Address>,

/// Coin's that will be slashed if the sequencer is malicious.
/// The coins will be transferred from `self.seq_rollup_address` to `self.address`
/// and locked forever, until sequencer decides to exit
Expand Down Expand Up @@ -108,4 +115,12 @@ impl<C: sov_modules_api::Context> SequencerRegistry<C> {

Ok(())
}

/// Return preferred sequencer if it was set
pub fn get_preferred_sequencer(
&self,
working_set: &mut WorkingSet<C::Storage>,
) -> Option<C::Address> {
self.preferred_sequencer.get(working_set)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ pub fn create_sequencer_config(
amount: LOCKED_AMOUNT,
token_address,
},
preferred_sequencer: None,
}
}

Expand Down

0 comments on commit 22105fb

Please sign in to comment.