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

Speed up "Synchronizing DAO" by ~30% #5484

Merged
merged 7 commits into from May 17, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -294,7 +294,7 @@ public List<Block> getBlocks() {
* {@code false}.
*/
public boolean isBlockHashKnown(String blockHash) {
return daoState.getBlocksByHash().contains(blockHash);
return daoState.getBlockHashes().contains(blockHash);
}

public Optional<Block> getLastBlock() {
Expand Down
12 changes: 6 additions & 6 deletions core/src/main/java/bisq/core/dao/state/model/DaoState.java
Expand Up @@ -113,7 +113,7 @@ public static DaoState getClone(DaoState daoState) {
@JsonExclude
private transient final Map<Integer, Block> blocksByHeight; // Blocks indexed by height
@JsonExclude
private transient final Set<String> blocksByHash; // Blocks indexed by hash
private transient final Set<String> blockHashes; // Cache of known block hashes

///////////////////////////////////////////////////////////////////////////////////////////
// Constructor
Expand Down Expand Up @@ -166,7 +166,7 @@ private DaoState(int chainHeight,
.flatMap(block -> block.getTxs().stream())
.collect(Collectors.toMap(Tx::getId, Function.identity(), (x, y) -> x, HashMap::new));

blocksByHash = blocks.stream()
blockHashes = blocks.stream()
.map(Block::getHash)
.collect(Collectors.toSet());

Expand Down Expand Up @@ -266,8 +266,8 @@ public Map<String, Tx> getTxCache() {
return Collections.unmodifiableMap(txCache);
}

public Set<String> getBlocksByHash() {
return Collections.unmodifiableSet(blocksByHash);
public Set<String> getBlockHashes() {
return Collections.unmodifiableSet(blockHashes);
}

public Map<Integer, Block> getBlocksByHeight() {
Expand Down Expand Up @@ -295,7 +295,7 @@ public Block getLastBlock() {

public void addBlock(Block block) {
blocks.add(block);
blocksByHash.add(block.getHash());
blockHashes.add(block.getHash());
blocksByHeight.put(block.getHeight(), block);
}

Expand All @@ -310,7 +310,7 @@ public void addBlocks(List<Block> newBlocks) {
public void clearAndSetBlocks(List<Block> newBlocks) {
blocks.clear();
blocksByHeight.clear();
blocksByHash.clear();
blockHashes.clear();

addBlocks(newBlocks);
}
Expand Down