Skip to content

Commit

Permalink
Only encode non nil block numbers (#13726)
Browse files Browse the repository at this point in the history
* WIP specify block 0

* Remove 0 block check

* Add changeset

* Tweak changeset

* Only set non nil block numbers

* Lint
  • Loading branch information
ferglor authored Jul 2, 2024
1 parent fea276c commit 2ecf45d
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 37 deletions.
5 changes: 5 additions & 0 deletions .changeset/curvy-months-change.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"chainlink": patch
---

Only encode non nil block numbers for eth_call #changed
57 changes: 36 additions & 21 deletions core/services/ocr2/plugins/ocr2keeper/evmregistry/v20/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -594,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 @@ -660,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 @@ -726,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 2ecf45d

Please sign in to comment.