1 // Copyright (c) 2014-2016 The btcsuite developers
2 // Use of this source code is governed by an ISC
3 // license that can be found in the LICENSE file.
11 // DeploymentError identifies an error that indicates a deployment ID was
12 // specified that does not exist.
13 type DeploymentError uint32
15 // Error returns the assertion error as a human-readable string and satisfies
16 // the error interface.
17 func (e DeploymentError) Error() string {
18 return fmt.Sprintf("deployment ID %d does not exist", uint32(e))
21 // AssertError identifies an error that indicates an internal code consistency
22 // issue and should be treated as a critical and unrecoverable error.
23 type AssertError string
25 // Error returns the assertion error as a human-readable string and satisfies
26 // the error interface.
27 func (e AssertError) Error() string {
28 return "assertion failed: " + string(e)
31 // ErrorCode identifies a kind of error.
34 // These constants are used to identify a specific RuleError.
36 // ErrDuplicateBlock indicates a block with the same hash already
38 ErrDuplicateBlock ErrorCode = iota
40 // ErrBlockTooBig indicates the serialized block size exceeds the
41 // maximum allowed size.
44 // ErrBlockWeightTooHigh indicates that the block's computed weight
45 // metric exceeds the maximum allowed value.
48 // ErrBlockVersionTooOld indicates the block version is too old and is
49 // no longer accepted since the majority of the network has upgraded
50 // to a newer version.
53 // ErrInvalidTime indicates the time in the passed block has a precision
54 // that is more than one second. The chain consensus rules require
55 // timestamps to have a maximum precision of one second.
58 // ErrTimeTooOld indicates the time is either before the median time of
59 // the last several blocks per the chain consensus rules or prior to the
60 // most recent checkpoint.
63 // ErrTimeTooNew indicates the time is too far in the future as compared
67 // ErrDifficultyTooLow indicates the difficulty for the block is lower
68 // than the difficulty required by the most recent checkpoint.
71 // ErrUnexpectedDifficulty indicates specified bits do not align with
72 // the expected value either because it doesn't match the calculated
73 // valued based on difficulty regarted rules or it is out of the valid
75 ErrUnexpectedDifficulty
77 // ErrHighHash indicates the block does not hash to a value which is
78 // lower than the required target difficultly.
81 // ErrBadMerkleRoot indicates the calculated merkle root does not match
82 // the expected value.
85 // ErrBadCheckpoint indicates a block that is expected to be at a
86 // checkpoint height does not match the expected one.
89 // ErrForkTooOld indicates a block is attempting to fork the block chain
90 // before the most recent checkpoint.
93 // ErrCheckpointTimeTooOld indicates a block has a timestamp before the
94 // most recent checkpoint.
95 ErrCheckpointTimeTooOld
97 // ErrNoTransactions indicates the block does not have a least one
98 // transaction. A valid block must have at least the coinbase
102 // ErrTooManyTransactions indicates the block has more transactions than
104 ErrTooManyTransactions
106 // ErrNoTxInputs indicates a transaction does not have any inputs. A
107 // valid transaction must have at least one input.
110 // ErrNoTxOutputs indicates a transaction does not have any outputs. A
111 // valid transaction must have at least one output.
114 // ErrTxTooBig indicates a transaction exceeds the maximum allowed size
118 // ErrBadTxOutValue indicates an output value for a transaction is
119 // invalid in some way such as being out of range.
122 // ErrDuplicateTxInputs indicates a transaction references the same
123 // input more than once.
126 // ErrBadTxInput indicates a transaction input is invalid in some way
127 // such as referencing a previous transaction outpoint which is out of
128 // range or not referencing one at all.
131 // ErrMissingTxOut indicates a transaction output referenced by an input
132 // either does not exist or has already been spent.
135 // ErrUnfinalizedTx indicates a transaction has not been finalized.
136 // A valid block may only contain finalized transactions.
139 // ErrDuplicateTx indicates a block contains an identical transaction
140 // (or at least two transactions which hash to the same value). A
141 // valid block may only contain unique transactions.
144 // ErrOverwriteTx indicates a block contains a transaction that has
145 // the same hash as a previous transaction which has not been fully
149 // ErrImmatureSpend indicates a transaction is attempting to spend a
150 // coinbase that has not yet reached the required maturity.
153 // ErrSpendTooHigh indicates a transaction is attempting to spend more
154 // value than the sum of all of its inputs.
157 // ErrBadFees indicates the total fees for a block are invalid due to
158 // exceeding the maximum possible value.
161 // ErrTooManySigOps indicates the total number of signature operations
162 // for a transaction or block exceed the maximum allowed limits.
165 // ErrFirstTxNotCoinbase indicates the first transaction in a block
166 // is not a coinbase transaction.
167 ErrFirstTxNotCoinbase
169 // ErrMultipleCoinbases indicates a block contains more than one
170 // coinbase transaction.
173 // ErrBadCoinbaseScriptLen indicates the length of the signature script
174 // for a coinbase transaction is not within the valid range.
175 ErrBadCoinbaseScriptLen
177 // ErrBadCoinbaseValue indicates the amount of a coinbase value does
178 // not match the expected value of the subsidy plus the sum of all fees.
181 // ErrMissingCoinbaseHeight indicates the coinbase transaction for a
182 // block does not start with the serialized block block height as
183 // required for version 2 and higher blocks.
184 ErrMissingCoinbaseHeight
186 // ErrBadCoinbaseHeight indicates the serialized block height in the
187 // coinbase transaction for version 2 and higher blocks does not match
188 // the expected value.
191 // ErrScriptMalformed indicates a transaction script is malformed in
192 // some way. For example, it might be longer than the maximum allowed
193 // length or fail to parse.
196 // ErrScriptValidation indicates the result of executing transaction
197 // script failed. The error covers any failure when executing scripts
198 // such signature verification failures and execution past the end of
202 // ErrUnexpectedWitness indicates that a block includes transactions
203 // with witness data, but doesn't also have a witness commitment within
204 // the coinbase transaction.
207 // ErrInvalidWitnessCommitment indicates that a block's witness
208 // commitment is not well formed.
209 ErrInvalidWitnessCommitment
211 // ErrWitnessCommitmentMismatch indicates that the witness commitment
212 // included in the block's coinbase transaction doesn't match the
213 // manually computed witness commitment.
214 ErrWitnessCommitmentMismatch
217 // Map of ErrorCode values back to their constant names for pretty printing.
218 var errorCodeStrings = map[ErrorCode]string{
219 ErrDuplicateBlock: "ErrDuplicateBlock",
220 ErrBlockTooBig: "ErrBlockTooBig",
221 ErrBlockVersionTooOld: "ErrBlockVersionTooOld",
222 ErrBlockWeightTooHigh: "ErrBlockWeightTooHigh",
223 ErrInvalidTime: "ErrInvalidTime",
224 ErrTimeTooOld: "ErrTimeTooOld",
225 ErrTimeTooNew: "ErrTimeTooNew",
226 ErrDifficultyTooLow: "ErrDifficultyTooLow",
227 ErrUnexpectedDifficulty: "ErrUnexpectedDifficulty",
228 ErrHighHash: "ErrHighHash",
229 ErrBadMerkleRoot: "ErrBadMerkleRoot",
230 ErrBadCheckpoint: "ErrBadCheckpoint",
231 ErrForkTooOld: "ErrForkTooOld",
232 ErrCheckpointTimeTooOld: "ErrCheckpointTimeTooOld",
233 ErrNoTransactions: "ErrNoTransactions",
234 ErrTooManyTransactions: "ErrTooManyTransactions",
235 ErrNoTxInputs: "ErrNoTxInputs",
236 ErrNoTxOutputs: "ErrNoTxOutputs",
237 ErrTxTooBig: "ErrTxTooBig",
238 ErrBadTxOutValue: "ErrBadTxOutValue",
239 ErrDuplicateTxInputs: "ErrDuplicateTxInputs",
240 ErrBadTxInput: "ErrBadTxInput",
241 ErrMissingTxOut: "ErrMissingTxOut",
242 ErrUnfinalizedTx: "ErrUnfinalizedTx",
243 ErrDuplicateTx: "ErrDuplicateTx",
244 ErrOverwriteTx: "ErrOverwriteTx",
245 ErrImmatureSpend: "ErrImmatureSpend",
246 ErrSpendTooHigh: "ErrSpendTooHigh",
247 ErrBadFees: "ErrBadFees",
248 ErrTooManySigOps: "ErrTooManySigOps",
249 ErrFirstTxNotCoinbase: "ErrFirstTxNotCoinbase",
250 ErrMultipleCoinbases: "ErrMultipleCoinbases",
251 ErrBadCoinbaseScriptLen: "ErrBadCoinbaseScriptLen",
252 ErrBadCoinbaseValue: "ErrBadCoinbaseValue",
253 ErrMissingCoinbaseHeight: "ErrMissingCoinbaseHeight",
254 ErrBadCoinbaseHeight: "ErrBadCoinbaseHeight",
255 ErrScriptMalformed: "ErrScriptMalformed",
256 ErrScriptValidation: "ErrScriptValidation",
257 ErrUnexpectedWitness: "ErrUnexpectedWitness",
258 ErrInvalidWitnessCommitment: "ErrInvalidWitnessCommitment",
259 ErrWitnessCommitmentMismatch: "ErrWitnessCommitmentMismatch",
262 // String returns the ErrorCode as a human-readable name.
263 func (e ErrorCode) String() string {
264 if s := errorCodeStrings[e]; s != "" {
267 return fmt.Sprintf("Unknown ErrorCode (%d)", int(e))
270 // RuleError identifies a rule violation. It is used to indicate that
271 // processing of a block or transaction failed due to one of the many validation
272 // rules. The caller can use type assertions to determine if a failure was
273 // specifically due to a rule violation and access the ErrorCode field to
274 // ascertain the specific reason for the rule violation.
275 type RuleError struct {
276 ErrorCode ErrorCode // Describes the kind of error
277 Description string // Human readable description of the issue
280 // Error satisfies the error interface and prints human-readable errors.
281 func (e RuleError) Error() string {
285 // ruleError creates an RuleError given a set of arguments.
286 func ruleError(c ErrorCode, desc string) RuleError {
287 return RuleError{ErrorCode: c, Description: desc}