Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dynamic lower limit of scheduled execution #6293

Draft
wants to merge 4 commits into
base: feat/chain-go-sdk
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 6 additions & 1 deletion process/block/preprocess/scheduledTxsExecution.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,13 @@ func (ste *scheduledTxsExecution) ExecuteAll(haveTime func() time.Duration) erro

mapAllIntermediateTxsBeforeScheduledExecution := ste.txCoordinator.GetAllIntermediateTxs()

for _, txData := range ste.scheduledTxs {
totalTxs := len(ste.scheduledTxs)

for i, txData := range ste.scheduledTxs {
if haveTime() <= 0 {
percentageProcessed := float64(i) / float64(totalTxs)
CurrentMaxGasLimitPercentage = CurrentMaxGasLimitPercentage * percentageProcessed
log.Debug("scheduledTxsExecution.ExecuteAll: time is out", "percentage processed", percentageProcessed, "CurrentMaxGasLimitPercentage", CurrentMaxGasLimitPercentage)
return process.ErrTimeIsOut
}

Expand Down
10 changes: 6 additions & 4 deletions process/block/preprocess/transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import (
vmcommon "github.com/multiversx/mx-chain-vm-common-go"
)

var CurrentMaxGasLimitPercentage = float64(1.00)
var ConsecutiveProcessedBlocksWithTransactions = 0
var _ process.DataMarshalizer = (*transactions)(nil)
var _ process.PreProcessor = (*transactions)(nil)

Expand Down Expand Up @@ -1059,10 +1061,10 @@ func (txs *transactions) getRemainingGasPerBlock() uint64 {

func (txs *transactions) getRemainingGasPerBlockAsScheduled() uint64 {
gasProvided := txs.gasHandler.TotalGasProvidedAsScheduled()
maxGasPerBlock := txs.economicsFee.MaxGasLimitPerBlock(txs.shardCoordinator.SelfId())
maxGasPerBlockWithLimit := uint64(float64(txs.economicsFee.MaxGasLimitPerBlock(txs.shardCoordinator.SelfId())) * CurrentMaxGasLimitPercentage)
gasBandwidth := uint64(0)
if gasProvided < maxGasPerBlock {
gasBandwidth = maxGasPerBlock - gasProvided
if gasProvided < maxGasPerBlockWithLimit {
gasBandwidth = maxGasPerBlockWithLimit - gasProvided
}
return gasBandwidth
}
Expand All @@ -1072,7 +1074,7 @@ func (txs *transactions) getRemainingGasPerBlockAsScheduled() uint64 {
// TODO: check if possible for transaction pre processor to receive a blockChainHook and use it to get the randomness instead
func (txs *transactions) CreateAndProcessMiniBlocks(haveTime func() bool, randomness []byte) (block.MiniBlockSlice, error) {
startTime := time.Now()

log.Debug("createScheduledMiniBlocks", "CurrentMaxGasLimitPercentage", CurrentMaxGasLimitPercentage)
gasBandwidth := txs.getRemainingGasPerBlock() * selectionGasBandwidthIncreasePercent / 100
gasBandwidthForScheduled := uint64(0)
if txs.enableEpochsHandler.IsFlagEnabled(common.ScheduledMiniBlocksFlag) {
Expand Down
21 changes: 20 additions & 1 deletion process/block/preprocess/transactionsV2.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,14 @@ func (txs *transactions) createAndProcessMiniBlocksFromMeV2(
}()

remainingTxs := make([]*txcache.WrappedTransaction, 0)
totalTxs := len(sortedTxs)
for index := range sortedTxs {
if !haveTime() {
log.Debug("time is out in createAndProcessMiniBlocksFromMeV2")
percentageProcessed := float64(index) / float64(totalTxs)
CurrentMaxGasLimitPercentage = CurrentMaxGasLimitPercentage * percentageProcessed
log.Debug("createAndProcessMiniBlocksFromMeV2: time is out", "percentage processed", percentageProcessed, "CurrentMaxGasLimitPercentage", CurrentMaxGasLimitPercentage)
ConsecutiveProcessedBlocksWithTransactions = 0
remainingTxs = append(remainingTxs, sortedTxs[index:]...)
break
}
Expand Down Expand Up @@ -88,6 +93,16 @@ func (txs *transactions) createAndProcessMiniBlocksFromMeV2(
mbInfo)
}

ConsecutiveProcessedBlocksWithTransactions++
if ConsecutiveProcessedBlocksWithTransactions >= 5 {
CurrentMaxGasLimitPercentage = CurrentMaxGasLimitPercentage * 1.1
if CurrentMaxGasLimitPercentage > 1.0 {
CurrentMaxGasLimitPercentage = 1.0
}
log.Debug("createAndProcessMiniBlocksFromMeV2: increasing CurrentMaxGasLimitPercentage", "CurrentMaxGasLimitPercentage", CurrentMaxGasLimitPercentage)
ConsecutiveProcessedBlocksWithTransactions = 0
}

miniBlocks := txs.getMiniBlockSliceFromMapV2(mbInfo.mapMiniBlocks)
txs.displayProcessingResults(miniBlocks, len(sortedTxs), mbInfo)

Expand Down Expand Up @@ -281,7 +296,11 @@ func (txs *transactions) createScheduledMiniBlocks(
log.Debug("time is out in createScheduledMiniBlocks")
break
}

maxGasLimitForScheduled := uint64(CurrentMaxGasLimitPercentage * float64(txs.economicsFee.MaxGasLimitPerBlock(txs.shardCoordinator.SelfId())))
if mbInfo.gasInfo.totalGasConsumedInSelfShard >= maxGasLimitForScheduled {
log.Debug("stopped processing transactions because the gas limit is reached", "CurrentMaxGasLimitPercentage", CurrentMaxGasLimitPercentage, "maxGasLimitForScheduled", maxGasLimitForScheduled)
break
}
tx, miniBlock, shouldContinue := txs.scheduledTXContinueFunc(
isShardStuck,
sortedTxs[index],
Expand Down
Loading