-
Notifications
You must be signed in to change notification settings - Fork 43
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
refactor(l1): move mempool from Store to Blockchain #2089
Conversation
|
crates/blockchain/mempool.rs
Outdated
Ok(hash) | ||
} | ||
|
||
/// Add a transaction to the mempool | ||
pub fn add_transaction(transaction: Transaction, store: &Store) -> Result<H256, MempoolError> { | ||
pub fn add_transaction( |
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.
what is the difference between this object and add_transaction_to_pool
?
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.
seems like this should be a method of blockchain
struct.
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.
The function add_transaction
was calling add_transaction_to_pool
at the end, but add_transaction
also included transaction validations, for these validations you need to access the store, so I decided to leave a minimal interface with the mempool from the blockchain struct:
add_transaction_to_pool
add_blob_transaction_to_pool
remove_transaction_from_pool
validate_transaction
-> this one needs access to the storage
Then the mempool struct implements functions to lock the mempool Mutex
then insert the transaction/blob without doing any validity checks leaving a comment indicating this.
@@ -261,7 +261,7 @@ async fn main() { | |||
peer_table.clone(), | |||
sync_mode, | |||
cancel_token.clone(), | |||
blockchain, | |||
blockchain.clone(), |
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.
Can't we pass a blockchain reference instead of cloning? I would disable clone
for a blockchain, since it's a singleton.
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.
That would mean adding an Arc and then cloning that Arc right? What we are doing right now is technically the same as the only field we are really cloning is the EVM both the store and mempool are internally arcs so when we clone them we are only cloning the references. I will still change it to Arc if thats what makes more sense.
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.
ok, leave it as is then.
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 will be tackled in a separate PR, moving blockchain
to an Arc
…functions, remove mempool_remove_transactions as it was only used once and the behaviour was incorrect
…ity checks, mempool don't
|
||
*/ | ||
|
||
pub fn validate_transaction( |
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.
Can be tackled in a follow up, but it seems this should call a function inside mempool
@@ -57,7 +57,7 @@ where | |||
node, | |||
stream, | |||
codec, | |||
context.storage, |
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.
let's pass both storage
and blockchain
since these are different entities and shouldn't be coupled together.
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.
@chaja This should be for all places where the store was replaced by blockchain? Specially on the initial layers like rpc start on cmd/ethrex/ethrex.rs
right? The idea is to distinguish the Blockchain having a reference to the store vs being the actual owner of the mempool at an arq level?
I'm a bit confused on when would be better to use the store separated from the blockchain struct and when to use the store reference inside the blockchain struct, as far as I understand most of this PR leaned to use the store ref inside blockchain replacing the previous isolated ones.
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.
My comment is about being more future proof. A store might be divided into different stores, like p2p store, state store, history store, etc.. Then relying in the store from blockchain wont be the solution inside every rpc/p2p call.
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.
When you remove the remaining context.blockchain.storage
from both rpc and p2p
We can create an issue to make the storage in blockchain private following this PR to avoid this kind of ambiguity in the future. |
Left an issue here #2105 |
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.
Great work, it's almost there, i have a couple of comments in line with previous request from @chaja, still reviewing the mempool and blockchain file, will finish ASAP
return Ok(None); | ||
}; | ||
let result = match tx { | ||
Transaction::LegacyTransaction(itx) => P2PTransaction::LegacyTransaction(itx), | ||
Transaction::EIP2930Transaction(itx) => P2PTransaction::EIP2930Transaction(itx), | ||
Transaction::EIP1559Transaction(itx) => P2PTransaction::EIP1559Transaction(itx), | ||
Transaction::EIP4844Transaction(itx) => { | ||
let Some(bundle) = store.get_blobs_bundle_from_pool(*hash)? else { | ||
let Some(bundle) = mempool.get_blobs_bundle(*hash)? else { |
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.
In the future we'll need a consistent interface through blockchain/mempool, right now in the following changes we useblockchain.add_blob_transaction_to_pool
or blockchain.add_transaction_to_pool
instead of using internal mempool functions as done here. We might want to go one way or the other in a future PR.
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 agree, the only reason why I left some functions that access the mempool as members of Blockchain is because to add transactions we perform some validations that use the Store. That was done before me knowing that the Store and Blockchain should be completely separate entities.
Knowing that I think they should be removed from blockchain and be functions of mempool that receive a store like add_transaction_to_pool(self, tx, store)
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.
Yeah, I think both ways have their pros and cons but clearly something we could tackle in another PR, so we could go ahead with it for now and discuss the next step later!
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.
Great work @LeanSerra 🚀. Left some minor las comment (all pointing to the same thing)
Motivation
The
mempool
is currently stored in theStore
struct, it makes more sense to have it in theBlockchain
structDescription
Mempool
that implements all the functions related to the mempool.Blockchain::add_transaction_to_pool
,Blockchain::add_blob_transaction_to_pool
Blockchain::remove_transaction_from_pool
Closes #2072