Skip to content

Draft local state query serialization tests #1501

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

Draft
wants to merge 15 commits into
base: js/cddls
Choose a base branch
from
Draft
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,5 @@ cabal.project.local
cabal.project.local~
.HTF/
.ghc.environment.*

ouroboros-consensus-cardano/cddl/out/
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "cardano-blueprint"]
path = cardano-blueprint
url = [email protected]:cardano-scaling/cardano-blueprint.git
39 changes: 39 additions & 0 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,42 @@ if impl (ghc >= 9.12)

-- https://github.com/kapralVV/Unique/issues/11
, Unique:hashable

source-repository-package
type: git
location: https://github.com/IntersectMBO/cardano-ledger
tag: d48965e0dc1a324f432f1ee01bc0cf2d60a8a702
--sha256: sha256-UFIQ1qinge1TMtqU2e0Nyjdpj42yj+lLKrpnXeqo1mI=
subdir:
eras/allegra/impl
eras/alonzo/impl
eras/alonzo/test-suite
eras/babbage/impl
eras/babbage/test-suite
eras/conway/impl
eras/conway/test-suite
eras/mary/impl
eras/shelley/impl
eras/shelley/test-suite
eras/shelley-ma/test-suite
libs/cardano-ledger-api
libs/cardano-ledger-core
libs/cardano-ledger-binary
libs/cardano-protocol-tpraos
libs/non-integral
libs/small-steps
libs/cardano-data
libs/set-algebra
libs/vector-map
eras/byron/chain/executable-spec
eras/byron/ledger/executable-spec
eras/byron/ledger/impl
eras/byron/crypto

