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

Implement async trait DataStore using maybe-async-await macro #725

Merged
merged 5 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions .github/workflows/no-std.yml → .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Runs no-std related jobs.
# Runs build related jobs.

name: no-std
name: build

on:
push:
Expand All @@ -9,6 +9,20 @@ on:
types: [opened, reopened, synchronize]

jobs:
async:
name: Build using `async` feature
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
toolchain: [stable, nightly]
steps:
- uses: actions/checkout@main
- name: Build using `async` feature
run: |
rustup update --no-self-update ${{ matrix.toolchain }}
make build-async

no-std:
name: Build for no-std
runs-on: ubuntu-latest
Expand All @@ -22,4 +36,4 @@ jobs:
run: |
rustup update --no-self-update ${{ matrix.toolchain }}
rustup target add wasm32-unknown-unknown
make build-no-std
make build-no-std
87 changes: 44 additions & 43 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,68 +4,69 @@

### Enhancements

* Add `Option<NoteTag>`to `NoteFile` (#741).
* Replaced `cargo-make` with just `make` for running tasks (#696).
* [BREAKING] Introduce `OutputNote::Partial` variant (#698).
* [BREAKING] Split `Account` struct constructor into `new()` and `from_parts()` (#699).
* [BREAKING] Changed the encoding of inputs notes in the advice map for consumed notes (#707).
* Created additional `emit` events for kernel related `.masm` procedures (#708).
* Implemented `build_recipient_hash` procedure to build recipient hash for custom notes (#710).
* Removed the `mock` crate in favor of having mock code behind the `testing` flag in remaining crates (#711).
* [BREAKING] Created `auth` module for `TransactionAuthenticator` and other related objects (#714).
* Added validation for the output stack to make sure it was properly cleaned (#717).
* Added new `NoteFile` object to represent serialized notes (#721).
* [BREAKING] Added support for delegated authenticated notes (#724).
* [BREAKING] Changed rng to mutable reference in note creation functions (#733).
* Added transaction IDs to the `Block` struct (#734).
* [BREAKING] Replaced `ToNullifier` trait with `ToInputNoteCommitments`, which includes the `note_id` for delayed note authentication (#732).
- Made `DataStore` conditionally async using `winter-maybe-async` (#725)
- Add `Option<NoteTag>`to `NoteFile` (#741).
- Replaced `cargo-make` with just `make` for running tasks (#696).
- [BREAKING] Introduce `OutputNote::Partial` variant (#698).
- [BREAKING] Split `Account` struct constructor into `new()` and `from_parts()` (#699).
- [BREAKING] Changed the encoding of inputs notes in the advice map for consumed notes (#707).
- Created additional `emit` events for kernel related `.masm` procedures (#708).
- Implemented `build_recipient_hash` procedure to build recipient hash for custom notes (#710).
- Removed the `mock` crate in favor of having mock code behind the `testing` flag in remaining crates (#711).
- [BREAKING] Created `auth` module for `TransactionAuthenticator` and other related objects (#714).
- Added validation for the output stack to make sure it was properly cleaned (#717).
- Added new `NoteFile` object to represent serialized notes (#721).
- [BREAKING] Added support for delegated authenticated notes (#724).
- [BREAKING] Changed rng to mutable reference in note creation functions (#733).
- Added transaction IDs to the `Block` struct (#734).
- [BREAKING] Replaced `ToNullifier` trait with `ToInputNoteCommitments`, which includes the `note_id` for delayed note authentication (#732).

## 0.3.0 (2024-05-14)

* Introduce the `miden-bench-tx` crate used for transactions benchmarking (#577).
* [BREAKING] Removed the transaction script root output from the transaction kernel (#608).
* [BREAKING] Refactored account update details, moved `Block` to `miden-objects` (#618, #621).
* [BREAKING] Made `TransactionExecutor` generic over `TransactionAuthenticator` (#628).
* [BREAKING] Changed type of `version` and `timestamp` fields to `u32`, moved `version` to the beginning of block header (#639).
* [BREAKING] Renamed `NoteEnvelope` into `NoteHeader` and introduced `NoteDetails` (#664).
* [BREAKING] Updated `create_swap_note()` procedure to return `NoteDetails` and defined SWAP note tag format (#665).
* Implemented `OutputNoteBuilder` (#669).
* [BREAKING] Added support for full details of private notes, renamed `OutputNote` variants and changed their meaning (#673).
* [BREAKING] Added `add_asset_to_note` procedure to the transaction kernel (#674).
* Made `TransactionArgs::add_expected_output_note()` more flexible (#681).
* [BREAKING] Enabled support for notes without assets and refactored `create_note` procedure in the transaction kernel (#686).
- Introduce the `miden-bench-tx` crate used for transactions benchmarking (#577).
- [BREAKING] Removed the transaction script root output from the transaction kernel (#608).
- [BREAKING] Refactored account update details, moved `Block` to `miden-objects` (#618, #621).
- [BREAKING] Made `TransactionExecutor` generic over `TransactionAuthenticator` (#628).
- [BREAKING] Changed type of `version` and `timestamp` fields to `u32`, moved `version` to the beginning of block header (#639).
- [BREAKING] Renamed `NoteEnvelope` into `NoteHeader` and introduced `NoteDetails` (#664).
- [BREAKING] Updated `create_swap_note()` procedure to return `NoteDetails` and defined SWAP note tag format (#665).
- Implemented `OutputNoteBuilder` (#669).
- [BREAKING] Added support for full details of private notes, renamed `OutputNote` variants and changed their meaning (#673).
- [BREAKING] Added `add_asset_to_note` procedure to the transaction kernel (#674).
- Made `TransactionArgs::add_expected_output_note()` more flexible (#681).
- [BREAKING] Enabled support for notes without assets and refactored `create_note` procedure in the transaction kernel (#686).

## 0.2.3 (2024-04-26) - `miden-tx` crate only

* Fixed handling of debug mode in `TransactionExecutor` (#627)
- Fixed handling of debug mode in `TransactionExecutor` (#627)

## 0.2.2 (2024-04-23) - `miden-tx` crate only

* Added `with_debug_mode()` methods to `TransactionCompiler` and `TransactionExecutor` (#562).
- Added `with_debug_mode()` methods to `TransactionCompiler` and `TransactionExecutor` (#562).

## 0.2.1 (2024-04-12)

* [BREAKING] Return a reference to `NoteMetadata` from output notes (#593).
* Add more type conversions for `NoteType` (#597).
* Fix note input padding for expected output notes (#598).
- [BREAKING] Return a reference to `NoteMetadata` from output notes (#593).
- Add more type conversions for `NoteType` (#597).
- Fix note input padding for expected output notes (#598).

## 0.2.0 (2024-04-11)

* [BREAKING] Implement support for public accounts (#481, #485, #538).
* [BREAKING] Implement support for public notes (#515, #540, #572).
* Improved `ProvenTransaction` validation (#532).
* [BREAKING] Updated `no-std` setup (#533).
* Improved `ProvenTransaction` serialization (#543).
* Implemented note tree wrapper structs (#560).
* [BREAKING] Migrated to v0.9 version of Miden VM (#567).
* [BREAKING] Added account storage type parameter to `create_basic_wallet` and `create_basic_fungible_faucet` (miden-lib
- [BREAKING] Implement support for public accounts (#481, #485, #538).
- [BREAKING] Implement support for public notes (#515, #540, #572).
- Improved `ProvenTransaction` validation (#532).
- [BREAKING] Updated `no-std` setup (#533).
- Improved `ProvenTransaction` serialization (#543).
- Implemented note tree wrapper structs (#560).
- [BREAKING] Migrated to v0.9 version of Miden VM (#567).
- [BREAKING] Added account storage type parameter to `create_basic_wallet` and `create_basic_fungible_faucet` (miden-lib
crate only) (#587).
* Removed serialization of source locations from account code (#590).
- Removed serialization of source locations from account code (#590).

## 0.1.1 (2024-03-07) - `miden-objects` crate only

* Added `BlockHeader::mock()` method (#511)
- Added `BlockHeader::mock()` method (#511)

## 0.1.0 (2024-03-05)

* Initial release.
- Initial release.
31 changes: 21 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 10 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,18 @@ help:

WARNINGS=RUSTDOCFLAGS="-D warnings"
DEBUG_ASSERTIONS=RUSTFLAGS="-C debug-assertions"
ALL_FEATURES_BUT_ASYNC=--features concurrent,testing,serde

# -- linting --------------------------------------------------------------------------------------

.PHONY: clippy
clippy: ## Runs Clippy with configs
cargo +nightly clippy --workspace --all-targets --all-features -- -D warnings
cargo +nightly clippy --workspace --all-targets $(ALL_FEATURES_BUT_ASYNC) -- -D warnings


.PHONY: fix
fix: ## Runs Fix with configs
cargo +nightly fix --allow-staged --allow-dirty --all-targets --all-features
cargo +nightly fix --allow-staged --allow-dirty --all-targets $(ALL_FEATURES_BUT_ASYNC)


.PHONY: format
Expand All @@ -37,8 +38,8 @@ lint: format fix clippy ## Runs all linting tasks at once (Clippy, fixing, forma
# --- docs ----------------------------------------------------------------------------------------

.PHONY: doc
doc: ## Generates & checks documentation
$(WARNINGS) cargo doc --all-features --keep-going --release
doc: ## Generates & checks documentation
Copy link
Contributor Author

Choose a reason for hiding this comment

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

FYI @bobbinth the miden base does not pass the doc command + doc command is not in CI should we add it and make the repo pass?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes - that would be good. But if it adds a lot of work, I'd do it in a different PR.

$(WARNINGS) cargo doc $(ALL_FEATURES_BUT_ASYNC) --keep-going --release


.PHONY: doc-serve
Expand Down Expand Up @@ -71,6 +72,11 @@ build: ## By default we should build in release mode
build-no-std: ## Build without the standard library
cargo build --no-default-features --target wasm32-unknown-unknown --workspace --exclude miden-bench-tx

.PHONY: build-async
build-async: ## Build with the `async` feature enabled (only libraries)
cargo build --lib --release --features async


# --- benchmarking --------------------------------------------------------------------------------

.PHONY: bench-tx
Expand Down
2 changes: 2 additions & 0 deletions miden-tx/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ concurrent = ["miden-lib/concurrent", "miden-objects/concurrent", "miden-prover/
default = ["std"]
std = ["miden-lib/std", "miden-objects/std", "miden-prover/std", "miden-verifier/std", "vm-processor/std"]
testing = ["miden-objects/testing", "miden-lib/testing", "vm-processor/internals"]
async = ["winter-maybe-async/async"]

[dependencies]
miden-lib = { path = "../miden-lib", version = "0.4", default-features = false }
miden-objects = { path = "../objects", version = "0.4", default-features = false }
miden-prover = { workspace = true }
miden-verifier = { workspace = true }
rand = { workspace = true }
winter-maybe-async = "0.10.0"
vm-processor = { workspace = true }

[dev-dependencies]
Expand Down
3 changes: 3 additions & 0 deletions miden-tx/src/executor/data_store.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use miden_objects::{
accounts::AccountId, assembly::ModuleAst, notes::NoteId, transaction::TransactionInputs,
};
use winter_maybe_async::maybe_async;

use crate::DataStoreError;

Expand All @@ -25,6 +26,7 @@ pub trait DataStore {
/// - Any of the notes with the specified IDs were already consumed.
/// - The combination of specified inputs resulted in a transaction input error.
/// - The data store encountered some internal error
#[maybe_async]
fn get_transaction_inputs(
&self,
account_id: AccountId,
Expand All @@ -33,5 +35,6 @@ pub trait DataStore {
) -> Result<TransactionInputs, DataStoreError>;

/// Returns the account code [ModuleAst] associated with the specified [AccountId].
#[maybe_async]
fn get_account_code(&self, account_id: AccountId) -> Result<ModuleAst, DataStoreError>;
}
18 changes: 10 additions & 8 deletions miden-tx/src/executor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use miden_objects::{
Felt, Word, ZERO,
};
use vm_processor::ExecutionOptions;
use winter_maybe_async::{maybe_async, maybe_await};

use super::{
AccountCode, AccountId, Digest, ExecutedTransaction, NoteId, NoteScript, PreparedTransaction,
Expand Down Expand Up @@ -102,13 +103,12 @@ impl<D: DataStore, A: TransactionAuthenticator> TransactionExecutor<D, A> {
/// Returns an error if:
/// - If the account code cannot be fetched from the [DataStore].
/// - If the account code fails to be loaded into the compiler.
#[maybe_async]
pub fn load_account(
&mut self,
account_id: AccountId,
) -> Result<AccountCode, TransactionExecutorError> {
let account_code = self
.data_store
.get_account_code(account_id)
let account_code = maybe_await!(self.data_store.get_account_code(account_id))
.map_err(TransactionExecutorError::FetchAccountCodeFailed)?;
self.compiler
.load_account(account_id, account_code)
Expand Down Expand Up @@ -174,14 +174,16 @@ impl<D: DataStore, A: TransactionAuthenticator> TransactionExecutor<D, A> {
/// - If required data can not be fetched from the [DataStore].
/// - If the transaction program can not be compiled.
/// - If the transaction program can not be executed.
#[maybe_async]
pub fn execute_transaction(
&self,
account_id: AccountId,
block_ref: u32,
notes: &[NoteId],
tx_args: TransactionArgs,
) -> Result<ExecutedTransaction, TransactionExecutorError> {
let transaction = self.prepare_transaction(account_id, block_ref, notes, tx_args)?;
let transaction =
maybe_await!(self.prepare_transaction(account_id, block_ref, notes, tx_args))?;

let (stack_inputs, advice_inputs) = transaction.get_kernel_inputs();
let advice_recorder: RecAdviceProvider = advice_inputs.into();
Expand Down Expand Up @@ -221,17 +223,17 @@ impl<D: DataStore, A: TransactionAuthenticator> TransactionExecutor<D, A> {
/// Returns an error if:
/// - If required data can not be fetched from the [DataStore].
/// - If the transaction can not be compiled.
#[maybe_async]
pub fn prepare_transaction(
&self,
account_id: AccountId,
block_ref: u32,
notes: &[NoteId],
tx_args: TransactionArgs,
) -> Result<PreparedTransaction, TransactionExecutorError> {
let tx_inputs = self
.data_store
.get_transaction_inputs(account_id, block_ref, notes)
.map_err(TransactionExecutorError::FetchTransactionInputsFailed)?;
let tx_inputs =
maybe_await!(self.data_store.get_transaction_inputs(account_id, block_ref, notes))
.map_err(TransactionExecutorError::FetchTransactionInputsFailed)?;

let tx_program = self
.compiler
Expand Down
Loading
Loading