Skip to content

Commit d8ac267

Browse files
committed
dirty tracking for state objects fixed
1 parent 982f73f commit d8ac267

File tree

4 files changed

+13
-8
lines changed

4 files changed

+13
-8
lines changed

core/block_processor.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -296,16 +296,13 @@ func (sm *BlockProcessor) AccumulateRewards(statedb *state.StateDB, block, paren
296296
r := new(big.Int)
297297
r.Mul(BlockReward, big.NewInt(15)).Div(r, big.NewInt(16))
298298

299-
uncleAccount := statedb.GetAccount(uncle.Coinbase)
300-
uncleAccount.AddAmount(r)
299+
statedb.AddBalance(uncle.Coinbase, r)
301300

302301
reward.Add(reward, new(big.Int).Div(BlockReward, big.NewInt(32)))
303302
}
304303

305304
// Get the account associated with the coinbase
306-
account := statedb.GetAccount(block.Header().Coinbase)
307-
// Reward amount of ether to the coinbase address
308-
account.AddAmount(reward)
305+
statedb.AddBalance(block.Header().Coinbase, reward)
309306

310307
return nil
311308
}

core/chain_manager.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ func (self *ChainManager) InsertChain(chain types.Blocks) error {
397397

398398
if chain {
399399
//self.setTransState(state.New(block.Root(), self.db))
400-
self.eventMux.Post(ChainEvent{block, td})
400+
//self.eventMux.Post(ChainEvent{block, td})
401401
}
402402

403403
if split {

eth/protocol.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
)
1414

1515
const (
16-
ProtocolVersion = 52
16+
ProtocolVersion = 53
1717
NetworkId = 0
1818
ProtocolLength = uint64(8)
1919
ProtocolMaxMsgSize = 10 * 1024 * 1024

state/state_object.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func NewStateObject(addr []byte, db ethutil.Database) *StateObject {
6565
// This to ensure that it has 20 bytes (and not 0 bytes), thus left or right pad doesn't matter.
6666
address := ethutil.Address(addr)
6767

68-
object := &StateObject{db: db, address: address, balance: new(big.Int), gasPool: new(big.Int)}
68+
object := &StateObject{db: db, address: address, balance: new(big.Int), gasPool: new(big.Int), dirty: true}
6969
object.State = New(nil, db) //New(trie.New(ethutil.Config.Db, ""))
7070
object.storage = make(Storage)
7171
object.gasPool = new(big.Int)
@@ -118,6 +118,7 @@ func (self *StateObject) GetStorage(key *big.Int) *ethutil.Value {
118118
}
119119
func (self *StateObject) SetStorage(key *big.Int, value *ethutil.Value) {
120120
self.SetState(key.Bytes(), value)
121+
self.dirty = true
121122
}
122123

123124
func (self *StateObject) Storage() map[string]*ethutil.Value {
@@ -142,6 +143,7 @@ func (self *StateObject) GetState(k []byte) *ethutil.Value {
142143
func (self *StateObject) SetState(k []byte, value *ethutil.Value) {
143144
key := ethutil.LeftPadBytes(k, 32)
144145
self.storage[string(key)] = value.Copy()
146+
self.dirty = true
145147
}
146148

147149
func (self *StateObject) Sync() {
@@ -166,6 +168,7 @@ func (c *StateObject) GetInstr(pc *big.Int) *ethutil.Value {
166168

167169
func (c *StateObject) AddBalance(amount *big.Int) {
168170
c.SetBalance(new(big.Int).Add(c.balance, amount))
171+
c.dirty = true
169172

170173
statelogger.Debugf("%x: #%d %v (+ %v)\n", c.Address(), c.Nonce, c.balance, amount)
171174
}
@@ -180,6 +183,7 @@ func (c *StateObject) SubAmount(amount *big.Int) { c.SubBalance(amount) }
180183

181184
func (c *StateObject) SetBalance(amount *big.Int) {
182185
c.balance = amount
186+
c.dirty = true
183187
}
184188

185189
func (self *StateObject) Balance() *big.Int { return self.balance }
@@ -198,6 +202,8 @@ func (c *StateObject) ConvertGas(gas, price *big.Int) error {
198202

199203
c.SubAmount(total)
200204

205+
c.dirty = true
206+
201207
return nil
202208
}
203209

@@ -219,6 +225,8 @@ func (self *StateObject) BuyGas(gas, price *big.Int) error {
219225

220226
self.AddAmount(rGas)
221227

228+
self.dirty = true
229+
222230
return nil
223231
}
224232

0 commit comments

Comments
 (0)