22 Commits

Author SHA1 Message Date
5327ebc97a Merge pull request #82 from hl-archive-node/fix/local-reader
fix(local-ingest-dir): Use more robust resumption for hl-node line reader, fix block number increment for reading files
2025-10-05 07:36:32 -04:00
4d83b687d4 feat: Add metrics for file read triggered
Usually, "Loading block data from ..." shouldn't be shown in logs at all. Add metrics to detect the file read.
2025-10-05 11:28:11 +00:00
12f366573e fix: Do not increase block counter when no block is read
This made ingest loop to infinitely increase the block number
2025-10-05 11:28:11 +00:00
b8bae7cde9 fix: Utillize LruMap better
LruMap was introduced to allow getting the same block twice, so removing the item when getting the block doesn't make sense.
2025-10-05 11:28:11 +00:00
0fd4b7943f refactor: Use offsets instead of lines, wrap related structs in one 2025-10-05 11:28:04 +00:00
bfd61094ee chore: cargo fmt 2025-10-05 09:58:13 +00:00
3b33b0a526 Merge pull request #81 from hl-archive-node/fix/typo-local
fix: Fix typo in --local (default hl-node dir)
2025-10-05 05:54:35 -04:00
de7b524f0b fix: Fix typo in --local (default hl-node dir) 2025-10-05 04:39:09 -04:00
24f2460337 Merge pull request #80 from hl-archive-node/chore/v1.8.2
chore: Upgrade to reth v1.8.2
2025-10-05 04:38:54 -04:00
b55ddc54ad chore: clippy 2025-10-05 04:04:30 -04:00
aa73fab281 chore: Now cargo fmt sorts imports and trait methods 2025-10-05 03:56:23 -04:00
ae0cb0da6d chore: Move sprites0/reth to hl-archive-node/reth 2025-10-05 03:56:23 -04:00
8605be9864 chore: Upgrade to reth v1.8.2 2025-10-05 03:56:23 -04:00
c93ff90f94 Merge pull request #79 from hl-archive-node/fix/issue-78
fix: Do not filter out logs based on bloom (which is for perf optimization)
2025-10-05 00:43:20 -04:00
ce64e00e2f fix: Do not filter out logs based on bloom (which is for perf optimization)
Resolves #78
2025-10-05 00:33:44 -04:00
8d8da57d3a Merge pull request #77 from hl-archive-node/feat/cutoff-latest
feat: Add debug CLI flag to enforce latest blocks (--debug-cutoff-height)
2025-10-02 10:57:04 -04:00
875304f891 feat: Add debug CLI flag to enforce latest blocks (--debug-cutoff-height)
This is useful when syncing to specific testnet blocks
2025-10-02 14:53:47 +00:00
b37ba15765 Merge pull request #74 from Quertyy/feat/block-precompila-data-rpc-method
feat(rpc): add HlBlockPrecompile rpc API
2025-09-19 02:42:21 -04:00
3080665702 style: pass clippy check 2025-09-19 13:23:49 +07:00
4896e4f0ea refactor: use BlockId as block type 2025-09-19 12:41:14 +07:00
458f506ad2 refactor: use BlockHashOrNumber as block type 2025-09-19 12:33:32 +07:00
1c7136bfab feat(rpc): add HlBlockPrecompile rpc API 2025-09-18 04:57:49 +07:00
57 changed files with 901 additions and 682 deletions

653
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,7 @@
[package]
name = "reth_hl"
version = "0.1.0"
edition = "2021"
edition = "2024"
build = "build.rs"
[lib]
@ -26,67 +26,67 @@ lto = "fat"
codegen-units = 1
[dependencies]
reth = { git = "https://github.com/sprites0/reth", rev = "d26fd2e25b57d695aa453c93f15a8cd158a1f505" }
reth-cli = { git = "https://github.com/sprites0/reth", rev = "d26fd2e25b57d695aa453c93f15a8cd158a1f505" }
reth-cli-commands = { git = "https://github.com/sprites0/reth", rev = "d26fd2e25b57d695aa453c93f15a8cd158a1f505" }
reth-basic-payload-builder = { git = "https://github.com/sprites0/reth", rev = "d26fd2e25b57d695aa453c93f15a8cd158a1f505" }
reth-db = { git = "https://github.com/sprites0/reth", rev = "d26fd2e25b57d695aa453c93f15a8cd158a1f505" }
reth-db-api = { git = "https://github.com/sprites0/reth", rev = "d26fd2e25b57d695aa453c93f15a8cd158a1f505" }
reth-chainspec = { git = "https://github.com/sprites0/reth", rev = "d26fd2e25b57d695aa453c93f15a8cd158a1f505" }
reth-cli-util = { git = "https://github.com/sprites0/reth", rev = "d26fd2e25b57d695aa453c93f15a8cd158a1f505" }
reth-discv4 = { git = "https://github.com/sprites0/reth", rev = "d26fd2e25b57d695aa453c93f15a8cd158a1f505" }
reth-engine-primitives = { git = "https://github.com/sprites0/reth", rev = "d26fd2e25b57d695aa453c93f15a8cd158a1f505" }
reth-ethereum-forks = { git = "https://github.com/sprites0/reth", rev = "d26fd2e25b57d695aa453c93f15a8cd158a1f505" }
reth-ethereum-payload-builder = { git = "https://github.com/sprites0/reth", rev = "d26fd2e25b57d695aa453c93f15a8cd158a1f505" }
reth-ethereum-primitives = { git = "https://github.com/sprites0/reth", rev = "d26fd2e25b57d695aa453c93f15a8cd158a1f505" }
reth-eth-wire = { git = "https://github.com/sprites0/reth", rev = "d26fd2e25b57d695aa453c93f15a8cd158a1f505" }
reth-eth-wire-types = { git = "https://github.com/sprites0/reth", rev = "d26fd2e25b57d695aa453c93f15a8cd158a1f505" }
reth-evm = { git = "https://github.com/sprites0/reth", rev = "d26fd2e25b57d695aa453c93f15a8cd158a1f505" }
reth-evm-ethereum = { git = "https://github.com/sprites0/reth", rev = "d26fd2e25b57d695aa453c93f15a8cd158a1f505" }
reth-node-core = { git = "https://github.com/sprites0/reth", rev = "d26fd2e25b57d695aa453c93f15a8cd158a1f505" }
reth-revm = { git = "https://github.com/sprites0/reth", rev = "d26fd2e25b57d695aa453c93f15a8cd158a1f505" }
reth-network = { git = "https://github.com/sprites0/reth", rev = "d26fd2e25b57d695aa453c93f15a8cd158a1f505" }
reth-network-p2p = { git = "https://github.com/sprites0/reth", rev = "d26fd2e25b57d695aa453c93f15a8cd158a1f505" }
reth-network-api = { git = "https://github.com/sprites0/reth", rev = "d26fd2e25b57d695aa453c93f15a8cd158a1f505" }
reth-node-ethereum = { git = "https://github.com/sprites0/reth", rev = "d26fd2e25b57d695aa453c93f15a8cd158a1f505" }
reth-network-peers = { git = "https://github.com/sprites0/reth", rev = "d26fd2e25b57d695aa453c93f15a8cd158a1f505" }
reth-payload-primitives = { git = "https://github.com/sprites0/reth", rev = "d26fd2e25b57d695aa453c93f15a8cd158a1f505" }
reth-primitives = { git = "https://github.com/sprites0/reth", rev = "d26fd2e25b57d695aa453c93f15a8cd158a1f505" }
reth-primitives-traits = { git = "https://github.com/sprites0/reth", rev = "d26fd2e25b57d695aa453c93f15a8cd158a1f505" }
reth-provider = { git = "https://github.com/sprites0/reth", rev = "d26fd2e25b57d695aa453c93f15a8cd158a1f505", features = ["test-utils"] }
reth-rpc = { git = "https://github.com/sprites0/reth", rev = "d26fd2e25b57d695aa453c93f15a8cd158a1f505" }
reth-rpc-eth-api = { git = "https://github.com/sprites0/reth", rev = "d26fd2e25b57d695aa453c93f15a8cd158a1f505" }
reth-rpc-engine-api = { git = "https://github.com/sprites0/reth", rev = "d26fd2e25b57d695aa453c93f15a8cd158a1f505" }
reth-tracing = { git = "https://github.com/sprites0/reth", rev = "d26fd2e25b57d695aa453c93f15a8cd158a1f505" }
reth-trie-common = { git = "https://github.com/sprites0/reth", rev = "d26fd2e25b57d695aa453c93f15a8cd158a1f505" }
reth-trie-db = { git = "https://github.com/sprites0/reth", rev = "d26fd2e25b57d695aa453c93f15a8cd158a1f505" }
reth-codecs = { git = "https://github.com/sprites0/reth", rev = "d26fd2e25b57d695aa453c93f15a8cd158a1f505" }
reth-transaction-pool = { git = "https://github.com/sprites0/reth", rev = "d26fd2e25b57d695aa453c93f15a8cd158a1f505" }
reth-stages-types = { git = "https://github.com/sprites0/reth", rev = "d26fd2e25b57d695aa453c93f15a8cd158a1f505" }
reth-storage-api = { git = "https://github.com/sprites0/reth", rev = "d26fd2e25b57d695aa453c93f15a8cd158a1f505" }
reth-errors = { git = "https://github.com/sprites0/reth", rev = "d26fd2e25b57d695aa453c93f15a8cd158a1f505" }
reth-rpc-convert = { git = "https://github.com/sprites0/reth", rev = "d26fd2e25b57d695aa453c93f15a8cd158a1f505" }
reth-rpc-eth-types = { git = "https://github.com/sprites0/reth", rev = "d26fd2e25b57d695aa453c93f15a8cd158a1f505" }
reth-rpc-server-types = { git = "https://github.com/sprites0/reth", rev = "d26fd2e25b57d695aa453c93f15a8cd158a1f505" }
reth-metrics = { git = "https://github.com/sprites0/reth", rev = "d26fd2e25b57d695aa453c93f15a8cd158a1f505" }
revm = { version = "29.0.0", default-features = false }
reth = { git = "https://github.com/hl-archive-node/reth", rev = "83baf84bcb6d88081fc1b39f97733b8ec345cb88" }
reth-cli = { git = "https://github.com/hl-archive-node/reth", rev = "83baf84bcb6d88081fc1b39f97733b8ec345cb88" }
reth-cli-commands = { git = "https://github.com/hl-archive-node/reth", rev = "83baf84bcb6d88081fc1b39f97733b8ec345cb88" }
reth-basic-payload-builder = { git = "https://github.com/hl-archive-node/reth", rev = "83baf84bcb6d88081fc1b39f97733b8ec345cb88" }
reth-db = { git = "https://github.com/hl-archive-node/reth", rev = "83baf84bcb6d88081fc1b39f97733b8ec345cb88" }
reth-db-api = { git = "https://github.com/hl-archive-node/reth", rev = "83baf84bcb6d88081fc1b39f97733b8ec345cb88" }
reth-chainspec = { git = "https://github.com/hl-archive-node/reth", rev = "83baf84bcb6d88081fc1b39f97733b8ec345cb88" }
reth-cli-util = { git = "https://github.com/hl-archive-node/reth", rev = "83baf84bcb6d88081fc1b39f97733b8ec345cb88" }
reth-discv4 = { git = "https://github.com/hl-archive-node/reth", rev = "83baf84bcb6d88081fc1b39f97733b8ec345cb88" }
reth-engine-primitives = { git = "https://github.com/hl-archive-node/reth", rev = "83baf84bcb6d88081fc1b39f97733b8ec345cb88" }
reth-ethereum-forks = { git = "https://github.com/hl-archive-node/reth", rev = "83baf84bcb6d88081fc1b39f97733b8ec345cb88" }
reth-ethereum-payload-builder = { git = "https://github.com/hl-archive-node/reth", rev = "83baf84bcb6d88081fc1b39f97733b8ec345cb88" }
reth-ethereum-primitives = { git = "https://github.com/hl-archive-node/reth", rev = "83baf84bcb6d88081fc1b39f97733b8ec345cb88" }
reth-eth-wire = { git = "https://github.com/hl-archive-node/reth", rev = "83baf84bcb6d88081fc1b39f97733b8ec345cb88" }
reth-eth-wire-types = { git = "https://github.com/hl-archive-node/reth", rev = "83baf84bcb6d88081fc1b39f97733b8ec345cb88" }
reth-evm = { git = "https://github.com/hl-archive-node/reth", rev = "83baf84bcb6d88081fc1b39f97733b8ec345cb88" }
reth-evm-ethereum = { git = "https://github.com/hl-archive-node/reth", rev = "83baf84bcb6d88081fc1b39f97733b8ec345cb88" }
reth-node-core = { git = "https://github.com/hl-archive-node/reth", rev = "83baf84bcb6d88081fc1b39f97733b8ec345cb88" }
reth-revm = { git = "https://github.com/hl-archive-node/reth", rev = "83baf84bcb6d88081fc1b39f97733b8ec345cb88" }
reth-network = { git = "https://github.com/hl-archive-node/reth", rev = "83baf84bcb6d88081fc1b39f97733b8ec345cb88" }
reth-network-p2p = { git = "https://github.com/hl-archive-node/reth", rev = "83baf84bcb6d88081fc1b39f97733b8ec345cb88" }
reth-network-api = { git = "https://github.com/hl-archive-node/reth", rev = "83baf84bcb6d88081fc1b39f97733b8ec345cb88" }
reth-node-ethereum = { git = "https://github.com/hl-archive-node/reth", rev = "83baf84bcb6d88081fc1b39f97733b8ec345cb88" }
reth-network-peers = { git = "https://github.com/hl-archive-node/reth", rev = "83baf84bcb6d88081fc1b39f97733b8ec345cb88" }
reth-payload-primitives = { git = "https://github.com/hl-archive-node/reth", rev = "83baf84bcb6d88081fc1b39f97733b8ec345cb88" }
reth-primitives = { git = "https://github.com/hl-archive-node/reth", rev = "83baf84bcb6d88081fc1b39f97733b8ec345cb88" }
reth-primitives-traits = { git = "https://github.com/hl-archive-node/reth", rev = "83baf84bcb6d88081fc1b39f97733b8ec345cb88" }
reth-provider = { git = "https://github.com/hl-archive-node/reth", rev = "83baf84bcb6d88081fc1b39f97733b8ec345cb88", features = ["test-utils"] }
reth-rpc = { git = "https://github.com/hl-archive-node/reth", rev = "83baf84bcb6d88081fc1b39f97733b8ec345cb88" }
reth-rpc-eth-api = { git = "https://github.com/hl-archive-node/reth", rev = "83baf84bcb6d88081fc1b39f97733b8ec345cb88" }
reth-rpc-engine-api = { git = "https://github.com/hl-archive-node/reth", rev = "83baf84bcb6d88081fc1b39f97733b8ec345cb88" }
reth-tracing = { git = "https://github.com/hl-archive-node/reth", rev = "83baf84bcb6d88081fc1b39f97733b8ec345cb88" }
reth-trie-common = { git = "https://github.com/hl-archive-node/reth", rev = "83baf84bcb6d88081fc1b39f97733b8ec345cb88" }
reth-trie-db = { git = "https://github.com/hl-archive-node/reth", rev = "83baf84bcb6d88081fc1b39f97733b8ec345cb88" }
reth-codecs = { git = "https://github.com/hl-archive-node/reth", rev = "83baf84bcb6d88081fc1b39f97733b8ec345cb88" }
reth-transaction-pool = { git = "https://github.com/hl-archive-node/reth", rev = "83baf84bcb6d88081fc1b39f97733b8ec345cb88" }
reth-stages-types = { git = "https://github.com/hl-archive-node/reth", rev = "83baf84bcb6d88081fc1b39f97733b8ec345cb88" }
reth-storage-api = { git = "https://github.com/hl-archive-node/reth", rev = "83baf84bcb6d88081fc1b39f97733b8ec345cb88" }
reth-errors = { git = "https://github.com/hl-archive-node/reth", rev = "83baf84bcb6d88081fc1b39f97733b8ec345cb88" }
reth-rpc-convert = { git = "https://github.com/hl-archive-node/reth", rev = "83baf84bcb6d88081fc1b39f97733b8ec345cb88" }
reth-rpc-eth-types = { git = "https://github.com/hl-archive-node/reth", rev = "83baf84bcb6d88081fc1b39f97733b8ec345cb88" }
reth-rpc-server-types = { git = "https://github.com/hl-archive-node/reth", rev = "83baf84bcb6d88081fc1b39f97733b8ec345cb88" }
reth-metrics = { git = "https://github.com/hl-archive-node/reth", rev = "83baf84bcb6d88081fc1b39f97733b8ec345cb88" }
revm = { version = "29.0.1", default-features = false }
# alloy dependencies
alloy-genesis = { version = "1.0.30", default-features = false }
alloy-consensus = { version = "1.0.30", default-features = false }
alloy-genesis = { version = "1.0.37", default-features = false }
alloy-consensus = { version = "1.0.37", default-features = false }
alloy-chains = { version = "0.2.5", default-features = false }
alloy-eips = { version = "1.0.30", default-features = false }
alloy-evm = { version = "0.20.1", default-features = false }
alloy-eips = { version = "1.0.37", default-features = false }
alloy-evm = { version = "0.21.0", default-features = false }
alloy-json-abi = { version = "1.3.1", default-features = false }
alloy-json-rpc = { version = "1.0.30", default-features = false }
alloy-json-rpc = { version = "1.0.37", default-features = false }
alloy-dyn-abi = "1.3.1"
alloy-network = { version = "1.0.30", default-features = false }
alloy-network = { version = "1.0.37", default-features = false }
alloy-primitives = { version = "1.3.1", default-features = false, features = ["map-foldhash"] }
alloy-rlp = { version = "0.3.10", default-features = false, features = ["core-net"] }
alloy-rpc-types = { version = "1.0.30", features = ["eth"], default-features = false }
alloy-rpc-types-eth = { version = "1.0.30", default-features = false }
alloy-rpc-types-engine = { version = "1.0.30", default-features = false }
alloy-signer = { version = "1.0.30", default-features = false }
alloy-rpc-types = { version = "1.0.37", features = ["eth"], default-features = false }
alloy-rpc-types-eth = { version = "1.0.37", default-features = false }
alloy-rpc-types-engine = { version = "1.0.37", default-features = false }
alloy-signer = { version = "1.0.37", default-features = false }
alloy-sol-macro = "1.3.1"
alloy-sol-types = { version = "1.3.1", default-features = false }

