mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-10 05:09:22 +00:00
Move Commit from including the round to including the round's end_time
The round was usable to build the current clock in an accumulated fashion, relative to the previous round. The end time is the absolute metric of it, which can be used to calculate the round number (with all previous end times). Substrate now builds off the best block, not genesis, using the end time included in the justification to start its machine in a synchronized state. Knowing the end time of a round, or the round in which block was committed to, is necessary for nodes to sync up with Tendermint. Encoding it in the commit ensures it's long lasting and makes it readily available, without the load of an entire transaction.
This commit is contained in:
@@ -3,9 +3,9 @@ use std::{
|
||||
sync::{Arc, RwLock},
|
||||
task::{Poll, Context},
|
||||
future::Future,
|
||||
time::SystemTime,
|
||||
};
|
||||
|
||||
use sp_core::Decode;
|
||||
use sp_inherents::CreateInherentDataProviders;
|
||||
use sp_runtime::traits::{Header, Block};
|
||||
use sp_api::{BlockId, TransactionFor};
|
||||
@@ -18,9 +18,14 @@ use sc_client_api::Backend;
|
||||
|
||||
use substrate_prometheus_endpoint::Registry;
|
||||
|
||||
use tendermint_machine::{ext::BlockNumber, TendermintMachine};
|
||||
use tendermint_machine::{
|
||||
ext::{BlockNumber, Commit},
|
||||
TendermintMachine,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
CONSENSUS_ID,
|
||||
signature_scheme::TendermintSigner,
|
||||
tendermint::{TendermintClient, TendermintImport},
|
||||
Announce,
|
||||
};
|
||||
@@ -98,12 +103,31 @@ where
|
||||
let authority = {
|
||||
let machine_clone = import.machine.clone();
|
||||
let mut import_clone = import.clone();
|
||||
let best = import.client.info().best_number;
|
||||
async move {
|
||||
*machine_clone.write().unwrap() = Some(TendermintMachine::new(
|
||||
import_clone.clone(),
|
||||
// TODO
|
||||
0,
|
||||
(BlockNumber(1), SystemTime::now()),
|
||||
(
|
||||
// Header::Number: TryInto<u64> doesn't implement Debug and can't be unwrapped
|
||||
match best.try_into() {
|
||||
Ok(best) => BlockNumber(best),
|
||||
Err(_) => panic!("BlockNumber exceeded u64"),
|
||||
},
|
||||
Commit::<TendermintSigner>::decode(
|
||||
&mut import_clone
|
||||
.client
|
||||
.justifications(&BlockId::Number(best))
|
||||
.unwrap()
|
||||
.unwrap()
|
||||
.get(CONSENSUS_ID)
|
||||
.unwrap()
|
||||
.as_ref(),
|
||||
)
|
||||
.unwrap()
|
||||
.end_time,
|
||||
),
|
||||
import_clone
|
||||
.get_proposal(&import_clone.client.header(BlockId::Number(0u8.into())).unwrap().unwrap())
|
||||
.await,
|
||||
|
||||
@@ -24,7 +24,7 @@ use sp_consensus::{Error, BlockOrigin, Proposer, Environment};
|
||||
use sc_consensus::{ForkChoiceStrategy, BlockImportParams, BlockImport, import_queue::IncomingBlock};
|
||||
|
||||
use sc_service::ImportQueue;
|
||||
use sc_client_api::{Backend, Finalizer};
|
||||
use sc_client_api::{BlockBackend, Backend, Finalizer};
|
||||
|
||||
use tendermint_machine::{
|
||||
ext::{BlockError, Commit, Network},
|
||||
@@ -43,6 +43,7 @@ pub trait TendermintClient<B: Block, Be: Backend<B> + 'static>:
|
||||
Send
|
||||
+ Sync
|
||||
+ HeaderBackend<B>
|
||||
+ BlockBackend<B>
|
||||
+ BlockImport<B, Transaction = TransactionFor<Self, B>>
|
||||
+ Finalizer<B, Be>
|
||||
+ ProvideRuntimeApi<B>
|
||||
@@ -55,6 +56,7 @@ impl<
|
||||
C: Send
|
||||
+ Sync
|
||||
+ HeaderBackend<B>
|
||||
+ BlockBackend<B>
|
||||
+ BlockImport<B, Transaction = TransactionFor<C, B>>
|
||||
+ Finalizer<B, Be>
|
||||
+ ProvideRuntimeApi<B>
|
||||
@@ -379,8 +381,8 @@ where
|
||||
let info = self.client.info();
|
||||
assert_eq!(info.best_hash, parent);
|
||||
assert_eq!(info.finalized_hash, parent);
|
||||
assert_eq!(info.best_number, number - 1);
|
||||
assert_eq!(info.finalized_number, number - 1);
|
||||
assert_eq!(info.best_number, number - 1u8.into());
|
||||
assert_eq!(info.finalized_number, number - 1u8.into());
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
Reference in New Issue
Block a user