Skip to content
17 changes: 17 additions & 0 deletions crates/anvil/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ use foundry_evm::{
utils::get_blob_params,
};
use foundry_evm_networks::NetworkConfigs;
use tempo_precompiles::TIP_FEE_MANAGER_ADDRESS;

/// Default port the rpc will open
pub const NODE_PORT: u16 = 8545;
Expand Down Expand Up @@ -523,6 +524,20 @@ impl Default for NodeConfig {
}

impl NodeConfig {
/// Applies Tempo's safe default beneficiary for forked nodes when the user
/// has not supplied a genesis coinbase.
pub(crate) fn apply_tempo_fork_beneficiary_default<N>(&self, evm_env: &mut EvmEnv<N>) {
if self.networks.is_tempo() && !self.fork_urls.is_empty() && self.genesis.is_none() {
// Tempo mainnet maps the zero validator token to a DONOTUSE sentinel.
// Forked transactions with the default zero beneficiary can therefore
// fail fee collection before producing a receipt. Use the same neutral
// fee-recipient sentinel as Tempo's simulation path so validator token
// lookup falls back to the default PathUSD token unless the user
// explicitly supplied a genesis coinbase.
evm_env.block_env.beneficiary = TIP_FEE_MANAGER_ADDRESS;
}
}

/// Returns the memory limit of the node
#[must_use]
pub const fn with_memory_limit(mut self, mems_value: Option<u64>) -> Self {
Expand Down Expand Up @@ -1163,6 +1178,8 @@ impl NodeConfig {
},
);

self.apply_tempo_fork_beneficiary_default(&mut evm_env);

let base_fee_params: BaseFeeParams =
self.networks.base_fee_params(self.get_genesis_timestamp());

Expand Down
1 change: 1 addition & 0 deletions crates/anvil/src/eth/backend/mem/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2140,6 +2140,7 @@ impl<N: Network> Backend<N> {
// `setup_fork_db_config`
node_config.base_fee.take();
node_config.fork_urls = vec![eth_rpc_url.clone()];
node_config.apply_tempo_fork_beneficiary_default(&mut evm_env);

node_config.setup_fork_db_config(eth_rpc_url, &mut evm_env, &self.fees).await?
};
Expand Down
35 changes: 33 additions & 2 deletions crates/anvil/tests/it/tempo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use alloy_eips::eip2718::Encodable2718;
use alloy_network::{ReceiptResponse, TransactionBuilder, TransactionResponse};
use alloy_primitives::{Address, Bytes, TxKind, U256, address};
use alloy_provider::{Provider, ext::TxPoolApi};
use alloy_rpc_types::{BlockId, BlockNumberOrTag, TransactionRequest};
use alloy_rpc_types::{BlockId, BlockNumberOrTag, TransactionRequest, anvil::Forking};
use alloy_serde::WithOtherFields;
use alloy_signer::Signer;
use alloy_signer_local::PrivateKeySigner;
Expand Down Expand Up @@ -47,11 +47,42 @@ async fn test_tempo_fork_detects_hardfork_from_fork_timestamp() {
)
.await;

let (api, _handle) =
let (api, handle) =
spawn(NodeConfig::test_tempo().with_eth_rpc_url(Some(source_handle.http_endpoint()))).await;

let node_info = api.anvil_node_info().await.unwrap();
assert_eq!(node_info.hard_fork, "T3");

api.mine_one().await;
let latest_block = handle
.http_provider()
.get_block_by_number(BlockNumberOrTag::Latest)
.await
.unwrap()
.unwrap();
assert_eq!(latest_block.header.beneficiary, TIP_FEE_MANAGER_ADDRESS);
}

#[tokio::test(flavor = "multi_thread")]
async fn test_tempo_reset_to_fork_uses_fee_manager_beneficiary() {
let (_source_api, source_handle) = spawn(NodeConfig::test()).await;

let (api, handle) = spawn(NodeConfig::test_tempo()).await;
api.anvil_reset(Some(Forking {
json_rpc_url: Some(source_handle.http_endpoint()),
block_number: None,
}))
.await
.unwrap();

api.mine_one().await;
let latest_block = handle
Comment thread
figtracer marked this conversation as resolved.
.http_provider()
.get_block_by_number(BlockNumberOrTag::Latest)
.await
.unwrap()
.unwrap();
assert_eq!(latest_block.header.beneficiary, TIP_FEE_MANAGER_ADDRESS);
}

sol! {
Expand Down