Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: start network with latest version if genesis version not set #2206

Merged
merged 11 commits into from
Oct 5, 2024
Merged
Binary file added .yarn/cache/fsevents-patch-19706e7e35-10.zip
Binary file not shown.
4 changes: 0 additions & 4 deletions packages/dashmate/configs/defaults/getBaseConfigFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
const { version } = JSON.parse(fs.readFileSync(path.join(PACKAGE_ROOT_DIR, 'package.json'), 'utf8'));

/**
* @param {HomeDir} homeDir
* @returns {getBaseConfig}
*/
export default function getBaseConfigFactory() {
Expand Down Expand Up @@ -398,9 +397,6 @@ export default function getBaseConfigFactory() {
validator: {
pub_key_types: ['bls12381'],
},
version: {
app_version: '1',
},
timeout: {
propose: '50000000000',
propose_delta: '5000000000',
Expand Down
5 changes: 5 additions & 0 deletions packages/dashmate/configs/defaults/getMainnetConfigFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ export default function getMainnetConfigFactory(homeDir, getBaseConfig) {
genesis: {
chain_id: 'evo1',
validator_quorum_type: 4,
consensus_params: {
version: {
app_version: '1',
},
},
},
},
abci: {
Expand Down
5 changes: 5 additions & 0 deletions packages/dashmate/configs/defaults/getTestnetConfigFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ export default function getTestnetConfigFactory(homeDir, getBaseConfig) {
genesis: {
chain_id: 'dash-testnet-51',
validator_quorum_type: 6,
consensus_params: {
version: {
app_version: '1',
},
},
shumkov marked this conversation as resolved.
Show resolved Hide resolved
},
},
},
Expand Down
8 changes: 0 additions & 8 deletions packages/rs-drive-abci/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,6 @@ pub struct PlatformConfig {
/// Approximately how often are blocks produced
pub block_spacing_ms: u64,

/// Initial protocol version
pub initial_protocol_version: ProtocolVersion,

/// Path to data storage
pub db_path: PathBuf,

Expand Down Expand Up @@ -276,7 +273,6 @@ impl<'de> Deserialize<'de> for PlatformConfig {
chain_lock: config.chain_lock,
instant_lock: config.instant_lock,
block_spacing_ms: config.block_spacing_ms,
initial_protocol_version: config.initial_protocol_version,
db_path: config.db_path,
rejections_path: config.rejections_path,
#[cfg(feature = "testing-config")]
Expand Down Expand Up @@ -734,7 +730,6 @@ impl PlatformConfig {
tokio_console_enabled: false,
tokio_console_address: PlatformConfig::default_tokio_console_address(),
tokio_console_retention_secs: PlatformConfig::default_tokio_console_retention_secs(),
initial_protocol_version: Self::default_initial_protocol_version(),
prometheus_bind_address: None,
grpc_bind_address: "127.0.0.1:26670".to_string(),
}
Expand Down Expand Up @@ -777,7 +772,6 @@ impl PlatformConfig {
tokio_console_enabled: false,
tokio_console_address: PlatformConfig::default_tokio_console_address(),
tokio_console_retention_secs: PlatformConfig::default_tokio_console_retention_secs(),
initial_protocol_version: Self::default_initial_protocol_version(),
prometheus_bind_address: None,
grpc_bind_address: "127.0.0.1:26670".to_string(),
}
Expand Down Expand Up @@ -817,7 +811,6 @@ impl PlatformConfig {
rejections_path: Some(PathBuf::from("/var/log/dash/rejected")),
#[cfg(feature = "testing-config")]
testing_configs: PlatformTestConfig::default(),
initial_protocol_version: Self::default_initial_protocol_version(),
prometheus_bind_address: None,
grpc_bind_address: "127.0.0.1:26670".to_string(),
tokio_console_enabled: false,
Expand Down Expand Up @@ -860,7 +853,6 @@ impl PlatformConfig {
rejections_path: Some(PathBuf::from("/var/log/dash/rejected")),
#[cfg(feature = "testing-config")]
testing_configs: PlatformTestConfig::default(),
initial_protocol_version: Self::default_initial_protocol_version(),
prometheus_bind_address: None,
grpc_bind_address: "127.0.0.1:26670".to_string(),
tokio_console_enabled: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ use dpp::version::PlatformVersion;
use tenderdash_abci::proto::types::ConsensusParams;

mod v0;
mod v1;

pub(crate) fn consensus_params_update(
network: Network,
original_platform_version: &PlatformVersion,
Expand All @@ -25,6 +27,12 @@ pub(crate) fn consensus_params_update(
new_platform_version,
epoch_info,
)),
1 => Ok(v1::consensus_params_update_v1(
network,
original_platform_version,
new_platform_version,
epoch_info,
)),
shumkov marked this conversation as resolved.
Show resolved Hide resolved
version => Err(Error::Execution(ExecutionError::UnknownVersionMismatch {
method: "consensus_params_update".to_string(),
known_versions: vec![0],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
use crate::platform_types::epoch_info::v0::EpochInfoV0Methods;
use crate::platform_types::epoch_info::EpochInfo;
use dpp::dashcore::Network;
use dpp::version::PlatformVersion;
use tenderdash_abci::proto::types::{ConsensusParams, VersionParams};

#[inline(always)]
pub(super) fn consensus_params_update_v1(
network: Network,
original_platform_version: &PlatformVersion,
new_platform_version: &PlatformVersion,
epoch_info: &EpochInfo,
) -> Option<ConsensusParams> {
// These are emergency consensus updates
match network {
Network::Dash => {
if epoch_info.is_first_block_of_epoch(3) {
QuantumExplorer marked this conversation as resolved.
Show resolved Hide resolved
return Some(ConsensusParams {
block: None,
evidence: None,
validator: None,
version: Some(VersionParams {
app_version: new_platform_version.protocol_version as u64,
consensus_version: 1,
}),
synchrony: None,
timeout: None,
abci: None,
});
}
}
Network::Testnet => {
if epoch_info.is_first_block_of_epoch(1480) {
return Some(ConsensusParams {
block: None,
evidence: None,
validator: None,
version: Some(VersionParams {
app_version: new_platform_version.protocol_version as u64,
consensus_version: 1,
}),
synchrony: None,
timeout: None,
abci: None,
});
}
}
QuantumExplorer marked this conversation as resolved.
Show resolved Hide resolved
_ => {}
}

// Update versions if any of them changed
if original_platform_version
.consensus
.tenderdash_consensus_version
== new_platform_version.consensus.tenderdash_consensus_version
&& original_platform_version.protocol_version == new_platform_version.protocol_version
{
None
} else {
Some(ConsensusParams {
block: None,
evidence: None,
validator: None,
version: Some(VersionParams {
app_version: new_platform_version.protocol_version as u64,
consensus_version: new_platform_version.consensus.tenderdash_consensus_version
as i32,
}),
synchrony: None,
timeout: None,
abci: None,
})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ use crate::platform_types::platform::Platform;

use crate::rpc::core::CoreRPCLike;

use crate::abci::AbciError;
use crate::error::execution::ExecutionError;
use dpp::version::PlatformVersion;
use dpp::version::ProtocolVersion;
use drive::grovedb::Transaction;
use tenderdash_abci::proto::abci::{RequestInitChain, ResponseInitChain};

Expand All @@ -22,8 +24,31 @@ where
) -> Result<ResponseInitChain, Error> {
// We don't have platform state at this point, so we should
// use initial protocol version from genesis
let protocol_version = self.config.initial_protocol_version;
let platform_version = PlatformVersion::get(protocol_version)?;
let consensus_params = request
.consensus_params
.as_ref()
.ok_or(AbciError::BadRequest(
"consensus params are required in init chain".to_string(),
))?;

let tenderdash_abci::proto::types::VersionParams {
app_version: protocol_version,
..
} = consensus_params
.version
.as_ref()
.ok_or(AbciError::BadRequest(
"consensus params version is required in init chain".to_string(),
))?;

let platform_version = if *protocol_version == 0 {
// Protocol version is not set.
// We are starting the chain with the desired version
PlatformVersion::desired()
} else {
// Use the version from the genesis
PlatformVersion::get(*protocol_version as ProtocolVersion)?
};

match platform_version.drive_abci.methods.engine.init_chain {
0 => self.init_chain_v0(request, transaction, platform_version),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ use dpp::block::block_info::BlockInfo;
use drive::error::Error::GroveDB;
use drive::grovedb::Transaction;

use crate::execution::engine::consensus_params_update::consensus_params_update;
use crate::platform_types::cleaned_abci_messages::request_init_chain_cleaned_params;
use crate::platform_types::epoch_info::v0::EpochInfoV0;
use crate::platform_types::epoch_info::EpochInfo;
use crate::platform_types::platform_state::v0::PlatformStateV0Methods;
use crate::platform_types::platform_state::PlatformState;
use crate::platform_types::validator_set::ValidatorSetExt;
Expand Down Expand Up @@ -68,8 +71,8 @@ where

// Create platform execution state
let mut initial_platform_state = PlatformState::default_with_protocol_versions(
request.initial_protocol_version,
request.initial_protocol_version,
platform_version.protocol_version,
platform_version.protocol_version,
&self.config,
)?;

Expand Down Expand Up @@ -113,9 +116,6 @@ where

initial_platform_state.set_genesis_block_info(Some(genesis_block_info));

initial_platform_state
.set_current_protocol_version_in_consensus(request.initial_protocol_version);

if tracing::enabled!(tracing::Level::TRACE) {
tracing::trace!(
platform_state_fingerprint = hex::encode(initial_platform_state.fingerprint()?),
Expand All @@ -132,8 +132,24 @@ where
.unwrap()
.map_err(GroveDB)?;

// We use first platform version because Tenderdash starts genesis with first versions
// by default
let first_platform_version = PlatformVersion::first();

let epoch_info = EpochInfo::V0(EpochInfoV0::calculate(
genesis_time,
genesis_time,
None,
self.config.execution.epoch_time_length_s,
)?);

Ok(ResponseInitChain {
consensus_params: None,
consensus_params: consensus_params_update(
self.config.network,
first_platform_version,
platform_version,
&epoch_info,
)?,
app_hash: app_hash.to_vec(),
validator_set_update: Some(validator_set),
next_core_chain_lock_update: None,
Expand Down
12 changes: 8 additions & 4 deletions packages/rs-drive-abci/src/test/fixture/abci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@

use crate::config::PlatformConfig;
use dpp::version::PlatformVersion;
use dpp::version::ProtocolVersion;
use tenderdash_abci::proto::abci::RequestInitChain;
use tenderdash_abci::proto::google::protobuf::Timestamp;
use tenderdash_abci::proto::types::{ConsensusParams, VersionParams};

/// Creates static init chain request fixture
pub fn static_init_chain_request(config: &PlatformConfig) -> RequestInitChain {
let platform_version = PlatformVersion::get(config.initial_protocol_version)
.expect("expected to get platform version");
pub fn static_init_chain_request(
config: &PlatformConfig,
protocol_version: ProtocolVersion,
QuantumExplorer marked this conversation as resolved.
Show resolved Hide resolved
) -> RequestInitChain {
let platform_version =
PlatformVersion::get(protocol_version).expect("expected to get platform version");
RequestInitChain {
time: Some(Timestamp {
seconds: 0,
Expand All @@ -19,7 +23,7 @@ pub fn static_init_chain_request(config: &PlatformConfig) -> RequestInitChain {
chain_id: "strategy_tests".to_string(),
consensus_params: Some(ConsensusParams {
version: Some(VersionParams {
app_version: config.initial_protocol_version as u64,
app_version: protocol_version as u64,
consensus_version: platform_version.consensus.tenderdash_consensus_version as i32,
}),
..Default::default()
Expand Down
9 changes: 8 additions & 1 deletion packages/rs-drive-abci/tests/strategy_tests/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -829,8 +829,15 @@ pub(crate) fn start_chain_for_strategy(
.get::<QuorumHash>(&current_validator_quorum_hash)
.expect("expected a quorum to be found");

let platform_state = abci_application.platform.state.load();
let protocol_version = platform_state
.current_platform_version()
.unwrap()
.protocol_version;
drop(platform_state);

// init chain
let mut init_chain_request = static_init_chain_request(&config);
let mut init_chain_request = static_init_chain_request(&config, protocol_version);

init_chain_request.initial_core_height = config.abci.genesis_core_height;
init_chain_request.validator_set = Some(ValidatorSetUpdate {
Expand Down
5 changes: 4 additions & 1 deletion packages/rs-drive-abci/tests/strategy_tests/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ mod tests {
use crate::execution::{continue_chain_for_strategy, run_chain_for_strategy};
use crate::query::QueryStrategy;
use crate::strategy::{FailureStrategy, MasternodeListChangesStrategy};
use assert_matches::assert_matches;
use dashcore_rpc::dashcore::hashes::Hash;
use dashcore_rpc::dashcore::BlockHash;
use dashcore_rpc::json::QuorumType;
Expand Down Expand Up @@ -87,6 +86,7 @@ mod tests {
};
use dpp::identity::{Identity, KeyType, Purpose, SecurityLevel};
use dpp::state_transition::StateTransition;
use platform_version::version::v1::PROTOCOL_VERSION_1;
QuantumExplorer marked this conversation as resolved.
Show resolved Hide resolved
use platform_version::version::PlatformVersion;
use simple_signer::signer::SimpleSigner;
use strategy_tests::transitions::create_state_transitions_for_identities;
Expand Down Expand Up @@ -1159,6 +1159,7 @@ mod tests {

let mut platform = TestPlatformBuilder::new()
.with_config(config.clone())
.with_initial_protocol_version(PROTOCOL_VERSION_1)
QuantumExplorer marked this conversation as resolved.
Show resolved Hide resolved
QuantumExplorer marked this conversation as resolved.
Show resolved Hide resolved
.build_with_mock_rpc();

let outcome = run_chain_for_strategy(&mut platform, 150, strategy, config, 15, &mut None);
Expand Down Expand Up @@ -1885,6 +1886,7 @@ mod tests {
let block_count = 120;
let mut platform = TestPlatformBuilder::new()
.with_config(config.clone())
.with_initial_protocol_version(PROTOCOL_VERSION_1)
QuantumExplorer marked this conversation as resolved.
Show resolved Hide resolved
.build_with_mock_rpc();

let outcome =
Expand Down Expand Up @@ -2015,6 +2017,7 @@ mod tests {
let block_count = 120;
let mut platform = TestPlatformBuilder::new()
.with_config(config.clone())
.with_initial_protocol_version(PROTOCOL_VERSION_1)
QuantumExplorer marked this conversation as resolved.
Show resolved Hide resolved
.build_with_mock_rpc();

let outcome =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ mod tests {
use platform_version::version;
use platform_version::version::mocks::v2_test::TEST_PROTOCOL_VERSION_2;
use platform_version::version::patches::PatchFn;
use platform_version::version::v1::PROTOCOL_VERSION_1;
use platform_version::version::PlatformVersion;

#[test]
Expand Down Expand Up @@ -105,6 +106,7 @@ mod tests {

let mut platform = TestPlatformBuilder::new()
.with_config(config.clone())
.with_initial_protocol_version(PROTOCOL_VERSION_1)
.build_with_mock_rpc();

// Run chain before the first patch
Expand Down
Loading
Loading