Skip to content

Conversation

@Woft257
Copy link

@Woft257 Woft257 commented Jan 10, 2026

This PR adds full indexing support for the Solana blockchain, capable of processing both native SOL and SPL token transfers.

The implementation is built to be resilient and aware of Solana's specific architecture. It correctly handles "skipped slots" as a normal chain event rather than an error, which prevents false positives and ensures the indexer can sync reliably.

To guarantee data integrity, transaction and block processing is robust:

  • Failed Transactions: The indexer inspects the meta.err field for each transaction. If a transaction has failed on-chain, it is skipped, ensuring that only successful transfers are processed and indexed.

  • Reorg Handling & Data Consistency: The indexer's existing reorg detection logic is fully applied to Solana by comparing the blockhash and previousBlockhash. Furthermore, all blocks are fetched with finalized commitment, which provides the strongest guarantee against reorgs and ensures data consistency.

- Implemented Solana indexer in `internal/indexer/solana.go` with methods to retrieve block information and transactions.
- Created Solana RPC client in `internal/rpc/solana/client.go` to interact with Solana's JSON-RPC API.
- Defined Solana API interface in `internal/rpc/solana/api.go` for abstraction.
- Added necessary types for Solana RPC responses in `internal/rpc/solana/types.go`.
- Updated worker factory in `internal/worker/factory.go` to include Solana indexer initialization.
ToAddress: r.addr,
AssetAddress: sender.mint,
Amount: fmt.Sprintf("%d", amt),
Type: "token_transfer",
Copy link
Contributor

Choose a reason for hiding this comment

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

Should take a look at other chains and reuse similar value

Copy link
Author

Choose a reason for hiding this comment

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

Updated. Replaced the custom "token_transfer"/"sol_transfer" strings with the shared tx type used across chains (constant.TxnTypeTransfer) for consistency.

Copy link
Contributor

Choose a reason for hiding this comment

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

we just define new TxType constant
TxTypeTokenTransfer TxType = "token_transfer"
TxTypeNativeTransfer TxType = "native_transfer"

should use either type token transfer or native transfer accordingly

BlockNumber: slot,
FromAddress: from,
ToAddress: to,
AssetAddress: solAssetAddress,
Copy link
Contributor

Choose a reason for hiding this comment

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

let empty for native sol

Copy link
Author

Choose a reason for hiding this comment

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

Changed AssetAddress to empty string for native SOL

Comment on lines 456 to 460
logger.Info("[SOLANA] extract transfers start",
"chain", s.chainName,
"slot", slot,
"rpc_txs", len(b.Transactions),
)
Copy link
Contributor

Choose a reason for hiding this comment

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

remove this comment, solana will produce noice for the logs

Copy link
Author

Choose a reason for hiding this comment

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

Removed noisy log [SOLANA] extract transfers start

Comment on lines 479 to 480
tokOwnerByAcc := map[string]string{}
tokMintByAcc := map[string]string{}
Copy link
Contributor

Choose a reason for hiding this comment

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

tokMint -> confusing name: tokenOwnerByAcc , tokenMintByAcc

Copy link
Author

Choose a reason for hiding this comment

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

Renamed tokOwnerByAcc → tokenOwnerByAcc, tokMintByAcc → tokenMintByAcc

ToAddress: to,
AssetAddress: solAssetAddress,
Amount: fmt.Sprintf("%d", lamports),
Type: constant.TxnTypeTransfer,
Copy link
Contributor

Choose a reason for hiding this comment

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

use new types

Copy link
Author

Choose a reason for hiding this comment

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

Updated to use the new transaction types:

  • constant.TxTypeNativeTransfer for SOL transfers
  • constant.TxTypeTokenTransfer for SPL token transfers

FromAddress: fromOwner,
ToAddress: toOwner,
AssetAddress: mint,
Amount: fmt.Sprintf("%d", amount),
Copy link
Contributor

Choose a reason for hiding this comment

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

would be better to use strconv.FormatUint(amount, 10)?

Method Allocations Relative speed
strconv.FormatUint 1 fastest
fmt.Sprintf 2–4 3–10× slower

Copy link
Author

Choose a reason for hiding this comment

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

Replaced fmt.Sprintf with strconv.FormatUint for better performance

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