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

Archive node feature #2338

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Archive node feature #2338

wants to merge 5 commits into from

Conversation

Neotamandua
Copy link
Member

@Neotamandua Neotamandua commented Sep 10, 2024

This PR introduces the "archive" feature flag to rusk and node. Another PR would build on top of this and introduce serving them through an http api.

When run with:
DUSK_CONSENSUS_KEYS_PASS=password cargo r --release --features archive -p rusk -- -s /tmp/example.state, the archive feature is active and starts archiving contract events from the vm into an SQLite database.

This was done by adding a new service, ArchivistSrv, to the node's service_list. This service listens on a channel that receives the VM events from a sender that sends them during the execution of the accept_transactions function of the Rusk struct (the same place where VM events are sent to RUES).

The ArchivistSrv, upon receiving new VM events, calls the SQLiteArchive (which manages a SQLite db) and stores all ContractTxEvent events from a block in a json serialized column.

Considerations:

  • Merge ContractEvent in rusk http lib with the one in node-data
  • Make SQLite more performant with pragmas in the next PR (e.g. PRAGMA journal_mode=WAL;)
  • We can add query CI checks with cargo install sqlx-cli && cargo sqlx prepare --check -- --all-targets --all-features for the queries
  • Migrate to rocksdb, lmdb or similar at the earliest feasible time

- Add archive feature flag to rusk (depends on node)
- Add ArchivalData enum to node-data
- Add VM event MPSC channel for archival to Rusk
- Add with_archivist to RuskNodeBuilder
- Split up build and run for RuskNodeBuilder
- Add ArchivistSrv to service list
- Add Archivist trait to node
- Add archive_sender to Rusk & send VM events in accept_transactions
- Add SQLiteArchive struct to Node
- Add optional sqlx, serde_json dep & archive feature to node
- Add migration file with archive db schema
- Add an .env file to get sqlx-cli & macros to work
- Add SQLiteArchive functionalities & tests
- Use hash type alias for [u8; 32]
- Add serialization support & tests to node_data ContractEvent
- Update gitignore (.vscode)
- fmt & todo comments
- Update README with archive run info
- Fix shutdown problem & get rid of Mutex
- Move ContractTxEvent to node-data
- Combine ContractTxEvent with ContractEvent
- Skip origin serialization if none
- Let sqlx queries compile without live db connection
- Update README
Copy link
Contributor

@miloszm miloszm left a comment

Choose a reason for hiding this comment

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

I'd prefer the code not to be so heavily #IFDEF'ed, #[cfg(feature="archive")] is used 22 times. I'd rather limit their usage to module inclusion and some constants, but not for, e.g., structs and method invocations, as in the long run such code is hard to maintain, read and test. Normal in-language optionality could be used in such places instead, so that we still have a common code base, only differing in some modules being included (or not) and in some constants.

@Neotamandua
Copy link
Member Author

I'd prefer the code not to be so heavily #IFDEF'ed, #[cfg(feature="archive")] is used 22 times.

Thanks for the input and I agree. I have taken note of this for the next related task, which aims to separate archivers from provisioners. This next task will change the structure again, so it's a good idea imo to tackle it there.

Copy link
Contributor

@Daksh14 Daksh14 left a comment

Choose a reason for hiding this comment

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

Some questions but I understand the use of the cfg feature everywhere, the archival needs to built with the node, its not optimal

node-data/src/events.rs Show resolved Hide resolved
/// - The block does not store the events, only the hash of the events. The
/// archivist will store the events.
#[cfg(feature = "archive")]
pub(crate) trait Archivist {
Copy link
Contributor

@Daksh14 Daksh14 Sep 17, 2024

Choose a reason for hiding this comment

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

if its a trait that's just being used inside the crate and not exported, don't you think it will be more readable with less abstraction and more functional. This is just design philosophy but traits are understandable if they are exported (we're also trying to reduce the number of traits in the wallets from Store/State moving towards functional design)

rusk/src/lib/node.rs Show resolved Hide resolved
rusk/src/lib/node/rusk.rs Show resolved Hide resolved
rusk/src/lib/node/rusk.rs Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement storage solutions for events
3 participants