Skip to content
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

126 atomic balances #165

Merged
merged 7 commits into from
May 2, 2018
Merged

Conversation

rlkelly
Copy link
Contributor

@rlkelly rlkelly commented May 1, 2018

pull request for issue 126, updated some error handling and testing

@garious
Copy link
Contributor

garious commented May 1, 2018

Can you run git pull --rebase upstream master && git push -f

@rlkelly
Copy link
Contributor Author

rlkelly commented May 1, 2018

sure

let bal = option.unwrap();
let current = bal.load(Ordering::Relaxed) as i64;

if current < tr.data.tokens {
Copy link
Contributor

Choose a reason for hiding this comment

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

I was thinking you could start a loop here that continues until compare_exchange returns Ok or the balance check returns InsufficentFunds. You shouldn't need to add that new error type BalanceUpdatedBeforeTransactionCompleted.

Copy link
Contributor

@garious garious left a comment

Choose a reason for hiding this comment

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

A bunch of small nits. This is very close to going in!

self.process_verified_transaction_debits(tr)?;
self.process_verified_transaction_credits(tr);
Ok(())
return match self.process_verified_transaction_debits(tr) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Was this changed needed? I'm having trouble understanding what is different than the original code.

}

/// Process a batch of verified transactions.
pub fn process_verified_transactions(&self, trs: Vec<Transaction>) -> Vec<Result<Transaction>> {
// Run all debits first to filter out any transactions that can't be processed
// in parallel deterministically.
let results: Vec<_> = trs.into_par_iter()
.map(|tr| self.process_verified_transaction_debits(&tr).map(|_| tr))
.filter_map(|tr| match self.process_verified_transaction_debits(&tr) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is probably a slower version of the original code that loses information in those Err values.

Copy link
Contributor Author

@rlkelly rlkelly May 2, 2018

Choose a reason for hiding this comment

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

This is unnecessary now since we're looping on failed transactions, but it will raise errors if you have transactions that fail in process_packets_bench since they're not being filtered out

@@ -131,23 +133,34 @@ impl Accountant {
// Hold a write lock before the condition check, so that a debit can't occur
Copy link
Contributor

@garious garious May 1, 2018

Choose a reason for hiding this comment

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

With your changes, you can delete this comment.


Ok(())
return match result {
Ok(_) => Ok(()),
Copy link
Contributor

Choose a reason for hiding this comment

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

If you don't mind, please run Clippy before submitting PRs. It would have a suggestion to make this code more idiomatic.

@garious
Copy link
Contributor

garious commented May 2, 2018

This looks flawless to me. I can work out the CI issues. Thanks for taking this on and for adding errors to the test to make it deterministic.

@@ -774,11 +774,11 @@ mod bench {
// Seed the 'from' account.
let rando0 = KeyPair::new();
let tr = Transaction::new(&mint.keypair(), rando0.pubkey(), 1_000, last_id);
acc.process_verified_transaction(&tr).unwrap();
let _ = acc.process_verified_transaction(&tr);
Copy link
Contributor

Choose a reason for hiding this comment

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

All the way back please. That unwrap() was an important sanity check.

@@ -803,7 +803,10 @@ mod bench {
drop(skel.historian.sender);
let entries: Vec<Entry> = skel.historian.receiver.iter().collect();
assert_eq!(entries.len(), 1);
assert_eq!(entries[0].events.len(), txs as usize);
assert_eq!(
Copy link
Contributor

Choose a reason for hiding this comment

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

cargo +nightly fmt

@garious
Copy link
Contributor

garious commented May 2, 2018

Some inconsistency between stable rustfmt and nightly rustfmt. I'll take care of that in a followup patch. Merging!

@garious garious merged commit 47c2317 into solana-labs:master May 2, 2018
@rlkelly rlkelly deleted the 126__atomic_balances branch May 2, 2018 17:03
garious added a commit to garious/solana that referenced this pull request May 7, 2018
vkomenda pushed a commit to vkomenda/solana that referenced this pull request Aug 29, 2021
yihau added a commit to yihau/solana that referenced this pull request Mar 11, 2024
steviez pushed a commit to steviez/solana that referenced this pull request Mar 13, 2024
… of solana-labs#165) (solana-labs#166)

ci: fix Windows gh release pipeline (solana-labs#165)

(cherry picked from commit 3863bb1)

Co-authored-by: Yihau Chen <a122092487@gmail.com>
apfitzge referenced this pull request in apfitzge/agave Mar 15, 2024
… of anza-xyz#165) (anza-xyz#167)

ci: fix Windows gh release pipeline (anza-xyz#165)

(cherry picked from commit 3863bb1)

Co-authored-by: Yihau Chen <a122092487@gmail.com>
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