Migrate the Fact0rn default node to allow Tor
What changed, and why it matters
This commit fixes a bug where the Fact0rn cryptocurrency default node in Stack Wallet stayed set to 'clearnet only' even after the app shipped a new default that supports Tor. For users who turned on Tor, the wallet could no longer connect to that node, so Fact0rn balances would not refresh and the node health test would fail. The patch adds a one-time database migration that flips Tor support on for the default Fact0rn node, but only if the user has not customized it. It is a connectivity/usability fix, not a vulnerability that lets an attacker steal funds or run code.
Treat as a routine bug-fix release. No urgent security response is required. Verify the migration runs cleanly on existing installs and that Tor-enabled Fact0rn wallets can refresh and pass the node test. Consider documenting the Tor connectivity improvement in release notes.
Security signals we found
Network-layer connectivity fix for Tor users
Migration touches only a single, narrowly matched default node
No cryptographic, authentication, or authorization changes
No input parsing, deserialization, or remote code paths modified
Tests assert customized nodes are not altered
Evidence from the diff
The change adds DB schema migration v17→v18. _v17() opens the Hive NodeModel box, computes the default Fact0rn node ID, and checks whether the saved node still exactly matches the old shipped default (host electrumx2.projectfactor.io, port 50002, default name, SSL on, failover on, no login, clearnet enabled, Tor disabled). If so, it rewrites the node with torEnabled=true while preserving clearnet and other fields. Constants.currentDataVersion is bumped to 18, and tests verify both that the untouched default is migrated and that any user-edited variant is left alone.
Changed components
lib/db/db_version_migration.dartlib/utilities/constants.darttest/db_version_migration_test.dartFact0rn default electrumx node configurationInspect captured patch +107 / −3
### lib/db/db_version_migration.dart
@@ -25,6 +25,7 @@ import '../services/wallets_service.dart';
import '../utilities/amount/amount.dart';
import '../utilities/constants.dart';
import '../utilities/default_eth_tokens.dart';
+import '../utilities/default_nodes.dart';
import '../utilities/flutter_secure_storage_interface.dart';
import '../utilities/logger.dart';
import '../utilities/prefs.dart';
@@ -423,6 +424,16 @@ class DbVersionMigrator with WalletDB {
);
return await migrate(17, secureStore: secureStore);
+ case 17:
+ await _v17();
+
+ await DB.instance.put<dynamic>(
+ boxName: DB.boxNameDBInfo,
+ key: "hive_data_version",
+ value: 18,
+ );
+ return await migrate(18, secureStore: secureStore);
+
default:
// finally return
return;
@@ -711,4 +722,37 @@ class DbVersionMigrator with WalletDB {
await primariesBox.deleteFromDisk();
}
+
+ Future<void> _v17() async {
+ final nodesBox = await DB.instance.hive.openBox<NodeModel>(
+ DB.boxNameNodeModels,
+ );
+ final id = DefaultNodes.buildId(Fact0rn(CryptoCurrencyNetwork.main));
+ final node = nodesBox.get(id);
+
+ // The Fact0rn default node used to ship clearnet only. Only touch a node
+ // that still matches everything the user could have edited on it, so a
+ // customised node keeps its settings.
+ final untouched =
+ node != null &&
+ node.host == "electrumx2.projectfactor.io" &&
+ node.port == 50002 &&
+ node.name == DefaultNodes.defaultName &&
+ node.useSSL &&
+ node.isFailover &&
+ node.loginName == null &&
+ !node.torEnabled &&
+ node.clearnetEnabled;
+
+ if (untouched) {
+ await nodesBox.put(
+ id,
+ node.copyWith(
+ loginName: node.loginName,
+ trusted: node.trusted,
+ torEnabled: true,
+ ),
+ );
+ }
+ }
}
### lib/utilities/constants.dart
@@ -40,7 +40,7 @@ abstract class Constants {
// Enable Logger.print statements
static const bool disableLogger = false;
- static const int currentDataVersion = 17;
+ static const int currentDataVersion = 18;
static const int rescanV1 = 1;
### test/db_version_migration_test.dart
@@ -6,9 +6,11 @@ import 'package:stackwallet/db/db_version_migration.dart';
import 'package:stackwallet/db/hive/db.dart';
import 'package:stackwallet/db/isar/main_db.dart';
import 'package:stackwallet/models/isar/models/ethereum/eth_contract.dart';
+import 'package:stackwallet/models/node_model.dart';
import 'package:stackwallet/utilities/constants.dart';
import 'package:stackwallet/utilities/default_eth_tokens.dart';
import 'package:stackwallet/utilities/flutter_secure_storage_interface.dart';
+import 'package:stackwallet/wallets/crypto_currency/crypto_currency.dart';
import 'hive/hive_ce_test_utils.dart';
@@ -34,8 +36,8 @@ void main() {
DbVersionMigrator().migrate(version, secureStore: FakeSecureStorage());
await migrate(16);
- expect(Constants.currentDataVersion, 17);
- expect(info.get('hive_data_version'), 17);
+ expect(Constants.currentDataVersion, 18);
+ expect(info.get('hive_data_version'), 18);
expect(await db.getEthContracts().isEmpty(), isTrue);
final custom = DefaultTokens.usdc.copyWith(name: 'Custom token');
@@ -58,4 +60,62 @@ void main() {
await migrate(info.get('hive_data_version') as int);
expect(await db.getEthContracts().count(), 1);
});
+
+ test('v18 lets the default Fact0rn node use Tor', () async {
+ await setUpHiveCeTest();
+ addTearDown(tearDownHiveCeTest);
+ final adapter = NodeModelAdapter();
+ if (!DB.instance.hive.isAdapterRegistered(adapter.typeId)) {
+ DB.instance.hive.registerAdapter(adapter);
+ }
+ final info = await DB.instance.hive.openBox<dynamic>(DB.boxNameDBInfo);
+ final nodes = await DB.instance.hive.openBox<NodeModel>(
+ DB.boxNameNodeModels,
+ );
+ NodeModel clearOnly(CryptoCurrency coin) => coin
+ .defaultNode(isPrimary: true)
+ .copyWith(loginName: null, trusted: null, torEnabled: false);
+ final fact0rn = clearOnly(Fact0rn(CryptoCurrencyNetwork.main));
+ final bitcoin = clearOnly(Bitcoin(CryptoCurrencyNetwork.main));
+ await nodes.put(fact0rn.id, fact0rn);
+ await nodes.put(bitcoin.id, bitcoin);
+
+ await DbVersionMigrator().migrate(17, secureStore: FakeSecureStorage());
+
+ expect(info.get('hive_data_version'), 18);
+ expect(nodes.get(fact0rn.id)!.torEnabled, isTrue);
+ expect(nodes.get(fact0rn.id)!.clearnetEnabled, isTrue);
+ expect(nodes.get(fact0rn.id)!.isPrimary, isTrue);
+ expect(nodes.get(bitcoin.id)!.torEnabled, isFalse);
+ });
+
+ test('v18 leaves an edited Fact0rn default node alone', () async {
+ await setUpHiveCeTest();
+ addTearDown(tearDownHiveCeTest);
+ final adapter = NodeModelAdapter();
+ if (!DB.instance.hive.isAdapterRegistered(adapter.typeId)) {
+ DB.instance.hive.registerAdapter(adapter);
+ }
+ await DB.instance.hive.openBox<dynamic>(DB.boxNameDBInfo);
+ final nodes = await DB.instance.hive.openBox<NodeModel>(
+ DB.boxNameNodeModels,
+ );
+ final shipped = Fact0rn(CryptoCurrencyNetwork.main)
+ .defaultNode(isPrimary: true)
+ .copyWith(loginName: null, trusted: null, torEnabled: false);
+ final edited = [
+ shipped.copyWith(loginName: null, trusted: null, isFailover: false),
+ shipped.copyWith(loginName: null, trusted: null, host: "example.com"),
+ shipped.copyWith(loginName: null, trusted: null, port: 50001),
+ shipped.copyWith(loginName: null, trusted: null, useSSL: false),
+ shipped.copyWith(loginName: null, trusted: null, name: "Mine"),
+ shipped.copyWith(loginName: "user", trusted: null),
+ ];
+
+ for (final node in edited) {
+ await nodes.put(node.id, node);
+ await DbVersionMigrator().migrate(17, secureStore: FakeSecureStorage());
+ expect(nodes.get(node.id)!.torEnabled, isFalse, reason: "$node");
+ }
+ });
}Why this scored 25/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.