Skip to content

Commit

Permalink
- fixed memory allocation on gasComputation implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
iulianpascalau committed Oct 1, 2022
1 parent 9f40da8 commit b46027b
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions process/block/preprocess/gasComputation.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
"github.com/ElrondNetwork/elrond-go/process"
)

const initialAllocation = 1000

var _ process.GasHandler = (*gasComputation)(nil)

type gasComputation struct {
Expand Down Expand Up @@ -91,18 +93,19 @@ func (gc *gasComputation) Init() {
}

// Reset method resets tx hashes with gas provided, refunded and penalized since last reset
// TODO remove this call from basePreProcess.handleProcessTransactionInit
func (gc *gasComputation) Reset(key []byte) {
gc.mutGasProvided.Lock()
gc.txHashesWithGasProvidedSinceLastReset[string(key)] = make([][]byte, 0)
gc.txHashesWithGasProvidedAsScheduledSinceLastReset[string(key)] = make([][]byte, 0)
gc.txHashesWithGasProvidedSinceLastReset[string(key)] = make([][]byte, 0, initialAllocation)
gc.txHashesWithGasProvidedAsScheduledSinceLastReset[string(key)] = make([][]byte, 0, initialAllocation)
gc.mutGasProvided.Unlock()

gc.mutGasRefunded.Lock()
gc.txHashesWithGasRefundedSinceLastReset[string(key)] = make([][]byte, 0)
gc.txHashesWithGasRefundedSinceLastReset[string(key)] = make([][]byte, 0, initialAllocation)
gc.mutGasRefunded.Unlock()

gc.mutGasPenalized.Lock()
gc.txHashesWithGasPenalizedSinceLastReset[string(key)] = make([][]byte, 0)
gc.txHashesWithGasPenalizedSinceLastReset[string(key)] = make([][]byte, 0, initialAllocation)
gc.mutGasPenalized.Unlock()
}

Expand Down

0 comments on commit b46027b

Please sign in to comment.