Skip to content

Commit 142ae31

Browse files
committed
Modified consensus verify and usize to u64 casting to support the new rust-bitcoin api
1 parent 00ba739 commit 142ae31

File tree

5 files changed

+29
-19
lines changed

5 files changed

+29
-19
lines changed

src/ln/chan_utils.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ pub fn get_revokeable_redeemscript(revocation_key: &PublicKey, to_self_delay: u1
133133
.push_slice(&revocation_key.serialize())
134134
.push_opcode(opcodes::all::OP_ELSE)
135135
.push_int(to_self_delay as i64)
136-
.push_opcode(opcodes::OP_CSV)
136+
.push_opcode(opcodes::all::OP_CSV)
137137
.push_opcode(opcodes::all::OP_DROP)
138138
.push_slice(&delayed_payment_key.serialize())
139139
.push_opcode(opcodes::all::OP_ENDIF)
@@ -206,7 +206,7 @@ pub fn get_htlc_redeemscript_with_explicit_keys(htlc: &HTLCOutputInCommitment, a
206206
.push_opcode(opcodes::all::OP_ELSE)
207207
.push_opcode(opcodes::all::OP_DROP)
208208
.push_int(htlc.cltv_expiry as i64)
209-
.push_opcode(opcodes::OP_CLTV)
209+
.push_opcode(opcodes::all::OP_CLTV)
210210
.push_opcode(opcodes::all::OP_DROP)
211211
.push_opcode(opcodes::all::OP_CHECKSIG)
212212
.push_opcode(opcodes::all::OP_ENDIF)

src/ln/channel.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2784,7 +2784,7 @@ impl Channel {
27842784
}
27852785
}
27862786

2787-
let proposed_sat_per_kw = msg.fee_satoshis * 1000 / closing_tx.get_weight();
2787+
let proposed_sat_per_kw = msg.fee_satoshis * 1000 / closing_tx.get_weight() as u64;
27882788
if self.channel_outbound {
27892789
let our_max_feerate = fee_estimator.get_est_sat_per_1000_weight(ConfirmationTarget::Normal);
27902790
if proposed_sat_per_kw > our_max_feerate {

src/ln/channelmonitor.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -488,13 +488,13 @@ macro_rules! subtract_high_prio_fee {
488488
($self: ident, $fee_estimator: expr, $value: expr, $predicted_weight: expr, $spent_txid: expr, $used_feerate: expr) => {
489489
{
490490
$used_feerate = $fee_estimator.get_est_sat_per_1000_weight(ConfirmationTarget::HighPriority);
491-
let mut fee = $used_feerate * $predicted_weight / 1000;
491+
let mut fee = $used_feerate * ($predicted_weight as u64) / 1000;
492492
if $value <= fee {
493493
$used_feerate = $fee_estimator.get_est_sat_per_1000_weight(ConfirmationTarget::Normal);
494-
fee = $used_feerate * $predicted_weight / 1000;
494+
fee = $used_feerate * ($predicted_weight as u64) / 1000;
495495
if $value <= fee {
496496
$used_feerate = $fee_estimator.get_est_sat_per_1000_weight(ConfirmationTarget::Background);
497-
fee = $used_feerate * $predicted_weight / 1000;
497+
fee = $used_feerate * ($predicted_weight as u64) / 1000;
498498
if $value <= fee {
499499
log_error!($self, "Failed to generate an on-chain punishment tx spending {} as even low priority fee ({} sat) was more than the entire claim balance ({} sat)",
500500
$spent_txid, fee, $value);
@@ -602,7 +602,7 @@ impl ChannelMonitor {
602602
}
603603
}
604604

605-
fn get_witnesses_weight(inputs: &[InputDescriptors]) -> u64 {
605+
fn get_witnesses_weight(inputs: &[InputDescriptors]) -> usize {
606606
let mut tx_weight = 2; // count segwit flags
607607
for inp in inputs {
608608
// We use expected weight (and not actual) as signatures and time lock delays may vary
@@ -3307,7 +3307,7 @@ mod tests {
33073307
let secp_ctx = Secp256k1::new();
33083308
let privkey = SecretKey::from_slice(&hex::decode("0101010101010101010101010101010101010101010101010101010101010101").unwrap()[..]).unwrap();
33093309
let pubkey = PublicKey::from_secret_key(&secp_ctx, &privkey);
3310-
let mut sum_actual_sigs: u64 = 0;
3310+
let mut sum_actual_sigs = 0;
33113311

33123312
macro_rules! sign_input {
33133313
($sighash_parts: expr, $input: expr, $idx: expr, $amount: expr, $input_type: expr, $sum_actual_sigs: expr) => {
@@ -3323,7 +3323,7 @@ mod tests {
33233323
let sig = secp_ctx.sign(&sighash, &privkey);
33243324
$input.witness.push(sig.serialize_der().to_vec());
33253325
$input.witness[0].push(SigHashType::All as u8);
3326-
sum_actual_sigs += $input.witness[0].len() as u64;
3326+
sum_actual_sigs += $input.witness[0].len();
33273327
if *$input_type == InputDescriptors::RevokedOutput {
33283328
$input.witness.push(vec!(1));
33293329
} else if *$input_type == InputDescriptors::RevokedOfferedHTLC || *$input_type == InputDescriptors::RevokedReceivedHTLC {
@@ -3366,7 +3366,7 @@ mod tests {
33663366
for (idx, inp) in claim_tx.input.iter_mut().zip(inputs_des.iter()).enumerate() {
33673367
sign_input!(sighash_parts, inp.0, idx as u32, 0, inp.1, sum_actual_sigs);
33683368
}
3369-
assert_eq!(base_weight + ChannelMonitor::get_witnesses_weight(&inputs_des[..]), claim_tx.get_weight() + /* max_length_sig */ (73 * inputs_des.len() as u64 - sum_actual_sigs));
3369+
assert_eq!(base_weight + ChannelMonitor::get_witnesses_weight(&inputs_des[..]), claim_tx.get_weight() + /* max_length_sig */ (73 * inputs_des.len() - sum_actual_sigs));
33703370

33713371
// Claim tx with 1 offered HTLCs, 3 received HTLCs
33723372
claim_tx.input.clear();
@@ -3388,7 +3388,7 @@ mod tests {
33883388
for (idx, inp) in claim_tx.input.iter_mut().zip(inputs_des.iter()).enumerate() {
33893389
sign_input!(sighash_parts, inp.0, idx as u32, 0, inp.1, sum_actual_sigs);
33903390
}
3391-
assert_eq!(base_weight + ChannelMonitor::get_witnesses_weight(&inputs_des[..]), claim_tx.get_weight() + /* max_length_sig */ (73 * inputs_des.len() as u64 - sum_actual_sigs));
3391+
assert_eq!(base_weight + ChannelMonitor::get_witnesses_weight(&inputs_des[..]), claim_tx.get_weight() + /* max_length_sig */ (73 * inputs_des.len() - sum_actual_sigs));
33923392

33933393
// Justice tx with 1 revoked HTLC-Success tx output
33943394
claim_tx.input.clear();
@@ -3408,7 +3408,7 @@ mod tests {
34083408
for (idx, inp) in claim_tx.input.iter_mut().zip(inputs_des.iter()).enumerate() {
34093409
sign_input!(sighash_parts, inp.0, idx as u32, 0, inp.1, sum_actual_sigs);
34103410
}
3411-
assert_eq!(base_weight + ChannelMonitor::get_witnesses_weight(&inputs_des[..]), claim_tx.get_weight() + /* max_length_isg */ (73 * inputs_des.len() as u64 - sum_actual_sigs));
3411+
assert_eq!(base_weight + ChannelMonitor::get_witnesses_weight(&inputs_des[..]), claim_tx.get_weight() + /* max_length_isg */ (73 * inputs_des.len() - sum_actual_sigs));
34123412
}
34133413

34143414
// Further testing is done in the ChannelManager integration tests.

src/ln/functional_test_utils.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -307,10 +307,13 @@ pub fn create_announced_chan_between_nodes_with_value(nodes: &Vec<Node>, a: usiz
307307
macro_rules! check_spends {
308308
($tx: expr, $spends_tx: expr) => {
309309
{
310-
let mut funding_tx_map = HashMap::new();
311-
let spends_tx = $spends_tx;
312-
funding_tx_map.insert(spends_tx.txid(), spends_tx);
313-
$tx.verify(&funding_tx_map).unwrap();
310+
$tx.verify(|out_point| {
311+
if out_point.txid == $spends_tx.txid() {
312+
$spends_tx.output.get(out_point.vout as usize).cloned()
313+
} else {
314+
None
315+
}
316+
}).unwrap();
314317
}
315318
}
316319
}

src/ln/functional_tests.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2032,9 +2032,16 @@ fn claim_htlc_outputs_single_tx() {
20322032

20332033
let mut revoked_tx_map = HashMap::new();
20342034
revoked_tx_map.insert(revoked_local_txn[0].txid(), revoked_local_txn[0].clone());
2035-
node_txn[0].verify(&revoked_tx_map).unwrap();
2036-
node_txn[1].verify(&revoked_tx_map).unwrap();
2037-
node_txn[2].verify(&revoked_tx_map).unwrap();
2035+
let closure = |out_point: &BitcoinOutPoint| {
2036+
if out_point.txid == revoked_local_txn[0].txid() {
2037+
revoked_local_txn[0].output.get(out_point.vout as usize).cloned()
2038+
} else {
2039+
None
2040+
}
2041+
};
2042+
node_txn[0].verify(closure).unwrap();
2043+
node_txn[1].verify(closure).unwrap();
2044+
node_txn[2].verify(closure).unwrap();
20382045

20392046
let mut witness_lens = BTreeSet::new();
20402047
witness_lens.insert(node_txn[0].input[0].witness.last().unwrap().len());

0 commit comments

Comments
 (0)