Skip to content

Commit

Permalink
remove height argument from fee related functions as per fixpastfees …
Browse files Browse the repository at this point in the history
…RFC (#602)

* remove height argument from fee related functions as per fixpastfees RFC

* Cargo.lock updated from cargo update -p grin_core
  • Loading branch information
tromp authored May 19, 2021
1 parent 83fd8ff commit b7f587f
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 43 deletions.
36 changes: 18 additions & 18 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 4 additions & 5 deletions controller/src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use crate::core::consensus::YEAR_HEIGHT;
use crate::core::core::FeeFields;
use crate::core::core::{self, amount_to_hr_string};
use crate::core::global;
Expand Down Expand Up @@ -191,7 +190,7 @@ pub fn txs(
let amount_debited_str = core::amount_to_hr_string(t.amount_debited, true);
let amount_credited_str = core::amount_to_hr_string(t.amount_credited, true);
let fee = match t.fee {
Some(f) => format!("{}", core::amount_to_hr_string(f.fee(cur_height), true)),
Some(f) => format!("{}", core::amount_to_hr_string(f.fee(), true)),
None => "None".to_owned(),
};
let net_diff = if t.amount_credited >= t.amount_debited {
Expand Down Expand Up @@ -418,13 +417,13 @@ pub fn estimate(
if dark_background_color_scheme {
table.add_row(row![
bFC->strategy,
FR->amount_to_hr_string(fee_fields.fee(2*YEAR_HEIGHT), false), // apply fee mask past HF4
FR->amount_to_hr_string(fee_fields.fee(), false), // apply fee mask past HF4
FY->amount_to_hr_string(total, false),
]);
} else {
table.add_row(row![
bFD->strategy,
FR->amount_to_hr_string(fee_fields.fee(2*YEAR_HEIGHT), false), // apply fee mask past HF4
FR->amount_to_hr_string(fee_fields.fee(), false), // apply fee mask past HF4
FY->amount_to_hr_string(total, false),
]);
}
Expand Down Expand Up @@ -486,7 +485,7 @@ pub fn payment_proof(tx: &TxLogEntry) -> Result<(), Error> {
None => "None".to_owned(),
};
let fee = match tx.fee {
Some(f) => f.fee(2 * YEAR_HEIGHT), // apply fee mask past HF4
Some(f) => f.fee(), // apply fee mask past HF4
None => 0,
};
let amount = if tx.amount_credited >= tx.amount_debited {
Expand Down
4 changes: 2 additions & 2 deletions controller/tests/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ fn basic_transaction_api(test_dir: &'static str) -> Result<(), libwallet::Error>
let est = sender_api.init_send_tx(m, init_args)?;
assert_eq!(est.amount, 600_000_000_000);
// fees for 5 inputs, 2 outputs, 1 kernel (weight 50)
assert_eq!(est.fee_fields.fee(0), 25_000_000);
assert_eq!(est.fee_fields.fee(), 25_000_000);

let init_args = InitTxArgs {
src_acct_name: None,
Expand All @@ -287,7 +287,7 @@ fn basic_transaction_api(test_dir: &'static str) -> Result<(), libwallet::Error>
let est = sender_api.init_send_tx(m, init_args)?;
assert_eq!(est.amount, 180_000_000_000);
// fees for 3 inputs, 2 outputs, 1 kernel (weight 48)
assert_eq!(est.fee_fields.fee(0), 24_000_000);
assert_eq!(est.fee_fields.fee(), 24_000_000);

Ok(())
})?;
Expand Down
2 changes: 1 addition & 1 deletion impls/src/test_framework/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ where
K: keychain::Keychain + 'a,
{
// build block fees
let fee_amt = txs.iter().map(|tx| tx.fee(prev.height + 1)).sum();
let fee_amt = txs.iter().map(|tx| tx.fee()).sum();
let block_fees = BlockFees {
fees: fee_amt,
key_id: None,
Expand Down
7 changes: 3 additions & 4 deletions libwallet/src/api_impl/owner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

use uuid::Uuid;

use crate::grin_core::consensus::YEAR_HEIGHT;
use crate::grin_core::core::hash::Hashed;
use crate::grin_core::core::Transaction;
use crate::grin_util::secp::key::SecretKey;
Expand Down Expand Up @@ -404,7 +403,7 @@ where
tx.amount_credited - tx.amount_debited
} else {
let fee = match tx.fee {
Some(f) => f.fee(2 * YEAR_HEIGHT), // apply fee mask past HF4
Some(f) => f.fee(), // apply fee mask past HF4
None => 0,
};
tx.amount_debited - tx.amount_credited - fee
Expand Down Expand Up @@ -800,7 +799,7 @@ where
args.max_outputs as usize,
args.num_change_outputs as usize,
args.selection_strategy_is_use_all,
Some(context.fee.map(|f| f.fee(current_height)).unwrap_or(0)),
Some(context.fee.map(|f| f.fee()).unwrap_or(0)),
parent_key_id.clone(),
false,
true,
Expand Down Expand Up @@ -907,7 +906,7 @@ where
Some(tx) => {
let mut slate = Slate::blank(2, false);
slate.tx = Some(tx.clone());
slate.fee_fields = tx.aggregate_fee_fields(2 * YEAR_HEIGHT).unwrap(); // apply fee mask past HF4
slate.fee_fields = tx.aggregate_fee_fields().unwrap(); // apply fee mask past HF4
slate.id = id;
slate.offset = tx.offset;
slate.state = SlateState::Standard3;
Expand Down
18 changes: 7 additions & 11 deletions libwallet/src/slate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
//! around during an interactive wallet exchange

use crate::error::{Error, ErrorKind};
use crate::grin_core::consensus::YEAR_HEIGHT;
use crate::grin_core::core::amount_to_hr_string;
use crate::grin_core::core::transaction::{
FeeFields, Input, Inputs, KernelFeatures, NRDRelativeHeight, Output, OutputFeatures,
Expand Down Expand Up @@ -552,21 +551,18 @@ impl Slate {
// we could just overwrite the fee here (but we won't) due to the sig
let fee = tx_fee(tx.inputs().len(), tx.outputs().len(), tx.kernels().len());

if fee > tx.fee(2 * YEAR_HEIGHT) {
if fee > tx.fee() {
// apply fee mask past HF4
return Err(ErrorKind::Fee(format!(
"Fee Dispute Error: {}, {}",
tx.fee(2 * YEAR_HEIGHT),
fee,
))
.into());
return Err(
ErrorKind::Fee(format!("Fee Dispute Error: {}, {}", tx.fee(), fee,)).into(),
);
}

if fee > self.amount + self.fee_fields.fee(2 * YEAR_HEIGHT) {
if fee > self.amount + self.fee_fields.fee() {
let reason = format!(
"Rejected the transfer because transaction fee ({}) exceeds received amount ({}).",
amount_to_hr_string(fee, false),
amount_to_hr_string(self.amount + self.fee_fields.fee(2 * YEAR_HEIGHT), false)
amount_to_hr_string(self.amount + self.fee_fields.fee(), false)
);
info!("{}", reason);
return Err(ErrorKind::Fee(reason).into());
Expand Down Expand Up @@ -675,7 +671,7 @@ impl Slate {

// confirm the overall transaction is valid (including the updated kernel)
// accounting for tx weight limits
if let Err(e) = final_tx.validate(Weighting::AsTransaction, 0) {
if let Err(e) = final_tx.validate(Weighting::AsTransaction) {
error!("Error with final tx validation: {}", e);
Err(e.into())
} else {
Expand Down
3 changes: 1 addition & 2 deletions libwallet/src/slate_versions/v4_bin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

//! Wraps a V4 Slate into a V4 Binary slate

use crate::grin_core::consensus::YEAR_HEIGHT;
use crate::grin_core::core::transaction::{FeeFields, OutputFeatures};
use crate::grin_core::ser as grin_ser;
use crate::grin_core::ser::{Readable, Reader, Writeable, Writer};
Expand Down Expand Up @@ -108,7 +107,7 @@ impl Writeable for SlateOptFields {
if self.amt > 0 {
status |= 0x02;
}
if self.fee.fee(2 * YEAR_HEIGHT) > 0 {
if self.fee.fee() > 0 {
// apply fee mask past HF4
status |= 0x04;
}
Expand Down

0 comments on commit b7f587f

Please sign in to comment.