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

Don't notify cache about nonces; pass the account nonce provider, instead #6603

Merged
merged 47 commits into from
Nov 27, 2024

Conversation

andreibancioiu
Copy link
Collaborator

@andreibancioiu andreibancioiu commented Nov 13, 2024

Reasoning behind the pull request

  • This is an improvement upon Mempool: improve selection algorithm #6581.
  • In certain exotic cases, concurrent notifications about account nonces might have lead the mempool to hold stale account nonces (very minor issue, but still an issue).
  • The flow of forgetting all account nonces after reverting a block is suboptimal (and somehow over-engineered).
  • Transaction de-duplication (based on nonces) wasn't entirely correct.
  • Accounts with transactions recently proposed in scheduled blocks had some issues with following transactions (selection was delayed due to missing nonce notifications).

Proposed changes

Testing procedure

  • Standard testing
  • Heavy load, to trigger evictions from the mempool

Pre-requisites

Based on the Contributing Guidelines the PR author and the reviewers must check the following requirements are met:

  • was the PR targeted to the correct branch?
  • if this is a larger feature that probably needs more than one PR, is there a feat branch created?
  • if this is a feat branch merging, do all satellite projects have a proper tag inside go.mod?

@andreibancioiu andreibancioiu changed the title Don't notify cache about nonces; provide the account nonce provider, instead Don't notify cache about nonces; pass the account nonce provider, instead Nov 13, 2024
@andreibancioiu andreibancioiu self-assigned this Nov 13, 2024
sasurobert
sasurobert previously approved these changes Nov 14, 2024
raduchis
raduchis previously approved these changes Nov 14, 2024
@multiversx multiversx deleted a comment from github-actions bot Nov 20, 2024
@multiversx multiversx deleted a comment from github-actions bot Nov 20, 2024
@@ -600,6 +600,7 @@ func createProcessorsForShardGenesisBlock(arg ArgsGenesisBlockCreator, enableEpo
disabledScheduledTxsExecutionHandler,
disabledProcessedMiniBlocksTracker,
arg.TxExecutionOrderHandler,
disabledGuardian.NewDisabledGuardedAccountHandler(),
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Genesis components, we can pass this object.

IsInterfaceNil() bool
}

// TxCache defines the functionality for the transactions cache
type TxCache interface {
SelectTransactions(gasRequested uint64, maxNum int) ([]*txcache.WrappedTransaction, uint64)
NotifyAccountNonce(accountKey []byte, nonce uint64)
SelectTransactions(accountStateProvider txcache.AccountStateProvider, gasRequested uint64, maxNum int, selectionLoopMaximumDuration time.Duration) ([]*txcache.WrappedTransaction, uint64)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now, we pass the (wrapped) accounts adapter; the mempool will be much more informed during selection.

@@ -136,15 +130,6 @@ func checkMiniBlocksBuilderArgs(args miniBlocksBuilderArgs) error {
return nil
}

func (mbb *miniBlocksBuilder) updateAccountShardsInfo(tx *transaction.Transaction, wtx *txcache.WrappedTransaction) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was used for mempool notifications.

@@ -446,6 +448,26 @@ func TestTxsPreprocessor_NewTransactionPreprocessorNilProcessedMiniBlocksTracker
assert.Equal(t, process.ErrNilProcessedMiniBlocksTracker, err)
}

func TestTxsPreprocessor_NewTransactionPreprocessorNilTxExecutionOrderHandler(t *testing.T) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was missing before.

@@ -143,3 +144,6 @@ const TxCacheSelectionGasRequested = 10_000_000_000

// TxCacheSelectionMaxNumTxs defines the maximum number of transactions that should be selected from the cache.
const TxCacheSelectionMaxNumTxs = 50000

// TxCacheSelectionLoopMaximumDuration defines the maximum duration for the loop that selects transactions from the cache.
const TxCacheSelectionLoopMaximumDuration = 250 * time.Millisecond
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question for review: all right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds good for 6 second round time, can remain like this. should be much lower for sub second round times

log.Trace("accountsDB.saveAccountToTrie",
"address", hex.EncodeToString(accountHandler.AddressBytes()),
)
log.Trace("accountsDB.saveAccountToTrie", "address", accountHandler.AddressBytes())
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still sub-optimal (slice is copied by value when returned by the function), but a bit better.

@andreibancioiu andreibancioiu marked this pull request as ready for review November 21, 2024 13:55
go.mod Outdated
@@ -20,7 +20,7 @@ require (
github.com/multiversx/mx-chain-es-indexer-go v1.7.10
github.com/multiversx/mx-chain-logger-go v1.0.15
github.com/multiversx/mx-chain-scenario-go v1.4.4
github.com/multiversx/mx-chain-storage-go v1.0.17
github.com/multiversx/mx-chain-storage-go v1.0.18-0.20241124203643-93c958ad66cf
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do not forget actual release

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will be set after all merges into the feat branch, right before preparing the release.

process/block/preprocess/transactions.go Outdated Show resolved Hide resolved
process/block/preprocess/transactions.go Outdated Show resolved Hide resolved
process/block/preprocess/basePreProcess.go Show resolved Hide resolved
@@ -143,3 +144,6 @@ const TxCacheSelectionGasRequested = 10_000_000_000

// TxCacheSelectionMaxNumTxs defines the maximum number of transactions that should be selected from the cache.
const TxCacheSelectionMaxNumTxs = 50000

// TxCacheSelectionLoopMaximumDuration defines the maximum duration for the loop that selects transactions from the cache.
const TxCacheSelectionLoopMaximumDuration = 250 * time.Millisecond
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds good for 6 second round time, can remain like this. should be much lower for sub second round times

@@ -20,7 +20,7 @@ require (
github.com/multiversx/mx-chain-es-indexer-go v1.7.10
github.com/multiversx/mx-chain-logger-go v1.0.15
github.com/multiversx/mx-chain-scenario-go v1.4.4
github.com/multiversx/mx-chain-storage-go v1.0.17
github.com/multiversx/mx-chain-storage-go v1.0.18-0.20241126200205-8a0cb502901f
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't forget to update after fixes.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We reference the latest commit from here: https://github.com/multiversx/mx-chain-storage-go/pull/57/commits.

A proper tag be set after all merges into the feat branch, right before preparing the release.

@@ -34,15 +33,10 @@ var _ process.PreProcessor = (*transactions)(nil)
var log = logger.GetOrCreate("process/block/preprocess")

// 200% bandwidth to allow 100% overshooting estimations
const selectionGasBandwidthIncreasePercent = 200
const selectionGasBandwidthIncreasePercent = 400
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe move these two constants in config?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should, yes. Added MX-16201 (we have some other constants to move to config).

@andreibancioiu andreibancioiu merged commit e04679e into feat/mempool Nov 27, 2024
5 checks passed
@andreibancioiu andreibancioiu deleted the MX-16107-no-more-notify branch November 27, 2024 17:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants