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

feat: Make sync compatible with node's next #758

Merged
merged 7 commits into from
Feb 25, 2025
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* [BREAKING] Refactored authentication out of the `Client` and added new separate authenticators (#718).
* Re-exported RemoteTransactionProver in `rust-client` (#752).
* Moved error handling to the `TransactionRequestBuilder::build()` (#750).
* [BREAKING] Added starting block number parameter to `CheckNullifiersByPrefix` and removed nullifiers from `SyncState` (#758).

## 0.7.0 (2025-01-28)

Expand Down
93 changes: 40 additions & 53 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ WARNINGS=RUSTDOCFLAGS="-D warnings"

NODE_DIR="miden-node"
NODE_REPO="https://github.com/0xPolygonMiden/miden-node.git"
NODE_BRANCH="cf87d340f394d03bf376abff06a4b36149d63b24"
NODE_BRANCH="next"

PROVER_DIR="miden-base"
PROVER_REPO="https://github.com/0xPolygonMiden/miden-base.git"
Expand Down
18 changes: 4 additions & 14 deletions crates/rust-client/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,13 @@ use crate::{
domain::{
account::{AccountDetails, AccountProofs},
note::{NetworkNote, NoteSyncInfo},
nullifier::NullifierUpdate,
sync::StateSyncInfo,
},
generated::{
merkle::MerklePath,
note::NoteSyncRecord,
responses::{NullifierUpdate, SyncNoteResponse, SyncStateResponse},
responses::{SyncNoteResponse, SyncStateResponse},
},
NodeRpcClient, RpcError,
},
Expand Down Expand Up @@ -164,24 +165,13 @@ impl MockRpcApi {
// Collect notes that are in the next block
let notes = self.get_notes_in_block(next_block_num).collect();

// Collect nullifiers from the next block
let nullifiers = next_block
.created_nullifiers()
.iter()
.map(|n| NullifierUpdate {
nullifier: Some(n.inner().into()),
block_num: next_block_num.as_u32(),
})
.collect();

SyncStateResponse {
chain_tip: self.get_chain_tip_block_num().as_u32(),
block_header: Some(next_block.header().into()),
mmr_delta,
accounts: vec![],
transactions: vec![],
notes,
nullifiers,
}
}

Expand Down Expand Up @@ -229,7 +219,6 @@ impl NodeRpcClient for MockRpcApi {
block_num: BlockNumber,
_account_ids: &[AccountId],
_note_tags: &[NoteTag],
_nullifiers_tags: &[u16],
) -> Result<StateSyncInfo, RpcError> {
// Match request -> response through block_num
let response = self.get_sync_state_request(block_num);
Expand Down Expand Up @@ -303,7 +292,8 @@ impl NodeRpcClient for MockRpcApi {
async fn check_nullifiers_by_prefix(
&mut self,
_prefix: &[u16],
) -> Result<Vec<(miden_objects::note::Nullifier, u32)>, RpcError> {
_block_num: BlockNumber,
) -> Result<Vec<NullifierUpdate>, RpcError> {
// Always return an empty list for now since it's only used when importing
Ok(vec![])
}
Expand Down
9 changes: 7 additions & 2 deletions crates/rust-client/src/note/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,13 @@ impl<R: FeltRng> Client<R> {
.into(),
));

if let Some(block_height) =
self.rpc_api.get_nullifier_commit_height(&note_record.nullifier()).await?
if let Some(block_height) = self
.rpc_api
.get_nullifier_commit_height(
&note_record.nullifier(),
inclusion_proof.location().block_num(),
)
.await?
{
if note_record.consumed_externally(note_record.nullifier(), block_height)? {
return Ok(Some(note_record));
Expand Down
17 changes: 16 additions & 1 deletion crates/rust-client/src/rpc/domain/nullifier.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use miden_objects::{crypto::hash::rpo::RpoDigest, note::Nullifier};

use crate::rpc::{errors::RpcConversionError, generated::digest::Digest};
use super::MissingFieldHelper;
use crate::rpc::{self, errors::RpcConversionError, generated::digest::Digest};

// NULLIFIER UPDATE
// ================================================================================================
Expand All @@ -24,3 +25,17 @@ impl TryFrom<Digest> for Nullifier {
Ok(digest.into())
}
}

impl TryFrom<&rpc::generated::responses::NullifierUpdate> for NullifierUpdate {
type Error = RpcConversionError;

fn try_from(value: &rpc::generated::responses::NullifierUpdate) -> Result<Self, Self::Error> {
Ok(Self {
nullifier: value
.nullifier
.ok_or(rpc::generated::responses::NullifierUpdate::missing_field("nullifier"))?
.try_into()?,
block_num: value.block_num,
})
}
}
Loading