Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
162 commits
Select commit Hold shift + click to select a range
9b92e7c
Add constructors
d0cd Mar 15, 2025
de65282
Add program checksum and edition to stack
d0cd Mar 15, 2025
341078d
Adjust operand
d0cd Mar 15, 2025
0f19c3a
Load operand
d0cd Mar 15, 2025
5906dfe
Set edition to default
d0cd Mar 15, 2025
8f97617
Implement constructors, add basic tests
d0cd Mar 18, 2025
0710e19
Fix and add test
d0cd Mar 18, 2025
091f43f
Fix expectation
d0cd Mar 18, 2025
b28c317
Fix comment
d0cd Mar 18, 2025
9f2e8e0
Cleanup
d0cd Mar 19, 2025
1277470
Feedback
d0cd Mar 20, 2025
d032476
Update good_constructor test, allow other FinalizeOperations
d0cd Mar 20, 2025
2ca3f04
Fine-grained pricing for constructors
d0cd Mar 20, 2025
6d284b4
Support updatability
d0cd Mar 19, 2025
ac8545c
Update deployment store
d0cd Mar 19, 2025
30db805
Fix deployment (de)serialization
d0cd Mar 19, 2025
434a3f8
Add benches and add migration TODOs
d0cd Mar 19, 2025
90f2621
Cleanup
d0cd Mar 19, 2025
86810f5
Cleanup up Deployment
d0cd Mar 19, 2025
1a76586
Improve deployment store API
d0cd Mar 20, 2025
75d047a
Update transaction store API
d0cd Mar 20, 2025
3b02904
Enable program checksums in the deployment
d0cd Mar 20, 2025
5112657
Improve comments, add checksum map
d0cd Mar 20, 2025
de65776
Implement migrations
d0cd Mar 20, 2025
69f2583
Fix test
d0cd Mar 20, 2025
7b36570
Cleanup comments
d0cd Mar 20, 2025
e2c4f75
Feedback
d0cd Mar 20, 2025
5da640e
Feedback
d0cd Mar 20, 2025
9646b02
Feedback
d0cd Mar 20, 2025
60784ef
Feedback
d0cd Mar 20, 2025
b2dcf99
Feedback
d0cd Mar 20, 2025
8179ffb
Feedback
d0cd Mar 20, 2025
2f35cf9
Feedback
d0cd Mar 20, 2025
ede2b81
Feedback
d0cd Mar 20, 2025
f4aa8a2
Merge branch 'feat/constructors-and-operands' into review/constructor…
d0cd Mar 21, 2025
542adb7
Merge pull request #2658 from ProvableHQ/review/constructors-and-oper…
d0cd Mar 21, 2025
cb1ea9f
Feedback
d0cd Mar 21, 2025
83b319e
Feedback
d0cd Mar 21, 2025
2eb82ba
Merge branch 'feat/constructors-and-operands' into feat/program-updat…
d0cd Mar 21, 2025
462920d
Feedback
d0cd Mar 21, 2025
7ff9b13
Feedback
d0cd Mar 21, 2025
ca5c330
Feedback
d0cd Mar 21, 2025
33a3c8a
Feedback
d0cd Mar 21, 2025
72b4a9c
Fix get_edition_for_transaction
d0cd Mar 27, 2025
56f27ad
Feedback
d0cd Mar 27, 2025
e0d0882
Remove edition and checksum as keywords
d0cd Mar 27, 2025
1d653af
Merge branch 'feat/constructors-and-operands' into feat/program-updat…
d0cd Mar 27, 2025
da28dc0
Merge pull request #2659 from ProvableHQ/migrate/program-updatability
d0cd Mar 27, 2025
b0abf1b
Fix
d0cd Mar 27, 2025
16e52e3
Update to non-empty constructors
d0cd Mar 27, 2025
3a6391e
Update test cases
d0cd Mar 27, 2025
efccdec
Rename to upgradability, add tests
d0cd Mar 28, 2025
50661f9
Fix test
d0cd Mar 28, 2025
0b42785
Fix CI
d0cd Mar 28, 2025
f0b119b
Cleanup
d0cd Mar 28, 2025
d1bdeec
Fix test
d0cd Mar 28, 2025
ae3efb4
Fix test and cleanup
d0cd Mar 28, 2025
8b3cacb
Update ledger tests to test both versions of deployments
d0cd Mar 28, 2025
8a884eb
Fix test
d0cd Mar 28, 2025
69790ec
Cleanup
d0cd Mar 28, 2025
fd173bc
Feedback
d0cd Mar 28, 2025
ae6eac1
Merge branch 'feat/constructors-and-operands' into feat/program-updat…
d0cd Mar 28, 2025
02cfd23
Rename Deployment::len to Deployment::num_functions
howardwu Mar 28, 2025
ea65a1c
Reorder tree declarations in order of hierarchy
howardwu Mar 28, 2025
26d03d9
Clippy
d0cd Mar 28, 2025
cb61dcc
Reorder tree methods in order of hierarchy
howardwu Mar 28, 2025
9b333ed
Merge branch 'feat/program-updatability' of https://github.com/Provab…
howardwu Mar 28, 2025
3378104
Removes fee_index from Transaction::transaction_tree
howardwu Mar 28, 2025
4d9cee1
Improve the note for better context
howardwu Mar 28, 2025
04d13cd
Feedback
d0cd Mar 28, 2025
266fbff
Merge branch 'feat/program-updatability' of https://github.com/Provab…
howardwu Mar 28, 2025
0236435
Remove PartialEq and Eq on Map traits
howardwu Mar 28, 2025
b624f38
Feedback
d0cd Mar 28, 2025
018076a
Feedback, redefine program checksums
d0cd Mar 29, 2025
08cdc22
Feedback
d0cd Mar 29, 2025
207f891
Fix tests
d0cd Mar 29, 2025
cacd25a
Restrict to one upgrade/deployment per block
d0cd Apr 1, 2025
2eea916
Merge pull request #2669 from ProvableHQ/remove/eq-on-maps
vicsn Apr 8, 2025
b97c783
Feedback
d0cd Apr 8, 2025
005cd60
Fix
d0cd Apr 8, 2025
4fadf23
Add to find/get API
d0cd Apr 8, 2025
0e274f1
Refactor based on feedback
d0cd Apr 8, 2025
c618b26
Further restrict new syntax before migration
d0cd Apr 10, 2025
be0a27c
Fix
d0cd Apr 10, 2025
3e0b08c
Removed constructor from reserved keywords
d0cd Apr 15, 2025
a225903
Add zero check for edition
d0cd Apr 17, 2025
01e228e
Merge branch 'staging' into feat/constructors-and-operands
d0cd Apr 18, 2025
05f30a5
Add additional fee_index check
howardwu Apr 18, 2025
493f29f
Resolve merge conflict
howardwu Apr 18, 2025
bfa667f
Adds extra deployment size checks
howardwu Apr 18, 2025
13afd8e
Update ledger/block/src/transaction/merkle.rs
vicsn Apr 21, 2025
d33c5ef
Feedback
d0cd Apr 23, 2025
bcaf360
Merge pull request #2668 from ProvableHQ/feat/improve-tree-logic
vicsn Apr 29, 2025
d4280d0
Require program owner after V5
d0cd May 18, 2025
2553d12
Add owner as operand
d0cd May 18, 2025
10369dc
Get read lock on process during transaction verification
d0cd May 21, 2025
c0e1632
Update conversation
d0cd May 21, 2025
1635858
Implement check
d0cd Apr 17, 2025
0570b29
Add better error reporting
d0cd Apr 17, 2025
7f9fc31
Move check to should_abort_transaction
d0cd Apr 21, 2025
cbfbe18
Add tests
d0cd Apr 21, 2025
2a685c2
Cleanup
d0cd May 21, 2025
c4e8c3b
Merge branch 'staging' into feat/constructors-and-operands
d0cd May 26, 2025
57b6790
Merge branch 'feat/constructors-and-operands' into feat/program-updat…
d0cd May 27, 2025
24b8453
Bump to V8
d0cd May 27, 2025
0fc9566
Fix tests
d0cd May 27, 2025
49d3cc0
Merge branch 'feat/program-updatability' into feat/program-owner-operand
d0cd May 27, 2025
10de4c5
Merge branch 'feat/program-owner-operand' into feat/reject-old-execs-…
d0cd May 27, 2025
aa2a0e5
Feedback
d0cd May 27, 2025
962d5fd
Fix test
d0cd May 27, 2025
3647869
Clean up constructor initializers
d0cd Jun 9, 2025
fd511fb
Improve code quality
d0cd Jun 9, 2025
5d0defb
Add edition to deployment_tree_v2
d0cd Jun 9, 2025
b114224
Preserve intra-block ordering
d0cd Jun 9, 2025
da73480
Remove checksum and edition from circuits
d0cd Jun 11, 2025
9e996c3
Stage, commit, and rollback stacks
d0cd Jun 11, 2025
8d7c63f
Fix tests
d0cd Jun 12, 2025
efccb36
Seed with default transition ID
d0cd Jun 13, 2025
8511f53
Sign function call graph when program upgrades are supported
vicsn Jun 9, 2025
fb9de10
Update deployment_tree_v2
d0cd Jun 13, 2025
8c11cd8
Remove check for freshness of state roots
d0cd Jun 13, 2025
a015246
Fix test
d0cd Jun 13, 2025
64a610f
Use program checksum as transaction cache key
d0cd Jun 17, 2025
a4573a3
Address feedback
d0cd Jun 19, 2025
e50ab36
Audit fixes
d0cd Jun 25, 2025
8f1df81
QOL improvements for managing consensus heights
d0cd Jun 25, 2025
9c350c2
Adjust lock acquisiting during verification
d0cd Jun 25, 2025
f1c516b
Remove broken test
d0cd Jun 25, 2025
b3cd7b2
Use defer macro
d0cd Jun 25, 2025
b8c1b12
Add ConsensusVersion::latest
d0cd Jun 26, 2025
df49038
Fmt
d0cd Jun 26, 2025
a3a387d
Merge branch 'staging' into refresh/upgradability-after-record-migration
d0cd Jul 12, 2025
e097d5d
Shift upgradability to consensus version V9
d0cd Jul 14, 2025
46b5ef3
Merge branch 'staging' into refresh/upgradability-after-record-migration
d0cd Jul 14, 2025
58d51a5
Fix
d0cd Jul 15, 2025
d1ac0ed
Merge branch 'staging' into refresh/upgradability-after-record-migration
d0cd Jul 15, 2025
6dc7824
Fix
d0cd Jul 15, 2025
2cbc8c5
Fix
d0cd Jul 16, 2025
b341eef
Fix
d0cd Jul 17, 2025
7a62ee8
Fix
d0cd Jul 17, 2025
4b8c879
Fix
d0cd Jul 19, 2025
9013262
Merge branch 'staging' into refresh/upgradability-after-record-migration
d0cd Jul 20, 2025
4e25aa1
Fix
d0cd Jul 20, 2025
05d92c0
Support deferred initialization of programs in the process
d0cd Jul 20, 2025
47b5d90
Fix CI config
d0cd Jul 20, 2025
164a057
More CI fixes
d0cd Jul 21, 2025
4e2d76a
Fix default manifest and process init
d0cd Jul 21, 2025
a070c69
Address feedback
d0cd Jul 21, 2025
b0bed87
Cleanup during review
d0cd Jul 22, 2025
a9b9c04
Address feedback
d0cd Jul 22, 2025
dc8fa0c
Fix
d0cd Jul 22, 2025
7dbc0c5
Fix CI config
d0cd Jul 22, 2025
86c108e
Merge branch 'staging' into refresh/upgradability-after-record-migration
d0cd Jul 22, 2025
51e79a3
Address feedback
d0cd Jul 23, 2025
05c72d3
Address feedback
d0cd Jul 23, 2025
b90e5ed
Abort executions that follow a deployment or redeployment in the same…
d0cd Jul 24, 2025
b7d23a5
Merge branch 'staging' into refresh/upgradability-after-record-migration
d0cd Jul 24, 2025
7db9a83
Merge branch 'staging' into refresh/upgradability-after-record-migration
d0cd Jul 24, 2025
2a7d8ca
cleanup
raychu86 Jul 24, 2025
2e84718
Add test and default to None on deployment
d0cd Jul 25, 2025
2ef66e4
Fix test
d0cd Jul 25, 2025
9f7a7f6
Merge branch 'staging' into refresh/upgradability-after-record-migration
d0cd Jul 25, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions circuit/program/src/data/plaintext/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,31 @@ impl<A: Aleo> From<&Literal<A>> for Plaintext<A> {
}
}

