mirror of
https://github.com/serai-dex/serai.git
synced 2025-01-18 08:45:00 +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 };
|
TendermintNetwork { genesis, signer, validators, blockchain, to_rebroadcast, p2p };
|
||||||
|
|
||||||
let TendermintHandle { synced_block, synced_block_result, messages, machine } =
|
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());
|
tokio::spawn(machine.run());
|
||||||
|
|
||||||
Some(Self {
|
Some(Self {
|
||||||
|
|
|
@ -16,6 +16,7 @@ use crate::{
|
||||||
|
|
||||||
pub(crate) struct BlockData<N: Network> {
|
pub(crate) struct BlockData<N: Network> {
|
||||||
db: N::Db,
|
db: N::Db,
|
||||||
|
genesis: [u8; 32],
|
||||||
|
|
||||||
pub(crate) number: BlockNumber,
|
pub(crate) number: BlockNumber,
|
||||||
pub(crate) validator_id: Option<N::ValidatorId>,
|
pub(crate) validator_id: Option<N::ValidatorId>,
|
||||||
|
@ -38,6 +39,7 @@ pub(crate) struct BlockData<N: Network> {
|
||||||
impl<N: Network> BlockData<N> {
|
impl<N: Network> BlockData<N> {
|
||||||
pub(crate) fn new(
|
pub(crate) fn new(
|
||||||
db: N::Db,
|
db: N::Db,
|
||||||
|
genesis: [u8; 32],
|
||||||
weights: Arc<N::Weights>,
|
weights: Arc<N::Weights>,
|
||||||
number: BlockNumber,
|
number: BlockNumber,
|
||||||
validator_id: Option<N::ValidatorId>,
|
validator_id: Option<N::ValidatorId>,
|
||||||
|
@ -45,6 +47,7 @@ impl<N: Network> BlockData<N> {
|
||||||
) -> BlockData<N> {
|
) -> BlockData<N> {
|
||||||
BlockData {
|
BlockData {
|
||||||
db,
|
db,
|
||||||
|
genesis,
|
||||||
|
|
||||||
number,
|
number,
|
||||||
validator_id,
|
validator_id,
|
||||||
|
@ -151,6 +154,7 @@ impl<N: Network> BlockData<N> {
|
||||||
let mut txn = self.db.txn();
|
let mut txn = self.db.txn();
|
||||||
let key = [
|
let key = [
|
||||||
b"tendermint-machine_already_sent_message".as_ref(),
|
b"tendermint-machine_already_sent_message".as_ref(),
|
||||||
|
&self.genesis,
|
||||||
&self.number.0.to_le_bytes(),
|
&self.number.0.to_le_bytes(),
|
||||||
&round_number.0.to_le_bytes(),
|
&round_number.0.to_le_bytes(),
|
||||||
&step.encode(),
|
&step.encode(),
|
||||||
|
|
|
@ -232,6 +232,7 @@ pub enum SlashEvent {
|
||||||
/// A machine executing the Tendermint protocol.
|
/// A machine executing the Tendermint protocol.
|
||||||
pub struct TendermintMachine<N: Network> {
|
pub struct TendermintMachine<N: Network> {
|
||||||
db: N::Db,
|
db: N::Db,
|
||||||
|
genesis: [u8; 32],
|
||||||
|
|
||||||
network: N,
|
network: N,
|
||||||
signer: <N::SignatureScheme as SignatureScheme>::Signer,
|
signer: <N::SignatureScheme as SignatureScheme>::Signer,
|
||||||
|
@ -325,6 +326,7 @@ impl<N: Network + 'static> TendermintMachine<N> {
|
||||||
// Create the new block
|
// Create the new block
|
||||||
self.block = BlockData::new(
|
self.block = BlockData::new(
|
||||||
self.db.clone(),
|
self.db.clone(),
|
||||||
|
self.genesis,
|
||||||
self.weights.clone(),
|
self.weights.clone(),
|
||||||
BlockNumber(self.block.number.0 + 1),
|
BlockNumber(self.block.number.0 + 1),
|
||||||
self.signer.validator_id().await,
|
self.signer.validator_id().await,
|
||||||
|
@ -375,6 +377,7 @@ impl<N: Network + 'static> TendermintMachine<N> {
|
||||||
pub async fn new(
|
pub async fn new(
|
||||||
db: N::Db,
|
db: N::Db,
|
||||||
network: N,
|
network: N,
|
||||||
|
genesis: [u8; 32],
|
||||||
last_block: BlockNumber,
|
last_block: BlockNumber,
|
||||||
last_time: u64,
|
last_time: u64,
|
||||||
proposal: N::Block,
|
proposal: N::Block,
|
||||||
|
@ -414,6 +417,7 @@ impl<N: Network + 'static> TendermintMachine<N> {
|
||||||
// 01-10
|
// 01-10
|
||||||
let mut machine = TendermintMachine {
|
let mut machine = TendermintMachine {
|
||||||
db: db.clone(),
|
db: db.clone(),
|
||||||
|
genesis,
|
||||||
|
|
||||||
network,
|
network,
|
||||||
signer,
|
signer,
|
||||||
|
@ -427,6 +431,7 @@ impl<N: Network + 'static> TendermintMachine<N> {
|
||||||
|
|
||||||
block: BlockData::new(
|
block: BlockData::new(
|
||||||
db,
|
db,
|
||||||
|
genesis,
|
||||||
weights,
|
weights,
|
||||||
BlockNumber(last_block.0 + 1),
|
BlockNumber(last_block.0 + 1),
|
||||||
validator_id,
|
validator_id,
|
||||||
|
|
|
@ -176,6 +176,7 @@ impl TestNetwork {
|
||||||
TendermintMachine::new(
|
TendermintMachine::new(
|
||||||
MemDb::new(),
|
MemDb::new(),
|
||||||
TestNetwork(i, arc.clone()),
|
TestNetwork(i, arc.clone()),
|
||||||
|
[0; 32],
|
||||||
BlockNumber(1),
|
BlockNumber(1),
|
||||||
start_time,
|
start_time,
|
||||||
TestBlock { id: 1u32.to_le_bytes(), valid: Ok(()) },
|
TestBlock { id: 1u32.to_le_bytes(), valid: Ok(()) },
|
||||||
|
|
Loading…
Reference in a new issue