Skip to content

Commit 8eff650

Browse files
authored
Merge pull request #3219 from dunxen/2024-08-PR2989-followups
Fix remaining feedback and other nits for 2989
2 parents 3d76753 + 016d7e1 commit 8eff650

File tree

1 file changed

+22
-25
lines changed

1 file changed

+22
-25
lines changed

lightning/src/ln/interactivetxs.rs

+22-25
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ impl ConstructedTransaction {
157157
weight.checked_add(estimate_input_weight(input.prev_output())).unwrap_or(Weight::MAX)
158158
});
159159
let outputs_weight = self.outputs.iter().fold(Weight::from_wu(0), |weight, output| {
160-
weight.checked_add(get_output_weight(&output.script_pubkey())).unwrap_or(Weight::MAX)
160+
weight.checked_add(get_output_weight(output.script_pubkey())).unwrap_or(Weight::MAX)
161161
});
162162
Weight::from_wu(TX_COMMON_FIELDS_WEIGHT)
163163
.checked_add(inputs_weight)
@@ -297,7 +297,7 @@ impl NegotiationContext {
297297
.iter()
298298
.filter(|(serial_id, _)| self.is_serial_id_valid_for_counterparty(serial_id))
299299
.fold(0u64, |weight, (_, output)| {
300-
weight.saturating_add(get_output_weight(&output.script_pubkey()).to_wu())
300+
weight.saturating_add(get_output_weight(output.script_pubkey()).to_wu())
301301
}),
302302
)
303303
}
@@ -508,7 +508,7 @@ impl NegotiationContext {
508508
sequence: Sequence(msg.sequence),
509509
..Default::default()
510510
};
511-
if !self.prevtx_outpoints.insert(txin.previous_output.clone()) {
511+
if !self.prevtx_outpoints.insert(txin.previous_output) {
512512
// We have added an input that already exists
513513
return Err(AbortReason::PrevTxOutInvalid);
514514
}
@@ -878,7 +878,7 @@ impl StateMachine {
878878
}
879879

880880
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
881-
pub enum AddingRole {
881+
enum AddingRole {
882882
Local,
883883
Remote,
884884
}
@@ -892,7 +892,7 @@ pub struct LocalOrRemoteInput {
892892
}
893893

894894
#[derive(Clone, Debug, Eq, PartialEq)]
895-
pub enum InteractiveTxInput {
895+
enum InteractiveTxInput {
896896
Local(LocalOrRemoteInput),
897897
Remote(LocalOrRemoteInput),
898898
// TODO(splicing) SharedInput should be added
@@ -925,7 +925,7 @@ impl SharedOwnedOutput {
925925
/// its ownership -- value fully owned by the adder or jointly
926926
#[derive(Clone, Debug, Eq, PartialEq)]
927927
pub enum OutputOwned {
928-
/// Belongs to local node -- controlled exclusively and fully belonging to local node
928+
/// Belongs to a single party -- controlled exclusively and fully belonging to a single party
929929
Single(TxOut),
930930
/// Output with shared control, but fully belonging to local node
931931
SharedControlFullyOwned(TxOut),
@@ -979,7 +979,7 @@ impl OutputOwned {
979979
}
980980

981981
#[derive(Clone, Debug, Eq, PartialEq)]
982-
pub struct InteractiveTxOutput {
982+
struct InteractiveTxOutput {
983983
serial_id: SerialId,
984984
added_by: AddingRole,
985985
output: OutputOwned,
@@ -1055,6 +1055,7 @@ pub(crate) struct InteractiveTxConstructor {
10551055
outputs_to_contribute: Vec<(SerialId, OutputOwned)>,
10561056
}
10571057

1058+
#[allow(clippy::enum_variant_names)] // Clippy doesn't like the repeated `Tx` prefix here
10581059
pub(crate) enum InteractiveTxMessageSend {
10591060
TxAddInput(msgs::TxAddInput),
10601061
TxAddOutput(msgs::TxAddOutput),
@@ -1126,7 +1127,7 @@ impl InteractiveTxConstructor {
11261127
},
11271128
OutputOwned::Shared(output) => {
11281129
// Sanity check
1129-
if output.local_owned > output.tx_out.value.to_sat() {
1130+
if output.local_owned >= output.tx_out.value.to_sat() {
11301131
return Err(AbortReason::InvalidLowFundingOutputValue);
11311132
}
11321133
Some((output.tx_out.script_pubkey.clone(), output.local_owned))
@@ -1328,12 +1329,12 @@ mod tests {
13281329
fn get_secure_random_bytes(&self) -> [u8; 32] {
13291330
let mut res = [0u8; 32];
13301331
let increment = self.0.get_increment();
1331-
for i in 0..32 {
1332+
for (i, byte) in res.iter_mut().enumerate() {
13321333
// Rotate the increment value by 'i' bits to the right, to avoid clashes
13331334
// when `generate_local_serial_id` does a parity flip on consecutive calls for the
13341335
// same party.
13351336
let rotated_increment = increment.rotate_right(i as u32);
1336-
res[i] = (rotated_increment & 0xff) as u8;
1337+
*byte = (rotated_increment & 0xff) as u8;
13371338
}
13381339
res
13391340
}
@@ -1402,7 +1403,7 @@ mod tests {
14021403
if shared_outputs_by_a.len() > 1 {
14031404
println!("Test warning: Expected at most one shared output. NodeA");
14041405
}
1405-
let shared_output_by_a = if shared_outputs_by_a.len() >= 1 {
1406+
let shared_output_by_a = if !shared_outputs_by_a.is_empty() {
14061407
Some(shared_outputs_by_a[0].value())
14071408
} else {
14081409
None
@@ -1412,7 +1413,7 @@ mod tests {
14121413
if shared_outputs_by_b.len() > 1 {
14131414
println!("Test warning: Expected at most one shared output. NodeB");
14141415
}
1415-
let shared_output_by_b = if shared_outputs_by_b.len() >= 1 {
1416+
let shared_output_by_b = if !shared_outputs_by_b.is_empty() {
14161417
Some(shared_outputs_by_b[0].value())
14171418
} else {
14181419
None
@@ -1424,23 +1425,19 @@ mod tests {
14241425
&session.a_expected_remote_shared_output
14251426
{
14261427
a_expected_remote_shared_output.1
1428+
} else if !shared_outputs_by_a.is_empty() {
1429+
shared_outputs_by_a[0].local_value(AddingRole::Local)
14271430
} else {
1428-
if shared_outputs_by_a.len() >= 1 {
1429-
shared_outputs_by_a[0].local_value(AddingRole::Local)
1430-
} else {
1431-
0
1432-
}
1431+
0
14331432
};
14341433
let expected_by_b = if let Some(b_expected_remote_shared_output) =
14351434
&session.b_expected_remote_shared_output
14361435
{
14371436
b_expected_remote_shared_output.1
1437+
} else if !shared_outputs_by_b.is_empty() {
1438+
shared_outputs_by_b[0].local_value(AddingRole::Local)
14381439
} else {
1439-
if shared_outputs_by_b.len() >= 1 {
1440-
shared_outputs_by_b[0].local_value(AddingRole::Local)
1441-
} else {
1442-
0
1443-
}
1440+
0
14441441
};
14451442

14461443
let expected_sum = expected_by_a + expected_by_b;
@@ -1458,7 +1455,7 @@ mod tests {
14581455
true,
14591456
tx_locktime,
14601457
session.inputs_a,
1461-
session.outputs_a.iter().map(|o| o.clone()).collect(),
1458+
session.outputs_a.to_vec(),
14621459
session.a_expected_remote_shared_output,
14631460
) {
14641461
Ok(r) => r,
@@ -1479,7 +1476,7 @@ mod tests {
14791476
false,
14801477
tx_locktime,
14811478
session.inputs_b,
1482-
session.outputs_b.iter().map(|o| o.clone()).collect(),
1479+
session.outputs_b.to_vec(),
14831480
session.b_expected_remote_shared_output,
14841481
) {
14851482
Ok(r) => r,
@@ -1665,7 +1662,7 @@ mod tests {
16651662
}
16661663

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

16711668
/// Generate a single output that is the funding output

0 commit comments

Comments
 (0)