Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
83a9498
fix(platform-wallet): persist DashPay backfill coverage so a relaunch…
HashEngineering Sep 25, 2026
3fd3f54
feat(platform-wallet-ffi): carry the DashPay backfill record across t…
HashEngineering Sep 25, 2026
7618785
feat(kotlin-sdk): persist the DashPay backfill record on the wallet r…
HashEngineering Sep 25, 2026
48b1eb0
fix(platform-wallet): keep the backfill record's extent honest and pe…
HashEngineering Sep 26, 2026
d3b1298
feat(platform-wallet-ffi): persist the outbound contact-account marke…
HashEngineering Sep 26, 2026
ee8fcc1
feat(kotlin-sdk): store the outbound contact-account marker on the co…
HashEngineering Sep 26, 2026
74898f5
test(platform-wallet): model late-discovered contacts rewinding once …
HashEngineering Sep 26, 2026
ffe15d6
fix(platform-wallet): keep the backfill record's coverage paired with…
HashEngineering Sep 27, 2026
a40871e
fix(platform-wallet): order backfill cursor writes against the event …
HashEngineering Sep 28, 2026
af72d09
fix(platform-wallet): order queued sync-height advances by emission, …
HashEngineering Sep 29, 2026
5ce582b
fix(platform-wallet): owe account-add rewinds, forward the account ge…
HashEngineering Sep 29, 2026
33612c9
fix(platform-wallet): seed a recreated wallet's durable cursor from t…
HashEngineering Sep 29, 2026
011fcf1
fix(platform-wallet)!: deliver backfill coverage only on atomic round…
HashEngineering Sep 30, 2026
4090444
fix(platform-wallet): drop an owed cursor once the host has climbed p…
HashEngineering Oct 1, 2026
df6e372
fix(platform-wallet): make same-id wallet recreation safe for the bac…
HashEngineering Oct 2, 2026
72b34c0
fix(platform-wallet): record contacts as forward-covered when the sca…
HashEngineering Oct 2, 2026
8c32330
fix(platform-wallet): keep a predecessor's cursor over the pre-lock s…
HashEngineering Oct 6, 2026
8ab6c9c
fix(platform-wallet): run the rescan sweep once more after the startu…
HashEngineering Sep 18, 2026
64a383a
test(platform-wallet): pin the post-drain rescan sweep at startup
HashEngineering Sep 18, 2026
28fa6bf
fix(platform-wallet): replace the host's backfill record when a same-…
HashEngineering Oct 7, 2026
dca544e
fix(platform-wallet): canonicalize the backfill cover set on every re…
HashEngineering Oct 8, 2026
46349d0
fix(unified-sdk-jni): wire the DashPay backfill slot only for a bridg…
HashEngineering Oct 8, 2026
4aa7cdc
Merge branch 'v5.0-dev' into fix/dashpay-backfill-persistence-4302
HashEngineering Oct 8, 2026
81e78a7
fix(platform-wallet): keep backfill coverage off buffering backends a…
HashEngineering Oct 8, 2026
2cb9049
fix(unified-sdk-jni): match the bridge override probe on the called d…
HashEngineering Oct 8, 2026
f20cf8a
fix(platform-wallet): require atomic changesets for durable backfill …
HashEngineering Oct 9, 2026
90cb46a
fix(platform-wallet-ffi): deliver empty backfill records as invalidat…
HashEngineering Oct 9, 2026
592cc1b
fix(platform-wallet)!: refuse to publish over backfill coverage a hos…
HashEngineering Oct 10, 2026
6739bab
Merge branch 'v5.0-dev' into fix/dashpay-backfill-persistence-4302
HashEngineering Oct 10, 2026
0309ff6
fix(unified-sdk-jni): wire the backfill slot only when the bridge als…
HashEngineering Oct 12, 2026
54459c0
fix(platform-wallet): serialize outbound account registration and bin…
HashEngineering Oct 12, 2026
7385b54
fix(platform-wallet): bind the outbound marker in the account's round…
HashEngineering Oct 12, 2026
cd17c61
fix(platform-wallet): keep outbound-account markers in memory unless …
HashEngineering Oct 12, 2026
fd21b6f
fix(platform-wallet): drop loaded backfill coverage for receival acco…
HashEngineering Oct 12, 2026
49aab2c
fix(platform-wallet): make registration the only writer of a durable …
HashEngineering Oct 12, 2026
3fda886
fix(platform-wallet): validate restored outbound addresses per row an…
HashEngineering Oct 12, 2026
a8d8dfb
refactor(platform-wallet): validate restored outbound addresses throu…
HashEngineering Oct 12, 2026
bb8b383
Merge branch 'v5.0-dev' into fix/dashpay-backfill-persistence-4302
HashEngineering Oct 12, 2026
fe9964d
Merge branch 'v5.0-dev' into fix/dashpay-backfill-persistence-4302
HashEngineering Oct 14, 2026
efb800d
fix(platform-wallet): keep the post-drain rescan sweep inside the sta…
HashEngineering Oct 14, 2026
c9cbdfe
fix(platform-wallet): keep a faulted session's backfill coverage in m…
HashEngineering Oct 14, 2026
87cbe07
fix(platform-wallet): ignore a rewind flag that has no height beside it
HashEngineering Oct 14, 2026
d95a0bc
fix(platform-wallet): re-read a stale load snapshot, and stop retryin…
HashEngineering Oct 14, 2026
5182e71
fix(platform-wallet): hold the cursor lock from a load's re-read to i…
HashEngineering Oct 14, 2026
ab88f3d
fix(platform-wallet-ffi): advertise the backfill record only to hosts…
HashEngineering Oct 14, 2026
f7ffed3
perf(platform-wallet): validate restored outbound pools only where a …
HashEngineering Oct 14, 2026
1d32295
Merge branch 'v5.0-dev' into fix/dashpay-backfill-persistence-4302
HashEngineering Oct 14, 2026
88243e3
perf(platform-wallet): index receival-account membership in the resca…
HashEngineering Oct 14, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -613,13 +613,90 @@ class DashDatabaseMigrationTest {
db.close()
}

