fix: Make room for compute ixs (#1349)
* Make room for compute ixs * Continue * Fix syntax * Fix contract manager * Go * Refacotr import
This commit is contained in:
parent
fc916c6496
commit
926aa55f75
|
@ -227,7 +227,9 @@ export class WormholeMultisigProposal {
|
|||
const signatures = await executeProposal(
|
||||
proposal,
|
||||
this.squad,
|
||||
this.cluster
|
||||
this.cluster,
|
||||
this.squad.connection.commitment,
|
||||
{}
|
||||
);
|
||||
const msgs: SubmittedWormholeMessage[] = [];
|
||||
for (const signature of signatures) {
|
||||
|
|
|
@ -33,13 +33,9 @@ async function run() {
|
|||
console.log("Trying to execute: ", proposal.publicKey.toBase58());
|
||||
// If we have previously cancelled because the proposal was failing, don't attempt
|
||||
if (proposal.cancelled.length == 0) {
|
||||
await executeProposal(
|
||||
proposal,
|
||||
squad,
|
||||
CLUSTER,
|
||||
COMMITMENT,
|
||||
COMPUTE_UNIT_PRICE_MICROLAMPORTS
|
||||
);
|
||||
await executeProposal(proposal, squad, CLUSTER, COMMITMENT, {
|
||||
computeUnitPriceMicroLamports: COMPUTE_UNIT_PRICE_MICROLAMPORTS,
|
||||
});
|
||||
} else {
|
||||
console.log("Skipping: ", proposal.publicKey.toBase58());
|
||||
}
|
||||
|
|
|
@ -83,11 +83,9 @@ app.post("/api/propose", async (req: Request, res: Response) => {
|
|||
|
||||
// preserve the existing API by returning only the first pubkey
|
||||
const proposalPubkey = (
|
||||
await vault.proposeInstructions(
|
||||
instructions,
|
||||
cluster,
|
||||
COMPUTE_UNIT_PRICE_MICROLAMPORTS
|
||||
)
|
||||
await vault.proposeInstructions(instructions, cluster, {
|
||||
computeUnitPriceMicroLamports: COMPUTE_UNIT_PRICE_MICROLAMPORTS,
|
||||
})
|
||||
)[0];
|
||||
res.status(200).json({ proposalPubkey: proposalPubkey });
|
||||
} catch (error) {
|
||||
|
|
|
@ -110,10 +110,12 @@ it("Unit test for getSizeOfTransaction", async () => {
|
|||
}
|
||||
|
||||
const txToSend: Transaction[] =
|
||||
TransactionBuilder.batchIntoLegacyTransactions(ixsToSend);
|
||||
TransactionBuilder.batchIntoLegacyTransactions(ixsToSend, {
|
||||
computeUnitPriceMicroLamports: 50000,
|
||||
});
|
||||
expect(
|
||||
txToSend.map((tx) => tx.instructions.length).reduce((a, b) => a + b)
|
||||
).toBe(ixsToSend.length);
|
||||
).toBe(ixsToSend.length + txToSend.length);
|
||||
expect(
|
||||
txToSend.every(
|
||||
(tx) => getSizeOfTransaction(tx.instructions, false) <= PACKET_DATA_SIZE
|
||||
|
|
|
@ -4,7 +4,6 @@ import { PythCluster } from "@pythnetwork/client/lib/cluster";
|
|||
import {
|
||||
AccountMeta,
|
||||
Commitment,
|
||||
ComputeBudgetProgram,
|
||||
PublicKey,
|
||||
SystemProgram,
|
||||
Transaction,
|
||||
|
@ -22,6 +21,10 @@ import {
|
|||
import { getCreateAccountWithSeedInstruction } from "./deterministic_oracle_accounts";
|
||||
import { AccountType, parseProductData } from "@pythnetwork/client";
|
||||
import { AnchorProvider } from "@project-serum/anchor";
|
||||
import {
|
||||
TransactionBuilder,
|
||||
PriorityFeeConfig,
|
||||
} from "@pythnetwork/solana-utils";
|
||||
|
||||
/**
|
||||
* Returns the instruction to pay the fee for a wormhole postMessage instruction
|
||||
|
@ -64,7 +67,7 @@ export async function executeProposal(
|
|||
squad: SquadsMesh,
|
||||
cluster: PythCluster,
|
||||
commitment: Commitment = "confirmed",
|
||||
computeUnitPriceMicroLamports?: number
|
||||
priorityFeeConfig: PriorityFeeConfig
|
||||
) {
|
||||
const multisigParser = MultisigParser.fromCluster(cluster);
|
||||
const signatures: string[] = [];
|
||||
|
@ -133,13 +136,7 @@ export async function executeProposal(
|
|||
}
|
||||
}
|
||||
|
||||
if (computeUnitPriceMicroLamports !== undefined) {
|
||||
const params = {
|
||||
microLamports: computeUnitPriceMicroLamports,
|
||||
};
|
||||
const ix = ComputeBudgetProgram.setComputeUnitPrice(params);
|
||||
transaction.add(ix);
|
||||
}
|
||||
TransactionBuilder.addPriorityFee(transaction, priorityFeeConfig);
|
||||
|
||||
transaction.add(
|
||||
await squad.buildExecuteInstruction(
|
||||
|
|
|
@ -5,10 +5,8 @@ import {
|
|||
SYSVAR_RENT_PUBKEY,
|
||||
SYSVAR_CLOCK_PUBKEY,
|
||||
SystemProgram,
|
||||
PACKET_DATA_SIZE,
|
||||
ConfirmOptions,
|
||||
sendAndConfirmRawTransaction,
|
||||
ComputeBudgetProgram,
|
||||
} from "@solana/web3.js";
|
||||
import { BN } from "bn.js";
|
||||
import { AnchorProvider } from "@coral-xyz/anchor";
|
||||
|
@ -27,8 +25,13 @@ import { MultisigAccount } from "@sqds/mesh/lib/types";
|
|||
import { mapKey } from "./remote_executor";
|
||||
import { WORMHOLE_ADDRESS } from "./wormhole";
|
||||
import { TransactionBuilder } from "@pythnetwork/solana-utils";
|
||||
import {
|
||||
PACKET_DATA_SIZE_WITH_ROOM_FOR_COMPUTE_BUDGET,
|
||||
PriorityFeeConfig,
|
||||
} from "@pythnetwork/solana-utils";
|
||||
|
||||
export const MAX_EXECUTOR_PAYLOAD_SIZE = PACKET_DATA_SIZE - 687; // Bigger payloads won't fit in one addInstruction call when adding to the proposal
|
||||
export const MAX_EXECUTOR_PAYLOAD_SIZE =
|
||||
PACKET_DATA_SIZE_WITH_ROOM_FOR_COMPUTE_BUDGET - 687; // Bigger payloads won't fit in one addInstruction call when adding to the proposal
|
||||
export const MAX_INSTRUCTIONS_PER_PROPOSAL = 256 - 1;
|
||||
export const MAX_NUMBER_OF_RETRIES = 10;
|
||||
|
||||
|
@ -262,7 +265,10 @@ export class MultisigVault {
|
|||
ixToSend.push(await this.activateProposalIx(proposalAddress));
|
||||
ixToSend.push(await this.approveProposalIx(proposalAddress));
|
||||
|
||||
const txToSend = TransactionBuilder.batchIntoLegacyTransactions(ixToSend);
|
||||
const txToSend = TransactionBuilder.batchIntoLegacyTransactions(
|
||||
ixToSend,
|
||||
{}
|
||||
);
|
||||
await this.sendAllTransactions(txToSend);
|
||||
return proposalAddress;
|
||||
}
|
||||
|
@ -276,8 +282,8 @@ export class MultisigVault {
|
|||
*/
|
||||
public async proposeInstructions(
|
||||
instructions: TransactionInstruction[],
|
||||
targetCluster?: PythCluster,
|
||||
computeUnitPriceMicroLamports?: number
|
||||
targetCluster: PythCluster,
|
||||
priorityFeeConfig: PriorityFeeConfig = {}
|
||||
): Promise<PublicKey[]> {
|
||||
const msAccount = await this.getMultisigAccount();
|
||||
const newProposals = [];
|
||||
|
@ -367,16 +373,16 @@ export class MultisigVault {
|
|||
}
|
||||
}
|
||||
|
||||
const txToSend = TransactionBuilder.batchIntoLegacyTransactions(ixToSend);
|
||||
const txToSend = TransactionBuilder.batchIntoLegacyTransactions(
|
||||
ixToSend,
|
||||
priorityFeeConfig
|
||||
);
|
||||
|
||||
await this.sendAllTransactions(txToSend, computeUnitPriceMicroLamports);
|
||||
await this.sendAllTransactions(txToSend);
|
||||
return newProposals;
|
||||
}
|
||||
|
||||
async sendAllTransactions(
|
||||
transactions: Transaction[],
|
||||
computeUnitPriceMicroLamports?: number
|
||||
) {
|
||||
async sendAllTransactions(transactions: Transaction[]) {
|
||||
const provider = this.getAnchorProvider({
|
||||
preflightCommitment: "processed",
|
||||
commitment: "processed",
|
||||
|
@ -385,17 +391,6 @@ export class MultisigVault {
|
|||
let needToFetchBlockhash = true; // We don't fetch blockhash everytime to save time
|
||||
let blockhash: string = "";
|
||||
for (let [index, tx] of transactions.entries()) {
|
||||
if (computeUnitPriceMicroLamports !== undefined) {
|
||||
console.log(
|
||||
`Setting compute unit price: ${computeUnitPriceMicroLamports} microLamports`
|
||||
);
|
||||
const params = {
|
||||
microLamports: computeUnitPriceMicroLamports,
|
||||
};
|
||||
const ix = ComputeBudgetProgram.setComputeUnitPrice(params);
|
||||
tx.add(ix);
|
||||
}
|
||||
|
||||
console.log("Trying to send transaction: " + index);
|
||||
let numberOfRetries = 0;
|
||||
let txHasLanded = false;
|
||||
|
|
|
@ -35,8 +35,8 @@ import {
|
|||
import {
|
||||
TransactionBuilder,
|
||||
InstructionWithEphemeralSigners,
|
||||
PriorityFeeConfig,
|
||||
} from "@pythnetwork/solana-utils";
|
||||
import { PriorityFeeConfig } from "@pythnetwork/solana-utils/lib/transaction";
|
||||
|
||||
export const DEFAULT_TREASURY_ID = 0;
|
||||
|
||||
|
|
|
@ -3,4 +3,6 @@ export {
|
|||
getSizeOfCompressedU16,
|
||||
TransactionBuilder,
|
||||
InstructionWithEphemeralSigners,
|
||||
PACKET_DATA_SIZE_WITH_ROOM_FOR_COMPUTE_BUDGET,
|
||||
PriorityFeeConfig,
|
||||
} from "./transaction";
|
||||
|
|
|
@ -199,7 +199,8 @@ export class TransactionBuilder {
|
|||
}
|
||||
|
||||
static batchIntoLegacyTransactions(
|
||||
instructions: TransactionInstruction[]
|
||||
instructions: TransactionInstruction[],
|
||||
priorityFeeConfig: PriorityFeeConfig
|
||||
): Transaction[] {
|
||||
const transactionBuilder = new TransactionBuilder(
|
||||
PublicKey.unique(),
|
||||
|
@ -208,9 +209,11 @@ export class TransactionBuilder {
|
|||
for (const instruction of instructions) {
|
||||
transactionBuilder.addInstruction({ instruction, signers: [] });
|
||||
}
|
||||
return transactionBuilder.getLegacyTransactions({}).map(({ tx }) => {
|
||||
return tx;
|
||||
});
|
||||
return transactionBuilder
|
||||
.getLegacyTransactions(priorityFeeConfig)
|
||||
.map(({ tx }) => {
|
||||
return tx;
|
||||
});
|
||||
}
|
||||
|
||||
static async batchIntoVersionedTransactions(
|
||||
|
@ -223,4 +226,17 @@ export class TransactionBuilder {
|
|||
transactionBuilder.addInstructions(instructions);
|
||||
return transactionBuilder.getVersionedTransactions(priorityFeeConfig);
|
||||
}
|
||||
|
||||
static addPriorityFee(
|
||||
transaction: Transaction,
|
||||
priorityFeeConfig: PriorityFeeConfig
|
||||
) {
|
||||
if (priorityFeeConfig.computeUnitPriceMicroLamports) {
|
||||
transaction.add(
|
||||
ComputeBudgetProgram.setComputeUnitPrice({
|
||||
microLamports: priorityFeeConfig.computeUnitPriceMicroLamports,
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue