Skip to content

Commit

Permalink
core: fix nspcc-dev#2845 Roman's feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhangTao1596 committed Feb 13, 2023
1 parent 18b7900 commit 238f254
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 deletions pkg/core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
Expand Down Expand Up @@ -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)
Expand 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{
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion pkg/core/interop/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions pkg/core/native/native_gas.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 238f254

Please sign in to comment.