// A macro that derives implementations of `From` for arrays of a plaintext literals of various sizes.
macro_rules! impl_plaintext_from_array {
($element:ident, $($size:literal),+) => {
$(
impl<A: Aleo> From<[$element<A>; $size]> for Plaintext<A> {
fn from(value: [$element<A>; $size]) -> Self {
Self::Array(
value
.into_iter()
.map(|element| Plaintext::from(Literal::$element(element)))
.collect(),
OnceCell::new(),
)
}
}
)+
};
}

// Implement for `[U8<N>, SIZE]` for sizes 1 through 32.
impl_plaintext_from_array!(
U8, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
31, 32
);

#[cfg(test)]
mod tests {
use super::*;
Expand Down
28 changes: 21 additions & 7 deletions circuit/program/src/request/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ impl<A: Aleo> Request<A> {
/// and the signature is valid.
///
/// Verifies (challenge == challenge') && (address == address') && (serial_numbers == serial_numbers') where:
/// challenge' := HashToScalar(r * G, pk_sig, pr_sig, signer, \[tvk, tcm, function ID, input IDs\])
/// challenge' := HashToScalar(r * G, pk_sig, pr_sig, signer, \[tvk, tcm, function ID, is_root, program checksum?, input IDs\])
/// The program checksum must be provided if the program has a constructor and should not be provided otherwise.
pub fn verify(
&self,
input_types: &[console::ValueType<A::Network>],
tpk: &Group<A>,
root_tvk: Option<Field<A>>,
is_root: Boolean<A>,
program_checksum: Option<Field<A>>,
) -> Boolean<A> {
// Compute the function ID.
let function_id = compute_function_id(&self.network_id, &self.program_id, &self.function_name);
Expand All @@ -40,6 +42,10 @@ impl<A: Aleo> Request<A> {
message.push(self.tcm.clone());
message.push(function_id);
message.push(is_root);
// Add the program checksum to the signature message if it was provided.
if let Some(program_checksum) = program_checksum {
message.push(program_checksum);
}

// Check the input IDs and construct the rest of the signature message.
let (input_checks, append_to_message) = Self::check_input_ids::<true>(
Expand All @@ -61,6 +67,7 @@ impl<A: Aleo> Request<A> {
None => A::halt("Missing input elements in request verification"),
}

// Determine the root transition view key.
let root_tvk = root_tvk.unwrap_or(Field::<A>::new(Mode::Private, self.tvk.eject_value()));

// Verify the transition public key and commitments are well-formed.
Expand Down Expand Up @@ -324,6 +331,7 @@ mod tests {
num_public: u64,
num_private: u64,
num_constraints: u64,
set_program_checksum: bool,
) -> Result<()> {
let rng = &mut TestRng::default();

Expand Down Expand Up @@ -367,9 +375,10 @@ mod tests {

// Sample 'root_tvk'.
let root_tvk = None;

// Sample 'is_root'.
let is_root = true;
// Sample 'program_checksum'.
let program_checksum = set_program_checksum.then(|| console::Field::from_u64(i as u64));

// Compute the signed request.
let request = console::Request::sign(
Expand All @@ -380,18 +389,20 @@ mod tests {
&input_types,
root_tvk,
is_root,
program_checksum,
rng,
)?;
assert!(request.verify(&input_types, is_root));
assert!(request.verify(&input_types, is_root, program_checksum));

// Inject the request into a circuit.
let tpk = Group::<Circuit>::new(mode, request.to_tpk());
let request = Request::<Circuit>::new(mode, request);
let is_root = Boolean::new(mode, is_root);
let program_checksum = program_checksum.map(|hash| Field::<Circuit>::new(mode, hash));

Circuit::scope(format!("Request {i}"), || {
let root_tvk = None;
let candidate = request.verify(&input_types, &tpk, root_tvk, is_root);
let candidate = request.verify(&input_types, &tpk, root_tvk, is_root, program_checksum);
assert!(candidate.eject_value());
match mode.is_constant() {
true => assert_scope!(<=num_constants, <=num_public, <=num_private, <=num_constraints),
Expand Down Expand Up @@ -425,16 +436,19 @@ mod tests {
// Note: This is correct. At this (high) level of a program, we override the default mode in the `Record` case,
// based on the user-defined visibility in the record type. Thus, we have nonzero private and constraint values.
// These bounds are determined experimentally.
check_verify(Mode::Constant, 45000, 0, 22000, 22000)
check_verify(Mode::Constant, 43440, 0, 21629, 21656, false)?;
check_verify(Mode::Constant, 43440, 0, 21629, 21656, true)
}

#[test]
fn test_sign_and_verify_public() -> Result<()> {
check_verify(Mode::Public, 40938, 0, 30031, 30062)
check_verify(Mode::Public, 40938, 0, 30031, 30062, false)?;
check_verify(Mode::Public, 40938, 0, 30546, 30577, true)
}

#[test]
fn test_sign_and_verify_private() -> Result<()> {
check_verify(Mode::Private, 40938, 0, 30031, 30062)
check_verify(Mode::Private, 40938, 0, 30031, 30062, false)?;
check_verify(Mode::Private, 40938, 0, 30546, 30577, true)
}
}
22 changes: 21 additions & 1 deletion console/algorithms/benches/bhp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,30 @@ fn bhp1024(c: &mut Criterion) {
c.bench_function(&format!("BHP1024 Hash - input size {}", input.len()), |b| b.iter(|| hash.hash(&input)));
}

fn bhp1024_large(c: &mut Criterion) {
const SIZE_IN_BYTES: [usize; 4] =
[1_000 /* 1 kB */, 10_000 /* 10 kB */, 100_000 /* 100 kB */, 1_000_000 /* 1 MB */];
let rng = &mut TestRng::default();

// Benchmark the BHP1024 hash function for different input sizes.
for size in SIZE_IN_BYTES.iter() {
let input = (0..size * 8).map(|_| bool::rand(rng)).collect::<Vec<_>>();
c.bench_function(&format!("BHP1024 Hash - input size {size} bytes"), |b| {
b.iter(|| BHP1024::<Console>::setup("BHP1024").unwrap().hash(&input))
});
}
}

criterion_group! {
name = bhp;
config = Criterion::default().sample_size(1000);
targets = bhp256, bhp512, bhp768, bhp1024
}

criterion_main!(bhp);
criterion_group! {
name = bhp_large;
config = Criterion::default().sample_size(100);
targets = bhp1024_large
}

criterion_main!(bhp, bhp_large);
3 changes: 3 additions & 0 deletions console/network/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ workspace = true
[dependencies.anyhow]
workspace = true

[dependencies.enum-iterator]
version = "2.1"

[dependencies.indexmap]
workspace = true

Expand Down
14 changes: 2 additions & 12 deletions console/network/src/canary_v0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,6 @@ impl Network for CanaryV0 {
/// The transmission checksum type.
type TransmissionChecksum = u128;

/// The network edition.
const EDITION: u16 = 0;
/// The genesis block coinbase target.
#[cfg(not(feature = "test_targets"))]
const GENESIS_COINBASE_TARGET: u64 = (1u64 << 29).saturating_sub(1);
Expand Down Expand Up @@ -185,16 +183,8 @@ impl Network for CanaryV0 {
/// A list of (consensus_version, block_height) pairs indicating when each consensus version takes effect.
/// Documentation for what is changed at each version can be found in `ConsensusVersion`.
/// Do not read this directly outside of tests, use `N::CONSENSUS_VERSION_HEIGHTS()` instead.
const _CONSENSUS_VERSION_HEIGHTS: [(ConsensusVersion, u32); NUM_CONSENSUS_VERSIONS] = [
(ConsensusVersion::V1, 0),
(ConsensusVersion::V2, 2_900_000),
(ConsensusVersion::V3, 4_560_000),
(ConsensusVersion::V4, 5_730_000),
(ConsensusVersion::V5, 5_780_000),
(ConsensusVersion::V6, 6_240_000),
(ConsensusVersion::V7, 6_880_000),
(ConsensusVersion::V8, 7_565_000),
];
const _CONSENSUS_VERSION_HEIGHTS: [(ConsensusVersion, u32); NUM_CONSENSUS_VERSIONS] =
CANARY_V0_CONSENSUS_VERSION_HEIGHTS;

/// Returns the block height where the the inclusion proof will be updated.
#[allow(non_snake_case)]
Expand Down
113 changes: 113 additions & 0 deletions console/network/src/consensus_heights.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
// Copyright (c) 2019-2025 Provable Inc.
// This file is part of the snarkVM library.

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at:

// http://www.apache.org/licenses/LICENSE-2.0

// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use crate::ConsensusVersion;

/// The consensus version height for `CanaryV0`.
pub const CANARY_V0_CONSENSUS_VERSION_HEIGHTS: [(ConsensusVersion, u32); 9] = [
(ConsensusVersion::V1, 0),
(ConsensusVersion::V2, 2_900_000),
(ConsensusVersion::V3, 4_560_000),
(ConsensusVersion::V4, 5_730_000),
(ConsensusVersion::V5, 5_780_000),
(ConsensusVersion::V6, 6_240_000),
(ConsensusVersion::V7, 6_880_000),
(ConsensusVersion::V8, 7_565_000),
(ConsensusVersion::V9, 999_999_999),
];

/// The consensus version height for `MainnetV0`.
pub const MAINNET_V0_CONSENSUS_VERSION_HEIGHTS: [(ConsensusVersion, u32); 9] = [
(ConsensusVersion::V1, 0),
(ConsensusVersion::V2, 2_800_000),
(ConsensusVersion::V3, 4_900_000),
(ConsensusVersion::V4, 6_135_000),
(ConsensusVersion::V5, 7_060_000),
(ConsensusVersion::V6, 7_560_000),
(ConsensusVersion::V7, 7_570_000),
(ConsensusVersion::V8, 9_430_000),
(ConsensusVersion::V9, 999_999_999),
];

/// The consensus version heights for `TestnetV0`.
pub const TESTNET_V0_CONSENSUS_VERSION_HEIGHTS: [(ConsensusVersion, u32); 9] = [
(ConsensusVersion::V1, 0),
(ConsensusVersion::V2, 2_950_000),
(ConsensusVersion::V3, 4_800_000),
(ConsensusVersion::V4, 6_625_000),
(ConsensusVersion::V5, 6_765_000),
(ConsensusVersion::V6, 7_600_000),
(ConsensusVersion::V7, 8_365_000),
(ConsensusVersion::V8, 9_173_000),
(ConsensusVersion::V9, 999_999_999),
];

/// The consensus version heights when the `test_consensus_heights` feature is enabled.
pub const TEST_CONSENSUS_VERSION_HEIGHTS: [(ConsensusVersion, u32); 9] = [
(ConsensusVersion::V1, 0),
(ConsensusVersion::V2, 10),
(ConsensusVersion::V3, 11),
(ConsensusVersion::V4, 12),
(ConsensusVersion::V5, 13),
(ConsensusVersion::V6, 14),
(ConsensusVersion::V7, 15),
(ConsensusVersion::V8, 16),
(ConsensusVersion::V9, 17),
];

#[cfg(any(test, feature = "test", feature = "test_consensus_heights"))]
pub(crate) fn load_test_consensus_heights<N: crate::Network>()
-> [(ConsensusVersion, u32); crate::NUM_CONSENSUS_VERSIONS] {
// Define a closure to verify the consensus heights.
let verify_consensus_heights = |heights: &[(ConsensusVersion, u32); crate::NUM_CONSENSUS_VERSIONS]| {
// Assert that the genesis height is 0.
assert_eq!(heights[0].1, 0, "Genesis height must be 0.");
// Assert that the consensus heights are strictly increasing.
for window in heights.windows(2) {
if window[0] >= window[1] {
panic!("Heights must be strictly increasing, but found: {window:?}");
}
}
};

// Define consensus version heights container used for testing.
let mut test_consensus_heights = N::TEST_CONSENSUS_VERSION_HEIGHTS;

// Check if we can read the heights from an environment variable.
match std::env::var("CONSENSUS_VERSION_HEIGHTS") {
Ok(height_string) => {
// Parse the heights from the environment variable.
let parsed_test_consensus_heights: [u32; crate::NUM_CONSENSUS_VERSIONS] = height_string
.replace(" ", "")
.split(",")
.map(|height| height.parse::<u32>().unwrap())
.collect::<Vec<u32>>()
.try_into()
.unwrap();
// Set the parsed heights in the test consensus heights.
for (i, height) in parsed_test_consensus_heights.into_iter().enumerate() {
test_consensus_heights[i] = (N::TEST_CONSENSUS_VERSION_HEIGHTS[i].0, height);
}
// Verify and return the parsed test consensus heights.
verify_consensus_heights(&test_consensus_heights);
test_consensus_heights
}
Err(_) => {
// Verify and return the default test consensus heights.
verify_consensus_heights(&test_consensus_heights);
test_consensus_heights
}
}
}
Loading