forked from solana-labs/solana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch from CSV to a pickledb database (solana-labs#8)
* Switch from CSV to a pickledb database * Allow PickleDb errors to bubble up * Dedup * Hoist db * Add finalized field to TransactionInfo * Don't allow RPC client to resign transactions * Remove dead code * Use transport::Result * Record unconfirmed transaction * Fix: separate stake account per allocation * Catch transport errors * Panic if we attempt to replay a transaction that hasn't been finalized * Attempt to fix CI PickleDb isn't calling flush() or close() after writing to files. No issue on MacOS, but looks racy in CI. * Revert "Attempt to fix CI" This reverts commit 1632394f636c54402b3578120e8817dd1660e19b. * Poll for signature before returning
- Loading branch information
Showing
6 changed files
with
176 additions
and
134 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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 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 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,105 +1,94 @@ | ||
use solana_client::rpc_client::RpcClient; | ||
use solana_runtime::bank_client::BankClient; | ||
use solana_sdk::{ | ||
client::SyncClient, | ||
client::{AsyncClient, SyncClient}, | ||
fee_calculator::FeeCalculator, | ||
hash::Hash, | ||
message::Message, | ||
pubkey::Pubkey, | ||
signature::{Signature, Signer}, | ||
signature::{Keypair, Signature, Signer}, | ||
signers::Signers, | ||
system_instruction, | ||
transaction::Transaction, | ||
transport::TransportError, | ||
transport::{Result, TransportError}, | ||
}; | ||
|
||
pub trait Client { | ||
fn send_and_confirm_message<S: Signers>( | ||
&self, | ||
message: Message, | ||
signers: &S, | ||
) -> Result<Signature, TransportError>; | ||
|
||
fn get_balance1(&self, pubkey: &Pubkey) -> Result<u64, TransportError>; | ||
fn send_and_confirm_transaction1(&self, transaction: Transaction) -> Result<Signature>; | ||
fn get_balance1(&self, pubkey: &Pubkey) -> Result<u64>; | ||
fn get_recent_blockhash_and_fees(&self) -> Result<(Hash, FeeCalculator)>; | ||
} | ||
|
||
impl Client for RpcClient { | ||
fn send_and_confirm_message<S: Signers>( | ||
&self, | ||
message: Message, | ||
signers: &S, | ||
) -> Result<Signature, TransportError> { | ||
let mut transaction = Transaction::new_unsigned(message); | ||
self.resign_transaction(&mut transaction, signers) | ||
.map_err(|e| TransportError::Custom(e.to_string()))?; | ||
let initial_signature = transaction.signatures[0]; | ||
println!("Sending transaction with signature {}", initial_signature); | ||
let signature = self | ||
.send_and_confirm_transaction_with_spinner(&mut transaction, signers) | ||
.map_err(|e| TransportError::Custom(e.to_string()))?; | ||
Ok(signature) | ||
fn send_and_confirm_transaction1(&self, mut transaction: Transaction) -> Result<Signature> { | ||
let signers: Vec<&Keypair> = vec![]; // Don't allow resigning | ||
self.send_and_confirm_transaction_with_spinner(&mut transaction, &signers) | ||
.map_err(|e| TransportError::Custom(e.to_string())) | ||
} | ||
|
||
fn get_balance1(&self, pubkey: &Pubkey) -> Result<u64, TransportError> { | ||
fn get_balance1(&self, pubkey: &Pubkey) -> Result<u64> { | ||
let balance = self | ||
.get_balance(pubkey) | ||
.map_err(|e| TransportError::Custom(e.to_string()))?; | ||
Ok(balance) | ||
} | ||
|
||
fn get_recent_blockhash_and_fees(&self) -> Result<(Hash, FeeCalculator)> { | ||
let blockhash = self | ||
.get_recent_blockhash() | ||
.map_err(|e| TransportError::Custom(e.to_string()))?; | ||
Ok(blockhash) | ||
} | ||
} | ||
|
||
impl Client for BankClient { | ||
fn send_and_confirm_message<S: Signers>( | ||
&self, | ||
message: Message, | ||
signers: &S, | ||
) -> Result<Signature, TransportError> { | ||
self.send_message(signers, message) | ||
fn send_and_confirm_transaction1(&self, transaction: Transaction) -> Result<Signature> { | ||
let signature = self.async_send_transaction(transaction)?; | ||
self.poll_for_signature(&signature)?; | ||
Ok(signature) | ||
} | ||
|
||
fn get_balance1(&self, pubkey: &Pubkey) -> Result<u64, TransportError> { | ||
fn get_balance1(&self, pubkey: &Pubkey) -> Result<u64> { | ||
self.get_balance(pubkey) | ||
} | ||
} | ||
|
||
impl Client for () { | ||
fn send_and_confirm_message<S: Signers>( | ||
&self, | ||
_message: Message, | ||
_signers: &S, | ||
) -> Result<Signature, TransportError> { | ||
Ok(Signature::default()) | ||
} | ||
|
||
fn get_balance1(&self, _pubkey: &Pubkey) -> Result<u64, TransportError> { | ||
Ok(0) | ||
fn get_recent_blockhash_and_fees(&self) -> Result<(Hash, FeeCalculator)> { | ||
self.get_recent_blockhash() | ||
} | ||
} | ||
|
||
pub struct ThinClient<C: Client>(pub C); | ||
|
||
impl<C: Client> ThinClient<C> { | ||
pub fn send_transaction(&self, transaction: Transaction) -> Result<Signature> { | ||
self.0.send_and_confirm_transaction1(transaction) | ||
} | ||
|
||
pub fn send_message<S: Signers>(&self, message: Message, signers: &S) -> Result<Signature> { | ||
let (blockhash, _fee_caluclator) = self.0.get_recent_blockhash_and_fees()?; | ||
let transaction = Transaction::new(signers, message, blockhash); | ||
let signature = transaction.signatures[0]; | ||
self.send_transaction(transaction)?; | ||
Ok(signature) | ||
} | ||
|
||
pub fn transfer<S: Signer>( | ||
&self, | ||
lamports: u64, | ||
sender_keypair: &S, | ||
to_pubkey: &Pubkey, | ||
) -> Result<Signature, TransportError> { | ||
) -> Result<Signature> { | ||
let create_instruction = | ||
system_instruction::transfer(&sender_keypair.pubkey(), &to_pubkey, lamports); | ||
let message = Message::new(&[create_instruction]); | ||
self.send_message(message, &[sender_keypair]) | ||
} | ||
} | ||
|
||
impl<C: Client> ThinClient<C> { | ||
pub fn send_message<S: Signers>( | ||
&self, | ||
message: Message, | ||
signers: &S, | ||
) -> Result<Signature, TransportError> { | ||
self.0.send_and_confirm_message(message, signers) | ||
pub fn get_recent_blockhash_and_fees(&self) -> Result<(Hash, FeeCalculator)> { | ||
self.0.get_recent_blockhash_and_fees() | ||
} | ||
|
||
pub fn get_balance(&self, pubkey: &Pubkey) -> Result<u64, TransportError> { | ||
pub fn get_balance(&self, pubkey: &Pubkey) -> Result<u64> { | ||
self.0.get_balance1(pubkey) | ||
} | ||
} |
Oops, something went wrong.