Skip to content

Commit

Permalink
Merge branch 'grarco/remove-pin-key' (#3142)
Browse files Browse the repository at this point in the history
* origin/grarco/remove-pin-key:
  Removes `query_tx_deltas`
  Changelog #2675
  Removes unused errors and integration test
  Fixes econding. Updates shielded keys and addresses for tests
  Adjusts wasm txs and client args
  Removes masp pin key
  Rmoves old allowlisted gas
  • Loading branch information
brentstone committed May 8, 2024
2 parents 316e496 + b3fff8d commit 78125b9
Show file tree
Hide file tree
Showing 32 changed files with 59 additions and 953 deletions.
2 changes: 2 additions & 0 deletions .changelog/unreleased/improvements/2675-remove-pin-key.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Removed the MASP pin key.
([\#2675](https://github.com/anoma/namada/issues/2675))
3 changes: 1 addition & 2 deletions crates/apps/src/lib/bench_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -983,7 +983,7 @@ impl Default for BenchShieldedCtx {
.wallet
.insert_payment_addr(
alias,
PaymentAddress::from(payment_addr).pinned(false),
PaymentAddress::from(payment_addr),
true,
)
.unwrap();
Expand Down Expand Up @@ -1076,7 +1076,6 @@ impl BenchShieldedCtx {
} else {
DenominatedAmount::native(amount)
},
key: None,
shielded: shielded_section_hash,
},
shielded,
Expand Down
8 changes: 0 additions & 8 deletions crates/apps/src/lib/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3184,7 +3184,6 @@ pub mod args {
pub const OWNER: Arg<WalletAddress> = arg("owner");
pub const OWNER_OPT: ArgOpt<WalletAddress> = OWNER.opt();
pub const PATH: Arg<PathBuf> = arg("path");
pub const PIN: ArgFlag = flag("pin");
pub const PORT_ID: ArgDefault<PortId> = arg_default(
"port-id",
DefaultFn(|| PortId::from_str("transfer").unwrap()),
Expand Down Expand Up @@ -6778,7 +6777,6 @@ pub mod args {
alias: self.alias,
alias_force: self.alias_force,
viewing_key,
pin: self.pin,
})
}
}
Expand All @@ -6788,12 +6786,10 @@ pub mod args {
let alias = ALIAS.parse(matches);
let alias_force = ALIAS_FORCE.parse(matches);
let viewing_key = VIEWING_KEY.parse(matches);
let pin = PIN.parse(matches);
Self {
alias,
alias_force,
viewing_key,
pin,
}
}

Expand All @@ -6807,10 +6803,6 @@ pub mod args {
"Override the alias without confirmation if it already exists.",
))
.arg(VIEWING_KEY.def().help("The viewing key."))
.arg(PIN.def().help(
"Require that the single transaction to this address be \
pinned.",
))
}
}

