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 new MinTxsInBlock consensus param #252

Merged
merged 3 commits into from
Jan 6, 2025
Merged

Add new MinTxsInBlock consensus param #252

merged 3 commits into from
Jan 6, 2025

Conversation

codchen
Copy link
Collaborator

@codchen codchen commented Dec 27, 2024

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:

  • a single transaction still cannot exceed the max gas by itself
  • max bytes will still take precedence

Testing performed to validate your change

integrated with sei-chain and tested in local sei

@@ -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)
Copy link
Contributor

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?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

added

Copy link
Contributor

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",
Copy link
Contributor

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"

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

updated

Copy link

codecov bot commented Jan 2, 2025

Codecov Report

Attention: Patch coverage is 83.33333% with 2 lines in your changes missing coverage. Please review.

Project coverage is 58.27%. Comparing base (57e0107) to head (bea5c8f).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
internal/consensus/replay_stubs.go 33.33% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            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     
Files with missing lines Coverage Δ
internal/mempool/mempool.go 73.58% <100.00%> (+0.16%) ⬆️
internal/mempool/types.go 0.00% <ø> (ø)
internal/state/execution.go 61.83% <100.00%> (ø)
internal/consensus/replay_stubs.go 47.36% <33.33%> (ø)

... and 17 files with indirect coverage changes

@@ -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 {
Copy link
Contributor

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?

Copy link
Contributor

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)
}

Copy link
Collaborator Author

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)
Copy link
Contributor

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)

@codchen codchen merged commit 327430d into main Jan 6, 2025
24 checks 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.

4 participants