From e382461bf260e1d76dd6d50572081094614559c1 Mon Sep 17 00:00:00 2001 From: Hongrui Fang Date: Thu, 10 Nov 2022 18:56:38 +0800 Subject: [PATCH] ensure votes changed in `VotingReady` while calling `UnlockStakes` --- agora/Agora/Proposal/Scripts.hs | 68 ++++++++++++++++++--------------- 1 file changed, 37 insertions(+), 31 deletions(-) diff --git a/agora/Agora/Proposal/Scripts.hs b/agora/Agora/Proposal/Scripts.hs index 7a362a3..0a10b6e 100644 --- a/agora/Agora/Proposal/Scripts.hs +++ b/agora/Agora/Proposal/Scripts.hs @@ -549,40 +549,41 @@ proposalValidator = PUnlockStake _ -> spendStakes $ \sctxF -> do let expectedVotes = - pfoldl - # plam - ( \votes stake -> unTermCont $ do - stakeF <- - pletFieldsC - @'["stakedAmount", "lockedBy"] - stake + pdata $ + pfoldl + # plam + ( \votes stake -> unTermCont $ do + stakeF <- + pletFieldsC + @'["stakedAmount", "lockedBy"] + stake - stakeRoles <- - pletC $ - pgetStakeRoles - # proposalInputDatumF.proposalId - # stakeF.lockedBy + stakeRoles <- + pletC $ + pgetStakeRoles + # proposalInputDatumF.proposalId + # stakeF.lockedBy - pguardC "Stake input should be relevant" $ - pnot #$ pisIrrelevant # stakeRoles + pguardC "Stake input should be relevant" $ + pnot #$ pisIrrelevant # stakeRoles - let canRetractVotes = - pisVoter # stakeRoles + let canRetractVotes = + pisVoter # stakeRoles - voteCount = - pto $ - pfromData stakeF.stakedAmount + voteCount = + pto $ + pfromData stakeF.stakedAmount - newVotes = - pretractVotes - # (pextractVoteOption # stakeRoles) - # voteCount - # votes + newVotes = + pretractVotes + # (pextractVoteOption # stakeRoles) + # voteCount + # votes - pure $ pif canRetractVotes newVotes votes - ) - # proposalInputDatumF.votes - # sctxF.inputStakes + pure $ pif canRetractVotes newVotes votes + ) + # proposalInputDatumF.votes + # sctxF.inputStakes inVotingPeriod = pisWithin # getTimingRelation PVotingPeriod @@ -611,14 +612,19 @@ proposalValidator = .& #thresholds .= proposalInputDatumF.thresholds .& #votes - .= pdata expectedVotes + .= expectedVotes .& #timingConfig .= proposalInputDatumF.timingConfig .& #startingTime .= proposalInputDatumF.startingTime ) - in ptraceIfFalse "Update votes" $ - expectedProposalOut #== proposalOutputDatum + in foldl1 + (#&&) + [ ptraceIfFalse "Votes changed" $ + pnot #$ expectedVotes #== proposalInputDatumF.votes + , ptraceIfFalse "Proposal update correct" $ + expectedProposalOut #== proposalOutputDatum + ] ) -- No change to the proposal is allowed. ( ptraceIfFalse "Proposal unchanged" $