Skip to content

Add NTC cddls #1518

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

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
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
16 changes: 16 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,22 @@ jobs:
- name: Build projects [build]
run: cabal build all -j

- name: Install cddlc
run: gem install cddlc

- name: Clone cuddle with validator
uses: actions/checkout
with:
repo: 'input-output-hk/cuddle'
ref: 'js/validator'
path: 'cuddle'

- name: Install cuddle
run: |
( cd $GITHUB_WORKSPACE/cuddle
cabal install --ignore-project exe:cuddle
)

- name: Test
if: matrix.test-set == 'all'
run: cabal test all -j --test-show-details=streaming
Expand Down
2 changes: 2 additions & 0 deletions nix/cddlc/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
source 'https://rubygems.org'
gem 'cddlc'
19 changes: 19 additions & 0 deletions nix/cddlc/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
GEM
remote: https://rubygems.org/
specs:
cddlc (0.4.2)
neatjson (~> 0.10)
treetop (~> 1)
neatjson (0.10.5)
polyglot (0.3.5)
treetop (1.6.14)
polyglot (~> 0.3)

PLATFORMS
ruby

DEPENDENCIES
cddlc

BUNDLED WITH
2.6.2
47 changes: 47 additions & 0 deletions nix/cddlc/gemset.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
cddlc = {
dependencies = [
"neatjson"
"treetop"
];
groups = [ "default" ];
platforms = [ ];
source = {
remotes = [ "https://rubygems.org" ];
sha256 = "1s3fbgd5yqgji162zsmlwnva1v1r3zc1qiyv6im7karv5f08r8m3";
type = "gem";
};
version = "0.4.2";
};
neatjson = {
groups = [ "default" ];
platforms = [ ];
source = {
remotes = [ "https://rubygems.org" ];
sha256 = "0wm1lq8yl6rzysh3wg6fa55w5534k6ppiz0qb7jyvdy582mk5i0s";
type = "gem";
};
version = "0.10.5";
};
polyglot = {
groups = [ "default" ];
platforms = [ ];
source = {
remotes = [ "https://rubygems.org" ];
sha256 = "1bqnxwyip623d8pr29rg6m8r0hdg08fpr2yb74f46rn1wgsnxmjr";
type = "gem";
};
version = "0.3.5";
};
treetop = {
dependencies = [ "polyglot" ];
groups = [ "default" ];
platforms = [ ];
source = {
remotes = [ "https://rubygems.org" ];
sha256 = "1m5fqy7vq6y7bgxmw7jmk7y6pla83m16p7lb41lbqgg53j8x2cds";
type = "gem";
};
version = "1.6.14";
};
}
23 changes: 23 additions & 0 deletions nix/cddlc/package.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{ lib
, bundlerApp
, bundlerUpdateScript
}:

bundlerApp {
pname = "cddlc";

gemdir = ./.;

exes = [ "cddlc" ];

passthru.updateScript = bundlerUpdateScript "cddlc";

meta = {
description = "CDDL conversion utilities";
homepage = "https://github.com/cabo/cddlc";
license = lib.licenses.mit;
maintainers = with lib.maintainers; [ amesgen ];
platforms = lib.platforms.unix;
mainProgram = "cddlc";
};
}
8 changes: 8 additions & 0 deletions nix/haskell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ let
extraSrcFiles = [ "golden/${n}/**/*" ];
}) [ "byron" "shelley" "cardano" ]);
}
({ pkgs, ... }: {
# Tools for CBOR/CDDL tests:
packages.ouroboros-consensus-cardano.components.tests.cardano-test = {
build-tools =
[ pkgs.cddlc pkgs.cuddle ];
extraSrcFiles = [ "cddl/**/*" ];
};
})
];
flake.variants = {
noAsserts = {
Expand Down
12 changes: 12 additions & 0 deletions nix/tools.nix
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,18 @@ in
compiler-nix-name = "ghc98";
};

cuddle = tool "cuddle" "git" {
src = final.fetchFromGitHub {
owner = "input-output-hk";
repo = "cuddle";
rev = "43050522b2c3326dc2bcb95a3fde852bce5bc729";
hash = "sha256-S3GJBmvBmnbdb7tD2Fq9FNr9Z8iuT/eWwRpRxq9is10=";
};
};

# remove once our nixpkgs contains https://github.com/NixOS/nixpkgs/pull/394873
cddlc = final.callPackage ./cddlc/package.nix { };

haskellBuildUtils = prev.haskellBuildUtils.override {
inherit (final.hsPkgs.args) compiler-nix-name;
index-state = tool-index-state;
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 = uint .size 4
word64 = uint .size 8
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
30 changes: 30 additions & 0 deletions ouroboros-consensus-cardano/cddl/disk/snapshot/ledgerstate.cddl
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
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

; TODO these should be imports from the ledger however they do not
; provide these definitions yet.
byron.ledgerstate = any
shelley.ledgerstate = any
allegra.ledgerstate = any
mary.ledgerstate = any
alonzo.ledgerstate = any
babbage.ledgerstate = any
conway.ledgerstate = any

;# import base
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