MCPcopy Create free account
hub / github.com/CovenantSQL/CovenantSQL / produceBlock

Method produceBlock

blockproducer/branch.go:183–233  ·  view source on GitHub ↗
(
	h uint32, ts time.Time, addr proto.AccountAddress, signer *ca.PrivateKey,
)

Source from the content-addressed store, hash-verified

181}
182
183func (b *branch) produceBlock(
184 h uint32, ts time.Time, addr proto.AccountAddress, signer *ca.PrivateKey,
185) (
186 br *branch, bl *types.BPBlock, err error,
187) {
188 var (
189 cpy = b.makeArena()
190 txs = cpy.sortUnpackedTxs()
191 ierr error
192 packCount = conf.MaxTransactionsPerBlock
193 )
194
195 if len(txs) < packCount {
196 packCount = len(txs)
197 }
198
199 out := make([]pi.Transaction, 0, packCount)
200 for _, v := range txs {
201 var k = v.Hash()
202 if ierr = cpy.preview.apply(v, h); ierr != nil {
203 continue
204 }
205 delete(cpy.unpacked, k)
206 cpy.packed[k] = v
207 out = append(out, v)
208 if len(out) == packCount {
209 break
210 }
211 }
212
213 // Create new block and update head
214 var block = &types.BPBlock{
215 SignedHeader: types.BPSignedHeader{
216 BPHeader: types.BPHeader{
217 Version: 0x01000000,
218 Producer: addr,
219 ParentHash: cpy.head.hash,
220 Timestamp: ts,
221 },
222 },
223 Transactions: out,
224 }
225 if ierr = block.PackAndSignBlock(signer); ierr != nil {
226 err = errors.Wrap(ierr, "failed to sign block")
227 return
228 }
229 cpy.head = newBlockNode(h, block, cpy.head)
230 br = cpy
231 bl = block
232 return
233}
234
235func (b *branch) clearPackedTxs(txs []pi.Transaction) {
236 for _, v := range txs {

Callers

nothing calls this directly

Calls 6

makeArenaMethod · 0.95
sortUnpackedTxsMethod · 0.80
applyMethod · 0.80
newBlockNodeFunction · 0.70
HashMethod · 0.65
PackAndSignBlockMethod · 0.45

Tested by

no test coverage detected