Skip to content

Commit 5035f99

Browse files
authored
core/state: get rid of field pointer in journal (#30361)
This pull request replaces the field pointer in journal entry with the field itself, specifically the address of mutated account. While it will introduce the extra allocation cost, but it's easier for code reading. Let's measure the overhead overall to see if the change is acceptable or not.
1 parent 623b17b commit 5035f99

File tree

1 file changed

+38
-40
lines changed

1 file changed

+38
-40
lines changed

core/state/journal.go

Lines changed: 38 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -153,20 +153,20 @@ func (j *journal) logChange(txHash common.Hash) {
153153
}
154154

155155
func (j *journal) createObject(addr common.Address) {
156-
j.append(createObjectChange{account: &addr})
156+
j.append(createObjectChange{account: addr})
157157
}
158158

159159
func (j *journal) createContract(addr common.Address) {
160160
j.append(createContractChange{account: addr})
161161
}
162162

163163
func (j *journal) destruct(addr common.Address) {
164-
j.append(selfDestructChange{account: &addr})
164+
j.append(selfDestructChange{account: addr})
165165
}
166166

167167
func (j *journal) storageChange(addr common.Address, key, prev, origin common.Hash) {
168168
j.append(storageChange{
169-
account: &addr,
169+
account: addr,
170170
key: key,
171171
prevvalue: prev,
172172
origvalue: origin,
@@ -175,7 +175,7 @@ func (j *journal) storageChange(addr common.Address, key, prev, origin common.Ha
175175

176176
func (j *journal) transientStateChange(addr common.Address, key, prev common.Hash) {
177177
j.append(transientStorageChange{
178-
account: &addr,
178+
account: addr,
179179
key: key,
180180
prevalue: prev,
181181
})
@@ -187,25 +187,25 @@ func (j *journal) refundChange(previous uint64) {
187187

188188
func (j *journal) balanceChange(addr common.Address, previous *uint256.Int) {
189189
j.append(balanceChange{
190-
account: &addr,
190+
account: addr,
191191
prev: previous.Clone(),
192192
})
193193
}
194194

195195
func (j *journal) setCode(address common.Address) {
196-
j.append(codeChange{account: &address})
196+
j.append(codeChange{account: address})
197197
}
198198

199199
func (j *journal) nonceChange(address common.Address, prev uint64) {
200200
j.append(nonceChange{
201-
account: &address,
201+
account: address,
202202
prev: prev,
203203
})
204204
}
205205

206206
func (j *journal) touchChange(address common.Address) {
207207
j.append(touchChange{
208-
account: &address,
208+
account: address,
209209
})
210210
if address == ripemd {
211211
// Explicitly put it in the dirty-cache, which is otherwise generated from
@@ -215,50 +215,48 @@ func (j *journal) touchChange(address common.Address) {
215215
}
216216

217217
func (j *journal) accessListAddAccount(addr common.Address) {
218-
j.append(accessListAddAccountChange{&addr})
218+
j.append(accessListAddAccountChange{addr})
219219
}
220220

221221
func (j *journal) accessListAddSlot(addr common.Address, slot common.Hash) {
222222
j.append(accessListAddSlotChange{
223-
address: &addr,
224-
slot: &slot,
223+
address: addr,
224+
slot: slot,
225225
})
226226
}
227227

228228
type (
229229
// Changes to the account trie.
230230
createObjectChange struct {
231-
account *common.Address
231+
account common.Address
232232
}
233-
234233
// createContractChange represents an account becoming a contract-account.
235234
// This event happens prior to executing initcode. The journal-event simply
236235
// manages the created-flag, in order to allow same-tx destruction.
237236
createContractChange struct {
238237
account common.Address
239238
}
240-
241239
selfDestructChange struct {
242-
account *common.Address
240+
account common.Address
243241
}
244242

245243
// Changes to individual accounts.
246244
balanceChange struct {
247-
account *common.Address
245+
account common.Address
248246
prev *uint256.Int
249247
}
250248
nonceChange struct {
251-
account *common.Address
249+
account common.Address
252250
prev uint64
253251
}
254252
storageChange struct {
255-
account *common.Address
253+
account common.Address
256254
key common.Hash
257255
prevvalue common.Hash
258256
origvalue common.Hash
259257
}
260258
codeChange struct {
261-
account *common.Address
259+
account common.Address
262260
}
263261

264262
// Changes to other state values.
@@ -269,31 +267,31 @@ type (
269267
txhash common.Hash
270268
}
271269
touchChange struct {
272-
account *common.Address
270+
account common.Address
273271
}
274272

275273
// Changes to the access list
276274
accessListAddAccountChange struct {
277-
address *common.Address
275+
address common.Address
278276
}
279277
accessListAddSlotChange struct {
280-
address *common.Address
281-
slot *common.Hash
278+
address common.Address
279+
slot common.Hash
282280
}
283281

284282
// Changes to transient storage
285283
transientStorageChange struct {
286-
account *common.Address
284+
account common.Address
287285
key, prevalue common.Hash
288286
}
289287
)
290288

291289
func (ch createObjectChange) revert(s *StateDB) {
292-
delete(s.stateObjects, *ch.account)
290+
delete(s.stateObjects, ch.account)
293291
}
294292

295293
func (ch createObjectChange) dirtied() *common.Address {
296-
return ch.account
294+
return &ch.account
297295
}
298296

299297
func (ch createObjectChange) copy() journalEntry {
@@ -317,14 +315,14 @@ func (ch createContractChange) copy() journalEntry {
317315
}
318316

319317
func (ch selfDestructChange) revert(s *StateDB) {
320-
obj := s.getStateObject(*ch.account)
318+
obj := s.getStateObject(ch.account)
321319
if obj != nil {
322320
obj.selfDestructed = false
323321
}
324322
}
325323

326324
func (ch selfDestructChange) dirtied() *common.Address {
327-
return ch.account
325+
return &ch.account
328326
}
329327

330328
func (ch selfDestructChange) copy() journalEntry {
@@ -339,7 +337,7 @@ func (ch touchChange) revert(s *StateDB) {
339337
}
340338

341339
func (ch touchChange) dirtied() *common.Address {
342-
return ch.account
340+
return &ch.account
343341
}
344342

345343
func (ch touchChange) copy() journalEntry {
@@ -349,11 +347,11 @@ func (ch touchChange) copy() journalEntry {
349347
}
350348

351349
func (ch balanceChange) revert(s *StateDB) {
352-
s.getStateObject(*ch.account).setBalance(ch.prev)
350+
s.getStateObject(ch.account).setBalance(ch.prev)
353351
}
354352

355353
func (ch balanceChange) dirtied() *common.Address {
356-
return ch.account
354+
return &ch.account
357355
}
358356

359357
func (ch balanceChange) copy() journalEntry {
@@ -364,11 +362,11 @@ func (ch balanceChange) copy() journalEntry {
364362
}
365363

366364
func (ch nonceChange) revert(s *StateDB) {
367-
s.getStateObject(*ch.account).setNonce(ch.prev)
365+
s.getStateObject(ch.account).setNonce(ch.prev)
368366
}
369367

370368
func (ch nonceChange) dirtied() *common.Address {
371-
return ch.account
369+
return &ch.account
372370
}
373371

374372
func (ch nonceChange) copy() journalEntry {
@@ -379,23 +377,23 @@ func (ch nonceChange) copy() journalEntry {
379377
}
380378

381379
func (ch codeChange) revert(s *StateDB) {
382-
s.getStateObject(*ch.account).setCode(types.EmptyCodeHash, nil)
380+
s.getStateObject(ch.account).setCode(types.EmptyCodeHash, nil)
383381
}
384382

385383
func (ch codeChange) dirtied() *common.Address {
386-
return ch.account
384+
return &ch.account
387385
}
388386

389387
func (ch codeChange) copy() journalEntry {
390388
return codeChange{account: ch.account}
391389
}
392390

393391
func (ch storageChange) revert(s *StateDB) {
394-
s.getStateObject(*ch.account).setState(ch.key, ch.prevvalue, ch.origvalue)
392+
s.getStateObject(ch.account).setState(ch.key, ch.prevvalue, ch.origvalue)
395393
}
396394

397395
func (ch storageChange) dirtied() *common.Address {
398-
return ch.account
396+
return &ch.account
399397
}
400398

401399
func (ch storageChange) copy() journalEntry {
@@ -407,7 +405,7 @@ func (ch storageChange) copy() journalEntry {
407405
}
408406

409407
func (ch transientStorageChange) revert(s *StateDB) {
410-
s.setTransientState(*ch.account, ch.key, ch.prevalue)
408+
s.setTransientState(ch.account, ch.key, ch.prevalue)
411409
}
412410

413411
func (ch transientStorageChange) dirtied() *common.Address {
@@ -466,7 +464,7 @@ func (ch accessListAddAccountChange) revert(s *StateDB) {
466464
(addr) at this point, since no storage adds can remain when come upon
467465
a single (addr) change.
468466
*/
469-
s.accessList.DeleteAddress(*ch.address)
467+
s.accessList.DeleteAddress(ch.address)
470468
}
471469

472470
func (ch accessListAddAccountChange) dirtied() *common.Address {
@@ -480,7 +478,7 @@ func (ch accessListAddAccountChange) copy() journalEntry {
480478
}
481479

482480
func (ch accessListAddSlotChange) revert(s *StateDB) {
483-
s.accessList.DeleteSlot(*ch.address, *ch.slot)
481+
s.accessList.DeleteSlot(ch.address, ch.slot)
484482
}
485483

486484
func (ch accessListAddSlotChange) dirtied() *common.Address {

0 commit comments

Comments
 (0)