Skip to content

Commit f4e0f1b

Browse files
committed
review feedback
Signed-off-by: Guillaume Ballet <[email protected]>
1 parent 13a09a4 commit f4e0f1b

File tree

1 file changed

+42
-42
lines changed

1 file changed

+42
-42
lines changed

core/state/access_events.go

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -95,63 +95,63 @@ func (ae *AccessEvents) Copy() *AccessEvents {
9595
// member fields of an account.
9696
func (ae *AccessEvents) AddAccount(addr common.Address, isWrite bool, availableGas uint64) uint64 {
9797
var gas uint64 // accumulate the consumed gas
98-
consumed, wanted := ae.touchAddressAndChargeGas(addr, zeroTreeIndex, utils.BasicDataLeafKey, isWrite, availableGas)
99-
if consumed < wanted {
100-
return wanted
98+
consumed, expected := ae.touchAddressAndChargeGas(addr, zeroTreeIndex, utils.BasicDataLeafKey, isWrite, availableGas)
99+
if consumed < expected {
100+
return expected
101101
}
102102
gas += consumed
103-
consumed, wanted = ae.touchAddressAndChargeGas(addr, zeroTreeIndex, utils.CodeHashLeafKey, isWrite, availableGas-consumed)
104-
if consumed < wanted {
105-
return wanted + gas
103+
consumed, expected = ae.touchAddressAndChargeGas(addr, zeroTreeIndex, utils.CodeHashLeafKey, isWrite, availableGas-consumed)
104+
if consumed < expected {
105+
return expected + gas
106106
}
107-
gas += wanted
107+
gas += expected
108108
return gas
109109
}
110110

111111
// MessageCallGas returns the gas to be charged for each of the currently
112112
// cold member fields of an account, that need to be touched when making a message
113113
// call to that account.
114114
func (ae *AccessEvents) MessageCallGas(destination common.Address, availableGas uint64) uint64 {
115-
_, wanted := ae.touchAddressAndChargeGas(destination, zeroTreeIndex, utils.BasicDataLeafKey, false, availableGas)
116-
if wanted == 0 {
117-
wanted = params.WarmStorageReadCostEIP2929
115+
_, expected := ae.touchAddressAndChargeGas(destination, zeroTreeIndex, utils.BasicDataLeafKey, false, availableGas)
116+
if expected == 0 {
117+
expected = params.WarmStorageReadCostEIP2929
118118
}
119-
return wanted
119+
return expected
120120
}
121121

122122
// ValueTransferGas returns the gas to be charged for each of the currently
123123
// cold balance member fields of the caller and the callee accounts.
124124
func (ae *AccessEvents) ValueTransferGas(callerAddr, targetAddr common.Address, availableGas uint64) uint64 {
125-
_, wanted1 := ae.touchAddressAndChargeGas(callerAddr, zeroTreeIndex, utils.BasicDataLeafKey, true, availableGas)
126-
if wanted1 > availableGas {
127-
return wanted1
125+
_, expected1 := ae.touchAddressAndChargeGas(callerAddr, zeroTreeIndex, utils.BasicDataLeafKey, true, availableGas)
126+
if expected1 > availableGas {
127+
return expected1
128128
}
129-
_, wanted2 := ae.touchAddressAndChargeGas(targetAddr, zeroTreeIndex, utils.BasicDataLeafKey, true, availableGas-wanted1)
130-
if wanted1+wanted2 > availableGas {
129+
_, expected2 := ae.touchAddressAndChargeGas(targetAddr, zeroTreeIndex, utils.BasicDataLeafKey, true, availableGas-expected1)
130+
if expected1+expected2 > availableGas {
131131
return params.WarmStorageReadCostEIP2929
132132
}
133-
return wanted1 + wanted2
133+
return expected1 + expected2
134134
}
135135

136136
// ContractCreatePreCheckGas charges access costs before
137137
// a contract creation is initiated. It is just reads, because the
138138
// address collision is done before the transfer, and so no write
139139
// are guaranteed to happen at this point.
140140
func (ae *AccessEvents) ContractCreatePreCheckGas(addr common.Address, availableGas uint64) uint64 {
141-
consumed, wanted1 := ae.touchAddressAndChargeGas(addr, zeroTreeIndex, utils.BasicDataLeafKey, false, availableGas)
142-
_, wanted2 := ae.touchAddressAndChargeGas(addr, zeroTreeIndex, utils.CodeHashLeafKey, false, availableGas-consumed)
143-
return wanted1 + wanted2
141+
consumed, expected1 := ae.touchAddressAndChargeGas(addr, zeroTreeIndex, utils.BasicDataLeafKey, false, availableGas)
142+
_, expected2 := ae.touchAddressAndChargeGas(addr, zeroTreeIndex, utils.CodeHashLeafKey, false, availableGas-consumed)
143+
return expected1 + expected2
144144
}
145145

146146
// ContractCreateInitGas returns the access gas costs for the initialization of
147147
// a contract creation.
148148
func (ae *AccessEvents) ContractCreateInitGas(addr common.Address, availableGas uint64) (uint64, uint64) {
149149
var gas uint64
150-
consumed, wanted1 := ae.touchAddressAndChargeGas(addr, zeroTreeIndex, utils.BasicDataLeafKey, true, availableGas)
150+
consumed, expected1 := ae.touchAddressAndChargeGas(addr, zeroTreeIndex, utils.BasicDataLeafKey, true, availableGas)
151151
gas += consumed
152-
consumed, wanted2 := ae.touchAddressAndChargeGas(addr, zeroTreeIndex, utils.CodeHashLeafKey, true, availableGas-consumed)
152+
consumed, expected2 := ae.touchAddressAndChargeGas(addr, zeroTreeIndex, utils.CodeHashLeafKey, true, availableGas-consumed)
153153
gas += consumed
154-
return gas, wanted1 + wanted2
154+
return gas, expected1 + expected2
155155
}
156156

157157
// AddTxOrigin adds the member fields of the sender account to the access event list,
@@ -171,15 +171,15 @@ func (ae *AccessEvents) AddTxDestination(addr common.Address, sendsValue, doesnt
171171
// SlotGas returns the amount of gas to be charged for a cold storage access.
172172
func (ae *AccessEvents) SlotGas(addr common.Address, slot common.Hash, isWrite bool, availableGas uint64, chargeWarmCosts bool) uint64 {
173173
treeIndex, subIndex := utils.StorageIndex(slot.Bytes())
174-
_, wanted := ae.touchAddressAndChargeGas(addr, *treeIndex, subIndex, isWrite, availableGas)
175-
if wanted == 0 && chargeWarmCosts {
176-
wanted = params.WarmStorageReadCostEIP2929
174+
_, expected := ae.touchAddressAndChargeGas(addr, *treeIndex, subIndex, isWrite, availableGas)
175+
if expected == 0 && chargeWarmCosts {
176+
expected = params.WarmStorageReadCostEIP2929
177177
}
178-
return wanted
178+
return expected
179179
}
180180

181-
// touchAddressAndChargeGas adds any missing access event to the access event list, and returns the cold
182-
// access cost to be charged, if need be.
181+
// touchAddressAndChargeGas adds any missing access event to the access event list, and returns the
182+
// consumed and required gas.
183183
func (ae *AccessEvents) touchAddressAndChargeGas(addr common.Address, treeIndex uint256.Int, subIndex byte, isWrite bool, availableGas uint64) (uint64, uint64) {
184184
branchKey := newBranchAccessKey(addr, treeIndex)
185185
chunkKey := newChunkAccessKey(branchKey, subIndex)
@@ -224,7 +224,7 @@ func (ae *AccessEvents) touchAddressAndChargeGas(addr common.Address, treeIndex
224224
}
225225

226226
if availableGas < gas {
227-
// consumed != wanted
227+
// consumed != expected
228228
return availableGas, gas
229229
}
230230

@@ -241,7 +241,7 @@ func (ae *AccessEvents) touchAddressAndChargeGas(addr common.Address, treeIndex
241241
ae.chunks[chunkKey] |= AccessWitnessWriteFlag
242242
}
243243

244-
// consumed == wanted
244+
// consumed == expected
245245
return gas, gas
246246
}
247247

@@ -293,10 +293,10 @@ func (ae *AccessEvents) CodeChunksRangeGas(contractAddr common.Address, startPC,
293293
for chunkNumber := startPC / 31; chunkNumber <= endPC/31; chunkNumber++ {
294294
treeIndex := *uint256.NewInt((chunkNumber + 128) / 256)
295295
subIndex := byte((chunkNumber + 128) % 256)
296-
consumed, wanted := ae.touchAddressAndChargeGas(contractAddr, treeIndex, subIndex, isWrite, availableGas)
296+
consumed, expected := ae.touchAddressAndChargeGas(contractAddr, treeIndex, subIndex, isWrite, availableGas)
297297
// did we OOG ?
298-
if wanted > consumed {
299-
return statelessGasCharged + consumed, statelessGasCharged + wanted
298+
if expected > consumed {
299+
return statelessGasCharged + consumed, statelessGasCharged + expected
300300
}
301301
var overflow bool
302302
statelessGasCharged, overflow = math.SafeAdd(statelessGasCharged, consumed)
@@ -313,14 +313,14 @@ func (ae *AccessEvents) CodeChunksRangeGas(contractAddr common.Address, startPC,
313313
// Note that an access in write mode implies an access in read mode, whereas an
314314
// access in read mode does not imply an access in write mode.
315315
func (ae *AccessEvents) BasicDataGas(addr common.Address, isWrite bool, availableGas uint64, chargeWarmCosts bool) uint64 {
316-
_, wanted := ae.touchAddressAndChargeGas(addr, zeroTreeIndex, utils.BasicDataLeafKey, isWrite, availableGas)
317-
if wanted == 0 && chargeWarmCosts {
316+
_, expected := ae.touchAddressAndChargeGas(addr, zeroTreeIndex, utils.BasicDataLeafKey, isWrite, availableGas)
317+
if expected == 0 && chargeWarmCosts {
318318
if availableGas < params.WarmStorageReadCostEIP2929 {
319319
return availableGas
320320
}
321-
wanted = params.WarmStorageReadCostEIP2929
321+
expected = params.WarmStorageReadCostEIP2929
322322
}
323-
return wanted
323+
return expected
324324
}
325325

326326
// CodeHashGas adds the account's code hash to the accessed data, and returns the
@@ -329,12 +329,12 @@ func (ae *AccessEvents) BasicDataGas(addr common.Address, isWrite bool, availabl
329329
// Note that an access in write mode implies an access in read mode, whereas an access in
330330
// read mode does not imply an access in write mode.
331331
func (ae *AccessEvents) CodeHashGas(addr common.Address, isWrite bool, availableGas uint64, chargeWarmCosts bool) uint64 {
332-
_, wanted := ae.touchAddressAndChargeGas(addr, zeroTreeIndex, utils.CodeHashLeafKey, isWrite, availableGas)
333-
if wanted == 0 && chargeWarmCosts {
332+
_, expected := ae.touchAddressAndChargeGas(addr, zeroTreeIndex, utils.CodeHashLeafKey, isWrite, availableGas)
333+
if expected == 0 && chargeWarmCosts {
334334
if availableGas < params.WarmStorageReadCostEIP2929 {
335335
return availableGas
336336
}
337-
wanted = params.WarmStorageReadCostEIP2929
337+
expected = params.WarmStorageReadCostEIP2929
338338
}
339-
return wanted
339+
return expected
340340
}

0 commit comments

Comments
 (0)