Skip to content

Commit 246ae4a

Browse files
committed
Simplify acceptedByCC
1 parent f6ee32d commit 246ae4a

File tree

1 file changed

+49
-52
lines changed

1 file changed

+49
-52
lines changed

src/Ledger/Conway/Specification/Ratify.lagda.md

Lines changed: 49 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -257,35 +257,30 @@ utilizes the following auxiliary definitions.
257257
cast by members of the `CC`{.AgdaInductiveConstructor} and are
258258
part of the `GovActionState`{.AgdaDatatype} `gaSt`{.AgdaBound}.
259259

260-
+ `getCCHotCred`{.AgdaFunction}: This function maps a `Credential`{.AgdaDatatype}
261-
and an `Epoch`{.AgdaDatatype} to the hot key corresponding to the given
262-
credential, in case this has not expired.
260+
+ `getCCHotCredential`{.AgdaFunction}: This function maps a
261+
`Credential`{.AgdaDatatype} and an `Epoch`{.AgdaDatatype} to the hot credential
262+
corresponding to the given cold credential, in case this has not expired.
263263

264-
+ `actualVote`{.AgdaFunction}: This function sets the default vote for
265-
`CC`{.AgdaInductiveConstructor} members. If the given
266-
`CC`{.AgdaInductiveConstructor} member's term has expired, if they have not
267-
yet registered a hot key, or if they have resigned, then
268-
`actualVote`{.AgdaFunction} returns `abstain`{.AgdaInductiveConstructor}; if none
269-
of these conditions is met, then
264+
+ `activeCC`{.AgdaFunction}: The active committee members as a map from cold credentials
265+
to hot credentials. A committee member is _active_ iff:
266+
1. their term has not expired, and
267+
2. they have a registered hot credential.
268+
Otherwise the member is considered to be _inactive_.
270269

271-
+ if the `CC`{.AgdaInductiveConstructor} member has voted, then that
272-
vote is returned;
270+
If the committee does not exist (e.g., the system is in a state of
271+
no-confidence) then this set is empty.
273272

274-
+ if the `CC`{.AgdaInductiveConstructor} member has not voted, then
275-
the default value `no`{.AgdaInductiveConstructor} is returned.
273+
+ `actualVotes`{.AgdaFunction}: This map contains the actual votes of the active
274+
`CC`{.AgdaInductiveConstructor}. For each member,
276275

277-
+ `actualVotes`{.AgdaFunction}: This map contains the actual votes of
278-
the `CC`{.AgdaInductiveConstructor}. If the commitee does not exists then it is
279-
the empty map, otherwise,
276+
+ if the member has cast a vote using the hot credential then this vote is used,
277+
+ if not the member default vote is `no`{.AgdaInductiveConstructor}.
280278

281-
+ if the number of `CC`{.AgdaInductiveConstructor} members with a registered hot
282-
key is greater than the protocol parameter `ccMinSize`{.AgdaBound}, then
283-
`actualVote`{.AgdaFunction} is returned (as a map), otherwise,
284-
285-
+ all commitee members vote `no`{.AgdaInductiveConstructor}.
286-
287-
+ `mT`{.AgdaFunction}: This is the threshold of the `CC`{.AgdaInductiveConstructor}.
288-
It may be `nothing`{.AgdaInductiveConstructor}.
279+
+ `mT`{.AgdaFunction}: This is the threshold of the
280+
`CC`{.AgdaInductiveConstructor}. In case it is
281+
`nothing`{.AgdaInductiveConstructor}, the `CC`{.AgdaInductiveConstructor} is
282+
not allowed to vote and the action is accepted automatically (e.g., for
283+
`NoConfidence` or `UpdateCommittee` actions).
289284

290285
+ `stakeDistr`{.AgdaFunction} computes the stake distribution. Note that every
291286
constitutional committe member has a stake of 1, giving them equal voting power.
@@ -299,12 +294,9 @@ utilizes the following auxiliary definitions.
299294
+ `totalStake`{.AgdaFunction}: This is the portion of `CC`{.AgdaInductiveConstructor}
300295
stake that voted either `yes`{.AgdaInductiveConstructor} or `no`{.AgdaInductiveConstructor}.
301296

302-
In addition, it must be the case that either
303-
304-
+ the size of the `CC`{.AgdaInductiveConstructor} is greater than
305-
`ccMinSize`{.AgdaBound}, or
306-
307-
+ the threshold function returns `nothing`{.AgdaInductiveConstructor}.
297+
In addition, if the committee is allowed to vote, it must be the case that the
298+
size of the active `CC`{.AgdaInductiveConstructor} is greater than
299+
`ccMinSize`{.AgdaBound}
308300

