From 454bebaa77c9690d098d747811e68da31f0d5b98 Mon Sep 17 00:00:00 2001 From: Luke Parker Date: Fri, 8 Mar 2024 01:15:10 -0500 Subject: [PATCH] Have the TendermintMachine domain-separate by genesis Enbables support for multiple machines over the same DB. --- coordinator/tributary/src/lib.rs | 10 +++++++++- coordinator/tributary/tendermint/src/block.rs | 4 ++++ coordinator/tributary/tendermint/src/lib.rs | 5 +++++ coordinator/tributary/tendermint/tests/ext.rs | 1 + 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/coordinator/tributary/src/lib.rs b/coordinator/tributary/src/lib.rs index 7f174d728..92fb98da3 100644 --- a/coordinator/tributary/src/lib.rs +++ b/coordinator/tributary/src/lib.rs @@ -218,7 +218,15 @@ impl Tributary { 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 { diff --git a/coordinator/tributary/tendermint/src/block.rs b/coordinator/tributary/tendermint/src/block.rs index 5b2e86eaf..71dfb3ccd 100644 --- a/coordinator/tributary/tendermint/src/block.rs +++ b/coordinator/tributary/tendermint/src/block.rs @@ -16,6 +16,7 @@ use crate::{ pub(crate) struct BlockData { db: N::Db, + genesis: [u8; 32], pub(crate) number: BlockNumber, pub(crate) validator_id: Option, @@ -38,6 +39,7 @@ pub(crate) struct BlockData { impl BlockData { pub(crate) fn new( db: N::Db, + genesis: [u8; 32], weights: Arc, number: BlockNumber, validator_id: Option, @@ -45,6 +47,7 @@ impl BlockData { ) -> BlockData { BlockData { db, + genesis, number, validator_id, @@ -151,6 +154,7 @@ impl BlockData { 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(), diff --git a/coordinator/tributary/tendermint/src/lib.rs b/coordinator/tributary/tendermint/src/lib.rs index 8faf67989..778056775 100644 --- a/coordinator/tributary/tendermint/src/lib.rs +++ b/coordinator/tributary/tendermint/src/lib.rs @@ -232,6 +232,7 @@ pub enum SlashEvent { /// A machine executing the Tendermint protocol. pub struct TendermintMachine { db: N::Db, + genesis: [u8; 32], network: N, signer: ::Signer, @@ -325,6 +326,7 @@ impl TendermintMachine { // 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, @@ -375,6 +377,7 @@ impl TendermintMachine { pub async fn new( db: N::Db, network: N, + genesis: [u8; 32], last_block: BlockNumber, last_time: u64, proposal: N::Block, @@ -414,6 +417,7 @@ impl TendermintMachine { // 01-10 let mut machine = TendermintMachine { db: db.clone(), + genesis, network, signer, @@ -427,6 +431,7 @@ impl TendermintMachine { block: BlockData::new( db, + genesis, weights, BlockNumber(last_block.0 + 1), validator_id, diff --git a/coordinator/tributary/tendermint/tests/ext.rs b/coordinator/tributary/tendermint/tests/ext.rs index f919b003e..3b3cf7c3b 100644 --- a/coordinator/tributary/tendermint/tests/ext.rs +++ b/coordinator/tributary/tendermint/tests/ext.rs @@ -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(()) },