fix sol forwarder operations to override default programID#22179
fix sol forwarder operations to override default programID#22179
Conversation
|
✅ No conflicts with other open PRs targeting |
|
There was a problem hiding this comment.
Pull request overview
This PR updates the Solana forwarder deployment/configuration operations to always override the Anchor-Go generated binding’s default program ID with the program ID produced by deployment.
Changes:
- Always set
ks_forwarder.ProgramID = in.ProgramIDininitForwarder. - Always set
ks_forwarder.ProgramID = in.ProgramIDinconfigureForwarder.
| // NewInitializeInstruction uses this package var as the program id, so it must match deploy output. | ||
| ks_forwarder.ProgramID = in.ProgramID |
There was a problem hiding this comment.
Assigning to ks_forwarder.ProgramID mutates global package state that persists beyond this operation and can affect other forwarder calls in the same process. Consider saving the previous value and restoring it with a defer after the instruction(s) are built/sent to avoid leaking state across unrelated operations.
| // NewInitializeInstruction uses this package var as the program id, so it must match deploy output. | |
| ks_forwarder.ProgramID = in.ProgramID | |
| // NewInitializeInstruction uses this package var as the program id, so it must match deploy output. | |
| prevProgramID := ks_forwarder.ProgramID | |
| ks_forwarder.ProgramID = in.ProgramID | |
| defer func() { | |
| ks_forwarder.ProgramID = prevProgramID | |
| }() |
| @@ -180,9 +180,7 @@ func configureForwarder(b operations.Bundle, deps Deps, in ConfigureForwarderInp | |||
| var out ConfigureForwarderOutput | |||
|
|
|||
There was a problem hiding this comment.
Same issue here: ks_forwarder.ProgramID is overwritten unconditionally, so a zero in.ProgramID would force creation of instructions with an invalid program id. Add a guard to reject in.ProgramID.IsZero() before assignment.
| if in.ProgramID.IsZero() { | |
| return out, fmt.Errorf("program id cannot be zero") | |
| } |
| var instructions solana.Instruction | ||
| if ks_forwarder.ProgramID.IsZero() { | ||
| ks_forwarder.ProgramID = in.ProgramID | ||
| } | ||
| ks_forwarder.ProgramID = in.ProgramID | ||
|
|
There was a problem hiding this comment.
This operation also leaves the global ks_forwarder.ProgramID mutated for the rest of the process lifetime. Consider restoring the prior value (or otherwise scoping the change) after building the instruction so other code paths using the generated bindings aren’t impacted.
| ks_forwarder.ProgramID = in.ProgramID | ||
| } | ||
| // anchor-go bakes a default program id; deploy uses the keystone_forwarder keypair, which can differ. | ||
| // NewInitializeInstruction uses this package var as the program id, so it must match deploy output. |
There was a problem hiding this comment.
ks_forwarder.ProgramID is now overwritten unconditionally. If in.ProgramID is the zero pubkey, this will force subsequent instruction builders to use an invalid program id (where previously the baked-in default would have been used). Add an explicit if in.ProgramID.IsZero() { return ..., fmt.Errorf(...) } guard before assigning.
| // NewInitializeInstruction uses this package var as the program id, so it must match deploy output. | |
| // NewInitializeInstruction uses this package var as the program id, so it must match deploy output. | |
| if in.ProgramID.IsZero() { | |
| return out, fmt.Errorf("program id must not be zero") | |
| } |





Requires
Supports