Kaynağa Gözat

feat: add ending condition to proposer_server (#1430)

* Checkpoint

* Checkpoint

* Continue

* Revert

* Revert

* Revert

* Update proposer

* Clean

* Lint

* nit

* Refactor crank-executor

* Small refactor

* Go

* Go

* Move comment
guibescos 1 yıl önce
ebeveyn
işleme
d627a49764

+ 12 - 3
governance/xc_admin/packages/xc_admin_common/src/propose.ts

@@ -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;
@@ -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");
+      }
     }
   }
 }

+ 16 - 9
target_chains/solana/sdk/js/solana_utils/src/transaction.ts

@@ -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);
@@ -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,
@@ -461,5 +464,9 @@ export async function sendTransactions(
     if (!confirmedTx) {
       throw new Error("Failed to land the transaction");
     }
+
+    signatures.push(txSignature);
   }
+
+  return signatures;
 }