Skip to content

Commit 7ea3316

Browse files
authored
fix: Fix the GasEstimateMessageGas API (#6109)
1 parent 58352c4 commit 7ea3316

14 files changed

Lines changed: 715 additions & 105 deletions

File tree

src/chain/store/chain_store.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,7 @@ where
661661

662662
for message in unsigned_box.chain(signed_box) {
663663
let from_address = &message.from();
664-
if applied.contains_key(from_address) {
664+
if !applied.contains_key(from_address) {
665665
let actor_state = state
666666
.get_actor(from_address)?
667667
.ok_or_else(|| Error::Other("Actor state not found".to_string()))?;

src/cli_shared/cli/config.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
// Copyright 2019-2025 ChainSafe Systems
22
// SPDX-License-Identifier: Apache-2.0, MIT
33

4+
use super::client::Client;
45
use crate::db::db_engine::DbConfig;
56
use crate::libp2p::Libp2pConfig;
67
use crate::shim::clock::ChainEpoch;
8+
use crate::shim::econ::TokenAmount;
79
use crate::utils::misc::env::is_env_set_and_truthy;
810
use crate::{chain_sync::SyncConfig, networks::NetworkChain};
911
use serde::{Deserialize, Serialize};
1012
use std::path::PathBuf;
1113

12-
use super::client::Client;
13-
1414
const FOREST_CHAIN_INDEXER_ENABLED: &str = "FOREST_CHAIN_INDEXER_ENABLED";
1515

1616
/// Structure that defines daemon configuration when process is detached
@@ -92,6 +92,23 @@ impl Default for ChainIndexerConfig {
9292
}
9393
}
9494

95+
#[derive(Deserialize, Serialize, PartialEq, Eq, Debug, Clone)]
96+
#[cfg_attr(test, derive(derive_quickcheck_arbitrary::Arbitrary))]
97+
pub struct FeeConfig {
98+
/// Indicates the default max fee for a message
99+
#[serde(with = "crate::lotus_json")]
100+
pub max_fee: TokenAmount,
101+
}
102+
103+
impl Default for FeeConfig {
104+
fn default() -> Self {
105+
// The code is taken from https://github.com/filecoin-project/lotus/blob/release/v1.34.1/node/config/def.go#L39
106+
Self {
107+
max_fee: TokenAmount::from_atto(70_000_000_000_000_000u64), // 0.07 FIL
108+
}
109+
}
110+
}
111+
95112
#[derive(Serialize, Deserialize, PartialEq, Default, Debug, Clone)]
96113
#[cfg_attr(test, derive(derive_quickcheck_arbitrary::Arbitrary))]
97114
#[serde(default)]
@@ -104,6 +121,7 @@ pub struct Config {
104121
pub daemon: DaemonConfig,
105122
pub events: EventsConfig,
106123
pub fevm: FevmConfig,
124+
pub fee: FeeConfig,
107125
pub chain_indexer: ChainIndexerConfig,
108126
}
109127

src/daemon/context.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ fn get_chain_config_and_set_network(config: &Config) -> Arc<ChainConfig> {
7979
Arc::new(ChainConfig {
8080
enable_indexer: config.chain_indexer.enable_indexer,
8181
enable_receipt_event_caching: config.client.enable_rpc,
82+
default_max_fee: config.fee.max_fee.clone(),
8283
..chain_config
8384
})
8485
}

src/lotus_json/signed_message.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ impl HasLotusJson for SignedMessage {
5959
},
6060
}),
6161
SignedMessage {
62-
message: crate::shim::message::Message::default(),
63-
signature: crate::shim::crypto::Signature {
62+
message: Message::default(),
63+
signature: Signature {
6464
sig_type: crate::shim::crypto::SignatureType::Bls,
6565
bytes: Vec::from_iter(*b"hello world!"),
6666
},

src/networks/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use fil_actors_shared::v13::runtime::Policy;
1010
use fvm_ipld_blockstore::Blockstore;
1111
use itertools::Itertools;
1212
use libp2p::Multiaddr;
13+
use num_traits::Zero;
1314
use serde::{Deserialize, Serialize};
1415
use strum::IntoEnumIterator;
1516
use strum_macros::Display;
@@ -283,6 +284,7 @@ pub struct ChainConfig {
283284
pub f3_initial_power_table: Option<Cid>,
284285
pub enable_indexer: bool,
285286
pub enable_receipt_event_caching: bool,
287+
pub default_max_fee: TokenAmount,
286288
}
287289

288290
impl ChainConfig {
@@ -316,6 +318,7 @@ impl ChainConfig {
316318
),
317319
enable_indexer: false,
318320
enable_receipt_event_caching: true,
321+
default_max_fee: TokenAmount::zero(),
319322
}
320323
}
321324

@@ -352,6 +355,7 @@ impl ChainConfig {
352355
),
353356
enable_indexer: false,
354357
enable_receipt_event_caching: true,
358+
default_max_fee: TokenAmount::zero(),
355359
}
356360
}
357361

