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 {
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 == 133 {
+ if witness_script_len == 136 {
Some(HTLCType::OfferedHTLC)
- } else if witness_script_len >= 136 && witness_script_len <= 139 {
+ } else if witness_script_len >= 139 && witness_script_len <= 142 {
Some(HTLCType::AcceptedHTLC)
} else {
None
.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)
.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()
}
}
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(),
});
} 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 };
}, None));
}
+
transaction_utils::sort_outputs(&mut txouts, |a, b| {
if let &Some(ref a_htlc) = a {
if let &Some(ref b_htlc) = b {
#[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());
nodes
}
-pub const ACCEPTED_HTLC_SCRIPT_WEIGHT: usize = 138; //Here we have a diff due to HTLC CLTV expiry being < 2^15 in test
-pub const OFFERED_HTLC_SCRIPT_WEIGHT: usize = 133;
+pub const ACCEPTED_HTLC_SCRIPT_WEIGHT: usize = 141; //Here we have a diff due to HTLC CLTV expiry being < 2^15 in test
+pub const OFFERED_HTLC_SCRIPT_WEIGHT: usize = 136;
#[derive(PartialEq)]
pub enum HTLCType { NONE, TIMEOUT, SUCCESS }
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 + 133
+ 1 + 1 + 73 + 1 + 33 + 1 + 136
},
// number_of_witness_elements + sig_length + revocation_sig + pubkey_length + revocationpubkey + witness_script_length + witness_script
&InputDescriptors::RevokedReceivedHTLC => {
- 1 + 1 + 73 + 1 + 33 + 1 + 139
+ 1 + 1 + 73 + 1 + 33 + 1 + 142
},
// number_of_witness_elements + sig_length + remotehtlc_sig + preimage_length + preimage + witness_script_length + witness_script
&InputDescriptors::OfferedHTLC => {
- 1 + 1 + 73 + 1 + 32 + 1 + 133
+ 1 + 1 + 73 + 1 + 32 + 1 + 136
},
// number_of_witness_elements + sig_length + revocation_sig + pubkey_length + revocationpubkey + witness_script_length + witness_script
&InputDescriptors::ReceivedHTLC => {
- 1 + 1 + 73 + 1 + 1 + 1 + 139
+ 1 + 1 + 73 + 1 + 1 + 1 + 142
},
// number_of_witness_elements + sig_length + revocation_sig + true_length + op_true + witness_script_length + witness_script
&InputDescriptors::RevokedOutput => {
{
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(),
- sequence: 0xfffffffd,
+ sequence: match material {
+ &InputMaterial::Revoked { .. } => 1, // XXX: Depends on spec discussion
+ &InputMaterial::RemoteHTLC { .. } => 1,
+ &InputMaterial::LocalHTLC { .. } => 1,
+ },
witness: Vec::new(),
});
}