node: remove implicit memory aliasing in a loop
Caught by an upgraded golangci-lint with the gosec linter: ::medium file=node/pkg/watchers/evm/connectors/batch_poller.go,line=226,col=8::G601: Implicit memory aliasing in for loop. (gosec) ::medium file=node/pkg/watchers/evm/connectors/batch_poller.go,line=285,col=8::G601: Implicit memory aliasing in for loop. (gosec) ::medium file=node/pkg/watchers/evm/connectors/batch_poller_test.go,line=128,col=37::G601: Implicit memory aliasing in for loop. (gosec) See also: https://husni.dev/beware-of-implicit-memory-aliasing-in-go-foor-loop/
This commit is contained in:
parent
2a56a68024
commit
bdb69c3e44
|
@ -207,12 +207,12 @@ func ccqBackFillDetermineMaxBatchSize(ctx context.Context, logger *zap.Logger, c
|
|||
|
||||
// Save the blocks we just retrieved to be used as our starting cache.
|
||||
blocks := Blocks{}
|
||||
for _, result := range results {
|
||||
if result.err != nil {
|
||||
return 0, nil, fmt.Errorf("failed to get block: %w", result.err)
|
||||
for i := range results {
|
||||
if results[i].err != nil {
|
||||
return 0, nil, fmt.Errorf("failed to get block: %w", results[i].err)
|
||||
}
|
||||
|
||||
m := &result.result
|
||||
m := &results[i].result
|
||||
|
||||
if m.Number != 0 {
|
||||
blocks = append(blocks, Block{
|
||||
|
@ -262,12 +262,12 @@ func (w *Watcher) ccqBackfillGetBlocks(ctx context.Context, initialBlockNum int6
|
|||
}
|
||||
|
||||
blocks := Blocks{}
|
||||
for _, result := range results {
|
||||
if result.err != nil {
|
||||
for i := range results {
|
||||
if results[i].err != nil {
|
||||
return nil, fmt.Errorf("failed to get block: %w", err)
|
||||
}
|
||||
|
||||
m := &result.result
|
||||
m := &results[i].result
|
||||
|
||||
if m.Number != 0 {
|
||||
blocks = append(blocks, Block{
|
||||
|
|
|
@ -223,7 +223,7 @@ func (b *BatchPollConnector) getBlocks(ctx context.Context, logger *zap.Logger)
|
|||
}
|
||||
|
||||
var n big.Int
|
||||
m := &result.result
|
||||
m := &results[idx].result
|
||||
if m.Number == nil {
|
||||
logger.Debug("number is nil, treating as zero", zap.Stringer("finality", finality), zap.String("tag", b.batchData[idx].tag))
|
||||
} else {
|
||||
|
@ -275,14 +275,14 @@ func (b *BatchPollConnector) getBlockRange(ctx context.Context, logger *zap.Logg
|
|||
}
|
||||
|
||||
ret := make(Blocks, numBlocks)
|
||||
for idx, result := range results {
|
||||
if result.err != nil {
|
||||
logger.Error("failed to get block", zap.Int("idx", idx), zap.Stringer("finality", finality), zap.Error(result.err))
|
||||
for idx := range results {
|
||||
if results[idx].err != nil {
|
||||
logger.Error("failed to get block", zap.Int("idx", idx), zap.Stringer("finality", finality), zap.Error(results[idx].err))
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var n big.Int
|
||||
m := &result.result
|
||||
m := &results[idx].result
|
||||
if m.Number == nil {
|
||||
logger.Debug("number is nil, treating as zero", zap.Stringer("finality", finality))
|
||||
} else {
|
||||
|
|
|
@ -107,7 +107,7 @@ func (e *mockConnectorForBatchPoller) RawBatchCallContext(ctx context.Context, b
|
|||
return err
|
||||
}
|
||||
|
||||
for _, entry := range b {
|
||||
for i, entry := range b {
|
||||
if entry.Method != "eth_getBlockByNumber" {
|
||||
panic("method not implemented by mockConnectorForBatchPoller")
|
||||
}
|
||||
|
@ -125,7 +125,7 @@ func (e *mockConnectorForBatchPoller) RawBatchCallContext(ctx context.Context, b
|
|||
e.blockNumbers = e.blockNumbers[1:]
|
||||
}
|
||||
str := fmt.Sprintf(`{"author":"0x24c275f0719fdaec6356c4eb9f39ecb9c4d37ce1","baseFeePerGas":"0x3b9aca00","difficulty":"0x0","extraData":"0x","gasLimit":"0xe4e1c0","gasUsed":"0x0","hash":"0xfc8b62a31110121c57cfcccfaf2b147cc2c13b6d01bde4737846cefd29f045cf","logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","miner":"0x24c275f0719fdaec6356c4eb9f39ecb9c4d37ce1","nonce":"0x0000000000000000","number":"0x%x","parentHash":"0x09d6d33a658b712f41db7fb9f775f94911ae0132123116aa4f8cf3da9f774e89","receiptsRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421","sha3Uncles":"0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347","size":"0x201","stateRoot":"0x0409ed10e03fd49424ae1489c6fbc6ff1897f45d0e214655ebdb8df94eedc3c0","timestamp":"0x6373ec24","totalDifficulty":"0x0","transactions":[],"transactionsRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421","uncles":[]}`, blockNumber)
|
||||
err = json.Unmarshal([]byte(str), &entry.Result)
|
||||
err = json.Unmarshal([]byte(str), &b[i].Result)
|
||||
if entry.Args[0] == "latest" {
|
||||
e.prevLatest = blockNumber
|
||||
} else if entry.Args[0] == "safe" {
|
||||
|
|
Loading…
Reference in New Issue