Skip to content

Commit

Permalink
[Validator] Add functionality to switch node operation
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelKim20 committed Mar 7, 2024
1 parent ca45c38 commit 49db0a8
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/validator/config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ setting:
ipfs_gateway_url: "${NODE_IPFS_GATEWAY_URL}"
nptServer: "kr.pool.ntp.org"
nptInterval: 10
enabledNode: true
SECONDS_PER_SLOT: ${SECONDS_PER_SLOT}
SLOTS_PER_EPOCH: ${SLOTS_PER_EPOCH}
GENESIS_TIME: ${GENESIS_TIME}
Expand Down
1 change: 1 addition & 0 deletions packages/validator/config/config_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ setting:
ipfs_gateway_url: "${NODE_IPFS_GATEWAY_URL}"
nptServer: "kr.pool.ntp.org"
nptInterval: 10
enabledNode: true
SECONDS_PER_SLOT: ${SECONDS_PER_SLOT}
SLOTS_PER_EPOCH: ${SLOTS_PER_EPOCH}
GENESIS_TIME: ${GENESIS_TIME}
Expand Down
4 changes: 3 additions & 1 deletion packages/validator/src/DefaultServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ export class DefaultServer extends WebService {
this.node = new Node(this.config, this.storage);

if (!schedules) schedules = [];
schedules.push(new NodeScheduler(this.node));
if (this.config.setting.enabledNode) {
schedules.push(new NodeScheduler(this.node));
}
schedules.forEach((m) => this.schedules.push(m));
this.schedules.forEach((m) =>
m.setOption({
Expand Down
5 changes: 5 additions & 0 deletions packages/validator/src/common/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,7 @@ export class Setting implements ISetting {
public SECONDS_PER_SLOT: number;
public SLOTS_PER_EPOCH: number;
public GENESIS_TIME: bigint;
public enabledNode: boolean;

/**
* Constructor
Expand All @@ -466,6 +467,7 @@ export class Setting implements ISetting {
this.SECONDS_PER_SLOT = defaults.SECONDS_PER_SLOT;
this.SLOTS_PER_EPOCH = defaults.SLOTS_PER_EPOCH;
this.GENESIS_TIME = BigInt(defaults.GENESIS_TIME);
this.enabledNode = defaults.enabledNode;
}

public readFromObject(config: ISetting) {
Expand All @@ -475,6 +477,7 @@ export class Setting implements ISetting {
if (config.SECONDS_PER_SLOT !== undefined) this.SECONDS_PER_SLOT = config.SECONDS_PER_SLOT;
if (config.SLOTS_PER_EPOCH !== undefined) this.SLOTS_PER_EPOCH = config.SLOTS_PER_EPOCH;
if (config.GENESIS_TIME !== undefined) this.GENESIS_TIME = BigInt(config.GENESIS_TIME);
if (config.enabledNode !== undefined) this.enabledNode = config.enabledNode;
}

/**
Expand All @@ -488,6 +491,7 @@ export class Setting implements ISetting {
GENESIS_TIME: 1704067200,
nptServer: "kr.pool.ntp.org",
nptInterval: 10000,
enabledNode: true,
} as unknown as ISetting;
}
}
Expand Down Expand Up @@ -643,6 +647,7 @@ export interface ISetting {
ipfs_gateway_url: string;
nptServer: string;
nptInterval: number;
enabledNode: boolean;
SECONDS_PER_SLOT: number;
SLOTS_PER_EPOCH: number;
GENESIS_TIME: bigint;
Expand Down

0 comments on commit 49db0a8

Please sign in to comment.