Skip to content

Commit d1c5d93

Browse files
authored
feat(price_pusher): use retry send transaction logic in pusher (#1438)
* Checkpoint * Nits * Nits * fix: type * Bump pusher version
1 parent ee455f1 commit d1c5d93

File tree

7 files changed

+47
-12
lines changed

7 files changed

+47
-12
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

price_pusher/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pythnetwork/price-pusher",
3-
"version": "6.4.2",
3+
"version": "6.4.3",
44
"description": "Pyth Price Pusher",
55
"homepage": "https://pyth.network",
66
"main": "lib/index.js",

price_pusher/src/solana/solana.ts

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
} from "../interface";
88
import { DurationInSeconds } from "../utils";
99
import { PriceServiceConnection } from "@pythnetwork/price-service-client";
10+
import { sendTransactions } from "@pythnetwork/solana-utils";
1011

1112
export class SolanaPriceListener extends ChainPriceListener {
1213
constructor(
@@ -54,13 +55,19 @@ export class SolanaPricePusher implements IPricePusher {
5455
private pythSolanaReceiver: PythSolanaReceiver,
5556
private priceServiceConnection: PriceServiceConnection,
5657
private shardId: number,
57-
private computeUnitPriceMicroLamports: number
58+
private computeUnitPriceMicroLamports: number,
59+
private alreadySending: boolean = false
5860
) {}
5961

6062
async updatePriceFeed(
6163
priceIds: string[],
6264
pubTimesToPush: number[]
6365
): Promise<void> {
66+
if (this.alreadySending) {
67+
console.log(new Date(), "updatePriceFeed already in progress");
68+
return;
69+
}
70+
this.alreadySending = true;
6471
if (priceIds.length === 0) {
6572
return;
6673
}
@@ -83,16 +90,22 @@ export class SolanaPricePusher implements IPricePusher {
8390
this.shardId
8491
);
8592

93+
const transactions = await transactionBuilder.buildVersionedTransactions({
94+
computeUnitPriceMicroLamports: this.computeUnitPriceMicroLamports,
95+
tightComputeBudget: true,
96+
});
97+
8698
try {
87-
await this.pythSolanaReceiver.provider.sendAll(
88-
await transactionBuilder.buildVersionedTransactions({
89-
computeUnitPriceMicroLamports: this.computeUnitPriceMicroLamports,
90-
}),
91-
{ skipPreflight: true }
99+
await sendTransactions(
100+
transactions,
101+
this.pythSolanaReceiver.connection,
102+
this.pythSolanaReceiver.wallet
92103
);
93104
console.log(new Date(), "updatePriceFeed successful");
105+
this.alreadySending = false;
94106
} catch (e: any) {
95107
console.error(new Date(), "updatePriceFeed failed", e);
108+
this.alreadySending = false;
96109
return;
97110
}
98111
}

target_chains/solana/sdk/js/pyth_solana_receiver/src/PythSolanaReceiver.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,13 @@ import {
2828
parsePriceFeedMessage,
2929
} from "@pythnetwork/price-service-sdk";
3030
import {
31+
INIT_ENCODED_VAA_COMPUTE_BUDGET,
3132
POST_UPDATE_ATOMIC_COMPUTE_BUDGET,
3233
POST_UPDATE_COMPUTE_BUDGET,
34+
UPDATE_PRICE_FEED_COMPUTE_BUDGET,
3335
VERIFY_ENCODED_VAA_COMPUTE_BUDGET,
3436
} from "./compute_budget";
35-
import { Wallet } from "@coral-xyz/anchor/dist/cjs/provider";
37+
import { Wallet } from "@coral-xyz/anchor";
3638
import {
3739
buildEncodedVaaCreateInstruction,
3840
buildWriteEncodedVaaWithSplitInstructions,
@@ -464,6 +466,7 @@ export class PythSolanaReceiver {
464466
})
465467
.instruction(),
466468
signers: [],
469+
computeUnits: INIT_ENCODED_VAA_COMPUTE_BUDGET,
467470
});
468471

469472
postInstructions.push(
@@ -634,7 +637,7 @@ export class PythSolanaReceiver {
634637
})
635638
.instruction(),
636639
signers: [],
637-
computeUnits: POST_UPDATE_COMPUTE_BUDGET,
640+
computeUnits: UPDATE_PRICE_FEED_COMPUTE_BUDGET,
638641
});
639642

640643
priceFeedIdToPriceUpdateAccount[

target_chains/solana/sdk/js/pyth_solana_receiver/src/compute_budget.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,15 @@ export const POST_UPDATE_ATOMIC_COMPUTE_BUDGET = 170000;
1010
* A hard-coded budget for the compute units required for the `postUpdate` instruction in the Pyth Solana Receiver program.
1111
*/
1212
export const POST_UPDATE_COMPUTE_BUDGET = 35000;
13+
/**
14+
* A hard-coded budget for the compute units required for the `updatePriceFeed` instruction in the Pyth Push Oracle program.
15+
*/
16+
export const UPDATE_PRICE_FEED_COMPUTE_BUDGET = 190000;
17+
/**
18+
* A hard-coded budget for the compute units required for the `initEncodedVaa` instruction in the Wormhole program.
19+
*/
20+
export const INIT_ENCODED_VAA_COMPUTE_BUDGET = 3000;
21+
/**
22+
* A hard-coded budget for the compute units required for the `writeEncodedVaa` instruction in the Wormhole program.
23+
*/
24+
export const WRITE_ENCODED_VAA_COMPUTE_BUDGET = 3000;

target_chains/solana/sdk/js/pyth_solana_receiver/src/vaa.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Keypair, PublicKey } from "@solana/web3.js";
22
import { WormholeCoreBridgeSolana } from "./idl/wormhole_core_bridge_solana";
33
import { Program } from "@coral-xyz/anchor";
44
import { InstructionWithEphemeralSigners } from "@pythnetwork/solana-utils";
5+
import { WRITE_ENCODED_VAA_COMPUTE_BUDGET } from "./compute_budget";
56

67
/**
78
* Get the index of the guardian set that signed a VAA
@@ -111,6 +112,7 @@ export async function buildWriteEncodedVaaWithSplitInstructions(
111112
})
112113
.instruction(),
113114
signers: [],
115+
computeUnits: WRITE_ENCODED_VAA_COMPUTE_BUDGET,
114116
},
115117
{
116118
instruction: await wormhole.methods
@@ -123,6 +125,7 @@ export async function buildWriteEncodedVaaWithSplitInstructions(
123125
})
124126
.instruction(),
125127
signers: [],
128+
computeUnits: WRITE_ENCODED_VAA_COMPUTE_BUDGET,
126129
},
127130
];
128131
}

target_chains/solana/sdk/js/solana_utils/src/transaction.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ export async function sendTransactions(
378378
const signatures: string[] = [];
379379

380380
// Signing logic for versioned transactions is different from legacy transactions
381-
for (const transaction of transactions) {
381+
for (const [index, transaction] of transactions.entries()) {
382382
const signers = transaction.signers;
383383
let tx = transaction.tx;
384384

@@ -439,7 +439,11 @@ export async function sendTransactions(
439439
break;
440440
}
441441
console.log(
442-
"Retrying transaction: ",
442+
"Retrying transaction ",
443+
index,
444+
" of ",
445+
transactions.length - 1,
446+
" with signature: ",
443447
txSignature,
444448
" Retry count: ",
445449
retryCount

0 commit comments

Comments
 (0)