Skip to content

Conversation

@guibescos
Copy link
Contributor

@guibescos guibescos commented Jan 12, 2023

Try to switch to a world where nothing can throw errors.

  • Update decode to not throw and instead return undefined
  • resolveAccountName can't throw

How undefined are handled :

    1. If we don't recognize the program of the instruction, it becomes UnrecognizedProgram implements MultisigInstruction which stores the instruction (useful to print the instruction)
    1. If we don't recognize an instruction in PythMultisigInstruction or WormholeMultisigInstruction the name of the instruction is set to unrecognizedInstruction instead of for example postMessage or addPrice.
    1. If we recognize a postMessage in WormholeMultisigInstruction but we can't deserialize the wormhole payload wormholeMultisigInstruction.governanceAction will be undefined, but the payload is stored in wormholeMultisigInstruction.args.payload

It think it's good to distinguish the 3 cases because the undefined is at a different depth. It ends up being a little bit inconsistent, but ultimately it is because we use anchor to deserialize the instructions and that part somehow breaks the types.

@guibescos guibescos changed the title Governance can be undefined Decoders can't throw Jan 12, 2023
@guibescos guibescos marked this pull request as ready for review January 12, 2023 19:57
} catch {
return undefined;
}

Copy link
Contributor Author

@guibescos guibescos Jan 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

buffer-layout can throw errors, so we need to handle them here so the user of our structs won't have to deal with them

@guibescos guibescos changed the title Decoders can't throw [xc-admin] Decoders can't throw Jan 12, 2023
Copy link
Contributor

@jayantk jayantk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems like a reasonable approach to me.

One thing I'll note is that I don't think you can necessarily decode -> encode if you have an unrecognized instruction. I'm not sure whether that's important though (maybe not)

@guibescos
Copy link
Contributor Author

seems like a reasonable approach to me.

One thing I'll note is that I don't think you can necessarily decode -> encode if you have an unrecognized instruction. I'm not sure whether that's important though (maybe not)

I think you can because the args field of unkwownInstruction contains the instruction data.

@guibescos guibescos merged commit bab7517 into main Jan 13, 2023
@guibescos guibescos deleted the xc-admin/governance-can-be-undefined-2 branch January 13, 2023 02:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants