Merge pull request #3003 from sqrrm/proposal-parsing-fix

Avoid validating proposals during initial sync
This commit is contained in:
sqrrm 2019-07-25 15:15:08 +02:00 committed by GitHub
commit 30b8e7b55d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 9 deletions

View File

@ -114,7 +114,8 @@ public class ProposalListPresentation implements DaoStateListener, MyProposalLis
List<Proposal> tempProposals = proposalService.getTempProposals(); List<Proposal> tempProposals = proposalService.getTempProposals();
Set<Proposal> verifiedProposals = proposalService.getProposalPayloads().stream() Set<Proposal> verifiedProposals = proposalService.getProposalPayloads().stream()
.map(ProposalPayload::getProposal) .map(ProposalPayload::getProposal)
.filter(proposal -> validatorProvider.getValidator(proposal).isValidAndConfirmed(proposal)) .filter(proposal -> !daoStateService.isParseBlockChainComplete() ||
validatorProvider.getValidator(proposal).isValidAndConfirmed(proposal))
.collect(Collectors.toSet()); .collect(Collectors.toSet());
Set<Proposal> set = new HashSet<>(tempProposals); Set<Proposal> set = new HashSet<>(tempProposals);
set.addAll(verifiedProposals); set.addAll(verifiedProposals);

View File

@ -248,15 +248,18 @@ public class ProposalService implements HashMapChangedListener, AppendOnlyDataSt
if (periodService.isInPhase(daoStateService.getChainHeight(), DaoPhase.Phase.PROPOSAL) || if (periodService.isInPhase(daoStateService.getChainHeight(), DaoPhase.Phase.PROPOSAL) ||
periodService.isInPhase(daoStateService.getChainHeight(), DaoPhase.Phase.BREAK1)) { periodService.isInPhase(daoStateService.getChainHeight(), DaoPhase.Phase.BREAK1)) {
if (!tempProposals.contains(proposal)) { 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) { if (fromBroadcastMessage) {
log.info("We received a TempProposalPayload and store it to our protectedStoreList. proposalTxId={}", log.info("We received a TempProposalPayload and store it to our protectedStoreList. proposalTxId={}",
proposal.getTxId()); proposal.getTxId());
} }
tempProposals.add(proposal); tempProposals.add(proposal);
} else { } else {
log.debug("We received an invalid proposal from the P2P network. Proposal.txId={}, blockHeight={}", log.debug("We received an invalid proposal from the P2P network. Proposal={}, blockHeight={}",
proposal.getTxId(), daoStateService.getChainHeight()); proposal, daoStateService.getChainHeight());
} }
} }
} }
@ -298,7 +301,11 @@ public class ProposalService implements HashMapChangedListener, AppendOnlyDataSt
// We don't validate phase and cycle as we might receive proposals from other cycles or phases at startup. // 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 // 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. // 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) { if (fromBroadcastMessage) {
log.info("We received a ProposalPayload and store it to our appendOnlyStoreList. proposalTxId={}", log.info("We received a ProposalPayload and store it to our appendOnlyStoreList. proposalTxId={}",
proposal.getTxId()); proposal.getTxId());
@ -306,8 +313,8 @@ public class ProposalService implements HashMapChangedListener, AppendOnlyDataSt
proposalPayloads.add(proposalPayload); proposalPayloads.add(proposalPayload);
} else { } else {
log.warn("We received a invalid append-only proposal from the P2P network. " + log.warn("We received a invalid append-only proposal from the P2P network. " +
"Proposal.txId={}, blockHeight={}", "Proposal={}, blockHeight={}",
proposal.getTxId(), daoStateService.getChainHeight()); proposal, daoStateService.getChainHeight());
} }
} }
} }

View File

@ -200,11 +200,12 @@ public class LiteNode extends BsqNode {
runDelayedBatchProcessing(new ArrayList<>(blockList), runDelayedBatchProcessing(new ArrayList<>(blockList),
() -> { () -> {
log.info("Parsing {} blocks took {} seconds.", blockList.size(), (System.currentTimeMillis() - ts) / 1000d); 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()); liteNodeNetworkService.requestBlocks(getStartBlockHeight());
else } else {
onParsingComplete.run(); onParsingComplete.run();
onParseBlockChainComplete(); onParseBlockChainComplete();
}
}); });
} }