Merge pull request #5875 from chimp1984/fix-incorrect-chainheight

Fix incorrect start height for block request
This commit is contained in:
Christoph Atteneder 2021-12-06 11:36:00 +01:00 committed by GitHub
commit 6e1a805b22
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 26 deletions

View File

@ -182,26 +182,6 @@ public abstract class BsqNode implements DaoSetupService {
p2PService.removeP2PServiceListener(p2PServiceListener);
}
@SuppressWarnings("WeakerAccess")
protected int getStartBlockHeight() {
int chainHeight = daoStateService.getChainHeight();
int startBlockHeight = chainHeight;
if (chainHeight > genesisBlockHeight)
startBlockHeight = chainHeight + 1;
log.info("getStartBlockHeight:\n" +
" Start block height={}\n" +
" Genesis txId={}\n" +
" Genesis block height={}\n" +
" Block height={}\n",
startBlockHeight,
genesisTxId,
genesisBlockHeight,
chainHeight);
return startBlockHeight;
}
protected abstract void startParseBlocks();
protected void onParseBlockChainComplete() {

View File

@ -107,8 +107,7 @@ public class FullNode extends BsqNode {
@Override
protected void startParseBlocks() {
int startBlockHeight = getStartBlockHeight();
int startBlockHeight = daoStateService.getChainHeight();
log.info("startParseBlocks: startBlockHeight={}", startBlockHeight);
rpcService.requestChainHeadHeight(chainHeight -> {
// If our persisted block is equal to the chain height we have startBlockHeight 1 block higher,

View File

@ -182,7 +182,20 @@ public class LiteNode extends BsqNode {
// First we request the blocks from a full node
@Override
protected void startParseBlocks() {
liteNodeNetworkService.requestBlocks(getStartBlockHeight());
int chainHeight = daoStateService.getChainHeight();
if (walletsSetup.isDownloadComplete() && chainHeight == bsqWalletService.getBestChainHeight()) {
log.info("No block request needed as we have already the most recent block. " +
"daoStateService.getChainHeight()={}, bsqWalletService.getBestChainHeight()={}",
chainHeight, bsqWalletService.getBestChainHeight());
onParseBlockChainComplete();
return;
}
if (chainHeight == daoStateService.getGenesisBlockHeight()) {
liteNodeNetworkService.requestBlocks(chainHeight);
} else {
liteNodeNetworkService.requestBlocks(chainHeight + 1);
}
}
@ -221,9 +234,8 @@ public class LiteNode extends BsqNode {
MathUtils.roundDouble(duration / blockList.size(), 2));
// We only request again if wallet is synced, otherwise we would get repeated calls we want to avoid.
// We deal with that case at the setupWalletBestBlockListener method above.
if (walletsSetup.isDownloadComplete() &&
daoStateService.getChainHeight() < bsqWalletService.getBestChainHeight()) {
liteNodeNetworkService.requestBlocks(getStartBlockHeight());
if (walletsSetup.isDownloadComplete() && daoStateService.getChainHeight() < bsqWalletService.getBestChainHeight()) {
liteNodeNetworkService.requestBlocks(daoStateService.getChainHeight() + 1);
} else {
onParsingComplete.run();
onParseBlockChainComplete();