Skip to content

Conversation

@dylankilkenny
Copy link
Member

No description provided.

Signed-off-by: Dylan Kilkenny <[email protected]>
Copilot AI review requested due to automatic review settings October 30, 2025 15:33
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces a comprehensive TypeScript script for bootstrapping and managing Stellar channel accounts in the OpenZeppelin Relayer system. The script automates the creation of signers, relayers, and on-chain account funding while providing validation and repair capabilities.

Key Changes

  • Added a new script create-channel-accounts.ts that manages channel account lifecycle
  • Implements validation and "fix" mode to heal partially created slots
  • Integrates with OpenZeppelin Relayer API and Stellar Horizon for account management

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

let attempt = 0;
while (!submitted && attempt < 2) {
attempt += 1;
const account = new Account(fundingAddress, currentSequence);
Copy link

Copilot AI Oct 30, 2025

Choose a reason for hiding this comment

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

The sequence number is not being incremented after each transaction builder instantiation. This will cause all transactions in the loop to use the same sequence number, leading to tx_bad_seq errors for subsequent transactions. The sequence should be incremented after line 948 with currentSequence = (BigInt(currentSequence) + 1n).toString().

Copilot uses AI. Check for mistakes.
Comment on lines +877 to +888
keypair = Keypair.random();
secretHex = Buffer.from(keypair.rawSecretKey()).toString('hex');
const signerIdentifier = await ensureSigner(signersApi, signerId, secretHex);
signerRecord = { id: signerIdentifier };
signerCreated = true;
} else {
keypair = Keypair.random();
secretHex = Buffer.from(keypair.rawSecretKey()).toString('hex');
const signerIdentifier = await ensureSigner(signersApi, signerId, secretHex);
signerRecord = { id: signerIdentifier };
signerCreated = true;
}
Copy link

Copilot AI Oct 30, 2025

Choose a reason for hiding this comment

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

The nested conditional logic for handling missing relayers (lines 872-889) contains duplicated code blocks that create keypairs and signers. The three branches (lines 875-881, lines 883-888, and the implicit else case) all perform identical operations. This duplication should be consolidated into a single code path.

Suggested change
keypair = Keypair.random();
secretHex = Buffer.from(keypair.rawSecretKey()).toString('hex');
const signerIdentifier = await ensureSigner(signersApi, signerId, secretHex);
signerRecord = { id: signerIdentifier };
signerCreated = true;
} else {
keypair = Keypair.random();
secretHex = Buffer.from(keypair.rawSecretKey()).toString('hex');
const signerIdentifier = await ensureSigner(signersApi, signerId, secretHex);
signerRecord = { id: signerIdentifier };
signerCreated = true;
}
}
keypair = Keypair.random();
secretHex = Buffer.from(keypair.rawSecretKey()).toString('hex');
const signerIdentifier = await ensureSigner(signersApi, signerId, secretHex);
signerRecord = { id: signerIdentifier };
signerCreated = true;

Copilot uses AI. Check for mistakes.
.build();

const transactionXdr = transaction.toXDR();
currentSequence = account.sequenceNumber();
Copy link

Copilot AI Oct 30, 2025

Choose a reason for hiding this comment

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

This line assigns the current sequence number back to itself without incrementing, which is incorrect. After building a transaction, the sequence should be incremented to prepare for the next transaction. This should be currentSequence = (BigInt(account.sequenceNumber()) + 1n).toString() to properly increment the sequence.

Suggested change
currentSequence = account.sequenceNumber();
currentSequence = (BigInt(account.sequenceNumber()) + 1n).toString();

Copilot uses AI. Check for mistakes.
const existingSigner = await fetchSignerRecord(signersApi, signerId);
const existingRelayer = await fetchRelayerRecord(relayersApi, relayerId);

const signerExistedBefore = Boolean(existingSigner);
Copy link

Copilot AI Oct 30, 2025

Choose a reason for hiding this comment

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

Unused variable signerExistedBefore.

Suggested change
const signerExistedBefore = Boolean(existingSigner);

Copilot uses AI. Check for mistakes.
const existingRelayer = await fetchRelayerRecord(relayersApi, relayerId);

const signerExistedBefore = Boolean(existingSigner);
const relayerExistedBefore = Boolean(existingRelayer);
Copy link

Copilot AI Oct 30, 2025

Choose a reason for hiding this comment

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

Unused variable relayerExistedBefore.

Suggested change
const relayerExistedBefore = Boolean(existingRelayer);

Copilot uses AI. Check for mistakes.
Comment on lines +877 to +888
keypair = Keypair.random();
secretHex = Buffer.from(keypair.rawSecretKey()).toString('hex');
const signerIdentifier = await ensureSigner(signersApi, signerId, secretHex);
signerRecord = { id: signerIdentifier };
signerCreated = true;
} else {
keypair = Keypair.random();
secretHex = Buffer.from(keypair.rawSecretKey()).toString('hex');
const signerIdentifier = await ensureSigner(signersApi, signerId, secretHex);
signerRecord = { id: signerIdentifier };
signerCreated = true;
}
Copy link

Copilot AI Oct 30, 2025

Choose a reason for hiding this comment

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

This use of variable 'signerRecord' always evaluates to true.

Suggested change
keypair = Keypair.random();
secretHex = Buffer.from(keypair.rawSecretKey()).toString('hex');
const signerIdentifier = await ensureSigner(signersApi, signerId, secretHex);
signerRecord = { id: signerIdentifier };
signerCreated = true;
} else {
keypair = Keypair.random();
secretHex = Buffer.from(keypair.rawSecretKey()).toString('hex');
const signerIdentifier = await ensureSigner(signersApi, signerId, secretHex);
signerRecord = { id: signerIdentifier };
signerCreated = true;
}
}
keypair = Keypair.random();
secretHex = Buffer.from(keypair.rawSecretKey()).toString('hex');
const signerIdentifier = await ensureSigner(signersApi, signerId, secretHex);
signerRecord = { id: signerIdentifier };
signerCreated = true;

Copilot uses AI. Check for mistakes.
Comment on lines +896 to +898
if (!signerRecord) {
throw new Error(`[${accountName}] Unable to ensure signer state.`);
}
Copy link

Copilot AI Oct 30, 2025

Choose a reason for hiding this comment

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

This negation always evaluates to false.

Suggested change
if (!signerRecord) {
throw new Error(`[${accountName}] Unable to ensure signer state.`);
}

Copilot uses AI. Check for mistakes.
Comment on lines +899 to +904
if (!relayerRecord) {
throw new Error(
`[${accountName}] Unable to determine account address. Consider deleting the relayer and signer manually before rerunning.`
);
}

Copy link

Copilot AI Oct 30, 2025

Choose a reason for hiding this comment

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

This negation always evaluates to false.

Suggested change
if (!relayerRecord) {
throw new Error(
`[${accountName}] Unable to determine account address. Consider deleting the relayer and signer manually before rerunning.`
);
}

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants