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

Method insertChain

protocols/cpc/fetcher/fetcher_test.go:118–136  ·  view source on GitHub ↗

insertChain injects a new blocks into the simulated chain.

(blocks types.Blocks)

Source from the content-addressed store, hash-verified

116
117// insertChain injects a new blocks into the simulated chain.
118func (f *fetcherTester) insertChain(blocks types.Blocks) (int, error) {
119 f.lock.Lock()
120 defer f.lock.Unlock()
121
122 for i, block := range blocks {
123 // Make sure the parent in known
124 if _, ok := f.blocks[block.ParentHash()]; !ok {
125 return i, errors.New("unknown parent")
126 }
127 // Discard any new blocks if the same height already exists
128 if block.NumberU64() <= f.blocks[f.hashes[len(f.hashes)-1]].NumberU64() {
129 return i, nil
130 }
131 // Otherwise build our current chain
132 f.hashes = append(f.hashes, block.Hash())
133 f.blocks[block.Hash()] = block
134 }
135 return 0, nil
136}
137
138// dropPeer is an emulator for the peer removal, simply accumulating the various
139// peers dropped by the fetcher.

Callers 2

insertMethod · 0.45
TestImportDeduplicationFunction · 0.45

Calls 5

LockMethod · 0.80
UnlockMethod · 0.80
ParentHashMethod · 0.80
NumberU64Method · 0.80
HashMethod · 0.65

Tested by

no test coverage detected