@@ -84,6 +84,9 @@ type BFTChain struct {
8484 statusReportMutex sync.Mutex
8585 consensusRelation types2.ConsensusRelation
8686 status types2.Status
87+
88+ exitCLock sync.RWMutex
89+ exitC chan struct {}
8790}
8891
8992// NewChain creates new BFT Smart chain
@@ -128,6 +131,7 @@ func NewChain(
128131 Logger : logger ,
129132 consensusRelation : types2 .ConsensusRelationConsenter ,
130133 status : types2 .StatusActive ,
134+ exitC : make (chan struct {}),
131135 Metrics : & Metrics {
132136 ClusterSize : metrics .ClusterSize .With ("channel" , support .ChannelID ()),
133137 CommittedBlockNumber : metrics .CommittedBlockNumber .With ("channel" , support .ChannelID ()),
@@ -445,8 +449,9 @@ func (c *BFTChain) WaitReady() error {
445449// This is especially useful for the Deliver client, who must terminate waiting
446450// clients when the consenter is not up to date.
447451func (c * BFTChain ) Errored () <- chan struct {} {
448- // TODO: Implement Errored
449- return nil
452+ c .exitCLock .RLock ()
453+ defer c .exitCLock .RUnlock ()
454+ return c .exitC
450455}
451456
452457// Start should allocate whatever resources are needed for staying up to date with the chain.
@@ -462,6 +467,14 @@ func (c *BFTChain) Start() {
462467// Halt frees the resources which were allocated for this Chain.
463468func (c * BFTChain ) Halt () {
464469 c .Logger .Infof ("Shutting down chain" )
470+ c .exitCLock .Lock ()
471+ select {
472+ case <- c .exitC :
473+ // already closed
474+ default :
475+ close (c .exitC )
476+ }
477+ c .exitCLock .Unlock ()
465478 c .consensus .Stop ()
466479}
467480
0 commit comments