-
Notifications
You must be signed in to change notification settings - Fork 4
fix: notify on-chain receives that skip mempool #588
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
Draft
CypherPoet
wants to merge
9
commits into
synonymdev:master
Choose a base branch
from
CypherPoet:fix/onchain-confirmed-received-sheet
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
f31d0ce
fix: notify on-chain receives that skip mempool
3df9c52
chore: rename changelog fragment
bd07776
fix: guard received sheet against duplicate presentation
479aac1
fix: suppress received sheet for restored historical receives
dd589eb
Merge remote-tracking branch 'origin/master' into fix/onchain-confirm…
6b15d25
Merge branch 'master' into fix/onchain-confirmed-received-sheet
piotr-iohk 1094317
Merge branch 'master' into fix/onchain-confirmed-received-sheet
piotr-iohk 6891cea
fix: lift restore sheet hold only after activities are seen
jvsena42 9a6e98d
fix: arm restore sheet hold before the node starts syncing
jvsena42 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| @testable import Bitkit | ||
| import BitkitCore | ||
| import XCTest | ||
|
|
||
| /// Regression cover for #588: the post-restore sweep marks the replayed historical activity as seen, | ||
| /// and must leave alone a payment that genuinely arrives while the restore is still running. | ||
| /// | ||
| /// Without the cutoff, such a payment was suppressed by `pendingRestoreActivitySeen` on arrival and | ||
| /// then marked seen by the sweep, so it never notified the user at all. | ||
| final class MarkAllUnseenActivitiesCutoffTests: XCTestCase { | ||
| private let testDbPath = NSTemporaryDirectory() | ||
| private let service = CoreService.shared.activity | ||
|
|
||
| private let restoreStartedAt: UInt64 = 1_700_000_000 | ||
|
|
||
| override func setUp() async throws { | ||
| try await super.setUp() | ||
| _ = try initDb(basePath: testDbPath) | ||
| try await Task.sleep(nanoseconds: 1_000_000_000) | ||
| } | ||
|
|
||
| override func tearDown() async throws { | ||
| try await super.tearDown() | ||
|
|
||
| let fileManager = FileManager.default | ||
| let dbPath = (testDbPath as NSString).appendingPathComponent("activity.db") | ||
| if fileManager.fileExists(atPath: dbPath) { | ||
| try fileManager.removeItem(atPath: dbPath) | ||
| } | ||
| } | ||
|
|
||
| func testSweepMarksReplayedHistoryButSparesNewerActivity() async throws { | ||
| let replayed = "restore-replayed-history" | ||
| let arrivedDuringRestore = "arrived-mid-restore" | ||
|
|
||
| try await service.insert(onchainActivity(id: replayed, txId: "old", timestamp: restoreStartedAt - 3600)) | ||
| try await service.insert( | ||
| onchainActivity(id: arrivedDuringRestore, txId: "new", timestamp: restoreStartedAt + 30) | ||
| ) | ||
|
|
||
| let completed = await service.markAllUnseenActivitiesAsSeen(startedBefore: restoreStartedAt) | ||
|
|
||
| let replayedSeenAt = try await seenAt(of: replayed) | ||
| let newerSeenAt = try await seenAt(of: arrivedDuringRestore) | ||
|
|
||
| XCTAssertTrue(completed) | ||
| XCTAssertNotNil(replayedSeenAt, "replayed history should be marked seen by the sweep") | ||
| XCTAssertNil( | ||
| newerSeenAt, | ||
| "a payment that arrived during the restore must stay unseen, or it never notifies" | ||
| ) | ||
| } | ||
|
|
||
| func testSweepWithoutACutoffStillMarksEverything() async throws { | ||
| let id = "no-cutoff" | ||
| try await service.insert(onchainActivity(id: id, txId: "any", timestamp: restoreStartedAt + 30)) | ||
|
|
||
| let completed = await service.markAllUnseenActivitiesAsSeen() | ||
|
|
||
| let markedSeenAt = try await seenAt(of: id) | ||
|
|
||
| XCTAssertTrue(completed) | ||
| XCTAssertNotNil(markedSeenAt, "the post-migration caller passes no cutoff and expects a full sweep") | ||
| } | ||
|
|
||
| // MARK: - Helpers | ||
|
|
||
| private func seenAt(of id: String) async throws -> UInt64? { | ||
| guard case let .onchain(activity) = try await service.getActivity(id: id) else { | ||
| XCTFail("activity \(id) was not stored as on-chain") | ||
| return nil | ||
| } | ||
| return activity.seenAt | ||
| } | ||
|
|
||
| private func onchainActivity(id: String, txId: String, timestamp: UInt64) -> Activity { | ||
| .onchain( | ||
| OnchainActivity( | ||
| walletId: WalletScope.default, | ||
| id: id, | ||
| txType: .received, | ||
| txId: txId, | ||
| value: 10000, | ||
| fee: 100, | ||
| feeRate: 1, | ||
| address: "bc1...", | ||
| confirmed: true, | ||
| timestamp: timestamp, | ||
| isBoosted: false, | ||
| boostTxIds: [], | ||
| isTransfer: false, | ||
| doesExist: true, | ||
| confirmTimestamp: nil, | ||
| channelId: nil, | ||
| transferTxId: nil, | ||
| contact: nil, | ||
| createdAt: nil, | ||
| updatedAt: nil, | ||
| seenAt: nil | ||
| ) | ||
| ) | ||
| } | ||
| } |
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.