Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid validating proposals during initial sync #3003

Merged
merged 2 commits into from
Jul 25, 2019
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ private void updateLists() {
List<Proposal> tempProposals = proposalService.getTempProposals();
Set<Proposal> verifiedProposals = proposalService.getProposalPayloads().stream()
.map(ProposalPayload::getProposal)
.filter(proposal -> validatorProvider.getValidator(proposal).isValidAndConfirmed(proposal))
.filter(proposal -> !daoStateService.isParseBlockChainComplete() ||
validatorProvider.getValidator(proposal).isValidAndConfirmed(proposal))
.collect(Collectors.toSet());
Set<Proposal> set = new HashSet<>(tempProposals);
set.addAll(verifiedProposals);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,15 +248,18 @@ private void onProtectedDataAdded(ProtectedStorageEntry entry, boolean fromBroad
if (periodService.isInPhase(daoStateService.getChainHeight(), DaoPhase.Phase.PROPOSAL) ||
periodService.isInPhase(daoStateService.getChainHeight(), DaoPhase.Phase.BREAK1)) {
if (!tempProposals.contains(proposal)) {
if (validatorProvider.getValidator(proposal).areDataFieldsValid(proposal)) {
// We only validate in case the blocks are parsed as otherwise some validators like param validator
// might fail as Dao state is not complete.
if (!daoStateService.isParseBlockChainComplete() ||
validatorProvider.getValidator(proposal).areDataFieldsValid(proposal)) {
if (fromBroadcastMessage) {
log.info("We received a TempProposalPayload and store it to our protectedStoreList. proposalTxId={}",
proposal.getTxId());
}
tempProposals.add(proposal);
} else {
log.debug("We received an invalid proposal from the P2P network. Proposal.txId={}, blockHeight={}",
proposal.getTxId(), daoStateService.getChainHeight());
log.debug("We received an invalid proposal from the P2P network. Proposal={}, blockHeight={}",
proposal, daoStateService.getChainHeight());
}
}
}
Expand Down Expand Up @@ -298,16 +301,20 @@ private void onAppendOnlyDataAdded(PersistableNetworkPayload persistableNetworkP
// We don't validate phase and cycle as we might receive proposals from other cycles or phases at startup.
// Beside that we might receive payloads we requested at the vote result phase in case we missed some
// payloads. We prefer here resilience over protection against late publishing attacks.
if (validatorProvider.getValidator(proposal).areDataFieldsValid(proposal)) {

// We only validate in case the blocks are parsed as otherwise some validators like param validator
// might fail as Dao state is not complete.
if (!daoStateService.isParseBlockChainComplete() ||
validatorProvider.getValidator(proposal).areDataFieldsValid(proposal)) {
if (fromBroadcastMessage) {
log.info("We received a ProposalPayload and store it to our appendOnlyStoreList. proposalTxId={}",
proposal.getTxId());
}
proposalPayloads.add(proposalPayload);
} else {
log.warn("We received a invalid append-only proposal from the P2P network. " +
"Proposal.txId={}, blockHeight={}",
proposal.getTxId(), daoStateService.getChainHeight());
"Proposal={}, blockHeight={}",
proposal, daoStateService.getChainHeight());
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions core/src/main/java/bisq/core/dao/node/lite/LiteNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,12 @@ private void onRequestedBlocksReceived(List<RawBlock> blockList, Runnable onPars
runDelayedBatchProcessing(new ArrayList<>(blockList),
() -> {
log.info("Parsing {} blocks took {} seconds.", blockList.size(), (System.currentTimeMillis() - ts) / 1000d);
if (daoStateService.getChainHeight() < bsqWalletService.getBestChainHeight())
if (daoStateService.getChainHeight() < bsqWalletService.getBestChainHeight()) {
liteNodeNetworkService.requestBlocks(getStartBlockHeight());
else
} else {
onParsingComplete.run();
onParseBlockChainComplete();
}
});
}

Expand Down