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

Test that tick slot hashes update the recent blockhash queue #24242

Merged
merged 1 commit into from
Apr 15, 2022

Conversation

jstarry
Copy link
Member

@jstarry jstarry commented Apr 11, 2022

Problem

There seems to be a common misconception that skipped slots do not impact the recent blockhash queue. There is no test to observe how this works.

Summary of Changes

  • Added test to observe how tick slots impact the age of blockhash queue hash entries
  • Added Bank::get_hash_age for use in above test
  • Moved the Default implementation for BlockhashQueue into the blockhash_queue module because I can never find it
  • Factored out new confirm_slot_entries function from blockstore_processor::confirm_slot_entries to make it easier to test the full verification flow for entries

Fixes #

@jstarry jstarry requested a review from ryoqun April 11, 2022 11:21
@jstarry jstarry force-pushed the blockhash-queue-tick-slots branch from fa4d4b1 to 37c2cd6 Compare April 11, 2022 11:24
@jstarry
Copy link
Member Author

jstarry commented Apr 11, 2022

Note that this implies that using "last valid block height" instead of "last valid slot" for transaction expiration is actually incorrect because it assumes that skipped slots don't affect transaction expiration. This test shows that hashes for skipped slots are also added to the recent blockhash queue and so slots should be used for transaction expiration. Using block height for detecting expiration results in clients waiting longer than they need to (cc @t-nelson @CriesofCarrots @mvines)

@jstarry jstarry changed the title Test tick slot hash updates to the recent blockhash queue Test that tick slot hashes update the recent blockhash queue Apr 11, 2022
@codecov
Copy link

codecov bot commented Apr 12, 2022

Codecov Report

Merging #24242 (37c2cd6) into master (2da4e3e) will increase coverage by 0.1%.
The diff coverage is 79.1%.

@@            Coverage Diff            @@
##           master   #24242     +/-   ##
=========================================
+ Coverage    81.8%    81.9%   +0.1%     
=========================================
  Files         581      580      -1     
  Lines      158312   161329   +3017     
=========================================
+ Hits       129518   132268   +2750     
- Misses      28794    29061    +267     

@jstarry jstarry requested review from mvines and t-nelson April 13, 2022 04:21
@ryoqun
Copy link
Member

ryoqun commented Apr 13, 2022

(wow, is this really? it's big news to me... i'll get to review on this later...)

@jstarry
Copy link
Member Author

jstarry commented Apr 13, 2022

(wow, is this really? it's big news to me... i'll get to review on this later...)

Yeah I was quite surprised too, let me know if you want to me to walk through how I reached this conclusion. I'll let you dig in first :)

@CriesofCarrots
Copy link
Contributor

Oh. Wow.
I was about to type something about "how do we undeprecate a field, ie last_valid_slot", but just saw this: #23949 (comment) Is it doable?

@mvines
Copy link
Member

mvines commented Apr 14, 2022

lol wut.

doesn't this mean that if 150 slots are skipped in a row, there does not exist a valid blockhash for future votes?

@t-nelson
Copy link
Contributor

tx forwards are a single hop. txs expire after 150 blocks. what's next?!

nice find! think it'll be enough to stop putting new ticks in or will there be side effect?

@ryoqun
Copy link
Member

ryoqun commented Apr 15, 2022

hmm, i think i found a counter-example?: https://explorer.solana.com/tx/5ecnMQYQhZEsup2YPr4Vii3skuvhx7VPXTXVVioVv96PhrkXwZhjbgpEzS8pnq4TdcRXDyuCQnga7wLG5GsDjJwX

this transaction is included in slot 117,746,642 with recent_blockhash Du5KNR1zXVucMpPzJuPRvt9XXHwMTXsaCWJQQqUe7GRG, which in turn refers to the slot 117,746,491

$ pry
[1] pry(main)> 117746642 - 117746491
=> 151 # greater than MAX_PROCESSING_AGE!

then, let's see block heights:

$ ./target/release/solana block 117746491 2> /dev/null | head
Slot: 117746491
Parent Slot: 117746490
Blockhash: Du5KNR1zXVucMpPzJuPRvt9XXHwMTXsaCWJQQqUe7GRG
Previous Blockhash: AzVaX69Z3YdCnuonpMfY48REUU8cJHbf7oyFuASYptTF
Block Time: 2022-01-25T17:45:38+09:00
Block Height: 106258160

$ ./target/release/solana block 117746642 2> /dev/null | head
Slot: 117746642
Parent Slot: 117746641
Blockhash: Czw8eVGqVpz843x3QBRbm4mQ78ZQAmHuTeFNGvv1Bj1X
Previous Blockhash: E6ii2Dg49Csb4u6dHdjZSJvfdmE25Kn92v5apk5rVJit
Block Time: 2022-01-25T17:47:01+09:00
Block Height: 106258298

$ pry
[1] pry(main)> 106258298 - 106258160
=> 138 # under MAX_PROCESSING_AGE!

@jstarry
Copy link
Member Author

jstarry commented Apr 15, 2022

You have to find a counter example greater than 151 because we allow processing transactions that are 151 slots behind the current block. I have a test to show this strange off-by-one behavior here:

// Note that the "age" of a hash in the queue is 0-indexed. So when processing
// transactions in block 50, the hash for block 49 has an age of 0 despite
// being one block in the past.

@jstarry
Copy link
Member Author

jstarry commented Apr 15, 2022

Any objections to merging this? I have a fix lined up here: #24389

Copy link
Member

@ryoqun ryoqun left a comment

Choose a reason for hiding this comment

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

lgtm!

@@ -891,7 +891,7 @@ pub fn confirm_slot(
) -> result::Result<(), BlockstoreProcessorError> {
let slot = bank.slot();

let (entries, num_shreds, slot_full) = {
let slot_entries_load_result = {
Copy link
Member

Choose a reason for hiding this comment

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

loves these tiny clean-ups.

@jstarry jstarry merged commit 4ed647d into solana-labs:master Apr 15, 2022
@jstarry jstarry deleted the blockhash-queue-tick-slots branch April 15, 2022 16:30
jeffwashington pushed a commit to jeffwashington/solana that referenced this pull request Jun 29, 2022
jeffwashington pushed a commit to jeffwashington/solana that referenced this pull request Jun 29, 2022
jeffwashington pushed a commit to jeffwashington/solana that referenced this pull request Jun 30, 2022
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.

5 participants