Skip to content

fix(rpc): preserve RPC errors in transfer_transaction source ATA lookup#373

Merged
dev-jodee merged 2 commits intosolana-foundation:release/2.2.0from
raushan728:fix/preserve-rpc-error-in-transfer
Mar 9, 2026
Merged

fix(rpc): preserve RPC errors in transfer_transaction source ATA lookup#373
dev-jodee merged 2 commits intosolana-foundation:release/2.2.0from
raushan728:fix/preserve-rpc-error-in-transfer

Conversation

@raushan728
Copy link
Contributor

@raushan728 raushan728 commented Mar 7, 2026

Source ATA lookup was discarding the real error and always returning
AccountNotFound — RPC failures like rate limits or timeouts now surface
correctly instead of misleading operators.


Open with Devin

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Mar 7, 2026

Greptile Summary

This PR partially fixes RPC error propagation in transfer_transaction by replacing the blanket map_err(|_| KoraError::AccountNotFound(...)) on the source ATA lookup with a pattern-match that only re-wraps genuine AccountNotFound errors and passes all other errors through unchanged (e.g., RPC rate-limits, timeouts, 503s now surface correctly).

Key observations:

  • Fix is correct for source ATA — the map_err closure at line 110-115 correctly discriminates AccountNotFound from other error variants.
  • Same class of bug remains for dest_ata — line 118 uses is_err(), which means any RPC failure during the destination ATA check is silently treated as "account not found", causing an ATA-creation instruction to be inserted even when the account may already exist and the RPC simply errored. This can produce invalid transactions.
  • New tests do not exercise the actual code path — both added tests instantiate the map_err closure directly in test code rather than calling transfer_transaction or mocking CacheUtil::get_account. They provide confidence in the closure semantics but not in the end-to-end propagation through the function.

Confidence Score: 3/5

  • Safe to merge as a partial improvement, but a symmetric RPC-error bug remains on the dest_ata path.
  • The targeted fix is logically correct and an improvement over the prior behavior. However, the identical error-swallowing pattern on the dest_ata check (line 118) means RPC failures can still silently produce incorrect transactions. The new tests also verify only the closure in isolation, not the live propagation path, so regression coverage is weaker than expected.
  • crates/lib/src/rpc_server/method/transfer_transaction.rs — specifically the dest_ata is_err() check at line 118.

Important Files Changed

Filename Overview
crates/lib/src/rpc_server/method/transfer_transaction.rs Fixes source ATA error propagation by preserving non-AccountNotFound errors; however, the analogous dest_ata check still swallows all errors via is_err(), and the new tests verify the closure in isolation rather than through the actual function.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["transfer_transaction()"] --> B["CacheUtil::get_account(source_ata)"]
    B -->|"Ok"| C["CacheUtil::get_account(dest_ata)"]
    B -->|"Err(AccountNotFound)"| E1["KoraError::AccountNotFound(source_ata) ✅ fixed"]
    B -->|"Err(RpcError / other)"| E2["Propagate original error ✅ fixed"]

    C -->|"Ok"| D["Build transfer instruction"]
    C -->|"is_err() — any error"| F["Create ATA instruction ⚠️ swallows RPC errors"]

    D --> G["Build & encode transaction"]
    F --> G
    G --> H["Return TransferTransactionResponse"]

    style E2 fill:#c8f0c8,stroke:#2e7d32
    style E1 fill:#c8f0c8,stroke:#2e7d32
    style F fill:#ffe0b2,stroke:#e65100
Loading

Comments Outside Diff (1)

  1. crates/lib/src/rpc_server/method/transfer_transaction.rs, line 118-124 (link)

    dest_ata check swallows RPC errors identically to the pre-fix source ATA pattern

    Line 118 uses is_err() on the dest_ata lookup, which means any error — including RPC rate-limits, timeouts, or 503s — silently falls through as "account not found" and causes an ATA-creation instruction to be appended. If the destination ATA actually exists but the RPC call failed transiently, the resulting transaction will include a redundant create_associated_token_account instruction that will fail on-chain.

    This is the same class of bug that this PR is fixing for the source ATA, and it exists one call-site below.

    // Current (line 118) – swallows RPC errors
    if CacheUtil::get_account(config, rpc_client, &dest_ata, false).await.is_err() {
    
    // Suggested – only create ATA when the account is genuinely absent
    match CacheUtil::get_account(config, rpc_client, &dest_ata, false).await {
        Ok(_) => {}
        Err(KoraError::AccountNotFound(_)) => {
            instructions.push(token_program.create_associated_token_account_instruction(
                &signer_pubkey,
                &destination,
                &token_mint.address(),
            ));
        }
        Err(other) => return Err(other),
    }

Last reviewed commit: 07c9a1f

@raushan728
Copy link
Contributor Author

Fixed the dest_ata check at line 118 as well — replaced .is_err() with a
match that only creates ATA on genuine AccountNotFound, and propagates
real RPC errors (rate limits, timeouts) to the caller.

Copy link

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 2 additional findings.

Open in Devin Review

@github-actions
Copy link

github-actions bot commented Mar 9, 2026

✅ Fork external live tests passed.

fork-external-live-pass:aac08be5ee9e85224c60cff1caa471d31ccd6a68
run: https://github.com/solana-foundation/kora/actions/runs/22861616305

@dev-jodee dev-jodee merged commit fda0342 into solana-foundation:release/2.2.0 Mar 9, 2026
11 of 12 checks passed
@raushan728 raushan728 deleted the fix/preserve-rpc-error-in-transfer branch March 10, 2026 10:28
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.

2 participants