-
Notifications
You must be signed in to change notification settings - Fork 35
/
miningerror.go
126 lines (102 loc) · 4.35 KB
/
miningerror.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
// Copyright (c) 2015-2016 The Decred developers
// Copyright (c) 2015-2016 The Decred developers
// Copyright (c) 2017 The Hcash developers
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.
package main
import (
"fmt"
)
// MiningErrorCode identifies a kind of error.
type MiningErrorCode int
// These constants are used to identify a specific RuleError.
const (
// ErrNotEnoughVoters indicates that there were not enough voters to
// build a block on top of HEAD.
ErrNotEnoughVoters MiningErrorCode = iota
// ErrFailedToGetGeneration specifies that the current generation for
// a block could not be obtained from blockchain.
ErrFailedToGetGeneration
// ErrGetStakeDifficulty indicates that the current stake difficulty
// could not be obtained.
ErrGetStakeDifficulty
// ErrGetStakeDifficulty indicates that the current top block of the
// blockchain could not be obtained.
ErrGetTopBlock
// ErrCreatingCoinbase indicates that there was a problem generating
// the coinbase.
ErrCreatingCoinbase
// ErrGettingMedianTime indicates that the server was unable to get the
// median adjusted time for the network.
ErrGettingMedianTime
// ErrGettingDifficulty indicates that there was an error getting the
// PoW difficulty.
ErrGettingDifficulty
// ErrTransactionAppend indicates there was a problem adding a msgtx
// to a msgblock.
ErrTransactionAppend
// ErrCheckConnectBlock indicates that a newly created block template
// failed blockchain.CheckBlockSanity.
ErrCheckBlockSanity
// ErrCheckConnectBlock indicates that a newly created block template
// failed blockchain.CheckConnectBlock.
ErrCheckConnectBlock
// ErrCoinbaseLengthOverflow indicates that a coinbase length was overflowed,
// probably of a result of incrementing extranonce.
ErrCoinbaseLengthOverflow
// ErrFraudProofIndex indicates that there was an error finding the index
// for a fraud proof.
ErrFraudProofIndex
// ErrFetchTxStore indicates a transaction store failed to fetch.
ErrFetchTxStore
// ErrFailedToGetFinalDescendant specifies that the MatchedDescendants for
// a block could not be obtained from blockchain.
ErrFailedToGetMatchedDescendants
ErrFailedToGetKeyGeneration
)
// Map of MiningErrorCode values back to their constant names for pretty printing.
var miningErrorCodeStrings = map[MiningErrorCode]string{
ErrNotEnoughVoters: "ErrNotEnoughVoters",
ErrFailedToGetGeneration: "ErrFailedToGetGeneration",
ErrGetStakeDifficulty: "ErrGetStakeDifficulty",
ErrGetTopBlock: "ErrGetTopBlock",
ErrCreatingCoinbase: "ErrCreatingCoinbase",
ErrGettingMedianTime: "ErrGettingMedianTime",
ErrGettingDifficulty: "ErrGettingDifficulty",
ErrTransactionAppend: "ErrTransactionAppend",
ErrCheckBlockSanity: "ErrCheckBlockSanity",
ErrCheckConnectBlock: "ErrCheckConnectBlock",
ErrCoinbaseLengthOverflow: "ErrCoinbaseLengthOverflow",
ErrFraudProofIndex: "ErrFraudProofIndex",
ErrFetchTxStore: "ErrFetchTxStore",
ErrFailedToGetMatchedDescendants: "ErrFailedToGetMatchedDescendants",
ErrFailedToGetKeyGeneration:"ErrFailedToGetKeyGeneration",
}
// String returns the MiningErrorCode as a human-readable name.
func (e MiningErrorCode) String() string {
if s := miningErrorCodeStrings[e]; s != "" {
return s
}
return fmt.Sprintf("Unknown MiningErrorCode (%d)", int(e))
}
// MiningRuleError identifies a rule violation. It is used to indicate that
// processing of a block or transaction failed due to one of the many validation
// rules. The caller can use type assertions to determine if a failure was
// specifically due to a rule violation and access the MiningErrorCode field to
// ascertain the specific reason for the rule violation.
type MiningRuleError struct {
ErrorCode MiningErrorCode // Describes the kind of error
Description string // Human readable description of the issue
}
// Error satisfies the error interface and prints human-readable errors.
func (e MiningRuleError) Error() string {
return e.Description
}
// GetCode satisfies the error interface and prints human-readable errors.
func (e MiningRuleError) GetCode() MiningErrorCode {
return e.ErrorCode
}
// miningRuleError creates an RuleError given a set of arguments.
func miningRuleError(c MiningErrorCode, desc string) MiningRuleError {
return MiningRuleError{ErrorCode: c, Description: desc}
}