Skip to content

Commit

Permalink
Only set non nil block numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
ferglor committed Jul 2, 2024
1 parent 0463408 commit 6ffc8c4
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 39 deletions.
2 changes: 1 addition & 1 deletion .changeset/curvy-months-change.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
61 changes: 39 additions & 22 deletions core/services/ocr2/plugins/ocr2keeper/evmregistry/v20/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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,
}

Expand Down Expand Up @@ -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,
})

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})

Expand Down Expand Up @@ -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,
})

Expand Down

0 comments on commit 6ffc8c4

Please sign in to comment.