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

Dao performance improvements #5010

Merged
merged 4 commits into from
Dec 28, 2020
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
2 changes: 1 addition & 1 deletion core/src/main/java/bisq/core/dao/DaoFacade.java
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ public Coin getGenesisTotalSupply() {
}

public int getNumIssuanceTransactions(IssuanceType issuanceType) {
return daoStateService.getIssuanceSet(issuanceType).size();
return daoStateService.getIssuanceSetForType(issuanceType).size();
}

public Set<Tx> getBurntFeeTxs() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ public MeritList getMerits(@Nullable String blindVoteTxId) {
.filter(txId -> periodService.isTxInPastCycle(txId, periodService.getChainHeight()))
.collect(Collectors.toSet());

return new MeritList(daoStateService.getIssuanceSet(IssuanceType.COMPENSATION).stream()
return new MeritList(daoStateService.getIssuanceSetForType(IssuanceType.COMPENSATION).stream()
.map(issuance -> {
checkArgument(issuance.getIssuanceType() == IssuanceType.COMPENSATION,
"IssuanceType must be COMPENSATION for MeritList");
Expand Down
11 changes: 3 additions & 8 deletions core/src/main/java/bisq/core/dao/state/DaoStateService.java
Original file line number Diff line number Diff line change
Expand Up @@ -597,23 +597,18 @@ public void addIssuance(Issuance issuance) {
daoState.getIssuanceMap().put(issuance.getTxId(), issuance);
}

public Set<Issuance> getIssuanceSet(IssuanceType issuanceType) {
public Set<Issuance> getIssuanceSetForType(IssuanceType issuanceType) {
return daoState.getIssuanceMap().values().stream()
.filter(issuance -> issuance.getIssuanceType() == issuanceType)
.collect(Collectors.toSet());
}

public Optional<Issuance> getIssuance(String txId, IssuanceType issuanceType) {
return daoState.getIssuanceMap().values().stream()
.filter(issuance -> issuance.getTxId().equals(txId))
.filter(issuance -> issuance.getIssuanceType() == issuanceType)
.findAny();
return getIssuance(txId).filter(issuance -> issuance.getIssuanceType() == issuanceType);
}

public Optional<Issuance> getIssuance(String txId) {
return daoState.getIssuanceMap().values().stream()
.filter(issuance -> issuance.getTxId().equals(txId))
.findAny();
return Optional.ofNullable(daoState.getIssuanceMap().get(txId));
}

public boolean isIssuanceTx(String txId) {
Expand Down
2 changes: 2 additions & 0 deletions core/src/main/java/bisq/core/dao/state/model/DaoState.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ public static DaoState getClone(DaoState daoState) {
private final LinkedList<Cycle> cycles;

// These maps represent mutual data which can get changed at parsing a transaction
// We use TreeMaps instead of HashMaps because we need deterministic sorting of the maps for the hashChains
// used for the DAO monitor.
@Getter
private final TreeMap<TxOutputKey, TxOutput> unspentTxOutputMap;
@Getter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@

import javafx.util.StringConverter;

import java.text.DecimalFormat;

import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
Expand All @@ -73,6 +71,8 @@
import java.time.temporal.TemporalAdjuster;
import java.time.temporal.TemporalAdjusters;

import java.text.DecimalFormat;

import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
Expand Down Expand Up @@ -630,10 +630,10 @@ private List<Number> updateBSQIssuedMonthly() {
.toLocalDate()
.with(ADJUSTERS.get(MONTH)));

Stream<Issuance> bsqByCompensation = daoStateService.getIssuanceSet(IssuanceType.COMPENSATION).stream()
Stream<Issuance> bsqByCompensation = daoStateService.getIssuanceSetForType(IssuanceType.COMPENSATION).stream()
.sorted(Comparator.comparing(Issuance::getChainHeight));

Stream<Issuance> bsqByReimbursement = daoStateService.getIssuanceSet(IssuanceType.REIMBURSEMENT).stream()
Stream<Issuance> bsqByReimbursement = daoStateService.getIssuanceSetForType(IssuanceType.REIMBURSEMENT).stream()
.sorted(Comparator.comparing(Issuance::getChainHeight));

Map<LocalDate, List<Issuance>> bsqAddedByVote = Stream.concat(bsqByCompensation, bsqByReimbursement)
Expand Down