MCPcopy Index your code
hub / github.com/CovenantSQL/CovenantSQL / applyBlock

Method applyBlock

blockproducer/branch.go:131–164  ·  view source on GitHub ↗
(n *blockNode)

Source from the content-addressed store, hash-verified

129}
130
131func (b *branch) applyBlock(n *blockNode) (br *branch, err error) {
132 var block = n.load()
133 if !b.head.hash.IsEqual(block.ParentHash()) {
134 err = ErrParentNotMatch
135 return
136 }
137 var cpy = b.makeArena()
138
139 if n.txCount > conf.MaxTransactionsPerBlock {
140 return nil, ErrTooManyTransactionsInBlock
141 }
142
143 for _, v := range block.Transactions {
144 var k = v.Hash()
145 // Check in tx pool
146 if _, ok := cpy.unpacked[k]; ok {
147 delete(cpy.unpacked, k)
148 } else if err = v.Verify(); err != nil {
149 return
150 }
151 if _, ok := cpy.packed[k]; ok {
152 err = ErrExistedTx
153 return
154 }
155 cpy.packed[k] = v
156 // Apply to preview
157 if err = cpy.preview.apply(v, n.height); err != nil {
158 return
159 }
160 }
161 cpy.head = n
162 br = cpy
163 return
164}
165
166func (b *branch) sortUnpackedTxs() (txs []pi.Transaction) {
167 txs = make([]pi.Transaction, 0, len(b.unpacked))

Callers

nothing calls this directly

Calls 7

makeArenaMethod · 0.95
applyMethod · 0.80
HashMethod · 0.65
VerifyMethod · 0.65
loadMethod · 0.45
IsEqualMethod · 0.45
ParentHashMethod · 0.45

Tested by

no test coverage detected