309301
```agda
310302
module AcceptedByCC (currentEpoch : Epoch)
@@ -322,49 +314,42 @@ module AcceptedByCC (currentEpoch : Epoch)
322314
```
323315
-->
324316
```agda
325-
sizeActiveCC : ℕ
326-
sizeActiveCC = case proj₁ cc of λ where
327-
(just ((ccMembers , _) , _)) → lengthˢ (filterˢ (activeInEpoch currentEpoch) ccMembers)
328-
nothing → 0
329-
330317
castVotes : Credential ⇀ Vote
331318
castVotes = gvCC
332319
333-
getCCHotCred : Credential × Epoch → Maybe Credential
334-
getCCHotCred (c , e) =
320+
getCCHotCredential : Credential Epoch → Maybe Credential
321+
getCCHotCredential c e =
335322
if currentEpoch > e
336323
then nothing -- credential has expired
337324
else case lookupᵐ? ccHotKeys c of λ where
338325
(just (just c')) → just c'
339326
_ → nothing -- hot key not registered or resigned
340327
341-
actualVote : Credential → Epoch → Vote
342-
actualVote c e = case getCCHotCred (c , e) of λ where
343-
(just c') → maybe id Vote.no (lookupᵐ? castVotes c')
344-
_ → Vote.abstain
328+
activeCC : Credential ⇀ Credential
329+
activeCC = case proj₁ cc of λ where
330+
(just (ccMembers , _)) → mapMaybeWithKeyᵐ getCCHotCredential ccMembers
331+
nothing → ∅
332+
333+
sizeActiveCC : ℕ
334+
sizeActiveCC = lengthˢ (dom activeCC)
345335
346336
actualVotes : Credential ⇀ Vote
347-
actualVotes = case proj₁ cc of λ where
348-
nothing → ∅
349-
(just (m , _)) → if ccMinSize ≤ lengthˢ (mapFromPartialFun getCCHotCred (m ˢ))
350-
then mapWithKey actualVote m
351-
else constMap (dom m) Vote.no
337+
actualVotes =
338+
mapWithKey (λ coldCredential hotCredential → maybe id Vote.no (lookupᵐ? castVotes hotCredential))
339+
activeCC
352340
353341
mT : Maybe ℚ
354342
mT = threshold (PParamsOf eSt) (proj₂ <$> (proj₁ cc)) action CC
355343
356-
t : ℚ
357-
t = maybe id 0ℚ mT
358-
359344
stakeDistr : Credential ⇀ Coin
360345
stakeDistr = constMap (dom actualVotes) 1
361346
362347
acceptedStake totalStake : Coin
363348
acceptedStake = ∑[ x ← stakeDistr ∣ actualVotes ⁻¹ Vote.yes ] x
364349
totalStake = ∑[ x ← stakeDistr ∣ dom (actualVotes ∣^ (❴ Vote.yes ❵ ∪ ❴ Vote.no ❵)) ] x
365350
366-
accepted = (acceptedStake /₀ totalStake) ≥ t
367-
× (sizeActiveCC ≥ ccMinSize ⊎ (Is-nothing mT × ccMinSize ≡ 0))
351+
accepted = if mT then (λ {t} → sizeActiveCC ≥ ccMinSize × (acceptedStake /₀ totalStake) ≥ t)
352+
else ⊤
368353
```
369354

370355
```agda
@@ -667,8 +652,20 @@ opaque
667652
Is-nothing? {x = x} = All.dec (const $ no id) x
668653
where import Data.Maybe.Relation.Unary.All as All
669654
655+
Is-just? : ∀ {A : Set} {x : Maybe A} → Dec (Is-just x)
656+
Is-just? {x = x} = Any.dec (const $ yes tt) x
657+
where import Data.Maybe.Relation.Unary.Any as Any
658+
670659
acceptedByCC? : ∀ Γ es st → Dec (acceptedByCC Γ es st)
671-
acceptedByCC? _ _ _ = _ ℚ.≤? _ ×-dec (_ ≥? _ ⊎-dec (Is-nothing? ×-dec ¿ _ ¿))
660+
acceptedByCC? Γ es st = d
661+
where
662+
open RatifyEnv Γ using (currentEpoch; ccHotKeys)
663+
module acbCC = AcceptedByCC currentEpoch ccHotKeys es st
664+
665+
d : Dec acbCC.accepted
666+
d with acbCC.mT
667+
... | just t = _ ≤? acbCC.sizeActiveCC ×-dec t ≤? _
668+
... | nothing = yes tt
672669
673670
acceptedByDRep? : ∀ Γ es st → Dec (acceptedByDRep Γ es st)
674671
acceptedByDRep? _ _ _ = _ ℚ.≤? _

0 commit comments

Comments
 (0)