delete keys (#756)

This commit is contained in:
Evgeny Danilenko 2020-07-17 10:34:52 +03:00 committed by GitHub
parent c8a594dec6
commit f79b156a0b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -230,7 +230,7 @@ func (r *Receiver) accountLoad(k []byte, value []byte, _ etl.State, _ etl.LoadNe
}
r.accountMap[newKStr] = &a
} else {
r.accountMap[newKStr] = nil
delete(r.accountMap, newKStr)
}
r.unfurlList = append(r.unfurlList, newKStr)
return nil
@ -245,7 +245,7 @@ func (r *Receiver) storageLoad(k []byte, value []byte, _ etl.State, _ etl.LoadNe
if len(value) > 0 {
r.storageMap[newKStr] = common.CopyBytes(value)
} else {
r.storageMap[newKStr] = nil
delete(r.storageMap, newKStr)
}
r.unfurlList = append(r.unfurlList, newKStr)
return nil
@ -368,14 +368,12 @@ func incrementIntermediateHashes(s *StageState, db ethdb.Database, to uint64, da
return err
}
for ks, acc := range r.accountMap {
if acc != nil {
// Fill the code hashes
if acc.Incarnation > 0 && acc.IsEmptyCodeHash() {
if codeHash, err := db.Get(dbutils.ContractCodeBucket, dbutils.GenerateStoragePrefix([]byte(ks), acc.Incarnation)); err == nil {
copy(acc.CodeHash[:], codeHash)
} else if !errors.Is(err, ethdb.ErrKeyNotFound) {
return fmt.Errorf("adjusting codeHash for ks %x, inc %d: %w", ks, acc.Incarnation, err)
}
// Fill the code hashes
if acc.Incarnation > 0 && acc.IsEmptyCodeHash() {
if codeHash, err := db.Get(dbutils.ContractCodeBucket, dbutils.GenerateStoragePrefix([]byte(ks), acc.Incarnation)); err == nil {
copy(acc.CodeHash[:], codeHash)
} else if !errors.Is(err, ethdb.ErrKeyNotFound) {
return fmt.Errorf("adjusting codeHash for ks %x, inc %d: %w", ks, acc.Incarnation, err)
}
}
}
@ -456,16 +454,14 @@ func unwindIntermediateHashesStageImpl(u *UnwindState, s *StageState, db ethdb.D
return err
}
for ks, acc := range r.accountMap {
if acc != nil {
// Fill the code hashes
if acc.Incarnation > 0 && acc.IsEmptyCodeHash() {
if codeHash, err := db.Get(dbutils.ContractCodeBucket, dbutils.GenerateStoragePrefix([]byte(ks), acc.Incarnation)); err == nil {
copy(acc.CodeHash[:], codeHash)
} else if errors.Is(err, ethdb.ErrKeyNotFound) {
copy(acc.CodeHash[:], trie.EmptyCodeHash[:])
} else {
return fmt.Errorf("adjusting codeHash for ks %x, inc %d: %w", ks, acc.Incarnation, err)
}
// Fill the code hashes
if acc.Incarnation > 0 && acc.IsEmptyCodeHash() {
if codeHash, err := db.Get(dbutils.ContractCodeBucket, dbutils.GenerateStoragePrefix([]byte(ks), acc.Incarnation)); err == nil {
copy(acc.CodeHash[:], codeHash)
} else if errors.Is(err, ethdb.ErrKeyNotFound) {
copy(acc.CodeHash[:], trie.EmptyCodeHash[:])
} else {
return fmt.Errorf("adjusting codeHash for ks %x, inc %d: %w", ks, acc.Incarnation, err)
}
}
}