Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core/scripts/ccip/manual-execution: fix linter issues #16716

Merged
merged 1 commit into from
Mar 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions core/scripts/ccip/manual-execution/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ require (
github.com/ethereum/go-ethereum v1.11.3
github.com/pkg/errors v0.9.1
github.com/smartcontractkit/chain-selectors v1.0.40
go.uber.org/multierr v1.1.0
golang.org/x/crypto v0.1.0
)

Expand All @@ -24,7 +23,6 @@ require (
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible // indirect
github.com/tklauser/go-sysconf v0.3.5 // indirect
github.com/tklauser/numcpus v0.2.2 // indirect
go.uber.org/atomic v1.3.2 // indirect
golang.org/x/sys v0.5.0 // indirect
gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
4 changes: 0 additions & 4 deletions core/scripts/ccip/manual-execution/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,6 @@ github.com/tklauser/numcpus v0.2.2/go.mod h1:x3qojaO3uyYt0i56EW/VUYs7uBvdl2fkfZF
github.com/tyler-smith/go-bip39 v1.1.0 h1:5eUemwrMargf3BSLRRCalXT93Ns6pQJIjYQN2nyfOP8=
github.com/urfave/cli/v2 v2.17.2-0.20221006022127-8f469abc00aa h1:5SqCsI/2Qya2bCzK15ozrqo2sZxkh0FHynJZOTVoV6Q=
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU=
go.uber.org/atomic v1.3.2 h1:2Oa65PReHzfn29GpvgsYwloV9AVFHPDk8tYxt2c2tr4=
go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
go.uber.org/multierr v1.1.0 h1:HoEmRHQPVSqub6w2z2d2EOVs2fjyFRGyofhKuyDq0QI=
go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=
golang.org/x/crypto v0.1.0 h1:MDRAIl0xIo9Io2xV565hzXHw3zVseKrJKodhohM5CjU=
golang.org/x/crypto v0.1.0/go.mod h1:RecgLatLF4+eUMCP1PoPZQb+cVrJcOPbHkTkbkB9sbw=
golang.org/x/exp v0.0.0-20230206171751-46f607a40771 h1:xP7rWLUr1e1n2xkK5YB4LI0hPEy3LJC6Wk+D4pGlOJg=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ type InternalExecutionReport struct {

type EVM2EVMOffRampExecutionStateChanged struct {
SequenceNumber uint64
MessageId [32]byte
MessageID [32]byte
State uint8
ReturnData []byte
Raw types.Log
Expand Down
12 changes: 6 additions & 6 deletions core/scripts/ccip/manual-execution/helpers/execReport.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,11 @@ func (t *LeafHasher) ParseEVM2EVMLog(log types.Log) (*SendRequestedEvent, error)
return event, err
}

func NewLeafHasher(sourceChainID uint64, destChainId uint64, onRampId common.Address, ctx Ctx[[32]byte]) *LeafHasher {
func NewLeafHasher(sourceChainID uint64, destChainID uint64, onRampID common.Address, ctx Ctx[[32]byte]) *LeafHasher {
geABI, _ := abi.JSON(strings.NewReader(OnRampABI))
return &LeafHasher{
geABI: geABI,
metaDataHash: getMetaDataHash(ctx, ctx.Hash([]byte("EVM2EVMMessageHashV2")), sourceChainID, onRampId, destChainId),
metaDataHash: getMetaDataHash(ctx, ctx.Hash([]byte("EVM2EVMMessageHashV2")), sourceChainID, onRampID, destChainID),
ctx: ctx,
}
}
Expand All @@ -166,11 +166,11 @@ func Keccak256Fixed(in []byte) [32]byte {
return h
}

func getMetaDataHash[H Hash](ctx Ctx[H], prefix [32]byte, sourceChainId uint64, onRampId common.Address, destChainId uint64) H {
paddedOnRamp := onRampId.Hash()
func getMetaDataHash[H Hash](ctx Ctx[H], prefix [32]byte, sourceChainID uint64, onRampID common.Address, destChainID uint64) H {
paddedOnRamp := onRampID.Hash()
return ctx.Hash(ConcatBytes(prefix[:],
math.U256Bytes(big.NewInt(0).SetUint64(sourceChainId)),
math.U256Bytes(big.NewInt(0).SetUint64(destChainId)), paddedOnRamp[:]))
math.U256Bytes(big.NewInt(0).SetUint64(sourceChainID)),
math.U256Bytes(big.NewInt(0).SetUint64(destChainID)), paddedOnRamp[:]))
}

// ConcatBytes appends a bunch of byte arrays into a single byte array
Expand Down
5 changes: 3 additions & 2 deletions core/scripts/ccip/manual-execution/helpers/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package helpers

import (
"context"
"errors"
"fmt"
"log"
"time"
Expand All @@ -13,7 +14,7 @@ import (

func VerifyAddress(addr string) error {
if addr == "" {
return fmt.Errorf("address is blank")
return errors.New("address is blank")
}
if !common.IsHexAddress(addr) {
return fmt.Errorf("address %s is invalid", addr)
Expand Down Expand Up @@ -41,7 +42,7 @@ func WaitForSuccessfulTxReceipt(client ethereum.TransactionReader, hash common.H
}
}
case <-ctx.Done():
return fmt.Errorf("tx not confirmed within time")
return errors.New("tx not confirmed within time")
}
}
}
66 changes: 33 additions & 33 deletions core/scripts/ccip/manual-execution/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethclient"
"go.uber.org/multierr"

chainselectors "github.com/smartcontractkit/chain-selectors"

Expand Down Expand Up @@ -47,10 +46,10 @@ type execArgs struct {
seqNum uint64
msgID [32]byte
sourceChain *ethclient.Client
sourceChainId *big.Int
sourceChainID *big.Int
destChain *ethclient.Client
destUser *bind.TransactOpts
destChainId *big.Int
destChainID *big.Int
srcStartBlock *big.Int
destStartBlock uint64
destLatestBlock uint64
Expand Down Expand Up @@ -93,7 +92,8 @@ func main() {
// mandatory fields check
err = cfg.verifyConfig()
if err != nil {
log.Println("config validation failed: \n", err)
log.Println("config validation failed:")

os.Exit(1)
}
args := &execArgs{cfg: cfg}
Expand All @@ -109,40 +109,38 @@ func main() {
}
}

func (cfg Config) verifyConfig() error {
var allErr error
func (cfg Config) verifyConfig() (errs error) {
if cfg.SrcNodeURL == "" {
allErr = multierr.Append(allErr, fmt.Errorf("must set src_rpc - source chain rpc\n"))
errs = errors.Join(errs, errors.New("must set src_rpc - source chain rpc"))
}
if cfg.DestNodeURL == "" {
allErr = multierr.Append(allErr, fmt.Errorf("must set dest_rpc - destination chain rpc\n"))
errs = errors.Join(errs, errors.New("must set dest_rpc - destination chain rpc"))
}
if cfg.DestOwner == "" {
allErr = multierr.Append(allErr, fmt.Errorf("must set dest_owner_key - destination user private key\n"))
errs = errors.Join(errs, errors.New("must set dest_owner_key - destination user private key"))
}
if cfg.SourceChainTx == "" {
allErr = multierr.Append(allErr, fmt.Errorf("must set source_chain_tx - txHash of ccip-send request\n"))
errs = errors.Join(errs, errors.New("must set source_chain_tx - txHash of ccip-send request"))
}

if cfg.DestStartBlock == 0 && cfg.DestDeployedAt == 0 {
allErr = multierr.Append(allErr, fmt.Errorf(`must set either of -
errs = errors.Join(errs, errors.New(`must set either of -
dest_deployed_at - the block number before destination contracts were deployed;
dest_start_block - the block number from which events will be filtered at destination chain.
`))
dest_start_block - the block number from which events will be filtered at destination chain`))
}
if cfg.GasLimitOverride == 0 {
allErr = multierr.Append(allErr, fmt.Errorf("must set gas_limit_override - new value of gas limit for ccip-send request\n"))
errs = errors.Join(errs, errors.New("must set gas_limit_override - new value of gas limit for ccip-send request"))
}
err := helpers.VerifyAddress(cfg.CommitStore)
if err != nil {
allErr = multierr.Append(allErr, fmt.Errorf("check the commit_store address - %v\n", err))
errs = errors.Join(errs, fmt.Errorf("check the commit_store address - %w", err))
}
err = helpers.VerifyAddress(cfg.OffRamp)
if err != nil {
allErr = multierr.Append(allErr, fmt.Errorf("check the off_ramp address - %v\n", err))
errs = errors.Join(errs, fmt.Errorf("check the off_ramp address - %w", err))
}

return allErr
return
}

func (args *execArgs) populateValues() error {
Expand All @@ -152,7 +150,7 @@ func (args *execArgs) populateValues() error {
if err != nil {
return err
}
args.sourceChainId, err = args.sourceChain.ChainID(context.Background())
args.sourceChainID, err = args.sourceChain.ChainID(context.Background())
if err != nil {
return err
}
Expand All @@ -161,7 +159,7 @@ func (args *execArgs) populateValues() error {
if err != nil {
return err
}
args.destChainId, err = args.destChain.ChainID(context.Background())
args.destChainID, err = args.destChain.ChainID(context.Background())
if err != nil {
return err
}
Expand All @@ -170,7 +168,7 @@ func (args *execArgs) populateValues() error {
return err
}

args.destUser, err = bind.NewKeyedTransactorWithChainID(ownerKey, args.destChainId)
args.destUser, err = bind.NewKeyedTransactorWithChainID(ownerKey, args.destChainID)
if err != nil {
return err
}
Expand Down Expand Up @@ -210,7 +208,8 @@ func (args *execArgs) execute() error {

var commitReport *helpers.ICommitStoreCommitReport
for iterator.Next() {
eventReport, err := iterator.CommitStoreReportAcceptedFromLog()
var eventReport *helpers.CommitStoreReportAccepted
eventReport, err = iterator.CommitStoreReportAcceptedFromLog()
if err != nil {
return err
}
Expand All @@ -229,8 +228,8 @@ func (args *execArgs) execute() error {
// Build a merkle tree for the report
mctx := helpers.NewKeccakCtx()
leafHasher := helpers.NewLeafHasher(
GetCCIPChainSelector(args.sourceChainId.Uint64()),
GetCCIPChainSelector(args.destChainId.Uint64()),
GetCCIPChainSelector(args.sourceChainID.Uint64()),
GetCCIPChainSelector(args.destChainID.Uint64()),
args.OnRamp,
mctx,
)
Expand All @@ -248,7 +247,8 @@ func (args *execArgs) execute() error {
}

for sendRequestedIterator.Next() {
event, err := sendRequestedIterator.SendRequestedEventFromLog()
var event *helpers.SendRequestedEvent
event, err = sendRequestedIterator.SendRequestedEventFromLog()
if err != nil {
return err
}
Expand Down Expand Up @@ -281,8 +281,8 @@ func (args *execArgs) execute() error {
return fmt.Errorf("unable to find msg with seqNr %d", seqNr)
}

expectedNumberOfLeaves := int(commitReport.Interval.Max - commitReport.Interval.Min + 1)
if len(leaves) != expectedNumberOfLeaves {
expectedNumberOfLeaves := commitReport.Interval.Max - commitReport.Interval.Min + 1
if uint64(len(leaves)) != expectedNumberOfLeaves {
return fmt.Errorf("not enough leaves gather to build a commit root - want %d got %d. Please set NumberOfBlocks const to a higher value", expectedNumberOfLeaves, len(leaves))
}

Expand All @@ -306,7 +306,7 @@ func (args *execArgs) execute() error {

for range offRampProof.Messages {
evm2evmOffRampGasLimitOverride := &helpers.EVM2EVMOffRampGasLimitOverride{
ReceiverExecutionGasLimit: big.NewInt(int64(args.cfg.GasLimitOverride)),
ReceiverExecutionGasLimit: new(big.Int).SetUint64(args.cfg.GasLimitOverride),
TokenGasOverrides: args.tokenGasOverrides,
}
gasLimitOverrides = append(gasLimitOverrides, evm2evmOffRampGasLimitOverride)
Expand Down Expand Up @@ -398,7 +398,7 @@ func (args *execArgs) approxDestStartBlock() error {
minBlockNum := args.cfg.DestDeployedAt
closestBlockNum := uint64(math.Floor((float64(maxBlockNum) + float64(minBlockNum)) / 2))
var closestBlockHdr *types.Header
closestBlockHdr, err = args.destChain.HeaderByNumber(context.Background(), big.NewInt(int64(closestBlockNum)))
closestBlockHdr, err = args.destChain.HeaderByNumber(context.Background(), new(big.Int).SetUint64(closestBlockNum))
if err != nil {
return err
}
Expand All @@ -420,7 +420,7 @@ func (args *execArgs) approxDestStartBlock() error {
minBlockNum = blockNum + 1
}
closestBlockNum = uint64(math.Floor((float64(maxBlockNum) + float64(minBlockNum)) / 2))
closestBlockHdr, err = args.destChain.HeaderByNumber(context.Background(), big.NewInt(int64(closestBlockNum)))
closestBlockHdr, err = args.destChain.HeaderByNumber(context.Background(), new(big.Int).SetUint64(closestBlockNum))
if err != nil {
return err
}
Expand All @@ -434,7 +434,7 @@ func (args *execArgs) approxDestStartBlock() error {
if closestBlockNum <= 0 {
return errors.New("approx destination blocknumber not found")
}
closestBlockHdr, err = args.destChain.HeaderByNumber(context.Background(), big.NewInt(int64(closestBlockNum)))
closestBlockHdr, err = args.destChain.HeaderByNumber(context.Background(), new(big.Int).SetUint64(closestBlockNum))
if err != nil {
return err
}
Expand All @@ -444,10 +444,10 @@ func (args *execArgs) approxDestStartBlock() error {
return nil
}

func GetCCIPChainSelector(chainId uint64) uint64 {
selector, err := chainselectors.SelectorFromChainId(chainId)
func GetCCIPChainSelector(chainID uint64) uint64 {
selector, err := chainselectors.SelectorFromChainId(chainID)
if err != nil {
panic(fmt.Sprintf("no chain selector for %d", chainId))
panic(fmt.Sprintf("no chain selector for %d", chainID))
}
return selector
}
Loading