point to rpcallowip when bitcoin core v32.1+ closes the rpc connection, and read the mempool vsize from vsize_adjusted
What changed, and why it matters
This commit updates Sparrow Wallet to work smoothly with Bitcoin Core version 32.1. It improves an error message when Bitcoin Core refuses a connection due to IP restrictions, and it reads a renamed mempool size field from newer Bitcoin Core versions. There is no indication this fixes an exploitable security vulnerability; it is primarily a compatibility and user-guidance improvement.
No security action required beyond normal review and release. The change is a compatibility/user-experience improvement. Users connecting to Bitcoin Core v32.1+ should ensure rpcallowip is configured correctly, as the improved error message now indicates.
Security signals we found
Improved error messaging for connection rejection (non-exploitable usability/security hygiene)
Compatibility update for Bitcoin Core v32.1 RPC/mempool field changes
Evidence from the diff
The patch makes two compatibility-oriented changes: (1) In BitcoindTransport, when Bitcoin Core v32.1+ silently closes an RPC connection from a non-allowed IP (instead of returning HTTP 403), the resulting IOException is wrapped with a clearer message pointing the user to check rpcallowip. (2) In MempoolEntry, the record now accepts both the legacy vsize field and the new vsize_adjusted field introduced in Bitcoin Core v32.1, preferring vsize_adjusted and falling back to vsize. Tests are added for both behaviors. No vulnerability class such as injection, buffer overflow, or cryptographic flaw is present in the diff.
Changed components
src/main/java/com/sparrowwallet/sparrow/net/cormorant/bitcoind/BitcoindTransport.javasrc/main/java/com/sparrowwallet/sparrow/net/cormorant/bitcoind/MempoolEntry.javaInspect captured patch +126 / −5
### src/main/java/com/sparrowwallet/sparrow/net/cormorant/bitcoind/BitcoindTransport.java
@@ -110,7 +110,15 @@ public String pass(String request) throws IOException {
os.write(jsonBytes);
}
- int statusCode = connection.getResponseCode();
+ int statusCode;
+ try {
+ statusCode = connection.getResponseCode();
+ } catch(InterruptedIOException e) {
+ throw e;
+ } catch(IOException e) {
+ //From v32.1 Bitcoin Core closes the connection from a client outside rpcallowip without answering, where earlier versions answered 403 below
+ throw new IOException("Bitcoin Core at " + bitcoindUrl.getAuthority() + " closed the connection without responding, check its rpcallowip settings", e);
+ }
//Trust on first use, as for non-CA-certified Electrum servers: the certificate presented by the node on the first connection is saved, and required on all connections thereafter
if(connection instanceof HttpsURLConnection httpsConn && Storage.getCertificateFile(bitcoindServer.getHost()) == null) {
### src/main/java/com/sparrowwallet/sparrow/net/cormorant/bitcoind/MempoolEntry.java
@@ -3,17 +3,22 @@
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.sparrowwallet.sparrow.net.cormorant.index.TxEntry;
+//Bitcoin Core v32.1 deprecates vsize in favour of the identical vsize_adjusted, so prefer the latter and fall back for earlier versions
@JsonIgnoreProperties(ignoreUnknown = true)
-public record MempoolEntry(int vsize, int ancestorsize, boolean bip125_replaceable, FeesMempoolEntry fees) {
+public record MempoolEntry(Integer vsize, Integer vsize_adjusted, int ancestorsize, FeesMempoolEntry fees) {
+ public int getVsize() {
+ return vsize_adjusted != null ? vsize_adjusted : vsize;
+ }
+
public boolean hasUnconfirmedParents() {
- return vsize != ancestorsize;
+ return getVsize() != ancestorsize;
}
public TxEntry getTxEntry(String txid) {
return new TxEntry(hasUnconfirmedParents() ? -1 : 0, 0, txid, fees().base());
}
public VsizeFeerate getVsizeFeerate() {
- return new VsizeFeerate(vsize, fees().base());
+ return new VsizeFeerate(getVsize(), fees().base());
}
}
### src/test/java/com/sparrowwallet/sparrow/net/cormorant/bitcoind/BitcoindTransportRejectionTest.java
@@ -0,0 +1,72 @@
+package com.sparrowwallet.sparrow.net.cormorant.bitcoind;
+
+import com.sparrowwallet.sparrow.SparrowWallet;
+import com.sparrowwallet.sparrow.io.Server;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.nio.file.Path;
+import java.time.Duration;
+
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTimeoutPreemptively;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * From v32.1 Bitcoin Core closes the connection from a client outside rpcallowip instead of answering 403.
+ */
+public class BitcoindTransportRejectionTest {
+ @TempDir
+ private static Path tempHome;
+
+ @BeforeAll
+ public static void setUp() {
+ //Config.get() caches its instance for the life of the JVM, so keep these tests from loading the developer's real config and leaving it cached for those that follow
+ System.setProperty(SparrowWallet.APP_HOME_PROPERTY, tempHome.toString());
+ }
+
+ @AfterAll
+ public static void tearDown() {
+ System.clearProperty(SparrowWallet.APP_HOME_PROPERTY);
+ }
+
+ @Test
+ public void closedConnectionPointsToRpcAllowIp() throws Exception {
+ assertRpcAllowIpHint(false);
+ }
+
+ @Test
+ public void resetConnectionPointsToRpcAllowIp() throws Exception {
+ assertRpcAllowIpHint(true);
+ }
+
+ private static void assertRpcAllowIpHint(boolean reset) throws Exception {
+ try(ServerSocket serverSocket = new ServerSocket(0, 50, InetAddress.getLoopbackAddress())) {
+ Thread acceptor = new Thread(() -> {
+ try {
+ while(!serverSocket.isClosed()) {
+ Socket socket = serverSocket.accept();
+ socket.setSoLinger(reset, 0);
+ socket.close();
+ }
+ } catch(IOException e) {
+ //Server socket closed at the end of the test
+ }
+ });
+ acceptor.setDaemon(true);
+ acceptor.start();
+
+ BitcoindTransport transport = new BitcoindTransport(new Server("http://127.0.0.1:" + serverSocket.getLocalPort()), "test", "user:pass");
+ assertTimeoutPreemptively(Duration.ofSeconds(10), () -> {
+ IOException thrown = assertThrows(IOException.class, () -> transport.pass("{\"id\":1,\"method\":\"getblockchaininfo\",\"params\":[]}"));
+ assertTrue(thrown.getMessage().contains("rpcallowip"), "Expected the rpcallowip hint, got: " + thrown);
+ });
+ }
+ }
+}
### src/test/java/com/sparrowwallet/sparrow/net/cormorant/bitcoind/MempoolEntryTest.java
@@ -0,0 +1,36 @@
+package com.sparrowwallet.sparrow.net.cormorant.bitcoind;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+public class MempoolEntryTest {
+ private static final ObjectMapper MAPPER = new ObjectMapper();
+ private static final String FEES = "\"fees\":{\"base\":0.00000282,\"ancestor\":0.00000282}";
+
+ @Test
+ public void readsVsizeFromCoreBeforeV32() throws Exception {
+ MempoolEntry entry = MAPPER.readValue("{\"vsize\":141,\"ancestorsize\":141,\"bip125-replaceable\":true," + FEES + "}", MempoolEntry.class);
+ assertEquals(141, entry.getVsize());
+ assertFalse(entry.hasUnconfirmedParents());
+ assertEquals(2.0, entry.getVsizeFeerate().getFeerate());
+ }
+
+ @Test
+ public void readsAdjustedVsizeFromCoreV32() throws Exception {
+ MempoolEntry entry = MAPPER.readValue("{\"vsize\":141,\"vsize_adjusted\":141,\"vsize_bip141\":141,\"ancestorsize\":282," + FEES + "}", MempoolEntry.class);
+ assertEquals(141, entry.getVsize());
+ assertTrue(entry.hasUnconfirmedParents());
+ }
+
+ @Test
+ public void readsAdjustedVsizeOnceVsizeIsRemoved() throws Exception {
+ MempoolEntry entry = MAPPER.readValue("{\"vsize_adjusted\":141,\"vsize_bip141\":141,\"ancestorsize\":141," + FEES + "}", MempoolEntry.class);
+ assertEquals(141, entry.getVsize());
+ assertFalse(entry.hasUnconfirmedParents());
+ assertEquals(2.0, entry.getVsizeFeerate().getFeerate());
+ }
+}
### src/test/java/com/sparrowwallet/sparrow/net/cormorant/index/StoreTest.java
@@ -88,7 +88,7 @@ public void testUnconfirmedTransactionWithUnconfirmedParentsIsNotUpdatedByRelist
ListTransaction unconfirmed = new ListTransaction(address.toString(), List.of(), Category.receive, 1.0, 0, 0.0, 0, null, 0, 0, 0, FIRST_TXID, 0, 0, List.of(), List.of());
assertEquals(scriptHash, store.addAddressTransaction(address, unconfirmed));
- store.getMempoolEntries().put(FIRST_TXID, new MempoolEntry(100, 200, true, new FeesMempoolEntry(0.00001, 0.00002)));
+ store.getMempoolEntries().put(FIRST_TXID, new MempoolEntry(100, null, 200, new FeesMempoolEntry(0.00001, 0.00002)));
assertEquals(Set.of(scriptHash), store.updateMempoolTransactions());
assertEquals(List.of(-1), store.getHistory(scriptHash).stream().map(txEntry -> txEntry.height).toList());
String status = store.getStatus(scriptHash);Why this scored 22/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.