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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
use util::*;
use io::*;
use header::BlockNumber;
use basic_types::LogBloom;
use client::Error as ClientError;
use ipc::binary::{BinaryConvertError, BinaryConvertable};
use types::block_import_error::BlockImportError;
use snapshot::Error as SnapshotError;
use engines::EngineError;
use ethkey::Error as EthkeyError;
use account_provider::SignError as AccountsError;
pub use types::executed::{ExecutionError, CallError};
#[derive(Debug, PartialEq, Clone, Copy)]
pub enum TransactionError {
AlreadyImported,
Old,
TooCheapToReplace,
LimitReached,
InsufficientGasPrice {
minimal: U256,
got: U256,
},
InsufficientGas {
minimal: U256,
got: U256,
},
InsufficientBalance {
balance: U256,
cost: U256,
},
GasLimitExceeded {
limit: U256,
got: U256,
},
InvalidGasLimit(OutOfBounds<U256>),
SenderBanned,
RecipientBanned,
CodeBanned,
InvalidNetworkId,
}
impl fmt::Display for TransactionError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use self::TransactionError::*;
let msg = match *self {
AlreadyImported => "Already imported".into(),
Old => "No longer valid".into(),
TooCheapToReplace => "Gas price too low to replace".into(),
LimitReached => "Transaction limit reached".into(),
InsufficientGasPrice { minimal, got } =>
format!("Insufficient gas price. Min={}, Given={}", minimal, got),
InsufficientGas { minimal, got } =>
format!("Insufficient gas. Min={}, Given={}", minimal, got),
InsufficientBalance { balance, cost } =>
format!("Insufficient balance for transaction. Balance={}, Cost={}",
balance, cost),
GasLimitExceeded { limit, got } =>
format!("Gas limit exceeded. Limit={}, Given={}", limit, got),
InvalidGasLimit(ref err) => format!("Invalid gas limit. {}", err),
SenderBanned => "Sender is temporarily banned.".into(),
RecipientBanned => "Recipient is temporarily banned.".into(),
CodeBanned => "Contract code is temporarily banned.".into(),
InvalidNetworkId => "Transaction of this network ID is not allowed on this chain.".into(),
};
f.write_fmt(format_args!("Transaction error ({})", msg))
}
}
#[derive(Debug, PartialEq, Clone, Copy, Eq)]
pub enum BlockError {
TooManyUncles(OutOfBounds<usize>),
ExtraDataOutOfBounds(OutOfBounds<usize>),
InvalidSealArity(Mismatch<usize>),
TooMuchGasUsed(OutOfBounds<U256>),
InvalidUnclesHash(Mismatch<H256>),
UncleTooOld(OutOfBounds<BlockNumber>),
UncleIsBrother(OutOfBounds<BlockNumber>),
UncleInChain(H256),
UncleParentNotInChain(H256),
InvalidStateRoot(Mismatch<H256>),
InvalidGasUsed(Mismatch<U256>),
InvalidTransactionsRoot(Mismatch<H256>),
DifficultyOutOfBounds(OutOfBounds<U256>),
InvalidDifficulty(Mismatch<U256>),
MismatchedH256SealElement(Mismatch<H256>),
InvalidProofOfWork(OutOfBounds<U256>),
InvalidSeal,
InvalidGasLimit(OutOfBounds<U256>),
InvalidReceiptsRoot(Mismatch<H256>),
InvalidTimestamp(OutOfBounds<u64>),
InvalidLogBloom(Mismatch<LogBloom>),
InvalidParentHash(Mismatch<H256>),
InvalidNumber(Mismatch<BlockNumber>),
RidiculousNumber(OutOfBounds<BlockNumber>),
UnknownParent(H256),
UnknownUncleParent(H256),
}
impl fmt::Display for BlockError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use self::BlockError::*;
let msg = match *self {
TooManyUncles(ref oob) => format!("Block has too many uncles. {}", oob),
ExtraDataOutOfBounds(ref oob) => format!("Extra block data too long. {}", oob),
InvalidSealArity(ref mis) => format!("Block seal in incorrect format: {}", mis),
TooMuchGasUsed(ref oob) => format!("Block has too much gas used. {}", oob),
InvalidUnclesHash(ref mis) => format!("Block has invalid uncles hash: {}", mis),
UncleTooOld(ref oob) => format!("Uncle block is too old. {}", oob),
UncleIsBrother(ref oob) => format!("Uncle from same generation as block. {}", oob),
UncleInChain(ref hash) => format!("Uncle {} already in chain", hash),
UncleParentNotInChain(ref hash) => format!("Uncle {} has a parent not in the chain", hash),
InvalidStateRoot(ref mis) => format!("Invalid state root in header: {}", mis),
InvalidGasUsed(ref mis) => format!("Invalid gas used in header: {}", mis),
InvalidTransactionsRoot(ref mis) => format!("Invalid transactions root in header: {}", mis),
DifficultyOutOfBounds(ref oob) => format!("Invalid block difficulty: {}", oob),
InvalidDifficulty(ref mis) => format!("Invalid block difficulty: {}", mis),
MismatchedH256SealElement(ref mis) => format!("Seal element out of bounds: {}", mis),
InvalidProofOfWork(ref oob) => format!("Block has invalid PoW: {}", oob),
InvalidSeal => "Block has invalid seal.".into(),
InvalidGasLimit(ref oob) => format!("Invalid gas limit: {}", oob),
InvalidReceiptsRoot(ref mis) => format!("Invalid receipts trie root in header: {}", mis),
InvalidTimestamp(ref oob) => format!("Invalid timestamp in header: {}", oob),
InvalidLogBloom(ref oob) => format!("Invalid log bloom in header: {}", oob),
InvalidParentHash(ref mis) => format!("Invalid parent hash: {}", mis),
InvalidNumber(ref mis) => format!("Invalid number in header: {}", mis),
RidiculousNumber(ref oob) => format!("Implausible block number. {}", oob),
UnknownParent(ref hash) => format!("Unknown parent: {}", hash),
UnknownUncleParent(ref hash) => format!("Unknown uncle parent: {}", hash),
};
f.write_fmt(format_args!("Block error ({})", msg))
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum ImportError {
AlreadyInChain,
AlreadyQueued,
KnownBad,
}
impl fmt::Display for ImportError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let msg = match *self {
ImportError::AlreadyInChain => "block already in chain",
ImportError::AlreadyQueued => "block already in the block queue",
ImportError::KnownBad => "block known to be bad",
};
f.write_fmt(format_args!("Block import error ({})", msg))
}
}
#[derive(Debug)]
pub enum Error {
Client(ClientError),
Util(UtilError),
Block(BlockError),
UnknownEngineName(String),
Execution(ExecutionError),
Transaction(TransactionError),
Import(ImportError),
PowHashInvalid,
PowInvalid,
Trie(TrieError),
Io(IoError),
StdIo(::std::io::Error),
Snappy(::util::snappy::InvalidInput),
Snapshot(SnapshotError),
Engine(EngineError),
Ethkey(EthkeyError),
AccountProvider(AccountsError),
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
Error::Client(ref err) => err.fmt(f),
Error::Util(ref err) => err.fmt(f),
Error::Io(ref err) => err.fmt(f),
Error::Block(ref err) => err.fmt(f),
Error::Execution(ref err) => err.fmt(f),
Error::Transaction(ref err) => err.fmt(f),
Error::Import(ref err) => err.fmt(f),
Error::UnknownEngineName(ref name) =>
f.write_fmt(format_args!("Unknown engine name ({})", name)),
Error::PowHashInvalid => f.write_str("Invalid or out of date PoW hash."),
Error::PowInvalid => f.write_str("Invalid nonce or mishash"),
Error::Trie(ref err) => err.fmt(f),
Error::StdIo(ref err) => err.fmt(f),
Error::Snappy(ref err) => err.fmt(f),
Error::Snapshot(ref err) => err.fmt(f),
Error::Engine(ref err) => err.fmt(f),
Error::Ethkey(ref err) => err.fmt(f),
Error::AccountProvider(ref err) => err.fmt(f),
}
}
}
pub type ImportResult = Result<H256, Error>;
impl From<ClientError> for Error {
fn from(err: ClientError) -> Error {
match err {
ClientError::Trie(err) => Error::Trie(err),
_ => Error::Client(err)
}
}
}
impl From<TransactionError> for Error {
fn from(err: TransactionError) -> Error {
Error::Transaction(err)
}
}
impl From<ImportError> for Error {
fn from(err: ImportError) -> Error {
Error::Import(err)
}
}
impl From<BlockError> for Error {
fn from(err: BlockError) -> Error {
Error::Block(err)
}
}
impl From<ExecutionError> for Error {
fn from(err: ExecutionError) -> Error {
Error::Execution(err)
}
}
impl From<::rlp::DecoderError> for Error {
fn from(err: ::rlp::DecoderError) -> Error {
Error::Util(UtilError::Decoder(err))
}
}
impl From<UtilError> for Error {
fn from(err: UtilError) -> Error {
Error::Util(err)
}
}
impl From<IoError> for Error {
fn from(err: IoError) -> Error {
Error::Io(err)
}
}
impl From<TrieError> for Error {
fn from(err: TrieError) -> Error {
Error::Trie(err)
}
}
impl From<::std::io::Error> for Error {
fn from(err: ::std::io::Error) -> Error {
Error::StdIo(err)
}
}
impl From<BlockImportError> for Error {
fn from(err: BlockImportError) -> Error {
match err {
BlockImportError::Block(e) => Error::Block(e),
BlockImportError::Import(e) => Error::Import(e),
BlockImportError::Other(s) => Error::Util(UtilError::SimpleString(s)),
}
}
}
impl From<snappy::InvalidInput> for Error {
fn from(err: snappy::InvalidInput) -> Error {
Error::Snappy(err)
}
}
impl From<SnapshotError> for Error {
fn from(err: SnapshotError) -> Error {
match err {
SnapshotError::Io(err) => Error::StdIo(err),
SnapshotError::Trie(err) => Error::Trie(err),
SnapshotError::Decoder(err) => err.into(),
other => Error::Snapshot(other),
}
}
}
impl From<EngineError> for Error {
fn from(err: EngineError) -> Error {
Error::Engine(err)
}
}
impl From<EthkeyError> for Error {
fn from(err: EthkeyError) -> Error {
Error::Ethkey(err)
}
}
impl From<AccountsError> for Error {
fn from(err: AccountsError) -> Error {
Error::AccountProvider(err)
}
}
impl<E> From<Box<E>> for Error where Error: From<E> {
fn from(err: Box<E>) -> Error {
Error::from(*err)
}
}
binary_fixed_size!(BlockError);
binary_fixed_size!(ImportError);
binary_fixed_size!(TransactionError);