Skip to content

Commit

Permalink
core/scripts/common: rm ava-labs/coreth; lint (#11451)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmank88 authored Dec 8, 2023
1 parent f99fd8e commit 06656fa
Show file tree
Hide file tree
Showing 13 changed files with 292 additions and 84 deletions.
4 changes: 0 additions & 4 deletions .github/workflows/ci-chaincli.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@ name: chaincli CI

on:
push:
paths:
- "core/scripts/chaincli/**"
pull_request:
paths:
- "core/scripts/chaincli/**"

jobs:
golangci:
Expand Down
2 changes: 1 addition & 1 deletion core/scripts/chaincli/command/keeper/verifiable_load.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var verifiableLoad = &cobra.Command{
if err != nil {
log.Fatal("failed to get verify flag: ", err)
}
hdlr.GetVerifiableLoadStats(cmd.Context(), csv)
hdlr.PrintVerifiableLoadStats(cmd.Context(), csv)
},
}

Expand Down
17 changes: 0 additions & 17 deletions core/scripts/chaincli/handler/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
gethcommon "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/ethclient"

ocr2keepers "github.com/smartcontractkit/chainlink-automation/pkg/v3/types"

Expand Down Expand Up @@ -317,22 +316,6 @@ func (k *Keeper) Debug(ctx context.Context, args []string) {
}
}

type blockSubscriber struct {
ethClient *ethclient.Client
}

func (bs *blockSubscriber) LatestBlock() *ocr2keepers.BlockKey {
header, err := bs.ethClient.HeaderByNumber(context.Background(), nil)
if err != nil {
return nil
}

return &ocr2keepers.BlockKey{
Number: ocr2keepers.BlockNumber(header.Number.Uint64()),
Hash: header.Hash(),
}
}

func logMatchesTriggerConfig(log *types.Log, config automation_utils_2_1.LogTriggerConfig) bool {
if log.Topics[0] != config.Topic0 {
return false
Expand Down
12 changes: 4 additions & 8 deletions core/scripts/chaincli/handler/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -435,9 +435,8 @@ func (k *Keeper) getRegistry20(ctx context.Context) (common.Address, *registry20
}
if k.cfg.RegistryConfigUpdate {
panic("KeeperRegistry2.0 could not be updated")
} else {
log.Println("KeeperRegistry2.0 config not updated: KEEPER_CONFIG_UPDATE=false")
}
log.Println("KeeperRegistry2.0 config not updated: KEEPER_CONFIG_UPDATE=false")
return registryAddr, keeperRegistry20
}

Expand All @@ -453,9 +452,8 @@ func (k *Keeper) getRegistry21(ctx context.Context) (common.Address, *iregistry2
}
if k.cfg.RegistryConfigUpdate {
panic("KeeperRegistry2.1 could not be updated")
} else {
log.Println("KeeperRegistry2.1 config not updated: KEEPER_CONFIG_UPDATE=false")
}
log.Println("KeeperRegistry2.1 config not updated: KEEPER_CONFIG_UPDATE=false")
return registryAddr, keeperRegistry21
}

Expand All @@ -479,9 +477,8 @@ func (k *Keeper) getRegistry12(ctx context.Context) (common.Address, *registry12
log.Fatalf("KeeperRegistry config update failed on registry address: %s, error is: %s", k.cfg.RegistryAddress, err.Error())
}
log.Println("KeeperRegistry config update:", k.cfg.RegistryAddress, "-", helpers.ExplorerLink(k.cfg.ChainID, transaction.Hash()))
} else {
log.Println("KeeperRegistry config not updated: KEEPER_CONFIG_UPDATE=false")
}
log.Println("KeeperRegistry config not updated: KEEPER_CONFIG_UPDATE=false")
return registryAddr, keeperRegistry12
}

Expand Down Expand Up @@ -513,9 +510,8 @@ func (k *Keeper) getRegistry11(ctx context.Context) (common.Address, *registry11
log.Fatalf("KeeperRegistry config update failed on registry address: %s, error is %s", k.cfg.RegistryAddress, err.Error())
}
log.Println("KeeperRegistry config update:", k.cfg.RegistryAddress, "-", helpers.ExplorerLink(k.cfg.ChainID, transaction.Hash()))
} else {
log.Println("KeeperRegistry config not updated: KEEPER_CONFIG_UPDATE=false")
}
log.Println("KeeperRegistry config not updated: KEEPER_CONFIG_UPDATE=false")
return registryAddr, keeperRegistry11
}

Expand Down
2 changes: 1 addition & 1 deletion core/scripts/chaincli/handler/keeper_launch.go
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ func (k *Keeper) createOCR2KeeperJob(client cmd.HTTPClient, contractAddr, nodeAd
}

// Correctly assign contract version in OCR job spec.
var contractVersion string = "v2.0"
contractVersion := "v2.0"
if k.cfg.RegistryVersion == keeper.RegistryVersion_2_1 {
contractVersion = "v2.1"
}
Expand Down
10 changes: 5 additions & 5 deletions core/scripts/chaincli/handler/keeper_verifiable_load.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ type upkeepStats struct {
SortedAllDelays []float64
}

