From 630c20633fbbf0ad1bb2ff73ca08c1c071848b4d Mon Sep 17 00:00:00 2001 From: Shashank <99187193+sudo-shashank@users.noreply.github.com> Date: Fri, 5 Jul 2024 19:55:31 +0530 Subject: [PATCH] feat(rpc) Filecoin.EthGetTransactionCount (#4487) --- Cargo.lock | 148 ++++++++++++++++---------------- Cargo.toml | 24 +++--- src/rpc/methods/eth.rs | 33 +++++++ src/rpc/mod.rs | 1 + src/tool/subcommands/api_cmd.rs | 7 ++ 5 files changed, 127 insertions(+), 86 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c07eef088db0..49a3fc8b27b8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1227,7 +1227,7 @@ dependencies = [ "iana-time-zone", "num-traits", "serde", - "windows-targets 0.52.5", + "windows-targets 0.52.6", ] [[package]] @@ -2540,7 +2540,7 @@ checksum = "3a82608ee96ce76aeab659e9b8d3c2b787bffd223199af88c674923d861ada10" dependencies = [ "execute-command-macro", "execute-command-tokens", - "generic-array 1.0.0", + "generic-array 1.1.0", ] [[package]] @@ -2630,9 +2630,9 @@ checksum = "28dea519a9695b9977216879a3ebfddf92f1c08c05d984f8996aecd6ecdc811d" [[package]] name = "fil_actor_account_state" -version = "15.0.0" +version = "15.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0d3939c38bc261fa7ef6e8a97934f458e0fbfbcb236fe3ab7e3c6f18946c88e" +checksum = "98c001e6c3952f311bb118d2ded5a8895642a033ad5d4558421a86a1e19f64c5" dependencies = [ "frc42_macros", "fvm_ipld_encoding", @@ -2646,9 +2646,9 @@ dependencies = [ [[package]] name = "fil_actor_cron_state" -version = "15.0.0" +version = "15.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3aa7eb877f9ed1ec52f1ae700925d99711c4da9337d635ad73e7e324e94ec8a9" +checksum = "ff94b767f31f091a2eb17985c5c9eb02b33dcfceb78d4b922caa09b06b448e30" dependencies = [ "fvm_ipld_encoding", "fvm_shared 2.7.0", @@ -2661,9 +2661,9 @@ dependencies = [ [[package]] name = "fil_actor_datacap_state" -version = "15.0.0" +version = "15.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c41074d7da023c6999883dd382bd4b2178b03795e29bd162613a5a433c55c580" +checksum = "ddddc761fc5e463287ef9d25a547f539b79d9be539685aeb35c829bd75debc68" dependencies = [ "fil_actors_shared", "frc42_macros", @@ -2681,9 +2681,9 @@ dependencies = [ [[package]] name = "fil_actor_evm_state" -version = "15.0.0" +version = "15.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1952ed4016cb377710ca02fee055d018b7559fd288836c21843108312f184f3f" +checksum = "f1f853a82a3709c31f13d4f6db65ef5da629ed630d7cba23e940845f687fa49b" dependencies = [ "cid", "fil_actors_shared", @@ -2701,9 +2701,9 @@ dependencies = [ [[package]] name = "fil_actor_init_state" -version = "15.0.0" +version = "15.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8270be7a047b398a66319d21e23e792ff8a9d3c264325a97447c0e2c125a8b5" +checksum = "dad95698b8e0304697acd08aa0330e85ce9ecbf7cfac0af25dbb3af135918bfc" dependencies = [ "anyhow", "cid", @@ -2722,9 +2722,9 @@ dependencies = [ [[package]] name = "fil_actor_interface" -version = "15.0.0" +version = "15.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50a1bb143d49c8b3ad6fa29fdfc041cc5258e04a631757e136599c16b5ae856a" +checksum = "a4d9fe53aca285762365b3032a5bff4f976c0d8b34b672cf696916131f2442d4" dependencies = [ "anyhow", "cid", @@ -2760,9 +2760,9 @@ dependencies = [ [[package]] name = "fil_actor_market_state" -version = "15.0.0" +version = "15.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b2f36c93351202dbf5c1c5b9132848ec537bfb28ca8a6d64db71de57fe4c770" +checksum = "dacd1e836fed9faf71d0dd2371f664a2680254d125eb8d985a99217b4f5f238f" dependencies = [ "anyhow", "cid", @@ -2787,9 +2787,9 @@ dependencies = [ [[package]] name = "fil_actor_miner_state" -version = "15.0.0" +version = "15.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f6e3ee635b3222173a9f0675683abd7a28ebbec729f1714a201a8d8fd0a8850" +checksum = "ecfafc071444d071d004fc510371ab103795ff0a034c2e7cb09cc67fdfcdf870" dependencies = [ "anyhow", "bitflags 2.6.0", @@ -2818,9 +2818,9 @@ dependencies = [ [[package]] name = "fil_actor_multisig_state" -version = "15.0.0" +version = "15.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9259179420d2cf112bf5b874d17fe038925037ff5951e3537cc67ac34b5bc23" +checksum = "4d17f929c15f325234c9deb2f4dc7ce0fd14fdd1d008a8d3d0cc6b48a4fb881a" dependencies = [ "anyhow", "cid", @@ -2842,9 +2842,9 @@ dependencies = [ [[package]] name = "fil_actor_power_state" -version = "15.0.0" +version = "15.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "274db1a8390af523b5ca18038bf1f443ed22cc344e584e95cf6b3dfeec6397e3" +checksum = "5375f201d6d04627364f0cb0aff558911f48945f2933789c94f3339ed048ab2c" dependencies = [ "anyhow", "cid", @@ -2866,9 +2866,9 @@ dependencies = [ [[package]] name = "fil_actor_reward_state" -version = "15.0.0" +version = "15.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3867426b007e1899abe99c2b42d904afaa1197f411761bee9cb6e7b938eb4590" +checksum = "668c981a0bd39198e441526a27141bb1d358397e7104e127cf24fd995f50d866" dependencies = [ "fil_actor_miner_state", "fil_actors_shared", @@ -2884,9 +2884,9 @@ dependencies = [ [[package]] name = "fil_actor_system_state" -version = "15.0.0" +version = "15.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57ccabf8ba7ed4786189e80c2505003389cfd138b002866da3781a5091c1cc32" +checksum = "8d51b44d50e848a185d05dab7d28f8e8a0131b9ede3ed50df82825c932891236" dependencies = [ "cid", "fil_actors_shared", @@ -2901,9 +2901,9 @@ dependencies = [ [[package]] name = "fil_actor_verifreg_state" -version = "15.0.0" +version = "15.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dcd1eab82dc350b7f2501d4b986349211f735f6a8e754cb1c8e2f5896f8875dd" +checksum = "ced66872a6b12b9c8106b085a3a5e67c9e1845c52caf777d5cbaaaa12f58b239" dependencies = [ "anyhow", "cid", @@ -2923,9 +2923,9 @@ dependencies = [ [[package]] name = "fil_actors_shared" -version = "15.0.0" +version = "15.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "280b83694ee213140d8bb72a66176880df23a0d754a5519b5fc1813f7d4bf9eb" +checksum = "5e6ce31431a0083f6ba25bf3c3572b72e7d032f1cded4973df846503f51bba72" dependencies = [ "anyhow", "cid", @@ -3950,9 +3950,9 @@ dependencies = [ [[package]] name = "generic-array" -version = "1.0.0" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe739944a5406424e080edccb6add95685130b9f160d5407c639c7df0c5836b0" +checksum = "96512db27971c2c3eece70a1e106fbe6c87760234e31e8f7e5634912fe52794a" dependencies = [ "typenum", ] @@ -6606,7 +6606,7 @@ dependencies = [ "redox_syscall 0.5.2", "smallvec", "thread-id", - "windows-targets 0.52.5", + "windows-targets 0.52.6", ] [[package]] @@ -7731,16 +7731,16 @@ dependencies = [ "once_cell", "ring 0.17.8", "rustls-pki-types", - "rustls-webpki 0.102.4", + "rustls-webpki 0.102.5", "subtle", "zeroize", ] [[package]] name = "rustls-native-certs" -version = "0.7.0" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f1fb85efa936c42c6d5fc28d2629bb51e4b2f4b8a5211e297d599cc5a093792" +checksum = "a88d6d420651b496bdd98684116959239430022a115c1240e6c3993be0b15fba" dependencies = [ "openssl-probe", "rustls-pemfile", @@ -7779,7 +7779,7 @@ dependencies = [ "rustls", "rustls-native-certs", "rustls-platform-verifier-android", - "rustls-webpki 0.102.4", + "rustls-webpki 0.102.5", "security-framework", "security-framework-sys", "webpki-roots", @@ -7804,9 +7804,9 @@ dependencies = [ [[package]] name = "rustls-webpki" -version = "0.102.4" +version = "0.102.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff448f7e92e913c4b7d4c6d8e4540a1724b319b4152b8aef6d4cf8339712b33e" +checksum = "f9a6fccd794a42c2c105b513a2f62bc3fd8f3ba57a4593677ceb0bd035164d78" dependencies = [ "ring 0.17.8", "rustls-pki-types", @@ -8088,9 +8088,9 @@ dependencies = [ [[package]] name = "serde_with" -version = "3.8.2" +version = "3.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "079f3a42cd87588d924ed95b533f8d30a483388c4e400ab736a7058e34f16169" +checksum = "e73139bc5ec2d45e6c5fd85be5a46949c1c39a4c18e56915f5eb4c12f975e377" dependencies = [ "base64 0.22.1", "chrono", @@ -8106,9 +8106,9 @@ dependencies = [ [[package]] name = "serde_with_macros" -version = "3.8.2" +version = "3.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc03aad67c1d26b7de277d51c86892e7d9a0110a2fe44bf6b26cc569fba302d6" +checksum = "b80d3d6b56b64335c0180e5ffde23b3c5e08c14c585b51a15bd0e95393f46703" dependencies = [ "darling 0.20.9", "proc-macro2", @@ -10178,7 +10178,7 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" dependencies = [ - "windows-targets 0.52.5", + "windows-targets 0.52.6", ] [[package]] @@ -10196,7 +10196,7 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" dependencies = [ - "windows-targets 0.52.5", + "windows-targets 0.52.6", ] [[package]] @@ -10216,18 +10216,18 @@ dependencies = [ [[package]] name = "windows-targets" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" dependencies = [ - "windows_aarch64_gnullvm 0.52.5", - "windows_aarch64_msvc 0.52.5", - "windows_i686_gnu 0.52.5", + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", "windows_i686_gnullvm", - "windows_i686_msvc 0.52.5", - "windows_x86_64_gnu 0.52.5", - "windows_x86_64_gnullvm 0.52.5", - "windows_x86_64_msvc 0.52.5", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", ] [[package]] @@ -10238,9 +10238,9 @@ checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" [[package]] name = "windows_aarch64_gnullvm" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" [[package]] name = "windows_aarch64_msvc" @@ -10256,9 +10256,9 @@ checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" [[package]] name = "windows_aarch64_msvc" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" [[package]] name = "windows_i686_gnu" @@ -10274,15 +10274,15 @@ checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" [[package]] name = "windows_i686_gnu" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" [[package]] name = "windows_i686_gnullvm" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" [[package]] name = "windows_i686_msvc" @@ -10298,9 +10298,9 @@ checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" [[package]] name = "windows_i686_msvc" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" [[package]] name = "windows_x86_64_gnu" @@ -10316,9 +10316,9 @@ checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" [[package]] name = "windows_x86_64_gnu" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" [[package]] name = "windows_x86_64_gnullvm" @@ -10328,9 +10328,9 @@ checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" [[package]] name = "windows_x86_64_gnullvm" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" [[package]] name = "windows_x86_64_msvc" @@ -10346,9 +10346,9 @@ checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" [[package]] name = "windows_x86_64_msvc" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" [[package]] name = "winnow" @@ -10516,18 +10516,18 @@ dependencies = [ [[package]] name = "zerocopy" -version = "0.7.34" +version = "0.7.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae87e3fcd617500e5d106f0380cf7b77f3c6092aae37191433159dda23cfb087" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" dependencies = [ "zerocopy-derive", ] [[package]] name = "zerocopy-derive" -version = "0.7.34" +version = "0.7.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15e934569e47891f7d9411f1a451d947a60e000ab3bd24fbb970f000387d1b3b" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" dependencies = [ "proc-macro2", "quote", diff --git a/Cargo.toml b/Cargo.toml index ff5dd8950a08..d88cddd99b8f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -47,18 +47,18 @@ digest = "0.10" directories = "5" displaydoc = "0.2" ethereum-types = "0.14" -fil_actor_account_state = { version = "15" } -fil_actor_cron_state = { version = "15" } -fil_actor_datacap_state = { version = "15" } -fil_actor_init_state = { version = "15" } -fil_actor_interface = { version = "15" } -fil_actor_market_state = { version = "15" } -fil_actor_miner_state = { version = "15" } -fil_actor_power_state = { version = "15" } -fil_actor_reward_state = { version = "15" } -fil_actor_system_state = { version = "15" } -fil_actor_verifreg_state = { version = "15" } -fil_actors_shared = { version = "15", features = ["json"] } +fil_actor_account_state = { version = "15.1" } +fil_actor_cron_state = { version = "15.1" } +fil_actor_datacap_state = { version = "15.1" } +fil_actor_init_state = { version = "15.1" } +fil_actor_interface = { version = "15.1" } +fil_actor_market_state = { version = "15.1" } +fil_actor_miner_state = { version = "15.1" } +fil_actor_power_state = { version = "15.1" } +fil_actor_reward_state = { version = "15.1" } +fil_actor_system_state = { version = "15.1" } +fil_actor_verifreg_state = { version = "15.1" } +fil_actors_shared = { version = "15.1", features = ["json"] } flume = "0.11" fs_extra = "1" futures = "0.3" diff --git a/src/rpc/methods/eth.rs b/src/rpc/methods/eth.rs index ae4776b1b064..b000878b4b24 100644 --- a/src/rpc/methods/eth.rs +++ b/src/rpc/methods/eth.rs @@ -1668,6 +1668,39 @@ impl RpcMethod<3> for EthGetStorageAt { } } +pub enum EthGetTransactionCount {} +impl RpcMethod<2> for EthGetTransactionCount { + const NAME: &'static str = "Filecoin.EthGetTransactionCount"; + const PARAM_NAMES: [&'static str; 2] = ["sender", "block_param"]; + const API_VERSION: ApiVersion = ApiVersion::V1; + const PERMISSION: Permission = Permission::Read; + + type Params = (EthAddress, BlockNumberOrHash); + type Ok = Uint64; + + async fn handle( + ctx: Ctx, + (sender, block_param): Self::Params, + ) -> Result { + let addr = sender.to_filecoin_address()?; + let ts = tipset_by_block_number_or_hash(&ctx.chain_store, block_param)?; + let state = + StateTree::new_from_root(ctx.state_manager.blockstore_owned(), ts.parent_state())?; + let actor = state.get_required_actor(&addr)?; + if fil_actor_interface::is_evm_actor(&actor.code) { + let evm_state = + fil_actor_interface::evm::State::load(ctx.store(), actor.code, actor.state)?; + if !evm_state.is_alive() { + return Ok(Uint64(0)); + } + + Ok(Uint64(evm_state.nonce())) + } else { + Ok(Uint64(ctx.mpool.get_sequence(&addr)?)) + } + } +} + #[cfg(test)] mod test { use super::*; diff --git a/src/rpc/mod.rs b/src/rpc/mod.rs index f74e91b86771..ce4ea9b420c8 100644 --- a/src/rpc/mod.rs +++ b/src/rpc/mod.rs @@ -81,6 +81,7 @@ macro_rules! for_each_method { $callback!(crate::rpc::eth::EthGetBlockTransactionCountByHash); $callback!(crate::rpc::eth::EthGetBlockTransactionCountByNumber); $callback!(crate::rpc::eth::EthGetMessageCidByTransactionHash); + $callback!(crate::rpc::eth::EthGetTransactionCount); // gas vertical $callback!(crate::rpc::gas::GasEstimateGasLimit); diff --git a/src/tool/subcommands/api_cmd.rs b/src/tool/subcommands/api_cmd.rs index 696c748b435b..4f4025fb1e16 100644 --- a/src/tool/subcommands/api_cmd.rs +++ b/src/tool/subcommands/api_cmd.rs @@ -1188,6 +1188,13 @@ fn eth_tests_with_tipset(shared_tipset: &Tipset) -> Vec { RpcTest::identity( EthGetBlockTransactionCountByNumber::request((Int64(shared_tipset.epoch()),)).unwrap(), ), + RpcTest::identity( + EthGetTransactionCount::request(( + EthAddress::from_str("0xff000000000000000000000000000000000003ec").unwrap(), + BlockNumberOrHash::from_block_hash_object(block_hash.clone(), true), + )) + .unwrap(), + ), RpcTest::identity( EthGetStorageAt::request(( // https://filfox.info/en/address/f410fpoidg73f7krlfohnla52dotowde5p2sejxnd4mq