Skip to content

Commit

Permalink
[release-builder] Add consensus config to release config
Browse files Browse the repository at this point in the history
  • Loading branch information
runtian-zhou committed Nov 14, 2022
1 parent 7f4c660 commit 89fd2a4
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 2 deletions.
19 changes: 18 additions & 1 deletion aptos-move/aptos-release-builder/data/example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -452,4 +452,21 @@ feature_flags:
enabled:
- code_dependency_check
- treat_friend_as_private
disabled: []
disabled: []
consensus_config:
V1:
decoupled_execution: true
back_pressure_limit: 10
exclude_round: 20
proposer_election_type:
leader_reputation:
proposer_and_voter_v2:
active_weight: 1000
inactive_weight: 10
failed_weight: 1
failure_threshold_percent: 10
proposer_window_num_validators_multiplier: 10
voter_window_num_validators_multiplier: 1
weight_by_voting_power: true
use_history_from_previous_epoch_max_count: 5
max_failed_authors_to_store: 10
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright (c) Aptos
// SPDX-License-Identifier: Apache-2.0

use crate::utils::*;
use anyhow::Result;
use aptos_types::on_chain_config::OnChainConsensusConfig;
use move_model::{code_writer::CodeWriter, emit, emitln, model::Loc};

pub fn generate_consensus_upgrade_proposal(
consensus_config: &OnChainConsensusConfig,
is_testnet: bool,
) -> Result<Vec<(String, String)>> {
let mut result = vec![];

let gas_schedule_blob = bcs::to_bytes(consensus_config).unwrap();

assert!(gas_schedule_blob.len() < 65536);

let writer = CodeWriter::new(Loc::default());

emitln!(writer, "// Consensus config upgrade proposal\n");

if is_testnet {
generate_testnet_header(&writer, "aptos_framework::consensus_config");
} else {
generate_governance_proposal_header(&writer, "aptos_framework::consensus_config");
}

emit!(writer, "let consensus_blob: vector<u8> = ");
generate_blob(&writer, &gas_schedule_blob);
emitln!(writer, ";\n");

emitln!(
writer,
"consensus_config::set(framework_signer, consensus_blob);"
);

result.push(("consensus-config".to_string(), finish_with_footer(&writer)));
Ok(result)
}
13 changes: 12 additions & 1 deletion aptos-move/aptos-release-builder/src/components/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@

use crate::components::feature_flags::Features;
use anyhow::{anyhow, Result};
use aptos_types::on_chain_config::{GasScheduleV2, Version};
use aptos_types::on_chain_config::{GasScheduleV2, OnChainConsensusConfig, Version};
use serde::{Deserialize, Serialize};
use std::{
fs::File,
io::{Read, Write},
path::Path,
};

pub mod consensus_config;
pub mod feature_flags;
pub mod framework;
pub mod gas;
Expand All @@ -26,6 +27,8 @@ pub struct ReleaseConfig {
pub version: Option<Version>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub feature_flags: Option<Features>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub consensus_config: Option<OnChainConsensusConfig>,
}

impl ReleaseConfig {
Expand Down Expand Up @@ -58,6 +61,13 @@ impl ReleaseConfig {
)?);
}

if let Some(consensus_config) = &self.consensus_config {
result.append(&mut consensus_config::generate_consensus_upgrade_proposal(
consensus_config,
self.testnet,
)?);
}

for (idx, (script_name, script)) in result.into_iter().enumerate() {
let mut script_path = base_path.to_path_buf();
let proposal_name = format!("{}-{}", idx, script_name);
Expand Down Expand Up @@ -116,6 +126,7 @@ impl Default for ReleaseConfig {
gas_schedule: Some(aptos_gas::gen::current_gas_schedule()),
version: None,
feature_flags: None,
consensus_config: Some(OnChainConsensusConfig::default()),
}
}
}

0 comments on commit 89fd2a4

Please sign in to comment.