Skip to content

Commit 238f254

Browse files
author
ZhangTao1596
committed
core: fix nspcc-dev#2845 Roman's feedback
1 parent 18b7900 commit 238f254

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

Diff for: pkg/core/blockchain.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -1418,7 +1418,7 @@ func (bc *Blockchain) storeBlock(block *block.Block, txpool *mempool.Pool) error
14181418
cache = bc.dao.GetPrivate()
14191419
aerCache = bc.dao.GetPrivate()
14201420
appExecResults = make([]*state.AppExecResult, 0, 2+len(block.Transactions))
1421-
txesConsumed = make(map[util.Uint256]int64, len(block.Transactions))
1421+
txesConsumed = make([]int64, len(block.Transactions))
14221422
aerchan = make(chan *state.AppExecResult, len(block.Transactions)/8) // Tested 8 and 4 with no practical difference, but feel free to test more and tune.
14231423
aerdone = make(chan error)
14241424
)
@@ -1511,7 +1511,7 @@ func (bc *Blockchain) storeBlock(block *block.Block, txpool *mempool.Pool) error
15111511
appExecResults = append(appExecResults, aer)
15121512
aerchan <- aer
15131513

1514-
for _, tx := range block.Transactions {
1514+
for i, tx := range block.Transactions {
15151515
systemInterop := bc.newInteropContext(trigger.Application, cache, block, tx)
15161516
systemInterop.ReuseVM(v)
15171517
v.LoadScriptWithFlags(tx.Script, callflag.All)
@@ -1534,7 +1534,7 @@ func (bc *Blockchain) storeBlock(block *block.Block, txpool *mempool.Pool) error
15341534
zap.Error(err))
15351535
faultException = err.Error()
15361536
}
1537-
txesConsumed[tx.Hash()] = v.GasConsumed()
1537+
txesConsumed[i] = v.GasConsumed()
15381538
aer := &state.AppExecResult{
15391539
Container: tx.Hash(),
15401540
Execution: state.Execution{
@@ -1685,7 +1685,7 @@ func (bc *Blockchain) IsExtensibleAllowed(u util.Uint160) bool {
16851685
return n < len(us)
16861686
}
16871687

1688-
func (bc *Blockchain) runPersist(script []byte, block *block.Block, cache *dao.Simple, trig trigger.Type, v *vm.VM, txesConsumed map[util.Uint256]int64) (*state.AppExecResult, *vm.VM, error) {
1688+
func (bc *Blockchain) runPersist(script []byte, block *block.Block, cache *dao.Simple, trig trigger.Type, v *vm.VM, txesConsumed []int64) (*state.AppExecResult, *vm.VM, error) {
16891689
systemInterop := bc.newInteropContext(trig, cache, block, nil)
16901690
if v == nil {
16911691
v = systemInterop.SpawnVM()

Diff for: pkg/core/interop/context.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ type Context struct {
6060
VM *vm.VM
6161
Functions []Function
6262
Invocations map[util.Uint160]int
63-
TxesConsumed map[util.Uint256]int64
63+
TxesConsumed []int64
6464

6565
cancelFuncs []context.CancelFunc
6666
getContract func(*dao.Simple, util.Uint160) (*state.Contract, error)

Diff for: pkg/core/native/native_gas.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,10 @@ func (g *GAS) OnPersist(ic *interop.Context) error {
129129

130130
// PostPersist implements the Contract interface.
131131
func (g *GAS) PostPersist(ic *interop.Context) error {
132-
for _, tx := range ic.Block.Transactions {
132+
for i, tx := range ic.Block.Transactions {
133133
attrs := tx.GetAttributes(transaction.RefundableSystemFeeT)
134134
if len(attrs) != 0 {
135-
consumed := ic.TxesConsumed[tx.Hash()]
135+
consumed := ic.TxesConsumed[i]
136136
if consumed < tx.SystemFee {
137137
g.mint(ic, tx.Sender(), big.NewInt(tx.SystemFee-consumed), false)
138138
}

0 commit comments

Comments
 (0)