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

Allow customisation of node config #1248

Merged
merged 1 commit into from
Jul 11, 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: 1 addition & 1 deletion app/screens/node/Node.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ const Node = ({ history, location }: Props) => {
<Address
key="smesherCoinbase"
type={AddressType.ACCOUNT}
address={coinbase}
address={coinbase || ''}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

because of a fast new flow , we're supporting smeshing from different folders from different configs ( right now each network may have its own smeshing options) , during node restart we're updating and smeshing process and till we're waiting for updates from the node, for 1 ms , we can get new update from the node where the coinbase not updated yet. It is just an issue with the update and react renderer. The user won't see an empty address

Copy link
Contributor Author

Choose a reason for hiding this comment

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

/>,
],
];
Expand Down
1 change: 0 additions & 1 deletion app/vars/ipcConsts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ enum IpcChannel {
SMESHER_START_SMESHING = 'SMESHER_START_SMESHING',
SMESHER_STOP_SMESHING = 'SMESHER_STOP_SMESHING',
SMESHER_GET_COINBASE = 'SMESHER_GET_COINBASE',
SMESHER_SET_COINBASE = 'SMESHER_SET_COINBASE',
SMESHER_GET_MIN_GAS = 'SMESHER_GET_MIN_GAS',
SMESHER_GET_ESTIMATED_REWARDS = 'SMESHER_GET_ESTIMATED_REWARDS',
SMESHER_SET_SETUP_COMPUTE_PROVIDERS = 'SMESHER_SET_SETUP_COMPUTE_PROVIDERS',
Expand Down
105 changes: 38 additions & 67 deletions desktop/SmesherManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,73 +6,56 @@ import { ipcConsts } from '../app/vars';
import {
HexString,
IPCSmesherStartupData,
NodeConfig,
PostProvingOpts,
PostSetupOpts,
PostSetupState,
PostSetupStatus,
} from '../shared/types';
import { configCodecByPath, delay } from '../shared/utils';
import { delay } from '../shared/utils';
import SmesherService from './SmesherService';
import Logger from './logger';
import { readFileAsync, writeFileAsync } from './utils';
import AbstractManager from './AbstractManager';
import StoreService from './storeService';
import { generateGenesisIDFromConfig } from './main/Networks';
import { safeSmeshingOpts } from './main/smeshingOpts';
import { DEFAULT_SMESHING_BATCH_SIZE } from './main/constants';
import {
loadCustomNodeConfig,
loadNodeConfig,
updateSmeshingOpts,
} from './main/NodeConfig';
import {
deleteSmeshingMetadata,
getSmeshingMetadata,
updateSmeshingMetadata,
} from './SmesherMetadataUtils';

import { DEFAULT_SMESHING_BATCH_SIZE } from './main/constants';

const checkDiskSpace = require('check-disk-space');

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

class SmesherManager extends AbstractManager {
private smesherService: SmesherService;

private readonly configFilePath: string;

private genesisID: string;

constructor(
mainWindow: BrowserWindow,
configFilePath: string,
genesisID: string
) {
private netName: string;

constructor(mainWindow: BrowserWindow, genesisID: string, netName: string) {
super(mainWindow);
this.smesherService = new SmesherService();
this.smesherService.createService();
this.configFilePath = configFilePath;
this.genesisID = genesisID;
this.netName = netName;
}

private loadConfig = async () => {
const fileContent = await readFileAsync(this.configFilePath, {
encoding: 'utf-8',
});
return configCodecByPath(this.configFilePath).parse(
fileContent
) as NodeConfig;
};

private writeConfig = async (config) => {
const data = configCodecByPath(this.configFilePath).stringify(config);
await writeFileAsync(this.configFilePath, data);
return true;
};

unsubscribe = () => {
this.smesherService.deactivateProgressStream();
this.smesherService.cancelStreams();
this.unsubscribeIPC();
};

getSmeshingConfig = async () => {
const config = await this.loadConfig();
const config = await loadNodeConfig();
return config.smeshing || {};
};

Expand All @@ -98,6 +81,14 @@ class SmesherManager extends AbstractManager {
);
};

setGenesisID = (id: HexString) => {
this.genesisID = id;
};

setNetName = (netName: string) => {
this.netName = netName;
};

updateSmesherState = async () => {
await this.sendSmesherSettingsAndStartupState();
await this.sendPostSetupProviders();
Expand Down Expand Up @@ -136,7 +127,7 @@ class SmesherManager extends AbstractManager {
postSetupState,
numLabelsWritten,
} = await this.smesherService.getPostSetupStatus();
const nodeConfig = await this.loadConfig();
const nodeConfig = await loadNodeConfig();
const numUnits =
nodeConfig.smeshing?.['smeshing-opts']?.['smeshing-opts-numunits'] || 0;
const maxFileSize =
Expand Down Expand Up @@ -169,7 +160,7 @@ class SmesherManager extends AbstractManager {

sendSmesherConfig = async () => {
// TODO: Merge with `sendSmesherSettingsAndStartupState`
const nodeConfig = await this.loadConfig();
const nodeConfig = await loadNodeConfig();
if (nodeConfig.smeshing && nodeConfig.smeshing['smeshing-opts']) {
const opts = nodeConfig.smeshing['smeshing-opts'];
const freeSpace = await this.checkDiskSpace({
Expand Down Expand Up @@ -223,15 +214,6 @@ class SmesherManager extends AbstractManager {
return this.selectPostFolder({ mainWindow: this.mainWindow });
};
const getCoinbase = () => this.smesherService.getCoinbase();
const setCoinbase = async (_event, { coinbase }) => {
// TODO: Unused handler
const res = await this.smesherService.setCoinbase({ coinbase });
const config = await this.loadConfig();
config.smeshing = config.smeshing || {};
config.smeshing['smeshing-coinbase'] = coinbase;
await this.writeConfig(config);
return res;
};
const getMinGas = () => this.smesherService.getMinGas();
const getEstimatedRewards = () => this.smesherService.getEstimatedRewards();

Expand All @@ -243,25 +225,16 @@ class SmesherManager extends AbstractManager {
deleteFiles: deleteFiles || false,
});
await this.clearSmesherMetadata();
const config = await this.loadConfig();
const genesisId = generateGenesisIDFromConfig(config);
if (deleteFiles) {
config.smeshing = {};
} else {
config.smeshing = {
...config.smeshing,
'smeshing-start': false,
};
}
const smeshingOpts = safeSmeshingOpts(config.smeshing, genesisId);
config.smeshing = smeshingOpts;
await this.writeConfig(config);
StoreService.set(`smeshing.${genesisId}`, smeshingOpts);

await updateSmeshingOpts(
this.netName,
deleteFiles ? {} : { 'smeshing-start': false }
);

return res?.error;
}
);
ipcMain.handle(ipcConsts.SMESHER_GET_COINBASE, getCoinbase);
ipcMain.handle(ipcConsts.SMESHER_SET_COINBASE, setCoinbase);
ipcMain.handle(ipcConsts.SMESHER_GET_MIN_GAS, getMinGas);
ipcMain.handle(
ipcConsts.SMESHER_GET_ESTIMATED_REWARDS,
Expand All @@ -272,7 +245,6 @@ class SmesherManager extends AbstractManager {
ipcMain.removeHandler(ipcConsts.SMESHER_SELECT_POST_FOLDER);
ipcMain.removeHandler(ipcConsts.SMESHER_STOP_SMESHING);
ipcMain.removeHandler(ipcConsts.SMESHER_GET_COINBASE);
ipcMain.removeHandler(ipcConsts.SMESHER_SET_COINBASE);
ipcMain.removeHandler(ipcConsts.SMESHER_GET_MIN_GAS);
ipcMain.removeHandler(ipcConsts.SMESHER_GET_ESTIMATED_REWARDS);
};
Expand All @@ -298,7 +270,7 @@ class SmesherManager extends AbstractManager {
maxFileSize,
} = postSetupOpts;
const { nonces, threads } = provingOpts;
const prevOpts = StoreService.get(`smeshing.${genesisID}`);
const customNodeConfig = await loadCustomNodeConfig(this.netName);
const opts = safeSmeshingOpts(
{
'smeshing-coinbase': coinbase,
Expand All @@ -308,25 +280,24 @@ class SmesherManager extends AbstractManager {
'smeshing-opts-numunits': numUnits,
'smeshing-opts-provider': provider,
'smeshing-opts-throttle': throttle,
'smeshing-opts-compute-batch-size': R.pathOr(
DEFAULT_SMESHING_BATCH_SIZE,
['smeshing-opts', 'smeshing-opts-compute-batch-size'],
prevOpts
),
},
'smeshing-proving-opts': {
'smeshing-opts-proving-nonces': nonces,
'smeshing-opts-proving-threads': threads,
'smeshing-opts-compute-batch-size': R.pathOr(
DEFAULT_SMESHING_BATCH_SIZE,
['smeshing-opts', 'smeshing-opts-compute-batch-size'],
customNodeConfig?.smeshing || {}
),
},
'smeshing-start': true,
},
genesisID
);
StoreService.set(`smeshing.${genesisID}`, opts);

const config = await this.loadConfig();
config.smeshing = opts;
return this.writeConfig(config);
await updateSmeshingOpts(this.netName, opts);

return true;
};

selectPostFolder = async ({ mainWindow }: { mainWindow: BrowserWindow }) => {
Expand Down
Loading
Loading