-
Notifications
You must be signed in to change notification settings - Fork 174
feat(solana-indexer): add traits module
#4508
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
tilacog
wants to merge
4
commits into
solana-indexer/PR2-bootstrap
Choose a base branch
from
solana-indexer/PR3-bootstrap
base: solana-indexer/PR2-bootstrap
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,7 @@ | ||
| //! `solana-indexer` — Solana settlement indexer. | ||
|
|
||
| #![allow(async_fn_in_trait)] | ||
| #![warn(missing_docs)] | ||
|
|
||
| pub mod traits; | ||
| pub mod types; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| //! Traits for external dependencies. | ||
|
|
||
| pub mod solana_client; | ||
| pub mod store; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| //! Solana RPC interface for the finalization worker. | ||
|
|
||
| use { | ||
| crate::types::{ | ||
| commitment::{AccountInfo, SignatureStatus}, | ||
| recovery::GetSignaturesOpts, | ||
| wire::SubscribeUpdateTransactionInfo, | ||
| }, | ||
| solana_client::client_error::ClientError, | ||
| solana_sdk::{pubkey::Pubkey, signature::Signature}, | ||
| }; | ||
|
|
||
| /// Interface for RPC calls the finalization worker needs: | ||
| /// promoting confirmed transactions to finalized, sweeping aged rows, | ||
| /// and reading account state for recovery. | ||
| pub trait SolanaClient { | ||
| /// Fetch status for multiple transaction signatures (up to 256). | ||
| /// `None` = transaction signature not found. | ||
| async fn get_signature_statuses( | ||
| &self, | ||
| signatures: &[Signature], | ||
| ) -> Result<Vec<Option<SignatureStatus>>, ClientError>; | ||
|
|
||
| /// Fetch a transaction by its signature. `Ok(None)` = never landed. | ||
| async fn get_transaction( | ||
| &self, | ||
| signature: &Signature, | ||
| ) -> Result<Option<SubscribeUpdateTransactionInfo>, ClientError>; | ||
|
|
||
| /// List all transaction signatures for a program address (used for | ||
| /// backfill). | ||
| async fn get_signatures_for_address( | ||
| &self, | ||
| address: &Pubkey, | ||
| opts: GetSignaturesOpts, | ||
| ) -> Result<Vec<Signature>, ClientError>; | ||
|
|
||
| /// Read account data. `Ok(None)` = account does not exist (deleted or not | ||
| /// initialized). | ||
| async fn get_account_info(&self, address: &Pubkey) -> Result<Option<AccountInfo>, ClientError>; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| //! PostgreSQL persistence layer for decoded events and slot state. | ||
|
|
||
| use { | ||
| crate::types::{ | ||
| commitment::{Commitment, UnfinalizedRow}, | ||
| dead_letter::DeadLetterEntry, | ||
| errors::StoreError, | ||
| events::DecodedEvent, | ||
| recovery::PdaSnapshot, | ||
| }, | ||
| std::ops::Range, | ||
| }; | ||
|
|
||
| /// PostgreSQL persistence. Used by Decoder, Watchdog, and FinalizationWorker. | ||
| pub trait Store { | ||
| /// Save decoded events and advance the slot watermark atomically. | ||
| async fn persist_events( | ||
| &self, | ||
| events: Vec<DecodedEvent>, | ||
| new_watermark: u64, | ||
| ) -> Result<(), StoreError>; | ||
|
|
||
| /// Record a slot checkpoint. Rejects downward writes. | ||
| async fn write_watermark(&self, slot: u64) -> Result<(), StoreError>; | ||
|
|
||
| /// Read persisted watermark for resuming after reconnect. | ||
| async fn read_watermark(&self) -> Result<Option<u64>, StoreError>; | ||
|
|
||
| /// Move stale partials (>32 slots behind) to dead letter table. | ||
| async fn write_dead_letter(&self, entry: DeadLetterEntry) -> Result<(), StoreError>; | ||
|
|
||
| /// Record gaps that fell outside the replay window (write-only in v0.1). | ||
| async fn record_lost_slot_range(&self, range: Range<u64>) -> Result<(), StoreError>; | ||
|
|
||
| /// Primary promotion pass: fetch `confirmed` rows whose `slot` is at or | ||
| /// above the finalization-window threshold (`slot >= newer_than_slot`). | ||
| /// `limit` caps the batch at 256 (RPC batch size). Returns `Err` on | ||
| /// backend failure so the caller can back off rather than | ||
| /// silently stall on a dead store. | ||
| async fn get_confirmed_rows( | ||
| &self, | ||
| newer_than_slot: u64, | ||
| limit: usize, | ||
| ) -> Result<Vec<UnfinalizedRow>, StoreError>; | ||
|
|
||
| /// Safety-net sweep for `confirmed` rows the primary promotion pass missed | ||
| /// (i.e. rows that aged past the signature-status retention horizon, | ||
| /// ~150 slots behind the chain tip). Returns `Err` on backend failure | ||
| /// (see `get_confirmed_rows`). | ||
| async fn get_aged_rows( | ||
| &self, | ||
| retention_horizon_slot: u64, | ||
| ) -> Result<Vec<UnfinalizedRow>, StoreError>; | ||
|
|
||
| /// Flip the `commitment` label on a specific row. | ||
| /// | ||
| /// The row's `table` field tells the implementer which `solana.*` table to | ||
| /// UPDATE. | ||
| async fn update_commitment( | ||
| &self, | ||
| row: &UnfinalizedRow, | ||
| new_commitment: Commitment, | ||
| ) -> Result<(), StoreError>; | ||
|
|
||
| /// Persist a single event during recovery/backfills, not the live ingestion | ||
| /// path. | ||
| /// | ||
| /// Unlike `persist_events`, this does not advance the watermark. | ||
| async fn backfill_event(&self, event: DecodedEvent) -> Result<(), StoreError>; | ||
|
|
||
| /// Upsert on-chain PDA state for reconciliation. | ||
| async fn upsert_pda_snapshot(&self, snapshot: PdaSnapshot) -> Result<(), StoreError>; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.