Skip to content

Commit

Permalink
f - split functions into multiple lines consistently
Browse files Browse the repository at this point in the history
  • Loading branch information
alecchendev committed Jun 27, 2023
1 parent 2c0c4d2 commit 2f3c0f9
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 16 deletions.
44 changes: 30 additions & 14 deletions lightning/src/ln/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1061,7 +1061,7 @@ impl<Signer: ChannelSigner> ChannelContext<Signer> {

pub fn get_max_dust_htlc_exposure_msat<F: Deref>(&self,
_fee_estimator: &LowerBoundedFeeEstimator<F>) -> u64
where F::Target: FeeEstimator
where F::Target: FeeEstimator
{
match self.config.options.max_dust_htlc_exposure_msat {
MaxDustHTLCExposure::FixedLimitMsat(limit) => limit,
Expand Down Expand Up @@ -1539,8 +1539,9 @@ impl<Signer: ChannelSigner> ChannelContext<Signer> {
/// Doesn't bother handling the
/// if-we-removed-it-already-but-haven't-fully-resolved-they-can-still-send-an-inbound-HTLC
/// corner case properly.
pub fn get_available_balances<F: Deref>(&self, fee_estimator: &LowerBoundedFeeEstimator<F>) -> AvailableBalances
where F::Target: FeeEstimator
pub fn get_available_balances<F: Deref>(&self, fee_estimator: &LowerBoundedFeeEstimator<F>)
-> AvailableBalances
where F::Target: FeeEstimator
{
let context = &self;
// Note that we have to handle overflow due to the above case.
Expand Down Expand Up @@ -2561,9 +2562,13 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
Ok(self.get_announcement_sigs(node_signer, genesis_block_hash, user_config, best_block.height(), logger))
}

pub fn update_add_htlc<F, FE: Deref, L: Deref>(&mut self, msg: &msgs::UpdateAddHTLC, mut pending_forward_status: PendingHTLCStatus, create_pending_htlc_status: F, fee_estimator: &LowerBoundedFeeEstimator<FE>, logger: &L) -> Result<(), ChannelError>
pub fn update_add_htlc<F, FE: Deref, L: Deref>(
&mut self, msg: &msgs::UpdateAddHTLC, mut pending_forward_status: PendingHTLCStatus,
create_pending_htlc_status: F, fee_estimator: &LowerBoundedFeeEstimator<FE>, logger: &L
) -> Result<(), ChannelError>
where F: for<'a> Fn(&'a Self, PendingHTLCStatus, u16) -> PendingHTLCStatus,
FE::Target: FeeEstimator, L::Target: Logger {
FE::Target: FeeEstimator, L::Target: Logger,
{
// We can't accept HTLCs sent after we've sent a shutdown.
let local_sent_shutdown = (self.context.channel_state & (ChannelState::ChannelReady as u32 | ChannelState::LocalShutdownSent as u32)) != (ChannelState::ChannelReady as u32);
if local_sent_shutdown {
Expand Down Expand Up @@ -3006,7 +3011,11 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
/// Public version of the below, checking relevant preconditions first.
/// If we're not in a state where freeing the holding cell makes sense, this is a no-op and
/// returns `(None, Vec::new())`.
pub fn maybe_free_holding_cell_htlcs<F: Deref, L: Deref>(&mut self, fee_estimator: &LowerBoundedFeeEstimator<F>, logger: &L) -> (Option<ChannelMonitorUpdate>, Vec<(HTLCSource, PaymentHash)>) where F::Target: FeeEstimator, L::Target: Logger {
pub fn maybe_free_holding_cell_htlcs<F: Deref, L: Deref>(
&mut self, fee_estimator: &LowerBoundedFeeEstimator<F>, logger: &L
) -> (Option<ChannelMonitorUpdate>, Vec<(HTLCSource, PaymentHash)>)
where F::Target: FeeEstimator, L::Target: Logger
{
if self.context.channel_state >= ChannelState::ChannelReady as u32 &&
(self.context.channel_state & (ChannelState::AwaitingRemoteRevoke as u32 | ChannelState::PeerDisconnected as u32 | ChannelState::MonitorUpdateInProgress as u32)) == 0 {
self.free_holding_cell_htlcs(fee_estimator, logger)
Expand All @@ -3015,7 +3024,9 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {

/// Frees any pending commitment updates in the holding cell, generating the relevant messages
/// for our counterparty.
fn free_holding_cell_htlcs<F: Deref, L: Deref>(&mut self, fee_estimator: &LowerBoundedFeeEstimator<F>, logger: &L) -> (Option<ChannelMonitorUpdate>, Vec<(HTLCSource, PaymentHash)>)
fn free_holding_cell_htlcs<F: Deref, L: Deref>(
&mut self, fee_estimator: &LowerBoundedFeeEstimator<F>, logger: &L
) -> (Option<ChannelMonitorUpdate>, Vec<(HTLCSource, PaymentHash)>)
where F::Target: FeeEstimator, L::Target: Logger
{
assert_eq!(self.context.channel_state & ChannelState::MonitorUpdateInProgress as u32, 0);
Expand Down Expand Up @@ -3133,7 +3144,9 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
/// waiting on this revoke_and_ack. The generation of this new commitment_signed may also fail,
/// generating an appropriate error *after* the channel state has been updated based on the
/// revoke_and_ack message.
pub fn revoke_and_ack<F: Deref, L: Deref>(&mut self, msg: &msgs::RevokeAndACK, fee_estimator: &LowerBoundedFeeEstimator<F>, logger: &L) -> Result<(Vec<(HTLCSource, PaymentHash)>, Option<ChannelMonitorUpdate>), ChannelError>
pub fn revoke_and_ack<F: Deref, L: Deref>(&mut self, msg: &msgs::RevokeAndACK,
fee_estimator: &LowerBoundedFeeEstimator<F>, logger: &L
) -> Result<(Vec<(HTLCSource, PaymentHash)>, Option<ChannelMonitorUpdate>), ChannelError>
where F::Target: FeeEstimator, L::Target: Logger,
{
if (self.context.channel_state & (ChannelState::ChannelReady as u32)) != (ChannelState::ChannelReady as u32) {
Expand Down Expand Up @@ -3371,7 +3384,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
/// commitment update.
pub fn queue_update_fee<F: Deref, L: Deref>(&mut self, feerate_per_kw: u32,
fee_estimator: &LowerBoundedFeeEstimator<F>, logger: &L)
where F::Target: FeeEstimator, L::Target: Logger
where F::Target: FeeEstimator, L::Target: Logger
{
let msg_opt = self.send_update_fee(feerate_per_kw, true, fee_estimator, logger);
assert!(msg_opt.is_none(), "We forced holding cell?");
Expand All @@ -3384,7 +3397,10 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
///
/// You MUST call [`Self::send_commitment_no_state_update`] prior to any other calls on this
/// [`Channel`] if `force_holding_cell` is false.
fn send_update_fee<F: Deref, L: Deref>(&mut self, feerate_per_kw: u32, mut force_holding_cell: bool, fee_estimator: &LowerBoundedFeeEstimator<F>, logger: &L) -> Option<msgs::UpdateFee>
fn send_update_fee<F: Deref, L: Deref>(
&mut self, feerate_per_kw: u32, mut force_holding_cell: bool,
fee_estimator: &LowerBoundedFeeEstimator<F>, logger: &L
) -> Option<msgs::UpdateFee>
where F::Target: FeeEstimator, L::Target: Logger
{
if !self.context.is_outbound() {
Expand Down Expand Up @@ -5013,7 +5029,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
onion_routing_packet: msgs::OnionPacket, skimmed_fee_msat: Option<u64>,
fee_estimator: &LowerBoundedFeeEstimator<F>, logger: &L
) -> Result<(), ChannelError>
where F::Target: FeeEstimator, L::Target: Logger
where F::Target: FeeEstimator, L::Target: Logger
{
self
.send_htlc(amount_msat, payment_hash, cltv_expiry, source, onion_routing_packet, true,
Expand Down Expand Up @@ -5047,7 +5063,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
onion_routing_packet: msgs::OnionPacket, mut force_holding_cell: bool,
skimmed_fee_msat: Option<u64>, fee_estimator: &LowerBoundedFeeEstimator<F>, logger: &L
) -> Result<Option<msgs::UpdateAddHTLC>, ChannelError>
where F::Target: FeeEstimator, L::Target: Logger
where F::Target: FeeEstimator, L::Target: Logger
{
if (self.context.channel_state & (ChannelState::ChannelReady as u32 | BOTH_SIDES_SHUTDOWN_MASK)) != (ChannelState::ChannelReady as u32) {
return Err(ChannelError::Ignore("Cannot send HTLC until channel is fully established and we haven't started shutting down".to_owned()));
Expand Down Expand Up @@ -5262,8 +5278,8 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
/// Shorthand for calling [`Self::send_htlc`] followed by a commitment update, see docs on
/// [`Self::send_htlc`] and [`Self::build_commitment_no_state_update`] for more info.
pub fn send_htlc_and_commit<F: Deref, L: Deref>(
&mut self, amount_msat: u64, payment_hash: PaymentHash, cltv_expiry: u32, source: HTLCSource,
onion_routing_packet: msgs::OnionPacket, skimmed_fee_msat: Option<u64>,
&mut self, amount_msat: u64, payment_hash: PaymentHash, cltv_expiry: u32,
source: HTLCSource, onion_routing_packet: msgs::OnionPacket, skimmed_fee_msat: Option<u64>,
fee_estimator: &LowerBoundedFeeEstimator<F>, logger: &L
) -> Result<Option<ChannelMonitorUpdate>, ChannelError>
where F::Target: FeeEstimator, L::Target: Logger
Expand Down
5 changes: 3 additions & 2 deletions lightning/src/ln/channelmanager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1505,8 +1505,9 @@ impl ChannelDetails {

fn from_channel_context<Signer: WriteableEcdsaChannelSigner, F: Deref>(
context: &ChannelContext<Signer>, best_block_height: u32, latest_features: InitFeatures,
fee_estimator: &LowerBoundedFeeEstimator<F>) -> Self
where F::Target: FeeEstimator
fee_estimator: &LowerBoundedFeeEstimator<F>
) -> Self
where F::Target: FeeEstimator
{

let balance = context.get_available_balances(fee_estimator);
Expand Down

0 comments on commit 2f3c0f9

Please sign in to comment.