all: make increaseKey common

This commit is contained in:
cuiweixie 2025-10-11 19:31:25 +08:00
parent 659342a523
commit 234c73a7b7
No known key found for this signature in database
GPG key ID: 16DF64EE15E495A3
4 changed files with 17 additions and 41 deletions

View file

@ -149,3 +149,15 @@ func TrimRightZeroes(s []byte) []byte {
}
return s[:idx]
}
// IncreaseKey increase the input key by one bit. Return nil if the entire
// addition operation overflows.
func IncreaseKey(key []byte) []byte {
for i := len(key) - 1; i >= 0; i-- {
key[i]++
if key[i] != 0x0 {
return key
}
}
return nil
}

View file

@ -212,18 +212,6 @@ func DeleteTrienodeHistoryIndexBlock(db ethdb.KeyValueWriter, addressHash common
}
}
// increaseKey increase the input key by one bit. Return nil if the entire
// addition operation overflows.
func increaseKey(key []byte) []byte {
for i := len(key) - 1; i >= 0; i-- {
key[i]++
if key[i] != 0x0 {
return key
}
}
return nil
}
// DeleteStateHistoryIndexes completely removes all history indexing data, including
// indexes for accounts and storages.
func DeleteStateHistoryIndexes(db ethdb.KeyValueRangeDeleter) {
@ -243,7 +231,7 @@ func DeleteTrienodeHistoryIndexes(db ethdb.KeyValueRangeDeleter) {
// Note, this method assumes the space with the given prefix is exclusively occupied!
func DeleteHistoryByRange(db ethdb.KeyValueRangeDeleter, prefix []byte) {
start := prefix
limit := increaseKey(bytes.Clone(prefix))
limit := common.IncreaseKey(bytes.Clone(prefix))
// Try to remove the data in the range by a loop, as the leveldb
// doesn't support the native range deletion.

View file

@ -545,7 +545,7 @@ func generateStorages(ctx *generatorContext, dl *diskLayer, stateRoot common.Has
if exhausted {
break
}
if origin = increaseKey(last); origin == nil {
if origin = common.IncreaseKey(last); origin == nil {
break // special case, the last is 0xffffffff...fff
}
}
@ -631,7 +631,7 @@ func generateAccounts(ctx *generatorContext, dl *diskLayer, accMarker []byte) er
if err != nil {
return err // The procedure it aborted, either by external signal or internal error.
}
origin = increaseKey(last)
origin = common.IncreaseKey(last)
// Last step, cleanup the storages after the last account.
// All the left storages should be treated as dangling.
@ -706,18 +706,6 @@ func (dl *diskLayer) generate(stats *generatorStats) {
abort <- nil
}
// increaseKey increase the input key by one bit. Return nil if the entire
// addition operation overflows.
func increaseKey(key []byte) []byte {
for i := len(key) - 1; i >= 0; i-- {
key[i]++
if key[i] != 0x0 {
return key
}
}
return nil
}
// abortErr wraps an interruption signal received to represent the
// generation is aborted by external processes.
type abortErr struct {

View file

@ -663,7 +663,7 @@ func (g *generator) generateStorages(ctx *generatorContext, account common.Hash,
if exhausted {
break
}
if origin = increaseKey(last); origin == nil {
if origin = common.IncreaseKey(last); origin == nil {
break // special case, the last is 0xffffffff...fff
}
}
@ -749,7 +749,7 @@ func (g *generator) generateAccounts(ctx *generatorContext, accMarker []byte) er
if err != nil {
return err // The procedure it aborted, either by external signal or internal error.
}
origin = increaseKey(last)
origin = common.IncreaseKey(last)
// Last step, cleanup the storages after the last account.
// All the left storages should be treated as dangling.
@ -829,18 +829,6 @@ func (g *generator) generate(ctx *generatorContext) {
close(abort)
}
// increaseKey increase the input key by one bit. Return nil if the entire
// addition operation overflows.
func increaseKey(key []byte) []byte {
for i := len(key) - 1; i >= 0; i-- {
key[i]++
if key[i] != 0x0 {
return key
}
}
return nil
}
// abortErr wraps an interruption signal received to represent the
// generation is aborted by external processes.
type abortErr struct {