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

Integrate the trie #57

Merged
merged 36 commits into from
Apr 29, 2024
Merged

Integrate the trie #57

merged 36 commits into from
Apr 29, 2024

Conversation

Avi-D-coder
Copy link
Contributor

This PR just sets up the trie thread and state.
We still need all the prior logic against the btree to pre-validate transactions.
That btree will be replaced by a cache db (PublicKey -> Account).

We could remove pre-validated transaction requirement with an immutable trie::SnapshotBuilder that supported could rollback.
However, we would still need to prevent DoS with the cache db. Real hardware is very different from the zkVM, binary tries don't perform all that well on SSDs.

In the future we will also need to warm up the NodeHash -> TrieNode DB right before a txn hits the trie state thread. By cashing TrieNodes into ram we can move slow IO off that thread.

Next Steps after this PR:

  • Adding persistence with rocks
  • Adding a validating thread for testing against (like a mock contract for testing)
  • General testing txns (we can replicate what I did in the trie repo).

@Avi-D-coder Avi-D-coder requested review from marijanp and koxu1996 April 2, 2024 06:50
@marijanp marijanp added the demo Required for our first demo label Apr 2, 2024
@Avi-D-coder
Copy link
Contributor Author

I'm going to merge the txn logic between the trie and btree-cache-db before this should be merged.

Copy link

github-actions bot commented Apr 2, 2024

File Coverage
All files 54%
kairos-crypto/src/implementations/casper.rs 3%
kairos-test-utils/src/cctl.rs 87%
kairos-test-utils/src/kairos.rs 95%
kairos-server/tests/transactions.rs 85%
kairos-server/src/routes/deposit.rs 88%
kairos-server/src/routes/transfer.rs 90%
kairos-tx/src/asn.rs 76%
kairos-tx/src/error.rs 0%
kairos-server/src/config.rs 0%
kairos-server/src/errors.rs 12%
kairos-server/src/state.rs 90%
kairos-server/src/utils.rs 22%
kairos-test-utils/src/cctl/parsers.rs 66%
kairos-server/src/state/transactions.rs 57%
kairos-server/src/state/trie.rs 35%
kairos-server/src/state/transactions/batch_state.rs 42%

Minimum allowed coverage is 60%

Generated by 🐒 cobertura-action against 4635140

Copy link
Contributor

@marijanp marijanp left a comment

Choose a reason for hiding this comment

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

Minor things, mostly requests for additional documentation

kairos-tx/schema.asn Outdated Show resolved Hide resolved
kairos-server/src/state.rs Show resolved Hide resolved
impl BatchState {
pub fn new() -> Arc<RwLock<Self>> {
pub fn new(
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you document what new does

kairos-server/src/state/trie.rs Outdated Show resolved Hide resolved
kairos-server/src/state/trie.rs Outdated Show resolved Hide resolved
kairos-server/src/routes/withdraw.rs Outdated Show resolved Hide resolved
kairos-server/src/state/trie.rs Show resolved Hide resolved
kairos-server/src/state/trie.rs Show resolved Hide resolved
@Avi-D-coder Avi-D-coder requested a review from marijanp April 24, 2024 05:50
Copy link
Contributor

@koxu1996 koxu1996 left a comment

Choose a reason for hiding this comment

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

Very solid PR 👏. One requested change is to remove epoch locking - as we discussed during last deep dive - so we avoid accepted transactions that are unexpectedly failing because of batch end/limit. 💬 (This was already done, I missed it somehow.)

Also thanks for the improvement to kairos-tx, I will extract them to separate PR to avoid clutter in yours.

@Avi-D-coder
Copy link
Contributor Author

One requested change is to remove epoch locking - as we discussed during last deep dive - so we avoid accepted transactions that are unexpectedly failing because of batch end/limit.

I think I already did this in 74d0444.

I removed the my outdated comment about batch epoch.
Although I think we might still need an epoch for time expiring transactions.

@koxu1996
Copy link
Contributor

What about TTL? It could be maximum timestamp, or maximum epoch.

Copy link
Contributor

@marijanp marijanp left a comment

Choose a reason for hiding this comment

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

Where I asked for more docs for types and functions, I was more in the hope of getting explanations of how the different datastructures are supposed to be used together, what caveats there are.

nixos/tests/end-to-end.nix Outdated Show resolved Hide resolved
kairos-server/src/errors.rs Outdated Show resolved Hide resolved
Comment on lines 100 to 106
pub fn new_deposit(amount: impl Into<Amount>) -> Self {
Self {
// deposits have no meaningful nonce
nonce: 0.into(),
body: TransactionBody::Deposit(Deposit::new(amount)),
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

All of this work in this file just to add a nonce to some of the types. I think we need to think how we can refactor kairos-tx

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe get rid of SigningPayload and adding the nonce where relevant.

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'd like to move nonce to transfer and withdraw in the future.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

However some of this duplication is to make type inference nicer.

SigningPayload::new vs SigningPayload::new_*

kairos-server/src/errors.rs Outdated Show resolved Hide resolved
@Avi-D-coder
Copy link
Contributor Author

Where I asked for more docs for types and functions, I was more in the hope of getting explanations of how the different datastructures are supposed to be used together, what caveats there are.

I added a bit more, but I'm not clear on what parts are confusing?
Are you looking for an overview of the trie logic or something else?

@koxu1996 koxu1996 mentioned this pull request Apr 29, 2024
Copy link
Contributor

@koxu1996 koxu1996 left a comment

Choose a reason for hiding this comment

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

🚀

kairos-tx/src/asn.rs Outdated Show resolved Hide resolved
kairos-tx/src/asn.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@marijanp marijanp left a comment

Choose a reason for hiding this comment

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

Thank you for adding the comments

@marijanp marijanp merged commit 366391c into main Apr 29, 2024
7 checks passed
@Avi-D-coder Avi-D-coder deleted the feature/trie branch April 29, 2024 18:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
demo Required for our first demo
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants