-
Notifications
You must be signed in to change notification settings - Fork 38
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 new MinTxsInBlock consensus param #252
Conversation
@@ -384,7 +384,7 @@ func TestTxMempool_ReapMaxBytesMaxGas(t *testing.T) { | |||
wg.Add(1) | |||
go func() { | |||
defer wg.Done() | |||
reapedTxs := txmp.ReapMaxBytesMaxGas(-1, 50) | |||
reapedTxs := txmp.ReapMaxBytesMaxGas(-1, 50, 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
coudl we add unit tests for when this value isn't 0?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it might be good to permutate these situations:
- min txs reached / not reached
- min size reached / not reached
- min gas reached / not reached
- with combinations of configurations (has gas/size/txs config)
(chat gpt should be able to help make a scenario-based test for that)
types/params.go
Outdated
@@ -286,6 +288,11 @@ func (params ConsensusParams) ValidateConsensusParams() error { | |||
params.Block.MaxGas) | |||
} | |||
|
|||
if params.Block.MinTxsInBlock < 0 { | |||
return fmt.Errorf("block.MinTxsInBlock must be positive. Got %d", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit - "must be non-negative"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #252 +/- ##
==========================================
+ Coverage 58.10% 58.27% +0.16%
==========================================
Files 249 249
Lines 34555 34559 +4
==========================================
+ Hits 20079 20138 +59
+ Misses 12877 12828 -49
+ Partials 1599 1593 -6
|
internal/mempool/mempool.go
Outdated
@@ -453,7 +453,7 @@ func (txmp *TxMempool) ReapMaxBytesMaxGas(maxBytes, maxGas int64) types.Txs { | |||
} | |||
totalSize += size | |||
gas := totalGas + wtx.gasWanted | |||
if maxGas > -1 && gas > maxGas { | |||
if len(txs) >= int(minTxsInBlock) && maxGas > -1 && gas > maxGas { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this might need to be also or size threshold is exceeded
. I suspect the incremented values totalSize
, totalGas
should only be incremented if the transaction is appended?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here's kinda what i'm thinking:
txmp.priorityIndex.ForEachTx(func(wtx *WrappedTx) bool {
size := types.ComputeProtoSizeForTxs([]types.Tx{wtx.tx})
if len(txs) >= int(minTxsInBlock) {
if thresholdExceeded(maxBytes, totalSize, size) {
return false
}
if thresholdExceeded(maxGas, totalGas, wtx.gasWanted) {
return false
}
}
totalGas += wtx.gasWanted
totalSize += size
txs = append(txs, wtx.tx)
return true
})
with helper:
func thresholdExceeded(threshold, totalSoFar, txValue int64) bool {
return threshold > -1 && ((totalSoFar + txValue) > threshold)
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should exempt txs from exceeding size limit since a large size does mean we need to store more data on chain (i.e. it's not sizeWanted but always sizeUsed)
@@ -384,7 +384,7 @@ func TestTxMempool_ReapMaxBytesMaxGas(t *testing.T) { | |||
wg.Add(1) | |||
go func() { | |||
defer wg.Done() | |||
reapedTxs := txmp.ReapMaxBytesMaxGas(-1, 50) | |||
reapedTxs := txmp.ReapMaxBytesMaxGas(-1, 50, 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it might be good to permutate these situations:
- min txs reached / not reached
- min size reached / not reached
- min gas reached / not reached
- with combinations of configurations (has gas/size/txs config)
(chat gpt should be able to help make a scenario-based test for that)
Describe your changes and provide context
Add a new param to specify the minimum number of transactions to take into a block (as long as there are so many in the mempool) regardless of the max gas for a block. Some things to note:
Testing performed to validate your change
integrated with sei-chain and tested in local sei