Skip to content

Commit

Permalink
Merge pull request #2329 from ManfredKarrer/dao-fix-snapshot-issue
Browse files Browse the repository at this point in the history
Dao fix snapshot issue
  • Loading branch information
ManfredKarrer authored Jan 29, 2019
2 parents de80b25 + a52fff1 commit b087b95
Show file tree
Hide file tree
Showing 25 changed files with 23 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public void onNewBlockHeight(int blockHeight) {
}

@Override
public void onParseTxsComplete(Block block) {
public void onParseTxsCompleteAfterBatchProcessing(Block block) {
if (isWalletReady())
updateBsqWalletTransactions();
}
Expand Down
5 changes: 0 additions & 5 deletions core/src/main/java/bisq/core/dao/DaoFacade.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
import bisq.core.dao.state.DaoStateListener;
import bisq.core.dao.state.DaoStateService;
import bisq.core.dao.state.DaoStateStorageService;
import bisq.core.dao.state.model.blockchain.Block;
import bisq.core.dao.state.model.blockchain.Tx;
import bisq.core.dao.state.model.blockchain.TxOutput;
import bisq.core.dao.state.model.blockchain.TxOutputKey;
Expand Down Expand Up @@ -188,10 +187,6 @@ public void onNewBlockHeight(int blockHeight) {
periodService.getCurrentCycle().getPhaseForHeight(blockHeight).ifPresent(phaseProperty::set);
}

@Override
public void onParseTxsComplete(Block block) {
}

@Override
public void onParseBlockChainComplete() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ public void onNewBlockHeight(int blockHeight) {
}

@Override
public void onParseTxsComplete(Block block) {
public void onParseTxsCompleteAfterBatchProcessing(Block block) {
int chainHeight = daoStateService.getChainHeight();
bsqFeePerDay = daoStateService.getParamValueAsCoin(Param.ASSET_LISTING_FEE_PER_DAY, chainHeight).value;
minVolumeInBtc = daoStateService.getParamValueAsCoin(Param.ASSET_MIN_VOLUME, chainHeight).value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public void onNewBlockHeight(int blockHeight) {
}

@Override
public void onParseTxsComplete(Block block) {
public void onParseTxsCompleteAfterBatchProcessing(Block block) {
onListChanged(ballotListService.getValidatedBallotList());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import bisq.core.dao.governance.blindvote.storage.BlindVoteStorageService;
import bisq.core.dao.state.DaoStateListener;
import bisq.core.dao.state.DaoStateService;
import bisq.core.dao.state.model.blockchain.Block;

import bisq.network.p2p.P2PService;
import bisq.network.p2p.storage.payload.PersistableNetworkPayload;
Expand Down Expand Up @@ -98,10 +97,6 @@ public void start() {
public void onNewBlockHeight(int blockHeight) {
}

@Override
public void onParseTxsComplete(Block block) {
}

@Override
public void onParseBlockChainComplete() {
fillListFromAppendOnlyDataStore();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import bisq.core.dao.governance.proposal.MyProposalListService;
import bisq.core.dao.state.DaoStateListener;
import bisq.core.dao.state.DaoStateService;
import bisq.core.dao.state.model.blockchain.Block;
import bisq.core.dao.state.model.governance.BallotList;
import bisq.core.dao.state.model.governance.CompensationProposal;
import bisq.core.dao.state.model.governance.DaoPhase;
Expand Down Expand Up @@ -176,10 +175,6 @@ public void readPersisted() {
public void onNewBlockHeight(int blockHeight) {
}

@Override
public void onParseTxsComplete(Block block) {
}

@Override
public void onParseBlockChainComplete() {
rePublishOnceWellConnected();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public void onNewBlockHeight(int blockHeight) {
}

@Override
public void onParseTxsComplete(Block block) {
public void onParseTxsCompleteAfterBatchProcessing(Block block) {
update();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public void onNewBlockHeight(int blockHeight) {
}

@Override
public void onParseTxsComplete(Block block) {
public void onParseTxsCompleteAfterBatchProcessing(Block block) {
update();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import bisq.core.dao.state.DaoStateListener;
import bisq.core.dao.state.DaoStateService;
import bisq.core.dao.state.GenesisTxInfo;
import bisq.core.dao.state.model.blockchain.Block;
import bisq.core.dao.state.model.governance.Cycle;
import bisq.core.dao.state.model.governance.DaoPhase;

Expand Down Expand Up @@ -83,10 +82,6 @@ public void onNewBlockHeight(int blockHeight) {
.ifPresent(daoStateService.getCycles()::add);
}

@Override
public void onParseTxsComplete(Block block) {
}

@Override
public void onParseBlockChainComplete() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public void onNewBlockHeight(int blockHeight) {
}

@Override
public void onParseTxsComplete(Block block) {
public void onParseTxsCompleteAfterBatchProcessing(Block block) {
updateList();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import bisq.core.dao.governance.proposal.storage.temp.TempProposalPayload;
import bisq.core.dao.state.DaoStateListener;
import bisq.core.dao.state.DaoStateService;
import bisq.core.dao.state.model.blockchain.Block;
import bisq.core.dao.state.model.blockchain.Tx;
import bisq.core.dao.state.model.governance.DaoPhase;
import bisq.core.dao.state.model.governance.Proposal;
Expand Down Expand Up @@ -125,10 +124,6 @@ public void readPersisted() {
public void onNewBlockHeight(int blockHeight) {
}

@Override
public void onParseTxsComplete(Block block) {
}

@Override
public void onParseBlockChainComplete() {
rePublishOnceWellConnected();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public void onNewBlockHeight(int blockHeight) {
}

@Override
public void onParseTxsComplete(Block block) {
public void onParseTxsCompleteAfterBatchProcessing(Block block) {
updateLists();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public void onNewBlockHeight(int blockHeight) {
}

@Override
public void onParseTxsComplete(Block block) {
public void onParseTxsCompleteAfterBatchProcessing(Block block) {
int heightForRepublishing = periodService.getFirstBlockOfPhase(daoStateService.getChainHeight(), DaoPhase.Phase.BREAK1);
if (block.getHeight() == heightForRepublishing) {
// We only republish if we are completed with parsing old blocks, otherwise we would republish old
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import bisq.core.dao.governance.votereveal.VoteRevealService;
import bisq.core.dao.state.DaoStateListener;
import bisq.core.dao.state.DaoStateService;
import bisq.core.dao.state.model.blockchain.Block;
import bisq.core.dao.state.model.blockchain.Tx;
import bisq.core.dao.state.model.blockchain.TxOutput;
import bisq.core.dao.state.model.governance.Ballot;
Expand Down Expand Up @@ -155,10 +154,6 @@ public void onNewBlockHeight(int blockHeight) {
maybeCalculateVoteResult(blockHeight);
}

@Override
public void onParseTxsComplete(Block block) {
}

@Override
public void onParseBlockChainComplete() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import bisq.core.dao.node.BsqNodeProvider;
import bisq.core.dao.state.DaoStateListener;
import bisq.core.dao.state.DaoStateService;
import bisq.core.dao.state.model.blockchain.Block;
import bisq.core.dao.state.model.blockchain.TxOutput;
import bisq.core.dao.state.model.governance.DaoPhase;

Expand Down Expand Up @@ -157,10 +156,6 @@ public void onNewBlockHeight(int blockHeight) {
maybeRevealVotes();
}

@Override
public void onParseTxsComplete(Block block) {
}

@Override
public void onParseBlockChainComplete() {
}
Expand Down
8 changes: 4 additions & 4 deletions core/src/main/java/bisq/core/dao/state/DaoStateListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
public interface DaoStateListener {
void onNewBlockHeight(int blockHeight);

void onParseTxsComplete(Block block);

void onParseBlockChainComplete();

// Never used but we still want to provide the event
default void onEmptyBlockAdded(Block block) {
default void onParseTxsCompleteAfterBatchProcessing(Block block) {
}

default void onParseTxsComplete(Block block) {
}
}
8 changes: 5 additions & 3 deletions core/src/main/java/bisq/core/dao/state/DaoStateService.java
Original file line number Diff line number Diff line change
Expand Up @@ -200,17 +200,19 @@ public void onNewBlockWithEmptyTxs(Block block) {
"That might happen in edge cases at reorgs.");
} else {
daoState.getBlocks().add(block);
daoStateListeners.forEach(l -> l.onEmptyBlockAdded(block));

log.info("New Block added at blockHeight " + block.getHeight());
}
}

// Third we get the onParseBlockComplete called after all rawTxs of blocks have been parsed
public void onParseBlockComplete(Block block) {
// We don't call it during batch parsing as that decreased performance a lot.
// With calling at each block we got about 50 seconds for 4000 blocks, without about 4 seconds.
// We use 2 different handlers as we don't want to update domain listeners during batch processing of all
// blocks as that cause performance issues. In earlier versions when we updated at each block it took
// 50 sec. for 4000 blocks, after that change it was about 4 sec.
if (parseBlockChainComplete)
daoStateListeners.forEach(l -> l.onParseTxsCompleteAfterBatchProcessing(block));
else
daoStateListeners.forEach(l -> l.onParseTxsComplete(block));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
*/
@Slf4j
public class DaoStateSnapshotService implements DaoStateListener {
private static final int SNAPSHOT_GRID = 10;
private static final int SNAPSHOT_GRID = 20;

private final DaoStateService daoStateService;
private final GenesisTxInfo genesisTxInfo;
Expand Down Expand Up @@ -74,6 +74,8 @@ public DaoStateSnapshotService(DaoStateService daoStateService,
public void onNewBlockHeight(int blockHeight) {
}

// We listen to each ParseTxsComplete event even if the batch processing of all blocks at startup is not completed
// as we need to write snapshots during that batch processing.
@Override
public void onParseTxsComplete(Block block) {
int chainHeight = block.getHeight();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

import bisq.core.dao.DaoFacade;
import bisq.core.dao.state.DaoStateListener;
import bisq.core.dao.state.model.blockchain.Block;
import bisq.core.dao.state.model.governance.DaoPhase;
import bisq.core.locale.Res;

Expand Down Expand Up @@ -96,10 +95,6 @@ public void onNewBlockHeight(int height) {
applyData(height);
}

@Override
public void onParseTxsComplete(Block block) {
}

@Override
public void onParseBlockChainComplete() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

import bisq.core.dao.DaoFacade;
import bisq.core.dao.state.DaoStateListener;
import bisq.core.dao.state.model.blockchain.Block;
import bisq.core.dao.state.model.governance.DaoPhase;
import bisq.core.locale.Res;
import bisq.core.util.BSFormatter;
Expand Down Expand Up @@ -111,10 +110,6 @@ public void onNewBlockHeight(int height) {
applyData(height);
}

@Override
public void onParseTxsComplete(Block block) {
}

@Override
public void onParseBlockChainComplete() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import bisq.core.dao.governance.proposal.TxException;
import bisq.core.dao.governance.proposal.param.ChangeParamValidator;
import bisq.core.dao.state.DaoStateListener;
import bisq.core.dao.state.model.blockchain.Block;
import bisq.core.dao.state.model.governance.DaoPhase;
import bisq.core.dao.state.model.governance.Proposal;
import bisq.core.dao.state.model.governance.Role;
Expand Down Expand Up @@ -188,10 +187,6 @@ public void onNewBlockHeight(int height) {
proposalTypeComboBox.getSelectionModel().clearSelection();
}

@Override
public void onParseTxsComplete(Block block) {
}

@Override
public void onParseBlockChainComplete() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ public void onNewBlockHeight(int blockHeight) {
}

@Override
public void onParseTxsComplete(Block block) {
public void onParseTxsCompleteAfterBatchProcessing(Block block) {
updateViews();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,6 @@ public void onNewBlockHeight(int height) {
fillCycleList();
}

@Override
public void onParseTxsComplete(Block block) {
}

@Override
public void onParseBlockChainComplete() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public void onNewBlockHeight(int blockHeight) {
}

@Override
public void onParseTxsComplete(Block block) {
public void onParseTxsCompleteAfterBatchProcessing(Block block) {
updateWithBsqBlockChainData();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ public void onNewBlockHeight(int blockHeight) {
}

@Override
public void onParseTxsComplete(Block block) {
public void onParseTxsCompleteAfterBatchProcessing(Block block) {
onUpdateAnyChainHeight();
}

Expand Down

0 comments on commit b087b95

Please sign in to comment.