Skip to content

Commit ec77a91

Browse files
authored
Merge branch 'main' into p2p-request-handler
2 parents f158f86 + a003e05 commit ec77a91

File tree

30 files changed

+276
-61
lines changed

30 files changed

+276
-61
lines changed

.github/labeler.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ A-cryptonight:
5656
- changed-files:
5757
- any-glob-to-any-file: cryptonight/**
5858

59+
A-constants:
60+
- changed-files:
61+
- any-glob-to-any-file: constants/**
62+
5963
A-storage:
6064
- changed-files:
6165
- any-glob-to-any-file: storage/**

Cargo.lock

Lines changed: 10 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ resolver = "2"
33

44
members = [
55
"binaries/cuprated",
6+
"constants",
67
"consensus",
78
"consensus/fast-sync",
89
"consensus/rules",

books/architecture/src/appendix/crates.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ cargo doc --open --package cuprate-blockchain
5555
## 1-off crates
5656
| Crate | In-tree path | Purpose |
5757
|-------|--------------|---------|
58+
| [`cuprate-constants`](https://doc.cuprate.org/cuprate_constants) | [`constants/`](https://github.com/Cuprate/cuprate/tree/main/constants) | Shared `const/static` data across Cuprate
5859
| [`cuprate-cryptonight`](https://doc.cuprate.org/cuprate_cryptonight) | [`cryptonight/`](https://github.com/Cuprate/cuprate/tree/main/cryptonight) | CryptoNight hash functions
5960
| [`cuprate-pruning`](https://doc.cuprate.org/cuprate_pruning) | [`pruning/`](https://github.com/Cuprate/cuprate/tree/main/pruning) | Monero pruning logic/types
6061
| [`cuprate-helper`](https://doc.cuprate.org/cuprate_helper) | [`helper/`](https://github.com/Cuprate/cuprate/tree/main/helper) | Kitchen-sink helper crate for Cuprate

consensus/rules/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ proptest = ["cuprate-types/proptest"]
1111
rayon = ["dep:rayon"]
1212

1313
[dependencies]
14+
cuprate-constants = { path = "../../constants", default-features = false }
1415
cuprate-helper = { path = "../../helper", default-features = false, features = ["std", "cast"] }
1516
cuprate-types = { path = "../../types", default-features = false }
1617
cuprate-cryptonight = {path = "../../cryptonight"}

consensus/rules/src/miner_tx.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use monero_serai::transaction::{Input, Output, Timelock, Transaction};
22

3+
use cuprate_constants::block::MAX_BLOCK_HEIGHT_USIZE;
34
use cuprate_types::TxVersion;
45

56
use crate::{is_decomposed_amount, transactions::check_output_types, HardFork};
@@ -112,7 +113,7 @@ const fn check_time_lock(time_lock: &Timelock, chain_height: usize) -> Result<()
112113
&Timelock::Block(till_height) => {
113114
// Lock times above this amount are timestamps not blocks.
114115
// This is just for safety though and shouldn't actually be hit.
115-
if till_height > 500_000_000 {
116+
if till_height > MAX_BLOCK_HEIGHT_USIZE {
116117
return Err(MinerTxError::InvalidLockTime);
117118
}
118119
if till_height == chain_height + MINER_TX_TIME_LOCKED_BLOCKS {

consensus/rules/src/transactions/tests.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use proptest::{collection::vec, prelude::*};
99

1010
use monero_serai::transaction::Output;
1111

12+
use cuprate_constants::block::MAX_BLOCK_HEIGHT;
1213
use cuprate_helper::cast::u64_to_usize;
1314

1415
use super::*;
@@ -160,10 +161,10 @@ prop_compose! {
160161
/// Returns a [`Timelock`] that is locked given a height and time.
161162
fn locked_timelock(height: u64, time_for_time_lock: u64)(
162163
timebased in any::<bool>(),
163-
lock_height in (height+1)..500_000_001,
164+
lock_height in (height+1)..=MAX_BLOCK_HEIGHT,
164165
time_for_time_lock in (time_for_time_lock+121)..,
165166
) -> Timelock {
166-
if timebased || lock_height > 500_000_000 {
167+
if timebased || lock_height > MAX_BLOCK_HEIGHT {
167168
Timelock::Time(time_for_time_lock)
168169
} else {
169170
Timelock::Block(u64_to_usize(lock_height))
@@ -240,7 +241,7 @@ proptest! {
240241
}
241242

242243
#[test]
243-
fn test_timestamp_time_lock(timestamp in 500_000_001..u64::MAX) {
244+
fn test_timestamp_time_lock(timestamp in MAX_BLOCK_HEIGHT+1..u64::MAX) {
244245
prop_assert!(check_timestamp_time_lock(timestamp, timestamp - 120, HardFork::V16));
245246
prop_assert!(!check_timestamp_time_lock(timestamp, timestamp - 121, HardFork::V16));
246247
prop_assert!(check_timestamp_time_lock(timestamp, timestamp, HardFork::V16));

constants/Cargo.toml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
[package]
2+
name = "cuprate-constants"
3+
version = "0.1.0"
4+
edition = "2021"
5+
description = "Constant/static data used throughout Cuprate"
6+
license = "MIT"
7+
authors = ["hinto-janai"]
8+
repository = "https://github.com/Cuprate/cuprate/tree/main/constants"
9+
keywords = ["cuprate", "constants"]
10+
11+
[features]
12+
default = []
13+
block = []
14+
build = []
15+
rpc = []
16+
17+
[dependencies]
18+
19+
[dev-dependencies]
20+
21+
[lints]
22+
workspace = true

constants/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# cuprate-constants
2+
This crate contains general constants that are not specific to any particular
3+
part of the codebase yet are used in multiple places such as the maximum block height.

helper/build.rs renamed to constants/build.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
fn main() {
2-
#[cfg(feature = "constants")]
32
set_commit_env();
43
}
54

6-
#[cfg(feature = "constants")]
75
/// This sets the git `COMMIT` environment variable.
86
fn set_commit_env() {
97
const PATH: &str = "../.git/refs/heads/";

0 commit comments

Comments
 (0)