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: calculate genesis id properly #1359

Merged
merged 4 commits into from
Jul 19, 2023
Merged

Fix: calculate genesis id properly #1359

merged 4 commits into from
Jul 19, 2023

Conversation

brusherru
Copy link
Member

@brusherru brusherru commented Jul 14, 2023

It closes #1377

@brusherru brusherru self-assigned this Jul 14, 2023
Copy link
Contributor

@dshulyak dshulyak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there an option to render it after fetching from grpc? it obviously won't change at this point, but in general it would be more robust to trust the local node on this info

@@ -11,7 +12,8 @@ import { toPublicService } from './utils';
//

export const generateGenesisID = (genesisTime: string, extraData: string) => {
return `${toHexString(hash(genesisTime + extraData)).substring(0, 40)}`;
const time = parseISODate(genesisTime).getTime() / 1000;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parseISODate returns milliseconds?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah

Agree about fetching from grpc, but we're indexing networks by genesis id (auto-connect to them, store logs using it and etc) — so we need it earlier (and even if Node does not work).

But probably Smapp should show some alerts in case the calculated genesis id and the one returned from API are different.

dshulyak
dshulyak previously approved these changes Jul 14, 2023
maparr
maparr previously approved these changes Jul 14, 2023
@github-actions
Copy link

Compiled Binaries

@brusherru
Copy link
Member Author

Okay, I just realized that if we will merge and deploy it as is — we will break UX for all Users.
Because Smapp will search for another network, another config file, etc.
We need some more code that will smoothly migrate to the new genesis id.
Like,

const oldGenesisId = legacyFalsyGenesisId(nodeConfig);
if (oldGenesisId === wallet.meta.genesisID) {
  const newGenesisId = genGenesisId(nodeConfig);
  updateWallet({ ..., genesisId: newGenesisId });
  saveCustomNodeConfig(newGenesisId, loadCustomNodeConfig(oldGenesisId));
}

@brusherru
Copy link
Member Author

brusherru commented Jul 18, 2023

It is ready for review.
Please, check it out carefully, because it's a supercritical change! 🙏

How it works:

  • when the User opens a wallet pointing to the network using old-wrong genesis id, it will...
  • "migrate" custom node config and node data dir, but keep PoS data as is
  • it also adds one line in the spacemesh-log just to reference previous logs
  • update the wallet file and change the genesis id to the new one
  • shows Wallet screen as usually

In case you are unlocking such a wallet, while you already have node-config.NEW_ID.json or node-data/NEW_ID — then it won't rename anything and just switch the wallet on proper genesis id.

--
P.S.
The easiest way to test it well — is to back up your Spacemesh/Electron directory every time before unlocking, because Smapp will rename some files there :)

@github-actions
Copy link

Compiled Binaries

@monikasmolarek
Copy link
Collaborator

monikasmolarek commented Jul 18, 2023

Tested on macOS only:

  • Wallet files and wallet screen ok,
  • Logs files ok,
  • POS location and generation ok
  • node-config.GENESIS_ID.json migrated except the "smeshing-proving-opts" (the same behaviour after each pause/restart pos, even on latest release, without switching to any other versions)
Screenshot 2023-07-19 at 00 54 29

Switching between smapp versions, pausing and resuming POS generation caused (the same on pure latest release with no version changing):
Screenshot 2023-07-19 at 00 44 55

@brusherru
Copy link
Member Author

@monikasmolarek This is another issue, reproducible in develop and does not related to genesis id.
So we will need to fix it in a separate PR.

Copy link
Contributor

@maparr maparr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@brusherru brusherru merged commit 58d12ed into develop Jul 19, 2023
8 checks passed
@brusherru brusherru deleted the fix-genesis-id branch July 19, 2023 11:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Calculate correct GenesisID in Smapp
4 participants