Skip to content

Commit d47cfcd

Browse files
Switch all feerate u64's to u32's.
The protocol only allows a u32, so if we received or sent something larger it would be an issue (though it's unlikely).
1 parent 4c655b2 commit d47cfcd

13 files changed

+76
-76
lines changed

fuzz/src/chanmon_consistency.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ use std::io::Cursor;
5252

5353
struct FuzzEstimator {}
5454
impl FeeEstimator for FuzzEstimator {
55-
fn get_est_sat_per_1000_weight(&self, _: ConfirmationTarget) -> u64 {
55+
fn get_est_sat_per_1000_weight(&self, _: ConfirmationTarget) -> u32 {
5656
253
5757
}
5858
}

fuzz/src/full_stack.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,10 @@ struct FuzzEstimator {
9494
input: Arc<InputData>,
9595
}
9696
impl FeeEstimator for FuzzEstimator {
97-
fn get_est_sat_per_1000_weight(&self, _: ConfirmationTarget) -> u64 {
97+
fn get_est_sat_per_1000_weight(&self, _: ConfirmationTarget) -> u32 {
9898
//TODO: We should actually be testing at least much more than 64k...
9999
match self.input.get_slice(2) {
100-
Some(slice) => cmp::max(slice_to_be16(slice) as u64, 253),
100+
Some(slice) => cmp::max(slice_to_be16(slice) as u32, 253),
101101
None => 253
102102
}
103103
}

lightning/src/chain/chaininterface.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,11 @@ pub trait FeeEstimator: Sync + Send {
119119
/// This translates to:
120120
/// * satoshis-per-byte * 250
121121
/// * ceil(satoshis-per-kbyte / 4)
122-
fn get_est_sat_per_1000_weight(&self, confirmation_target: ConfirmationTarget) -> u64;
122+
fn get_est_sat_per_1000_weight(&self, confirmation_target: ConfirmationTarget) -> u32;
123123
}
124124

125125
/// Minimum relay fee as required by bitcoin network mempool policy.
126-
pub const MIN_RELAY_FEE_SAT_PER_1000_WEIGHT: u64 = 4000;
126+
pub const MIN_RELAY_FEE_SAT_PER_1000_WEIGHT: u32 = 4000;
127127

128128
/// Utility for tracking registered txn/outpoints and checking for matches
129129
#[cfg_attr(test, derive(PartialEq))]

lightning/src/chain/keysinterface.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ pub trait ChannelKeys : Send+Clone {
211211
// TODO: Document the things someone using this interface should enforce before signing.
212212
// TODO: Add more input vars to enable better checking (preferably removing commitment_tx and
213213
// making the callee generate it via some util function we expose)!
214-
fn sign_remote_commitment<T: secp256k1::Signing + secp256k1::Verification>(&self, feerate_per_kw: u64, commitment_tx: &Transaction, keys: &TxCreationKeys, htlcs: &[&HTLCOutputInCommitment], to_self_delay: u16, secp_ctx: &Secp256k1<T>) -> Result<(Signature, Vec<Signature>), ()>;
214+
fn sign_remote_commitment<T: secp256k1::Signing + secp256k1::Verification>(&self, feerate_per_kw: u32, commitment_tx: &Transaction, keys: &TxCreationKeys, htlcs: &[&HTLCOutputInCommitment], to_self_delay: u16, secp_ctx: &Secp256k1<T>) -> Result<(Signature, Vec<Signature>), ()>;
215215

216216
/// Create a signature for a local commitment transaction. This will only ever be called with
217217
/// the same local_commitment_tx (or a copy thereof), though there are currently no guarantees
@@ -408,7 +408,7 @@ impl ChannelKeys for InMemoryChannelKeys {
408408
fn pubkeys<'a>(&'a self) -> &'a ChannelPublicKeys { &self.local_channel_pubkeys }
409409
fn key_derivation_params(&self) -> (u64, u64) { self.key_derivation_params }
410410

411-
fn sign_remote_commitment<T: secp256k1::Signing + secp256k1::Verification>(&self, feerate_per_kw: u64, commitment_tx: &Transaction, keys: &TxCreationKeys, htlcs: &[&HTLCOutputInCommitment], to_self_delay: u16, secp_ctx: &Secp256k1<T>) -> Result<(Signature, Vec<Signature>), ()> {
411+
fn sign_remote_commitment<T: secp256k1::Signing + secp256k1::Verification>(&self, feerate_per_kw: u32, commitment_tx: &Transaction, keys: &TxCreationKeys, htlcs: &[&HTLCOutputInCommitment], to_self_delay: u16, secp_ctx: &Secp256k1<T>) -> Result<(Signature, Vec<Signature>), ()> {
412412
if commitment_tx.input.len() != 1 { return Err(()); }
413413

414414
let funding_pubkey = PublicKey::from_secret_key(secp_ctx, &self.funding_key);

lightning/src/ln/chan_utils.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ pub fn make_funding_redeemscript(a: &PublicKey, b: &PublicKey) -> Script {
462462
}
463463

464464
/// panics if htlc.transaction_output_index.is_none()!
465-
pub fn build_htlc_transaction(prev_hash: &Txid, feerate_per_kw: u64, to_self_delay: u16, htlc: &HTLCOutputInCommitment, a_delayed_payment_key: &PublicKey, revocation_key: &PublicKey) -> Transaction {
465+
pub fn build_htlc_transaction(prev_hash: &Txid, feerate_per_kw: u32, to_self_delay: u16, htlc: &HTLCOutputInCommitment, a_delayed_payment_key: &PublicKey, revocation_key: &PublicKey) -> Transaction {
466466
let mut txins: Vec<TxIn> = Vec::new();
467467
txins.push(TxIn {
468468
previous_output: OutPoint {
@@ -475,15 +475,15 @@ pub fn build_htlc_transaction(prev_hash: &Txid, feerate_per_kw: u64, to_self_del
475475
});
476476

477477
let total_fee = if htlc.offered {
478-
feerate_per_kw * HTLC_TIMEOUT_TX_WEIGHT / 1000
478+
feerate_per_kw * HTLC_TIMEOUT_TX_WEIGHT as u32 / 1000
479479
} else {
480-
feerate_per_kw * HTLC_SUCCESS_TX_WEIGHT / 1000
480+
feerate_per_kw * HTLC_SUCCESS_TX_WEIGHT as u32 / 1000
481481
};
482482

483483
let mut txouts: Vec<TxOut> = Vec::new();
484484
txouts.push(TxOut {
485485
script_pubkey: get_revokeable_redeemscript(revocation_key, to_self_delay, a_delayed_payment_key).to_v0_p2wsh(),
486-
value: htlc.amount_msat / 1000 - total_fee //TODO: BOLT 3 does not specify if we should add amount_msat before dividing or if we should divide by 1000 before subtracting (as we do here)
486+
value: htlc.amount_msat / 1000 - total_fee as u64 //TODO: BOLT 3 does not specify if we should add amount_msat before dividing or if we should divide by 1000 before subtracting (as we do here)
487487
});
488488

489489
Transaction {
@@ -513,7 +513,7 @@ pub struct LocalCommitmentTransaction {
513513
pub local_keys: TxCreationKeys,
514514
/// The feerate paid per 1000-weight-unit in this commitment transaction. This value is
515515
/// controlled by the channel initiator.
516-
pub feerate_per_kw: u64,
516+
pub feerate_per_kw: u32,
517517
/// The HTLCs and remote htlc signatures which were included in this commitment transaction.
518518
///
519519
/// Note that this includes all HTLCs, including ones which were considered dust and not
@@ -561,7 +561,7 @@ impl LocalCommitmentTransaction {
561561

562562
/// Generate a new LocalCommitmentTransaction based on a raw commitment transaction,
563563
/// remote signature and both parties keys
564-
pub(crate) fn new_missing_local_sig(unsigned_tx: Transaction, their_sig: Signature, our_funding_key: &PublicKey, their_funding_key: &PublicKey, local_keys: TxCreationKeys, feerate_per_kw: u64, htlc_data: Vec<(HTLCOutputInCommitment, Option<Signature>)>) -> LocalCommitmentTransaction {
564+
pub(crate) fn new_missing_local_sig(unsigned_tx: Transaction, their_sig: Signature, our_funding_key: &PublicKey, their_funding_key: &PublicKey, local_keys: TxCreationKeys, feerate_per_kw: u32, htlc_data: Vec<(HTLCOutputInCommitment, Option<Signature>)>) -> LocalCommitmentTransaction {
565565
if unsigned_tx.input.len() != 1 { panic!("Tried to store a commitment transaction that had input count != 1!"); }
566566
if unsigned_tx.input[0].witness.len() != 0 { panic!("Tried to store a signed commitment transaction?"); }
567567

0 commit comments

Comments
 (0)