/**
* v14 -> v15 adds the DashPay backfill record columns on `wallets`
* (`dashPayBackfillFloor`, `dashPayBackfillRewoundFrom`,
* `dashPayBackfillCovered`), all nullable and additive. A pre-migration
* wallet reads back with no record — native then rewinds once, as it did
* before the record existed — and a row written afterwards keeps all
* three, so a restored wallet resumes its backfill instead of restarting
* it (dashpay/platform#4302).
*/
@Test
fun migrate14To15AddsDashPayBackfillColumns() {
helper.createDatabase(dbName, 14).apply {
execSQL(
"INSERT INTO wallets (walletId, walletGroupId, networkRaw, name, birthHeight, " +
"syncedHeight, lastSynced, isImported, createdAt, lastUpdated) " +
"VALUES (x'01', x'02', 1, 'w', 0, 2309809, 0, 0, 0, 0)",
)
execSQL(
"INSERT INTO identities (identityId, balance, revision, isLocal, identityType, " +
"createdAt, lastUpdated, networkRaw, identityIndex, walletId) " +
"VALUES (x'0A', 0, 0, 1, 'User', 0, 0, 1, 0, x'01')",
)
execSQL(
"INSERT INTO dashpay_contact_requests (networkRaw, ownerIdentityId, " +
"contactIdentityId, isOutgoing, senderKeyIndex, recipientKeyIndex, " +
"accountReference, encryptedPublicKey, coreHeightCreatedAt, createdAtMillis, " +
"paymentChannelBroken, contactHidden, createdAt, lastUpdated) " +
"VALUES (1, x'0A', x'0B', 0, 2, 3, 4, x'05', 1226329, 0, 0, 0, 0, 0)",
)
close()
}

val db = helper.runMigrationsAndValidate(dbName, 15, true, DashDatabase.MIGRATION_14_15)

db.query(
"SELECT externalAccountReference FROM dashpay_contact_requests WHERE ownerIdentityId = x'0A'",
).use { c ->
assertTrue(c.moveToFirst())
assertTrue("pre-migration contact rows carry no outbound-account marker", c.isNull(0))
}
db.execSQL(
"UPDATE dashpay_contact_requests SET externalAccountReference = 4 WHERE ownerIdentityId = x'0A'",
)
db.query(
"SELECT externalAccountReference FROM dashpay_contact_requests WHERE ownerIdentityId = x'0A'",
).use { c ->
assertTrue(c.moveToFirst())
assertEquals(4, c.getInt(0))
}

db.query(
"SELECT dashPayBackfillFloor, dashPayBackfillRewoundFrom, dashPayBackfillCovered, " +
"syncedHeight FROM wallets WHERE walletId = x'01'",
).use { c ->
assertTrue(c.moveToFirst())
assertTrue("pre-migration wallets have no backfill record", c.isNull(0))
assertTrue(c.isNull(1))
assertTrue(c.isNull(2))
assertEquals("the cursor itself is untouched", 2_309_809, c.getInt(3))
}
db.execSQL(
"UPDATE wallets SET dashPayBackfillFloor = 2167092, " +
"dashPayBackfillRewoundFrom = 2537092, dashPayBackfillCovered = x'AABB' " +
"WHERE walletId = x'01'",
)
db.query(
"SELECT dashPayBackfillFloor, dashPayBackfillRewoundFrom, dashPayBackfillCovered " +
"FROM wallets WHERE walletId = x'01'",
).use { c ->
assertTrue(c.moveToFirst())
assertEquals(2_167_092, c.getInt(0))
assertEquals(2_537_092, c.getInt(1))
assertTrue(byteArrayOf(0xAA.toByte(), 0xBB.toByte()).contentEquals(c.getBlob(2)))
}
db.close()
}

