Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 22 additions & 25 deletions lightning/src/ln/interactivetxs.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -157,7 +157,7 @@ impl ConstructedTransaction {
weight.checked_add(estimate_input_weight(input.prev_output())).unwrap_or(Weight::MAX)
});
let outputs_weight = self.outputs.iter().fold(Weight::from_wu(0), |weight, output| {
weight.checked_add(get_output_weight(&output.script_pubkey())).unwrap_or(Weight::MAX)
weight.checked_add(get_output_weight(output.script_pubkey())).unwrap_or(Weight::MAX)
});
Weight::from_wu(TX_COMMON_FIELDS_WEIGHT)
.checked_add(inputs_weight)
Expand DownExpand Up@@ -297,7 +297,7 @@ impl NegotiationContext {
.iter()
.filter(|(serial_id, _)| self.is_serial_id_valid_for_counterparty(serial_id))
.fold(0u64, |weight, (_, output)| {
weight.saturating_add(get_output_weight(&output.script_pubkey()).to_wu())
weight.saturating_add(get_output_weight(output.script_pubkey()).to_wu())
}),
)
}
Expand DownExpand Up@@ -508,7 +508,7 @@ impl NegotiationContext {
sequence: Sequence(msg.sequence),
..Default::default()
};
if !self.prevtx_outpoints.insert(txin.previous_output.clone()) {
if !self.prevtx_outpoints.insert(txin.previous_output) {
// We have added an input that already exists
return Err(AbortReason::PrevTxOutInvalid);
}
Expand DownExpand Up@@ -878,7 +878,7 @@ impl StateMachine {
}

#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum AddingRole {
enum AddingRole {
Local,
Remote,
}
Expand All@@ -892,7 +892,7 @@ pub struct LocalOrRemoteInput {
}

#[derive(Clone, Debug, Eq, PartialEq)]
pub enum InteractiveTxInput {
enum InteractiveTxInput {
Local(LocalOrRemoteInput),
Remote(LocalOrRemoteInput),
// TODO(splicing) SharedInput should be added
Expand DownExpand Up@@ -925,7 +925,7 @@ impl SharedOwnedOutput {
/// its ownership -- value fully owned by the adder or jointly
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum OutputOwned {
/// Belongs to local node -- controlled exclusively and fully belonging to local node
/// Belongs to a single party -- controlled exclusively and fully belonging to a single party
Single(TxOut),
/// Output with shared control, but fully belonging to local node
SharedControlFullyOwned(TxOut),
Expand DownExpand Up@@ -979,7 +979,7 @@ impl OutputOwned {
}

#[derive(Clone, Debug, Eq, PartialEq)]
pub struct InteractiveTxOutput {
struct InteractiveTxOutput {
serial_id: SerialId,
added_by: AddingRole,
output: OutputOwned,
Expand DownExpand Up@@ -1055,6 +1055,7 @@ pub(crate) struct InteractiveTxConstructor {
outputs_to_contribute: Vec<(SerialId, OutputOwned)>,
}

#[allow(clippy::enum_variant_names)] // Clippy doesn't like the repeated `Tx` prefix here
pub(crate) enum InteractiveTxMessageSend {
TxAddInput(msgs::TxAddInput),
TxAddOutput(msgs::TxAddOutput),
Expand DownExpand Up@@ -1126,7 +1127,7 @@ impl InteractiveTxConstructor {
},
OutputOwned::Shared(output) => {
// Sanity check
if output.local_owned > output.tx_out.value.to_sat() {
if output.local_owned >= output.tx_out.value.to_sat() {
return Err(AbortReason::InvalidLowFundingOutputValue);
}
Some((output.tx_out.script_pubkey.clone(), output.local_owned))
Expand DownExpand Up@@ -1328,12 +1329,12 @@ mod tests {
fn get_secure_random_bytes(&self) -> [u8; 32] {
let mut res = [0u8; 32];
let increment = self.0.get_increment();
for i in 0..32 {
for (i, byte) in res.iter_mut().enumerate() {
// Rotate the increment value by 'i' bits to the right, to avoid clashes
// when `generate_local_serial_id` does a parity flip on consecutive calls for the
// same party.
let rotated_increment = increment.rotate_right(i as u32);
res[i] = (rotated_increment & 0xff) as u8;
*byte = (rotated_increment & 0xff) as u8;
}
res
}
Expand DownExpand Up@@ -1402,7 +1403,7 @@ mod tests {
if shared_outputs_by_a.len() > 1 {
println!("Test warning: Expected at most one shared output. NodeA");
}
let shared_output_by_a = if shared_outputs_by_a.len() >= 1 {
let shared_output_by_a = if !shared_outputs_by_a.is_empty() {
Some(shared_outputs_by_a[0].value())
} else {
None
Expand All@@ -1412,7 +1413,7 @@ mod tests {
if shared_outputs_by_b.len() > 1 {
println!("Test warning: Expected at most one shared output. NodeB");
}
let shared_output_by_b = if shared_outputs_by_b.len() >= 1 {
let shared_output_by_b = if !shared_outputs_by_b.is_empty() {
Some(shared_outputs_by_b[0].value())
} else {
None
Expand All@@ -1424,23 +1425,19 @@ mod tests {
&session.a_expected_remote_shared_output
{
a_expected_remote_shared_output.1
} else if !shared_outputs_by_a.is_empty() {
shared_outputs_by_a[0].local_value(AddingRole::Local)
} else {
if shared_outputs_by_a.len() >= 1 {
shared_outputs_by_a[0].local_value(AddingRole::Local)
} else {
0
}
0
};
let expected_by_b = if let Some(b_expected_remote_shared_output) =
&session.b_expected_remote_shared_output
{
b_expected_remote_shared_output.1
} else if !shared_outputs_by_b.is_empty() {
shared_outputs_by_b[0].local_value(AddingRole::Local)
} else {
if shared_outputs_by_b.len() >= 1 {
shared_outputs_by_b[0].local_value(AddingRole::Local)
} else {
0
}
0
};

let expected_sum = expected_by_a + expected_by_b;
Expand All@@ -1458,7 +1455,7 @@ mod tests {
true,
tx_locktime,
session.inputs_a,
session.outputs_a.iter().map(|o| o.clone()).collect(),
session.outputs_a.to_vec(),
session.a_expected_remote_shared_output,
) {
Ok(r) => r,
Expand All@@ -1479,7 +1476,7 @@ mod tests {
false,
tx_locktime,
session.inputs_b,
session.outputs_b.iter().map(|o| o.clone()).collect(),
session.outputs_b.to_vec(),
session.b_expected_remote_shared_output,
) {
Ok(r) => r,
Expand DownExpand Up@@ -1665,7 +1662,7 @@ mod tests {
}

fn generate_outputs(outputs: &[TestOutput]) -> Vec<OutputOwned> {
outputs.iter().map(|o| generate_output_nonfunding_one(o)).collect()
outputs.iter().map(generate_output_nonfunding_one).collect()
}

/// Generate a single output that is the funding output
Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { // Add copy buttons to all
 blocks
(function() {
function addCopyButtons() {
document.querySelectorAll('pre code').forEach(function(codeBlock) {
if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;
codeBlock.parentElement.setAttribute('data-copy-added', 'true');
var btn = document.createElement('button');
btn.textContent = 'Copy';
btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';
btn.onmouseover = function() { this.style.opacity = '1'; };
btn.onmouseout = function() { this.style.opacity = '0.7'; };
btn.onclick = function() {
navigator.clipboard.writeText(codeBlock.textContent).then(function() {
btn.textContent = 'Copied!';
setTimeout(function() { btn.textContent = 'Copy'; }, 1500);
});
};
codeBlock.parentElement.style.position = 'relative';
codeBlock.parentElement.appendChild(btn);
});
}
addCopyButtons();
// Re-run on dynamic content
var observer = new MutationObserver(addCopyButtons);
observer.observe(document.body, { childList: true, subtree: true });
})();
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Fix remaining feedback and other nits for 2989 by dunxen · Pull Request #3219 · lightningdevkit/rust-lightning · GitHub
Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 22 additions & 25 deletions lightning/src/ln/interactivetxs.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -157,7 +157,7 @@ impl ConstructedTransaction {
weight.checked_add(estimate_input_weight(input.prev_output())).unwrap_or(Weight::MAX)
});
let outputs_weight = self.outputs.iter().fold(Weight::from_wu(0), |weight, output| {
weight.checked_add(get_output_weight(&output.script_pubkey())).unwrap_or(Weight::MAX)
weight.checked_add(get_output_weight(output.script_pubkey())).unwrap_or(Weight::MAX)
});
Weight::from_wu(TX_COMMON_FIELDS_WEIGHT)
.checked_add(inputs_weight)
Expand DownExpand Up@@ -297,7 +297,7 @@ impl NegotiationContext {
.iter()
.filter(|(serial_id, _)| self.is_serial_id_valid_for_counterparty(serial_id))
.fold(0u64, |weight, (_, output)| {
weight.saturating_add(get_output_weight(&output.script_pubkey()).to_wu())
weight.saturating_add(get_output_weight(output.script_pubkey()).to_wu())
}),
)
}
Expand DownExpand Up@@ -508,7 +508,7 @@ impl NegotiationContext {
sequence: Sequence(msg.sequence),
..Default::default()
};
if !self.prevtx_outpoints.insert(txin.previous_output.clone()) {
if !self.prevtx_outpoints.insert(txin.previous_output) {
// We have added an input that already exists
return Err(AbortReason::PrevTxOutInvalid);
}
Expand DownExpand Up@@ -878,7 +878,7 @@ impl StateMachine {
}

#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum AddingRole {
enum AddingRole {
Local,
Remote,
}
Expand All@@ -892,7 +892,7 @@ pub struct LocalOrRemoteInput {
}

#[derive(Clone, Debug, Eq, PartialEq)]
pub enum InteractiveTxInput {
enum InteractiveTxInput {
Local(LocalOrRemoteInput),
Remote(LocalOrRemoteInput),
// TODO(splicing) SharedInput should be added
Expand DownExpand Up@@ -925,7 +925,7 @@ impl SharedOwnedOutput {
/// its ownership -- value fully owned by the adder or jointly
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum OutputOwned {
/// Belongs to local node -- controlled exclusively and fully belonging to local node
/// Belongs to a single party -- controlled exclusively and fully belonging to a single party
Single(TxOut),
/// Output with shared control, but fully belonging to local node
SharedControlFullyOwned(TxOut),
Expand DownExpand Up@@ -979,7 +979,7 @@ impl OutputOwned {
}

#[derive(Clone, Debug, Eq, PartialEq)]
pub struct InteractiveTxOutput {
struct InteractiveTxOutput {
serial_id: SerialId,
added_by: AddingRole,
output: OutputOwned,
Expand DownExpand Up@@ -1055,6 +1055,7 @@ pub(crate) struct InteractiveTxConstructor {
outputs_to_contribute: Vec<(SerialId, OutputOwned)>,
}

#[allow(clippy::enum_variant_names)] // Clippy doesn't like the repeated `Tx` prefix here
pub(crate) enum InteractiveTxMessageSend {
TxAddInput(msgs::TxAddInput),
TxAddOutput(msgs::TxAddOutput),
Expand DownExpand Up@@ -1126,7 +1127,7 @@ impl InteractiveTxConstructor {
},
OutputOwned::Shared(output) => {
// Sanity check
if output.local_owned > output.tx_out.value.to_sat() {
if output.local_owned >= output.tx_out.value.to_sat() {
return Err(AbortReason::InvalidLowFundingOutputValue);
}
Some((output.tx_out.script_pubkey.clone(), output.local_owned))
Expand DownExpand Up@@ -1328,12 +1329,12 @@ mod tests {
fn get_secure_random_bytes(&self) -> [u8; 32] {
let mut res = [0u8; 32];
let increment = self.0.get_increment();
for i in 0..32 {
for (i, byte) in res.iter_mut().enumerate() {
// Rotate the increment value by 'i' bits to the right, to avoid clashes
// when `generate_local_serial_id` does a parity flip on consecutive calls for the
// same party.
let rotated_increment = increment.rotate_right(i as u32);
res[i] = (rotated_increment & 0xff) as u8;
*byte = (rotated_increment & 0xff) as u8;
}
res
}
Expand DownExpand Up@@ -1402,7 +1403,7 @@ mod tests {
if shared_outputs_by_a.len() > 1 {
println!("Test warning: Expected at most one shared output. NodeA");
}
let shared_output_by_a = if shared_outputs_by_a.len() >= 1 {
let shared_output_by_a = if !shared_outputs_by_a.is_empty() {
Some(shared_outputs_by_a[0].value())
} else {
None
Expand All@@ -1412,7 +1413,7 @@ mod tests {
if shared_outputs_by_b.len() > 1 {
println!("Test warning: Expected at most one shared output. NodeB");
}
let shared_output_by_b = if shared_outputs_by_b.len() >= 1 {
let shared_output_by_b = if !shared_outputs_by_b.is_empty() {
Some(shared_outputs_by_b[0].value())
} else {
None
Expand All@@ -1424,23 +1425,19 @@ mod tests {
&session.a_expected_remote_shared_output
{
a_expected_remote_shared_output.1
} else if !shared_outputs_by_a.is_empty() {
shared_outputs_by_a[0].local_value(AddingRole::Local)
} else {
if shared_outputs_by_a.len() >= 1 {
shared_outputs_by_a[0].local_value(AddingRole::Local)
} else {
0
}
0
};
let expected_by_b = if let Some(b_expected_remote_shared_output) =
&session.b_expected_remote_shared_output
{
b_expected_remote_shared_output.1
} else if !shared_outputs_by_b.is_empty() {
shared_outputs_by_b[0].local_value(AddingRole::Local)
} else {
if shared_outputs_by_b.len() >= 1 {
shared_outputs_by_b[0].local_value(AddingRole::Local)
} else {
0
}
0
};

let expected_sum = expected_by_a + expected_by_b;
Expand All@@ -1458,7 +1455,7 @@ mod tests {
true,
tx_locktime,
session.inputs_a,
session.outputs_a.iter().map(|o| o.clone()).collect(),
session.outputs_a.to_vec(),
session.a_expected_remote_shared_output,
) {
Ok(r) => r,
Expand All@@ -1479,7 +1476,7 @@ mod tests {
false,
tx_locktime,
session.inputs_b,
session.outputs_b.iter().map(|o| o.clone()).collect(),
session.outputs_b.to_vec(),
session.b_expected_remote_shared_output,
) {
Ok(r) => r,
Expand DownExpand Up@@ -1665,7 +1662,7 @@ mod tests {
}

fn generate_outputs(outputs: &[TestOutput]) -> Vec<OutputOwned> {
outputs.iter().map(|o| generate_output_nonfunding_one(o)).collect()
outputs.iter().map(generate_output_nonfunding_one).collect()
}

/// Generate a single output that is the funding output
Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { // Force GitHub README to respect dark mode (function() { var style = document.createElement('style'); style.textContent = ' .markdown-body { color-scheme: dark light; } .markdown-body pre { background: #161b22 !important; } .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; } .markdown-body table th, .markdown-body table td { border-color: #30363d !important; } .markdown-body img { background: #0d1117; } .markdown-body blockquote { border-left-color: #8b949e; } .markdown-body hr { border-color: #30363d; } '; document.head.appendChild(style); })(); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' Fix remaining feedback and other nits for 2989 by dunxen · Pull Request #3219 · lightningdevkit/rust-lightning · GitHub
Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 22 additions & 25 deletions lightning/src/ln/interactivetxs.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -157,7 +157,7 @@ impl ConstructedTransaction {
weight.checked_add(estimate_input_weight(input.prev_output())).unwrap_or(Weight::MAX)
});
let outputs_weight = self.outputs.iter().fold(Weight::from_wu(0), |weight, output| {
weight.checked_add(get_output_weight(&output.script_pubkey())).unwrap_or(Weight::MAX)
weight.checked_add(get_output_weight(output.script_pubkey())).unwrap_or(Weight::MAX)
});
Weight::from_wu(TX_COMMON_FIELDS_WEIGHT)
.checked_add(inputs_weight)
Expand DownExpand Up@@ -297,7 +297,7 @@ impl NegotiationContext {
.iter()
.filter(|(serial_id, _)| self.is_serial_id_valid_for_counterparty(serial_id))
.fold(0u64, |weight, (_, output)| {
weight.saturating_add(get_output_weight(&output.script_pubkey()).to_wu())
weight.saturating_add(get_output_weight(output.script_pubkey()).to_wu())
}),
)
}
Expand DownExpand Up@@ -508,7 +508,7 @@ impl NegotiationContext {
sequence: Sequence(msg.sequence),
..Default::default()
};
if !self.prevtx_outpoints.insert(txin.previous_output.clone()) {
if !self.prevtx_outpoints.insert(txin.previous_output) {
// We have added an input that already exists
return Err(AbortReason::PrevTxOutInvalid);
}
Expand DownExpand Up@@ -878,7 +878,7 @@ impl StateMachine {
}

#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum AddingRole {
enum AddingRole {
Local,
Remote,
}
Expand All@@ -892,7 +892,7 @@ pub struct LocalOrRemoteInput {
}

#[derive(Clone, Debug, Eq, PartialEq)]
pub enum InteractiveTxInput {
enum InteractiveTxInput {
Local(LocalOrRemoteInput),
Remote(LocalOrRemoteInput),
// TODO(splicing) SharedInput should be added
Expand DownExpand Up@@ -925,7 +925,7 @@ impl SharedOwnedOutput {
/// its ownership -- value fully owned by the adder or jointly
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum OutputOwned {
/// Belongs to local node -- controlled exclusively and fully belonging to local node
/// Belongs to a single party -- controlled exclusively and fully belonging to a single party
Single(TxOut),
/// Output with shared control, but fully belonging to local node
SharedControlFullyOwned(TxOut),
Expand DownExpand Up@@ -979,7 +979,7 @@ impl OutputOwned {
}

#[derive(Clone, Debug, Eq, PartialEq)]
pub struct InteractiveTxOutput {
struct InteractiveTxOutput {
serial_id: SerialId,
added_by: AddingRole,
output: OutputOwned,
Expand DownExpand Up@@ -1055,6 +1055,7 @@ pub(crate) struct InteractiveTxConstructor {
outputs_to_contribute: Vec<(SerialId, OutputOwned)>,
}

#[allow(clippy::enum_variant_names)] // Clippy doesn't like the repeated `Tx` prefix here
pub(crate) enum InteractiveTxMessageSend {
TxAddInput(msgs::TxAddInput),
TxAddOutput(msgs::TxAddOutput),
Expand DownExpand Up@@ -1126,7 +1127,7 @@ impl InteractiveTxConstructor {
},
OutputOwned::Shared(output) => {
// Sanity check
if output.local_owned > output.tx_out.value.to_sat() {
if output.local_owned >= output.tx_out.value.to_sat() {
return Err(AbortReason::InvalidLowFundingOutputValue);
}
Some((output.tx_out.script_pubkey.clone(), output.local_owned))
Expand DownExpand Up@@ -1328,12 +1329,12 @@ mod tests {
fn get_secure_random_bytes(&self) -> [u8; 32] {
let mut res = [0u8; 32];
let increment = self.0.get_increment();
for i in 0..32 {
for (i, byte) in res.iter_mut().enumerate() {
// Rotate the increment value by 'i' bits to the right, to avoid clashes
// when `generate_local_serial_id` does a parity flip on consecutive calls for the
// same party.
let rotated_increment = increment.rotate_right(i as u32);
res[i] = (rotated_increment & 0xff) as u8;
*byte = (rotated_increment & 0xff) as u8;
}
res
}
Expand DownExpand Up@@ -1402,7 +1403,7 @@ mod tests {
if shared_outputs_by_a.len() > 1 {
println!("Test warning: Expected at most one shared output. NodeA");
}
let shared_output_by_a = if shared_outputs_by_a.len() >= 1 {
let shared_output_by_a = if !shared_outputs_by_a.is_empty() {
Some(shared_outputs_by_a[0].value())
} else {
None
Expand All@@ -1412,7 +1413,7 @@ mod tests {
if shared_outputs_by_b.len() > 1 {
println!("Test warning: Expected at most one shared output. NodeB");
}
let shared_output_by_b = if shared_outputs_by_b.len() >= 1 {
let shared_output_by_b = if !shared_outputs_by_b.is_empty() {
Some(shared_outputs_by_b[0].value())
} else {
None
Expand All@@ -1424,23 +1425,19 @@ mod tests {
&session.a_expected_remote_shared_output
{
a_expected_remote_shared_output.1
} else if !shared_outputs_by_a.is_empty() {
shared_outputs_by_a[0].local_value(AddingRole::Local)
} else {
if shared_outputs_by_a.len() >= 1 {
shared_outputs_by_a[0].local_value(AddingRole::Local)
} else {
0
}
0
};
let expected_by_b = if let Some(b_expected_remote_shared_output) =
&session.b_expected_remote_shared_output
{
b_expected_remote_shared_output.1
} else if !shared_outputs_by_b.is_empty() {
shared_outputs_by_b[0].local_value(AddingRole::Local)
} else {
if shared_outputs_by_b.len() >= 1 {
shared_outputs_by_b[0].local_value(AddingRole::Local)
} else {
0
}
0
};

let expected_sum = expected_by_a + expected_by_b;
Expand All@@ -1458,7 +1455,7 @@ mod tests {
true,
tx_locktime,
session.inputs_a,
session.outputs_a.iter().map(|o| o.clone()).collect(),
session.outputs_a.to_vec(),
session.a_expected_remote_shared_output,
) {
Ok(r) => r,
Expand All@@ -1479,7 +1476,7 @@ mod tests {
false,
tx_locktime,
session.inputs_b,
session.outputs_b.iter().map(|o| o.clone()).collect(),
session.outputs_b.to_vec(),
session.b_expected_remote_shared_output,
) {
Ok(r) => r,
Expand DownExpand Up@@ -1665,7 +1662,7 @@ mod tests {
}

fn generate_outputs(outputs: &[TestOutput]) -> Vec<OutputOwned> {
outputs.iter().map(|o| generate_output_nonfunding_one(o)).collect()
outputs.iter().map(generate_output_nonfunding_one).collect()
}

/// Generate a single output that is the funding output
Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { // Highlight search terms from Google/DuckDuckGo/Bing referrer (function() { var ref = document.referrer; var terms = []; if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) { var url = new URL(ref); var q = url.searchParams.get('q') || url.searchParams.get('p'); if (q) { terms = q.split(/\s+/).filter(function(t) { return t.length > 2; }); } } if (terms.length === 0) return; var style = document.createElement('style'); style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }'; document.head.appendChild(style); function highlight(node) { if (node.nodeType === 3) { // text node var text = node.textContent; var found = false; terms.forEach(function(term) { var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\]\\]/g, '\\') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' Fix remaining feedback and other nits for 2989 by dunxen · Pull Request #3219 · lightningdevkit/rust-lightning · GitHub
Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 22 additions & 25 deletions lightning/src/ln/interactivetxs.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -157,7 +157,7 @@ impl ConstructedTransaction {
weight.checked_add(estimate_input_weight(input.prev_output())).unwrap_or(Weight::MAX)
});
let outputs_weight = self.outputs.iter().fold(Weight::from_wu(0), |weight, output| {
weight.checked_add(get_output_weight(&output.script_pubkey())).unwrap_or(Weight::MAX)
weight.checked_add(get_output_weight(output.script_pubkey())).unwrap_or(Weight::MAX)
});
Weight::from_wu(TX_COMMON_FIELDS_WEIGHT)
.checked_add(inputs_weight)
Expand DownExpand Up@@ -297,7 +297,7 @@ impl NegotiationContext {
.iter()
.filter(|(serial_id, _)| self.is_serial_id_valid_for_counterparty(serial_id))
.fold(0u64, |weight, (_, output)| {
weight.saturating_add(get_output_weight(&output.script_pubkey()).to_wu())
weight.saturating_add(get_output_weight(output.script_pubkey()).to_wu())
}),
)
}
Expand DownExpand Up@@ -508,7 +508,7 @@ impl NegotiationContext {
sequence: Sequence(msg.sequence),
..Default::default()
};
if !self.prevtx_outpoints.insert(txin.previous_output.clone()) {
if !self.prevtx_outpoints.insert(txin.previous_output) {
// We have added an input that already exists
return Err(AbortReason::PrevTxOutInvalid);
}
Expand DownExpand Up@@ -878,7 +878,7 @@ impl StateMachine {
}

#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum AddingRole {
enum AddingRole {
Local,
Remote,
}
Expand All@@ -892,7 +892,7 @@ pub struct LocalOrRemoteInput {
}

#[derive(Clone, Debug, Eq, PartialEq)]
pub enum InteractiveTxInput {
enum InteractiveTxInput {
Local(LocalOrRemoteInput),
Remote(LocalOrRemoteInput),
// TODO(splicing) SharedInput should be added
Expand DownExpand Up@@ -925,7 +925,7 @@ impl SharedOwnedOutput {
/// its ownership -- value fully owned by the adder or jointly
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum OutputOwned {
/// Belongs to local node -- controlled exclusively and fully belonging to local node
/// Belongs to a single party -- controlled exclusively and fully belonging to a single party
Single(TxOut),
/// Output with shared control, but fully belonging to local node
SharedControlFullyOwned(TxOut),
Expand DownExpand Up@@ -979,7 +979,7 @@ impl OutputOwned {
}

#[derive(Clone, Debug, Eq, PartialEq)]
pub struct InteractiveTxOutput {
struct InteractiveTxOutput {
serial_id: SerialId,
added_by: AddingRole,
output: OutputOwned,
Expand DownExpand Up@@ -1055,6 +1055,7 @@ pub(crate) struct InteractiveTxConstructor {
outputs_to_contribute: Vec<(SerialId, OutputOwned)>,
}

#[allow(clippy::enum_variant_names)] // Clippy doesn't like the repeated `Tx` prefix here
pub(crate) enum InteractiveTxMessageSend {
TxAddInput(msgs::TxAddInput),
TxAddOutput(msgs::TxAddOutput),
Expand DownExpand Up@@ -1126,7 +1127,7 @@ impl InteractiveTxConstructor {
},
OutputOwned::Shared(output) => {
// Sanity check
if output.local_owned > output.tx_out.value.to_sat() {
if output.local_owned >= output.tx_out.value.to_sat() {
return Err(AbortReason::InvalidLowFundingOutputValue);
}
Some((output.tx_out.script_pubkey.clone(), output.local_owned))
Expand DownExpand Up@@ -1328,12 +1329,12 @@ mod tests {
fn get_secure_random_bytes(&self) -> [u8; 32] {
let mut res = [0u8; 32];
let increment = self.0.get_increment();
for i in 0..32 {
for (i, byte) in res.iter_mut().enumerate() {
// Rotate the increment value by 'i' bits to the right, to avoid clashes
// when `generate_local_serial_id` does a parity flip on consecutive calls for the
// same party.
let rotated_increment = increment.rotate_right(i as u32);
res[i] = (rotated_increment & 0xff) as u8;
*byte = (rotated_increment & 0xff) as u8;
}
res
}
Expand DownExpand Up@@ -1402,7 +1403,7 @@ mod tests {
if shared_outputs_by_a.len() > 1 {
println!("Test warning: Expected at most one shared output. NodeA");
}
let shared_output_by_a = if shared_outputs_by_a.len() >= 1 {
let shared_output_by_a = if !shared_outputs_by_a.is_empty() {
Some(shared_outputs_by_a[0].value())
} else {
None
Expand All@@ -1412,7 +1413,7 @@ mod tests {
if shared_outputs_by_b.len() > 1 {
println!("Test warning: Expected at most one shared output. NodeB");
}
let shared_output_by_b = if shared_outputs_by_b.len() >= 1 {
let shared_output_by_b = if !shared_outputs_by_b.is_empty() {
Some(shared_outputs_by_b[0].value())
} else {
None
Expand All@@ -1424,23 +1425,19 @@ mod tests {
&session.a_expected_remote_shared_output
{
a_expected_remote_shared_output.1
} else if !shared_outputs_by_a.is_empty() {
shared_outputs_by_a[0].local_value(AddingRole::Local)
} else {
if shared_outputs_by_a.len() >= 1 {
shared_outputs_by_a[0].local_value(AddingRole::Local)
} else {
0
}
0
};
let expected_by_b = if let Some(b_expected_remote_shared_output) =
&session.b_expected_remote_shared_output
{
b_expected_remote_shared_output.1
} else if !shared_outputs_by_b.is_empty() {
shared_outputs_by_b[0].local_value(AddingRole::Local)
} else {
if shared_outputs_by_b.len() >= 1 {
shared_outputs_by_b[0].local_value(AddingRole::Local)
} else {
0
}
0
};

let expected_sum = expected_by_a + expected_by_b;
Expand All@@ -1458,7 +1455,7 @@ mod tests {
true,
tx_locktime,
session.inputs_a,
session.outputs_a.iter().map(|o| o.clone()).collect(),
session.outputs_a.to_vec(),
session.a_expected_remote_shared_output,
) {
Ok(r) => r,
Expand All@@ -1479,7 +1476,7 @@ mod tests {
false,
tx_locktime,
session.inputs_b,
session.outputs_b.iter().map(|o| o.clone()).collect(),
session.outputs_b.to_vec(),
session.b_expected_remote_shared_output,
) {
Ok(r) => r,
Expand DownExpand Up@@ -1665,7 +1662,7 @@ mod tests {
}

fn generate_outputs(outputs: &[TestOutput]) -> Vec<OutputOwned> {
outputs.iter().map(|o| generate_output_nonfunding_one(o)).collect()
outputs.iter().map(generate_output_nonfunding_one).collect()
}

/// Generate a single output that is the funding output
Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ' Fix remaining feedback and other nits for 2989 by dunxen · Pull Request #3219 · lightningdevkit/rust-lightning · GitHub
Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 22 additions & 25 deletions lightning/src/ln/interactivetxs.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -157,7 +157,7 @@ impl ConstructedTransaction {
weight.checked_add(estimate_input_weight(input.prev_output())).unwrap_or(Weight::MAX)
});
let outputs_weight = self.outputs.iter().fold(Weight::from_wu(0), |weight, output| {
weight.checked_add(get_output_weight(&output.script_pubkey())).unwrap_or(Weight::MAX)
weight.checked_add(get_output_weight(output.script_pubkey())).unwrap_or(Weight::MAX)
});
Weight::from_wu(TX_COMMON_FIELDS_WEIGHT)
.checked_add(inputs_weight)
Expand DownExpand Up@@ -297,7 +297,7 @@ impl NegotiationContext {
.iter()
.filter(|(serial_id, _)| self.is_serial_id_valid_for_counterparty(serial_id))
.fold(0u64, |weight, (_, output)| {
weight.saturating_add(get_output_weight(&output.script_pubkey()).to_wu())
weight.saturating_add(get_output_weight(output.script_pubkey()).to_wu())
}),
)
}
Expand DownExpand Up@@ -508,7 +508,7 @@ impl NegotiationContext {
sequence: Sequence(msg.sequence),
..Default::default()
};
if !self.prevtx_outpoints.insert(txin.previous_output.clone()) {
if !self.prevtx_outpoints.insert(txin.previous_output) {
// We have added an input that already exists
return Err(AbortReason::PrevTxOutInvalid);
}
Expand DownExpand Up@@ -878,7 +878,7 @@ impl StateMachine {
}

#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum AddingRole {
enum AddingRole {
Local,
Remote,
}
Expand All@@ -892,7 +892,7 @@ pub struct LocalOrRemoteInput {
}

#[derive(Clone, Debug, Eq, PartialEq)]
pub enum InteractiveTxInput {
enum InteractiveTxInput {
Local(LocalOrRemoteInput),
Remote(LocalOrRemoteInput),
// TODO(splicing) SharedInput should be added
Expand DownExpand Up@@ -925,7 +925,7 @@ impl SharedOwnedOutput {
/// its ownership -- value fully owned by the adder or jointly
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum OutputOwned {
/// Belongs to local node -- controlled exclusively and fully belonging to local node
/// Belongs to a single party -- controlled exclusively and fully belonging to a single party
Single(TxOut),
/// Output with shared control, but fully belonging to local node
SharedControlFullyOwned(TxOut),
Expand DownExpand Up@@ -979,7 +979,7 @@ impl OutputOwned {
}

#[derive(Clone, Debug, Eq, PartialEq)]
pub struct InteractiveTxOutput {
struct InteractiveTxOutput {
serial_id: SerialId,
added_by: AddingRole,
output: OutputOwned,
Expand DownExpand Up@@ -1055,6 +1055,7 @@ pub(crate) struct InteractiveTxConstructor {
outputs_to_contribute: Vec<(SerialId, OutputOwned)>,
}

#[allow(clippy::enum_variant_names)] // Clippy doesn't like the repeated `Tx` prefix here
pub(crate) enum InteractiveTxMessageSend {
TxAddInput(msgs::TxAddInput),
TxAddOutput(msgs::TxAddOutput),
Expand DownExpand Up@@ -1126,7 +1127,7 @@ impl InteractiveTxConstructor {
},
OutputOwned::Shared(output) => {
// Sanity check
if output.local_owned > output.tx_out.value.to_sat() {
if output.local_owned >= output.tx_out.value.to_sat() {
return Err(AbortReason::InvalidLowFundingOutputValue);
}
Some((output.tx_out.script_pubkey.clone(), output.local_owned))
Expand DownExpand Up@@ -1328,12 +1329,12 @@ mod tests {
fn get_secure_random_bytes(&self) -> [u8; 32] {
let mut res = [0u8; 32];
let increment = self.0.get_increment();
for i in 0..32 {
for (i, byte) in res.iter_mut().enumerate() {
// Rotate the increment value by 'i' bits to the right, to avoid clashes
// when `generate_local_serial_id` does a parity flip on consecutive calls for the
// same party.
let rotated_increment = increment.rotate_right(i as u32);
res[i] = (rotated_increment & 0xff) as u8;
*byte = (rotated_increment & 0xff) as u8;
}
res
}
Expand DownExpand Up@@ -1402,7 +1403,7 @@ mod tests {
if shared_outputs_by_a.len() > 1 {
println!("Test warning: Expected at most one shared output. NodeA");
}
let shared_output_by_a = if shared_outputs_by_a.len() >= 1 {
let shared_output_by_a = if !shared_outputs_by_a.is_empty() {
Some(shared_outputs_by_a[0].value())
} else {
None
Expand All@@ -1412,7 +1413,7 @@ mod tests {
if shared_outputs_by_b.len() > 1 {
println!("Test warning: Expected at most one shared output. NodeB");
}
let shared_output_by_b = if shared_outputs_by_b.len() >= 1 {
let shared_output_by_b = if !shared_outputs_by_b.is_empty() {
Some(shared_outputs_by_b[0].value())
} else {
None
Expand All@@ -1424,23 +1425,19 @@ mod tests {
&session.a_expected_remote_shared_output
{
a_expected_remote_shared_output.1
} else if !shared_outputs_by_a.is_empty() {
shared_outputs_by_a[0].local_value(AddingRole::Local)
} else {
if shared_outputs_by_a.len() >= 1 {
shared_outputs_by_a[0].local_value(AddingRole::Local)
} else {
0
}
0
};
let expected_by_b = if let Some(b_expected_remote_shared_output) =
&session.b_expected_remote_shared_output
{
b_expected_remote_shared_output.1
} else if !shared_outputs_by_b.is_empty() {
shared_outputs_by_b[0].local_value(AddingRole::Local)
} else {
if shared_outputs_by_b.len() >= 1 {
shared_outputs_by_b[0].local_value(AddingRole::Local)
} else {
0
}
0
};

let expected_sum = expected_by_a + expected_by_b;
Expand All@@ -1458,7 +1455,7 @@ mod tests {
true,
tx_locktime,
session.inputs_a,
session.outputs_a.iter().map(|o| o.clone()).collect(),
session.outputs_a.to_vec(),
session.a_expected_remote_shared_output,
) {
Ok(r) => r,
Expand All@@ -1479,7 +1476,7 @@ mod tests {
false,
tx_locktime,
session.inputs_b,
session.outputs_b.iter().map(|o| o.clone()).collect(),
session.outputs_b.to_vec(),
session.b_expected_remote_shared_output,
) {
Ok(r) => r,
Expand DownExpand Up@@ -1665,7 +1662,7 @@ mod tests {
}

fn generate_outputs(outputs: &[TestOutput]) -> Vec<OutputOwned> {
outputs.iter().map(|o| generate_output_nonfunding_one(o)).collect()
outputs.iter().map(generate_output_nonfunding_one).collect()
}

/// Generate a single output that is the funding output
Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' Fix remaining feedback and other nits for 2989 by dunxen · Pull Request #3219 · lightningdevkit/rust-lightning · GitHub
Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 22 additions & 25 deletions lightning/src/ln/interactivetxs.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -157,7 +157,7 @@ impl ConstructedTransaction {
weight.checked_add(estimate_input_weight(input.prev_output())).unwrap_or(Weight::MAX)
});
let outputs_weight = self.outputs.iter().fold(Weight::from_wu(0), |weight, output| {
weight.checked_add(get_output_weight(&output.script_pubkey())).unwrap_or(Weight::MAX)
weight.checked_add(get_output_weight(output.script_pubkey())).unwrap_or(Weight::MAX)
});
Weight::from_wu(TX_COMMON_FIELDS_WEIGHT)
.checked_add(inputs_weight)
Expand DownExpand Up@@ -297,7 +297,7 @@ impl NegotiationContext {
.iter()
.filter(|(serial_id, _)| self.is_serial_id_valid_for_counterparty(serial_id))
.fold(0u64, |weight, (_, output)| {
weight.saturating_add(get_output_weight(&output.script_pubkey()).to_wu())
weight.saturating_add(get_output_weight(output.script_pubkey()).to_wu())
}),
)
}
Expand DownExpand Up@@ -508,7 +508,7 @@ impl NegotiationContext {
sequence: Sequence(msg.sequence),
..Default::default()
};
if !self.prevtx_outpoints.insert(txin.previous_output.clone()) {
if !self.prevtx_outpoints.insert(txin.previous_output) {
// We have added an input that already exists
return Err(AbortReason::PrevTxOutInvalid);
}
Expand DownExpand Up@@ -878,7 +878,7 @@ impl StateMachine {
}

#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum AddingRole {
enum AddingRole {
Local,
Remote,
}
Expand All@@ -892,7 +892,7 @@ pub struct LocalOrRemoteInput {
}

#[derive(Clone, Debug, Eq, PartialEq)]
pub enum InteractiveTxInput {
enum InteractiveTxInput {
Local(LocalOrRemoteInput),
Remote(LocalOrRemoteInput),
// TODO(splicing) SharedInput should be added
Expand DownExpand Up@@ -925,7 +925,7 @@ impl SharedOwnedOutput {
/// its ownership -- value fully owned by the adder or jointly
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum OutputOwned {
/// Belongs to local node -- controlled exclusively and fully belonging to local node
/// Belongs to a single party -- controlled exclusively and fully belonging to a single party
Single(TxOut),
/// Output with shared control, but fully belonging to local node
SharedControlFullyOwned(TxOut),
Expand DownExpand Up@@ -979,7 +979,7 @@ impl OutputOwned {
}

#[derive(Clone, Debug, Eq, PartialEq)]
pub struct InteractiveTxOutput {
struct InteractiveTxOutput {
serial_id: SerialId,
added_by: AddingRole,
output: OutputOwned,
Expand DownExpand Up@@ -1055,6 +1055,7 @@ pub(crate) struct InteractiveTxConstructor {
outputs_to_contribute: Vec<(SerialId, OutputOwned)>,
}

#[allow(clippy::enum_variant_names)] // Clippy doesn't like the repeated `Tx` prefix here
pub(crate) enum InteractiveTxMessageSend {
TxAddInput(msgs::TxAddInput),
TxAddOutput(msgs::TxAddOutput),
Expand DownExpand Up@@ -1126,7 +1127,7 @@ impl InteractiveTxConstructor {
},
OutputOwned::Shared(output) => {
// Sanity check
if output.local_owned > output.tx_out.value.to_sat() {
if output.local_owned >= output.tx_out.value.to_sat() {
return Err(AbortReason::InvalidLowFundingOutputValue);
}
Some((output.tx_out.script_pubkey.clone(), output.local_owned))
Expand DownExpand Up@@ -1328,12 +1329,12 @@ mod tests {
fn get_secure_random_bytes(&self) -> [u8; 32] {
let mut res = [0u8; 32];
let increment = self.0.get_increment();
for i in 0..32 {
for (i, byte) in res.iter_mut().enumerate() {
// Rotate the increment value by 'i' bits to the right, to avoid clashes
// when `generate_local_serial_id` does a parity flip on consecutive calls for the
// same party.
let rotated_increment = increment.rotate_right(i as u32);
res[i] = (rotated_increment & 0xff) as u8;
*byte = (rotated_increment & 0xff) as u8;
}
res
}
Expand DownExpand Up@@ -1402,7 +1403,7 @@ mod tests {
if shared_outputs_by_a.len() > 1 {
println!("Test warning: Expected at most one shared output. NodeA");
}
let shared_output_by_a = if shared_outputs_by_a.len() >= 1 {
let shared_output_by_a = if !shared_outputs_by_a.is_empty() {
Some(shared_outputs_by_a[0].value())
} else {
None
Expand All@@ -1412,7 +1413,7 @@ mod tests {
if shared_outputs_by_b.len() > 1 {
println!("Test warning: Expected at most one shared output. NodeB");
}
let shared_output_by_b = if shared_outputs_by_b.len() >= 1 {
let shared_output_by_b = if !shared_outputs_by_b.is_empty() {
Some(shared_outputs_by_b[0].value())
} else {
None
Expand All@@ -1424,23 +1425,19 @@ mod tests {
&session.a_expected_remote_shared_output
{
a_expected_remote_shared_output.1
} else if !shared_outputs_by_a.is_empty() {
shared_outputs_by_a[0].local_value(AddingRole::Local)
} else {
if shared_outputs_by_a.len() >= 1 {
shared_outputs_by_a[0].local_value(AddingRole::Local)
} else {
0
}
0
};
let expected_by_b = if let Some(b_expected_remote_shared_output) =
&session.b_expected_remote_shared_output
{
b_expected_remote_shared_output.1
} else if !shared_outputs_by_b.is_empty() {
shared_outputs_by_b[0].local_value(AddingRole::Local)
} else {
if shared_outputs_by_b.len() >= 1 {
shared_outputs_by_b[0].local_value(AddingRole::Local)
} else {
0
}
0
};

let expected_sum = expected_by_a + expected_by_b;
Expand All@@ -1458,7 +1455,7 @@ mod tests {
true,
tx_locktime,
session.inputs_a,
session.outputs_a.iter().map(|o| o.clone()).collect(),
session.outputs_a.to_vec(),
session.a_expected_remote_shared_output,
) {
Ok(r) => r,
Expand All@@ -1479,7 +1476,7 @@ mod tests {
false,
tx_locktime,
session.inputs_b,
session.outputs_b.iter().map(|o| o.clone()).collect(),
session.outputs_b.to_vec(),
session.b_expected_remote_shared_output,
) {
Ok(r) => r,
Expand DownExpand Up@@ -1665,7 +1662,7 @@ mod tests {
}

fn generate_outputs(outputs: &[TestOutput]) -> Vec<OutputOwned> {
outputs.iter().map(|o| generate_output_nonfunding_one(o)).collect()
outputs.iter().map(generate_output_nonfunding_one).collect()
}

/// Generate a single output that is the funding output
Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); })(); Fix remaining feedback and other nits for 2989 by dunxen · Pull Request #3219 · lightningdevkit/rust-lightning · GitHub
Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 22 additions & 25 deletions lightning/src/ln/interactivetxs.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -157,7 +157,7 @@ impl ConstructedTransaction {
weight.checked_add(estimate_input_weight(input.prev_output())).unwrap_or(Weight::MAX)
});
let outputs_weight = self.outputs.iter().fold(Weight::from_wu(0), |weight, output| {
weight.checked_add(get_output_weight(&output.script_pubkey())).unwrap_or(Weight::MAX)
weight.checked_add(get_output_weight(output.script_pubkey())).unwrap_or(Weight::MAX)
});
Weight::from_wu(TX_COMMON_FIELDS_WEIGHT)
.checked_add(inputs_weight)
Expand DownExpand Up@@ -297,7 +297,7 @@ impl NegotiationContext {
.iter()
.filter(|(serial_id, _)| self.is_serial_id_valid_for_counterparty(serial_id))
.fold(0u64, |weight, (_, output)| {
weight.saturating_add(get_output_weight(&output.script_pubkey()).to_wu())
weight.saturating_add(get_output_weight(output.script_pubkey()).to_wu())
}),
)
}
Expand DownExpand Up@@ -508,7 +508,7 @@ impl NegotiationContext {
sequence: Sequence(msg.sequence),
..Default::default()
};
if !self.prevtx_outpoints.insert(txin.previous_output.clone()) {
if !self.prevtx_outpoints.insert(txin.previous_output) {
// We have added an input that already exists
return Err(AbortReason::PrevTxOutInvalid);
}
Expand DownExpand Up@@ -878,7 +878,7 @@ impl StateMachine {
}

#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum AddingRole {
enum AddingRole {
Local,
Remote,
}
Expand All@@ -892,7 +892,7 @@ pub struct LocalOrRemoteInput {
}

#[derive(Clone, Debug, Eq, PartialEq)]
pub enum InteractiveTxInput {
enum InteractiveTxInput {
Local(LocalOrRemoteInput),
Remote(LocalOrRemoteInput),
// TODO(splicing) SharedInput should be added
Expand DownExpand Up@@ -925,7 +925,7 @@ impl SharedOwnedOutput {
/// its ownership -- value fully owned by the adder or jointly
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum OutputOwned {
/// Belongs to local node -- controlled exclusively and fully belonging to local node
/// Belongs to a single party -- controlled exclusively and fully belonging to a single party
Single(TxOut),
/// Output with shared control, but fully belonging to local node
SharedControlFullyOwned(TxOut),
Expand DownExpand Up@@ -979,7 +979,7 @@ impl OutputOwned {
}

#[derive(Clone, Debug, Eq, PartialEq)]
pub struct InteractiveTxOutput {
struct InteractiveTxOutput {
serial_id: SerialId,
added_by: AddingRole,
output: OutputOwned,
Expand DownExpand Up@@ -1055,6 +1055,7 @@ pub(crate) struct InteractiveTxConstructor {
outputs_to_contribute: Vec<(SerialId, OutputOwned)>,
}

#[allow(clippy::enum_variant_names)] // Clippy doesn't like the repeated `Tx` prefix here
pub(crate) enum InteractiveTxMessageSend {
TxAddInput(msgs::TxAddInput),
TxAddOutput(msgs::TxAddOutput),
Expand DownExpand Up@@ -1126,7 +1127,7 @@ impl InteractiveTxConstructor {
},
OutputOwned::Shared(output) => {
// Sanity check
if output.local_owned > output.tx_out.value.to_sat() {
if output.local_owned >= output.tx_out.value.to_sat() {
return Err(AbortReason::InvalidLowFundingOutputValue);
}
Some((output.tx_out.script_pubkey.clone(), output.local_owned))
Expand DownExpand Up@@ -1328,12 +1329,12 @@ mod tests {
fn get_secure_random_bytes(&self) -> [u8; 32] {
let mut res = [0u8; 32];
let increment = self.0.get_increment();
for i in 0..32 {
for (i, byte) in res.iter_mut().enumerate() {
// Rotate the increment value by 'i' bits to the right, to avoid clashes
// when `generate_local_serial_id` does a parity flip on consecutive calls for the
// same party.
let rotated_increment = increment.rotate_right(i as u32);
res[i] = (rotated_increment & 0xff) as u8;
*byte = (rotated_increment & 0xff) as u8;
}
res
}
Expand DownExpand Up@@ -1402,7 +1403,7 @@ mod tests {
if shared_outputs_by_a.len() > 1 {
println!("Test warning: Expected at most one shared output. NodeA");
}
let shared_output_by_a = if shared_outputs_by_a.len() >= 1 {
let shared_output_by_a = if !shared_outputs_by_a.is_empty() {
Some(shared_outputs_by_a[0].value())
} else {
None
Expand All@@ -1412,7 +1413,7 @@ mod tests {
if shared_outputs_by_b.len() > 1 {
println!("Test warning: Expected at most one shared output. NodeB");
}
let shared_output_by_b = if shared_outputs_by_b.len() >= 1 {
let shared_output_by_b = if !shared_outputs_by_b.is_empty() {
Some(shared_outputs_by_b[0].value())
} else {
None
Expand All@@ -1424,23 +1425,19 @@ mod tests {
&session.a_expected_remote_shared_output
{
a_expected_remote_shared_output.1
} else if !shared_outputs_by_a.is_empty() {
shared_outputs_by_a[0].local_value(AddingRole::Local)
} else {
if shared_outputs_by_a.len() >= 1 {
shared_outputs_by_a[0].local_value(AddingRole::Local)
} else {
0
}
0
};
let expected_by_b = if let Some(b_expected_remote_shared_output) =
&session.b_expected_remote_shared_output
{
b_expected_remote_shared_output.1
} else if !shared_outputs_by_b.is_empty() {
shared_outputs_by_b[0].local_value(AddingRole::Local)
} else {
if shared_outputs_by_b.len() >= 1 {
shared_outputs_by_b[0].local_value(AddingRole::Local)
} else {
0
}
0
};

let expected_sum = expected_by_a + expected_by_b;
Expand All@@ -1458,7 +1455,7 @@ mod tests {
true,
tx_locktime,
session.inputs_a,
session.outputs_a.iter().map(|o| o.clone()).collect(),
session.outputs_a.to_vec(),
session.a_expected_remote_shared_output,
) {
Ok(r) => r,
Expand All@@ -1479,7 +1476,7 @@ mod tests {
false,
tx_locktime,
session.inputs_b,
session.outputs_b.iter().map(|o| o.clone()).collect(),
session.outputs_b.to_vec(),
session.b_expected_remote_shared_output,
) {
Ok(r) => r,
Expand DownExpand Up@@ -1665,7 +1662,7 @@ mod tests {
}

fn generate_outputs(outputs: &[TestOutput]) -> Vec<OutputOwned> {
outputs.iter().map(|o| generate_output_nonfunding_one(o)).collect()
outputs.iter().map(generate_output_nonfunding_one).collect()
}

/// Generate a single output that is the funding output
Expand Down