Skip to content

Commit

Permalink
solana sdk: Fix getIsApproved to check inbox item (#550)
Browse files Browse the repository at this point in the history
* solana sdk: Fix getIsApproved to check inbox item

getIsApproved() was returning true when the VAA was posted, causing
track() to set the receipt state to DestinationInitiated prematurely.
It should check if the inbox item is initialized instead.

Fixes an issue that caused calls to NttManualRoute.complete() to
return early and never actually complete the transfer in rare cases
(receipt.DestinationInitiated === true and inbox item not created).

* throw instead of return false
  • Loading branch information
kev1n-peters authored Nov 13, 2024
1 parent 6b4ea16 commit 764126b
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions solana/ts/sdk/ntt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -800,14 +800,22 @@ export class SolanaNtt<N extends Network, C extends SolanaChains>
}

async getIsApproved(attestation: Ntt.Attestation): Promise<boolean> {
const digest = (attestation as WormholeNttTransceiver.VAA).hash;
const vaaAddress = utils.derivePostedVaaKey(
this.core.address,
Buffer.from(digest)
);

const info = await this.connection.getAccountInfo(vaaAddress);
return info !== null;
if (attestation.payloadName !== "WormholeTransfer") {
throw new Error(`Invalid payload: ${attestation.payloadName}`);
}
const payload = attestation.payload["nttManagerPayload"];
try {
// check that the inbox item was initialized
const inboxItem = await this.program.account.inboxItem.fetch(
this.pdas.inboxItemAccount(attestation.emitterChain, payload)
);
return inboxItem.init;
} catch (e: any) {
if (e.message?.includes("Account does not exist")) {
return false;
}
throw e;
}
}

async *completeInboundQueuedTransfer(
Expand Down

0 comments on commit 764126b

Please sign in to comment.