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(dashmate): check for DKG before stopping node #1683

Merged
merged 27 commits into from
May 14, 2024
Merged
Changes from 4 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
4fec12e
feat(dashmate): draft DKG window check
pshenmic Jan 24, 2024
3ef382e
feat(dashmate): add DKG check prompt
pshenmic Jan 30, 2024
1e480db
feat(dashmate): skip DKG check for local networks
pshenmic Jan 30, 2024
ba87047
feat(dashmate): lint fix
pshenmic Jan 30, 2024
4aae4fa
Merge branch 'v1.0-dev' into feat/dashmate-dkg-check
pshenmic Mar 14, 2024
6eee4a7
feat(dashmate): replace call with dkginfo
pshenmic Mar 14, 2024
ac5f284
feat(dashmate): check active and next dkgs before stop
pshenmic Mar 14, 2024
f3ddf50
feat(dashmate): replace skip with enable
pshenmic Mar 14, 2024
182009c
feat(dashmate): lint fix
pshenmic Mar 14, 2024
35dbff1
Merge branch 'v1.0-dev' into feat/dashmate-dkg-check
pshenmic Apr 22, 2024
a2422f4
Merge branch 'v1.0-dev' into feat/dashmate-dkg-check
pshenmic May 2, 2024
e66a3f2
feat(dashmate): implement --safe and waitForDKGWindowPass
pshenmic May 5, 2024
09ceb39
feat(dashmate): fix wait func
pshenmic May 5, 2024
b26caf8
feat(dashmate): fix error string
pshenmic May 5, 2024
d661b95
feat(dashmate): add masternode check
pshenmic May 5, 2024
f74e885
feat(dashmate): remove active dkgs check
pshenmic May 5, 2024
89bd966
feat(dashmate): add safe flag for groups
pshenmic May 5, 2024
2af204d
Merge branch 'v1.0-dev' into feat/dashmate-dkg-check
pshenmic May 5, 2024
f92cd56
chore(dashmate): fix lint
pshenmic May 6, 2024
3ed9e05
chore(dashmate): add safe flag to restart command
pshenmic May 6, 2024
8147ac8
fix(dashmate): add --safe flag in the e2e tests
pshenmic May 6, 2024
05d80c3
fix(dashmate): code review fixes
pshenmic May 6, 2024
ad045eb
Merge branch 'v1.0-dev' into feat/dashmate-dkg-check
pshenmic May 6, 2024
00a6814
feat(dashmate): turn off check for fullnodes
pshenmic May 6, 2024
7336c94
fix(dashmate): lint fix
pshenmic May 7, 2024
f7bc2af
Merge branch 'v1.0-dev' into feat/dashmate-dkg-check
pshenmic May 8, 2024
42d6039
fix(dashmate): refactor to do-while
pshenmic May 8, 2024
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
48 changes: 48 additions & 0 deletions packages/dashmate/src/listr/tasks/stopNodeTaskFactory.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
/* eslint-disable no-console */
import lodash from 'lodash';
import { Listr } from 'listr2';
import { NETWORK_LOCAL } from '../../constants.js';

/**
* @param {DockerCompose} dockerCompose
Expand Down Expand Up @@ -34,6 +37,51 @@ export default function stopNodeTaskFactory(
}
},
},
{
title: 'Check node is participating in DKG',
skip: (ctx) => ctx.isForce || config.get('network') === NETWORK_LOCAL,
shumkov marked this conversation as resolved.
Show resolved Hide resolved
task: async (ctx, task) => {
const rpcClient = createRpcClient({
port: config.get('core.rpc.port'),
user: config.get('core.rpc.user'),
pass: config.get('core.rpc.password'),
host: await getConnectionHost(config, 'core', 'core.rpc.host'),
});

const { result: blockCount } = await rpcClient.getBlockCount();

const firstWindow = [Math.floor(blockCount / 24) * 24,
Math.floor(blockCount / 24) * 24 + 10];
const secondWindow = [Math.floor(blockCount / 288) * 288,
Math.floor(blockCount / 288) * 288 + 42];

console.log('BlockCount', blockCount);
console.log(`First window [${firstWindow[0]}, ${firstWindow[1]}]`);
console.log(`Second window [${secondWindow[0]}, ${secondWindow[1]}]`);

const isInFirstWindow = lodash.inRange(blockCount, firstWindow[0], firstWindow[1]);
const isInSecondWindow = lodash.inRange(blockCount, secondWindow[0], secondWindow[1]);

if (isInFirstWindow || isInSecondWindow) {
console.log(`Is in first window = ${isInFirstWindow}`);
console.log(`Is in second window = ${isInSecondWindow}`);

const agreement = await task.prompt({
shumkov marked this conversation as resolved.
Show resolved Hide resolved
type: 'toggle',
name: 'confirm',
header: 'Your node is currently participating in DKG exchange session, restarting may '
+ 'result in PoSE ban.\n Do you want to proceed?',
message: 'Restart node?',
enabled: 'Yes',
disabled: 'No',
});

if (!agreement) {
throw new Error('Node is currently in the DKG window');
}
}
},
},
{
title: 'Save core node time',
enabled: () => config.get('group') === 'local',
Expand Down
Loading