Skip to content

Commit

Permalink
save
Browse files Browse the repository at this point in the history
  • Loading branch information
AskAlexSharov committed Nov 6, 2024
1 parent 97f49a5 commit 7dc38c5
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 38 deletions.
8 changes: 4 additions & 4 deletions cmd/devnet/devnetutils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,10 @@ func GenerateTopic(signature string) []libcommon.Hash {
}

// RandomNumberInRange returns a random number between min and max NOT inclusive
func RandomNumberInRange(min, max uint64) (uint64, error) {
if max <= min {
return 0, fmt.Errorf("Invalid range: upper bound %d less or equal than lower bound %d", max, min)
func RandomNumberInRange(_min, _max uint64) (uint64, error) {
if _max <= _min {
return 0, fmt.Errorf("Invalid range: upper bound %d less or equal than lower bound %d", _max, _min)
}

return uint64(RandomInt(int(max-min)) + int(min)), nil
return uint64(RandomInt(int(_max-_min)) + int(_min)), nil
}
4 changes: 2 additions & 2 deletions consensus/ethash/consensus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,11 @@ func TestCalcDifficulty(t *testing.T) {
}
}

func randSlice(min, max uint32) []byte {
func randSlice(_min, _max uint32) []byte {
var b = make([]byte, 4)
rand.Read(b)
a := binary.LittleEndian.Uint32(b)
size := min + a%(max-min)
size := _min + a%(_max-_min)
out := make([]byte, size)
rand.Read(out)
return out
Expand Down
8 changes: 4 additions & 4 deletions erigon-lib/chain/snapcfg/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -464,17 +464,17 @@ func MergeLimitFromCfg(cfg *Cfg, snapType snaptype.Enum, fromBlock uint64) uint6
}

func MaxSeedableSegment(chain string, dir string) uint64 {
var max uint64
var _max uint64

if list, err := snaptype.Segments(dir); err == nil {
for _, info := range list {
if Seedable(chain, info) && info.Type.Enum() == snaptype.MinCoreEnum && info.To > max {
max = info.To
if Seedable(chain, info) && info.Type.Enum() == snaptype.MinCoreEnum && info.To > _max {
_max = info.To
}
}
}

return max
return _max
}

var oldMergeSteps = append([]uint64{snaptype.Erigon2OldMergeLimit}, snaptype.MergeSteps...)
Expand Down
16 changes: 8 additions & 8 deletions erigon-lib/types/ssz/ssz.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func DecodeDynamicList[T Unmarshaler](bytes []byte, start, end uint32, _max uint
return objs, nil
}

func DecodeStaticList[T Unmarshaler](bytes []byte, start, end, bytesPerElement uint32, max uint64, version int) ([]T, error) {
func DecodeStaticList[T Unmarshaler](bytes []byte, start, end, bytesPerElement uint32, _max uint64, version int) ([]T, error) {
if start > end || len(bytes) < int(end) {
return nil, ErrBadOffset
}
Expand All @@ -131,7 +131,7 @@ func DecodeStaticList[T Unmarshaler](bytes []byte, start, end, bytesPerElement u
if uint32(len(buf))%bytesPerElement != 0 {
return nil, ErrBufferNotRounded
}
if elementsNum > max {
if elementsNum > _max {
return nil, ErrTooBigList
}
objs := make([]T, elementsNum)
Expand All @@ -144,7 +144,7 @@ func DecodeStaticList[T Unmarshaler](bytes []byte, start, end, bytesPerElement u
return objs, nil
}

func DecodeHashList(bytes []byte, start, end, max uint32) ([]common.Hash, error) {
func DecodeHashList(bytes []byte, start, end, _max uint32) ([]common.Hash, error) {
if start > end || len(bytes) < int(end) {
return nil, ErrBadOffset
}
Expand All @@ -154,7 +154,7 @@ func DecodeHashList(bytes []byte, start, end, max uint32) ([]common.Hash, error)
if uint32(len(buf))%length.Hash != 0 {
return nil, ErrBufferNotRounded
}
if elementsNum > max {
if elementsNum > _max {
return nil, ErrTooBigList
}
objs := make([]common.Hash, elementsNum)
Expand All @@ -164,7 +164,7 @@ func DecodeHashList(bytes []byte, start, end, max uint32) ([]common.Hash, error)
return objs, nil
}

func DecodeNumbersList(bytes []byte, start, end uint32, max uint64) ([]uint64, error) {
func DecodeNumbersList(bytes []byte, start, end uint32, _max uint64) ([]uint64, error) {
if start > end || len(bytes) < int(end) {
return nil, ErrBadOffset
}
Expand All @@ -174,7 +174,7 @@ func DecodeNumbersList(bytes []byte, start, end uint32, max uint64) ([]uint64, e
if uint64(len(buf))%length.BlockNum != 0 {
return nil, ErrBufferNotRounded
}
if elementsNum > max {
if elementsNum > _max {
return nil, ErrTooBigList
}
objs := make([]uint64, elementsNum)
Expand All @@ -195,12 +195,12 @@ func CalculateIndiciesLimit(maxCapacity, numItems, size uint64) uint64 {
return numItems
}

func DecodeString(bytes []byte, start, end, max uint64) ([]byte, error) {
func DecodeString(bytes []byte, start, end, _max uint64) ([]byte, error) {
if start > end || len(bytes) < int(end) {
return nil, ErrBadOffset
}
buf := bytes[start:end]
if uint64(len(buf)) > max {
if uint64(len(buf)) > _max {
return nil, ErrTooBigList
}
return buf, nil
Expand Down
12 changes: 6 additions & 6 deletions eth/stagedsync/stage_snapshots.go
Original file line number Diff line number Diff line change
Expand Up @@ -758,22 +758,22 @@ func (u *snapshotUploader) init(ctx context.Context, logger log.Logger) {
}

func (u *snapshotUploader) maxUploadedHeader() uint64 {
var max uint64
var _max uint64

if len(u.files) > 0 {
for _, state := range u.files {
if state.local && state.remote {
if state.info != nil {
if state.info.Type.Enum() == coresnaptype.Enums.Headers {
if state.info.To > max {
max = state.info.To
if state.info.To > _max {
_max = state.info.To
}
}
} else {
if info, _, ok := snaptype.ParseFileName(u.cfg.dirs.Snap, state.file); ok {
if info.Type.Enum() == coresnaptype.Enums.Headers {
if info.To > max {
max = info.To
if info.To > _max {
_max = info.To
}
}
state.info = &info
Expand All @@ -783,7 +783,7 @@ func (u *snapshotUploader) maxUploadedHeader() uint64 {
}
}

return max
return _max
}

type dirEntry struct {
Expand Down
8 changes: 4 additions & 4 deletions tests/fuzzers/difficulty/difficulty-fuzz.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ func (f *fuzzer) readSlice(min, max int) []byte {
return out
}

func (f *fuzzer) readUint64(min, max uint64) uint64 {
if min == max {
return min
func (f *fuzzer) readUint64(_min, _max uint64) uint64 {
if _min == _max {
return _min
}
var a uint64
if err := binary.Read(f.input, binary.LittleEndian, &a); err != nil {
f.exhausted = true
}
a = min + a%(max-min)
a = _min + a%(_max-_min)
return a
}
func (f *fuzzer) readBool() bool {
Expand Down
8 changes: 4 additions & 4 deletions turbo/snapshotsync/freezeblocks/bor_snapshots.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func (br *BlockRetire) retireBorBlocks(ctx context.Context, minBlockNum uint64,

// this is one off code to fix an issue in 2.49.x->2.52.x which missed
// removal of intermediate segments after a merge operation
func removeBorOverlaps(dir string, active []snaptype.FileInfo, max uint64) {
func removeBorOverlaps(dir string, active []snaptype.FileInfo, _max uint64) {
list, err := snaptype.Segments(dir)

if err != nil {
Expand All @@ -165,12 +165,12 @@ func removeBorOverlaps(dir string, active []snaptype.FileInfo, max uint64) {

// added overhead to make sure we don't delete in the
// current 500k block segment
if max > 500_001 {
max -= 500_001
if _max > 500_001 {
_max -= 500_001
}

for _, f := range l {
if max < f.From {
if _max < f.From {
continue
}

Expand Down
12 changes: 6 additions & 6 deletions turbo/snapshotsync/snapshots.go
Original file line number Diff line number Diff line change
Expand Up @@ -838,38 +838,38 @@ func (s *RoSnapshots) dirtyIdxAvailability(segtype snaptype.Enum) uint64 {
return 0
}

var max uint64
var _max uint64

dirty.Walk(func(segments []*DirtySegment) bool {
for _, seg := range segments {
if !seg.IsIndexed() {
break
}

max = seg.to - 1
_max = seg.to - 1
}

return true
})

return max
return _max
}

func (s *RoSnapshots) visibleIdxAvailability(segtype snaptype.Enum) uint64 {
tx := s.ViewType(segtype.Type())
defer tx.Close()

var max uint64
var _max uint64

for _, seg := range tx.Segments {
if !seg.IsIndexed() {
break
}

max = seg.to - 1
_max = seg.to - 1
}

return max
return _max
}

func (s *RoSnapshots) Ls() {
Expand Down

0 comments on commit 7dc38c5

Please sign in to comment.