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

Witness filtering with refactored state management workflow #241

Merged
merged 12 commits into from
Aug 9, 2024

Conversation

dr-orlovsky
Copy link
Member

@dr-orlovsky dr-orlovsky commented Jul 26, 2024

Addresses RGB-WG/rgb#124 and #238

Also provides prerequisites for fulfilling RGB-WG/rgb-core#147 and completing RGB-WG/rgb-core#208

Requires/based on RGB-WG/rgb-core#208

The PR refactors State type - the manager of the state of smart contracts - in the same manner Stash and Index work. Previously, most of contract state related types were the part of RGB Core library, due to the fact that contract state can be accessed by AluVM op-codes.

The mentioned issues required introducing concept of checking witness transaction mining (or channel) status (see WitnessOrd type) and filtering only the state which is valid. This can be done only with a "thick" State type organized in the same manner as Stash or Index. To achieve this purpose, RGB Core instead of using concrete state types has moved to the use of trait-based accessors to the contract state, ensuring that the consensus parameters of the state are fixed there. Next, this PR does the refactoring of the State in the standard library, adding information about the status of the witness transactions and using it for filtering all contract state data.

With that, the contract state becomes aware of witness transaction mining status and knows how to re-organize itself on blockchain re-orgs. Thus, an RGB wallet just gets proper state, with state not anymore commited to valid transactions (like previous channel state or related to transactions removed from the blockchain after a re-org) already filtered out; nothing additional should be done on the wallet part and no new filters are needed. As a result, when you try to do a payment, you get a consistent state of PSBT inputs using only valid transactions.

The new workflow also works with a global state (it was the harderst part of the story). Other than that, API ensures that all of that is present in the same consitent way in the consensus level (will be needed when we will have full contract state introspection in AluVM, which is related to RGB-WG/rgb-core#147 and RGB-WG/rgb-core#208).

Pls keep in mind these changes do touch only state, not stash or index, meaning that stash still contains all the past state transitions, even those which witnesses are no more mined or are related to the past channel. It is only ephemeral state which reacts to re-orgs and adjusts itself accordingly, filtering out the no-more-valid parts of the stash (which may become valid again after another re-org or because of a non-cooperative closing).

TODO list:

  • filter out global state basing on the witness information
  • provide an API to sync witness mining status from rgb

Part of the epic:

@dr-orlovsky dr-orlovsky added bug Something isn't working epic Epic task covering multiple steps of implementation labels Jul 26, 2024
@dr-orlovsky dr-orlovsky added this to the v0.11.0 milestone Jul 26, 2024
@dr-orlovsky dr-orlovsky self-assigned this Jul 26, 2024
@dr-orlovsky dr-orlovsky force-pushed the mining branch 2 times, most recently from 5fff29a to f69a5ce Compare July 27, 2024 21:06
@dr-orlovsky dr-orlovsky merged commit ea0e5eb into master Aug 9, 2024
18 of 19 checks passed
@dr-orlovsky dr-orlovsky deleted the mining branch September 5, 2024 10:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working epic Epic task covering multiple steps of implementation
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

1 participant