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

Improve data structure, validation and performance #2556

Merged
merged 55 commits into from Mar 23, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
2baced1
Only log if hashchain has been updated
ManfredKarrer Mar 18, 2019
45185d3
Fix incorrect maybeUpdateHashChain call
ManfredKarrer Mar 18, 2019
1160986
Add dao-testnet explorer, update testnet url
ManfredKarrer Mar 18, 2019
7748366
Add UNDEFINED enum entry to all dao enums to allow updates
ManfredKarrer Mar 18, 2019
b66c23f
Log time needed for rpc getBlock call
ManfredKarrer Mar 18, 2019
0198bf4
Merge branch 'master' into misc-dao-improvements
ManfredKarrer Mar 18, 2019
c961477
Add comment
ManfredKarrer Mar 18, 2019
4119113
Adjust THRESHOLD_CHANGE_PARAM and THRESHOLD_CONFISCATION
ManfredKarrer Mar 18, 2019
f411a16
Rename PRICE_NODE_OPERATOR to DATA_RELAY_NODE_OPERATOR
ManfredKarrer Mar 18, 2019
16d1b77
Add BTC_DONATION_ADDRESS_OWNER
ManfredKarrer Mar 18, 2019
d8e226e
Add BTC_DONATION_ADDRESS_OWNER translation string
ManfredKarrer Mar 18, 2019
c8b0e88
Fix incorrect maxIncrease value
ManfredKarrer Mar 18, 2019
3d5e109
Rename getMiningFeeAndTxSize to getBlindVoteMiningFeeAndTxSize
ManfredKarrer Mar 18, 2019
d86aa28
Make ARBITRATOR_FEE % based, Add more validations
ManfredKarrer Mar 18, 2019
3dc9939
Refactor ChangeParamValidator
ManfredKarrer Mar 19, 2019
d02609a
Refactor: Rename ValidationException to ProposalValidationException
ManfredKarrer Mar 19, 2019
dbf3eba
Use ProposalValidatorProvider to operate on concrete ProposalValidator
ManfredKarrer Mar 19, 2019
ff5d18a
Use block height of proposal tx if available
ManfredKarrer Mar 19, 2019
e673d6c
Merge branch 'master' into misc-dao-improvements
ManfredKarrer Mar 19, 2019
bf474a3
Change blind vote phase and vote reveal durations
ManfredKarrer Mar 19, 2019
aa8dc29
Change min/max factor for phase durations from 3 to 2
ManfredKarrer Mar 19, 2019
4157ce1
Increase bond for youtube operator
ManfredKarrer Mar 19, 2019
729d59b
Add 3 new roles, adjust bond amount
ManfredKarrer Mar 19, 2019
a47ba42
Fix comments
ManfredKarrer Mar 20, 2019
7eb414a
Change bond lock time from 60 days to 75 days
ManfredKarrer Mar 20, 2019
ac3374c
Remove requiredQuorum and requiredThreshold from EvaluatedProposal
ManfredKarrer Mar 20, 2019
3aa50a3
Store requiredBond and unlockTime in RoleProposal
ManfredKarrer Mar 20, 2019
13ca802
Add extraDataMap to BlindVote and Proposal
ManfredKarrer Mar 20, 2019
fb3ca06
Add ConsensusCritical to proposal validators
ManfredKarrer Mar 20, 2019
eb2975a
Dont' call updateBsqBalance while batch processing
ManfredKarrer Mar 20, 2019
2a23896
Change log levels, improve logging
ManfredKarrer Mar 20, 2019
c732ce8
Rename db file to enforce usage of new file with new data structure
ManfredKarrer Mar 20, 2019
f780cf5
Add SHA3-256 hash function
ManfredKarrer Mar 21, 2019
735f619
Stream block batch processing on render frames
ManfredKarrer Mar 21, 2019
28c9367
Fix logging
ManfredKarrer Mar 21, 2019
e371fd4
Use ParamValidationException instead of AddressFormatException
ManfredKarrer Mar 21, 2019
81f4dd6
Add UNDEFINED entries
ManfredKarrer Mar 21, 2019
7651a94
Support exportToJson also for lite node
ManfredKarrer Mar 21, 2019
6d5b404
Remove SHA3-256 hash as it turned out it is slower as SHA256
ManfredKarrer Mar 21, 2019
c9ff5f7
Misc cleanups and refactorings
ManfredKarrer Mar 21, 2019
46f5b15
Update json export for vote results
ManfredKarrer Mar 21, 2019
7e61afc
Add BONDED_ROLE_FACTOR to param to react on BSQ price changes
ManfredKarrer Mar 22, 2019
92fdca2
Cleanup TODOs
ManfredKarrer Mar 22, 2019
49a0076
Don't support spending of pending BTC utxos in the BSQ wallet.
ManfredKarrer Mar 22, 2019
61a3be3
Remove nonBsqTxOutputMap from daoState
ManfredKarrer Mar 22, 2019
2ad86ab
Apply code inspection, cleanup
ManfredKarrer Mar 22, 2019
7b61429
Fix string
ManfredKarrer Mar 22, 2019
a9ef339
Merge branch 'master' into misc-dao-improvements
ManfredKarrer Mar 22, 2019
b20cb39
Update db files
ManfredKarrer Mar 22, 2019
f36678e
Add phaseChangeListener only after batch processing
ManfredKarrer Mar 22, 2019
68894ea
Update db files
ManfredKarrer Mar 22, 2019
954c5af
Use translation strings and show min/max values at change param valid…
ManfredKarrer Mar 22, 2019
26fd61d
Fix tests
ManfredKarrer Mar 22, 2019
43155b8
Fix % display
ManfredKarrer Mar 23, 2019
eb8feec
Add missing @EqualsAndHashCode(exclude = {"date"})
ManfredKarrer Mar 23, 2019
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 @@ -19,6 +19,7 @@

