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

feat: [ADR-070] Unordered Transactions (2/2) #18739

Merged

Conversation

alexanderbez
Copy link
Contributor

@alexanderbez alexanderbez commented Dec 13, 2023

Description

#18641 addresses the core implementation of unordered txs. However, a crucial component to safely support unordered txs is the ability to ensure the map that stores them is durable and consistent[1] across all nodes.

Specifically, when a node restarts, the unordered tx manager (map), needs to be populated with all NON-STALE unordered txs that have been committed so far, i.e. unordered transactions whose TTL value is yet to expire.

We propose to do this by simply writing to a file. However, we also need to address the case of where a new node joins a network via state sync. As it will naturally not have this file, we will also implement a snapshotter extension that will allow the manager (map) to be populated.

Ref:

  • [1] The map only needs to be consistent across all nodes for transactions that are NOT stale. i.e. Consider set A to be the set of all unordered txs that are NOT stale. Consider set B to be the set of all unordered txs that are either NOT stale or some that are stale. Nodes only need to be consistent across set A. It doesn't matter if some nodes have unpurged stale txs -- they'll eventually be cleaned up.

Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • included the correct type prefix in the PR title
  • confirmed ! in the type prefix if API or client breaking change
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • reviewed "Files changed" and left comments if necessary
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • updated the relevant documentation or specification, including comments for documenting Go code
  • confirmed all CI checks have passed

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic, API design and naming, documentation is accurate, tests and test coverage

x/auth/ante/unorderedtx/manager.go Fixed Show fixed Hide fixed
x/auth/ante/unorderedtx/manager.go Fixed Show fixed Hide fixed
x/auth/ante/unorderedtx/manager.go Dismissed Show dismissed Hide dismissed
@alexanderbez alexanderbez marked this pull request as ready for review December 18, 2023 18:22
@alexanderbez alexanderbez requested a review from a team as a code owner December 18, 2023 18:22
Copy link
Contributor

@alexanderbez your pull request is missing a changelog!

@alexanderbez
Copy link
Contributor Author

alexanderbez commented Dec 18, 2023

Marking this ready to review to show the basic idea. Granted, there are docs that need to be written and this needs to be tested more thoroughly.

In general, the design is so so to me personally. The main disadvantage here is that an external manager needs to be managed and we also write and read from disk. If a node for whatever reason fails to read/write to disk, then it's technically not functional and the node has to resync. This should be less of a concern with store v2, but still somewhat brittle IMO.

The alternative to something like this is to manage the state in-protocol, i.e. a completely different design like a 2D nonce lane, e.g. https://github.com/ethereum/RIPs/blob/e8af8009251f24e67311e0d955e7a951284717fc/RIPS/rip-7560.md#non-sequential-nonce-support

cc @yihuang @tac0turtle @testinginprod

mu sync.RWMutex
// txHashes defines a map from tx hash -> TTL value, which is used for duplicate
// checking and replay protection, as well as purging the map when the TTL is
// expired.
txHashes map[TxHash]uint64
}

func NewManager() *Manager {
func NewManager(dataDir string) *Manager {
path := filepath.Join(dataDir, dirName)
Copy link
Member

Choose a reason for hiding this comment

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

whats the difference with putting the file creation from app.go here vs in app.go?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The idea, like WASMVM, is to have the "component" be responsible or "own" the directory/location of where data is written. Also, less work for the app to do.

Copy link
Member

Choose a reason for hiding this comment

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

does that mean this https://github.com/cosmos/cosmos-sdk/pull/18739/files#r1430642896 would get moved into here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, which file?

Copy link
Member

@tac0turtle tac0turtle left a comment

Choose a reason for hiding this comment

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

utACK

simapp/app.go Outdated Show resolved Hide resolved
Copy link
Collaborator

@yihuang yihuang left a comment

Choose a reason for hiding this comment

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

some minor suggestions.

@alexanderbez
Copy link
Contributor Author

Addressed comments @yihuang :)

@alexanderbez alexanderbez merged commit 453e270 into bez/feature/unordered-txs Jan 3, 2024
55 of 59 checks passed
@alexanderbez alexanderbez deleted the bez/feature/unordered-txs-state-mgmt branch January 3, 2024 19:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants