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

[NONEVM-984][solana] - Reorg Detection + lighter rpc call #951

Merged
merged 106 commits into from
Jan 10, 2025

Conversation

Farber98
Copy link
Contributor

@Farber98 Farber98 commented Nov 28, 2024

Description

  • Track transaction statuses on per signature basis to identify which signature for a transaction was included to detect re-orgs specifically for it
  • Update the confirmation logic to identify regression in a signature’s transaction status when no or processed status is received to detect re-orgs
    • A transaction can revert back to no status or processed from confirmed status
    • A transaction can revert back to no status from processed status
  • If a re-org is detected
    • from confirmed, restart the retry/bump loop
    • from processed, we don't do nothing and it's handled by expiration rebroadcast if needed later

Tickets

Soak Testing

Comment on lines +593 to +594
case txmutils.Confirmed:
if sigOnChainState == txmutils.Processed || sigOnChainState == txmutils.Broadcasted || sigOnChainState == txmutils.NotFound {
Copy link
Contributor

Choose a reason for hiding this comment

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

Wouldn't there be a case where the in-memory state differs from the on-chain state due to the chain being polled more recently, which wouldn't be a true reorg?

Copy link
Contributor Author

@Farber98 Farber98 Jan 8, 2025

Choose a reason for hiding this comment

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

There's no problem that we have different states as long as the on-chain one is greater or equal than our in-memory one.

If this premise is false, it's because:

Copy link
Contributor

@silaslenihan silaslenihan Jan 8, 2025

Choose a reason for hiding this comment

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

#951 (comment)

Yeah this is what I was getting at... I guess you guys have already thought it through though and nothing has come up in soak testing

Comment on lines +615 to +618
if tempTx, confirmedExists = c.confirmedTxs[id]; confirmedExists {
tx = tempTx
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't it be impossible for a tx to exist in both confirmed and broadcasted since it's deleted during OnCofirmed? Not saying this is a huge issue mostly just testing my understanding

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, this shouldn't happen. What is your concern about this?

Copy link
Contributor

Choose a reason for hiding this comment

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

Well this function seems to be okay with that case where broadcastedExists and confirmedExists, I guess the reorg would just be caught elsewhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We catch the reorgs here:

  • When getting a NotFound sig, we check if our in-memory state is higher for it (Processed or Confirmed) and needs to be handled
  • When getting a Processed signature sig, if our in-memory state is higher for it (Confirmed) and needs to be handled
  • By definition, no reorgs from Finalized state should happen, that's why they are not handled

Copy link
Contributor

@jadepark-dev jadepark-dev left a comment

Choose a reason for hiding this comment

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

Amazing work, looks good to me!

@aalu1418 aalu1418 merged commit e2a9566 into develop Jan 10, 2025
57 of 69 checks passed
@aalu1418 aalu1418 deleted the nonevm-984-reorg branch January 10, 2025 14:25
amit-momin pushed a commit that referenced this pull request Jan 24, 2025
* refactor so txm owns blockhash assignment

* lastValidBlockHeight shouldn't be exported

* better comment

* refactor sendWithRetry to make it clearer

* confirm loop refactor

* fix infinite loop

* move accountID inside msg

* lint fix

* base58 does not contain lower l

* fix hash errors

* fix generate random hash

* remove blockhash as we only need block height

* expired tx changes without tests

* add maybe to mocks

* expiration tests

* send txes through queue

* revert pendingtx leakage of information. overwrite blockhash

* fix order of confirm loop and not found signature check

* fix mocks

* prevent confirmation loop to mark tx as errored when it needs to be rebroadcasted

* fix test

* fix pointer

* add comments

* reduce rpc calls + refactors

* tests + check to save rpc calls

* address feedback + remove redundant impl

* iface comment

* address feedback on compute unit limit and lastValidBlockHeight assignment

* blockhash assignment inside txm.sendWithRetry

* address feedback

* Merge branch 'develop' into nonevm-706-support-custom-bumping-strategy-rpc-expiration-within-confirmation

* refactors after merge

* fix interactive rebase

* fix whitespace diffs

* fix import

* fix mocks

* add on prebroadcaste error

* remove rebroadcast count and fix package

* improve docs

* track status on each signature to detect reorgs

* move things arround + add reorg detection

* linting errors

* fix some state tracking instances

* remove redundant sig update

* move state from txes to sigs

* fix listAllExpiredBroadcastedTxs

* handle reorg after confirm cycle

* associate sigs to retry ctx

* remove unused ctx

* add errored state and remove finalized

* comment

* Revert "comment"

This reverts commit 6bc0c62.

* Revert "remove unused ctx"

This reverts commit 2902ec0.

* Revert "associate sigs to retry ctx"

This reverts commit 8c18891.

* Revert "fix listAllExpiredBroadcastedTxs"

This reverts commit f4c6069.

* Revert "move state from txes to sigs"

This reverts commit 3a6e643.

* fix tx state

* address feedback

* fix ci

* fix lint

* handle multiple sigs case

* improve comment

* improve logic and comments

* fix comparison against blockHeight instead of slotHeight

* address feedback

* fix lint

* fix log

* address feedback

* remove useless slot height

* address feedback

* add comment

* tests and fix some bugs

* address feedback

* address feedback

* validate that tx doesn't exist in any of maps when adding new tx

* get height instead of whole block optimization

* fix mocks on expiration

* fix test

* rebroadcast with new blockhash + add integration tests

* fix integration tests

* remove unused params and better comments

* handle reorg equally for processed and confirmed at a sig level

* add comments and rename txHasReorg to IsTxReorged for better readability

* change test name to solve github CI failing check

* fix ci

* fix tests removing parallel

* fix integration tests

* capture range var

* address feedback

* address feedback
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.

6 participants