MCPcopy Create free account
hub / github.com/chain/txvm / GenerateBlock

Method GenerateBlock

protocol/block.go:39–51  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

37// After generating the block, the pending transaction pool will be
38// empty.
39func (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

Callers 6

TestGenerateBlockFunction · 0.80
TestPersistSnapshotFunction · 0.80
TestBadMaxNonceWindowFunction · 0.80
MakeBlockFunction · 0.80

Calls 5

StateMethod · 0.95
PrintkvFunction · 0.92
StartMethod · 0.80
AddTxMethod · 0.80
BuildMethod · 0.45

Tested by 5

TestGenerateBlockFunction · 0.64
TestPersistSnapshotFunction · 0.64
TestBadMaxNonceWindowFunction · 0.64