Compare commits

...

14 Commits

Author SHA1 Message Date
Devon R. James
be373552f5 v 1.1.6
updated brcypto to 5.4.0 and bfilter to devon's fork
2021-04-16 12:16:13 -07:00
Sky Young
5ea8c38f35
Merge pull request #17 from mediciland/fix-bfilter-bug
Fix installation bug with `bfilter` and `mrmr`
2020-12-09 11:57:54 -07:00
Sky Young
9ed0967b68 v1.1.5 2020-12-09 11:36:16 -07:00
Sky Young
31765b1dff Use murmur3 inside of bcrypto 2020-11-19 14:12:00 -07:00
Sky Young
4819265745
Merge pull request #1 from oipwg/master
Pull changes from oipwg master
2020-11-19 14:03:48 -07:00
ohryan
a7486eaae1
Merge pull request #16 from oipwg/nlr
add nlr check to reorganize function
2020-07-23 09:33:43 -07:00
ohryan
5321251db3 set competitor chain tip to invaild
setting the competitor chain tip to invaild fixes the problem where the chain continues to sync after nlr. main chain will no longer sync with competitor after nlr
2020-07-21 14:01:48 -07:00
ohryan
83a11fbcb2 setInvalid instead of invalidate + strictEqual assert
instead of running this.invalidate which deadlocks the chain, set the hash to invalid manually with this.setInvalid.

update assertion to use strict equal
2020-07-20 17:43:34 -07:00
ohryan
36671d02ed pull loop variable outside for reassignment 2020-07-17 20:03:07 -07:00
ohryan
c6317a268d update invalidation stepping to use just the while loop and add missing await to assert check 2020-07-16 19:20:49 -07:00
ohryan
11534032f4 fix/update logger warning and fix incorrect assert usage 2020-07-16 19:07:39 -07:00
ohryan
9f9c536efc add missing awaits 2020-07-16 08:31:10 -07:00
ohryan
7a1816a3a8 refactor/update nlr function; check nlr for spv wallet 2020-07-15 19:07:25 -07:00
ohryan
430276b592 add nlr check to reorganize function 2020-07-15 17:45:56 -07:00
6 changed files with 114 additions and 25 deletions

View File

