Revert "Vote Reveal - Silent Fail"

This commit is contained in:
Christoph Atteneder 2020-02-28 16:01:03 +01:00 committed by GitHub
parent 1d1cba1e4d
commit fa56b91f6d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 46 deletions

View File

@ -69,17 +69,21 @@ import lombok.extern.slf4j.Slf4j;
@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
@ -102,6 +106,7 @@ public class VoteRevealService implements DaoStateListener, DaoSetupService {
this.walletsManager = walletsManager;
}
///////////////////////////////////////////////////////////////////////////////////////////
// DaoSetupService
///////////////////////////////////////////////////////////////////////////////////////////
@ -120,6 +125,11 @@ public class VoteRevealService implements DaoStateListener, DaoSetupService {
public void start() {
}
///////////////////////////////////////////////////////////////////////////////////////////
// API
///////////////////////////////////////////////////////////////////////////////////////////
private byte[] getHashOfBlindVoteList() {
List<BlindVote> blindVotes = BlindVoteConsensus.getSortedBlindVoteListOfCycle(blindVoteListService);
byte[] hashOfBlindVoteList = VoteRevealConsensus.getHashOfBlindVoteList(blindVotes);
@ -134,24 +144,25 @@ public class VoteRevealService implements DaoStateListener, DaoSetupService {
///////////////////////////////////////////////////////////////////////////////////////////
// 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.
@ -187,7 +198,7 @@ public class VoteRevealService implements DaoStateListener, DaoSetupService {
// 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);
@ -201,11 +212,6 @@ public class VoteRevealService implements DaoStateListener, DaoSetupService {
});
}
///////////////////////////////////////////////////////////////////////////////////////////
// DaoStateListener
///////////////////////////////////////////////////////////////////////////////////////////
private void revealVote(MyVote myVote, boolean isInVoteRevealPhase) {
try {
// We collect all valid blind vote items we received via the p2p network.
@ -232,7 +238,7 @@ public class VoteRevealService implements DaoStateListener, DaoSetupService {
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) {
@ -241,21 +247,13 @@ public class VoteRevealService implements DaoStateListener, DaoSetupService {
} 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()));
}
@ -274,12 +272,4 @@ public class VoteRevealService implements DaoStateListener, DaoSetupService {
Transaction txWithBtcFee = btcWalletService.completePreparedVoteRevealTx(preparedTx, opReturnData);
return bsqWalletService.signTx(txWithBtcFee);
}
public interface VoteRevealTxPublishedListener {
void onVoteRevealTxPublished(String txId);
}
public interface VoteRevealTxFailedListener {
void onVoteRevealTxFailed(VoteRevealException exception);
}
}

View File

@ -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

View File

@ -78,16 +78,6 @@ public class DaoView extends ActivatableView<TabPane, Void> {
.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