Skip to content

Commit

Permalink
Merge next
Browse files Browse the repository at this point in the history
  • Loading branch information
igamigo committed Jul 29, 2024
1 parent c63c75b commit 5f7b94e
Show file tree
Hide file tree
Showing 14 changed files with 624 additions and 46 deletions.
36 changes: 18 additions & 18 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ on:
types: [opened, reopened, synchronize]

jobs:
version:
name: check rust version consistency
clippy:
name: clippy nightly on ubuntu-latest
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@main
with:
profile: minimal
override: true
- name: check rust versions
run: ./scripts/check-rust-version.sh
- name: Clippy
run: |
rustup update --no-self-update nightly
rustup +nightly component add clippy
make clippy
rustfmt:
name: rustfmt check nightly on ubuntu-latest
Expand All @@ -31,17 +31,6 @@ jobs:
rustup +nightly component add rustfmt
make format-check
clippy:
name: clippy nightly on ubuntu-latest
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@main
- name: Clippy
run: |
rustup update --no-self-update nightly
rustup +nightly component add clippy
make clippy
doc:
name: doc stable on ubuntu-latest
runs-on: ubuntu-latest
Expand All @@ -51,3 +40,14 @@ jobs:
run: |
rustup update --no-self-update
make doc
version:
name: check rust version consistency
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@main
with:
profile: minimal
override: true
- name: check rust versions
run: ./scripts/check-rust-version.sh
10 changes: 6 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
- [BREAKING] Renamed public accessors of the `Block` struct to match the updated fields (#791).
- [BREAKING] Changed the `TransactionArgs` to use `AdviceInputs` (#793).
- Setters in `memory` module don't drop the setting `Word` anymore (#795).
- [BREAKING] Increase of nonce does not require changes in account state any more (#789).
- [BREAKING] Increase of nonce does not require changes in account state any more (#796).
- Added `CHANGELOG.md` warning message on CI (#799).
- Account deltas can now be merged (#797).

## 0.4.0 (2024-07-03)

Expand Down Expand Up @@ -43,9 +45,9 @@

## 0.3.1 (2024-06-12)

* Replaced `cargo-make` with just `make` for running tasks (#696).
* Made `DataStore` conditionally async using `winter-maybe-async` (#725)
* Fixed `StorageMap`s implementation and included into apply_delta (#745)
- Replaced `cargo-make` with just `make` for running tasks (#696).
- Made `DataStore` conditionally async using `winter-maybe-async` (#725)
- Fixed `StorageMap`s implementation and included into apply_delta (#745)

## 0.3.0 (2024-05-14)

Expand Down
162 changes: 162 additions & 0 deletions Cargo.lock

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

33 changes: 18 additions & 15 deletions miden-tx/tests/integration/scripts/p2id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,6 @@ use crate::{
prove_and_verify_transaction,
};

fn create_new_account() -> (Account, Word, Rc<BasicAuthenticator<StdRng>>) {
let (pub_key, falcon_auth) = get_new_pk_and_authenticator();

let storage_item = SlotItem::new_value(0, 0, pub_key);

let (account, seed) = AccountBuilder::new(ChaCha20Rng::from_entropy())
.add_storage_item(storage_item)
.account_type(AccountType::RegularAccountUpdatableCode)
.nonce(Felt::ZERO)
.build(&TransactionKernel::assembler())
.unwrap();

(account, seed, falcon_auth)
}

// P2ID TESTS
// ===============================================================================================
// We test the Pay to ID script. So we create a note that can only be consumed by the target
Expand Down Expand Up @@ -332,3 +317,21 @@ fn test_note_script_to_from_felt() {

assert_eq!(note_script, decoded);
}

// HELPER FUNCTIONS
// ===============================================================================================

fn create_new_account() -> (Account, Word, Rc<BasicAuthenticator<StdRng>>) {
let (pub_key, falcon_auth) = get_new_pk_and_authenticator();

let storage_item = SlotItem::new_value(0, 0, pub_key);

let (account, seed) = AccountBuilder::new(ChaCha20Rng::from_entropy())
.add_storage_item(storage_item)
.account_type(AccountType::RegularAccountUpdatableCode)
.nonce(Felt::ZERO)
.build(&TransactionKernel::assembler())
.unwrap();

(account, seed, falcon_auth)
}
1 change: 1 addition & 0 deletions objects/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,5 @@ winter-rand-utils = { version = "0.8", optional = true }
[dev-dependencies]
criterion = { version = "0.5", default-features = false, features = ["html_reports"] }
miden-objects = { path = ".", features = ["testing"] }
rstest = { version = "0.21" }
tempfile = { version = "3.0" }
45 changes: 45 additions & 0 deletions objects/src/accounts/delta/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,22 @@ impl AccountDelta {
Ok(Self { storage, vault, nonce })
}

/// Merge another [AccountDelta] into this one.
pub fn merge(self, other: Self) -> Result<Self, AccountDeltaError> {
let nonce = match (self.nonce, other.nonce) {
(Some(old), Some(new)) if new.as_int() <= old.as_int() => {
return Err(AccountDeltaError::InconsistentNonceUpdate(format!(
"New nonce {new} is not larger than the old nonce {old}"
)))
},
// Incoming nonce takes precedence.
(old, new) => new.or(old),
};
let storage = self.storage.merge(other.storage)?;
let vault = self.vault.merge(other.vault)?;
Self::new(storage, vault, nonce)
}

// PUBLIC ACCESSORS
// --------------------------------------------------------------------------------------------

Expand Down Expand Up @@ -103,6 +119,35 @@ impl AccountUpdateDetails {
pub fn is_private(&self) -> bool {
matches!(self, Self::Private)
}

/// Merges the `other` update into this one.
///
/// This account update is assumed to come before the other.
pub fn merge(self, other: AccountUpdateDetails) -> Result<Self, AccountDeltaError> {
let merged_update = match (self, other) {
(AccountUpdateDetails::Private, AccountUpdateDetails::Private) => {
AccountUpdateDetails::Private
},
(AccountUpdateDetails::New(mut account), AccountUpdateDetails::Delta(delta)) => {
account.apply_delta(&delta).map_err(|_| {
AccountDeltaError::IncompatibleAccountUpdates(
AccountUpdateDetails::New(account.clone()),
AccountUpdateDetails::Delta(delta),
)
})?;

AccountUpdateDetails::New(account)
},
(AccountUpdateDetails::Delta(initial), AccountUpdateDetails::Delta(new_delta)) => {
AccountUpdateDetails::Delta(initial.merge(new_delta)?)
},
(left, right) => {
return Err(AccountDeltaError::IncompatibleAccountUpdates(left, right))
},
};

Ok(merged_update)
}
}

// SERIALIZATION
Expand Down
Loading

0 comments on commit 5f7b94e

Please sign in to comment.