mirror of
https://github.com/serai-dex/serai.git
synced 2024-12-22 19:49:22 +00:00
Have the TendermintMachine domain-separate by genesis
Enbables support for multiple machines over the same DB.
This commit is contained in:
parent
0d569ff7a3
commit
454bebaa77
4 changed files with 19 additions and 1 deletions
|
@ -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 {
|
||||
|
|
|
@ -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>,
|
||||
|
@ -38,6 +39,7 @@ 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>,
|
||||
|
@ -45,6 +47,7 @@ impl<N: Network> BlockData<N> {
|
|||
) -> BlockData<N> {
|
||||
BlockData {
|
||||
db,
|
||||
genesis,
|
||||
|
||||
number,
|
||||
validator_id,
|
||||
|
@ -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(),
|
||||
|
|
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -414,6 +417,7 @@ impl<N: Network + 'static> TendermintMachine<N> {
|
|||
// 01-10
|
||||
let mut machine = TendermintMachine {
|
||||
db: db.clone(),
|
||||
genesis,
|
||||
|
||||
network,
|
||||
signer,
|
||||
|
@ -427,6 +431,7 @@ impl<N: Network + 'static> TendermintMachine<N> {
|
|||
|
||||
block: BlockData::new(
|
||||
db,
|
||||
genesis,
|
||||
weights,
|
||||
BlockNumber(last_block.0 + 1),
|
||||
validator_id,
|
||||
|
|
|
@ -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(()) },
|
||||
|
|
Loading…
Reference in a new issue