@@ -378,6 +382,7 @@ impl ChainConfig {
378382
f3_initial_power_table: None,
379383
enable_indexer: false,
380384
enable_receipt_event_caching: true,
385+
default_max_fee: TokenAmount::zero(),
381386
}
382387
}
383388

@@ -410,6 +415,7 @@ impl ChainConfig {
410415
f3_initial_power_table: None,
411416
enable_indexer: false,
412417
enable_receipt_event_caching: true,
418+
default_max_fee: TokenAmount::zero(),
413419
}
414420
}
415421

src/rpc/methods/chain.rs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ impl RpcMethod<1> for ChainGetMessage {
219219
const DESCRIPTION: Option<&'static str> = Some("Returns the message with the specified CID.");
220220

221221
type Params = (Cid,);
222-
type Ok = Message;
222+
type Ok = FlattenedApiMessage;
223223

224224
async fn handle(
225225
ctx: Ctx<impl Blockstore>,
@@ -229,10 +229,13 @@ impl RpcMethod<1> for ChainGetMessage {
229229
.store()
230230
.get_cbor(&message_cid)?
231231
.with_context(|| format!("can't find message with cid {message_cid}"))?;
232-
Ok(match chain_message {
232+
let message = match chain_message {
233233
ChainMessage::Signed(m) => m.into_message(),
234234
ChainMessage::Unsigned(m) => m,
235-
})
235+
};
236+
237+
let cid = message.cid();
238+
Ok(FlattenedApiMessage { message, cid })
236239
}
237240
}
238241

@@ -1357,6 +1360,18 @@ pub struct ApiMessage {
13571360

13581361
lotus_json_with_self!(ApiMessage);
13591362

1363+
#[derive(Serialize, Deserialize, JsonSchema, Clone, Debug, Eq, PartialEq)]
1364+
pub struct FlattenedApiMessage {
1365+
#[serde(flatten, with = "crate::lotus_json")]
1366+
#[schemars(with = "LotusJson<Message>")]
1367+
pub message: Message,
1368+
#[serde(rename = "CID", with = "crate::lotus_json")]
1369+
#[schemars(with = "LotusJson<Cid>")]
1370+
pub cid: Cid,
1371+
}
1372+
1373+
lotus_json_with_self!(FlattenedApiMessage);
1374+
13601375
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
13611376
pub struct ForestChainExportParams {
13621377
pub version: FilecoinSnapshotVersion,

src/rpc/methods/eth.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -848,7 +848,7 @@ impl RpcMethod<0> for EthGasPrice {
848848
let ts = ctx.chain_store().heaviest_tipset();
849849
let block0 = ts.block_headers().first();
850850
let base_fee = block0.parent_base_fee.atto();
851-
let tip = crate::rpc::gas::estimate_gas_premium(&ctx, 0)
851+
let tip = crate::rpc::gas::estimate_gas_premium(&ctx, 0, &ApiTipsetKey(None))
852852
.await
853853
.map(|gas_premium| gas_premium.atto().to_owned())
854854
.unwrap_or_default();
@@ -2321,7 +2321,7 @@ impl RpcMethod<0> for EthMaxPriorityFeePerGas {
23212321
ctx: Ctx<impl Blockstore + Send + Sync + 'static>,
23222322
(): Self::Params,
23232323
) -> Result<Self::Ok, ServerError> {
2324-
match crate::rpc::gas::estimate_gas_premium(&ctx, 0).await {
2324+
match gas::estimate_gas_premium(&ctx, 0, &ApiTipsetKey(None)).await {
23252325
Ok(gas_premium) => Ok(EthBigInt(gas_premium.atto().clone())),
23262326
Err(_) => Ok(EthBigInt(num_bigint::BigInt::zero())),
23272327
}

0 commit comments

Comments
 (0)