Skip to content

Commit

Permalink
Have the TendermintMachine domain-separate by genesis
Browse files Browse the repository at this point in the history
Enbables support for multiple machines over the same DB.
  • Loading branch information
kayabaNerve committed Mar 8, 2024
1 parent 0d569ff commit 454beba
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
10 changes: 9 additions & 1 deletion coordinator/tributary/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,15 @@ impl<D: Db, T: TransactionTrait, P: P2p> Tributary<D, T, P> {
TendermintNetwork { genesis, signer, validators, blockchain, to_rebroadcast, p2p };

let TendermintHandle { synced_block, synced_block_result, messages, machine } =
TendermintMachine::new(db.clone(), network.clone(), block_number, start_time, proposal).await;
TendermintMachine::new(
db.clone(),
network.clone(),
genesis,
block_number,
start_time,
proposal,
)
.await;
tokio::spawn(machine.run());

Some(Self {
Expand Down
4 changes: 4 additions & 0 deletions coordinator/tributary/tendermint/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use crate::{

pub(crate) struct BlockData<N: Network> {
db: N::Db,
genesis: [u8; 32],

pub(crate) number: BlockNumber,
pub(crate) validator_id: Option<N::ValidatorId>,
Expand All @@ -38,13 +39,15 @@ pub(crate) struct BlockData<N: Network> {
impl<N: Network> BlockData<N> {
pub(crate) fn new(
db: N::Db,
genesis: [u8; 32],
weights: Arc<N::Weights>,
number: BlockNumber,
validator_id: Option<N::ValidatorId>,
proposal: Option<N::Block>,
) -> BlockData<N> {
BlockData {
db,
genesis,

number,
validator_id,
Expand Down Expand Up @@ -151,6 +154,7 @@ impl<N: Network> BlockData<N> {
let mut txn = self.db.txn();
let key = [
b"tendermint-machine_already_sent_message".as_ref(),
&self.genesis,
&self.number.0.to_le_bytes(),
&round_number.0.to_le_bytes(),
&step.encode(),
Expand Down
5 changes: 5 additions & 0 deletions coordinator/tributary/tendermint/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ pub enum SlashEvent {
/// A machine executing the Tendermint protocol.
pub struct TendermintMachine<N: Network> {
db: N::Db,
genesis: [u8; 32],

network: N,
signer: <N::SignatureScheme as SignatureScheme>::Signer,
Expand Down Expand Up @@ -325,6 +326,7 @@ impl<N: Network + 'static> TendermintMachine<N> {
// Create the new block
self.block = BlockData::new(
self.db.clone(),
self.genesis,
self.weights.clone(),
BlockNumber(self.block.number.0 + 1),
self.signer.validator_id().await,
Expand Down Expand Up @@ -375,6 +377,7 @@ impl<N: Network + 'static> TendermintMachine<N> {
pub async fn new(
db: N::Db,
network: N,
genesis: [u8; 32],
last_block: BlockNumber,
last_time: u64,
proposal: N::Block,
Expand Down Expand Up @@ -414,6 +417,7 @@ impl<N: Network + 'static> TendermintMachine<N> {
// 01-10
let mut machine = TendermintMachine {
db: db.clone(),
genesis,

network,
signer,
Expand All @@ -427,6 +431,7 @@ impl<N: Network + 'static> TendermintMachine<N> {

block: BlockData::new(
db,
genesis,
weights,
BlockNumber(last_block.0 + 1),
validator_id,
Expand Down
1 change: 1 addition & 0 deletions coordinator/tributary/tendermint/tests/ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ impl TestNetwork {
TendermintMachine::new(
MemDb::new(),
TestNetwork(i, arc.clone()),
[0; 32],
BlockNumber(1),
start_time,
TestBlock { id: 1u32.to_le_bytes(), valid: Ok(()) },
Expand Down

0 comments on commit 454beba

Please sign in to comment.