Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ members = [ "application", "node", "rpc", "types", "finalizer", "orchestrator",
resolver = "3"

[workspace.package]
version = "0.0.1-alpha"
version = "0.0.2-alpha"
edition = "2024"

[workspace.dependencies]
Expand Down
1 change: 1 addition & 0 deletions example_genesis.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ validator_minimum_stake = 32000000000
validator_maximum_stake = 32000000000
blocks_per_epoch = 10000
allowed_timestamp_future_ms = 10000
max_deposits_per_epoch = 3

[[validators]]
node_public_key = "1be3cb06d7cc347602421fb73838534e4b54934e28959de98906d120d0799ef2"
Expand Down
6 changes: 5 additions & 1 deletion finalizer/src/actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1010,6 +1010,10 @@ impl<
let address = self.canonical_state.get_treasury_address();
let _ = sender.send(ConsensusStateResponse::TreasuryAddress(address));
}
ConsensusStateRequest::GetMaxDepositsPerEpoch => {
let value = self.canonical_state.get_max_deposits_per_epoch();
let _ = sender.send(ConsensusStateResponse::MaxDepositsPerEpoch(value));
}
ConsensusStateRequest::GetEpochBounds(epoch) => {
let bounds = self
.canonical_state
Expand Down Expand Up @@ -1649,7 +1653,7 @@ async fn process_execution_requests<
consts: &ProtocolConsts,
) {
if is_penultimate_block_of_epoch(state.get_epocher(), new_height) {
for _ in 0..consts.validator_onboarding_limit_per_block {
for _ in 0..state.get_max_deposits_per_epoch() as usize {
if let Some(request) = state.pop_deposit() {
let node_pubkey_bytes: [u8; 32] = request.node_pubkey.as_ref().try_into().unwrap();

Expand Down
2 changes: 0 additions & 2 deletions finalizer/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ use tokio_util::sync::CancellationToken;

/// Fixed protocol-level constants governing validator lifecycle.
pub struct ProtocolConsts {
/// The maximum number of validators that will be onboarded at the same time.
pub validator_onboarding_limit_per_block: usize,
/// Number of epochs to wait before activating validators after deposit.
pub validator_num_warm_up_epochs: u64,
/// Number of epochs after a withdrawal request until the payout.
Expand Down
18 changes: 18 additions & 0 deletions finalizer/src/ingress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,24 @@ impl<S: Scheme<B::Digest>, B: ConsensusBlock> FinalizerMailbox<S, B> {
address
}

pub async fn get_max_deposits_per_epoch(&self) -> u64 {
let (response, rx) = oneshot::channel();
let request = ConsensusStateRequest::GetMaxDepositsPerEpoch;
let _ = self
.sender
.clone()
.send(FinalizerMessage::QueryState { request, response })
.await;

let res = rx
.await
.expect("consensus state query response sender dropped");
let ConsensusStateResponse::MaxDepositsPerEpoch(value) = res else {
unreachable!("request and response variants must match");
};
value
}

pub async fn get_epoch_bounds(&self, epoch: u64) -> Option<(u64, u64)> {
let (response, rx) = oneshot::channel();
let request = ConsensusStateRequest::GetEpochBounds(epoch);
Expand Down
8 changes: 1 addition & 7 deletions finalizer/src/tests/fork_handling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ fn create_test_initial_state(genesis_hash: [u8; 32], epoch_length: NonZeroU64) -
epoch_length,
10_000,
Address::ZERO,
10,
);
state.set_validator_accounts(validator_accounts);
state
Expand Down Expand Up @@ -147,7 +148,6 @@ fn test_orphaned_block_processed_when_parent_arrives() {
engine_client: MockEngineClient::new(),
oracle: MockNetworkOracle,
protocol_consts: ProtocolConsts {
validator_onboarding_limit_per_block: 10,
validator_num_warm_up_epochs: 2,
validator_withdrawal_num_epochs: 2,
},
Expand Down Expand Up @@ -229,7 +229,6 @@ fn test_multiple_forks_tracked() {
engine_client: MockEngineClient::new(),
oracle: MockNetworkOracle,
protocol_consts: ProtocolConsts {
validator_onboarding_limit_per_block: 10,
validator_num_warm_up_epochs: 2,
validator_withdrawal_num_epochs: 2,
},
Expand Down Expand Up @@ -312,7 +311,6 @@ fn test_dead_fork_block_discarded() {
engine_client: MockEngineClient::new(),
oracle: MockNetworkOracle,
protocol_consts: ProtocolConsts {
validator_onboarding_limit_per_block: 10,
validator_num_warm_up_epochs: 2,
validator_withdrawal_num_epochs: 2,
},
Expand Down Expand Up @@ -411,7 +409,6 @@ fn test_fork_states_pruned_after_finalization() {
engine_client: MockEngineClient::new(),
oracle: MockNetworkOracle,
protocol_consts: ProtocolConsts {
validator_onboarding_limit_per_block: 10,
validator_num_warm_up_epochs: 2,
validator_withdrawal_num_epochs: 2,
},
Expand Down Expand Up @@ -529,7 +526,6 @@ fn test_orphaned_blocks_pruned_after_finalization() {
engine_client: MockEngineClient::new(),
oracle: MockNetworkOracle,
protocol_consts: ProtocolConsts {
validator_onboarding_limit_per_block: 10,
validator_num_warm_up_epochs: 2,
validator_withdrawal_num_epochs: 2,
},
Expand Down Expand Up @@ -639,7 +635,6 @@ fn test_fork_state_reused_when_notarized_then_finalized() {
engine_client: MockEngineClient::new(),
oracle: MockNetworkOracle,
protocol_consts: ProtocolConsts {
validator_onboarding_limit_per_block: 10,
validator_num_warm_up_epochs: 2,
validator_withdrawal_num_epochs: 2,
},
Expand Down Expand Up @@ -745,7 +740,6 @@ fn test_competing_fork_pruned_on_finalization() {
engine_client: MockEngineClient::new(),
oracle: MockNetworkOracle,
protocol_consts: ProtocolConsts {
validator_onboarding_limit_per_block: 10,
validator_num_warm_up_epochs: 2,
validator_withdrawal_num_epochs: 2,
},
Expand Down
5 changes: 1 addition & 4 deletions finalizer/src/tests/state_queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ fn create_test_initial_state(genesis_hash: [u8; 32], epoch_length: NonZeroU64) -
epoch_length,
10_000,
Address::ZERO,
10,
);
state.set_validator_accounts(validator_accounts);
state
Expand Down Expand Up @@ -156,7 +157,6 @@ fn test_get_latest_epoch() {
engine_client: MockEngineClient::new(),
oracle: MockNetworkOracle,
protocol_consts: ProtocolConsts {
validator_onboarding_limit_per_block: 10,
validator_num_warm_up_epochs: 2,
validator_withdrawal_num_epochs: 2,
},
Expand Down Expand Up @@ -266,7 +266,6 @@ fn test_get_epoch_genesis_hash() {
engine_client: MockEngineClient::new(),
oracle: MockNetworkOracle,
protocol_consts: ProtocolConsts {
validator_onboarding_limit_per_block: 10,
validator_num_warm_up_epochs: 2,
validator_withdrawal_num_epochs: 2,
},
Expand Down Expand Up @@ -364,7 +363,6 @@ fn test_get_aux_data_from_canonical_chain() {
engine_client: MockEngineClient::new(),
oracle: MockNetworkOracle,
protocol_consts: ProtocolConsts {
validator_onboarding_limit_per_block: 10,
validator_num_warm_up_epochs: 2,
validator_withdrawal_num_epochs: 2,
},
Expand Down Expand Up @@ -436,7 +434,6 @@ fn test_get_aux_data_returns_none_for_invalid_parent() {
engine_client: MockEngineClient::new(),
oracle: MockNetworkOracle,
protocol_consts: ProtocolConsts {
validator_onboarding_limit_per_block: 10,
validator_num_warm_up_epochs: 2,
validator_withdrawal_num_epochs: 2,
},
Expand Down
2 changes: 1 addition & 1 deletion finalizer/src/tests/syncing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ fn create_test_initial_state(genesis_hash: [u8; 32], epoch_length: NonZeroU64) -
epoch_length,
10_000,
Address::ZERO,
10,
);
state.set_validator_accounts(validator_accounts);
state
Expand All @@ -146,7 +147,6 @@ fn create_checkpoint_initial_state(

fn default_protocol_consts() -> ProtocolConsts {
ProtocolConsts {
validator_onboarding_limit_per_block: 10,
validator_num_warm_up_epochs: 2,
validator_withdrawal_num_epochs: 2,
}
Expand Down
2 changes: 1 addition & 1 deletion finalizer/src/tests/validator_lifecycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ fn create_test_initial_state(genesis_hash: [u8; 32], epoch_length: NonZeroU64) -
epoch_length,
10_000,
Address::ZERO,
10,
);
state.set_validator_accounts(validator_accounts);
state
Expand Down Expand Up @@ -165,7 +166,6 @@ fn test_validator_exit_triggers_cancellation() {
engine_client: MockEngineClient::new(),
oracle: MockNetworkOracle,
protocol_consts: ProtocolConsts {
validator_onboarding_limit_per_block: 10,
validator_num_warm_up_epochs: 2,
validator_withdrawal_num_epochs: 2,
},
Expand Down
1 change: 1 addition & 0 deletions node/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,7 @@ fn get_initial_state(
epoch_length,
genesis.allowed_timestamp_future_ms,
treasury_address,
genesis.max_deposits_per_epoch,
);
// Add the genesis nodes to the consensus state with the minimum stake balance.
for validator in genesis_committee {
Expand Down
7 changes: 1 addition & 6 deletions node/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,8 @@ const FREEZER_TABLE_INITIAL_SIZE: u32 = 1024 * 1024; // 100mb
const MAX_REPAIR: NonZero<usize> = NZUsize!(10);

//
// Onboarding config (set arbitrarily for now)
// Onboarding config

#[cfg(debug_assertions)]
const VALIDATOR_ONBOARDING_LIMIT_PER_BLOCK: usize = 10;
#[cfg(not(debug_assertions))]
const VALIDATOR_ONBOARDING_LIMIT_PER_BLOCK: usize = 3;
// Number of epochs after a deposit until a validator joins the committee
pub const VALIDATOR_NUM_WARM_UP_EPOCHS: u64 = 2;
// Number of epochs after a withdrawal request until the payout
Expand Down Expand Up @@ -146,7 +142,6 @@ where
engine_client: cfg.engine_client.clone(),
oracle: cfg.oracle.clone(),
protocol_consts: ProtocolConsts {
validator_onboarding_limit_per_block: VALIDATOR_ONBOARDING_LIMIT_PER_BLOCK,
validator_num_warm_up_epochs: VALIDATOR_NUM_WARM_UP_EPOCHS,
validator_withdrawal_num_epochs: VALIDATOR_WITHDRAWAL_NUM_EPOCHS,
},
Expand Down
1 change: 1 addition & 0 deletions node/src/test_harness/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ pub fn get_initial_state(
NonZeroU64::new(DEFAULT_BLOCKS_PER_EPOCH).unwrap(),
10_000, // 10 seconds
Address::ZERO,
10,
);
// Add the genesis nodes to the consensus state with the minimum stake balance.
for ((node_pubkey, consensus_pubkey), address) in committee.iter().zip(addresses.iter()) {
Expand Down
2 changes: 2 additions & 0 deletions node/src/tests/checkpointing/verification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ fn test_checkpoint_verification_fixed_committee() {
blocks_per_epoch: common::DEFAULT_BLOCKS_PER_EPOCH,
allowed_timestamp_future_ms: 10_000,
treasury_address: Address::ZERO.to_string(),
max_deposits_per_epoch: 10,
};

let node_public_keys: Vec<_> = validators.iter().map(|(pk, _)| pk.clone()).collect();
Expand Down Expand Up @@ -316,6 +317,7 @@ fn test_checkpoint_verification_dynamic_committee() {
blocks_per_epoch: common::DEFAULT_BLOCKS_PER_EPOCH,
allowed_timestamp_future_ms: 10_000,
treasury_address: Address::ZERO.to_string(),
max_deposits_per_epoch: 10,
};

let node_public_keys: Vec<_> = validators.iter().map(|(pk, _)| pk.clone()).collect();
Expand Down
Loading
Loading