From 6ffc8c4a9b76a79b8ec977be583fb591a3522024 Mon Sep 17 00:00:00 2001 From: Fergal Gribben Date: Tue, 2 Jul 2024 11:45:04 +0100 Subject: [PATCH] Only set non nil block numbers --- .changeset/curvy-months-change.md | 2 +- .../ocr2keeper/evmregistry/v20/registry.go | 61 ++++++++++++------- .../v21/registry_check_pipeline.go | 43 ++++++++----- 3 files changed, 67 insertions(+), 39 deletions(-) diff --git a/.changeset/curvy-months-change.md b/.changeset/curvy-months-change.md index ee1af694f72..1a3b1b3ce99 100644 --- a/.changeset/curvy-months-change.md +++ b/.changeset/curvy-months-change.md @@ -2,4 +2,4 @@ "chainlink": patch --- -Allow block 0 in buildCallOpts to prevent nil pointer #changed +Only encode non nil block numbers for eth_call #changed diff --git a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v20/registry.go b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v20/registry.go index 524d4177f3f..0cddd434483 100644 --- a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v20/registry.go +++ b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v20/registry.go @@ -466,7 +466,9 @@ func (r *EvmRegistry) buildCallOpts(ctx context.Context, block *big.Int) (*bind. } if block == nil || block.Int64() == 0 { - opts.BlockNumber = big.NewInt(r.LatestBlock()) + if r.LatestBlock() != 0 { + opts.BlockNumber = big.NewInt(r.LatestBlock()) + } } else { opts.BlockNumber = block } @@ -592,16 +594,21 @@ func (r *EvmRegistry) checkUpkeeps(ctx context.Context, keys []ocr2keepers.Upkee return nil, err } + args := []interface{}{ + map[string]interface{}{ + "to": r.addr.Hex(), + "data": hexutil.Bytes(payload), + }, + } + + if opts.BlockNumber != nil { + args = append(args, hexutil.EncodeBig(opts.BlockNumber)) + } + var result string checkReqs[i] = rpc.BatchElem{ Method: "eth_call", - Args: []interface{}{ - map[string]interface{}{ - "to": r.addr.Hex(), - "data": hexutil.Bytes(payload), - }, - hexutil.EncodeBig(opts.BlockNumber), - }, + Args: args, Result: &result, } @@ -658,16 +665,21 @@ func (r *EvmRegistry) simulatePerformUpkeeps(ctx context.Context, checkResults [ return nil, err } + args := []interface{}{ + map[string]interface{}{ + "to": r.addr.Hex(), + "data": hexutil.Bytes(payload), + }, + } + + if opts.BlockNumber != nil { + args = append(args, hexutil.EncodeBig(opts.BlockNumber)) + } + var result string performReqs = append(performReqs, rpc.BatchElem{ Method: "eth_call", - Args: []interface{}{ - map[string]interface{}{ - "to": r.addr.Hex(), - "data": hexutil.Bytes(payload), - }, - hexutil.EncodeBig(opts.BlockNumber), - }, + Args: args, Result: &result, }) @@ -724,16 +736,21 @@ func (r *EvmRegistry) getUpkeepConfigs(ctx context.Context, ids []*big.Int) ([]a return nil, fmt.Errorf("failed to pack id with abi: %s", err) } + args := []interface{}{ + map[string]interface{}{ + "to": r.addr.Hex(), + "data": hexutil.Bytes(payload), + }, + } + + if opts.BlockNumber != nil { + args = append(args, hexutil.EncodeBig(opts.BlockNumber)) + } + var result string uReqs[i] = rpc.BatchElem{ Method: "eth_call", - Args: []interface{}{ - map[string]interface{}{ - "to": r.addr.Hex(), - "data": hexutil.Bytes(payload), - }, - hexutil.EncodeBig(opts.BlockNumber), - }, + Args: args, Result: &result, } diff --git a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/registry_check_pipeline.go b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/registry_check_pipeline.go index f14c9865c35..4b68286b526 100644 --- a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/registry_check_pipeline.go +++ b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/registry_check_pipeline.go @@ -233,17 +233,22 @@ func (r *EvmRegistry) checkUpkeeps(ctx context.Context, payloads []ocr2keepers.U indices[len(checkReqs)] = i results[i] = encoding.GetIneligibleCheckResultWithoutPerformData(p, encoding.UpkeepFailureReasonNone, encoding.NoPipelineError, false) + args := []interface{}{ + map[string]interface{}{ + "from": zeroAddress, + "to": r.addr.Hex(), + "data": hexutil.Bytes(payload), + }, + } + + if opts.BlockNumber != nil { + args = append(args, hexutil.EncodeBig(opts.BlockNumber)) + } + var result string checkReqs = append(checkReqs, rpc.BatchElem{ Method: "eth_call", - Args: []interface{}{ - map[string]interface{}{ - "from": zeroAddress, - "to": r.addr.Hex(), - "data": hexutil.Bytes(payload), - }, - hexutil.EncodeBig(opts.BlockNumber), - }, + Args: args, Result: &result, }) @@ -334,17 +339,23 @@ func (r *EvmRegistry) simulatePerformUpkeeps(ctx context.Context, checkResults [ } opts := r.buildCallOpts(ctx, block) + + args := []interface{}{ + map[string]interface{}{ + "from": zeroAddress, + "to": r.addr.Hex(), + "data": hexutil.Bytes(payload), + }, + } + + if opts.BlockNumber != nil { + args = append(args, hexutil.EncodeBig(opts.BlockNumber)) + } + var result string performReqs = append(performReqs, rpc.BatchElem{ Method: "eth_call", - Args: []interface{}{ - map[string]interface{}{ - "from": zeroAddress, - "to": r.addr.Hex(), - "data": hexutil.Bytes(payload), - }, - hexutil.EncodeBig(opts.BlockNumber), - }, + Args: args, Result: &result, })