primitives: renamed TransactionDecoderError::Transitioning to Errored
What changed, and why it matters
This commit is a simple internal rename and documentation cleanup. It renames a temporary error state inside a Bitcoin transaction decoder from 'Transitioning' to 'Errored' and updates the panic messages to be clearer. It also removes one panic that shouldn't have been there and replaces it with a safe dummy value. There are no observable behavior changes for users.
No security action needed. This is a non-functional refactor and documentation improvement.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch renames TransactionDecoderState::Transitioning to State::Errored and updates all match arms accordingly. It changes panic messages to clarify that the decoder is being used after an error occurred. Crucially, it replaces a panic in read_limit() when in the errored state with a return of 0, because read_limit() is not documented to panic. The commit message explicitly states ‘No observable behavior changes except that some panic messages change.’
Changed components
primitives/src/transaction.rsInspect captured patch +10 / −13
diff --git a/primitives/src/transaction.rs b/primitives/src/transaction.rs
index 9dff5501..b086ab84 100644
--- a/primitives/src/transaction.rs
+++ b/primitives/src/transaction.rs
@@ -422,13 +422,11 @@ impl Decoder for TransactionDecoder {
}
},
State::Done(..) => return Ok(false),
- State::Transitioning => {
- panic!("use of decoder in transitioning state");
- }
+ State::Errored => panic!("call to push_bytes() after decoder errored"),
}
// If the above failed, end the current decoder and go to the next state.
- match mem::replace(&mut self.state, State::Transitioning) {
+ match mem::replace(&mut self.state, State::Errored) {
State::Version(decoder) => {
let version = decoder.end()?;
self.state = State::Inputs(version, Attempt::First, VecDecoder::<TxIn>::new());
@@ -509,9 +507,7 @@ impl Decoder for TransactionDecoder {
return Ok(false);
}
State::Done(..) => return Ok(false),
- State::Transitioning => {
- panic!("use of decoder in transitioning state");
- }
+ State::Errored => unreachable!("checked above"),
}
}
}
@@ -528,9 +524,7 @@ impl Decoder for TransactionDecoder {
State::Witnesses(..) => panic!("tried to end decoder in state: Witnesses"),
State::LockTime(..) => panic!("tried to end decoder in state: LockTime"),
State::Done(tx) => Ok(tx),
- State::Transitioning => {
- panic!("use of decoder in transitioning state");
- }
+ State::Errored => panic!("call to end() after decoder errored"),
}
}
@@ -546,7 +540,9 @@ impl Decoder for TransactionDecoder {
State::Witnesses(_, _, _, _, decoder) => decoder.read_limit(),
State::LockTime(_, _, _, decoder) => decoder.read_limit(),
State::Done(_) => 0,
- State::Transitioning => panic!("use of decoder in transitioning state"),
+ // `read_limit` is not documented to panic or return an error, so we
+ // return a dummy value if the decoder is in an error state.
+ State::Errored => 0,
}
}
}
@@ -574,8 +570,9 @@ enum TransactionDecoderState {
LockTime(Version, Vec<TxIn>, Vec<TxOut>, LockTimeDecoder),
/// Done decoding the [`Transaction`].
Done(Transaction),
- /// Temporary state during transitions, should never be observed.
- Transitioning,
+ /// When `end()`ing a sub-decoder, encountered an error which prevented us
+ /// from constructing the next sub-decoder.
+ Errored,
}
/// Boolean used to track number of times we have attempted to decode the inputs vector.
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.