Skip to content

Commit 896c314

Browse files
committed
Update update_fee API signature
to use APIError unwrap send_update_fee add is_outbound() accessor
1 parent fc36e3e commit 896c314

File tree

2 files changed

+25
-12
lines changed

2 files changed

+25
-12
lines changed

src/ln/channel.rs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1893,31 +1893,34 @@ impl Channel {
18931893

18941894
}
18951895

1896-
pub fn send_update_fee(&mut self, feerate_per_kw: u64) -> Result<Option<msgs::UpdateFee>, HandleError> {
1896+
/// Adds a pending update to this channel. See the doc for send_htlc for
1897+
/// further details on the optionness of the return value.
1898+
/// You MUST call send_commitment prior to any other calls on this Channel
1899+
fn send_update_fee(&mut self, feerate_per_kw: u64) -> Option<msgs::UpdateFee> {
18971900
if !self.channel_outbound {
1898-
return Err(HandleError{err: "Cannot send fee from inbound channel", action: None});
1901+
panic!("Cannot send fee from inbound channel");
18991902
}
19001903

1901-
if (self.channel_state & (ChannelState::ChannelFunded as u32 | BOTH_SIDES_SHUTDOWN_MASK)) != (ChannelState::ChannelFunded as u32) {
1902-
return Err(HandleError{err: "Cannot update fee until channel is fully established and we haven't started shutting down", action: None});
1904+
if !self.is_usable() {
1905+
panic!("Cannot update fee until channel is fully established and we haven't started shutting down");
19031906
}
19041907

19051908
if (self.channel_state & (ChannelState::AwaitingRemoteRevoke as u32)) == (ChannelState::AwaitingRemoteRevoke as u32) {
19061909
self.holding_cell_update_fee = Some(feerate_per_kw);
1907-
return Ok(None);
1910+
return None;
19081911
}
19091912

19101913
debug_assert!(self.pending_update_fee.is_none());
19111914
self.pending_update_fee = Some(feerate_per_kw);
19121915

1913-
Ok(Some(msgs::UpdateFee {
1916+
Some(msgs::UpdateFee {
19141917
channel_id: self.channel_id,
19151918
feerate_per_kw: feerate_per_kw as u32,
1916-
}))
1919+
})
19171920
}
19181921

19191922
pub fn send_update_fee_and_commit(&mut self, feerate_per_kw: u64) -> Result<Option<(msgs::UpdateFee, msgs::CommitmentSigned, ChannelMonitor)>, HandleError> {
1920-
match self.send_update_fee(feerate_per_kw)? {
1923+
match self.send_update_fee(feerate_per_kw) {
19211924
Some(update_fee) => {
19221925
let (commitment_signed, monitor_update) = self.send_commitment_no_status_check()?;
19231926
Ok(Some((update_fee, commitment_signed, monitor_update)))
@@ -2348,6 +2351,10 @@ impl Channel {
23482351
self.announce_publicly
23492352
}
23502353

2354+
pub fn is_outbound(&self) -> bool {
2355+
self.channel_outbound
2356+
}
2357+
23512358
/// Gets the fee we'd want to charge for adding an HTLC output to this Channel
23522359
/// Allowed in any state (including after shutdown)
23532360
pub fn get_our_fee_base_msat(&self, fee_estimator: &FeeEstimator) -> u32 {

src/ln/channelmanager.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1930,15 +1930,21 @@ impl ChannelManager {
19301930
res
19311931
}
19321932

1933-
pub fn update_fee(&self, channel_id: [u8;32], feerate_per_kw: u64) -> Result<(), HandleError> {
1933+
/// Begin Update fee process. Allowed only on an outbound channel.
1934+
/// If successful, will generate a UpdateHTLCs event, so you should probably poll
1935+
/// PeerManager::process_events afterwards.
1936+
pub fn update_fee(&self, channel_id: [u8;32], feerate_per_kw: u64) -> Result<(), APIError> {
19341937
let mut channel_state = self.channel_state.lock().unwrap();
19351938
match channel_state.by_id.get_mut(&channel_id) {
1936-
None => return Err(HandleError{err: "Failed to find corresponding channel", action: None}),
1939+
None => return Err(APIError::APIMisuseError{err: "Failed to find corresponding channel"}),
19371940
Some(chan) => {
19381941
if !chan.is_usable() {
1939-
return Err(HandleError{err: "Got an announcement_signatures before we were ready for it", action: None});
1942+
return Err(APIError::APIMisuseError{err: "Channel is not in usuable state"});
1943+
}
1944+
if !chan.is_outbound() {
1945+
return Err(APIError::APIMisuseError{err: "update_fee cannot be sent for an inbound channel"});
19401946
}
1941-
if let Some((update_fee, commitment_signed, chan_monitor)) = chan.send_update_fee_and_commit(feerate_per_kw)? {
1947+
if let Some((update_fee, commitment_signed, chan_monitor)) = chan.send_update_fee_and_commit(feerate_per_kw).map_err(|e| APIError::APIMisuseError{err: e.err})? {
19421948
if let Err(_e) = self.monitor.add_update_monitor(chan_monitor.get_funding_txo().unwrap(), chan_monitor) {
19431949
unimplemented!();
19441950
}

0 commit comments

Comments
 (0)