( h uint32, ts time.Time, addr proto.AccountAddress, signer *ca.PrivateKey, )
| 181 | } |
| 182 | |
| 183 | func (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 | |
| 235 | func (b *branch) clearPackedTxs(txs []pi.Transaction) { |
| 236 | for _, v := range txs { |
nothing calls this directly
no test coverage detected