Skip to content

Commit 38c8c90

Browse files
committed
Merge rust-bitcoin#4065: locktimes: Remove PartialOrd and ArbitraryOrd
4259dab Remove rust-ordered dependency (Tobin C. Harding) d392cdb Remove PartialOrd from locktimes (Tobin C. Harding) Pull request description: These two things are related so we remove them both in the same PR. Please see commit logs for full explanation. For more context see discussion below and also: - rust-bitcoin#2500 - rust-bitcoin#4002 - rust-bitcoin#3881 Close: rust-bitcoin#4029 ACKs for top commit: Kixunil: ACK 4259dab apoelstra: ACK 4259dab; successfully ran local tests Tree-SHA512: 7526d4faaa9edf8017d2af412c41a33f33d851ad5130c9a745bba86d9c71dc1db7f20d07377aaf3a25fec2c0de79f3ffabc2c538a5a366e415c7a6eaa730153c
2 parents dfe6935 + 4259dab commit 38c8c90

File tree

9 files changed

+11
-99
lines changed

9 files changed

+11
-99
lines changed

Cargo-minimal.lock

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ dependencies = [
6262
"bitcoinconsensus",
6363
"hex-conservative 0.3.0",
6464
"hex_lit",
65-
"ordered",
6665
"secp256k1",
6766
"serde",
6867
"serde_json",
@@ -111,7 +110,6 @@ dependencies = [
111110
"bitcoin-units",
112111
"bitcoin_hashes 0.16.0",
113112
"hex-conservative 0.3.0",
114-
"ordered",
115113
"serde",
116114
"serde_json",
117115
]
@@ -254,12 +252,6 @@ dependencies = [
254252
"libc",
255253
]
256254

257-
[[package]]
258-
name = "ordered"
259-
version = "0.4.0"
260-
source = "registry+https://github.com/rust-lang/crates.io-index"
261-
checksum = "79c12388aac4f817eae0359011d67d4072ed84cfc63b0d9a7958ef476fb74bec"
262-
263255
[[package]]
264256
name = "ppv-lite86"
265257
version = "0.2.8"

Cargo-recent.lock

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ dependencies = [
6161
"bitcoinconsensus",
6262
"hex-conservative 0.3.0",
6363
"hex_lit",
64-
"ordered",
6564
"secp256k1",
6665
"serde",
6766
"serde_json",
@@ -110,7 +109,6 @@ dependencies = [
110109
"bitcoin-units",
111110
"bitcoin_hashes 0.16.0",
112111
"hex-conservative 0.3.0",
113-
"ordered",
114112
"serde",
115113
"serde_json",
116114
]
@@ -262,12 +260,6 @@ dependencies = [
262260
"libc",
263261
]
264262

265-
[[package]]
266-
name = "ordered"
267-
version = "0.4.0"
268-
source = "registry+https://github.com/rust-lang/crates.io-index"
269-
checksum = "79c12388aac4f817eae0359011d67d4072ed84cfc63b0d9a7958ef476fb74bec"
270-
271263
[[package]]
272264
name = "ppv-lite86"
273265
version = "0.2.20"

bitcoin/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ arbitrary = { version = "1.4", optional = true }
3939
base64 = { version = "0.22.0", optional = true }
4040
# `bitcoinconsensus` version includes metadata which indicates the version of Core. Use `cargo tree` to see it.
4141
bitcoinconsensus = { version = "0.106.0", default-features = false, optional = true }
42-
ordered = { version = "0.4.0", optional = true }
4342
serde = { version = "1.0.103", default-features = false, features = [ "derive", "alloc" ], optional = true }
4443

4544
[dev-dependencies]

bitcoin/contrib/test_vars.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
# shellcheck disable=SC2034
66

77
# Test all these features with "std" enabled.
8-
FEATURES_WITH_STD="rand-std serde secp-recovery bitcoinconsensus base64 ordered arbitrary"
8+
FEATURES_WITH_STD="rand-std serde secp-recovery bitcoinconsensus base64 arbitrary"
99

1010
# Test all these features without "std" or "alloc" enabled.
11-
FEATURES_WITHOUT_STD="rand serde secp-recovery bitcoinconsensus base64 ordered arbitrary"
11+
FEATURES_WITHOUT_STD="rand serde secp-recovery bitcoinconsensus base64 arbitrary"
1212

1313
# Run these examples.
1414
EXAMPLES="ecdsa-psbt:std,bitcoinconsensus sign-tx-segwit-v0:rand-std sign-tx-taproot:rand-std taproot-psbt:bitcoinconsensus,rand-std sighash:std"

bitcoin/src/lib.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
//! * `base64` (dependency) - enables encoding of PSBTs and message signatures.
1717
//! * `bitcoinconsensus` (dependency) - enables validating scripts and transactions.
1818
//! * `default` - enables `std` and `secp-recovery`.
19-
//! * `ordered` (dependency) - adds implementations of `ArbitraryOrd` to some structs.
2019
//! * `rand` (transitive dependency) - makes it more convenient to generate random values.
2120
//! * `rand-std` - same as `rand` but also enables `std` here and in `secp256k1`.
2221
//! * `serde` (dependency) - implements `serde`-based serialization and deserialization.
@@ -80,10 +79,6 @@ pub extern crate hex;
8079
/// Re-export the `bitcoin-io` crate.
8180
pub extern crate io;
8281

83-
/// Re-export the `ordered` crate.
84-
#[cfg(feature = "ordered")]
85-
pub extern crate ordered;
86-
8782
/// Re-export the `rust-secp256k1` crate.
8883
///
8984
/// Rust wrapper library for Pieter Wuille's libsecp256k1. Implements ECDSA and BIP-340 signatures

primitives/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ internals = { package = "bitcoin-internals", version = "0.4.0" }
2828
units = { package = "bitcoin-units", version = "0.2.0", default-features = false }
2929

3030
arbitrary = { version = "1.4", optional = true }
31-
ordered = { version = "0.4.0", optional = true }
3231
serde = { version = "1.0.103", default-features = false, features = ["derive", "alloc"], optional = true }
3332

3433
[dev-dependencies]

primitives/contrib/test_vars.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
# shellcheck disable=SC2034
66

77
# Test these features with "std" enabled.
8-
FEATURES_WITH_STD="ordered serde arbitrary"
8+
FEATURES_WITH_STD="serde arbitrary"
99

1010
# Test these features without "std" enabled.
11-
FEATURES_WITHOUT_STD="alloc ordered serde arbitrary"
11+
FEATURES_WITHOUT_STD="alloc serde arbitrary"
1212

1313
# Run these examples.
1414
EXAMPLES=""

primitives/src/locktime/absolute.rs

Lines changed: 4 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
//! There are two types of lock time: lock-by-blockheight and lock-by-blocktime, distinguished by
66
//! whether `LockTime < LOCKTIME_THRESHOLD`.
77
8-
use core::cmp::Ordering;
98
use core::fmt;
109

1110
#[cfg(feature = "arbitrary")]
@@ -28,11 +27,12 @@ pub use units::locktime::absolute::{ConversionError, Height, ParseHeightError, P
2827
/// ### Note on ordering
2928
///
3029
/// Locktimes may be height- or time-based, and these metrics are incommensurate; there is no total
31-
/// ordering on locktimes. We therefore have implemented [`PartialOrd`] but not [`Ord`].
30+
/// ordering on locktimes. In order to compare locktimes, instead of using `<` or `>` we provide the
31+
/// [`LockTime::is_satisfied_by`] API.
32+
///
3233
/// For [`Transaction`], which has a locktime field, we implement a total ordering to make
3334
/// it easy to store transactions in sorted data structures, and use the locktime's 32-bit integer
34-
/// consensus encoding to order it. We also implement [`ordered::ArbitraryOrd`] if the "ordered"
35-
/// feature is enabled.
35+
/// consensus encoding to order it.
3636
///
3737
/// ### Relevant BIPs
3838
///
@@ -319,19 +319,6 @@ impl From<Time> for LockTime {
319319
fn from(t: Time) -> Self { LockTime::Seconds(t) }
320320
}
321321

322-
impl PartialOrd for LockTime {
323-
#[inline]
324-
fn partial_cmp(&self, other: &LockTime) -> Option<Ordering> {
325-
use LockTime::*;
326-
327-
match (*self, *other) {
328-
(Blocks(ref a), Blocks(ref b)) => a.partial_cmp(b),
329-
(Seconds(ref a), Seconds(ref b)) => a.partial_cmp(b),
330-
(_, _) => None,
331-
}
332-
}
333-
}
334-
335322
impl fmt::Debug for LockTime {
336323
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
337324
use LockTime::*;
@@ -400,20 +387,6 @@ impl<'de> serde::Deserialize<'de> for LockTime {
400387
}
401388
}
402389

403-
#[cfg(feature = "ordered")]
404-
impl ordered::ArbitraryOrd for LockTime {
405-
fn arbitrary_cmp(&self, other: &Self) -> Ordering {
406-
use LockTime::*;
407-
408-
match (self, other) {
409-
(Blocks(_), Seconds(_)) => Ordering::Less,
410-
(Seconds(_), Blocks(_)) => Ordering::Greater,
411-
(Blocks(this), Blocks(that)) => this.cmp(that),
412-
(Seconds(this), Seconds(that)) => this.cmp(that),
413-
}
414-
}
415-
}
416-
417390
#[cfg(feature = "arbitrary")]
418391
impl<'a> Arbitrary<'a> for LockTime {
419392
fn arbitrary(u: &mut Unstructured<'a>) -> arbitrary::Result<Self> {
@@ -501,9 +474,6 @@ mod tests {
501474
assert!(lock_by_height.is_satisfied_by(height_same, time));
502475
assert!(lock_by_height.is_satisfied_by(height_above, time));
503476
assert!(!lock_by_height.is_satisfied_by(height_below, time));
504-
505-
let lock_by_height_above = LockTime::from_consensus(800_000);
506-
assert!(lock_by_height < lock_by_height_above)
507477
}
508478

509479
#[test]
@@ -519,9 +489,6 @@ mod tests {
519489
assert!(lock_by_time.is_satisfied_by(height, time_same));
520490
assert!(lock_by_time.is_satisfied_by(height, time_after));
521491
assert!(!lock_by_time.is_satisfied_by(height, time_before));
522-
523-
let lock_by_time_after = LockTime::from_consensus(1653282000);
524-
assert!(lock_by_time < lock_by_time_after);
525492
}
526493

527494
#[test]

primitives/src/locktime/relative.rs

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
//! There are two types of lock time: lock-by-blockheight and lock-by-blocktime, distinguished by
66
//! whether bit 22 of the `u32` consensus value is set.
77
8-
#[cfg(feature = "ordered")]
9-
use core::cmp::Ordering;
10-
use core::{cmp, convert, fmt};
8+
use core::{convert, fmt};
119

1210
use crate::Sequence;
1311
#[cfg(all(doc, feature = "alloc"))]
@@ -25,8 +23,8 @@ pub use units::locktime::relative::{Height, Time, TimeOverflowError};
2523
/// ### Note on ordering
2624
///
2725
/// Locktimes may be height- or time-based, and these metrics are incommensurate; there is no total
28-
/// ordering on locktimes. We therefore have implemented [`PartialOrd`] but not [`Ord`]. We also
29-
/// implement [`ordered::ArbitraryOrd`] if the "ordered" feature is enabled.
26+
/// ordering on locktimes. In order to compare locktimes, instead of using `<` or `>` we provide the
27+
/// [`LockTime::is_satisfied_by`] API.
3028
///
3129
/// ### Relevant BIPs
3230
///
@@ -352,19 +350,6 @@ impl From<Time> for LockTime {
352350
fn from(t: Time) -> Self { LockTime::Time(t) }
353351
}
354352

355-
impl PartialOrd for LockTime {
356-
#[inline]
357-
fn partial_cmp(&self, other: &LockTime) -> Option<cmp::Ordering> {
358-
use LockTime::*;
359-
360-
match (*self, *other) {
361-
(Blocks(ref a), Blocks(ref b)) => a.partial_cmp(b),
362-
(Time(ref a), Time(ref b)) => a.partial_cmp(b),
363-
(_, _) => None,
364-
}
365-
}
366-
}
367-
368353
impl fmt::Display for LockTime {
369354
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
370355
use LockTime::*;
@@ -383,20 +368,6 @@ impl fmt::Display for LockTime {
383368
}
384369
}
385370

386-
#[cfg(feature = "ordered")]
387-
impl ordered::ArbitraryOrd for LockTime {
388-
fn arbitrary_cmp(&self, other: &Self) -> Ordering {
389-
use LockTime::*;
390-
391-
match (self, other) {
392-
(Blocks(_), Time(_)) => Ordering::Less,
393-
(Time(_), Blocks(_)) => Ordering::Greater,
394-
(Blocks(this), Blocks(that)) => this.cmp(that),
395-
(Time(this), Time(that)) => this.cmp(that),
396-
}
397-
}
398-
}
399-
400371
impl convert::TryFrom<Sequence> for LockTime {
401372
type Error = DisabledLockTimeError;
402373
fn try_from(seq: Sequence) -> Result<LockTime, DisabledLockTimeError> {
@@ -501,9 +472,6 @@ mod tests {
501472
assert!(!lock_by_height1.is_same_unit(lock_by_time1));
502473
assert!(lock_by_time1.is_same_unit(lock_by_time2));
503474
assert!(!lock_by_time1.is_same_unit(lock_by_height1));
504-
505-
assert!(lock_by_height1 < lock_by_height2);
506-
assert!(lock_by_time1 < lock_by_time2);
507475
}
508476

509477
#[test]

0 commit comments

Comments
 (0)