import bisq.core.dao.governance.period.PeriodService;
import bisq.core.dao.state.DaoStateService;
import bisq.core.dao.state.model.blockchain.BaseTx;
import bisq.core.dao.state.model.blockchain.Tx;
import bisq.core.dao.state.model.blockchain.TxType;
import bisq.core.dao.state.model.governance.CompensationProposal;
Expand Down Expand Up @@ -135,4 +136,12 @@ private boolean isValid(Proposal proposal, boolean allowUnconfirmed) {
return false;
}
}

protected Integer getBlockHeight(Proposal proposal) {
// When we receive a temp proposal the tx is usually not confirmed so we cannot lookup the block height of
// the tx. We take the current block height in that case as it would be in the same cycle anyway.
return daoStateService.getTx(proposal.getTxId())
.map(BaseTx::getBlockHeight)
.orElseGet(daoStateService::getChainHeight);
}
}
Expand Up @@ -24,14 +24,7 @@
import bisq.core.dao.governance.proposal.reimbursement.ReimbursementValidator;
import bisq.core.dao.governance.proposal.removeAsset.RemoveAssetValidator;
import bisq.core.dao.governance.proposal.role.RoleValidator;
import bisq.core.dao.state.model.governance.ChangeParamProposal;
import bisq.core.dao.state.model.governance.CompensationProposal;
import bisq.core.dao.state.model.governance.ConfiscateBondProposal;
import bisq.core.dao.state.model.governance.GenericProposal;
import bisq.core.dao.state.model.governance.Proposal;
import bisq.core.dao.state.model.governance.ReimbursementProposal;
import bisq.core.dao.state.model.governance.RemoveAssetProposal;
import bisq.core.dao.state.model.governance.RoleProposal;

import javax.inject.Inject;

Expand Down Expand Up @@ -65,21 +58,26 @@ public ProposalValidatorProvider(CompensationValidator compensationValidator,
}

public ProposalValidator getValidator(Proposal proposal) {
if (proposal instanceof CompensationProposal)
return compensationValidator;
else if (proposal instanceof ConfiscateBondProposal)
return confiscateBondValidator;
else if (proposal instanceof GenericProposal)
return genericProposalValidator;
else if (proposal instanceof ChangeParamProposal)
return changeParamValidator;
else if (proposal instanceof ReimbursementProposal)
return reimbursementValidator;
else if (proposal instanceof RemoveAssetProposal)
return removeAssetValidator;
else if (proposal instanceof RoleProposal)
return roleValidator;
else
throw new RuntimeException("");
return getValidator(proposal.getType());
}

public ProposalValidator getValidator(ProposalType proposalType) {
switch (proposalType) {
case COMPENSATION_REQUEST:
return compensationValidator;
case REIMBURSEMENT_REQUEST:
return reimbursementValidator;
case CHANGE_PARAM:
return changeParamValidator;
case BONDED_ROLE:
return roleValidator;
case CONFISCATE_BOND:
return confiscateBondValidator;
case GENERIC:
return genericProposalValidator;
case REMOVE_ASSET:
return removeAssetValidator;
}
throw new RuntimeException("Proposal type " + proposalType.name() + " was not covered by switch case.");
}
}
Expand Up @@ -17,8 +17,8 @@

