Skip to content

Commit 79ebd31

Browse files
authored
feat: scale gasprice by 1e12 (#663)
Closes #629 changes all relevant code to calculate transaction cost as `(gas * gas_price).div_ceil(1e12)`
1 parent 59927ff commit 79ebd31

File tree

23 files changed

+170
-108
lines changed

23 files changed

+170
-108
lines changed

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/chainspec/src/genesis/adagio.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"pragueTime": 0,
3333
"adagioTime": 0
3434
},
35-
"baseFeePerGas": "0x2c",
35+
"baseFeePerGas": "0x28048c5ec000",
3636
"gasLimit": 50000000,
3737
"alloc": {
3838
"0x7702c00000000000000000000000000000000000": {

crates/chainspec/src/spec.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use std::sync::{Arc, LazyLock};
1616
use tempo_contracts::DEFAULT_7702_DELEGATE_ADDRESS;
1717
use tempo_primitives::TempoHeader;
1818

19-
pub const TEMPO_BASE_FEE: u64 = 44;
19+
pub const TEMPO_BASE_FEE: u64 = 44_000_000_000_000;
2020

2121
/// Tempo genesis info extracted from genesis extra_fields
2222
#[derive(Debug, Clone, Default, serde::Deserialize, serde::Serialize)]

crates/node/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ workspace = true
1313
[dependencies]
1414
tempo-alloy = { workspace = true, features = ["tempo-compat"] }
1515
tempo-evm = { workspace = true, features = ["rpc"] }
16-
tempo-revm.workspace = true
1716
tempo-transaction-pool.workspace = true
1817
tempo-faucet.workspace = true
1918
tempo-chainspec.workspace = true

crates/node/src/node.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ where
357357
.with_max_tx_input_bytes(ctx.config().txpool.max_tx_input_bytes)
358358
.kzg_settings(ctx.kzg_settings()?)
359359
.with_local_transactions_config(pool_config.local_transactions_config.clone())
360-
.set_tx_fee_cap(ctx.config().rpc.rpc_tx_fee_cap)
360+
.set_tx_fee_cap(0)
361361
.with_max_tx_gas_limit(ctx.config().txpool.max_tx_gas_limit)
362362
.disable_balance_check()
363363
.with_minimum_priority_fee(ctx.config().txpool.minimum_priority_fee)

crates/node/src/rpc/mod.rs

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ pub use token::{TempoToken, TempoTokenApiServer};
1616

1717
use crate::node::TempoNode;
1818
use alloy::{consensus::TxReceipt, primitives::U256};
19-
use alloy_primitives::Address;
2019
use reth_ethereum::tasks::{
2120
TaskSpawner,
2221
pool::{BlockingTaskGuard, BlockingTaskPool},
@@ -30,7 +29,7 @@ use reth_node_builder::{
3029
NodeAdapter,
3130
rpc::{EthApiBuilder, EthApiCtx},
3231
};
33-
use reth_provider::ChainSpecProvider;
32+
use reth_provider::{ChainSpecProvider, ProviderError};
3433
use reth_rpc::{DynRpcConverter, eth::EthApi};
3534
use reth_rpc_eth_api::{
3635
EthApiTypes, RpcConverter, RpcNodeCore, RpcNodeCoreExt,
@@ -47,8 +46,7 @@ use reth_rpc_eth_types::{
4746
use tempo_alloy::TempoNetwork;
4847
use tempo_evm::TempoEvmConfig;
4948
use tempo_precompiles::provider::TIPFeeDatabaseExt;
50-
use tempo_primitives::TempoReceipt;
51-
use tempo_revm::TempoTxEnv;
49+
use tempo_primitives::{TEMPO_GAS_PRICE_SCALING_FACTOR, TempoReceipt};
5250
use tokio::sync::Mutex;
5351

5452
/// Tempo `Eth` API implementation.
@@ -74,24 +72,6 @@ impl<N: FullNodeTypes<Types = TempoNode>> TempoEthApi<N> {
7472
) -> Self {
7573
Self { inner: eth_api }
7674
}
77-
78-
/// Returns the feeToken balance of the tx caller in the token's native decimals
79-
pub fn caller_fee_token_allowance<DB>(
80-
&self,
81-
db: &mut DB,
82-
env: &TempoTxEnv,
83-
validator: Address,
84-
) -> Result<U256, EthApiError>
85-
where
86-
DB: Database<Error: Into<EthApiError>>,
87-
{
88-
db.get_fee_token_balance(
89-
env.fee_payer().map_err(EVMError::<DB::Error, _>::from)?,
90-
validator,
91-
env.fee_token,
92-
)
93-
.map_err(Into::into)
94-
}
9575
}
9676

9777
impl<N: FullNodeTypes<Types = TempoNode>> EthApiTypes for TempoEthApi<N> {
@@ -230,10 +210,19 @@ impl<N: FullNodeTypes<Types = TempoNode>> Call for TempoEthApi<N> {
230210
evm_env: &EvmEnvFor<Self::Evm>,
231211
tx_env: &TxEnvFor<Self::Evm>,
232212
) -> Result<u64, Self::Error> {
233-
let fee_token_balance =
234-
self.caller_fee_token_allowance(&mut db, tx_env, evm_env.block_env.beneficiary)?;
213+
let fee_token_balance = db
214+
.get_fee_token_balance(
215+
tx_env
216+
.fee_payer()
217+
.map_err(EVMError::<ProviderError, _>::from)?,
218+
evm_env.block_env.beneficiary,
219+
tx_env.fee_token,
220+
)
221+
.map_err(Into::into)?;
235222

236223
Ok(fee_token_balance
224+
// multiply by the scaling factor
225+
.saturating_mul(TEMPO_GAS_PRICE_SCALING_FACTOR)
237226
// Calculate the amount of gas the caller can afford with the specified gas price.
238227
.checked_div(U256::from(tx_env.inner.gas_price))
239228
// This will be 0 if gas price is 0. It is fine, because we check it before.

crates/node/tests/assets/base-fee-test.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,5 +334,5 @@
334334
}
335335
}
336336
},
337-
"baseFeePerGas": "0x2c"
337+
"baseFeePerGas": "0x28048c5ec000"
338338
}

crates/node/tests/assets/test-genesis.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1504,5 +1504,5 @@
15041504
}
15051505
}
15061506
},
1507-
"baseFeePerGas": "0x2c"
1507+
"baseFeePerGas": "0x28048c5ec000"
15081508
}

