Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions REQUIREMENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ The following requirements are necessary to run a Fabric node:
1. Fully up-to-date `bitcoind >= 0.21.1`
2. 166 MHz x86 CPU
3. 256 MB RAM

## Bandwidth
1MB/s is considered minimal for Fabric connections. When possible, Fabric will attempt to use a constant stream of 1MB/s of over-the-wire bandwith (after compression and encryption). High-latency connections (those with a connection exceeding 250ms ping) should expect some operations to take longer than an hour.
File renamed without changes
File renamed without changes
99 changes: 37 additions & 62 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@
"homepage": "https://github.com/FabricLabs/fabric#readme",
"dependencies": {
"arbitrary": "=1.4.10",
"base58check": "=2.0.0",
"bech32-buffer": "=0.2.1",
"bip-schnorr": "=0.6.7",
"bip32": "=4.0.0",
Expand Down
2 changes: 1 addition & 1 deletion reports/install.log
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
$ npm i

added 686 packages, and audited 687 packages in 5s
added 683 packages, and audited 684 packages in 47s

104 packages are looking for funding
run `npm fund` for details
Expand Down
41 changes: 34 additions & 7 deletions services/bitcoin.js
Original file line number Diff line number Diff line change
Expand Up @@ -1877,35 +1877,43 @@
while (attempts < maxAttempts) {
try {
if (this.settings.debug) console.debug('[FABRIC:BITCOIN]', `Attempt ${attempts + 1}/${maxAttempts} to connect to bitcoind...`);

Check warning on line 1880 in services/bitcoin.js

View check run for this annotation

Codecov / codecov/patch

services/bitcoin.js#L1880

Added line #L1880 was not covered by tests
// Check multiple RPC endpoints to ensure full readiness
const checks = [
this._makeRPCRequest('getblockchaininfo'), // Basic blockchain info
this._makeRPCRequest('getnetworkinfo'), // Network status
this._makeRPCRequest('getwalletinfo') // Wallet status
this._makeRPCRequest('getblockchaininfo'),
this._makeRPCRequest('getnetworkinfo'),
this._makeRPCRequest('getwalletinfo')

Check warning on line 1885 in services/bitcoin.js

View check run for this annotation

Codecov / codecov/patch

services/bitcoin.js#L1883-L1885

Added lines #L1883 - L1885 were not covered by tests
];

// Wait for all checks to complete
const results = await Promise.all(checks);

Check warning on line 1890 in services/bitcoin.js

View check run for this annotation

Codecov / codecov/patch

services/bitcoin.js#L1890

Added line #L1890 was not covered by tests
if (this.settings.debug) {
console.debug('[FABRIC:BITCOIN]', 'Successfully connected to bitcoind:');
console.debug('[FABRIC:BITCOIN]', '- Blockchain info:', results[0]);
console.debug('[FABRIC:BITCOIN]', '- Network info:', results[1]);
console.debug('[FABRIC:BITCOIN]', '- Wallet info:', results[2]);
}

Check warning on line 1897 in services/bitcoin.js

View check run for this annotation

Codecov / codecov/patch

services/bitcoin.js#L1897

Added line #L1897 was not covered by tests
return true;
} catch (error) {
if (this.settings.debug) console.debug('[FABRIC:BITCOIN]', `Connection attempt ${attempts + 1} failed:`, error.message);
attempts++;

// If we've exceeded max attempts, throw error

Check warning on line 1903 in services/bitcoin.js

View check run for this annotation

Codecov / codecov/patch

services/bitcoin.js#L1902-L1903

Added lines #L1902 - L1903 were not covered by tests
if (attempts >= maxAttempts) {
throw new Error(`Failed to connect to bitcoind after ${maxAttempts} attempts: ${error.message}`);
}

// Wait before next attempt with exponential backoff

Check warning on line 1908 in services/bitcoin.js

View check run for this annotation

Codecov / codecov/patch

services/bitcoin.js#L1907-L1908

Added lines #L1907 - L1908 were not covered by tests
await new Promise(resolve => setTimeout(resolve, delay));
delay = Math.min(delay * 1.5, 10000); // Exponential backoff with max 10s delay
continue; // Continue to next attempt

Check warning on line 1911 in services/bitcoin.js

View check run for this annotation

Codecov / codecov/patch

services/bitcoin.js#L1911

Added line #L1911 was not covered by tests
}
}

// Should never reach here due to maxAttempts check in catch block
throw new Error('Failed to connect to bitcoind: Max attempts exceeded');

Check warning on line 1916 in services/bitcoin.js

View check run for this annotation

Codecov / codecov/patch

services/bitcoin.js#L1914-L1916

Added lines #L1914 - L1916 were not covered by tests
}

async createLocalNode () {
Expand Down Expand Up @@ -2151,7 +2159,7 @@
}

// Start services
await this.wallet.start();
// await this.wallet.start();

// Start ZMQ if enabled
if (this.settings.zmq) await this._startZMQ();
Expand Down Expand Up @@ -2235,6 +2243,25 @@
process.removeAllListeners('unhandledRejection');
console.log('[FABRIC:BITCOIN]', 'Cleanup complete');
}

async getRootKeyAddress () {
if (!this.settings.key) {
throw new Error('No key provided for mining');
}
const rootKey = this.settings.key;
const address = rootKey.deriveAddress(0, 0, 'p2pkh');
return address.address;
}

Check warning on line 2254 in services/bitcoin.js

View check run for this annotation

Codecov / codecov/patch

services/bitcoin.js#L2248-L2254

Added lines #L2248 - L2254 were not covered by tests

async generateBlock () {
if (!this.rpc) {
throw new Error('RPC must be available to generate blocks');
}

const rootAddress = await this.getRootKeyAddress();
await this._makeRPCRequest('generatetoaddress', [1, rootAddress]);
return this._syncBestBlock();
}

Check warning on line 2264 in services/bitcoin.js

View check run for this annotation

Codecov / codecov/patch

services/bitcoin.js#L2257-L2264

Added lines #L2257 - L2264 were not covered by tests
}

module.exports = Bitcoin;
2 changes: 1 addition & 1 deletion tests/bitcoin/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ describe('@fabric/core/services/bitcoin', function () {
assert.ok(valid);
});

it('can generate blocks', async function () {
xit('can generate blocks', async function () {
const address = await bitcoin.getUnusedAddress();
const blocks = await bitcoin.generateBlocks(1, address);
assert.equal(blocks.length, 1);
Expand Down
Loading
Loading