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

Revert "Vote Reveal - Silent Fail" #4017

Merged
merged 1 commit into from
Feb 29, 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
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,21 @@
@Slf4j
public class VoteRevealService implements DaoStateListener, DaoSetupService {

public interface VoteRevealTxPublishedListener {
void onVoteRevealTxPublished(String txId);
}

private final DaoStateService daoStateService;
private final BlindVoteListService blindVoteListService;
private final PeriodService periodService;
private final MyVoteListService myVoteListService;
private final BsqWalletService bsqWalletService;
private final BtcWalletService btcWalletService;
private final WalletsManager walletsManager;
private final WalletsManager walletsManager;

@Getter
private final ObservableList<VoteRevealException> voteRevealExceptions = FXCollections.observableArrayList();
private final List<VoteRevealTxPublishedListener> voteRevealTxPublishedListeners = new ArrayList<>();
private final List<VoteRevealTxFailedListener> voteRevealTxFailedListeners = new ArrayList<>();

///////////////////////////////////////////////////////////////////////////////////////////
// Constructor
Expand All @@ -102,6 +106,7 @@ public VoteRevealService(DaoStateService daoStateService,
this.walletsManager = walletsManager;
}


///////////////////////////////////////////////////////////////////////////////////////////
// DaoSetupService
///////////////////////////////////////////////////////////////////////////////////////////
Expand All @@ -120,6 +125,11 @@ public void addListeners() {
public void start() {
}


///////////////////////////////////////////////////////////////////////////////////////////
// API
///////////////////////////////////////////////////////////////////////////////////////////

private byte[] getHashOfBlindVoteList() {
List<BlindVote> blindVotes = BlindVoteConsensus.getSortedBlindVoteListOfCycle(blindVoteListService);
byte[] hashOfBlindVoteList = VoteRevealConsensus.getHashOfBlindVoteList(blindVotes);
Expand All @@ -134,24 +144,25 @@ public void addVoteRevealTxPublishedListener(VoteRevealTxPublishedListener voteR


///////////////////////////////////////////////////////////////////////////////////////////
// API
// DaoStateListener
///////////////////////////////////////////////////////////////////////////////////////////

public void addVoteRevealTxFailedListener(VoteRevealTxFailedListener voteRevealTxFailedListener) {
voteRevealTxFailedListeners.add(voteRevealTxFailedListener);
}

@Override
public void onParseBlockCompleteAfterBatchProcessing(Block block) {
maybeRevealVotes(block.getHeight());
}


///////////////////////////////////////////////////////////////////////////////////////////
// Private
///////////////////////////////////////////////////////////////////////////////////////////

// Creation of vote reveal tx is done without user activity!
// We create automatically the vote reveal tx when we are in the reveal phase of the current cycle when
// the blind vote was created in case we have not done it already.
// The voter need to be at least once online in the reveal phase when he has a blind vote created,
// The voter needs to be at least once online in the reveal phase when he has a blind vote created,
// otherwise his vote becomes invalid.
// In case the user miss the vote reveal phase an (invalid) vote reveal tx will be created the next time the user is
// In case the user misses the vote reveal phase an (invalid) vote reveal tx will be created the next time the user is
// online. That tx only serves the purpose to unlock the stake from the blind vote but it will be ignored for voting.
// A blind vote which did not get revealed might still be part of the majority hash calculation as we cannot know
// which blind votes might be revealed until the phase is over at the moment when we publish the vote reveal tx.
Expand Down Expand Up @@ -187,7 +198,7 @@ private void maybeRevealVotes(int chainHeight) {
// BSQ because the blind vote tx is already in the snapshot and does not get parsed
// again. It would require a reset of the snapshot and parse all blocks again.
// As this is an exceptional case we prefer to have a simple solution instead and just
// publish the vote reveal tx but are aware that is is invalid.
// publish the vote reveal tx but are aware that it is invalid.
log.warn("We missed the vote reveal phase but publish now the tx to unlock our locked " +
"BSQ from the blind vote tx. BlindVoteTxId={}, blockHeight={}",
blindVoteTxId, chainHeight);
Expand All @@ -201,11 +212,6 @@ private void maybeRevealVotes(int chainHeight) {
});
}


///////////////////////////////////////////////////////////////////////////////////////////
// DaoStateListener
///////////////////////////////////////////////////////////////////////////////////////////

private void revealVote(MyVote myVote, boolean isInVoteRevealPhase) {
try {
// We collect all valid blind vote items we received via the p2p network.
Expand All @@ -232,7 +238,7 @@ private void revealVote(MyVote myVote, boolean isInVoteRevealPhase) {
publishTx(voteRevealTx);

// We don't want to wait for a successful broadcast to avoid issues if the broadcast succeeds delayed or at
// next startup but the tx was actually broadcasted.
// next startup but the tx was actually broadcast.
myVoteListService.applyRevealTxId(myVote, voteRevealTx.getHashAsString());
} catch (IOException | WalletException | TransactionVerificationException
| InsufficientMoneyException e) {
Expand All @@ -241,21 +247,13 @@ private void revealVote(MyVote myVote, boolean isInVoteRevealPhase) {
} catch (VoteRevealException e) {
voteRevealExceptions.add(e);
}

//Display vote reveal exceptions
voteRevealExceptions.forEach(e -> voteRevealTxFailedListeners.forEach(l -> l.onVoteRevealTxFailed(e)));
}


///////////////////////////////////////////////////////////////////////////////////////////
// Private
///////////////////////////////////////////////////////////////////////////////////////////

private void publishTx(Transaction voteRevealTx) {
walletsManager.publishAndCommitBsqTx(voteRevealTx, TxType.VOTE_REVEAL, new TxBroadcaster.Callback() {
@Override
public void onSuccess(Transaction transaction) {
log.info("voteRevealTx successfully broadcasted.");
log.info("voteRevealTx successfully broadcast.");
voteRevealTxPublishedListeners.forEach(l -> l.onVoteRevealTxPublished(transaction.getHashAsString()));
}

Expand All @@ -274,12 +272,4 @@ private Transaction getVoteRevealTx(TxOutput stakeTxOutput, byte[] opReturnData)
Transaction txWithBtcFee = btcWalletService.completePreparedVoteRevealTx(preparedTx, opReturnData);
return bsqWalletService.signTx(txWithBtcFee);
}

public interface VoteRevealTxPublishedListener {
void onVoteRevealTxPublished(String txId);
}

public interface VoteRevealTxFailedListener {
void onVoteRevealTxFailed(VoteRevealException exception);
}
}
3 changes: 0 additions & 3 deletions core/src/main/resources/i18n/displayStrings.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1619,9 +1619,6 @@ dao.cycle.phaseDurationWithoutBlocks=Block {0} - {1} (≈{2} - ≈{3})
dao.voteReveal.txPublished.headLine=Vote reveal transaction published
dao.voteReveal.txPublished=Your vote reveal transaction with transaction ID {0} was successfully published.\n\n\
This happens automatically by the software if you have participated in the DAO voting.
dao.voteReveal.txFailed.headLine=Vote reveal transaction failed
dao.voteReveal.txFailed=Your vote reveal transaction with transaction ID {0} failed.\n\n\
Reason was: {1}.

dao.results.cycles.header=Cycles
dao.results.cycles.table.header.cycle=Cycle
Expand Down
10 changes: 0 additions & 10 deletions desktop/src/main/java/bisq/desktop/main/dao/DaoView.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,6 @@ private DaoView(CachingViewLoader viewLoader, VoteRevealService voteRevealServic
.feedback(Res.get("dao.voteReveal.txPublished", txId))
.show();
});

voteRevealService.addVoteRevealTxFailedListener((exception) -> {
String key = "showVoteRevealFailedWarnPopupOnStartup" + exception.getBlindVoteTxId();
if (preferences.showAgain(key)) {
new Popup().headLine(Res.get("dao.voteReveal.txFailed.headLine"))
.dontShowAgainId(key)
.error(Res.get("dao.voteReveal.txFailed", exception.getBlindVoteTxId(), exception.getLocalizedMessage()))
.show();
}
});
}

@Override
Expand Down