Skip to content

Commit

Permalink
Remove channel keep_on_close option
Browse files Browse the repository at this point in the history
  • Loading branch information
contrun committed Jul 5, 2024
1 parent 1aed0c2 commit c989118
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 50 deletions.
12 changes: 1 addition & 11 deletions src/ckb/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,21 +185,14 @@ pub struct ChannelActor<S> {
peer_id: PeerId,
network: ActorRef<NetworkActorMessage>,
store: S,
keep_on_closed: bool,
}

impl<S: ChannelActorStateStore> ChannelActor<S> {
pub fn new(
peer_id: PeerId,
network: ActorRef<NetworkActorMessage>,
store: S,
keep_on_closed: bool,
) -> Self {
pub fn new(peer_id: PeerId, network: ActorRef<NetworkActorMessage>, store: S) -> Self {
Self {
peer_id,
network,
store,
keep_on_closed,
}
}

Expand Down Expand Up @@ -882,9 +875,6 @@ impl<S: ChannelActorStateStore> ChannelActor<S> {
}
ChannelEvent::ClosingTransactionConfirmed => {
myself.stop(Some("ChannelClosed".to_string()));
if !self.keep_on_closed {
self.store.delete_channel_actor_state(&state.get_id());
}
}
}
Ok(())
Expand Down
12 changes: 0 additions & 12 deletions src/ckb/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,6 @@ pub struct CkbConfig {
help = "whether to accept open channel requests with ckb funding amount automatically, unit: shannons [default: 6200000000 shannons], if this is set to zero, it means to disable auto accept"
)]
pub auto_accept_channel_ckb_funding_amount: Option<u64>,
/// whether to keep closed channels from store [default: false]
#[arg(
name = "CKB_KEEP_CLOSED_CHANNELS",
long = "ckb-keep-closed-channels",
env,
help = "whether to keep closed channels from store [default: false]"
)]
pub keep_closed_channels: Option<bool>,
}

impl CkbConfig {
Expand Down Expand Up @@ -128,10 +120,6 @@ impl CkbConfig {
self.auto_accept_channel_ckb_funding_amount
.unwrap_or(DEFAULT_CHANNEL_MINIMAL_CKB_AMOUNT)
}

pub fn keep_closed_channels(&self) -> bool {
self.keep_closed_channels.unwrap_or(false)
}
}

// Basically ckb_sdk::types::NetworkType. But we added a `Mocknet` variant.
Expand Down
34 changes: 7 additions & 27 deletions src/ckb/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,9 @@ where
// TODO: We should remove the channel from the session_channels_map.
state.channels.remove(&channel_id);
if let Some(session) = state.get_peer_session(&peer_id) {
if let Some(set) = state.session_channels_map.get_mut(&session) { set.remove(&channel_id); }
if let Some(set) = state.session_channels_map.get_mut(&session) {
set.remove(&channel_id);
}
}
state.send_message_to_channel_actor(
channel_id,
Expand Down Expand Up @@ -812,8 +814,6 @@ pub struct NetworkActorState {
open_channel_auto_accept_min_ckb_funding_amount: u64,
// Tha default amount of CKB to be funded when auto accepting a channel.
auto_accept_channel_ckb_funding_amount: u64,
// If true, the network actor will keep closed channels in database.
keep_closed_channels: bool,
}

static CHANNEL_ACTOR_NAME_PREFIX: AtomicU64 = AtomicU64::new(0u64);
Expand Down Expand Up @@ -868,12 +868,7 @@ impl NetworkActorState {
let (tx, rx) = oneshot::channel::<Hash256>();
let channel = Actor::spawn_linked(
Some(generate_channel_actor_name(&self.peer_id, &peer_id)),
ChannelActor::new(
peer_id.clone(),
network.clone(),
store,
self.keep_closed_channels,
),
ChannelActor::new(peer_id.clone(), network.clone(), store),
ChannelInitializationParameter::OpenChannel(OpenChannelParameter {
funding_amount,
seed,
Expand Down Expand Up @@ -924,12 +919,7 @@ impl NetworkActorState {
let (tx, rx) = oneshot::channel::<Hash256>();
let channel = Actor::spawn_linked(
Some(generate_channel_actor_name(&self.peer_id, &peer_id)),
ChannelActor::new(
peer_id.clone(),
network.clone(),
store,
self.keep_closed_channels,
),
ChannelActor::new(peer_id.clone(), network.clone(), store),
ChannelInitializationParameter::AcceptChannel(AcceptChannelParameter {
funding_amount,
reserved_ckb_amount,
Expand Down Expand Up @@ -1095,12 +1085,7 @@ impl NetworkActorState {
debug!("Reestablishing channel {:x}", &channel_id);
if let Ok((channel, _)) = Actor::spawn_linked(
Some(generate_channel_actor_name(&self.peer_id, peer_id)),
ChannelActor::new(
peer_id.clone(),
self.network.clone(),
store.clone(),
self.keep_closed_channels,
),
ChannelActor::new(peer_id.clone(), self.network.clone(), store.clone()),
ChannelInitializationParameter::ReestablishChannel(channel_id),
self.network.get_cell(),
)
Expand Down Expand Up @@ -1156,11 +1141,7 @@ impl NetworkActorState {
let message = match result {
Ok(Status::Committed) => {
info!("Cloisng transaction {:?} confirmed", &tx_hash);
NetworkActorEvent::ClosingTransactionConfirmed(
peer_id,
channel_id,
tx_hash,
)
NetworkActorEvent::ClosingTransactionConfirmed(peer_id, channel_id, tx_hash)
}
Ok(status) => {
error!(
Expand Down Expand Up @@ -1385,7 +1366,6 @@ where
open_channel_auto_accept_min_ckb_funding_amount: config
.open_channel_auto_accept_min_ckb_funding_amount(),
auto_accept_channel_ckb_funding_amount: config.auto_accept_channel_ckb_funding_amount(),
keep_closed_channels: config.keep_closed_channels(),
})
}

Expand Down

0 comments on commit c989118

Please sign in to comment.