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 small issues #49

Merged
merged 5 commits into from
Jun 19, 2024
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
21 changes: 12 additions & 9 deletions .example.env
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
# Application Port - KOA server listens on this port (default 4000).
RELAYER_PORT=4000

# Environment
NODE_ENV=development

SUBNET_URL=https://devnetstats.apothem.network/subnet

PARENTNET_URL=https://devnetstats.apothem.network/devnet

CHECKPOINT_CONTRACT=0x16da2C7caf46D0d7270d68e590A992A90DfcF7ee

PARENTNET_WALLET_PK=0x123
CHECKPOINT_CONTRACT=0x1111111111111111111111111111111111111111
PARENTNET_WALLET_PK=0x1111111111111111111111111111111111111111111111111111111111111111

# # XDC-ZERO. It's optional. Don't uncomment it if not planning to enable it
# PARENTNET_ZERO_CONTRACT=0x1111111111111111111111111111111111111111
# SUBNET_ZERO_CONTRACT=0x1111111111111111111111111111111111111111
# PARENTNET_ZERO_WALLET_PK=0x1111111111111111111111111111111111111111111111111111111111111111

# XDC-ZERO. It's optional. Don't add it if not planning to enable it
SUBNET_ZERO_CONTRACT=0x0000000
PARENTNET_ZERO_CONTRACT=0x0000000
# # Reverse-XDC-ZERO. optional.
# REVERSE_CHECKPOINT_CONTRACT=0x1111111111111111111111111111111111111111
# SUBNET_WALLET_PK=0x1111111111111111111111111111111111111111111111111111111111111111
# SUBNET_ZERO_WALLET_PK=0x1111111111111111111111111111111111111111111111111111111111111111

PARENTNET_WALLET_PK=0x123

PARENTNET_ZERO_WALLET_PK=0x123
MAX_FETCH_BLOCK_SIZE=120

# Notification
SLACK_WEBHOOK=https://hooks.slack.com/services/blablabla
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# API keys and secrets
.env
.env.devnet
.env.testnet

