mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat(engine): new payload execution (#631)
* feat(engine): new payload execution * address PR comments * rm unused dev deps * add comment about lru * remove par_iter
This commit is contained in:
@ -12,7 +12,7 @@ use reth_eth_wire::DisconnectReason;
|
||||
use reth_net_common::ban_list::BanList;
|
||||
use reth_network::{NetworkConfig, NetworkEvent, NetworkManager, PeersConfig};
|
||||
use reth_primitives::{NodeRecord, PeerId};
|
||||
use reth_provider::test_utils::TestApi;
|
||||
use reth_provider::test_utils::NoopProvider;
|
||||
use secp256k1::SecretKey;
|
||||
use std::{collections::HashSet, net::SocketAddr, sync::Arc, time::Duration};
|
||||
use tokio::task;
|
||||
@ -94,7 +94,7 @@ async fn test_already_connected() {
|
||||
let mut net = Testnet::default();
|
||||
|
||||
let secret_key = SecretKey::new(&mut rand::thread_rng());
|
||||
let client = Arc::new(TestApi::default());
|
||||
let client = Arc::new(NoopProvider::default());
|
||||
let p1 = PeerConfig::default();
|
||||
|
||||
// initialize two peers with the same identifier
|
||||
@ -140,8 +140,9 @@ async fn test_connect_with_boot_nodes() {
|
||||
let mut discv4 = Discv4Config::builder();
|
||||
discv4.add_boot_nodes(mainnet_nodes());
|
||||
|
||||
let config =
|
||||
NetworkConfig::builder(Arc::new(TestApi::default()), secret_key).discovery(discv4).build();
|
||||
let config = NetworkConfig::builder(Arc::new(NoopProvider::default()), secret_key)
|
||||
.discovery(discv4)
|
||||
.build();
|
||||
let network = NetworkManager::new(config).await.unwrap();
|
||||
|
||||
let handle = network.handle().clone();
|
||||
@ -161,7 +162,7 @@ async fn test_connect_with_builder() {
|
||||
let mut discv4 = Discv4Config::builder();
|
||||
discv4.add_boot_nodes(mainnet_nodes());
|
||||
|
||||
let client = Arc::new(TestApi::default());
|
||||
let client = Arc::new(NoopProvider::default());
|
||||
let config = NetworkConfig::builder(Arc::clone(&client), secret_key).discovery(discv4).build();
|
||||
let (handle, network, _, requests) = NetworkManager::new(config)
|
||||
.await
|
||||
@ -209,7 +210,7 @@ async fn test_incoming_node_id_blacklist() {
|
||||
|
||||
let reth_p2p_socket = SocketAddr::new([127, 0, 0, 1].into(), 30303);
|
||||
let reth_disc_socket = SocketAddr::new([127, 0, 0, 1].into(), 30304);
|
||||
let config = NetworkConfig::builder(Arc::new(TestApi::default()), secret_key)
|
||||
let config = NetworkConfig::builder(Arc::new(NoopProvider::default()), secret_key)
|
||||
.listener_addr(reth_p2p_socket)
|
||||
.discovery_addr(reth_disc_socket)
|
||||
.peer_config(peer_config)
|
||||
@ -259,7 +260,7 @@ async fn test_incoming_connect_with_single_geth() {
|
||||
|
||||
let reth_p2p_socket = SocketAddr::new([127, 0, 0, 1].into(), 30305);
|
||||
let reth_disc_socket = SocketAddr::new([127, 0, 0, 1].into(), 30306);
|
||||
let config = NetworkConfig::builder(Arc::new(TestApi::default()), secret_key)
|
||||
let config = NetworkConfig::builder(Arc::new(NoopProvider::default()), secret_key)
|
||||
.listener_addr(reth_p2p_socket)
|
||||
.discovery_addr(reth_disc_socket)
|
||||
.build();
|
||||
@ -294,7 +295,7 @@ async fn test_outgoing_connect_with_single_geth() {
|
||||
|
||||
let reth_p2p_socket = SocketAddr::new([127, 0, 0, 1].into(), 30307);
|
||||
let reth_disc_socket = SocketAddr::new([127, 0, 0, 1].into(), 30308);
|
||||
let config = NetworkConfig::builder(Arc::new(TestApi::default()), secret_key)
|
||||
let config = NetworkConfig::builder(Arc::new(NoopProvider::default()), secret_key)
|
||||
.listener_addr(reth_p2p_socket)
|
||||
.discovery_addr(reth_disc_socket)
|
||||
.build();
|
||||
@ -341,7 +342,7 @@ async fn test_geth_disconnect() {
|
||||
|
||||
let reth_p2p_socket = SocketAddr::new([127, 0, 0, 1].into(), 30309);
|
||||
let reth_disc_socket = SocketAddr::new([127, 0, 0, 1].into(), 30310);
|
||||
let config = NetworkConfig::builder(Arc::new(TestApi::default()), secret_key)
|
||||
let config = NetworkConfig::builder(Arc::new(NoopProvider::default()), secret_key)
|
||||
.listener_addr(reth_p2p_socket)
|
||||
.discovery_addr(reth_disc_socket)
|
||||
.build();
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
//! Tests for eth related requests
|
||||
|
||||
use super::testnet::Testnet;
|
||||
use crate::{MockEthProvider, NetworkEventStream};
|
||||
use crate::NetworkEventStream;
|
||||
use rand::Rng;
|
||||
use reth_eth_wire::BlockBody;
|
||||
use reth_interfaces::p2p::{
|
||||
@ -12,6 +12,7 @@ use reth_primitives::{
|
||||
Block, Bytes, Header, HeadersDirection, Signature, Transaction, TransactionKind,
|
||||
TransactionSigned, TxEip2930, H256, U256,
|
||||
};
|
||||
use reth_provider::test_utils::MockEthProvider;
|
||||
use std::sync::Arc;
|
||||
|
||||
/// Returns a new [`TransactionSigned`] with some random parameters
|
||||
|
||||
@ -1,21 +1,16 @@
|
||||
//! A network implementation for testing purposes.
|
||||
|
||||
use futures::{FutureExt, StreamExt};
|
||||
use parking_lot::Mutex;
|
||||
use pin_project::pin_project;
|
||||
use reth_eth_wire::DisconnectReason;
|
||||
use reth_network::{
|
||||
error::NetworkError, eth_requests::EthRequestHandler, NetworkConfig, NetworkEvent,
|
||||
NetworkHandle, NetworkManager,
|
||||
};
|
||||
use reth_primitives::{
|
||||
rpc::{BlockId, BlockNumber},
|
||||
Block, BlockHash, Header, PeerId, H256, U256,
|
||||
};
|
||||
use reth_provider::{test_utils::TestApi, BlockProvider, ChainInfo, HeaderProvider};
|
||||
use reth_primitives::PeerId;
|
||||
use reth_provider::{test_utils::NoopProvider, BlockProvider, HeaderProvider};
|
||||
use secp256k1::SecretKey;
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
fmt,
|
||||
future::Future,
|
||||
net::{Ipv4Addr, SocketAddr, SocketAddrV4},
|
||||
@ -145,7 +140,7 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl Testnet<TestApi> {
|
||||
impl Testnet<NoopProvider> {
|
||||
/// Same as [`Self::try_create`] but panics on error
|
||||
pub async fn create(num_peers: usize) -> Self {
|
||||
Self::try_create(num_peers).await.unwrap()
|
||||
@ -258,7 +253,7 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
pub struct PeerConfig<C = TestApi> {
|
||||
pub struct PeerConfig<C = NoopProvider> {
|
||||
config: NetworkConfig<C>,
|
||||
client: Arc<C>,
|
||||
secret_key: SecretKey,
|
||||
@ -286,7 +281,7 @@ where
|
||||
|
||||
impl Default for PeerConfig {
|
||||
fn default() -> Self {
|
||||
Self::new(Arc::new(TestApi::default()))
|
||||
Self::new(Arc::new(NoopProvider::default()))
|
||||
}
|
||||
}
|
||||
|
||||
@ -324,92 +319,3 @@ impl NetworkEventStream {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
/// A mock implementation for Provider interfaces.
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub struct MockEthProvider {
|
||||
pub blocks: Arc<Mutex<HashMap<H256, Block>>>,
|
||||
pub headers: Arc<Mutex<HashMap<H256, Header>>>,
|
||||
}
|
||||
|
||||
impl MockEthProvider {
|
||||
pub fn add_block(&self, hash: H256, block: Block) {
|
||||
self.blocks.lock().insert(hash, block);
|
||||
}
|
||||
|
||||
pub fn extend_blocks(&self, iter: impl IntoIterator<Item = (H256, Block)>) {
|
||||
for (hash, block) in iter.into_iter() {
|
||||
self.add_block(hash, block)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn add_header(&self, hash: H256, header: Header) {
|
||||
self.headers.lock().insert(hash, header);
|
||||
}
|
||||
|
||||
pub fn extend_headers(&self, iter: impl IntoIterator<Item = (H256, Header)>) {
|
||||
for (hash, header) in iter.into_iter() {
|
||||
self.add_header(hash, header)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl HeaderProvider for MockEthProvider {
|
||||
fn header(&self, block_hash: &BlockHash) -> reth_interfaces::Result<Option<Header>> {
|
||||
let lock = self.headers.lock();
|
||||
Ok(lock.get(block_hash).cloned())
|
||||
}
|
||||
|
||||
fn header_by_number(&self, num: u64) -> reth_interfaces::Result<Option<Header>> {
|
||||
let lock = self.headers.lock();
|
||||
Ok(lock.values().find(|h| h.number == num).cloned())
|
||||
}
|
||||
|
||||
fn header_td(&self, _hash: &BlockHash) -> reth_interfaces::Result<Option<U256>> {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
impl BlockProvider for MockEthProvider {
|
||||
fn chain_info(&self) -> reth_interfaces::Result<ChainInfo> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn block(&self, id: BlockId) -> reth_interfaces::Result<Option<Block>> {
|
||||
let lock = self.blocks.lock();
|
||||
match id {
|
||||
BlockId::Hash(hash) => Ok(lock.get(&hash).cloned()),
|
||||
BlockId::Number(BlockNumber::Number(num)) => {
|
||||
Ok(lock.values().find(|b| b.number == num.as_u64()).cloned())
|
||||
}
|
||||
_ => {
|
||||
unreachable!("unused in network tests")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn block_number(
|
||||
&self,
|
||||
hash: H256,
|
||||
) -> reth_interfaces::Result<Option<reth_primitives::BlockNumber>> {
|
||||
let lock = self.blocks.lock();
|
||||
let num = lock.iter().find_map(|(h, b)| if *h == hash { Some(b.number) } else { None });
|
||||
Ok(num)
|
||||
}
|
||||
|
||||
fn block_hash(&self, number: U256) -> reth_interfaces::Result<Option<H256>> {
|
||||
let lock = self.blocks.lock();
|
||||
|
||||
let hash =
|
||||
lock.iter().find_map(
|
||||
|(hash, b)| {
|
||||
if b.number == number.as_u64() {
|
||||
Some(*hash)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
},
|
||||
);
|
||||
Ok(hash)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user