From dc0dbc62bef4453da115465d391aa7402f21431b Mon Sep 17 00:00:00 2001 From: AntiochP <30642645+antiochp@users.noreply.github.com> Date: Tue, 10 Oct 2017 13:30:34 -0400 Subject: [PATCH] Set approximate wallet fee to avoid LowFeeTransaction (#163) Set approximate wallet fee when building a transaction so we avoid getting a LowFeeTransaction error from the pool * rustfmt --- pool/src/pool.rs | 7 ++++++- wallet/src/receiver.rs | 11 +++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/pool/src/pool.rs b/pool/src/pool.rs index 4cad0a803..8500e4bd4 100644 --- a/pool/src/pool.rs +++ b/pool/src/pool.rs @@ -567,6 +567,11 @@ where // TODO evict old/large transactions instead return Err(PoolError::OverCapacity); } + + // for a basic transaction (1 input, 2 outputs) - + // (-1 * 1) + (4 * 2) + 1 = 8 + // 8 * 10 = 80 + // if self.config.accept_fee_base > 0 { let mut tx_weight = -1 * (tx.inputs.len() as i32) + (4 * tx.outputs.len() as i32) + 1; if tx_weight < 1 { @@ -1055,7 +1060,7 @@ mod tests { fn test_setup(dummy_chain: &Arc) -> TransactionPool { TransactionPool { - config: PoolConfig{ + config: PoolConfig { accept_fee_base: 0, max_pool_size: 10_000, }, diff --git a/wallet/src/receiver.rs b/wallet/src/receiver.rs index 1c7894291..4519b8b3c 100644 --- a/wallet/src/receiver.rs +++ b/wallet/src/receiver.rs @@ -234,10 +234,13 @@ fn receive_transaction( let derivation = wallet_data.next_child(fingerprint.clone()); let pubkey = keychain.derive_pubkey(derivation)?; - // TODO - replace with real fee calculation - // TODO - note we are not enforcing this in consensus anywhere yet - // Note: consensus rules require this to be an even value so it can be split - let fee_amount = 10; + // from pool.rs + // (-1 * num_inputs) + (4 * num_outputs) + 1 + // then multiply by accept_fee_base==10 + // so 80 is basically the minimum fee for a basic transaction + // so lets use 100 for now (revisit this) + + let fee_amount = 100; let out_amount = amount - fee_amount; let (tx_final, _) = build::transaction(vec![