Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
60d1e05
adapted the gas tracker implementation to follow the new limits after…
sstanculeanu Sep 26, 2025
b7f753d
updated blockCapacityOverestimationFactor value
sstanculeanu Sep 26, 2025
81136a5
fixed tests
sstanculeanu Sep 26, 2025
b371b84
Merge branch 'unique-chunks-processor' of https://github.com/multiver…
sstanculeanu Sep 29, 2025
89633c6
Merge branch 'rc/supernova' into adapt-old-gas-tracker
sstanculeanu Oct 14, 2025
3caa6ec
Merge branch 'rc/supernova' into adapt-old-gas-tracker
sstanculeanu Oct 14, 2025
d19cd77
Merge branch 'feat/supernova-async-exec' of https://github.com/multiv…
sstanculeanu Oct 15, 2025
8947bbf
fixes after merge
sstanculeanu Oct 15, 2025
6f56759
Merge branch 'feat/supernova-async-exec' into adapt-old-gas-tracker
sstanculeanu Oct 15, 2025
0aec862
Merge branch 'feat/supernova-async-exec' into adapt-old-gas-tracker
sstanculeanu Oct 15, 2025
57daf58
fixed duplicated error after merge
sstanculeanu Oct 15, 2025
1aced0f
removed todo
sstanculeanu Oct 15, 2025
fcb5021
Merge branch 'feat/supernova-async-exec' into adapt-old-gas-tracker
sstanculeanu Oct 15, 2025
c901848
Merge branch 'feat/supernova-async-exec' into adapt-old-gas-tracker
sstanculeanu Oct 16, 2025
ec105ec
Merge branch 'feat/supernova-async-exec' into adapt-old-gas-tracker
sstanculeanu Oct 20, 2025
41ca089
Merge branch 'feat/supernova-async-exec' into adapt-old-gas-tracker
sstanculeanu Oct 20, 2025
ff14f6a
Merge branch 'feat/supernova-async-exec' into adapt-old-gas-tracker
sstanculeanu Oct 24, 2025
43fe93c
Merge branch 'feat/supernova-async-exec' into adapt-old-gas-tracker
sstanculeanu Oct 28, 2025
e6e5072
fixes after review
sstanculeanu Oct 28, 2025
9715c7d
fix panic
sstanculeanu Oct 28, 2025
262bd96
Merge branch 'feat/supernova-async-exec' into adapt-old-gas-tracker
sstanculeanu Oct 28, 2025
c714a22
Merge branch 'feat/supernova-async-exec' into adapt-old-gas-tracker
sstanculeanu Oct 29, 2025
21903f1
Merge branch 'feat/supernova-async-exec' into adapt-old-gas-tracker
sstanculeanu Oct 29, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions genesis/process/disabled/disabled_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ func TestFeeHandler(t *testing.T) {
require.Equal(t, uint64(math.MaxUint64), handler.MaxGasLimitPerBlockForSafeCrossShard())
require.Equal(t, uint64(math.MaxUint64), handler.MaxGasLimitPerMiniBlockForSafeCrossShard())
require.Equal(t, uint64(math.MaxUint64), handler.MaxGasLimitPerTx())
require.Equal(t, uint64(math.MaxUint64), handler.BlockCapacityOverestimationFactor())
require.Equal(t, uint64(math.MaxUint64), handler.MaxGasLimitPerTxInEpoch(0))
require.Equal(t, uint64(math.MaxUint64), handler.MaxGasLimitPerBlockForSafeCrossShardInEpoch(0))
require.Equal(t, uint64(math.MaxUint64), handler.MaxGasLimitPerBlockInEpoch(0, 0))
require.Equal(t, uint64(0), handler.ComputeGasLimit(nil))
require.Equal(t, big.NewInt(0), handler.ComputeMoveBalanceFee(nil))
require.Equal(t, big.NewInt(0), handler.ComputeFeeForProcessing(nil, 0))
Expand Down
20 changes: 20 additions & 0 deletions genesis/process/disabled/feeHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,21 @@ func (fh *FeeHandler) MaxGasPriceSetGuardian() uint64 {
return math.MaxUint64
}

// BlockCapacityOverestimationFactor returns max uint64
func (fh *FeeHandler) BlockCapacityOverestimationFactor() uint64 {
return math.MaxUint64
}

// MaxGasLimitPerBlock returns max uint64
func (fh *FeeHandler) MaxGasLimitPerBlock(uint32) uint64 {
return math.MaxUint64
}

// MaxGasLimitPerBlockInEpoch returns max uint64
func (fh *FeeHandler) MaxGasLimitPerBlockInEpoch(_ uint32, _ uint32) uint64 {
return math.MaxUint64
}

// MaxGasLimitPerMiniBlock returns max uint64
func (fh *FeeHandler) MaxGasLimitPerMiniBlock(uint32) uint64 {
return math.MaxUint64
Expand All @@ -72,6 +82,11 @@ func (fh *FeeHandler) MaxGasLimitPerBlockForSafeCrossShard() uint64 {
return math.MaxUint64
}

// MaxGasLimitPerBlockForSafeCrossShardInEpoch returns max uint64
func (fh *FeeHandler) MaxGasLimitPerBlockForSafeCrossShardInEpoch(_ uint32) uint64 {
return math.MaxUint64
}

// MaxGasLimitPerMiniBlockForSafeCrossShard returns max uint64
func (fh *FeeHandler) MaxGasLimitPerMiniBlockForSafeCrossShard() uint64 {
return math.MaxUint64
Expand All @@ -87,6 +102,11 @@ func (fh *FeeHandler) MaxGasLimitPerTx() uint64 {
return math.MaxUint64
}

// MaxGasLimitPerTxInEpoch returns max uint64
func (fh *FeeHandler) MaxGasLimitPerTxInEpoch(_ uint32) uint64 {
return math.MaxUint64
}

// ComputeGasLimit returns 0
func (fh *FeeHandler) ComputeGasLimit(_ data.TransactionWithFeeHandler) uint64 {
return 0
Expand Down
6 changes: 3 additions & 3 deletions genesis/process/metaGenesisBlockCreator.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ import (
"github.com/multiversx/mx-chain-core-go/data/block"
"github.com/multiversx/mx-chain-core-go/data/transaction"
"github.com/multiversx/mx-chain-core-go/marshal"
vmcommon "github.com/multiversx/mx-chain-vm-common-go"
vmcommonBuiltInFunctions "github.com/multiversx/mx-chain-vm-common-go/builtInFunctions"
"github.com/multiversx/mx-chain-vm-common-go/parsers"

processBlock "github.com/multiversx/mx-chain-go/process/block"

Expand Down Expand Up @@ -51,6 +48,9 @@ import (
"github.com/multiversx/mx-chain-go/update"
hardForkProcess "github.com/multiversx/mx-chain-go/update/process"
"github.com/multiversx/mx-chain-go/vm"
vmcommon "github.com/multiversx/mx-chain-vm-common-go"
vmcommonBuiltInFunctions "github.com/multiversx/mx-chain-vm-common-go/builtInFunctions"
"github.com/multiversx/mx-chain-vm-common-go/parsers"
)

// CreateMetaGenesisBlock will create a metachain genesis block
Expand Down
5 changes: 2 additions & 3 deletions genesis/process/shardGenesisBlockCreator.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ import (
"github.com/multiversx/mx-chain-core-go/core/check"
"github.com/multiversx/mx-chain-core-go/data"
dataBlock "github.com/multiversx/mx-chain-core-go/data/block"
logger "github.com/multiversx/mx-chain-logger-go"
"github.com/multiversx/mx-chain-vm-common-go/parsers"

"github.com/multiversx/mx-chain-go/common"
disabledCommon "github.com/multiversx/mx-chain-go/common/disabled"
"github.com/multiversx/mx-chain-go/common/enablers"
Expand Down Expand Up @@ -45,6 +42,8 @@ import (
"github.com/multiversx/mx-chain-go/txcache"
"github.com/multiversx/mx-chain-go/update"
hardForkProcess "github.com/multiversx/mx-chain-go/update/process"
logger "github.com/multiversx/mx-chain-logger-go"
"github.com/multiversx/mx-chain-vm-common-go/parsers"
)

const unreachableEpoch = ^uint32(0)
Expand Down
58 changes: 52 additions & 6 deletions process/block/preprocess/gasTracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,19 @@ package preprocess
import (
"github.com/multiversx/mx-chain-core-go/core"
"github.com/multiversx/mx-chain-core-go/data"
"github.com/multiversx/mx-chain-go/common"
"github.com/multiversx/mx-chain-go/process"
"github.com/multiversx/mx-chain-go/sharding"
)

const noOverestimationFactor = uint64(100)

type gasTracker struct {
shardCoordinator sharding.Coordinator
economicsFee process.FeeHandler
gasHandler process.GasHandler
shardCoordinator sharding.Coordinator
economicsFee process.FeeHandler
gasHandler process.GasHandler
enableEpochsHandler common.EnableEpochsHandler
enableRoundsHandler common.EnableRoundsHandler
}

func (gt *gasTracker) computeGasProvided(
Expand All @@ -29,22 +34,24 @@ func (gt *gasTracker) computeGasProvided(
return 0, err
}

epoch, overEstimationFactor := gt.getEpochAndOverestimationFactorForGasLimits()

gasProvidedByTxInSelfShard := uint64(0)
if gt.shardCoordinator.SelfId() == senderShardId {
gasProvidedByTxInSelfShard = gasProvidedByTxInSenderShard

if gasProvidedByTxInReceiverShard > gt.economicsFee.MaxGasLimitPerTx() {
if gasProvidedByTxInReceiverShard > gt.getMaxGasLimitPerTx(epoch) {
return 0, process.ErrMaxGasLimitPerOneTxInReceiverShardIsReached
}

if gasInfo.gasConsumedByMiniBlockInReceiverShard+gasProvidedByTxInReceiverShard > gt.economicsFee.MaxGasLimitPerBlockForSafeCrossShard() {
if gasInfo.gasConsumedByMiniBlockInReceiverShard+gasProvidedByTxInReceiverShard > gt.getMaxGasLimitPerBlockForSafeCrossShard(epoch, overEstimationFactor) {
return 0, process.ErrMaxGasLimitPerMiniBlockInReceiverShardIsReached
}
} else {
gasProvidedByTxInSelfShard = gasProvidedByTxInReceiverShard
}

if gasInfo.totalGasConsumedInSelfShard+gasProvidedByTxInSelfShard > gt.economicsFee.MaxGasLimitPerBlock(gt.shardCoordinator.SelfId()) {
if gasInfo.totalGasConsumedInSelfShard+gasProvidedByTxInSelfShard > gt.getMaxGasLimitPerBlock(epoch, overEstimationFactor) {
return 0, process.ErrMaxGasLimitPerBlockInSelfShardIsReached
}

Expand All @@ -55,6 +62,45 @@ func (gt *gasTracker) computeGasProvided(
return gasProvidedByTxInSelfShard, nil
}

func (gt *gasTracker) getEpochAndOverestimationFactorForGasLimits() (epoch uint32, overestimationFactor uint64) {
epoch = gt.enableEpochsHandler.GetCurrentEpoch()
overestimationFactor = noOverestimationFactor

// TODO: optimize this to be called once per epoch, not once per tx
isSupernovaEpochEnabled := gt.enableEpochsHandler.IsFlagEnabled(common.SupernovaFlag)
if !isSupernovaEpochEnabled {
return
}

isSupernovaRoundEnabled := gt.enableRoundsHandler.IsFlagEnabled(common.SupernovaRoundFlag)
Comment thread
raduchis marked this conversation as resolved.
if !isSupernovaRoundEnabled {
// if Supernova epoch is active, but round not yet,
// use the limits from previous epoch with no overestimation factor
if epoch > 0 {
epoch = epoch - 1
}

return
}

// new limits and overestimation should be enabled once the Supernova round is active
overestimationFactor = gt.economicsFee.BlockCapacityOverestimationFactor()

return
}

func (gt *gasTracker) getMaxGasLimitPerTx(epoch uint32) uint64 {
return gt.economicsFee.MaxGasLimitPerTxInEpoch(epoch)
}

func (gt *gasTracker) getMaxGasLimitPerBlockForSafeCrossShard(epoch uint32, overEstimationFactor uint64) uint64 {
return gt.economicsFee.MaxGasLimitPerBlockForSafeCrossShardInEpoch(epoch) * overEstimationFactor / 100
}

func (gt *gasTracker) getMaxGasLimitPerBlock(epoch uint32, overEstimationFactor uint64) uint64 {
return gt.economicsFee.MaxGasLimitPerBlockInEpoch(gt.shardCoordinator.SelfId(), epoch) * overEstimationFactor / 100
}

func (gt *gasTracker) computeGasProvidedByTx(
senderShardId uint32,
receiverShardId uint32,
Expand Down
Loading
Loading