Skip to content

Commit

Permalink
chore: add dense_initial_pull
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielZhangReal committed Mar 22, 2023
1 parent e34e455 commit 4f00056
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 12 deletions.
8 changes: 4 additions & 4 deletions pallets/manta-pay/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -571,15 +571,15 @@ pub mod pallet {
pub fn initial_pull(checkpoint: Checkpoint, max_receivers: u64) -> InitialSyncResponse {
let (should_continue, receivers) =
Self::pull_receivers(*checkpoint.receiver_index, max_receivers);
let utxos = receivers.into_iter().map(|receiver| receiver.0).collect();
let paths = (0..=255)
let utxo_data = receivers.into_iter().map(|receiver| receiver.0).collect();
let membership_proof_data = (0..=255)
.map(|i| ShardTrees::<T>::get(i).current_path)
.collect();
let nullifier_count = NullifierSetSize::<T>::get() as u128;
InitialSyncResponse {
should_continue,
utxos,
paths,
utxo_data,
membership_proof_data,
nullifier_count,
}
}
Expand Down
13 changes: 7 additions & 6 deletions pallets/manta-pay/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

use crate::{
runtime::PullLedgerDiffApi,
types::{DensePullResponse, InitialSyncResponse},
types::{DensePullResponse, DenseInitialSyncResponse},
Checkpoint, PullResponse,
};
use alloc::sync::Arc;
Expand Down Expand Up @@ -57,12 +57,12 @@ pub trait PullApi {
) -> RpcResult<DensePullResponse>;

///
#[method(name = "mantaPay_initial_pull", blocking)]
fn initial_pull(
#[method(name = "mantaPay_dense_initial_pull", blocking)]
fn dense_initial_pull(
&self,
checkpoint: Checkpoint,
max_receivers: u64,
) -> RpcResult<InitialSyncResponse>;
) -> RpcResult<DenseInitialSyncResponse>;
}

/// Pull RPC API Implementation
Expand Down Expand Up @@ -134,14 +134,15 @@ where
}

#[inline]
fn initial_pull(
fn dense_initial_pull(
&self,
checkpoint: Checkpoint,
max_receivers: u64,
) -> RpcResult<InitialSyncResponse> {
) -> RpcResult<DenseInitialSyncResponse> {
let api = self.client.runtime_api();
let at = BlockId::hash(self.client.info().finalized_hash);
api.initial_pull(&at, checkpoint.into(), max_receivers)
.map(Into::into)
.map_err(|err| {
CallError::Custom(ErrorObject::owned(
PULL_LEDGER_DIFF_ERROR,
Expand Down
42 changes: 40 additions & 2 deletions pallets/manta-pay/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -906,15 +906,53 @@ pub struct InitialSyncResponse {
pub should_continue: bool,

/// Ledger Utxo Chunk
pub utxos: UtxoChunk,
pub utxo_data: UtxoChunk,

/// Ledger [`CurrentPath`] Chunk
pub paths: CurrentPathChunk,
pub membership_proof_data: CurrentPathChunk,

/// Nullifier Count
pub nullifier_count: u128,
}

/// Ledger Source Dense Pull Response
#[cfg_attr(
feature = "serde",
derive(Deserialize, Serialize),
serde(crate = "manta_util::serde", deny_unknown_fields)
)]
#[derive(Clone, Debug, Encode, Default, Eq, Hash, Decode, PartialEq, TypeInfo)]
pub struct DenseInitialSyncResponse {
/// Pull Continuation Flag
///
/// The `should_continue` flag is set to `true` if the client should request more data from the
/// ledger to finish the pull.
pub should_continue: bool,

/// Ledger Utxo Chunk
#[codec(skip)]
pub utxo_data: alloc::string::String,

/// Ledger [`CurrentPath`] Chunk
#[codec(skip)]
pub membership_proof_data: alloc::string::String,

/// Nullifier Count
pub nullifier_count: u128,
}

impl From<InitialSyncResponse> for DenseInitialSyncResponse {
#[inline]
fn from(resp: InitialSyncResponse) -> DenseInitialSyncResponse {
Self {
should_continue: resp.should_continue,
utxo_data: base64::encode(resp.utxo_data.encode()),
membership_proof_data: base64::encode(resp.membership_proof_data.encode()),
nullifier_count: resp.nullifier_count,
}
}
}

/// Ledger Source Pull Response
#[cfg_attr(
feature = "serde",
Expand Down

0 comments on commit 4f00056

Please sign in to comment.