allow-newer:
ouroboros-consensus:cardano-ledger-core,
ouroboros-consensus-cardano:cardano-ledger-byron,
ouroboros-consensus-cardano:cardano-ledger-conway,
ouroboros-consensus-cardano:cardano-ledger-core,
ouroboros-consensus-cardano:cardano-ledger-shelley,
ouroboros-consensus-protocol:cardano-ledger-core,
1 change: 1 addition & 0 deletions cardano-blueprint
Submodule cardano-blueprint added at 9a6019
3 changes: 3 additions & 0 deletions nix/shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ hsPkgs.shellFor {
pkgs.ghcid
pkgs.xrefcheck

# testing cddls
pkgs.cddl

# release management
pkgs.scriv
(pkgs.python3.withPackages (p: [ p.beautifulsoup4 p.html5lib p.matplotlib p.pandas ]))
Expand Down
53 changes: 53 additions & 0 deletions ouroboros-consensus-cardano/cddl/base.cddl
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
telescope7<byron, shelley, allegra, mary, alonzo, babbage, conway>
= [pastEra, pastEra, pastEra, pastEra, pastEra, pastEra, currentEra<conway>] /
[pastEra, pastEra, pastEra, pastEra, pastEra, currentEra<babbage>] /
[pastEra, pastEra, pastEra, pastEra, currentEra<alonzo>] /
[pastEra, pastEra, pastEra, currentEra<mary>] /
[pastEra, pastEra, currentEra<allegra>] /
[pastEra, currentEra<shelley>] /
[currentEra<byron>]

ns7<byron, shelley, allegra, mary, alonzo, babbage, conway>
= [6, conway] /
[5, babbage] /
[4, alonzo] /
[3, mary] /
[2, allegra] /
[1, shelley] /
[0, byron]

;; Blockchain types
pastEra = [bound, bound]
currentEra<st> = [bound, st]
bound = [relativeTime, slotno, epochno]
eraIdx = word8
individualPoolStake = [stake, hash]
nonce = [0] / [1, hash]
point = [] / [ slotno, hash ]
poolDistr = map<keyhash, individualPoolStake>
slotno = word64
stake = rational

withOrigin<v> = [] / [v]
withOriginTH<v> = [0] / [1, v]

;; Collections
either<x, y> = [0, x] / [1, y]
map<x, y> = { * x => y }
maybe<x> = [] / [x]
seq<x> = [*23 x] / [24* x] ; encoded with indefinite-length encoding
set<x> = #6.258([* x])

;; Types from other packages
blockno = word64
epochno = word64
coin = word64
rational = [int, int]
keyhash = bstr .size 28
hash = bstr .size 32
relativeTime = int

;; Base word types
word8 = uint .size 1
word32 = unit .size 4
word64 = unit .size 8
44 changes: 44 additions & 0 deletions ouroboros-consensus-cardano/cddl/cddlc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
mkdir -p out

gen () {
echo -n -e "\t- $1"
mkdir -p out/$(echo $1 | rev | cut -d'/' -f2- | rev)
cddlc -u2tcddl $1.cddl > "out/$1.compiled.cddl"
echo " ok"
}

CDDL_INCLUDE_PATH=""
for f in $(fd -t d); do
CDDL_INCLUDE_PATH+="$f:"
done

export CDDL_INCLUDE_PATH=$CDDL_INCLUDE_PATH.:

IN=$(fd -e cddl \
-E ledger-cddls \
-E out \
-E base.cddl \
-E node-to-client/localstatequery/shelley \
-E node-to-client/localstatequery/byron \
-E node-to-client/localstatequery/consensus \
-E disk/snapshot
)

echo "Generating complete CDDLs:"
for f in $IN; do
gen $(echo $f | cut -d'.' -f1)
done

UNDEFINEDS=$(grep -R undefined out)

if [ ! -z "$UNDEFINEDS" ]; then
echo -e "\033[0;31mThere were undefined references!\n$UNDEFINEDS\033[0m"

while IFS= read -r line || [[ -n $line ]]; do
fileName=$(echo $line | cut -d':' -f1)
ref=$(echo $line | cut -d':' -f3 | tr -d ' ')
echo "$ref = any" >> $fileName
done < <(printf '%s' "$UNDEFINEDS")
fi

echo "Done"
15 changes: 15 additions & 0 deletions ouroboros-consensus-cardano/cddl/disk/block.cddl
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
cardanoBlock = byron.block
/ [2, shelley.block]
/ [3, allegra.block]
/ [4, mary.block]
/ [5, alonzo.block]
/ [6, babbage.block]
/ [7, conway.block]

;# import byron as byron
;# import shelley as shelley
;# import allegra as allegra
;# import mary as mary
;# import alonzo as alonzo
;# import babbage as babbage
;# import conway as conway
9 changes: 9 additions & 0 deletions ouroboros-consensus-cardano/cddl/disk/snapshot.cddl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
ledgerStateSnapshot =
[snapshotEncodingVersion1, extLedgerState]

snapshotEncodingVersion1 = 1

extLedgerState = [ledgerState, headerState]

;# import ledgerstate
;# import headerstate
23 changes: 23 additions & 0 deletions ouroboros-consensus-cardano/cddl/disk/snapshot/headerstate.cddl
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
headerState =
[withOrigin<headerStateTip>, headerStateChainDep]

headerStateTip =
ns7<byronAnnTip, annTip, annTip, annTip, annTip, annTip, annTip>

byronAnnTip = [slotno, hash, blockno, bool]
annTip = [slotno, hash, blockno]

headerStateChainDep =
telescope7<versionedPbftState,
versionedTPraosState,
versionedTPraosState,
versionedTPraosState,
versionedTPraosState,
versionedPraosState,
versionedPraosState>

versionedPbftState = [serializationFormat1, {* keyhash => [* slotno]}]

;# import base
;# import praos
;# import tpraos
27 changes: 27 additions & 0 deletions ouroboros-consensus-cardano/cddl/disk/snapshot/ledgerstate.cddl
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
ledgerState =
telescope7<byron.ledgerstate,
versionedShelleyLedgerState<shelley.ledgerstate>,
versionedShelleyLedgerState<allegra.ledgerstate>,
versionedShelleyLedgerState<mary.ledgerstate>,
versionedShelleyLedgerState<alonzo.ledgerstate>,
versionedShelleyLedgerState<babbage.ledgerstate>,
versionedShelleyLedgerState<conway.ledgerstate>>

versionedShelleyLedgerState<era> = [ shelleyVersion2, shelleyLedgerState<era> ]

shelleyVersion2 = 2

shelleyLedgerState<era> = [ withOrigin<shelleyTip>, era, shelleyTransition ]

shelleyTip = [slotno, blockno, hash]

shelleyTransition = word32

;# import base
;# import byron as byron
;# import shelley as shelley
;# import allegra as allegra
;# import mary as mary
;# import alonzo as alonzo
;# import babbage as babbage
;# import conway as conway
13 changes: 13 additions & 0 deletions ouroboros-consensus-cardano/cddl/disk/snapshot/praos.cddl
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
versionedPraosState = [praosVersion, praosState]

praosVersion = 0

praosState = [withOrigin<slotno>,
{* keyhash => word64},
nonce,
nonce,
nonce,
nonce,
nonce]

;# import base
12 changes: 12 additions & 0 deletions ouroboros-consensus-cardano/cddl/disk/snapshot/tpraos.cddl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
versionedTPraosState =
[serializationFormat1, [withOriginTH<slotno>, tpraosState]]

tpraosState = [prtclState, ticknState, nonce]

prtclState = [{* keyhash => word64}, nonce, nonce]

ticknState = [nonce, nonce]

serializationFormat1 = 1

;# import base
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
query = 0
result = byron.upistate

;# import byron as byron
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
query = 2
result = blockno

;# import base
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
query = 3
result = point

;# import base
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
query = [1]
result = eraIdx

;# import base
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
query = [0]
result = maybe<bound>

;# import base
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
query = [0]
result = interpreter

interpreter = [* eraSummary]
eraSummary = [eraStart, eraEnd, eraParams]
eraStart = bound
eraEnd = null / bound
eraParams = [epochSize, slotLength, safeZone, genesisWindow]
epochSize = word64
slotLength = int ; millisec
safeZone = standardSafeZone / unsafeIndefiniteSafeZone
standardSafeZone = [0, safeFromTip, safeBeforeEpoch]
safeFromTip = word64
safeBeforeEpoch = [0]
unsafeIndefiniteSafeZone = [1]
genesisWindow = word64

;# import base
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
query = 1
result = utctime

utctime = [year, dayOfYear, timeOfDayPico]
year = bigint
dayOfYear = int
timeOfDayPico = bigint
Loading
Loading