mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-22 20:56:42 +00:00
all: make increaseKey common
This commit is contained in:
parent
659342a523
commit
234c73a7b7
4 changed files with 17 additions and 41 deletions
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Reference in a new issue