Skip to content

Commit 699aab4

Browse files
committed
Add CDDLs
1 parent 99e49de commit 699aab4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+711
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,5 @@ cabal.project.local
9898
cabal.project.local~
9999
.HTF/
100100
.ghc.environment.*
101+
102+
ouroboros-consensus-cardano/cddl/out/

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "ledger-cddls"]
2+
path = ouroboros-consensus-cardano/cddl/ledger-cddls
3+
url = [email protected]:IntersectMBO/cardano-ledger
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
telescope7<byron, shelley, allegra, mary, alonzo, babbage, conway>
2+
= [pastEra, pastEra, pastEra, pastEra, pastEra, pastEra, currentEra<conway>] /
3+
[pastEra, pastEra, pastEra, pastEra, pastEra, currentEra<babbage>] /
4+
[pastEra, pastEra, pastEra, pastEra, currentEra<alonzo>] /
5+
[pastEra, pastEra, pastEra, currentEra<mary>] /
6+
[pastEra, pastEra, currentEra<allegra>] /
7+
[pastEra, currentEra<shelley>] /
8+
[currentEra<byron>]
9+
10+
ns7<byron, shelley, allegra, mary, alonzo, babbage, conway>
11+
= [6, conway] /
12+
[5, babbage] /
13+
[4, alonzo] /
14+
[3, mary] /
15+
[2, allegra] /
16+
[1, shelley] /
17+
[0, byron]
18+
19+
;; Blockchain types
20+
pastEra = [bound, bound]
21+
currentEra<st> = [bound, st]
22+
bound = [relativeTime, slotno, epochno]
23+
eraIdx = word8
24+
individualPoolStake = [stake, hash]
25+
nonce = [0] / [1, hash]
26+
point = [] / [ slotno, hash ]
27+
poolDistr = map<keyhash, individualPoolStake>
28+
slotno = word64
29+
stake = rational
30+
31+
withOrigin<v> = [] / [v]
32+
withOriginTH<v> = [0] / [1, v]
33+
34+
;; Collections
35+
either<x, y> = [0, x] / [1, y]
36+
map<x, y> = { * x => y }
37+
maybe<x> = [] / [x]
38+
seq<x> = [*23 x] / [24* x] ; encoded with indefinite-length encoding
39+
set<x> = #6.258([* x])
40+
41+
;; Types from other packages
42+
blockno = word64
43+
epochno = word64
44+
coin = word64
45+
rational = [int, int]
46+
keyhash = bstr .size 28
47+
hash = bstr .size 32
48+
relativeTime = int
49+
50+
;; Base word types
51+
word8 = uint .size 1
52+
word32 = unit .size 4
53+
word64 = unit .size 8
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
mkdir -p out
2+
3+
gen () {
4+
echo -n -e "\t- $1"
5+
mkdir -p out/$(echo $1 | rev | cut -d'/' -f2- | rev)
6+
cddlc -u2tcddl $1.cddl > "out/$1.compiled.cddl"
7+
echo " ok"
8+
}
9+
10+
CDDL_INCLUDE_PATH=""
11+
for f in $(fd -t d); do
12+
CDDL_INCLUDE_PATH+="$f:"
13+
done
14+
15+
export CDDL_INCLUDE_PATH=$CDDL_INCLUDE_PATH.:
16+
17+
IN=$(fd -e cddl \
18+
-E ledger-cddls \
19+
-E out \
20+
-E base.cddl \
21+
-E node-to-client/localstatequery/shelley \
22+
-E node-to-client/localstatequery/byron \
23+
-E node-to-client/localstatequery/consensus \
24+
-E disk/snapshot
25+
)
26+
27+
echo "Generating complete CDDLs:"
28+
for f in $IN; do
29+
gen $(echo $f | cut -d'.' -f1)
30+
done
31+
32+
UNDEFINEDS=$(grep -R undefined out)
33+
34+
if [ ! -z "$UNDEFINEDS" ]; then
35+
echo -e "\033[0;31mThere were undefined references!\n$UNDEFINEDS\033[0m"
36+
37+
while IFS= read -r line || [[ -n $line ]]; do
38+
fileName=$(echo $line | cut -d':' -f1)
39+
ref=$(echo $line | cut -d':' -f3 | tr -d ' ')
40+
echo "$ref = any" >> $fileName
41+
done < <(printf '%s' "$UNDEFINEDS")
42+
fi
43+
44+
echo "Done"
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
cardanoBlock = byron.block
2+
/ [2, shelley.block]
3+
/ [3, allegra.block]
4+
/ [4, mary.block]
5+
/ [5, alonzo.block]
6+
/ [6, babbage.block]
7+
/ [7, conway.block]
8+
9+
;# import byron as byron
10+
;# import shelley as shelley
11+
;# import allegra as allegra
12+
;# import mary as mary
13+
;# import alonzo as alonzo
14+
;# import babbage as babbage
15+
;# import conway as conway
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
ledgerStateSnapshot =
2+
[snapshotEncodingVersion1, extLedgerState]
3+
4+
snapshotEncodingVersion1 = 1
5+
6+
extLedgerState = [ledgerState, headerState]
7+
8+
;# import ledgerstate
9+
;# import headerstate
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
headerState =
2+
[withOrigin<headerStateTip>, headerStateChainDep]
3+
4+
headerStateTip =
5+
ns7<byronAnnTip, annTip, annTip, annTip, annTip, annTip, annTip>
6+
7+
byronAnnTip = [slotno, hash, blockno, bool]
8+
annTip = [slotno, hash, blockno]
9+
10+
headerStateChainDep =
11+
telescope7<versionedPbftState,
12+
versionedTPraosState,
13+
versionedTPraosState,
14+
versionedTPraosState,
15+
versionedTPraosState,
16+
versionedPraosState,
17+
versionedPraosState>
18+
19+
versionedPbftState = [serializationFormat1, {* keyhash => [* slotno]}]
20+
21+
;# import base
22+
;# import praos
23+
;# import tpraos
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
ledgerState =
2+
telescope7<byron.ledgerstate,
3+
versionedShelleyLedgerState<shelley.ledgerstate>,
4+
versionedShelleyLedgerState<allegra.ledgerstate>,
5+
versionedShelleyLedgerState<mary.ledgerstate>,
6+
versionedShelleyLedgerState<alonzo.ledgerstate>,
7+
versionedShelleyLedgerState<babbage.ledgerstate>,
8+
versionedShelleyLedgerState<conway.ledgerstate>>
9+
10+
versionedShelleyLedgerState<era> = [ shelleyVersion2, shelleyLedgerState<era> ]
11+
12+
shelleyVersion2 = 2
13+
14+
shelleyLedgerState<era> = [ withOrigin<shelleyTip>, era, shelleyTransition ]
15+
16+
shelleyTip = [slotno, blockno, hash]
17+
18+
shelleyTransition = word32
19+
20+
;# import base
21+
;# import byron as byron
22+
;# import shelley as shelley
23+
;# import allegra as allegra
24+
;# import mary as mary
25+
;# import alonzo as alonzo
26+
;# import babbage as babbage
27+
;# import conway as conway
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
versionedPraosState = [praosVersion, praosState]
2+
3+
praosVersion = 0
4+
5+
praosState = [withOrigin<slotno>,
6+
{* keyhash => word64},
7+
nonce,
8+
nonce,
9+
nonce,
10+
nonce,
11+
nonce]
12+
13+
;# import base
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
versionedTPraosState =
2+
[serializationFormat1, [withOriginTH<slotno>, tpraosState]]
3+
4+
tpraosState = [prtclState, ticknState, nonce]
5+
6+
prtclState = [{* keyhash => word64}, nonce, nonce]
7+
8+
ticknState = [nonce, nonce]
9+
10+
serializationFormat1 = 1
11+
12+
;# import base
Submodule ledger-cddls added at 29bf737
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
query = 0
2+
result = byron.upistate
3+
4+
;# import byron as byron
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
query = 2
2+
result = blockno
3+
4+
;# import base
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
query = 3
2+
result = point
3+
4+
;# import base
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
query = [1]
2+
result = eraIdx
3+
4+
;# import base
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
query = [0]
2+
result = maybe<bound>
3+
4+
;# import base
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
query = [0]
2+
result = interpreter
3+
4+
interpreter = [* eraSummary]
5+
eraSummary = [eraStart, eraEnd, eraParams]
6+
eraStart = bound
7+
eraEnd = null / bound
8+
eraParams = [epochSize, slotLength, safeZone, genesisWindow]
9+
epochSize = word64
10+
slotLength = int ; millisec
11+
safeZone = standardSafeZone / unsafeIndefiniteSafeZone
12+
standardSafeZone = [0, safeFromTip, safeBeforeEpoch]
13+
safeFromTip = word64
14+
safeBeforeEpoch = [0]
15+
unsafeIndefiniteSafeZone = [1]
16+
genesisWindow = word64
17+
18+
;# import base
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
query = 1
2+
result = utctime
3+
4+
utctime = [year, dayOfYear, timeOfDayPico]
5+
year = bigint
6+
dayOfYear = int
7+
timeOfDayPico = bigint
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
query = [0, blockQuery]
2+
/ [getSystemStart.query]
3+
/ [getChainBlockNo.query]
4+
/ [getChainPoint.query]
5+
6+
blockQuery = queryIfCurrent
7+
/ queryAnyTime
8+
/ queryHardFork
9+
10+
queryAnyTime = [1, getEraStart.query, eraIdx]
11+
12+
queryHardFork = [2, getInterpreter.query / getCurrentEra.query]
13+
14+
queryIfCurrent =
15+
[0, ns7<byronQuery,
16+
shelleyQuery,
17+
shelleyQuery,
18+
shelleyQuery,
19+
shelleyQuery,
20+
shelleyQuery,
21+
shelleyQuery>
22+
]
23+
24+
byronQuery = getUpdateInterfaceState.query
25+
26+
shelleyQuery = getLedgerTip.query
27+
/ getEpochNo.query
28+
/ getNonMyopicMemberRewards.query
29+
/ getCurrentPParams.query
30+
/ getProposedPParamsUpdates.query
31+
/ getStakeDistribution.query
32+
/ getUTxOByAddress.query
33+
/ getUTxOWhole.query
34+
/ debugEpochState.query
35+
/ getCBOR.query
36+
/ getFilteredDelegationsAndRewardAccounts.query
37+
/ getGenesisConfig.query
38+
/ debugNewEpochState.query
39+
/ debugChainDepState.query
40+
/ getRewardProvenance.query
41+
/ getUTxOByTxIn.query
42+
/ getStakePools.query
43+
/ getStakePoolParams.query
44+
/ getRewardInfoPools.query
45+
/ getPoolState.query
46+
/ getStakeSnapshots.query
47+
/ getPoolDistr.query
48+
/ getStakeDelegDeposits.query
49+
/ getConstitution.query
50+
/ getGovState.query
51+
/ getDRepState.query
52+
/ getDRepStakeDistr.query
53+
/ getCommitteeMembersState.query
54+
/ getFilteredVoteDelegatees.query
55+
/ getAccountState.query
56+
/ getSPOStakeDistr.query
57+
/ getProposals.query
58+
/ getRatifyState.query
59+
/ getFuturePParams.query
60+
/ getBigLedgerPeersSnapshot.query
61+
62+
getCBOR.query = [9, shelleyQuery]
63+
64+
;# include getSystemStart as getSystemStart
65+
;# include getChainBlockNo as getChainBlockNo
66+
;# include getChainPoint as getChainPoint
67+
;# include getEraStart as getEraStart
68+
;# include getInterpreter as getInterpreter
69+
;# include getCurrentEra as getCurrentEra
70+
;# include getUpdateInterfaceState as getUpdateInterfaceState
71+
;# include getLedgerTip as getLedgerTip
72+
;# include getEpochNo as getEpochNo
73+
;# include getNonMyopicMemberRewards as getNonMyopicMemberRewards
74+
;# include getCurrentPParams as getCurrentPParams
75+
;# include getProposedPParamsUpdates as getProposedPParamsUpdates
76+
;# include getStakeDistribution as getStakeDistribution
77+
;# include getUTxOByAddress as getUTxOByAddress
78+
;# include getUTxOWhole as getUTxOWhole
79+
;# include debugEpochState as debugEpochState
80+
;# include getFilteredDelegationsAndRewardAccounts as getFilteredDelegationsAndRewardAccounts
81+
;# include getGenesisConfig as getGenesisConfig
82+
;# include debugNewEpochState as debugNewEpochState
83+
;# include debugChainDepState as debugChainDepState
84+
;# include getRewardProvenance as getRewardProvenance
85+
;# include getUTxOByTxIn as getUTxOByTxIn
86+
;# include getStakePools as getStakePools
87+
;# include getStakePoolParams as getStakePoolParams
88+
;# include getRewardInfoPools as getRewardInfoPools
89+
;# include getPoolState as getPoolState
90+
;# include getStakeSnapshots as getStakeSnapshots
91+
;# include getPoolDistr as getPoolDistr
92+
;# include getStakeDelegDeposits as getStakeDelegDeposits
93+
;# include getConstitution as getConstitution
94+
;# include getGovState as getGovState
95+
;# include getDRepState as getDRepState
96+
;# include getDRepStakeDistr as getDRepStakeDistr
97+
;# include getCommitteeMembersState as getCommitteeMembersState
98+
;# include getFilteredVoteDelegatees as getFilteredVoteDelegatees
99+
;# include getAccountState as getAccountState
100+
;# include getSPOStakeDistr as getSPOStakeDistr
101+
;# include getProposals as getProposals
102+
;# include getRatifyState as getRatifyState
103+
;# include getFuturePParams as getFuturePParams
104+
;# include getBigLedgerPeersSnapshot as getBigLedgerPeersSnapshot
105+
;# import base

0 commit comments

Comments
 (0)