Skip to content

Commit

Permalink
feat(price_pusher): use retry send transaction logic in pusher (#1438)
Browse files Browse the repository at this point in the history
* Checkpoint

* Nits

* Nits

* fix: type

* Bump pusher version
  • Loading branch information
guibescos authored Apr 10, 2024
1 parent ee455f1 commit d1c5d93
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 12 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion price_pusher/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pythnetwork/price-pusher",
"version": "6.4.2",
"version": "6.4.3",
"description": "Pyth Price Pusher",
"homepage": "https://pyth.network",
"main": "lib/index.js",
Expand Down
25 changes: 19 additions & 6 deletions price_pusher/src/solana/solana.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
} from "../interface";
import { DurationInSeconds } from "../utils";
import { PriceServiceConnection } from "@pythnetwork/price-service-client";
import { sendTransactions } from "@pythnetwork/solana-utils";

export class SolanaPriceListener extends ChainPriceListener {
constructor(
Expand Down Expand Up @@ -54,13 +55,19 @@ export class SolanaPricePusher implements IPricePusher {
private pythSolanaReceiver: PythSolanaReceiver,
private priceServiceConnection: PriceServiceConnection,
private shardId: number,
private computeUnitPriceMicroLamports: number
private computeUnitPriceMicroLamports: number,
private alreadySending: boolean = false
) {}

async updatePriceFeed(
priceIds: string[],
pubTimesToPush: number[]
): Promise<void> {
if (this.alreadySending) {
console.log(new Date(), "updatePriceFeed already in progress");
return;
}
this.alreadySending = true;
if (priceIds.length === 0) {
return;
}
Expand All @@ -83,16 +90,22 @@ export class SolanaPricePusher implements IPricePusher {
this.shardId
);

const transactions = await transactionBuilder.buildVersionedTransactions({
computeUnitPriceMicroLamports: this.computeUnitPriceMicroLamports,
tightComputeBudget: true,
});

try {
await this.pythSolanaReceiver.provider.sendAll(
await transactionBuilder.buildVersionedTransactions({
computeUnitPriceMicroLamports: this.computeUnitPriceMicroLamports,
}),
{ skipPreflight: true }
await sendTransactions(
transactions,
this.pythSolanaReceiver.connection,
this.pythSolanaReceiver.wallet
);
console.log(new Date(), "updatePriceFeed successful");
this.alreadySending = false;
} catch (e: any) {
console.error(new Date(), "updatePriceFeed failed", e);
this.alreadySending = false;
return;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ import {
parsePriceFeedMessage,
} from "@pythnetwork/price-service-sdk";
import {
INIT_ENCODED_VAA_COMPUTE_BUDGET,
POST_UPDATE_ATOMIC_COMPUTE_BUDGET,
POST_UPDATE_COMPUTE_BUDGET,
UPDATE_PRICE_FEED_COMPUTE_BUDGET,
VERIFY_ENCODED_VAA_COMPUTE_BUDGET,
} from "./compute_budget";
import { Wallet } from "@coral-xyz/anchor/dist/cjs/provider";
import { Wallet } from "@coral-xyz/anchor";
import {
buildEncodedVaaCreateInstruction,
buildWriteEncodedVaaWithSplitInstructions,
Expand Down Expand Up @@ -464,6 +466,7 @@ export class PythSolanaReceiver {
})
.instruction(),
signers: [],
computeUnits: INIT_ENCODED_VAA_COMPUTE_BUDGET,
});

postInstructions.push(
Expand Down Expand Up @@ -634,7 +637,7 @@ export class PythSolanaReceiver {
})
.instruction(),
signers: [],
computeUnits: POST_UPDATE_COMPUTE_BUDGET,
computeUnits: UPDATE_PRICE_FEED_COMPUTE_BUDGET,
});

priceFeedIdToPriceUpdateAccount[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,15 @@ export const POST_UPDATE_ATOMIC_COMPUTE_BUDGET = 170000;
* A hard-coded budget for the compute units required for the `postUpdate` instruction in the Pyth Solana Receiver program.
*/
export const POST_UPDATE_COMPUTE_BUDGET = 35000;
/**
* A hard-coded budget for the compute units required for the `updatePriceFeed` instruction in the Pyth Push Oracle program.
*/
export const UPDATE_PRICE_FEED_COMPUTE_BUDGET = 190000;
/**
* A hard-coded budget for the compute units required for the `initEncodedVaa` instruction in the Wormhole program.
*/
export const INIT_ENCODED_VAA_COMPUTE_BUDGET = 3000;
/**
* A hard-coded budget for the compute units required for the `writeEncodedVaa` instruction in the Wormhole program.
*/
export const WRITE_ENCODED_VAA_COMPUTE_BUDGET = 3000;
3 changes: 3 additions & 0 deletions target_chains/solana/sdk/js/pyth_solana_receiver/src/vaa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Keypair, PublicKey } from "@solana/web3.js";
import { WormholeCoreBridgeSolana } from "./idl/wormhole_core_bridge_solana";
import { Program } from "@coral-xyz/anchor";
import { InstructionWithEphemeralSigners } from "@pythnetwork/solana-utils";
import { WRITE_ENCODED_VAA_COMPUTE_BUDGET } from "./compute_budget";

/**
* Get the index of the guardian set that signed a VAA
Expand Down Expand Up @@ -111,6 +112,7 @@ export async function buildWriteEncodedVaaWithSplitInstructions(
})
.instruction(),
signers: [],
computeUnits: WRITE_ENCODED_VAA_COMPUTE_BUDGET,
},
{
instruction: await wormhole.methods
Expand All @@ -123,6 +125,7 @@ export async function buildWriteEncodedVaaWithSplitInstructions(
})
.instruction(),
signers: [],
computeUnits: WRITE_ENCODED_VAA_COMPUTE_BUDGET,
},
];
}
8 changes: 6 additions & 2 deletions target_chains/solana/sdk/js/solana_utils/src/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ export async function sendTransactions(
const signatures: string[] = [];

// Signing logic for versioned transactions is different from legacy transactions
for (const transaction of transactions) {
for (const [index, transaction] of transactions.entries()) {
const signers = transaction.signers;
let tx = transaction.tx;

Expand Down Expand Up @@ -439,7 +439,11 @@ export async function sendTransactions(
break;
}
console.log(
"Retrying transaction: ",
"Retrying transaction ",
index,
" of ",
transactions.length - 1,
" with signature: ",
txSignature,
" Retry count: ",
retryCount
Expand Down

0 comments on commit d1c5d93

Please sign in to comment.