فهرست منبع

[message-buffer] improve logging for setup message buffer script (#872)

* chore: better loggging for init script

* fix: change init-buffer script to use npx
swimricky 2 سال پیش
والد
کامیت
91ccaee57c

+ 1 - 1
pythnet/message_buffer/package.json

@@ -3,7 +3,7 @@
   "version": "0.1.0",
   "private": "true",
   "scripts": {
-    "init-buffer": "yarn ts-node scripts/setup_message_buffer.ts"
+    "init-buffer": "npx ts-node scripts/setup_message_buffer.ts"
   },
   "dependencies": {
     "@coral-xyz/anchor": "^0.27.0",

+ 1 - 1
pythnet/message_buffer/scripts/.env.pythtest

@@ -4,6 +4,6 @@ CLUSTER=pythtest-crosschain
 # Whitelist admin will be initialized to same as payer
 # then a separate txn will be used to set it to the following address
 # after the message buffers have been initialized
-# WHITELIST_ADMIN=D8y6qTbQeYQdyrgKUvZbsveQkfnUThRKZvewddr4SKNt # Pythtest Multisig authority address (PDA of executor)
+# WHITELIST_ADMIN=AmqEnGN76cdRYqNUFg44hX47iXwxRqoGsmNZR29UEGJB # Price feed multisig authority
 # 522 + 85(PriceFeedMessage) + 101(TwapMessage) + extra buffer
 INITIAL_SIZE=2048

+ 19 - 14
pythnet/message_buffer/scripts/setup_message_buffer.ts

@@ -271,17 +271,17 @@ async function main() {
 
   const messageBufferKeys = priceIds.map((priceId) => {
     return {
-      messageBufferKey: getMessageBufferPubkey(
+      messageBuffer: getMessageBufferPubkey(
         pythOracleCpiAuth,
         priceId,
         messageBufferPid
       ),
-      priceAccountKey: priceId,
+      priceAccount: priceId,
     };
   });
 
   let accounts = await messageBufferProgram.account.messageBuffer.fetchMultiple(
-    messageBufferKeys.map((k) => k.messageBufferKey)
+    messageBufferKeys.map((k) => k.messageBuffer)
   );
 
   const msgBufferKeysAndData = messageBufferKeys.map((k, i) => {
@@ -291,15 +291,20 @@ async function main() {
     };
   });
 
-  alreadyInitializedAccounts = msgBufferKeysAndData.filter((idAndAccount) => {
-    return idAndAccount.messageBufferData !== null;
-  });
+  alreadyInitializedAccounts = msgBufferKeysAndData
+    .filter((idAndAccount) => {
+      return idAndAccount.messageBufferData !== null;
+    })
+    .map((v) => {
+      return {
+        priceAccount: v.priceAccount.toString(),
+        messageBuffer: v.messageBuffer.toString(),
+      };
+    });
 
   console.log(`
-  ${
-    alreadyInitializedAccounts.length
-  } message buffer accounts already initialized.
-  alreadyInitializedAccounts: ${JSON.stringify(alreadyInitializedAccounts)}`);
+  ${alreadyInitializedAccounts.length} message buffer accounts already initialized`);
+  console.table(alreadyInitializedAccounts);
 
   const priceAccountPubkeysForNewlyInitializedMessageBuffers =
     msgBufferKeysAndData.filter((idAndAccount) => {
@@ -307,15 +312,14 @@ async function main() {
     });
 
   if (priceAccountPubkeysForNewlyInitializedMessageBuffers.length === 0) {
-    console.info(`no new message buffers to initialize. exiting...`);
-    process.exit(1);
+    console.info(`no new message buffers to initialize`);
   }
   // TODO: optimize with batching
   await Promise.all(
     priceAccountPubkeysForNewlyInitializedMessageBuffers.map(
       async (idAndAccount) => {
-        const priceId = idAndAccount.priceAccountKey;
-        const messageBufferPda = idAndAccount.messageBufferKey;
+        const priceId = idAndAccount.priceAccount;
+        const messageBufferPda = idAndAccount.messageBuffer;
         const msgBufferPdaMetas = [
           {
             pubkey: messageBufferPda,
@@ -360,6 +364,7 @@ async function main() {
     console.info(`Accounts with errors: ${JSON.stringify(errorAccounts)}`);
   }
   console.log(`Initialized ${newlyInitializedAccounts.length} accounts`);
+  console.table(newlyInitializedAccounts);
 
   // Update whitelist admin at the end otherwise all the message buffer PDAs
   // will have to be initialized by the whitelist admin (which could be the multisig)