Skip to content

Commit

Permalink
Send all transactions as quickly as possible, then wait (solana-labs#26)
Browse files Browse the repository at this point in the history
* Send all transactions as quickly as possible, then wait

* Exit when finalized or blockhashes have expired

* Don't need blockhash in the CSV output

* Better types

CSV library was choking on Pubkey as a type. PickleDb doesn't have that problem.

* Resend if blockhash has not expired

* Attempt to fix CI
  • Loading branch information
garious authored May 8, 2020
1 parent 6007905 commit a29ae50
Show file tree
Hide file tree
Showing 6 changed files with 221 additions and 95 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
language: rust
cache: cargo
addons:
apt:
packages:
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ csv = "1.1.3"
clap = "2.33.0"
console = "0.10.3"
indexmap = "1.3.2"
indicatif = "0.14.0"
itertools = "0.9.0"
pickledb = "0.4.1"
serde = { version = "1.0", features = ["derive"] }
Expand Down
28 changes: 28 additions & 0 deletions src/thin_client.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use solana_client::rpc_client::RpcClient;
use solana_runtime::bank_client::BankClient;
use solana_sdk::{
account::Account,
client::{AsyncClient, SyncClient},
fee_calculator::FeeCalculator,
hash::Hash,
Expand All @@ -9,6 +10,10 @@ use solana_sdk::{
signature::{Signature, Signer},
signers::Signers,
system_instruction,
sysvar::{
recent_blockhashes::{self, RecentBlockhashes},
Sysvar,
},
transaction::Transaction,
transport::{Result, TransportError},
};
Expand All @@ -26,6 +31,7 @@ pub trait Client {
) -> Result<Vec<Option<TransactionStatus>>>;
fn get_balance1(&self, pubkey: &Pubkey) -> Result<u64>;
fn get_recent_blockhash1(&self) -> Result<(Hash, FeeCalculator)>;
fn get_account1(&self, pubkey: &Pubkey) -> Result<Option<Account>>;
}

impl Client for RpcClient {
Expand Down Expand Up @@ -58,6 +64,12 @@ impl Client for RpcClient {
self.get_recent_blockhash()
.map_err(|e| TransportError::Custom(e.to_string()))
}

fn get_account1(&self, pubkey: &Pubkey) -> Result<Option<Account>> {
self.get_account(pubkey)
.map(Some)
.map_err(|e| TransportError::Custom(e.to_string()))
}
}

impl Client for BankClient {
Expand Down Expand Up @@ -97,6 +109,10 @@ impl Client for BankClient {
fn get_recent_blockhash1(&self) -> Result<(Hash, FeeCalculator)> {
self.get_recent_blockhash()
}

fn get_account1(&self, pubkey: &Pubkey) -> Result<Option<Account>> {
self.get_account(pubkey)
}
}

pub struct ThinClient<C: Client>(pub C);
Expand Down Expand Up @@ -144,4 +160,16 @@ impl<C: Client> ThinClient<C> {
pub fn get_balance(&self, pubkey: &Pubkey) -> Result<u64> {
self.0.get_balance1(pubkey)
}

pub fn get_account(&self, pubkey: &Pubkey) -> Result<Option<Account>> {
self.0.get_account1(pubkey)
}

pub fn get_recent_blockhashes(&self) -> Result<Vec<Hash>> {
let opt_blockhashes_account = self.get_account(&recent_blockhashes::id())?;
let blockhashes_account = opt_blockhashes_account.unwrap();
let recent_blockhashes = RecentBlockhashes::from_account(&blockhashes_account).unwrap();
let hashes = recent_blockhashes.iter().map(|x| x.blockhash).collect();
Ok(hashes)
}
}
Loading

0 comments on commit a29ae50

Please sign in to comment.