Skip to content

Commit

Permalink
Flash: Avoid allocating while gossiping
Browse files Browse the repository at this point in the history
  • Loading branch information
omerfirmak authored and Geod24 committed May 31, 2021
1 parent 9c836b5 commit 5eac9dd
Showing 1 changed file with 2 additions and 12 deletions.
14 changes: 2 additions & 12 deletions source/agora/flash/Node.d
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,6 @@ public abstract class FlashNode : FlashControlAPI
{
log.info("gossipChannelsOpen() with {} channels", chan_configs.length);

ChannelConfig[] to_gossip;
foreach (conf; chan_configs)
{
if (conf.chan_id in this.known_channels)
Expand All @@ -665,20 +664,15 @@ public abstract class FlashNode : FlashControlAPI
this.known_channels[conf.chan_id] = conf;
this.network.addChannel(conf);

to_gossip ~= conf; // gossip only new channels
this.gossip_queue.insertBack(GossipEvent(conf)); // gossip only new channels
}

// also gossip new channels to peers later
to_gossip.each!(chan =>
this.gossip_queue.insertBack(GossipEvent(chan)));
}

/// See `FlashAPI.gossipChannelUpdates`
public void gossipChannelUpdates (ChannelUpdate[] chan_updates)
{
log.info("gossipChannelUpdates() with {} channels", chan_updates.length);

ChannelUpdate[] to_gossip;
foreach (update; chan_updates)
{
if (auto conf = update.chan_id in this.known_channels)
Expand All @@ -696,14 +690,10 @@ public abstract class FlashNode : FlashControlAPI
if (!verify(pk, update.sig, update))
continue;
this.channel_updates[update.chan_id][update.direction] = update;
to_gossip ~= update;
this.gossip_queue.insertBack(GossipEvent(update));
this.dump();
}
}

// also gossip new updates to peers later
to_gossip.each!(update =>
this.gossip_queue.insertBack(GossipEvent(update)));
}

/// See `FlashAPI.requestCloseSig`
Expand Down

0 comments on commit 5eac9dd

Please sign in to comment.