/** The requested contiguous path from the pre-u64 v4 schema to latest. */
@Test
fun migrate4ToLatest() {
helper.createDatabase(dbName, 4).close()
helper.runMigrationsAndValidate(
dbName,
14,
15,
true,
DashDatabase.MIGRATION_4_5,
DashDatabase.MIGRATION_5_6,
Expand All @@ -631,16 +708,17 @@ class DashDatabaseMigrationTest {
DashDatabase.MIGRATION_11_12,
DashDatabase.MIGRATION_12_13,
DashDatabase.MIGRATION_13_14,
DashDatabase.MIGRATION_14_15,
).close()
}

/** The full chain from v1 must also land on a valid v14 schema. */
/** The full chain from v1 must also land on a valid v15 schema. */
@Test
fun migrateAllTheWayFrom1() {
helper.createDatabase(dbName, 1).close()
helper.runMigrationsAndValidate(
dbName,
14,
15,
true,
DashDatabase.MIGRATION_1_2,
DashDatabase.MIGRATION_2_3,
Expand All @@ -655,6 +733,7 @@ class DashDatabaseMigrationTest {
DashDatabase.MIGRATION_11_12,
DashDatabase.MIGRATION_12_13,
DashDatabase.MIGRATION_13_14,
DashDatabase.MIGRATION_14_15,
).close()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,40 @@ abstract class NativePersistenceBridge {
*/
open fun onWalletChangesetChainLockHeight(walletId: ByteArray, height: Int): Int = 0

/**
* The wallet's DashPay coreHeight backfill record — the durable half of
* the contact rescan guard (dashpay/platform#4302). Fired inside the
* round, after the wallet changeset header, on every round whose
* changeset carries a record; the rescan sweep writes it on the SAME
* round as the lowered `syncedHeight` it belongs with, so a handler that
* stores both holds a record that only ever vouches for a cursor it also
* stored. Descriptor `([BII[BI)I`.
*
* Whole-record semantics: replace what the wallet row holds, never
* merge. [covered] is ONE flat `byte[]` of `72 * coveredCount` bytes —
* per receival account the owner identity id (32), the contact identity
* id (32), the account index (u32) and the height it is covered from
* (u32), both little-endian — the same
* packing the sweep slot uses for its txids. Store it as an opaque blob
* and hand it back unchanged on [WalletRestoreData.dashPayBackfillCovered];
* only native reads it.
*
* Purely additive: an implementation that ignores it keeps today's
* behaviour — the backfill re-fires on every launch, re-walking every
* filter from the earliest contact's core height. Slow, never lossy.
*
* Delivered only to a bridge that also overrides [onWalletChangesetHeader]:
* the record vouches for the cursor that callback stores, so a bridge
* keeping the inherited no-op header never receives it.
*/
open fun onWalletChangesetDashPayBackfill(
walletId: ByteArray,
floor: Int,
rewoundFrom: Int,
covered: ByteArray,
coveredCount: Int,
): Int = 0

// ── Identities ────────────────────────────────────────────────────

/**
Expand Down Expand Up @@ -562,14 +596,25 @@ abstract class NativePersistenceBridge {
// ── Contacts ──────────────────────────────────────────────────────

/**
* One `ContactRequestFFI` upsert. Descriptor
* `([B[B[BZIII[B[B[BIJZLjava/lang/String;Ljava/lang/String;ZLjava/lang/String;[I)I`.
* One `ContactRequestFFI` upsert, marker-less form (the signature this
* API had before the outbound-account marker). Native calls the
* overload below; this one stays so existing implementations keep
* compiling and keep receiving rows through the delegating default.
*
* The tail block ([paymentChannelBroken] / [alias] / [note] /
* [isHidden] / [contactAccountLabel] / [acceptedAccounts]) is
* established-row relationship metadata (contactInfo + DIP-15
* accepted accounts) — null / false / empty on pending rows.
* [acceptedAccounts] is never null (empty when absent).
*
* [hasExternalAccountReference] / [externalAccountReference] mirror
* `EstablishedContact::external_account_reference`: the incoming
* `accountReference` the registered outbound (sending) account was
* built from. Store it and hand it back on
* [ContactRequestRestoreData]; a cold start that restores `None`
* treats the account as rotated and rebuilds it on every launch
* (dashpay/platform#4302). Replicated onto both established rows;
* `false` / 0 on pending rows.
*/
@Suppress("LongParameterList")
open fun onPersistContactUpsert(
Expand All @@ -593,6 +638,45 @@ abstract class NativePersistenceBridge {
acceptedAccounts: IntArray,
): Int = 0

/**
* The overload native calls (descriptor
* `([B[B[BZIII[B[B[BIJZLjava/lang/String;Ljava/lang/String;ZLjava/lang/String;[IZI)I`):
* the row above plus `EstablishedContact::external_account_reference` as
* `(hasExternalAccountReference, externalAccountReference)`. The default
* body delegates to the marker-less overload, so an implementation that
* overrides only that one keeps persisting every other field and merely
* loses the marker (native then rebuilds the outbound account once per
* launch, the pre-marker behaviour). Override this one to store it.
*/
@Suppress("LongParameterList")
open fun onPersistContactUpsert(
walletId: ByteArray,
ownerId: ByteArray,
contactId: ByteArray,
isOutgoing: Boolean,
senderKeyIndex: Int,
recipientKeyIndex: Int,
accountReference: Int,
encryptedPublicKey: ByteArray,
encryptedAccountLabel: ByteArray?,
autoAcceptProof: ByteArray?,
coreHeightCreatedAt: Int,
createdAt: Long,
paymentChannelBroken: Boolean,
alias: String?,
note: String?,
isHidden: Boolean,
contactAccountLabel: String?,
acceptedAccounts: IntArray,
hasExternalAccountReference: Boolean,
externalAccountReference: Int,
): Int = onPersistContactUpsert(
walletId, ownerId, contactId, isOutgoing, senderKeyIndex, recipientKeyIndex,
accountReference, encryptedPublicKey, encryptedAccountLabel, autoAcceptProof,
coreHeightCreatedAt, createdAt, paymentChannelBroken, alias, note, isHidden,
contactAccountLabel, acceptedAccounts,
)

/** One sent-side `ContactRequestRemovalFFI`. Descriptor `([B[B[B)I`. */
open fun onPersistContactRemovalSent(
walletId: ByteArray,
Expand Down Expand Up @@ -968,7 +1052,41 @@ class WalletRestoreData(
* `loadWalletList`.
*/
@JvmField val lastAppliedChainLockBytes: ByteArray,
)
) {
// The DashPay backfill record rides as body properties, not constructor
// parameters, so this class keeps exactly the JVM constructors it had
// before the record existed: a bridge compiled against the older SDK —
// Java, or Kotlin using the defaulted `providerSpecialTxs` — still links
// (dashpay/platform#4302 review). Set them with `apply { … }`; native
// reads them by field name either way.

/**
* Whether the wallet row holds a DashPay coreHeight backfill record
* (dashpay/platform#4302). `false` for a wallet that never rewound for a
* contact or a row persisted before the record existed; native then
* ignores the three fields below, and the first rescan sweep behaves as
* it always did and writes one. Mirror of
* `WalletRestoreEntryFFI.has_dashpay_backfill`.
*/
@JvmField var hasDashPayBackfill: Boolean = false

/** Lowest height the backfill rewound the cursor to. */
@JvmField var dashPayBackfillFloor: Int = 0

/**
* Highest cursor the backfill rewound from — the height the scan climbs
* back to for the backfill to be complete.
*/
@JvmField var dashPayBackfillRewoundFrom: Int = 0

/**
* The record's cover set, exactly as [NativePersistenceBridge.onWalletChangesetDashPayBackfill]
* delivered it: `72` bytes per covered receival account. Native re-packs it into
* a `DashPayBackfillCoveredContactFFI` array; a blob that is not a whole
* number of entries is read as no record.
*/
@JvmField var dashPayBackfillCovered: ByteArray = ByteArray(0)
}

/**
* Kotlin staging row for the unchanged `ProviderSpecialTxRestoreEntryFFI`.
Expand Down Expand Up @@ -1258,7 +1376,21 @@ class ContactRequestRestoreData(
@JvmField val isHidden: Boolean,
@JvmField val contactAccountLabel: String?,
@JvmField val acceptedAccounts: IntArray,
)
) {
// Body properties, not constructor parameters, for the same reason as
// [WalletRestoreData]'s backfill fields: the class keeps the JVM
// constructor it had before the marker existed.

/**
* `EstablishedContact::external_account_reference` as a `(present,
* value)` pair, exactly as [NativePersistenceBridge.onPersistContactUpsert]
* delivered it. `false` restores `None`, which makes native rebuild the
* outbound account once on the next sweep.
*/
@JvmField var hasExternalAccountReference: Boolean = false

@JvmField var externalAccountReference: Int = 0
}

/**
* One flat identity-public-key row — mirror of `IdentityKeyRestoreFFI`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,27 @@ import org.dashfoundation.dashsdk.persistence.entities.WalletManagerMetadataEnti
* contract's `oncePerIdentityDistribution` block as JSON, so the claim
* screen can offer the third distribution kind. NULL for every pre-existing
* row; the next contract materialization fills it in.
*
* Version 15 (durable DashPay backfill, dashpay/platform#4302): adds the
* nullable `wallets.dashPayBackfillFloor`, `wallets.dashPayBackfillRewoundFrom`
* and `wallets.dashPayBackfillCovered` columns — the record native writes
* through `onWalletChangesetDashPayBackfill` on the same round as the lowered
* `syncedHeight` it belongs with, and reads back on `loadWalletList`. The
* contact rescan used to guard against re-lowering the cursor in memory only,
* while the cursor it lowers is durable, so every fresh process rewound again
* and re-walked every filter from the earliest contact's core height. All
* three NULL (every pre-migration row) means no record: native rewinds once
* more, writes one, and never again for the contacts it covers. The same
* version adds the nullable `dashpay_contact_requests.externalAccountReference`
* column — `EstablishedContact::external_account_reference`, the marker that
* says which incoming `accountReference` the outbound sending account was
* built from. It was never persisted, so every cold start read it as absent,
* treated the account as rotated, tore it down and rebuilt it — and that
* rebuild was the per-launch cursor rewind. NULL for pre-migration rows:
* native rebuilds once, stamps it, and never again.
*/
@Database(
version = 14,
version = 15,
exportSchema = true,
entities = [
WalletEntity::class,
Expand Down Expand Up @@ -679,6 +697,25 @@ abstract class DashDatabase : RoomDatabase() {
}
}

/**
* v14 -> v15: additive nullable `wallets.dashPayBackfillFloor`,
* `wallets.dashPayBackfillRewoundFrom`, `wallets.dashPayBackfillCovered`
* and `dashpay_contact_requests.externalAccountReference`, see the
* version-15 class doc above. NULL for every pre-existing row — no
* record on file and no marker, so the next sweep rebuilds the
* outbound account once, rescans once, and writes both.
*/
val MIGRATION_14_15: Migration = object : Migration(14, 15) {
override fun migrate(db: SupportSQLiteDatabase) {
db.execSQL("ALTER TABLE `wallets` ADD COLUMN `dashPayBackfillFloor` INTEGER")
db.execSQL("ALTER TABLE `wallets` ADD COLUMN `dashPayBackfillRewoundFrom` INTEGER")
db.execSQL("ALTER TABLE `wallets` ADD COLUMN `dashPayBackfillCovered` BLOB")
db.execSQL(
"ALTER TABLE `dashpay_contact_requests` ADD COLUMN `externalAccountReference` INTEGER",
)
}
}

/**
* Build the on-disk database. WAL is Room's default journal mode on
* API 16+; writes go through the persistence handler inside
Expand Down Expand Up @@ -708,6 +745,7 @@ abstract class DashDatabase : RoomDatabase() {
MIGRATION_11_12,
MIGRATION_12_13,
MIGRATION_13_14,
MIGRATION_14_15,
)
.build()

Expand Down
Loading
Loading