units: make Sequence inner field private
What changed, and why it matters
This commit makes a single internal number field private in a Rust Bitcoin library type called Sequence. It is an API-cleanup change to follow Rust naming conventions (C-STRUCT-PRIVATE). It does not fix a memory corruption bug, a cryptographic flaw, or a consensus issue. Existing code inside the project is updated to use the already-provided public constructor and getter, so behavior is unchanged.
No security action required. Treat as a normal semver-aware API change; downstream users who accessed `Sequence.0` directly will need to migrate to `from_consensus`/`to_consensus_u32`.
Security signals we found
No security signal: this is an API-encapsulation refactor
No validation or serialization logic changed
No unsafe code, no cryptographic operations modified
No mention of vulnerability, CVE, or security issue in commit message
Evidence from the diff
The change converts pub struct Sequence(pub u32) to pub struct Sequence(u32), hiding the inner u32. Callers are directed to Sequence::from_consensus(u32) and Sequence::to_consensus_u32(), which already existed. The diff updates two internal call sites (p2p/src/bip152.rs test and primitives/src/transaction.rs hash serialization) and the public-API snapshot files (units/api/*.txt). No logic, validation, or serialization behavior changes.
Changed components
units/src/sequence.rsprimitives/src/transaction.rsp2p/src/bip152.rsunits/api/*.txt public API snapshotsInspect captured patch +9 / −9
diff --git a/p2p/src/bip152.rs b/p2p/src/bip152.rs
index a23ef006..6516f8a8 100644
--- a/p2p/src/bip152.rs
+++ b/p2p/src/bip152.rs
@@ -852,7 +852,7 @@ mod test {
inputs: vec![TxIn {
previous_output: OutPoint { txid: dummy_txid, vout: 0 },
script_sig: ScriptSigBuf::new(),
- sequence: Sequence(1),
+ sequence: Sequence::from_consensus(1),
witness: Witness::new(),
}],
outputs: vec![TxOut { amount: Amount::ONE_SAT, script_pubkey: ScriptPubKeyBuf::new() }],
diff --git a/primitives/src/transaction.rs b/primitives/src/transaction.rs
index 0b9ad119..3b01154e 100644
--- a/primitives/src/transaction.rs
+++ b/primitives/src/transaction.rs
@@ -337,7 +337,7 @@ fn hash_transaction(tx: &Transaction, uses_segwit_serialization: bool) -> sha256
enc.input(crate::compact_size_encode(script_sig_bytes.len()).as_slice());
enc.input(script_sig_bytes);
- enc.input(&input.sequence.0.to_le_bytes());
+ enc.input(&input.sequence.to_consensus_u32().to_le_bytes());
}
// Encode outputs with leading compact size encoded int.
diff --git a/units/api/all-features.txt b/units/api/all-features.txt
index 1293689a..d8b6bc56 100644
--- a/units/api/all-features.txt
+++ b/units/api/all-features.txt
@@ -8755,7 +8755,7 @@ impl<T> core::clone::CloneToUninit for bitcoin_units::sequence::error::SequenceD
pub unsafe fn bitcoin_units::sequence::error::SequenceDecoderError::clone_to_uninit(&self, dest: *mut u8) [impl: impl<T> core::clone::CloneToUninit for bitcoin_units::sequence::error::SequenceDecoderError where T: core::clone::Clone]
impl<T> core::convert::From<T> for bitcoin_units::sequence::error::SequenceDecoderError
pub fn bitcoin_units::sequence::error::SequenceDecoderError::from(t: T) -> T [impl: impl<T> core::convert::From<T> for bitcoin_units::sequence::error::SequenceDecoderError]
-pub struct bitcoin_units::sequence::Sequence(pub u32)
+pub struct bitcoin_units::sequence::Sequence(_)
impl bitcoin_units::sequence::Sequence
pub const bitcoin_units::sequence::Sequence::ENABLE_LOCKTIME_AND_RBF: Self
pub const bitcoin_units::sequence::Sequence::ENABLE_LOCKTIME_NO_RBF: Self
@@ -11257,7 +11257,7 @@ impl<T> core::clone::CloneToUninit for bitcoin_units::FeeRate where T: core::clo
pub unsafe fn bitcoin_units::FeeRate::clone_to_uninit(&self, dest: *mut u8) [impl: impl<T> core::clone::CloneToUninit for bitcoin_units::FeeRate where T: core::clone::Clone]
impl<T> core::convert::From<T> for bitcoin_units::FeeRate
pub fn bitcoin_units::FeeRate::from(t: T) -> T [impl: impl<T> core::convert::From<T> for bitcoin_units::FeeRate]
-pub struct bitcoin_units::Sequence(pub u32)
+pub struct bitcoin_units::Sequence(_)
impl bitcoin_units::sequence::Sequence
pub const bitcoin_units::sequence::Sequence::ENABLE_LOCKTIME_AND_RBF: Self
pub const bitcoin_units::sequence::Sequence::ENABLE_LOCKTIME_NO_RBF: Self
diff --git a/units/api/alloc-only.txt b/units/api/alloc-only.txt
index baf367c6..60293f57 100644
--- a/units/api/alloc-only.txt
+++ b/units/api/alloc-only.txt
@@ -7368,7 +7368,7 @@ impl<T> core::convert::From<T> for bitcoin_units::result::error::NumOpError
pub fn bitcoin_units::result::error::NumOpError::from(t: T) -> T [impl: impl<T> core::convert::From<T> for bitcoin_units::result::error::NumOpError]
pub mod bitcoin_units::sequence
pub mod bitcoin_units::sequence::error
-pub struct bitcoin_units::sequence::Sequence(pub u32)
+pub struct bitcoin_units::sequence::Sequence(_)
impl bitcoin_units::sequence::Sequence
pub const bitcoin_units::sequence::Sequence::ENABLE_LOCKTIME_AND_RBF: Self
pub const bitcoin_units::sequence::Sequence::ENABLE_LOCKTIME_NO_RBF: Self
@@ -9467,7 +9467,7 @@ impl<T> core::clone::CloneToUninit for bitcoin_units::FeeRate where T: core::clo
pub unsafe fn bitcoin_units::FeeRate::clone_to_uninit(&self, dest: *mut u8) [impl: impl<T> core::clone::CloneToUninit for bitcoin_units::FeeRate where T: core::clone::Clone]
impl<T> core::convert::From<T> for bitcoin_units::FeeRate
pub fn bitcoin_units::FeeRate::from(t: T) -> T [impl: impl<T> core::convert::From<T> for bitcoin_units::FeeRate]
-pub struct bitcoin_units::Sequence(pub u32)
+pub struct bitcoin_units::Sequence(_)
impl bitcoin_units::sequence::Sequence
pub const bitcoin_units::sequence::Sequence::ENABLE_LOCKTIME_AND_RBF: Self
pub const bitcoin_units::sequence::Sequence::ENABLE_LOCKTIME_NO_RBF: Self
diff --git a/units/api/no-features.txt b/units/api/no-features.txt
index 180e86fa..f13c881e 100644
--- a/units/api/no-features.txt
+++ b/units/api/no-features.txt
@@ -6548,7 +6548,7 @@ impl<T> core::convert::From<T> for bitcoin_units::result::error::NumOpError
pub fn bitcoin_units::result::error::NumOpError::from(t: T) -> T [impl: impl<T> core::convert::From<T> for bitcoin_units::result::error::NumOpError]
pub mod bitcoin_units::sequence
pub mod bitcoin_units::sequence::error
-pub struct bitcoin_units::sequence::Sequence(pub u32)
+pub struct bitcoin_units::sequence::Sequence(_)
impl bitcoin_units::sequence::Sequence
pub const bitcoin_units::sequence::Sequence::ENABLE_LOCKTIME_AND_RBF: Self
pub const bitcoin_units::sequence::Sequence::ENABLE_LOCKTIME_NO_RBF: Self
@@ -8519,7 +8519,7 @@ impl<T> core::clone::CloneToUninit for bitcoin_units::FeeRate where T: core::clo
pub unsafe fn bitcoin_units::FeeRate::clone_to_uninit(&self, dest: *mut u8) [impl: impl<T> core::clone::CloneToUninit for bitcoin_units::FeeRate where T: core::clone::Clone]
impl<T> core::convert::From<T> for bitcoin_units::FeeRate
pub fn bitcoin_units::FeeRate::from(t: T) -> T [impl: impl<T> core::convert::From<T> for bitcoin_units::FeeRate]
-pub struct bitcoin_units::Sequence(pub u32)
+pub struct bitcoin_units::Sequence(_)
impl bitcoin_units::sequence::Sequence
pub const bitcoin_units::sequence::Sequence::ENABLE_LOCKTIME_AND_RBF: Self
pub const bitcoin_units::sequence::Sequence::ENABLE_LOCKTIME_NO_RBF: Self
diff --git a/units/src/sequence.rs b/units/src/sequence.rs
index fe0856cb..cf189624 100644
--- a/units/src/sequence.rs
+++ b/units/src/sequence.rs
@@ -33,7 +33,7 @@ pub use self::error::SequenceDecoderError;
/// Bitcoin transaction input sequence number.
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
-pub struct Sequence(pub u32);
+pub struct Sequence(u32);
impl Sequence {
/// The maximum allowable sequence number.
Why this scored 20/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.