-
Notifications
You must be signed in to change notification settings - Fork 6
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
Add implementation for UpdateChannelConfig Api. #16
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
use ldk_node::bitcoin::secp256k1::PublicKey; | ||
use ldk_node::config::{ChannelConfig, MaxDustHTLCExposure}; | ||
use ldk_node::{Node, UserChannelId}; | ||
use protos::channel_config::MaxDustHtlcExposure; | ||
use protos::{UpdateChannelConfigRequest, UpdateChannelConfigResponse}; | ||
use std::str::FromStr; | ||
use std::sync::Arc; | ||
|
||
pub(crate) const UPDATE_CHANNEL_CONFIG_PATH: &str = "UpdateChannelConfig"; | ||
|
||
pub(crate) fn handle_update_channel_config_request( | ||
node: Arc<Node>, request: UpdateChannelConfigRequest, | ||
) -> Result<UpdateChannelConfigResponse, ldk_node::NodeError> { | ||
let user_channel_id: u128 = | ||
request.user_channel_id.parse().map_err(|_| ldk_node::NodeError::InvalidChannelId)?; | ||
|
||
//FIXME: Use ldk/ldk-node's partial config update api. | ||
let current_config = node | ||
.list_channels() | ||
.into_iter() | ||
.find(|c| c.user_channel_id.0 == user_channel_id) | ||
.ok_or_else(|| ldk_node::NodeError::InvalidChannelId)? | ||
.config; | ||
|
||
let updated_channel_config = | ||
build_updated_channel_config(current_config, request.channel_config.unwrap()); | ||
|
||
let counterparty_node_id = PublicKey::from_str(&request.counterparty_node_id) | ||
.map_err(|_| ldk_node::NodeError::InvalidPublicKey)?; | ||
node.update_channel_config( | ||
&UserChannelId(user_channel_id), | ||
counterparty_node_id, | ||
updated_channel_config, | ||
) | ||
.map_err(ldk_node::NodeError::from)?; | ||
|
||
Ok(UpdateChannelConfigResponse {}) | ||
} | ||
|
||
fn build_updated_channel_config( | ||
current_config: ChannelConfig, proto_channel_config: protos::ChannelConfig, | ||
) -> ChannelConfig { | ||
let max_dust_htlc_exposure = proto_channel_config | ||
.max_dust_htlc_exposure | ||
.map(|max_dust_htlc_exposure| match max_dust_htlc_exposure { | ||
MaxDustHtlcExposure::FixedLimitMsat(limit_msat) => { | ||
MaxDustHTLCExposure::FixedLimit { limit_msat } | ||
}, | ||
MaxDustHtlcExposure::FeeRateMultiplier(multiplier) => { | ||
MaxDustHTLCExposure::FeeRateMultiplier { multiplier } | ||
}, | ||
}) | ||
.unwrap_or(current_config.max_dust_htlc_exposure); | ||
|
||
let cltv_expiry_delta = proto_channel_config | ||
.cltv_expiry_delta.map(|c| u16::try_from(c).unwrap()) | ||
.unwrap_or(current_config.cltv_expiry_delta); | ||
|
||
ChannelConfig { | ||
forwarding_fee_proportional_millionths: proto_channel_config | ||
.forwarding_fee_proportional_millionths | ||
.unwrap_or(current_config.forwarding_fee_proportional_millionths), | ||
forwarding_fee_base_msat: proto_channel_config | ||
.forwarding_fee_base_msat | ||
.unwrap_or(current_config.forwarding_fee_base_msat), | ||
cltv_expiry_delta, | ||
max_dust_htlc_exposure, | ||
force_close_avoidance_max_fee_satoshis: proto_channel_config | ||
.force_close_avoidance_max_fee_satoshis | ||
.unwrap_or(current_config.force_close_avoidance_max_fee_satoshis), | ||
accept_underpaying_htlcs: proto_channel_config | ||
.accept_underpaying_htlcs | ||
.unwrap_or(current_config.accept_underpaying_htlcs), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we do this now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Afaiu, Currently there is no api in ldk-node for partial config update, this will have to wait until next ldk-node release.
Since the functionality/user-interface here is equivalent, I don't think there is much point in waiting till then.
Created: lightningdevkit/ldk-node#385
We can remove this once that is complete.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, right!