mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-26 22:56:43 +00:00
Enable prealloc check and improve address comparison
This commit is contained in:
parent
45a72bc49e
commit
2e2557a2d0
7 changed files with 18 additions and 17 deletions
|
|
@ -38,7 +38,7 @@ linters:
|
|||
- noctx
|
||||
#- nosprintfhostport # TODO: do we use IPv6?
|
||||
- paralleltest
|
||||
# - prealloc
|
||||
- prealloc
|
||||
- predeclared
|
||||
#- promlinter
|
||||
#- revive
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ type difficultiesKV struct {
|
|||
}
|
||||
|
||||
func rankMapDifficulties(values map[common.Address]uint64) []difficultiesKV {
|
||||
var ss []difficultiesKV
|
||||
ss := make([]difficultiesKV, 0, len(values))
|
||||
for k, v := range values {
|
||||
ss = append(ss, difficultiesKV{k, v})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -472,10 +472,9 @@ func (c *Bor) verifyCascadingFields(chain consensus.ChainHeaderReader, header *t
|
|||
// nolint: gocognit
|
||||
func (c *Bor) snapshot(chain consensus.ChainHeaderReader, number uint64, hash common.Hash, parents []*types.Header) (*Snapshot, error) {
|
||||
// Search for a snapshot in memory or on disk for checkpoints
|
||||
var (
|
||||
headers []*types.Header
|
||||
snap *Snapshot
|
||||
)
|
||||
var snap *Snapshot
|
||||
|
||||
headers := make([]*types.Header, 0, 16)
|
||||
|
||||
//nolint:govet
|
||||
for snap == nil {
|
||||
|
|
@ -549,6 +548,8 @@ func (c *Bor) snapshot(chain consensus.ChainHeaderReader, number uint64, hash co
|
|||
number, hash = number-1, header.ParentHash
|
||||
}
|
||||
|
||||
log.Info("Snapshot has been found in %d headers depth.", len(headers))
|
||||
|
||||
// check if snapshot is nil
|
||||
if snap == nil {
|
||||
return nil, fmt.Errorf("Unknown error while retrieving snapshot at block number %v", number)
|
||||
|
|
@ -701,7 +702,7 @@ func (c *Bor) Prepare(chain consensus.ChainHeaderReader, header *types.Header) e
|
|||
|
||||
var succession int
|
||||
// if signer is not empty
|
||||
if !bytes.Equal(c.signer.Bytes(), common.Address{}.Bytes()) {
|
||||
if c.signer != (common.Address{}) {
|
||||
succession, err = snap.GetSignerSuccessionNumber(c.signer)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
@ -1146,7 +1147,7 @@ func (c *Bor) fetchAndCommitSpan(
|
|||
}
|
||||
|
||||
// get validators bytes
|
||||
var validators []MinimalVal
|
||||
validators := make([]MinimalVal, 0, len(heimdallSpan.ValidatorSet.Validators))
|
||||
for _, val := range heimdallSpan.ValidatorSet.Validators {
|
||||
validators = append(validators, val.MinimalVal())
|
||||
}
|
||||
|
|
@ -1158,7 +1159,7 @@ func (c *Bor) fetchAndCommitSpan(
|
|||
}
|
||||
|
||||
// get producers bytes
|
||||
var producers []MinimalVal
|
||||
producers := make([]MinimalVal, 0, len(heimdallSpan.SelectedProducers))
|
||||
for _, val := range heimdallSpan.SelectedProducers {
|
||||
producers = append(producers, val.MinimalVal())
|
||||
}
|
||||
|
|
@ -1401,7 +1402,7 @@ func applyMessage(
|
|||
|
||||
func validatorContains(a []*Validator, x *Validator) (*Validator, bool) {
|
||||
for _, n := range a {
|
||||
if bytes.Equal(n.Address.Bytes(), x.Address.Bytes()) {
|
||||
if n.Address == x.Address {
|
||||
return n, true
|
||||
}
|
||||
}
|
||||
|
|
@ -1413,7 +1414,7 @@ func getUpdatedValidatorSet(oldValidatorSet *ValidatorSet, newVals []*Validator)
|
|||
v := oldValidatorSet
|
||||
oldVals := v.Validators
|
||||
|
||||
var changes []*Validator
|
||||
changes := make([]*Validator, 0, len(oldVals))
|
||||
|
||||
for _, ov := range oldVals {
|
||||
if f, ok := validatorContains(newVals, ov); ok {
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ func convertTo32(input []byte) (output [32]byte) {
|
|||
}
|
||||
|
||||
func convert(input []([32]byte)) [][]byte {
|
||||
var output [][]byte
|
||||
output := make([][]byte, 0, len(input))
|
||||
|
||||
for _, in := range input {
|
||||
newInput := make([]byte, len(in[:]))
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package bor
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
|
||||
lru "github.com/hashicorp/golang-lru"
|
||||
|
|
@ -208,7 +207,7 @@ func (s *Snapshot) signers() []common.Address {
|
|||
// Difficulty returns the difficulty for a particular signer at the current snapshot number
|
||||
func (s *Snapshot) Difficulty(signer common.Address) uint64 {
|
||||
// if signer is empty
|
||||
if bytes.Equal(signer.Bytes(), common.Address{}.Bytes()) {
|
||||
if signer == (common.Address{}) {
|
||||
return 1
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -255,7 +255,7 @@ func (vals *ValidatorSet) GetByAddress(address common.Address) (index int, val *
|
|||
idx := sort.Search(len(vals.Validators), func(i int) bool {
|
||||
return bytes.Compare(address.Bytes(), vals.Validators[i].Address.Bytes()) <= 0
|
||||
})
|
||||
if idx < len(vals.Validators) && bytes.Equal(vals.Validators[idx].Address.Bytes(), address.Bytes()) {
|
||||
if idx < len(vals.Validators) && vals.Validators[idx].Address == address {
|
||||
return idx, vals.Validators[idx].Copy()
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -182,9 +182,10 @@ func (c *AttachCommand) makeConsolePreloads() []string {
|
|||
return nil
|
||||
}
|
||||
// Otherwise resolve absolute paths and return them
|
||||
var preloads []string
|
||||
splitFlags := strings.Split(c.PreloadJSFlag, ",")
|
||||
preloads := make([]string, 0, len(splitFlags))
|
||||
|
||||
for _, file := range strings.Split(c.PreloadJSFlag, ",") {
|
||||
for _, file := range splitFlags {
|
||||
preloads = append(preloads, strings.TrimSpace(file))
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue