Skip to content

Commit

Permalink
Merge pull request #1928 from radixdlt/feature/lower-min-rounds-per-e…
Browse files Browse the repository at this point in the history
…poch

Change the min rounds per epoch
  • Loading branch information
0xOmarA committed Sep 27, 2024
2 parents 08e006d + 9857c93 commit 0b92ab2
Show file tree
Hide file tree
Showing 15 changed files with 273 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,23 @@ pub struct ConsensusManagerConfig {
}

impl ConsensusManagerConfig {
pub fn mainnet_genesis() -> Self {
Self {
max_validators: 100,
epoch_change_condition: EpochChangeCondition {
min_round_count: 500,
max_round_count: 3000,
target_duration_millis: 300000,
},
num_unstake_epochs: 2016,
total_emission_xrd_per_epoch: dec!("2853.881278538812785388"),
min_validator_reliability: Decimal::one(),
num_owner_stake_units_unlock_epochs: 8064,
num_fee_increase_delay_epochs: 4032,
validator_creation_usd_cost: dec!(1000),
}
}

pub fn test_default() -> Self {
ConsensusManagerConfig {
max_validators: 10,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"kind": "CommitSuccess",
"state_updates_summary": {
"new_entities": [
"account_sim1cxfcgpnu3kcax77255p6mfcnsrmnyqe7vsghqxm397r9fg64nxzuja",
"account_sim1cxe8weyfw9efyag5qs50rq3f7h8g9qc08v72yxg6hck8ctmh2h4z5u"
],
"metadata_updates": {},
"non_fungible_data_updates": {},
"newly_minted_non_fungibles": []
},
"worktop_changes": {
"3": [
{
"kind": "Put",
"value": {
"kind": "Amount",
"resource_address": "resource_sim1tknxxxxxxxxxradxrdxxxxxxxxx009923554798xxxxxxxxxakj8n3",
"amount": "10000"
}
}
],
"4": [
{
"kind": "Take",
"value": {
"kind": "Amount",
"resource_address": "resource_sim1tknxxxxxxxxxradxrdxxxxxxxxx009923554798xxxxxxxxxakj8n3",
"amount": "10000"
}
}
]
},
"fee_summary": {
"execution_fees_in_xrd": "0.3370283",
"finalization_fees_in_xrd": "0.0812626",
"storage_fees_in_xrd": "0.24166106762",
"royalty_fees_in_xrd": "0"
},
"locked_fees": {
"contingent": "0",
"non_contingent": "5000"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"kind": "CommitSuccess",
"state_updates_summary": {
"new_entities": [],
"metadata_updates": {},
"non_fungible_data_updates": {},
"newly_minted_non_fungibles": []
},
"worktop_changes": {},
"fee_summary": {
"execution_fees_in_xrd": "0.0838967",
"finalization_fees_in_xrd": "0.0052508",
"storage_fees_in_xrd": "0.05140304477",
"royalty_fees_in_xrd": "0"
},
"locked_fees": {
"contingent": "0",
"non_contingent": "5000"
}
}
33 changes: 33 additions & 0 deletions radix-engine-tests/tests/protocol/consensus_manager.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
use scrypto_test::prelude::*;

#[test]
fn consensus_manager_min_rounds_per_epoch_is_100_in_cuttlefish() {
// Arrange
let ledger = LedgerSimulatorBuilder::new()
.with_custom_protocol(|builder| {
builder
.configure_cuttlefish(|mut creator| {
creator.update_number_of_min_rounds_per_epoch =
UpdateSetting::Enabled(UpdateNumberOfMinRoundsPerEpochSettings::Set {
value: 100,
});
creator
})
.from_bootstrap_to(ProtocolVersion::Cuttlefish)
})
.build();
let database = ledger.substate_db();

// Act
let config = database
.get_existing_substate::<FieldSubstate<VersionedConsensusManagerConfiguration>>(
CONSENSUS_MANAGER,
MAIN_BASE_PARTITION,
ConsensusManagerField::Configuration,
)
.into_payload()
.fully_update_and_into_latest_version();

// Assert
assert_eq!(config.config.epoch_change_condition.min_round_count, 100);
}
1 change: 1 addition & 0 deletions radix-engine-tests/tests/protocol/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// We used to use automod, but it breaks various tools
// such as cargo fmt, so let's just list them explicitly.
mod always_visible_global_nodes;
mod consensus_manager;
mod cuttlefish_transaction_changes;
mod protocol_updates;
mod transaction;
16 changes: 15 additions & 1 deletion radix-engine/src/updates/babylon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,20 @@ impl BabylonSettings {
}
}

pub fn test_mainnet() -> Self {
let pub_key = Secp256k1PrivateKey::from_u64(1u64).unwrap().public_key();
let genesis_epoch = Epoch::of(1);
let consensus_manager_config = ConsensusManagerConfig::mainnet_genesis();
Self::single_validator_and_staker(
pub_key,
Decimal::one(),
Decimal::zero(),
ComponentAddress::preallocated_account_from_public_key(&pub_key),
genesis_epoch,
consensus_manager_config,
)
}

pub fn test_default() -> Self {
let pub_key = Secp256k1PrivateKey::from_u64(1u64).unwrap().public_key();
let genesis_epoch = Epoch::of(1);
Expand Down Expand Up @@ -167,7 +181,7 @@ impl BabylonSettings {
Self {
genesis_data_chunks,
genesis_epoch: Epoch::of(1),
consensus_manager_config: ConsensusManagerConfig::test_default(),
consensus_manager_config: ConsensusManagerConfig::mainnet_genesis(),
initial_time_ms: 1,
initial_current_leader: Some(0),
faucet_supply: Decimal::zero(),
Expand Down
72 changes: 71 additions & 1 deletion radix-engine/src/updates/cuttlefish.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use radix_transactions::validation::*;

use super::*;
use crate::{kernel::kernel::KernelBoot, system::system_callback::*};
use crate::blueprints::consensus_manager::*;
use crate::kernel::kernel::KernelBoot;
use crate::system::system_callback::*;

#[derive(Clone)]
pub struct CuttlefishSettings {
Expand All @@ -11,6 +13,9 @@ pub struct CuttlefishSettings {
pub kernel_version_update: UpdateSetting<NoSettings>,
/// Add transaction validation changes
pub transaction_validation_update: UpdateSetting<NoSettings>,
/// updates the min number of rounds per epoch.
pub update_number_of_min_rounds_per_epoch:
UpdateSetting<UpdateNumberOfMinRoundsPerEpochSettings>,
}

impl UpdateSettings for CuttlefishSettings {
Expand All @@ -25,6 +30,9 @@ impl UpdateSettings for CuttlefishSettings {
system_logic_update: UpdateSetting::enabled_as_default_for_network(network),
kernel_version_update: UpdateSetting::enabled_as_default_for_network(network),
transaction_validation_update: UpdateSetting::enabled_as_default_for_network(network),
update_number_of_min_rounds_per_epoch: UpdateSetting::enabled_as_default_for_network(
network,
),
}
}

Expand All @@ -33,6 +41,7 @@ impl UpdateSettings for CuttlefishSettings {
system_logic_update: UpdateSetting::Disabled,
kernel_version_update: UpdateSetting::Disabled,
transaction_validation_update: UpdateSetting::Disabled,
update_number_of_min_rounds_per_epoch: UpdateSetting::Disabled,
}
}

Expand All @@ -43,6 +52,23 @@ impl UpdateSettings for CuttlefishSettings {
}
}

#[derive(Clone, Copy, Debug)]
pub enum UpdateNumberOfMinRoundsPerEpochSettings {
Set { value: u64 },
SetIfEquals { if_equals: u64, to_value: u64 },
}

impl Default for UpdateNumberOfMinRoundsPerEpochSettings {
fn default() -> Self {
Self::SetIfEquals {
if_equals: 500,
to_value: 100,
}
}
}

impl UpdateSettingMarker for UpdateNumberOfMinRoundsPerEpochSettings {}

#[derive(Clone)]
pub struct CuttlefishBatchGenerator {
settings: CuttlefishSettings,
Expand Down Expand Up @@ -85,6 +111,7 @@ fn generate_principal_batch(
system_logic_update,
kernel_version_update: always_visible_global_nodes_update,
transaction_validation_update,
update_number_of_min_rounds_per_epoch,
}: &CuttlefishSettings,
) -> ProtocolUpdateBatch {
let mut transactions = vec![];
Expand All @@ -106,6 +133,12 @@ fn generate_principal_batch(
generate_cuttlefish_transaction_validation_updates(),
));
}
if let UpdateSetting::Enabled(settings) = &update_number_of_min_rounds_per_epoch {
transactions.push(ProtocolUpdateTransactionDetails::flash(
"cuttlefish-update-number-of-min-rounds-per-epoch",
generate_cuttlefish_update_min_rounds_per_epoch(store, *settings),
));
}
ProtocolUpdateBatch { transactions }
}

Expand Down Expand Up @@ -160,3 +193,40 @@ fn generate_cuttlefish_transaction_validation_updates() -> StateUpdates {
),
)
}

fn generate_cuttlefish_update_min_rounds_per_epoch<S: SubstateDatabase + ?Sized>(
db: &S,
settings: UpdateNumberOfMinRoundsPerEpochSettings,
) -> StateUpdates {
let mut consensus_manager_config = db
.get_existing_substate::<FieldSubstate<VersionedConsensusManagerConfiguration>>(
CONSENSUS_MANAGER,
MAIN_BASE_PARTITION,
ConsensusManagerField::Configuration,
)
.into_payload()
.fully_update_and_into_latest_version();
let min_rounds_per_epoch = &mut consensus_manager_config
.config
.epoch_change_condition
.min_round_count;

match settings {
UpdateNumberOfMinRoundsPerEpochSettings::Set { value } => *min_rounds_per_epoch = value,
UpdateNumberOfMinRoundsPerEpochSettings::SetIfEquals {
if_equals,
to_value,
} => {
if *min_rounds_per_epoch == if_equals {
*min_rounds_per_epoch = to_value
}
}
}

StateUpdates::empty().set_substate(
CONSENSUS_MANAGER,
MAIN_BASE_PARTITION,
ConsensusManagerField::Configuration,
consensus_manager_config.into_locked_substate(),
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ Name: Anemone

== SUMMARY HASHES ==
These Anemone hashes should NEVER change, else they will cause divergence when run historically.
State changes: 1eacf7c315d53aa6 (should never change)
State changes: 544976f80579365e (should never change)
Events : 2a6146032d8e884d (should never change)

Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@ STATE UPDATES: 1 entity
Value: LOCKED ConsensusManagerConfigurationFieldPayload::V1(
ConsensusManagerConfigSubstate {
config: ConsensusManagerConfig {
max_validators: 10u32,
max_validators: 100u32,
epoch_change_condition: EpochChangeCondition {
min_round_count: 1u64,
max_round_count: 1u64,
target_duration_millis: 0u64,
min_round_count: 500u64,
max_round_count: 3000u64,
target_duration_millis: 300000u64,
},
num_unstake_epochs: 1u64,
total_emission_xrd_per_epoch: Decimal("1"),
num_unstake_epochs: 2016u64,
total_emission_xrd_per_epoch: Decimal("2853.881278538812785388"),
min_validator_reliability: Decimal("1"),
num_owner_stake_units_unlock_epochs: 2u64,
num_fee_increase_delay_epochs: 1u64,
num_owner_stake_units_unlock_epochs: 8064u64,
num_fee_increase_delay_epochs: 4032u64,
validator_creation_usd_cost: Decimal("100"),
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11322,18 +11322,18 @@ CALL_FUNCTION
AddressReservation("reservation18")
1u64
Tuple(
10u32,
100u32,
Tuple(
1u64,
1u64,
0u64
500u64,
3000u64,
300000u64
),
1u64,
Decimal("1"),
2016u64,
Decimal("2853.881278538812785388"),
Decimal("1"),
2u64,
1u64,
Decimal("100")
8064u64,
4032u64,
Decimal("1000")
)
1i64
Enum<1u8>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ Name: Babylon

== SUMMARY HASHES ==
These Babylon hashes should NEVER change, else they will cause divergence when run historically.
State changes: 893a6b5a0f34d8bc (should never change)
State changes: d0442077ef9c4d22 (should never change)
Events : a9bb58d27fc1ad0f (should never change)

Original file line number Diff line number Diff line change
Expand Up @@ -107,18 +107,18 @@ STATE UPDATES: 34 entities
Value: LOCKED ConsensusManagerConfigurationFieldPayload::V1(
ConsensusManagerConfigSubstate {
config: ConsensusManagerConfig {
max_validators: 10u32,
max_validators: 100u32,
epoch_change_condition: EpochChangeCondition {
min_round_count: 1u64,
max_round_count: 1u64,
target_duration_millis: 0u64,
min_round_count: 500u64,
max_round_count: 3000u64,
target_duration_millis: 300000u64,
},
num_unstake_epochs: 1u64,
total_emission_xrd_per_epoch: Decimal("1"),
num_unstake_epochs: 2016u64,
total_emission_xrd_per_epoch: Decimal("2853.881278538812785388"),
min_validator_reliability: Decimal("1"),
num_owner_stake_units_unlock_epochs: 2u64,
num_fee_increase_delay_epochs: 1u64,
validator_creation_usd_cost: Decimal("100"),
num_owner_stake_units_unlock_epochs: 8064u64,
num_fee_increase_delay_epochs: 4032u64,
validator_creation_usd_cost: Decimal("1000"),
},
},
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ Name: Cuttlefish

== SUMMARY HASHES ==
These Cuttlefish hashes are permitted to change only until the protocol update is deployed to a permanent network, else it can cause divergence.
State changes: f24cdfa28ca60d91 (allowed to change if not deployed to any network)
Events : 07c81f1e6d320830 (allowed to change if not deployed to any network)
State changes: 3d1e256693bf6142 (allowed to change if not deployed to any network)
Events : 2a6146032d8e884d (allowed to change if not deployed to any network)

Loading

0 comments on commit 0b92ab2

Please sign in to comment.