Skip to content

Commit

Permalink
feat: start network with latest version if genesis version not set (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
shumkov authored Oct 5, 2024
1 parent 14309e6 commit 00fb663
Show file tree
Hide file tree
Showing 20 changed files with 283 additions and 46 deletions.
1 change: 1 addition & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ npmAuditExcludePackages:
- "@humanwhocodes/config-array" # TODO: Update eslint
- "@humanwhocodes/object-schema" # TODO: Update eslint
- micromatch # TODO: remove when new micromatch will be released https://github.com/advisories/GHSA-952p-6rrq-rcjv
- eslint # TODO: Update eslint https://github.com/dashpay/platform/issues/2212

packageExtensions:
"@dashevo/protobufjs@*":
Expand Down
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',
},
},
},
},
},
Expand Down
110 changes: 105 additions & 5 deletions packages/dashmate/configs/getConfigFileMigrationsFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -448,12 +448,63 @@ export default function getConfigFileMigrationsFactory(homeDir, defaultConfigs)
return configFile;
},
'1.0.0-dev.2': (configFile) => {
const consensusParams = {
block: {
max_bytes: '2097152',
max_gas: '57631392000',
time_iota_ms: '5000',
},
evidence: {
max_age: '100000',
max_age_num_blocks: '100000',
max_age_duration: '172800000000000',
},
validator: {
pub_key_types: ['bls12381'],
},
timeout: {
propose: '50000000000',
propose_delta: '5000000000',
vote: '10000000000',
vote_delta: '1000000000',
},
synchrony: {
message_delay: '70000000000',
precision: '1000000000',
},
abci: {
recheck_tx: true,
},
version: {
app_version: '1',
},
};

const genesis = {
base: {
consensus_params: lodash.cloneDeep(consensusParams),
},
local: {
consensus_params: lodash.cloneDeep(consensusParams),
},
testnet: {
chain_id: 'dash-testnet-51',
validator_quorum_type: 6,
consensus_params: lodash.cloneDeep(consensusParams),
},
mainnet: {
chain_id: 'evo1',
validator_quorum_type: 4,
consensus_params: lodash.cloneDeep(consensusParams),
},
};

Object.entries(configFile.configs)
.forEach(([name, options]) => {
if (defaultConfigs.has(name)) {
options.platform.drive.tenderdash.genesis = defaultConfigs.get(name)
.get('platform.drive.tenderdash.genesis');
if (genesis[name]) {
options.platform.drive.tenderdash.genesis = genesis[name];
}

options.platform.dapi.api.docker.deploy = base.get('platform.dapi.api.docker.deploy');

let baseConfigName = name;
Expand Down Expand Up @@ -774,6 +825,38 @@ export default function getConfigFileMigrationsFactory(homeDir, defaultConfigs)
return configFile;
},
'1.1.0-dev.1': (configFile) => {
const consensusParams = {
block: {
max_bytes: '2097152',
max_gas: '57631392000',
time_iota_ms: '5000',
},
evidence: {
max_age: '100000',
max_age_num_blocks: '100000',
max_age_duration: '172800000000000',
},
validator: {
pub_key_types: ['bls12381'],
},
timeout: {
propose: '50000000000',
propose_delta: '5000000000',
vote: '10000000000',
vote_delta: '1000000000',
},
synchrony: {
message_delay: '70000000000',
precision: '1000000000',
},
abci: {
recheck_tx: true,
},
version: {
app_version: '1',
},
};

Object.entries(configFile.configs)
.forEach(([name, options]) => {
if (name === 'local') {
Expand All @@ -792,8 +875,12 @@ export default function getConfigFileMigrationsFactory(homeDir, defaultConfigs)

options.platform.drive.tenderdash.p2p.maxConnections = 64;
options.platform.drive.tenderdash.p2p.maxOutgoingConnections = 30;
options.platform.drive.tenderdash.genesis
.consensus_params = base.get('platform.drive.tenderdash.genesis.consensus_params');

if (defaultConfigs.has(name)) {
options.platform.drive.tenderdash.genesis
.consensus_params = lodash.cloneDeep(consensusParams);
}

options.platform.drive.tenderdash.docker.image = base.get('platform.drive.tenderdash.docker.image');
});
return configFile;
Expand Down Expand Up @@ -911,6 +998,19 @@ export default function getConfigFileMigrationsFactory(homeDir, defaultConfigs)
});
return configFile;
},
'1.4.0-dev.4': (configFile) => {
Object.entries(configFile.configs)
.forEach(([name, options]) => {
if (name === 'base' || name === 'local') {
delete options.platform.drive.tenderdash.genesis.consensus_params.version;
} else if (options.network === NETWORK_TESTNET) {
options.platform.drive.tenderdash.genesis.consensus_params.version = {
app_version: '1',
};
}
});
return configFile;
},
};
}

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,9 +27,15 @@ 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,
)),
version => Err(Error::Execution(ExecutionError::UnknownVersionMismatch {
method: "consensus_params_update".to_string(),
known_versions: vec![0],
known_versions: vec![0, 1],
received: version,
})),
}
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) {
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,
});
}
}
_ => {}
}

// 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
Loading

0 comments on commit 00fb663

Please sign in to comment.