Skip to content
Closed
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: 1 addition & 1 deletion .github/workflows/haskell-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ jobs:
uses: actions/checkout@v4
with:
repository: tweag/CIPs
ref: 79ab917054f8398af4f81c0404b3a8bf698f06d5
ref: 9a9041f440d50888f224c0c62ffe6229e6bfaa20
path: cips
- name: set env for reference CDDL
run: |
Expand Down
8 changes: 4 additions & 4 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
inputs.nixpkgs.follows = "nixpkgs";
};
inputs.cips = {
url = "github:tweag/CIPs/snapshot-update";
url = "github:tweag/CIPs/accounts";
flake = false;
};
outputs =
Expand Down
8 changes: 7 additions & 1 deletion scls-cardano/cddl-src/Cardano/SCLS/CDDL.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module Cardano.SCLS.CDDL (
knownNamespaces,
) where

import Cardano.SCLS.Namespace.Accounts qualified as Accounts
import Cardano.SCLS.Namespace.Blocks qualified as Blocks
import Cardano.SCLS.Namespace.GovCommittee qualified as GovCommittee
import Cardano.SCLS.Namespace.GovConstitution qualified as GovConstitution
Expand All @@ -33,6 +34,9 @@ namespaceSymbolFromText :: Text -> Maybe SomeNamespaceSymbol
namespaceSymbolFromText t =
find (\ns -> T.pack (toString ns) == t) knownNamespaces

instance KnownSpec "accounts/v0" where
namespaceSpec _ = mkDefinition Accounts.record_entry

instance KnownSpec "utxo/v0" where
namespaceSpec _ = mkDefinition UTxO.record_entry

Expand Down Expand Up @@ -72,7 +76,8 @@ knownNamespaceKeySizes =

