Skip to content

Commit b72305a

Browse files
committed
various clean-ups for bugs
1 parent 2020121 commit b72305a

File tree

7 files changed

+405
-276
lines changed

7 files changed

+405
-276
lines changed

src/commands/helper/activity.ts

Lines changed: 59 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ enum Layer {
1818
export default class HelperActivity extends Command {
1919
private providers: Record<Layer, ethers.JsonRpcProvider> = {} as Record<Layer, ethers.JsonRpcProvider>;
2020
private rpcUrls: Record<Layer, string> = {} as Record<Layer, string>;
21+
private flags: any;
22+
private nonceTrackers: Record<Layer, number> = {} as Record<Layer, number>;
2123

2224
static description = 'Generate transactions on the specified network(s) to produce more blocks'
2325

@@ -60,10 +62,30 @@ export default class HelperActivity extends Command {
6062
char: 'r',
6163
description: 'RPC URL (overrides config for both layers)',
6264
}),
65+
debug: Flags.boolean({
66+
char: 'd',
67+
default: false,
68+
description: 'Enable debug mode for more detailed logging',
69+
}),
70+
}
71+
72+
private debugLog(message: string): void {
73+
if (this.flags && this.flags.debug) {
74+
this.log(chalk.gray(`[DEBUG] ${message}`))
75+
}
76+
}
77+
78+
private async initializeNonceTrackers(wallets: Record<Layer, ethers.Wallet>) {
79+
for (const [layer, wallet] of Object.entries(wallets)) {
80+
const nonce = await wallet.getNonce();
81+
this.nonceTrackers[layer as Layer] = nonce;
82+
this.debugLog(`Initialized nonce for ${layer}: ${nonce}`);
83+
}
6384
}
6485

6586
public async run(): Promise<void> {
6687
const { flags } = await this.parse(HelperActivity)
88+
this.flags = flags // Assign parsed flags to the instance property
6789

6890
const configPath = path.resolve(flags.config)
6991
const config = parseTomlConfig(configPath)
@@ -142,22 +164,23 @@ export default class HelperActivity extends Command {
142164
`Sender: ${publicKey} | Recipient: ${recipientAddr}`,
143165
),
144166
)
167+
}
145168

146-
// eslint-disable-next-line no-constant-condition
147-
layers.map(async (layer) => {
148-
while (true) {
149-
for (const layer of layers) {
150-
// eslint-disable-next-line no-await-in-loop
151-
await this.sendTransaction(wallets[layer], recipientAddr, layer)
152-
}
169+
await this.initializeNonceTrackers(wallets);
153170

154-
// eslint-disable-next-line no-await-in-loop, no-promise-executor-return
155-
await new Promise((resolve) => setTimeout(resolve, flags.interval * 1000))
171+
// eslint-disable-next-line no-constant-condition
172+
layers.map(async (layer) => {
173+
while (true) {
174+
for (const layer of layers) {
175+
// eslint-disable-next-line no-await-in-loop
176+
await this.sendTransaction(wallets[layer], recipientAddr, layer)
156177
}
157178

158-
})
159-
}
179+
// eslint-disable-next-line no-await-in-loop, no-promise-executor-return
180+
await new Promise((resolve) => setTimeout(resolve, flags.interval * 1000))
181+
}
160182

183+
})
161184
}
162185