func (k *Keeper) GetVerifiableLoadStats(ctx context.Context, csv bool) {
func (k *Keeper) PrintVerifiableLoadStats(ctx context.Context, csv bool) {
var v verifiableLoad
var err error
addr := common.HexToAddress(k.cfg.VerifiableLoadContractAddress)
Expand Down Expand Up @@ -99,7 +99,7 @@ func (k *Keeper) GetVerifiableLoadStats(ctx context.Context, csv bool) {
// create a number of workers to process the upkeep ids in batch
for i := 0; i < workerNum; i++ {
wg.Add(1)
go k.getUpkeepInfo(idChan, resultsChan, v, opts, &wg, csv)
go k.fetchUpkeepInfo(idChan, resultsChan, v, opts, &wg, csv)
}

for _, id := range upkeepIds {
Expand Down Expand Up @@ -134,7 +134,7 @@ func (k *Keeper) GetVerifiableLoadStats(ctx context.Context, csv bool) {
log.Printf("All STATS ABOVE ARE CALCULATED AT BLOCK %d", blockNum)
}

func (k *Keeper) getUpkeepInfo(idChan chan *big.Int, resultsChan chan *upkeepInfo, v verifiableLoad, opts *bind.CallOpts, wg *sync.WaitGroup, csv bool) {
func (k *Keeper) fetchUpkeepInfo(idChan chan *big.Int, resultsChan chan *upkeepInfo, v verifiableLoad, opts *bind.CallOpts, wg *sync.WaitGroup, csv bool) {
defer wg.Done()

for id := range idChan {
Expand All @@ -161,7 +161,7 @@ func (k *Keeper) getUpkeepInfo(idChan chan *big.Int, resultsChan chan *upkeepInf
var wg1 sync.WaitGroup
for i := uint16(0); i <= b; i++ {
wg1.Add(1)
go k.getBucketData(v, opts, id, i, &wg1, info)
go k.fetchBucketData(v, opts, id, i, &wg1, info)
}
wg1.Wait()

Expand Down Expand Up @@ -196,7 +196,7 @@ func (k *Keeper) getUpkeepInfo(idChan chan *big.Int, resultsChan chan *upkeepInf
}
}

func (k *Keeper) getBucketData(v verifiableLoad, opts *bind.CallOpts, id *big.Int, bucketNum uint16, wg *sync.WaitGroup, info *upkeepInfo) {
func (k *Keeper) fetchBucketData(v verifiableLoad, opts *bind.CallOpts, id *big.Int, bucketNum uint16, wg *sync.WaitGroup, info *upkeepInfo) {
defer wg.Done()

var bucketDelays []*big.Int
Expand Down
2 changes: 2 additions & 0 deletions core/scripts/chaincli/handler/mercury_lookup_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ func (mlh *MercuryLookupHandler) singleFeedRequest(ctx context.Context, ch chan<
defer func(Body io.ReadCloser) {
err := Body.Close()
if err != nil {
_ = "" // placate linter
// mlh.logger.Errorf("Encountered error when closing the body of the response in single feed: %s", err)
}
}(resp.Body)
Expand Down Expand Up @@ -326,6 +327,7 @@ func (mlh *MercuryLookupHandler) multiFeedsRequest(ctx context.Context, ch chan<
defer func(Body io.ReadCloser) {
err := Body.Close()
if err != nil {
_ = "" // placate linter
// mlh.logger.Errorf("Encountered error when closing the body of the response in the multi feed: %s", err)
}
}(resp.Body)
Expand Down
15 changes: 5 additions & 10 deletions core/scripts/chaincli/handler/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,15 +235,12 @@ func (t *OCR2Transaction) BlockNumber() (uint64, error) {
block, err := hexutil.DecodeUint64(blStr)
if err != nil {
return 0, fmt.Errorf("failed to parse block number: %s", err)
} else {
return block, nil
}
} else {
return 0, fmt.Errorf("not a string")
return block, nil
}
} else {
return 0, fmt.Errorf("not found")
return 0, fmt.Errorf("not a string")
}
return 0, fmt.Errorf("not found")
}

func (t *OCR2Transaction) To() *common.Address {
Expand Down Expand Up @@ -335,17 +332,15 @@ func (t *OCR2TransmitTx) SetStaticValues(elem *OCR2ReportDataElem) {
if err != nil {
elem.Err = err.Error()
return
} else {
elem.From = from.String()
}
elem.From = from.String()

block, err := t.BlockNumber()
if err != nil {
elem.Err = err.Error()
return
} else {
elem.BlockNumber = fmt.Sprintf("%d", block)
}
elem.BlockNumber = fmt.Sprintf("%d", block)

upkeeps, err := t.UpkeepsInTransmit()
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion core/scripts/chaincli/handler/scrape_node_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,5 +279,5 @@ func writeJSON(data interface{}, path string) error {
return err
}

return os.WriteFile(path, dataBytes, 0644)
return os.WriteFile(path, dataBytes, 0644) //nolint:gosec
}
Loading

0 comments on commit 06656fa

Please sign in to comment.