Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rustfmt: Run on lightning-background-processor #3138

Merged
merged 2 commits into from
Jul 14, 2024

Conversation

tnull
Copy link
Contributor

@tnull tnull commented Jun 20, 2024

.. probably will want to wait with this until #3125 landed, happy to rebase then.

@dunxen
Copy link
Contributor

dunxen commented Jun 24, 2024

SGTM, but I'll check the diff after your rebase.

@tnull
Copy link
Contributor Author

tnull commented Jul 1, 2024

SGTM, but I'll check the diff after your rebase.

Rebased

@codecov-commenter
Copy link

codecov-commenter commented Jul 1, 2024

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

Attention: Patch coverage is 93.28358% with 36 lines in your changes missing coverage. Please review.

Project coverage is 89.77%. Comparing base (bcacf85) to head (438515d).

Files Patch % Lines
lightning-background-processor/src/lib.rs 93.28% 23 Missing and 13 partials ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3138      +/-   ##
==========================================
+ Coverage   89.76%   89.77%   +0.01%     
==========================================
  Files         121      121              
  Lines       99790   100149     +359     
  Branches    99790   100149     +359     
==========================================
+ Hits        89572    89911     +339     
- Misses       7548     7568      +20     
  Partials     2670     2670              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

dunxen
dunxen previously approved these changes Jul 1, 2024
Copy link
Contributor

@dunxen dunxen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get the same result when running cargo fmt --package lightning-background-processor on the base of the PR. I have no opinions on the output so LGTM 👍

Copy link
Collaborator

@TheBlueMatt TheBlueMatt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like there's some obvious improvements here to go? These should probably mostly be caught before the PR is opened.

lightning-background-processor/src/lib.rs Outdated Show resolved Hide resolved
lightning-background-processor/src/lib.rs Outdated Show resolved Hide resolved
lightning-background-processor/src/lib.rs Outdated Show resolved Hide resolved
lightning-background-processor/src/lib.rs Outdated Show resolved Hide resolved
lightning-background-processor/src/lib.rs Outdated Show resolved Hide resolved
@tnull
Copy link
Contributor Author

tnull commented Jul 9, 2024

Addressed outstanding feedback.

Copy link
Collaborator

@TheBlueMatt TheBlueMatt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only changes since @dunxen's ACK are straightforward, even if the diff isn't tiny. Gonna go ahead and land.

