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

Add limits for number of transactions by sender #1716

Merged
merged 41 commits into from
May 15, 2020
Merged

Conversation

andreibancioiu
Copy link
Collaborator

@andreibancioiu andreibancioiu commented May 11, 2020

A sender can have no more than k transactions in the pool. The transactions can not exceed s bytes in total. These limits are checked and enforced at transaction insertion (addition) time.

k: SizePerSender = 1000
s: SizeInBytesPerSender = 614400

Furthermore, removed phase 1 of eviction ("evict high nonce transactions") - redundant. The previous phase 2 ("evict senders with bad score") is now phase 1.

Lastly, fixed the fee scale when computing the score of the senders - because of the new minGasPrice (the change of 3 orders of magnitude affected the score formula).

Note that this PR includes #1725, so that one should enter first in development - thus please skip testnet-related changes when reviewing this PR.

@andreibancioiu andreibancioiu changed the title Add limits for number of transactions by sender [WIP ]Add limits for number of transactions by sender May 11, 2020
@andreibancioiu andreibancioiu changed the title [WIP ]Add limits for number of transactions by sender [WIP] Add limits for number of transactions by sender May 11, 2020
@andreibancioiu andreibancioiu self-assigned this May 11, 2020
@andreibancioiu andreibancioiu changed the title [WIP] Add limits for number of transactions by sender Add limits for number of transactions by sender May 12, 2020
@andreibancioiu andreibancioiu marked this pull request as ready for review May 12, 2020 19:40
dataRetriever/txpool/interface.go Show resolved Hide resolved
process/smartContract/process.go Outdated Show resolved Hide resolved
scripts/testnet/variables.sh Outdated Show resolved Hide resolved
storage/txcache/config.go Outdated Show resolved Hide resolved
storage/txcache/disabledCache.go Outdated Show resolved Hide resolved
storage/txcache/txCache_test.go Outdated Show resolved Hide resolved
storage/txcache/txListForSender.go Show resolved Hide resolved

if nonce == incomingNonce && gasPrice > incomingGasPrice {
return element
// The incoming transaction will be placed right after the existing one, which has same nonce but higher price.
return element, nil
}

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should add a another case here for
nonce == incomingNonce && gasPrice <= incomingGasPrice and return the element - 1 position (if that exists) in order to put the transaction just before the existing. Otherwise, will exit on the last function return instruction, adding on the first position.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Code in findInsertionPlace isn't currently very self-explanatory (and thus is decorated with a lot of comments), but if the I've found a place event does not happen in the iteration where the condition currentTxNonce == incomingNonce && currentTxGasPrice <= incomingGasPrice holds, the flow goes on and then stops at currentTxNonce < incomingNonce which is the most brutal / catch all condition of the iteration - and triggers the I've found a place event (and thus the SORT BY nonce ASC THEN BY gasPrice DESC holds).

Fixed ambiguity by adding an extra test and some comments.
When writing the test, I've discovered that I was incorrectly relying on require.ElementsMatch :)

storage/txcache/wrappedTransaction.go Show resolved Hide resolved
@@ -21,9 +21,15 @@ func (args *ArgShardedTxPool) verify() error {
if config.SizeInBytes < dataRetriever.TxPoolMinSizeInBytes {
return fmt.Errorf("%w: config.SizeInBytes is less than [dataRetriever.TxPoolMinSizeInBytes]", dataRetriever.ErrCacheConfigInvalidSizeInBytes)
}
if config.SizeInBytesPerSender < dataRetriever.TxPoolMinSizeInBytes {
return fmt.Errorf("%w: config.SizeInBytesPerSender is less than [dataRetriever.TxPoolMinSizeInBytes]", dataRetriever.ErrCacheConfigInvalidSizeInBytes)
Copy link
Contributor

Choose a reason for hiding this comment

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

what size does TxPoolMinSizeInBytes refer to?
if it is the size of a transaction then it is fine, although name is confusing, if it refers to the size of the pool itself then I don't think the condition is entirely correct, unless the minimum size we want for txpool is one tx.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

TxPoolMinSizeInBytes is (was) ~ 40kb, and added mostly to ensure that there are no zeros (just positives) in the configuration. This was an arbitrary number to account for the size in bytes of one transaction, indeed (like 1 was used for counts / num shards and so on).

Fixed to remove ambiguity, and now we use a simple condition for "strictly positive".

Copy link
Contributor

@LucianMincu LucianMincu left a comment

Choose a reason for hiding this comment

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

System tests passed.

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.

None yet

4 participants