Skip to content

Commit

Permalink
Make MeritList & VoteWithProposalTxIdList standalone classes
Browse files Browse the repository at this point in the history
Remove an unnecessary PersistableEnvelope interface by making them
standalone @value classes with private List fields, instead of extending
PersistableList. As they weren't using any functionality of the latter
other than the getList() and stream() methods, this should not alter
behaviour, outside MeritList::toString.

Also comment out the MERIT_LIST PersistableEnvelope protobuf message
type, which shouldn't be encountered as merit lists were never persisted
directly to a storage file.

This removes the last superfluous PersistableEnvelope implementations,
leaving the following type hierarchy:

  PersistableEnvelope *
  +- NavigationPath
  +- PeerList
  +- PersistableList *
  +- ThreadedPersistableEnvelope *
  |  +- AccountAgeWitnessStore
  |  +- BlindVoteStore
  |  +- DaoStateStore
  |  +- PersistableNetworkPayloadList              *  is abstract
  |  +- ProposalStore
  |  +- SequenceNumberMap
  |  +- SignedWitnessStore
  |  +- TempProposalStore
  |  \- TradeStatistics2Store
  \- UserThreadMappedPersistableEnvelope *
     +- AddressEntryList
     +- DisputeList *
     |  +- ArbitrationDisputeList
     |  +- MediationDisputeList
     |  \- RefundDisputeList
     +- UserThreadMappedPersistableList *
     |  +- BallotList
     |  +- MyBlindVoteList
     |  +- MyProofOfBurnList
     |  +- MyProposalList
     |  +- MyReputationList
     |  +- MyVoteList
     |  +- PaymentAccountList
     |  \- UnconfirmedBsqChangeOutputList
     +- PreferencesPayload
     +- TradableList
     \- UserPayload
  • Loading branch information
stejbac committed Mar 29, 2020
1 parent 594b42a commit 74022e0
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,26 @@

import bisq.core.dao.governance.ConsensusCritical;

import bisq.common.proto.persistable.PersistableList;
import bisq.common.Proto;

import com.google.protobuf.InvalidProtocolBufferException;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

import lombok.EqualsAndHashCode;
import lombok.Value;
import lombok.extern.slf4j.Slf4j;

/**
* We don't persist that list but use it only for encoding the VoteWithProposalTxId list
* to PB bytes in the blindVote. The bytes get encrypted and later decrypted. To use a ByteOutputStream
* and add all list elements would work for encryption but for decrypting we don't know the length of a list entry
* and it would make the process complicate (e.g. require a custom serialisation format).
* We encode the VoteWithProposalTxId list to PB bytes in the blindVote. The bytes get encrypted and later decrypted.
* To use a ByteOutputStream and add all list elements would work for encryption but for decrypting we don't know the
* length of a list entry and it would make the process complicated (e.g. require a custom serialisation format).
*/
@Slf4j
@EqualsAndHashCode(callSuper = true)
public class VoteWithProposalTxIdList extends PersistableList<VoteWithProposalTxId> implements ConsensusCritical {

VoteWithProposalTxIdList(List<VoteWithProposalTxId> list) {
super(list);
}

@Value
public class VoteWithProposalTxIdList implements Proto, ConsensusCritical {
private final List<VoteWithProposalTxId> list;

///////////////////////////////////////////////////////////////////////////////////////////
// PROTO BUFFER
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ private BallotList createBallotList(VoteWithProposalTxIdList voteWithProposalTxI

// We convert the list to a map with proposalTxId as key and the vote as value. As the vote can be null we
// wrap it into an optional.
Map<String, Optional<Vote>> voteByTxIdMap = voteWithProposalTxIdList.stream()
Map<String, Optional<Vote>> voteByTxIdMap = voteWithProposalTxIdList.getList().stream()
.collect(Collectors.toMap(VoteWithProposalTxId::getProposalTxId, e -> Optional.ofNullable(e.getVote())));

// We make a map with proposalTxId as key and the ballot as value out of our stored ballot list.
Expand Down Expand Up @@ -414,11 +414,11 @@ private BallotList createBallotList(VoteWithProposalTxIdList voteWithProposalTxI
// If we received a proposal after we had already voted we consider it as a proposal withhold attack and
// treat the proposal as it was voted with a rejected vote.
ballotByTxIdMap.entrySet().stream()
.filter(e -> !voteByTxIdMap.keySet().contains(e.getKey()))
.filter(e -> !voteByTxIdMap.containsKey(e.getKey()))
.map(Map.Entry::getValue)
.forEach(ballot -> {
log.warn("We have a proposal which was not part of our blind vote and reject it. " +
"Proposal ={}" + ballot.getProposal());
"Proposal={}", ballot.getProposal());
ballots.add(new Ballot(ballot.getProposal(), new Vote(false)));
});

Expand Down Expand Up @@ -776,7 +776,7 @@ private boolean isInVoteResultPhase(int chainHeight) {
///////////////////////////////////////////////////////////////////////////////////////////

@Value
public class HashWithStake {
public static class HashWithStake {
private final byte[] hash;
private final long stake;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,19 @@
import bisq.core.dao.governance.ConsensusCritical;
import bisq.core.dao.state.model.ImmutableDaoStateModel;

import bisq.common.proto.persistable.PersistableList;
import bisq.common.Proto;

import com.google.protobuf.InvalidProtocolBufferException;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

import lombok.EqualsAndHashCode;

import javax.annotation.concurrent.Immutable;

// We don't persist that list but use it only for encoding the MeritList list
// to PB bytes in the blindVote.
@Immutable
@EqualsAndHashCode(callSuper = true)
public class MeritList extends PersistableList<Merit> implements ConsensusCritical, ImmutableDaoStateModel {

public MeritList(List<Merit> list) {
super(list);
}
import lombok.Value;

@Value
public class MeritList implements Proto, ConsensusCritical, ImmutableDaoStateModel {
private final List<Merit> list;

///////////////////////////////////////////////////////////////////////////////////////////
// PROTO BUFFER
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import bisq.core.dao.governance.proposal.storage.temp.TempProposalStore;
import bisq.core.dao.state.DaoStateStore;
import bisq.core.dao.state.model.governance.BallotList;
import bisq.core.dao.state.model.governance.MeritList;
import bisq.core.dao.state.unconfirmed.UnconfirmedBsqChangeOutputList;
import bisq.core.payment.PaymentAccountList;
import bisq.core.proto.CoreProtoResolver;
Expand Down Expand Up @@ -144,8 +143,6 @@ public PersistableEnvelope fromProto(protobuf.PersistableEnvelope proto) {
return MyVoteList.fromProto(proto.getMyVoteList());
case MY_BLIND_VOTE_LIST:
return MyBlindVoteList.fromProto(proto.getMyBlindVoteList());
case MERIT_LIST:
return MeritList.fromProto(proto.getMeritList());
case DAO_STATE_STORE:
return DaoStateStore.fromProto(proto.getDaoStateStore());
case MY_REPUTATION_LIST:
Expand Down
2 changes: 1 addition & 1 deletion proto/src/main/proto/pb.proto
Original file line number Diff line number Diff line change
Expand Up @@ -1139,7 +1139,7 @@ message PersistableEnvelope {
BallotList ballot_list = 20;
MyVoteList my_vote_list = 21;
MyBlindVoteList my_blind_vote_list = 22;
MeritList merit_list = 23;
// MeritList merit_list = 23; // was not used here, but its class used to implement PersistableEnvelope via its super
DaoStateStore dao_state_store = 24;
MyReputationList my_reputation_list = 25;
MyProofOfBurnList my_proof_of_burn_list = 26;
Expand Down

0 comments on commit 74022e0

Please sign in to comment.