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

Vectorize transfers #3356

Merged
merged 9 commits into from
Jul 5, 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
2 changes: 2 additions & 0 deletions .changelog/unreleased/features/3356-vectorize-transfers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Reworked transparent and masp transfers to allow for multiple sources, targets,
tokens and amounts. ([\#3356](https://github.com/anoma/namada/pull/3356))
92 changes: 68 additions & 24 deletions crates/apps_lib/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4338,14 +4338,21 @@ pub mod args {
ctx: &mut Context,
) -> Result<TxTransparentTransfer<SdkTypes>, Self::Error> {
let tx = self.tx.to_sdk(ctx)?;
let mut data = vec![];
let chain_ctx = ctx.borrow_mut_chain_or_exit();

for transfer_data in self.data {
data.push(TxTransparentTransferData {
source: chain_ctx.get(&transfer_data.source),
target: chain_ctx.get(&transfer_data.target),
token: chain_ctx.get(&transfer_data.token),
amount: transfer_data.amount,
});
}

Ok(TxTransparentTransfer::<SdkTypes> {
tx,
source: chain_ctx.get(&self.source),
target: chain_ctx.get(&self.target),
token: chain_ctx.get(&self.token),
amount: self.amount,
data,
tx_code_path: self.tx_code_path.to_path_buf(),
})
}
Expand All @@ -4359,12 +4366,16 @@ pub mod args {
let token = TOKEN.parse(matches);
let amount = InputAmount::Unvalidated(AMOUNT.parse(matches));
let tx_code_path = PathBuf::from(TX_TRANSPARENT_TRANSFER_WASM);
Self {
tx,
let data = vec![TxTransparentTransferData {
source,
target,
token,
amount,
}];

Self {
tx,
data,
tx_code_path,
}
}
Expand Down Expand Up @@ -4393,14 +4404,21 @@ pub mod args {
ctx: &mut Context,
) -> Result<TxShieldedTransfer<SdkTypes>, Self::Error> {
let tx = self.tx.to_sdk(ctx)?;
let mut data = vec![];
let chain_ctx = ctx.borrow_mut_chain_or_exit();

for transfer_data in self.data {
data.push(TxShieldedTransferData {
source: chain_ctx.get_cached(&transfer_data.source),
target: chain_ctx.get(&transfer_data.target),
token: chain_ctx.get(&transfer_data.token),
amount: transfer_data.amount,
});
}

Ok(TxShieldedTransfer::<SdkTypes> {
tx,
source: chain_ctx.get_cached(&self.source),
target: chain_ctx.get(&self.target),
token: chain_ctx.get(&self.token),
amount: self.amount,
data,
tx_code_path: self.tx_code_path.to_path_buf(),
})
}
Expand All @@ -4414,12 +4432,16 @@ pub mod args {
let token = TOKEN.parse(matches);
let amount = InputAmount::Unvalidated(AMOUNT.parse(matches));
let tx_code_path = PathBuf::from(TX_SHIELDED_TRANSFER_WASM);
Self {
tx,
let data = vec![TxShieldedTransferData {
source,
target,
token,
amount,
}];

Self {
tx,
data,
tx_code_path,
}
}
Expand Down Expand Up @@ -4453,14 +4475,21 @@ pub mod args {
ctx: &mut Context,
) -> Result<TxShieldingTransfer<SdkTypes>, Self::Error> {
let tx = self.tx.to_sdk(ctx)?;
let mut data = vec![];
let chain_ctx = ctx.borrow_mut_chain_or_exit();

for transfer_data in self.data {
data.push(TxShieldingTransferData {
source: chain_ctx.get(&transfer_data.source),
token: chain_ctx.get(&transfer_data.token),
amount: transfer_data.amount,
});
}

Ok(TxShieldingTransfer::<SdkTypes> {
tx,
source: chain_ctx.get(&self.source),
data,
target: chain_ctx.get(&self.target),
token: chain_ctx.get(&self.token),
amount: self.amount,
tx_code_path: self.tx_code_path.to_path_buf(),
})
}
Expand All @@ -4474,12 +4503,16 @@ pub mod args {
let token = TOKEN.parse(matches);
let amount = InputAmount::Unvalidated(AMOUNT.parse(matches));
let tx_code_path = PathBuf::from(TX_SHIELDING_TRANSFER_WASM);
Self {
tx,
let data = vec![TxShieldingTransferData {
source,
target,
token,
amount,
}];

Self {
tx,
data,
target,
tx_code_path,
}
}
Expand Down Expand Up @@ -4514,14 +4547,21 @@ pub mod args {
ctx: &mut Context,
) -> Result<TxUnshieldingTransfer<SdkTypes>, Self::Error> {
let tx = self.tx.to_sdk(ctx)?;
let mut data = vec![];
let chain_ctx = ctx.borrow_mut_chain_or_exit();

for transfer_data in self.data {
data.push(TxUnshieldingTransferData {
target: chain_ctx.get(&transfer_data.target),
token: chain_ctx.get(&transfer_data.token),
amount: transfer_data.amount,
});
}

Ok(TxUnshieldingTransfer::<SdkTypes> {
tx,
data,
source: chain_ctx.get_cached(&self.source),
target: chain_ctx.get(&self.target),
token: chain_ctx.get(&self.token),
amount: self.amount,
tx_code_path: self.tx_code_path.to_path_buf(),
})
}
Expand All @@ -4535,12 +4575,16 @@ pub mod args {
let token = TOKEN.parse(matches);
let amount = InputAmount::Unvalidated(AMOUNT.parse(matches));
let tx_code_path = PathBuf::from(TX_UNSHIELDING_TRANSFER_WASM);
Self {
tx,
source,
let data = vec![TxUnshieldingTransferData {
target,
token,
amount,
}];

Self {
tx,
source,
data,
tx_code_path,
}
}
Expand Down
21 changes: 20 additions & 1 deletion crates/apps_lib/src/client/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,26 @@ pub async fn submit_transparent_transfer(
namada: &impl Namada,
args: args::TxTransparentTransfer,
) -> Result<(), error::Error> {
submit_reveal_aux(namada, args.tx.clone(), &args.source).await?;
if args.data.len() > 1 {
// TODO(namada#3379): Vectorized transfers are not yet supported in the
// CLI
return Err(error::Error::Other(
"Unexpected vectorized transparent transfer".to_string(),
));
}

submit_reveal_aux(
namada,
args.tx.clone(),
&args
.data
.first()
yito88 marked this conversation as resolved.
Show resolved Hide resolved
.ok_or_else(|| {
error::Error::Other("Missing transfer data".to_string())
})?
.source,
)
.await?;

let (mut tx, signing_data) = args.clone().build(namada).await?;

Expand Down
6 changes: 3 additions & 3 deletions crates/benches/host_env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use namada::core::account::AccountPublicKeysMap;
use namada::core::address;
use namada::core::collections::{HashMap, HashSet};
use namada::ledger::storage::DB;
use namada::token::{Amount, TransparentTransfer};
use namada::token::{Amount, TransparentTransfer, TransparentTransferData};
use namada::tx::Authorization;
use namada::vm::wasm::TxCache;
use namada_apps_lib::wallet::defaults;
Expand All @@ -18,12 +18,12 @@ use namada_node::bench_utils::{
// transaction
fn tx_section_signature_validation(c: &mut Criterion) {
let shell = BenchShell::default();
let transfer_data = TransparentTransfer {
let transfer_data = TransparentTransfer(vec![TransparentTransferData {
source: defaults::albert_address(),
target: defaults::bertha_address(),
token: address::testing::nam(),
amount: Amount::native_whole(500).native_denominated(),
};
}]);
let tx = shell.generate_tx(
TX_TRANSPARENT_TRANSFER_WASM,
transfer_data,
Expand Down
6 changes: 3 additions & 3 deletions crates/benches/native_vps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ use namada::sdk::masp_primitives::merkle_tree::CommitmentTree;
use namada::sdk::masp_primitives::transaction::Transaction;
use namada::sdk::masp_proofs::sapling::SaplingVerificationContextInner;
use namada::state::{Epoch, StorageRead, StorageWrite, TxIndex};
use namada::token::{Amount, TransparentTransfer};
use namada::token::{Amount, TransparentTransfer, TransparentTransferData};
use namada::tx::{BatchedTx, Code, Section, Tx};
use namada_apps_lib::wallet::defaults;
use namada_node::bench_utils::{
Expand Down Expand Up @@ -476,12 +476,12 @@ fn vp_multitoken(c: &mut Criterion) {

let transfer = shell.generate_tx(
TX_TRANSPARENT_TRANSFER_WASM,
TransparentTransfer {
TransparentTransfer(vec![TransparentTransferData {
source: defaults::albert_address(),
target: defaults::bertha_address(),
token: address::testing::nam(),
amount: Amount::native_whole(1000).native_denominated(),
},
}]),
None,
None,
vec![&defaults::albert_keypair()],
Expand Down
8 changes: 5 additions & 3 deletions crates/benches/process_wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ use namada::core::address;
use namada::core::key::RefTo;
use namada::core::storage::BlockHeight;
use namada::core::time::DateTimeUtc;
use namada::token::{Amount, DenominatedAmount, TransparentTransfer};
use namada::token::{
Amount, DenominatedAmount, TransparentTransfer, TransparentTransferData,
};
use namada::tx::data::{Fee, WrapperTx};
use namada::tx::Authorization;
use namada_apps_lib::wallet::defaults;
Expand All @@ -19,12 +21,12 @@ fn process_tx(c: &mut Criterion) {

let mut batched_tx = shell.generate_tx(
TX_TRANSPARENT_TRANSFER_WASM,
TransparentTransfer {
TransparentTransfer(vec![TransparentTransferData {
source: defaults::albert_address(),
target: defaults::bertha_address(),
token: address::testing::nam(),
amount: Amount::native_whole(1).native_denominated(),
},
}]),
None,
None,
vec![&defaults::albert_keypair()],
Expand Down
Loading
Loading