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

fix(dashmate): local network starting issues #2394

Merged
merged 2 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .yarn/cache/fsevents-patch-19706e7e35-10.zip
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ export default function getBaseConfigFactory() {
miner: {
enable: false,
interval: '2.5m',
mediantime: null,
address: null,
},
devnet: {
Expand Down
2 changes: 2 additions & 0 deletions packages/dashmate/configs/getConfigFileMigrationsFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -1059,6 +1059,8 @@ export default function getConfigFileMigrationsFactory(homeDir, defaultConfigs)
'1.8.0': (configFile) => {
Object.entries(configFile.configs)
.forEach(([, options]) => {
delete options.core.miner.mediantime;

options.platform.drive.abci.docker.image = 'dashpay/drive:1-dev';
options.platform.dapi.api.docker.image = 'dashpay/dapi:1-dev';
});
Expand Down
6 changes: 1 addition & 5 deletions packages/dashmate/src/config/configJsonSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -349,15 +349,11 @@ export default {
interval: {
$ref: '#/definitions/duration',
},
mediantime: {
type: ['integer', 'null'],
minimum: 0,
},
address: {
type: ['string', 'null'],
},
},
required: ['enable', 'interval', 'mediantime', 'address'],
required: ['enable', 'interval', 'address'],
additionalProperties: false,
},
devnet: {
Expand Down
17 changes: 6 additions & 11 deletions packages/dashmate/src/core/quorum/waitForMasternodeProbes.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { LLMQ_TYPE_TEST } from '../../constants.js';
import wait from '../../util/wait.js';

/**
* Checks all mastrenodoes probes to incterconnected masternodes
*
* @param {RpcClient[]} rpcClients
* @param {Function} bumpMockTime
*
* @return {Promise<boolean>}
*/
async function checkProbes(rpcClients, bumpMockTime) {
async function checkProbes(rpcClients) {
let masternodes = await Promise.all(
rpcClients.map((rpc) => {
const promise = rpc.masternode('status');
Expand All @@ -30,8 +30,6 @@ async function checkProbes(rpcClients, bumpMockTime) {
.find((connection) => connection.llmqType === LLMQ_TYPE_TEST);

if (!llmqConnection) {
await bumpMockTime();

return false;
}

Expand All @@ -49,16 +47,12 @@ async function checkProbes(rpcClients, bumpMockTime) {
// probe is not too old. Probes are retried after 50 minutes, while DKGs consider
// a probe as failed after 60 minutes
if (mnInfo.metaInfo.lastOutboundSuccessElapsed > 55 * 60) {
await bumpMockTime();

return false;
}
// MN is expected to be offline, so let's only check that
// the last probe is not too long ago
} else if (mnInfo.metaInfo.lastOutboundAttemptElapsed > 55 * 60
&& mnInfo.metaInfo.lastOutboundSuccessElapsed > 55 * 60) {
await bumpMockTime();

return false;
}
}
Expand All @@ -72,20 +66,21 @@ async function checkProbes(rpcClients, bumpMockTime) {
/**
*
* @param {RpcClient[]} rpcClients
* @param {Function} bumpMockTime
* @param {number} [timeout]
* @return {Promise<void>}
*/
export default async function waitForMasternodeProbes(rpcClients, bumpMockTime, timeout = 30000) {
export default async function waitForMasternodeProbes(rpcClients, timeout = 30000) {
const deadline = Date.now() + timeout;

let isReady = false;

while (!isReady) {
isReady = await checkProbes(rpcClients, bumpMockTime);
isReady = await checkProbes(rpcClients);

if (Date.now() > deadline) {
throw new Error(`waitForMasternodeProbes deadline of ${timeout} exceeded`);
}

await wait(100);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,12 @@ async function checkQuorumConnections(rpcClient, expectedConnectionsCount) {
*
* @param {RpcClient[]} rpcClients
* @param {number} expectedConnectionsCount
* @param {Function} bumpMockTime
* @param {number} [timeout]
* @return {Promise<void>}
*/
export default async function waitForQuorumConnections(
rpcClients,
expectedConnectionsCount,
bumpMockTime,
timeout = 300000,
) {
const deadline = Date.now() + timeout;
Expand All @@ -58,8 +56,6 @@ export default async function waitForQuorumConnections(
}));

if (readyNodes.size < nodesToWait) {
await bumpMockTime();

await wait(1000);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,15 +212,6 @@ export default function configureCoreTaskFactory(
));

ctx.seedRpcClient = ctx.seedCoreService.getRpcClient();

ctx.mockTime = 0;
ctx.bumpMockTime = async (time = 1) => {
ctx.mockTime += time;

await Promise.all(
ctx.rpcClients.map((rpcClient) => rpcClient.setMockTime(ctx.mockTime)),
);
};
},
},
{
Expand All @@ -232,25 +223,6 @@ export default function configureCoreTaskFactory(
)));
},
},
{
title: 'Set initial mock time',
task: async () => {
// Set initial mock time from the last block
const { result: bestBlockHash } = await ctx.seedRpcClient.getBestBlockHash();
const { result: bestBlock } = await ctx.seedRpcClient.getBlock(bestBlockHash);

await ctx.bumpMockTime(bestBlock.time);

// Sync nodes
await ctx.bumpMockTime();

await generateBlocks(
ctx.seedCoreService,
1,
NETWORK_LOCAL,
);
},
},
{
title: 'Wait for nodes to have the same height',
task: () => waitForNodesToHaveTheSameHeight(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ export default function enableCoreQuorumsTaskFactory(generateBlocks) {
// move forward to next DKG
const blocksUntilNextDKG = 24 - (bestBlockHeight % 24);
if (blocksUntilNextDKG !== 0) {
await ctx.bumpMockTime();

await generateBlocks(
ctx.seedCoreService,
blocksUntilNextDKG,
Expand Down Expand Up @@ -82,7 +80,6 @@ export default function enableCoreQuorumsTaskFactory(generateBlocks) {
await waitForQuorumConnections(
ctx.masternodeRpcClients,
ctx.expectedConnections,
ctx.bumpMockTime,
);

const { result: sporks } = await ctx.seedRpcClient.spork('show');
Expand All @@ -91,12 +88,9 @@ export default function enableCoreQuorumsTaskFactory(generateBlocks) {
if (isSpork21Active) {
await waitForMasternodeProbes(
ctx.masternodeRpcClients,
ctx.bumpMockTime,
);
}

await ctx.bumpMockTime();

await generateBlocks(
ctx.seedCoreService,
2,
Expand All @@ -119,8 +113,6 @@ export default function enableCoreQuorumsTaskFactory(generateBlocks) {
ctx.expectedMembers,
);

await ctx.bumpMockTime();

await generateBlocks(
ctx.seedCoreService,
2,
Expand All @@ -145,8 +137,6 @@ export default function enableCoreQuorumsTaskFactory(generateBlocks) {
ctx.expectedComplaints,
);

await ctx.bumpMockTime();

await generateBlocks(
ctx.seedCoreService,
2,
Expand All @@ -171,8 +161,6 @@ export default function enableCoreQuorumsTaskFactory(generateBlocks) {
ctx.expectedJustifications,
);

await ctx.bumpMockTime();

await generateBlocks(
ctx.seedCoreService,
2,
Expand All @@ -197,8 +185,6 @@ export default function enableCoreQuorumsTaskFactory(generateBlocks) {
ctx.expectedCommitments,
);

await ctx.bumpMockTime();

await generateBlocks(
ctx.seedCoreService,
2,
Expand Down Expand Up @@ -232,8 +218,6 @@ export default function enableCoreQuorumsTaskFactory(generateBlocks) {
{
title: 'Mining final commitment',
task: async (ctx, task) => {
await ctx.bumpMockTime();

await generateBlocks(
ctx.seedCoreService,
1,
Expand All @@ -246,8 +230,6 @@ export default function enableCoreQuorumsTaskFactory(generateBlocks) {
while (!testPlatformQuorumEnabled) {
await wait(300);

await ctx.bumpMockTime();

await generateBlocks(
ctx.seedCoreService,
1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,11 @@ export default function setupLocalPresetTaskFactory(
config.set('core.log.debug.enabled', true);
}

// Although not all nodes are miners, all nodes should be aware of
// the miner interval to be able to sync mocked time
config.set('core.miner.interval', ctx.minerInterval);

config.set('dashmate.helper.api.port', config.get('dashmate.helper.api.port') + (i * 100));

if (config.getName() === 'local_seed') {
config.set('core.miner.interval', ctx.minerInterval);

config.set('description', 'seed node for local network');

config.set('core.masternode.enable', false);
Expand Down
40 changes: 0 additions & 40 deletions packages/dashmate/src/listr/tasks/startGroupNodesTaskFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,46 +82,6 @@ export default function startGroupNodesTaskFactory(
return new Listr(tasks, { concurrent: true });
},
},
{
title: 'Mock core node time',
enabled: () => minerConfig && minerConfig.get('network') === NETWORK_LOCAL,
task: async () => {
// TASK RATIONALE:
// During DKG sessions, nodes can make only 1 quorum request per 10 minutes.
// If mocktime is not adjusted, quorums will start failing to form after some time.
const minerInterval = minerConfig.get('core.miner.interval');
// 2.5 minutes - mimics the behaviour of the real network
const secondsToAdd = 150;

const tasks = configGroup.map((config) => ({
title: `Adjust ${config.getName()} mock time`,
task: async () => {
/* eslint-disable no-useless-escape */
await dockerCompose.execCommand(
config,
'core',
[
'bash',
'-c',
`
response=\$(dash-cli getblockchaininfo);
mocktime=\$(echo \${response} | grep -o -E '\"mediantime\"\: [0-9]+' | cut -d ' ' -f2);
while true; do
mocktime=\$((mocktime + ${secondsToAdd}));
dash-cli setmocktime \$mocktime;
sleep ${minerInterval};
done
`,
],
['--detach'],
);
/* eslint-enable no-useless-escape */
},
}));

return new Listr(tasks, { concurrent: true });
},
},
{
title: 'Start a miner',
enabled: () => minerConfig && minerConfig.get('network') === NETWORK_LOCAL,
Expand Down
1 change: 0 additions & 1 deletion packages/dashmate/templates/core/dash.conf.dot
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ regtest=1
testactivationheight=mn_rr@1000
{{? it.core.spork.address}}sporkaddr={{=it.core.spork.address}}{{?}}
{{? it.core.spork.privateKey}}sporkkey={{=it.core.spork.privateKey}}{{?}}
{{? it.core.miner.mediantime}}mocktime={{=it.core.miner.mediantime}}{{?}}
llmqtestinstantsenddip0024=llmq_test_instantsend

{{?? it.network === 'devnet'}}
Expand Down
Loading