Skip to content

Commit 926aa55

Browse files
authored
fix: Make room for compute ixs (#1349)
* Make room for compute ixs * Continue * Fix syntax * Fix contract manager * Go * Refacotr import
1 parent fc916c6 commit 926aa55

File tree

9 files changed

+60
-52
lines changed

9 files changed

+60
-52
lines changed

contract_manager/src/governance.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,9 @@ export class WormholeMultisigProposal {
227227
const signatures = await executeProposal(
228228
proposal,
229229
this.squad,
230-
this.cluster
230+
this.cluster,
231+
this.squad.connection.commitment,
232+
{}
231233
);
232234
const msgs: SubmittedWormholeMessage[] = [];
233235
for (const signature of signatures) {

governance/xc_admin/packages/crank_executor/src/index.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,9 @@ async function run() {
3333
console.log("Trying to execute: ", proposal.publicKey.toBase58());
3434
// If we have previously cancelled because the proposal was failing, don't attempt
3535
if (proposal.cancelled.length == 0) {
36-
await executeProposal(
37-
proposal,
38-
squad,
39-
CLUSTER,
40-
COMMITMENT,
41-
COMPUTE_UNIT_PRICE_MICROLAMPORTS
42-
);
36+
await executeProposal(proposal, squad, CLUSTER, COMMITMENT, {
37+
computeUnitPriceMicroLamports: COMPUTE_UNIT_PRICE_MICROLAMPORTS,
38+
});
4339
} else {
4440
console.log("Skipping: ", proposal.publicKey.toBase58());
4541
}

governance/xc_admin/packages/proposer_server/src/index.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,9 @@ app.post("/api/propose", async (req: Request, res: Response) => {
8383

8484
// preserve the existing API by returning only the first pubkey
8585
const proposalPubkey = (
86-
await vault.proposeInstructions(
87-
instructions,
88-
cluster,
89-
COMPUTE_UNIT_PRICE_MICROLAMPORTS
90-
)
86+
await vault.proposeInstructions(instructions, cluster, {
87+
computeUnitPriceMicroLamports: COMPUTE_UNIT_PRICE_MICROLAMPORTS,
88+
})
9189
)[0];
9290
res.status(200).json({ proposalPubkey: proposalPubkey });
9391
} catch (error) {

governance/xc_admin/packages/xc_admin_common/src/__tests__/TransactionSize.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,12 @@ it("Unit test for getSizeOfTransaction", async () => {
110110
}
111111

112112
const txToSend: Transaction[] =
113-
TransactionBuilder.batchIntoLegacyTransactions(ixsToSend);
113+
TransactionBuilder.batchIntoLegacyTransactions(ixsToSend, {
114+
computeUnitPriceMicroLamports: 50000,
115+
});
114116
expect(
115117
txToSend.map((tx) => tx.instructions.length).reduce((a, b) => a + b)
116-
).toBe(ixsToSend.length);
118+
).toBe(ixsToSend.length + txToSend.length);
117119
expect(
118120
txToSend.every(
119121
(tx) => getSizeOfTransaction(tx.instructions, false) <= PACKET_DATA_SIZE

governance/xc_admin/packages/xc_admin_common/src/executor.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { PythCluster } from "@pythnetwork/client/lib/cluster";
44
import {
55
AccountMeta,
66
Commitment,
7-
ComputeBudgetProgram,
87
PublicKey,
98
SystemProgram,
109
Transaction,
@@ -22,6 +21,10 @@ import {
2221
import { getCreateAccountWithSeedInstruction } from "./deterministic_oracle_accounts";
2322
import { AccountType, parseProductData } from "@pythnetwork/client";
2423
import { AnchorProvider } from "@project-serum/anchor";
24+
import {
25+
TransactionBuilder,
26+
PriorityFeeConfig,
27+
} from "@pythnetwork/solana-utils";
2528

2629
/**
2730
* Returns the instruction to pay the fee for a wormhole postMessage instruction
@@ -64,7 +67,7 @@ export async function executeProposal(
6467
squad: SquadsMesh,
6568
cluster: PythCluster,
6669
commitment: Commitment = "confirmed",
67-
computeUnitPriceMicroLamports?: number
70+
priorityFeeConfig: PriorityFeeConfig
6871
) {
6972
const multisigParser = MultisigParser.fromCluster(cluster);
7073
const signatures: string[] = [];
@@ -133,13 +136,7 @@ export async function executeProposal(
133136
}
134137
}
135138

136-
if (computeUnitPriceMicroLamports !== undefined) {
137-
const params = {
138-
microLamports: computeUnitPriceMicroLamports,
139-
};
140-
const ix = ComputeBudgetProgram.setComputeUnitPrice(params);
141-
transaction.add(ix);
142-
}
139+
TransactionBuilder.addPriorityFee(transaction, priorityFeeConfig);
143140

144141
transaction.add(
145142
await squad.buildExecuteInstruction(

governance/xc_admin/packages/xc_admin_common/src/propose.ts

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@ import {
55
SYSVAR_RENT_PUBKEY,
66
SYSVAR_CLOCK_PUBKEY,
77
SystemProgram,
8-
PACKET_DATA_SIZE,
98
ConfirmOptions,
109
sendAndConfirmRawTransaction,
11-
ComputeBudgetProgram,
1210
} from "@solana/web3.js";
1311
import { BN } from "bn.js";
1412
import { AnchorProvider } from "@coral-xyz/anchor";
@@ -27,8 +25,13 @@ import { MultisigAccount } from "@sqds/mesh/lib/types";
2725
import { mapKey } from "./remote_executor";
2826
import { WORMHOLE_ADDRESS } from "./wormhole";
2927
import { TransactionBuilder } from "@pythnetwork/solana-utils";
28+
import {
29+
PACKET_DATA_SIZE_WITH_ROOM_FOR_COMPUTE_BUDGET,
30+
PriorityFeeConfig,
31+
} from "@pythnetwork/solana-utils";
3032

31-
export const MAX_EXECUTOR_PAYLOAD_SIZE = PACKET_DATA_SIZE - 687; // Bigger payloads won't fit in one addInstruction call when adding to the proposal
33+
export const MAX_EXECUTOR_PAYLOAD_SIZE =
34+
PACKET_DATA_SIZE_WITH_ROOM_FOR_COMPUTE_BUDGET - 687; // Bigger payloads won't fit in one addInstruction call when adding to the proposal
3235
export const MAX_INSTRUCTIONS_PER_PROPOSAL = 256 - 1;
3336
export const MAX_NUMBER_OF_RETRIES = 10;
3437

@@ -262,7 +265,10 @@ export class MultisigVault {
262265
ixToSend.push(await this.activateProposalIx(proposalAddress));
263266
ixToSend.push(await this.approveProposalIx(proposalAddress));
264267

265-
const txToSend = TransactionBuilder.batchIntoLegacyTransactions(ixToSend);
268+
const txToSend = TransactionBuilder.batchIntoLegacyTransactions(
269+
ixToSend,
270+
{}
271+
);
266272
await this.sendAllTransactions(txToSend);
267273
return proposalAddress;
268274
}
@@ -276,8 +282,8 @@ export class MultisigVault {
276282
*/
277283
public async proposeInstructions(
278284
instructions: TransactionInstruction[],
279-
targetCluster?: PythCluster,
280-
computeUnitPriceMicroLamports?: number
285+
targetCluster: PythCluster,
286+
priorityFeeConfig: PriorityFeeConfig = {}
281287
): Promise<PublicKey[]> {
282288
const msAccount = await this.getMultisigAccount();
283289
const newProposals = [];
@@ -367,16 +373,16 @@ export class MultisigVault {
367373
}
368374
}
369375

370-
const txToSend = TransactionBuilder.batchIntoLegacyTransactions(ixToSend);
376+
const txToSend = TransactionBuilder.batchIntoLegacyTransactions(
377+
ixToSend,
378+
priorityFeeConfig
379+
);
371380

372-
await this.sendAllTransactions(txToSend, computeUnitPriceMicroLamports);
381+
await this.sendAllTransactions(txToSend);
373382
return newProposals;
374383
}
375384

376-
async sendAllTransactions(
377-
transactions: Transaction[],
378-
computeUnitPriceMicroLamports?: number
379-
) {
385+
async sendAllTransactions(transactions: Transaction[]) {
380386
const provider = this.getAnchorProvider({
381387
preflightCommitment: "processed",
382388
commitment: "processed",
@@ -385,17 +391,6 @@ export class MultisigVault {
385391
let needToFetchBlockhash = true; // We don't fetch blockhash everytime to save time
386392
let blockhash: string = "";
387393
for (let [index, tx] of transactions.entries()) {
388-
if (computeUnitPriceMicroLamports !== undefined) {
389-
console.log(
390-
`Setting compute unit price: ${computeUnitPriceMicroLamports} microLamports`
391-
);
392-
const params = {
393-
microLamports: computeUnitPriceMicroLamports,
394-
};
395-
const ix = ComputeBudgetProgram.setComputeUnitPrice(params);
396-
tx.add(ix);
397-
}
398-
399394
console.log("Trying to send transaction: " + index);
400395
let numberOfRetries = 0;
401396
let txHasLanded = false;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ import {
3535
import {
3636
TransactionBuilder,
3737
InstructionWithEphemeralSigners,
38+
PriorityFeeConfig,
3839
} from "@pythnetwork/solana-utils";
39-
import { PriorityFeeConfig } from "@pythnetwork/solana-utils/lib/transaction";
4040

4141
export const DEFAULT_TREASURY_ID = 0;
4242

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@ export {
33
getSizeOfCompressedU16,
44
TransactionBuilder,
55
InstructionWithEphemeralSigners,
6+
PACKET_DATA_SIZE_WITH_ROOM_FOR_COMPUTE_BUDGET,
7+
PriorityFeeConfig,
68
} from "./transaction";

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

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,8 @@ export class TransactionBuilder {
199199
}
200200

201201
static batchIntoLegacyTransactions(
202-
instructions: TransactionInstruction[]
202+
instructions: TransactionInstruction[],
203+
priorityFeeConfig: PriorityFeeConfig
203204
): Transaction[] {
204205
const transactionBuilder = new TransactionBuilder(
205206
PublicKey.unique(),
@@ -208,9 +209,11 @@ export class TransactionBuilder {
208209
for (const instruction of instructions) {
209210
transactionBuilder.addInstruction({ instruction, signers: [] });
210211
}
211-
return transactionBuilder.getLegacyTransactions({}).map(({ tx }) => {
212-
return tx;
213-
});
212+
return transactionBuilder
213+
.getLegacyTransactions(priorityFeeConfig)
214+
.map(({ tx }) => {
215+
return tx;
216+
});
214217
}
215218

216219
static async batchIntoVersionedTransactions(
@@ -223,4 +226,17 @@ export class TransactionBuilder {
223226
transactionBuilder.addInstructions(instructions);
224227
return transactionBuilder.getVersionedTransactions(priorityFeeConfig);
225228
}
229+
230+
static addPriorityFee(
231+
transaction: Transaction,
232+
priorityFeeConfig: PriorityFeeConfig
233+
) {
234+
if (priorityFeeConfig.computeUnitPriceMicroLamports) {
235+
transaction.add(
236+
ComputeBudgetProgram.setComputeUnitPrice({
237+
microLamports: priorityFeeConfig.computeUnitPriceMicroLamports,
238+
})
239+
);
240+
}
241+
}
226242
}

0 commit comments

Comments
 (0)