Skip to content

Commit

Permalink
chore: activate platform on EHF fork (#1972)
Browse files Browse the repository at this point in the history
  • Loading branch information
shumkov authored Jul 17, 2024
1 parent 782fd97 commit d097ef3
Show file tree
Hide file tree
Showing 9 changed files with 301 additions and 42 deletions.
207 changes: 207 additions & 0 deletions packages/dapi-grpc/clients/platform/v0/objective-c/Platform.pbobjc.h

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions packages/dashmate/src/core/activateCoreSpork.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
* @typedef activateCoreSpork
* @param {RpcClient} rpcClient
* @param {string} spork
* @param {number} height
* @returns {Promise<void>}
*/
export default async function activateCoreSpork(rpcClient, spork) {
await rpcClient.sporkupdate(spork, 0);
export default async function activateCoreSpork(rpcClient, spork, height = 0) {
await rpcClient.sporkupdate(spork, height);
}
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,6 @@ export default function configureCoreTaskFactory(
'SPORK_9_SUPERBLOCKS_ENABLED',
'SPORK_17_QUORUM_DKG_ENABLED',
'SPORK_19_CHAINLOCKS_ENABLED',
'SPORK_24_TEST_EHF',
];

await Promise.all(
Expand Down Expand Up @@ -348,18 +347,6 @@ export default function configureCoreTaskFactory(
title: 'Wait for quorums to be enabled',
task: () => enableCoreQuorumsTask(),
},
{
title: 'Setting initial core chain locked height',
task: async (_, task) => {
const rpcClient = ctx.seedCoreService.getRpcClient();
const { result: initialCoreChainLockedHeight } = await rpcClient.getBlockCount();

ctx.initialCoreChainLockedHeight = initialCoreChainLockedHeight;

// eslint-disable-next-line no-param-reassign
task.output = `Initial chain locked core height is set to: ${ctx.initialCoreChainLockedHeight}`;
},
},
{
title: 'Activating V20 fork',
task: () => new Observable(async (observer) => {
Expand Down Expand Up @@ -401,6 +388,74 @@ export default function configureCoreTaskFactory(
return this;
}),
},
{
title: 'Wait for nodes to have the same height',
task: () => waitForNodesToHaveTheSameHeight(
ctx.rpcClients,
WAIT_FOR_NODES_TIMEOUT,
),
},
{
title: 'Enable EHF spork',
task: async () => new Observable(async (observer) => {
const seedRpcClient = ctx.seedCoreService.getRpcClient();
const {
result: initialCoreChainLockedHeight,
} = await seedRpcClient.getBlockCount();

await activateCoreSpork(
seedRpcClient,
'SPORK_24_TEST_EHF',
initialCoreChainLockedHeight,
);

let isEhfActivated = false;
let blockchainInfo;

let blocksGenerated = 0;

const blocksToGenerateInOneStep = 48;

do {
({
result: blockchainInfo,
} = await ctx.seedCoreService.getRpcClient().getBlockchainInfo());

isEhfActivated = blockchainInfo.softforks && blockchainInfo.softforks.mn_rr
&& blockchainInfo.softforks.mn_rr.active;
if (isEhfActivated) {
break;
}

await ctx.bumpMockTime(blocksToGenerateInOneStep);

await generateBlocks(
ctx.seedCoreService,
blocksToGenerateInOneStep,
NETWORK_LOCAL,
// eslint-disable-next-line no-loop-func
(blocks) => {
blocksGenerated += blocks;

observer.next(`${blocksGenerated} blocks generated`);
},
);
} while (!isEhfActivated);

observer.next(`EHF has been activated at height ${blockchainInfo.softforks.mn_rr.height}`);

observer.complete();

return this;
}),
},
{
title: 'Wait for nodes to have the same height',
task: () => waitForNodesToHaveTheSameHeight(
ctx.rpcClients,
WAIT_FOR_NODES_TIMEOUT,
),
},
{
title: 'Stopping nodes',
task: async () => (Promise.all(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default function configureTenderdashTaskFactory() {
function configureTenderdashTask(configGroup) {
return new Listr([
{
task: async (ctx) => {
task: async () => {
const platformConfigs = configGroup.filter((config) => config.get('platform.enable'));

const subTasks = [];
Expand All @@ -28,10 +28,6 @@ export default function configureTenderdashTaskFactory() {
platformConfigs.forEach((config, index) => {
config.set('platform.drive.tenderdash.genesis.genesis_time', genesisTime);
config.set('platform.drive.tenderdash.genesis.chain_id', chainId);
config.set(
'platform.drive.tenderdash.genesis.initial_core_chain_locked_height',
ctx.initialCoreChainLockedHeight,
);

const p2pPeers = platformConfigs
.filter((_, i) => i !== index)
Expand Down
6 changes: 3 additions & 3 deletions packages/rs-drive-abci/src/error/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ pub enum ExecutionError {
InitializationForkNotActive(String),

/// Invalid core chain locked height
#[error("core chain locked height {requested} is invalid: {v20_fork} <= {requested} <= {best} is not true")]
#[error("core chain locked height {requested} is invalid: {mn_rr_fork} <= {requested} <= {best} is not true")]
InitializationBadCoreLockedHeight {
/// v20 fork height
v20_fork: u32,
/// mn_rr fork height
mn_rr_fork: u32,
/// requested core height
requested: u32,
/// best core lock height
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ where
request,
)?;

// We get core height early, as this also verifies v20 fork
// We get core height early, as this also verifies mn_rr fork
let core_height =
self.initial_core_height(request.initial_core_height, platform_version)?;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ where
/// Determine initial core height.
///
/// Use core height received from Tenderdash (from genesis.json) by default,
/// otherwise we go with height of v20 fork.
/// otherwise we go with height of mn_rr fork.
///
/// Core height is verified to ensure that it is both at or after v20 fork, and
/// Core height is verified to ensure that it is both at or after mn_rr fork, and
/// before or at last chain lock.
///
/// ## Error handling
///
/// This function will fail if:
///
/// * v20 fork is not yet active
/// * `requested` core height is before v20 fork
/// * mn_rr fork is not yet active
/// * `requested` core height is before mn_rr fork
/// * `requested` core height is after current best chain lock
///
pub(in crate::execution) fn initial_core_height(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,51 +10,51 @@ where
/// Determine initial core height.
///
/// Use core height received from Tenderdash (from genesis.json) by default,
/// otherwise we go with height of v20 fork.
/// otherwise we go with height of mn_rr fork.
///
/// Core height is verified to ensure that it is both at or after v20 fork, and
/// Core height is verified to ensure that it is both at or after mn_rr fork, and
/// before or at last chain lock.
///
/// ## Error handling
///
/// This function will fail if:
///
/// * v20 fork is not yet active
/// * `requested` core height is before v20 fork
/// * mn_rr fork is not yet active
/// * `requested` core height is before mn_rr fork
/// * `requested` core height is after current best chain lock
///
pub(in crate::execution::platform_events) fn initial_core_height_v0(
&self,
requested: Option<u32>,
) -> Result<u32, Error> {
let fork_info = self.core_rpc.get_fork_info("v20")?.ok_or(
let fork_info = self.core_rpc.get_fork_info("mn_rr")?.ok_or(
ExecutionError::InitializationForkNotActive("fork is not yet known".to_string()),
)?;
if !fork_info.active || fork_info.height.is_none() {
// fork is not good yet
return Err(ExecutionError::InitializationForkNotActive(format!(
"fork is not yet known (currently {:?})",
fork_info.bip9.unwrap()
fork_info
))
.into());
} else {
tracing::debug!(?fork_info, "core fork v20 is active");
tracing::debug!(?fork_info, "core fork mn_rr is active");
};
// We expect height to present if the fork is active
let v20_fork = fork_info.height.unwrap();
let mn_rr_fork = fork_info.height.unwrap();

if let Some(requested) = requested {
let best = self.core_rpc.get_best_chain_lock()?.block_height;

tracing::trace!(
requested,
v20_fork,
mn_rr_fork,
best,
"selecting initial core lock height"
);
// TODO in my opinion, the condition should be:
//
// `v20_fork <= requested && requested <= best`
// `mn_rr_fork <= requested && requested <= best`
//
// but it results in 1440 <= 1243 <= 1545
//
Expand All @@ -65,13 +65,13 @@ where
Err(ExecutionError::InitializationBadCoreLockedHeight {
requested,
best,
v20_fork,
mn_rr_fork,
}
.into())
}
} else {
tracing::trace!(v20_fork, "used fork height as initial core lock height");
Ok(v20_fork)
tracing::trace!(mn_rr_fork, "used fork height as initial core lock height");
Ok(mn_rr_fork)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ mod tests {
)),
FeeResult {
storage_fee: 11556000,
processing_fee: 1253700,
processing_fee: 634380,
fee_refunds: FeeRefunds::default(),
removed_bytes_from_system: 0
}
Expand Down

0 comments on commit d097ef3

Please sign in to comment.