Skip to content

Commit 1dde7c2

Browse files
authored
Add NTN cddls (#1571)
# Description This PR contains the NTN cddls, which we check on CI that they are the same as in the blueprints. Golden files are checked against CDDL too in the test-suite, and the machinery for doing it with roundtrip tests is also ready but we can't use it due to input-output-hk/cuddle#79
2 parents d6eff84 + c1cbba6 commit 1dde7c2

File tree

40 files changed

+966
-98
lines changed

40 files changed

+966
-98
lines changed

.github/workflows/ci.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ jobs:
5555
steps:
5656
- uses: actions/checkout@v4
5757

58+
- name: Check CDDLs up-to-date with Blueprints
59+
continue-on-error: true
60+
run: |
61+
./scripts/ci/diff-cddls.sh
62+
5863
- name: Install base libraries
5964
uses: input-output-hk/actions/base@latest
6065
with:
@@ -138,6 +143,17 @@ jobs:
138143
- name: Build projects [build]
139144
run: cabal build all -j
140145

146+
- name: Install Ruby for CDDL
147+
uses: ruby/setup-ruby@v1
148+
with:
149+
ruby-version: '3.4'
150+
bundler-cache: true
151+
152+
- name: Install cddl tools
153+
run: |
154+
gem install cddlc
155+
cabal install cuddle-0.5.0.0
156+
141157
- name: Test
142158
if: matrix.test-set == 'all'
143159
run: cabal test all -j --test-show-details=streaming

nix/cddlc/Gemfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
source 'https://rubygems.org'
2+
gem 'cddlc'

nix/cddlc/Gemfile.lock

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
GEM
2+
remote: https://rubygems.org/
3+
specs:
4+
cddlc (0.4.2)
5+
neatjson (~> 0.10)
6+
treetop (~> 1)
7+
neatjson (0.10.5)
8+
polyglot (0.3.5)
9+
treetop (1.6.14)
10+
polyglot (~> 0.3)
11+
12+
PLATFORMS
13+
ruby
14+
15+
DEPENDENCIES
16+
cddlc
17+
18+
BUNDLED WITH
19+
2.6.2

nix/cddlc/gemset.nix

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{
2+
cddlc = {
3+
dependencies = [
4+
"neatjson"
5+
"treetop"
6+
];
7+
groups = [ "default" ];
8+
platforms = [ ];
9+
source = {
10+
remotes = [ "https://rubygems.org" ];
11+
sha256 = "1s3fbgd5yqgji162zsmlwnva1v1r3zc1qiyv6im7karv5f08r8m3";
12+
type = "gem";
13+
};
14+
version = "0.4.2";
15+
};
16+
neatjson = {
17+
groups = [ "default" ];
18+
platforms = [ ];
19+
source = {
20+
remotes = [ "https://rubygems.org" ];
21+
sha256 = "0wm1lq8yl6rzysh3wg6fa55w5534k6ppiz0qb7jyvdy582mk5i0s";
22+
type = "gem";
23+
};
24+
version = "0.10.5";
25+
};
26+
polyglot = {
27+
groups = [ "default" ];
28+
platforms = [ ];
29+
source = {
30+
remotes = [ "https://rubygems.org" ];
31+
sha256 = "1bqnxwyip623d8pr29rg6m8r0hdg08fpr2yb74f46rn1wgsnxmjr";
32+
type = "gem";
33+
};
34+
version = "0.3.5";
35+
};
36+
treetop = {
37+
dependencies = [ "polyglot" ];
38+
groups = [ "default" ];
39+
platforms = [ ];
40+
source = {
41+
remotes = [ "https://rubygems.org" ];
42+
sha256 = "1m5fqy7vq6y7bgxmw7jmk7y6pla83m16p7lb41lbqgg53j8x2cds";
43+
type = "gem";
44+
};
45+
version = "1.6.14";
46+
};
47+
}

nix/cddlc/package.nix

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{ lib
2+
, bundlerApp
3+
, bundlerUpdateScript
4+
}:
5+
6+
bundlerApp {
7+
pname = "cddlc";
8+
9+
gemdir = ./.;
10+
11+
exes = [ "cddlc" ];
12+
13+
passthru.updateScript = bundlerUpdateScript "cddlc";
14+
15+
meta = {
16+
description = "CDDL conversion utilities";
17+
homepage = "https://github.com/cabo/cddlc";
18+
license = lib.licenses.mit;
19+
maintainers = with lib.maintainers; [ amesgen ];
20+
platforms = lib.platforms.unix;
21+
mainProgram = "cddlc";
22+
};
23+
}

nix/haskell.nix

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,19 @@ let
3838
({ pkgs, lib, ... }: lib.mkIf pkgs.stdenv.hostPlatform.isWindows {
3939
# https://github.com/input-output-hk/haskell.nix/issues/2332
4040
packages.basement.configureFlags = [ "--hsc2hs-option=--cflag=-Wno-int-conversion" ];
41+
# We can't cross-compile the ruby gem `cddlc` so we decided to skip this
42+
# test on Windows in Hydra.
43+
packages.ouroboros-consensus-cardano.components.tests.cardano-test.preCheck = ''
44+
export DISABLE_CDDLC=1
45+
'';
46+
})
47+
({ pkgs, ... }: lib.mkIf (!pkgs.stdenv.hostPlatform.isWindows) {
48+
# Tools for CBOR/CDDL tests:
49+
packages.ouroboros-consensus-cardano.components.tests.cardano-test = {
50+
build-tools =
51+
[ pkgs.cddlc pkgs.cuddle ];
52+
extraSrcFiles = [ "cddl/**/*" ];
53+
};
4154
})
4255
];
4356
flake.variants = {

nix/shell.nix

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ hsPkgs.shellFor {
1616
pkgs.ghcid
1717
pkgs.xrefcheck
1818
pkgs.fourmolu
19+
pkgs.cuddle
20+
pkgs.cddlc
1921

2022
# release management
2123
pkgs.scriv

nix/tools.nix

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,18 @@ in
3838

3939
fourmolu = tool "fourmolu" "0.18.0.0" { };
4040

41+
cuddle = tool "cuddle" "git" {
42+
src = final.fetchFromGitHub {
43+
owner = "input-output-hk";
44+
repo = "cuddle";
45+
rev = "cuddle-0.5.0.0";
46+
hash = "sha256-06a9N1IAh0kKW/xPu1qiLK22HpXyARnipA1YJxY4jOQ=";
47+
};
48+
};
49+
50+
# remove once our nixpkgs contains https://github.com/NixOS/nixpkgs/pull/394873
51+
cddlc = final.callPackage ./cddlc/package.nix { };
52+
4153
haskellBuildUtils = prev.haskellBuildUtils.override {
4254
inherit (final.hsPkgs.args) compiler-nix-name;
4355
index-state = tool-index-state;
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 = uint .size 4
53+
word64 = uint .size 8
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
chunkFile = bytes .cborseq block.cardanoBlock
2+
3+
;# import block as block

0 commit comments

Comments
 (0)