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