MCPcopy Create free account
hub / github.com/DNAProject/DNA / AddBlock

Method AddBlock

validator/increment/increment.go:69–92  ·  view source on GitHub ↗

AddBlock add a new block to this validator

(block *types.Block)

Source from the content-addressed store, hash-verified

67
68// AddBlock add a new block to this validator
69func (self *IncrementValidator) AddBlock(block *types.Block) {
70 self.mutex.Lock()
71 defer self.mutex.Unlock()
72 if len(self.blocks) == 0 {
73 self.baseHeight = block.Header.Height
74 }
75
76 if self.baseHeight+uint32(len(self.blocks)) != block.Header.Height {
77 start, end := self.blockRange()
78 log.Errorf("discontinue block is not allowed: [start, end)=[%d, %d), block height= %d",
79 start, end, block.Header.Height)
80 return
81 }
82
83 if len(self.blocks) >= self.maxBlocks {
84 self.blocks = self.blocks[1:]
85 self.baseHeight += 1
86 }
87 txHashes := make(map[common.Uint256]bool)
88 for _, tx := range block.Transactions {
89 txHashes[tx.Hash()] = true
90 }
91 self.blocks = append(self.blocks, txHashes)
92}
93
94// Verfiy does increment check start at startHeight
95func (self *IncrementValidator) Verify(tx *types.Transaction, startHeight uint32) error {

Callers

nothing calls this directly

Calls 3

blockRangeMethod · 0.95
ErrorfFunction · 0.92
HashMethod · 0.65

Tested by

no test coverage detected