Skip to content

Commit

Permalink
fix(jstzd): use protocol version from proto params
Browse files Browse the repository at this point in the history
  • Loading branch information
huancheng-trili committed Dec 6, 2024
1 parent 8330a51 commit 26bec48
Show file tree
Hide file tree
Showing 2 changed files with 119 additions and 10 deletions.
60 changes: 50 additions & 10 deletions crates/jstzd/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ use anyhow::{Context, Result};
use jstz_node::config::JstzNodeConfig;
use octez::r#async::endpoint::Endpoint;
use octez::r#async::protocol::{BootstrapContract, ProtocolParameter};
use octez::r#async::rollup::{OctezRollupConfigBuilder, RollupDataDir};
use octez::r#async::{
baker::{BakerBinaryPath, OctezBakerConfig, OctezBakerConfigBuilder},
client::{OctezClientConfig, OctezClientConfigBuilder},
node_config::{OctezNodeConfig, OctezNodeConfigBuilder},
protocol::{BootstrapAccount, Protocol, ProtocolParameterBuilder},
protocol::{BootstrapAccount, ProtocolParameterBuilder},
rollup::{OctezRollupConfigBuilder, RollupDataDir},
};
use serde::Deserialize;
use tezos_crypto_rs::hash::SmartRollupHash;
Expand Down Expand Up @@ -78,10 +78,12 @@ pub(crate) async fn build_config(
None => OctezClientConfigBuilder::new(octez_node_config.rpc_endpoint.clone()),
}
.build()?;
let protocol_params = build_protocol_params(config.protocol).await?;
let baker_config = populate_baker_config(
config.octez_baker,
&octez_node_config,
&octez_client_config,
&protocol_params,
)?;

let kernel_debug_file = Path::new(KERNEL_DEBUG_FILE);
Expand All @@ -106,7 +108,7 @@ pub(crate) async fn build_config(
&octez_rollup_config.rpc_endpoint,
kernel_debug_file,
);
let protocol_params = build_protocol_params(config.protocol).await?;