Expand Down
3 changes: 0 additions & 3 deletions crates/apps/src/lib/cli/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -621,8 +621,5 @@ impl ArgFromMutContext for BalanceOwner {
ExtendedViewingKey::arg_from_mut_ctx(ctx, raw)
.map(Self::FullViewingKey)
})
.or_else(|_| {
PaymentAddress::arg_from_ctx(ctx, raw).map(Self::PaymentAddress)
})
}
}
3 changes: 1 addition & 2 deletions crates/apps/src/lib/cli/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,6 @@ fn payment_address_gen(
alias,
alias_force,
viewing_key,
pin,
..
}: args::PayAddressGen,
) {
Expand All @@ -326,7 +325,7 @@ fn payment_address_gen(
let masp_payment_addr = viewing_key
.to_payment_address(div)
.expect("a PaymentAddress");
let payment_addr = PaymentAddress::from(masp_payment_addr).pinned(pin);
let payment_addr = PaymentAddress::from(masp_payment_addr);
let alias = wallet
.insert_payment_addr(alias, payment_addr, alias_force)
.unwrap_or_else(|| {
Expand Down
206 changes: 4 additions & 202 deletions crates/apps/src/lib/client/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,19 @@

use std::collections::{BTreeMap, BTreeSet};
use std::io;
use std::str::FromStr;

use borsh::BorshDeserialize;
use data_encoding::HEXLOWER;
use masp_primitives::asset_type::AssetType;
use masp_primitives::merkle_tree::MerklePath;
use masp_primitives::sapling::{Node, ViewingKey};
use masp_primitives::sapling::Node;
use masp_primitives::transaction::components::I128Sum;
use masp_primitives::zip32::ExtendedFullViewingKey;
use namada::core::address::{Address, InternalAddress, MASP, MULTITOKEN};
use namada::core::collections::{HashMap, HashSet};
use namada::core::hash::Hash;
use namada::core::key::*;
use namada::core::masp::{BalanceOwner, ExtendedViewingKey, PaymentAddress};
use namada::core::masp::BalanceOwner;
use namada::core::storage::{BlockHeight, BlockResults, Epoch, Key, KeySeg};
use namada::core::token::MaspDigitPos;
use namada::governance::parameters::GovernanceParameters;
Expand All @@ -39,9 +38,7 @@ use namada::proof_of_stake::types::{
};
use namada::{state as storage, token};
use namada_sdk::control_flow::time::{Duration, Instant};
use namada_sdk::error::{
is_pinned_error, Error, PinnedBalanceError, QueryError,
};
use namada_sdk::error::QueryError;
use namada_sdk::masp::MaspTokenRewardData;
use namada_sdk::proof_of_stake::types::ValidatorMetaData;
use namada_sdk::queries::Client;
Expand All @@ -51,7 +48,7 @@ use namada_sdk::rpc::{
use namada_sdk::tendermint_rpc::endpoint::status;
use namada_sdk::tx::display_inner_resp;
use namada_sdk::wallet::AddressVpType;
use namada_sdk::{display, display_line, edisplay_line, error, prompt, Namada};
use namada_sdk::{display, display_line, edisplay_line, error, Namada};

use crate::cli::{self, args};
use crate::facade::tendermint::merkle::proof::ProofOps;
Expand Down Expand Up @@ -193,12 +190,7 @@ pub async fn query_balance(context: &impl Namada, args: args::QueryBalance) {
Some(BalanceOwner::Address(_owner)) => {
query_transparent_balance(context, args).await
}
Some(BalanceOwner::PaymentAddress(_owner)) => {
query_pinned_balance(context, args).await
}
None => {
// Print pinned balance
query_pinned_balance(context, args.clone()).await;
// Print shielded balance
query_shielded_balance(context, args.clone()).await;
// Then print transparent balance
Expand Down Expand Up @@ -300,196 +292,6 @@ pub async fn query_transparent_balance(
}
}

/// Query the token pinned balance(s)
pub async fn query_pinned_balance(
context: &impl Namada,
args: args::QueryBalance,
) {
// Map addresses to token names
let wallet = context.wallet().await;
let owners = if let Some(pa) = args.owner.and_then(|x| x.payment_address())
{
vec![pa]
} else {
wallet
.get_payment_addrs()
.into_values()
.filter(PaymentAddress::is_pinned)
.collect()
};
// Get the viewing keys with which to try note decryptions
let viewing_keys: Vec<ViewingKey> = wallet
.get_viewing_keys()
.values()
.map(|fvk| ExtendedFullViewingKey::from(*fvk).fvk.vk)
.collect();
let _ = context.shielded_mut().await.load().await;
// Precompute asset types to increase chances of success in decoding
let token_map =
query_tokens(context, args.token.as_ref(), None, args.show_ibc_tokens)
.await;
let tokens = token_map.values().collect();
let _ = context
.shielded_mut()
.await
.precompute_asset_types(context.client(), tokens)
.await;
// Print the token balances by payment address
for owner in owners {
let mut balance =
Err(Error::from(PinnedBalanceError::InvalidViewingKey));
// Find the viewing key that can recognize payments the current payment
// address
for vk in &viewing_keys {
balance = context
.shielded_mut()
.await
.compute_exchanged_pinned_balance(context, owner, vk)
.await;
if !is_pinned_error(&balance) {
break;
}
}
// If a suitable viewing key was not found, then demand it from the user
if is_pinned_error(&balance) {
let vk_str =
prompt!(context.io(), "Enter the viewing key for {}: ", owner)
.await;
let fvk = match ExtendedViewingKey::from_str(vk_str.trim()) {
Ok(fvk) => fvk,
_ => {
edisplay_line!(context.io(), "Invalid viewing key entered");
continue;
}
};
let vk = ExtendedFullViewingKey::from(fvk).fvk.vk;
// Use the given viewing key to decrypt pinned transaction data
balance = context
.shielded_mut()
.await
.compute_exchanged_pinned_balance(context, owner, &vk)
.await
}

// Now print out the received quantities according to CLI arguments
match (balance, args.token.as_ref()) {
(Err(Error::Pinned(PinnedBalanceError::InvalidViewingKey)), _) => {
display_line!(
context.io(),
"Supplied viewing key cannot decode transactions to given \
payment address."
)
}
(
Err(Error::Pinned(PinnedBalanceError::NoTransactionPinned)),
_,
) => {
display_line!(
context.io(),
"Payment address {} has not yet been consumed.",
owner
)
}
(Err(other), _) => {
display_line!(
context.io(),
"Error in Querying Pinned balance {}",
other
)
}
(Ok((balance, _undecoded, epoch)), Some(base_token)) => {
let tokens = query_tokens(
context,
Some(base_token),
None,
args.show_ibc_tokens,
)
.await;
for (token_alias, token) in &tokens {
let total_balance = balance
.0
.get(&token.clone())
.cloned()
.unwrap_or_default();

if total_balance.is_zero() {
display_line!(
context.io(),
"Payment address {} was consumed during epoch {}. \
Received no shielded {}",
owner,
epoch,
token_alias
);
} else {
let formatted = context
.format_amount(token, total_balance.into())
.await;
display_line!(
context.io(),
"Payment address {} was consumed during epoch {}. \
Received {} {}",
owner,
epoch,
formatted,
token_alias,
);
}
}
}
(Ok((balance, undecoded, epoch)), None) => {
let mut found_any = false;

for (token_addr, value) in balance.components() {
if !found_any {
display_line!(
context.io(),
"Payment address {} was consumed during epoch {}. \
Received:",
owner,
epoch
);
found_any = true;
}
let formatted = context
.format_amount(token_addr, (*value).into())
.await;
let token_alias =
lookup_token_alias(context, token_addr, &MASP).await;
display_line!(
context.io(),
" {}: {}",
token_alias,
formatted,
);
}
for (asset_type, value) in undecoded.components() {
if !found_any {
display_line!(
context.io(),
"Payment address {} was consumed during epoch {}. \
Received:",
owner,
epoch
);
found_any = true;
}
display_line!(context.io(), " {}: {}", asset_type, value,);
}
if !found_any {
display_line!(
context.io(),
"Payment address {} was consumed during epoch {}. \
Received no shielded assets.",
owner,
epoch
);
}
}
}
}
}

async fn print_balances(
context: &impl Namada,
balances: impl Iterator<Item = (storage::Key, token::Amount)>,
Expand Down
1 change: 0 additions & 1 deletion crates/benches/host_env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ fn tx_section_signature_validation(c: &mut Criterion) {
target: defaults::bertha_address(),
token: address::testing::nam(),
amount: Amount::native_whole(500).native_denominated(),
key: None,
shielded: None,
};
let tx = shell.generate_tx(
Expand Down
1 change: 0 additions & 1 deletion crates/benches/native_vps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,6 @@ fn vp_multitoken(c: &mut Criterion) {
target: defaults::bertha_address(),
token: address::testing::nam(),
amount: Amount::native_whole(1000).native_denominated(),
key: None,
shielded: None,
},
None,
Expand Down
1 change: 0 additions & 1 deletion crates/benches/process_wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ fn process_tx(c: &mut Criterion) {
target: defaults::bertha_address(),
token: address::testing::nam(),
amount: Amount::native_whole(1).native_denominated(),
key: None,
shielded: None,
},
None,
Expand Down
4 changes: 0 additions & 4 deletions crates/benches/vps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ fn vp_implicit(c: &mut Criterion) {
target: defaults::bertha_address(),
token: address::testing::nam(),
amount: Amount::native_whole(500).native_denominated(),
key: None,
shielded: None,
},
None,
Expand All @@ -60,7 +59,6 @@ fn vp_implicit(c: &mut Criterion) {
target: Address::from(&implicit_account.to_public()),
token: address::testing::nam(),
amount: Amount::native_whole(1000).native_denominated(),
key: None,
shielded: None,
},
None,
Expand Down Expand Up @@ -189,7 +187,6 @@ fn vp_user(c: &mut Criterion) {
target: defaults::bertha_address(),
token: address::testing::nam(),
amount: Amount::native_whole(1000).native_denominated(),
key: None,
shielded: None,
},
None,
Expand All @@ -204,7 +201,6 @@ fn vp_user(c: &mut Criterion) {
target: defaults::validator_address(),
token: address::testing::nam(),
amount: Amount::native_whole(1000).native_denominated(),
key: None,
shielded: None,
},
None,
Expand Down
Loading

0 comments on commit 78125b9

Please sign in to comment.