discovery/gossiper: hold ref to block epoch stream and cancel when stopped
This commit is contained in:
parent
6830024faf
commit
9ecfdb3c32
@ -161,9 +161,9 @@ type AuthenticatedGossiper struct {
|
|||||||
// was initialized with.
|
// was initialized with.
|
||||||
cfg *Config
|
cfg *Config
|
||||||
|
|
||||||
// newBlocks is a channel in which new blocks connected to the end of
|
// blockEpochs encapsulates a stream of block epochs that are sent at
|
||||||
// the main chain are sent over.
|
// every new block height.
|
||||||
newBlocks <-chan *chainntnfs.BlockEpoch
|
blockEpochs *chainntnfs.BlockEpochEvent
|
||||||
|
|
||||||
// prematureAnnouncements maps a block height to a set of network
|
// prematureAnnouncements maps a block height to a set of network
|
||||||
// messages which are "premature" from our PoV. A message is premature
|
// messages which are "premature" from our PoV. A message is premature
|
||||||
@ -410,7 +410,7 @@ func (d *AuthenticatedGossiper) Start() error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
d.newBlocks = blockEpochs.Epochs
|
d.blockEpochs = blockEpochs
|
||||||
|
|
||||||
height, err := d.cfg.Router.CurrentBlockHeight()
|
height, err := d.cfg.Router.CurrentBlockHeight()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -440,6 +440,8 @@ func (d *AuthenticatedGossiper) Stop() {
|
|||||||
|
|
||||||
log.Info("Authenticated Gossiper is stopping")
|
log.Info("Authenticated Gossiper is stopping")
|
||||||
|
|
||||||
|
d.blockEpochs.Cancel()
|
||||||
|
|
||||||
d.syncerMtx.RLock()
|
d.syncerMtx.RLock()
|
||||||
for _, syncer := range d.peerSyncers {
|
for _, syncer := range d.peerSyncers {
|
||||||
syncer.Stop()
|
syncer.Stop()
|
||||||
@ -1105,7 +1107,7 @@ func (d *AuthenticatedGossiper) networkHandler() {
|
|||||||
|
|
||||||
// A new block has arrived, so we can re-process the previously
|
// A new block has arrived, so we can re-process the previously
|
||||||
// premature announcements.
|
// premature announcements.
|
||||||
case newBlock, ok := <-d.newBlocks:
|
case newBlock, ok := <-d.blockEpochs.Epochs:
|
||||||
// If the channel has been closed, then this indicates
|
// If the channel has been closed, then this indicates
|
||||||
// the daemon is shutting down, so we exit ourselves.
|
// the daemon is shutting down, so we exit ourselves.
|
||||||
if !ok {
|
if !ok {
|
||||||
|
Loading…
Reference in New Issue
Block a user