let server_port = config.server_port.unwrap_or(DEFAULT_JSTZD_SERVER_PORT);
Ok((
server_port,
Expand Down Expand Up @@ -134,10 +136,11 @@ fn populate_baker_config(
mut config_builder: OctezBakerConfigBuilder,
octez_node_config: &OctezNodeConfig,
octez_client_config: &OctezClientConfig,
protocol_params: &ProtocolParameter,
) -> Result<OctezBakerConfig> {
if config_builder.binary_path().is_none() {
config_builder =
config_builder.set_binary_path(BakerBinaryPath::Env(Protocol::Alpha));
config_builder = config_builder
.set_binary_path(BakerBinaryPath::Env(protocol_params.protocol()));
}
if config_builder.octez_client_base_dir().is_none() {
config_builder = config_builder
Expand Down Expand Up @@ -208,7 +211,7 @@ mod tests {
use tezos_crypto_rs::hash::ContractKt1Hash;
use tokio::io::AsyncReadExt;

use super::{jstz_rollup_path, JSTZ_ROLLUP_ADDRESS, KERNEL_DEBUG_FILE};
use super::{jstz_rollup_path, ACTIVATOR_PK, JSTZ_ROLLUP_ADDRESS, KERNEL_DEBUG_FILE};

use super::Config;

Expand Down Expand Up @@ -400,13 +403,50 @@ mod tests {
.build()
.unwrap();
let baker_builder = OctezBakerConfigBuilder::new();
let baker_config =
super::populate_baker_config(baker_builder, &node_config, &client_config)
.unwrap();
let protocol_params = ProtocolParameterBuilder::new()
.set_protocol(Protocol::ParisC)
.set_bootstrap_accounts([
BootstrapAccount::new(ACTIVATOR_PK, 40_000_000_000).unwrap()
])
.build()
.unwrap();
let baker_config = super::populate_baker_config(
baker_builder,
&node_config,
&client_config,
&protocol_params,
)
.unwrap();

// baker path is not provided in the config, so the builder takes the protocol version from
// protocol_params
assert_eq!(
baker_config,
OctezBakerConfigBuilder::new()
.set_binary_path(BakerBinaryPath::Env(Protocol::ParisC))
.set_octez_client_base_dir(tmp_dir.path().to_str().unwrap())
.set_octez_node_endpoint(&Endpoint::localhost(5678))
.build()
.unwrap()
);

// baker path is provided in the config, so the builder takes that path and ignores protocol_params
let baker_builder = OctezBakerConfigBuilder::new().set_binary_path(
BakerBinaryPath::Custom(PathBuf::from_str("/foo/bar").unwrap()),
);
let baker_config = super::populate_baker_config(
baker_builder,
&node_config,
&client_config,
&protocol_params,
)
.unwrap();
assert_eq!(
baker_config,
OctezBakerConfigBuilder::new()
.set_binary_path(BakerBinaryPath::Env(Protocol::Alpha))
.set_binary_path(BakerBinaryPath::Custom(
PathBuf::from_str("/foo/bar").unwrap()
))
.set_octez_client_base_dir(tmp_dir.path().to_str().unwrap())
.set_octez_node_endpoint(&Endpoint::localhost(5678))
.build()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{ "consensus_rights_delay": 2,
"blocks_preservation_cycles": 1, "delegate_parameters_activation_delay": 2,
"blocks_per_cycle": 8, "blocks_per_commitment": 4,
"nonce_revelation_threshold": 4, "cycles_per_voting_period": 8,
"hard_gas_limit_per_operation": "1040000",
"hard_gas_limit_per_block": "1386666",
"proof_of_work_threshold": "4611686018427387903",
"minimal_stake": "6000000000", "minimal_frozen_stake": "600000000",
"vdf_difficulty": "50000", "origination_size": 257,
"issuance_weights":
{ "base_total_issued_per_minute": "80007812",
"baking_reward_fixed_portion_weight": 5120,
"baking_reward_bonus_weight": 5120, "attesting_reward_weight": 10240,
"seed_nonce_revelation_tip_weight": 1, "vdf_revelation_tip_weight": 1 },
"cost_per_byte": "250", "hard_storage_limit_per_operation": "60000",
"quorum_min": 2000, "quorum_max": 7000, "min_proposal_quorum": 500,
"liquidity_baking_subsidy": "5000000",
"liquidity_baking_toggle_ema_threshold": 1000000000,
"max_operations_time_to_live": 8, "minimal_block_delay": "1",
"delay_increment_per_round": "1", "consensus_committee_size": 256,
"consensus_threshold": 0,
"minimal_participation_ratio": { "numerator": 2, "denominator": 3 },
"limit_of_delegation_over_baking": 19,
"percentage_of_frozen_deposits_slashed_per_double_baking": 500,
"percentage_of_frozen_deposits_slashed_per_double_attestation": 5000,
"max_slashing_per_block": 10000, "max_slashing_threshold": 101,
"cache_script_size": 100000000, "cache_stake_distribution_cycles": 5,
"cache_sampler_state_cycles": 5,
"dal_parametric":
{ "feature_enable": true, "incentives_enable": false,
"number_of_slots": 16, "attestation_lag": 8,
"attestation_threshold": 66, "redundancy_factor": 8, "page_size": 3967,
"slot_size": 126944, "number_of_shards": 256 },
"smart_rollup_arith_pvm_enable": false,
"smart_rollup_origination_size": 6314,
"smart_rollup_challenge_window_in_blocks": 151200,
"smart_rollup_stake_amount": "10000000000",
"smart_rollup_commitment_period_in_blocks": 112,
"smart_rollup_max_lookahead_in_blocks": 324000,
"smart_rollup_max_active_outbox_levels": 151200,
"smart_rollup_max_outbox_messages_per_level": 100,
"smart_rollup_number_of_sections_in_dissection": 32,
"smart_rollup_timeout_period_in_blocks": 75600,
"smart_rollup_max_number_of_cemented_commitments": 5,
"smart_rollup_max_number_of_parallel_games": 32,
"smart_rollup_reveal_activation_level":
{ "raw_data": { "Blake2B": 0 }, "metadata": 0, "dal_page": 1,
"dal_parameters": 1, "dal_attested_slots_validity_lag": 241920 },
"smart_rollup_private_enable": true,
"smart_rollup_riscv_pvm_enable": false, "zk_rollup_enable": false,
"zk_rollup_origination_size": 4000, "zk_rollup_min_pending_to_process": 10,
"zk_rollup_max_ticket_payload_size": 2048,
"global_limit_of_staking_over_baking": 5,
"edge_of_staking_over_delegation": 2,
"adaptive_issuance_launch_ema_threshold": 0,
"adaptive_rewards_params":
{ "issuance_ratio_final_min": { "numerator": "1", "denominator": "400" },
"issuance_ratio_final_max": { "numerator": "1", "denominator": "10" },
"issuance_ratio_initial_min":
{ "numerator": "9", "denominator": "200" },
"issuance_ratio_initial_max":
{ "numerator": "11", "denominator": "200" }, "initial_period": 10,
"transition_period": 50, "max_bonus": "50000000000000",
"growth_rate": { "numerator": "1", "denominator": "100" },
"center_dz": { "numerator": "1", "denominator": "2" },
"radius_dz": { "numerator": "1", "denominator": "50" } },
"adaptive_issuance_activation_vote_enable": true,
"autostaking_enable": true, "adaptive_issuance_force_activation": false,
"ns_enable": true, "direct_ticket_spending_enable": false }

0 comments on commit 26bec48

Please sign in to comment.