GenerateBlock generates a valid, but unsigned, candidate block from the current pending transaction pool. It returns the new block and a snapshot of what the state snapshot is if the block is applied. After generating the block, the pending transaction pool will be empty.
(ctx context.Context, timestampMS uint64, txs []*bc.CommitmentsTx)
| 37 | // After generating the block, the pending transaction pool will be |
| 38 | // empty. |
| 39 | func (c *Chain) GenerateBlock(ctx context.Context, timestampMS uint64, txs []*bc.CommitmentsTx) (*bc.UnsignedBlock, *state.Snapshot, error) { |
| 40 | err := c.bb.Start(c.State(), timestampMS) |
| 41 | if err != nil { |
| 42 | return nil, nil, err |
| 43 | } |
| 44 | for _, tx := range txs { |
| 45 | err := c.bb.AddTx(tx) |
| 46 | if err != nil { |
| 47 | log.Printkv(ctx, "event", "invalid tx", "error", err, "tx", hex.EncodeToString(tx.Tx.Program)) |
| 48 | } |
| 49 | } |
| 50 | return c.bb.Build() |
| 51 | } |
| 52 | |
| 53 | // CommitAppliedBlock takes a block, commits it to persistent storage and |
| 54 | // sets c's state. Unlike CommitBlock, it accepts an already applied |