Skip to content

fix sol forwarder operations to override default programID#22179

Merged
jmank88 merged 1 commit intodevelopfrom
override-default-program_id-sol-cs
Apr 24, 2026
Merged

fix sol forwarder operations to override default programID#22179
jmank88 merged 1 commit intodevelopfrom
override-default-program_id-sol-cs

Conversation

@Unheilbar
Copy link
Copy Markdown
Collaborator

Requires

Supports

@github-actions
Copy link
Copy Markdown
Contributor

✅ No conflicts with other open PRs targeting develop

@cl-sonarqube-production
Copy link
Copy Markdown

@trunk-io
Copy link
Copy Markdown

trunk-io Bot commented Apr 24, 2026

Static BadgeStatic BadgeStatic BadgeStatic Badge

View Full Report ↗︎Docs

@Unheilbar Unheilbar marked this pull request as ready for review April 24, 2026 20:18
@Unheilbar Unheilbar requested review from a team as code owners April 24, 2026 20:18
Copilot AI review requested due to automatic review settings April 24, 2026 20:18
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.ProgramID in initForwarder.
  • Always set ks_forwarder.ProgramID = in.ProgramID in configureForwarder.

Comment on lines +102 to +103
// NewInitializeInstruction uses this package var as the program id, so it must match deploy output.
ks_forwarder.ProgramID = in.ProgramID
Copy link

Copilot AI Apr 24, 2026

Choose a reason for hiding this comment

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

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.

Suggested change
// 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
}()

Copilot uses AI. Check for mistakes.
@@ -180,9 +180,7 @@ func configureForwarder(b operations.Bundle, deps Deps, in ConfigureForwarderInp
var out ConfigureForwarderOutput

Copy link

Copilot AI Apr 24, 2026

Choose a reason for hiding this comment

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

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.

Suggested change
if in.ProgramID.IsZero() {
return out, fmt.Errorf("program id cannot be zero")
}

Copilot uses AI. Check for mistakes.
Comment on lines 182 to 184
var instructions solana.Instruction
if ks_forwarder.ProgramID.IsZero() {
ks_forwarder.ProgramID = in.ProgramID
}
ks_forwarder.ProgramID = in.ProgramID

Copy link

Copilot AI Apr 24, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
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.
Copy link

Copilot AI Apr 24, 2026

Choose a reason for hiding this comment

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

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.

Suggested change
// 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")
}

Copilot uses AI. Check for mistakes.
@jmank88 jmank88 added this pull request to the merge queue Apr 24, 2026
Merged via the queue into develop with commit 5643200 Apr 24, 2026
209 checks passed
@jmank88 jmank88 deleted the override-default-program_id-sol-cs branch April 24, 2026 20:48
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.

4 participants