diff --git a/CHANGELOG.md b/CHANGELOG.md index 7dda289f3c2..1236b67b3f7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,6 +35,8 @@ ### Fixed +- [#7227](https://github.com/ChainSafe/forest/issues/7227): Fixed invalid `Filecoin.GasEstimateGasPremium` and `Filecoin.GasEstimateFeeCap` responses that were returning a fraction instead of an integer. + ## Forest v0.33.7 "Shimmergloom" ### Added diff --git a/scripts/tests/api_compare/filter-list-gateway b/scripts/tests/api_compare/filter-list-gateway index 870225d6f8c..ada82a50479 100644 --- a/scripts/tests/api_compare/filter-list-gateway +++ b/scripts/tests/api_compare/filter-list-gateway @@ -12,6 +12,7 @@ !Filecoin.EthGetTransactionByHashLimited !Filecoin.F3 !Filecoin.GasEstimateGasLimit +!Filecoin.GasEstimateFeeCap !Filecoin.MinerCreateBlock !Filecoin.MpoolGetConfig !Filecoin.MpoolSelect diff --git a/src/rpc/methods/gas.rs b/src/rpc/methods/gas.rs index af7cdec3c02..7d82dae054a 100644 --- a/src/rpc/methods/gas.rs +++ b/src/rpc/methods/gas.rs @@ -37,14 +37,14 @@ impl RpcMethod<3> for GasEstimateFeeCap { Some("Returns the estimated fee cap for the given parameters."); type Params = (Message, i64, ApiTipsetKey); - type Ok = String; + type Ok = TokenAmount; async fn handle( ctx: Ctx, (msg, max_queue_blks, tsk): Self::Params, _: &http::Extensions, ) -> Result { - estimate_fee_cap(&ctx, &msg, max_queue_blks, &tsk).map(|n| TokenAmount::to_string(&n)) + estimate_fee_cap(&ctx, &msg, max_queue_blks, &tsk) } } @@ -85,16 +85,14 @@ impl RpcMethod<4> for GasEstimateGasPremium { Some("Returns the estimated gas premium for the given parameters."); type Params = (u64, Address, i64, ApiTipsetKey); - type Ok = String; + type Ok = TokenAmount; async fn handle( ctx: Ctx, (nblocksincl, _sender, _gas_limit, tsk): Self::Params, _: &http::Extensions, ) -> Result { - estimate_gas_premium(&ctx, nblocksincl, &tsk) - .await - .map(|n| TokenAmount::to_string(&n)) + estimate_gas_premium(&ctx, nblocksincl, &tsk).await } } diff --git a/src/rpc/snapshots/forest__rpc__tests__rpc__v0.snap b/src/rpc/snapshots/forest__rpc__tests__rpc__v0.snap index 616900104cd..522afa58b03 100644 --- a/src/rpc/snapshots/forest__rpc__tests__rpc__v0.snap +++ b/src/rpc/snapshots/forest__rpc__tests__rpc__v0.snap @@ -1869,7 +1869,7 @@ methods: name: Filecoin.GasEstimateFeeCap.Result required: true schema: - type: string + $ref: "#/components/schemas/TokenAmount" paramStructure: by-position - name: Filecoin.GasEstimateGasLimit description: Returns the estimated gas limit for the given parameters. @@ -1923,7 +1923,7 @@ methods: name: Filecoin.GasEstimateGasPremium.Result required: true schema: - type: string + $ref: "#/components/schemas/TokenAmount" paramStructure: by-position - name: Filecoin.GasEstimateMessageGas description: Returns the estimated gas for the given parameters. diff --git a/src/rpc/snapshots/forest__rpc__tests__rpc__v1.snap b/src/rpc/snapshots/forest__rpc__tests__rpc__v1.snap index 103f87e5e3b..0b86416f0f0 100644 --- a/src/rpc/snapshots/forest__rpc__tests__rpc__v1.snap +++ b/src/rpc/snapshots/forest__rpc__tests__rpc__v1.snap @@ -1949,7 +1949,7 @@ methods: name: Filecoin.GasEstimateFeeCap.Result required: true schema: - type: string + $ref: "#/components/schemas/TokenAmount" paramStructure: by-position - name: Filecoin.GasEstimateGasLimit description: Returns the estimated gas limit for the given parameters. @@ -2003,7 +2003,7 @@ methods: name: Filecoin.GasEstimateGasPremium.Result required: true schema: - type: string + $ref: "#/components/schemas/TokenAmount" paramStructure: by-position - name: Filecoin.GasEstimateMessageGas description: Returns the estimated gas for the given parameters. diff --git a/src/tool/subcommands/api_cmd/api_compare_tests.rs b/src/tool/subcommands/api_cmd/api_compare_tests.rs index c4adc623224..b880adaa971 100644 --- a/src/tool/subcommands/api_cmd/api_compare_tests.rs +++ b/src/tool/subcommands/api_cmd/api_compare_tests.rs @@ -2388,7 +2388,7 @@ fn gas_tests_with_tipset(shared_tipset: &Tipset) -> Vec { // return reasonable values within expected bounds rather than exact equality. RpcTest::validate( GasEstimateMessageGas::request(( - message, + message.clone(), None, // No MessageSendSpec shared_tipset.key().into(), )) @@ -2417,6 +2417,35 @@ fn gas_tests_with_tipset(shared_tipset: &Tipset) -> Vec { && forest_premium.is_within_percent(lotus_premium, 5) }, ), + // Pin to `shared_tipset` so both nodes compute over the same chain history; + // the only remaining difference is each node's ±1% gaussian noise, which the + // 5% tolerance absorbs. The heaviest tipset would compare two independently- + // synced heads and diff arbitrarily. + RpcTest::validate( + GasEstimateGasPremium::request((3, addr, 9, shared_tipset.key().into())).unwrap(), + |forest_premium, lotus_premium| { + // Gas premium should not be negative + if forest_premium.is_negative() || lotus_premium.is_negative() { + return false; + } + + forest_premium.is_within_percent(&lotus_premium, 5) + }, + ), + // The fee cap derives from the noise-perturbed premium, so use the same 5% + // tolerance; pinning to `shared_tipset` fixes the parent base fee both nodes + // read. Deserializing the result as `TokenAmount` is what rejects a FIL-decimal + // serialization regression (such a string fails to parse as an integer). + RpcTest::validate( + GasEstimateFeeCap::request((message, 20, shared_tipset.key().into())).unwrap(), + |forest_fee_cap, lotus_fee_cap| { + if forest_fee_cap.is_negative() || lotus_fee_cap.is_negative() { + return false; + } + + forest_fee_cap.is_within_percent(&lotus_fee_cap, 5) + }, + ), ] }