Commit 2b247595 authored by Mark Tyneway's avatar Mark Tyneway Committed by GitHub

state-surgery: safer memorydb (#3261)

Do not overwrite accounts that already exist when
creating accounts with the memory db. Also panic
if trying to set state in an account that doesn't
yet exist in the state.
Co-authored-by: default avatarmergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
parent 692ca3ff
......@@ -60,12 +60,15 @@ func (db *MemoryStateDB) CreateAccount(addr common.Address) {
db.rw.Lock()
defer db.rw.Unlock()
db.genesis.Alloc[addr] = core.GenesisAccount{
Code: []byte{},
Storage: make(map[common.Hash]common.Hash),
Balance: big.NewInt(0),
Nonce: 0,
if _, ok := db.genesis.Alloc[addr]; !ok {
db.genesis.Alloc[addr] = core.GenesisAccount{
Code: []byte{},
Storage: make(map[common.Hash]common.Hash),
Balance: big.NewInt(0),
Nonce: 0,
}
}
}
func (db *MemoryStateDB) SubBalance(addr common.Address, amount *big.Int) {
......@@ -216,7 +219,7 @@ func (db *MemoryStateDB) SetState(addr common.Address, key, value common.Hash) {
account, ok := db.genesis.Alloc[addr]
if !ok {
return
panic(fmt.Sprintf("%s not in state", addr))
}
account.Storage[key] = value
db.genesis.Alloc[addr] = account
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment