Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
# Conflicts:
#	core/src/main/java/bisq/core/dao/state/SnapshotManager.java
  • Loading branch information
ManfredKarrer committed Sep 26, 2018
2 parents 0bcb96b + 5d46a99 commit 3689e4c
Show file tree
Hide file tree
Showing 27 changed files with 391 additions and 267 deletions.
1 change: 1 addition & 0 deletions .idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions core/src/main/java/bisq/core/dao/DaoModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
import bisq.core.dao.node.full.FullNode;
import bisq.core.dao.node.full.RpcService;
import bisq.core.dao.node.full.network.FullNodeNetworkService;
import bisq.core.dao.node.json.JsonBlockChainExporter;
import bisq.core.dao.node.json.ExportJsonFilesService;
import bisq.core.dao.node.lite.LiteNode;
import bisq.core.dao.node.lite.network.LiteNodeNetworkService;
import bisq.core.dao.node.parser.BlockParser;
Expand Down Expand Up @@ -99,7 +99,7 @@ protected void configure() {
bind(BsqState.class).in(Singleton.class);
bind(BsqStateService.class).in(Singleton.class);
bind(SnapshotManager.class).in(Singleton.class);
bind(JsonBlockChainExporter.class).in(Singleton.class);
bind(ExportJsonFilesService.class).in(Singleton.class);

// Period
bind(CycleService.class).in(Singleton.class);
Expand Down
9 changes: 7 additions & 2 deletions core/src/main/java/bisq/core/dao/DaoSetup.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import bisq.core.dao.governance.votereveal.VoteRevealService;
import bisq.core.dao.node.BsqNode;
import bisq.core.dao.node.BsqNodeProvider;
import bisq.core.dao.node.json.ExportJsonFilesService;
import bisq.core.dao.state.BsqStateService;
import bisq.core.dao.state.period.CycleService;

Expand All @@ -35,7 +36,6 @@
/**
* High level entry point for Dao domain.
* We initialize all main service classes here to be sure they are started.
*
*/
public class DaoSetup {
private final BsqStateService bsqStateService;
Expand All @@ -47,6 +47,7 @@ public class DaoSetup {
private final VoteRevealService voteRevealService;
private final VoteResultService voteResultService;
private final BsqNode bsqNode;
private final ExportJsonFilesService exportJsonFilesService;

@Inject
public DaoSetup(BsqNodeProvider bsqNodeProvider,
Expand All @@ -57,7 +58,8 @@ public DaoSetup(BsqNodeProvider bsqNodeProvider,
BlindVoteListService blindVoteListService,
MyBlindVoteListService myBlindVoteListService,
VoteRevealService voteRevealService,
VoteResultService voteResultService) {
VoteResultService voteResultService,
ExportJsonFilesService exportJsonFilesService) {
this.bsqStateService = bsqStateService;
this.cycleService = cycleService;
this.proposalService = proposalService;
Expand All @@ -66,6 +68,7 @@ public DaoSetup(BsqNodeProvider bsqNodeProvider,
this.myBlindVoteListService = myBlindVoteListService;
this.voteRevealService = voteRevealService;
this.voteResultService = voteResultService;
this.exportJsonFilesService = exportJsonFilesService;

bsqNode = bsqNodeProvider.getBsqNode();
}
Expand All @@ -81,6 +84,7 @@ public void onAllServicesInitialized(ErrorMessageHandler errorMessageHandler) {
myBlindVoteListService.addListeners();
voteRevealService.addListeners();
voteResultService.addListeners();
exportJsonFilesService.addListeners();

bsqStateService.start();
cycleService.start();
Expand All @@ -90,6 +94,7 @@ public void onAllServicesInitialized(ErrorMessageHandler errorMessageHandler) {
myBlindVoteListService.start();
voteRevealService.start();
voteResultService.start();
exportJsonFilesService.start();

bsqNode.setErrorMessageHandler(errorMessageHandler);
bsqNode.start();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import bisq.core.dao.governance.ballot.vote.Vote;
import bisq.core.dao.governance.proposal.ProposalService;
import bisq.core.dao.governance.proposal.storage.appendonly.ProposalPayload;
import bisq.core.dao.state.period.PeriodService;

import bisq.common.proto.persistable.PersistedDataHost;
import bisq.common.storage.Storage;
Expand All @@ -32,6 +33,7 @@

import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.stream.Collectors;

import lombok.extern.slf4j.Slf4j;

Expand All @@ -49,14 +51,16 @@ public interface BallotListChangeListener {
}

private final ProposalService proposalService;
private final PeriodService periodService;
private final Storage<BallotList> storage;

private final BallotList ballotList = new BallotList();
private final List<BallotListChangeListener> listeners = new CopyOnWriteArrayList<>();

@Inject
public BallotListService(ProposalService proposalService, Storage<BallotList> storage) {
public BallotListService(ProposalService proposalService, PeriodService periodService, Storage<BallotList> storage) {
this.proposalService = proposalService;
this.periodService = periodService;
this.storage = storage;
}

Expand Down Expand Up @@ -125,6 +129,12 @@ public BallotList getBallotList() {
return ballotList;
}

public List<Ballot> getBallotsOfCycle() {
return ballotList.stream()
.filter(ballot -> periodService.isTxInCorrectCycle(ballot.getTxId(), periodService.getChainHeight()))
.collect(Collectors.toList());
}


///////////////////////////////////////////////////////////////////////////////////////////
// Private
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public static boolean hasOpReturnDataValidLength(byte[] opReturnData) {
}

public static BallotList getSortedBallotList(BallotListService ballotListService) {
List<Ballot> ballotList = ballotListService.getBallotList().stream()
List<Ballot> ballotList = ballotListService.getBallotsOfCycle().stream()
.sorted(Comparator.comparing(Ballot::getTxId))
.collect(Collectors.toList());
log.info("Sorted ballotList: " + ballotList);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ public boolean areDataFieldsValidAndTxConfirmed(BlindVote blindVote) {
public boolean isTxInPhaseAndCycle(BlindVote blindVote) {
String txId = blindVote.getTxId();
Optional<Tx> optionalTx = bsqStateService.getTx(txId);
if (!optionalTx.isPresent()) {
log.warn("Tx is not in bsqStateService. blindVoteTxId={}", txId);
return false;
}

int txHeight = optionalTx.get().getBlockHeight();
if (!periodService.isTxInCorrectCycle(txHeight, bsqStateService.getChainHeight())) {
log.debug("Tx is not in current cycle. blindVote={}", blindVote);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,10 +271,11 @@ private byte[] getEncryptedMeritList(String blindVoteTxId, SecretKey secretKey)

// blindVoteTxId is null if we use the method from the getCurrentlyAvailableMerit call.
public MeritList getMerits(@Nullable String blindVoteTxId) {
// Create a lookup set for txIds of own comp. requests
// Create a lookup set for txIds of own comp. requests from past cycles (we ignore request form that cycle)
Set<String> myCompensationProposalTxIs = myProposalListService.getList().stream()
.filter(proposal -> proposal instanceof CompensationProposal)
.map(Proposal::getTxId)
.filter(txId -> periodService.isTxInPastCycle(txId, periodService.getChainHeight()))
.collect(Collectors.toSet());

return new MeritList(bsqStateService.getIssuanceSet().stream()
Expand Down
9 changes: 9 additions & 0 deletions core/src/main/java/bisq/core/dao/governance/merit/Merit.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import bisq.common.proto.network.NetworkPayload;
import bisq.common.proto.persistable.PersistablePayload;
import bisq.common.util.Utilities;

import io.bisq.generated.protobuffer.PB;

Expand Down Expand Up @@ -63,4 +64,12 @@ public static Merit fromProto(PB.Merit proto) {
public String getIssuanceTxId() {
return issuance.getTxId();
}

@Override
public String toString() {
return "Merit{" +
"\n issuance=" + issuance +
",\n signature=" + Utilities.bytesAsHexString(signature) +
"\n}";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ static boolean isSignatureValid(byte[] signatureFromMerit, String pubKeyAsHex, S
// We verify if signature of hash of blindVoteTxId is correct. EC key from first input for blind vote tx is
// used for signature.
if (pubKeyAsHex == null) {
log.error("Error at getMeritStake: pubKeyAsHex is null");
log.error("Error at isSignatureValid: pubKeyAsHex is null");
return false;
}

Expand All @@ -110,16 +110,15 @@ static boolean isSignatureValid(byte[] signatureFromMerit, String pubKeyAsHex, S

public static long getWeightedMeritAmount(long amount, int issuanceHeight, int blockHeight, int blocksPerYear) {
if (issuanceHeight > blockHeight)
throw new IllegalArgumentException("issuanceHeight must not be larger than blockHeight");
throw new IllegalArgumentException("issuanceHeight must not be larger than blockHeight. issuanceHeight=" + issuanceHeight + "; blockHeight=" + blockHeight);
if (blockHeight < 0)
throw new IllegalArgumentException("blockHeight must not be negative");
throw new IllegalArgumentException("blockHeight must not be negative. blockHeight=" + blockHeight);
if (amount < 0)
throw new IllegalArgumentException("amount must not be negative");
throw new IllegalArgumentException("amount must not be negative. amount" + amount);
if (blocksPerYear < 0)
throw new IllegalArgumentException("blocksPerYear must not be negative");
throw new IllegalArgumentException("blocksPerYear must not be negative. blocksPerYear=" + blocksPerYear);
if (issuanceHeight < 0)
throw new IllegalArgumentException("issuanceHeight must not be negative");

throw new IllegalArgumentException("issuanceHeight must not be negative. issuanceHeight=" + issuanceHeight);

// We use a linear function to apply a factor for the issuance amount of 1 if the issuance was recent and 0
// if the issuance was 2 years old or older.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ public Date getCreationDate() {

public abstract Param getThresholdParam();


@Override
public String toString() {
return "Proposal{" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class EvaluatedProposal {
private final long requiredQuorum;
private final long requiredThreshold;

public EvaluatedProposal(boolean isAccepted, ProposalVoteResult proposalVoteResult, long requiredQuorum, long requiredThreshold) {
EvaluatedProposal(boolean isAccepted, ProposalVoteResult proposalVoteResult, long requiredQuorum, long requiredThreshold) {
this.isAccepted = isAccepted;
this.proposalVoteResult = proposalVoteResult;
this.requiredQuorum = requiredQuorum;
Expand Down
12 changes: 6 additions & 6 deletions core/src/main/java/bisq/core/dao/node/full/FullNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import bisq.core.dao.node.BsqNode;
import bisq.core.dao.node.full.network.FullNodeNetworkService;
import bisq.core.dao.node.json.JsonBlockChainExporter;
import bisq.core.dao.node.json.ExportJsonFilesService;
import bisq.core.dao.node.parser.BlockParser;
import bisq.core.dao.node.parser.exceptions.BlockNotConnectingException;
import bisq.core.dao.state.BsqStateService;
Expand Down Expand Up @@ -49,7 +49,7 @@ public class FullNode extends BsqNode {

private final RpcService rpcService;
private final FullNodeNetworkService fullNodeNetworkService;
private final JsonBlockChainExporter jsonBlockChainExporter;
private final ExportJsonFilesService exportJsonFilesService;
private boolean addBlockHandlerAdded;


Expand All @@ -64,12 +64,12 @@ public FullNode(BlockParser blockParser,
SnapshotManager snapshotManager,
P2PService p2PService,
RpcService rpcService,
JsonBlockChainExporter jsonBlockChainExporter,
ExportJsonFilesService exportJsonFilesService,
FullNodeNetworkService fullNodeNetworkService) {
super(blockParser, bsqStateService, snapshotManager, p2PService);
this.rpcService = rpcService;

this.jsonBlockChainExporter = jsonBlockChainExporter;
this.exportJsonFilesService = exportJsonFilesService;
this.fullNodeNetworkService = fullNodeNetworkService;
}

Expand All @@ -88,7 +88,7 @@ public void start() {
}

public void shutDown() {
jsonBlockChainExporter.shutDown();
exportJsonFilesService.shutDown();
fullNodeNetworkService.shutDown();
}

Expand Down Expand Up @@ -147,7 +147,7 @@ private void addBlockHandler() {
}

private void onNewBlock(Block block) {
jsonBlockChainExporter.maybeExport();
exportJsonFilesService.exportToJson();

if (p2pNetworkReady && parseBlockchainComplete)
fullNodeNetworkService.publishNewBlock(block);
Expand Down
Loading

0 comments on commit 3689e4c

Please sign in to comment.