From 872066123aeb11d9ee0aba0aaa3a969ef255d47d Mon Sep 17 00:00:00 2001 From: amit-momin Date: Fri, 28 Jun 2024 11:26:08 -0500 Subject: [PATCH] Fixed upgrade check batch result parsing --- core/chains/evm/gas/rollups/op_l1_oracle.go | 32 ++++++++++++++++--- .../evm/gas/rollups/op_l1_oracle_test.go | 13 ++++++-- 2 files changed, 38 insertions(+), 7 deletions(-) diff --git a/core/chains/evm/gas/rollups/op_l1_oracle.go b/core/chains/evm/gas/rollups/op_l1_oracle.go index 2a82ce212cf..51d0cd2ca6f 100644 --- a/core/chains/evm/gas/rollups/op_l1_oracle.go +++ b/core/chains/evm/gas/rollups/op_l1_oracle.go @@ -52,7 +52,9 @@ type optimismL1Oracle struct { blobBaseFeeScalarCalldata []byte decimalsCalldata []byte isEcotoneCalldata []byte + isEcotoneMethodAbi abi.ABI isFjordCalldata []byte + isFjordMethodAbi abi.ABI } const ( @@ -208,7 +210,9 @@ func newOpStackL1GasOracle(lggr logger.Logger, ethClient l1OracleClient, chainTy blobBaseFeeScalarCalldata: blobBaseFeeScalarCalldata, decimalsCalldata: decimalsCalldata, isEcotoneCalldata: isEcotoneCalldata, + isEcotoneMethodAbi: isEcotoneMethodAbi, isFjordCalldata: isFjordCalldata, + isFjordMethodAbi: isFjordMethodAbi, }, nil } @@ -373,7 +377,7 @@ func (o *optimismL1Oracle) checkForUpgrade(ctx context.Context) error { }, "latest", }, - Result: new(bool), + Result: new(string), }, { Method: "eth_call", @@ -385,7 +389,7 @@ func (o *optimismL1Oracle) checkForUpgrade(ctx context.Context) error { }, "latest", }, - Result: new(bool), + Result: new(string), }, } err := o.client.BatchCallContext(ctx, rpcBatchCalls) @@ -394,10 +398,30 @@ func (o *optimismL1Oracle) checkForUpgrade(ctx context.Context) error { } // These calls are expected to revert if chain has not upgraded. Ignore non-nil Error field. if rpcBatchCalls[0].Error == nil { - o.isFjord = *(rpcBatchCalls[0].Result.(*bool)) + result := *(rpcBatchCalls[0].Result.(*string)) + if b, err := hexutil.Decode(result); err == nil { + if res, err := o.isFjordMethodAbi.Unpack(isFjordMethod, b); err == nil { + o.isFjord = res[0].(bool) + } else { + o.logger.Errorw("failed to unpack results", "method", isFjordMethod, "hex", result, "error", err) + } + } else { + o.logger.Errorw("failed to decode bytes", "method", isFjordMethod, "hex", result, "error", err) + } + } if rpcBatchCalls[1].Error == nil { - o.isEcotone = *(rpcBatchCalls[1].Result.(*bool)) + result := *(rpcBatchCalls[1].Result.(*string)) + if b, err := hexutil.Decode(result); err == nil { + if res, err := o.isEcotoneMethodAbi.Unpack(isEcotoneMethod, b); err == nil { + o.isEcotone = res[0].(bool) + } else { + o.logger.Errorw("failed to unpack results", "method", isEcotoneMethod, "hex", result, "error", err) + } + } else { + o.logger.Errorw("failed to decode bytes", "method", isEcotoneMethod, "hex", result, "error", err) + } + } return nil } diff --git a/core/chains/evm/gas/rollups/op_l1_oracle_test.go b/core/chains/evm/gas/rollups/op_l1_oracle_test.go index 800e39a4f8d..f5f009f1ea6 100644 --- a/core/chains/evm/gas/rollups/op_l1_oracle_test.go +++ b/core/chains/evm/gas/rollups/op_l1_oracle_test.go @@ -80,7 +80,7 @@ func TestOPL1Oracle_ReadV1GasPrice(t *testing.T) { } require.Equal(t, hexutil.Bytes(isFjordCalldata), rpcElements[0].Args[0].(map[string]interface{})["data"]) require.Equal(t, hexutil.Bytes(isEcotoneCalldata), rpcElements[1].Args[0].(map[string]interface{})["data"]) - isUpgraded := false + isUpgraded := "0x0000000000000000000000000000000000000000000000000000000000000000" if tc.isFjordError { rpcElements[0].Error = fmt.Errorf("test error") } else { @@ -112,6 +112,12 @@ func TestOPL1Oracle_ReadV1GasPrice(t *testing.T) { } func setupUpgradeCheck(t *testing.T, oracleAddress string, isFjord, isEcotone bool) *mocks.L1OracleClient { + trueHex := "0x0000000000000000000000000000000000000000000000000000000000000001" + falseHex := "0x0000000000000000000000000000000000000000000000000000000000000000" + boolToHexMap := map[bool]*string{ + true: &trueHex, + false: &falseHex, + } // IsFjord calldata isFjordMethodAbi, err := abi.JSON(strings.NewReader(OPIsFjordAbiString)) require.NoError(t, err) @@ -135,8 +141,9 @@ func setupUpgradeCheck(t *testing.T, oracleAddress string, isFjord, isEcotone bo } require.Equal(t, hexutil.Bytes(isFjordCalldata), rpcElements[0].Args[0].(map[string]interface{})["data"]) require.Equal(t, hexutil.Bytes(isEcotoneCalldata), rpcElements[1].Args[0].(map[string]interface{})["data"]) - rpcElements[0].Result = &isFjord - rpcElements[1].Result = &isEcotone + + rpcElements[0].Result = boolToHexMap[isFjord] + rpcElements[1].Result = boolToHexMap[isEcotone] }).Return(nil).Once() return ethClient