mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
chore: move block body to primitives (#1874)
This commit is contained in:
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -4709,7 +4709,6 @@ dependencies = [
|
|||||||
"pin-project",
|
"pin-project",
|
||||||
"rayon",
|
"rayon",
|
||||||
"reth-db",
|
"reth-db",
|
||||||
"reth-eth-wire",
|
|
||||||
"reth-interfaces",
|
"reth-interfaces",
|
||||||
"reth-metrics-derive",
|
"reth-metrics-derive",
|
||||||
"reth-primitives",
|
"reth-primitives",
|
||||||
|
|||||||
@ -2,8 +2,7 @@ use std::pin::Pin;
|
|||||||
|
|
||||||
use crate::p2p::{download::DownloadClient, error::PeerRequestResult, priority::Priority};
|
use crate::p2p::{download::DownloadClient, error::PeerRequestResult, priority::Priority};
|
||||||
use futures::Future;
|
use futures::Future;
|
||||||
use reth_eth_wire::BlockBody;
|
use reth_primitives::{BlockBody, H256};
|
||||||
use reth_primitives::H256;
|
|
||||||
|
|
||||||
/// The bodies future type
|
/// The bodies future type
|
||||||
pub type BodiesFut = Pin<Box<dyn Future<Output = PeerRequestResult<Vec<BlockBody>>> + Send + Sync>>;
|
pub type BodiesFut = Pin<Box<dyn Future<Output = PeerRequestResult<Vec<BlockBody>>> + Send + Sync>>;
|
||||||
|
|||||||
@ -6,8 +6,7 @@ use crate::p2p::{
|
|||||||
};
|
};
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use futures::{future, Future, FutureExt};
|
use futures::{future, Future, FutureExt};
|
||||||
use reth_eth_wire::BlockBody;
|
use reth_primitives::{BlockBody, WithPeerId, H256};
|
||||||
use reth_primitives::{WithPeerId, H256};
|
|
||||||
use std::{
|
use std::{
|
||||||
fmt::{Debug, Formatter},
|
fmt::{Debug, Formatter},
|
||||||
pin::Pin,
|
pin::Pin,
|
||||||
|
|||||||
@ -11,7 +11,6 @@ description = "Implementations of various block downloaders"
|
|||||||
# reth
|
# reth
|
||||||
reth-interfaces = { path = "../../interfaces" }
|
reth-interfaces = { path = "../../interfaces" }
|
||||||
reth-primitives = { path = "../../primitives" }
|
reth-primitives = { path = "../../primitives" }
|
||||||
reth-eth-wire = { path = "../eth-wire" }
|
|
||||||
reth-db = { path = "../../storage/db" }
|
reth-db = { path = "../../storage/db" }
|
||||||
reth-tasks = { path = "../../tasks" }
|
reth-tasks = { path = "../../tasks" }
|
||||||
reth-metrics-derive = { path = "../../metrics/metrics-derive" }
|
reth-metrics-derive = { path = "../../metrics/metrics-derive" }
|
||||||
|
|||||||
@ -536,9 +536,8 @@ mod tests {
|
|||||||
use assert_matches::assert_matches;
|
use assert_matches::assert_matches;
|
||||||
use futures_util::stream::StreamExt;
|
use futures_util::stream::StreamExt;
|
||||||
use reth_db::mdbx::{test_utils::create_test_db, EnvKind, WriteMap};
|
use reth_db::mdbx::{test_utils::create_test_db, EnvKind, WriteMap};
|
||||||
use reth_eth_wire::BlockBody;
|
|
||||||
use reth_interfaces::test_utils::{generators::random_block_range, TestConsensus};
|
use reth_interfaces::test_utils::{generators::random_block_range, TestConsensus};
|
||||||
use reth_primitives::H256;
|
use reth_primitives::{BlockBody, H256};
|
||||||
use std::{collections::HashMap, sync::Arc};
|
use std::{collections::HashMap, sync::Arc};
|
||||||
|
|
||||||
// Check that the blocks are emitted in order of block number, not in order of
|
// Check that the blocks are emitted in order of block number, not in order of
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
use crate::metrics::DownloaderMetrics;
|
use crate::metrics::DownloaderMetrics;
|
||||||
use futures::{Future, FutureExt};
|
use futures::{Future, FutureExt};
|
||||||
use reth_eth_wire::BlockBody;
|
|
||||||
use reth_interfaces::{
|
use reth_interfaces::{
|
||||||
consensus::{Consensus as ConsensusTrait, Consensus},
|
consensus::{Consensus as ConsensusTrait, Consensus},
|
||||||
p2p::{
|
p2p::{
|
||||||
@ -9,7 +8,7 @@ use reth_interfaces::{
|
|||||||
priority::Priority,
|
priority::Priority,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
use reth_primitives::{PeerId, SealedBlock, SealedHeader, WithPeerId, H256};
|
use reth_primitives::{BlockBody, PeerId, SealedBlock, SealedHeader, WithPeerId, H256};
|
||||||
use std::{
|
use std::{
|
||||||
collections::VecDeque,
|
collections::VecDeque,
|
||||||
pin::Pin,
|
pin::Pin,
|
||||||
|
|||||||
@ -6,9 +6,8 @@ use reth_db::{
|
|||||||
tables,
|
tables,
|
||||||
transaction::DbTxMut,
|
transaction::DbTxMut,
|
||||||
};
|
};
|
||||||
use reth_eth_wire::BlockBody;
|
|
||||||
use reth_interfaces::{db, p2p::bodies::response::BlockResponse};
|
use reth_interfaces::{db, p2p::bodies::response::BlockResponse};
|
||||||
use reth_primitives::{Block, SealedBlock, SealedHeader, H256};
|
use reth_primitives::{Block, BlockBody, SealedBlock, SealedHeader, H256};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
pub(crate) fn zip_blocks<'a>(
|
pub(crate) fn zip_blocks<'a>(
|
||||||
|
|||||||
@ -1010,8 +1010,8 @@ impl Default for ReverseHeadersDownloaderBuilder {
|
|||||||
impl ReverseHeadersDownloaderBuilder {
|
impl ReverseHeadersDownloaderBuilder {
|
||||||
/// Set the request batch size.
|
/// Set the request batch size.
|
||||||
///
|
///
|
||||||
/// This determines the `limit` for a [GetHeaders](reth_eth_wire::GetBlockHeaders) requests, the
|
/// This determines the `limit` for a `GetBlockHeaders` requests, the number of headers we ask
|
||||||
/// number of headers we ask for.
|
/// for.
|
||||||
pub fn request_limit(mut self, limit: u64) -> Self {
|
pub fn request_limit(mut self, limit: u64) -> Self {
|
||||||
self.request_limit = limit;
|
self.request_limit = limit;
|
||||||
self
|
self
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
use super::file_codec::BlockFileCodec;
|
use super::file_codec::BlockFileCodec;
|
||||||
use itertools::Either;
|
use itertools::Either;
|
||||||
use reth_eth_wire::BlockBody;
|
|
||||||
use reth_interfaces::{
|
use reth_interfaces::{
|
||||||
p2p::{
|
p2p::{
|
||||||
bodies::client::{BodiesClient, BodiesFut},
|
bodies::client::{BodiesClient, BodiesFut},
|
||||||
@ -12,7 +11,8 @@ use reth_interfaces::{
|
|||||||
sync::{SyncState, SyncStateProvider, SyncStateUpdater},
|
sync::{SyncState, SyncStateProvider, SyncStateUpdater},
|
||||||
};
|
};
|
||||||
use reth_primitives::{
|
use reth_primitives::{
|
||||||
Block, BlockHash, BlockHashOrNumber, BlockNumber, Header, HeadersDirection, PeerId, H256,
|
Block, BlockBody, BlockHash, BlockHashOrNumber, BlockNumber, Header, HeadersDirection, PeerId,
|
||||||
|
H256,
|
||||||
};
|
};
|
||||||
use reth_rlp::{Decodable, Header as RlpHeader};
|
use reth_rlp::{Decodable, Header as RlpHeader};
|
||||||
use std::{
|
use std::{
|
||||||
|
|||||||
@ -2,9 +2,8 @@
|
|||||||
//! Test helper impls
|
//! Test helper impls
|
||||||
use crate::bodies::test_utils::create_raw_bodies;
|
use crate::bodies::test_utils::create_raw_bodies;
|
||||||
use futures::SinkExt;
|
use futures::SinkExt;
|
||||||
use reth_eth_wire::BlockBody;
|
|
||||||
use reth_interfaces::test_utils::generators::random_block_range;
|
use reth_interfaces::test_utils::generators::random_block_range;
|
||||||
use reth_primitives::{SealedHeader, H256};
|
use reth_primitives::{BlockBody, SealedHeader, H256};
|
||||||
use std::{collections::HashMap, io::SeekFrom};
|
use std::{collections::HashMap, io::SeekFrom};
|
||||||
use tokio::{
|
use tokio::{
|
||||||
fs::File,
|
fs::File,
|
||||||
|
|||||||
@ -1,10 +1,9 @@
|
|||||||
use reth_eth_wire::BlockBody;
|
|
||||||
use reth_interfaces::p2p::{
|
use reth_interfaces::p2p::{
|
||||||
bodies::client::{BodiesClient, BodiesFut},
|
bodies::client::{BodiesClient, BodiesFut},
|
||||||
download::DownloadClient,
|
download::DownloadClient,
|
||||||
priority::Priority,
|
priority::Priority,
|
||||||
};
|
};
|
||||||
use reth_primitives::{PeerId, H256};
|
use reth_primitives::{BlockBody, PeerId, H256};
|
||||||
use std::{
|
use std::{
|
||||||
collections::HashMap,
|
collections::HashMap,
|
||||||
fmt::Debug,
|
fmt::Debug,
|
||||||
|
|||||||
@ -1,9 +1,7 @@
|
|||||||
//! Implements the `GetBlockHeaders`, `GetBlockBodies`, `BlockHeaders`, and `BlockBodies` message
|
//! Implements the `GetBlockHeaders`, `GetBlockBodies`, `BlockHeaders`, and `BlockBodies` message
|
||||||
//! types.
|
//! types.
|
||||||
use reth_codecs::derive_arbitrary;
|
use reth_codecs::derive_arbitrary;
|
||||||
use reth_primitives::{
|
use reth_primitives::{BlockBody, BlockHashOrNumber, Header, HeadersDirection, H256};
|
||||||
Block, BlockHashOrNumber, Header, HeadersDirection, TransactionSigned, Withdrawal, H256,
|
|
||||||
};
|
|
||||||
use reth_rlp::{RlpDecodable, RlpDecodableWrapper, RlpEncodable, RlpEncodableWrapper};
|
use reth_rlp::{RlpDecodable, RlpDecodableWrapper, RlpEncodable, RlpEncodableWrapper};
|
||||||
|
|
||||||
#[cfg(feature = "serde")]
|
#[cfg(feature = "serde")]
|
||||||
@ -68,35 +66,6 @@ impl From<Vec<H256>> for GetBlockBodies {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(onbjerg): We should have this type in primitives
|
|
||||||
/// A response to [`GetBlockBodies`], containing bodies if any bodies were found.
|
|
||||||
///
|
|
||||||
/// Withdrawals can be optionally included at the end of the RLP encoded message.
|
|
||||||
#[derive_arbitrary(rlp, 10)]
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq, Default, RlpEncodable, RlpDecodable)]
|
|
||||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
|
||||||
#[rlp(trailing)]
|
|
||||||
pub struct BlockBody {
|
|
||||||
/// Transactions in the block
|
|
||||||
pub transactions: Vec<TransactionSigned>,
|
|
||||||
/// Uncle headers for the given block
|
|
||||||
pub ommers: Vec<Header>,
|
|
||||||
/// Withdrawals in the block.
|
|
||||||
pub withdrawals: Option<Vec<Withdrawal>>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl BlockBody {
|
|
||||||
/// Create a [`Block`](reth_primitives::Block) from the body and its header.
|
|
||||||
pub fn create_block(&self, header: Header) -> Block {
|
|
||||||
Block {
|
|
||||||
header,
|
|
||||||
body: self.transactions.clone(),
|
|
||||||
ommers: self.ommers.clone(),
|
|
||||||
withdrawals: self.withdrawals.clone(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The response to [`GetBlockBodies`], containing the block bodies that the peer knows about if
|
/// The response to [`GetBlockBodies`], containing the block bodies that the peer knows about if
|
||||||
/// any were found.
|
/// any were found.
|
||||||
#[derive_arbitrary(rlp, 1)]
|
#[derive_arbitrary(rlp, 1)]
|
||||||
|
|||||||
@ -3,11 +3,11 @@
|
|||||||
use crate::peers::PeersHandle;
|
use crate::peers::PeersHandle;
|
||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
use reth_eth_wire::{
|
use reth_eth_wire::{
|
||||||
BlockBodies, BlockBody, BlockHeaders, GetBlockBodies, GetBlockHeaders, GetNodeData,
|
BlockBodies, BlockHeaders, GetBlockBodies, GetBlockHeaders, GetNodeData, GetReceipts, NodeData,
|
||||||
GetReceipts, NodeData, Receipts,
|
Receipts,
|
||||||
};
|
};
|
||||||
use reth_interfaces::p2p::error::RequestResult;
|
use reth_interfaces::p2p::error::RequestResult;
|
||||||
use reth_primitives::{BlockHashOrNumber, Header, HeadersDirection, PeerId};
|
use reth_primitives::{BlockBody, BlockHashOrNumber, Header, HeadersDirection, PeerId};
|
||||||
use reth_provider::{BlockProvider, HeaderProvider};
|
use reth_provider::{BlockProvider, HeaderProvider};
|
||||||
use std::{
|
use std::{
|
||||||
borrow::Borrow,
|
borrow::Borrow,
|
||||||
|
|||||||
@ -2,14 +2,14 @@
|
|||||||
|
|
||||||
use crate::{message::BlockRequest, peers::PeersHandle};
|
use crate::{message::BlockRequest, peers::PeersHandle};
|
||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
use reth_eth_wire::{BlockBody, GetBlockBodies, GetBlockHeaders};
|
use reth_eth_wire::{GetBlockBodies, GetBlockHeaders};
|
||||||
use reth_interfaces::p2p::{
|
use reth_interfaces::p2p::{
|
||||||
error::{EthResponseValidator, PeerRequestResult, RequestError, RequestResult},
|
error::{EthResponseValidator, PeerRequestResult, RequestError, RequestResult},
|
||||||
headers::client::HeadersRequest,
|
headers::client::HeadersRequest,
|
||||||
priority::Priority,
|
priority::Priority,
|
||||||
};
|
};
|
||||||
use reth_network_api::ReputationChangeKind;
|
use reth_network_api::ReputationChangeKind;
|
||||||
use reth_primitives::{Header, PeerId, H256};
|
use reth_primitives::{BlockBody, Header, PeerId, H256};
|
||||||
use std::{
|
use std::{
|
||||||
collections::{HashMap, VecDeque},
|
collections::{HashMap, VecDeque},
|
||||||
sync::{
|
sync::{
|
||||||
|
|||||||
@ -5,13 +5,13 @@
|
|||||||
|
|
||||||
use futures::FutureExt;
|
use futures::FutureExt;
|
||||||
use reth_eth_wire::{
|
use reth_eth_wire::{
|
||||||
capability::RawCapabilityMessage, message::RequestPair, BlockBodies, BlockBody, BlockHeaders,
|
capability::RawCapabilityMessage, message::RequestPair, BlockBodies, BlockHeaders, EthMessage,
|
||||||
EthMessage, GetBlockBodies, GetBlockHeaders, GetNodeData, GetPooledTransactions, GetReceipts,
|
GetBlockBodies, GetBlockHeaders, GetNodeData, GetPooledTransactions, GetReceipts, NewBlock,
|
||||||
NewBlock, NewBlockHashes, NewPooledTransactionHashes, NodeData, PooledTransactions, Receipts,
|
NewBlockHashes, NewPooledTransactionHashes, NodeData, PooledTransactions, Receipts,
|
||||||
SharedTransactions, Transactions,
|
SharedTransactions, Transactions,
|
||||||
};
|
};
|
||||||
use reth_interfaces::p2p::error::{RequestError, RequestResult};
|
use reth_interfaces::p2p::error::{RequestError, RequestResult};
|
||||||
use reth_primitives::{Bytes, Header, PeerId, Receipt, TransactionSigned, H256};
|
use reth_primitives::{BlockBody, Bytes, Header, PeerId, Receipt, TransactionSigned, H256};
|
||||||
use std::{
|
use std::{
|
||||||
fmt,
|
fmt,
|
||||||
sync::Arc,
|
sync::Arc,
|
||||||
|
|||||||
@ -511,10 +511,10 @@ mod tests {
|
|||||||
};
|
};
|
||||||
use reth_eth_wire::{
|
use reth_eth_wire::{
|
||||||
capability::{Capabilities, Capability},
|
capability::{Capabilities, Capability},
|
||||||
BlockBodies, BlockBody, EthVersion, Status,
|
BlockBodies, EthVersion, Status,
|
||||||
};
|
};
|
||||||
use reth_interfaces::p2p::{bodies::client::BodiesClient, error::RequestError};
|
use reth_interfaces::p2p::{bodies::client::BodiesClient, error::RequestError};
|
||||||
use reth_primitives::{Header, PeerId, H256};
|
use reth_primitives::{BlockBody, Header, PeerId, H256};
|
||||||
use reth_provider::test_utils::NoopProvider;
|
use reth_provider::test_utils::NoopProvider;
|
||||||
use std::{
|
use std::{
|
||||||
future::poll_fn,
|
future::poll_fn,
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
//! Tests for eth related requests
|
//! Tests for eth related requests
|
||||||
|
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
use reth_eth_wire::BlockBody;
|
|
||||||
use reth_interfaces::p2p::{
|
use reth_interfaces::p2p::{
|
||||||
bodies::client::BodiesClient,
|
bodies::client::BodiesClient,
|
||||||
headers::client::{HeadersClient, HeadersRequest},
|
headers::client::{HeadersClient, HeadersRequest},
|
||||||
@ -9,7 +8,7 @@ use reth_interfaces::p2p::{
|
|||||||
use reth_network::test_utils::{NetworkEventStream, Testnet};
|
use reth_network::test_utils::{NetworkEventStream, Testnet};
|
||||||
use reth_network_api::{NetworkInfo, Peers};
|
use reth_network_api::{NetworkInfo, Peers};
|
||||||
use reth_primitives::{
|
use reth_primitives::{
|
||||||
Block, Bytes, Header, HeadersDirection, Signature, Transaction, TransactionKind,
|
Block, BlockBody, Bytes, Header, HeadersDirection, Signature, Transaction, TransactionKind,
|
||||||
TransactionSigned, TxEip2930, H256, U256,
|
TransactionSigned, TxEip2930, H256, U256,
|
||||||
};
|
};
|
||||||
use reth_provider::test_utils::MockEthProvider;
|
use reth_provider::test_utils::MockEthProvider;
|
||||||
|
|||||||
@ -570,6 +570,35 @@ impl AsRef<H256> for BlockHash {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A response to `GetBlockBodies`, containing bodies if any bodies were found.
|
||||||
|
///
|
||||||
|
/// Withdrawals can be optionally included at the end of the RLP encoded message.
|
||||||
|
#[derive_arbitrary(rlp, 10)]
|
||||||
|
#[derive(
|
||||||
|
Clone, Debug, PartialEq, Eq, Default, Serialize, Deserialize, RlpEncodable, RlpDecodable,
|
||||||
|
)]
|
||||||
|
#[rlp(trailing)]
|
||||||
|
pub struct BlockBody {
|
||||||
|
/// Transactions in the block
|
||||||
|
pub transactions: Vec<TransactionSigned>,
|
||||||
|
/// Uncle headers for the given block
|
||||||
|
pub ommers: Vec<Header>,
|
||||||
|
/// Withdrawals in the block.
|
||||||
|
pub withdrawals: Option<Vec<Withdrawal>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl BlockBody {
|
||||||
|
/// Create a [`Block`](Block) from the body and its header.
|
||||||
|
pub fn create_block(&self, header: Header) -> Block {
|
||||||
|
Block {
|
||||||
|
header,
|
||||||
|
body: self.transactions.clone(),
|
||||||
|
ommers: self.ommers.clone(),
|
||||||
|
withdrawals: self.withdrawals.clone(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use super::{BlockId, BlockNumberOrTag::*, *};
|
use super::{BlockId, BlockNumberOrTag::*, *};
|
||||||
|
|||||||
@ -39,7 +39,8 @@ pub mod proofs;
|
|||||||
pub use account::{Account, Bytecode};
|
pub use account::{Account, Bytecode};
|
||||||
pub use bits::H512;
|
pub use bits::H512;
|
||||||
pub use block::{
|
pub use block::{
|
||||||
Block, BlockHashOrNumber, BlockId, BlockNumberOrTag, SealedBlock, SealedBlockWithSenders,
|
Block, BlockBody, BlockHashOrNumber, BlockId, BlockNumberOrTag, SealedBlock,
|
||||||
|
SealedBlockWithSenders,
|
||||||
};
|
};
|
||||||
pub use bloom::Bloom;
|
pub use bloom::Bloom;
|
||||||
pub use chain::{
|
pub use chain::{
|
||||||
|
|||||||
@ -447,7 +447,6 @@ mod tests {
|
|||||||
tables,
|
tables,
|
||||||
transaction::{DbTx, DbTxMut},
|
transaction::{DbTx, DbTxMut},
|
||||||
};
|
};
|
||||||
use reth_eth_wire::BlockBody;
|
|
||||||
use reth_interfaces::{
|
use reth_interfaces::{
|
||||||
consensus::Consensus,
|
consensus::Consensus,
|
||||||
p2p::{
|
p2p::{
|
||||||
@ -465,7 +464,7 @@ mod tests {
|
|||||||
TestConsensus,
|
TestConsensus,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
use reth_primitives::{BlockNumber, SealedBlock, SealedHeader, TxNumber, H256};
|
use reth_primitives::{BlockBody, BlockNumber, SealedBlock, SealedHeader, TxNumber, H256};
|
||||||
use std::{
|
use std::{
|
||||||
collections::{HashMap, VecDeque},
|
collections::{HashMap, VecDeque},
|
||||||
ops::Range,
|
ops::Range,
|
||||||
|
|||||||
Reference in New Issue
Block a user