-
Notifications
You must be signed in to change notification settings - Fork 49
Change Tx validation logic to add: Tx wait that its parent has been validated. #137
Conversation
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 in general. I didn't fully execute the code in my head, but skimmed it through. Couple minor suggestions on naming mostly.
When you are done with this, can you change the state to Ready for Review
and I'll do one more look on changed parts 🙂
@@ -202,3 +273,275 @@ impl TxEvent<NewTx> { | |||
.await | |||
} | |||
} | |||
|
|||
// Use to cache New tx and store waiting Tx that have missing parent. | |||
pub struct TXCache { |
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.
Should this possibly be named TxCache
so that it's aligned with other types (e.g. TxEvent
or WaitTx
etc.)?
) | ||
} | ||
pub fn build(cache_size: usize, max_waiting_tx: usize, max_waiting_time: u64) -> Self { | ||
let cachedtx_for_verification = |
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 cachedtx_for_verification = | |
let cached_tx_for_verification = |
Would it be ok to separate the words like this so it's easier to read when skimming the code through?
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've updated all occurrences in the code.
let tx_hash = tx_event.tx.hash; | ||
let res = tx_event.process_event(&mut wait_tx_cache, &db).await; | ||
assert!(res.is_ok()); | ||
// Evicted but new ket 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.
What's ket
here?
crates/node/src/txvalidation/mod.rs
Outdated
Ok(new_tx_list) => { | ||
// | ||
let jh = tokio::spawn({ | ||
let newtx_receiver = newtx_receiver.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.
Maybe these could also be renamed to new_tx_receiver
for easier readability?
Co-authored-by: Tuomas Mäkinen <[email protected]>
Co-authored-by: Tuomas Mäkinen <[email protected]>
I've applied the changes. |
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.
Awesome 🙌
A Child Tx must be executed after its parent if it has a parent Tx.
This order is not guaranteed by the current code and can easily arrive when Proof has a big file as input. The child verify Tx can be executed during the proof input file download.
After Tx verification, the Tx's parent, if it exists, is verified to be already validated.
To do that, the presence of the parent Tx in the db is verified. A cache is used to avoid Db query of the recent Tx.
If the parent is not found, the Tx is put in a waiting list.
When the parent arrives, the child Tx are removed from the waiting list and added to the mempool with the parent tx.
The process_event logic code is more complex because I wanted to avoid using a mutex for the cache, and we need to mix sync code (cache / waiting Tx verification) and async one.
I set it in draft because to be fully tested, the PE #136 must be merged to be able to test it with bigfile.