163186
private async replaceTransactions(wallet: ethers.Wallet, startNonce: number, endNonce: number, layer: Layer) {
@@ -210,11 +233,24 @@ export default class HelperActivity extends Command {
210233

211234
private async sendTransaction(wallet: ethers.Wallet, recipient: string, layer: Layer) {
212235
try {
236+
this.debugLog(`Preparing transaction for ${layer.toUpperCase()}`)
237+
this.debugLog(`Sender: ${wallet.address}, Recipient: ${recipient}`)
238+
239+
const currentNonce = this.nonceTrackers[layer];
240+
this.debugLog(`Current nonce for ${layer}: ${currentNonce}`);
241+
213242
const tx = await wallet.sendTransaction({
214243
to: recipient,
215244
value: ethers.parseUnits('0.1', 'gwei'),
245+
nonce: currentNonce,
216246
})
217247

248+
this.debugLog(`Transaction created: ${JSON.stringify(tx, null, 2)}`)
249+
250+
// Increment the nonce tracker immediately after sending the transaction
251+
this.nonceTrackers[layer]++;
252+
this.debugLog(`Updated nonce for ${layer}: ${this.nonceTrackers[layer]}`);
253+
218254
const timeoutPromise = new Promise((_, reject) =>
219255
setTimeout(() => reject(new Error('Transaction taking longer than expected')), 5000)
220256
);
@@ -223,20 +259,27 @@ export default class HelperActivity extends Command {
223259
const receipt = await Promise.race([tx.wait(), timeoutPromise]) as ethers.TransactionReceipt | null;
224260
if (receipt) {
225261
this.log(chalk.green(`${layer.toUpperCase()} Transaction sent: ${tx.hash} (Block: ${receipt.blockNumber})`))
262+
this.debugLog(`Full receipt: ${JSON.stringify(receipt, null, 2)}`)
226263
} else {
227264
this.log(chalk.yellow(`${layer.toUpperCase()} Transaction sent: ${tx.hash} (Receipt not available)`))
228265
}
229266
} catch (timeoutError) {
230267
this.log(chalk.yellow(`${layer.toUpperCase()} Transaction sent, but taking longer than expected: ${tx.hash}`))
231-
this.log(`${JSON.stringify(tx)}`)
268+
this.debugLog(`Timeout error: ${timeoutError}`)
232269
}
233270
} catch (error) {
234271
this.log(
235272
chalk.red(
236-
`Failed to send ${layer.toUpperCase()} transaction: ${error instanceof Error ? error.message : 'Unknown error'
237-
}`,
238-
),
273+
`Failed to send ${layer.toUpperCase()} transaction: ${error instanceof Error ? error.message : 'Unknown error'}`
274+
)
239275
)
276+
if (error instanceof Error) {
277+
this.debugLog(`Error stack: ${error.stack}`)
278+
if ('code' in error) {
279+
this.debugLog(`Error code: ${(error as any).code}`)
280+
}
281+
}
282+
this.debugLog(`Full error object: ${JSON.stringify(error, null, 2)}`)
240283
}
241284
}
242-
}
285+
}