$ git range-diff 3ccf06416091e107f443ee92027501105c48054b..e86d2199e459107d59c24e6271668ecf153af680 bcacf85a796e30dd6ace4515f46be40e300245a5..438515d2c47150af478d206bab97bd493d45b3cc
-:  --------- > 1:  a60f7a7fc Prepare `lightning-background-processor/src/lib.rs`
1:  e86d2199e ! 2:  438515d2c `rustfmt`: Run on `lightning-background-processor/src/lib.rs`
    @@ lightning-background-processor/src/lib.rs: pub async fn process_events_async<
      ) -> Result<(), lightning::io::Error>
      where
        UL::Target: 'static + UtxoLookup,
    -@@ lightning-background-processor/src/lib.rs: where
    -           let logger = &logger;
    -           let persister = &persister;
    -           let fetch_time = &fetch_time;
    --          Box::pin(async move { // We should be able to drop the Box once our MSRV is 1.68
    -+          Box::pin(async move {
    -+                  // We should be able to drop the Box once our MSRV is 1.68
    -                   if let Some(network_graph) = network_graph {
    -                           handle_network_graph_update(network_graph, &event)
    -                   }
     @@ lightning-background-processor/src/lib.rs: where
                })
        };
    @@ lightning-background-processor/src/lib.rs: mod tests {

                for i in 0..num_nodes {
     -                  for j in (i+1)..num_nodes {
    --                          nodes[i].node.peer_connected(&nodes[j].node.get_our_node_id(), &Init {
    --                                  features: nodes[j].node.init_features(), networks: None, remote_network_address: None
    --                          }, true).unwrap();
    --                          nodes[j].node.peer_connected(&nodes[i].node.get_our_node_id(), &Init {
    --                                  features: nodes[i].node.init_features(), networks: None, remote_network_address: None
    --                          }, false).unwrap();
     +                  for j in (i + 1)..num_nodes {
    +                           let init_i = Init {
    +-                                  features: nodes[j].node.init_features(), networks: None, remote_network_address: None
    ++                                  features: nodes[j].node.init_features(),
    ++                                  networks: None,
    ++                                  remote_network_address: None,
    +                           };
    +-                          nodes[i].node.peer_connected(&nodes[j].node.get_our_node_id(), &init_i, true).unwrap();
     +                          nodes[i]
     +                                  .node
    -+                                  .peer_connected(
    -+                                          &nodes[j].node.get_our_node_id(),
    -+                                          &Init {
    -+                                                  features: nodes[j].node.init_features(),
    -+                                                  networks: None,
    -+                                                  remote_network_address: None,
    -+                                          },
    -+                                          true,
    -+                                  )
    ++                                  .peer_connected(&nodes[j].node.get_our_node_id(), &init_i, true)
     +                                  .unwrap();
    +                           let init_j = Init {
    +-                                  features: nodes[i].node.init_features(), networks: None, remote_network_address: None
    ++                                  features: nodes[i].node.init_features(),
    ++                                  networks: None,
    ++                                  remote_network_address: None,
    +                           };
    +-                          nodes[j].node.peer_connected(&nodes[i].node.get_our_node_id(), &init_j, false).unwrap();
     +                          nodes[j]
     +                                  .node
    -+                                  .peer_connected(
    -+                                          &nodes[i].node.get_our_node_id(),
    -+                                          &Init {
    -+                                                  features: nodes[i].node.init_features(),
    -+                                                  networks: None,
    -+                                                  remote_network_address: None,
    -+                                          },
    -+                                          false,
    -+                                  )
    ++                                  .peer_connected(&nodes[i].node.get_our_node_id(), &init_j, false)
     +                                  .unwrap();
                        }
                }
    @@ lightning-background-processor/src/lib.rs: mod tests {
                        assert_eq!(events.len(), 1);
     -                  let (temporary_channel_id, tx) = handle_funding_generation_ready!(events[0], $channel_value);
     -                  $node_a.node.funding_transaction_generated(&temporary_channel_id, &$node_b.node.get_our_node_id(), tx.clone()).unwrap();
    --                  $node_b.node.handle_funding_created(&$node_a.node.get_our_node_id(), &get_event_msg!($node_a, MessageSendEvent::SendFundingCreated, $node_b.node.get_our_node_id()));
    +-                  let msg_a = get_event_msg!($node_a, MessageSendEvent::SendFundingCreated, $node_b.node.get_our_node_id());
     +                  let (temporary_channel_id, tx) =
     +                          handle_funding_generation_ready!(events[0], $channel_value);
     +                  $node_a
    @@ lightning-background-processor/src/lib.rs: mod tests {
     +                                  tx.clone(),
     +                          )
     +                          .unwrap();
    -+                  $node_b.node.handle_funding_created(
    -+                          &$node_a.node.get_our_node_id(),
    -+                          &get_event_msg!(
    -+                                  $node_a,
    -+                                  MessageSendEvent::SendFundingCreated,
    -+                                  $node_b.node.get_our_node_id()
    -+                          ),
    ++                  let msg_a = get_event_msg!(
    ++                          $node_a,
    ++                          MessageSendEvent::SendFundingCreated,
    ++                          $node_b.node.get_our_node_id()
     +                  );
    +                   $node_b.node.handle_funding_created(&$node_a.node.get_our_node_id(), &msg_a);
                        get_event!($node_b, Event::ChannelPending);
    --                  $node_a.node.handle_funding_signed(&$node_b.node.get_our_node_id(), &get_event_msg!($node_b, MessageSendEvent::SendFundingSigned, $node_a.node.get_our_node_id()));
    -+                  $node_a.node.handle_funding_signed(
    -+                          &$node_b.node.get_our_node_id(),
    -+                          &get_event_msg!(
    -+                                  $node_b,
    -+                                  MessageSendEvent::SendFundingSigned,
    -+                                  $node_a.node.get_our_node_id()
    -+                          ),
    +-                  let msg_b = get_event_msg!($node_b, MessageSendEvent::SendFundingSigned, $node_a.node.get_our_node_id());
    ++                  let msg_b = get_event_msg!(
    ++                          $node_b,
    ++                          MessageSendEvent::SendFundingSigned,
    ++                          $node_a.node.get_our_node_id()
     +                  );
    +                   $node_a.node.handle_funding_signed(&$node_b.node.get_our_node_id(), &msg_b);
                        get_event!($node_a, Event::ChannelPending);
                        tx
     -          }}
    @@ lightning-background-processor/src/lib.rs: mod tests {
        macro_rules! begin_open_channel {
                ($node_a: expr, $node_b: expr, $channel_value: expr) => {{
     -                  $node_a.node.create_channel($node_b.node.get_our_node_id(), $channel_value, 100, 42, None, None).unwrap();
    --                  $node_b.node.handle_open_channel(&$node_a.node.get_our_node_id(), &get_event_msg!($node_a, MessageSendEvent::SendOpenChannel, $node_b.node.get_our_node_id()));
    --                  $node_a.node.handle_accept_channel(&$node_b.node.get_our_node_id(), &get_event_msg!($node_b, MessageSendEvent::SendAcceptChannel, $node_a.node.get_our_node_id()));
    --          }}
    +-                  let msg_a = get_event_msg!($node_a, MessageSendEvent::SendOpenChannel, $node_b.node.get_our_node_id());
     +                  $node_a
     +                          .node
     +                          .create_channel($node_b.node.get_our_node_id(), $channel_value, 100, 42, None, None)
     +                          .unwrap();
    -+                  $node_b.node.handle_open_channel(
    -+                          &$node_a.node.get_our_node_id(),
    -+                          &get_event_msg!(
    -+                                  $node_a,
    -+                                  MessageSendEvent::SendOpenChannel,
    -+                                  $node_b.node.get_our_node_id()
    -+                          ),
    ++                  let msg_a = get_event_msg!(
    ++                          $node_a,
    ++                          MessageSendEvent::SendOpenChannel,
    ++                          $node_b.node.get_our_node_id()
     +                  );
    -+                  $node_a.node.handle_accept_channel(
    -+                          &$node_b.node.get_our_node_id(),
    -+                          &get_event_msg!(
    -+                                  $node_b,
    -+                                  MessageSendEvent::SendAcceptChannel,
    -+                                  $node_a.node.get_our_node_id()
    -+                          ),
    +                   $node_b.node.handle_open_channel(&$node_a.node.get_our_node_id(), &msg_a);
    +-                  let msg_b = get_event_msg!($node_b, MessageSendEvent::SendAcceptChannel, $node_a.node.get_our_node_id());
    ++                  let msg_b = get_event_msg!(
    ++                          $node_b,
    ++                          MessageSendEvent::SendAcceptChannel,
    ++                          $node_a.node.get_our_node_id()
     +                  );
    +                   $node_a.node.handle_accept_channel(&$node_b.node.get_our_node_id(), &msg_b);
    +-          }}
     +          }};
        }

    @@ lightning-background-processor/src/lib.rs: mod tests {
        }

        fn confirm_transaction_depth(node: &mut Node, tx: &Transaction, depth: u32) {
    -@@ lightning-background-processor/src/lib.rs: mod tests {
    -                                   // We need the TestBroadcaster to know about the new height so that it doesn't think
    -                                   // we're violating the time lock requirements of transactions broadcasted at that
    -                                   // point.
    --                                  node.tx_broadcaster.blocks.lock().unwrap().push((genesis_block(Network::Bitcoin), height));
    -+                                  node.tx_broadcaster
    -+                                          .blocks
    -+                                          .lock()
    -+                                          .unwrap()
    -+                                          .push((genesis_block(Network::Bitcoin), height));
    -                                   node.node.best_block_updated(&header, height);
    -                                   node.chain_monitor.best_block_updated(&header, height);
    -                                   node.sweeper.best_block_updated(&header, height);
    -@@ lightning-background-processor/src/lib.rs: mod tests {
    -                           // We need the TestBroadcaster to know about the new height so that it doesn't think
    -                           // we're violating the time lock requirements of transactions broadcasted at that
    -                           // point.
    --                          node.tx_broadcaster.blocks.lock().unwrap().push((genesis_block(Network::Bitcoin), height));
    -+                          node.tx_broadcaster
    -+                                  .blocks
    -+                                  .lock()
    -+                                  .unwrap()
    -+                                  .push((genesis_block(Network::Bitcoin), height));
    -                           node.node.best_block_updated(&header, height);
    -                           node.chain_monitor.best_block_updated(&header, height);
    -                           node.sweeper.best_block_updated(&header, height);
     @@ lightning-background-processor/src/lib.rs: mod tests {
                let data_dir = nodes[0].kv_store.get_data_dir();
                let persister = Arc::new(Persister::new(data_dir));
    @@ lightning-background-processor/src/lib.rs: mod tests {
                let (temporary_channel_id, funding_tx) = funding_generation_recv
                        .recv_timeout(Duration::from_secs(EVENT_DEADLINE))
                        .expect("FundingGenerationReady not handled within deadline");
    --          nodes[0].node.funding_transaction_generated(&temporary_channel_id, &nodes[1].node.get_our_node_id(), funding_tx.clone()).unwrap();
    --          nodes[1].node.handle_funding_created(&nodes[0].node.get_our_node_id(), &get_event_msg!(nodes[0], MessageSendEvent::SendFundingCreated, nodes[1].node.get_our_node_id()));
    +-          nodes[0].node.funding_transaction_generated(&temporary_channel_id, &node_1_id, funding_tx.clone()).unwrap();
     +          nodes[0]
     +                  .node
    -+                  .funding_transaction_generated(
    -+                          &temporary_channel_id,
    -+                          &nodes[1].node.get_our_node_id(),
    -+                          funding_tx.clone(),
    -+                  )
    ++                  .funding_transaction_generated(&temporary_channel_id, &node_1_id, funding_tx.clone())
     +                  .unwrap();
    -+          nodes[1].node.handle_funding_created(
    -+                  &nodes[0].node.get_our_node_id(),
    -+                  &get_event_msg!(
    -+                          nodes[0],
    -+                          MessageSendEvent::SendFundingCreated,
    -+                          nodes[1].node.get_our_node_id()
    -+                  ),
    -+          );
    +           let msg_0 = get_event_msg!(nodes[0], MessageSendEvent::SendFundingCreated, node_1_id);
    +           nodes[1].node.handle_funding_created(&node_0_id, &msg_0);
                get_event!(nodes[1], Event::ChannelPending);
    --          nodes[0].node.handle_funding_signed(&nodes[1].node.get_our_node_id(), &get_event_msg!(nodes[1], MessageSendEvent::SendFundingSigned, nodes[0].node.get_our_node_id()));
    +           let msg_1 = get_event_msg!(nodes[1], MessageSendEvent::SendFundingSigned, node_0_id);
    +           nodes[0].node.handle_funding_signed(&node_1_id, &msg_1);
     -          let _ = channel_pending_recv.recv_timeout(Duration::from_secs(EVENT_DEADLINE))
    -+          nodes[0].node.handle_funding_signed(
    -+                  &nodes[1].node.get_our_node_id(),
    -+                  &get_event_msg!(
    -+                          nodes[1],
    -+                          MessageSendEvent::SendFundingSigned,
    -+                          nodes[0].node.get_our_node_id()
    -+                  ),
    -+          );
     +          let _ = channel_pending_recv
     +                  .recv_timeout(Duration::from_secs(EVENT_DEADLINE))
                        .expect("ChannelPending not handled within deadline");

                // Confirm the funding transaction.
    -           confirm_transaction(&mut nodes[0], &funding_tx);
    --          let as_funding = get_event_msg!(nodes[0], MessageSendEvent::SendChannelReady, nodes[1].node.get_our_node_id());
    -+          let as_funding = get_event_msg!(
    -+                  nodes[0],
    -+                  MessageSendEvent::SendChannelReady,
    -+                  nodes[1].node.get_our_node_id()
    -+          );
    +@@ lightning-background-processor/src/lib.rs: mod tests {
                confirm_transaction(&mut nodes[1], &funding_tx);
    --          let bs_funding = get_event_msg!(nodes[1], MessageSendEvent::SendChannelReady, nodes[0].node.get_our_node_id());
    -+          let bs_funding = get_event_msg!(
    -+                  nodes[1],
    -+                  MessageSendEvent::SendChannelReady,
    -+                  nodes[0].node.get_our_node_id()
    -+          );
    -           nodes[0].node.handle_channel_ready(&nodes[1].node.get_our_node_id(), &bs_funding);
    --          let _as_channel_update = get_event_msg!(nodes[0], MessageSendEvent::SendChannelUpdate, nodes[1].node.get_our_node_id());
    -+          let _as_channel_update = get_event_msg!(
    -+                  nodes[0],
    -+                  MessageSendEvent::SendChannelUpdate,
    -+                  nodes[1].node.get_our_node_id()
    -+          );
    -           nodes[1].node.handle_channel_ready(&nodes[0].node.get_our_node_id(), &as_funding);
    --          let _bs_channel_update = get_event_msg!(nodes[1], MessageSendEvent::SendChannelUpdate, nodes[0].node.get_our_node_id());
    +           let bs_funding = get_event_msg!(nodes[1], MessageSendEvent::SendChannelReady, node_0_id);
    +           nodes[0].node.handle_channel_ready(&node_1_id, &bs_funding);
    +-          let _as_channel_update = get_event_msg!(nodes[0], MessageSendEvent::SendChannelUpdate, node_1_id);
    ++          let _as_channel_update =
    ++                  get_event_msg!(nodes[0], MessageSendEvent::SendChannelUpdate, node_1_id);
    +           nodes[1].node.handle_channel_ready(&node_0_id, &as_funding);
    +-          let _bs_channel_update = get_event_msg!(nodes[1], MessageSendEvent::SendChannelUpdate, node_0_id);
     -          let broadcast_funding = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().pop().unwrap();
    -+          let _bs_channel_update = get_event_msg!(
    -+                  nodes[1],
    -+                  MessageSendEvent::SendChannelUpdate,
    -+                  nodes[0].node.get_our_node_id()
    -+          );
    ++          let _bs_channel_update =
    ++                  get_event_msg!(nodes[1], MessageSendEvent::SendChannelUpdate, node_0_id);
     +          let broadcast_funding =
     +                  nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().pop().unwrap();
                assert_eq!(broadcast_funding.txid(), funding_tx.txid());
    @@ lightning-background-processor/src/lib.rs: mod tests {

                // Force close the channel and check that the SpendableOutputs event was handled.
                let error_message = "Channel force-closed";
    --          nodes[0].node.force_close_broadcasting_latest_txn(&nodes[0].node.list_channels()[0].channel_id, &nodes[1].node.get_our_node_id(), error_message.to_string()).unwrap();
    +-          nodes[0].node.force_close_broadcasting_latest_txn(&nodes[0].node.list_channels()[0].channel_id, &node_1_id, error_message.to_string()).unwrap();
     +          nodes[0]
     +                  .node
     +                  .force_close_broadcasting_latest_txn(
     +                          &nodes[0].node.list_channels()[0].channel_id,
    -+                          &nodes[1].node.get_our_node_id(),
    ++                          &node_1_id,
     +                          error_message.to_string(),
     +                  )
     +                  .unwrap();
$ 

@TheBlueMatt TheBlueMatt merged commit dd5d297 into lightningdevkit:main Jul 14, 2024
11 of 17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants