-
Notifications
You must be signed in to change notification settings - Fork 111
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
re-org safety: watch asset transactions and re-create proofs when necessary #419
Conversation
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 haven't finished reviewing, looks good so far. I think you could roll the first two commits into a PR and get those merged as is. I'll try out the new review tool with this PR.
Good idea, done: #424 |
027128f
to
10c4486
Compare
d53d81e
to
4118058
Compare
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.
Looks good! The callback in each subsystem pattern is really neat.
I don't think I saw rebroadcast logic for the actual anchor TX after a reorg, is that handled by the backing LND or did I just miss it?
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.
This is great. I've finished reviewing the whole PR. I couldn't see any further issues that haven't already been commented on.
The only dynamics that concern me are those that relate to multiple actions (mint, send, recv) occurring in close succession. But I think that this PR in its current state is still a big improvement and should probably be merged regardless.
I've updated the proof watching logic and also added a new itest to verify the new behavior. Unfortunately the way we store proofs is a bit weird, so this requires a bit of an explanation. If node A minted (
Now further assume that both blocks 2 and 3 are not yet fully confirmed (<6 confs) and a re-org happens that removes both anchor transactions out of the chain, then we need to update all proofs for block 2 and 3. So for block 2 we would need to update the following files:
And for block 3 we would need to update the following files:
Now the issue is that in case both anchor transactions for state 2 and 3 confirm in the same block now, we don't know in what order the confirmation notifications come in. So however we order things, the proof files where we need to update more than one proof will be temporarily invalid until we have updated both proofs. Currently we do this by just using a dummy header verifier (see I think this is fine for now as eventually the proofs will be valid again once all confirmation notifications were acted upon. I don't think it's worth attempting to do a full dependency tracking and resolution mechanism to address this (it would require the proof watcher to be refactored quite a bit). Curious to hear your thoughts though. |
15e2131
to
5ab7cc1
Compare
The proofs are queried from both the file system and the DB and the first one that has a certain proof returns it. It is a bit unfortunate that we have to do this. Maybe if this becomes a bottleneck we could also store the proof's block height in the DB so we can filter more efficiently?
I checked again, and because we're using the
That's also part of
Yes, once the issuer detects a re-org, it will update the universe(s) it initially sent the issuance proof to. And the universe will do an
No. But what I added is logic in the proof watcher to address this: |
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.
Reviewed all commit messages.
Reviewable status: all files reviewed, 20 unresolved discussions (waiting on @ffranr, @guggero, @positiveblue, and @Roasbeef)
@ guggero thanks for double-checking on the btcwallet
and lnd
behavior in this situation!
Re: proof querying, yes tagging proofs with block height sounds helpful, since the current locator scheme provides no sense of time / ordering.
Also, for the archiver proof reading, would the file backend terminate early if the DB returns first, or complete with the result dropped? Wondering if slow proof reads would slow down DB reads for the same proof or set of proofs (can we short-circuit proof reads, essentially). No changes needed in this PR.
Reading a proof goes through each backend sequentially and the first that returns a non-error is used and the rest is then skipped. Since we add the DB first, then the file archive, the DB will always be asked first. If we feel like that might slow things down, we could perhaps switch the order of the backends. But that might have other impacts, so I'd do it in a separate PR. |
The itest ran into:
Will take a look. |
Okay, looks like this was a flake, wasn't able to reproduce locally. But I removed the error and turned it into a log statement since this might happen in some edge cases around restart and when a block and the conf notification come in at the same time (if we process the block update first and the conf notification afterwards). PR should be good to go now! |
return | ||
} | ||
|
||
err = w.MaybeWatch(f, w.DefaultUpdateCallback()) |
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.
Re the earlier suggestion, if we only pass the items that actually are in "danger" of a re-org, then we wouldn't need this check. We'd also be able to avoid reading all the proof data above here as well (for all the open assets that is).
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 think even with the optimized query where we only fetch the assets not yet buried, we'll want to inspect the full proof file as there might be ancestor transactions that haven't fully confirmed yet.
"of the chain, will update proof "+ | ||
"with next confirmation", txHash) | ||
|
||
// We continue to watch the transaction until |
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.
Ahh ok I think that's the behavior I missed before: that we'll get another confirmation notification in the event of a re-org. So given that, why do we even need to reorg channel in the first place?
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.
For now, just for logging, which was helpful for debugging the itest. In the future, we could react to it.
Needs a rebase after the utxo locking PR was merged! |
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 🏒
Depends on #424, the first 5 commits aren't part of this PR anymore.Fixes #317.
The PR is fully ready for review!
TODOs:
Add re-org watcher to custodian to watch received assetsAdd re-org watcher to freighter to watch sent assetsAllow minting proofs to be updated in the universe/federation after re-orgIntegration tests for above mentioned use casesUnit test re-org watcherThis change is