From 221faf6052edec2b82dfccc3561bdc9de5833ba3 Mon Sep 17 00:00:00 2001 From: Aryan Tikarya Date: Mon, 4 Aug 2025 23:25:34 +0530 Subject: [PATCH 01/11] add fvm_actor_utils --- Cargo.lock | 8 ++++++++ Cargo.toml | 2 ++ 2 files changed, 10 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 2731ee566ba6..680c481bf4d1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3159,6 +3159,7 @@ dependencies = [ "fvm 2.11.1", "fvm 3.13.1", "fvm 4.7.2", + "fvm_actor_utils", "fvm_ipld_blockstore", "fvm_ipld_encoding", "fvm_shared 2.11.1", @@ -3280,6 +3281,7 @@ dependencies = [ "tracing-subscriber", "unsigned-varint 0.8.0", "url", + "use", "uuid", "walkdir", "zstd", @@ -9763,6 +9765,12 @@ dependencies = [ "serde", ] +[[package]] +name = "use" +version = "0.0.1-pre.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f916b8b6102de89f9999988ddc8e9bd0f119a8344e06bb19b0b03fb655769035" + [[package]] name = "utf8_iter" version = "1.0.4" diff --git a/Cargo.toml b/Cargo.toml index 6250e9da98f8..9357be14e6ec 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -224,10 +224,12 @@ zstd = "0.13" # optional dependencies console-subscriber = { version = "0.4", features = ["parking_lot"], optional = true } +fvm_actor_utils = "14.0.0" paste = "1" tikv-jemallocator = { version = "0.6", optional = true } tracing-chrome = { version = "0.7", optional = true } tracing-loki = { version = "0.2", default-features = false, features = ["compat-0-2-1", "rustls"], optional = true } +use = "0.0.1-pre.0" [target.'cfg(unix)'.dependencies] termios = "0.3" From 31b6839de9fb3056dacda2e27cbbac442eb505b7 Mon Sep 17 00:00:00 2001 From: Aryan Tikarya Date: Tue, 5 Aug 2025 19:55:37 +0530 Subject: [PATCH 02/11] add support for conversion of forest signature from and to fvm_shared4 and fvm_shared3 --- src/shim/crypto.rs | 87 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) diff --git a/src/shim/crypto.rs b/src/shim/crypto.rs index 5b1ad4536d59..d698d247a4c2 100644 --- a/src/shim/crypto.rs +++ b/src/shim/crypto.rs @@ -68,6 +68,93 @@ impl<'de> de::Deserialize<'de> for Signature { } } +impl From for Signature { + fn from(sig: fvm_shared3::crypto::signature::Signature) -> Self { + Self { + sig_type: match sig.sig_type { + fvm_shared3::crypto::signature::SignatureType::BLS => SignatureType::Bls, + fvm_shared3::crypto::signature::SignatureType::Secp256k1 => { + SignatureType::Secp256k1 + } + }, + bytes: sig.bytes, + } + } +} + +impl From for Signature { + fn from(sig: fvm_shared4::crypto::signature::Signature) -> Self { + Self { + sig_type: match sig.sig_type { + fvm_shared4::crypto::signature::SignatureType::BLS => SignatureType::Bls, + fvm_shared4::crypto::signature::SignatureType::Secp256k1 => { + SignatureType::Secp256k1 + } + }, + bytes: sig.bytes, + } + } +} + +impl From for fvm_shared3::crypto::signature::Signature { + fn from(sig: Signature) -> Self { + Self { + sig_type: match sig.sig_type { + SignatureType::Bls => fvm_shared3::crypto::signature::SignatureType::BLS, + SignatureType::Secp256k1 => { + fvm_shared3::crypto::signature::SignatureType::Secp256k1 + } + SignatureType::Delegated => fvm_shared3::crypto::signature::SignatureType::BLS, // fallback v3 doesn't have Delegated + }, + bytes: sig.bytes, + } + } +} + +impl From for Signature { + fn from(sig: fvm_shared2::crypto::signature::Signature) -> Self { + Self { + sig_type: match sig.sig_type { + fvm_shared2::crypto::signature::SignatureType::BLS => SignatureType::Bls, + fvm_shared2::crypto::signature::SignatureType::Secp256k1 => { + SignatureType::Secp256k1 + } + }, + bytes: sig.bytes, + } + } +} + +impl From for fvm_shared2::crypto::signature::Signature { + fn from(sig: Signature) -> Self { + Self { + sig_type: match sig.sig_type { + SignatureType::Bls => fvm_shared2::crypto::signature::SignatureType::BLS, + SignatureType::Secp256k1 => { + fvm_shared2::crypto::signature::SignatureType::Secp256k1 + } + SignatureType::Delegated => fvm_shared2::crypto::signature::SignatureType::BLS, // fallback if v2 doesn't have Delegated + }, + bytes: sig.bytes, + } + } +} + +impl From for fvm_shared4::crypto::signature::Signature { + fn from(sig: Signature) -> Self { + Self { + sig_type: match sig.sig_type { + SignatureType::Bls => fvm_shared4::crypto::signature::SignatureType::BLS, + SignatureType::Secp256k1 => { + fvm_shared4::crypto::signature::SignatureType::Secp256k1 + } + SignatureType::Delegated => fvm_shared4::crypto::signature::SignatureType::BLS, // fallback v4 doesn't have Delegated + }, + bytes: sig.bytes, + } + } +} + impl Signature { pub fn new(sig_type: SignatureType, bytes: Vec) -> Self { Signature { sig_type, bytes } From a5de37caf897ddae52a988f52792581dca8c9e91 Mon Sep 17 00:00:00 2001 From: Aryan Tikarya Date: Tue, 5 Aug 2025 19:56:20 +0530 Subject: [PATCH 03/11] feat: add support for verified reg actor in state decode params API and small refactor --- src/lotus_json/actor_states/methods/mod.rs | 2 + .../methods/verified_reg_actor.rs | 1035 +++++++++++++++++ src/rpc/registry/actors/account.rs | 1 - src/rpc/registry/actors/evm.rs | 1 - src/rpc/registry/actors/init.rs | 1 - src/rpc/registry/actors/miner.rs | 1 - src/rpc/registry/actors/mod.rs | 1 + src/rpc/registry/actors/power.rs | 1 - src/rpc/registry/actors/reward.rs | 1 - src/rpc/registry/actors/verified_reg.rs | 251 ++++ src/rpc/registry/methods_reg.rs | 7 +- 11 files changed, 1294 insertions(+), 8 deletions(-) create mode 100644 src/lotus_json/actor_states/methods/verified_reg_actor.rs create mode 100644 src/rpc/registry/actors/verified_reg.rs diff --git a/src/lotus_json/actor_states/methods/mod.rs b/src/lotus_json/actor_states/methods/mod.rs index f475f0147628..0b5bdca94a81 100644 --- a/src/lotus_json/actor_states/methods/mod.rs +++ b/src/lotus_json/actor_states/methods/mod.rs @@ -1,5 +1,6 @@ // Copyright 2019-2025 ChainSafe Systems // SPDX-License-Identifier: Apache-2.0, MIT + use super::*; mod account_authenticate_params; mod account_constructor_params; @@ -13,3 +14,4 @@ mod miner_constructor_params; mod multisig_actor; mod power_actor; mod reward_methods; +pub mod verified_reg_actor; diff --git a/src/lotus_json/actor_states/methods/verified_reg_actor.rs b/src/lotus_json/actor_states/methods/verified_reg_actor.rs new file mode 100644 index 000000000000..76618b8abff0 --- /dev/null +++ b/src/lotus_json/actor_states/methods/verified_reg_actor.rs @@ -0,0 +1,1035 @@ +// Copyright 2019-2025 ChainSafe Systems +// SPDX-License-Identifier: Apache-2.0, MIT + +use super::*; +use crate::shim::address::Address; +use crate::shim::clock::ChainEpoch; +use crate::shim::crypto::Signature; +use crate::shim::sector::SectorNumber; +use ::cid::Cid; +use fvm_ipld_encoding::RawBytes; +use fvm_shared4::{ActorID, bigint::BigInt}; +use paste::paste; +use serde::{Deserialize, Serialize}; + +#[derive(Serialize, Deserialize, JsonSchema, Debug, Clone, PartialEq)] +#[serde(rename_all = "PascalCase")] +pub struct ConstructorParamsLotusJson( + #[schemars(with = "LotusJson
")] + #[serde(with = "crate::lotus_json")] + Address, +); + +#[derive(Serialize, Deserialize, JsonSchema, Debug, Clone, PartialEq)] +#[serde(rename_all = "PascalCase")] +pub struct VerifierParamsLotusJson { + #[schemars(with = "LotusJson
")] + #[serde(with = "crate::lotus_json")] + pub address: Address, + #[schemars(with = "LotusJson")] + #[serde(with = "crate::lotus_json")] + pub allowance: BigInt, +} + +#[derive(Serialize, Deserialize, JsonSchema, Debug, Clone, PartialEq)] +#[serde(rename_all = "PascalCase")] +pub struct RemoveVerifierParamsLotusJson( + #[schemars(with = "LotusJson
")] + #[serde(with = "crate::lotus_json")] + Address, +); + +#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)] +#[serde(rename_all = "PascalCase")] +pub struct RemoveDataCapParamsLotusJson { + #[serde(with = "crate::lotus_json")] + pub verified_client_to_remove: Address, + #[serde(with = "crate::lotus_json")] + pub data_cap_amount_to_remove: BigInt, + pub verifier_request_1: RemoveDataCapRequestLotusJson, + pub verifier_request_2: RemoveDataCapRequestLotusJson, +} + +#[derive(Serialize, Deserialize, JsonSchema, Debug, Clone, PartialEq)] +#[serde(rename_all = "PascalCase")] +pub struct RemoveDataCapRequestLotusJson { + #[schemars(with = "LotusJson
")] + #[serde(with = "crate::lotus_json")] + pub verifier: Address, + #[schemars(with = "LotusJson")] + #[serde(with = "crate::lotus_json")] + #[serde(rename = "VerifierSignature")] + pub signature: Signature, +} + +#[derive(Serialize, Deserialize, JsonSchema, Debug, Clone, PartialEq)] +#[serde(rename_all = "PascalCase")] +pub struct RemoveExpiredAllocationsParamsLotusJson { + #[schemars(with = "LotusJson")] + #[serde(with = "crate::lotus_json")] + pub client: ActorID, + #[schemars(with = "LotusJson>")] + #[serde(with = "crate::lotus_json")] + pub allocation_ids: Vec, +} + +#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)] +#[serde(rename_all = "PascalCase")] +pub struct ClaimAllocationsParamsLotusJson { + pub sectors: Vec, + pub all_or_nothing: bool, +} + +#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)] +#[serde(rename_all = "PascalCase")] +pub struct SectorAllocationClaimsLotusJson { + #[serde(with = "crate::lotus_json")] + pub sector: SectorNumber, + #[serde(with = "crate::lotus_json")] + #[serde(rename = "SectorExpiry")] + pub expiry: ChainEpoch, + pub claims: Vec, +} + +#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)] +#[serde(rename_all = "PascalCase")] +pub struct AllocationClaimLotusJson { + #[serde(with = "crate::lotus_json")] + pub client: ActorID, + pub allocation_id: u64, + #[serde(with = "crate::lotus_json")] + pub data: Cid, + pub size: u64, +} + +#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)] +#[serde(rename_all = "PascalCase")] +pub struct ClaimAllocationsParamsV11LotusJson { + pub sectors: Vec, + pub all_or_nothing: bool, +} + +#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)] +#[serde(rename_all = "PascalCase")] +pub struct SectorAllocationClaimV11LotusJson { + #[serde(with = "crate::lotus_json")] + pub client: ActorID, + pub allocation_id: u64, + #[serde(with = "crate::lotus_json")] + pub data: Cid, + pub size: u64, + #[serde(with = "crate::lotus_json")] + pub sector: SectorNumber, + #[serde(with = "crate::lotus_json")] + pub sector_expiry: ChainEpoch, +} + +#[derive(Serialize, Deserialize, JsonSchema, Debug, Clone, PartialEq)] +#[serde(rename_all = "PascalCase")] +pub struct GetClaimsParamsLotusJson { + #[schemars(with = "LotusJson")] + #[serde(with = "crate::lotus_json")] + pub provider: ActorID, + #[schemars(with = "LotusJson>")] + #[serde(with = "crate::lotus_json")] + pub claim_ids: Vec, +} + +#[derive(Serialize, Deserialize, JsonSchema, Debug, Clone, PartialEq)] +#[serde(rename_all = "PascalCase")] +pub struct ExtendClaimTermsParamsLotusJson { + pub terms: Vec, +} + +#[derive(Serialize, Deserialize, JsonSchema, Debug, Clone, PartialEq)] +#[serde(rename_all = "PascalCase")] +pub struct ClaimTermLotusJson { + #[schemars(with = "LotusJson")] + #[serde(with = "crate::lotus_json")] + pub provider: ActorID, + pub claim_id: u64, + #[schemars(with = "LotusJson")] + #[serde(with = "crate::lotus_json")] + pub term_max: ChainEpoch, +} + +#[derive(Serialize, Deserialize, JsonSchema, Debug, Clone, PartialEq)] +#[serde(rename_all = "PascalCase")] +pub struct RemoveExpiredClaimsParamsLotusJson { + #[schemars(with = "LotusJson")] + #[serde(with = "crate::lotus_json")] + pub provider: ActorID, + #[schemars(with = "LotusJson>")] + #[serde(with = "crate::lotus_json")] + pub claim_ids: Vec, +} + +#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)] +#[serde(rename_all = "PascalCase")] +pub struct AllocationRequestsLotusJson { + pub allocations: Vec, + pub extensions: Vec, +} + +#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)] +#[serde(rename_all = "PascalCase")] +pub struct AllocationRequestLotusJson { + #[serde(with = "crate::lotus_json")] + pub provider: ActorID, + #[serde(with = "crate::lotus_json")] + pub data: Cid, + pub size: PaddedPieceSize, + #[serde(with = "crate::lotus_json")] + pub term_min: ChainEpoch, + #[serde(with = "crate::lotus_json")] + pub term_max: ChainEpoch, + #[serde(with = "crate::lotus_json")] + pub expiration: ChainEpoch, +} + +#[derive(Serialize, Deserialize, JsonSchema, Debug, Clone, PartialEq)] +#[serde(rename_all = "PascalCase")] +pub struct ClaimExtensionRequestLotusJson { + #[schemars(with = "LotusJson")] + #[serde(with = "crate::lotus_json")] + pub provider: ActorID, + pub claim: u64, + #[schemars(with = "LotusJson")] + #[serde(with = "crate::lotus_json")] + pub term_max: ChainEpoch, +} + +#[derive(Serialize, Deserialize, JsonSchema, Debug, Clone, PartialEq)] +#[serde(rename_all = "PascalCase")] +pub struct UniversalReceiverParamsLotusJson { + #[serde(rename = "Type_")] + pub type_: u32, + #[schemars(with = "LotusJson")] + #[serde(with = "crate::lotus_json")] + pub payload: RawBytes, +} + +#[derive(Serialize, Deserialize, JsonSchema, Debug, Clone, PartialEq)] +#[serde(rename_all = "PascalCase")] +pub struct BytesParamsLotusJson { + #[schemars(with = "LotusJson
")] + #[serde(with = "crate::lotus_json")] + pub address: Address, + #[schemars(with = "LotusJson")] + #[serde(with = "crate::lotus_json")] + pub deal_size: BigInt, +} + +macro_rules! impl_constructor_params { + ($($version:literal),+) => { + $( + paste! { + impl HasLotusJson for fil_actor_verifreg_state::[]::ConstructorParams { + type LotusJson = ConstructorParamsLotusJson; + + #[cfg(test)] + fn snapshots() -> Vec<(serde_json::Value, Self)> { + vec![( + json!({ + "RootKey": "f01234", + }), + Self { + root_key: Address::new_id(1234).into(), + }, + )] + } + + fn into_lotus_json(self) -> Self::LotusJson { + ConstructorParamsLotusJson(self.root_key.into()) + } + + fn from_lotus_json(lotus_json: Self::LotusJson) -> Self { + Self { + root_key: lotus_json.0.into(), + } + } + } + } + )+ + }; +} + +macro_rules! impl_verifier_params { + ($($version:literal),+) => { + $( + paste! { + impl HasLotusJson for fil_actor_verifreg_state::[]::VerifierParams { + type LotusJson = VerifierParamsLotusJson; + + #[cfg(test)] + fn snapshots() -> Vec<(serde_json::Value, Self)> { + vec![( + json!({ + "Address": "f01234", + "Allowance": "1000000000000000000", + }), + Self { + address: Address::new_id(1234).into(), + allowance: BigInt::from(1000000000000000000u64), + }, + )] + } + + fn into_lotus_json(self) -> Self::LotusJson { + VerifierParamsLotusJson { + address: self.address.into(), + allowance: self.allowance, + } + } + + fn from_lotus_json(lotus_json: Self::LotusJson) -> Self { + Self { + address: lotus_json.address.into(), + allowance: lotus_json.allowance, + } + } + } + } + )+ + }; +} + +// Implementation for RemoveVerifierParams +macro_rules! impl_remove_verifier_params { + ($($version:literal),+) => { + $( + paste! { + impl HasLotusJson for fil_actor_verifreg_state::[]::RemoveVerifierParams { + type LotusJson = RemoveVerifierParamsLotusJson; + + #[cfg(test)] + fn snapshots() -> Vec<(serde_json::Value, Self)> { + vec![( + json!({ + "Verifier": "f01234", + }), + Self { + verifier: Address::new_id(1234).into(), + }, + )] + } + + fn into_lotus_json(self) -> Self::LotusJson { + RemoveVerifierParamsLotusJson(self.verifier.into()) + } + + fn from_lotus_json(lotus_json: Self::LotusJson) -> Self { + Self { + verifier: lotus_json.0.into(), + } + } + } + } + )+ + }; +} + +// Implementation for RemoveExpiredAllocationsParams +macro_rules! impl_remove_expired_allocations_params { + ($($version:literal),+) => { + $( + paste! { + impl HasLotusJson for fil_actor_verifreg_state::[]::RemoveExpiredAllocationsParams { + type LotusJson = RemoveExpiredAllocationsParamsLotusJson; + + #[cfg(test)] + fn snapshots() -> Vec<(serde_json::Value, Self)> { + vec![( + json!({ + "Client": 1001, + "AllocationIds": [1, 2, 3], + }), + Self { + client: 1001, + allocation_ids: vec![1, 2, 3], + }, + )] + } + + fn into_lotus_json(self) -> Self::LotusJson { + RemoveExpiredAllocationsParamsLotusJson { + client: self.client, + allocation_ids: self.allocation_ids, + } + } + + fn from_lotus_json(lotus_json: Self::LotusJson) -> Self { + Self { + client: lotus_json.client, + allocation_ids: lotus_json.allocation_ids, + } + } + } + } + )+ + }; +} + +// Implementation for GetClaimsParams +macro_rules! impl_get_claims_params { + ($($version:literal),+) => { + $( + paste! { + impl HasLotusJson for fil_actor_verifreg_state::[]::GetClaimsParams { + type LotusJson = GetClaimsParamsLotusJson; + + #[cfg(test)] + fn snapshots() -> Vec<(serde_json::Value, Self)> { + vec![( + json!({ + "Provider": 1001, + "ClaimIds": [1, 2, 3], + }), + Self { + provider: 1001, + claim_ids: vec![1, 2, 3], + }, + )] + } + + fn into_lotus_json(self) -> Self::LotusJson { + GetClaimsParamsLotusJson { + provider: self.provider, + claim_ids: self.claim_ids, + } + } + + fn from_lotus_json(lotus_json: Self::LotusJson) -> Self { + Self { + provider: lotus_json.provider, + claim_ids: lotus_json.claim_ids, + } + } + } + } + )+ + }; +} + +// Implementation for RemoveExpiredClaimsParams +macro_rules! impl_remove_expired_claims_params { + ($($version:literal),+) => { + $( + paste! { + impl HasLotusJson for fil_actor_verifreg_state::[]::RemoveExpiredClaimsParams { + type LotusJson = RemoveExpiredClaimsParamsLotusJson; + + #[cfg(test)] + fn snapshots() -> Vec<(serde_json::Value, Self)> { + vec![( + json!({ + "Provider": 1001, + "ClaimIds": [1, 2, 3], + }), + Self { + provider: 1001, + claim_ids: vec![1, 2, 3], + }, + )] + } + + fn into_lotus_json(self) -> Self::LotusJson { + RemoveExpiredClaimsParamsLotusJson { + provider: self.provider, + claim_ids: self.claim_ids, + } + } + + fn from_lotus_json(lotus_json: Self::LotusJson) -> Self { + Self { + provider: lotus_json.provider, + claim_ids: lotus_json.claim_ids, + } + } + } + } + )+ + }; +} + +// Implementation for UniversalReceiverParams (not version-specific) +impl HasLotusJson for fvm_actor_utils::receiver::UniversalReceiverParams { + type LotusJson = UniversalReceiverParamsLotusJson; + + #[cfg(test)] + fn snapshots() -> Vec<(serde_json::Value, Self)> { + vec![( + json!({ + "Type": 1, + "Payload": "dGVzdCBwYXlsb2Fk", + }), + Self { + type_: 1, + payload: RawBytes::new(b"test payload".to_vec()), + }, + )] + } + + fn into_lotus_json(self) -> Self::LotusJson { + UniversalReceiverParamsLotusJson { + type_: self.type_, + payload: self.payload, + } + } + + fn from_lotus_json(lotus_json: Self::LotusJson) -> Self { + Self { + type_: lotus_json.type_, + payload: lotus_json.payload, + } + } +} + +// Implementation for ExtendClaimTermsParams +macro_rules! impl_extend_claim_terms_params { + ($($version:literal),+) => { + $( + paste! { + impl HasLotusJson for fil_actor_verifreg_state::[]::ExtendClaimTermsParams { + type LotusJson = ExtendClaimTermsParamsLotusJson; + + #[cfg(test)] + fn snapshots() -> Vec<(serde_json::Value, Self)> { + vec![( + json!({ + "Terms": [ + { + "Provider": 1001, + "ClaimId": 1, + "TermMax": 12345, + } + ], + }), + Self { + terms: vec![fil_actor_verifreg_state::[]::ClaimTerm { + provider: 1001, + claim_id: 1, + term_max: 12345, + }], + }, + )] + } + + fn into_lotus_json(self) -> Self::LotusJson { + ExtendClaimTermsParamsLotusJson { + terms: self + .terms + .into_iter() + .map(|term| ClaimTermLotusJson { + provider: term.provider, + claim_id: term.claim_id, + term_max: term.term_max, + }) + .collect(), + } + } + + fn from_lotus_json(lotus_json: Self::LotusJson) -> Self { + Self { + terms: lotus_json + .terms + .into_iter() + .map(|term| fil_actor_verifreg_state::[]::ClaimTerm { + provider: term.provider, + claim_id: term.claim_id, + term_max: term.term_max, + }) + .collect(), + } + } + } + } + )+ + }; +} + +// Implementation for RemoveDataCapParams (unified for all versions) +macro_rules! impl_remove_data_cap_params { + ($type_suffix:path: $($version:literal),+) => { + $( + paste! { + impl HasLotusJson for fil_actor_verifreg_state::[]::RemoveDataCapParams { + type LotusJson = RemoveDataCapParamsLotusJson; + + #[cfg(test)] + fn snapshots() -> Vec<(serde_json::Value, Self)> { + vec![( + json!({ + "VerifiedClientToRemove": "f01234", + "DataCapAmountToRemove": "1000000000000000000", + "VerifierRequest1": { + "Verifier": "f01235", + "Signature": { + "Type": 1, + "Data": "dGVzdA==", + } + }, + "VerifierRequest2": { + "Verifier": "f01236", + "Signature": { + "Type": 1, + "Data": "dGVzdA==", + } + }, + }), + Self { + verified_client_to_remove: Address::new_id(1234).into(), + data_cap_amount_to_remove: BigInt::from(1000000000000000000u64), + verifier_request_1: fil_actor_verifreg_state::[]::RemoveDataCapRequest { + verifier: Address::new_id(1235).into(), + signature: $type_suffix::signature::Signature::new_bls(b"test".to_vec()), + }, + verifier_request_2: fil_actor_verifreg_state::[]::RemoveDataCapRequest { + verifier: Address::new_id(1236).into(), + signature: $type_suffix::signature::Signature::new_bls(b"test".to_vec()), + }, + }, + )] + } + + fn into_lotus_json(self) -> Self::LotusJson { + RemoveDataCapParamsLotusJson { + verified_client_to_remove: self.verified_client_to_remove.into(), + data_cap_amount_to_remove: self.data_cap_amount_to_remove, + verifier_request_1: RemoveDataCapRequestLotusJson { + verifier: self.verifier_request_1.verifier.into(), + signature: self.verifier_request_1.signature.into(), + }, + verifier_request_2: RemoveDataCapRequestLotusJson { + verifier: self.verifier_request_2.verifier.into(), + signature: self.verifier_request_2.signature.into() + }, + } + } + + fn from_lotus_json(lotus_json: Self::LotusJson) -> Self { + Self { + verified_client_to_remove: lotus_json.verified_client_to_remove.into(), + data_cap_amount_to_remove: lotus_json.data_cap_amount_to_remove, + verifier_request_1: fil_actor_verifreg_state::[]::RemoveDataCapRequest { + verifier: lotus_json.verifier_request_1.verifier.into(), + signature: lotus_json.verifier_request_1.signature.into(), + }, + verifier_request_2: fil_actor_verifreg_state::[]::RemoveDataCapRequest { + verifier: lotus_json.verifier_request_2.verifier.into(), + signature: lotus_json.verifier_request_2.signature.into() + }, + } + } + } + } + )+ + }; +} + +// Implementation for ClaimAllocationsParams (v12-v16 with nested structure) +macro_rules! impl_claim_allocations_params_v12_plus { + ($type_suffix:path: $($version:literal),+) => { + $( + paste! { + impl HasLotusJson for fil_actor_verifreg_state::[]::ClaimAllocationsParams { + type LotusJson = ClaimAllocationsParamsLotusJson; + + #[cfg(test)] + fn snapshots() -> Vec<(serde_json::Value, Self)> { + vec![( + json!({ + "Sectors": [ + { + "Sector": 1, + "Expiry": 12345, + "Claims": [ + { + "Client": 1001, + "AllocationId": 1, + "Data": {"/": "bafk2bzacedbdmwqy4jrh4tgm7l77vz5fxb27jgmb2xkuprzzudbe2xj5u2nzm"}, + "Size": 2048, + } + ], + } + ], + "AllOrNothing": true, + }), + Self { + sectors: vec![fil_actor_verifreg_state::[]::SectorAllocationClaims { + sector: 1, + expiry: 12345, + claims: vec![fil_actor_verifreg_state::[]::AllocationClaim { + client: 1001, + allocation_id: 1, + data: Cid::try_from( + "bafk2bzacedbdmwqy4jrh4tgm7l77vz5fxb27jgmb2xkuprzzudbe2xj5u2nzm", + ) + .unwrap(), + size: $type_suffix::piece::PaddedPieceSize(2048), + }], + }], + all_or_nothing: true, + }, + )] + } + + fn into_lotus_json(self) -> Self::LotusJson { + ClaimAllocationsParamsLotusJson { + sectors: self + .sectors + .into_iter() + .map(|sector| SectorAllocationClaimsLotusJson { + sector: sector.sector, + expiry: sector.expiry, + claims: sector + .claims + .into_iter() + .map(|claim| AllocationClaimLotusJson { + client: claim.client, + allocation_id: claim.allocation_id, + data: claim.data, + size: claim.size.0, + }) + .collect(), + }) + .collect(), + all_or_nothing: self.all_or_nothing, + } + } + + fn from_lotus_json(lotus_json: Self::LotusJson) -> Self { + Self { + sectors: lotus_json + .sectors + .into_iter() + .map( + |sector| fil_actor_verifreg_state::[]::SectorAllocationClaims { + sector: sector.sector, + expiry: sector.expiry, + claims: sector + .claims + .into_iter() + .map(|claim| fil_actor_verifreg_state::[]::AllocationClaim { + client: claim.client, + allocation_id: claim.allocation_id, + data: claim.data, + size: $type_suffix::piece::PaddedPieceSize(claim.size), + }) + .collect(), + }, + ) + .collect(), + all_or_nothing: lotus_json.all_or_nothing, + } + } + } + } + )+ + }; +} + +// Implementation for ClaimAllocationsParams (v9-v11 with flat structure) +macro_rules! impl_claim_allocations_params_v11 { + ($type_suffix:path: $($version:literal),+) => { + $( + paste! { + impl HasLotusJson for fil_actor_verifreg_state::[]::ClaimAllocationsParams { + type LotusJson = ClaimAllocationsParamsV11LotusJson; + + #[cfg(test)] + fn snapshots() -> Vec<(serde_json::Value, Self)> { + vec![( + json!({ + "Sectors": [ + { + "Client": 1001, + "AllocationId": 1, + "Data": {"/": "bafk2bzacedbdmwqy4jrh4tgm7l77vz5fxb27jgmb2xkuprzzudbe2xj5u2nzm"}, + "Size": 2048, + "Sector": 1, + "SectorExpiry": 12345, + } + ], + "AllOrNothing": true, + }), + Self { + sectors: vec![fil_actor_verifreg_state::[]::SectorAllocationClaim { + client: 1001, + allocation_id: 1, + data: Cid::try_from( + "bafk2bzacedbdmwqy4jrh4tgm7l77vz5fxb27jgmb2xkuprzzudbe2xj5u2nzm", + ) + .unwrap(), + size: $type_suffix::piece::PaddedPieceSize(2048), + sector: 1, + sector_expiry: 12345, + }], + all_or_nothing: true, + }, + )] + } + + fn into_lotus_json(self) -> Self::LotusJson { + ClaimAllocationsParamsV11LotusJson { + sectors: self + .sectors + .into_iter() + .map(|sector| SectorAllocationClaimV11LotusJson { + client: sector.client, + allocation_id: sector.allocation_id, + data: sector.data, + size: sector.size.0, + sector: sector.sector, + sector_expiry: sector.sector_expiry, + }) + .collect(), + all_or_nothing: self.all_or_nothing, + } + } + + fn from_lotus_json(lotus_json: Self::LotusJson) -> Self { + Self { + sectors: lotus_json + .sectors + .into_iter() + .map(|sector| fil_actor_verifreg_state::[]::SectorAllocationClaim { + client: sector.client, + allocation_id: sector.allocation_id, + data: sector.data, + size: $type_suffix::piece::PaddedPieceSize(sector.size), + sector: sector.sector, + sector_expiry: sector.sector_expiry, + }) + .collect(), + all_or_nothing: lotus_json.all_or_nothing, + } + } + } + } + )+ + }; +} + +// Implementation for AllocationRequests (unified for all versions) +macro_rules! impl_allocation_requests { + ($type_suffix:path: $($version:literal),+) => { + $( + paste! { + impl HasLotusJson for fil_actor_verifreg_state::[]::AllocationRequests { + type LotusJson = AllocationRequestsLotusJson; + + #[cfg(test)] + fn snapshots() -> Vec<(serde_json::Value, Self)> { + vec![( + json!({ + "Allocations": [ + { + "Provider": 1001, + "Data": {"/": "bafk2bzacedbdmwqy4jrh4tgm7l77vz5fxb27jgmb2xkuprzzudbe2xj5u2nzm"}, + "Size": 2048, + "TermMin": 1000, + "TermMax": 2000, + "Expiration": 12345, + } + ], + "Extensions": [ + { + "Provider": 1002, + "Claim": 1, + "TermMax": 3000, + } + ], + }), + Self { + allocations: vec![fil_actor_verifreg_state::[]::AllocationRequest { + provider: 1001, + data: Cid::try_from( + "bafk2bzacedbdmwqy4jrh4tgm7l77vz5fxb27jgmb2xkuprzzudbe2xj5u2nzm", + ) + .unwrap(), + size: $type_suffix::piece::PaddedPieceSize(2048), + term_min: 1000, + term_max: 2000, + expiration: 12345, + }], + extensions: vec![fil_actor_verifreg_state::[]::ClaimExtensionRequest { + provider: 1002, + claim: 1, + term_max: 3000, + }], + }, + )] + } + + fn into_lotus_json(self) -> Self::LotusJson { + AllocationRequestsLotusJson { + allocations: self + .allocations + .into_iter() + .map(|alloc| AllocationRequestLotusJson { + provider: alloc.provider, + data: alloc.data, + size: PaddedPieceSize(alloc.size.0), + term_min: alloc.term_min, + term_max: alloc.term_max, + expiration: alloc.expiration, + }) + .collect(), + extensions: self + .extensions + .into_iter() + .map(|ext| ClaimExtensionRequestLotusJson { + provider: ext.provider, + claim: ext.claim, + term_max: ext.term_max, + }) + .collect(), + } + } + + fn from_lotus_json(lotus_json: Self::LotusJson) -> Self { + Self { + allocations: lotus_json + .allocations + .into_iter() + .map(|alloc| fil_actor_verifreg_state::[]::AllocationRequest { + provider: alloc.provider, + data: alloc.data, + size: $type_suffix::piece::PaddedPieceSize(alloc.size.0), + term_min: alloc.term_min, + term_max: alloc.term_max, + expiration: alloc.expiration, + }) + .collect(), + extensions: lotus_json + .extensions + .into_iter() + .map(|ext| fil_actor_verifreg_state::[]::ClaimExtensionRequest { + provider: ext.provider, + claim: ext.claim, + term_max: ext.term_max, + }) + .collect(), + } + } + } + } + )+ + }; +} + +// v8 has unique BytesParams for UseBytes/RestoreBytes methods +impl HasLotusJson for fil_actor_verifreg_state::v8::BytesParams { + type LotusJson = BytesParamsLotusJson; + + #[cfg(test)] + fn snapshots() -> Vec<(serde_json::Value, Self)> { + vec![( + json!({ + "Address": "f01234", + "DealSize": "1048576", // 1MB + }), + Self { + address: Address::new_id(1234).into(), + deal_size: BigInt::from(1048576u64), + }, + )] + } + + fn into_lotus_json(self) -> Self::LotusJson { + BytesParamsLotusJson { + address: self.address.into(), + deal_size: self.deal_size, + } + } + + fn from_lotus_json(lotus_json: Self::LotusJson) -> Self { + Self { + address: lotus_json.address.into(), + deal_size: lotus_json.deal_size, + } + } +} + +impl HasLotusJson for fil_actor_verifreg_state::v8::VerifierParams { + type LotusJson = VerifierParamsLotusJson; + + #[cfg(test)] + fn snapshots() -> Vec<(serde_json::Value, Self)> { + vec![( + json!({ + "Address": "f01234", + "Allowance": "1000000000000000000", + }), + Self { + address: Address::new_id(1234).into(), + allowance: BigInt::from(1000000000000000000u64), + }, + )] + } + + fn into_lotus_json(self) -> Self::LotusJson { + VerifierParamsLotusJson { + address: self.address.into(), + allowance: self.allowance, + } + } + + fn from_lotus_json(lotus_json: Self::LotusJson) -> Self { + Self { + address: lotus_json.address.into(), + allowance: lotus_json.allowance, + } + } +} + +impl HasLotusJson for fil_actor_verifreg_state::v9::AddVerifierClientParams { + type LotusJson = VerifierParamsLotusJson; + + #[cfg(test)] + fn snapshots() -> Vec<(serde_json::Value, Self)> { + vec![( + json!({ + "Address": "f01234", + "Allowance": "1000000000000000000", + }), + Self { + address: Address::new_id(1234).into(), + allowance: BigInt::from(1000000000000000000u64), + }, + )] + } + + fn into_lotus_json(self) -> Self::LotusJson { + VerifierParamsLotusJson { + address: self.address.into(), + allowance: self.allowance, + } + } + + fn from_lotus_json(lotus_json: Self::LotusJson) -> Self { + Self { + address: lotus_json.address.into(), + allowance: lotus_json.allowance, + } + } +} + +impl_constructor_params!(11, 12, 13, 14, 15, 16); +impl_verifier_params!(10, 11, 12, 13, 14, 15, 16); // Exclude v8,v9 due to different param names +impl_remove_verifier_params!(11, 12, 13, 14, 15, 16); +impl_remove_expired_allocations_params!(9, 10, 11, 12, 13, 14, 15, 16); +impl_get_claims_params!(9, 10, 11, 12, 13, 14, 15, 16); +impl_remove_expired_claims_params!(9, 10, 11, 12, 13, 14, 15, 16); +impl_extend_claim_terms_params!(9, 10, 11, 12, 13, 14, 15, 16); + +impl_remove_data_cap_params!(fvm_shared2::crypto: 8, 9); +impl_remove_data_cap_params!(fvm_shared3::crypto: 10, 11); +impl_remove_data_cap_params!(fvm_shared4::crypto: 12, 13, 14, 15, 16); + +impl_claim_allocations_params_v11!(fvm_shared2: 9); +impl_claim_allocations_params_v11!(fvm_shared3: 10, 11); +impl_claim_allocations_params_v12_plus!(fvm_shared4: 12, 13, 14, 15, 16); +impl_allocation_requests!(fvm_shared4: 12, 13, 14, 15, 16); +impl_allocation_requests!(fvm_shared3: 11); diff --git a/src/rpc/registry/actors/account.rs b/src/rpc/registry/actors/account.rs index d44574645293..dce848fa62a4 100644 --- a/src/rpc/registry/actors/account.rs +++ b/src/rpc/registry/actors/account.rs @@ -3,7 +3,6 @@ use crate::rpc::registry::methods_reg::{MethodRegistry, register_actor_methods}; use crate::shim::message::MethodNum; -use anyhow::Result; use cid::Cid; /// Macro to generate account method registration for different versions diff --git a/src/rpc/registry/actors/evm.rs b/src/rpc/registry/actors/evm.rs index 618093c5d731..99114b21a339 100644 --- a/src/rpc/registry/actors/evm.rs +++ b/src/rpc/registry/actors/evm.rs @@ -3,7 +3,6 @@ use crate::rpc::registry::methods_reg::{MethodRegistry, register_actor_methods}; use crate::shim::message::MethodNum; -use anyhow::Result; use cid::Cid; macro_rules! register_evm_version { diff --git a/src/rpc/registry/actors/init.rs b/src/rpc/registry/actors/init.rs index 18939c822b2c..af06ef04c449 100644 --- a/src/rpc/registry/actors/init.rs +++ b/src/rpc/registry/actors/init.rs @@ -3,7 +3,6 @@ use crate::rpc::registry::methods_reg::{MethodRegistry, register_actor_methods}; use crate::shim::message::MethodNum; -use anyhow::Result; use cid::Cid; // Macro for versions 8-10 that only have Exec method diff --git a/src/rpc/registry/actors/miner.rs b/src/rpc/registry/actors/miner.rs index cc4f0a59624e..c5deaca03092 100644 --- a/src/rpc/registry/actors/miner.rs +++ b/src/rpc/registry/actors/miner.rs @@ -3,7 +3,6 @@ use crate::rpc::registry::methods_reg::{MethodRegistry, register_actor_methods}; use crate::shim::message::MethodNum; -use anyhow::Result; use cid::Cid; macro_rules! register_miner_version { diff --git a/src/rpc/registry/actors/mod.rs b/src/rpc/registry/actors/mod.rs index da5178093ad9..4d7f8535d6fd 100644 --- a/src/rpc/registry/actors/mod.rs +++ b/src/rpc/registry/actors/mod.rs @@ -10,3 +10,4 @@ pub(crate) mod multisig; pub(crate) mod power; pub(crate) mod reward; pub(crate) mod system; +pub(crate) mod verified_reg; diff --git a/src/rpc/registry/actors/power.rs b/src/rpc/registry/actors/power.rs index 64a1224ac2b6..50b0a1b06472 100644 --- a/src/rpc/registry/actors/power.rs +++ b/src/rpc/registry/actors/power.rs @@ -3,7 +3,6 @@ use crate::rpc::registry::methods_reg::{MethodRegistry, register_actor_methods}; use crate::shim::message::MethodNum; -use anyhow::Result; use cid::Cid; // Macro for versions 8-9 that have limited methods diff --git a/src/rpc/registry/actors/reward.rs b/src/rpc/registry/actors/reward.rs index f5e6ca51f0ae..344459dc94d0 100644 --- a/src/rpc/registry/actors/reward.rs +++ b/src/rpc/registry/actors/reward.rs @@ -3,7 +3,6 @@ use crate::rpc::registry::methods_reg::{MethodRegistry, register_actor_methods}; use crate::shim::message::MethodNum; -use anyhow::Result; use cid::Cid; macro_rules! register_reward_version_11_to_16 { diff --git a/src/rpc/registry/actors/verified_reg.rs b/src/rpc/registry/actors/verified_reg.rs new file mode 100644 index 000000000000..719b789fad62 --- /dev/null +++ b/src/rpc/registry/actors/verified_reg.rs @@ -0,0 +1,251 @@ +// Copyright 2019-2025 ChainSafe Systems +// SPDX-License-Identifier: Apache-2.0, MIT + +use crate::rpc::registry::methods_reg::{MethodRegistry, register_actor_methods}; +use crate::shim::address::Address; +use crate::shim::message::MethodNum; +use cid::Cid; +use paste::paste; + +// Core methods present in all versions +macro_rules! register_core_methods { + ($registry:expr, $cid:expr, v8) => {{ + use fil_actor_verifreg_state::v8::{Method, RemoveDataCapParams, VerifierParams}; + register_actor_methods!( + $registry, + $cid, + [ + (Method::Constructor, Address), + (Method::AddVerifier, VerifierParams), + (Method::RemoveVerifier, Address), + (Method::AddVerifiedClient, VerifierParams), + (Method::RemoveVerifiedClientDataCap, RemoveDataCapParams), + ] + ); + }}; + + ($registry:expr, $cid:expr, v9) => {{ + use fil_actor_verifreg_state::v9::{ + AddVerifierClientParams, AddVerifierParams, Method, RemoveDataCapParams, + }; + register_actor_methods!( + $registry, + $cid, + [ + (Method::Constructor, Address), + (Method::AddVerifier, AddVerifierParams), + (Method::RemoveVerifier, Address), + (Method::AddVerifiedClient, AddVerifierClientParams), + (Method::RemoveVerifiedClientDataCap, RemoveDataCapParams), + ] + ); + }}; + + ($registry:expr, $cid:expr, v10) => {{ + use fil_actor_verifreg_state::v10::{ + AddVerifiedClientParams, AddVerifierParams, Method, RemoveDataCapParams, + }; + register_actor_methods!( + $registry, + $cid, + [ + (Method::Constructor, Address), + (Method::AddVerifier, AddVerifierParams), + (Method::RemoveVerifier, Address), + (Method::AddVerifiedClient, AddVerifiedClientParams), + (Method::RemoveVerifiedClientDataCap, RemoveDataCapParams), + ] + ); + }}; + + ($registry:expr, $cid:expr, $state_version:path) => {{ + use $state_version::{ + AddVerifiedClientParams, AddVerifierParams, ConstructorParams, Method, + RemoveDataCapParams, RemoveVerifierParams, + }; + register_actor_methods!( + $registry, + $cid, + [ + (Method::Constructor, ConstructorParams), + (Method::AddVerifier, AddVerifierParams), + (Method::RemoveVerifier, RemoveVerifierParams), + (Method::AddVerifiedClient, AddVerifiedClientParams), + (Method::RemoveVerifiedClientDataCap, RemoveDataCapParams), + ] + ); + }}; +} + +// unique methods (UseBytes/RestoreBytes) +macro_rules! register_v8_unique_methods { + ($registry:expr, $cid:expr) => {{ + use fil_actor_verifreg_state::v8::{BytesParams, Method}; + register_actor_methods!( + $registry, + $cid, + [ + (Method::UseBytes, BytesParams), + (Method::RestoreBytes, BytesParams), + ] + ); + }}; +} + +// Allocation/Claims methods +macro_rules! register_allocation_methods { + ($registry:expr, $cid:expr, v9) => {{ + use fil_actor_verifreg_state::v9::{ + ClaimAllocationsParams, ExtendClaimTermsParams, GetClaimsParams, Method, + RemoveExpiredAllocationsParams, RemoveExpiredClaimsParams, + }; + register_actor_methods!( + $registry, + $cid, + [ + ( + Method::RemoveExpiredAllocations, + RemoveExpiredAllocationsParams + ), + (Method::ClaimAllocations, ClaimAllocationsParams), + (Method::GetClaims, GetClaimsParams), + (Method::ExtendClaimTerms, ExtendClaimTermsParams), + (Method::RemoveExpiredClaims, RemoveExpiredClaimsParams), + ] + ); + }}; + + ($registry:expr, $cid:expr, $state_version:path, no_claim) => {{ + use $state_version::{ + ExtendClaimTermsParams, GetClaimsParams, Method, RemoveExpiredAllocationsParams, + RemoveExpiredClaimsParams, + }; + register_actor_methods!( + $registry, + $cid, + [ + ( + Method::RemoveExpiredAllocations, + RemoveExpiredAllocationsParams + ), + (Method::GetClaims, GetClaimsParams), + (Method::ExtendClaimTerms, ExtendClaimTermsParams), + (Method::RemoveExpiredClaims, RemoveExpiredClaimsParams), + ] + ); + }}; + + ($registry:expr, $cid:expr, $state_version:path) => {{ + use $state_version::{ + ClaimAllocationsParams, ExtendClaimTermsParams, GetClaimsParams, Method, + RemoveExpiredAllocationsParams, RemoveExpiredClaimsParams, + }; + register_actor_methods!( + $registry, + $cid, + [ + ( + Method::RemoveExpiredAllocations, + RemoveExpiredAllocationsParams + ), + (Method::ClaimAllocations, ClaimAllocationsParams), + (Method::GetClaims, GetClaimsParams), + (Method::ExtendClaimTerms, ExtendClaimTermsParams), + (Method::RemoveExpiredClaims, RemoveExpiredClaimsParams), + ] + ); + }}; +} + +macro_rules! register_exported_methods { + ($registry:expr, $cid:expr, $state_version:path) => {{ + use $state_version::{ + AddVerifiedClientParams, ExtendClaimTermsParams, GetClaimsParams, Method, + RemoveExpiredAllocationsParams, RemoveExpiredClaimsParams, + }; + register_actor_methods!( + $registry, + $cid, + [ + (Method::AddVerifiedClientExported, AddVerifiedClientParams), + ( + Method::RemoveExpiredAllocationsExported, + RemoveExpiredAllocationsParams + ), + (Method::GetClaimsExported, GetClaimsParams), + (Method::ExtendClaimTermsExported, ExtendClaimTermsParams), + ( + Method::RemoveExpiredClaimsExported, + RemoveExpiredClaimsParams + ), + ] + ); + }}; +} + +macro_rules! register_universal_receiver_hook { + ($registry:expr, $cid:expr, $version:tt) => { + paste! { + { + use fil_actor_verifreg_state::[<$version>]::Method; + register_actor_methods!( + $registry, + $cid, + [( + Method::UniversalReceiverHook, + fvm_actor_utils::receiver::UniversalReceiverParams + ),] + ); + } + } + }; +} + +fn register_verified_reg_v8(registry: &mut MethodRegistry, cid: Cid) { + register_core_methods!(registry, cid, v8); + register_v8_unique_methods!(registry, cid); +} + +fn register_verified_reg_v9(registry: &mut MethodRegistry, cid: Cid) { + register_core_methods!(registry, cid, v9); + register_allocation_methods!(registry, cid, v9); + register_universal_receiver_hook!(registry, cid, v9); +} + +fn register_verified_reg_v10(registry: &mut MethodRegistry, cid: Cid) { + register_core_methods!(registry, cid, v10); + register_allocation_methods!(registry, cid, fil_actor_verifreg_state::v10, no_claim); + register_exported_methods!(registry, cid, fil_actor_verifreg_state::v10); + register_universal_receiver_hook!(registry, cid, v10); +} + +fn register_verified_reg_v11(registry: &mut MethodRegistry, cid: Cid) { + register_core_methods!(registry, cid, fil_actor_verifreg_state::v11); + register_allocation_methods!(registry, cid, fil_actor_verifreg_state::v11, no_claim); + register_exported_methods!(registry, cid, fil_actor_verifreg_state::v11); + register_universal_receiver_hook!(registry, cid, v11); +} + +macro_rules! register_verified_reg_v12_plus { + ($registry:expr, $cid:expr, $state_version:path, $version:tt) => {{ + register_core_methods!($registry, $cid, $state_version); + register_allocation_methods!($registry, $cid, $state_version); + register_exported_methods!($registry, $cid, $state_version); + register_universal_receiver_hook!($registry, $cid, $version); + }}; +} + +pub(crate) fn register_actor_methods(registry: &mut MethodRegistry, cid: Cid, version: u64) { + match version { + 8 => register_verified_reg_v8(registry, cid), + 9 => register_verified_reg_v9(registry, cid), + 10 => register_verified_reg_v10(registry, cid), + 11 => register_verified_reg_v11(registry, cid), + 12 => register_verified_reg_v12_plus!(registry, cid, fil_actor_verifreg_state::v12, v12), + 13 => register_verified_reg_v12_plus!(registry, cid, fil_actor_verifreg_state::v13, v13), + 14 => register_verified_reg_v12_plus!(registry, cid, fil_actor_verifreg_state::v14, v14), + 15 => register_verified_reg_v12_plus!(registry, cid, fil_actor_verifreg_state::v15, v15), + 16 => register_verified_reg_v12_plus!(registry, cid, fil_actor_verifreg_state::v16, v16), + _ => {} + } +} diff --git a/src/rpc/registry/methods_reg.rs b/src/rpc/registry/methods_reg.rs index c8fc478514df..469590f68731 100644 --- a/src/rpc/registry/methods_reg.rs +++ b/src/rpc/registry/methods_reg.rs @@ -74,7 +74,7 @@ impl MethodRegistry { fn register_known_methods(&mut self) { use crate::rpc::registry::actors::{ - account, datacap, evm, init, miner, multisig, power, reward, system, + account, datacap, evm, init, miner, multisig, power, reward, system, verified_reg }; for (&cid, &(actor_type, version)) in ACTOR_REGISTRY.iter() { @@ -92,6 +92,9 @@ impl MethodRegistry { BuiltinActor::Power => power::register_actor_methods(self, cid, version), BuiltinActor::Reward => reward::register_actor_methods(self, cid, version), BuiltinActor::Multisig => multisig::register_actor_methods(self, cid, version), + BuiltinActor::VerifiedRegistry => { + verified_reg::register_actor_methods(self, cid, version) + } _ => {} } } @@ -135,7 +138,7 @@ macro_rules! register_actor_methods { $registry.register_method( $code_cid, $method as MethodNum, - |bytes| -> Result<$param_type> { Ok(fvm_ipld_encoding::from_slice(bytes)?) }, + |bytes| -> anyhow::Result<$param_type> { Ok(fvm_ipld_encoding::from_slice(bytes)?) }, ); )* }; From ece9a2cdb85b233004596deac71cb671376d373d Mon Sep 17 00:00:00 2001 From: Aryan Tikarya Date: Tue, 5 Aug 2025 19:56:41 +0530 Subject: [PATCH 04/11] add test for verified reg state decode params api --- .../subcommands/api_cmd/api_compare_tests.rs | 187 ++++++++++++++++++ .../subcommands/api_cmd/test_snapshots.txt | 12 ++ 2 files changed, 199 insertions(+) diff --git a/src/tool/subcommands/api_cmd/api_compare_tests.rs b/src/tool/subcommands/api_cmd/api_compare_tests.rs index 542abb71e73f..8d4a7fd5aad3 100644 --- a/src/tool/subcommands/api_cmd/api_compare_tests.rs +++ b/src/tool/subcommands/api_cmd/api_compare_tests.rs @@ -1940,6 +1940,97 @@ fn state_decode_params_api_tests(tipset: &Tipset) -> anyhow::Result amount: Default::default(), }; + let verified_reg_constructor_params = fil_actor_verifreg_state::v16::ConstructorParams { + root_key: Address::new_id(1000).into(), + }; + + let verified_reg_add_verifier_params = fil_actor_verifreg_state::v16::AddVerifierParams { + address: Address::new_id(1234).into(), + allowance: StoragePower::from(1048576u64), // 1MB + }; + + let verified_reg_remove_verifier_params = fil_actor_verifreg_state::v16::RemoveVerifierParams { + verifier: Address::new_id(1234).into(), + }; + + let verified_reg_add_verified_client_params = + fil_actor_verifreg_state::v16::AddVerifiedClientParams { + address: Address::new_id(1235).into(), + allowance: fil_actor_verifreg_state::v16::types::DataCap::from(2097152u64), // 2MB + }; + + let verified_reg_remove_data_cap_params = fil_actor_verifreg_state::v16::RemoveDataCapParams { + verified_client_to_remove: Address::new_id(1236).into(), + data_cap_amount_to_remove: fil_actor_verifreg_state::v16::types::DataCap::from(1048576u64), + verifier_request_1: fil_actor_verifreg_state::v16::RemoveDataCapRequest { + verifier: Address::new_id(1237).into(), + signature: fvm_shared4::crypto::signature::Signature::new_bls( + b"test_signature_1".to_vec(), + ), + }, + verifier_request_2: fil_actor_verifreg_state::v16::RemoveDataCapRequest { + verifier: Address::new_id(1238).into(), + signature: fvm_shared4::crypto::signature::Signature::new_secp256k1( + b"test_signature_2".to_vec(), + ), + }, + }; + + let verified_reg_remove_expired_allocations_params = + fil_actor_verifreg_state::v16::RemoveExpiredAllocationsParams { + client: 1239, + allocation_ids: vec![1001, 1002, 1003], + }; + + let verified_reg_claim_allocations_params = + fil_actor_verifreg_state::v16::ClaimAllocationsParams { + sectors: vec![fil_actor_verifreg_state::v16::SectorAllocationClaims { + sector: 42, + expiry: 2000000, + claims: vec![ + fil_actor_verifreg_state::v16::AllocationClaim { + client: 1240, + allocation_id: 2001, + data: Cid::default(), + size: fvm_shared4::piece::PaddedPieceSize(1024), + }, + fil_actor_verifreg_state::v16::AllocationClaim { + client: 1241, + allocation_id: 2002, + data: Cid::default(), + size: fvm_shared4::piece::PaddedPieceSize(2048), + }, + ], + }], + all_or_nothing: false, + }; + + let verified_reg_get_claims_params = fil_actor_verifreg_state::v16::GetClaimsParams { + provider: 1242, + claim_ids: vec![3001, 3002, 3003], + }; + + let verified_reg_extend_claim_terms_params = + fil_actor_verifreg_state::v16::ExtendClaimTermsParams { + terms: vec![fil_actor_verifreg_state::v16::ClaimTerm { + provider: 12, + claim_id: 12, + term_max: 123, + }], + }; + + let verified_reg_remove_expired_claims_params = + fil_actor_verifreg_state::v16::RemoveExpiredClaimsParams { + provider: 1243, + claim_ids: vec![4001, 4002, 4003], + }; + + let verified_reg_universal_receiver_params = + fvm_actor_utils::receiver::UniversalReceiverParams { + type_: 42, + payload: fvm_ipld_encoding::RawBytes::new(vec![0x12, 0x34, 0x56, 0x78]), + }; + let mut tests = vec![ RpcTest::identity(StateDecodeParams::request(( MINER_ADDRESS, @@ -2165,6 +2256,102 @@ fn state_decode_params_api_tests(tipset: &Tipset) -> anyhow::Result vec![], tipset.key().into(), ))?), + RpcTest::identity(StateDecodeParams::request(( + Address::VERIFIED_REGISTRY_ACTOR, + fil_actor_verifreg_state::v16::Method::Constructor as u64, + to_vec(&verified_reg_constructor_params)?, + tipset.key().into(), + ))?), + RpcTest::identity(StateDecodeParams::request(( + Address::VERIFIED_REGISTRY_ACTOR, + fil_actor_verifreg_state::v16::Method::AddVerifier as u64, + to_vec(&verified_reg_add_verifier_params)?, + tipset.key().into(), + ))?), + RpcTest::identity(StateDecodeParams::request(( + Address::VERIFIED_REGISTRY_ACTOR, + fil_actor_verifreg_state::v16::Method::RemoveVerifier as u64, + to_vec(&verified_reg_remove_verifier_params)?, + tipset.key().into(), + ))?), + RpcTest::identity(StateDecodeParams::request(( + Address::VERIFIED_REGISTRY_ACTOR, + fil_actor_verifreg_state::v16::Method::AddVerifiedClient as u64, + to_vec(&verified_reg_add_verified_client_params)?, + tipset.key().into(), + ))?), + RpcTest::identity(StateDecodeParams::request(( + Address::VERIFIED_REGISTRY_ACTOR, + fil_actor_verifreg_state::v16::Method::RemoveVerifiedClientDataCap as u64, + to_vec(&verified_reg_remove_data_cap_params)?, + tipset.key().into(), + ))?), + RpcTest::identity(StateDecodeParams::request(( + Address::VERIFIED_REGISTRY_ACTOR, + fil_actor_verifreg_state::v16::Method::RemoveExpiredAllocations as u64, + to_vec(&verified_reg_remove_expired_allocations_params)?, + tipset.key().into(), + ))?), + RpcTest::identity(StateDecodeParams::request(( + Address::VERIFIED_REGISTRY_ACTOR, + fil_actor_verifreg_state::v16::Method::ClaimAllocations as u64, + to_vec(&verified_reg_claim_allocations_params)?, + tipset.key().into(), + ))?), + RpcTest::identity(StateDecodeParams::request(( + Address::VERIFIED_REGISTRY_ACTOR, + fil_actor_verifreg_state::v16::Method::GetClaims as u64, + to_vec(&verified_reg_get_claims_params)?, + tipset.key().into(), + ))?), + RpcTest::identity(StateDecodeParams::request(( + Address::VERIFIED_REGISTRY_ACTOR, + fil_actor_verifreg_state::v16::Method::ExtendClaimTerms as u64, + to_vec(&verified_reg_extend_claim_terms_params)?, + tipset.key().into(), + ))?), + RpcTest::identity(StateDecodeParams::request(( + Address::VERIFIED_REGISTRY_ACTOR, + fil_actor_verifreg_state::v16::Method::RemoveExpiredClaims as u64, + to_vec(&verified_reg_remove_expired_claims_params)?, + tipset.key().into(), + ))?), + RpcTest::identity(StateDecodeParams::request(( + Address::VERIFIED_REGISTRY_ACTOR, + fil_actor_verifreg_state::v16::Method::AddVerifiedClientExported as u64, + to_vec(&verified_reg_add_verified_client_params)?, // reuse same params + tipset.key().into(), + ))?), + RpcTest::identity(StateDecodeParams::request(( + Address::VERIFIED_REGISTRY_ACTOR, + fil_actor_verifreg_state::v16::Method::RemoveExpiredAllocationsExported as u64, + to_vec(&verified_reg_remove_expired_allocations_params)?, // reuse same params + tipset.key().into(), + ))?), + RpcTest::identity(StateDecodeParams::request(( + Address::VERIFIED_REGISTRY_ACTOR, + fil_actor_verifreg_state::v16::Method::GetClaimsExported as u64, + to_vec(&verified_reg_get_claims_params)?, // reuse same params + tipset.key().into(), + ))?), + RpcTest::identity(StateDecodeParams::request(( + Address::VERIFIED_REGISTRY_ACTOR, + fil_actor_verifreg_state::v16::Method::ExtendClaimTermsExported as u64, + to_vec(&verified_reg_extend_claim_terms_params)?, // reuse same params + tipset.key().into(), + ))?), + RpcTest::identity(StateDecodeParams::request(( + Address::VERIFIED_REGISTRY_ACTOR, + fil_actor_verifreg_state::v16::Method::RemoveExpiredClaimsExported as u64, + to_vec(&verified_reg_remove_expired_claims_params)?, // reuse same params + tipset.key().into(), + ))?), + RpcTest::identity(StateDecodeParams::request(( + Address::VERIFIED_REGISTRY_ACTOR, + fil_actor_verifreg_state::v16::Method::UniversalReceiverHook as u64, + to_vec(&verified_reg_universal_receiver_params)?, + tipset.key().into(), + ))?), ]; tests.extend(datacap_actor_state_decode_params_tests(tipset)?); diff --git a/src/tool/subcommands/api_cmd/test_snapshots.txt b/src/tool/subcommands/api_cmd/test_snapshots.txt index 1f8120b9b01d..96ac41fe6d0b 100644 --- a/src/tool/subcommands/api_cmd/test_snapshots.txt +++ b/src/tool/subcommands/api_cmd/test_snapshots.txt @@ -177,6 +177,18 @@ filecoin_multisig_statedecodeparams_1754230255631872.rpcsnap.json.zst filecoin_multisig_statedecodeparams_1754230255631946.rpcsnap.json.zst filecoin_multisig_statedecodeparams_1754230255632019.rpcsnap.json.zst filecoin_multisig_statedecodeparams_1754581573704814.rpcsnap.json.zst +filecoin_statedecodeparams_1754401651142334.rpcsnap.json.zst +filecoin_statedecodeparams_1754401651146485.rpcsnap.json.zst +filecoin_statedecodeparams_1754401651146560.rpcsnap.json.zst +filecoin_statedecodeparams_1754401651146644.rpcsnap.json.zst +filecoin_statedecodeparams_1754401651146719.rpcsnap.json.zst +filecoin_statedecodeparams_1754401651146788.rpcsnap.json.zst +filecoin_statedecodeparams_1754401651146860.rpcsnap.json.zst +filecoin_statedecodeparams_1754401651146948.rpcsnap.json.zst +filecoin_statedecodeparams_1754401651147022.rpcsnap.json.zst +filecoin_statedecodeparams_1754401651147091.rpcsnap.json.zst +filecoin_statedecodeparams_1754401651147157.rpcsnap.json.zst +filecoin_statedecodeparams_1754401651147231.rpcsnap.json.zst filecoin_statereplay_1743504051038215.rpcsnap.json.zst filecoin_statesearchmsg_1741784596636715.rpcsnap.json.zst filecoin_statesearchmsglimited_1741784596704876.rpcsnap.json.zst From 4be146da5c965ea663c73927c144ae0776ee621b Mon Sep 17 00:00:00 2001 From: Aryan Tikarya Date: Tue, 5 Aug 2025 20:05:51 +0530 Subject: [PATCH 05/11] remove unused dependecy --- Cargo.lock | 7 ------- Cargo.toml | 1 - 2 files changed, 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 680c481bf4d1..18b76f3bcdde 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3281,7 +3281,6 @@ dependencies = [ "tracing-subscriber", "unsigned-varint 0.8.0", "url", - "use", "uuid", "walkdir", "zstd", @@ -9765,12 +9764,6 @@ dependencies = [ "serde", ] -[[package]] -name = "use" -version = "0.0.1-pre.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f916b8b6102de89f9999988ddc8e9bd0f119a8344e06bb19b0b03fb655769035" - [[package]] name = "utf8_iter" version = "1.0.4" diff --git a/Cargo.toml b/Cargo.toml index 9357be14e6ec..22e3ed103b65 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -229,7 +229,6 @@ paste = "1" tikv-jemallocator = { version = "0.6", optional = true } tracing-chrome = { version = "0.7", optional = true } tracing-loki = { version = "0.2", default-features = false, features = ["compat-0-2-1", "rustls"], optional = true } -use = "0.0.1-pre.0" [target.'cfg(unix)'.dependencies] termios = "0.3" From 233fe46d3c2ed1e0ce31078d84a007e948b3722e Mon Sep 17 00:00:00 2001 From: Aryan Tikarya Date: Wed, 6 Aug 2025 16:33:17 +0530 Subject: [PATCH 06/11] address comments --- .../subcommands/api_cmd/api_compare_tests.rs | 842 +++++++++--------- .../subcommands/api_cmd/test_snapshots.txt | 24 +- 2 files changed, 454 insertions(+), 412 deletions(-) diff --git a/src/tool/subcommands/api_cmd/api_compare_tests.rs b/src/tool/subcommands/api_cmd/api_compare_tests.rs index 8d4a7fd5aad3..98e1c3c41649 100644 --- a/src/tool/subcommands/api_cmd/api_compare_tests.rs +++ b/src/tool/subcommands/api_cmd/api_compare_tests.rs @@ -1808,15 +1808,39 @@ fn eth_tests_with_tipset(store: &Arc, shared_tipset: &Tipset } fn state_decode_params_api_tests(tipset: &Tipset) -> anyhow::Result> { - let account_constructor_params = fil_actor_account_state::v16::types::ConstructorParams { - address: Address::new_id(1234).into(), + let evm_constructor_params = fil_actor_evm_state::v16::ConstructorParams { + creator: fil_actor_evm_state::evm_shared::v16::address::EthAddress([0; 20]), + initcode: fvm_ipld_encoding::RawBytes::new(vec![0x12, 0x34, 0x56]), // dummy bytecode }; - let account_auth_params = fil_actor_account_state::v16::types::AuthenticateMessageParams { - signature: vec![0x00; 32], // dummy signature - message: b"test message".to_vec(), - }; + let mut tests = vec![ + RpcTest::identity(StateDecodeParams::request(( + Address::from_str(EVM_ADDRESS).unwrap(), // evm actor + 1, + to_vec(&evm_constructor_params)?, + tipset.key().into(), + ))?), + RpcTest::identity(StateDecodeParams::request(( + Address::SYSTEM_ACTOR, + fil_actor_system_state::v16::Method::Constructor as u64, + vec![], + tipset.key().into(), + ))?), + ]; + + tests.extend(miner_actor_state_decode_params_tests(tipset)?); + tests.extend(account_actor_state_decode_params_tests(tipset)?); + tests.extend(init_actor_state_decode_params_tests(tipset)?); + tests.extend(reward_actor_state_decode_params_tests(tipset)?); + tests.extend(power_actor_state_decode_params_tests(tipset)?); + tests.extend(datacap_actor_state_decode_params_tests(tipset)?); + tests.extend(multisig_actor_state_decode_params_tests(tipset)?); + tests.extend(verified_reg_actor_state_decode_params_tests(tipset)?); + Ok(tests) +} + +fn miner_actor_state_decode_params_tests(tipset: &Tipset) -> anyhow::Result> { let miner_constructor_params = fil_actor_miner_state::v16::MinerConstructorParams { owner: Address::new_id(1000).into(), worker: Address::new_id(1001).into(), @@ -1831,207 +1855,7 @@ fn state_decode_params_api_tests(tipset: &Tipset) -> anyhow::Result new_control_addresses: vec![Address::new_id(2001).into()], }; - let evm_constructor_params = fil_actor_evm_state::v16::ConstructorParams { - creator: fil_actor_evm_state::evm_shared::v16::address::EthAddress([0; 20]), - initcode: fvm_ipld_encoding::RawBytes::new(vec![0x12, 0x34, 0x56]), // dummy bytecode - }; - - let init_constructor_params = fil_actor_init_state::v16::ConstructorParams { - network_name: "calibnet".to_string(), - }; - - let init_exec4_params = fil_actor_init_state::v16::Exec4Params { - code_cid: Cid::default(), - constructor_params: fvm_ipld_encoding::RawBytes::new(vec![0x12, 0x34, 0x56]), // dummy bytecode - subaddress: fvm_ipld_encoding::RawBytes::new(vec![0x12, 0x34, 0x56]), // dummy bytecode - }; - - let init_exec_params = fil_actor_init_state::v16::ExecParams { - code_cid: Cid::default(), - constructor_params: fvm_ipld_encoding::RawBytes::new(vec![0x12, 0x34, 0x56]), // dummy bytecode - }; - - let power_create_miner_params = fil_actor_power_state::v16::CreateMinerParams { - owner: Address::new_id(1000).into(), - worker: Address::new_id(1001).into(), - window_post_proof_type: fvm_shared4::sector::RegisteredPoStProof::StackedDRGWinning2KiBV1, - peer: b"miner".to_vec(), - multiaddrs: Default::default(), - }; - - // not supported by the lotus - // let _power_miner_power_exp_params = fil_actor_power_state::v16::MinerPowerParams{ - // miner: 1234, - // }; - - let power_update_claim_params = fil_actor_power_state::v16::UpdateClaimedPowerParams { - raw_byte_delta: StoragePower::from(1024u64), - quality_adjusted_delta: StoragePower::from(2048u64), - }; - - let power_enroll_event_params = fil_actor_power_state::v16::EnrollCronEventParams { - event_epoch: 123, - payload: Default::default(), - }; - - let power_update_pledge_ttl_params = fil_actor_power_state::v16::UpdatePledgeTotalParams { - pledge_delta: Default::default(), - }; - - let power_miner_raw_params = fil_actor_power_state::v16::MinerRawPowerParams { miner: 1234 }; - - let reward_constructor_params = fil_actor_reward_state::v16::ConstructorParams { - power: Some(Default::default()), - }; - - let reward_award_block_reward_params = fil_actor_reward_state::v16::AwardBlockRewardParams { - miner: Address::new_id(1000).into(), - penalty: Default::default(), - gas_reward: Default::default(), - win_count: 0, - }; - - let reward_update_network_params = fil_actor_reward_state::v16::UpdateNetworkKPIParams { - curr_realized_power: Option::from(fvm_shared4::bigint::bigint_ser::BigIntDe(BigInt::from( - 111, - ))), - }; - - let multisig_constructor_params = fil_actor_multisig_state::v16::ConstructorParams { - signers: vec![Address::new_id(1000).into(), Address::new_id(1001).into()], - num_approvals_threshold: Default::default(), - unlock_duration: Default::default(), - start_epoch: Default::default(), - }; - - let multisig_propose_params = fil_actor_multisig_state::v16::ProposeParams { - to: Address::new_id(1000).into(), - value: Default::default(), - method: 0, - params: Default::default(), - }; - - let multisig_tx_id_params = fil_actor_multisig_state::v16::TxnIDParams { - id: Default::default(), - proposal_hash: vec![Default::default()], - }; - - let multisig_add_signer_params = fil_actor_multisig_state::v16::AddSignerParams { - signer: Address::new_id(1012).into(), - increase: false, - }; - - let multisig_remove_signer_params = fil_actor_multisig_state::v16::RemoveSignerParams { - signer: Address::new_id(1012).into(), - decrease: false, - }; - - let multisig_swap_signer_params = fil_actor_multisig_state::v16::SwapSignerParams { - from: Address::new_id(122).into(), - to: Address::new_id(1234).into(), - }; - - let multisig_change_num_app_params = - fil_actor_multisig_state::v16::ChangeNumApprovalsThresholdParams { new_threshold: 2 }; - - let multisig_lock_bal_params = fil_actor_multisig_state::v16::LockBalanceParams { - start_epoch: 22, - unlock_duration: 12, - amount: Default::default(), - }; - - let verified_reg_constructor_params = fil_actor_verifreg_state::v16::ConstructorParams { - root_key: Address::new_id(1000).into(), - }; - - let verified_reg_add_verifier_params = fil_actor_verifreg_state::v16::AddVerifierParams { - address: Address::new_id(1234).into(), - allowance: StoragePower::from(1048576u64), // 1MB - }; - - let verified_reg_remove_verifier_params = fil_actor_verifreg_state::v16::RemoveVerifierParams { - verifier: Address::new_id(1234).into(), - }; - - let verified_reg_add_verified_client_params = - fil_actor_verifreg_state::v16::AddVerifiedClientParams { - address: Address::new_id(1235).into(), - allowance: fil_actor_verifreg_state::v16::types::DataCap::from(2097152u64), // 2MB - }; - - let verified_reg_remove_data_cap_params = fil_actor_verifreg_state::v16::RemoveDataCapParams { - verified_client_to_remove: Address::new_id(1236).into(), - data_cap_amount_to_remove: fil_actor_verifreg_state::v16::types::DataCap::from(1048576u64), - verifier_request_1: fil_actor_verifreg_state::v16::RemoveDataCapRequest { - verifier: Address::new_id(1237).into(), - signature: fvm_shared4::crypto::signature::Signature::new_bls( - b"test_signature_1".to_vec(), - ), - }, - verifier_request_2: fil_actor_verifreg_state::v16::RemoveDataCapRequest { - verifier: Address::new_id(1238).into(), - signature: fvm_shared4::crypto::signature::Signature::new_secp256k1( - b"test_signature_2".to_vec(), - ), - }, - }; - - let verified_reg_remove_expired_allocations_params = - fil_actor_verifreg_state::v16::RemoveExpiredAllocationsParams { - client: 1239, - allocation_ids: vec![1001, 1002, 1003], - }; - - let verified_reg_claim_allocations_params = - fil_actor_verifreg_state::v16::ClaimAllocationsParams { - sectors: vec![fil_actor_verifreg_state::v16::SectorAllocationClaims { - sector: 42, - expiry: 2000000, - claims: vec![ - fil_actor_verifreg_state::v16::AllocationClaim { - client: 1240, - allocation_id: 2001, - data: Cid::default(), - size: fvm_shared4::piece::PaddedPieceSize(1024), - }, - fil_actor_verifreg_state::v16::AllocationClaim { - client: 1241, - allocation_id: 2002, - data: Cid::default(), - size: fvm_shared4::piece::PaddedPieceSize(2048), - }, - ], - }], - all_or_nothing: false, - }; - - let verified_reg_get_claims_params = fil_actor_verifreg_state::v16::GetClaimsParams { - provider: 1242, - claim_ids: vec![3001, 3002, 3003], - }; - - let verified_reg_extend_claim_terms_params = - fil_actor_verifreg_state::v16::ExtendClaimTermsParams { - terms: vec![fil_actor_verifreg_state::v16::ClaimTerm { - provider: 12, - claim_id: 12, - term_max: 123, - }], - }; - - let verified_reg_remove_expired_claims_params = - fil_actor_verifreg_state::v16::RemoveExpiredClaimsParams { - provider: 1243, - claim_ids: vec![4001, 4002, 4003], - }; - - let verified_reg_universal_receiver_params = - fvm_actor_utils::receiver::UniversalReceiverParams { - type_: 42, - payload: fvm_ipld_encoding::RawBytes::new(vec![0x12, 0x34, 0x56, 0x78]), - }; - - let mut tests = vec![ + Ok(vec![ RpcTest::identity(StateDecodeParams::request(( MINER_ADDRESS, 1, @@ -2044,6 +1868,20 @@ fn state_decode_params_api_tests(tipset: &Tipset) -> anyhow::Result to_vec(&miner_change_worker_params)?, tipset.key().into(), ))?), + ]) +} + +fn account_actor_state_decode_params_tests(tipset: &Tipset) -> anyhow::Result> { + let account_constructor_params = fil_actor_account_state::v16::types::ConstructorParams { + address: Address::new_id(1234).into(), + }; + + let account_auth_params = fil_actor_account_state::v16::types::AuthenticateMessageParams { + signature: vec![0x00; 32], // dummy signature + message: b"test message".to_vec(), + }; + + Ok(vec![ RpcTest::identity(StateDecodeParams::request(( ACCOUNT_ADDRESS, 1, @@ -2056,12 +1894,26 @@ fn state_decode_params_api_tests(tipset: &Tipset) -> anyhow::Result to_vec(&account_auth_params)?, tipset.key().into(), ))?), - RpcTest::identity(StateDecodeParams::request(( - Address::from_str(EVM_ADDRESS).unwrap(), // evm actor - 1, - to_vec(&evm_constructor_params)?, - tipset.key().into(), - ))?), + ]) +} + +fn init_actor_state_decode_params_tests(tipset: &Tipset) -> anyhow::Result> { + let init_constructor_params = fil_actor_init_state::v16::ConstructorParams { + network_name: "calibnet".to_string(), + }; + + let init_exec4_params = fil_actor_init_state::v16::Exec4Params { + code_cid: Cid::default(), + constructor_params: fvm_ipld_encoding::RawBytes::new(vec![0x12, 0x34, 0x56]), // dummy bytecode + subaddress: fvm_ipld_encoding::RawBytes::new(vec![0x12, 0x34, 0x56]), // dummy bytecode + }; + + let init_exec_params = fil_actor_init_state::v16::ExecParams { + code_cid: Cid::default(), + constructor_params: fvm_ipld_encoding::RawBytes::new(vec![0x12, 0x34, 0x56]), // dummy bytecode + }; + + Ok(vec![ RpcTest::identity(StateDecodeParams::request(( Address::INIT_ACTOR, 1, @@ -2080,6 +1932,28 @@ fn state_decode_params_api_tests(tipset: &Tipset) -> anyhow::Result to_vec(&init_exec4_params)?, tipset.key().into(), ))?), + ]) +} + +fn reward_actor_state_decode_params_tests(tipset: &Tipset) -> anyhow::Result> { + let reward_constructor_params = fil_actor_reward_state::v16::ConstructorParams { + power: Some(Default::default()), + }; + + let reward_award_block_reward_params = fil_actor_reward_state::v16::AwardBlockRewardParams { + miner: Address::new_id(1000).into(), + penalty: Default::default(), + gas_reward: Default::default(), + win_count: 0, + }; + + let reward_update_network_params = fil_actor_reward_state::v16::UpdateNetworkKPIParams { + curr_realized_power: Option::from(fvm_shared4::bigint::bigint_ser::BigIntDe(BigInt::from( + 111, + ))), + }; + + Ok(vec![ RpcTest::identity(StateDecodeParams::request(( Address::REWARD_ACTOR, fil_actor_reward_state::v16::Method::Constructor as u64, @@ -2104,6 +1978,40 @@ fn state_decode_params_api_tests(tipset: &Tipset) -> anyhow::Result vec![], tipset.key().into(), ))?), + ]) +} + +fn power_actor_state_decode_params_tests(tipset: &Tipset) -> anyhow::Result> { + let power_create_miner_params = fil_actor_power_state::v16::CreateMinerParams { + owner: Address::new_id(1000).into(), + worker: Address::new_id(1001).into(), + window_post_proof_type: fvm_shared4::sector::RegisteredPoStProof::StackedDRGWinning2KiBV1, + peer: b"miner".to_vec(), + multiaddrs: Default::default(), + }; + + // not supported by the lotus + // let _power_miner_power_exp_params = fil_actor_power_state::v16::MinerPowerParams{ + // miner: 1234, + // }; + + let power_update_claim_params = fil_actor_power_state::v16::UpdateClaimedPowerParams { + raw_byte_delta: StoragePower::from(1024u64), + quality_adjusted_delta: StoragePower::from(2048u64), + }; + + let power_enroll_event_params = fil_actor_power_state::v16::EnrollCronEventParams { + event_epoch: 123, + payload: Default::default(), + }; + + let power_update_pledge_ttl_params = fil_actor_power_state::v16::UpdatePledgeTotalParams { + pledge_delta: Default::default(), + }; + + let power_miner_raw_params = fil_actor_power_state::v16::MinerRawPowerParams { miner: 1234 }; + + Ok(vec![ RpcTest::identity(StateDecodeParams::request(( Address::POWER_ACTOR, fil_actor_power_state::v16::Method::CreateMiner as u64, @@ -2140,6 +2048,14 @@ fn state_decode_params_api_tests(tipset: &Tipset) -> anyhow::Result to_vec(&power_miner_raw_params)?, tipset.key().into(), ))?), + // Not supported by the lotus, + // TODO(go-state-types): https://github.com/filecoin-project/go-state-types/issues/401 + // RpcTest::identity(StateDecodeParams::request(( + // Address::POWER_ACTOR, + // Method::MinerPowerExported as u64, + // to_vec(&power_miner_power_exp_params)?, + // tipset.key().into(), + // ))?), RpcTest::identity(StateDecodeParams::request(( Address::POWER_ACTOR, fil_actor_power_state::v16::Method::Constructor as u64, @@ -2176,14 +2092,222 @@ fn state_decode_params_api_tests(tipset: &Tipset) -> anyhow::Result vec![], tipset.key().into(), ))?), - // Not supported by the lotus, - // TODO(go-state-types): https://github.com/filecoin-project/go-state-types/issues/401 - // RpcTest::identity(StateDecodeParams::request(( - // Address::POWER_ACTOR, - // Method::MinerPowerExported as u64, - // to_vec(&power_miner_power_exp_params)?, - // tipset.key().into(), - // ))?), + ]) +} + +fn datacap_actor_state_decode_params_tests(tipset: &Tipset) -> anyhow::Result> { + let datacap_constructor_params = fil_actor_datacap_state::v16::ConstructorParams { + governor: Address::new_id(3000).into(), + }; + + let datacap_mint_params = fil_actor_datacap_state::v16::MintParams { + to: Address::new_id(3001).into(), + amount: TokenAmount::default().into(), + operators: vec![Address::new_id(3002).into(), Address::new_id(3003).into()], + }; + + let datacap_destroy_params = fil_actor_datacap_state::v16::DestroyParams { + owner: Address::new_id(3004).into(), + amount: TokenAmount::default().into(), + }; + + let datacap_balance_params = fil_actor_datacap_state::v16::BalanceParams { + address: Address::new_id(3005).into(), + }; + + let datacap_transfer_params = fil_actors_shared::frc46_token::token::types::TransferParams { + to: Address::new_id(3006).into(), + amount: TokenAmount::default().into(), + operator_data: fvm_ipld_encoding::RawBytes::new(b"transfer test data".to_vec()), + }; + + let datacap_transfer_from_params = + fil_actors_shared::frc46_token::token::types::TransferFromParams { + from: Address::new_id(3007).into(), + to: Address::new_id(3008).into(), + amount: TokenAmount::default().into(), + operator_data: fvm_ipld_encoding::RawBytes::new(b"transfer_from test data".to_vec()), + }; + + let datacap_increase_allowance_params = + fil_actors_shared::frc46_token::token::types::IncreaseAllowanceParams { + operator: Address::new_id(3009).into(), + increase: TokenAmount::default().into(), + }; + + let datacap_decrease_allowance_params = + fil_actors_shared::frc46_token::token::types::DecreaseAllowanceParams { + operator: Address::new_id(3010).into(), + decrease: TokenAmount::default().into(), + }; + + let datacap_revoke_allowance_params = + fil_actors_shared::frc46_token::token::types::RevokeAllowanceParams { + operator: Address::new_id(3011).into(), + }; + + let datacap_burn_params = fil_actors_shared::frc46_token::token::types::BurnParams { + amount: TokenAmount::default().into(), + }; + + let datacap_burn_from_params = fil_actors_shared::frc46_token::token::types::BurnFromParams { + owner: Address::new_id(3012).into(), + amount: TokenAmount::default().into(), + }; + + let datacap_get_allowance_params = + fil_actors_shared::frc46_token::token::types::GetAllowanceParams { + owner: Address::new_id(3013).into(), + operator: Address::new_id(3014).into(), + }; + + let tests = vec![ + RpcTest::identity(StateDecodeParams::request(( + Address::DATACAP_TOKEN_ACTOR, + fil_actor_datacap_state::v16::Method::Constructor as u64, + to_vec(&datacap_constructor_params)?, + tipset.key().into(), + ))?), + RpcTest::identity(StateDecodeParams::request(( + Address::DATACAP_TOKEN_ACTOR, + fil_actor_datacap_state::v16::Method::MintExported as u64, + to_vec(&datacap_mint_params)?, + tipset.key().into(), + ))?), + RpcTest::identity(StateDecodeParams::request(( + Address::DATACAP_TOKEN_ACTOR, + fil_actor_datacap_state::v16::Method::DestroyExported as u64, + to_vec(&datacap_destroy_params)?, + tipset.key().into(), + ))?), + RpcTest::identity(StateDecodeParams::request(( + Address::DATACAP_TOKEN_ACTOR, + fil_actor_datacap_state::v16::Method::NameExported as u64, + vec![], + tipset.key().into(), + ))?), + RpcTest::identity(StateDecodeParams::request(( + Address::DATACAP_TOKEN_ACTOR, + fil_actor_datacap_state::v16::Method::SymbolExported as u64, + vec![], + tipset.key().into(), + ))?), + RpcTest::identity(StateDecodeParams::request(( + Address::DATACAP_TOKEN_ACTOR, + fil_actor_datacap_state::v16::Method::TotalSupplyExported as u64, + vec![], + tipset.key().into(), + ))?), + RpcTest::identity(StateDecodeParams::request(( + Address::DATACAP_TOKEN_ACTOR, + fil_actor_datacap_state::v16::Method::BalanceExported as u64, + to_vec(&datacap_balance_params)?, + tipset.key().into(), + ))?), + RpcTest::identity(StateDecodeParams::request(( + Address::DATACAP_TOKEN_ACTOR, + fil_actor_datacap_state::v16::Method::GranularityExported as u64, + vec![], + tipset.key().into(), + ))?), + RpcTest::identity(StateDecodeParams::request(( + Address::DATACAP_TOKEN_ACTOR, + fil_actor_datacap_state::v16::Method::TransferExported as u64, + to_vec(&datacap_transfer_params)?, + tipset.key().into(), + ))?), + RpcTest::identity(StateDecodeParams::request(( + Address::DATACAP_TOKEN_ACTOR, + fil_actor_datacap_state::v16::Method::TransferFromExported as u64, + to_vec(&datacap_transfer_from_params)?, + tipset.key().into(), + ))?), + RpcTest::identity(StateDecodeParams::request(( + Address::DATACAP_TOKEN_ACTOR, + fil_actor_datacap_state::v16::Method::IncreaseAllowanceExported as u64, + to_vec(&datacap_increase_allowance_params)?, + tipset.key().into(), + ))?), + RpcTest::identity(StateDecodeParams::request(( + Address::DATACAP_TOKEN_ACTOR, + fil_actor_datacap_state::v16::Method::DecreaseAllowanceExported as u64, + to_vec(&datacap_decrease_allowance_params)?, + tipset.key().into(), + ))?), + RpcTest::identity(StateDecodeParams::request(( + Address::DATACAP_TOKEN_ACTOR, + fil_actor_datacap_state::v16::Method::RevokeAllowanceExported as u64, + to_vec(&datacap_revoke_allowance_params)?, + tipset.key().into(), + ))?), + RpcTest::identity(StateDecodeParams::request(( + Address::DATACAP_TOKEN_ACTOR, + fil_actor_datacap_state::v16::Method::BurnExported as u64, + to_vec(&datacap_burn_params)?, + tipset.key().into(), + ))?), + RpcTest::identity(StateDecodeParams::request(( + Address::DATACAP_TOKEN_ACTOR, + fil_actor_datacap_state::v16::Method::BurnFromExported as u64, + to_vec(&datacap_burn_from_params)?, + tipset.key().into(), + ))?), + RpcTest::identity(StateDecodeParams::request(( + Address::DATACAP_TOKEN_ACTOR, + fil_actor_datacap_state::v16::Method::AllowanceExported as u64, + to_vec(&datacap_get_allowance_params)?, + tipset.key().into(), + ))?), + ]; + + Ok(tests) +} + +fn multisig_actor_state_decode_params_tests(tipset: &Tipset) -> anyhow::Result> { + let multisig_constructor_params = fil_actor_multisig_state::v16::ConstructorParams { + signers: vec![Address::new_id(1000).into(), Address::new_id(1001).into()], + num_approvals_threshold: Default::default(), + unlock_duration: Default::default(), + start_epoch: Default::default(), + }; + + let multisig_propose_params = fil_actor_multisig_state::v16::ProposeParams { + to: Address::new_id(1000).into(), + value: Default::default(), + method: 0, + params: Default::default(), + }; + + let multisig_tx_id_params = fil_actor_multisig_state::v16::TxnIDParams { + id: Default::default(), + proposal_hash: vec![Default::default()], + }; + + let multisig_add_signer_params = fil_actor_multisig_state::v16::AddSignerParams { + signer: Address::new_id(1012).into(), + increase: false, + }; + + let multisig_remove_signer_params = fil_actor_multisig_state::v16::RemoveSignerParams { + signer: Address::new_id(1012).into(), + decrease: false, + }; + + let multisig_swap_signer_params = fil_actor_multisig_state::v16::SwapSignerParams { + from: Address::new_id(122).into(), + to: Address::new_id(1234).into(), + }; + + let multisig_change_num_app_params = + fil_actor_multisig_state::v16::ChangeNumApprovalsThresholdParams { new_threshold: 2 }; + + let multisig_lock_bal_params = fil_actor_multisig_state::v16::LockBalanceParams { + start_epoch: 22, + unlock_duration: 12, + amount: Default::default(), + }; + + Ok(vec![ RpcTest::identity(StateDecodeParams::request(( Address::new_id(18101), // https://calibration.filscan.io/en/address/t018101/, fil_actor_multisig_state::v16::Method::Constructor as u64, @@ -2250,12 +2374,102 @@ fn state_decode_params_api_tests(tipset: &Tipset) -> anyhow::Result BASE64_STANDARD.decode("ghgqRBI0Vng=").unwrap(), tipset.key().into(), ))?), - RpcTest::identity(StateDecodeParams::request(( - Address::SYSTEM_ACTOR, - fil_actor_system_state::v16::Method::Constructor as u64, - vec![], - tipset.key().into(), - ))?), + ]) +} + +fn verified_reg_actor_state_decode_params_tests(tipset: &Tipset) -> anyhow::Result> { + let verified_reg_constructor_params = fil_actor_verifreg_state::v16::ConstructorParams { + root_key: Address::new_id(1000).into(), + }; + + let verified_reg_add_verifier_params = fil_actor_verifreg_state::v16::AddVerifierParams { + address: Address::new_id(1234).into(), + allowance: StoragePower::from(1048576u64), // 1MB + }; + + let verified_reg_remove_verifier_params = fil_actor_verifreg_state::v16::RemoveVerifierParams { + verifier: Address::new_id(1234).into(), + }; + + let verified_reg_add_verified_client_params = + fil_actor_verifreg_state::v16::AddVerifiedClientParams { + address: Address::new_id(1235).into(), + allowance: fil_actor_verifreg_state::v16::types::DataCap::from(2097152u64), // 2MB + }; + + let verified_reg_remove_data_cap_params = fil_actor_verifreg_state::v16::RemoveDataCapParams { + verified_client_to_remove: Address::new_id(1236).into(), + data_cap_amount_to_remove: fil_actor_verifreg_state::v16::types::DataCap::from(1048576u64), + verifier_request_1: fil_actor_verifreg_state::v16::RemoveDataCapRequest { + verifier: Address::new_id(1237).into(), + signature: fvm_shared4::crypto::signature::Signature::new_bls( + b"test_signature_1".to_vec(), + ), + }, + verifier_request_2: fil_actor_verifreg_state::v16::RemoveDataCapRequest { + verifier: Address::new_id(1238).into(), + signature: fvm_shared4::crypto::signature::Signature::new_secp256k1( + b"test_signature_2".to_vec(), + ), + }, + }; + + let verified_reg_remove_expired_allocations_params = + fil_actor_verifreg_state::v16::RemoveExpiredAllocationsParams { + client: 1239, + allocation_ids: vec![1001, 1002, 1003], + }; + + let verified_reg_claim_allocations_params = + fil_actor_verifreg_state::v16::ClaimAllocationsParams { + sectors: vec![fil_actor_verifreg_state::v16::SectorAllocationClaims { + sector: 42, + expiry: 2000000, + claims: vec![ + fil_actor_verifreg_state::v16::AllocationClaim { + client: 1240, + allocation_id: 2001, + data: Cid::default(), + size: fvm_shared4::piece::PaddedPieceSize(1024), + }, + fil_actor_verifreg_state::v16::AllocationClaim { + client: 1241, + allocation_id: 2002, + data: Cid::default(), + size: fvm_shared4::piece::PaddedPieceSize(2048), + }, + ], + }], + all_or_nothing: false, + }; + + let verified_reg_get_claims_params = fil_actor_verifreg_state::v16::GetClaimsParams { + provider: 1242, + claim_ids: vec![3001, 3002, 3003], + }; + + let verified_reg_extend_claim_terms_params = + fil_actor_verifreg_state::v16::ExtendClaimTermsParams { + terms: vec![fil_actor_verifreg_state::v16::ClaimTerm { + provider: 12, + claim_id: 12, + term_max: 123, + }], + }; + + let verified_reg_remove_expired_claims_params = + fil_actor_verifreg_state::v16::RemoveExpiredClaimsParams { + provider: 1243, + claim_ids: vec![4001, 4002, 4003], + }; + + let verified_reg_universal_receiver_params = + fvm_actor_utils::receiver::UniversalReceiverParams { + type_: 42, + payload: fvm_ipld_encoding::RawBytes::new(vec![0x12, 0x34, 0x56, 0x78]), + }; + + Ok(vec![ RpcTest::identity(StateDecodeParams::request(( Address::VERIFIED_REGISTRY_ACTOR, fil_actor_verifreg_state::v16::Method::Constructor as u64, @@ -2352,179 +2566,7 @@ fn state_decode_params_api_tests(tipset: &Tipset) -> anyhow::Result to_vec(&verified_reg_universal_receiver_params)?, tipset.key().into(), ))?), - ]; - - tests.extend(datacap_actor_state_decode_params_tests(tipset)?); - - Ok(tests) -} - -fn datacap_actor_state_decode_params_tests(tipset: &Tipset) -> anyhow::Result> { - let datacap_constructor_params = fil_actor_datacap_state::v16::ConstructorParams { - governor: Address::new_id(3000).into(), - }; - - let datacap_mint_params = fil_actor_datacap_state::v16::MintParams { - to: Address::new_id(3001).into(), - amount: TokenAmount::default().into(), - operators: vec![Address::new_id(3002).into(), Address::new_id(3003).into()], - }; - - let datacap_destroy_params = fil_actor_datacap_state::v16::DestroyParams { - owner: Address::new_id(3004).into(), - amount: TokenAmount::default().into(), - }; - - let datacap_balance_params = fil_actor_datacap_state::v16::BalanceParams { - address: Address::new_id(3005).into(), - }; - - let datacap_transfer_params = fil_actors_shared::frc46_token::token::types::TransferParams { - to: Address::new_id(3006).into(), - amount: TokenAmount::default().into(), - operator_data: fvm_ipld_encoding::RawBytes::new(b"transfer test data".to_vec()), - }; - - let datacap_transfer_from_params = - fil_actors_shared::frc46_token::token::types::TransferFromParams { - from: Address::new_id(3007).into(), - to: Address::new_id(3008).into(), - amount: TokenAmount::default().into(), - operator_data: fvm_ipld_encoding::RawBytes::new(b"transfer_from test data".to_vec()), - }; - - let datacap_increase_allowance_params = - fil_actors_shared::frc46_token::token::types::IncreaseAllowanceParams { - operator: Address::new_id(3009).into(), - increase: TokenAmount::default().into(), - }; - - let datacap_decrease_allowance_params = - fil_actors_shared::frc46_token::token::types::DecreaseAllowanceParams { - operator: Address::new_id(3010).into(), - decrease: TokenAmount::default().into(), - }; - - let datacap_revoke_allowance_params = - fil_actors_shared::frc46_token::token::types::RevokeAllowanceParams { - operator: Address::new_id(3011).into(), - }; - - let datacap_burn_params = fil_actors_shared::frc46_token::token::types::BurnParams { - amount: TokenAmount::default().into(), - }; - - let datacap_burn_from_params = fil_actors_shared::frc46_token::token::types::BurnFromParams { - owner: Address::new_id(3012).into(), - amount: TokenAmount::default().into(), - }; - - let datacap_get_allowance_params = - fil_actors_shared::frc46_token::token::types::GetAllowanceParams { - owner: Address::new_id(3013).into(), - operator: Address::new_id(3014).into(), - }; - - let tests = vec![ - RpcTest::identity(StateDecodeParams::request(( - Address::DATACAP_TOKEN_ACTOR, - fil_actor_datacap_state::v16::Method::Constructor as u64, - to_vec(&datacap_constructor_params)?, - tipset.key().into(), - ))?), - RpcTest::identity(StateDecodeParams::request(( - Address::DATACAP_TOKEN_ACTOR, - fil_actor_datacap_state::v16::Method::MintExported as u64, - to_vec(&datacap_mint_params)?, - tipset.key().into(), - ))?), - RpcTest::identity(StateDecodeParams::request(( - Address::DATACAP_TOKEN_ACTOR, - fil_actor_datacap_state::v16::Method::DestroyExported as u64, - to_vec(&datacap_destroy_params)?, - tipset.key().into(), - ))?), - RpcTest::identity(StateDecodeParams::request(( - Address::DATACAP_TOKEN_ACTOR, - fil_actor_datacap_state::v16::Method::NameExported as u64, - vec![], - tipset.key().into(), - ))?), - RpcTest::identity(StateDecodeParams::request(( - Address::DATACAP_TOKEN_ACTOR, - fil_actor_datacap_state::v16::Method::SymbolExported as u64, - vec![], - tipset.key().into(), - ))?), - RpcTest::identity(StateDecodeParams::request(( - Address::DATACAP_TOKEN_ACTOR, - fil_actor_datacap_state::v16::Method::TotalSupplyExported as u64, - vec![], - tipset.key().into(), - ))?), - RpcTest::identity(StateDecodeParams::request(( - Address::DATACAP_TOKEN_ACTOR, - fil_actor_datacap_state::v16::Method::BalanceExported as u64, - to_vec(&datacap_balance_params)?, - tipset.key().into(), - ))?), - RpcTest::identity(StateDecodeParams::request(( - Address::DATACAP_TOKEN_ACTOR, - fil_actor_datacap_state::v16::Method::GranularityExported as u64, - vec![], - tipset.key().into(), - ))?), - RpcTest::identity(StateDecodeParams::request(( - Address::DATACAP_TOKEN_ACTOR, - fil_actor_datacap_state::v16::Method::TransferExported as u64, - to_vec(&datacap_transfer_params)?, - tipset.key().into(), - ))?), - RpcTest::identity(StateDecodeParams::request(( - Address::DATACAP_TOKEN_ACTOR, - fil_actor_datacap_state::v16::Method::TransferFromExported as u64, - to_vec(&datacap_transfer_from_params)?, - tipset.key().into(), - ))?), - RpcTest::identity(StateDecodeParams::request(( - Address::DATACAP_TOKEN_ACTOR, - fil_actor_datacap_state::v16::Method::IncreaseAllowanceExported as u64, - to_vec(&datacap_increase_allowance_params)?, - tipset.key().into(), - ))?), - RpcTest::identity(StateDecodeParams::request(( - Address::DATACAP_TOKEN_ACTOR, - fil_actor_datacap_state::v16::Method::DecreaseAllowanceExported as u64, - to_vec(&datacap_decrease_allowance_params)?, - tipset.key().into(), - ))?), - RpcTest::identity(StateDecodeParams::request(( - Address::DATACAP_TOKEN_ACTOR, - fil_actor_datacap_state::v16::Method::RevokeAllowanceExported as u64, - to_vec(&datacap_revoke_allowance_params)?, - tipset.key().into(), - ))?), - RpcTest::identity(StateDecodeParams::request(( - Address::DATACAP_TOKEN_ACTOR, - fil_actor_datacap_state::v16::Method::BurnExported as u64, - to_vec(&datacap_burn_params)?, - tipset.key().into(), - ))?), - RpcTest::identity(StateDecodeParams::request(( - Address::DATACAP_TOKEN_ACTOR, - fil_actor_datacap_state::v16::Method::BurnFromExported as u64, - to_vec(&datacap_burn_from_params)?, - tipset.key().into(), - ))?), - RpcTest::identity(StateDecodeParams::request(( - Address::DATACAP_TOKEN_ACTOR, - fil_actor_datacap_state::v16::Method::AllowanceExported as u64, - to_vec(&datacap_get_allowance_params)?, - tipset.key().into(), - ))?), - ]; - - Ok(tests) + ]) } fn read_state_api_tests(tipset: &Tipset) -> anyhow::Result> { diff --git a/src/tool/subcommands/api_cmd/test_snapshots.txt b/src/tool/subcommands/api_cmd/test_snapshots.txt index 96ac41fe6d0b..e1ced05b208f 100644 --- a/src/tool/subcommands/api_cmd/test_snapshots.txt +++ b/src/tool/subcommands/api_cmd/test_snapshots.txt @@ -177,18 +177,18 @@ filecoin_multisig_statedecodeparams_1754230255631872.rpcsnap.json.zst filecoin_multisig_statedecodeparams_1754230255631946.rpcsnap.json.zst filecoin_multisig_statedecodeparams_1754230255632019.rpcsnap.json.zst filecoin_multisig_statedecodeparams_1754581573704814.rpcsnap.json.zst -filecoin_statedecodeparams_1754401651142334.rpcsnap.json.zst -filecoin_statedecodeparams_1754401651146485.rpcsnap.json.zst -filecoin_statedecodeparams_1754401651146560.rpcsnap.json.zst -filecoin_statedecodeparams_1754401651146644.rpcsnap.json.zst -filecoin_statedecodeparams_1754401651146719.rpcsnap.json.zst -filecoin_statedecodeparams_1754401651146788.rpcsnap.json.zst -filecoin_statedecodeparams_1754401651146860.rpcsnap.json.zst -filecoin_statedecodeparams_1754401651146948.rpcsnap.json.zst -filecoin_statedecodeparams_1754401651147022.rpcsnap.json.zst -filecoin_statedecodeparams_1754401651147091.rpcsnap.json.zst -filecoin_statedecodeparams_1754401651147157.rpcsnap.json.zst -filecoin_statedecodeparams_1754401651147231.rpcsnap.json.zst +filecoin_verified_reg_statedecodeparams_1754401651142334.rpcsnap.json.zst +filecoin_verified_reg_statedecodeparams_1754401651146485.rpcsnap.json.zst +filecoin_verified_reg_statedecodeparams_1754401651146560.rpcsnap.json.zst +filecoin_verified_reg_statedecodeparams_1754401651146644.rpcsnap.json.zst +filecoin_verified_reg_statedecodeparams_1754401651146719.rpcsnap.json.zst +filecoin_verified_reg_statedecodeparams_1754401651146788.rpcsnap.json.zst +filecoin_verified_reg_statedecodeparams_1754401651146860.rpcsnap.json.zst +filecoin_verified_reg_statedecodeparams_1754401651146948.rpcsnap.json.zst +filecoin_verified_reg_statedecodeparams_1754401651147022.rpcsnap.json.zst +filecoin_verified_reg_statedecodeparams_1754401651147091.rpcsnap.json.zst +filecoin_verified_reg_statedecodeparams_1754401651147157.rpcsnap.json.zst +filecoin_verified_reg_statedecodeparams_1754401651147231.rpcsnap.json.zst filecoin_statereplay_1743504051038215.rpcsnap.json.zst filecoin_statesearchmsg_1741784596636715.rpcsnap.json.zst filecoin_statesearchmsglimited_1741784596704876.rpcsnap.json.zst From 8e2a6f07adbd9152c9d9a3587961fe00247cb475 Mon Sep 17 00:00:00 2001 From: Aryan Tikarya Date: Wed, 6 Aug 2025 19:20:19 +0530 Subject: [PATCH 07/11] add more test files --- src/tool/subcommands/api_cmd/test_snapshots.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/tool/subcommands/api_cmd/test_snapshots.txt b/src/tool/subcommands/api_cmd/test_snapshots.txt index e1ced05b208f..ad23b0b1634c 100644 --- a/src/tool/subcommands/api_cmd/test_snapshots.txt +++ b/src/tool/subcommands/api_cmd/test_snapshots.txt @@ -178,6 +178,10 @@ filecoin_multisig_statedecodeparams_1754230255631946.rpcsnap.json.zst filecoin_multisig_statedecodeparams_1754230255632019.rpcsnap.json.zst filecoin_multisig_statedecodeparams_1754581573704814.rpcsnap.json.zst filecoin_verified_reg_statedecodeparams_1754401651142334.rpcsnap.json.zst +filecoin_verified_reg_statedecodeparams_1754401651146144.rpcsnap.json.zst +filecoin_verified_reg_statedecodeparams_1754401651146246.rpcsnap.json.zst +filecoin_verified_reg_statedecodeparams_1754401651146327.rpcsnap.json.zst +filecoin_verified_reg_statedecodeparams_1754401651146402.rpcsnap.json.zst filecoin_verified_reg_statedecodeparams_1754401651146485.rpcsnap.json.zst filecoin_verified_reg_statedecodeparams_1754401651146560.rpcsnap.json.zst filecoin_verified_reg_statedecodeparams_1754401651146644.rpcsnap.json.zst From bd4dba41dbdd5f27b0e3f9fa14888e32860c9e6b Mon Sep 17 00:00:00 2001 From: Aryan Tikarya Date: Wed, 6 Aug 2025 20:42:00 +0530 Subject: [PATCH 08/11] replace failing rpc snap file --- src/tool/subcommands/api_cmd/test_snapshots.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tool/subcommands/api_cmd/test_snapshots.txt b/src/tool/subcommands/api_cmd/test_snapshots.txt index ad23b0b1634c..c1a019a2087a 100644 --- a/src/tool/subcommands/api_cmd/test_snapshots.txt +++ b/src/tool/subcommands/api_cmd/test_snapshots.txt @@ -178,7 +178,7 @@ filecoin_multisig_statedecodeparams_1754230255631946.rpcsnap.json.zst filecoin_multisig_statedecodeparams_1754230255632019.rpcsnap.json.zst filecoin_multisig_statedecodeparams_1754581573704814.rpcsnap.json.zst filecoin_verified_reg_statedecodeparams_1754401651142334.rpcsnap.json.zst -filecoin_verified_reg_statedecodeparams_1754401651146144.rpcsnap.json.zst +filecoin_verified_reg_statedecodeparams_1754492006350827.rpcsnap.json.zst filecoin_verified_reg_statedecodeparams_1754401651146246.rpcsnap.json.zst filecoin_verified_reg_statedecodeparams_1754401651146327.rpcsnap.json.zst filecoin_verified_reg_statedecodeparams_1754401651146402.rpcsnap.json.zst From 53be23e4b1cf77252a1563534bfc3f1c3e837863 Mon Sep 17 00:00:00 2001 From: Aryan Tikarya Date: Wed, 6 Aug 2025 20:42:44 +0530 Subject: [PATCH 09/11] refactor crypto signature conversion --- .../methods/verified_reg_actor.rs | 4 +- src/shim/crypto.rs | 131 +++++++++++++----- 2 files changed, 100 insertions(+), 35 deletions(-) diff --git a/src/lotus_json/actor_states/methods/verified_reg_actor.rs b/src/lotus_json/actor_states/methods/verified_reg_actor.rs index 76618b8abff0..8102cc8a797e 100644 --- a/src/lotus_json/actor_states/methods/verified_reg_actor.rs +++ b/src/lotus_json/actor_states/methods/verified_reg_actor.rs @@ -613,11 +613,11 @@ macro_rules! impl_remove_data_cap_params { data_cap_amount_to_remove: lotus_json.data_cap_amount_to_remove, verifier_request_1: fil_actor_verifreg_state::[]::RemoveDataCapRequest { verifier: lotus_json.verifier_request_1.verifier.into(), - signature: lotus_json.verifier_request_1.signature.into(), + signature: lotus_json.verifier_request_1.signature.try_into().unwrap(), }, verifier_request_2: fil_actor_verifreg_state::[]::RemoveDataCapRequest { verifier: lotus_json.verifier_request_2.verifier.into(), - signature: lotus_json.verifier_request_2.signature.into() + signature: lotus_json.verifier_request_2.signature.try_into().unwrap() }, } } diff --git a/src/shim/crypto.rs b/src/shim/crypto.rs index d698d247a4c2..edb41eed8209 100644 --- a/src/shim/crypto.rs +++ b/src/shim/crypto.rs @@ -96,18 +96,21 @@ impl From for Signature { } } -impl From for fvm_shared3::crypto::signature::Signature { - fn from(sig: Signature) -> Self { - Self { - sig_type: match sig.sig_type { - SignatureType::Bls => fvm_shared3::crypto::signature::SignatureType::BLS, - SignatureType::Secp256k1 => { - fvm_shared3::crypto::signature::SignatureType::Secp256k1 - } - SignatureType::Delegated => fvm_shared3::crypto::signature::SignatureType::BLS, // fallback v3 doesn't have Delegated - }, +impl TryFrom for fvm_shared3::crypto::signature::Signature { + type Error = anyhow::Error; + + fn try_from(sig: Signature) -> Result { + let sig_type = match sig.sig_type { + SignatureType::Bls => fvm_shared3::crypto::signature::SignatureType::BLS, + SignatureType::Secp256k1 => fvm_shared3::crypto::signature::SignatureType::Secp256k1, + SignatureType::Delegated => { + anyhow::bail!("fvm_shared3 does not support Delegated signature type") + } + }; + Ok(Self { + sig_type, bytes: sig.bytes, - } + }) } } @@ -125,33 +128,39 @@ impl From for Signature { } } -impl From for fvm_shared2::crypto::signature::Signature { - fn from(sig: Signature) -> Self { - Self { - sig_type: match sig.sig_type { - SignatureType::Bls => fvm_shared2::crypto::signature::SignatureType::BLS, - SignatureType::Secp256k1 => { - fvm_shared2::crypto::signature::SignatureType::Secp256k1 - } - SignatureType::Delegated => fvm_shared2::crypto::signature::SignatureType::BLS, // fallback if v2 doesn't have Delegated - }, +impl TryFrom for fvm_shared2::crypto::signature::Signature { + type Error = anyhow::Error; + + fn try_from(sig: Signature) -> Result { + let sig_type = match sig.sig_type { + SignatureType::Bls => fvm_shared2::crypto::signature::SignatureType::BLS, + SignatureType::Secp256k1 => fvm_shared2::crypto::signature::SignatureType::Secp256k1, + SignatureType::Delegated => { + anyhow::bail!("fvm_shared2 does not support Delegated signature type") + } + }; + Ok(Self { + sig_type, bytes: sig.bytes, - } + }) } } -impl From for fvm_shared4::crypto::signature::Signature { - fn from(sig: Signature) -> Self { - Self { - sig_type: match sig.sig_type { - SignatureType::Bls => fvm_shared4::crypto::signature::SignatureType::BLS, - SignatureType::Secp256k1 => { - fvm_shared4::crypto::signature::SignatureType::Secp256k1 - } - SignatureType::Delegated => fvm_shared4::crypto::signature::SignatureType::BLS, // fallback v4 doesn't have Delegated - }, +impl TryFrom for fvm_shared4::crypto::signature::Signature { + type Error = anyhow::Error; + + fn try_from(sig: Signature) -> Result { + let sig_type = match sig.sig_type { + SignatureType::Bls => fvm_shared4::crypto::signature::SignatureType::BLS, + SignatureType::Secp256k1 => fvm_shared4::crypto::signature::SignatureType::Secp256k1, + SignatureType::Delegated => { + anyhow::bail!("fvm_shared4 does not support Delegated signature type") + } + }; + Ok(Self { + sig_type, bytes: sig.bytes, - } + }) } } @@ -580,4 +589,60 @@ mod tests { assert!(result.is_err(), "Chain ID mismatch should fail"); } + + #[test] + fn test_try_from_delegated_signature_to_fvm_shared() { + let delegated_sig = Signature::new_delegated(vec![1, 2, 3, 4]); + + // Test conversion to fvm_shared2 + let result_v2: Result = + delegated_sig.clone().try_into(); + assert!(result_v2.is_err(), "Should fail for fvm_shared2"); + assert!( + result_v2 + .unwrap_err() + .to_string() + .contains("fvm_shared2 does not support Delegated") + ); + + // Test conversion to fvm_shared3 + let result_v3: Result = + delegated_sig.clone().try_into(); + assert!(result_v3.is_err(), "Should fail for fvm_shared3"); + assert!( + result_v3 + .unwrap_err() + .to_string() + .contains("fvm_shared3 does not support Delegated") + ); + + // Test conversion to fvm_shared4 + let result_v4: Result = + delegated_sig.try_into(); + assert!(result_v4.is_err(), "Should fail for fvm_shared4"); + assert!( + result_v4 + .unwrap_err() + .to_string() + .contains("fvm_shared4 does not support Delegated") + ); + } + + #[test] + fn test_try_from_valid_signatures_to_fvm_shared() { + let bls_sig = Signature::new_bls(vec![1, 2, 3, 4]); + let secp_sig = Signature::new_secp256k1(vec![5, 6, 7, 8]); + + // Test BLS conversion succeeds + let result_bls: Result = bls_sig.try_into(); + assert!(result_bls.is_ok(), "BLS conversion should succeed"); + let converted = result_bls.unwrap(); + assert_eq!(converted.bytes, vec![1, 2, 3, 4]); + + // Test Secp256k1 conversion succeeds + let result_secp: Result = secp_sig.try_into(); + assert!(result_secp.is_ok(), "Secp256k1 conversion should succeed"); + let converted = result_secp.unwrap(); + assert_eq!(converted.bytes, vec![5, 6, 7, 8]); + } } From b40cd3fb2c5d4bc7b12918c1498ccd117622fa47 Mon Sep 17 00:00:00 2001 From: Aryan Tikarya Date: Thu, 14 Aug 2025 14:55:39 +0530 Subject: [PATCH 10/11] fix formatting issue --- src/rpc/registry/methods_reg.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpc/registry/methods_reg.rs b/src/rpc/registry/methods_reg.rs index 469590f68731..46a46886bc42 100644 --- a/src/rpc/registry/methods_reg.rs +++ b/src/rpc/registry/methods_reg.rs @@ -74,7 +74,7 @@ impl MethodRegistry { fn register_known_methods(&mut self) { use crate::rpc::registry::actors::{ - account, datacap, evm, init, miner, multisig, power, reward, system, verified_reg + account, datacap, evm, init, miner, multisig, power, reward, system, verified_reg, }; for (&cid, &(actor_type, version)) in ACTOR_REGISTRY.iter() { From 311ae33d94f6038420148fdabc7ab29004a4f472 Mon Sep 17 00:00:00 2001 From: Aryan Tikarya Date: Mon, 18 Aug 2025 17:28:43 +0530 Subject: [PATCH 11/11] refactor the signature implementation and fix linter issues --- .../methods/verified_reg_actor.rs | 266 ++++++++++++++++-- src/lotus_json/signature.rs | 123 ++++++++ src/lotus_json/signature_type.rs | 93 ++++++ src/rpc/registry/actors/cron.rs | 1 - src/rpc/registry/actors/datacap.rs | 1 - src/rpc/registry/actors/multisig.rs | 1 - src/shim/crypto.rs | 152 ---------- 7 files changed, 459 insertions(+), 178 deletions(-) diff --git a/src/lotus_json/actor_states/methods/verified_reg_actor.rs b/src/lotus_json/actor_states/methods/verified_reg_actor.rs index 8102cc8a797e..06d86ba03102 100644 --- a/src/lotus_json/actor_states/methods/verified_reg_actor.rs +++ b/src/lotus_json/actor_states/methods/verified_reg_actor.rs @@ -4,7 +4,6 @@ use super::*; use crate::shim::address::Address; use crate::shim::clock::ChainEpoch; -use crate::shim::crypto::Signature; use crate::shim::sector::SectorNumber; use ::cid::Cid; use fvm_ipld_encoding::RawBytes; @@ -39,27 +38,74 @@ pub struct RemoveVerifierParamsLotusJson( Address, ); +// Version-specific structs for different FVM versions to avoid conversion issues #[derive(Serialize, Deserialize, Debug, Clone, PartialEq)] #[serde(rename_all = "PascalCase")] -pub struct RemoveDataCapParamsLotusJson { +pub struct RemoveDataCapParamsV2LotusJson { #[serde(with = "crate::lotus_json")] pub verified_client_to_remove: Address, #[serde(with = "crate::lotus_json")] pub data_cap_amount_to_remove: BigInt, - pub verifier_request_1: RemoveDataCapRequestLotusJson, - pub verifier_request_2: RemoveDataCapRequestLotusJson, + pub verifier_request_1: RemoveDataCapRequestV2LotusJson, + pub verifier_request_2: RemoveDataCapRequestV2LotusJson, } #[derive(Serialize, Deserialize, JsonSchema, Debug, Clone, PartialEq)] #[serde(rename_all = "PascalCase")] -pub struct RemoveDataCapRequestLotusJson { +pub struct RemoveDataCapRequestV2LotusJson { #[schemars(with = "LotusJson
")] #[serde(with = "crate::lotus_json")] pub verifier: Address, - #[schemars(with = "LotusJson")] + #[schemars(with = "LotusJson")] #[serde(with = "crate::lotus_json")] #[serde(rename = "VerifierSignature")] - pub signature: Signature, + pub signature: fvm_shared2::crypto::signature::Signature, +} + +#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)] +#[serde(rename_all = "PascalCase")] +pub struct RemoveDataCapParamsV3LotusJson { + #[serde(with = "crate::lotus_json")] + pub verified_client_to_remove: Address, + #[serde(with = "crate::lotus_json")] + pub data_cap_amount_to_remove: BigInt, + pub verifier_request_1: RemoveDataCapRequestV3LotusJson, + pub verifier_request_2: RemoveDataCapRequestV3LotusJson, +} + +#[derive(Serialize, Deserialize, JsonSchema, Debug, Clone, PartialEq)] +#[serde(rename_all = "PascalCase")] +pub struct RemoveDataCapRequestV3LotusJson { + #[schemars(with = "LotusJson
")] + #[serde(with = "crate::lotus_json")] + pub verifier: Address, + #[schemars(with = "LotusJson")] + #[serde(with = "crate::lotus_json")] + #[serde(rename = "VerifierSignature")] + pub signature: fvm_shared3::crypto::signature::Signature, +} + +#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)] +#[serde(rename_all = "PascalCase")] +pub struct RemoveDataCapParamsV4LotusJson { + #[serde(with = "crate::lotus_json")] + pub verified_client_to_remove: Address, + #[serde(with = "crate::lotus_json")] + pub data_cap_amount_to_remove: BigInt, + pub verifier_request_1: RemoveDataCapRequestV4LotusJson, + pub verifier_request_2: RemoveDataCapRequestV4LotusJson, +} + +#[derive(Serialize, Deserialize, JsonSchema, Debug, Clone, PartialEq)] +#[serde(rename_all = "PascalCase")] +pub struct RemoveDataCapRequestV4LotusJson { + #[schemars(with = "LotusJson
")] + #[serde(with = "crate::lotus_json")] + pub verifier: Address, + #[schemars(with = "LotusJson")] + #[serde(with = "crate::lotus_json")] + #[serde(rename = "VerifierSignature")] + pub signature: fvm_shared4::crypto::signature::Signature, } #[derive(Serialize, Deserialize, JsonSchema, Debug, Clone, PartialEq)] @@ -548,13 +594,13 @@ macro_rules! impl_extend_claim_terms_params { }; } -// Implementation for RemoveDataCapParams (unified for all versions) -macro_rules! impl_remove_data_cap_params { - ($type_suffix:path: $($version:literal),+) => { +// Implementation for RemoveDataCapParams with version-specific types +macro_rules! impl_remove_data_cap_params_v2 { + ($($version:literal),+) => { $( paste! { impl HasLotusJson for fil_actor_verifreg_state::[]::RemoveDataCapParams { - type LotusJson = RemoveDataCapParamsLotusJson; + type LotusJson = RemoveDataCapParamsV2LotusJson; #[cfg(test)] fn snapshots() -> Vec<(serde_json::Value, Self)> { @@ -582,27 +628,201 @@ macro_rules! impl_remove_data_cap_params { data_cap_amount_to_remove: BigInt::from(1000000000000000000u64), verifier_request_1: fil_actor_verifreg_state::[]::RemoveDataCapRequest { verifier: Address::new_id(1235).into(), - signature: $type_suffix::signature::Signature::new_bls(b"test".to_vec()), + signature: fvm_shared2::crypto::signature::Signature { + sig_type: fvm_shared2::crypto::signature::SignatureType::Secp256k1, + bytes: b"test".to_vec(), + }, + }, + verifier_request_2: fil_actor_verifreg_state::[]::RemoveDataCapRequest { + verifier: Address::new_id(1236).into(), + signature: fvm_shared2::crypto::signature::Signature { + sig_type: fvm_shared2::crypto::signature::SignatureType::Secp256k1, + bytes: b"test".to_vec(), + }, + }, + }, + )] + } + + fn into_lotus_json(self) -> Self::LotusJson { + RemoveDataCapParamsV2LotusJson { + verified_client_to_remove: self.verified_client_to_remove.into(), + data_cap_amount_to_remove: self.data_cap_amount_to_remove, + verifier_request_1: RemoveDataCapRequestV2LotusJson { + verifier: self.verifier_request_1.verifier.into(), + signature: self.verifier_request_1.signature, + }, + verifier_request_2: RemoveDataCapRequestV2LotusJson { + verifier: self.verifier_request_2.verifier.into(), + signature: self.verifier_request_2.signature, + }, + } + } + + fn from_lotus_json(lotus_json: Self::LotusJson) -> Self { + Self { + verified_client_to_remove: lotus_json.verified_client_to_remove.into(), + data_cap_amount_to_remove: lotus_json.data_cap_amount_to_remove, + verifier_request_1: fil_actor_verifreg_state::[]::RemoveDataCapRequest { + verifier: lotus_json.verifier_request_1.verifier.into(), + signature: lotus_json.verifier_request_1.signature, + }, + verifier_request_2: fil_actor_verifreg_state::[]::RemoveDataCapRequest { + verifier: lotus_json.verifier_request_2.verifier.into(), + signature: lotus_json.verifier_request_2.signature, + }, + } + } + } + } + )+ + }; +} + +macro_rules! impl_remove_data_cap_params_v3 { + ($($version:literal),+) => { + $( + paste! { + impl HasLotusJson for fil_actor_verifreg_state::[]::RemoveDataCapParams { + type LotusJson = RemoveDataCapParamsV3LotusJson; + + #[cfg(test)] + fn snapshots() -> Vec<(serde_json::Value, Self)> { + vec![( + json!({ + "VerifiedClientToRemove": "f01234", + "DataCapAmountToRemove": "1000000000000000000", + "VerifierRequest1": { + "Verifier": "f01235", + "VerifierSignature": { + "Type": 1, + "Data": "dGVzdA==", + } + }, + "VerifierRequest2": { + "Verifier": "f01236", + "VerifierSignature": { + "Type": 1, + "Data": "dGVzdA==", + } + }, + }), + Self { + verified_client_to_remove: Address::new_id(1234).into(), + data_cap_amount_to_remove: BigInt::from(1000000000000000000u64), + verifier_request_1: fil_actor_verifreg_state::[]::RemoveDataCapRequest { + verifier: Address::new_id(1235).into(), + signature: fvm_shared3::crypto::signature::Signature { + sig_type: fvm_shared3::crypto::signature::SignatureType::Secp256k1, + bytes: b"test".to_vec(), + }, + }, + verifier_request_2: fil_actor_verifreg_state::[]::RemoveDataCapRequest { + verifier: Address::new_id(1236).into(), + signature: fvm_shared3::crypto::signature::Signature { + sig_type: fvm_shared3::crypto::signature::SignatureType::Secp256k1, + bytes: b"test".to_vec(), + }, + }, + }, + )] + } + + fn into_lotus_json(self) -> Self::LotusJson { + RemoveDataCapParamsV3LotusJson { + verified_client_to_remove: self.verified_client_to_remove.into(), + data_cap_amount_to_remove: self.data_cap_amount_to_remove, + verifier_request_1: RemoveDataCapRequestV3LotusJson { + verifier: self.verifier_request_1.verifier.into(), + signature: self.verifier_request_1.signature, + }, + verifier_request_2: RemoveDataCapRequestV3LotusJson { + verifier: self.verifier_request_2.verifier.into(), + signature: self.verifier_request_2.signature, + }, + } + } + + fn from_lotus_json(lotus_json: Self::LotusJson) -> Self { + Self { + verified_client_to_remove: lotus_json.verified_client_to_remove.into(), + data_cap_amount_to_remove: lotus_json.data_cap_amount_to_remove, + verifier_request_1: fil_actor_verifreg_state::[]::RemoveDataCapRequest { + verifier: lotus_json.verifier_request_1.verifier.into(), + signature: lotus_json.verifier_request_1.signature, + }, + verifier_request_2: fil_actor_verifreg_state::[]::RemoveDataCapRequest { + verifier: lotus_json.verifier_request_2.verifier.into(), + signature: lotus_json.verifier_request_2.signature, + }, + } + } + } + } + )+ + }; +} + +macro_rules! impl_remove_data_cap_params_v4 { + ($($version:literal),+) => { + $( + paste! { + impl HasLotusJson for fil_actor_verifreg_state::[]::RemoveDataCapParams { + type LotusJson = RemoveDataCapParamsV4LotusJson; + + #[cfg(test)] + fn snapshots() -> Vec<(serde_json::Value, Self)> { + vec![( + json!({ + "VerifiedClientToRemove": "f01234", + "DataCapAmountToRemove": "1000000000000000000", + "VerifierRequest1": { + "Verifier": "f01235", + "VerifierSignature": { + "Type": 1, + "Data": "dGVzdA==", + } + }, + "VerifierRequest2": { + "Verifier": "f01236", + "VerifierSignature": { + "Type": 1, + "Data": "dGVzdA==", + } + }, + }), + Self { + verified_client_to_remove: Address::new_id(1234).into(), + data_cap_amount_to_remove: BigInt::from(1000000000000000000u64), + verifier_request_1: fil_actor_verifreg_state::[]::RemoveDataCapRequest { + verifier: Address::new_id(1235).into(), + signature: fvm_shared4::crypto::signature::Signature { + sig_type: fvm_shared4::crypto::signature::SignatureType::Secp256k1, + bytes: b"test".to_vec(), + }, }, verifier_request_2: fil_actor_verifreg_state::[]::RemoveDataCapRequest { verifier: Address::new_id(1236).into(), - signature: $type_suffix::signature::Signature::new_bls(b"test".to_vec()), + signature: fvm_shared4::crypto::signature::Signature { + sig_type: fvm_shared4::crypto::signature::SignatureType::Secp256k1, + bytes: b"test".to_vec(), + }, }, }, )] } fn into_lotus_json(self) -> Self::LotusJson { - RemoveDataCapParamsLotusJson { + RemoveDataCapParamsV4LotusJson { verified_client_to_remove: self.verified_client_to_remove.into(), data_cap_amount_to_remove: self.data_cap_amount_to_remove, - verifier_request_1: RemoveDataCapRequestLotusJson { + verifier_request_1: RemoveDataCapRequestV4LotusJson { verifier: self.verifier_request_1.verifier.into(), - signature: self.verifier_request_1.signature.into(), + signature: self.verifier_request_1.signature, }, - verifier_request_2: RemoveDataCapRequestLotusJson { + verifier_request_2: RemoveDataCapRequestV4LotusJson { verifier: self.verifier_request_2.verifier.into(), - signature: self.verifier_request_2.signature.into() + signature: self.verifier_request_2.signature, }, } } @@ -613,11 +833,11 @@ macro_rules! impl_remove_data_cap_params { data_cap_amount_to_remove: lotus_json.data_cap_amount_to_remove, verifier_request_1: fil_actor_verifreg_state::[]::RemoveDataCapRequest { verifier: lotus_json.verifier_request_1.verifier.into(), - signature: lotus_json.verifier_request_1.signature.try_into().unwrap(), + signature: lotus_json.verifier_request_1.signature, }, verifier_request_2: fil_actor_verifreg_state::[]::RemoveDataCapRequest { verifier: lotus_json.verifier_request_2.verifier.into(), - signature: lotus_json.verifier_request_2.signature.try_into().unwrap() + signature: lotus_json.verifier_request_2.signature, }, } } @@ -1024,9 +1244,9 @@ impl_get_claims_params!(9, 10, 11, 12, 13, 14, 15, 16); impl_remove_expired_claims_params!(9, 10, 11, 12, 13, 14, 15, 16); impl_extend_claim_terms_params!(9, 10, 11, 12, 13, 14, 15, 16); -impl_remove_data_cap_params!(fvm_shared2::crypto: 8, 9); -impl_remove_data_cap_params!(fvm_shared3::crypto: 10, 11); -impl_remove_data_cap_params!(fvm_shared4::crypto: 12, 13, 14, 15, 16); +impl_remove_data_cap_params_v2!(8, 9); +impl_remove_data_cap_params_v3!(10, 11); +impl_remove_data_cap_params_v4!(12, 13, 14, 15, 16); impl_claim_allocations_params_v11!(fvm_shared2: 9); impl_claim_allocations_params_v11!(fvm_shared3: 10, 11); diff --git a/src/lotus_json/signature.rs b/src/lotus_json/signature.rs index a329c787e1d8..44ec3d828800 100644 --- a/src/lotus_json/signature.rs +++ b/src/lotus_json/signature.rs @@ -16,6 +16,42 @@ pub struct SignatureLotusJson { data: Vec, } +#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, JsonSchema)] +#[serde(rename_all = "PascalCase")] +#[schemars(rename = "Signature")] +pub struct SignatureV2LotusJson { + #[schemars(with = "LotusJson")] + #[serde(with = "crate::lotus_json")] + r#type: fvm_shared2::crypto::signature::SignatureType, + #[schemars(with = "LotusJson>")] + #[serde(with = "crate::lotus_json")] + data: Vec, +} + +#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, JsonSchema)] +#[serde(rename_all = "PascalCase")] +#[schemars(rename = "Signature")] +pub struct SignatureV3LotusJson { + #[schemars(with = "LotusJson")] + #[serde(with = "crate::lotus_json")] + r#type: fvm_shared3::crypto::signature::SignatureType, + #[schemars(with = "LotusJson>")] + #[serde(with = "crate::lotus_json")] + data: Vec, +} + +#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, JsonSchema)] +#[serde(rename_all = "PascalCase")] +#[schemars(rename = "Signature")] +pub struct SignatureV4LotusJson { + #[schemars(with = "LotusJson")] + #[serde(with = "crate::lotus_json")] + r#type: fvm_shared4::crypto::signature::SignatureType, + #[schemars(with = "LotusJson>")] + #[serde(with = "crate::lotus_json")] + data: Vec, +} + impl HasLotusJson for Signature { type LotusJson = SignatureLotusJson; @@ -46,3 +82,90 @@ impl HasLotusJson for Signature { } } } + +impl HasLotusJson for fvm_shared2::crypto::signature::Signature { + type LotusJson = SignatureV2LotusJson; + + #[cfg(test)] + fn snapshots() -> Vec<(serde_json::Value, Self)> { + vec![( + json!({"Type": 2, "Data": "aGVsbG8gd29ybGQh"}), + Self { + sig_type: fvm_shared2::crypto::signature::SignatureType::BLS, + bytes: Vec::from_iter(*b"hello world!"), + }, + )] + } + + fn into_lotus_json(self) -> Self::LotusJson { + SignatureV2LotusJson { + r#type: self.sig_type, + data: self.bytes, + } + } + + fn from_lotus_json(lotus_json: Self::LotusJson) -> Self { + Self { + sig_type: lotus_json.r#type, + bytes: lotus_json.data, + } + } +} + +impl HasLotusJson for fvm_shared3::crypto::signature::Signature { + type LotusJson = SignatureV3LotusJson; + + #[cfg(test)] + fn snapshots() -> Vec<(serde_json::Value, Self)> { + vec![( + json!({"Type": 1, "Data": "aGVsbG8gd29ybGQh"}), + Self { + sig_type: fvm_shared3::crypto::signature::SignatureType::Secp256k1, + bytes: Vec::from_iter(*b"hello world!"), + }, + )] + } + + fn into_lotus_json(self) -> Self::LotusJson { + SignatureV3LotusJson { + r#type: self.sig_type, + data: self.bytes, + } + } + + fn from_lotus_json(lotus_json: Self::LotusJson) -> Self { + Self { + sig_type: lotus_json.r#type, + bytes: lotus_json.data, + } + } +} + +impl HasLotusJson for fvm_shared4::crypto::signature::Signature { + type LotusJson = SignatureV4LotusJson; + + #[cfg(test)] + fn snapshots() -> Vec<(serde_json::Value, Self)> { + vec![( + json!({"Type": 1, "Data": "aGVsbG8gd29ybGQh"}), + Self { + sig_type: fvm_shared4::crypto::signature::SignatureType::Secp256k1, + bytes: Vec::from_iter(*b"hello world!"), + }, + )] + } + + fn into_lotus_json(self) -> Self::LotusJson { + SignatureV4LotusJson { + r#type: self.sig_type, + data: self.bytes, + } + } + + fn from_lotus_json(lotus_json: Self::LotusJson) -> Self { + Self { + sig_type: lotus_json.r#type, + bytes: lotus_json.data, + } + } +} diff --git a/src/lotus_json/signature_type.rs b/src/lotus_json/signature_type.rs index 1d0289f026cc..07aad5ac2cfe 100644 --- a/src/lotus_json/signature_type.rs +++ b/src/lotus_json/signature_type.rs @@ -48,3 +48,96 @@ fn deserialize_integer() { serde_json::from_value(json!(2)).unwrap() ); } + +#[derive(Deserialize, Serialize, JsonSchema)] +#[serde(untagged)] +pub enum SignatureTypeV2LotusJson { + Integer(#[schemars(with = "u8")] fvm_shared2::crypto::signature::SignatureType), +} + +#[derive(Deserialize, Serialize, JsonSchema)] +#[serde(untagged)] +pub enum SignatureTypeV3LotusJson { + Integer(#[schemars(with = "u8")] fvm_shared3::crypto::signature::SignatureType), +} + +#[derive(Deserialize, Serialize, JsonSchema)] +#[serde(untagged)] +pub enum SignatureTypeV4LotusJson { + Integer(#[schemars(with = "u8")] fvm_shared4::crypto::signature::SignatureType), +} + +impl HasLotusJson for fvm_shared2::crypto::signature::SignatureType { + type LotusJson = SignatureTypeV2LotusJson; + + #[cfg(test)] + fn snapshots() -> Vec<(serde_json::Value, Self)> { + vec![ + ( + json!(1), + fvm_shared2::crypto::signature::SignatureType::Secp256k1, + ), + (json!(2), fvm_shared2::crypto::signature::SignatureType::BLS), + ] + } + + fn into_lotus_json(self) -> Self::LotusJson { + SignatureTypeV2LotusJson::Integer(self) + } + + fn from_lotus_json(lotus_json: Self::LotusJson) -> Self { + match lotus_json { + SignatureTypeV2LotusJson::Integer(inner) => inner, + } + } +} + +impl HasLotusJson for fvm_shared3::crypto::signature::SignatureType { + type LotusJson = SignatureTypeV3LotusJson; + + #[cfg(test)] + fn snapshots() -> Vec<(serde_json::Value, Self)> { + vec![ + ( + json!(1), + fvm_shared3::crypto::signature::SignatureType::Secp256k1, + ), + (json!(2), fvm_shared3::crypto::signature::SignatureType::BLS), + ] + } + + fn into_lotus_json(self) -> Self::LotusJson { + SignatureTypeV3LotusJson::Integer(self) + } + + fn from_lotus_json(lotus_json: Self::LotusJson) -> Self { + match lotus_json { + SignatureTypeV3LotusJson::Integer(inner) => inner, + } + } +} + +impl HasLotusJson for fvm_shared4::crypto::signature::SignatureType { + type LotusJson = SignatureTypeV4LotusJson; + + #[cfg(test)] + fn snapshots() -> Vec<(serde_json::Value, Self)> { + vec![ + ( + json!(1), + fvm_shared4::crypto::signature::SignatureType::Secp256k1, + ), + (json!(2), fvm_shared4::crypto::signature::SignatureType::BLS), + ] + } + + fn into_lotus_json(self) -> Self::LotusJson { + SignatureTypeV4LotusJson::Integer(self) + } + + fn from_lotus_json(lotus_json: Self::LotusJson) -> Self { + match lotus_json { + SignatureTypeV4LotusJson::Integer(inner) => inner, + } + } +} diff --git a/src/rpc/registry/actors/cron.rs b/src/rpc/registry/actors/cron.rs index 12f9143cafb4..56117b2afbaf 100644 --- a/src/rpc/registry/actors/cron.rs +++ b/src/rpc/registry/actors/cron.rs @@ -3,7 +3,6 @@ use crate::rpc::registry::methods_reg::{MethodRegistry, register_actor_methods}; use crate::shim::message::MethodNum; -use anyhow::Result; use cid::Cid; macro_rules! register_cron_version { diff --git a/src/rpc/registry/actors/datacap.rs b/src/rpc/registry/actors/datacap.rs index df13780b9948..d21bd4b22bed 100644 --- a/src/rpc/registry/actors/datacap.rs +++ b/src/rpc/registry/actors/datacap.rs @@ -4,7 +4,6 @@ use crate::rpc::registry::methods_reg::{MethodRegistry, register_actor_methods}; use crate::shim::address::Address; use crate::shim::message::MethodNum; -use anyhow::Result; use cid::Cid; macro_rules! register_datacap_v9 { diff --git a/src/rpc/registry/actors/multisig.rs b/src/rpc/registry/actors/multisig.rs index 543e11d1890a..b7b6c689ce6a 100644 --- a/src/rpc/registry/actors/multisig.rs +++ b/src/rpc/registry/actors/multisig.rs @@ -3,7 +3,6 @@ use crate::rpc::registry::methods_reg::{MethodRegistry, register_actor_methods}; use crate::shim::message::MethodNum; -use anyhow::Result; use cid::Cid; // Macro for version 8 that doesn't have UniversalReceiverHook diff --git a/src/shim/crypto.rs b/src/shim/crypto.rs index edb41eed8209..5b1ad4536d59 100644 --- a/src/shim/crypto.rs +++ b/src/shim/crypto.rs @@ -68,102 +68,6 @@ impl<'de> de::Deserialize<'de> for Signature { } } -impl From for Signature { - fn from(sig: fvm_shared3::crypto::signature::Signature) -> Self { - Self { - sig_type: match sig.sig_type { - fvm_shared3::crypto::signature::SignatureType::BLS => SignatureType::Bls, - fvm_shared3::crypto::signature::SignatureType::Secp256k1 => { - SignatureType::Secp256k1 - } - }, - bytes: sig.bytes, - } - } -} - -impl From for Signature { - fn from(sig: fvm_shared4::crypto::signature::Signature) -> Self { - Self { - sig_type: match sig.sig_type { - fvm_shared4::crypto::signature::SignatureType::BLS => SignatureType::Bls, - fvm_shared4::crypto::signature::SignatureType::Secp256k1 => { - SignatureType::Secp256k1 - } - }, - bytes: sig.bytes, - } - } -} - -impl TryFrom for fvm_shared3::crypto::signature::Signature { - type Error = anyhow::Error; - - fn try_from(sig: Signature) -> Result { - let sig_type = match sig.sig_type { - SignatureType::Bls => fvm_shared3::crypto::signature::SignatureType::BLS, - SignatureType::Secp256k1 => fvm_shared3::crypto::signature::SignatureType::Secp256k1, - SignatureType::Delegated => { - anyhow::bail!("fvm_shared3 does not support Delegated signature type") - } - }; - Ok(Self { - sig_type, - bytes: sig.bytes, - }) - } -} - -impl From for Signature { - fn from(sig: fvm_shared2::crypto::signature::Signature) -> Self { - Self { - sig_type: match sig.sig_type { - fvm_shared2::crypto::signature::SignatureType::BLS => SignatureType::Bls, - fvm_shared2::crypto::signature::SignatureType::Secp256k1 => { - SignatureType::Secp256k1 - } - }, - bytes: sig.bytes, - } - } -} - -impl TryFrom for fvm_shared2::crypto::signature::Signature { - type Error = anyhow::Error; - - fn try_from(sig: Signature) -> Result { - let sig_type = match sig.sig_type { - SignatureType::Bls => fvm_shared2::crypto::signature::SignatureType::BLS, - SignatureType::Secp256k1 => fvm_shared2::crypto::signature::SignatureType::Secp256k1, - SignatureType::Delegated => { - anyhow::bail!("fvm_shared2 does not support Delegated signature type") - } - }; - Ok(Self { - sig_type, - bytes: sig.bytes, - }) - } -} - -impl TryFrom for fvm_shared4::crypto::signature::Signature { - type Error = anyhow::Error; - - fn try_from(sig: Signature) -> Result { - let sig_type = match sig.sig_type { - SignatureType::Bls => fvm_shared4::crypto::signature::SignatureType::BLS, - SignatureType::Secp256k1 => fvm_shared4::crypto::signature::SignatureType::Secp256k1, - SignatureType::Delegated => { - anyhow::bail!("fvm_shared4 does not support Delegated signature type") - } - }; - Ok(Self { - sig_type, - bytes: sig.bytes, - }) - } -} - impl Signature { pub fn new(sig_type: SignatureType, bytes: Vec) -> Self { Signature { sig_type, bytes } @@ -589,60 +493,4 @@ mod tests { assert!(result.is_err(), "Chain ID mismatch should fail"); } - - #[test] - fn test_try_from_delegated_signature_to_fvm_shared() { - let delegated_sig = Signature::new_delegated(vec![1, 2, 3, 4]); - - // Test conversion to fvm_shared2 - let result_v2: Result = - delegated_sig.clone().try_into(); - assert!(result_v2.is_err(), "Should fail for fvm_shared2"); - assert!( - result_v2 - .unwrap_err() - .to_string() - .contains("fvm_shared2 does not support Delegated") - ); - - // Test conversion to fvm_shared3 - let result_v3: Result = - delegated_sig.clone().try_into(); - assert!(result_v3.is_err(), "Should fail for fvm_shared3"); - assert!( - result_v3 - .unwrap_err() - .to_string() - .contains("fvm_shared3 does not support Delegated") - ); - - // Test conversion to fvm_shared4 - let result_v4: Result = - delegated_sig.try_into(); - assert!(result_v4.is_err(), "Should fail for fvm_shared4"); - assert!( - result_v4 - .unwrap_err() - .to_string() - .contains("fvm_shared4 does not support Delegated") - ); - } - - #[test] - fn test_try_from_valid_signatures_to_fvm_shared() { - let bls_sig = Signature::new_bls(vec![1, 2, 3, 4]); - let secp_sig = Signature::new_secp256k1(vec![5, 6, 7, 8]); - - // Test BLS conversion succeeds - let result_bls: Result = bls_sig.try_into(); - assert!(result_bls.is_ok(), "BLS conversion should succeed"); - let converted = result_bls.unwrap(); - assert_eq!(converted.bytes, vec![1, 2, 3, 4]); - - // Test Secp256k1 conversion succeeds - let result_secp: Result = secp_sig.try_into(); - assert!(result_secp.is_ok(), "Secp256k1 conversion should succeed"); - let converted = result_secp.unwrap(); - assert_eq!(converted.bytes, vec![5, 6, 7, 8]); - } }