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

PDF cleanup: Fig 36 (improved) #250

Merged
merged 1 commit into from
Oct 18, 2023
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
3 changes: 3 additions & 0 deletions src/Axiom/Set/Map.agda
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ filterᵐ-finite : {P : A × B → Type} → (sp : specProperty P) → Decidable
finite (m ˢ) finite (filterᵐ sp m ˢ)
filterᵐ-finite = filter-finite

filterKeys : {P : A Type} specProperty P Map A B Map A B
filterKeys sp-P = filterᵐ (sp-∘ sp-P proj₁)

singletonᵐ : A B Map A B
singletonᵐ a b = ❴ (a , b) ❵
, (from ∈-singleton -⟨ (λ where refl refl refl) ⟩- from ∈-singleton)
Expand Down
58 changes: 26 additions & 32 deletions src/Ledger/Ratify.lagda
Original file line number Diff line number Diff line change
Expand Up @@ -345,37 +345,38 @@ The code in Figure~\ref{fig:defs:ratify-ii} defines \votedHashes, which returns
{\small
\begin{code}[hide]
abstract
-- unused, keep until we know for sure that there'll be no minimum AVS
-- activeVotingStake : ℙ VDeleg → StakeDistrs → (VDeleg ⇀ Vote) → Coin
-- activeVotingStake cc dists votes =
-- Σᵐᵛ[ x ← getStakeDist DRep cc dists ∣ dom votes ᶜ ᶠᵐ ] x

-- TODO: explain this notation in the prose and it's purpose:
-- if there's no stake, accept only if threshold is zero
_/₀_ : ℕ → ℕ → ℚ
x /₀ 0 = ℚ.0ℚ
x /₀ y@(suc _) = ℤ.+ x ℚ./ y
\end{code}
\begin{code}
getStakeDist : GovRole → ℙ VDeleg → StakeDistrs → VDeleg ⇀ Coin
getStakeDist CC cc _ = constMap (filterˢ isCCProp cc) 1
getStakeDist DRep _ record { stakeDistr = dist } = filterᵐ (sp-∘ isDRepProp proj₁) dist
getStakeDist SPO _ record { stakeDistr = dist } = filterᵐ (sp-∘ isSPOProp proj₁) dist
getStakeDist DRep _ record { stakeDistr = dist } = filterKeys isDRepProp dist
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice.

getStakeDist SPO _ record { stakeDistr = dist } = filterKeys isSPOProp dist

acceptedStake : GovRole → ℙ VDeleg → StakeDistrs → (VDeleg ⇀ Vote) → Coin
acceptedStake r cc dists votes =
Σᵐᵛ[ x ← (getStakeDist r cc dists ∣ votedYesHashes votes r) ᶠᵐ ] x
acceptedStakeRatio : GovRole → ℙ VDeleg → StakeDistrs → (VDeleg ⇀ Vote) → ℚ
acceptedStakeRatio r cc dists votes = acceptedStake /₀ totalStake
where
acceptedStake totalStake : Coin
acceptedStake = Σᵐᵛ[ x ← (getStakeDist r cc dists ∣ votedYesHashes votes r) ᶠᵐ ] x
totalStake = Σᵐᵛ[ x ← getStakeDist r cc dists ∣ votedAbstainHashes votes r ᶜ ᶠᵐ ] x

totalStake : GovRole → ℙ VDeleg → StakeDistrs → (VDeleg ⇀ Vote) → Coin
totalStake r cc dists votes =
Σᵐᵛ[ x ← getStakeDist r cc dists ∣ votedAbstainHashes votes r ᶜ ᶠᵐ ] x

activeVotingStake : ℙ VDeleg → StakeDistrs → (VDeleg ⇀ Vote) → Coin
activeVotingStake cc dists votes =
Σᵐᵛ[ x ← getStakeDist DRep cc dists ∣ dom votes ᶜ ᶠᵐ ] x

acceptedBy : (Γ : RatifyEnv) (es : EnactState) (gs : GovActionState) → GovRole → Set
acceptedBy : RatifyEnv → EnactState → GovActionState → GovRole → Set
acceptedBy Γ (record { cc = cc , _; pparams = pparams , _ }) gs role =
let open RatifyEnv Γ; open GovActionState gs; open PParams pparams
votes' = actualVotes Γ cc votes action pparams
cc' = dom votes'
redStakeDistr = restrictedDists coinThreshold rankThreshold stakeDistrs
t = maybe id ℚ.0ℚ $ threshold pparams (proj₂ <$> cc) action role in
case totalStake role cc' redStakeDistr votes' of λ where
0 → t ≡ ℚ.0ℚ -- if there's no stake, accept only if threshold is zero
x@(suc _) → ℤ.+ acceptedStake role cc' redStakeDistr votes' ℚ./ x ℚ.≥ t

accepted : (Γ : RatifyEnv) (es : EnactState) (gs : GovActionState) → Set
let open GovActionState gs
votes' = actualVotes Γ cc votes action pparams
t = maybe id ℚ.0ℚ $ threshold pparams (proj₂ <$> cc) action role
in acceptedStakeRatio role (dom votes') (RatifyEnv.stakeDistrs Γ) votes' ℚ.≥ t

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice. I think this is better than my attempt to simplify acceptedBy and accepted (#248), so I'll close that PR.

accepted : RatifyEnv → EnactState → GovActionState → Set
accepted Γ es gs = acceptedBy Γ es gs CC ∧ acceptedBy Γ es gs DRep ∧ acceptedBy Γ es gs SPO

expired : Epoch → GovActionState → Set
Expand Down Expand Up @@ -438,14 +439,7 @@ abstract
delayed? a h es d = let instance _ = verifyPrev? a h es in it

acceptedBy? : ∀ Γ es st role → Dec (acceptedBy Γ es st role)
acceptedBy? Γ record{ cc = cc , _ ; pparams = pparams , _ } st role
with (let open RatifyEnv Γ; open GovActionState st; open PParams pparams
votes' = actualVotes Γ cc votes action pparams
cc' = dom votes'
redStakeDistr = restrictedDists coinThreshold rankThreshold stakeDistrs
in totalStake role cc' redStakeDistr votes')
... | zero = it
... | suc n = it
acceptedBy? Γ record{ cc = cc , _ ; pparams = pparams , _ } st role = _ ℚ.≤? _

accepted? : ∀ Γ es st → Dec (accepted Γ es st)
accepted? Γ es st =
Expand Down