Skip to content

Commit

Permalink
feat: add feature to delete a dlc channel from our storage
Browse files Browse the repository at this point in the history
Note: this is a dangerous API to call and should only be used if we can't help us otherwise.
Signed-off-by: Philipp Hoenisch <[email protected]>
  • Loading branch information
bonomat committed Jan 27, 2024
1 parent bda9e59 commit a917ca3
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
44 changes: 44 additions & 0 deletions coordinator/src/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use commons::CollaborativeRevertCoordinatorRequest;
use commons::LegacyCollaborativeRevertCoordinatorRequest;
use dlc_manager::channel::Channel;
use dlc_manager::contract::Contract;
use dlc_manager::Storage;
use lightning::chain::chaininterface::ConfirmationTarget;
use lightning_invoice::Bolt11Invoice;
use ln_dlc_node::node::NodeInfo;
Expand Down Expand Up @@ -557,6 +558,49 @@ pub async fn close_channel(
Ok(())
}

#[derive(Debug, Deserialize)]
pub struct DeleteDlcChannel {
#[serde(default, deserialize_with = "empty_string_as_none")]
i_know_what_i_am_doing: Option<bool>,
}

/// This function deletes a DLC channel from our database irreversible!
/// If you want to close a channel instead, use `close_channel`
#[instrument(skip_all, err(Debug))]
pub async fn delete_dlc_channels(
Path(channel_id_string): Path<String>,
State(state): State<Arc<AppState>>,
Query(params): Query<DeleteDlcChannel>,
) -> Result<(), AppError> {
if !params.i_know_what_i_am_doing.unwrap_or_default() {
let error_message =
"Looks like you don't know what you are doing! Go and ask your supervisor for help!";
tracing::warn!(error_message);
return Err(AppError::BadRequest(error_message.to_string()));
}

let channel_id = parse_dlc_channel_id(&channel_id_string)
.map_err(|_| AppError::BadRequest("Provided channel ID was invalid".to_string()))?;

tracing::info!(channel_id = %channel_id_string, "Deleting dlc channel");

state
.node
.inner
.dlc_storage
.delete_channel(&channel_id)
.map_err(|e| {
AppError::InternalServerError(format!(
"Could not delete dlc_channel with id {} due to {:?}",
channel_id_string, e
))
})?;

tracing::info!(channel_id = %channel_id_string, "Deleted dlc channel");

Ok(())
}

#[instrument(skip_all, err(Debug))]
pub async fn force_close_ln_dlc_channel(
Path(channel_id_string): Path<String>,
Expand Down
5 changes: 5 additions & 0 deletions coordinator/src/routes.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::admin::close_channel;
use crate::admin::collaborative_revert;
use crate::admin::connect_to_peer;
use crate::admin::delete_dlc_channels;
use crate::admin::force_close_ln_dlc_channel;
use crate::admin::get_balance;
use crate::admin::get_fee_rate_estimation;
Expand Down Expand Up @@ -164,6 +165,10 @@ pub fn router(
.route("/api/admin/peers", get(list_peers))
.route("/api/admin/send_payment/:invoice", post(send_payment))
.route("/api/admin/dlc_channels", get(list_dlc_channels))
.route(
"/api/admin/dlc_channels/:channel_id",
delete(delete_dlc_channels),
)
.route("/api/admin/transactions", get(list_on_chain_transactions))
.route("/api/admin/sign/:msg", get(sign_message))
.route("/api/admin/connect", post(connect_to_peer))
Expand Down

0 comments on commit a917ca3

Please sign in to comment.