Skip to content

Commit

Permalink
GUI: governance, IBD check before opening the proposal creation wizard.
Browse files Browse the repository at this point in the history
  • Loading branch information
furszy committed Dec 7, 2021
1 parent 97728e5 commit 57a7205
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/qt/pivx/governancewidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,27 @@ void GovernanceWidget::onVoteForPropClicked(const ProposalInfo& proposalInfo)

void GovernanceWidget::onCreatePropClicked()
{
if (!walletModel || !governanceModel) return;
if (!walletModel || !governanceModel || !clientModel) return;

if (!governanceModel->isTierTwoSync()) {
inform(tr("Please wait until the node is fully synced"));
return;
}

// Do not allow proposals submission 1440 blocks away (1 day) from the next superblock
// The budget finalization could have been submitted and the user would never know it, losing the first superblock.
// And, do not allow submission until we are 120 blocks (2 hours) after the superblock
// just to be sure that the node passed the default chain reorg depth.
// future: customizable future superblock height selection (for now, we are automatically using the next superblock).
const int chainHeight = clientModel->getLastBlockProcessedHeight();
const int nBlocksPerCycle = governanceModel->getNumBlocksPerBudgetCycle();
const int nextSuperblock = chainHeight - chainHeight % nBlocksPerCycle + nBlocksPerCycle;
const int pastRange = walletModel->isTestNetwork() ? 10 : 1440;
const int futureRange = walletModel->isTestNetwork() ? 10 : 120;
if (nextSuperblock - pastRange < chainHeight && chainHeight < nextSuperblock + futureRange) {
inform(tr("Cannot create proposal, superblock is too close. Need to wait %d blocks").arg(nextSuperblock + 120 - chainHeight));
return;
}

auto ptrUnlockedContext = std::make_unique<WalletModel::UnlockContext>(walletModel->requestUnlock());
if (!ptrUnlockedContext->isValid()) {
Expand Down

0 comments on commit 57a7205

Please sign in to comment.