Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@

- [#6380](https://github.com/ChainSafe/forest/pull/6380) Implemented `Filecoin.EthFeeHistory` for API v2.

- [#6387](https://github.com/ChainSafe/forest/pull/6387) Implemented `Filecoin.EthGetTransactionCount` for API v2.

### Changed

### Removed
Expand Down
83 changes: 64 additions & 19 deletions src/rpc/methods/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2393,33 +2393,78 @@ impl RpcMethod<2> for EthGetTransactionCount {
(sender, block_param): Self::Params,
) -> Result<Self::Ok, ServerError> {
let addr = sender.to_filecoin_address()?;
if let BlockNumberOrHash::PredefinedBlock(ref predefined) = block_param
&& *predefined == Predefined::Pending
{
return Ok(EthUint64(ctx.mpool.get_sequence(&addr)?));
match block_param {
BlockNumberOrHash::PredefinedBlock(Predefined::Pending) => {
Ok(EthUint64(ctx.mpool.get_sequence(&addr)?))
}
_ => {
let ts = tipset_by_block_number_or_hash(
ctx.chain_store(),
block_param,
ResolveNullTipset::TakeOlder,
)?;
eth_get_transaction_count(&ctx, &ts, addr).await
}
}
let ts = tipset_by_block_number_or_hash(
ctx.chain_store(),
block_param.clone(),
ResolveNullTipset::TakeOlder,
)?;
}
}

let (state_cid, _) = ctx.state_manager.tipset_state(&ts).await?;
pub enum EthGetTransactionCountV2 {}
impl RpcMethod<2> for EthGetTransactionCountV2 {
const NAME: &'static str = "Filecoin.EthGetTransactionCount";
const NAME_ALIAS: Option<&'static str> = Some("eth_getTransactionCount");
const PARAM_NAMES: [&'static str; 2] = ["sender", "blockParam"];
const API_PATHS: BitFlags<ApiPaths> = make_bitflags!(ApiPaths::V2);
const PERMISSION: Permission = Permission::Read;

type Params = (EthAddress, ExtBlockNumberOrHash);
type Ok = EthUint64;

let state = StateTree::new_from_root(ctx.store_owned(), &state_cid)?;
let actor = state.get_required_actor(&addr)?;
if is_evm_actor(&actor.code) {
let evm_state = evm::State::load(ctx.store(), actor.code, actor.state)?;
if !evm_state.is_alive() {
return Ok(EthUint64(0));
async fn handle(
ctx: Ctx<impl Blockstore + Send + Sync + 'static>,
(sender, block_param): Self::Params,
) -> Result<Self::Ok, ServerError> {
let addr = sender.to_filecoin_address()?;
match block_param {
ExtBlockNumberOrHash::PredefinedBlock(ExtPredefined::Pending) => {
Ok(EthUint64(ctx.mpool.get_sequence(&addr)?))
}
_ => {
let ts = tipset_by_block_number_or_hash_v2(
&ctx,
block_param,
ResolveNullTipset::TakeOlder,
)
.await?;
eth_get_transaction_count(&ctx, &ts, addr).await
}
Ok(EthUint64(evm_state.nonce()))
} else {
Ok(EthUint64(actor.sequence))
}
}
}

async fn eth_get_transaction_count<B>(
ctx: &Ctx<B>,
ts: &Tipset,
addr: FilecoinAddress,
) -> Result<EthUint64, ServerError>
where
B: Blockstore + Send + Sync + 'static,
{
let (state_cid, _) = ctx.state_manager.tipset_state(ts).await?;

let state = StateTree::new_from_root(ctx.store_owned(), &state_cid)?;
let actor = state.get_required_actor(&addr)?;
if is_evm_actor(&actor.code) {
let evm_state = evm::State::load(ctx.store(), actor.code, actor.state)?;
if !evm_state.is_alive() {
return Ok(EthUint64(0));
}
Ok(EthUint64(evm_state.nonce()))
} else {
Ok(EthUint64(actor.sequence))
}
}

pub enum EthMaxPriorityFeePerGas {}
impl RpcMethod<0> for EthMaxPriorityFeePerGas {
const NAME: &'static str = "Filecoin.EthMaxPriorityFeePerGas";
Expand Down
1 change: 1 addition & 0 deletions src/rpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ macro_rules! for_each_rpc_method {
$callback!($crate::rpc::eth::EthGetTransactionByHash);
$callback!($crate::rpc::eth::EthGetTransactionByHashLimited);
$callback!($crate::rpc::eth::EthGetTransactionCount);
$callback!($crate::rpc::eth::EthGetTransactionCountV2);
$callback!($crate::rpc::eth::EthGetTransactionHashByCid);
$callback!($crate::rpc::eth::EthGetTransactionByBlockNumberAndIndex);
$callback!($crate::rpc::eth::EthGetTransactionByBlockHashAndIndex);
Expand Down
43 changes: 43 additions & 0 deletions src/tool/subcommands/api_cmd/api_compare_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1757,6 +1757,49 @@ fn eth_tests_with_tipset<DB: Blockstore>(store: &Arc<DB>, shared_tipset: &Tipset
))
.unwrap(),
),
RpcTest::identity(
EthGetTransactionCountV2::request((
EthAddress::from_str("0xff000000000000000000000000000000000003ec").unwrap(),
ExtBlockNumberOrHash::from_block_hash_object(block_hash.clone(), true),
))
.unwrap(),
),
RpcTest::identity(
EthGetTransactionCountV2::request((
EthAddress::from_str("0xff000000000000000000000000000000000003ec").unwrap(),
ExtBlockNumberOrHash::from_predefined(ExtPredefined::Earliest),
))
.unwrap(),
)
.policy_on_rejected(PolicyOnRejected::PassWithQuasiIdenticalError),
RpcTest::basic(
EthGetTransactionCountV2::request((
EthAddress::from_str("0xff000000000000000000000000000000000003ec").unwrap(),
ExtBlockNumberOrHash::from_predefined(ExtPredefined::Pending),
))
.unwrap(),
),
RpcTest::basic(
EthGetTransactionCountV2::request((
EthAddress::from_str("0xff000000000000000000000000000000000003ec").unwrap(),
ExtBlockNumberOrHash::from_predefined(ExtPredefined::Latest),
))
.unwrap(),
),
RpcTest::basic(
EthGetTransactionCountV2::request((
EthAddress::from_str("0xff000000000000000000000000000000000003ec").unwrap(),
ExtBlockNumberOrHash::from_predefined(ExtPredefined::Safe),
))
.unwrap(),
),
RpcTest::basic(
EthGetTransactionCountV2::request((
EthAddress::from_str("0xff000000000000000000000000000000000003ec").unwrap(),
ExtBlockNumberOrHash::from_predefined(ExtPredefined::Finalized),
))
.unwrap(),
),
RpcTest::identity(
EthGetStorageAt::request((
// https://filfox.info/en/address/f410fpoidg73f7krlfohnla52dotowde5p2sejxnd4mq
Expand Down
1 change: 1 addition & 0 deletions src/tool/subcommands/api_cmd/test_snapshots.txt
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ filecoin_ethgettransactionbyblocknumberandindex_1740132538304408.rpcsnap.json.zs
filecoin_ethgettransactionbyhash_1741272955520821.rpcsnap.json.zst
filecoin_ethgettransactionbyhashlimited_1741272955509708.rpcsnap.json.zst
filecoin_ethgettransactioncount_1740132538183426.rpcsnap.json.zst
filecoin_ethgettransactioncount_v2_1767847407595348.rpcsnap.json.zst
filecoin_ethgettransactionhashbycid_1737446676698540.rpcsnap.json.zst
filecoin_ethgettransactionreceipt_1741272955712904.rpcsnap.json.zst
filecoin_ethgettransactionreceipt_1765811578590165.rpcsnap.json.zst # transaction not found
Expand Down
Loading