Skip to content

Commit

Permalink
Renaming channel id for peerd
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-orlovsky committed Nov 5, 2020
1 parent 48b05aa commit e67a136
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
7 changes: 5 additions & 2 deletions src/channeld/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,11 @@ impl Runtime {
ServiceId::Lnpd,
Request::UpdateChannelId(self.channel_id),
)?;
self.send_ctl(
senders,
self.peer_service.clone(),
Request::UpdateChannelId(self.channel_id),
)?;
self.identity = self.channel_id.into();
let msg = format!(
"{} set to {}",
Expand Down Expand Up @@ -750,8 +755,6 @@ impl Runtime {
info!("{}", msg);
let _ = self.report_progress_to(senders, &enquirer, msg);

self.update_channel_id(senders)?;

Ok(funding_created)
}

Expand Down
22 changes: 14 additions & 8 deletions src/peerd/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ pub struct Runtime {
local_socket: Option<InetSocketAddr>,
remote_socket: InetSocketAddr,

routing: HashMap<ServiceId, MessageFilter>,
routing: HashMap<ServiceId, ServiceId>,
sender: PeerSender,
connect: bool,

Expand Down Expand Up @@ -245,17 +245,13 @@ impl Runtime {
match &request {
Request::PeerMessage(Messages::FundingSigned(
message::FundingSigned { channel_id, .. },
))
| Request::PeerMessage(Messages::FundingLocked(
message::FundingLocked { channel_id, .. },
)) => {
debug!(
"Renaming channeld service from temporary id {:#} to channel id #{:#}",
source, channel_id
);
self.routing.remove(&source);
self.routing
.insert(channel_id.clone().into(), MessageFilter {});
self.routing.insert(channel_id.clone().into(), source);
}
_ => {}
}
Expand Down Expand Up @@ -287,6 +283,15 @@ impl Runtime {
request: Request,
) -> Result<(), Error> {
match request {
Request::UpdateChannelId(channel_id) => {
debug!(
"Renaming channeld service from temporary id {:#} to channel id #{:#}",
source, channel_id
);
self.routing.remove(&source);
self.routing.insert(channel_id.clone().into(), source);
}

Request::GetInfo => {
let info = PeerInfo {
local_id: self.local_id,
Expand Down Expand Up @@ -381,7 +386,7 @@ impl Runtime {
Request::PeerMessage(Messages::AcceptChannel(accept_channel)) => {
let channeld: ServiceId =
accept_channel.temporary_channel_id.into();
self.routing.insert(channeld.clone(), MessageFilter {});
self.routing.insert(channeld.clone(), channeld.clone());
senders.send_to(
ServiceBus::Msg,
self.identity(),
Expand Down Expand Up @@ -425,10 +430,11 @@ impl Runtime {
| Request::PeerMessage(Messages::AssignFunds(
message::AssignFunds { channel_id, .. },
)) => {
let channeld: ServiceId = channel_id.clone().into();
senders.send_to(
ServiceBus::Msg,
self.identity(),
channel_id.clone().into(),
self.routing.get(&channeld).cloned().unwrap_or(channeld),
request,
)?;
}
Expand Down

0 comments on commit e67a136

Please sign in to comment.