feat(protocol): Early Bitcoin refund (#344)

* feat(protocol): Early Bitcoin refund

Alice can choose to let Bob refund his Bitcoin early (before TxCancel timelock expires)

* feat: Let Bob check for TxEarlyRefund

* fix: compile errors
feat(alice): if we cannot lock Monero within 2 minutes, early refund bitcoin

* satisfy clippy

* fix(gui): Emit tauri event when Bitcoin is early refunded

* tests progress

* rename AliceStates

* progress: working prototype!

* add unit tests for tx_early_refund construction (tx_early_refund_can_be_constructed_and_signed, tx_early weight check)

* fix compile error in swap/tests/alice_zero_xmr_early_refund.rs

* only make [`tx_early_refund_sig_bob`] optional in state machine, not message machine

* feat: working integration test alice_zero_xmr_early_refund.rs

* fix tests

* add changelog entry, add integration test with broken monero-wallet-rpc simulation

* amend

* amend changelog

* nitpick

* feat(gui): Bump MIN_ASB_VERSION to 2.0.0

* feat(bob): explicitly check for tx_early_rewfund

* refactor(bob): Assume tx_early_refund will not be published if timelock has expired

* add todo

* refactor

* refactor(swap): Differentiate between BtcRefundPublished, BtcEarlyRefundPublished, BtcEarlyRefunded and BtcRefunded

* refactor: move weight of tx_early into TX_EARLY_REFUND_WEIGHT const

* efactor(swap): Differentiate between BtcRefundPublished,BtcEarlyRefundPublished, BtcEarlyRefunded and BtcRefunded

* small refactors

* nitpciks

* dprint fmt

* add context to get_raw_transaction

* refactor: remove duplicated code in watch_for_redeem_btc, dprint fmt

* fix: parse -5 electrum transaction not found error correctly

* refactor: send btc_refund_finalized flag to tauri with BtcRefunded state

* remove uncessary .context

* dprint dfmt

* remove unused import

* refactor: explicitly mark state3.expired_timelocks(...) as transient error when locking Monero

* use .context instead of ok_or_else(...)

* fix: in get_raw_transaction also check for "missing transaction"

* add 4 different types of tauri events for different refund states

* display BobStateName.BtcEarlyRefunded as done state

* add global bottom to DialogContentText

* fix(gui): Add missing padding in SwapDialog

* proof of concept: electrum load balancer

* load balancer progress

* wrap Mutex<Vec<Arc<BdkElectrumClient<Client>>>> in electrum_balancer in another Arc, free locks as fast as possible

* refactor

* refactor(electrum balancer): use OnceCell to do lazy initilization

* tests

* refactor(electrum): enhance error handling with MultiError for comprehensive failure analysis

This commit introduces a robust MultiError system for the Electrum balancer that collects
and exposes all individual node failures, enabling better error analysis and decision making.

Key improvements:
- Add MultiError struct with methods for inspecting all collected errors from failed nodes
- Modify electrum_balancer::call() to return MultiError instead of single Error
- Enhance Client::get_tx() to properly detect transaction-not-found across multiple nodes
- Add call_async_with_multi_error() method for detailed async error analysis
- Improve error tracing and logging throughout the Bitcoin wallet operations
- Add comprehensive test coverage for MultiError functionality and edge cases
- Remove obsolete should_retry_on_error() logic in favor of MultiError inspection

The MultiError type maintains backward compatibility through automatic conversion to Error
while providing rich error analysis capabilities for callers that need detailed failure
information. This particularly improves handling of transaction-not-found scenarios where
different nodes may return different error formats.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* add changelog entry for electrum node balancing

* refactors of electrum balancer

* only warn if .check_for_tx_early_refund fails

* clippy

* remove verbose message

* use AtomicUsize

* final touches

* log libp2p crates

* merge master

* display LinearProgressWithSubtitle as indeterminate if progress=100%

* let broadcast return a MultiError, log all libp2p crates

* nitpick

* make clippy happy

* log "kind" for join_all load balancer

* add kind to join_all method, show warning alert if alice takes a long time to redeem Bitcoin

* parse multierrors correctly

* fmt

---------

Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
Mohan 2025-06-11 20:40:16 +02:00 committed by GitHub
parent 8aad1bdf75
commit 07f935bfbc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
54 changed files with 3204 additions and 392 deletions

View file

@ -29,7 +29,10 @@ export enum BobStateName {
BtcRedeemed = "btc is redeemed",
CancelTimelockExpired = "cancel timelock is expired",
BtcCancelled = "btc is cancelled",
BtcRefundPublished = "btc refund is published",
BtcEarlyRefundPublished = "btc early refund is published",
BtcRefunded = "btc is refunded",
BtcEarlyRefunded = "btc is early refunded",
XmrRedeemed = "xmr is redeemed",
BtcPunished = "btc is punished",
SafelyAborted = "safely aborted",
@ -55,8 +58,14 @@ export function bobStateNameToHumanReadable(stateName: BobStateName): string {
return "Cancel timelock expired";
case BobStateName.BtcCancelled:
return "Bitcoin cancelled";
case BobStateName.BtcRefundPublished:
return "Bitcoin refund published";
case BobStateName.BtcEarlyRefundPublished:
return "Bitcoin early refund published";
case BobStateName.BtcRefunded:
return "Bitcoin refunded";
case BobStateName.BtcEarlyRefunded:
return "Bitcoin early refunded";
case BobStateName.XmrRedeemed:
return "Monero redeemed";
case BobStateName.BtcPunished:
@ -102,6 +111,7 @@ export type BobStateNameRunningSwap = Exclude<
| BobStateName.Started
| BobStateName.SwapSetupCompleted
| BobStateName.BtcRefunded
| BobStateName.BtcEarlyRefunded
| BobStateName.BtcPunished
| BobStateName.SafelyAborted
| BobStateName.XmrRedeemed
@ -122,6 +132,7 @@ export function isBobStateNameRunningSwap(
BobStateName.Started,
BobStateName.SwapSetupCompleted,
BobStateName.BtcRefunded,
BobStateName.BtcEarlyRefunded,
BobStateName.BtcPunished,
BobStateName.SafelyAborted,
BobStateName.XmrRedeemed,
@ -131,6 +142,7 @@ export function isBobStateNameRunningSwap(
export type BobStateNameCompletedSwap =
| BobStateName.XmrRedeemed
| BobStateName.BtcRefunded
| BobStateName.BtcEarlyRefunded
| BobStateName.BtcPunished
| BobStateName.SafelyAborted;
@ -140,6 +152,7 @@ export function isBobStateNameCompletedSwap(
return [
BobStateName.XmrRedeemed,
BobStateName.BtcRefunded,
BobStateName.BtcEarlyRefunded,
BobStateName.BtcPunished,
BobStateName.SafelyAborted,
].includes(state);
@ -150,7 +163,9 @@ export type BobStateNamePossiblyCancellableSwap =
| BobStateName.XmrLockProofReceived
| BobStateName.XmrLocked
| BobStateName.EncSigSent
| BobStateName.CancelTimelockExpired;
| BobStateName.CancelTimelockExpired
| BobStateName.BtcRefundPublished
| BobStateName.BtcEarlyRefundPublished;
/**
Checks if a swap is in a state where it can possibly be cancelled
@ -161,6 +176,7 @@ The following conditions must be met:
- The bitcoin must not be cancelled
- The bitcoin must not be refunded
- The bitcoin must not be punished
- The bitcoin must not be early refunded
See: https://github.com/comit-network/xmr-btc-swap/blob/7023e75bb51ab26dff4c8fcccdc855d781ca4b15/swap/src/cli/cancel.rs#L16-L35
*/
@ -173,6 +189,8 @@ export function isBobStateNamePossiblyCancellableSwap(
BobStateName.XmrLocked,
BobStateName.EncSigSent,
BobStateName.CancelTimelockExpired,
BobStateName.BtcRefundPublished,
BobStateName.BtcEarlyRefundPublished,
].includes(state);
}
@ -182,7 +200,9 @@ export type BobStateNamePossiblyRefundableSwap =
| BobStateName.XmrLocked
| BobStateName.EncSigSent
| BobStateName.CancelTimelockExpired
| BobStateName.BtcCancelled;
| BobStateName.BtcCancelled
| BobStateName.BtcRefundPublished
| BobStateName.BtcEarlyRefundPublished;
/**
Checks if a swap is in a state where it can possibly be refunded (meaning it's not impossible)
@ -205,6 +225,8 @@ export function isBobStateNamePossiblyRefundableSwap(
BobStateName.EncSigSent,
BobStateName.CancelTimelockExpired,
BobStateName.BtcCancelled,
BobStateName.BtcRefundPublished,
BobStateName.BtcEarlyRefundPublished,
].includes(state);
}

View file

@ -91,16 +91,13 @@ function BitcoinLockedNoTimelockExpiredStateAlert({
return (
<MessageList
messages={[
isRunning
? "We are waiting for the other party to lock their Monero"
: null,
<>
If the swap isn't completed in{" "}
<HumanizedBitcoinBlockDuration
blocks={timelock.content.blocks_left}
displayBlocks={false}
/>
, it needs to be refunded
, it will be refunded
</>,
"For that, you need to have the app open sometime within the refund period",
<>
@ -187,6 +184,8 @@ export function StateAlert({
case BobStateName.EncSigSent:
case BobStateName.CancelTimelockExpired:
case BobStateName.BtcCancelled:
case BobStateName.BtcRefundPublished: // Even if the transactions have been published, it cannot be
case BobStateName.BtcEarlyRefundPublished: // guaranteed that they will be confirmed in time
if (swap.timelock != null) {
switch (swap.timelock.type) {
case "None":
@ -220,6 +219,13 @@ export function StateAlert({
}
}
// How many blocks need to be left for the timelock to be considered unusual
// A bit arbitrary but we don't want to alarm the user
// 72 is the default cancel timelock in blocks
// 4 blocks are around 40 minutes
// If the swap has taken longer than 40 minutes, we consider it unusual
const UNUSUAL_AMOUNT_OF_TIME_HAS_PASSED_THRESHOLD = 72 - 4;
/**
* Main component for displaying the swap status alert.
* @param swap - The swap information.
@ -228,9 +234,11 @@ export function StateAlert({
export default function SwapStatusAlert({
swap,
isRunning,
onlyShowIfUnusualAmountOfTimeHasPassed,
}: {
swap: GetSwapInfoResponseExt;
isRunning: boolean;
onlyShowIfUnusualAmountOfTimeHasPassed?: boolean;
}): JSX.Element | null {
// If the swap is completed, we do not need to display anything
if (!isGetSwapInfoResponseRunningSwap(swap)) {
@ -242,6 +250,16 @@ export default function SwapStatusAlert({
return null;
}
// If we are only showing if an unusual amount of time has passed, we need to check if the swap has been running for a while
if (
onlyShowIfUnusualAmountOfTimeHasPassed &&
swap.timelock.type === "None" &&
swap.timelock.content.blocks_left >
UNUSUAL_AMOUNT_OF_TIME_HAS_PASSED_THRESHOLD
) {
return null;
}
return (
<Alert
key={swap.swap_id}

View file

@ -53,7 +53,10 @@ export function LinearProgressWithSubtitle({
width: "10rem",
}}
>
<LinearProgress variant="determinate" value={value} />
<LinearProgress
variant={value === 100 ? "indeterminate" : "determinate"}
value={value}
/>
</Box>
</Box>
);

View file

@ -1,4 +1,10 @@
import { Button, Dialog, DialogActions, DialogContent } from "@mui/material";
import {
Box,
Button,
Dialog,
DialogActions,
DialogContent,
} from "@mui/material";
import { useState } from "react";
import { swapReset } from "store/features/swapSlice";
import { useAppDispatch, useAppSelector, useIsSwapRunning } from "store/hooks";
@ -49,15 +55,25 @@ export default function SwapDialog({
display: "flex",
flexDirection: "column",
justifyContent: "space-between",
flex: 1,
gap: "1rem",
}}
>
{debug ? (
<DebugPage />
) : (
<>
<Box
sx={{
display: "flex",
flexDirection: "column",
gap: 2,
justifyContent: "space-between",
flex: 1,
}}
>
<SwapStatePage state={swap.state} />
<SwapStateStepper state={swap.state} />
</>
</Box>
)}
</DialogContent>

View file

@ -98,8 +98,15 @@ function getActiveStep(state: SwapState | null): PathStep | null {
case "BtcCancelled":
return [PathType.UNHAPPY_PATH, 1, isReleased];
// Step 2: Swap cancelled and Bitcoin refunded successfully
// Step 2: One of the two Bitcoin refund transactions have been published
// but they haven't been confirmed yet
case "BtcRefundPublished":
case "BtcEarlyRefundPublished":
return [PathType.UNHAPPY_PATH, 1, isReleased];
// Step 2: One of the two Bitcoin refund transactions have been confirmed
case "BtcRefunded":
case "BtcEarlyRefunded":
return [PathType.UNHAPPY_PATH, 2, false];
// Step 2 (Failed): Failed to refund Bitcoin

View file

@ -1,8 +1,13 @@
import { Box } from "@mui/material";
import { SwapState } from "models/storeModel";
import { TauriSwapProgressEventType } from "models/tauriModelExt";
import CircularProgressWithSubtitle from "../CircularProgressWithSubtitle";
import BitcoinPunishedPage from "./done/BitcoinPunishedPage";
import BitcoinRefundedPage from "./done/BitcoinRefundedPage";
import {
BitcoinRefundedPage,
BitcoinEarlyRefundedPage,
BitcoinEarlyRefundPublishedPage,
BitcoinRefundPublishedPage,
} from "./done/BitcoinRefundedPage";
import XmrRedeemInMempoolPage from "./done/XmrRedeemInMempoolPage";
import ProcessExitedPage from "./exited/ProcessExitedPage";
import BitcoinCancelledPage from "./in_progress/BitcoinCancelledPage";
@ -16,13 +21,16 @@ import XmrLockedPage from "./in_progress/XmrLockedPage";
import XmrLockTxInMempoolPage from "./in_progress/XmrLockInMempoolPage";
import InitPage from "./init/InitPage";
import WaitingForBitcoinDepositPage from "./init/WaitingForBitcoinDepositPage";
import { exhaustiveGuard } from "utils/typescriptUtils";
export default function SwapStatePage({ state }: { state: SwapState | null }) {
if (state === null) {
return <InitPage />;
}
switch (state.curr.type) {
const type: TauriSwapProgressEventType = state.curr.type;
switch (type) {
case "RequestingQuote":
return <CircularProgressWithSubtitle description="Requesting quote..." />;
case "Resuming":
@ -30,13 +38,26 @@ export default function SwapStatePage({ state }: { state: SwapState | null }) {
case "ReceivedQuote":
return <ReceivedQuotePage />;
case "WaitingForBtcDeposit":
return <WaitingForBitcoinDepositPage {...state.curr.content} />;
// This double check is necessary for the typescript compiler to infer types
if (state.curr.type === "WaitingForBtcDeposit") {
return <WaitingForBitcoinDepositPage {...state.curr.content} />;
}
break;
case "SwapSetupInflight":
return <SwapSetupInflightPage {...state.curr.content} />;
if (state.curr.type === "SwapSetupInflight") {
return <SwapSetupInflightPage {...state.curr.content} />;
}
break;
case "BtcLockTxInMempool":
return <BitcoinLockTxInMempoolPage {...state.curr.content} />;
if (state.curr.type === "BtcLockTxInMempool") {
return <BitcoinLockTxInMempoolPage {...state.curr.content} />;
}
break;
case "XmrLockTxInMempool":
return <XmrLockTxInMempoolPage {...state.curr.content} />;
if (state.curr.type === "XmrLockTxInMempool") {
return <XmrLockTxInMempoolPage {...state.curr.content} />;
}
break;
case "XmrLocked":
return <XmrLockedPage />;
case "EncryptedSignatureSent":
@ -44,15 +65,43 @@ export default function SwapStatePage({ state }: { state: SwapState | null }) {
case "BtcRedeemed":
return <BitcoinRedeemedPage />;
case "XmrRedeemInMempool":
return <XmrRedeemInMempoolPage {...state.curr.content} />;
if (state.curr.type === "XmrRedeemInMempool") {
return <XmrRedeemInMempoolPage {...state.curr.content} />;
}
break;
case "CancelTimelockExpired":
return <CancelTimelockExpiredPage />;
case "BtcCancelled":
return <BitcoinCancelledPage />;
case "BtcRefunded":
return <BitcoinRefundedPage {...state.curr.content} />;
//// 4 different types of Bitcoin refund states we can be in
case "BtcRefundPublished": // tx_refund has been published but has not been confirmed yet
if (state.curr.type === "BtcRefundPublished") {
return <BitcoinRefundPublishedPage {...state.curr.content} />;
}
break;
case "BtcEarlyRefundPublished": // tx_early_refund has been published but has not been confirmed yet
if (state.curr.type === "BtcEarlyRefundPublished") {
return <BitcoinEarlyRefundPublishedPage {...state.curr.content} />;
}
break;
case "BtcRefunded": // tx_refund has been confirmed
if (state.curr.type === "BtcRefunded") {
return <BitcoinRefundedPage {...state.curr.content} />;
}
break;
case "BtcEarlyRefunded": // tx_early_refund has been confirmed
if (state.curr.type === "BtcEarlyRefunded") {
return <BitcoinEarlyRefundedPage {...state.curr.content} />;
}
break;
//// 4 different types of Bitcoin punished states we can be in
case "BtcPunished":
return <BitcoinPunishedPage state={state.curr} />;
if (state.curr.type === "BtcPunished") {
return <BitcoinPunishedPage state={state.curr} />;
}
break;
case "AttemptingCooperativeRedeem":
return (
<CircularProgressWithSubtitle description="Attempting to redeem the Monero with the help of the other party" />
@ -62,18 +111,14 @@ export default function SwapStatePage({ state }: { state: SwapState | null }) {
<CircularProgressWithSubtitle description="The other party is cooperating with us to redeem the Monero..." />
);
case "CooperativeRedeemRejected":
return <BitcoinPunishedPage state={state.curr} />;
if (state.curr.type === "CooperativeRedeemRejected") {
return <BitcoinPunishedPage state={state.curr} />;
}
break;
case "Released":
return <ProcessExitedPage prevState={state.prev} swapId={state.swapId} />;
default:
// TODO: Use this when we have all states implemented, ensures we don't forget to implement a state
// return exhaustiveGuard(state.curr.type);
return (
<Box>
No information to display
<br />
State: {JSON.stringify(state, null, 4)}
</Box>
);
return exhaustiveGuard(type);
}
}

View file

@ -4,14 +4,66 @@ import { useActiveSwapInfo } from "store/hooks";
import FeedbackInfoBox from "../../../../pages/help/FeedbackInfoBox";
import BitcoinTransactionInfoBox from "../../BitcoinTransactionInfoBox";
export default function BitcoinRefundedPage({
export function BitcoinRefundPublishedPage({
btc_refund_txid,
}: TauriSwapProgressEventContent<"BtcRefundPublished">) {
return (
<MultiBitcoinRefundedPage
btc_refund_txid={btc_refund_txid}
btc_refund_finalized={false}
/>
);
}
export function BitcoinEarlyRefundPublishedPage({
btc_early_refund_txid,
}: TauriSwapProgressEventContent<"BtcEarlyRefundPublished">) {
return (
<MultiBitcoinRefundedPage
btc_refund_txid={btc_early_refund_txid}
btc_refund_finalized={false}
/>
);
}
export function BitcoinRefundedPage({
btc_refund_txid,
}: TauriSwapProgressEventContent<"BtcRefunded">) {
// TODO: Reimplement this using Tauri
return (
<MultiBitcoinRefundedPage
btc_refund_txid={btc_refund_txid}
btc_refund_finalized={true}
/>
);
}
export function BitcoinEarlyRefundedPage({
btc_early_refund_txid,
}: TauriSwapProgressEventContent<"BtcEarlyRefunded">) {
return (
<MultiBitcoinRefundedPage
btc_refund_txid={btc_early_refund_txid}
btc_refund_finalized={true}
/>
);
}
function MultiBitcoinRefundedPage({
btc_refund_txid,
btc_refund_finalized,
}: {
btc_refund_txid: string;
btc_refund_finalized: boolean;
}) {
const swap = useActiveSwapInfo();
const additionalContent = swap
? `Refund address: ${swap.btc_refund_address}`
: null;
const additionalContent = swap ? (
<>
{!btc_refund_finalized &&
"Waiting for refund transaction to be confirmed"}
{!btc_refund_finalized && <br />}
Refund address: {swap.btc_refund_address}
</>
) : null;
return (
<Box>
@ -27,13 +79,10 @@ export default function BitcoinRefundedPage({
gap: "0.5rem",
}}
>
{
// TODO: We should display the confirmation count here
}
<BitcoinTransactionInfoBox
title="Bitcoin Refund Transaction"
txId={btc_refund_txid}
loading={false}
loading={!btc_refund_finalized}
additionalContent={additionalContent}
/>
<FeedbackInfoBox />

View file

@ -1,7 +1,25 @@
import SwapStatusAlert from "renderer/components/alert/SwapStatusAlert/SwapStatusAlert";
import CircularProgressWithSubtitle from "../../CircularProgressWithSubtitle";
import { useActiveSwapInfo, useSwapInfosSortedByDate } from "store/hooks";
import { Box } from "@mui/material";
export default function EncryptedSignatureSentPage() {
const swap = useActiveSwapInfo();
return (
<CircularProgressWithSubtitle description="Waiting for them to redeem the Bitcoin" />
<Box sx={{ display: "flex", flexDirection: "column", gap: "1rem" }}>
<SwapStatusAlert
swap={swap}
isRunning={true}
onlyShowIfUnusualAmountOfTimeHasPassed={true}
/>
<Box
sx={{
minHeight: "10rem",
}}
>
<CircularProgressWithSubtitle description="Waiting for them to redeem the Bitcoin" />
</Box>
</Box>
);
}

View file

@ -16,7 +16,7 @@ export default function ReceivedQuotePage() {
return (
<LinearProgressWithSubtitle
description={`Syncing Bitcoin wallet (${percentage}%)`}
description={`Syncing Bitcoin wallet`}
value={percentage}
/>
);

View file

@ -17,9 +17,10 @@ export function AmountWithUnit({
exchangeRate?: Amount;
parenthesisText?: string;
}) {
const [fetchFiatPrices, fiatCurrency] = useSettings(
(settings) => [settings.fetchFiatPrices, settings.fiatCurrency],
);
const [fetchFiatPrices, fiatCurrency] = useSettings((settings) => [
settings.fetchFiatPrices,
settings.fiatCurrency,
]);
const title =
fetchFiatPrices &&
exchangeRate != null &&

View file

@ -35,11 +35,7 @@ import {
Network,
setTheme,
} from "store/features/settingsSlice";
import {
useAppDispatch,
useNodes,
useSettings,
} from "store/hooks";
import { useAppDispatch, useNodes, useSettings } from "store/hooks";
import ValidatedTextField from "renderer/components/other/ValidatedTextField";
import HelpIcon from "@mui/icons-material/HelpOutline";
import { ReactNode, useState } from "react";

View file

@ -76,6 +76,14 @@ export default function HistoryRowActions(swap: GetSwapInfoResponse) {
);
}
if (swap.state_name === BobStateName.BtcEarlyRefunded) {
return (
<Tooltip title="This swap is completed. Your Bitcoin has been refunded.">
<DoneIcon style={{ color: green[500] }} />
</Tooltip>
);
}
if (swap.state_name === BobStateName.BtcPunished) {
return (
<Tooltip title="You have been punished. You can attempt to recover the Monero with the help of the other party but that is not guaranteed to work">

View file

@ -35,6 +35,13 @@ const baseTheme: ThemeOptions = {
},
},
},
MuiDialogContentText: {
styleOverrides: {
root: {
marginBottom: "0.5rem",
},
},
},
MuiTextField: {
styleOverrides: {
root: {

View file

@ -218,39 +218,40 @@ export async function initializeContext() {
const testnet = isTestnet();
const useTor = store.getState().settings.enableTor;
// This looks convoluted but it does the following:
// - Fetch the status of all nodes for each blockchain in parallel
// - Return the first available node for each blockchain
// - If no node is available for a blockchain, return null for that blockchain
const [bitcoinNode, moneroNode] = await Promise.all(
[Blockchain.Bitcoin, Blockchain.Monero].map(async (blockchain) => {
const nodes = store.getState().settings.nodes[network][blockchain];
// Get all Bitcoin nodes without checking availability
// The backend ElectrumBalancer will handle load balancing and failover
const bitcoinNodes =
store.getState().settings.nodes[network][Blockchain.Bitcoin];
if (nodes.length === 0) {
return null;
}
// For Monero nodes, check availability and use the first working one
const moneroNodes =
store.getState().settings.nodes[network][Blockchain.Monero];
let moneroNode = null;
try {
return await Promise.any(
nodes.map(async (node) => {
const isAvailable = await getNodeStatus(node, blockchain, network);
if (moneroNodes.length > 0) {
try {
moneroNode = await Promise.any(
moneroNodes.map(async (node) => {
const isAvailable = await getNodeStatus(
node,
Blockchain.Monero,
network,
);
if (isAvailable) {
return node;
}
throw new Error(`Monero node ${node} is not available`);
}),
);
} catch {
// If no Monero node is available, use null
moneroNode = null;
}
}
if (isAvailable) {
return node;
}
throw new Error(`No available ${blockchain} node found`);
}),
);
} catch {
return null;
}
}),
);
// Initialize Tauri settings with null values
// Initialize Tauri settings
const tauriSettings: TauriSettings = {
electrum_rpc_url: bitcoinNode,
electrum_rpc_urls: bitcoinNodes,
monero_node_url: moneroNode,
use_tor: useTor,
};
@ -324,12 +325,11 @@ export async function updateAllNodeStatuses() {
const network = getNetwork();
const settings = store.getState().settings;
// For all nodes, check if they are available and store the new status (in parallel)
// Only check Monero nodes, skip Bitcoin nodes since we pass all electrum servers
// to the backend without checking them (ElectrumBalancer handles failover)
await Promise.all(
Object.values(Blockchain).flatMap((blockchain) =>
settings.nodes[network][blockchain].map((node) =>
updateNodeStatus(node, blockchain, network),
),
settings.nodes[network][Blockchain.Monero].map((node) =>
updateNodeStatus(node, Blockchain.Monero, network),
),
);
}

View file

@ -78,12 +78,21 @@ const initialState: SettingsState = {
nodes: {
[Network.Testnet]: {
[Blockchain.Bitcoin]: [
"ssl://ax101.blockeng.ch:60002",
"ssl://blackie.c3-soft.com:57006",
"ssl://v22019051929289916.bestsrv.de:50002",
"tcp://v22019051929289916.bestsrv.de:50001",
"tcp://electrum.blockstream.info:60001",
"ssl://electrum.blockstream.info:60002",
"ssl://blockstream.info:993",
"tcp://blockstream.info:143",
"ssl://testnet.aranguren.org:51002",
"ssl://testnet.qtornado.com:51002",
"tcp://testnet.qtornado.com:51001",
"tcp://testnet.aranguren.org:51001",
"ssl://bitcoin.stagemole.eu:5010",
"tcp://bitcoin.stagemole.eu:5000",
"ssl://testnet.aranguren.org:51002",
"ssl://testnet.qtornado.com:50002",
"ssl://bitcoin.devmole.eu:5010",
"tcp://bitcoin.devmole.eu:5000",
],
[Blockchain.Monero]: [],
},

View file

@ -4,7 +4,8 @@ import semver from "semver";
import { isTestnet } from "store/config";
// const MIN_ASB_VERSION = "1.0.0-alpha.1" // First version to support new libp2p protocol
const MIN_ASB_VERSION = "1.1.0-rc.3"; // First version with support for bdk > 1.0
// const MIN_ASB_VERSION = "1.1.0-rc.3" // First version with support for bdk > 1.0
const MIN_ASB_VERSION = "2.0.0-beta.1"; // First version with support for tx_early_refund
export function providerToConcatenatedMultiAddr(provider: Maker) {
return new Multiaddr(provider.multiAddr)