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: golangci-lint cleanup #11583

Merged
merged 1 commit into from
Dec 15, 2023
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
13 changes: 5 additions & 8 deletions core/scripts/chaincli/command/keeper/upkeep.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,11 @@ var ocr2UpkeepReportHistoryCmd = &cobra.Command{
hdlr := handler.NewBaseHandler(cfg)

var hashes []string
var err error
var path string

path, err = cmd.Flags().GetString("csv")
path, err := cmd.Flags().GetString("csv")
if err == nil && len(path) != 0 {
rec, err := readCsvFile(path)
if err != nil {
log.Fatal(err)
rec, err2 := readCsvFile(path)
if err2 != nil {
log.Fatal(err2)
}

if len(rec) < 1 {
Expand All @@ -107,7 +104,7 @@ var ocr2UpkeepReportHistoryCmd = &cobra.Command{
}
}

if err := handler.OCR2AutomationReports(hdlr, hashes); err != nil {
if err = handler.OCR2AutomationReports(hdlr, hashes); err != nil {
log.Fatalf("failed to collect transaction data: %s", err)
}
},
Expand Down
32 changes: 16 additions & 16 deletions core/scripts/chaincli/handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,44 +411,44 @@ func (h *baseHandler) launchChainlinkNode(ctx context.Context, port int, contain

if writeLogs {
var rdr io.ReadCloser
rdr, err := dockerClient.ContainerLogs(ctx, nodeContainerResp.ID, types.ContainerLogsOptions{
rdr, err2 := dockerClient.ContainerLogs(ctx, nodeContainerResp.ID, types.ContainerLogsOptions{
ShowStderr: true,
Timestamps: true,
})
if err != nil {
if err2 != nil {
rdr.Close()
log.Fatal("Failed to collect logs from container: ", err)
log.Fatal("Failed to collect logs from container: ", err2)
}

stdErr, err := os.OpenFile(fmt.Sprintf("./%s-stderr.log", nodeContainerResp.ID), os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0755)
if err != nil {
stdErr, err2 := os.OpenFile(fmt.Sprintf("./%s-stderr.log", nodeContainerResp.ID), os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0755)
if err2 != nil {
rdr.Close()
stdErr.Close()
log.Fatal("Failed to open file: ", err)
log.Fatal("Failed to open file: ", err2)
}

if _, err := stdcopy.StdCopy(io.Discard, stdErr, rdr); err != nil {
if _, err2 := stdcopy.StdCopy(io.Discard, stdErr, rdr); err2 != nil {
rdr.Close()
stdErr.Close()
log.Fatal("Failed to write logs to file: ", err)
log.Fatal("Failed to write logs to file: ", err2)
}

rdr.Close()
stdErr.Close()
}

if err = dockerClient.ContainerStop(ctx, nodeContainerResp.ID, container.StopOptions{}); err != nil {
log.Fatal("Failed to stop node container: ", err)
if err2 := dockerClient.ContainerStop(ctx, nodeContainerResp.ID, container.StopOptions{}); err2 != nil {
log.Fatal("Failed to stop node container: ", err2)
}
if err = dockerClient.ContainerRemove(ctx, nodeContainerResp.ID, types.ContainerRemoveOptions{}); err != nil {
log.Fatal("Failed to remove node container: ", err)
if err2 := dockerClient.ContainerRemove(ctx, nodeContainerResp.ID, types.ContainerRemoveOptions{}); err2 != nil {
log.Fatal("Failed to remove node container: ", err2)
}

if err = dockerClient.ContainerStop(ctx, dbContainerResp.ID, container.StopOptions{}); err != nil {
log.Fatal("Failed to stop DB container: ", err)
if err2 := dockerClient.ContainerStop(ctx, dbContainerResp.ID, container.StopOptions{}); err2 != nil {
log.Fatal("Failed to stop DB container: ", err2)
}
if err = dockerClient.ContainerRemove(ctx, dbContainerResp.ID, types.ContainerRemoveOptions{}); err != nil {
log.Fatal("Failed to remove DB container: ", err)
if err2 := dockerClient.ContainerRemove(ctx, dbContainerResp.ID, types.ContainerRemoveOptions{}); err2 != nil {
log.Fatal("Failed to remove DB container: ", err2)
}
}, nil
}
Expand Down
109 changes: 46 additions & 63 deletions core/scripts/chaincli/handler/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -528,13 +528,11 @@ func (k *Keeper) deployUpkeeps(ctx context.Context, registryAddr common.Address,
var registerUpkeepTx *types.Transaction
var logUpkeepCounter *log_upkeep_counter_wrapper.LogUpkeepCounter
var checkData []byte
var err error

switch k.cfg.UpkeepType {
case config.Conditional:
checkData = []byte(k.cfg.UpkeepCheckData)
if err != nil {
log.Fatal(err)
}
var err error
if k.cfg.UpkeepAverageEligibilityCadence > 0 {
upkeepAddr, deployUpkeepTx, _, err = upkeep.DeployUpkeepPerformCounterRestrictive(
k.buildTxOpts(ctx),
Expand Down Expand Up @@ -570,9 +568,7 @@ func (k *Keeper) deployUpkeeps(ctx context.Context, registryAddr common.Address,
}
case config.Mercury:
checkData = []byte(k.cfg.UpkeepCheckData)
if err != nil {
log.Fatal(err)
}
var err error
if k.cfg.VerifiableLoadTest {
upkeepAddr, deployUpkeepTx, _, err = verifiable_load_streams_lookup_upkeep_wrapper.DeployVerifiableLoadStreamsLookupUpkeep(
k.buildTxOpts(ctx),
Expand Down Expand Up @@ -603,6 +599,7 @@ func (k *Keeper) deployUpkeeps(ctx context.Context, registryAddr common.Address,
log.Fatal(i, upkeepAddr.Hex(), ": RegisterUpkeep failed - ", err)
}
case config.LogTrigger:
var err error
upkeepAddr, deployUpkeepTx, logUpkeepCounter, err = log_upkeep_counter_wrapper.DeployLogUpkeepCounter(
k.buildTxOpts(ctx),
k.client,
Expand Down Expand Up @@ -637,7 +634,7 @@ func (k *Keeper) deployUpkeeps(ctx context.Context, registryAddr common.Address,
if err != nil {
log.Fatal("failed to start log upkeep counter", err)
}
if err := k.waitTx(ctx, logUpkeepStartTx); err != nil {
if err = k.waitTx(ctx, logUpkeepStartTx); err != nil {
log.Fatalf("Log upkeep Start() failed for upkeepId: %s, error is %s", upkeepAddr.Hex(), err.Error())
}
log.Println(i, upkeepAddr.Hex(), ": Log upkeep successfully started - ", helpers.ExplorerLink(k.cfg.ChainID, logUpkeepStartTx.Hash()))
Expand All @@ -653,32 +650,34 @@ func (k *Keeper) deployUpkeeps(ctx context.Context, registryAddr common.Address,
upkeepAddrs = append(upkeepAddrs, upkeepAddr)
}

var err error
var upkeepGetter activeUpkeepGetter
upkeepCount := big.NewInt(k.cfg.UpkeepCount) // second arg in GetActiveUpkeepIds (on registry)
switch k.cfg.RegistryVersion {
case keeper.RegistryVersion_1_1:
panic("not supported 1.1 registry")
case keeper.RegistryVersion_1_2:
upkeepGetter, err = registry12.NewKeeperRegistry(
registryAddr,
k.client,
)
case keeper.RegistryVersion_2_0:
upkeepGetter, err = registry20.NewKeeperRegistry(
registryAddr,
k.client,
)
case keeper.RegistryVersion_2_1:
upkeepGetter, err = iregistry21.NewIKeeperRegistryMaster(
registryAddr,
k.client,
)
default:
panic("unexpected registry address")
}
if err != nil {
log.Fatal("Registry failed: ", err)
{
var err error
switch k.cfg.RegistryVersion {
case keeper.RegistryVersion_1_1:
panic("not supported 1.1 registry")
case keeper.RegistryVersion_1_2:
upkeepGetter, err = registry12.NewKeeperRegistry(
registryAddr,
k.client,
)
case keeper.RegistryVersion_2_0:
upkeepGetter, err = registry20.NewKeeperRegistry(
registryAddr,
k.client,
)
case keeper.RegistryVersion_2_1:
upkeepGetter, err = iregistry21.NewIKeeperRegistryMaster(
registryAddr,
k.client,
)
default:
panic("unexpected registry address")
}
if err != nil {
log.Fatal("Registry failed: ", err)
}
}

activeUpkeepIds := k.getActiveUpkeepIds(ctx, upkeepGetter, big.NewInt(existingCount), upkeepCount)
Expand Down Expand Up @@ -724,22 +723,24 @@ func (k *Keeper) deployUpkeeps(ctx context.Context, registryAddr common.Address,
}

for _, id := range activeUpkeepIds {
tx, err := reg21.SetUpkeepPrivilegeConfig(k.buildTxOpts(ctx), id, adminBytes)
if err != nil {
log.Fatalf("failed to upkeep privilege config: %v", err)
tx, err2 := reg21.SetUpkeepPrivilegeConfig(k.buildTxOpts(ctx), id, adminBytes)
if err2 != nil {
log.Fatalf("failed to upkeep privilege config: %v", err2)
}
err = k.waitTx(ctx, tx)
if err != nil {
log.Fatalf("failed to wait for tx: %v", err)
} else {
log.Printf("upkeep privilege config is set for %s", id.String())
err2 = k.waitTx(ctx, tx)
if err2 != nil {
log.Fatalf("failed to wait for tx: %v", err2)
}
log.Printf("upkeep privilege config is set for %s", id.String())

info, err := reg21.GetUpkeep(nil, id)
if err != nil {
log.Fatalf("failed to fetch upkeep id %s from registry 2.1: %v", id, err)
info, err2 := reg21.GetUpkeep(nil, id)
if err2 != nil {
log.Fatalf("failed to fetch upkeep id %s from registry 2.1: %v", id, err2)
}
min, err2 := reg21.GetMinBalanceForUpkeep(nil, id)
if err2 != nil {
log.Fatalf("failed to fetch upkeep id %s from registry 2.1: %v", id, err2)
}
min, err := reg21.GetMinBalanceForUpkeep(nil, id)
log.Printf(" Balance: %s", info.Balance)
log.Printf("Min Balance: %s", min.String())
}
Expand All @@ -757,7 +758,7 @@ func (k *Keeper) setKeepers(ctx context.Context, cls []cmd.HTTPClient, deployer
log.Fatal("SetKeepers failed: ", err)
}

if err := k.waitTx(ctx, setKeepersTx); err != nil {
if err = k.waitTx(ctx, setKeepersTx); err != nil {
log.Fatalf("SetKeepers failed, error is: %s", err.Error())
}

Expand All @@ -777,24 +778,6 @@ func (k *Keeper) keepers() ([]common.Address, []common.Address) {
return addrs, fromAddrs
}

// createKeeperJobOnExistingNode connect to existing node to create keeper job
func (k *Keeper) createKeeperJobOnExistingNode(urlStr, email, password, registryAddr, nodeAddr string) error {
lggr, closeLggr := logger.NewLogger()
logger.Sugared(lggr).ErrorIfFn(closeLggr, "Failed to close logger")

cl, err := authenticate(urlStr, email, password, lggr)
if err != nil {
return err
}

if err = k.createKeeperJob(cl, registryAddr, nodeAddr); err != nil {
log.Println("Failed to create keeper job: ", err)
return err
}

return nil
}

type activeUpkeepGetter interface {
Address() common.Address
GetActiveUpkeepIDs(opts *bind.CallOpts, startIndex *big.Int, maxCount *big.Int) ([]*big.Int, error)
Expand Down
26 changes: 12 additions & 14 deletions core/scripts/chaincli/handler/keeper_launch.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,12 @@ func (k *Keeper) LaunchAndTest(ctx context.Context, withdraw, printLogs, force,

if len(k.cfg.KeeperKeys) > 0 {
// import key if exists
var err error
nodeAddrHex, err = k.addKeyToKeeper(cl, k.cfg.KeeperKeys[i])
if err != nil {
log.Fatal("could not add key to keeper", err)
}
} else {
// get node's default wallet address
var err error
nodeAddrHex, err = getNodeAddress(cl)
if err != nil {
log.Println("Failed to get node addr: ", err)
Expand Down Expand Up @@ -220,35 +218,35 @@ func (k *Keeper) LaunchAndTest(ctx context.Context, withdraw, printLogs, force,

// cancelAndWithdrawActiveUpkeeps cancels all active upkeeps and withdraws funds for registry 1.2
func (k *Keeper) cancelAndWithdrawActiveUpkeeps(ctx context.Context, activeUpkeepIds []*big.Int, canceller canceller) error {
var err error
for i := 0; i < len(activeUpkeepIds); i++ {
var tx *ethtypes.Transaction
upkeepId := activeUpkeepIds[i]
if tx, err = canceller.CancelUpkeep(k.buildTxOpts(ctx), upkeepId); err != nil {
tx, err := canceller.CancelUpkeep(k.buildTxOpts(ctx), upkeepId)
if err != nil {
return fmt.Errorf("failed to cancel upkeep %s: %s", upkeepId.String(), err)
}

if err := k.waitTx(ctx, tx); err != nil {
if err = k.waitTx(ctx, tx); err != nil {
log.Fatalf("failed to cancel upkeep for upkeepId: %s, error is: %s", upkeepId.String(), err.Error())
}

if tx, err = canceller.WithdrawFunds(k.buildTxOpts(ctx), upkeepId, k.fromAddr); err != nil {
tx, err = canceller.WithdrawFunds(k.buildTxOpts(ctx), upkeepId, k.fromAddr)
if err != nil {
return fmt.Errorf("failed to withdraw upkeep %s: %s", upkeepId.String(), err)
}

if err := k.waitTx(ctx, tx); err != nil {
if err = k.waitTx(ctx, tx); err != nil {
log.Fatalf("failed to withdraw upkeep for upkeepId: %s, error is: %s", upkeepId.String(), err.Error())
}

log.Printf("Upkeep %s successfully canceled and refunded: ", upkeepId.String())
}

var tx *ethtypes.Transaction
if tx, err = canceller.RecoverFunds(k.buildTxOpts(ctx)); err != nil {
tx, err := canceller.RecoverFunds(k.buildTxOpts(ctx))
if err != nil {
return fmt.Errorf("failed to recover funds: %s", err)
}

if err := k.waitTx(ctx, tx); err != nil {
if err = k.waitTx(ctx, tx); err != nil {
log.Fatalf("failed to recover funds, error is: %s", err.Error())
}

Expand All @@ -264,15 +262,15 @@ func (k *Keeper) cancelAndWithdrawUpkeeps(ctx context.Context, upkeepCount *big.
return fmt.Errorf("failed to cancel upkeep %d: %s", i, err)
}

if err := k.waitTx(ctx, tx); err != nil {
if err = k.waitTx(ctx, tx); err != nil {
log.Fatalf("failed to cancel upkeep, error is: %s", err.Error())
}

if tx, err = canceller.WithdrawFunds(k.buildTxOpts(ctx), big.NewInt(i), k.fromAddr); err != nil {
return fmt.Errorf("failed to withdraw upkeep %d: %s", i, err)
}

if err := k.waitTx(ctx, tx); err != nil {
if err = k.waitTx(ctx, tx); err != nil {
log.Fatalf("failed to withdraw upkeep, error is: %s", err.Error())
}

Expand All @@ -284,7 +282,7 @@ func (k *Keeper) cancelAndWithdrawUpkeeps(ctx context.Context, upkeepCount *big.
return fmt.Errorf("failed to recover funds: %s", err)
}

if err := k.waitTx(ctx, tx); err != nil {
if err = k.waitTx(ctx, tx); err != nil {
log.Fatalf("failed to recover funds, error is: %s", err.Error())
}

Expand Down
2 changes: 1 addition & 1 deletion core/scripts/chaincli/handler/ocr2_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func OCR2GetConfig(hdlr *baseHandler, registry_addr string) error {

func configFromBlock(bl *types.Block, addr common.Address, detail keeper_registry_wrapper2_0.LatestConfigDetails) (*confighelper.PublicConfig, error) {
for _, tx := range bl.Transactions() {
if tx.To() != nil && bytes.Compare(tx.To()[:], addr[:]) == 0 {
if tx.To() != nil && bytes.Equal(tx.To()[:], addr[:]) {
// this is our transaction
// txRes, txErr, err := getTransactionDetailForHashes(hdlr, []string{tx})
ocr2Tx, err := NewBaseOCR2Tx(tx)
Expand Down
14 changes: 8 additions & 6 deletions core/scripts/chaincli/handler/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,24 +85,26 @@ func OCR2AutomationReports(hdlr *baseHandler, txs []string) error {
}

txRes, txErr, err = getSimulationsForTxs(hdlr, simBatch)
if err != nil {
return err
}
for i := range txRes {
if txErr[i] == nil {
continue
}

err, ok := txErr[i].(JsonError)
err2, ok := txErr[i].(JsonError) //nolint:errorlint
if ok {
decoded, err := hexutil.Decode(err.ErrorData().(string))
decoded, err := hexutil.Decode(err2.ErrorData().(string))
if err != nil {
elements[i].Err = err.Error()
continue
}

elements[i].Err = ocr2Txs[i].DecodeError(decoded)
} else if err != nil {
elements[i].Err = err.Error()
} else if err2 != nil {
elements[i].Err = err2.Error()
}

}

data := make([][]string, len(elements))
Expand Down Expand Up @@ -275,7 +277,7 @@ func (t *OCR2Transaction) DecodeError(b []byte) string {
}
}

return fmt.Sprintf("%s", j)
return j
}

func NewOCR2TransmitTx(raw map[string]interface{}) (*OCR2TransmitTx, error) {
Expand Down
Loading
Loading