Skip to content

Commit

Permalink
fix: rebase corrections
Browse files Browse the repository at this point in the history
  • Loading branch information
86667 committed Dec 12, 2024
1 parent b9cdcfe commit 3fd4bc0
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 29 deletions.
7 changes: 3 additions & 4 deletions z2/src/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ use zilliqa::{
self, allowed_timestamp_skew_default, block_request_batch_size_default,
block_request_limit_default, consensus_timeout_default, empty_block_timeout_default,
eth_chain_id_default, failed_request_sleep_duration_default, local_address_default,
max_blocks_in_flight_default, minimum_time_left_for_empty_block_default,
scilla_address_default, scilla_ext_libs_path_default, scilla_stdlib_dir_default,
state_rpc_limit_default, total_native_token_supply_default, Amount, ApiServer,
ConsensusConfig, GenesisDeposit,
max_blocks_in_flight_default, scilla_address_default, scilla_ext_libs_path_default,
scilla_stdlib_dir_default, state_rpc_limit_default, total_native_token_supply_default,
Amount, ApiServer, ConsensusConfig, GenesisDeposit,
},
transaction::EvmGas,
};
Expand Down
5 changes: 0 additions & 5 deletions zilliqa/src/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,6 @@ impl Default for ConsensusConfig {
genesis_deposits: vec![],
genesis_accounts: vec![],
empty_block_timeout: empty_block_timeout_default(),
minimum_time_left_for_empty_block: minimum_time_left_for_empty_block_default(),
scilla_address: scilla_address_default(),
scilla_stdlib_dir: scilla_stdlib_dir_default(),
scilla_ext_libs_path: scilla_ext_libs_path_default(),
Expand Down Expand Up @@ -381,10 +380,6 @@ pub fn empty_block_timeout_default() -> Duration {
Duration::from_millis(1000)
}

pub fn minimum_time_left_for_empty_block_default() -> Duration {
Duration::from_millis(3000)
}

pub fn scilla_address_default() -> String {
String::from("http://localhost:3000")
}
Expand Down
21 changes: 9 additions & 12 deletions zilliqa/src/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -494,14 +494,14 @@ impl Consensus {
}

let (time_since_last_view_change, exponential_backoff_timeout, empty_block_timeout) =
self.get_consensus_timeout_params();
self.get_consensus_timeout_params()?;

trace!(
"timeout reached create_next_block_on_timeout: {}",
self.create_next_block_on_timeout
);
if self.create_next_block_on_timeout {
// Check if enough time elapsed to propse block
// Check if enough time elapsed to propose block
if time_since_last_view_change > empty_block_timeout {
if let Ok(Some((block, transactions))) = self.propose_new_block() {
self.create_next_block_on_timeout = false;
Expand Down Expand Up @@ -577,14 +577,15 @@ impl Consensus {
}

fn get_consensus_timeout_params(&self) -> Result<(u64, u64, u64)> {
let consensus_timeout_ms = self.config.consensus.consensus_timeout.as_millis() as u64;
let time_since_last_view_change = SystemTime::now()
.duration_since(self.view_updated_at)
.unwrap_or_default()
.as_millis() as u64;
let view_difference = self.get_view().saturating_sub(self.high_qc.view);
// in view N our highQC is the one we obtained in view N-1 (or before) and its view is N-2 (or lower)
// in other words, the current view is always at least 2 views ahead of the highQC's view
// i.e. to get `consensus_timeout_ms * 2^0` we have to subtract 2 from `view_difference`
let view_difference = self.get_view()?.saturating_sub(self.high_qc.view);
// In view N our highQC is the one we obtained in view N-1 (or before) and its view is N-2 (or lower)
// in other words, the current view is always at least 2 views ahead of the highQC's view.
// Therefore to get `consensus_timeout_ms * 2^0` we have to subtract 2 from `view_difference`
let exponential_backoff_timeout =
consensus_timeout_ms * 2u64.pow((view_difference as u32).saturating_sub(2));
let empty_block_timeout = self.config.consensus.empty_block_timeout.as_millis() as u64;
Expand Down Expand Up @@ -1350,16 +1351,12 @@ impl Consensus {
while let Some(tx) = self.transaction_pool.best_transaction(&state)? {
// First - check if we have time left to process txns and give enough time for block propagation
let (time_since_last_view_change, _, empty_block_timeout) =
self.get_consensus_timeout_params();
self.get_consensus_timeout_params()?;

if time_since_last_view_change > empty_block_timeout {
debug!(
time_since_last_view_change,
exponential_backoff_timeout,
minimum_time_left_for_empty_block,
"timeout proposal {} for view {}",
proposal.header.number,
proposal.header.view,
"timeout proposal {} for view {}", proposal.header.number, proposal.header.view,
);
// don't have time
break;
Expand Down
8 changes: 4 additions & 4 deletions zilliqa/tests/it/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ use zilliqa::{
cfg::{
allowed_timestamp_skew_default, block_request_batch_size_default,
block_request_limit_default, eth_chain_id_default, failed_request_sleep_duration_default,
max_blocks_in_flight_default, minimum_time_left_for_empty_block_default,
scilla_address_default, scilla_ext_libs_path_default, scilla_stdlib_dir_default,
state_cache_size_default, state_rpc_limit_default, total_native_token_supply_default,
Amount, ApiServer, Checkpoint, ConsensusConfig, GenesisDeposit, NodeConfig,
max_blocks_in_flight_default, scilla_address_default, scilla_ext_libs_path_default,
scilla_stdlib_dir_default, state_cache_size_default, state_rpc_limit_default,
total_native_token_supply_default, Amount, ApiServer, Checkpoint, ConsensusConfig,
GenesisDeposit, NodeConfig,
},
crypto::{SecretKey, TransactionPublicKey},
db,
Expand Down
7 changes: 3 additions & 4 deletions zilliqa/tests/it/persistence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ use zilliqa::{
allowed_timestamp_skew_default, block_request_batch_size_default,
block_request_limit_default, consensus_timeout_default, eth_chain_id_default,
failed_request_sleep_duration_default, max_blocks_in_flight_default,
minimum_time_left_for_empty_block_default, scilla_address_default,
scilla_ext_libs_path_default, scilla_stdlib_dir_default, state_cache_size_default,
state_rpc_limit_default, total_native_token_supply_default, ApiServer, Checkpoint,
ConsensusConfig, NodeConfig,
scilla_address_default, scilla_ext_libs_path_default, scilla_stdlib_dir_default,
state_cache_size_default, state_rpc_limit_default, total_native_token_supply_default,
ApiServer, Checkpoint, ConsensusConfig, NodeConfig,
},
crypto::{Hash, SecretKey},
transaction::EvmGas,
Expand Down

0 comments on commit 3fd4bc0

Please sign in to comment.