소스 검색

Retry uploading of program code after failure (#1156)

* Retry uploading of program code after failure

Uploading of program code intermittently fails, which causes CI tests
to fail. Improve this a little bit.

Signed-off-by: Sean Young <sean@mess.org>
Sean Young 2 년 전
부모
커밋
c01a13d203
1개의 변경된 파일20개의 추가작업 그리고 3개의 파일을 삭제
  1. 20 3
      integration/solana/setup.ts

+ 20 - 3
integration/solana/setup.ts

@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: Apache-2.0
 // SPDX-License-Identifier: Apache-2.0
 
 
-import { Connection, Keypair, LAMPORTS_PER_SOL, PublicKey, BpfLoader, Transaction, SystemProgram, BPF_LOADER_PROGRAM_ID } from '@solana/web3.js';
+import { Connection, Keypair, LAMPORTS_PER_SOL, PublicKey, BpfLoader, Transaction, SystemProgram, BPF_LOADER_PROGRAM_ID, TransactionExpiredBlockheightExceededError } from '@solana/web3.js';
 import { AnchorProvider, Program } from '@project-serum/anchor';
 import { AnchorProvider, Program } from '@project-serum/anchor';
 import fs from 'fs';
 import fs from 'fs';
 
 
@@ -96,7 +96,7 @@ async function setup() {
         fs.writeFileSync(file_name, JSON.stringify(Array.from(key.secretKey)));
         fs.writeFileSync(file_name, JSON.stringify(Array.from(key.secretKey)));
     };
     };
 
 
-    const connection = newConnection();
+    let connection = newConnection();
     const payer = await newAccountWithLamports(connection);
     const payer = await newAccountWithLamports(connection);
 
 
     write_key('payer.key', payer);
     write_key('payer.key', payer);
@@ -117,12 +117,29 @@ async function setup() {
 
 
             console.log(`Loading ${name} at ${program.publicKey}...`);
             console.log(`Loading ${name} at ${program.publicKey}...`);
             const program_so = fs.readFileSync(file);
             const program_so = fs.readFileSync(file);
-            await BpfLoader.load(connection, payer, program, program_so, BPF_LOADER_PROGRAM_ID);
+            for (let retries = 5; retries > 0; retries -= 1) {
+                try {
+                    await BpfLoader.load(connection, payer, program, program_so, BPF_LOADER_PROGRAM_ID);
+                    break;
+                } catch (e) {
+                    if (e instanceof TransactionExpiredBlockheightExceededError) {
+                        console.log(e);
+                        console.log('retrying...');
+                        connection = newConnection();
+                    } else {
+                        throw e;
+                    }
+                }
+            }
             console.log(`Done loading ${name} ...`);
             console.log(`Done loading ${name} ...`);
 
 
             write_key(`${name}.key`, program);
             write_key(`${name}.key`, program);
         }
         }
     }
     }
+
+    // If there was a TransactionExpiredBlockheightExceededError exception, then
+    // setup.ts does not exit. I have no idea why
+    process.exit();
 }
 }
 
 
 function newConnection(): Connection {
 function newConnection(): Connection {