commit
4819265745
@ -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
|
||||
|
||||
@ -339,7 +339,8 @@ exports.getReward = function getReward(height, interval) {
|
||||
// BIP 42 (well, our own version of it,
|
||||
// since we can only handle 32 bit shifts).
|
||||
// https://github.com/bitcoin/bips/blob/master/bip-0042.mediawiki
|
||||
if (halvings >= 33)
|
||||
// FLO can safely handle 34 (instead of 33) halvings
|
||||
if (halvings >= 34)
|
||||
return 0;
|
||||
|
||||
// We need to shift right by `halvings`,
|
||||
|
||||
@ -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();
|
||||
|
||||
@ -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)
|
||||
*/
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "fcoin",
|
||||
"version": "1.1.3",
|
||||
"version": "1.1.4",
|
||||
"description": "FLO bike-shed",
|
||||
"license": "MIT",
|
||||
"repository": "git://github.com/oipwg/fcoin.git",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user