-
Notifications
You must be signed in to change notification settings - Fork 20.2k
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: sort txs at the same gas price by received time #21358
Conversation
While I agree with the general idea, I'm not sure this is the best approach. It feels wrong to hack in a new field into the transaction. The arrival time is relevant only for the txpool and the miner. Otherwise a transaction has no notion nor need for an arrival time. I don't think it makes sense to add it to a core type just to make the miner happy. |
To be clear, this isn't to make miners happy. It is to remove an incentive currently present that is resulting in a significant amount of spam against the network and blockchain, which is contributing to gas prices going up. Is your issue with the general idea of sorting by seen-time, or is your concern with the specific implementation presented here? |
I agree that the data does not really belong in the Transaction. I mean the caches of non-txdata are already there but I agree they are closer than a mempool-reliant concept like time of arrival. |
Micah, the 'miner' part of the codebase, and 'txpool' part of codebase. I agree - would be better with an auxiliary map/lookup of timestamps, rather than putting it onto the core objects.
|
My initial gut approach would be to have the txpool track the arrival time along each transaction, maybe by wrapping the txs in some auxiliary wrapper. That seems better vs. a totally external map Martin suggested because you don't need to explicitly track liveliness/contets and keep it in lockstep with the pool contents. That said, I do see that the txpool uses types.Transaction quite extensively, not sure what the implication would be of introducing a wrapper in there. All in all I do like the idea with the arrival time, just trying to figure out where exactly is it the most suitable to be injected. If it's only tracked by the |
Another potential idea could be to have a |
I've pushed a bit of a modification on top of this PR. Instead of leaking the receipt time into the tx API, I've made it a hidden fields only handled within the Regarding my original complaint that the receipt time has no place in the tx object, I'm happy with my above approach as long as the field is private and completely hidden, so all the rest of the code is oblivious that it exists. I did try to move all this out of @holiman PTAL if this approach makes sense to you or not? |
@karalabe Thanks for taking care of this. Looks good to me. Covering time setting in constructors and decode methods seems to cover all cases that involve the mempool. |
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.
LGTM
Awesome responsiveness, thanks Peter as always! |
@@ -341,8 +358,8 @@ type TransactionsByPriceAndNonce struct { | |||
// Note, the input map is reowned so the caller should not interact any more with | |||
// if after providing it to the constructor. | |||
func NewTransactionsByPriceAndNonce(signer Signer, txs map[common.Address]Transactions) *TransactionsByPriceAndNonce { |
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.
s/NewTransactionsByPriceAndNonce/NewTransactionsByPriceTimeAndNonce/g ?
@hendrikhofstadt do you have any thoughts on this alternate proposal: https://notes.ethereum.org/@holiman/H17hFNWfd |
@palkeo sounds great. I can try to fix it so you have comment-access, or we could use some other forum. Should I post on e.g. fellowship of magicians, or use some discord channel? |
@holiman @palkeo happy to start a fresh discussion. A lot of context to the issue unfortunately got lost in the Ethereum devs discord history where I originally brought this up and discussed it with a couple of folks The original idea behind the issue was to reduce block congestion due to “sorting bids” which I consider successful given that for most backrunning opportunities there are only some 4-10 bids from different bots. My current take is that given the value of all MEV transactions (see Flashbots’ explorer), any change that incentivises shot gunning or bruteforcing hashes (and subsequently sending multiple attempts) might significantly increase congestion again (as if it wasn’t bad enough right now). |
Closes harmony-one#4113 by sorting transactions by time received instead of using a hashmap based transaction ordering. This sorting is on top of the gas price and nonce sorting already implemented. Effectively, this allows the production of almost a deterministic order of transaction ordering, as opposed to a heap-based hash map ordering which is affected by Golang's internal operations. Consequently, arbitrageurs, who spam the network with a view to exist around arbitrag-able transactions, will have to focus on latency instead of network spamming. See also bsc-chain/bsc#269 and ethereum/go-ethereum#21358 for related issues in other chains.
Closes harmony-one#4113 by sorting transactions by time received instead of using a hashmap based transaction ordering. This sorting is on top of the gas price and nonce sorting already implemented. Effectively, this allows the production of almost a deterministic order of transaction ordering, as opposed to a heap-based hash map ordering which is affected by Golang's internal operations. Consequently, arbitrageurs, who spam the network with a view to exist around arbitrag-able transactions, will have to focus on latency instead of network spamming. See also bnb-chain/bsc#269 and ethereum/go-ethereum#21358 for related issues in other chains.
Closes #4113 by sorting transactions by time received instead of using a hashmap based transaction ordering. This sorting is on top of the gas price and nonce sorting already implemented. Effectively, this allows the production of almost a deterministic order of transaction ordering, as opposed to a heap-based hash map ordering which is affected by Golang's internal operations. Consequently, arbitrageurs, who spam the network with a view to exist around arbitrag-able transactions, will have to focus on latency instead of network spamming. See also bnb-chain/bsc#269 and ethereum/go-ethereum#21358 for related issues in other chains.
This PR changes the sorting of pool transactions with the same gas price.
Previously transactions were sorted randomly (due to the way go maps work).
Now they are sorted by the time that they were added to the mempool in ascending order.
This is supposed to remove the incentive for spamming transactions to backrun a tx (#21350).
Potential cons of this solution: