-
Notifications
You must be signed in to change notification settings - Fork 15
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: btc ingress egress tracking #4133
Conversation
PRO-868 Ingress Egress Tracker
This will/should be broken down into smaller tickets after we've discussed it. Problem: The swapping app currently has to wait for the CFE witnessing and respective confirmation on the SC, both for ingress, when the user is depositing funds, and for egress, when the user is receiving funds. This duration can be quite long, because of the added safety margins to protect against reorgs. Solution: While the reorg safety is important for the protocol it's not important for the product. We can use the same code that we use in the CFE witnessing to avoid duplicating the work, but instead redirect the results of that. Requirements:
Useful info:
Out of scope:
If you have questions for the product team and what they need, you can reach out to nat PRO-916 BTC ingress-egress tracker settings to be unified into DepositTrackerSettings
The settings for BTC in the ingress-egress tracker are read from environment on every call. They should instead be read in at the same time as the other settings. |
Codecov Report
@@ Coverage Diff @@
## main #4133 +/- ##
======================================
Coverage 72% 72%
======================================
Files 378 378
Lines 60663 60898 +235
Branches 60663 60898 +235
======================================
+ Hits 43495 43675 +180
- Misses 14904 14956 +52
- Partials 2264 2267 +3
... and 14 files with indirect coverage changes 📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
Fwiw - it's not completely free to do this. the cost of compute on the engine isn't the limiting factor, but how much we're potentially consuming in request limits on any paid PRC provider operators might be using. (I think 5 seconds is fine for now though, but probably wouldn't go any faster). |
engine/src/witness/btc.rs
Outdated
.script_pubkey(), | ||
// TODO: Ideally we can submit an empty type here. For | ||
// Bitcoin and some other chains fee tracking is not | ||
// necessary. PRO-370. |
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.
while we're here, PRO-370 is cancelled, we can delete this comment. we will want to track the fee for btc, but that'll be part of another issue
|
||
let btc_source = BtcSource::new(btc_client.clone()).shared(scope); | ||
|
||
let strictly_monotonic_source = btc_source.strictly_monotonic().then({ |
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.
We can inline this, no need to do the vaults query in between.
let vaults = epoch_source.vaults().await; | ||
|
||
strictly_monotonic_source | ||
.clone() |
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.
unnecessary clone - we need to use the shared adapter here instead - and it's not required on the source
As in: https://linear.app/chainflip/issue/PRO-925/use-shared-adapter-inside-the-chunking-adapters
Pull Request
Closes: PRO-868 and PRO-916
Checklist
Please conduct a thorough self-review before opening the PR.
Summary
This compliments existing "mempool" tracking by allowing an rpc client to subscribe to BTC transactions. This PR is best to be reviewed commit-by-commit.
Note that I also changed BTC client poll internals from 10s to 5s. This is to account for localnet where block time is ~6s or so and would result in missing blocks (mostly doesn't matter, but I want to avoid future surprises when people try this on localnet). I think this is a reasonable change for engine witnessing on mainnet too (I would decrese it even further personally).
I know that
continuous
adapter is meant to fill in the gaps (and I even experimented with it) but it has some side effects like prosessing blocks from the start of the epoch (which I imagine we don't want for the tracker) and expecting a database. Long term I wouldn't mind an adapter of some sort which would just ensure we don't skip blocks (in some rare edge cases) and not worry about epochs/databases, but for now it is not srictly necessary since we already don't guarantee 100% reliability in the tracker.Also, I discovered that the current engine's witnesser delays blocks by ~20 seconds even when safety margin isn't used, so the current tracker doesn't process blocks as early as we would hope (I created a separate issue to address this: https://linear.app/chainflip/issue/PRO-923/remove-block-delay-in-ingress-egress-tracker)