skip a silent payments transaction the server cannot return when processing a subscription batch, and fetch it again on the next refresh
What changed, and why it matters
This commit fixes a bug in how Sparrow Wallet handles Silent Payments transactions that the server cannot currently return (for example, because a transaction left the mempool before the wallet fetched it). Previously, such a missing transaction could stop the whole batch of Silent Payments updates from being processed, potentially causing later payments to be missed or the wallet state to become inconsistent. The fix skips the missing transaction, processes the rest of the batch, and tries again on the next refresh. It also ensures that if the wallet already holds a placeholder for an unfetchable transaction, it will be fetched again rather than treated as the real transaction.
Treat as a bug-fix commit with low-to-moderate security relevance. Users relying on Silent Payments should upgrade to avoid missed transactions or inconsistent wallet state. No immediate emergency response is indicated, but a routine patch release is appropriate.
Security signals we found
Denial-of-service-like wallet state corruption: a missing mempool transaction could previously abort Silent Payments batch processing, causing subsequent valid payments to be ignored.
Incorrect sentinel handling: UNFETCHABLE_BLOCK_TRANSACTION could be mistaken for a real transaction, leading to wrong wallet balance or UTXO set.
Fix adds explicit guard and retry behavior for unfetchable transactions.
No cryptographic, signature, or authentication changes observed.
Evidence from the diff
In ElectrumServer.processSilentPaymentBatch, the code now checks whether an existing wallet transaction is the sentinel UNFETCHABLE_BLOCK_TRANSACTION and, if so, does not treat it as already present. After fetching transactions from the server, any entries equal to UNFETCHABLE_BLOCK_TRANSACTION are removed from the fetched map so they do not enter the wallet as real transactions. The missing transaction is left out of the current batch and will be retried on the next refresh. A new test class, SilentPaymentsBatchTest, verifies that: (1) normal Silent Payments entries add wallet nodes; (2) an entry whose transaction the server does not supply is skipped without breaking subsequent entries; (3) the payment is found once the server supplies the transaction; and (4) a previously unfetchable placeholder is re-fetched correctly.
Changed components
src/main/java/com/sparrowwallet/sparrow/net/ElectrumServer.javaSilent Payments batch processingWallet transaction update pathInspect captured patch +196 / −1
### src/main/java/com/sparrowwallet/sparrow/net/ElectrumServer.java
@@ -2947,7 +2947,7 @@ public Set<WalletNode> processSilentPaymentBatch(Wallet wallet, List<SilentPayme
tweakMap.putIfAbsent(txid, tweakKey);
BlockTransaction existing = wallet.getWalletTransaction(txid);
- if(existing != null) {
+ if(existing != null && !existing.equals(UNFETCHABLE_BLOCK_TRANSACTION)) {
transactionMap.put(txid, existing);
alreadyInWallet.add(txid);
} else {
@@ -2966,6 +2966,9 @@ public Set<WalletNode> processSilentPaymentBatch(Wallet wallet, List<SilentPayme
Map<BlockTransactionHash, BlockHeader> proven = isVerifyingTransactions() ? verifySilentPaymentReferences(wallet, referencesToFetch) : Collections.emptyMap();
Map<Integer, BlockHeader> blockHeaderMap = getBlockHeaders(wallet, referencesToFetch.keySet());
Map<Sha256Hash, BlockTransaction> fetched = getTransactions(wallet, referencesToFetch, blockHeaderMap, proven);
+ //A transaction the server did not supply, as where it has left the mempool since it was announced, reaches neither the batch nor the wallet,
+ //and is asked for again on the next refresh
+ fetched.values().removeIf(blkTx -> blkTx.equals(UNFETCHABLE_BLOCK_TRANSACTION));
if(isVerifyingSignatures()) {
Function<Sha256Hash, Transaction> inputTransactions = txid -> {
BlockTransaction blockTransaction = fetched.containsKey(txid) ? fetched.get(txid) : wallet.getWalletTransaction(txid);
### src/test/java/com/sparrowwallet/sparrow/net/SilentPaymentsBatchTest.java
@@ -0,0 +1,192 @@
+package com.sparrowwallet.sparrow.net;
+
+import com.github.arteam.simplejsonrpc.client.Transport;
+import com.google.common.net.HostAndPort;
+import com.sparrowwallet.drongo.KeyDerivation;
+import com.sparrowwallet.drongo.KeyPurpose;
+import com.sparrowwallet.drongo.Network;
+import com.sparrowwallet.drongo.Utils;
+import com.sparrowwallet.drongo.crypto.ECKey;
+import com.sparrowwallet.drongo.policy.Policy;
+import com.sparrowwallet.drongo.policy.PolicyType;
+import com.sparrowwallet.drongo.protocol.HashIndex;
+import com.sparrowwallet.drongo.protocol.Script;
+import com.sparrowwallet.drongo.protocol.ScriptType;
+import com.sparrowwallet.drongo.protocol.Sha256Hash;
+import com.sparrowwallet.drongo.protocol.Transaction;
+import com.sparrowwallet.drongo.silentpayments.SilentPayment;
+import com.sparrowwallet.drongo.silentpayments.SilentPaymentScanAddress;
+import com.sparrowwallet.drongo.silentpayments.SilentPaymentUtils;
+import com.sparrowwallet.drongo.wallet.BlockTransactionHashIndex;
+import com.sparrowwallet.drongo.wallet.Keystore;
+import com.sparrowwallet.drongo.wallet.Wallet;
+import com.sparrowwallet.drongo.wallet.WalletNode;
+import com.sparrowwallet.sparrow.SparrowWallet;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+import java.math.BigInteger;
+import java.nio.file.Path;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * What a batch of silent payments entries adds to a wallet. The entries held for a subscription are all processed again on every refresh, so an entry
+ * that cannot be processed is passed over rather than failing the batch it is in and each one after it.
+ */
+public class SilentPaymentsBatchTest {
+ private static final String UNKNOWN_TXID = "1100000000000000000000000000000000000000000000000000000000000000";
+
+ @TempDir
+ private static Path tempHome;
+
+ private ElectrumServerRpc previousElectrumServerRpc;
+ private CloseableTransport previousTransport;
+ private ServerCapability previousServerCapability;
+ private final Map<String, Transaction> served = new LinkedHashMap<>();
+
+ @BeforeAll
+ public static void setUpAll() {
+ System.setProperty(SparrowWallet.APP_HOME_PROPERTY, tempHome.toString());
+ }
+
+ @AfterAll
+ public static void tearDownAll() {
+ System.clearProperty(SparrowWallet.APP_HOME_PROPERTY);
+ }
+
+ @BeforeEach
+ public void setUp() {
+ Network.set(Network.TESTNET);
+ previousElectrumServerRpc = ElectrumServer.electrumServerRpc;
+ previousTransport = ElectrumServer.transport;
+ previousServerCapability = ElectrumServer.serverCapability;
+ ElectrumServer.transport = new TcpTransport(HostAndPort.fromParts("localhost", 1));
+ ElectrumServer.serverCapability = new ServerCapability(false, false, false);
+ ElectrumServer.electrumServerRpc = new SimpleElectrumServerRpc() {
+ @Override
+ public Map<String, String> getTransactions(Transport transport, Wallet wallet, Set<String> txids) {
+ Map<String, String> result = new LinkedHashMap<>();
+ txids.forEach(txid -> result.put(txid, served.containsKey(txid) ? Utils.bytesToHex(served.get(txid).bitcoinSerialize()) : Sha256Hash.ZERO_HASH.toString()));
+ return result;
+ }
+ };
+ }
+
+ @AfterEach
+ public void tearDown() {
+ ElectrumServer.electrumServerRpc = previousElectrumServerRpc;
+ ElectrumServer.transport = previousTransport;
+ ElectrumServer.serverCapability = previousServerCapability;
+ ElectrumServer.clearPreviousServerState();
+ Network.set(null);
+ }
+
+ @Test
+ public void addsANodeForEachPaymentFound() throws Exception {
+ Wallet wallet = silentPaymentsWallet();
+ List<SilentPaymentsTx> entries = List.of(payment(wallet, 1, 10000L), payment(wallet, 2, 20000L));
+
+ Set<WalletNode> affectedNodes = new ElectrumServer().processSilentPaymentBatch(wallet, entries);
+
+ assertEquals(2, affectedNodes.size());
+ assertEquals(30000L, walletBalance(wallet));
+ }
+
+ /**
+ * A transaction can leave the mempool between being announced and being fetched. The entry naming it is skipped as a malformed one is, and
+ * nothing is recorded for it, so the other entries of this batch and of those that follow are still processed.
+ */
+ @Test
+ public void skipsAnEntryWhoseTransactionTheServerDoesNotSupply() throws Exception {
+ Wallet wallet = silentPaymentsWallet();
+ SilentPaymentsTx first = payment(wallet, 1, 10000L);
+ SilentPaymentsTx unfetchable = new SilentPaymentsTx(0, UNKNOWN_TXID, first.tweak_key);
+
+ assertEquals(1, new ElectrumServer().processSilentPaymentBatch(wallet, List.of(unfetchable, first)).size());
+ assertFalse(wallet.getTransactions().containsKey(Sha256Hash.wrap(UNKNOWN_TXID)));
+
+ SilentPaymentsTx second = payment(wallet, 2, 20000L);
+ assertEquals(1, new ElectrumServer().processSilentPaymentBatch(wallet, List.of(unfetchable, first, second)).size());
+ assertEquals(2, wallet.getNode(KeyPurpose.RECEIVE).getChildren().size());
+ assertEquals(30000L, walletBalance(wallet));
+ }
+
+ /**
+ * A skipped entry is asked for again on each refresh, so its payment is found once the server has the transaction.
+ */
+ @Test
+ public void findsAPaymentOnceTheServerSuppliesItsTransaction() throws Exception {
+ Wallet wallet = silentPaymentsWallet();
+ SilentPaymentsTx payment = payment(wallet, 1, 10000L);
+ Transaction transaction = served.remove(payment.tx_hash);
+
+ assertTrue(new ElectrumServer().processSilentPaymentBatch(wallet, List.of(payment)).isEmpty());
+ assertEquals(0L, walletBalance(wallet));
+
+ served.put(payment.tx_hash, transaction);
+ assertEquals(1, new ElectrumServer().processSilentPaymentBatch(wallet, List.of(payment)).size());
+ assertEquals(10000L, walletBalance(wallet));
+ }
+
+ /**
+ * A failed script hash fetch leaves the unfetchable placeholder in the wallet's transactions. It is fetched again rather than taken as the transaction.
+ */
+ @Test
+ public void fetchesAgainATransactionTheWalletHoldsAsUnfetchable() throws Exception {
+ Wallet wallet = silentPaymentsWallet();
+ SilentPaymentsTx payment = payment(wallet, 1, 10000L);
+ wallet.updateTransactions(Map.of(Sha256Hash.wrap(payment.tx_hash), ElectrumServer.UNFETCHABLE_BLOCK_TRANSACTION));
+
+ assertEquals(1, new ElectrumServer().processSilentPaymentBatch(wallet, List.of(payment)).size());
+ assertEquals(10000L, walletBalance(wallet));
+ }
+
+ /**
+ * Builds a payment to the wallet's silent payment address, which the server then holds in its mempool, returning the entry a subscription reports for it.
+ */
+ private SilentPaymentsTx payment(Wallet wallet, int sender, long amount) throws Exception {
+ ECKey senderKey = ECKey.fromPrivate(BigInteger.valueOf(1000 + sender));
+ HashIndex outpoint = new HashIndex(Sha256Hash.of(new byte[] {(byte)sender}), 0);
+ SilentPayment silentPayment = new SilentPayment(wallet.getSilentPaymentScanAddress().getSilentPaymentAddress(), null, amount, false);
+ SilentPaymentUtils.computeOutputAddresses(List.of(silentPayment), senderKey, Set.of(outpoint));
+
+ Transaction transaction = new Transaction();
+ transaction.addInput(outpoint.getHash(), outpoint.getIndex(), new Script(new byte[0]));
+ transaction.addOutput(amount, silentPayment.getAddress());
+ served.put(transaction.getTxId().toString(), transaction);
+
+ ECKey senderPubKey = ECKey.fromPublicOnly(senderKey);
+ BigInteger inputHash = SilentPaymentUtils.getInputHash(Set.of(outpoint), senderPubKey);
+ return new SilentPaymentsTx(0, transaction.getTxId().toString(), Utils.bytesToHex(senderPubKey.multiply(inputHash, true).getPubKey(true)));
+ }
+
+ private static long walletBalance(Wallet wallet) {
+ return wallet.getWalletUtxos().keySet().stream().mapToLong(BlockTransactionHashIndex::getValue).sum();
+ }
+
+ private static Wallet silentPaymentsWallet() {
+ ECKey scanKey = ECKey.fromPrivate(Utils.hexToBytes("a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2"));
+ ECKey spendKey = ECKey.fromPrivate(Utils.hexToBytes("b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3"));
+
+ Wallet wallet = new Wallet("silentpayments");
+ wallet.setPolicyType(PolicyType.SINGLE_SP);
+ wallet.setScriptType(ScriptType.P2TR);
+ Keystore keystore = new Keystore();
+ keystore.setSilentPaymentScanAddress(new SilentPaymentScanAddress(scanKey, ECKey.fromPublicOnly(spendKey)));
+ keystore.setKeyDerivation(new KeyDerivation("deadbeef", "m/352'/1'/0'"));
+ wallet.getKeystores().add(keystore);
+ wallet.setDefaultPolicy(Policy.getPolicy(PolicyType.SINGLE_SP, ScriptType.P2TR, wallet.getKeystores(), 1));
+ return wallet;
+ }
+}Why this scored 34/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.