Skip to content

Commit

Permalink
[stream] instruct the beaconhelper also uses insertHelper
Browse files Browse the repository at this point in the history
  • Loading branch information
JackyWYX committed Mar 12, 2021
1 parent 05c8ed7 commit a65e783
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
6 changes: 4 additions & 2 deletions hmy/downloader/beaconhelper.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type (
// insert the latest blocks to the beacon chain.
beaconHelper struct {
bc blockChain
ih insertHelper
blockC <-chan *types.Block
// TODO: refactor this hook to consensus module. We'd better put it in
// consensus module under a subscription.
Expand All @@ -33,9 +34,10 @@ type (
}
)

func newBeaconHelper(bc blockChain, blockC <-chan *types.Block, insertHook func()) *beaconHelper {
func newBeaconHelper(bc blockChain, ih insertHelper, blockC <-chan *types.Block, insertHook func()) *beaconHelper {
return &beaconHelper{
bc: bc,
ih: ih,
blockC: blockC,
insertHook: insertHook,
lastMileCache: newBlocksByNumber(lastMileCap),
Expand Down Expand Up @@ -118,7 +120,7 @@ func (bh *beaconHelper) insertLastMileBlocks() (inserted int, bn uint64, err err
bn--
return
}
if _, err = bh.bc.InsertChain(types.Blocks{b}, true); err != nil {
if err = bh.ih.verifyAndInsertBlock(b); err != nil {
bn--
return
}
Expand Down
2 changes: 1 addition & 1 deletion hmy/downloader/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func NewDownloader(host p2p.Host, bc *core.BlockChain, config Config) *Downloade

var bh *beaconHelper
if config.BHConfig != nil && bc.ShardID() == 0 {
bh = newBeaconHelper(bc, config.BHConfig.BlockC, config.BHConfig.InsertHook)
bh = newBeaconHelper(bc, ih, config.BHConfig.BlockC, config.BHConfig.InsertHook)
}

ctx, cancel := context.WithCancel(context.Background())
Expand Down
5 changes: 2 additions & 3 deletions p2p/stream/protocols/sync/message/msg.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a65e783

Please sign in to comment.