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

core/tx_pool: count tx size in slots, bump max size ot 4x32 Kb #20352

Merged
merged 5 commits into from
Jan 10, 2020

Conversation

MichaelRiabzev-StarkWare
Copy link
Contributor

@MichaelRiabzev-StarkWare MichaelRiabzev-StarkWare commented Nov 21, 2019

This change allows transactions of bigger than 32KB. To prevent DoS over the tx pool (the original reason to limit the transaction size), this change should not introduce any additional memory consumption over the original implementation. Thus instead of the straightforward solution of enlarging the hard-coded limit, it introduces slots in the tx pool. The size of the tx pool is limited by the number of slots. Each slot is of size up to 32KB, and each transaction can now take up to 4 slots. The eviction of underpriced transactions stays the same as before, in particular, a 4-slot transaction can evict 4 1-slot transactions even in the case it is slightly more profitable.


This change is Reviewable

core/tx_pool.go Outdated
@@ -583,7 +595,7 @@ func (pool *TxPool) add(tx *types.Transaction, local bool) (replaced bool, err e
return false, ErrUnderpriced
}
// New transaction is better than our worse ones, make room for it
drop := pool.priced.Discard(pool.all.Count()-int(pool.config.GlobalSlots+pool.config.GlobalQueue-1), pool.locals)
drop := pool.priced.Discard(pool.all.SlotsUsed()-int(pool.config.GlobalSlots+pool.config.GlobalQueue)+NumSlots(tx), pool.locals)
Copy link
Contributor

Choose a reason for hiding this comment

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

If I'm reading this right, it means that one 4-slot tx will push out 4 1-slot transactions, even though it's only marginally better.
That may be fine, but please update the PR description with more information about the expected behaviours, such as this.
These types of choices that is made internally deep within the tx pool determines whether the macro behaviour of the network can be attacked or not.

It might be good to introduce some randomness to how the tx pool behaves in this regard.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've updated the PR description accordingly. Do you have concrete suggestions for the tx pool behavior?

core/tx_pool.go Outdated
@@ -270,6 +279,9 @@ func NewTxPool(config TxPoolConfig, chainconfig *params.ChainConfig, chain block
reorgDoneCh: make(chan chan struct{}),
reorgShutdownCh: make(chan struct{}),
gasPrice: new(big.Int).SetUint64(config.PriceLimit),

// Heuristic limit, reject transactions requiring over 4 slots to prevent DOS attacks
maxTxSize: 4 * slotSize,
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a 4x bump. I'm not sure we should bump that immediately, or do something a bit less dramatic, e.g. set it randomly so 50% retain 1x slotsize, 25% 2x and 25% 4x. Up for discussion (and please add it to PR description)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought this was a solution you felt comfortable with, notice it does not enlarge resource consumption.

@holiman holiman changed the title Michael/slots core/tx_pool: count tx size in slots, bump max size ot 4x32 Kb Nov 25, 2019
Copy link
Member

@karalabe karalabe left a comment

Choose a reason for hiding this comment

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

SGTM

@karalabe karalabe added this to the 1.9.10 milestone Jan 9, 2020
@karalabe karalabe merged commit 8bd37a1 into ethereum:master Jan 10, 2020
enriquefynn pushed a commit to enriquefynn/go-ethereum that referenced this pull request Mar 10, 2021
* tests for tx size

* alow multiple slots transactions

* tests for tx size limit (32 KB)

* change tx size tests to use addRemoteSync instead of validateTx (requested in pool request).

* core: minor tx slotting polishes, add slot tracking metric

Co-authored-by: Michael Riabzev <RiabzevMichael@gmail.com>
Co-authored-by: Péter Szilágyi <peterke@gmail.com>
@gzliudan gzliudan mentioned this pull request May 11, 2024
20 tasks
gzliudan added a commit to gzliudan/XDPoSChain that referenced this pull request May 13, 2024
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