Skip to content

Commit e86a56c

Browse files
committed
primitives: renamed TransactionDecoderError::Transitioning to Errored
Search-and-replace the error variant name, and update all the panic conditions that are triggered by it. From a user point of view this state does not represent "transitioning". It represents that we called end() on a sub-decoder and that call yielded an error, leaving us with no meaningful state. The docs for Decoder::end and Decoder::current_chunk say that after returning the initial error we are allowed to panic; update the panic message to say that this is what we're doing. (We also have a panic in read_limit, which we are not allowed to do, so replace that with a dummy value return.) No observable behavior changes except that some panic messages change.
1 parent 681af66 commit e86a56c

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

primitives/src/transaction.rs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -422,13 +422,11 @@ impl Decoder for TransactionDecoder {
422422
}
423423
},
424424
State::Done(..) => return Ok(false),
425-
State::Transitioning => {
426-
panic!("use of decoder in transitioning state");
427-
}
425+
State::Errored => panic!("call to push_bytes() after decoder errored"),
428426
}
429427

430428
// If the above failed, end the current decoder and go to the next state.
431-
match mem::replace(&mut self.state, State::Transitioning) {
429+
match mem::replace(&mut self.state, State::Errored) {
432430
State::Version(decoder) => {
433431
let version = decoder.end()?;
434432
self.state = State::Inputs(version, Attempt::First, VecDecoder::<TxIn>::new());
@@ -509,9 +507,7 @@ impl Decoder for TransactionDecoder {
509507
return Ok(false);
510508
}
511509
State::Done(..) => return Ok(false),
512-
State::Transitioning => {
513-
panic!("use of decoder in transitioning state");
514-
}
510+
State::Errored => unreachable!("checked above"),
515511
}
516512
}
517513
}
@@ -528,9 +524,7 @@ impl Decoder for TransactionDecoder {
528524
State::Witnesses(..) => panic!("tried to end decoder in state: Witnesses"),
529525
State::LockTime(..) => panic!("tried to end decoder in state: LockTime"),
530526
State::Done(tx) => Ok(tx),
531-
State::Transitioning => {
532-
panic!("use of decoder in transitioning state");
533-
}
527+
State::Errored => panic!("call to end() after decoder errored"),
534528
}
535529
}
536530

@@ -546,7 +540,9 @@ impl Decoder for TransactionDecoder {
546540
State::Witnesses(_, _, _, _, decoder) => decoder.read_limit(),
547541
State::LockTime(_, _, _, decoder) => decoder.read_limit(),
548542
State::Done(_) => 0,
549-
State::Transitioning => panic!("use of decoder in transitioning state"),
543+
// `read_limit` is not documented to panic or return an error, so we
544+
// return a dummy value if the decoder is in an error state.
545+
State::Errored => 0,
550546
}
551547
}
552548
}
@@ -574,8 +570,9 @@ enum TransactionDecoderState {
574570
LockTime(Version, Vec<TxIn>, Vec<TxOut>, LockTimeDecoder),
575571
/// Done decoding the [`Transaction`].
576572
Done(Transaction),
577-
/// Temporary state during transitions, should never be observed.
578-
Transitioning,
573+
/// When `end()`ing a sub-decoder, encountered an error which prevented us
574+
/// from constructing the next sub-decoder.
575+
Errored,
579576
}
580577

581578
/// Boolean used to track number of times we have attempted to decode the inputs vector.

0 commit comments

Comments
 (0)