Skip to content

Commit

Permalink
fixup! Integrate new Seen Tx Checkpoint API
Browse files Browse the repository at this point in the history
  • Loading branch information
samholmes committed Jan 14, 2025
1 parent 2a0fc6a commit 43d7b6a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
20 changes: 14 additions & 6 deletions src/common/utxobased/engine/UtxoEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,25 @@ export async function makeUtxoEngine(
// private keys.
let nonceDataLayer: DataLayer | undefined

// This cached value allows the engine to resync using the same checkpoint as
// what the core gave the plugin when the core started plugin.
/**
* This is a stateful function, which means it is both a setter and a getter.
* The state is the cached seenTxCheckpoint for the engine during runtime.
* It is initialized with the seenTxCheckpoint state from the core via
* `EdgeCurrencyEngineOptions`.
* It is updated by the engine's processor as the wallet syncs.
* Once the wallet fully syncs, the seenTxCheckpoint value is emitted to the
* `onSeenTxCheckpoint` callback so the core can persist this state to disk.
*/
const seenTxCheckpoint = ((state?: string) => (
value?: string
): string | undefined => {
if (value != null) state = value
return state
})()

// Initialize the seenTxCheckpoint with the value from the core.
seenTxCheckpoint(config.engineOptions.seenTxCheckpoint)

emitter.on(EngineEvent.SEEN_TX_CHECKPOINT, checkpoint => {
seenTxCheckpoint(checkpoint)
})
Expand Down Expand Up @@ -364,9 +374,7 @@ export async function makeUtxoEngine(
}
},

async startEngine(opts): Promise<void> {
seenTxCheckpoint(opts?.seenTxCheckpoint)

async startEngine(): Promise<void> {
emitter.emit(
EngineEvent.WALLET_BALANCE_CHANGED,
currencyInfo.currencyCode,
Expand Down Expand Up @@ -739,7 +747,7 @@ export async function makeUtxoEngine(
await pluginState.refreshServers()

// Restart the engine
await engine.startEngine({ seenTxCheckpoint: seenTxCheckpoint() })
await engine.startEngine()
},

async saveTx(edgeTx: EdgeTransaction): Promise<void> {
Expand Down
4 changes: 2 additions & 2 deletions src/common/utxobased/engine/UtxoEngineProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ interface TaskCache {
readonly blockbookUtxoCache: BlockbookUtxoCache
readonly dataLayerUtxoCache: DataLayerUtxoCache
readonly transactionSpecificUpdateCache: TransactionSpecificUpdateCache
readonly transactionUpdateCache: transactionUpdateCache
readonly transactionUpdateCache: TransactionUpdateCache
}

interface AddressForTransactionsCache {
Expand Down Expand Up @@ -683,7 +683,7 @@ interface BlockbookUtxoCache {
interface TransactionSpecificUpdateCache {
[key: string]: { processing: boolean }
}
interface transactionUpdateCache {
interface TransactionUpdateCache {
[key: string]: { processing: boolean }
}

Expand Down
2 changes: 1 addition & 1 deletion test/common/utxobased/engine/engine.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ describe('engine.spec', function () {
done() // Can be "done" since the promise resolves before the event fires but just be on the safe side
}
})
engine.startEngine({ seenTxCheckpoint: '' }).catch(e => {
engine.startEngine().catch(e => {
fakeLogger.info('startEngine error', e, e.message)
})
}
Expand Down

0 comments on commit 43d7b6a

Please sign in to comment.