View File

@ -2,18 +2,18 @@ use alloy_eips::BlockId;
use alloy_json_rpc::RpcObject;
use alloy_primitives::{Bytes, U256};
use alloy_rpc_types_eth::{
state::{EvmOverrides, StateOverride},
BlockOverrides,
state::{EvmOverrides, StateOverride},
};
use jsonrpsee::{
http_client::{HttpClient, HttpClientBuilder},
proc_macros::rpc,
rpc_params,
types::{error::INTERNAL_ERROR_CODE, ErrorObject},
types::{ErrorObject, error::INTERNAL_ERROR_CODE},
};
use jsonrpsee_core::{async_trait, client::ClientT, ClientError, RpcResult};
use jsonrpsee_core::{ClientError, RpcResult, async_trait, client::ClientT};
use reth_rpc::eth::EthApiTypes;
use reth_rpc_eth_api::{helpers::EthCall, RpcTxReq};
use reth_rpc_eth_api::{RpcTxReq, helpers::EthCall};
#[rpc(server, namespace = "eth")]
pub(crate) trait CallForwarderApi<TxReq: RpcObject> {

View File

@ -7,34 +7,37 @@
//! For non-system transactions, we can just return the log as is, and the client will
//! adjust the transaction index accordingly.
use alloy_consensus::{transaction::TransactionMeta, BlockHeader, TxReceipt};
use alloy_consensus::{
BlockHeader, TxReceipt,
transaction::{TransactionMeta, TxHashRef},
};
use alloy_eips::{BlockId, BlockNumberOrTag};
use alloy_json_rpc::RpcObject;
use alloy_primitives::{B256, U256};
use alloy_rpc_types::{
pubsub::{Params, SubscriptionKind},
BlockTransactions, Filter, FilterChanges, FilterId, Log, PendingTransactionFilterKind,
TransactionInfo,
pubsub::{Params, SubscriptionKind},
};
use jsonrpsee::{proc_macros::rpc, PendingSubscriptionSink, SubscriptionMessage, SubscriptionSink};
use jsonrpsee_core::{async_trait, RpcResult};
use jsonrpsee_types::{error::INTERNAL_ERROR_CODE, ErrorObject};
use jsonrpsee::{PendingSubscriptionSink, SubscriptionMessage, SubscriptionSink, proc_macros::rpc};
use jsonrpsee_core::{RpcResult, async_trait};
use jsonrpsee_types::{ErrorObject, error::INTERNAL_ERROR_CODE};
use reth::{api::FullNodeComponents, builder::rpc::RpcContext, tasks::TaskSpawner};
use reth_primitives_traits::{BlockBody as _, SignedTransaction};
use reth_provider::{BlockIdReader, BlockReader, BlockReaderIdExt, ReceiptProvider};
use reth_rpc::{eth::pubsub::SubscriptionSerializeError, EthFilter, EthPubSub, RpcTypes};
use reth_rpc::{EthFilter, EthPubSub, RpcTypes, eth::pubsub::SubscriptionSerializeError};
use reth_rpc_eth_api::{
helpers::{EthBlocks, EthTransactions, LoadReceipt},
transaction::ConvertReceiptInput,
EthApiServer, EthApiTypes, EthFilterApiServer, EthPubSubApiServer, FullEthApiTypes, RpcBlock,
RpcConvert, RpcHeader, RpcNodeCoreExt, RpcReceipt, RpcTransaction, RpcTxReq,
helpers::{EthBlocks, EthTransactions, LoadReceipt},
transaction::ConvertReceiptInput,
};
use serde::Serialize;
use std::{borrow::Cow, marker::PhantomData, sync::Arc};
use std::{marker::PhantomData, sync::Arc};
use tokio_stream::{Stream, StreamExt};
use tracing::{trace, Instrument};
use tracing::{Instrument, trace};
use crate::{node::primitives::HlPrimitives, HlBlock};
use crate::{HlBlock, node::primitives::HlPrimitives};
pub trait EthWrapper:
EthApiServer<
@ -182,7 +185,7 @@ impl<Eth: EthWrapper> HlSystemTransactionExt<Eth> {
};
let input = ConvertReceiptInput {
receipt: Cow::Borrowed(receipt),
receipt: receipt.clone(),
tx,
gas_used: receipt.cumulative_gas_used() - gas_used,
next_log_index,
@ -530,7 +533,7 @@ async fn adjust_block_receipts<Eth: EthWrapper>(
};
let input = ConvertReceiptInput {
receipt: Cow::Borrowed(receipt),
receipt: receipt.clone(),
tx,
gas_used: receipt.cumulative_gas_used() - gas_used,
next_log_index,
@ -576,9 +579,8 @@ async fn adjust_transaction_receipt<Eth: EthWrapper>(
fn system_tx_count_for_block<Eth: EthWrapper>(eth_api: &Eth, block_id: BlockId) -> usize {
let provider = eth_api.provider();
let block = provider.block_by_id(block_id).unwrap().unwrap();
let system_tx_count =
block.body.transactions().iter().filter(|tx| tx.is_system_transaction()).count();
system_tx_count
block.body.transactions().iter().filter(|tx| tx.is_system_transaction()).count()
}
#[async_trait]

View File

@ -2,14 +2,14 @@ use std::time::Duration;
use alloy_json_rpc::RpcObject;
use alloy_network::Ethereum;
use alloy_primitives::{Bytes, B256};
use alloy_primitives::{B256, Bytes};
use alloy_rpc_types::TransactionRequest;
use jsonrpsee::{
http_client::{HttpClient, HttpClientBuilder},
proc_macros::rpc,
types::{error::INTERNAL_ERROR_CODE, ErrorObject},
types::{ErrorObject, error::INTERNAL_ERROR_CODE},
};
use jsonrpsee_core::{async_trait, client::ClientT, ClientError, RpcResult};
use jsonrpsee_core::{ClientError, RpcResult, async_trait, client::ClientT};
use reth::rpc::{result::internal_rpc_err, server_types::eth::EthApiError};
use reth_rpc_eth_api::RpcReceipt;

View File

@ -1,5 +1,5 @@
use alloy_chains::{Chain, NamedChain};
use alloy_primitives::{b256, Address, Bytes, B256, B64, U256};
use alloy_primitives::{Address, B64, B256, Bytes, U256, b256};
use reth_chainspec::{ChainHardforks, ChainSpec, EthereumHardfork, ForkCondition, Hardfork};
use reth_primitives::{Header, SealedHeader};
use std::sync::LazyLock;

View File

@ -1,4 +1,4 @@
use crate::chainspec::{hl::hl_testnet, HlChainSpec};
use crate::chainspec::{HlChainSpec, hl::hl_testnet};
use super::hl::hl_mainnet;
use reth_cli::chainspec::ChainSpecParser;

View File

@ -1,4 +1,4 @@
use alloy_primitives::{BlockNumber, B256};
use alloy_primitives::{B256, BlockNumber};
use reth_provider::{BlockNumReader, ProviderError};
use std::cmp::Ordering;

View File

@ -2,8 +2,8 @@ use super::HlEvmInner;
use crate::evm::{spec::HlSpecId, transaction::HlTxTr};
use reth_revm::context::ContextTr;
use revm::{
context::Cfg, context_interface::Block, handler::instructions::EthInstructions,
interpreter::interpreter::EthInterpreter, Context, Database,
Context, Database, context::Cfg, context_interface::Block,
handler::instructions::EthInstructions, interpreter::interpreter::EthInterpreter,
};
/// Trait that allows for hl HlEvm to be built.

View File

@ -1,8 +1,8 @@
use crate::evm::{spec::HlSpecId, transaction::HlTxEnv};
use revm::{
Context, Journal, MainContext,
context::{BlockEnv, CfgEnv, TxEnv},
database_interface::EmptyDB,
Context, Journal, MainContext,
};
/// Type alias for the default context type of the HlEvm.

View File

@ -1,16 +1,16 @@
use super::HlEvmInner;
use crate::evm::{spec::HlSpecId, transaction::HlTxTr};
use revm::{
context::{result::HaltReason, ContextSetters},
context_interface::{
result::{EVMError, ExecutionResult, ResultAndState},
Cfg, ContextTr, Database, JournalTr,
},
handler::{instructions::EthInstructions, PrecompileProvider},
inspector::{InspectCommitEvm, InspectEvm, Inspector, JournalExt},
interpreter::{interpreter::EthInterpreter, InterpreterResult},
state::EvmState,
DatabaseCommit, ExecuteCommitEvm, ExecuteEvm,
context::{ContextSetters, result::HaltReason},
context_interface::{
Cfg, ContextTr, Database, JournalTr,
result::{EVMError, ExecutionResult, ResultAndState},
},
handler::{PrecompileProvider, instructions::EthInstructions},
inspector::{InspectCommitEvm, InspectEvm, Inspector, JournalExt},
interpreter::{InterpreterResult, interpreter::EthInterpreter},
state::EvmState,
};
// Type alias for HL context

View File

@ -1,15 +1,15 @@
use revm::{
Inspector,
bytecode::opcode::BLOCKHASH,
context::{ContextSetters, Evm, FrameStack},
context_interface::ContextTr,
handler::{
EthFrame, EthPrecompiles, EvmTr, FrameInitOrResult, FrameTr, PrecompileProvider,
evm::{ContextDbError, FrameInitResult},
instructions::{EthInstructions, InstructionProvider},
EthFrame, EthPrecompiles, EvmTr, FrameInitOrResult, FrameTr, PrecompileProvider,
},
inspector::{InspectorEvmTr, JournalExt},
interpreter::{interpreter::EthInterpreter, Instruction, InterpreterResult},
Inspector,
interpreter::{Instruction, InterpreterResult, interpreter::EthInterpreter},
};
use crate::chainspec::MAINNET_CHAIN_ID;

View File

@ -7,8 +7,8 @@ use alloy_primitives::keccak256;
use revm::{
context::Host,
interpreter::{
as_u64_saturated, interpreter_types::StackTr, popn_top, InstructionContext,
InterpreterTypes,
InstructionContext, InterpreterTypes, as_u64_saturated, interpreter_types::StackTr,
popn_top,
},
primitives::{BLOCK_HASH_HISTORY, U256},
};

View File

@ -7,7 +7,7 @@ use reth_primitives_traits::SignerRecoverable;
use revm::{
context::TxEnv,
context_interface::transaction::Transaction,
primitives::{Address, Bytes, TxKind, B256, U256},
primitives::{Address, B256, Bytes, TxKind, U256},
};
#[auto_impl(&, &mut, Box, Arc)]

View File

@ -2,7 +2,7 @@
use alloy_chains::{Chain, NamedChain};
use core::any::Any;
use reth_chainspec::ForkCondition;
use reth_ethereum_forks::{hardfork, ChainHardforks, EthereumHardfork, Hardfork};
use reth_ethereum_forks::{ChainHardforks, EthereumHardfork, Hardfork, hardfork};
hardfork!(
/// The name of a hl hardfork.

View File

@ -9,11 +9,12 @@ use reth_hl::{
hl_node_compliance::install_hl_node_compliance,
tx_forwarder::{self, EthForwarderApiServer},
},
chainspec::{parser::HlChainSpecParser, HlChainSpec},
chainspec::{HlChainSpec, parser::HlChainSpecParser},
node::{
cli::{Cli, HlNodeArgs},
storage::tables::Tables,
HlNode,
cli::{Cli, HlNodeArgs},
rpc::precompile::{HlBlockPrecompileApiServer, HlBlockPrecompileExt},
storage::tables::Tables,
},
};
use tracing::info;
@ -26,11 +27,6 @@ static ALLOC: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;
fn main() -> eyre::Result<()> {
reth_cli_util::sigsegv_handler::install();
// Enable backtraces unless a RUST_BACKTRACE value has already been explicitly provided.
if std::env::var_os("RUST_BACKTRACE").is_none() {
std::env::set_var("RUST_BACKTRACE", "1");
}
// Initialize custom version metadata before parsing CLI so --version uses reth-hl values
reth_hl::version::init_reth_hl_version();
@ -39,7 +35,8 @@ fn main() -> eyre::Result<()> {
ext: HlNodeArgs| async move {
let default_upstream_rpc_url = builder.config().chain.official_rpc_url();
let (node, engine_handle_tx) = HlNode::new(ext.block_source_args.parse().await?);
let (node, engine_handle_tx) =
HlNode::new(ext.block_source_args.parse().await?, ext.debug_cutoff_height);
let NodeHandle { node, node_exit_future: exit_future } = builder
.node(node)
.extend_rpc_modules(move |mut ctx| {
@ -72,10 +69,14 @@ fn main() -> eyre::Result<()> {
info!("eth_getProof is disabled by default");
}
ctx.modules.merge_configured(
HlBlockPrecompileExt::new(ctx.registry.eth_api().clone()).into_rpc(),
)?;
Ok(())
})
.apply(|builder| {
builder.db().create_tables_for::<Tables>().expect("create tables");
.apply(|mut builder| {
builder.db_mut().create_tables_for::<Tables>().expect("create tables");
builder
})
.launch()

View File

@ -1,21 +1,21 @@
use crate::{
chainspec::{parser::HlChainSpecParser, HlChainSpec},
node::{consensus::HlConsensus, evm::config::HlEvmConfig, storage::tables::Tables, HlNode},
chainspec::{HlChainSpec, parser::HlChainSpecParser},
node::{HlNode, consensus::HlConsensus, evm::config::HlEvmConfig, storage::tables::Tables},
pseudo_peer::BlockSourceArgs,
};
use clap::{Args, Parser};
use reth::{
CliRunner,
args::LogArgs,
builder::{NodeBuilder, WithLaunchContext},
cli::Commands,
prometheus_exporter::install_prometheus_recorder,
version::version_metadata,
CliRunner,
};
use reth_chainspec::EthChainSpec;
use reth_cli::chainspec::ChainSpecParser;
use reth_cli_commands::{common::EnvironmentArgs, launcher::FnLauncher};
use reth_db::{init_db, mdbx::init_db_for, DatabaseEnv};
use reth_db::{DatabaseEnv, init_db, mdbx::init_db_for};
use reth_tracing::FileWorkerGuard;
use std::{
fmt::{self},
@ -35,6 +35,12 @@ pub struct HlNodeArgs {
#[command(flatten)]
pub block_source_args: BlockSourceArgs,
/// Debug cutoff height.
///
/// This option is used to cut off the block import at a specific height.
#[arg(long, env = "DEBUG_CUTOFF_HEIGHT")]
pub debug_cutoff_height: Option<u64>,
/// Upstream RPC URL to forward incoming transactions.
///
/// Default to Hyperliquid's RPC URL when not provided (https://rpc.hyperliquid.xyz/evm).
@ -130,8 +136,9 @@ where
// Install the prometheus recorder to be sure to record all metrics
let _ = install_prometheus_recorder();
let components =
|spec: Arc<C::ChainSpec>| (HlEvmConfig::new(spec.clone()), HlConsensus::new(spec));
let components = |spec: Arc<C::ChainSpec>| {
(HlEvmConfig::new(spec.clone()), Arc::new(HlConsensus::new(spec)))
};
match self.command {
Commands::Node(command) => runner.run_command_until_exit(|ctx| {
@ -151,9 +158,6 @@ where
runner.run_command_until_exit(|ctx| command.execute::<HlNode, _>(ctx, components))
}
Commands::Config(command) => runner.run_until_ctrl_c(command.execute()),
Commands::Recover(command) => {
runner.run_command_until_exit(|ctx| command.execute::<HlNode>(ctx))
}
Commands::Prune(command) => runner.run_until_ctrl_c(command.execute::<HlNode>()),
Commands::Import(command) => {
runner.run_blocking_until_ctrl_c(command.execute::<HlNode, _>(components))

View File

@ -1,9 +1,9 @@
use crate::{hardforks::HlHardforks, node::HlNode, HlBlock, HlBlockBody, HlPrimitives};
use crate::{HlBlock, HlBlockBody, HlPrimitives, hardforks::HlHardforks, node::HlNode};
use alloy_consensus::Header;
use reth::{
api::FullNodeTypes,
api::{FullNodeTypes, NodeTypes},
beacon_consensus::EthBeaconConsensus,
builder::{components::ConsensusBuilder, BuilderContext},
builder::{BuilderContext, components::ConsensusBuilder},
consensus::{Consensus, ConsensusError, FullConsensus, HeaderValidator},
consensus_common::validation::{
validate_against_parent_4844, validate_against_parent_hash_number,
@ -24,7 +24,7 @@ impl<Node> ConsensusBuilder<Node> for HlConsensusBuilder
where
Node: FullNodeTypes<Types = HlNode>,
{
type Consensus = Arc<dyn FullConsensus<HlPrimitives, Error = ConsensusError>>;
type Consensus = Arc<HlConsensus<<Node::Types as NodeTypes>::ChainSpec>>;
async fn build_consensus(self, ctx: &BuilderContext<Node>) -> eyre::Result<Self::Consensus> {
Ok(Arc::new(HlConsensus::new(ctx.chain_spec())))

View File

@ -1,11 +1,11 @@
//! Copy of reth codebase.
use alloy_consensus::{proofs::calculate_receipt_root, BlockHeader, TxReceipt};
use alloy_consensus::{BlockHeader, TxReceipt, proofs::calculate_receipt_root};
use alloy_eips::eip7685::Requests;
use alloy_primitives::{Bloom, B256};
use alloy_primitives::{B256, Bloom};
use reth::consensus::ConsensusError;
use reth_chainspec::EthereumHardforks;
use reth_primitives::{gas_spent_by_transactions, GotExpected, RecoveredBlock};
use reth_primitives::{GotExpected, RecoveredBlock, gas_spent_by_transactions};
use reth_primitives_traits::{Block, Receipt as ReceiptTrait};
pub fn validate_block_post_execution<B, R, ChainSpec>(

View File

@ -1,6 +1,6 @@
use crate::{
node::evm::config::{HlBlockExecutorFactory, HlEvmConfig},
HlBlock,
node::evm::config::{HlBlockExecutorFactory, HlEvmConfig},
};
use alloy_consensus::Header;
use reth_evm::{

View File

@ -1,5 +1,6 @@
use super::{executor::HlBlockExecutor, factory::HlEvmFactory};
use crate::{
HlBlock, HlBlockBody, HlPrimitives,
chainspec::HlChainSpec,
evm::{spec::HlSpecId, transaction::HlTxEnv},
hardforks::HlHardforks,
@ -9,31 +10,30 @@ use crate::{
rpc::engine_api::validator::HlExecutionData,
types::HlExtras,
},
HlBlock, HlBlockBody, HlPrimitives,
};
use alloy_consensus::{BlockHeader, Header, Transaction as _, TxReceipt, EMPTY_OMMER_ROOT_HASH};
use alloy_eips::{merge::BEACON_NONCE, Encodable2718};
use alloy_consensus::{BlockHeader, EMPTY_OMMER_ROOT_HASH, Header, Transaction as _, TxReceipt};
use alloy_eips::{Encodable2718, merge::BEACON_NONCE};
use alloy_primitives::{Log, U256};
use reth_chainspec::{EthChainSpec, EthereumHardforks, Hardforks};
use reth_evm::{
block::{BlockExecutionError, BlockExecutorFactory, BlockExecutorFor},
eth::{receipt_builder::ReceiptBuilder, EthBlockExecutionCtx},
execute::{BlockAssembler, BlockAssemblerInput},
precompiles::PrecompilesMap,
ConfigureEngineEvm, ConfigureEvm, EvmEnv, EvmEnvFor, EvmFactory, ExecutableTxIterator,
ExecutionCtxFor, FromRecoveredTx, FromTxWithEncoded, IntoTxEnv, NextBlockEnvAttributes,
block::{BlockExecutionError, BlockExecutorFactory, BlockExecutorFor},
eth::{EthBlockExecutionCtx, receipt_builder::ReceiptBuilder},
execute::{BlockAssembler, BlockAssemblerInput},
precompiles::PrecompilesMap,
};
use reth_evm_ethereum::EthBlockAssembler;
use reth_payload_primitives::NewPayloadError;
use reth_primitives::{logs_bloom, BlockTy, HeaderTy, Receipt, SealedBlock, SealedHeader};
use reth_primitives_traits::{proofs, SignerRecoverable, WithEncoded};
use reth_primitives::{BlockTy, HeaderTy, Receipt, SealedBlock, SealedHeader, logs_bloom};
use reth_primitives_traits::{SignerRecoverable, WithEncoded, proofs};
use reth_provider::BlockExecutionResult;
use reth_revm::State;
use revm::{
Inspector,
context::{BlockEnv, CfgEnv, TxEnv},
context_interface::block::BlobExcessGasAndPrice,
primitives::hardfork::SpecId,
Inspector,
};
use std::{borrow::Cow, convert::Infallible, sync::Arc};
@ -106,7 +106,10 @@ where
} else {
// for the first post-fork block, both parent.blob_gas_used and
// parent.excess_blob_gas are evaluated as 0
Some(alloy_eips::eip7840::BlobParams::cancun().next_block_excess_blob_gas(0, 0))
Some(
alloy_eips::eip7840::BlobParams::cancun()
.next_block_excess_blob_gas_osaka(0, 0, 0),
)
};
}
@ -284,7 +287,7 @@ where
self
}
fn evm_env(&self, header: &Header) -> EvmEnv<HlSpecId> {
fn evm_env(&self, header: &Header) -> Result<EvmEnv<HlSpecId>, Self::Error> {
let blob_params = self.chain_spec().blob_params_at_timestamp(header.timestamp);
let spec = revm_spec_by_timestamp_and_block_number(
self.chain_spec().clone(),
@ -324,7 +327,7 @@ where
blob_excess_gas_and_price,
};
EvmEnv { cfg_env, block_env }
Ok(EvmEnv { cfg_env, block_env })
}
fn next_evm_env(
@ -373,9 +376,9 @@ where
fn context_for_block<'a>(
&self,
block: &'a SealedBlock<BlockTy<Self::Primitives>>,
) -> ExecutionCtxFor<'a, Self> {
) -> Result<ExecutionCtxFor<'a, Self>, Self::Error> {
let block_body = block.body();
HlBlockExecutionCtx {
Ok(HlBlockExecutionCtx {
ctx: EthBlockExecutionCtx {
parent_hash: block.header().parent_hash,
parent_beacon_block_root: block.header().parent_beacon_block_root,
@ -386,15 +389,15 @@ where
read_precompile_calls: block_body.read_precompile_calls.clone(),
highest_precompile_address: block_body.highest_precompile_address,
},
}
})
}
fn context_for_next_block(
&self,
parent: &SealedHeader<HeaderTy<Self::Primitives>>,
attributes: Self::NextBlockEnvCtx,
) -> ExecutionCtxFor<'_, Self> {
HlBlockExecutionCtx {
) -> Result<ExecutionCtxFor<'_, Self>, Self::Error> {
Ok(HlBlockExecutionCtx {
ctx: EthBlockExecutionCtx {
parent_hash: parent.hash(),
parent_beacon_block_root: attributes.parent_beacon_block_root,
@ -402,13 +405,13 @@ where
withdrawals: attributes.withdrawals.map(Cow::Owned),
},
extras: HlExtras::default(), // TODO: hacky, double check if this is correct
}
})
}
}
impl ConfigureEngineEvm<HlExecutionData> for HlEvmConfig {
fn evm_env_for_payload(&self, payload: &HlExecutionData) -> EvmEnvFor<Self> {
self.evm_env(&payload.0.header)
self.evm_env(&payload.0.header).unwrap()
}
fn context_for_payload<'a>(&self, payload: &'a HlExecutionData) -> ExecutionCtxFor<'a, Self> {

View File

@ -8,29 +8,26 @@ use crate::{
},
};
use alloy_consensus::{Transaction, TxReceipt};
use alloy_eips::{eip7685::Requests, Encodable2718};
use alloy_eips::{Encodable2718, eip7685::Requests};
use alloy_evm::{block::ExecutableTx, eth::receipt_builder::ReceiptBuilderCtx};
use alloy_primitives::{address, hex, Address, Bytes, U160, U256};
use alloy_primitives::{Address, Bytes, U160, U256, address, hex};
use reth_chainspec::{EthChainSpec, EthereumHardforks, Hardforks};
use reth_evm::{
block::{BlockValidationError, CommitChanges},
Database, Evm, FromRecoveredTx, FromTxWithEncoded, IntoTxEnv, OnStateHook,
block::BlockValidationError,
eth::receipt_builder::ReceiptBuilder,
execute::{BlockExecutionError, BlockExecutor},
precompiles::{DynPrecompile, PrecompileInput, PrecompilesMap},
Database, Evm, FromRecoveredTx, FromTxWithEncoded, IntoTxEnv, OnStateHook,
};
use reth_provider::BlockExecutionResult;
use reth_revm::State;
use revm::{
context::{
result::{ExecutionResult, ResultAndState},
TxEnv,
},
DatabaseCommit,
context::{TxEnv, result::ResultAndState},
interpreter::instructions::utility::IntoU256,
precompile::{PrecompileError, PrecompileOutput, PrecompileResult},
primitives::HashMap,
state::Bytecode,
DatabaseCommit,
};
pub fn is_system_transaction(tx: &TransactionSigned) -> bool {
@ -110,7 +107,9 @@ where
const COREWRITER_ENABLED_BLOCK_NUMBER: u64 = 7578300;
const COREWRITER_CONTRACT_ADDRESS: Address =
address!("0x3333333333333333333333333333333333333333");
const COREWRITER_CODE: &[u8] = &hex!("608060405234801561000f575f5ffd5b5060043610610029575f3560e01c806317938e131461002d575b5f5ffd5b61004760048036038101906100429190610123565b610049565b005b5f5f90505b61019081101561006557808060010191505061004e565b503373ffffffffffffffffffffffffffffffffffffffff167f8c7f585fb295f7eb1e6aeb8fba61b23a4fe60beda405f0045073b185c74412e383836040516100ae9291906101c8565b60405180910390a25050565b5f5ffd5b5f5ffd5b5f5ffd5b5f5ffd5b5f5ffd5b5f5f83601f8401126100e3576100e26100c2565b5b8235905067ffffffffffffffff811115610100576100ff6100c6565b5b60208301915083600182028301111561011c5761011b6100ca565b5b9250929050565b5f5f60208385031215610139576101386100ba565b5b5f83013567ffffffffffffffff811115610156576101556100be565b5b610162858286016100ce565b92509250509250929050565b5f82825260208201905092915050565b828183375f83830152505050565b5f601f19601f8301169050919050565b5f6101a7838561016e565b93506101b483858461017e565b6101bd8361018c565b840190509392505050565b5f6020820190508181035f8301526101e181848661019c565b9050939250505056fea2646970667358221220f01517e1fbaff8af4bd72cb063cccecbacbb00b07354eea7dd52265d355474fb64736f6c634300081c0033");
const COREWRITER_CODE: &[u8] = &hex!(
"608060405234801561000f575f5ffd5b5060043610610029575f3560e01c806317938e131461002d575b5f5ffd5b61004760048036038101906100429190610123565b610049565b005b5f5f90505b61019081101561006557808060010191505061004e565b503373ffffffffffffffffffffffffffffffffffffffff167f8c7f585fb295f7eb1e6aeb8fba61b23a4fe60beda405f0045073b185c74412e383836040516100ae9291906101c8565b60405180910390a25050565b5f5ffd5b5f5ffd5b5f5ffd5b5f5ffd5b5f5ffd5b5f5f83601f8401126100e3576100e26100c2565b5b8235905067ffffffffffffffff811115610100576100ff6100c6565b5b60208301915083600182028301111561011c5761011b6100ca565b5b9250929050565b5f5f60208385031215610139576101386100ba565b5b5f83013567ffffffffffffffff811115610156576101556100be565b5b610162858286016100ce565b92509250509250929050565b5f82825260208201905092915050565b828183375f83830152505050565b5f601f19601f8301169050919050565b5f6101a7838561016e565b93506101b483858461017e565b6101bd8361018c565b840190509392505050565b5f6020820190508181035f8301526101e181848661019c565b9050939250505056fea2646970667358221220f01517e1fbaff8af4bd72cb063cccecbacbb00b07354eea7dd52265d355474fb64736f6c634300081c0033"
);
if self.evm.block().number != U256::from(COREWRITER_ENABLED_BLOCK_NUMBER) {
return Ok(());
@ -161,11 +160,10 @@ where
Ok(())
}
fn execute_transaction_with_commit_condition(
fn execute_transaction_without_commit(
&mut self,
tx: impl ExecutableTx<Self>,
f: impl FnOnce(&ExecutionResult<<Self::Evm as Evm>::HaltReason>) -> CommitChanges,
) -> Result<Option<u64>, BlockExecutionError> {
) -> Result<ResultAndState<<Self::Evm as Evm>::HaltReason>, BlockExecutionError> {
// The sum of the transaction's gas limit, Tg, and the gas utilized in this block prior,
// must be no greater than the block's gasLimit.
let block_available_gas = self.evm.block().gas_limit - self.gas_used;
@ -178,16 +176,20 @@ where
.into());
}
// Execute transaction.
let ResultAndState { result, mut state } = self
.evm
.transact(&tx)
.map_err(|err| BlockExecutionError::evm(err, tx.tx().trie_hash()))?;
if !f(&result).should_commit() {
return Ok(None);
// Execute transaction and return the result
self.evm.transact(&tx).map_err(|err| {
let hash = tx.tx().trie_hash();
BlockExecutionError::evm(err, hash)
})
}
fn commit_transaction(
&mut self,
output: ResultAndState<<Self::Evm as Evm>::HaltReason>,
tx: impl ExecutableTx<Self>,
) -> Result<u64, BlockExecutionError> {
let ResultAndState { result, mut state } = output;
let gas_used = result.gas_used();
// append gas used
@ -215,7 +217,7 @@ where
// Commit the state changes.
self.evm.db_mut().commit(state);
Ok(Some(gas_used))
Ok(gas_used)
}
fn finish(self) -> Result<(Self::Evm, BlockExecutionResult<R::Receipt>), BlockExecutionError> {

View File

@ -7,16 +7,16 @@ use crate::evm::{
spec::HlSpecId,
transaction::HlTxEnv,
};
use reth_evm::{precompiles::PrecompilesMap, Database, EvmEnv, EvmFactory};
use reth_evm::{Database, EvmEnv, EvmFactory, precompiles::PrecompilesMap};
use reth_revm::Context;
use revm::{
Inspector,
context::{
result::{EVMError, HaltReason},
TxEnv,
result::{EVMError, HaltReason},
},
inspector::NoOpInspector,
precompile::{PrecompileSpecId, Precompiles},
Inspector,
};
/// Factory producing [`HlEvm`].

View File

@ -1,6 +1,6 @@
use crate::{
evm::{
api::{ctx::HlContext, HlEvmInner},
api::{HlEvmInner, ctx::HlContext},
spec::HlSpecId,
transaction::HlTxEnv,
},
@ -10,18 +10,18 @@ use alloy_primitives::{Address, Bytes};
use config::HlEvmConfig;
use reth::{
api::FullNodeTypes,
builder::{components::ExecutorBuilder, BuilderContext},
builder::{BuilderContext, components::ExecutorBuilder},
};
use reth_evm::{Database, Evm, EvmEnv};
use revm::{
context::{
result::{EVMError, ExecutionResult, HaltReason, Output, ResultAndState, SuccessReason},
BlockEnv, TxEnv,
},
handler::{instructions::EthInstructions, EthPrecompiles, PrecompileProvider},
interpreter::{interpreter::EthInterpreter, InterpreterResult},
state::EvmState,
Context, ExecuteEvm, InspectEvm, Inspector,
context::{
BlockEnv, TxEnv,
result::{EVMError, ExecutionResult, HaltReason, Output, ResultAndState, SuccessReason},
},
handler::{EthPrecompiles, PrecompileProvider, instructions::EthInstructions},
interpreter::{InterpreterResult, interpreter::EthInterpreter},
state::EvmState,
};
use std::ops::{Deref, DerefMut};
@ -98,11 +98,7 @@ where
&mut self,
tx: Self::Tx,
) -> Result<ResultAndState<Self::HaltReason>, Self::Error> {
if self.inspect {
self.inner.inspect_tx(tx)
} else {
self.inner.transact(tx)
}
if self.inspect { self.inner.inspect_tx(tx) } else { self.inner.transact(tx) }
}
fn transact_system_call(

View File

@ -1,4 +1,4 @@
use alloy_primitives::{address, Address};
use alloy_primitives::{Address, address};
use reth_evm::block::BlockExecutionError;
use revm::{primitives::HashMap, state::Account};

View File

@ -4,11 +4,11 @@ use crate::{
pool::HlPoolBuilder,
primitives::{HlBlock, HlPrimitives},
rpc::{
HlEthApiBuilder,
engine_api::{
builder::HlEngineApiBuilder, payload::HlPayloadTypes,
validator::HlPayloadValidatorBuilder,
},
HlEthApiBuilder,
},
storage::HlStorage,
},
@ -20,14 +20,14 @@ use network::HlNetworkBuilder;
use reth::{
api::{FullNodeTypes, NodeTypes},
builder::{
Node, NodeAdapter,
components::{ComponentsBuilder, NoopPayloadServiceBuilder},
rpc::RpcAddOns,
Node, NodeAdapter,
},
};
use reth_engine_primitives::ConsensusEngineHandle;
use std::{marker::PhantomData, sync::Arc};
use tokio::sync::{oneshot, Mutex};
use tokio::sync::{Mutex, oneshot};
pub mod cli;
pub mod consensus;
@ -49,14 +49,23 @@ pub type HlNodeAddOns<N> =
pub struct HlNode {
engine_handle_rx: Arc<Mutex<Option<oneshot::Receiver<ConsensusEngineHandle<HlPayloadTypes>>>>>,
block_source_config: BlockSourceConfig,
debug_cutoff_height: Option<u64>,
}
impl HlNode {
pub fn new(
block_source_config: BlockSourceConfig,
debug_cutoff_height: Option<u64>,
) -> (Self, oneshot::Sender<ConsensusEngineHandle<HlPayloadTypes>>) {
let (tx, rx) = oneshot::channel();
(Self { engine_handle_rx: Arc::new(Mutex::new(Some(rx))), block_source_config }, tx)
(
Self {
engine_handle_rx: Arc::new(Mutex::new(Some(rx))),
block_source_config,
debug_cutoff_height,
},
tx,
)
}
}
@ -84,6 +93,7 @@ impl HlNode {
.network(HlNetworkBuilder {
engine_handle_rx: self.engine_handle_rx.clone(),
block_source_config: self.block_source_config.clone(),
debug_cutoff_height: self.debug_cutoff_height,
})
.consensus(HlConsensusBuilder::default())
}

View File

@ -8,7 +8,7 @@ use reth_primitives::NodePrimitives;
use service::{BlockMsg, ImportEvent, Outcome};
use std::{
fmt,
task::{ready, Context, Poll},
task::{Context, Poll, ready},
};
use crate::node::network::HlNewBlock;

View File

@ -1,17 +1,17 @@
use super::handle::ImportHandle;
use crate::{
HlBlock, HlBlockBody,
consensus::HlConsensus,
node::{
network::HlNewBlock,
rpc::engine_api::payload::HlPayloadTypes,
types::{BlockAndReceipts, EvmBlock},
},
HlBlock, HlBlockBody,
};
use alloy_consensus::{BlockBody, Header};
use alloy_primitives::U128;
use alloy_rpc_types::engine::{ForkchoiceState, PayloadStatusEnum};
use futures::{future::Either, stream::FuturesUnordered, StreamExt};
use futures::{StreamExt, future::Either, stream::FuturesUnordered};
use reth_engine_primitives::{ConsensusEngineHandle, EngineTypes};
use reth_eth_wire::NewBlock;
use reth_network::{

View File

@ -1,20 +1,20 @@
#![allow(clippy::owned_cow)]
use crate::{
HlBlock,
consensus::HlConsensus,
node::{
network::block_import::{handle::ImportHandle, service::ImportService, HlBlockImport},
HlNode,
network::block_import::{HlBlockImport, handle::ImportHandle, service::ImportService},
primitives::HlPrimitives,
rpc::engine_api::payload::HlPayloadTypes,
types::ReadPrecompileCalls,
HlNode,
},
pseudo_peer::{start_pseudo_peer, BlockSourceConfig},
HlBlock,
pseudo_peer::{BlockSourceConfig, start_pseudo_peer},
};
use alloy_rlp::{Decodable, Encodable};
use reth::{
api::{FullNodeTypes, TxTy},
builder::{components::NetworkBuilder, BuilderContext},
builder::{BuilderContext, components::NetworkBuilder},
transaction_pool::{PoolTransaction, TransactionPool},
};
use reth_discv4::NodeRecord;
@ -26,7 +26,7 @@ use reth_network_api::PeersInfo;
use reth_provider::StageCheckpointReader;
use reth_stages_types::StageId;
use std::sync::Arc;
use tokio::sync::{mpsc, oneshot, Mutex};
use tokio::sync::{Mutex, mpsc, oneshot};
use tracing::info;
pub mod block_import;
@ -38,8 +38,8 @@ pub struct HlNewBlock(pub NewBlock<HlBlock>);
mod rlp {
use super::*;
use crate::{
node::primitives::{BlockBody, TransactionSigned},
HlBlockBody,
node::primitives::{BlockBody, TransactionSigned},
};
use alloy_consensus::{BlobTransactionSidecar, Header};
use alloy_primitives::{Address, U128};
@ -142,6 +142,8 @@ pub struct HlNetworkBuilder {
Arc<Mutex<Option<oneshot::Receiver<ConsensusEngineHandle<HlPayloadTypes>>>>>,
pub(crate) block_source_config: BlockSourceConfig,
pub(crate) debug_cutoff_height: Option<u64>,
}
impl HlNetworkBuilder {
@ -203,6 +205,7 @@ where
pool: Pool,
) -> eyre::Result<Self::Network> {
let block_source_config = self.block_source_config.clone();
let debug_cutoff_height = self.debug_cutoff_height;
let handle =
ctx.start_network(NetworkManager::builder(self.network_config(ctx)?).await?, pool);
let local_node_record = handle.local_node_record();
@ -223,6 +226,7 @@ where
block_source_config
.create_cached_block_source((*chain_spec).clone(), next_block_number)
.await,
debug_cutoff_height,
)
.await
.unwrap();

View File

@ -6,12 +6,12 @@
//! Ethereum transaction pool only supports TransactionSigned (EthereumTxEnvelope<TxEip4844>),
//! hence this placeholder for the transaction pool.
use crate::node::{primitives::TransactionSigned, HlNode};
use crate::node::{HlNode, primitives::TransactionSigned};
use alloy_consensus::{
error::ValueError, EthereumTxEnvelope, Transaction as TransactionTrait, TxEip4844,
EthereumTxEnvelope, Transaction as TransactionTrait, TxEip4844, error::ValueError,
};
use alloy_eips::{eip7702::SignedAuthorization, Typed2718};
use alloy_primitives::{Address, Bytes, ChainId, TxHash, TxKind, B256, U256};
use alloy_eips::{Typed2718, eip7702::SignedAuthorization};
use alloy_primitives::{Address, B256, Bytes, ChainId, TxHash, TxKind, U256};
use alloy_rpc_types::AccessList;
use reth::{
api::FullNodeTypes, builder::components::PoolBuilder, transaction_pool::PoolTransaction,
@ -19,7 +19,7 @@ use reth::{
use reth_ethereum_primitives::PooledTransactionVariant;
use reth_primitives::Recovered;
use reth_primitives_traits::InMemorySize;
use reth_transaction_pool::{noop::NoopTransactionPool, EthPoolTransaction};
use reth_transaction_pool::{EthPoolTransaction, noop::NoopTransactionPool};
use std::sync::Arc;
pub struct HlPoolBuilder;

View File

@ -1,30 +1,32 @@
//! HlNodePrimitives::TransactionSigned; it's the same as ethereum transaction type,
//! except that it supports pseudo signer for system transactions.
use std::convert::Infallible;
use crate::evm::transaction::HlTxEnv;
use alloy_consensus::{
crypto::RecoveryError, error::ValueError, SignableTransaction, Signed,
Transaction as TransactionTrait, TransactionEnvelope, TxEip1559, TxEip2930, TxEip4844,
TxEip7702, TxLegacy, TxType, TypedTransaction,
SignableTransaction, Signed, Transaction as TransactionTrait, TransactionEnvelope, TxEip1559,
TxEip2930, TxEip4844, TxEip7702, TxLegacy, TxType, TypedTransaction, crypto::RecoveryError,
error::ValueError, transaction::TxHashRef,
};
use alloy_eips::Encodable2718;
use alloy_network::TxSigner;
use alloy_primitives::{address, Address, TxHash, U256};
use alloy_primitives::{Address, TxHash, U256, address};
use alloy_rpc_types::{Transaction, TransactionInfo, TransactionRequest};
use alloy_signer::Signature;
use reth_codecs::alloy::transaction::{Envelope, FromTxCompact};
use reth_db::{
table::{Compress, Decompress},
DatabaseError,
table::{Compress, Decompress},
};
use reth_ethereum_primitives::PooledTransactionVariant;
use reth_evm::FromRecoveredTx;
use reth_primitives::Recovered;
use reth_primitives_traits::{
serde_bincode_compat::SerdeBincodeCompat, InMemorySize, SignedTransaction, SignerRecoverable,
InMemorySize, SignedTransaction, SignerRecoverable, serde_bincode_compat::SerdeBincodeCompat,
};
use reth_rpc_eth_api::{
transaction::{FromConsensusTx, TryIntoTxEnv},
EthTxEnvError, SignTxRequestError, SignableTxRequest, TryIntoSimTx,
transaction::{FromConsensusTx, TryIntoTxEnv},
};
use revm::context::{BlockEnv, CfgEnv, TxEnv};
@ -46,6 +48,12 @@ fn s_to_address(s: U256) -> Address {
Address::from_slice(&buf)
}
impl TxHashRef for TransactionSigned {
fn tx_hash(&self) -> &TxHash {
self.inner().tx_hash()
}
}
impl SignerRecoverable for TransactionSigned {
fn recover_signer(&self) -> Result<Address, RecoveryError> {
if self.is_system_transaction() {
@ -69,11 +77,7 @@ impl SignerRecoverable for TransactionSigned {
}
}
impl SignedTransaction for TransactionSigned {
fn tx_hash(&self) -> &TxHash {
self.inner().tx_hash()
}
}
impl SignedTransaction for TransactionSigned {}
// ------------------------------------------------------------
// NOTE: All lines below are just wrappers for the inner type.
@ -250,9 +254,17 @@ impl TryIntoTxEnv<HlTxEnv<TxEnv>> for TransactionRequest {
impl FromConsensusTx<TransactionSigned> for Transaction {
type TxInfo = TransactionInfo;
type Err = Infallible;
fn from_consensus_tx(tx: TransactionSigned, signer: Address, tx_info: Self::TxInfo) -> Self {
Self::from_transaction(Recovered::new_unchecked(tx.into_inner().into(), signer), tx_info)
fn from_consensus_tx(
tx: TransactionSigned,
signer: Address,
tx_info: Self::TxInfo,
) -> Result<Self, Self::Err> {
Ok(Self::from_transaction(
Recovered::new_unchecked(tx.into_inner().into(), signer),
tx_info,
))
}
}

View File

@ -1,12 +1,12 @@
use crate::node::rpc::{HlEthApi, HlRpcNodeCore};
use reth::rpc::server_types::eth::{
builder::config::PendingBlockKind, error::FromEvmError, EthApiError, PendingBlock,
EthApiError, PendingBlock, builder::config::PendingBlockKind, error::FromEvmError,
};
use reth_rpc_eth_api::{
helpers::{
pending_block::PendingEnvBuilder, EthBlocks, LoadBlock, LoadPendingBlock, LoadReceipt,
},
RpcConvert,
helpers::{
EthBlocks, LoadBlock, LoadPendingBlock, LoadReceipt, pending_block::PendingEnvBuilder,
},
};
impl<N, Rpc> EthBlocks for HlEthApi<N, Rpc>
@ -29,7 +29,7 @@ impl<N, Rpc> LoadPendingBlock for HlEthApi<N, Rpc>
where
N: HlRpcNodeCore,
EthApiError: FromEvmError<N::Evm>,
Rpc: RpcConvert<Primitives = N::Primitives, Error = EthApiError>,
Rpc: RpcConvert<Primitives = N::Primitives>,
{
#[inline]
fn pending_block(&self) -> &tokio::sync::Mutex<Option<PendingBlock<N::Primitives>>> {
@ -50,7 +50,6 @@ where
impl<N, Rpc> LoadReceipt for HlEthApi<N, Rpc>
where
N: HlRpcNodeCore,
EthApiError: FromEvmError<N::Evm>,
Rpc: RpcConvert<Primitives = N::Primitives, Error = EthApiError>,
{
}

View File

@ -1,19 +1,19 @@
use core::fmt;
use super::{HlEthApi, HlRpcNodeCore};
use crate::{node::evm::apply_precompiles, HlBlock};
use crate::{HlBlock, node::evm::apply_precompiles};
use alloy_consensus::transaction::TxHashRef;
use alloy_evm::Evm;
use alloy_primitives::B256;
use reth::rpc::server_types::eth::EthApiError;
use reth_evm::{ConfigureEvm, Database, EvmEnvFor, HaltReasonFor, InspectorFor, SpecFor, TxEnvFor};
use reth_primitives::{NodePrimitives, Recovered};
use reth_primitives_traits::SignedTransaction;
use reth_provider::{ProviderError, ProviderTx};
use reth_rpc_eth_api::{
helpers::{Call, EthCall},
FromEvmError, RpcConvert, RpcNodeCore,
helpers::{Call, EthCall},
};
use revm::{context::result::ResultAndState, DatabaseCommit};
use revm::{DatabaseCommit, context::result::ResultAndState};
impl<N> HlRpcNodeCore for N where N: RpcNodeCore<Primitives: NodePrimitives<Block = HlBlock>> {}
@ -61,7 +61,7 @@ where
DB: Database<Error = ProviderError> + fmt::Debug,
{
let block_number = evm_env.block_env().number;
let hl_extras = self.get_hl_extras(block_number.try_into().unwrap())?;
let hl_extras = self.get_hl_extras(block_number.to::<u64>().into())?;
let mut evm = self.evm_config().evm_with_env(db, evm_env);
apply_precompiles(&mut evm, &hl_extras);
@ -82,7 +82,7 @@ where
I: InspectorFor<Self::Evm, DB>,
{
let block_number = evm_env.block_env().number;
let hl_extras = self.get_hl_extras(block_number.try_into().unwrap())?;
let hl_extras = self.get_hl_extras(block_number.to::<u64>().into())?;
let mut evm = self.evm_config().evm_with_env_and_inspector(db, evm_env, inspector);
apply_precompiles(&mut evm, &hl_extras);
@ -103,7 +103,7 @@ where
I: IntoIterator<Item = Recovered<&'a ProviderTx<Self::Provider>>>,
{
let block_number = evm_env.block_env().number;
let hl_extras = self.get_hl_extras(block_number.try_into().unwrap())?;
let hl_extras = self.get_hl_extras(block_number.to::<u64>().into())?;
let mut evm = self.evm_config().evm_with_env(db, evm_env);
apply_precompiles(&mut evm, &hl_extras);

View File

@ -9,7 +9,7 @@ use alloy_primitives::B256;
use alloy_rpc_types_engine::PayloadError;
use reth::{
api::{FullNodeComponents, NodeTypes},
builder::{rpc::PayloadValidatorBuilder, AddOnsContext},
builder::{AddOnsContext, rpc::PayloadValidatorBuilder},
};
use reth_engine_primitives::{ExecutionPayload, PayloadValidator};
use reth_payload_primitives::NewPayloadError;

View File

@ -1,5 +1,5 @@
use super::{apply_precompiles, HlEthApi, HlRpcNodeCore};
use alloy_evm::overrides::{apply_state_overrides, StateOverrideError};
use super::{HlEthApi, HlRpcNodeCore, apply_precompiles};
use alloy_evm::overrides::{StateOverrideError, apply_state_overrides};
use alloy_network::TransactionBuilder;
use alloy_primitives::{TxKind, U256};
use alloy_rpc_types_eth::state::StateOverride;
@ -9,19 +9,19 @@ use reth_evm::{ConfigureEvm, Evm, EvmEnvFor, SpecFor, TransactionEnv, TxEnvFor};
use reth_revm::{database::StateProviderDatabase, db::CacheDB};
use reth_rpc_convert::{RpcConvert, RpcTxReq};
use reth_rpc_eth_api::{
helpers::{
estimate::{update_estimated_gas_range, EstimateCall},
Call,
},
AsEthApiError, IntoEthApiError, RpcNodeCore,
helpers::{
Call,
estimate::{EstimateCall, update_estimated_gas_range},
},
};
use reth_rpc_eth_types::{
error::{api::FromEvmHalt, FromEvmError},
EthApiError, RevertError, RpcInvalidTransactionError,
error::{FromEvmError, api::FromEvmHalt},
};
use reth_rpc_server_types::constants::gas_oracle::{CALL_STIPEND_GAS, ESTIMATE_GAS_ERROR_RATIO};
use reth_storage_api::StateProvider;
use revm::context_interface::{result::ExecutionResult, Transaction};
use revm::context_interface::{Transaction, result::ExecutionResult};
use tracing::trace;
impl<N, Rpc> EstimateCall for HlEthApi<N, Rpc>
@ -82,13 +82,12 @@ where
let mut tx_env = self.create_txn_env(&evm_env, request, &mut db)?;
let mut is_basic_transfer = false;
if tx_env.input().is_empty() {
if let TxKind::Call(to) = tx_env.kind() {
if let Ok(code) = db.db.account_code(&to) {
if tx_env.input().is_empty() &&
let TxKind::Call(to) = tx_env.kind() &&
let Ok(code) = db.db.account_code(&to)
{
is_basic_transfer = code.map(|code| code.is_empty()).unwrap_or(true);
}
}
}
if tx_env.gas_price() > 0 {
highest_gas_limit =
@ -98,7 +97,7 @@ where
tx_env.set_gas_limit(tx_env.gas_limit().min(highest_gas_limit));
let block_number = evm_env.block_env().number;
let hl_extras = self.get_hl_extras(block_number.try_into().unwrap())?;
let hl_extras = self.get_hl_extras(block_number.to::<u64>().into())?;
let mut evm = self.evm_config().evm_with_env(&mut db, evm_env);
apply_precompiles(&mut evm, &hl_extras);
@ -107,12 +106,12 @@ where
let mut min_tx_env = tx_env.clone();
min_tx_env.set_gas_limit(MIN_TRANSACTION_GAS);
if let Ok(res) = evm.transact(min_tx_env).map_err(Self::Error::from_evm_err) {
if res.result.is_success() {
if let Ok(res) = evm.transact(min_tx_env).map_err(Self::Error::from_evm_err) &&
res.result.is_success()
{
return Ok(U256::from(MIN_TRANSACTION_GAS));
}
}
}
trace!(target: "rpc::eth::estimate", ?tx_env, gas_limit = tx_env.gas_limit(), is_basic_transfer, "Starting gas estimation");

View File

@ -1,40 +1,43 @@
use crate::{
HlBlock, HlPrimitives,
chainspec::HlChainSpec,
node::{evm::apply_precompiles, types::HlExtras},
HlBlock, HlPrimitives,
};
use alloy_eips::BlockId;
use alloy_evm::Evm;
use alloy_network::Ethereum;
use alloy_primitives::U256;
use reth::{
api::{FullNodeTypes, HeaderTy, NodeTypes, PrimitivesTy},
builder::{
rpc::{EthApiBuilder, EthApiCtx},
FullNodeComponents,
rpc::{EthApiBuilder, EthApiCtx},
},
rpc::{
eth::{core::EthApiInner, DevSigner, FullEthApiServer},
eth::{DevSigner, FullEthApiServer, core::EthApiInner},
server_types::eth::{
receipt::EthReceiptConverter, EthApiError, EthStateCache, FeeHistoryCache,
GasPriceOracle,
EthApiError, EthStateCache, FeeHistoryCache, GasPriceOracle,
receipt::EthReceiptConverter,
},
},
tasks::{
pool::{BlockingTaskGuard, BlockingTaskPool},
TaskSpawner,
pool::{BlockingTaskGuard, BlockingTaskPool},
},
};
use reth_evm::{ConfigureEvm, Database, EvmEnvFor, HaltReasonFor, InspectorFor, TxEnvFor};
use reth_primitives::NodePrimitives;
use reth_provider::{BlockReader, ChainSpecProvider, ProviderError, ProviderHeader, ProviderTx};
use reth_provider::{
BlockReaderIdExt, ChainSpecProvider, ProviderError, ProviderHeader, ProviderTx,
};
use reth_rpc::RpcTypes;
use reth_rpc_eth_api::{
helpers::{
pending_block::BuildPendingEnv, spec::SignersForApi, AddDevSigners, EthApiSpec, EthFees,
EthState, LoadFee, LoadPendingBlock, LoadState, SpawnBlocking, Trace,
},
EthApiTypes, FromEvmError, RpcConvert, RpcConverter, RpcNodeCore, RpcNodeCoreExt,
SignableTxRequest,
helpers::{
AddDevSigners, EthApiSpec, EthFees, EthState, LoadFee, LoadPendingBlock, LoadState,
SpawnBlocking, Trace, pending_block::BuildPendingEnv, spec::SignersForApi,
},
};
use revm::context::result::ResultAndState;
use std::{fmt, marker::PhantomData, sync::Arc};
@ -43,6 +46,7 @@ mod block;
mod call;
pub mod engine_api;
mod estimate;
pub mod precompile;
mod transaction;
pub trait HlRpcNodeCore: RpcNodeCore<Primitives: NodePrimitives<Block = HlBlock>> {}
@ -56,12 +60,17 @@ pub(crate) struct HlEthApiInner<N: HlRpcNodeCore, Rpc: RpcConvert> {
type HlRpcConvert<N, NetworkT> =
RpcConverter<NetworkT, <N as FullNodeComponents>::Evm, EthReceiptConverter<HlChainSpec>>;
#[derive(Clone)]
pub struct HlEthApi<N: HlRpcNodeCore, Rpc: RpcConvert> {
/// Gateway to node's core components.
pub(crate) inner: Arc<HlEthApiInner<N, Rpc>>,
}
impl<N: HlRpcNodeCore, Rpc: RpcConvert> Clone for HlEthApi<N, Rpc> {
fn clone(&self) -> Self {
Self { inner: self.inner.clone() }
}
}
impl<N, Rpc> fmt::Debug for HlEthApi<N, Rpc>
where
N: HlRpcNodeCore,
@ -75,7 +84,7 @@ where
impl<N, Rpc> EthApiTypes for HlEthApi<N, Rpc>
where
N: HlRpcNodeCore,
Rpc: RpcConvert<Primitives = N::Primitives, Error = EthApiError>,
Rpc: RpcConvert<Primitives = N::Primitives>,
{
type Error = EthApiError;
type NetworkTypes = Rpc::Network;
@ -151,7 +160,7 @@ where
impl<N, Rpc> SpawnBlocking for HlEthApi<N, Rpc>
where
N: HlRpcNodeCore,
Rpc: RpcConvert<Primitives = N::Primitives, Error = EthApiError>,
Rpc: RpcConvert<Primitives = N::Primitives>,
{
#[inline]
fn io_task_spawner(&self) -> impl TaskSpawner {
@ -232,7 +241,7 @@ where
I: InspectorFor<Self::Evm, DB>,
{
let block_number = evm_env.block_env().number;
let hl_extras = self.get_hl_extras(block_number.try_into().unwrap())?;
let hl_extras = self.get_hl_extras(block_number.to::<u64>().into())?;
let mut evm = self.evm_config().evm_with_env_and_inspector(db, evm_env, inspector);
apply_precompiles(&mut evm, &hl_extras);
@ -245,10 +254,10 @@ where
N: HlRpcNodeCore,
Rpc: RpcConvert<Primitives = N::Primitives, Error = EthApiError>,
{
fn get_hl_extras(&self, block_number: u64) -> Result<HlExtras, ProviderError> {
fn get_hl_extras(&self, block: BlockId) -> Result<HlExtras, ProviderError> {
Ok(self
.provider()
.block_by_number(block_number)?
.block_by_id(block)?
.map(|block| HlExtras {
read_precompile_calls: block.body.read_precompile_calls.clone(),
highest_precompile_address: block.body.highest_precompile_address,

View File

@ -0,0 +1,44 @@
use alloy_eips::BlockId;
use jsonrpsee::proc_macros::rpc;
use jsonrpsee_core::{RpcResult, async_trait};
use reth_rpc_convert::RpcConvert;
use reth_rpc_eth_types::EthApiError;
use tracing::trace;
use crate::node::{
rpc::{HlEthApi, HlRpcNodeCore},
types::HlExtras,
};
/// A custom RPC trait for fetching block precompile data.
#[rpc(server, namespace = "eth")]
#[async_trait]
pub trait HlBlockPrecompileApi {
/// Fetches precompile data for a given block.
#[method(name = "blockPrecompileData")]
async fn block_precompile_data(&self, block: BlockId) -> RpcResult<HlExtras>;
}
pub struct HlBlockPrecompileExt<N: HlRpcNodeCore, Rpc: RpcConvert> {
eth_api: HlEthApi<N, Rpc>,
}
impl<N: HlRpcNodeCore, Rpc: RpcConvert> HlBlockPrecompileExt<N, Rpc> {
/// Creates a new instance of the [`HlBlockPrecompileExt`].
pub fn new(eth_api: HlEthApi<N, Rpc>) -> Self {
Self { eth_api }
}
}
#[async_trait]
impl<N, Rpc> HlBlockPrecompileApiServer for HlBlockPrecompileExt<N, Rpc>
where
N: HlRpcNodeCore,
Rpc: RpcConvert<Primitives = N::Primitives, Error = EthApiError>,
{
async fn block_precompile_data(&self, block: BlockId) -> RpcResult<HlExtras> {
trace!(target: "rpc::eth", ?block, "Serving eth_blockPrecompileData");
let hl_extras = self.eth_api.get_hl_extras(block).map_err(EthApiError::from)?;
Ok(hl_extras)
}
}

View File

@ -1,9 +1,11 @@
use std::time::Duration;
use crate::node::rpc::{HlEthApi, HlRpcNodeCore};
use alloy_primitives::{Bytes, B256};
use alloy_primitives::{B256, Bytes};
use reth::rpc::server_types::eth::EthApiError;
use reth_rpc_eth_api::{
helpers::{spec::SignersForRpc, EthTransactions, LoadTransaction},
RpcConvert,
helpers::{EthTransactions, LoadTransaction, spec::SignersForRpc},
};
impl<N, Rpc> LoadTransaction for HlEthApi<N, Rpc>
@ -25,4 +27,8 @@ where
async fn send_raw_transaction(&self, _tx: Bytes) -> Result<B256, Self::Error> {
unreachable!()
}
fn send_raw_transaction_sync_timeout(&self) -> Duration {
self.inner.eth_api.send_raw_transaction_sync_timeout()
}
}

View File

@ -1,5 +1,5 @@
use crate::node::spot_meta::SpotId;
use alloy_primitives::{address, Address};
use alloy_primitives::{Address, address};
use std::collections::BTreeMap;
/// Testnet-specific fix for #67

View File

@ -1,22 +1,22 @@
use crate::{
HlBlock, HlBlockBody, HlPrimitives,
node::{
primitives::tx_wrapper::{convert_to_eth_block_body, convert_to_hl_block_body},
types::HlExtras,
},
HlBlock, HlBlockBody, HlPrimitives,
};
use alloy_consensus::BlockHeader;
use alloy_primitives::Bytes;
use reth_chainspec::EthereumHardforks;
use reth_db::{
DbTxUnwindExt,
cursor::{DbCursorRO, DbCursorRW},
transaction::{DbTx, DbTxMut},
DbTxUnwindExt,
};
use reth_provider::{
providers::{ChainStorage, NodeTypesForProvider},
BlockBodyReader, BlockBodyWriter, ChainSpecProvider, ChainStorageReader, ChainStorageWriter,
DBProvider, DatabaseProvider, EthStorage, ProviderResult, ReadBodyInput, StorageLocation,
providers::{ChainStorage, NodeTypesForProvider},
};
pub mod tables;

View File

@ -1,5 +1,5 @@
use alloy_primitives::{BlockNumber, Bytes};
use reth_db::{table::TableInfo, tables, TableSet, TableType, TableViewer};
use reth_db::{TableSet, TableType, TableViewer, table::TableInfo, tables};
use std::fmt;
tables! {

View File

@ -2,7 +2,7 @@
//!
//! Changes:
//! - ReadPrecompileCalls supports RLP encoding / decoding
use alloy_primitives::{Address, Bytes, Log, B256};
use alloy_primitives::{Address, B256, Bytes, Log};
use alloy_rlp::{Decodable, Encodable, RlpDecodable, RlpEncodable};
use bytes::BufMut;
use serde::{Deserialize, Serialize};

View File

@ -10,12 +10,12 @@ use std::{
use tracing::info;
use crate::{
HlBlock, HlBlockBody,
node::{
primitives::TransactionSigned as TxSigned,
spot_meta::{erc20_contract_to_spot_token, SpotId},
spot_meta::{SpotId, erc20_contract_to_spot_token},
types::{ReadPrecompileCalls, SystemTx},
},
HlBlock, HlBlockBody,
};
/// A raw transaction.

View File

@ -46,7 +46,7 @@ impl BlockSourceConfig {
.expect("home dir not found")
.join("hl")
.join("data")
.join("evm_blocks_and_receipts"),
.join("evm_block_and_receipts"),
},
block_source_from_node: None,
}

View File

@ -37,6 +37,7 @@ pub async fn start_pseudo_peer(
chain_spec: Arc<HlChainSpec>,
destination_peer: String,
block_source: BlockSourceBoxed,
debug_cutoff_height: Option<u64>,
) -> eyre::Result<()> {
let blockhash_cache = new_blockhash_cache();
@ -46,6 +47,7 @@ pub async fn start_pseudo_peer(
destination_peer,
block_source.clone(),
blockhash_cache.clone(),
debug_cutoff_height,
)
.await?;

View File

@ -1,8 +1,8 @@
use super::service::{BlockHashCache, BlockPoller};
use crate::{chainspec::HlChainSpec, node::network::HlNetworkPrimitives, HlPrimitives};
use crate::{HlPrimitives, chainspec::HlChainSpec, node::network::HlNetworkPrimitives};
use reth_network::{
config::{rng_secret_key, SecretKey},
NetworkConfig, NetworkManager, PeersConfig,
config::{SecretKey, rng_secret_key},
};
use reth_network_peers::TrustedPeer;
use reth_provider::test_utils::NoopProvider;
@ -20,6 +20,7 @@ pub struct NetworkBuilder {
discovery_port: u16,
listener_port: u16,
chain_spec: HlChainSpec,
debug_cutoff_height: Option<u64>,
}
impl Default for NetworkBuilder {
@ -31,6 +32,7 @@ impl Default for NetworkBuilder {
discovery_port: 0,
listener_port: 0,
chain_spec: HlChainSpec::default(),
debug_cutoff_height: None,
}
}
}
@ -46,6 +48,11 @@ impl NetworkBuilder {
self
}
pub fn with_debug_cutoff_height(mut self, debug_cutoff_height: Option<u64>) -> Self {
self.debug_cutoff_height = debug_cutoff_height;
self
}
pub async fn build<BS>(
self,
block_source: Arc<Box<dyn super::sources::BlockSource>>,
@ -58,8 +65,12 @@ impl NetworkBuilder {
.listener_addr(SocketAddr::new(Ipv4Addr::LOCALHOST.into(), self.listener_port));
let chain_id = self.chain_spec.inner.chain().id();
let (block_poller, start_tx) =
BlockPoller::new_suspended(chain_id, block_source, blockhash_cache);
let (block_poller, start_tx) = BlockPoller::new_suspended(
chain_id,
block_source,
blockhash_cache,
self.debug_cutoff_height,
);
let config = builder.block_import(Box::new(block_poller)).build(Arc::new(NoopProvider::<
HlChainSpec,
HlPrimitives,
@ -77,10 +88,12 @@ pub async fn create_network_manager<BS>(
destination_peer: String,
block_source: Arc<Box<dyn super::sources::BlockSource>>,
blockhash_cache: BlockHashCache,
debug_cutoff_height: Option<u64>,
) -> eyre::Result<(NetworkManager<HlNetworkPrimitives>, mpsc::Sender<()>)> {
NetworkBuilder::default()
.with_boot_nodes(vec![TrustedPeer::from_str(&destination_peer).unwrap()])
.with_chain_spec(chain_spec)
.with_debug_cutoff_height(debug_cutoff_height)
.build::<BS>(block_source, blockhash_cache)
.await
}

View File

@ -52,12 +52,12 @@ impl BlockPoller {
chain_id: u64,
block_source: BS,
blockhash_cache: BlockHashCache,
debug_cutoff_height: Option<u64>,
) -> (Self, mpsc::Sender<()>) {
let block_source = Arc::new(block_source);
let (start_tx, start_rx) = mpsc::channel(1);
let (block_tx, block_rx) = mpsc::channel(100);
let block_tx_clone = block_tx.clone();
let task = tokio::spawn(Self::task(start_rx, block_source, block_tx_clone));
let task = tokio::spawn(Self::task(start_rx, block_source, block_tx, debug_cutoff_height));
(Self { chain_id, block_rx, task, blockhash_cache: blockhash_cache.clone() }, start_tx)
}
@ -69,7 +69,8 @@ impl BlockPoller {
async fn task<BS: BlockSource>(
mut start_rx: mpsc::Receiver<()>,
block_source: Arc<BS>,
block_tx_clone: mpsc::Sender<(u64, BlockAndReceipts)>,
block_tx: mpsc::Sender<(u64, BlockAndReceipts)>,
debug_cutoff_height: Option<u64>,
) -> eyre::Result<()> {
start_rx.recv().await.ok_or(eyre::eyre!("Failed to receive start signal"))?;
info!("Starting block poller");
@ -80,10 +81,16 @@ impl BlockPoller {
.await
.ok_or(eyre::eyre!("Failed to find latest block number"))?;
if let Some(debug_cutoff_height) = debug_cutoff_height &&
next_block_number > debug_cutoff_height
{
next_block_number = debug_cutoff_height;
}
loop {
match block_source.collect_block(next_block_number).await {
Ok(block) => {
block_tx_clone.send((next_block_number, block)).await?;
block_tx.send((next_block_number, block)).await?;
next_block_number += 1;
}
Err(_) => tokio::time::sleep(polling_interval).await,

View File

@ -1,6 +1,6 @@
use super::{BlockSource, BlockSourceBoxed};
use crate::node::types::BlockAndReceipts;
use futures::{future::BoxFuture, FutureExt};
use futures::{FutureExt, future::BoxFuture};
use reth_network::cache::LruMap;
use std::sync::{Arc, RwLock};

View File

@ -27,7 +27,7 @@ impl LocalBlocksCache {
}
pub fn get_block(&mut self, height: u64) -> Option<BlockAndReceipts> {
self.cache.remove(&height)
self.cache.get(&height).cloned()
}
pub fn get_path_for_height(&self, height: u64) -> Option<PathBuf> {

View File

@ -1,4 +1,4 @@
use super::{scan::Scanner, time_utils::TimeUtils, HOURLY_SUBDIR};
use super::{HOURLY_SUBDIR, scan::Scanner, time_utils::TimeUtils};
use crate::node::types::BlockAndReceipts;
use std::{
fs::File,

View File

@ -8,13 +8,13 @@ mod time_utils;
use self::{
cache::LocalBlocksCache,
file_ops::FileOperations,
scan::{ScanOptions, Scanner},
scan::{LineStream, ScanOptions, Scanner},
time_utils::TimeUtils,
};
use super::{BlockSource, BlockSourceBoxed};
use crate::node::types::BlockAndReceipts;
use futures::future::BoxFuture;
use reth_metrics::{metrics, metrics::Counter, Metrics};
use reth_metrics::{Metrics, metrics, metrics::Counter};
use std::{
path::{Path, PathBuf},
sync::Arc,
@ -52,6 +52,8 @@ pub struct HlNodeBlockSourceMetrics {
pub fetched_from_hl_node: Counter,
/// How many times the HL node block source is fetched from the fallback
pub fetched_from_fallback: Counter,
/// How many times `try_collect_local_block` was faster than ingest loop
pub file_read_triggered: Counter,
}
impl BlockSource for HlNodeBlockSource {
@ -64,7 +66,9 @@ impl BlockSource for HlNodeBlockSource {
Box::pin(async move {
let now = OffsetDateTime::now_utc();
if let Some(block) = Self::try_collect_local_block(local_blocks_cache, height).await {
if let Some(block) =
Self::try_collect_local_block(&metrics, local_blocks_cache, height).await
{
Self::update_last_fetch(last_local_fetch, height, now).await;
metrics.fetched_from_hl_node.increment(1);
return Ok(block);
@ -120,6 +124,28 @@ impl BlockSource for HlNodeBlockSource {
}
}
struct CurrentFile {
path: PathBuf,
line_stream: Option<LineStream>,
}
impl CurrentFile {
pub fn from_datetime(dt: OffsetDateTime, root: &Path) -> Self {
let (hour, day_str) = (dt.hour(), TimeUtils::date_from_datetime(dt));
let path = root.join(HOURLY_SUBDIR).join(&day_str).join(format!("{}", hour));
Self { path, line_stream: None }
}
pub fn open(&mut self) -> eyre::Result<()> {
if self.line_stream.is_some() {
return Ok(());
}
self.line_stream = Some(LineStream::from_path(&self.path)?);
Ok(())
}
}
impl HlNodeBlockSource {
async fn update_last_fetch(
last_local_fetch: Arc<Mutex<Option<(u64, OffsetDateTime)>>>,
@ -133,6 +159,7 @@ impl HlNodeBlockSource {
}
async fn try_collect_local_block(
metrics: &HlNodeBlockSourceMetrics,
local_blocks_cache: Arc<Mutex<LocalBlocksCache>>,
height: u64,
) -> Option<BlockAndReceipts> {
@ -142,9 +169,10 @@ impl HlNodeBlockSource {
}
let path = u_cache.get_path_for_height(height)?;
info!("Loading block data from {:?}", path);
metrics.file_read_triggered.increment(1);
let mut line_stream = LineStream::from_path(&path).ok()?;
let scan_result = Scanner::scan_hour_file(
&path,
&mut 0,
&mut line_stream,
ScanOptions { start_height: 0, only_load_ranges: false },
);
u_cache.load_scan_result(scan_result);
@ -165,9 +193,10 @@ impl HlNodeBlockSource {
} else {
warn!("Failed to parse last line of file: {:?}", subfile);
}
let mut line_stream =
LineStream::from_path(&subfile).expect("Failed to open line stream");
let mut scan_result = Scanner::scan_hour_file(
&subfile,
&mut 0,
&mut line_stream,
ScanOptions { start_height: cutoff_height, only_load_ranges: true },
);
scan_result.new_blocks.clear(); // Only store ranges, load data lazily
@ -188,15 +217,13 @@ impl HlNodeBlockSource {
}
tokio::time::sleep(TAIL_INTERVAL).await;
};
let (mut hour, mut day_str, mut last_line) =
(dt.hour(), TimeUtils::date_from_datetime(dt), 0);
let mut current_file = CurrentFile::from_datetime(dt, &root);
info!("Starting local ingest loop from height: {}", current_head);
loop {
let hour_file = root.join(HOURLY_SUBDIR).join(&day_str).join(format!("{hour}"));
if hour_file.exists() {
let _ = current_file.open();
if let Some(line_stream) = &mut current_file.line_stream {
let scan_result = Scanner::scan_hour_file(
&hour_file,
&mut last_line,
line_stream,
ScanOptions { start_height: next_height, only_load_ranges: false },
);
next_height = scan_result.next_expected_height;
@ -205,11 +232,8 @@ impl HlNodeBlockSource {
let now = OffsetDateTime::now_utc();
if dt + ONE_HOUR < now {
dt += ONE_HOUR;
(hour, day_str, last_line) = (dt.hour(), TimeUtils::date_from_datetime(dt), 0);
info!(
"Moving to new file: {:?}",
root.join(HOURLY_SUBDIR).join(&day_str).join(format!("{hour}"))
);
current_file = CurrentFile::from_datetime(dt, &root);
info!("Moving to new file: {:?}", current_file.path);
continue;
}
tokio::time::sleep(TAIL_INTERVAL).await;

View File

@ -2,7 +2,7 @@ use crate::node::types::{BlockAndReceipts, EvmBlock};
use serde::{Deserialize, Serialize};
use std::{
fs::File,
io::{BufRead, BufReader},
io::{BufRead, BufReader, Seek, SeekFrom},
ops::RangeInclusive,
path::{Path, PathBuf},
};
@ -25,6 +25,57 @@ pub struct ScanOptions {
pub struct Scanner;
/// Stream for sequentially reading lines from a file.
///
/// This struct allows sequential iteration over lines over [Self::next] method.
/// It is resilient to cases where the line producer process is interrupted while writing:
/// - If a line is incomplete but still ends with a line ending, it is skipped: later, the fallback
/// block source will be used to retrieve the missing block.
/// - If a line does not end with a newline (i.e., the write was incomplete), the method returns
/// `None` to break out of the loop and avoid reading partial data.
/// - If a temporary I/O error occurs, the stream exits the loop without rewinding the cursor, which
/// will result in skipping ahead to the next unread bytes.
pub struct LineStream {
path: PathBuf,
reader: BufReader<File>,
}
impl LineStream {
pub fn from_path(path: &Path) -> std::io::Result<Self> {
let reader = BufReader::with_capacity(1024 * 1024, File::open(path)?);
Ok(Self { path: path.to_path_buf(), reader })
}
pub fn next(&mut self) -> Option<String> {
let mut line_buffer = vec![];
let Ok(size) = self.reader.read_until(b'\n', &mut line_buffer) else {
// Temporary I/O error; restart the loop
return None;
};
// Now cursor is right after the end of the line
// On UTF-8 error, skip the line
let Ok(mut line) = String::from_utf8(line_buffer) else {
return Some(String::new());
};
// If line is not completed yet, return None so that we can break the loop
if line.ends_with('\n') {
if line.ends_with('\r') {
line.pop();
}
line.pop();
return Some(line);
}
// info!("Line is not completed yet: {}", line);
if size != 0 {
self.reader.seek(SeekFrom::Current(-(size as i64))).unwrap();
}
None
}
}
impl Scanner {
pub fn line_to_evm_block(line: &str) -> serde_json::Result<(BlockAndReceipts, u64)> {
let LocalBlockAndReceipts(_, parsed_block): LocalBlockAndReceipts =
@ -35,31 +86,20 @@ impl Scanner {
Ok((parsed_block, height))
}
pub fn scan_hour_file(path: &Path, last_line: &mut usize, options: ScanOptions) -> ScanResult {
let lines: Vec<String> =
BufReader::new(File::open(path).expect("Failed to open hour file"))
.lines()
.collect::<Result<_, _>>()
.unwrap();
let skip = if *last_line == 0 { 0 } else { *last_line - 1 };
pub fn scan_hour_file(line_stream: &mut LineStream, options: ScanOptions) -> ScanResult {
let mut new_blocks = Vec::new();
let mut last_height = options.start_height;
let mut block_ranges = Vec::new();
let mut current_range: Option<(u64, u64)> = None;
for (line_idx, line) in lines.iter().enumerate().skip(skip) {
if line_idx < *last_line || line.trim().is_empty() {
continue;
}
match Self::line_to_evm_block(line) {
while let Some(line) = line_stream.next() {
match Self::line_to_evm_block(&line) {
Ok((parsed_block, height)) => {
if height >= options.start_height {
last_height = last_height.max(height);
if !options.only_load_ranges {
new_blocks.push(parsed_block);
}
*last_line = line_idx;
}
match current_range {
@ -74,16 +114,17 @@ impl Scanner {
}
}
}
Err(_) => warn!("Failed to parse line: {}...", line.get(0..50).unwrap_or(line)),
Err(_) => warn!("Failed to parse line: {}...", line.get(0..50).unwrap_or(&line)),
}
}
if let Some((start, end)) = current_range {
block_ranges.push(start..=end);
}
ScanResult {
path: path.to_path_buf(),
next_expected_height: last_height + 1,
path: line_stream.path.clone(),
next_expected_height: last_height + current_range.is_some() as u64,
new_blocks,
new_block_ranges: block_ranges,
}

View File

@ -1,10 +1,10 @@
use super::*;
use crate::{
node::types::{reth_compat, ReadPrecompileCalls},
pseudo_peer::sources::{hl_node::scan::LocalBlockAndReceipts, LocalBlockSource},
node::types::{ReadPrecompileCalls, reth_compat},
pseudo_peer::sources::{LocalBlockSource, hl_node::scan::LocalBlockAndReceipts},
};
use alloy_consensus::{BlockBody, Header};
use alloy_primitives::{Address, Bloom, Bytes, B256, B64, U256};
use alloy_primitives::{Address, B64, B256, Bloom, Bytes, U256};
use std::{io::Write, time::Duration};
const DEFAULT_FALLBACK_THRESHOLD_FOR_TEST: Duration = Duration::from_millis(5000);

View File

@ -1,5 +1,5 @@
use std::path::Path;
use time::{macros::format_description, Date, OffsetDateTime, Time};
use time::{Date, OffsetDateTime, Time, macros::format_description};
pub struct TimeUtils;

View File

@ -1,8 +1,8 @@
use super::{utils, BlockSource};
use super::{BlockSource, utils};
use crate::node::types::BlockAndReceipts;
use eyre::Context;
use futures::{future::BoxFuture, FutureExt};
use reth_metrics::{metrics, metrics::Counter, Metrics};
use futures::{FutureExt, future::BoxFuture};
use reth_metrics::{Metrics, metrics, metrics::Counter};
use std::path::PathBuf;
use tracing::info;

View File

@ -1,8 +1,8 @@
use super::{utils, BlockSource};
use super::{BlockSource, utils};
use crate::node::types::BlockAndReceipts;
use aws_sdk_s3::types::RequestPayer;
use futures::{future::BoxFuture, FutureExt};
use reth_metrics::{metrics, metrics::Counter, Metrics};
use futures::{FutureExt, future::BoxFuture};
use reth_metrics::{Metrics, metrics, metrics::Counter};
use std::{sync::Arc, time::Duration};
use tracing::info;

View File

@ -1,6 +1,6 @@
use std::borrow::Cow;
use reth_node_core::version::{try_init_version_metadata, RethCliVersionConsts};
use reth_node_core::version::{RethCliVersionConsts, try_init_version_metadata};
pub fn init_reth_hl_version() {
let cargo_pkg_version = env!("CARGO_PKG_VERSION").to_string();