-
Notifications
You must be signed in to change notification settings - Fork 59
fix(platform-wallet): harden asset-lock recovery — invisible chain-locked rows, two unbounded waits #4422
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
Merged
Merged
fix(platform-wallet): harden asset-lock recovery — invisible chain-locked rows, two unbounded waits #4422
Changes from 6 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
c97ecf3
fix(wallet): surface RecoveredFromChain asset locks on host resume paths
bfoss765 1f06fc5
fix(wallet): bound the asset-lock recovery waits that could pin a hos…
bfoss765 c017d88
fix(wallet): a rejected re-broadcast must not untrack, and bound the …
bfoss765 a21c55c
fix(wallet): RecoveredFromChain is proven-final and fundable in the K…
bfoss765 7768174
fix(wallet): surface and route resumable SHIELDED top-ups on both hosts
bfoss765 6f4506c
docs(wallet-ffi): a zero resume timeout selects the policy default, n…
bfoss765 3ab29ab
fix(example-apps): key shielded resume single-flighting on the operat…
bfoss765 19849eb
docs(wallet-ffi): carve the accepted Built re-broadcast out of the ze…
bfoss765 d46ae46
docs(wallet): record why reconcile degrades every proof-upgrade failu…
bfoss765 6ff9c1e
test(wallet): pin both promotion-failure arms of the reconciliation d…
bfoss765 fc62336
fix(wallet): consult the local proof before failing a rejected defens…
bfoss765 d03dcf7
fix(example-apps): mint a unique operation id per fresh shield
bfoss765 0558156
Merge branch 'v4.2-dev' into fix/asset-lock-recovery-hardening
HashEngineering e74f847
Merge branch 'v4.2-dev' into fix/asset-lock-recovery-hardening
HashEngineering 2b7b85d
fix(wallet): do not report a rejected defensive re-broadcast as a rej…
shumkov 70ee558
Merge branch 'v4.2-dev' into fix/asset-lock-recovery-hardening
HashEngineering a148a89
Merge remote-tracking branch 'origin/v4.2-dev' into w4422
shumkov 3ea5e88
Merge branch 'v4.2-dev' into fix/asset-lock-recovery-hardening
shumkov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
...tlinExampleApp/app/src/main/java/org/dashfoundation/example/ui/funding/ResumableTopUps.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| package org.dashfoundation.example.ui.funding | ||
|
|
||
| import kotlinx.coroutines.flow.Flow | ||
| import kotlinx.coroutines.flow.combine | ||
| import kotlinx.coroutines.flow.flowOf | ||
| import org.dashfoundation.dashsdk.persistence.entities.AssetLockEntity | ||
| import org.dashfoundation.example.navigation.FundFromAssetLock | ||
| import org.dashfoundation.example.navigation.ShieldedFund | ||
| import org.dashfoundation.example.util.hexToBytes | ||
|
|
||
| /** | ||
| * The two `AssetLockFundingType` discriminants that own the "Pending | ||
| * Platform Top Ups" recovery surface. | ||
| * | ||
| * The full domain is `0 IdentityRegistration, 1 IdentityTopUp, | ||
| * 2 IdentityTopUpNotBound, 3 IdentityInvitation, 4 AssetLockAddressTopUp, | ||
| * 5 AssetLockShieldedAddressTopUp`. Types `0..2` recover on the identity | ||
| * screens (`IdentitiesContentView.crossWalletResumableLocks` and its Kotlin | ||
| * counterpart, both of which admit only `0..2`); `3` is a bearer voucher | ||
| * consumed exclusively by the invitation reclaim flow. That leaves `4` and | ||
| * `5` with no recovery home other than this surface — and `5` had none at | ||
| * all until it was added here. | ||
| */ | ||
| internal const val FUNDING_TYPE_ADDRESS_TOP_UP = 4 | ||
| internal const val FUNDING_TYPE_SHIELDED_ADDRESS_TOP_UP = 5 | ||
|
|
||
| /** | ||
| * Funding types the top-up recovery surface observes, in render order. | ||
| * | ||
| * This list is the whole point of `AssetLockDao.observeResumableTopUpsByFundingType` | ||
| * existing: the older `observeResumableAddressTopUps` hardcodes | ||
| * `fundingTypeRaw = 4`, so a stalled or `RecoveredFromChain` SHIELDED | ||
| * top-up (`5`) was returned by no query any screen ran. Widening the | ||
| * status predicate alone did not fix that — a row invisible on the | ||
| * funding-type axis stays invisible however generous the status axis is. | ||
| */ | ||
| internal val RESUMABLE_TOP_UP_FUNDING_TYPES = listOf( | ||
| FUNDING_TYPE_ADDRESS_TOP_UP, | ||
| FUNDING_TYPE_SHIELDED_ADDRESS_TOP_UP, | ||
| ) | ||
|
|
||
| /** | ||
| * Cross-wallet, cross-funding-type stream of resumable orphan top-up locks, | ||
| * each tagged with the hex wallet id that owns it (needed for the Resume | ||
| * navigation, which is wallet-scoped while the Identities tab is not). | ||
| * | ||
| * [observe] is the DAO seam — production passes | ||
| * `AssetLockDao::observeResumableTopUpsByFundingType`, which applies the | ||
| * recoverable-status predicate (`[1,3] ∪ {5}`) SQL-side. Taking it as a | ||
| * parameter keeps this function a pure combinator: the funding-type fan-out | ||
| * that the blocker was about is then assertable without a Room database or | ||
| * a Compose runtime. | ||
| * | ||
| * Emissions are ordered by (wallet, funding type) so the rendered list | ||
| * doesn't reshuffle between recompositions. | ||
| */ | ||
| internal fun resumableTopUpsAcrossWallets( | ||
| walletIdHexes: List<String>, | ||
| observe: (walletId: ByteArray, fundingTypeRaw: Int) -> Flow<List<AssetLockEntity>>, | ||
| ): Flow<List<Pair<String, AssetLockEntity>>> { | ||
| // `combine` over an empty source list never emits, which would leave the | ||
| // section stuck on its initial value instead of resolving to "nothing to | ||
| // recover". Short-circuit to an explicit empty emission. | ||
| if (walletIdHexes.isEmpty()) return flowOf(emptyList()) | ||
|
|
||
| val slots: List<Pair<String, Int>> = walletIdHexes.flatMap { hex -> | ||
| RESUMABLE_TOP_UP_FUNDING_TYPES.map { fundingType -> hex to fundingType } | ||
| } | ||
| val flows = slots.map { (hex, fundingType) -> observe(hex.hexToBytes(), fundingType) } | ||
| return combine(flows) { emissions -> | ||
| slots.zip(emissions.toList()).flatMap { (slot, locks) -> | ||
| val (hex, _) = slot | ||
| locks.map { hex to it } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * The screen a Resume tap on an orphan top-up row must open, or `null` when | ||
| * the row's funding type has no resume flow on this surface. | ||
| * | ||
| * Routing on `fundingTypeRaw` is the second half of the fix: surfacing a | ||
| * type-5 row is useless if its Resume lands on | ||
| * [org.dashfoundation.example.ui.funding.FundFromAssetLockScreen], whose | ||
| * submit calls `resumeFundFromAssetLock` — the platform-ADDRESS resume. A | ||
| * shielded lock has to reach `shieldedResumeFundFromAssetLock` instead, | ||
| * which is what [ShieldedFund] in resume mode does. | ||
| * | ||
| * Fail-closed on anything else: identity-family types (`0..3`) recover on | ||
| * the identity screens, and an unknown discriminant must not be dispatched | ||
| * to a resume flow that would mis-handle it. | ||
| */ | ||
| internal fun resumeRouteFor(walletIdHex: String, lock: AssetLockEntity): Any? = | ||
| when (lock.fundingTypeRaw) { | ||
| FUNDING_TYPE_ADDRESS_TOP_UP -> FundFromAssetLock( | ||
| walletIdHex = walletIdHex, | ||
| resumeOutPointHex = lock.outPointHex, | ||
| ) | ||
| FUNDING_TYPE_SHIELDED_ADDRESS_TOP_UP -> ShieldedFund( | ||
| walletIdHex = walletIdHex, | ||
| resumeOutPointHex = lock.outPointHex, | ||
| ) | ||
| else -> null | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.