@exodus/bitcoin-api 5.0.5 → 5.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,24 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [5.0.7](https://github.com/ExodusMovement/assets/compare/@exodus/bitcoin-api@5.0.6...@exodus/bitcoin-api@5.0.7) (2026-10-06)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* **bitcoin-api:** remove orphaned UTXOs on refresh ([#8873](https://github.com/ExodusMovement/assets/issues/8873)) ([3f169ec](https://github.com/ExodusMovement/assets/commit/3f169ecb2df12924182c04571221cf5356c801f3))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
## [5.0.6](https://github.com/ExodusMovement/assets/compare/@exodus/bitcoin-api@5.0.5...@exodus/bitcoin-api@5.0.6) (2026-10-06)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### Bug Fixes
|
|
19
|
+
|
|
20
|
+
* **bitcoin-api:** retry rate-limited mempool reads ([#8874](https://github.com/ExodusMovement/assets/issues/8874)) ([5636aac](https://github.com/ExodusMovement/assets/commit/5636aacb50663b3faac2887e67a1e78a3b81f86d))
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
6
24
|
## [5.0.5](https://github.com/ExodusMovement/assets/compare/@exodus/bitcoin-api@5.0.4...@exodus/bitcoin-api@5.0.5) (2026-10-06)
|
|
7
25
|
|
|
8
26
|
|
package/README.md
CHANGED
|
@@ -12,7 +12,7 @@ Confirmation checks recheck their inputs if a WebSocket update, disconnect, or b
|
|
|
12
12
|
|
|
13
13
|
Every HTTP 429 starts a process-local cooldown shared across clients and endpoints on the same origin. Valid `Retry-After` seconds or HTTP dates take precedence, using the server's `Date` header for clock skew when available, and are capped at five minutes. Missing or invalid values use a ten-second fallback; failed recovery doubles it with 0–20% positive jitter, also capped at five minutes. Concurrent responses from the original burst do not multiply backoff, but longer server deadlines are preserved.
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
Reads receiving HTTP 429 rejoin the end of the queue instead of immediately failing the monitor scan. Each read permits at most two retries, sharing its original 30-second queue deadline; cancellation, overflow, or expiry still fail finally. Exhausted retries fail with code `429`, `finalError`, bounded `retryAt`/`retryAfterMs`, and hint `mempoolRateLimited`; generic retries stop. Queued reads wait until one recovery read can run, with a ten-second timeout including its body. Success or an ordinary 404 releases the cooldown; other HTTP, transport, or body failures renew it. No recovery request is generated when the queue is empty.
|
|
16
16
|
|
|
17
17
|
## Mempool request scheduling
|
|
18
18
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exodus/bitcoin-api",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.7",
|
|
4
4
|
"description": "Bitcoin transaction and fee monitors, RPC with the blockchain node, other networking code.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.js",
|
|
@@ -59,5 +59,5 @@
|
|
|
59
59
|
"type": "git",
|
|
60
60
|
"url": "git+https://github.com/ExodusMovement/assets.git"
|
|
61
61
|
},
|
|
62
|
-
"gitHead": "
|
|
62
|
+
"gitHead": "95f26b6479a44cb9272d39a83baaa56e2de7e263"
|
|
63
63
|
}
|
|
@@ -4,6 +4,7 @@ const MAX_ACTIVE_REQUESTS = 2
|
|
|
4
4
|
const REQUEST_INTERVAL_MS = 200
|
|
5
5
|
const MAX_QUEUED_REQUESTS = 100
|
|
6
6
|
const MAX_QUEUE_WAIT_MS = 30_000
|
|
7
|
+
const MAX_READ_RETRIES = 2
|
|
7
8
|
const schedulersByOrigin = new Map()
|
|
8
9
|
|
|
9
10
|
const createAbortError = (signal) => {
|
|
@@ -67,12 +68,12 @@ const drain = (origin) => {
|
|
|
67
68
|
|
|
68
69
|
export const resumeMempoolRequests = (origin) => drain(origin)
|
|
69
70
|
|
|
70
|
-
|
|
71
|
-
origin,
|
|
72
|
-
execute,
|
|
73
|
-
{ signal, isBroadcast, getCooldown } = {}
|
|
74
|
-
) {
|
|
71
|
+
function enqueueMempoolRequest(origin, execute, { signal, isBroadcast, getCooldown, expiresAt }) {
|
|
75
72
|
if (signal?.aborted) return Promise.reject(createAbortError(signal))
|
|
73
|
+
const maxWaitMs = expiresAt - Date.now()
|
|
74
|
+
if (maxWaitMs <= 0) {
|
|
75
|
+
return Promise.reject(createQueueError('MEMPOOL_REQUEST_QUEUE_TIMEOUT'))
|
|
76
|
+
}
|
|
76
77
|
let scheduler = schedulersByOrigin.get(origin)
|
|
77
78
|
if (!scheduler) {
|
|
78
79
|
scheduler = { active: 0, timer: null, wakeTimer: null, queue: [], getCooldown }
|
|
@@ -87,12 +88,11 @@ export default function scheduleMempoolRequest(
|
|
|
87
88
|
}
|
|
88
89
|
|
|
89
90
|
return new Promise((resolve, reject) => {
|
|
90
|
-
const maxWaitMs = isBroadcast ? 1000 : MAX_QUEUE_WAIT_MS
|
|
91
91
|
const entry = {
|
|
92
92
|
execute,
|
|
93
93
|
resolve,
|
|
94
94
|
reject,
|
|
95
|
-
expiresAt
|
|
95
|
+
expiresAt,
|
|
96
96
|
cleanup: () => {
|
|
97
97
|
clearTimeout(timeout)
|
|
98
98
|
signal?.removeEventListener('abort', onAbort)
|
|
@@ -119,3 +119,14 @@ export default function scheduleMempoolRequest(
|
|
|
119
119
|
drain(origin)
|
|
120
120
|
})
|
|
121
121
|
}
|
|
122
|
+
|
|
123
|
+
export default async function scheduleMempoolRequest(origin, execute, options = {}) {
|
|
124
|
+
const expiresAt = Date.now() + (options.isBroadcast ? 1000 : MAX_QUEUE_WAIT_MS)
|
|
125
|
+
for (let attempt = 0; ; attempt++) {
|
|
126
|
+
try {
|
|
127
|
+
return await enqueueMempoolRequest(origin, execute, { ...options, expiresAt })
|
|
128
|
+
} catch (error) {
|
|
129
|
+
if (options.isBroadcast || error?.code !== '429' || attempt >= MAX_READ_RETRIES) throw error
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
@@ -105,11 +105,11 @@ export class BitcoinMonitorScanner {
|
|
|
105
105
|
const storedUtxos = getUtxos({ asset, accountState })
|
|
106
106
|
|
|
107
107
|
const currentTime = Date.now()
|
|
108
|
+
// Give local sends time to be indexed before checking whether their outputs still exist.
|
|
109
|
+
const isRecentSentTx = (tx) =>
|
|
110
|
+
tx?.sent && tx.date && currentTime - tx.date.getTime() <= SENT_TIME_TO_DROP
|
|
108
111
|
const unconfirmedTxsToCheck = [...currentTxs].reduce((txs, tx) => {
|
|
109
|
-
if (
|
|
110
|
-
tx.pending && // Don't check sent tx that is younger than 2 minutes, because server might not have indexed it yet
|
|
111
|
-
(!tx.sent || !tx.date || currentTime - tx.date.getTime() > SENT_TIME_TO_DROP)
|
|
112
|
-
) {
|
|
112
|
+
if (tx.pending && !isRecentSentTx(tx)) {
|
|
113
113
|
txs[tx.txId] = tx
|
|
114
114
|
}
|
|
115
115
|
|
|
@@ -677,28 +677,52 @@ export class BitcoinMonitorScanner {
|
|
|
677
677
|
// but vin.addr did not match our wallet address map.
|
|
678
678
|
utxoCol = utxoCol.union(storedUtxos).difference(utxosToRemoveCol).difference(spentStoredUtxos)
|
|
679
679
|
|
|
680
|
-
const
|
|
680
|
+
const txIdsToCheck = new Set(Object.keys(unconfirmedTxsToCheck))
|
|
681
|
+
if (refresh) {
|
|
682
|
+
const refreshedTxIds = new Set(newTxs.map((tx) => tx.txId))
|
|
683
|
+
const scannedTxIds = new Set([...allTxs, ...storedUtxoAddressTxs].map((tx) => tx.txid))
|
|
684
|
+
// Refresh overwrites the tx log. Keep unindexed recent sends, including their
|
|
685
|
+
// original date and inputs, so another refresh preserves the same grace period.
|
|
686
|
+
// The extra stored-UTXO-address scan does not emit entries to the refreshed log.
|
|
687
|
+
for (const tx of currentTxs) {
|
|
688
|
+
if (tx.pending && isRecentSentTx(tx) && !refreshedTxIds.has(tx.txId)) {
|
|
689
|
+
existingTxs.push({ ...tx })
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
// A previous refresh may have removed a funding tx from the log while retaining
|
|
694
|
+
// its UTXOs. Verify retained outputs independently of pending tx-log entries.
|
|
695
|
+
for (const { txId } of utxoCol.toArray()) {
|
|
696
|
+
if (!scannedTxIds.has(txId) && !isRecentSentTx(currentTxs.get(txId))) {
|
|
697
|
+
txIdsToCheck.add(txId)
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
}
|
|
701
|
+
|
|
681
702
|
const verificationResults = await Promise.all(
|
|
682
|
-
|
|
703
|
+
[...txIdsToCheck].map(async (txId) => {
|
|
683
704
|
try {
|
|
684
|
-
const txStatus = await insightClient.fetchTx(
|
|
685
|
-
return {
|
|
705
|
+
const txStatus = await insightClient.fetchTx(txId)
|
|
706
|
+
return { txId, shouldDrop: txStatus === null }
|
|
686
707
|
} catch (err) {
|
|
687
708
|
console.debug(
|
|
688
|
-
`${assetName}: failed to verify
|
|
709
|
+
`${assetName}: failed to verify tx ${txId} before drop check: ${
|
|
689
710
|
err?.message || 'unknown'
|
|
690
711
|
}`
|
|
691
712
|
)
|
|
692
|
-
return {
|
|
713
|
+
return { txId, shouldDrop: false }
|
|
693
714
|
}
|
|
694
715
|
})
|
|
695
716
|
)
|
|
696
717
|
|
|
697
|
-
for (const {
|
|
718
|
+
for (const { txId, shouldDrop } of verificationResults) {
|
|
698
719
|
if (!shouldDrop) continue
|
|
699
720
|
|
|
721
|
+
utxoCol = utxoCol.difference(utxoCol.getTxIdUtxos(txId))
|
|
722
|
+
const tx = unconfirmedTxsToCheck[txId]
|
|
723
|
+
if (!tx) continue
|
|
724
|
+
|
|
700
725
|
existingTxs.push({ ...tx, dropped: true }) // TODO: this will decrease the chain index, it shouldn't be an issue considering the gap limit
|
|
701
|
-
utxoCol = utxoCol.difference(utxoCol.getTxIdUtxos(tx.txId))
|
|
702
726
|
const utxosToAdd = []
|
|
703
727
|
if (tx.data.inputs) {
|
|
704
728
|
const prevUtxos = UtxoCollection.fromJSON(tx.data.inputs, { currency })
|
package/src/tx-send/index.js
CHANGED
|
@@ -5,7 +5,7 @@ import assert from 'minimalistic-assert'
|
|
|
5
5
|
import { extractTransactionContext } from '../psbt-parser.js'
|
|
6
6
|
import { broadcastTransaction } from './broadcast-tx.js'
|
|
7
7
|
import { repairConfirmedSpentInputs } from './repair-spent-inputs.js'
|
|
8
|
-
import {
|
|
8
|
+
import { updateAccountStateBatch, updateTransactionLogBatch } from './update-state.js'
|
|
9
9
|
|
|
10
10
|
const getErrorText = (error) => [error?.message, error?.reason].filter(Boolean).join(' ')
|
|
11
11
|
|
|
@@ -259,7 +259,11 @@ export const sendTxFactory = ({
|
|
|
259
259
|
txId,
|
|
260
260
|
})
|
|
261
261
|
|
|
262
|
-
|
|
262
|
+
// Publish change and its recent-send history together so refresh cannot mistake
|
|
263
|
+
// newly created change for an orphan while transaction metadata is being derived.
|
|
264
|
+
const batch = assetClientInterface.createOperationsBatch()
|
|
265
|
+
updateAccountStateBatch({
|
|
266
|
+
batch,
|
|
263
267
|
assetClientInterface,
|
|
264
268
|
assetName,
|
|
265
269
|
walletAccount,
|
|
@@ -274,7 +278,8 @@ export const sendTxFactory = ({
|
|
|
274
278
|
rbfEnabled,
|
|
275
279
|
})
|
|
276
280
|
|
|
277
|
-
await
|
|
281
|
+
await updateTransactionLogBatch({
|
|
282
|
+
batch,
|
|
278
283
|
asset,
|
|
279
284
|
assetClientInterface,
|
|
280
285
|
walletAccount,
|
|
@@ -294,6 +299,8 @@ export const sendTxFactory = ({
|
|
|
294
299
|
size,
|
|
295
300
|
})
|
|
296
301
|
|
|
302
|
+
await assetClientInterface.executeOperationsBatch(batch)
|
|
303
|
+
|
|
297
304
|
return {
|
|
298
305
|
txId,
|
|
299
306
|
sendUtxoIndex,
|
|
@@ -102,7 +102,8 @@ const getWalletAddressObjects = async ({
|
|
|
102
102
|
return addresses
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
-
export
|
|
105
|
+
export function updateAccountStateBatch({
|
|
106
|
+
batch,
|
|
106
107
|
assetClientInterface,
|
|
107
108
|
assetName,
|
|
108
109
|
walletAccount,
|
|
@@ -116,7 +117,7 @@ export async function updateAccountState({
|
|
|
116
117
|
ourAddress,
|
|
117
118
|
rbfEnabled,
|
|
118
119
|
}) {
|
|
119
|
-
const knownBalanceUtxoIds = accountState.knownBalanceUtxoIds || []
|
|
120
|
+
const knownBalanceUtxoIds = [...(accountState.knownBalanceUtxoIds || [])]
|
|
120
121
|
// updateAccountState replaces the stored UTXO collection, so remove selected inputs
|
|
121
122
|
// from the full stored set.
|
|
122
123
|
let remainingUtxos = accountState.utxos.difference(selectedUtxos)
|
|
@@ -144,7 +145,9 @@ export async function updateAccountState({
|
|
|
144
145
|
}
|
|
145
146
|
|
|
146
147
|
// Update account state
|
|
147
|
-
|
|
148
|
+
assetClientInterface.updateAccountStateBatch({
|
|
149
|
+
batch,
|
|
150
|
+
accountState,
|
|
148
151
|
assetName,
|
|
149
152
|
walletAccount,
|
|
150
153
|
newData: {
|
|
@@ -154,7 +157,8 @@ export async function updateAccountState({
|
|
|
154
157
|
})
|
|
155
158
|
}
|
|
156
159
|
|
|
157
|
-
export async function
|
|
160
|
+
export async function updateTransactionLogBatch({
|
|
161
|
+
batch,
|
|
158
162
|
asset,
|
|
159
163
|
assetClientInterface,
|
|
160
164
|
walletAccount,
|
|
@@ -262,7 +266,8 @@ export async function updateTransactionLog({
|
|
|
262
266
|
const coinAmount = selfSend ? asset.currency.ZERO : totalAmount.abs().negate()
|
|
263
267
|
|
|
264
268
|
// Update transaction log
|
|
265
|
-
|
|
269
|
+
assetClientInterface.updateTxLogAndNotifyBatch({
|
|
270
|
+
batch,
|
|
266
271
|
assetName,
|
|
267
272
|
walletAccount,
|
|
268
273
|
txs: [
|
|
@@ -299,7 +304,8 @@ export async function updateTransactionLog({
|
|
|
299
304
|
replacedBy: txId,
|
|
300
305
|
},
|
|
301
306
|
}
|
|
302
|
-
|
|
307
|
+
assetClientInterface.updateTxLogAndNotifyBatch({
|
|
308
|
+
batch,
|
|
303
309
|
assetName,
|
|
304
310
|
walletAccount,
|
|
305
311
|
txs: [updatedReplaceTx],
|