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

Revert genesis id migration #1386

Merged
merged 3 commits into from
Jul 20, 2023
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
2 changes: 0 additions & 2 deletions app/StyledApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { getThemeById } from './theme';
import { init } from './sentry';
import WriteFilePermissionError from './screens/modal/WriteFilePermissionError';
import NoInternetConnection from './screens/modal/NoInternetConnection';
import GenesisIDMigrationFailed from './screens/modal/GenesisIDMigrationFailed';

const history = createMemoryHistory();

Expand Down Expand Up @@ -69,7 +68,6 @@ const StyledApp = () => {
))}
<Redirect to="/auth" />
</Switch>
<GenesisIDMigrationFailed />
<WriteFilePermissionError />
<NoInternetConnection />
<CloseAppModal />
Expand Down
6 changes: 2 additions & 4 deletions app/redux/ui/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ import { RootState } from '../../types';

export const getWarnings = (state: RootState) => state.ui.warnings;

export const getWarningByType = <T extends WarningType>(type: T) => (
state: RootState
) =>
export const getWarningByType = (type: WarningType) => (state: RootState) =>
getWarnings(state).find((w) => w.type === type) as
| WarningObject<T>
| WarningObject<WarningType.WriteFilePermission>
| undefined;
125 changes: 0 additions & 125 deletions app/screens/modal/GenesisIDMigrationFailed.tsx

This file was deleted.

8 changes: 3 additions & 5 deletions desktop/main/Networks.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { hash } from '@spacemesh/sm-codec';
import { app } from 'electron';
import { Network, NodeConfig, PublicService } from '../../shared/types';
import { parseISODate } from '../../shared/datetime';
import { toHexString } from '../../shared/utils';
import { getStandaloneNetwork, isTestMode } from '../testMode';
import { fetchJSON, isDevNet } from '../utils';
Expand All @@ -12,8 +11,7 @@ import { toPublicService } from './utils';
//

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

export const generateGenesisIDFromConfig = (nodeConfig: NodeConfig) => {
Expand All @@ -22,8 +20,8 @@ export const generateGenesisIDFromConfig = (nodeConfig: NodeConfig) => {
nodeConfig?.genesis?.['genesis-extra-data']
) {
return generateGenesisID(
nodeConfig.genesis['genesis-time'],
nodeConfig.genesis['genesis-extra-data']
nodeConfig.genesis['genesis-time'] || '',
nodeConfig.genesis['genesis-extra-data'] || ''
);
}

Expand Down
8 changes: 2 additions & 6 deletions desktop/main/sources/currentNetwork.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
iif,
map,
Observable,
share,
Subject,
switchMap,
} from 'rxjs';
Expand All @@ -21,6 +20,7 @@ export default (
) =>
$networks.pipe(
combineLatestWith($runNodeBeforeLogin, $wallet),
distinctUntilChanged(),
switchMap(([_, runNodeOnStart, wallet]) => {
return iif(
() => runNodeOnStart && !wallet,
Expand All @@ -34,12 +34,8 @@ export default (
)
);
}),
distinctUntilChanged(
(prev, next) => prev[0] === next[0] && prev[1] === next[1]
),
map(
([networks, genesisID]) =>
find((net) => net.genesisID === genesisID, networks) || null
),
share()
)
);
5 changes: 0 additions & 5 deletions desktop/main/sources/fetchDiscovery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import { handleIPC, handlerResult, makeSubscription } from '../rx.utils';
import { fetchNodeConfig } from '../../utils';
import { Managers } from '../app.types';
import Logger from '../../logger';
import { getWrongGenesisID } from '../../migrations/migrateWrongGenesisId';

const logger = Logger({ className: 'fetchDiscovery' });

Expand All @@ -51,10 +50,6 @@ export const withGenesisID = () =>
(net, i): Network => ({
...net,
genesisID: generateGenesisIDFromConfig(configs[i]),
_wrongGenesisID: getWrongGenesisID(
configs[i].genesis['genesis-time'],
configs[i].genesis['genesis-extra-data']
),
})
);
})
Expand Down
69 changes: 5 additions & 64 deletions desktop/main/sources/wallet.ipc.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { resolve } from 'path';
import * as R from 'ramda';
import {
combineLatest,
Expand Down Expand Up @@ -34,7 +33,6 @@ import {
} from '../../../shared/ipcMessages';
import { Network, Wallet, WalletType } from '../../../shared/types';
import {
getShortGenesisId,
isLocalNodeApi,
isRemoteNodeApi,
stringifySocketAddress,
Expand Down Expand Up @@ -64,9 +62,6 @@ import {
WRONG_PASSWORD_MESSAGE,
} from '../walletFile';
import { getLocalNodeConnectionConfig } from '../utils';
import migrateWrongGenesisId from '../../migrations/migrateWrongGenesisId';
import { getCustomNodeConfigPath } from '../NodeConfig';
import StoreService from '../../storeService';

type WalletData = {
// path to wallet file
Expand Down Expand Up @@ -172,65 +167,11 @@ const handleWalletIpcRequests = (
handleIPC(
ipcConsts.W_M_UNLOCK_WALLET,
({ path, password }: UnlockWalletRequest) =>
loadAndMigrateWallet$(path, password).pipe(
withLatestFrom($networks),
map(([res, networks]) => {
if (res[0]) return res;
const { wallet } = res[1];
const gId = wallet.meta.genesisID;
const netByOldId = networks.find((n) => n._wrongGenesisID === gId);
if (!netByOldId) return res;
// Switch to the new id of the same network automatically
// and update the wallet file
// https://github.com/spacemeshos/smapp/issues/1377
migrateWrongGenesisId(
netByOldId._wrongGenesisID,
netByOldId.genesisID
).catch((error) => {
logger.error('Cannot migrate Genesis ID:', error, netByOldId);
const nodeDataDir = StoreService.get('node.dataPath');
$warnings.next(
Warning.fromError(
WarningType.GenesisIDMigrationFailed,
{
nodeConfig: {
prev: getCustomNodeConfigPath(netByOldId._wrongGenesisID),
next: getCustomNodeConfigPath(netByOldId.genesisID),
},
nodeData: {
prev: resolve(
nodeDataDir,
getShortGenesisId(netByOldId._wrongGenesisID)
),
next: resolve(
nodeDataDir,
getShortGenesisId(netByOldId.genesisID)
),
},
},
error
)
);
});
return handlerResult(<WalletData>{
...res[1],
wallet: {
...wallet,
meta: {
...wallet.meta,
genesisID: netByOldId.genesisID,
},
},
save: true,
});
})
),
({ wallet }): UnlockWalletResponse['payload'] => {
return {
meta: wallet.meta,
forceNetworkSelection: false,
};
}
loadAndMigrateWallet$(path, password),
({ wallet }): UnlockWalletResponse['payload'] => ({
meta: wallet.meta,
forceNetworkSelection: false,
})
),
//
handleIPC(
Expand Down
72 changes: 0 additions & 72 deletions desktop/migrations/migrateWrongGenesisId.ts

This file was deleted.

Loading
Loading