Skip to content

Commit

Permalink
Fixed upgrade check batch result parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
amit-momin committed Jun 28, 2024
1 parent d63c64c commit 8720661
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 7 deletions.
32 changes: 28 additions & 4 deletions core/chains/evm/gas/rollups/op_l1_oracle.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ type optimismL1Oracle struct {
blobBaseFeeScalarCalldata []byte
decimalsCalldata []byte
isEcotoneCalldata []byte
isEcotoneMethodAbi abi.ABI
isFjordCalldata []byte
isFjordMethodAbi abi.ABI
}

const (
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -373,7 +377,7 @@ func (o *optimismL1Oracle) checkForUpgrade(ctx context.Context) error {
},
"latest",
},
Result: new(bool),
Result: new(string),
},
{
Method: "eth_call",
Expand All @@ -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)
Expand All @@ -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 {

Check failure on line 403 in core/chains/evm/gas/rollups/op_l1_oracle.go

View workflow job for this annotation

GitHub Actions / lint

shadow: declaration of "err" shadows declaration at line 402 (govet)
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)
}

}

Check failure on line 412 in core/chains/evm/gas/rollups/op_l1_oracle.go

View workflow job for this annotation

GitHub Actions / lint

unnecessary trailing newline (whitespace)
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 {

Check failure on line 416 in core/chains/evm/gas/rollups/op_l1_oracle.go

View workflow job for this annotation

GitHub Actions / lint

shadow: declaration of "err" shadows declaration at line 415 (govet)
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)
}

}

Check failure on line 425 in core/chains/evm/gas/rollups/op_l1_oracle.go

View workflow job for this annotation

GitHub Actions / lint

unnecessary trailing newline (whitespace)
return nil
}
Expand Down
13 changes: 10 additions & 3 deletions core/chains/evm/gas/rollups/op_l1_oracle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit 8720661

Please sign in to comment.