package bisq.core.dao.governance.proposal.compensation;

import bisq.core.dao.governance.proposal.ProposalValidationException;
import bisq.core.dao.governance.period.PeriodService;
import bisq.core.dao.governance.proposal.ProposalValidationException;
import bisq.core.dao.governance.proposal.ProposalValidator;
import bisq.core.dao.state.DaoStateService;
import bisq.core.dao.state.model.governance.CompensationProposal;
Expand Down Expand Up @@ -53,13 +53,15 @@ public void validateDataFields(Proposal proposal) throws ProposalValidationExcep
compensationProposal.getAddress(); // throws AddressFormatException if wrong address

Coin requestedBsq = compensationProposal.getRequestedBsq();
Coin maxCompensationRequestAmount = CompensationConsensus.getMaxCompensationRequestAmount(daoStateService, periodService.getChainHeight());
int chainHeight = getBlockHeight(proposal);
Coin maxCompensationRequestAmount = CompensationConsensus.getMaxCompensationRequestAmount(daoStateService, chainHeight);
checkArgument(requestedBsq.compareTo(maxCompensationRequestAmount) <= 0,
"Requested BSQ must not exceed " + (maxCompensationRequestAmount.value / 100L) + " BSQ");
Coin minCompensationRequestAmount = CompensationConsensus.getMinCompensationRequestAmount(daoStateService, periodService.getChainHeight());
Coin minCompensationRequestAmount = CompensationConsensus.getMinCompensationRequestAmount(daoStateService, chainHeight);
checkArgument(requestedBsq.compareTo(minCompensationRequestAmount) >= 0,
"Requested BSQ must not be less than " + (minCompensationRequestAmount.value / 100L) + " BSQ");

} catch (ProposalValidationException e) {
throw e;
} catch (Throwable throwable) {
throw new ProposalValidationException(throwable);
}
Expand Down
Expand Up @@ -17,8 +17,8 @@

package bisq.core.dao.governance.proposal.confiscatebond;

import bisq.core.dao.governance.proposal.ProposalValidationException;
import bisq.core.dao.governance.period.PeriodService;
import bisq.core.dao.governance.proposal.ProposalValidationException;
import bisq.core.dao.governance.proposal.ProposalValidator;
import bisq.core.dao.state.DaoStateService;
import bisq.core.dao.state.model.governance.ConfiscateBondProposal;
Expand All @@ -28,6 +28,8 @@

import lombok.extern.slf4j.Slf4j;

import static org.apache.commons.lang3.Validate.notEmpty;