@ -855,6 +855,9 @@ class Chain extends AsyncEmitter {
assert(fork, 'No free space or data corruption.');
// Check NLR
if (await this.noLongReorg(tip, fork, competitor)) return true
// Blocks to disconnect.
const disconnect = [];
let entry = tip;
@ -912,6 +915,9 @@ class Chain extends AsyncEmitter {
assert(fork, 'No free space or data corruption.');
// Check NLR
if (await this.noLongReorg(tip, fork, competitor)) return true
// Buffer disconnected blocks.
const disconnect = [];
let entry = tip;
@ -950,6 +956,48 @@ class Chain extends AsyncEmitter {
return this.emitAsync('reorganize', tip, competitor);
}
/**
* Checks if a reorganization breaks the set nlrLimit,
* if it does, it invalidates necessary blocks and returns true
* else return false
* @param {ChainEntry} tip - Current tip of this chain.
* @param {ChainEntry} fork - The tip of the fork.
* @param {ChainEntry} competitor - The competing chain's tip.
* @returns {Promise<boolean>}
*/
async noLongReorg (tip, fork, competitor) {
if (tip.height - fork.height >= this.network.nlrLimit) {
if (this.network.nlrLimit !== 0) {
this.logger.warning(
'NLR Activated. Preventing reorganization: current=%h(%d) competitor=%h(%d) fork=%h(%d) reorg_size=%d nlr=%d',
tip.hash,
tip.height,
competitor.hash,
competitor.height,
fork.hash,
fork.height,
tip.height - fork.height,
this.network.nlrLimit
);
let indexWalk = competitor
// mark invalid_child from tip of competitor to first block of fork
while (indexWalk.height > fork.height) {
await this.setInvalid(indexWalk.hash)
indexWalk = await this.getPrevious(indexWalk)
}
// check
indexWalk = await this.getPrevious(indexWalk)
assert.strictEqual(indexWalk, fork)
return true
}
}
return false
}
/**
* Disconnect an entry from the chain (updates the tip).
* @param {ChainEntry} entry
@ -2209,7 +2257,7 @@ class Chain extends AsyncEmitter {
targetTimespan = pow.targetTimespan_Version1;
} else if ((prev.height + 1) < pow.blockHeight_Version3){
retargetInterval = pow.retargetInterval_Version2;
averagingInterval = pow.averagingInterval_Version2;
targetTimespan = pow.targetTimespan_Version2 * targetSpacing;
@ -2247,10 +2295,10 @@ class Chain extends AsyncEmitter {
// Back 6 block
var back = averagingInterval - 1;
if (prev.height + 1 !== averagingInterval)
back = averagingInterval;
let first = prev;
for (let i = 0; i < back; i++){
if (first)

View File

@ -12,7 +12,7 @@ const fs = require('bfile');
const IP = require('binet');
const dns = require('bdns');
const Logger = require('blgr');
const murmur3 = require('mrmr');
const murmur3 = require('bcrypto/lib/murmur3');
const List = require('blst');
const util = require('../utils/util');
const Network = require('../protocol/network');

View File

@ -58,6 +58,7 @@ class Network {
this.maxFeeRate = options.maxFeeRate;
this.selfConnect = options.selfConnect;
this.requestMempool = options.requestMempool;
this.nlrLimit = options.nlrLimit;
this.time = new TimeData();
this.init();

View File

@ -563,6 +563,8 @@ main.selfConnect = false;
main.requestMempool = false;
main.nlrLimit = 100 // 100 * ~40s = ~66 minutes
/*
* Testnet (v3)
* https://en.bitcoin.it/wiki/Testnet
@ -800,6 +802,8 @@ testnet.selfConnect = false;
testnet.requestMempool = false;
testnet.nlrLimit = 50; // 50 * ~40s = ~33 minutes
/*
* Regtest
*/
@ -1019,6 +1023,8 @@ regtest.selfConnect = true;
regtest.requestMempool = true;
regtest.nlrLimit = 10;
/*
* Simnet (btcd)
*/

69
package-lock.json generated
View File

@ -1,6 +1,6 @@
{
"name": "fcoin",
"version": "1.1.0",
"version": "1.1.4",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
@ -74,13 +74,58 @@
"integrity": "sha512-du2QjKNkqZ1YJweWEQeq3CEqd+nQD/WOnmAMfs52ok5ujBBagWYLZC5ORDuqfV2fuF88of44PZdsnAVfxoH31g=="
},
"bfilter": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/bfilter/-/bfilter-1.0.5.tgz",
"integrity": "sha512-GupIidtCvLbKhXnA1sxvrwa+gh95qbjafy7P1U1x/2DHxNabXq4nGW0x3rmgzlJMYlVl+c8fMxoMRIwpKYlgcQ==",
"version": "git+https://github.com/bcoin-org/bfilter.git#252b496e0057e1b59288efe8472fd021c74f5b91",
"from": "git+https://github.com/bcoin-org/bfilter.git#semver:~2.0.0",
"requires": {
"bsert": "~0.0.10",
"bufio": "~1.0.6",
"mrmr": "~0.1.6"
"bcrypto": "git+https://github.com/bcoin-org/bcrypto.git#semver:~5.0.3",
"bsert": "git+https://github.com/chjj/bsert.git#semver:~0.0.10",
"bufio": "git+https://github.com/bcoin-org/bufio.git#semver:~1.0.6",
"loady": "git+https://github.com/chjj/loady.git#semver:~0.0.1",
"nan": "git+https://github.com/braydonf/nan.git#semver:~2.14.0"
},
"dependencies": {
"bcrypto": {
"version": "git+https://github.com/bcoin-org/bcrypto.git#0a01f693443d8b19f6db1154e0133c7bf703b205",
"from": "git+https://github.com/bcoin-org/bcrypto.git#semver:~5.0.3",
"requires": {
"bufio": "~1.0.6",
"loady": "~0.0.1",
"nan": "^2.14.0"
},
"dependencies": {
"bufio": {
"version": "1.0.7",
"resolved": "https://registry.npmjs.org/bufio/-/bufio-1.0.7.tgz",
"integrity": "sha512-bd1dDQhiC+bEbEfg56IdBv7faWa6OipMs/AFFFvtFnB3wAYjlwQpQRZ0pm6ZkgtfL0pILRXhKxOiQj6UzoMR7A=="
},
"loady": {
"version": "0.0.5",
"resolved": "https://registry.npmjs.org/loady/-/loady-0.0.5.tgz",
"integrity": "sha512-uxKD2HIj042/HBx77NBcmEPsD+hxCgAtjEWlYNScuUjIsh/62Uyu39GOR68TBR68v+jqDL9zfftCWoUo4y03sQ=="
},
"nan": {
"version": "2.14.2",
"resolved": "https://registry.npmjs.org/nan/-/nan-2.14.2.tgz",
"integrity": "sha512-M2ufzIiINKCuDfBSAUr1vWQ+vuVcA9kqx8JJUsbQi6yf1uGRyb7HfpdfUr5qLXf3B/t8dPvcjhKMmlfnP47EzQ=="
}
}
},
"bsert": {
"version": "git+https://github.com/chjj/bsert.git#bd09d49eab8644bca08ae8259a3d8756e7d453fc",
"from": "git+https://github.com/chjj/bsert.git#semver:~0.0.10"
},
"bufio": {
"version": "git+https://github.com/bcoin-org/bufio.git#91ae6c93899ff9fad7d7cee9afd2a1c4933ca984",
"from": "git+https://github.com/bcoin-org/bufio.git#semver:~1.0.6"
},
"loady": {
"version": "git+https://github.com/chjj/loady.git#b94958b7ee061518f4b85ea6da380e7ee93222d5",
"from": "git+https://github.com/chjj/loady.git#semver:~0.0.1"
},
"nan": {
"version": "git+https://github.com/braydonf/nan.git#1dcc61bd06d84e389bfd5311b2b1492a14c74201",
"from": "git+https://github.com/braydonf/nan.git#semver:~2.14.0"
}
}
},
"bheep": {
@ -243,16 +288,6 @@
"resolved": "https://registry.npmjs.org/loady/-/loady-0.0.1.tgz",
"integrity": "sha512-PW5Z13Jd0v6ZcA1P6ZVUc3EV8BJwQuAiwUvvT6VQGHoaZ1d/tu7r1QZctuKfQqwy9SFBWeAGfcIdLxhp7ZW3Rw=="
},
"mrmr": {
"version": "0.1.8",
"resolved": "https://registry.npmjs.org/mrmr/-/mrmr-0.1.8.tgz",
"integrity": "sha512-lNav10EJsPZvlMqlBOYQ5atIO9jrlvbJ4/7asqunXY89dHooN5c+W6AV7jtvBRw4wFDR7TpEWfmBQgRGRVwBzA==",
"requires": {
"bsert": "~0.0.10",
"loady": "~0.0.1",
"nan": "^2.13.1"
}
},
"n64": {
"version": "0.2.10",
"resolved": "https://registry.npmjs.org/n64/-/n64-0.2.10.tgz",

View File

@ -1,6 +1,6 @@
{
"name": "fcoin",
"version": "1.1.4",
"version": "1.1.6",
"description": "FLO bike-shed",
"license": "MIT",
"repository": "git://github.com/oipwg/fcoin.git",
@ -30,12 +30,12 @@
"dependencies": {
"bcfg": "~0.1.6",
"@oipwg/fclient": "~0.1.7",
"bcrypto": "~3.1.11",
"bcrypto": "~5.4.0",
"bdb": "~1.1.7",
"bdns": "~0.1.5",
"bevent": "~0.1.5",
"bfile": "~0.2.1",
"bfilter": "~1.0.5",
"bfilter": "git+https://github.com/devonjames/bfilter.git",
"bheep": "~0.1.5",
"binet": "~0.3.5",
"blgr": "~0.1.7",
@ -53,7 +53,6 @@
"bupnp": "~0.2.6",
"bval": "~0.1.6",
"bweb": "~0.1.9",
"mrmr": "~0.1.8",
"n64": "~0.2.10"
},
"devDependencies": {