Skip to content
This repository has been archived by the owner on Dec 17, 2024. It is now read-only.

Change Tx validation logic to add: Tx wait that its parent has been validated. #137

Merged
merged 13 commits into from
Mar 14, 2024

Conversation

musitdev
Copy link
Contributor

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.

@musitdev musitdev requested a review from tuommaki March 13, 2024 09:54
Copy link
Contributor

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

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

Choose a reason for hiding this comment

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

Suggested change
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?

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

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/event.rs Outdated Show resolved Hide resolved
Ok(new_tx_list) => {
//
let jh = tokio::spawn({
let newtx_receiver = newtx_receiver.clone();
Copy link
Contributor

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?

crates/node/src/types/transaction.rs Outdated Show resolved Hide resolved
@musitdev musitdev marked this pull request as ready for review March 13, 2024 20:01
@musitdev
Copy link
Contributor Author

I've applied the changes.

Copy link
Contributor

@tuommaki tuommaki left a comment

Choose a reason for hiding this comment

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

Awesome 🙌

@musitdev musitdev merged commit 2d6a154 into main Mar 14, 2024
4 checks passed
@musitdev musitdev deleted the wait_parent_tx_logic branch March 14, 2024 11:02
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants