Skip to content

Commit 6a2b98b

Browse files
authored
Merge pull request #3194 from ProvableHQ/feat/update-anchor-time
Decrease sensitivity of retargeting algorithm
2 parents e190a25 + 2af9460 commit 6a2b98b

6 files changed

Lines changed: 301 additions & 48 deletions

File tree

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -872,7 +872,7 @@ jobs:
872872
steps:
873873
- run_test:
874874
workspace_member: snarkvm-parameters
875-
flags: --run-ignored ignored-only -- --test-threads=2
875+
flags: --run-ignored ignored-only -- --test-threads=2
876876
use_cache: false
877877
cache_key_suffix: -v-{{ epoch }}
878878
no_output_timeout: 20m

console/network/src/consensus_heights.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ pub enum ConsensusVersion {
5555
/// and dynamic dispatch, and identifier literal types.
5656
V14 = 14,
5757
/// V15: Introduces the record-existence check and `commit.*.raw` instruction variants.
58+
/// Increase the anchor time to 35.
5859
V15 = 15,
5960
}
6061

@@ -347,6 +348,11 @@ mod tests {
347348
assert!(*version > previous_version);
348349
previous_version = *version;
349350
}
351+
let mut previous_version = N::ANCHOR_TIMES.first().unwrap().0;
352+
for (version, _) in N::ANCHOR_TIMES.iter().skip(1) {
353+
assert!(*version > previous_version);
354+
previous_version = *version;
355+
}
350356
}
351357

352358
/// Ensure that consensus *heights* are unique and incrementing.
@@ -400,6 +406,10 @@ mod tests {
400406
// Double-check that consensus_config_value returns the correct value.
401407
assert_eq!(consensus_config_value!(N, MAX_WRITES, height).unwrap(), *value);
402408
}
409+
for (version, value) in N::ANCHOR_TIMES.iter() {
410+
let height = N::CONSENSUS_VERSION_HEIGHTS().iter().find(|(c_version, _)| c_version == version).unwrap().1;
411+
assert_eq!(consensus_config_value!(N, ANCHOR_TIMES, height).unwrap(), *value);
412+
}
403413
}
404414

405415
/// Ensure that consensus_config_value returns a valid value for all consensus versions.
@@ -411,6 +421,7 @@ mod tests {
411421
assert!(consensus_config_value!(N, MAX_PROGRAM_SIZE, *height).is_some());
412422
assert!(consensus_config_value!(N, MAX_TRANSACTION_SIZE, *height).is_some());
413423
assert!(consensus_config_value!(N, MAX_WRITES, *height).is_some());
424+
assert!(consensus_config_value!(N, ANCHOR_TIMES, *height).is_some());
414425
}
415426
}
416427

@@ -460,6 +471,7 @@ mod tests {
460471
let _ = [N1::MAX_PROGRAM_SIZE, N2::MAX_PROGRAM_SIZE, N3::MAX_PROGRAM_SIZE];
461472
let _ = [N1::MAX_TRANSACTION_SIZE, N2::MAX_TRANSACTION_SIZE, N3::MAX_TRANSACTION_SIZE];
462473
let _ = [N1::MAX_WRITES, N2::MAX_WRITES, N3::MAX_WRITES];
474+
let _ = [N1::ANCHOR_TIMES, N2::ANCHOR_TIMES, N3::ANCHOR_TIMES];
463475
}
464476

465477
/// Ensure that `LATEST_MAX_*` functions return valid values without panicking.
@@ -534,4 +546,11 @@ mod tests {
534546
let result = ConsensusVersion::from_bytes_le(&invalid_bytes);
535547
assert!(result.is_err());
536548
}
549+
550+
#[test]
551+
fn test_reward_anchor_time() {
552+
assert_eq!(MainnetV0::REWARD_ANCHOR_TIME, MainnetV0::ANCHOR_TIMES.first().unwrap().1);
553+
assert_eq!(TestnetV0::REWARD_ANCHOR_TIME, TestnetV0::ANCHOR_TIMES.first().unwrap().1);
554+
assert_eq!(CanaryV0::REWARD_ANCHOR_TIME, CanaryV0::ANCHOR_TIMES.first().unwrap().1);
555+
}
537556
}

console/network/src/lib.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,17 @@ pub trait Network:
165165
const ARC_0005_COMPUTE_DISCOUNT: u64 = 25;
166166

167167
/// The anchor height, defined as the expected number of blocks to reach the coinbase target.
168-
const ANCHOR_HEIGHT: u32 = Self::ANCHOR_TIME as u32 / Self::BLOCK_TIME as u32;
169-
/// The anchor time in seconds.
170-
const ANCHOR_TIME: u16 = 25;
168+
/// Note: The anchor height used exclusively by `coinbase_reward_v1`.
169+
const ANCHOR_HEIGHT: u32 = Self::REWARD_ANCHOR_TIME as u32 / Self::BLOCK_TIME as u32;
170+
/// The anchor time used specifically for calculating the coinbase reward.
171+
/// We ensure that the reward anchor time matches the original ConsensusVersion::V1 anchor time
172+
/// to maintain the original coinbase reward schedule.
173+
const REWARD_ANCHOR_TIME: u16 = 25;
174+
/// A list of (consensus_version, anchor_time_in_seconds) pairs (sparse).
175+
/// Each entry takes effect at the specified version and remains active until the next entry.
176+
/// The anchor time, defined as the expected time in seconds to reach the coinbase target.
177+
const ANCHOR_TIMES: [(ConsensusVersion, u16); 2] =
178+
[(ConsensusVersion::V1, Self::REWARD_ANCHOR_TIME), (ConsensusVersion::V15, 35)];
171179
/// The expected time per block in seconds.
172180
const BLOCK_TIME: u16 = 10;
173181
/// The number of blocks per epoch.

0 commit comments

Comments
 (0)