crates/node/tests/it/backfill.rs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
use alloy::{
2+
consensus::{SignableTransaction, TxEip1559, TxEnvelope},
23
network::EthereumWallet,
34
providers::{Provider, ProviderBuilder},
45
signers::local::MnemonicBuilder,
56
};
6-
use alloy_eips::BlockNumberOrTag;
7+
use alloy_eips::{BlockNumberOrTag, Encodable2718};
8+
use alloy_network::TxSignerSync;
9+
use alloy_primitives::Address;
710
use alloy_rpc_types_engine::ForkchoiceState;
8-
use reth_e2e_test_utils::{transaction::TransactionTestContext, wallet::Wallet};
11+
use reth_e2e_test_utils::wallet::Wallet;
912
use reth_node_api::EngineApiMessageVersion;
1013
use reth_node_metrics::recorder::install_prometheus_recorder;
1114
use reth_primitives_traits::AlloyBlockHeader as _;
15+
use tempo_chainspec::spec::TEMPO_BASE_FEE;
1216

1317
/// Test that verifies backfill sync works correctly.
1418
///
@@ -65,7 +69,20 @@ async fn test_backfill_sync() -> eyre::Result<()> {
6569
let wallet_signer = wallets[i as usize].clone();
6670

6771
// Create a new transaction for this block
68-
let raw_tx = TransactionTestContext::transfer_tx_bytes(chain_id, wallet_signer).await;
72+
let raw_tx = {
73+
let mut tx = TxEip1559 {
74+
chain_id,
75+
gas_limit: 21000,
76+
to: Address::ZERO.into(),
77+
max_fee_per_gas: TEMPO_BASE_FEE as u128,
78+
max_priority_fee_per_gas: TEMPO_BASE_FEE as u128,
79+
..Default::default()
80+
};
81+
let signature = wallet_signer.sign_transaction_sync(&mut tx).unwrap();
82+
TxEnvelope::Eip1559(tx.into_signed(signature))
83+
.encoded_2718()
84+
.into()
85+
};
6986

7087
// Send the transaction
7188
let tx_hash = node1.rpc.inject_tx(raw_tx).await?;

crates/node/tests/it/block_building.rs

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
use alloy::{
2-
consensus::Transaction,
2+
consensus::{SignableTransaction, Transaction, TxEip1559, TxEnvelope},
33
network::{EthereumWallet, TransactionBuilder},
4-
primitives::U256,
4+
primitives::{Address, U256},
55
providers::{Provider, ProviderBuilder},
66
signers::local::MnemonicBuilder,
77
sol_types::SolEvent,
88
};
99
use alloy_eips::eip2718::Encodable2718;
10-
use alloy_network::Ethereum;
10+
use alloy_network::{Ethereum, TxSignerSync};
1111
use alloy_primitives::Bytes;
1212
use alloy_rpc_types_eth::TransactionRequest;
13-
use reth_e2e_test_utils::transaction::TransactionTestContext;
13+
use tempo_chainspec::spec::TEMPO_BASE_FEE;
1414
use tempo_contracts::precompiles::{IRolesAuth, ITIP20, ITIP20Factory};
1515
use tempo_node::node::TempoNode;
1616
use tempo_precompiles::{
@@ -40,9 +40,10 @@ where
4040
tx_req.nonce = Some(nonce);
4141
tx_req.chain_id = Some(chain_id);
4242
tx_req.gas = tx_req.gas.or(Some(200_000));
43-
tx_req.max_fee_per_gas = tx_req.max_fee_per_gas.or(Some(20e9 as u128));
44-
tx_req.max_priority_fee_per_gas =
45-
tx_req.max_priority_fee_per_gas.or(Some(20e9 as u128));
43+
tx_req.max_fee_per_gas = tx_req.max_fee_per_gas.or(Some(TEMPO_BASE_FEE as u128));
44+
tx_req.max_priority_fee_per_gas = tx_req
45+
.max_priority_fee_per_gas
46+
.or(Some(TEMPO_BASE_FEE as u128));
4647

4748
let signed =
4849
<TransactionRequest as TransactionBuilder<Ethereum>>::build(tx_req, &signer_clone)
@@ -113,8 +114,23 @@ async fn inject_non_payment_txs(
113114
let wallet_signer = MnemonicBuilder::from_phrase(crate::utils::TEST_MNEMONIC)
114115
.index(start_index + i as u32)?
115116
.build()?;
116-
let raw_tx = TransactionTestContext::transfer_tx_bytes(chain_id, wallet_signer).await;
117-
node.rpc.inject_tx(raw_tx).await?;
117+
let mut tx = TxEip1559 {
118+
chain_id,
119+
gas_limit: 21000,
120+
to: Address::ZERO.into(),
121+
max_fee_per_gas: TEMPO_BASE_FEE as u128,
122+
max_priority_fee_per_gas: TEMPO_BASE_FEE as u128,
123+
..Default::default()
124+
};
125+
let signature = wallet_signer.sign_transaction_sync(&mut tx).unwrap();
126+
127+
node.rpc
128+
.inject_tx(
129+
TxEnvelope::Eip1559(tx.into_signed(signature))
130+
.encoded_2718()
131+
.into(),
132+
)
133+
.await?;
118134
}
119135
Ok(())
120136
}
@@ -140,8 +156,8 @@ where
140156
tx_request.nonce = Some(current_nonce + i as u64);
141157
tx_request.chain_id = Some(chain_id);
142158
tx_request.gas = Some(100_000);
143-
tx_request.max_fee_per_gas = Some(20e9 as u128);
144-
tx_request.max_priority_fee_per_gas = Some(20e9 as u128);
159+
tx_request.max_fee_per_gas = Some(TEMPO_BASE_FEE as u128);
160+
tx_request.max_priority_fee_per_gas = Some(TEMPO_BASE_FEE as u128);
145161

146162
let signed_tx =
147163
<TransactionRequest as TransactionBuilder<Ethereum>>::build(tx_request, &signer)
@@ -336,7 +352,20 @@ async fn test_block_building_only_non_payment_txs() -> eyre::Result<()> {
336352
.with_chain_id(chain_id)
337353
.wallet_gen();
338354
for wallet_signer in wallets {
339-
let raw_tx = TransactionTestContext::transfer_tx_bytes(chain_id, wallet_signer).await;
355+
let raw_tx = {
356+
let mut tx = TxEip1559 {
357+
chain_id,
358+
gas_limit: 21000,
359+
to: Address::ZERO.into(),
360+
max_fee_per_gas: TEMPO_BASE_FEE as u128,
361+
max_priority_fee_per_gas: TEMPO_BASE_FEE as u128,
362+
..Default::default()
363+
};
364+
let signature = wallet_signer.sign_transaction_sync(&mut tx).unwrap();
365+
TxEnvelope::Eip1559(tx.into_signed(signature))
366+
.encoded_2718()
367+
.into()
368+
};
340369
setup.node.rpc.inject_tx(raw_tx).await?;
341370
}
342371

0 commit comments

Comments
 (0)