Skip to content

Commit f50f504

Browse files
committed
proposalpool and blockbuilder as blockchain subscriber
1 parent 582aeb4 commit f50f504

File tree

1 file changed

+5
-13
lines changed

1 file changed

+5
-13
lines changed

consensus/scheme/rolldpos/chainmanager.go

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,16 @@ func NewChainManager(bc blockchain.Blockchain, srf StateReaderFactory, bbf Block
109109
if err != nil {
110110
log.L().Panic("Failed to generate prometheus timer factory.", zap.Error(err))
111111
}
112+
pool := newProposalPool()
113+
bc.AddSubscriber(bbf)
114+
bc.AddSubscriber(pool)
112115

113116
return &chainManager{
114117
bc: bc,
115118
bbf: bbf,
116119
timerFactory: timerFactory,
117120
srf: srf,
118-
pool: newProposalPool(),
121+
pool: pool,
119122
}
120123
}
121124

@@ -243,18 +246,7 @@ func (cm *chainManager) ValidateBlock(blk *block.Block) error {
243246

244247
// CommitBlock validates and appends a block to the chain
245248
func (cm *chainManager) CommitBlock(blk *block.Block) error {
246-
if err := cm.bc.CommitBlock(blk); err != nil {
247-
return err
248-
}
249-
if err := cm.bbf.ReceiveBlock(blk); err != nil {
250-
blkHash := blk.HashBlock()
251-
log.L().Error("failed to receive block", zap.Error(err), zap.Uint64("height", blk.Height()), log.Hex("hash", blkHash[:]))
252-
}
253-
if err := cm.pool.ReceiveBlock(blk); err != nil {
254-
blkHash := blk.HashBlock()
255-
log.L().Error("failed to receive block", zap.Error(err), zap.Uint64("height", blk.Height()), log.Hex("hash", blkHash[:]))
256-
}
257-
return nil
249+
return cm.bc.CommitBlock(blk)
258250
}
259251

260252
func (cm *chainManager) Start(ctx context.Context) error {

0 commit comments

Comments
 (0)