Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 21 additions & 23 deletions backend/src/node/connector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,37 +98,35 @@ impl NodeConnector {
fn handle_message(&mut self, msg: NodeMessage, data: Bytes, ctx: &mut <Self as Actor>::Context) {
let conn_id = msg.id.unwrap_or(0);

let backlog = match self.multiplex.entry(conn_id).or_default() {
match self.multiplex.entry(conn_id).or_default() {
ConnMultiplex::Connected { nid, chain } => {
chain.do_send(UpdateNode {
nid: *nid,
msg,
raw: Some(data),
});

return;
}
ConnMultiplex::Waiting { backlog } => backlog,
};

if let Details::SystemConnected(connected) = msg.details {
let SystemConnected { network_id: _, mut node } = connected;
let rec = ctx.address().recipient();

// FIXME: Use genesis hash instead of names to avoid this mess
match &*node.chain {
"Kusama CC3" => node.chain = "Kusama".into(),
"Polkadot CC1" => node.chain = "Polkadot".into(),
_ => (),
}

self.aggregator.do_send(AddNode { rec, conn_id, node });
} else {
if backlog.len() >= 10 {
backlog.remove(0);
ConnMultiplex::Waiting { backlog } => {
if let Details::SystemConnected(connected) = msg.details {
let SystemConnected { network_id: _, mut node } = connected;
let rec = ctx.address().recipient();

// FIXME: Use genesis hash instead of names to avoid this mess
match &*node.chain {
"Kusama CC3" => node.chain = "Kusama".into(),
"Polkadot CC1" => node.chain = "Polkadot".into(),
_ => (),
}

self.aggregator.do_send(AddNode { rec, conn_id, node });
} else {
if backlog.len() >= 10 {
backlog.remove(0);
}

backlog.push(msg);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this is the fix here?

Copy link
Contributor Author

@maciejhirsz maciejhirsz Nov 4, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue was that I had a separate backlog and Addr<Chain> per ConnId, but was using a single NodeId. Now the NodeId is tied to ConnId, everything else (using the enum for ConnMultiplex) is a refactor to make the intent clearer, and to avoid having 3 separate BTreeMaps for no good reason (one for chain address, one for backlog, one for node id).

}
}

backlog.push(msg);
}
}

Expand Down