-
Notifications
You must be signed in to change notification settings - Fork 137
tapdb: add implementation of supplycommit.CommitmentTracker and supplycommit.StateMachineStore #1508
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
Conversation
4778c90
to
d718094
Compare
522c3ee
to
d786104
Compare
d718094
to
1db2104
Compare
d786104
to
af5f8f5
Compare
e67b58f
to
6b99f70
Compare
af5f8f5
to
64516c9
Compare
6b99f70
to
5056daa
Compare
64516c9
to
6e0b6a4
Compare
5056daa
to
5c20025
Compare
6e0b6a4
to
aa782c8
Compare
-- Table storing individual update events associated with a pending transition. | ||
CREATE TABLE supply_update_events ( | ||
event_id INTEGER PRIMARY KEY, | ||
|
||
-- Reference to the state transition this event is part of. | ||
transition_id BIGINT NOT NULL REFERENCES supply_commit_transitions(transition_id) ON DELETE CASCADE, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
an update event can't be persisted unless it references an existing transition, is that correct?
If so, then if we're waiting for tx conf then new update events can't be persisted?
If true, then I don't think it matters a great deal, but from a UX perspective, we will need to return an error to the user along the lines of: unconfirmed supply tx, can't accept new asset ignore right now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a great insight. As of right now, if everything is spun up together and a user attempts to add a new update while we're creating a new commitment on-disk, then this'll fail.
I think we can fix this just by removing the NOT NULL
here. We'll need some additional follow ups in the state machine though:
- Any time an update comes through in a state, attempt to insert it to disk w/ a nil
transition_id
. - Once we circle back to the default state, then read all the "dangling" update from disk, and assign them to a state transition (in a single db txn).
Alternatively, we can create some other table, then re-insert them in the default state.
I can either do this in another PR (as it affects this one, and the next), or do the incremental change here. Which is preferred?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great stuff! Did a first pass to load some context, will continue with the other PRs in the saga.
// NULL (e.g., initial commit before ApplyStateTransition ran), use the | ||
// empty root. | ||
var rootNode *mssmt.BranchNode | ||
if commit.SupplyRootHash == nil || !commit.SupplyRootSum.Valid { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check length instead of nil?
tapdb/supply_commit.go
Outdated
// its associated chain confirmation details. | ||
func fetchCommitment(ctx context.Context, db SupplyCommitStore, | ||
commitID sql.NullInt64, groupKeyBytes []byte, | ||
) (lfn.Option[supplycommit.RootCommitment], lfn.Option[commitmentChainInfo], error) { //nolint:lll |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does the root commitment here really need to be an option? Doesn't look like it's ever None
in a non-error case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have it as an option as in supplycommit.SupplyStateTransition
, it's an option. It's an option here as the very first time we go to create a state transition, OldCommitment
won't yet exist.
We can return a value of None
in the very fist error case: if we query and it doesn't exist (ErrNoRows
), then noneRootCommit
with a nil
error is returned.
} | ||
``` | ||
|
||
## State Machine Persistence Logic |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice doc!
aa782c8
to
36e3753
Compare
bf61350
to
16ae70c
Compare
36e3753
to
1c17470
Compare
16ae70c
to
67728da
Compare
1c17470
to
b5f3d5e
Compare
8b06b69
to
b8988d3
Compare
@Roasbeef, remember to re-request review from reviewers when ready |
37bdcfa
to
b5a6c5e
Compare
b8988d3
to
85109d9
Compare
b5a6c5e
to
c59b408
Compare
Changed the base to target main. |
@Roasbeef here's a rebased version of this PR with additional fixups to address the unit test failures and SQL migration conflict: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM pending existing commits and rebase (and DB migration file re-numbering) 🎉
c59b408
to
99529ae
Compare
Pull Request Test Coverage Report for Build 15915388434Details
💛 - Coveralls |
87ba694
to
e285f19
Compare
… tree state machine In this commit, we add a new migration for the persistence layer of the supply tree state machine. We track a state machine that points to the latest supply commitment. We update the supply commit via a new state transition, which references a series of updates. Once we're ready to apply, we'll apply the updates, mark the transition as finalized, and finally update the relevant pointers. We also make a change to modify mint_anchor_uni_commitments to point to a supply commitment. This lets us keep track of the set of pre commitments that aren't yet spent.
… new spent_by field
…and supplycommit.StateMachineStore In this commit, we add concrete implementation of both CommitmentTracker and StateMachineStore. This implements the persistence layer for the supply commit state machine. The main method to understand is ApplyStateTransition, as it implements the atomic update of all the various components (tree, state transition, etc) on disk.
e285f19
to
277c8f3
Compare
In this PR, we add a concrete implementation of the two fundamental interfaces that will drive the state machine implemented in #1464.
We start with a state machine on disk for a given group key that also points to the latest supply commitment. When we want to add new elements to the supply tree, we create a new state transition, and then queue pending updates associated with this state transition. Once we've signed and broadcasted the commitment transaction, we then apply the state transition: insert all the updates into the tree, update the state machine to point to that new tree, and finalize the state transition.
See the readme for more details.