MCPcopy Create free account
hub / github.com/CPChain/chain / returnBlocksLoop

Method returnBlocksLoop

protocols/cpc/syncer/syncer_test.go:879–903  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

877}
878
879func (fp *FakePeer) returnBlocksLoop() {
880 for {
881 select {
882 case start := <-fp.requestCh:
883 _, number := fp.Head()
884 end := uint64(math.Min(float64(start+syncer.MaxBlockFetch), float64(number.Uint64()+1)))
885 blocks := make(types.Blocks, int(end-start))
886
887 fmt.Println("received start request", "start", start, "batch", syncer.MaxBlockFetch, "end", end)
888 for i := start; i < end; i++ {
889 block := fp.blockchain.GetBlockByNumber(i)
890 if fp.badBlockIdx == int(i) {
891 // change its parent hash to generate a bad block
892 block.RefHeader().ParentHash = common.Hash{}
893 }
894 blocks[i-start] = block
895 }
896
897 fp.returnCh <- blocks
898
899 case <-fp.quitCh:
900 return
901 }
902 }
903}
904
905func (fp *FakePeer) quit() {
906 if fp.quitCh != nil {

Callers 8

TestSyncerNormalFunction · 0.80
TestSyncerErrOrderFunction · 0.80
TestSyncerInvalidChainFunction · 0.80
TestSyncerUnknownPeerFunction · 0.80
TestCallSyncTwiceFunction · 0.80
TestSyncStateFunction · 0.80

Calls 4

HeadMethod · 0.95
Uint64Method · 0.80
RefHeaderMethod · 0.80
GetBlockByNumberMethod · 0.65

Tested by

no test coverage detected