src/commands/helper/fund-accounts.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,14 @@ export default class HelperFundAccounts extends Command {
124124
this.blockExplorers.l1.blockExplorerURI = config?.frontend?.EXTERNAL_EXPLORER_URI_L1
125125
this.blockExplorers.l2.blockExplorerURI = config?.frontend?.EXTERNAL_EXPLORER_URI_L2
126126

127-
this.l1ETHGateway = config?.contracts?.L1_ETH_GATEWAY_PROXY_ADDR
127+
// Parse config-contracts.toml
128+
const contractsConfigPath = path.resolve(flags.contracts)
129+
const contractsConfig = parseTomlConfig(contractsConfigPath)
130+
this.l1ETHGateway = contractsConfig.L1_ETH_GATEWAY_PROXY_ADDR
128131

129132
if (flags['private-key']) {
130133
this.fundingWallet = new ethers.Wallet(flags['private-key'], this.l1Provider)
131-
} else if (!flags.manual && !flags.dev) {
134+
} else if (!flags.manual) {
132135
this.fundingWallet = new ethers.Wallet(config.accounts.DEPLOYER_PRIVATE_KEY, this.l1Provider)
133136
}
134137

@@ -138,9 +141,6 @@ export default class HelperFundAccounts extends Command {
138141
if (this.altGasTokenEnabled) {
139142
this.log(chalk.yellow('Alternative Gas Token mode is enabled.'))
140143

141-
// Parse config-contracts.toml
142-
const contractsConfigPath = path.resolve(flags.contracts)
143-
const contractsConfig = parseTomlConfig(contractsConfigPath)
144144
this.l1GasTokenGateway = contractsConfig.L1_GAS_TOKEN_GATEWAY_PROXY_ADDR
145145
this.l1GasTokenAddress = contractsConfig.L1_GAS_TOKEN_ADDR
146146

@@ -281,6 +281,8 @@ export default class HelperFundAccounts extends Command {
281281
const gasLimit = BigInt(170_000)
282282
const value = ethers.parseEther((amount + 0.001).toString())
283283

284+
console.log(this.l1ETHGateway);
285+
284286
const l1ETHGateway = new ethers.Contract(
285287
this.l1ETHGateway,
286288
['function depositETH(address _to, uint256 _amount, uint256 _gasLimit) payable'],

src/commands/setup/configs.ts

Lines changed: 33 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ export default class SetupConfigs extends Command {
112112
const config = toml.parse(configContent)
113113

114114
const services = [
115-
'admin-system-backend', 'blockscout', 'bridge-history-api', 'bridge-history-fetcher', 'chain-monitor', 'coordinator-api', 'coordinator-cron',
115+
'admin-system-backend', 'admin-system-cron', 'blockscout', 'bridge-history-api', 'bridge-history-fetcher', 'chain-monitor', 'coordinator-api', 'coordinator-cron',
116116
'gas-oracle', 'l1-explorer', 'l2-sequencer', 'rollup-node'
117117
]
118118

@@ -132,7 +132,8 @@ export default class SetupConfigs extends Command {
132132
// TODO: check privatekey secrets once integrated
133133
private generateEnvContent(service: string, config: any): { [key: string]: string } {
134134
const mapping: Record<string, string[]> = {
135-
'admin-system-backend': ['ADMIN_SYSTEM_BACKEND_DB_CONNECTION_STRING:SCROLL_ADMIN_AUTH_DB_CONFIG', 'ADMIN_SYSTEM_BACKEND_DB_CONNECTION_STRING:SCROLL_ADMIN_DB_CONFIG_DSN', 'ADMIN_SYSTEM_BACKEND_DB_CONNECTION_STRING:SCROLL_ADMION_READ_ONLY_DB_CONFIG_DSN'],
135+
'admin-system-backend': ['ADMIN_SYSTEM_BACKEND_DB_CONNECTION_STRING:SCROLL_ADMIN_AUTH_DB_CONFIG_DSN', 'ADMIN_SYSTEM_BACKEND_DB_CONNECTION_STRING:SCROLL_ADMIN_DB_CONFIG_DSN', 'ADMIN_SYSTEM_BACKEND_DB_CONNECTION_STRING:SCROLL_ADMIN_READ_ONLY_DB_CONFIG_DSN'],
136+
'admin-system-cron': ['ADMIN_SYSTEM_BACKEND_DB_CONNECTION_STRING:SCROLL_ADMIN_AUTH_DB_CONFIG_DSN', 'ADMIN_SYSTEM_BACKEND_DB_CONNECTION_STRING:SCROLL_ADMIN_DB_CONFIG_DSN', 'ADMIN_SYSTEM_BACKEND_DB_CONNECTION_STRING:SCROLL_ADMIN_READ_ONLY_DB_CONFIG_DSN'],
136137
'blockscout': ['BLOCKSCOUT_DB_CONNECTION_STRING:DATABASE_URL'],
137138
'bridge-history-api': ['BRIDGE_HISTORY_DB_CONNECTION_STRING:SCROLL_BRIDGE_HISTORY_DB_DSN'],
138139
'bridge-history-fetcher': ['BRIDGE_HISTORY_DB_CONNECTION_STRING:SCROLL_BRIDGE_HISTORY_DB_DSN'],
@@ -482,39 +483,29 @@ export default class SetupConfigs extends Command {
482483
}
483484

484485
const fileMappings = [
485-
{ source: 'admin-system-backend-config.yaml', target: 'admin-system-backend-config.yaml', prefix: 'admin-system-backend:' },
486-
{ source: 'admin-system-backend-config.yaml', target: 'admin-system-cron-config.yaml', prefix: 'admin-system-cron:' },
487-
{ source: 'balance-checker-config.yaml', target: 'balance-checker-config.yaml', prefix: 'balance-checker:' },
488-
{ source: 'bridge-history-config.yaml', target: 'bridge-history-api-config.yaml', prefix: 'bridge-history-api:' },
489-
{ source: 'bridge-history-config.yaml', target: 'bridge-history-fetcher-config.yaml', prefix: 'bridge-history-fetcher:' },
490-
{ source: 'chain-monitor-config.yaml', target: 'chain-monitor-config.yaml', prefix: 'chain-monitor:' },
491-
{ source: 'coordinator-config.yaml', target: 'coordinator-api-config.yaml', prefix: 'coordinator-api:' },
492-
{ source: 'coordinator-config.yaml', target: 'coordinator-cron-config.yaml', prefix: 'coordinator-cron:' },
493-
{ source: 'frontend-config.yaml', target: 'frontends-config.yaml', prefix: 'frontends:' },
494-
{ source: 'genesis.yaml', target: 'genesis.yaml', prefix: 'scroll-common:' },
495-
{ source: 'rollup-config.yaml', target: 'gas-oracle-config.yaml', prefix: 'gas-oracle:' },
496-
{ source: 'rollup-config.yaml', target: 'rollup-node-config.yaml', prefix: 'rollup-node:' },
497-
{ source: 'rollup-explorer-backend-config.yaml', target: 'rollup-explorer-backend-config.yaml', prefix: 'rollup-explorer-backend:' },
486+
{ source: 'admin-system-backend-config.yaml', target: 'admin-system-backend-config.yaml' },
487+
{ source: 'admin-system-backend-config.yaml', target: 'admin-system-cron-config.yaml' },
488+
{ source: 'balance-checker-config.yaml', target: 'balance-checker-config.yaml' },
489+
{ source: 'bridge-history-config.yaml', target: 'bridge-history-api-config.yaml' },
490+
{ source: 'bridge-history-config.yaml', target: 'bridge-history-fetcher-config.yaml' },
491+
{ source: 'chain-monitor-config.yaml', target: 'chain-monitor-config.yaml' },
492+
{ source: 'coordinator-config.yaml', target: 'coordinator-api-config.yaml' },
493+
{ source: 'coordinator-config.yaml', target: 'coordinator-cron-config.yaml' },
494+
{ source: 'frontend-config.yaml', target: 'frontends-config.yaml' },
495+
{ source: 'genesis.yaml', target: 'genesis.yaml' },
496+
{ source: 'rollup-config.yaml', target: 'gas-oracle-config.yaml' },
497+
{ source: 'rollup-config.yaml', target: 'rollup-node-config.yaml' },
498+
{ source: 'rollup-explorer-backend-config.yaml', target: 'rollup-explorer-backend-config.yaml' },
498499
];
499500

500-
// Read all source files first
501-
const sourceFiles = new Map<string, string>();
501+
// Process all mappings
502502
for (const mapping of fileMappings) {
503503
const sourcePath = path.join(sourceDir, mapping.source);
504-
if (fs.existsSync(sourcePath) && !sourceFiles.has(mapping.source)) {
505-
sourceFiles.set(mapping.source, fs.readFileSync(sourcePath, 'utf8'));
506-
}
507-
}
504+
const targetPath = path.join(targetDir, mapping.target);
508505

509-
// Process all mappings
510-
for (const mapping of fileMappings) {
511-
const content = sourceFiles.get(mapping.source);
512-
if (content) {
513-
const targetPath = path.join(targetDir, mapping.target);
506+
if (fs.existsSync(sourcePath)) {
514507
try {
515-
const indentedContent = content.split('\n').map(line => ` ${line}`).join('\n');
516-
const newContent = `${mapping.prefix}\n${indentedContent}`;
517-
fs.writeFileSync(targetPath, newContent);
508+
fs.copyFileSync(sourcePath, targetPath);
518509
this.log(chalk.green(`Processed file: ${mapping.source} -> ${mapping.target}`));
519510
} catch (error: unknown) {
520511
if (error instanceof Error) {
@@ -529,16 +520,18 @@ export default class SetupConfigs extends Command {
529520
}
530521

531522
// Remove source files after all processing is complete
532-
for (const sourceFile of sourceFiles.keys()) {
533-
const sourcePath = path.join(sourceDir, sourceFile);
534-
try {
535-
fs.unlinkSync(sourcePath);
536-
this.log(chalk.green(`Removed source file: ${sourceFile}`));
537-
} catch (error: unknown) {
538-
if (error instanceof Error) {
539-
this.log(chalk.red(`Error removing file ${sourceFile}: ${error.message}`));
540-
} else {
541-
this.log(chalk.red(`Unknown error removing file ${sourceFile}`));
523+
for (const mapping of fileMappings) {
524+
const sourcePath = path.join(sourceDir, mapping.source);
525+
if (fs.existsSync(sourcePath)) {
526+
try {
527+
fs.unlinkSync(sourcePath);
528+
this.log(chalk.green(`Removed source file: ${mapping.source}`));
529+
} catch (error: unknown) {
530+
if (error instanceof Error) {
531+
this.log(chalk.red(`Error removing file ${mapping.source}: ${error.message}`));
532+
} else {
533+
this.log(chalk.red(`Unknown error removing file ${mapping.source}`));
534+
}
542535
}
543536
}
544537
}
@@ -556,9 +549,7 @@ export default class SetupConfigs extends Command {
556549
if (fs.existsSync(sourcePath)) {
557550
const content = fs.readFileSync(sourcePath, 'utf8');
558551
const yamlContent = {
559-
contracts: {
560-
[file.key]: content,
561-
},
552+
[file.key]: content,
562553
};
563554
const yamlString = yaml.dump(yamlContent, { indent: 2 });
564555
fs.writeFileSync(targetPath, yamlString);

0 commit comments

Comments
 (0)