@Slf4j
public class ConfiscateBondValidator extends ProposalValidator {

Expand All @@ -40,9 +42,10 @@ public ConfiscateBondValidator(DaoStateService daoStateService, PeriodService pe
public void validateDataFields(Proposal proposal) throws ProposalValidationException {
try {
super.validateDataFields(proposal);

ConfiscateBondProposal confiscateBondProposal = (ConfiscateBondProposal) proposal;
//TODO
notEmpty(confiscateBondProposal.getLockupTxId(), "LockupTxId must not be empty");
} catch (ProposalValidationException e) {
throw e;
} catch (Throwable throwable) {
throw new ProposalValidationException(throwable);
}
Expand Down
Expand Up @@ -17,11 +17,10 @@

package bisq.core.dao.governance.proposal.generic;

import bisq.core.dao.governance.proposal.ProposalValidationException;
import bisq.core.dao.governance.period.PeriodService;
import bisq.core.dao.governance.proposal.ProposalValidationException;
import bisq.core.dao.governance.proposal.ProposalValidator;
import bisq.core.dao.state.DaoStateService;
import bisq.core.dao.state.model.governance.GenericProposal;
import bisq.core.dao.state.model.governance.Proposal;

import javax.inject.Inject;
Expand All @@ -40,9 +39,8 @@ public GenericProposalValidator(DaoStateService daoStateService, PeriodService p
public void validateDataFields(Proposal proposal) throws ProposalValidationException {
try {
super.validateDataFields(proposal);

GenericProposal genericProposalProposal = (GenericProposal) proposal;
//TODO
} catch (ProposalValidationException e) {
throw e;
} catch (Throwable throwable) {
throw new ProposalValidationException(throwable);
}
Expand Down
Expand Up @@ -24,7 +24,6 @@
import bisq.core.dao.governance.proposal.ProposalValidationException;
import bisq.core.dao.governance.proposal.ProposalValidator;
import bisq.core.dao.state.DaoStateService;
import bisq.core.dao.state.model.blockchain.BaseTx;
import bisq.core.dao.state.model.governance.ChangeParamProposal;
import bisq.core.dao.state.model.governance.Proposal;
import bisq.core.locale.Res;
Expand Down Expand Up @@ -86,14 +85,10 @@ public ChangeParamValidator(DaoStateService daoStateService, PeriodService perio
public void validateDataFields(Proposal proposal) throws ProposalValidationException {
try {
super.validateDataFields(proposal);

ChangeParamProposal changeParamProposal = (ChangeParamProposal) proposal;
// When we receive a temp proposal the tx is usually not confirmed so we cannot lookup the block height of
// the tx. We take the current block height in that case as it would be in the same cycle anyway.
int blockHeight = daoStateService.getTx(proposal.getTxId())
.map(BaseTx::getBlockHeight)
.orElseGet(daoStateService::getChainHeight);
validateParamValue(changeParamProposal.getParam(), changeParamProposal.getParamValue(), blockHeight);
validateParamValue(changeParamProposal.getParam(), changeParamProposal.getParamValue(), getBlockHeight(proposal));
} catch (ProposalValidationException e) {
throw e;
} catch (Throwable throwable) {
throw new ProposalValidationException(throwable);
}
Expand All @@ -104,7 +99,7 @@ public void validateParamValue(Param param, String inputValue) throws ParamValid
validateParamValue(param, inputValue, blockHeight);
}

public void validateParamValue(Param param, String inputValue, int blockHeight) throws ParamValidationException {
private void validateParamValue(Param param, String inputValue, int blockHeight) throws ParamValidationException {
String currentParamValue = daoStateService.getParamValue(param, blockHeight);
validateParamValue(param, currentParamValue, inputValue);
}
Expand Down
Expand Up @@ -17,9 +17,10 @@

package bisq.core.dao.governance.proposal.reimbursement;

import bisq.core.dao.governance.proposal.ProposalValidationException;
import bisq.core.dao.governance.period.PeriodService;
import bisq.core.dao.governance.proposal.ProposalValidationException;
import bisq.core.dao.governance.proposal.ProposalValidator;
import bisq.core.dao.governance.proposal.compensation.CompensationConsensus;
import bisq.core.dao.state.DaoStateService;
import bisq.core.dao.state.model.governance.Proposal;
import bisq.core.dao.state.model.governance.ReimbursementProposal;
Expand Down Expand Up @@ -53,12 +54,15 @@ public void validateDataFields(Proposal proposal) throws ProposalValidationExcep
reimbursementProposal.getAddress(); // throws AddressFormatException if wrong address

Coin requestedBsq = reimbursementProposal.getRequestedBsq();
Coin maxReimbursementRequestAmount = ReimbursementConsensus.getMaxReimbursementRequestAmount(daoStateService, periodService.getChainHeight());
checkArgument(requestedBsq.compareTo(maxReimbursementRequestAmount) <= 0,
"Requested BSQ must not exceed " + (maxReimbursementRequestAmount.value / 100L) + " BSQ");
Coin minReimbursementRequestAmount = ReimbursementConsensus.getMinReimbursementRequestAmount(daoStateService, periodService.getChainHeight());
checkArgument(requestedBsq.compareTo(minReimbursementRequestAmount) >= 0,
"Requested BSQ must not be less than " + (minReimbursementRequestAmount.value / 100L) + " BSQ");
int chainHeight = getBlockHeight(proposal);
Coin maxCompensationRequestAmount = CompensationConsensus.getMaxCompensationRequestAmount(daoStateService, chainHeight);
checkArgument(requestedBsq.compareTo(maxCompensationRequestAmount) <= 0,
"Requested BSQ must not exceed " + (maxCompensationRequestAmount.value / 100L) + " BSQ");
Coin minCompensationRequestAmount = CompensationConsensus.getMinCompensationRequestAmount(daoStateService, chainHeight);
checkArgument(requestedBsq.compareTo(minCompensationRequestAmount) >= 0,
"Requested BSQ must not be less than " + (minCompensationRequestAmount.value / 100L) + " BSQ");
} catch (ProposalValidationException e) {
throw e;
} catch (Throwable throwable) {
throw new ProposalValidationException(throwable);
}
Expand Down
Expand Up @@ -17,8 +17,8 @@

package bisq.core.dao.governance.proposal.removeAsset;

import bisq.core.dao.governance.proposal.ProposalValidationException;
import bisq.core.dao.governance.period.PeriodService;
import bisq.core.dao.governance.proposal.ProposalValidationException;
import bisq.core.dao.governance.proposal.ProposalValidator;
import bisq.core.dao.state.DaoStateService;
import bisq.core.dao.state.model.governance.Proposal;
Expand All @@ -28,6 +28,8 @@

import lombok.extern.slf4j.Slf4j;

import static org.apache.commons.lang3.Validate.notEmpty;

@Slf4j
public class RemoveAssetValidator extends ProposalValidator {

Expand All @@ -42,7 +44,9 @@ public void validateDataFields(Proposal proposal) throws ProposalValidationExcep
super.validateDataFields(proposal);

RemoveAssetProposal removeAssetProposal = (RemoveAssetProposal) proposal;
//TODO
notEmpty(removeAssetProposal.getTickerSymbol(), "TickerSymbol must not be empty");
} catch (ProposalValidationException e) {
throw e;
} catch (Throwable throwable) {
throw new ProposalValidationException(throwable);
}
Expand Down
Expand Up @@ -17,19 +17,18 @@

package bisq.core.dao.governance.proposal.role;

import bisq.core.dao.governance.proposal.ProposalValidationException;
import bisq.core.dao.governance.period.PeriodService;
import bisq.core.dao.governance.proposal.ProposalValidationException;
import bisq.core.dao.governance.proposal.ProposalValidator;
import bisq.core.dao.state.DaoStateService;
import bisq.core.dao.state.model.governance.Proposal;
import bisq.core.dao.state.model.governance.Role;
import bisq.core.dao.state.model.governance.RoleProposal;

import javax.inject.Inject;

import lombok.extern.slf4j.Slf4j;

import static org.apache.commons.lang3.Validate.notEmpty;
import static org.apache.commons.lang3.Validate.notNull;

@Slf4j
public class RoleValidator extends ProposalValidator {
Expand All @@ -45,11 +44,7 @@ public void validateDataFields(Proposal proposal) throws ProposalValidationExcep
super.validateDataFields(proposal);

RoleProposal roleProposal = (RoleProposal) proposal;
Role role = roleProposal.getRole();

//TODO
notEmpty(role.getName(), "role.name must not be empty");

notNull(roleProposal.getRole(), "Bonded role must not be null");
} catch (Throwable throwable) {
throw new ProposalValidationException(throwable);
}
Expand Down
Expand Up @@ -51,6 +51,7 @@ public abstract class Proposal implements PersistablePayload, NetworkPayload, Co
protected final String link;
protected final byte version;
protected final long creationDate;
@Nullable
protected final String txId;

protected Proposal(String name,
Expand Down
Expand Up @@ -33,10 +33,10 @@
import bisq.core.btc.setup.WalletsSetup;
import bisq.core.btc.wallet.BsqWalletService;
import bisq.core.dao.DaoFacade;
import bisq.core.dao.governance.proposal.ProposalValidationException;
import bisq.core.dao.governance.bond.Bond;
import bisq.core.dao.governance.param.Param;
import bisq.core.dao.governance.proposal.ProposalType;
import bisq.core.dao.governance.proposal.ProposalValidationException;
import bisq.core.dao.governance.proposal.ProposalWithTransaction;
import bisq.core.dao.governance.proposal.TxException;
import bisq.core.dao.governance.proposal.param.ChangeParamValidator;
Expand Down Expand Up @@ -358,14 +358,14 @@ private void doPublishMyProposal(Proposal proposal, Transaction transaction) {
}

@Nullable
private ProposalWithTransaction getProposalWithTransaction(ProposalType type)
private ProposalWithTransaction getProposalWithTransaction(ProposalType proposalType)
throws InsufficientMoneyException, ProposalValidationException, TxException {

checkNotNull(proposalDisplay, "proposalDisplay must not be null");

String link = proposalDisplay.linkInputTextField.getText();
String name = proposalDisplay.nameTextField.getText();
switch (type) {
switch (proposalType) {
case COMPENSATION_REQUEST:
checkNotNull(proposalDisplay.requestedBsqTextField,
"proposalDisplay.requestedBsqTextField must not be null");
Expand Down