Skip to content
This repository has been archived by the owner on Oct 3, 2023. It is now read-only.

Commit

Permalink
[WIP] Implement add_custom_output protocol
Browse files Browse the repository at this point in the history
fixup! [WIP] Implement add_custom_output protocol

Just some formattings.

[WIP] Continue implementing add_custom_output protocol

fixup! [WIP] Continue implementing add_custom_output protocol

Some formattings

fixup! [WIP] Continue implementing add_custom_output protocol

Some formattings

Add todo: can this be removed?

In this case we did not update the fee rate

Fix: mostly using correct variable

Impl readable and writable to UpdateAddCustomOutput

chore: remove comment

This was done now :)

chore: some more formattings

make tests work

We have a test which pretends to add a custom output to the commit transaction. Msgs are being exchanged and commit transactions are being revoked. What is missing is to actually add the output

[WIP] Add custom outputs to commit transaction

change custom output value to 1234567 to find it easier in logs

fixup! [WIP] Add custom outputs to commit transaction

pass in a ref of a ref of course :)

chore: fix formatting

chore: Mark our TODOs with 10101 tag

missing docs
  • Loading branch information
luckysori authored and bonomat committed Nov 2, 2022
1 parent 3b2f694 commit b56f6ae
Show file tree
Hide file tree
Showing 15 changed files with 964 additions and 184 deletions.
10 changes: 5 additions & 5 deletions fuzz/src/chanmon_consistency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out) {
let expect_drop_id = if let Some(id) = expect_drop_node { Some(nodes[id].get_our_node_id()) } else { None };
for event in $excess_events {
let push_a = match event {
events::MessageSendEvent::UpdateHTLCs { ref node_id, .. } => {
events::MessageSendEvent::UpdateCommitmentOutputs { ref node_id, .. } => {
if Some(*node_id) == expect_drop_id { panic!("peer_disconnected should drop msgs bound for the disconnected peer"); }
*node_id == a_id
},
Expand Down Expand Up @@ -670,7 +670,7 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out) {
for event in &mut events_iter {
had_events = true;
match event {
events::MessageSendEvent::UpdateHTLCs { node_id, updates: CommitmentUpdate { update_add_htlcs, update_fail_htlcs, update_fulfill_htlcs, update_fail_malformed_htlcs, update_fee, commitment_signed } } => {
events::MessageSendEvent::UpdateCommitmentOutputs { node_id, updates: CommitmentUpdate { update_add_htlcs, update_fail_htlcs, update_fulfill_htlcs, update_fail_malformed_htlcs, update_fee, commitment_signed } } => {
for (idx, dest) in nodes.iter().enumerate() {
if dest.get_our_node_id() == node_id {
for update_add in update_add_htlcs.iter() {
Expand Down Expand Up @@ -708,7 +708,7 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out) {
!update_fail_htlcs.is_empty() || !update_fail_malformed_htlcs.is_empty();
if $limit_events != ProcessMessages::AllMessages && processed_change {
// If we only want to process some messages, don't deliver the CS until later.
extra_ev = Some(events::MessageSendEvent::UpdateHTLCs { node_id, updates: CommitmentUpdate {
extra_ev = Some(events::MessageSendEvent::UpdateCommitmentOutputs { node_id, updates: CommitmentUpdate {
update_add_htlcs: Vec::new(),
update_fail_htlcs: Vec::new(),
update_fulfill_htlcs: Vec::new(),
Expand Down Expand Up @@ -783,7 +783,7 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out) {
if $counterparty_id == 0 {
for event in nodes[0].get_and_clear_pending_msg_events() {
match event {
events::MessageSendEvent::UpdateHTLCs { .. } => {},
events::MessageSendEvent::UpdateCommitmentOutputs { .. } => {},
events::MessageSendEvent::SendRevokeAndACK { .. } => {},
events::MessageSendEvent::SendChannelReestablish { .. } => {},
events::MessageSendEvent::SendChannelReady { .. } => {},
Expand All @@ -804,7 +804,7 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out) {
} else {
for event in nodes[2].get_and_clear_pending_msg_events() {
match event {
events::MessageSendEvent::UpdateHTLCs { .. } => {},
events::MessageSendEvent::UpdateCommitmentOutputs { .. } => {},
events::MessageSendEvent::SendRevokeAndACK { .. } => {},
events::MessageSendEvent::SendChannelReestablish { .. } => {},
events::MessageSendEvent::SendChannelReady { .. } => {},
Expand Down
2 changes: 1 addition & 1 deletion lightning-invoice/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1054,7 +1054,7 @@ mod test {
let mut events = nodes[0].node.get_and_clear_pending_msg_events();
assert_eq!(events.len(), 1);
let fwd_idx = match events[0] {
MessageSendEvent::UpdateHTLCs { node_id, .. } => {
MessageSendEvent::UpdateCommitmentOutputs { node_id, .. } => {
if node_id == nodes[1].node.get_our_node_id() {
1
} else { 2 }
Expand Down
163 changes: 126 additions & 37 deletions lightning/src/ln/chan_utils.rs

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions lightning/src/ln/chanmon_update_fail_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ fn do_test_monitor_temporary_update_fail(disconnect_count: usize) {
let events_2 = nodes[1].node.get_and_clear_pending_msg_events();
assert_eq!(events_2.len(), 1);
let (bs_initial_fulfill, bs_initial_commitment_signed) = match events_2[0] {
MessageSendEvent::UpdateHTLCs { ref node_id, updates: msgs::CommitmentUpdate { ref update_add_htlcs, ref update_fulfill_htlcs, ref update_fail_htlcs, ref update_fail_malformed_htlcs, ref update_fee, ref commitment_signed } } => {
MessageSendEvent::UpdateCommitmentOutputs { ref node_id, updates: msgs::CommitmentUpdate { ref update_add_htlcs, ref update_fulfill_htlcs, ref update_fail_htlcs, ref update_fail_malformed_htlcs, ref update_fee, ref commitment_signed, ref update_add_custom_output } } => {
assert_eq!(*node_id, nodes[0].node.get_our_node_id());
assert!(update_add_htlcs.is_empty());
assert_eq!(update_fulfill_htlcs.len(), 1);
Expand Down Expand Up @@ -654,7 +654,7 @@ fn test_monitor_update_fail_cs() {
_ => panic!("Unexpected event"),
}
match responses[1] {
MessageSendEvent::UpdateHTLCs { ref updates, ref node_id } => {
MessageSendEvent::UpdateCommitmentOutputs { ref updates, ref node_id } => {
assert!(updates.update_add_htlcs.is_empty());
assert!(updates.update_fulfill_htlcs.is_empty());
assert!(updates.update_fail_htlcs.is_empty());
Expand Down Expand Up @@ -936,7 +936,7 @@ fn do_test_monitor_update_fail_raa(test_ignore_second_cs: bool) {
// Note that the ordering of the events for different nodes is non-prescriptive, though the
// ordering of the two events that both go to nodes[2] have to stay in the same order.
let messages_a = match events_3.pop().unwrap() {
MessageSendEvent::UpdateHTLCs { node_id, mut updates } => {
MessageSendEvent::UpdateCommitmentOutputs { node_id, mut updates } => {
assert_eq!(node_id, nodes[0].node.get_our_node_id());
assert!(updates.update_fulfill_htlcs.is_empty());
assert_eq!(updates.update_fail_htlcs.len(), 1);
Expand Down Expand Up @@ -1004,7 +1004,7 @@ fn do_test_monitor_update_fail_raa(test_ignore_second_cs: bool) {
as_cs = get_htlc_update_msgs!(nodes[1], nodes[2].node.get_our_node_id());

match bs_revoke_and_commit[1] {
MessageSendEvent::UpdateHTLCs { ref node_id, ref updates } => {
MessageSendEvent::UpdateCommitmentOutputs { ref node_id, ref updates } => {
assert_eq!(*node_id, nodes[1].node.get_our_node_id());
assert!(updates.update_add_htlcs.is_empty());
assert!(updates.update_fail_htlcs.is_empty());
Expand Down Expand Up @@ -1364,7 +1364,7 @@ fn claim_while_disconnected_monitor_update_fail() {
assert_eq!(bs_msgs.len(), 2);

match bs_msgs[0] {
MessageSendEvent::UpdateHTLCs { ref node_id, ref updates } => {
MessageSendEvent::UpdateCommitmentOutputs { ref node_id, ref updates } => {
assert_eq!(*node_id, nodes[0].node.get_our_node_id());
nodes[0].node.handle_update_fulfill_htlc(&nodes[1].node.get_our_node_id(), &updates.update_fulfill_htlcs[0]);
nodes[0].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), &updates.commitment_signed);
Expand Down Expand Up @@ -2040,7 +2040,7 @@ fn test_pending_update_fee_ack_on_reconnect() {
nodes[1].node.handle_channel_reestablish(&nodes[0].node.get_our_node_id(), &as_connect_msg);
let bs_resend_msgs = nodes[1].node.get_and_clear_pending_msg_events();
assert_eq!(bs_resend_msgs.len(), 3);
if let MessageSendEvent::UpdateHTLCs { ref updates, .. } = bs_resend_msgs[0] {
if let MessageSendEvent::UpdateCommitmentOutputs { ref updates, .. } = bs_resend_msgs[0] {
assert_eq!(*updates, bs_initial_send_msgs);
} else { panic!(); }
if let MessageSendEvent::SendRevokeAndACK { ref msg, .. } = bs_resend_msgs[1] {
Expand Down Expand Up @@ -2173,7 +2173,7 @@ fn do_update_fee_resend_test(deliver_update: bool, parallel_updates: bool) {
let mut as_reconnect_msgs = nodes[0].node.get_and_clear_pending_msg_events();
assert_eq!(as_reconnect_msgs.len(), 2);
if let MessageSendEvent::SendChannelUpdate { .. } = as_reconnect_msgs.pop().unwrap() {} else { panic!(); }
let update_msgs = if let MessageSendEvent::UpdateHTLCs { updates, .. } = as_reconnect_msgs.pop().unwrap()
let update_msgs = if let MessageSendEvent::UpdateCommitmentOutputs { updates, .. } = as_reconnect_msgs.pop().unwrap()
{ updates } else { panic!(); };
assert!(update_msgs.update_fee.is_some());
nodes[1].node.handle_update_fee(&nodes[0].node.get_our_node_id(), update_msgs.update_fee.as_ref().unwrap());
Expand Down Expand Up @@ -2379,7 +2379,7 @@ fn do_channel_holding_cell_serialize(disconnect: bool, reload_a: bool) {
check_added_monitors!(nodes[0], 1);

let commitment_msg = match events.pop().unwrap() {
MessageSendEvent::UpdateHTLCs { node_id, updates } => {
MessageSendEvent::UpdateCommitmentOutputs { node_id, updates } => {
assert_eq!(node_id, nodes[1].node.get_our_node_id());
assert!(updates.update_fail_htlcs.is_empty());
assert!(updates.update_fail_malformed_htlcs.is_empty());
Expand Down Expand Up @@ -2686,7 +2686,7 @@ fn double_temp_error() {
assert_eq!(events.len(), 1);
let (update_fulfill_1, commitment_signed_b1, node_id) = {
match &events[0] {
&MessageSendEvent::UpdateHTLCs { ref node_id, updates: msgs::CommitmentUpdate { ref update_add_htlcs, ref update_fulfill_htlcs, ref update_fail_htlcs, ref update_fail_malformed_htlcs, ref update_fee, ref commitment_signed } } => {
&MessageSendEvent::UpdateCommitmentOutputs { ref node_id, updates: msgs::CommitmentUpdate { ref update_add_htlcs, ref update_fulfill_htlcs, ref update_fail_htlcs, ref update_fail_malformed_htlcs, ref update_fee, ref commitment_signed, ref update_add_custom_output } } => {
assert!(update_add_htlcs.is_empty());
assert_eq!(update_fulfill_htlcs.len(), 1);
assert!(update_fail_htlcs.is_empty());
Expand Down Expand Up @@ -2717,7 +2717,7 @@ fn double_temp_error() {
let events = nodes[1].node.get_and_clear_pending_msg_events();
assert_eq!(events.len(), 2);
(match &events[0] {
MessageSendEvent::UpdateHTLCs { node_id, updates } => {
MessageSendEvent::UpdateCommitmentOutputs { node_id, updates } => {
assert_eq!(*node_id, nodes[0].node.get_our_node_id());
assert!(updates.update_add_htlcs.is_empty());
assert!(updates.update_fail_htlcs.is_empty());
Expand Down
Loading

0 comments on commit b56f6ae

Please sign in to comment.