Update last_id between client retries

Fixes #1694
This commit is contained in:
Greg Fitzgerald 2018-11-06 06:07:43 -07:00
parent 6b5d12a8bb
commit 54968b59bb
4 changed files with 14 additions and 11 deletions

View File

@ -116,7 +116,7 @@ impl Drone {
); );
let last_id = client.get_last_id(); let last_id = client.get_last_id();
let tx = match req { let mut tx = match req {
DroneRequest::GetAirdrop { DroneRequest::GetAirdrop {
airdrop_request_amount, airdrop_request_amount,
client_pubkey, client_pubkey,
@ -147,7 +147,7 @@ impl Drone {
influxdb::Value::Integer(self.request_current as i64), influxdb::Value::Integer(self.request_current as i64),
).to_owned(), ).to_owned(),
); );
client.retry_transfer_signed(&tx, 10) client.retry_transfer(&self.mint_keypair, &mut tx, 10)
} else { } else {
Err(Error::new(ErrorKind::Other, "token limit reached")) Err(Error::new(ErrorKind::Other, "token limit reached"))
} }

View File

@ -75,13 +75,15 @@ impl ThinClient {
} }
/// Retry a sending a signed Transaction to the server for processing. /// Retry a sending a signed Transaction to the server for processing.
pub fn retry_transfer_signed( pub fn retry_transfer(
&mut self, &mut self,
tx: &Transaction, keypair: &Keypair,
tx: &mut Transaction,
tries: usize, tries: usize,
) -> io::Result<Signature> { ) -> io::Result<Signature> {
let data = serialize(&tx).expect("serialize Transaction in pub fn transfer_signed");
for x in 0..tries { for x in 0..tries {
tx.sign(&keypair, self.get_last_id());
let data = serialize(&tx).expect("serialize Transaction in pub fn transfer_signed");
self.transactions_socket self.transactions_socket
.send_to(&data, &self.transactions_addr)?; .send_to(&data, &self.transactions_addr)?;
if self.poll_for_signature(&tx.signature).is_ok() { if self.poll_for_signature(&tx.signature).is_ok() {
@ -91,7 +93,7 @@ impl ThinClient {
} }
Err(io::Error::new( Err(io::Error::new(
io::ErrorKind::Other, io::ErrorKind::Other,
"retry_transfer_signed failed", "retry_transfer failed",
)) ))
} }

View File

@ -95,12 +95,12 @@ impl Transaction {
let mut tx = Transaction { let mut tx = Transaction {
signature: Signature::default(), signature: Signature::default(),
account_keys, account_keys,
last_id, last_id: Hash::default(),
fee, fee,
program_ids, program_ids,
instructions, instructions,
}; };
tx.sign(from_keypair); tx.sign(from_keypair, last_id);
tx tx
} }
pub fn userdata(&self, instruction_index: usize) -> &[u8] { pub fn userdata(&self, instruction_index: usize) -> &[u8] {
@ -146,7 +146,8 @@ impl Transaction {
} }
/// Sign this transaction. /// Sign this transaction.
pub fn sign(&mut self, keypair: &Keypair) { pub fn sign(&mut self, keypair: &Keypair, last_id: Hash) {
self.last_id = last_id;
let sign_data = self.get_sign_data(); let sign_data = self.get_sign_data();
self.signature = Signature::new(keypair.sign(&sign_data).as_ref()); self.signature = Signature::new(keypair.sign(&sign_data).as_ref());
} }

View File

@ -1490,9 +1490,9 @@ fn send_tx_and_retry_get_balance(
let mut client = mk_client(leader); let mut client = mk_client(leader);
trace!("getting leader last_id"); trace!("getting leader last_id");
let last_id = client.get_last_id(); let last_id = client.get_last_id();
let tx = Transaction::system_new(&alice.keypair(), *bob_pubkey, transfer_amount, last_id); let mut tx = Transaction::system_new(&alice.keypair(), *bob_pubkey, transfer_amount, last_id);
info!("executing leader transfer"); info!("executing leader transfer");
let _res = client.retry_transfer_signed(&tx, 30); let _res = client.retry_transfer(&alice.keypair(), &mut tx, 30);
retry_get_balance(&mut client, bob_pubkey, expected) retry_get_balance(&mut client, bob_pubkey, expected)
} }