mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
fix: use latest header in autoseal (#3239)
This commit is contained in:
@ -20,7 +20,7 @@ use reth_primitives::{
|
|||||||
BlockBody, BlockHash, BlockHashOrNumber, BlockNumber, ChainSpec, Header, SealedBlock,
|
BlockBody, BlockHash, BlockHashOrNumber, BlockNumber, ChainSpec, Header, SealedBlock,
|
||||||
SealedHeader, H256, U256,
|
SealedHeader, H256, U256,
|
||||||
};
|
};
|
||||||
use reth_provider::CanonStateNotificationSender;
|
use reth_provider::{BlockProviderIdExt, CanonStateNotificationSender};
|
||||||
use reth_transaction_pool::TransactionPool;
|
use reth_transaction_pool::TransactionPool;
|
||||||
use std::{collections::HashMap, sync::Arc};
|
use std::{collections::HashMap, sync::Arc};
|
||||||
use tokio::sync::{mpsc::UnboundedSender, RwLock, RwLockReadGuard, RwLockWriteGuard};
|
use tokio::sync::{mpsc::UnboundedSender, RwLock, RwLockReadGuard, RwLockWriteGuard};
|
||||||
@ -88,7 +88,10 @@ pub struct AutoSealBuilder<Client, Pool> {
|
|||||||
|
|
||||||
// === impl AutoSealBuilder ===
|
// === impl AutoSealBuilder ===
|
||||||
|
|
||||||
impl<Client, Pool: TransactionPool> AutoSealBuilder<Client, Pool> {
|
impl<Client, Pool: TransactionPool> AutoSealBuilder<Client, Pool>
|
||||||
|
where
|
||||||
|
Client: BlockProviderIdExt,
|
||||||
|
{
|
||||||
/// Creates a new builder instance to configure all parts.
|
/// Creates a new builder instance to configure all parts.
|
||||||
pub fn new(
|
pub fn new(
|
||||||
chain_spec: Arc<ChainSpec>,
|
chain_spec: Arc<ChainSpec>,
|
||||||
@ -97,9 +100,15 @@ impl<Client, Pool: TransactionPool> AutoSealBuilder<Client, Pool> {
|
|||||||
to_engine: UnboundedSender<BeaconEngineMessage>,
|
to_engine: UnboundedSender<BeaconEngineMessage>,
|
||||||
canon_state_notification: CanonStateNotificationSender,
|
canon_state_notification: CanonStateNotificationSender,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
|
let latest_header = client
|
||||||
|
.latest_header()
|
||||||
|
.ok()
|
||||||
|
.flatten()
|
||||||
|
.unwrap_or_else(|| chain_spec.sealed_genesis_header());
|
||||||
let mode = MiningMode::interval(std::time::Duration::from_secs(1));
|
let mode = MiningMode::interval(std::time::Duration::from_secs(1));
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
storage: Storage::new(&chain_spec),
|
storage: Storage::new(latest_header),
|
||||||
client,
|
client,
|
||||||
consensus: AutoSealConsensus::new(chain_spec),
|
consensus: AutoSealConsensus::new(chain_spec),
|
||||||
pool,
|
pool,
|
||||||
@ -116,6 +125,7 @@ impl<Client, Pool: TransactionPool> AutoSealBuilder<Client, Pool> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Consumes the type and returns all components
|
/// Consumes the type and returns all components
|
||||||
|
#[track_caller]
|
||||||
pub fn build(self) -> (AutoSealConsensus, AutoSealClient, MiningTask<Client, Pool>) {
|
pub fn build(self) -> (AutoSealConsensus, AutoSealClient, MiningTask<Client, Pool>) {
|
||||||
let Self { client, consensus, pool, mode, storage, to_engine, canon_state_notification } =
|
let Self { client, consensus, pool, mode, storage, to_engine, canon_state_notification } =
|
||||||
self;
|
self;
|
||||||
@ -142,11 +152,14 @@ pub(crate) struct Storage {
|
|||||||
// == impl Storage ===
|
// == impl Storage ===
|
||||||
|
|
||||||
impl Storage {
|
impl Storage {
|
||||||
fn new(chain_spec: &ChainSpec) -> Self {
|
fn new(header: SealedHeader) -> Self {
|
||||||
let header = chain_spec.genesis_header();
|
let (header, best_hash) = header.split();
|
||||||
let best_hash = header.hash_slow();
|
let mut storage = StorageInner {
|
||||||
let mut storage =
|
best_hash,
|
||||||
StorageInner { best_hash, total_difficulty: header.difficulty, ..Default::default() };
|
total_difficulty: header.difficulty,
|
||||||
|
best_block: header.number,
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
storage.headers.insert(0, header);
|
storage.headers.insert(0, header);
|
||||||
storage.bodies.insert(best_hash, BlockBody::default());
|
storage.bodies.insert(best_hash, BlockBody::default());
|
||||||
Self { inner: Arc::new(RwLock::new(storage)) }
|
Self { inner: Arc::new(RwLock::new(storage)) }
|
||||||
|
|||||||
Reference in New Issue
Block a user