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

Early sapling balance check #3439

Merged
merged 40 commits into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from 39 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
e9f5a46
Vectorizes transparent transfers
grarco Jun 2, 2024
36e215b
Vectorizes masp transfers
grarco Jun 3, 2024
3eff3b4
Fixes benchmarks
grarco Jun 3, 2024
453b211
Fixes signature generation for vectorized transfers
grarco Jun 4, 2024
4a94e0e
Check no vectorized transfers in cli
grarco Jun 6, 2024
9d6c19d
Misc improvements to signing for vectorized transfers
grarco Jun 6, 2024
561e4e8
Avoids reloading shielded context
grarco Jun 6, 2024
3a77b4a
Fmt
grarco Jun 6, 2024
1e98403
Changelog #3356
grarco Jun 4, 2024
69980be
Introduces masp fee payment
grarco May 29, 2024
40401f4
Passes the correct tx index to masp fee payment check
grarco May 29, 2024
bece3de
Reworks masp fee payment to correctly handle errors. Misc refactors
grarco May 29, 2024
3d9ccc4
`check_fees` checks masp fee payment
grarco May 30, 2024
25dbf81
`check_fees` drop the storage changes in case of failure
grarco May 30, 2024
d5aafd5
Returns `BatchedTxResult` from masp fee payment
grarco May 30, 2024
606a0f0
Renames fee payment gas limit parameter
grarco May 30, 2024
2f072b0
Skips the execution of the first inner tx when masp fee payment
grarco May 31, 2024
ba943ef
Refactors batch execution in case of masp fee payment
grarco May 31, 2024
07522e2
Adds integration tests for masp fee payment
grarco Jun 2, 2024
5a1b578
Removes write log precommit and leverages the batch log
grarco Jun 4, 2024
0e2b488
Different gas cost for storage deletes
grarco Jun 4, 2024
92aafe7
Refactors the write log api
grarco Jun 4, 2024
120ad8e
Adds support for masp fee payment in sdk
grarco Jun 6, 2024
584d2eb
Removes unused denominate function
grarco Jun 7, 2024
9f390a7
Updates shielded wasm code to handle fee unshielding
grarco Jun 7, 2024
fb0df69
Fixes masp tx generation and integration tests
grarco Jun 8, 2024
217afe3
Masp fee payment for shielded actions
grarco Jun 12, 2024
13ea7b6
Adds missing gas spending key arg to ibc tx
grarco Jun 13, 2024
bab5cde
Changelog #3393
grarco Jun 13, 2024
9698bb7
Panics in fee payment if balance read fails
grarco Jun 14, 2024
70f40a6
Fixes typo
grarco Jun 14, 2024
4f89335
Reuses token transfer
grarco Jun 14, 2024
ed74656
Fixes broken docs
grarco Jun 14, 2024
6026c42
Fixes masp amounts conversion
grarco Jun 16, 2024
dc0316c
Fixes typo
grarco Jun 18, 2024
9e4d4c9
Removes useless write-log commit in fee payment
grarco Jun 21, 2024
13b4bcd
Renames misleading gas limit variable
grarco Jun 24, 2024
09df28b
Early sapling balance check in masp vp
grarco Jun 25, 2024
dd907d5
Changelog #2721
grarco Jun 25, 2024
a3bb632
Extracts the sapling value balance directly in `validate_transparent_…
grarco Jun 25, 2024
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))
2 changes: 2 additions & 0 deletions .changelog/unreleased/features/3393-masp-fee-payment.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Added support for fee payment directly from the MASP pool.
([\#3393](https://github.com/anoma/namada/pull/3393))
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Moved up the check on the sapling value balance in the masp vp.
([\#2721](https://github.com/anoma/namada/issues/2721))
141 changes: 117 additions & 24 deletions crates/apps_lib/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3221,6 +3221,8 @@ pub mod args {
"gas-limit",
DefaultFn(|| GasLimit::from(DEFAULT_GAS_LIMIT)),
);
pub const GAS_SPENDING_KEY: ArgOpt<WalletSpendingKey> =
arg_opt("gas-spending-key");
pub const FEE_TOKEN: ArgDefaultFromCtx<WalletAddrOrNativeToken> =
arg_default_from_ctx("gas-token", DefaultFn(|| "".parse().unwrap()));
pub const FEE_PAYER: Arg<WalletAddress> = arg("fee-payer");
Expand Down Expand Up @@ -4338,14 +4340,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 +4368,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 +4406,28 @@ 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,
});
}

let gas_spending_keys = self
.gas_spending_keys
.iter()
.map(|key| chain_ctx.get_cached(key))
.collect();

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,
gas_spending_keys,
tx_code_path: self.tx_code_path.to_path_buf(),
})
}
Expand All @@ -4414,12 +4441,21 @@ 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,
}];
let mut gas_spending_keys = vec![];
if let Some(key) = GAS_SPENDING_KEY.parse(matches) {
gas_spending_keys.push(key);
}

Self {
tx,
data,
gas_spending_keys,
tx_code_path,
}
}
Expand All @@ -4442,6 +4478,10 @@ pub mod args {
.def()
.help(wrap!("The amount to transfer in decimal.")),
)
.arg(GAS_SPENDING_KEY.def().help(wrap!(
"The optional spending key that will be used in addition \
to the source for gas payment."
)))
}
}

Expand All @@ -4453,14 +4493,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 +4521,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 +4565,27 @@ 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,
});
}
let gas_spending_keys = self
.gas_spending_keys
.iter()
.map(|key| chain_ctx.get_cached(key))
.collect();

Ok(TxUnshieldingTransfer::<SdkTypes> {
tx,
data,
gas_spending_keys,
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 +4599,21 @@ 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,
}];
let mut gas_spending_keys = vec![];
if let Some(key) = GAS_SPENDING_KEY.parse(matches) {
gas_spending_keys.push(key);
}

Self {
tx,
source,
data,
gas_spending_keys,
tx_code_path,
}
}
Expand All @@ -4563,6 +4636,10 @@ pub mod args {
.def()
.help(wrap!("The amount to transfer in decimal.")),
)
.arg(GAS_SPENDING_KEY.def().help(wrap!(
"The optional spending key that will be used in addition \
to the source for gas payment."
)))
}
}

Expand All @@ -4575,6 +4652,11 @@ pub mod args {
) -> Result<TxIbcTransfer<SdkTypes>, Self::Error> {
let tx = self.tx.to_sdk(ctx)?;
let chain_ctx = ctx.borrow_mut_chain_or_exit();
let gas_spending_keys = self
.gas_spending_keys
.iter()
.map(|key| chain_ctx.get_cached(key))
.collect();

Ok(TxIbcTransfer::<SdkTypes> {
tx,
Expand All @@ -4588,6 +4670,7 @@ pub mod args {
timeout_sec_offset: self.timeout_sec_offset,
refund_target: chain_ctx.get_opt(&self.refund_target),
memo: self.memo,
gas_spending_keys,
tx_code_path: self.tx_code_path.to_path_buf(),
})
}
Expand All @@ -4609,6 +4692,10 @@ pub mod args {
std::fs::read_to_string(path)
.expect("Expected a file at given path")
});
let mut gas_spending_keys = vec![];
if let Some(key) = GAS_SPENDING_KEY.parse(matches) {
gas_spending_keys.push(key);
}
let tx_code_path = PathBuf::from(TX_IBC_WASM);
Self {
tx,
Expand All @@ -4622,6 +4709,7 @@ pub mod args {
timeout_sec_offset,
refund_target,
memo,
gas_spending_keys,
tx_code_path,
}
}
Expand Down Expand Up @@ -4658,6 +4746,11 @@ pub mod args {
.arg(IBC_TRANSFER_MEMO_PATH.def().help(wrap!(
"The path for the memo field of ICS20 transfer."
)))
.arg(GAS_SPENDING_KEY.def().help(wrap!(
"The optional spending key that will be used in addition \
to the source for gas payment (if this is a shielded \
action)."
)))
}
}

Expand Down
8 changes: 4 additions & 4 deletions crates/apps_lib/src/client/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -660,16 +660,16 @@ pub async fn query_protocol_parameters(
.expect("Parameter should be defined.");
display_line!(context.io(), "{:4}Max block gas: {:?}", "", max_block_gas);

let key = param_storage::get_fee_unshielding_gas_limit_key();
let fee_unshielding_gas_limit: u64 =
let key = param_storage::get_masp_fee_payment_gas_limit_key();
let masp_fee_payment_gas_limit: u64 =
query_storage_value(context.client(), &key)
.await
.expect("Parameter should be defined.");
display_line!(
context.io(),
"{:4}Fee unshielding gas limit: {:?}",
"{:4}Masp fee payment gas limit: {:?}",
"",
fee_unshielding_gas_limit
masp_fee_payment_gas_limit
);

let key = param_storage::get_gas_cost_key();
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()
.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
4 changes: 2 additions & 2 deletions crates/apps_lib/src/config/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,8 @@ pub struct Parameters {
pub masp_epoch_multiplier: u64,
/// Maximum amount of signatures per transaction
pub max_signatures_per_transaction: u8,
/// Fee unshielding gas limit
pub fee_unshielding_gas_limit: u64,
/// The gas limit for a masp transaction paying fees
pub masp_fee_payment_gas_limit: u64,
/// Map of the cost per gas unit for every token allowed for fee payment
pub minimum_gas_price: BTreeMap<Address, token::Amount>,
}
Expand Down
4 changes: 2 additions & 2 deletions crates/apps_lib/src/config/genesis/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ impl Finalized {
epochs_per_year,
masp_epoch_multiplier,
max_signatures_per_transaction,
fee_unshielding_gas_limit,
masp_fee_payment_gas_limit,
max_block_gas,
minimum_gas_price,
max_tx_bytes,
Expand Down Expand Up @@ -350,7 +350,7 @@ impl Finalized {
masp_epoch_multiplier,
max_proposal_bytes,
max_signatures_per_transaction,
fee_unshielding_gas_limit,
masp_fee_payment_gas_limit,
max_block_gas,
minimum_gas_price: minimum_gas_price
.iter()
Expand Down
Loading
Loading