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

flips nonce/non-nonce blockhash check #25711

Closed

Conversation

behzadnouri
Copy link
Contributor

@behzadnouri behzadnouri commented Jun 1, 2022

Problem

Durable nonce transactions can be executed twice.

Summary of Changes

@t-nelson:

gist is to flip the nonce/non-nonce blockhash check so that whether a
durable nonce transaction is flagged is not dependent up whether the
blockhash is extant in the rbh queue

@behzadnouri behzadnouri added the noCI Suppress CI on this Pull Request label Jun 1, 2022
@behzadnouri behzadnouri force-pushed the nonce-blockhash-check branch 4 times, most recently from 7fe8ae5 to 9b84bc5 Compare Jun 1, 2022
@behzadnouri behzadnouri removed the noCI Suppress CI on this Pull Request label Jun 1, 2022
@behzadnouri behzadnouri marked this pull request as ready for review Jun 1, 2022
jstarry
jstarry previously approved these changes Jun 1, 2022
Copy link
Member

@jstarry jstarry left a comment

Lgtm

@mergify mergify bot dismissed jstarry’s stale review Jun 1, 2022

Pull request has been modified.

CriesofCarrots
CriesofCarrots previously approved these changes Jun 1, 2022
Copy link
Contributor

@CriesofCarrots CriesofCarrots left a comment

Lgtm, thanks, Behzad!

@mergify mergify bot dismissed CriesofCarrots’s stale review Jun 1, 2022

Pull request has been modified.

t-nelson
t-nelson previously approved these changes Jun 1, 2022
Copy link
Contributor

@t-nelson t-nelson left a comment

lgtm. thanks!

were you able to get the test fixed up?

|| self.cluster_type() != ClusterType::MainnetBeta
|| self.slot() <= 135986379)
.then(|| self.check_message_for_nonce(tx.message()))
.flatten()
Copy link
Contributor

@t-nelson t-nelson Jun 1, 2022

Choose a reason for hiding this comment

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

ah, flatten! that's what i was looking for 🙂

@behzadnouri
Copy link
Contributor Author

behzadnouri commented Jun 1, 2022

were you able to get the test fixed up?

no, can't produce failure on master.

@behzadnouri behzadnouri requested a review from ryoqun Jun 2, 2022
@t-nelson
Copy link
Contributor

t-nelson commented Jun 2, 2022

no, can't produce failure on master.

i'll try to fix up the test this evening

Copy link
Contributor

@t-nelson t-nelson left a comment

sry, changing my mind. this change is insufficient on its own because nonce_account::verify_nonce_account only returns bool. so even with the hash checks swapped, if a transaction leads with a SystemProgram::AdvanceNonceAccount ix, but references some other rbh that's still extant in the queue, we fall back to the non-nonced tx check and the transaction is accepted.

i can pick this up in the morning

@t-nelson t-nelson self-requested a review Jun 2, 2022
@nguyenkha
Copy link

nguyenkha commented Jun 2, 2022

Hi, is there any ETA for fix of nonce account? My software relies on the nonce account feature for durable transaction due to offline signing. Thank you.

@mergify mergify bot dismissed t-nelson’s stale review Jun 2, 2022

Pull request has been modified.

@behzadnouri behzadnouri force-pushed the nonce-blockhash-check branch 2 times, most recently from 36c76ce to 1c3bf59 Compare Jun 2, 2022
Durable nonce transactions can be executed twice.

@t-nelson:
> gist is to flip the nonce/non-nonce blockhash check so that whether a
> durable nonce transaction is flagged is not dependent up whether the
> blockhash is extant in the rbh queue
@behzadnouri behzadnouri force-pushed the nonce-blockhash-check branch 4 times, most recently from adcd09e to d043479 Compare Jun 2, 2022
@behzadnouri
Copy link
Contributor Author

behzadnouri commented Jun 2, 2022

sry, changing my mind. this change is insufficient on its own because nonce_account::verify_nonce_account only returns bool. so even with the hash checks swapped, if a transaction leads with a SystemProgram::AdvanceNonceAccount ix, but references some other rbh that's still extant in the queue, we fall back to the non-nonced tx check and the transaction is accepted.

i can pick this up in the morning

@t-nelson How about the last commit here?

The code is now distinguishing between cases where:

  • Transaction message does not refer to a durable nonce address.

Whereas transaction message is referring to a durable nonce address but:

  • Nonce account is not found in accounts-db.
  • Or, nonce account is invalid, i.e. verify_nonce_account returns false.
  • Or, durable nonce is disabled.

@behzadnouri behzadnouri added the feature-gate Pull Request adds or modifies a runtime feature gate label Jun 2, 2022
@behzadnouri
Copy link
Contributor Author

behzadnouri commented Jun 2, 2022

Added a 2nd feature activation:

  • The 1st feature flips nonce/non-nonce blockhash check but keeps durable nonce disabled.
  • The 2nd feature enables durable nonce.

This should prevent double execution at epoch boundary when the 1st feature is activated.

&self,
message: &SanitizedMessage,
) -> std::result::Result<TransactionAccount, NonceError> {
let nonce_address = message
.get_durable_nonce(self.feature_set.is_active(&nonce_must_be_writable::id()))
Copy link
Contributor

@t-nelson t-nelson Jun 2, 2022

Choose a reason for hiding this comment

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

I think we need to plumb NonceError through here and discern between the SystemProgram::AdvanceNonceAccount marker ix existing (nonced tx or not) and the referenced nonce account not existing (nonced tx that's going to fail)

let nonce_account = self
.get_account_with_fixed_root(nonce_address)
.ok_or(NonceError::NonceAccountNotFound)?;
if nonce_account::verify_nonce_account(&nonce_account, message.recent_blockhash()) {
Copy link
Contributor

@t-nelson t-nelson Jun 2, 2022

Choose a reason for hiding this comment

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

I was considering plumbing NonceError through here too, so we can discern between an invalid nonce account and a blockhash mismatch, but I think it'd just be informational (and we'd eat that info immediately)

@jstarry
Copy link
Member

jstarry commented Jun 2, 2022

Will this be closed in favor of #25744 ?

@behzadnouri
Copy link
Contributor Author

behzadnouri commented Jun 3, 2022

Will this be closed in favor of #25744 ?

lets see if #25744 passes tests

@solana-labs solana-labs deleted a comment from RieserStern Jun 3, 2022
@jstarry
Copy link
Member

jstarry commented Jun 4, 2022

Quick question :) We're serializing durable nonce transactions using the blockhash we receive for a nonce account from the node. If I understand correctly, no need to change anything on my part even after this change, right? The new blockhash derivation will only change what the node returns and it is used as before.

We'll release guidance on this soon once the patch is finalized

@maayank
Copy link

maayank commented Jun 4, 2022

Quick question :) We're serializing durable nonce transactions using the blockhash we receive for a nonce account from the node. If I understand correctly, no need to change anything on my part even after this change, right? The new blockhash derivation will only change what the node returns and it is used as before.

We'll release guidance on this soon once the patch is finalized

Thank you for the answer! I accidentally posted the question in this issue so deleted it and posted in the more recent issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-gate Pull Request adds or modifies a runtime feature gate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants