-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Add transient tx map to DaoState to speed up getTx queries #3773
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,11 +45,12 @@ | |
import com.google.common.base.Preconditions; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.Collections; | ||
import java.util.Comparator; | ||
import java.util.HashSet; | ||
import java.util.LinkedList; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.Set; | ||
import java.util.TreeMap; | ||
|
@@ -363,24 +364,24 @@ public Stream<Tx> getTxStream() { | |
.flatMap(block -> block.getTxs().stream()); | ||
} | ||
|
||
public Map<String, Tx> getTxMap() { | ||
return daoState.getTxMap(); | ||
private Stream<Tx> getUnorderedTxStream() { | ||
return getTxs().stream(); | ||
} | ||
|
||
public Set<Tx> getTxs() { | ||
return new HashSet<>(getTxMap().values()); | ||
} | ||
|
||
public Optional<Tx> getTx(String txId) { | ||
return Optional.ofNullable(getTxMap().get(txId)); | ||
public Collection<Tx> getTxs() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This method is only called by DaoFacade where the client is only interested in the size, so I would suggest to add a new |
||
return Collections.unmodifiableCollection(daoState.getTxMap().values()); | ||
} | ||
|
||
public List<Tx> getInvalidTxs() { | ||
return getTxStream().filter(tx -> tx.getTxType() == TxType.INVALID).collect(Collectors.toList()); | ||
return getUnorderedTxStream().filter(tx -> tx.getTxType() == TxType.INVALID).collect(Collectors.toList()); | ||
} | ||
|
||
public List<Tx> getIrregularTxs() { | ||
return getTxStream().filter(tx -> tx.getTxType() == TxType.IRREGULAR).collect(Collectors.toList()); | ||
return getUnorderedTxStream().filter(tx -> tx.getTxType() == TxType.IRREGULAR).collect(Collectors.toList()); | ||
} | ||
|
||
public Optional<Tx> getTx(String txId) { | ||
return Optional.ofNullable(daoState.getTxMap().get(txId)); | ||
} | ||
|
||
public boolean containsTx(String txId) { | ||
|
@@ -410,11 +411,11 @@ public boolean hasTxBurntFee(String txId) { | |
} | ||
|
||
public long getTotalBurntFee() { | ||
return getTxStream().mapToLong(Tx::getBurntFee).sum(); | ||
return getUnorderedTxStream().mapToLong(Tx::getBurntFee).sum(); | ||
} | ||
|
||
public Set<Tx> getBurntFeeTxs() { | ||
return getTxStream() | ||
return getUnorderedTxStream() | ||
.filter(tx -> tx.getBurntFee() > 0) | ||
.collect(Collectors.toSet()); | ||
} | ||
|
@@ -433,17 +434,17 @@ public Optional<TxOutput> getConnectedTxOutput(TxInput txInput) { | |
// TxOutput | ||
/////////////////////////////////////////////////////////////////////////////////////////// | ||
|
||
public Stream<TxOutput> getTxOutputStream() { | ||
return getTxStream() | ||
private Stream<TxOutput> getUnorderedTxOutputStream() { | ||
return getUnorderedTxStream() | ||
.flatMap(tx -> tx.getTxOutputs().stream()); | ||
} | ||
|
||
public boolean existsTxOutput(TxOutputKey key) { | ||
return getTxOutputStream().anyMatch(txOutput -> txOutput.getKey().equals(key)); | ||
return getUnorderedTxOutputStream().anyMatch(txOutput -> txOutput.getKey().equals(key)); | ||
} | ||
|
||
public Optional<TxOutput> getTxOutput(TxOutputKey txOutputKey) { | ||
return getTxOutputStream() | ||
return getUnorderedTxOutputStream() | ||
.filter(txOutput -> txOutput.getKey().equals(txOutputKey)) | ||
.findAny(); | ||
} | ||
|
@@ -528,8 +529,8 @@ public boolean isTxOutputSpendable(TxOutputKey key) { | |
// TxOutputType | ||
/////////////////////////////////////////////////////////////////////////////////////////// | ||
|
||
public Set<TxOutput> getTxOutputsByTxOutputType(TxOutputType txOutputType) { | ||
return getTxOutputStream() | ||
private Set<TxOutput> getTxOutputsByTxOutputType(TxOutputType txOutputType) { | ||
return getUnorderedTxOutputStream() | ||
.filter(txOutput -> txOutput.getTxOutputType() == txOutputType) | ||
.collect(Collectors.toSet()); | ||
} | ||
|
@@ -838,12 +839,12 @@ public long getTotalAmountOfConfiscatedTxOutputs() { | |
} | ||
|
||
public long getTotalAmountOfInvalidatedBsq() { | ||
return getTxStream().mapToLong(Tx::getInvalidatedBsq).sum(); | ||
return getUnorderedTxStream().mapToLong(Tx::getInvalidatedBsq).sum(); | ||
} | ||
|
||
// Contains burnt fee and invalidated bsq due invalid txs | ||
public long getTotalAmountOfBurntBsq() { | ||
return getTxStream().mapToLong(Tx::getBurntBsq).sum(); | ||
return getUnorderedTxStream().mapToLong(Tx::getBurntBsq).sum(); | ||
} | ||
|
||
// Confiscate bond | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As the client only is interested in the number of txs, I think we should change that to a method only returning the size. This will further render the getTxs() method in daoStateService needless.