Skip to content

Commit

Permalink
feat: add ending condition to proposer_server (#1430)
Browse files Browse the repository at this point in the history
* Checkpoint

* Checkpoint

* Continue

* Revert

* Revert

* Revert

* Update proposer

* Clean

* Lint

* nit

* Refactor crank-executor

* Small refactor

* Go

* Go

* Move comment
  • Loading branch information
guibescos authored Apr 9, 2024
1 parent 299dec1 commit d627a49
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
15 changes: 12 additions & 3 deletions governance/xc_admin/packages/xc_admin_common/src/propose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ import NodeWallet from "@coral-xyz/anchor/dist/cjs/nodewallet";
export const MAX_EXECUTOR_PAYLOAD_SIZE =
PACKET_DATA_SIZE_WITH_ROOM_FOR_COMPUTE_BUDGET - 687; // Bigger payloads won't fit in one addInstruction call when adding to the proposal
export const MAX_INSTRUCTIONS_PER_PROPOSAL = 256 - 1;
export const TIMEOUT = 10;
export const MAX_RETRY_SEND = 70;

type SquadInstruction = {
instruction: TransactionInstruction;
Expand Down Expand Up @@ -394,18 +396,25 @@ export class MultisigVault {

for (const [index, tx] of transactions.entries()) {
console.log("Trying transaction: ", index, " of ", transactions.length);
let retry = true;
while (true)

let retries = 0;
while (retries < TIMEOUT) {
try {
await sendTransactions(
[{ tx, signers: [] }],
provider.connection,
this.squad.wallet as NodeWallet
this.squad.wallet as NodeWallet,
MAX_RETRY_SEND
);
break;
} catch (e) {
console.log(e);
retries++;
}
}
if (retries === TIMEOUT) {
throw new Error("Too many retries");
}
}
}
}
Expand Down
25 changes: 16 additions & 9 deletions target_chains/solana/sdk/js/solana_utils/src/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -370,15 +370,18 @@ export async function sendTransactions(
connection: Connection,
wallet: Wallet,
maxRetries?: number
) {
): Promise<string[]> {
const blockhashResult = await connection.getLatestBlockhashAndContext({
commitment: "confirmed",
});

const signatures: string[] = [];

// Signing logic for versioned transactions is different from legacy transactions
for (const transaction of transactions) {
const { signers } = transaction;
const signers = transaction.signers;
let tx = transaction.tx;

if (isVersionedTransaction(tx)) {
if (signers) {
tx.sign(signers);
Expand All @@ -402,14 +405,14 @@ export async function sendTransactions(
let confirmedTx = null;
let retryCount = 0;

try {
// Get the signature of the transaction with different logic for versioned transactions
const txSignature = bs58.encode(
isVersionedTransaction(tx)
? tx.signatures?.[0] || new Uint8Array()
: tx.signature ?? new Uint8Array()
);
// Get the signature of the transaction with different logic for versioned transactions
const txSignature = bs58.encode(
isVersionedTransaction(tx)
? tx.signatures?.[0] || new Uint8Array()
: tx.signature ?? new Uint8Array()
);

try {
const confirmTransactionPromise = connection.confirmTransaction(
{
signature: txSignature,
Expand Down Expand Up @@ -461,5 +464,9 @@ export async function sendTransactions(
if (!confirmedTx) {
throw new Error("Failed to land the transaction");
}

signatures.push(txSignature);
}

return signatures;
}

0 comments on commit d627a49

Please sign in to comment.