Skip to content

Commit

Permalink
Merge branch 'fraccaman+grarco/testnet-fee-fix' (#1019) into maint-0.13
Browse files Browse the repository at this point in the history
* fraccaman+grarco/testnet-fee-fix:
  changelog: add #1019
  Fixes wrapper fee check
  • Loading branch information
juped committed Jan 20, 2023
2 parents 84cea19 + 84c5785 commit 26ee42b
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 19 deletions.
2 changes: 2 additions & 0 deletions .changelog/unreleased/bug-fixes/1019-testnet-fee-fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Fixes testnet wrapper fee checks
([#1019](https://github.com/anoma/namada/pull/1019))
2 changes: 1 addition & 1 deletion apps/src/lib/client/signing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ pub async fn sign_wrapper(
let client = HttpClient::new(args.ledger_address.clone()).unwrap();

let fee_amount = if cfg!(feature = "mainnet") {
Amount::from(MIN_FEE)
Amount::whole(MIN_FEE)
} else {
let wrapper_tx_fees_key = parameter_storage::get_wrapper_tx_fees_key();
rpc::query_storage_value::<token::Amount>(&client, &wrapper_tx_fees_key)
Expand Down
4 changes: 2 additions & 2 deletions apps/src/lib/node/ledger/shell/finalize_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ mod test_finalize_block {
);
shell
.storage
.write(&balance_key, Amount::from(1000).try_to_vec().unwrap())
.write(&balance_key, Amount::whole(1000).try_to_vec().unwrap())
.unwrap();

// create some wrapper txs
Expand Down Expand Up @@ -675,7 +675,7 @@ mod test_finalize_block {
);
shell
.storage
.write(&balance_key, Amount::from(1000).try_to_vec().unwrap())
.write(&balance_key, Amount::whole(1000).try_to_vec().unwrap())
.unwrap();

// create two decrypted txs
Expand Down
6 changes: 3 additions & 3 deletions apps/src/lib/node/ledger/shell/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ use namada::types::internal::WrapperTxInQueue;
use namada::types::key::*;
use namada::types::storage::{BlockHeight, Key, TxIndex};
use namada::types::time::{DateTimeUtc, TimeZone, Utc};
use namada::types::token::{self, Amount};
use namada::types::token::{self};
use namada::types::transaction::{
hash_tx, process_tx, verify_decrypted_correctly, AffineCurve, DecryptedTx,
EllipticCurve, PairingEngine, TxType, MIN_FEE,
Expand Down Expand Up @@ -597,7 +597,7 @@ where
#[cfg(feature = "mainnet")]
let has_valid_pow = false;

if !has_valid_pow && Amount::from(MIN_FEE) > balance {
if !has_valid_pow && self.get_wrapper_tx_fees() > balance {
response.code = 1;
response.log = String::from(
"The address given does not have sufficient \
Expand Down Expand Up @@ -728,7 +728,7 @@ where
&self.storage,
)
.expect("Must be able to read wrapper tx fees parameter");
fees.unwrap_or_default()
fees.unwrap_or(token::Amount::whole(MIN_FEE))
}

#[cfg(not(feature = "mainnet"))]
Expand Down
16 changes: 5 additions & 11 deletions apps/src/lib/node/ledger/shell/process_proposal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,9 @@ where
#[cfg(feature = "mainnet")]
let has_valid_pow = false;

if has_valid_pow || Amount::from(MIN_FEE) <= balance {
if has_valid_pow
|| self.get_wrapper_tx_fees() <= balance
{
TxResult {
code: ErrorCodes::Ok.into(),
info: "Process proposal accepted this \
Expand Down Expand Up @@ -408,14 +410,6 @@ mod test_process_proposal {
#[test]
fn test_wrapper_insufficient_balance_address() {
let (mut shell, _) = TestShell::new();
shell.init_chain(RequestInitChain {
time: Some(Timestamp {
seconds: 0,
nanos: 0,
}),
chain_id: ChainId::default().to_string(),
..Default::default()
});
let keypair = crate::wallet::defaults::daewon_keypair();
// reduce address balance to match the 100 token fee
let balance_key = token::balance_key(
Expand All @@ -424,7 +418,7 @@ mod test_process_proposal {
);
shell
.storage
.write(&balance_key, Amount::from(99).try_to_vec().unwrap())
.write(&balance_key, Amount::whole(99).try_to_vec().unwrap())
.unwrap();

let tx = Tx::new(
Expand All @@ -433,7 +427,7 @@ mod test_process_proposal {
);
let wrapper = WrapperTx::new(
Fee {
amount: Amount::whole(1_000_100),
amount: Amount::whole(100),
token: shell.storage.native_token.clone(),
},
&keypair,
Expand Down
4 changes: 2 additions & 2 deletions core/src/ledger/parameters/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -478,10 +478,10 @@ where
let (value, gas_wrapper_tx_fees) = storage
.read(&wrapper_tx_fees_key)
.map_err(ReadError::StorageError)?;
let address: Option<token::Amount> = value
let fee: Option<token::Amount> = value
.map(|value| decode(value).map_err(ReadError::StorageTypeError))
.transpose()?;
Ok((address, gas_wrapper_tx_fees))
Ok((fee, gas_wrapper_tx_fees))
}

// Read the all the parameters from storage. Returns the parameters and gas
Expand Down

0 comments on commit 26ee42b

Please sign in to comment.