Skip to content

Commit

Permalink
chore: update miden-base dependency to fixed version
Browse files Browse the repository at this point in the history
refactor: extract `apply_delta` function
fix: separate error invariant for missed details in store
fix: make account details optional
refactor: introduce `UpdatedAccount` struct
fix: avoid cloning of block data
feat: simple details validation in store
feat: rewrite `sql::upsert_accounts` to simplified work with details and update test
fix: compilation errors
feat: use serialized account details
feat: writing account details on block applying
  • Loading branch information
polydez committed Apr 6, 2024
1 parent 0932b78 commit d338bda
Show file tree
Hide file tree
Showing 24 changed files with 542 additions and 105 deletions.
152 changes: 148 additions & 4 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ exclude = [".github/"]
[workspace.dependencies]
miden-air = { version = "0.9", default-features = false }
miden-lib = { git = "https://github.com/0xPolygonMiden/miden-base.git", branch = "next" }
miden-mock = { git = "https://github.com/0xPolygonMiden/miden-base.git", branch = "next" }
miden-objects = { git = "https://github.com/0xPolygonMiden/miden-base.git", branch = "next" }
miden-processor = { version = "0.9" }
miden-stdlib = { version = "0.9", default-features = false }
Expand All @@ -36,3 +37,4 @@ tracing-subscriber = { version = "0.3", features = [
"json",
"env-filter",
] }
winter-rand-utils = "0.8.3"
15 changes: 9 additions & 6 deletions block-producer/src/batch_builder/batch.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use std::collections::BTreeMap;

use miden_node_proto::domain::accounts::UpdatedAccount;
use miden_node_proto::domain::accounts::AccountDetailsUpdate;
use miden_objects::{
accounts::AccountId,
batches::BatchNoteTree,
crypto::hash::blake::{Blake3Digest, Blake3_256},
notes::{NoteEnvelope, Nullifier},
transaction::AccountDetails,
Digest, MAX_NOTES_PER_BATCH,
};
use tracing::instrument;
Expand Down Expand Up @@ -54,6 +55,7 @@ impl TransactionBatch {
AccountStates {
initial_state: tx.initial_account_hash(),
final_state: tx.final_account_hash(),
details: tx.account_details().cloned(),
},
)
})
Expand Down Expand Up @@ -107,15 +109,15 @@ impl TransactionBatch {
.map(|(account_id, account_states)| (*account_id, account_states.initial_state))
}

/// Returns an iterator over (account_id, new_state_hash) tuples for accounts that were
/// Returns an iterator over (account_id, details, new_state_hash) tuples for accounts that were
/// modified in this transaction batch.
pub fn updated_accounts(&self) -> impl Iterator<Item = UpdatedAccount> + '_ {
pub fn updated_accounts(&self) -> impl Iterator<Item = AccountDetailsUpdate> + '_ {
self.updated_accounts
.iter()
.map(|(&account_id, account_states)| UpdatedAccount {
.map(|(&account_id, account_states)| AccountDetailsUpdate {
account_id,
final_state_hash: account_states.final_state,
details: None, // TODO: In the next PR: account_states.details.clone(),
details: account_states.details.clone(),
})
}

Expand Down Expand Up @@ -150,8 +152,9 @@ impl TransactionBatch {
/// account.
///
/// TODO: should this be moved into domain objects?
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
#[derive(Debug, Clone, PartialEq, Eq)]
struct AccountStates {
initial_state: Digest,
final_state: Digest,
details: Option<AccountDetails>,
}
5 changes: 2 additions & 3 deletions block-producer/src/block.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::collections::BTreeMap;

use miden_node_proto::{
domain::accounts::UpdatedAccount,
domain::accounts::AccountDetailsUpdate,
errors::{ConversionError, MissingFieldHelper},
generated::responses::GetBlockInputsResponse,
AccountInputRecord, NullifierWitness,
Expand All @@ -18,11 +18,10 @@ use crate::store::BlockInputsError;
#[derive(Debug, Clone)]
pub struct Block {
pub header: BlockHeader,
pub updated_accounts: Vec<UpdatedAccount>,
pub updated_accounts: Vec<AccountDetailsUpdate>,
pub created_notes: Vec<(usize, usize, NoteEnvelope)>,
pub produced_nullifiers: Vec<Nullifier>,
// TODO:
// - full states for updated public accounts
// - full states for created public notes
// - zk proof
}
Expand Down
2 changes: 1 addition & 1 deletion block-producer/src/block_builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ where
info!(target: COMPONENT, block_num, %block_hash, "block built");
debug!(target: COMPONENT, ?block);

self.state_view.apply_block(block).await?;
self.state_view.apply_block(&block).await?;

info!(target: COMPONENT, block_num, %block_hash, "block committed");

Expand Down
Loading

0 comments on commit d338bda

Please sign in to comment.