Skip to content

Commit

Permalink
[contract_manager] make solana rpcs configurable (#1646)
Browse files Browse the repository at this point in the history
I'm hitting errors using the mainnet-beta endpoint when trying to deploy the entropy contract. This change makes the RPCs configurable in the functions so I can pass in a different RPC in the script.

The right thing to do here is probably to load the solana rpc urls from configuration files in the chains directory, but doesn't seem worth it to do that now.
  • Loading branch information
jayantk authored May 31, 2024
1 parent 0763cb0 commit 223559e
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions contract_manager/src/governance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ class InvalidTransactionError extends Error {
}
}

// A registry of solana RPC nodes for each cluster.
export type SolanaRpcRegistry = (cluster: PythCluster) => string;

export class SubmittedWormholeMessage {
constructor(
public emitter: PublicKey,
Expand All @@ -58,12 +61,10 @@ export class SubmittedWormholeMessage {
*/
static async fromTransactionSignature(
signature: string,
cluster: PythCluster
cluster: PythCluster,
registry: SolanaRpcRegistry = getPythClusterApiUrl
): Promise<SubmittedWormholeMessage> {
const connection = new Connection(
getPythClusterApiUrl(cluster),
"confirmed"
);
const connection = new Connection(registry(cluster), "confirmed");

const txDetails = await connection.getParsedTransaction(signature);
const sequenceLogPrefix = "Sequence: ";
Expand Down Expand Up @@ -151,9 +152,12 @@ export class WormholeEmitter {
return this.wallet.publicKey;
}

async sendMessage(payload: Buffer) {
async sendMessage(
payload: Buffer,
registry: SolanaRpcRegistry = getPythClusterApiUrl
) {
const provider = new AnchorProvider(
new Connection(getPythClusterApiUrl(this.cluster), "confirmed"),
new Connection(registry(this.cluster), "confirmed"),
this.wallet,
{
commitment: "confirmed",
Expand Down Expand Up @@ -296,11 +300,11 @@ export class Vault extends Storable {
* The wallet should be a multisig signer of the vault
* @param wallet
*/
public connect(wallet: Wallet): void {
this.squad = SquadsMesh.endpoint(
getPythClusterApiUrl(this.cluster),
wallet
);
public connect(
wallet: Wallet,
registry: SolanaRpcRegistry = getPythClusterApiUrl
): void {
this.squad = SquadsMesh.endpoint(registry(this.cluster), wallet);
}

getSquadOrThrow(): SquadsMesh {
Expand All @@ -311,9 +315,9 @@ export class Vault extends Storable {
/**
* Gets the emitter address of the vault
*/
public async getEmitter() {
public async getEmitter(registry: SolanaRpcRegistry = getPythClusterApiUrl) {
const squad = SquadsMesh.endpoint(
getPythClusterApiUrl(this.cluster),
registry(this.cluster),
new NodeWallet(Keypair.generate()) // dummy wallet
);
return squad.getAuthorityPDA(this.key, 1);
Expand Down

0 comments on commit 223559e

Please sign in to comment.