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

Function BlockOnly

protocol/validation/validation.go:100–125  ·  view source on GitHub ↗

BlockOnly performs those parts of block validation that depend only on the block and not on the previous block header. TODO(eric): consider another name

(b *bc.UnsignedBlock)

Source from the content-addressed store, hash-verified

98// on the block and not on the previous block header.
99// TODO(eric): consider another name
100func BlockOnly(b *bc.UnsignedBlock) error {
101 // TODO(bobg): check version >= 3?
102
103 runlimit := b.Runlimit
104 for _, tx := range b.Transactions {
105 if b.Version == 3 && tx.Version != 3 {
106 return errors.WithDetailf(errTxVersion, "block version %d, transaction version %d", b.Version, tx.Version)
107 }
108
109 runlimit -= tx.Runlimit
110 if runlimit < 0 {
111 return errors.Wrap(errRunlimit)
112 }
113 }
114
115 txRoot := bc.TxMerkleRoot(b.Transactions)
116 if txRoot != *b.TransactionsRoot {
117 return errors.WithDetailf(errMismatchedMerkleRoot, "computed %x, current block wants %x", txRoot.Bytes(), b.TransactionsRoot.Bytes())
118 }
119
120 if b.Version == 3 && len(b.ExtraFields) > 0 {
121 return errExtraFields
122 }
123
124 return nil
125}
126
127// BlockPrev performs those parts of block validation that require the
128// previous block's header.

Callers 3

validateFunction · 0.92
TestBlockOnlyFunction · 0.85
BlockFunction · 0.85

Calls 4

WithDetailfFunction · 0.92
WrapFunction · 0.92
TxMerkleRootFunction · 0.92
BytesMethod · 0.45

Tested by 1

TestBlockOnlyFunction · 0.68