# Dependency directory
node_modules
Expand Down
34 changes: 29 additions & 5 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export interface NotificationConfig {

export interface XdcZeroConfig {
isEnabled: boolean;
isReverseEnabled: boolean;
subnetZeroContractAddress?: string;
parentChainZeroContractAddress?: string;
parentnetWalletPk?: string;
Expand Down Expand Up @@ -57,14 +58,37 @@ const environment = process.env.NODE_ENV || "production";
export const devMode = environment != "production";

const getZeroConfig = (): XdcZeroConfig => {
const isEnabled: boolean = "PARENTNET_ZERO_WALLET_PK" in process.env && "SUBNET_ZERO_WALLET_PK" in process.env && "SUBNET_ZERO_CONTRACT" in process.env && "PARENTNET_ZERO_CONTRACT" in process.env;
return isEnabled ? {
const reqXdcZero = [
"PARENTNET_ZERO_CONTRACT",
"SUBNET_ZERO_CONTRACT",
"PARENTNET_ZERO_WALLET_PK",
"CHECKPOINT_CONTRACT"
];
const reqReverseXdcZero = [
"PARENTNET_ZERO_CONTRACT",
"SUBNET_ZERO_CONTRACT",
"SUBNET_ZERO_WALLET_PK",
"REVERSE_CHECKPOINT_CONTRACT"
];
const isEnabled = reqXdcZero.every(envVar => envVar in process.env);
const isReverseEnabled = reqReverseXdcZero.every(envVar => envVar in process.env);

let parentnetWalletPk = "";
if (isEnabled){
parentnetWalletPk = process.env.PARENTNET_ZERO_WALLET_PK.startsWith("0x") ? process.env.PARENTNET_ZERO_WALLET_PK : `0x${process.env.PARENTNET_ZERO_WALLET_PK}`;
}
let subnetWalletPk = "";
if (isReverseEnabled){
subnetWalletPk = process.env.SUBNET_ZERO_WALLET_PK.startsWith("0x") ? process.env.SUBNET_ZERO_WALLET_PK : `0x${process.env.SUBNET_WALLET_PK}`;
}
return {
isEnabled,
isReverseEnabled,
subnetZeroContractAddress: process.env.SUBNET_ZERO_CONTRACT,
subnetWalletPk: subnetWalletPk,
parentChainZeroContractAddress: process.env.PARENTNET_ZERO_CONTRACT,
parentnetWalletPk: process.env.PARENTNET_ZERO_WALLET_PK.startsWith("0x") ? process.env.PARENTNET_ZERO_WALLET_PK : `0x${process.env.PARENTNET_ZERO_WALLET_PK}`,
subnetWalletPk: process.env.SUBNET_WALLET_PK.startsWith("0x") ? process.env.SUBNET_WALLET_PK : `0x${process.env.SUBNET_WALLET_PK}`
}: { isEnabled: false };
parentnetWalletPk: parentnetWalletPk,
};
};

const config: Config = {
Expand Down
3 changes: 3 additions & 0 deletions src/processors/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ export class Processors {

if (config.xdcZero.isEnabled) {
modes.push(Mode.ZERO);
}

if (config.xdcZero.isReverseEnabled){
modes.push(Mode.REVERSE_ZERO);
}

Expand Down
9 changes: 2 additions & 7 deletions src/service/mainnet/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,9 @@ export class MainnetService {
const blocksPerTx = [30, 15, 5, 1];
//make 1 initial try, this is for when blocks are caught up
if (results.length < blocksPerTx[0]){
try{
this.logger.info("submitDynamic startblock", results[0].blockNum, "pushing", results.length, "blocks,",results.length, "remaining(inclusive) into PARENTNET");
await this.submitTxs(results);
return;
} catch (error){}
}

//loop while reducing tx size
Expand All @@ -147,16 +145,13 @@ export class MainnetService {
while (i < blocksPerTx.length){
const val = blocksPerTx[i];
if (results.length >= val){
try{
this.logger.info("submitDynamic startblock", results[0].blockNum, "pushing", val, "blocks,",results.length, "remaining(inclusive) into PARENTNET");
await this.submitTxs(results.slice(0, val));
results = results.slice(val, results.length);
break; //if push success, reset push size
} catch (error){}
}
if (i < blocksPerTx.length){
i++;
}
i++;
await sleep(3000);
}
}
}
Expand Down
9 changes: 2 additions & 7 deletions src/service/subnet/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,27 +306,22 @@ export class SubnetService {
const blocksPerTx = [20, 10, 5, 1];
//make 1 initial try, this is for when blocks are caught up
if (results.length < blocksPerTx[0]){
try{
this.logger.info("submitDynamic startblock", results[0].blockNum, "pushing", results.length, "blocks,",results.length, "remaining(inclusive) into SUBNET");
await this.submitTxs(results);
return;
} catch (error){}
}
while (results.length) {
let i = 0;
while (i < blocksPerTx.length){
const val = blocksPerTx[i];
if (results.length >= val){
try{
this.logger.info("submitDynamic startblock", results[0].blockNum, "pushing", val, "blocks,", results.length, "remaining(inclusive) into SUBNET");
await this.submitTxs(results.slice(0, val));
results = results.slice(val, results.length);
break; //if push success, reset push size
} catch (error){}
}
if (i < blocksPerTx.length){
i++;
}
i++;
await sleep(3000);
}
}
}
Expand Down
20 changes: 12 additions & 8 deletions src/service/zero/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,23 @@ export class ZeroService {
this.parentnetService = new MainnetService(config.subnet, logger);
this.childnetUrl = config.mainnet.url;
this.parentnetUrl = config.subnet.url;
this.parentnetCSCAddress = config.subnet.smartContractAddress;
this.subnetZeroAddress = config.xdcZero.parentChainZeroContractAddress;
this.parentnetZeroAddress = config.xdcZero.subnetZeroContractAddress;
this.parentnetWalletAccount = privateKeyToAccount(config.xdcZero.subnetWalletPk as Hex);
if (config.xdcZero.isReverseEnabled){
this.parentnetCSCAddress = config.subnet.smartContractAddress;
this.subnetZeroAddress = config.xdcZero.parentChainZeroContractAddress;
this.parentnetZeroAddress = config.xdcZero.subnetZeroContractAddress;
this.parentnetWalletAccount = privateKeyToAccount(config.xdcZero.subnetWalletPk as Hex);
}
} else {
this.childnetService = new SubnetService(config.subnet, logger);
this.parentnetService = new MainnetService(config.mainnet, logger);
this.childnetUrl = config.subnet.url;
this.parentnetUrl = config.mainnet.url;
this.parentnetCSCAddress = config.mainnet.smartContractAddress;
this.subnetZeroAddress = config.xdcZero.subnetZeroContractAddress;
this.parentnetZeroAddress = config.xdcZero.parentChainZeroContractAddress;
this.parentnetWalletAccount = privateKeyToAccount(config.xdcZero.parentnetWalletPk as Hex);
if (config.xdcZero.isEnabled){
this.parentnetCSCAddress = config.mainnet.smartContractAddress;
this.subnetZeroAddress = config.xdcZero.subnetZeroContractAddress;
this.parentnetZeroAddress = config.xdcZero.parentChainZeroContractAddress;
this.parentnetWalletAccount = privateKeyToAccount(config.xdcZero.parentnetWalletPk as Hex);
}
}
}

Expand Down
Loading