fix(net): set status, forkfilter from chainspec (#939)

This commit is contained in:
Dan Cline
2023-01-20 04:53:01 -05:00
committed by GitHub
parent 2ec490a13d
commit eb11da8adf
3 changed files with 59 additions and 35 deletions

View File

@ -1,4 +1,4 @@
use crate::{EthVersion, StatusBuilder};
use crate::{BlockHashNumber, EthVersion, StatusBuilder};
use ethers_core::utils::Genesis;
use reth_codecs::derive_arbitrary;
@ -82,6 +82,23 @@ impl Status {
pub fn builder() -> StatusBuilder {
Default::default()
}
/// Create a [`StatusBuilder`] from the given [`ChainSpec`](reth_primitives::ChainSpec) and
/// head block number.
///
/// Sets the `chain` and `genesis`, `blockhash`, and `forkid` fields based on the [`ChainSpec`]
/// and head.
///
/// The user should set the `total_difficulty` field if desired. Otherwise, the total
/// difficulty will be set to the [`Default`](std::default::Default) implementation for
/// [`Status`].
pub fn spec_builder(spec: &ChainSpec, head: &BlockHashNumber) -> StatusBuilder {
Self::builder()
.chain(spec.chain)
.genesis(spec.genesis_hash())
.blockhash(head.hash)
.forkid(spec.fork_id(head.number))
}
}
impl Display for Status {