refactor: rename HeaderLocked to SealedHeader (#173)

This commit is contained in:
Matthias Seitz
2022-11-07 21:06:53 +01:00
committed by GitHub
parent 099d3cee9a
commit caad026c70
10 changed files with 78 additions and 77 deletions

View File

@@ -1,5 +1,5 @@
use async_trait::async_trait;
use reth_primitives::{BlockHash, BlockNumber, HeaderLocked, H256};
use reth_primitives::{BlockHash, BlockNumber, SealedHeader, H256};
use tokio::sync::watch::Receiver;
/// Re-export forkchoice state
@@ -14,7 +14,7 @@ pub trait Consensus: Send + Sync {
fn fork_choice_state(&self) -> Receiver<ForkchoiceState>;
/// Validate if header is correct and follows consensus specification
fn validate_header(&self, header: &HeaderLocked, parent: &HeaderLocked) -> Result<(), Error>;
fn validate_header(&self, header: &SealedHeader, parent: &SealedHeader) -> Result<(), Error>;
}
/// Consensus Errors

View File

@@ -4,7 +4,7 @@ use crate::consensus::Consensus;
use async_trait::async_trait;
use reth_primitives::{
rpc::{BlockId, BlockNumber},
Header, HeaderLocked, H256,
Header, SealedHeader, H256,
};
use reth_rpc_types::engine::ForkchoiceState;
use std::{fmt::Debug, time::Duration};
@@ -74,9 +74,9 @@ pub trait Downloader: Sync + Send {
/// Download the headers
async fn download(
&self,
head: &HeaderLocked,
head: &SealedHeader,
forkchoice: &ForkchoiceState,
) -> Result<Vec<HeaderLocked>, DownloadError>;
) -> Result<Vec<SealedHeader>, DownloadError>;
/// Perform a header request and returns the headers.
// TODO: Isn't this effectively blocking per request per downloader?
@@ -108,7 +108,7 @@ pub trait Downloader: Sync + Send {
/// Validate whether the header is valid in relation to it's parent
///
/// Returns Ok(false) if the
fn validate(&self, header: &HeaderLocked, parent: &HeaderLocked) -> Result<(), DownloadError> {
fn validate(&self, header: &SealedHeader, parent: &SealedHeader) -> Result<(), DownloadError> {
if !(parent.hash() == header.parent_hash && parent.number + 1 == header.number) {
return Err(DownloadError::MismatchedHeaders {
header_number: header.number.into(),

View File

@@ -7,7 +7,7 @@ use crate::{
};
use std::{collections::HashSet, sync::Arc, time::Duration};
use reth_primitives::{Header, HeaderLocked, H256, H512, U256};
use reth_primitives::{Header, SealedHeader, H256, H512, U256};
use reth_rpc_types::engine::ForkchoiceState;
use tokio::sync::{broadcast, mpsc, watch};
@@ -16,12 +16,12 @@ use tokio_stream::{wrappers::BroadcastStream, StreamExt};
#[derive(Debug)]
/// A test downloader which just returns the values that have been pushed to it.
pub struct TestDownloader {
result: Result<Vec<HeaderLocked>, DownloadError>,
result: Result<Vec<SealedHeader>, DownloadError>,
}
impl TestDownloader {
/// Instantiates the downloader with the mock responses
pub fn new(result: Result<Vec<HeaderLocked>, DownloadError>) -> Self {
pub fn new(result: Result<Vec<SealedHeader>, DownloadError>) -> Self {
Self { result }
}
}
@@ -45,9 +45,9 @@ impl Downloader for TestDownloader {
async fn download(
&self,
_: &HeaderLocked,
_: &SealedHeader,
_: &ForkchoiceState,
) -> Result<Vec<HeaderLocked>, DownloadError> {
) -> Result<Vec<SealedHeader>, DownloadError> {
self.result.clone()
}
}
@@ -157,8 +157,8 @@ impl Consensus for TestConsensus {
fn validate_header(
&self,
_header: &HeaderLocked,
_parent: &HeaderLocked,
_header: &SealedHeader,
_parent: &SealedHeader,
) -> Result<(), consensus::Error> {
if self.fail_validation {
Err(consensus::Error::BaseFeeMissing)
@@ -170,19 +170,19 @@ impl Consensus for TestConsensus {
/// Generate a range of random header. The parent hash of the first header
/// in the result will be equal to head
pub fn gen_random_header_range(rng: std::ops::Range<u64>, head: H256) -> Vec<HeaderLocked> {
pub fn gen_random_header_range(rng: std::ops::Range<u64>, head: H256) -> Vec<SealedHeader> {
let mut headers = Vec::with_capacity(rng.end.saturating_sub(rng.start) as usize);
for idx in rng {
headers.push(gen_random_header(
idx,
Some(headers.last().map(|h: &HeaderLocked| h.hash()).unwrap_or(head)),
Some(headers.last().map(|h: &SealedHeader| h.hash()).unwrap_or(head)),
));
}
headers
}
/// Generate a random header
pub fn gen_random_header(number: u64, parent: Option<H256>) -> HeaderLocked {
pub fn gen_random_header(number: u64, parent: Option<H256>) -> SealedHeader {
let header = reth_primitives::Header {
number,
nonce: rand::random(),
@@ -190,5 +190,5 @@ pub fn gen_random_header(number: u64, parent: Option<H256>) -> HeaderLocked {
parent_hash: parent.unwrap_or_default(),
..Default::default()
};
header.lock()
header.seal()
}