knownNamespaces :: [SomeNamespaceSymbol]
knownNamespaces =
[ mkNamespaceSymbol @"utxo/v0"
[ mkNamespaceSymbol @"accounts/v0"
, mkNamespaceSymbol @"utxo/v0"
, mkNamespaceSymbol @"blocks/v0"
, mkNamespaceSymbol @"snapshots/mark/v0"
, mkNamespaceSymbol @"snapshots/set/v0"
Expand All @@ -84,6 +89,7 @@ knownNamespaces =
, mkNamespaceSymbol @"gov/proposals/v0"
]

type instance Spec.NamespaceKeySize "accounts/v0" = 1
type instance Spec.NamespaceKeySize "utxo/v0" = 34
type instance Spec.NamespaceKeySize "blocks/v0" = 36 -- 28 bytes for key, and 8 for epoch in BE
type instance Spec.NamespaceKeySize "nonces/v0" = 1 -- Just zero
Expand Down
3 changes: 3 additions & 0 deletions scls-cardano/cddl-src/Cardano/SCLS/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ int64 = "int64" =:= toInteger (minBound @Int64) ... toInteger (maxBound @Int64)
word64 :: Rule
word64 = "word64" =:= VUInt `sized` (8 :: Word)

word64_non_zero :: Rule
word64_non_zero = "word64_non_zero" =:= (1 :: Integer) ... toInteger (maxBound @Word64)
Comment thread
qnikst marked this conversation as resolved.

-------------------------------------------------------------------------------
-- Utility
--------------------------------------------------------------------------------
Expand Down
116 changes: 116 additions & 0 deletions scls-cardano/cddl-src/Cardano/SCLS/Namespace/Accounts.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
{-# LANGUAGE ImportQualifiedPost #-}
{-# LANGUAGE OverloadedLists #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -Wno-unrecognised-pragmas #-}

{-# HLINT ignore "Use camelCase" #-}
module Cardano.SCLS.Namespace.Accounts where

import Cardano.SCLS.Common
import Codec.CBOR.Cuddle.Huddle
import Text.Heredoc (str)
import Prelude (($))

record_entry :: Rule
record_entry =
comment
[str| The key for the entry is one of the following:
|
| ```
| meta:
| endian: be
|
| seq:
| - id: key
| type: section
|
| types:
| section:
| seq:
| - id: section_type
| type: u1
| enum: accounts_section
| enums:
| accounts_section:
| 0: dstate
| 1: pstate
| ```
|]
$ "record_entry" =:= accounts_out

accounts_out :: Rule
accounts_out =
comment
[str| Information about accounts in the ledger state |]
$ "accounts_out"
=:= mp ["dstate" ==> dstate, "pstate" ==> pstate]

pstate :: Rule
pstate =
"pstate"
=:= mp
[ "retiring" ==> mp [0 <+ asKey pool_keyhash ==> epoch_no]
, "vrf_key_hashes" ==> mp [0 <+ asKey vrf_keyhash ==> word64_non_zero]
, "future_stake_pool_params" ==> mp [0 <+ asKey pool_keyhash ==> pool_params]
]

dstate :: Rule
dstate =
"dstate"
=:= mp
[ "delegation_map" ==> mp [0 <+ asKey vkey_genesis ==> vkey]
, "last_delegation" ==> mp [0 <+ asKey vkey_genesis ==> slot_no]
]

vkey_genesis :: Rule
vkey_genesis = "vkey_genesis" =:= int64

pool_params :: Rule
pool_params =
"pool_params"
=:= mp
[ "cost" ==> coin
, "margin" ==> unit_interval
, "pledge" ==> coin
, "relays" ==> arr [0 <+ a relay]
, "operator" ==> pool_keyhash
, "pool_owners" ==> set addr_keyhash
, "vrf_keyhash" ==> vrf_keyhash
, "pool_metadata" ==> (pool_metadata / VNil)
, "reward_account" ==> reward_account
]

relay :: Rule
relay =
"relay"
=:= sarr [0, a single_host_addr]
/ sarr [1, a single_host_name]
/ sarr [2, a multi_host_name]

single_host_addr :: GroupDef
single_host_addr =
comment [str| A single host address relay |] $
"single_host_addr"
=:~ grp
[ a (port / VNil)
, a (ipv4 / VNil)
, a (ipv6 / VNil)
]

single_host_name :: GroupDef
single_host_name =
"single_host_name"
=:~ grp [a (port / VNil), a dns_name]

multi_host_name :: GroupDef
multi_host_name =
"multi_host_name" =:~ grp [a dns_name]

pool_metadata :: Rule
pool_metadata = "pool_metadata" =:= arr [a url, a pool_metadata_hash]

pool_metadata_hash :: Rule
pool_metadata_hash = "pool_metadata_hash" =:= VBytes
1 change: 1 addition & 0 deletions scls-cardano/scls-cardano.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ library

other-modules:
Cardano.SCLS.Common
Cardano.SCLS.Namespace.Accounts
Cardano.SCLS.Namespace.Blocks
Cardano.SCLS.Namespace.GovCommittee
Cardano.SCLS.Namespace.GovConstitution
Expand Down
3 changes: 2 additions & 1 deletion scls-cardano/test/Reference.hs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ loadReferenceCDDL path namespace = do
allReferenceCDDLs :: [(Text, FilePath)]
allReferenceCDDLs =
-- This should match the CDDL files listed in CIP-0165
[ ("utxo/v0", "utxo_v0.cddl")
[ ("accounts/v0", "accounts_v0.cddl")
, ("utxo/v0", "utxo_v0.cddl")
, ("blocks/v0", "blocks_v0.cddl")
, ("snapshots/mark/v0", "snapshots_mark_v0.cddl")
, ("snapshots/set/v0", "snapshots_set_v0.cddl")
Expand Down
4 changes: 3 additions & 1 deletion scls-cardano/testlib/Cardano/SCLS/Testlib.hs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ type ConstrNS a = (KnownNamespace a, Arbitrary (NamespaceEntry a), Eq (Namespace

-- | Test all supported NS for conformance with SCLS.
testAllNS ::
( ConstrNS "blocks/v0"
( ConstrNS "accounts/v0"
, ConstrNS "blocks/v0"
, ConstrNS "utxo/v0"
, ConstrNS "snapshots/go/v0"
Comment thread
qnikst marked this conversation as resolved.
, ConstrNS "snapshots/mark/v0"
Expand All @@ -62,6 +63,7 @@ testAllNS ::
) =>
Spec
testAllNS = describe "scls/conformance" $ do
testNS @"accounts/v0"
testNS @"blocks/v0"
testNS @"utxo/v0"
testNS @"snapshots/go/v0"
Expand Down
Loading