recover from race condition in interrupted sync
This commit is contained in:
parent
fbe16eda9f
commit
ed787d58cb
|
@ -238,22 +238,32 @@ function spec() {
|
||||||
function(err) {
|
function(err) {
|
||||||
if (err) return next(err);
|
if (err) return next(err);
|
||||||
var ret = false;
|
var ret = false;
|
||||||
if ( self.blockChainHeight === blockInfo.height ||
|
if ( self.blockChainHeight === blockInfo.height || // Still the tip
|
||||||
blockInfo.confirmations > 0) {
|
blockInfo.confirmations > 0) { // Or is confirmed
|
||||||
ret = false;
|
ret = false;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
oldtip = tip;
|
oldtip = tip;
|
||||||
tip = blockInfo.previousblockhash;
|
tip = blockInfo.previousblockhash;
|
||||||
assert(tip);
|
p('Previous TIP is now orphan.');
|
||||||
p('Previous TIP is now orphan. Back to:' + tip);
|
if (tip) {
|
||||||
|
p('\tGoing back to:' + tip);
|
||||||
ret = true;
|
ret = true;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
p('\tNo able to recover last tip. A Total resync is needed.');
|
||||||
|
tip = self.genesis;
|
||||||
|
self.needResync = 1;
|
||||||
|
ret = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
return ret;
|
return ret;
|
||||||
},
|
},
|
||||||
function(err) {
|
function(err) {
|
||||||
self.startBlock = tip;
|
self.startBlock = tip;
|
||||||
|
if (!self.needResync) {
|
||||||
p('Resuming sync from block:'+tip);
|
p('Resuming sync from block:'+tip);
|
||||||
|
}
|
||||||
return next(err);
|
return next(err);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -354,15 +364,22 @@ function spec() {
|
||||||
function(s_c) {
|
function(s_c) {
|
||||||
self.checkNetworkSettings(s_c);
|
self.checkNetworkSettings(s_c);
|
||||||
},
|
},
|
||||||
function(s_c) {
|
|
||||||
self.updateConnectedCountDB(s_c);
|
|
||||||
},
|
|
||||||
function(s_c) {
|
function(s_c) {
|
||||||
self.updateBlockChainHeight(s_c);
|
self.updateBlockChainHeight(s_c);
|
||||||
},
|
},
|
||||||
function(s_c) {
|
function(s_c) {
|
||||||
self.updateStartBlock(s_c);
|
self.updateStartBlock(s_c);
|
||||||
},
|
},
|
||||||
|
function(s_c) {
|
||||||
|
if (self.needResync) {
|
||||||
|
self.needResync=0;
|
||||||
|
self.sync.destroy(s_c);
|
||||||
|
}
|
||||||
|
else s_c();
|
||||||
|
},
|
||||||
|
function(s_c) {
|
||||||
|
self.updateConnectedCountDB(s_c);
|
||||||
|
},
|
||||||
function(s_c) {
|
function(s_c) {
|
||||||
self.prepareFileSync(opts, s_c);
|
self.prepareFileSync(opts, s_c);
|
||||||
},
|
},
|
||||||
|
|
|
@ -673,7 +673,6 @@ isspent
|
||||||
|
|
||||||
var k = FROM_BLK_PREFIX + hash;
|
var k = FROM_BLK_PREFIX + hash;
|
||||||
var k2 = IN_BLK_PREFIX;
|
var k2 = IN_BLK_PREFIX;
|
||||||
// This is slow, but prevent us to create a new block->tx index.
|
|
||||||
db.createReadStream({
|
db.createReadStream({
|
||||||
start: k,
|
start: k,
|
||||||
end: k + '~'
|
end: k + '~'
|
||||||
|
|
Loading…
Reference in New Issue