projects
/
rust-lightning
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
8b6434e
)
WIP
master
rlwt
author
Matt Corallo
<git@bluematt.me>
Tue, 24 Mar 2020 00:24:32 +0000
(20:24 -0400)
committer
Matt Corallo
<git@bluematt.me>
Mon, 25 May 2020 19:36:59 +0000
(15:36 -0400)
lightning/src/ln/chan_utils.rs
patch
|
blob
|
history
lightning/src/ln/channel.rs
patch
|
blob
|
history
lightning/src/ln/functional_test_utils.rs
patch
|
blob
|
history
lightning/src/ln/onchaintx.rs
patch
|
blob
|
history
diff --git
a/lightning/src/ln/chan_utils.rs
b/lightning/src/ln/chan_utils.rs
index c229819c3b64e6d3e875002c814190a1d40e153e..2d0af708f2c5e801759d391bec6f3d15e68afa56 100644
(file)
--- a/
lightning/src/ln/chan_utils.rs
+++ b/
lightning/src/ln/chan_utils.rs
@@
-26,8
+26,8
@@
use std::{cmp, mem};
const MAX_ALLOC_SIZE: usize = 64*1024;
const MAX_ALLOC_SIZE: usize = 64*1024;
-pub(super) const HTLC_SUCCESS_TX_WEIGHT: u64 = 703;
-pub(super) const HTLC_TIMEOUT_TX_WEIGHT: u64 = 663;
+pub(super) const HTLC_SUCCESS_TX_WEIGHT: u64 = 703;
// XXX
+pub(super) const HTLC_TIMEOUT_TX_WEIGHT: u64 = 663;
// XXX
#[derive(PartialEq)]
pub(crate) enum HTLCType {
#[derive(PartialEq)]
pub(crate) enum HTLCType {
@@
-38,9
+38,9
@@
pub(crate) enum HTLCType {
impl HTLCType {
/// Check if a given tx witnessScript len matchs one of a pre-signed HTLC
pub(crate) fn scriptlen_to_htlctype(witness_script_len: usize) -> Option<HTLCType> {
impl HTLCType {
/// Check if a given tx witnessScript len matchs one of a pre-signed HTLC
pub(crate) fn scriptlen_to_htlctype(witness_script_len: usize) -> Option<HTLCType> {
- if witness_script_len == 13
3
{
+ if witness_script_len == 13
6
{
Some(HTLCType::OfferedHTLC)
Some(HTLCType::OfferedHTLC)
- } else if witness_script_len >= 13
6 && witness_script_len <= 139
{
+ } else if witness_script_len >= 13
9 && witness_script_len <= 142
{
Some(HTLCType::AcceptedHTLC)
} else {
None
Some(HTLCType::AcceptedHTLC)
} else {
None
@@
-385,6
+385,9
@@
pub(crate) fn get_htlc_redeemscript_with_explicit_keys(htlc: &HTLCOutputInCommit
.push_opcode(opcodes::all::OP_CHECKSIG)
.push_opcode(opcodes::all::OP_ENDIF)
.push_opcode(opcodes::all::OP_ENDIF)
.push_opcode(opcodes::all::OP_CHECKSIG)
.push_opcode(opcodes::all::OP_ENDIF)
.push_opcode(opcodes::all::OP_ENDIF)
+ .push_int(1)
+ .push_opcode(opcodes::all::OP_CSV)
+ .push_opcode(opcodes::all::OP_DROP)
.into_script()
} else {
Builder::new().push_opcode(opcodes::all::OP_DUP)
.into_script()
} else {
Builder::new().push_opcode(opcodes::all::OP_DUP)
@@
-416,6
+419,9
@@
pub(crate) fn get_htlc_redeemscript_with_explicit_keys(htlc: &HTLCOutputInCommit
.push_opcode(opcodes::all::OP_CHECKSIG)
.push_opcode(opcodes::all::OP_ENDIF)
.push_opcode(opcodes::all::OP_ENDIF)
.push_opcode(opcodes::all::OP_CHECKSIG)
.push_opcode(opcodes::all::OP_ENDIF)
.push_opcode(opcodes::all::OP_ENDIF)
+ .push_int(1)
+ .push_opcode(opcodes::all::OP_CSV)
+ .push_opcode(opcodes::all::OP_DROP)
.into_script()
}
}
.into_script()
}
}
@@
-452,7
+458,7
@@
pub fn build_htlc_transaction(prev_hash: &Txid, feerate_per_kw: u64, to_self_del
vout: htlc.transaction_output_index.expect("Can't build an HTLC transaction for a dust output"),
},
script_sig: Script::new(),
vout: htlc.transaction_output_index.expect("Can't build an HTLC transaction for a dust output"),
},
script_sig: Script::new(),
- sequence:
0
,
+ sequence:
1
,
witness: Vec::new(),
});
witness: Vec::new(),
});
diff --git
a/lightning/src/ln/channel.rs
b/lightning/src/ln/channel.rs
index e22186ec2d8aae254b6f869fece0ab4ffa0548b6..9a586254beaad85cce559fa898846db5135b2ffe 100644
(file)
--- a/
lightning/src/ln/channel.rs
+++ b/
lightning/src/ln/channel.rs
@@
-961,6
+961,8
@@
impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
} else {
(value_to_self_msat / 1000, value_to_remote_msat / 1000 - total_fee as i64 - ANCHOR_VALUE_SATOSHIS as i64)
};
} else {
(value_to_self_msat / 1000, value_to_remote_msat / 1000 - total_fee as i64 - ANCHOR_VALUE_SATOSHIS as i64)
};
+ debug_assert!(value_to_self >= 0);
+ debug_assert!(value_to_remote >= 0);
let value_to_a = if local { value_to_self } else { value_to_remote };
let value_to_b = if local { value_to_remote } else { value_to_self };
let value_to_a = if local { value_to_self } else { value_to_remote };
let value_to_b = if local { value_to_remote } else { value_to_self };
@@
-998,6
+1000,7
@@
impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
}, None));
}
}, None));
}
+
transaction_utils::sort_outputs(&mut txouts, |a, b| {
if let &Some(ref a_htlc) = a {
if let &Some(ref b_htlc) = b {
transaction_utils::sort_outputs(&mut txouts, |a, b| {
if let &Some(ref a_htlc) = a {
if let &Some(ref b_htlc) = b {
@@
-4443,8
+4446,6
@@
mod tests {
#[test]
fn outbound_commitment_test() {
#[test]
fn outbound_commitment_test() {
- return; // Disabled as we don't have test vectors for the currently-partially-implemented option_anchor_outputs
-
// Test vectors from BOLT 3 Appendix C:
let feeest = TestFeeEstimator{fee_est: 15000};
let logger : Arc<Logger> = Arc::new(test_utils::TestLogger::new());
// Test vectors from BOLT 3 Appendix C:
let feeest = TestFeeEstimator{fee_est: 15000};
let logger : Arc<Logger> = Arc::new(test_utils::TestLogger::new());
diff --git
a/lightning/src/ln/functional_test_utils.rs
b/lightning/src/ln/functional_test_utils.rs
index a8c4d279763950e8dda2b5d326c7587c4e089214..890ce010a292a12d11e99eb3a2f58a77881696c9 100644
(file)
--- a/
lightning/src/ln/functional_test_utils.rs
+++ b/
lightning/src/ln/functional_test_utils.rs
@@
-1119,8
+1119,8
@@
pub fn create_network<'a, 'b: 'a, 'c: 'b>(node_count: usize, cfgs: &'b Vec<NodeC
nodes
}
nodes
}
-pub const ACCEPTED_HTLC_SCRIPT_WEIGHT: usize = 1
38
; //Here we have a diff due to HTLC CLTV expiry being < 2^15 in test
-pub const OFFERED_HTLC_SCRIPT_WEIGHT: usize = 13
3
;
+pub const ACCEPTED_HTLC_SCRIPT_WEIGHT: usize = 1
41
; //Here we have a diff due to HTLC CLTV expiry being < 2^15 in test
+pub const OFFERED_HTLC_SCRIPT_WEIGHT: usize = 13
6
;
#[derive(PartialEq)]
pub enum HTLCType { NONE, TIMEOUT, SUCCESS }
#[derive(PartialEq)]
pub enum HTLCType { NONE, TIMEOUT, SUCCESS }
diff --git
a/lightning/src/ln/onchaintx.rs
b/lightning/src/ln/onchaintx.rs
index f263ddf434b5d83f4c78be7b6bf72fca7fd56d8e..f4926471d1de4441338e3f64aab761959f5d452c 100644
(file)
--- a/
lightning/src/ln/onchaintx.rs
+++ b/
lightning/src/ln/onchaintx.rs
@@
-376,19
+376,19
@@
impl<ChanSigner: ChannelKeys> OnchainTxHandler<ChanSigner> {
tx_weight += match inp {
// number_of_witness_elements + sig_length + revocation_sig + pubkey_length + revocationpubkey + witness_script_length + witness_script
&InputDescriptors::RevokedOfferedHTLC => {
tx_weight += match inp {
// number_of_witness_elements + sig_length + revocation_sig + pubkey_length + revocationpubkey + witness_script_length + witness_script
&InputDescriptors::RevokedOfferedHTLC => {
- 1 + 1 + 73 + 1 + 33 + 1 + 13
3
+ 1 + 1 + 73 + 1 + 33 + 1 + 13
6
},
// number_of_witness_elements + sig_length + revocation_sig + pubkey_length + revocationpubkey + witness_script_length + witness_script
&InputDescriptors::RevokedReceivedHTLC => {
},
// number_of_witness_elements + sig_length + revocation_sig + pubkey_length + revocationpubkey + witness_script_length + witness_script
&InputDescriptors::RevokedReceivedHTLC => {
- 1 + 1 + 73 + 1 + 33 + 1 + 1
39
+ 1 + 1 + 73 + 1 + 33 + 1 + 1
42
},
// number_of_witness_elements + sig_length + remotehtlc_sig + preimage_length + preimage + witness_script_length + witness_script
&InputDescriptors::OfferedHTLC => {
},
// number_of_witness_elements + sig_length + remotehtlc_sig + preimage_length + preimage + witness_script_length + witness_script
&InputDescriptors::OfferedHTLC => {
- 1 + 1 + 73 + 1 + 32 + 1 + 13
3
+ 1 + 1 + 73 + 1 + 32 + 1 + 13
6
},
// number_of_witness_elements + sig_length + revocation_sig + pubkey_length + revocationpubkey + witness_script_length + witness_script
&InputDescriptors::ReceivedHTLC => {
},
// number_of_witness_elements + sig_length + revocation_sig + pubkey_length + revocationpubkey + witness_script_length + witness_script
&InputDescriptors::ReceivedHTLC => {
- 1 + 1 + 73 + 1 + 1 + 1 + 1
39
+ 1 + 1 + 73 + 1 + 1 + 1 + 1
42
},
// number_of_witness_elements + sig_length + revocation_sig + true_length + op_true + witness_script_length + witness_script
&InputDescriptors::RevokedOutput => {
},
// number_of_witness_elements + sig_length + revocation_sig + true_length + op_true + witness_script_length + witness_script
&InputDescriptors::RevokedOutput => {
@@
-421,12
+421,16
@@
impl<ChanSigner: ChannelKeys> OnchainTxHandler<ChanSigner> {
{
if cached_claim_datas.per_input_material.len() == 0 { return None } // But don't prune pending claiming request yet, we may have to resurrect HTLCs
let mut inputs = Vec::new();
{
if cached_claim_datas.per_input_material.len() == 0 { return None } // But don't prune pending claiming request yet, we may have to resurrect HTLCs
let mut inputs = Vec::new();
- for
outp in cached_claim_datas.per_input_material.keys
() {
+ for
(outp, material) in cached_claim_datas.per_input_material.iter
() {
log_trace!(logger, "Outpoint {}:{}", outp.txid, outp.vout);
inputs.push(TxIn {
previous_output: *outp,
script_sig: Script::new(),
log_trace!(logger, "Outpoint {}:{}", outp.txid, outp.vout);
inputs.push(TxIn {
previous_output: *outp,
script_sig: Script::new(),
- sequence: 0xfffffffd,
+ sequence: match material {
+ &InputMaterial::Revoked { .. } => 1, // XXX: Depends on spec discussion
+ &InputMaterial::RemoteHTLC { .. } => 1,
+ &InputMaterial::LocalHTLC { .. } => 1,
+ },
witness: Vec::new(),
});
}
witness: Vec::new(),
});
}