Skip to content

Commit 6b7006e

Browse files
Merge pull request #381 from bsv-blockchain/feature/globalKVStore-withDoubleSpendRetry
Feature/global kv store with double spend retry
2 parents 4f847d0 + bf20213 commit 6b7006e

File tree

10 files changed

+273
-118
lines changed

10 files changed

+273
-118
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ All notable changes to this project will be documented in this file. The format
55
## Table of Contents
66

77
- [Unreleased](#unreleased)
8+
- [1.9.3 - 2025-11-11](#193---2025-11-11)
89
- [1.9.2 - 2025-11-11](#192---2025-11-11)
910
- [1.9.1 - 2025-11-10](#191---2025-11-10)
1011
- [1.9.0 - 2025-11-09](#190---2025-11-09)
@@ -176,6 +177,15 @@ All notable changes to this project will be documented in this file. The format
176177

177178
---
178179

180+
### [1.9.3] - 2025-11-11
181+
182+
### Added
183+
184+
- Added `withDoubleSpendRetry` overlay tool to retry broadcast with resolved competing transactions.
185+
- Updated GlobalKVStore to use `withDoubleSpendRetry` in set/remove operations.
186+
187+
---
188+
179189
### [1.9.2] - 2025-11-11
180190

181191
### Fixed

docs/reference/kvstore.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ export interface KVStoreConfig {
5050
wallet?: WalletInterface;
5151
networkPreset?: "mainnet" | "testnet" | "local";
5252
acceptDelayedBroadcast?: boolean;
53+
overlayBroadcast?: boolean;
5354
tokenSetDescription?: string;
5455
tokenUpdateDescription?: string;
5556
tokenRemovalDescription?: string;
@@ -82,6 +83,14 @@ Originator
8283
originator?: string
8384
```
8485

86+
#### Property overlayBroadcast
87+
88+
Whether to let overlay handle broadcasting (prevents UTXO spending on rejection)
89+
90+
```ts
91+
overlayBroadcast?: boolean
92+
```
93+
8594
#### Property overlayHost
8695

8796
The overlay service host URL

docs/reference/overlay-tools.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,38 @@ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](
564564
---
565565
## Functions
566566

567+
### Function: withDoubleSpendRetry
568+
569+
Executes an operation with automatic retry logic for double-spend errors.
570+
When a double-spend is detected, broadcasts the competing transaction to
571+
update the overlay with missing state, then retries the operation.
572+
573+
```ts
574+
export async function withDoubleSpendRetry<T>(operation: () => Promise<T>, broadcaster: TopicBroadcaster, maxRetries: number = MAX_DOUBLE_SPEND_RETRIES): Promise<T>
575+
```
576+
577+
See also: [TopicBroadcaster](./overlay-tools.md#class-topicbroadcaster)
578+
579+
Returns
580+
581+
The result of the successful operation
582+
583+
Argument Details
584+
585+
+ **operation**
586+
+ The async operation to execute (e.g., createAction + signAction)
587+
+ **broadcaster**
588+
+ The TopicBroadcaster to use for syncing missing state
589+
+ **maxRetries**
590+
+ Maximum number of retry attempts (default: MAX_DOUBLE_SPEND_RETRIES)
591+
592+
Throws
593+
594+
If max retries exceeded or non-double-spend error occurs
595+
596+
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Enums](#enums), [Variables](#variables)
597+
598+
---
567599
## Types
568600

569601
| |

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@bsv/sdk",
3-
"version": "1.9.2",
3+
"version": "1.9.3",
44
"type": "module",
55
"description": "BSV Blockchain Software Development Kit",
66
"main": "dist/cjs/mod.js",

0 commit comments

Comments
 (0)