From 238f254b19364d9d6221fc4e9037afdba7e3ed09 Mon Sep 17 00:00:00 2001 From: ZhangTao1596 Date: Mon, 13 Feb 2023 14:30:52 +0800 Subject: [PATCH] core: fix #2845 Roman's feedback --- pkg/core/blockchain.go | 8 ++++---- pkg/core/interop/context.go | 2 +- pkg/core/native/native_gas.go | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/pkg/core/blockchain.go b/pkg/core/blockchain.go index bdaa3b165d..9fbf6781e0 100644 --- a/pkg/core/blockchain.go +++ b/pkg/core/blockchain.go @@ -1418,7 +1418,7 @@ func (bc *Blockchain) storeBlock(block *block.Block, txpool *mempool.Pool) error cache = bc.dao.GetPrivate() aerCache = bc.dao.GetPrivate() appExecResults = make([]*state.AppExecResult, 0, 2+len(block.Transactions)) - txesConsumed = make(map[util.Uint256]int64, len(block.Transactions)) + txesConsumed = make([]int64, len(block.Transactions)) 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. aerdone = make(chan error) ) @@ -1511,7 +1511,7 @@ func (bc *Blockchain) storeBlock(block *block.Block, txpool *mempool.Pool) error appExecResults = append(appExecResults, aer) aerchan <- aer - for _, tx := range block.Transactions { + for i, tx := range block.Transactions { systemInterop := bc.newInteropContext(trigger.Application, cache, block, tx) systemInterop.ReuseVM(v) v.LoadScriptWithFlags(tx.Script, callflag.All) @@ -1534,7 +1534,7 @@ func (bc *Blockchain) storeBlock(block *block.Block, txpool *mempool.Pool) error zap.Error(err)) faultException = err.Error() } - txesConsumed[tx.Hash()] = v.GasConsumed() + txesConsumed[i] = v.GasConsumed() aer := &state.AppExecResult{ Container: tx.Hash(), Execution: state.Execution{ @@ -1685,7 +1685,7 @@ func (bc *Blockchain) IsExtensibleAllowed(u util.Uint160) bool { return n < len(us) } -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) { +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) { systemInterop := bc.newInteropContext(trig, cache, block, nil) if v == nil { v = systemInterop.SpawnVM() diff --git a/pkg/core/interop/context.go b/pkg/core/interop/context.go index c244950f2e..1a595007ce 100644 --- a/pkg/core/interop/context.go +++ b/pkg/core/interop/context.go @@ -60,7 +60,7 @@ type Context struct { VM *vm.VM Functions []Function Invocations map[util.Uint160]int - TxesConsumed map[util.Uint256]int64 + TxesConsumed []int64 cancelFuncs []context.CancelFunc getContract func(*dao.Simple, util.Uint160) (*state.Contract, error) diff --git a/pkg/core/native/native_gas.go b/pkg/core/native/native_gas.go index 8357269479..7f5a7b1974 100644 --- a/pkg/core/native/native_gas.go +++ b/pkg/core/native/native_gas.go @@ -129,10 +129,10 @@ func (g *GAS) OnPersist(ic *interop.Context) error { // PostPersist implements the Contract interface. func (g *GAS) PostPersist(ic *interop.Context) error { - for _, tx := range ic.Block.Transactions { + for i, tx := range ic.Block.Transactions { attrs := tx.GetAttributes(transaction.RefundableSystemFeeT) if len(attrs) != 0 { - consumed := ic.TxesConsumed[tx.Hash()] + consumed := ic.TxesConsumed[i] if consumed < tx.SystemFee { g.mint(ic, tx.Sender(), big.NewInt(tx.SystemFee-consumed), false) }