From a3800ab77a7d0af6629882988ded2e87b0ce5dcf Mon Sep 17 00:00:00 2001 From: Aurora Gaffney Date: Sun, 29 Sep 2024 16:22:34 -0500 Subject: [PATCH] feat: support for loading cardano-node and genesis configs This commit also includes the upstream cardano-node and genesis config files for the preview network --- Dockerfile | 2 + config.go | 10 + config/cardano/node.go | 107 +++++++ config/cardano/node_test.go | 87 ++++++ config/cardano/testdata | 1 + configs/cardano/preview/alonzo-genesis.json | 196 ++++++++++++ configs/cardano/preview/byron-genesis.json | 117 ++++++++ configs/cardano/preview/config.json | 114 +++++++ configs/cardano/preview/conway-genesis.json | 297 +++++++++++++++++++ configs/cardano/preview/shelley-genesis.json | 68 +++++ go.mod | 1 + go.sum | 8 + internal/config/config.go | 22 +- internal/node/node.go | 10 + 14 files changed, 1030 insertions(+), 10 deletions(-) create mode 100644 config/cardano/node.go create mode 100644 config/cardano/node_test.go create mode 120000 config/cardano/testdata create mode 100644 configs/cardano/preview/alonzo-genesis.json create mode 100644 configs/cardano/preview/byron-genesis.json create mode 100644 configs/cardano/preview/config.json create mode 100644 configs/cardano/preview/conway-genesis.json create mode 100644 configs/cardano/preview/shelley-genesis.json diff --git a/Dockerfile b/Dockerfile index 50ce327..647efa4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,4 +8,6 @@ RUN make build FROM debian:bookworm-slim AS node COPY --from=build /code/node /bin/ +COPY ./configs/cardano /opt/cardano/config +ENV CARDANO_CONFIG=/opt/cardano/config/preview/config.json ENTRYPOINT ["node"] diff --git a/config.go b/config.go index e2c9980..deffb3e 100644 --- a/config.go +++ b/config.go @@ -19,6 +19,7 @@ import ( "io" "log/slog" + "github.com/blinklabs-io/node/config/cardano" "github.com/blinklabs-io/node/topology" ouroboros "github.com/blinklabs-io/gouroboros" @@ -27,6 +28,7 @@ import ( ) type Config struct { + cardanoNodeConfig *cardano.CardanoNodeConfig dataDir string intersectPoints []ocommon.Point intersectTip bool @@ -98,6 +100,14 @@ func NewConfig(opts ...ConfigOptionFunc) Config { return c } +// WithCardanoNodeConfig specifies the CardanoNodeConfig object to use. This is mostly used for loading genesis config files +// referenced by the node config +func WithCardanoNodeConfig(cardanoNodeConfig *cardano.CardanoNodeConfig) ConfigOptionFunc { + return func(c *Config) { + c.cardanoNodeConfig = cardanoNodeConfig + } +} + // WithDataDir specifies the persistent data directory to use. The default is to store everything in memory func WithDataDir(dataDir string) ConfigOptionFunc { return func(c *Config) { diff --git a/config/cardano/node.go b/config/cardano/node.go new file mode 100644 index 0000000..bc52762 --- /dev/null +++ b/config/cardano/node.go @@ -0,0 +1,107 @@ +// Copyright 2024 Blink Labs Software +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package cardano + +import ( + "io" + "os" + "path" + + "github.com/blinklabs-io/gouroboros/ledger/alonzo" + "github.com/blinklabs-io/gouroboros/ledger/byron" + "github.com/blinklabs-io/gouroboros/ledger/conway" + "github.com/blinklabs-io/gouroboros/ledger/shelley" + "gopkg.in/yaml.v3" +) + +// CardanoNodeConfig represents the config.json/yaml file used by cardano-node +type CardanoNodeConfig struct { + path string + AlonzoGenesisFile string `yaml:"AlonzoGenesisFile"` + AlonzoGenesisHash string `yaml:"AlonzoGenesisHash"` + ByronGenesisFile string `yaml:"ByronGenesisFile"` + ByronGenesisHash string `yaml:"ByronGenesisHash"` + ConwayGenesisFile string `yaml:"ConwayGenesisFile"` + ConwayGenesisHash string `yaml:"ConwayGenesisHash"` + ShelleyGenesisFile string `yaml:"ShelleyGenesisFile"` + ShelleyGenesisHash string `yaml:"ShelleyGenesisHash"` + // TODO: add more fields from cardano-node config as we need them +} + +func NewCardanoNodeConfigFromReader(r io.Reader) (*CardanoNodeConfig, error) { + var ret CardanoNodeConfig + dec := yaml.NewDecoder(r) + if err := dec.Decode(&ret); err != nil { + return nil, err + } + return &ret, nil +} + +func NewCardanoNodeConfigFromFile(file string) (*CardanoNodeConfig, error) { + f, err := os.Open(file) + if err != nil { + return nil, err + } + c, err := NewCardanoNodeConfigFromReader(f) + if err != nil { + return nil, err + } + c.path = path.Dir(file) + return c, nil +} + +// ByronGenesis loads and returns the Byron genesis config specified in the node config +func (c *CardanoNodeConfig) ByronGenesis() (*byron.ByronGenesis, error) { + tmpPath := path.Join(c.path, c.ByronGenesisFile) + // TODO: check genesis file hash + ret, err := byron.NewByronGenesisFromFile(tmpPath) + if err != nil { + return nil, err + } + return &ret, err +} + +// ShelleyGenesis loads and returns the Shelley genesis config specified in the node config +func (c *CardanoNodeConfig) ShelleyGenesis() (*shelley.ShelleyGenesis, error) { + tmpPath := path.Join(c.path, c.ShelleyGenesisFile) + // TODO: check genesis file hash + ret, err := shelley.NewShelleyGenesisFromFile(tmpPath) + if err != nil { + return nil, err + } + return &ret, err +} + +// AlonzoGenesis loads and returns the Alonzo genesis config specified in the node config +func (c *CardanoNodeConfig) AlonzoGenesis() (*alonzo.AlonzoGenesis, error) { + tmpPath := path.Join(c.path, c.AlonzoGenesisFile) + // TODO: check genesis file hash + ret, err := alonzo.NewAlonzoGenesisFromFile(tmpPath) + if err != nil { + return nil, err + } + return &ret, err +} + +// ConwayGenesis loads and returns the Conway genesis config specified in the node config +func (c *CardanoNodeConfig) ConwayGenesis() (*conway.ConwayGenesis, error) { + tmpPath := path.Join(c.path, c.ConwayGenesisFile) + // TODO: check genesis file hash + ret, err := conway.NewConwayGenesisFromFile(tmpPath) + if err != nil { + return nil, err + } + return &ret, err +} diff --git a/config/cardano/node_test.go b/config/cardano/node_test.go new file mode 100644 index 0000000..d05f6d7 --- /dev/null +++ b/config/cardano/node_test.go @@ -0,0 +1,87 @@ +// Copyright 2024 Blink Labs Software +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package cardano + +import ( + "path" + "reflect" + "testing" +) + +const ( + testDataDir = "testdata" +) + +var expectedCardanoNodeConfig = &CardanoNodeConfig{ + path: testDataDir, + AlonzoGenesisFile: "alonzo-genesis.json", + AlonzoGenesisHash: "7e94a15f55d1e82d10f09203fa1d40f8eede58fd8066542cf6566008068ed874", + ByronGenesisFile: "byron-genesis.json", + ByronGenesisHash: "83de1d7302569ad56cf9139a41e2e11346d4cb4a31c00142557b6ab3fa550761", + ConwayGenesisFile: "conway-genesis.json", + ConwayGenesisHash: "9cc5084f02e27210eacba47af0872e3dba8946ad9460b6072d793e1d2f3987ef", + ShelleyGenesisFile: "shelley-genesis.json", + ShelleyGenesisHash: "363498d1024f84bb39d3fa9593ce391483cb40d479b87233f868d6e57c3a400d", +} + +func TestCardanoNodeConfig(t *testing.T) { + tmpPath := path.Join( + testDataDir, + "config.json", + ) + cfg, err := NewCardanoNodeConfigFromFile(tmpPath) + if err != nil { + t.Fatalf("unexpected error: %s", err) + } + if !reflect.DeepEqual(cfg, expectedCardanoNodeConfig) { + t.Fatalf("did not get expected object\n got: %#v\n wanted: %#v\n", cfg, expectedCardanoNodeConfig) + } + t.Run("Byron genesis", func(t *testing.T) { + g, err := cfg.ByronGenesis() + if err != nil { + t.Fatalf("unexpected error: %s", err) + } + if g == nil { + t.Fatalf("got nil instead of ByronGenesis") + } + }) + t.Run("Shelley genesis", func(t *testing.T) { + g, err := cfg.ShelleyGenesis() + if err != nil { + t.Fatalf("unexpected error: %s", err) + } + if g == nil { + t.Fatalf("got nil instead of ShelleyGenesis") + } + }) + t.Run("Alonzo genesis", func(t *testing.T) { + g, err := cfg.AlonzoGenesis() + if err != nil { + t.Fatalf("unexpected error: %s", err) + } + if g == nil { + t.Fatalf("got nil instead of AlonzoGenesis") + } + }) + t.Run("Conway genesis", func(t *testing.T) { + g, err := cfg.ConwayGenesis() + if err != nil { + t.Fatalf("unexpected error: %s", err) + } + if g == nil { + t.Fatalf("got nil instead of ConwayGenesis") + } + }) +} diff --git a/config/cardano/testdata b/config/cardano/testdata new file mode 120000 index 0000000..1fed4ef --- /dev/null +++ b/config/cardano/testdata @@ -0,0 +1 @@ +../../configs/cardano/preview \ No newline at end of file diff --git a/configs/cardano/preview/alonzo-genesis.json b/configs/cardano/preview/alonzo-genesis.json new file mode 100644 index 0000000..0fd90de --- /dev/null +++ b/configs/cardano/preview/alonzo-genesis.json @@ -0,0 +1,196 @@ +{ + "lovelacePerUTxOWord": 34482, + "executionPrices": { + "prSteps": + { + "numerator" : 721, + "denominator" : 10000000 + }, + "prMem": + { + "numerator" : 577, + "denominator" : 10000 + } + }, + "maxTxExUnits": { + "exUnitsMem": 10000000, + "exUnitsSteps": 10000000000 + }, + "maxBlockExUnits": { + "exUnitsMem": 50000000, + "exUnitsSteps": 40000000000 + }, + "maxValueSize": 5000, + "collateralPercentage": 150, + "maxCollateralInputs": 3, + "costModels": { + "PlutusV1": { + "sha2_256-memory-arguments": 4, + "equalsString-cpu-arguments-constant": 1000, + "cekDelayCost-exBudgetMemory": 100, + "lessThanEqualsByteString-cpu-arguments-intercept": 103599, + "divideInteger-memory-arguments-minimum": 1, + "appendByteString-cpu-arguments-slope": 621, + "blake2b-cpu-arguments-slope": 29175, + "iData-cpu-arguments": 150000, + "encodeUtf8-cpu-arguments-slope": 1000, + "unBData-cpu-arguments": 150000, + "multiplyInteger-cpu-arguments-intercept": 61516, + "cekConstCost-exBudgetMemory": 100, + "nullList-cpu-arguments": 150000, + "equalsString-cpu-arguments-intercept": 150000, + "trace-cpu-arguments": 150000, + "mkNilData-memory-arguments": 32, + "lengthOfByteString-cpu-arguments": 150000, + "cekBuiltinCost-exBudgetCPU": 29773, + "bData-cpu-arguments": 150000, + "subtractInteger-cpu-arguments-slope": 0, + "unIData-cpu-arguments": 150000, + "consByteString-memory-arguments-intercept": 0, + "divideInteger-memory-arguments-slope": 1, + "divideInteger-cpu-arguments-model-arguments-slope": 118, + "listData-cpu-arguments": 150000, + "headList-cpu-arguments": 150000, + "chooseData-memory-arguments": 32, + "equalsInteger-cpu-arguments-intercept": 136542, + "sha3_256-cpu-arguments-slope": 82363, + "sliceByteString-cpu-arguments-slope": 5000, + "unMapData-cpu-arguments": 150000, + "lessThanInteger-cpu-arguments-intercept": 179690, + "mkCons-cpu-arguments": 150000, + "appendString-memory-arguments-intercept": 0, + "modInteger-cpu-arguments-model-arguments-slope": 118, + "ifThenElse-cpu-arguments": 1, + "mkNilPairData-cpu-arguments": 150000, + "lessThanEqualsInteger-cpu-arguments-intercept": 145276, + "addInteger-memory-arguments-slope": 1, + "chooseList-memory-arguments": 32, + "constrData-memory-arguments": 32, + "decodeUtf8-cpu-arguments-intercept": 150000, + "equalsData-memory-arguments": 1, + "subtractInteger-memory-arguments-slope": 1, + "appendByteString-memory-arguments-intercept": 0, + "lengthOfByteString-memory-arguments": 4, + "headList-memory-arguments": 32, + "listData-memory-arguments": 32, + "consByteString-cpu-arguments-intercept": 150000, + "unIData-memory-arguments": 32, + "remainderInteger-memory-arguments-minimum": 1, + "bData-memory-arguments": 32, + "lessThanByteString-cpu-arguments-slope": 248, + "encodeUtf8-memory-arguments-intercept": 0, + "cekStartupCost-exBudgetCPU": 100, + "multiplyInteger-memory-arguments-intercept": 0, + "unListData-memory-arguments": 32, + "remainderInteger-cpu-arguments-model-arguments-slope": 118, + "cekVarCost-exBudgetCPU": 29773, + "remainderInteger-memory-arguments-slope": 1, + "cekForceCost-exBudgetCPU": 29773, + "sha2_256-cpu-arguments-slope": 29175, + "equalsInteger-memory-arguments": 1, + "indexByteString-memory-arguments": 1, + "addInteger-memory-arguments-intercept": 1, + "chooseUnit-cpu-arguments": 150000, + "sndPair-cpu-arguments": 150000, + "cekLamCost-exBudgetCPU": 29773, + "fstPair-cpu-arguments": 150000, + "quotientInteger-memory-arguments-minimum": 1, + "decodeUtf8-cpu-arguments-slope": 1000, + "lessThanInteger-memory-arguments": 1, + "lessThanEqualsInteger-cpu-arguments-slope": 1366, + "fstPair-memory-arguments": 32, + "modInteger-memory-arguments-intercept": 0, + "unConstrData-cpu-arguments": 150000, + "lessThanEqualsInteger-memory-arguments": 1, + "chooseUnit-memory-arguments": 32, + "sndPair-memory-arguments": 32, + "addInteger-cpu-arguments-intercept": 197209, + "decodeUtf8-memory-arguments-slope": 8, + "equalsData-cpu-arguments-intercept": 150000, + "mapData-cpu-arguments": 150000, + "mkPairData-cpu-arguments": 150000, + "quotientInteger-cpu-arguments-constant": 148000, + "consByteString-memory-arguments-slope": 1, + "cekVarCost-exBudgetMemory": 100, + "indexByteString-cpu-arguments": 150000, + "unListData-cpu-arguments": 150000, + "equalsInteger-cpu-arguments-slope": 1326, + "cekStartupCost-exBudgetMemory": 100, + "subtractInteger-cpu-arguments-intercept": 197209, + "divideInteger-cpu-arguments-model-arguments-intercept": 425507, + "divideInteger-memory-arguments-intercept": 0, + "cekForceCost-exBudgetMemory": 100, + "blake2b-cpu-arguments-intercept": 2477736, + "remainderInteger-cpu-arguments-constant": 148000, + "tailList-cpu-arguments": 150000, + "encodeUtf8-cpu-arguments-intercept": 150000, + "equalsString-cpu-arguments-slope": 1000, + "lessThanByteString-memory-arguments": 1, + "multiplyInteger-cpu-arguments-slope": 11218, + "appendByteString-cpu-arguments-intercept": 396231, + "lessThanEqualsByteString-cpu-arguments-slope": 248, + "modInteger-memory-arguments-slope": 1, + "addInteger-cpu-arguments-slope": 0, + "equalsData-cpu-arguments-slope": 10000, + "decodeUtf8-memory-arguments-intercept": 0, + "chooseList-cpu-arguments": 150000, + "constrData-cpu-arguments": 150000, + "equalsByteString-memory-arguments": 1, + "cekApplyCost-exBudgetCPU": 29773, + "quotientInteger-memory-arguments-slope": 1, + "verifySignature-cpu-arguments-intercept": 3345831, + "unMapData-memory-arguments": 32, + "mkCons-memory-arguments": 32, + "sliceByteString-memory-arguments-slope": 1, + "sha3_256-memory-arguments": 4, + "ifThenElse-memory-arguments": 1, + "mkNilPairData-memory-arguments": 32, + "equalsByteString-cpu-arguments-slope": 247, + "appendString-cpu-arguments-intercept": 150000, + "quotientInteger-cpu-arguments-model-arguments-slope": 118, + "cekApplyCost-exBudgetMemory": 100, + "equalsString-memory-arguments": 1, + "multiplyInteger-memory-arguments-slope": 1, + "cekBuiltinCost-exBudgetMemory": 100, + "remainderInteger-memory-arguments-intercept": 0, + "sha2_256-cpu-arguments-intercept": 2477736, + "remainderInteger-cpu-arguments-model-arguments-intercept": 425507, + "lessThanEqualsByteString-memory-arguments": 1, + "tailList-memory-arguments": 32, + "mkNilData-cpu-arguments": 150000, + "chooseData-cpu-arguments": 150000, + "unBData-memory-arguments": 32, + "blake2b-memory-arguments": 4, + "iData-memory-arguments": 32, + "nullList-memory-arguments": 32, + "cekDelayCost-exBudgetCPU": 29773, + "subtractInteger-memory-arguments-intercept": 1, + "lessThanByteString-cpu-arguments-intercept": 103599, + "consByteString-cpu-arguments-slope": 1000, + "appendByteString-memory-arguments-slope": 1, + "trace-memory-arguments": 32, + "divideInteger-cpu-arguments-constant": 148000, + "cekConstCost-exBudgetCPU": 29773, + "encodeUtf8-memory-arguments-slope": 8, + "quotientInteger-cpu-arguments-model-arguments-intercept": 425507, + "mapData-memory-arguments": 32, + "appendString-cpu-arguments-slope": 1000, + "modInteger-cpu-arguments-constant": 148000, + "verifySignature-cpu-arguments-slope": 1, + "unConstrData-memory-arguments": 32, + "quotientInteger-memory-arguments-intercept": 0, + "equalsByteString-cpu-arguments-constant": 150000, + "sliceByteString-memory-arguments-intercept": 0, + "mkPairData-memory-arguments": 32, + "equalsByteString-cpu-arguments-intercept": 112536, + "appendString-memory-arguments-slope": 1, + "lessThanInteger-cpu-arguments-slope": 497, + "modInteger-cpu-arguments-model-arguments-intercept": 425507, + "modInteger-memory-arguments-minimum": 1, + "sha3_256-cpu-arguments-intercept": 0, + "verifySignature-memory-arguments": 1, + "cekLamCost-exBudgetMemory": 100, + "sliceByteString-cpu-arguments-intercept": 150000 + } + } +} diff --git a/configs/cardano/preview/byron-genesis.json b/configs/cardano/preview/byron-genesis.json new file mode 100644 index 0000000..99b5845 --- /dev/null +++ b/configs/cardano/preview/byron-genesis.json @@ -0,0 +1,117 @@ +{ "bootStakeholders": + { "021e737009040bf7f1e7b1bcc148f29d748d4a6b561902c95e4a9f36": 1 + , "0bc82ced9544980b9ffe7f64b1538bbda6804a5cc32c8035485e184b": 1 + , "18ed9844deef98cf9ba8b39791dede0538d2d2fa79bf67ef37dcc826": 1 + , "66cfa84ad0ee5ca8586244c8393007cf3d9622d77cfa03fd4f35065b": 1 + , "76c4d6c68c0ef81ae364411a84e52ce66089ed006ca29adfc0227901": 1 + , "8cc6b89fec65cc83d34b7bab2e6494db631d8476a86625767dd0c2a0": 1 + , "e90060fdc085ac9f63cdb3b32ba1d84e0f7eb98561687b213b4c8770": 1 + } +, "heavyDelegation": + { "021e737009040bf7f1e7b1bcc148f29d748d4a6b561902c95e4a9f36": + { "omega": 0 + , "issuerPk": + "6hSFCotivD08t02n43RMiaF9LzwtYVrFMu/WX6ShfEsxfdXFL5Y6c+DwHSZOCywU0RJz5er2icIO03UytC9NTg==" + , "delegatePk": + "JEnSVQTPGriTx1+lAMkKhCNsMBDNPGw+NiEvNPh4ui6IdvxrO+WkQPTy5U865XB4VFvi/zb7d+H1bilnztQNBg==" + , "cert": + "558952d17442e8cc73f0c7dd606e329b38ed2ec0c1f83fe2567d28b21ef2223d2d23640cd0531f75832b50e519631c48643fcfaa7168851645dce07b90d87f0e" + } + , "0bc82ced9544980b9ffe7f64b1538bbda6804a5cc32c8035485e184b": + { "omega": 0 + , "issuerPk": + "MJ7IskKU8GKk0Eeg3zhfSOK1DDVXOMHD2V/zhEpODUtL9YB0Y7sXnbZfg3+Df05hskP5Jz+dZvdC6DH/dP9jmQ==" + , "delegatePk": + "hwO7NJL7LfAk5e/QG61FKcdORoK60tvprE3063Muh4EQKrWA6l7t23B2GziK8D0hRO0j5W1Gzpn8WW69XLIlKA==" + , "cert": + "2bccf50d0c3cbb03dd29cfba817e8ba615db3d7722b41b264ad08722e548cfe83d069b29d13e490823d7519ecdd9940ea49573f6027056c4bd58da1adf75020e" + } + , "18ed9844deef98cf9ba8b39791dede0538d2d2fa79bf67ef37dcc826": + { "omega": 0 + , "issuerPk": + "pXbW4Jak8maeuWiosvrurykKnqDSHswUjroonSDS3fTnWS+BKe+vjT4zZJNKhQ33KbagiHVJ5CJUNggfsCtG2g==" + , "delegatePk": + "rbJAZp3kWCUvp8dnLR6qsgpGU+qKAFow4NHYKWiKCkfm1qFCFONob50N1IbNWCGWAhg38ZPTvBazTasjsfj6yQ==" + , "cert": + "89e1638e31fd3d402cecb897ba773d8c2c11c2d3cff2462b266e21461539b1a4fe8fb528e159b9af473799b51e49aa5b5816a88f10c484aa7cef7ad12850830a" + } + , "66cfa84ad0ee5ca8586244c8393007cf3d9622d77cfa03fd4f35065b": + { "omega": 0 + , "issuerPk": + "/LGZjmmcAMRisP7Rf454GM2QUKgj2aAyqE+iQo2PIEhcistFOlT+idtbLTceZAnQcwwPJDtTcNi+EnPQyscZOg==" + , "delegatePk": + "rinFUiKKCPPFY0ULEKn1SPRgLVmOS3jdTXDtrxK6VI1I11G3uBS1Olxi0mQSN3kf+B3hm/xHkuUDVNaSXNiBeQ==" + , "cert": + "3e7f30bb68c5bc4d23c2a730ac154a188a1fd45aac3f438efd380303171443d2ca4f50e5a1ff66b40ae3da64697f2599956ae06c21b73fa828b8c0dc9fb27302" + } + , "76c4d6c68c0ef81ae364411a84e52ce66089ed006ca29adfc0227901": + { "omega": 0 + , "issuerPk": + "9EE85tTLdSSR4T1Xoy6n9wr6jlbavCdfp9oQKusskO3DSSyNqRYS7QzYQ96j/WnphUey63082YkKijMfF9A4eA==" + , "delegatePk": + "dvyHDkXg8LFtb0K6Sitl8OGSEZPvfCVQYLDR6Au6t6/ROvlerMKQ8uri4fG7hQQzbHKtdKWgv94t+zuFJTQ1fw==" + , "cert": + "5ec0ed46ae7e575bdb089f1bceca3b2689b13a7162fe08578fe60ba64607fffaa507412a97652c3c81cc0ef93ff404cf809a628ae19faba1a035fca0505c1d04" + } + , "8cc6b89fec65cc83d34b7bab2e6494db631d8476a86625767dd0c2a0": + { "omega": 0 + , "issuerPk": + "Hr5S5PAxf9HSB4FzmtZzaFcXrNrctrI5XUrDrnCkOUTX6rhbtOMkXU3sWVDOvU6LNSSr3/Ws2+iCYZIr7LmTWg==" + , "delegatePk": + "FaLH2b5H/XS31YRnm98N6fP4Etx6m+GbniVAXMwOp8KhYXPKBJBsX/EjIy3pSkvRBhGCjsycB0yrDxWMi5ZsIQ==" + , "cert": + "10f06304cceb42071605ebba67b308c7568e5e6fe0d773c58f7e8c13bc8d8a340f70a4fd5e1b4a1c1db1de5c7646802bbc929d6c82d7adb8a77cb6ad77eac50a" + } + , "e90060fdc085ac9f63cdb3b32ba1d84e0f7eb98561687b213b4c8770": + { "omega": 0 + , "issuerPk": + "B2R+VXzy3c8bxncdOpQ2Z/tblxRNQO8AXQ0OsJDQvZYnLeGQcLD78kyYLpi3nfuS4SfnLar23NV4yiEVwaw+Yw==" + , "delegatePk": + "nACHGIBacymrKwn07iW/a5ZKJCPZ2cKQqeXw3ivR7WOYVUuufWhZlCoUTZ7rtBqoDaexblUQwkC7hA7AmNA3FA==" + , "cert": + "b5440daa05f7fae557df46e4f1b7c5802b86f465daad1137e315abf6e72f1c877207276abb8dcba86e18e42d39b34c2f0fa82ba2919944cdc8e2e5264baa450b" + } + } +, "startTime": 1666656000 +, "nonAvvmBalances": + { "FHnt4NL7yPXjpZtYj1YUiX9QYYUZGXDT9gA2PJXQFkTSMx3EgawXK5BUrCHdhe2": + "0" + , "FHnt4NL7yPXk7D87qAWEmfnL7wSQ9AzBU2mjZt3eM48NSCbygxgzAU6vCGiRZEW": + "0" + , "FHnt4NL7yPXpazQsTdJ3Gp1twQUo4N5rrgGbRNSzchjchPiApc1k4CvqDMcdd7H": + "0" + , "FHnt4NL7yPXtNo1wLCLZyGTMfAvB14h8onafiYkM7B69ZwvGgXeUyQWfi7FPrif": + "0" + , "FHnt4NL7yPXtmi4mAjD43V3NB3shDs1gCuHNcMLPsRWjaw1b2yRV2xad8S8V6aq": + "0" + , "FHnt4NL7yPXvDWHa8bVs73UEUdJd64VxWXSFNqetECtYfTd9TtJguJ14Lu3feth": + "30000000000000000" + , "FHnt4NL7yPXvNSRpCYydjRr7koQCrsTtkovk5uYMimgqMJX2DyrEEBqiXaTd8rG": + "0" + , "FHnt4NL7yPY9rTvdsCeyRnsbzp4bN7XdmAZeU5PzA1qR2asYmN6CsdxJw4YoDjG": + "0" + } +, "blockVersionData": + { "scriptVersion": 0 + , "slotDuration": "20000" + , "maxBlockSize": "2000000" + , "maxHeaderSize": "2000000" + , "maxTxSize": "4096" + , "maxProposalSize": "700" + , "mpcThd": "20000000000000" + , "heavyDelThd": "300000000000" + , "updateVoteThd": "1000000000000" + , "updateProposalThd": "100000000000000" + , "updateImplicit": "10000" + , "softforkRule": + { "initThd": "900000000000000" + , "minThd": "600000000000000" + , "thdDecrement": "50000000000000" + } + , "txFeePolicy": + { "summand": "155381000000000" , "multiplier": "43946000000" } + , "unlockStakeEpoch": "18446744073709551615" + } +, "protocolConsts": { "k": 432 , "protocolMagic": 2 } +, "avvmDistr": {} +} diff --git a/configs/cardano/preview/config.json b/configs/cardano/preview/config.json new file mode 100644 index 0000000..2a5ab35 --- /dev/null +++ b/configs/cardano/preview/config.json @@ -0,0 +1,114 @@ +{ + "AlonzoGenesisFile": "alonzo-genesis.json", + "AlonzoGenesisHash": "7e94a15f55d1e82d10f09203fa1d40f8eede58fd8066542cf6566008068ed874", + "ByronGenesisFile": "byron-genesis.json", + "ByronGenesisHash": "83de1d7302569ad56cf9139a41e2e11346d4cb4a31c00142557b6ab3fa550761", + "ConwayGenesisFile": "conway-genesis.json", + "ConwayGenesisHash": "9cc5084f02e27210eacba47af0872e3dba8946ad9460b6072d793e1d2f3987ef", + "EnableP2P": true, + "ExperimentalHardForksEnabled": false, + "ExperimentalProtocolsEnabled": false, + "LastKnownBlockVersion-Alt": 0, + "LastKnownBlockVersion-Major": 3, + "LastKnownBlockVersion-Minor": 1, + "MinNodeVersion": "8.12.0", + "PeerSharing": true, + "Protocol": "Cardano", + "RequiresNetworkMagic": "RequiresMagic", + "ShelleyGenesisFile": "shelley-genesis.json", + "ShelleyGenesisHash": "363498d1024f84bb39d3fa9593ce391483cb40d479b87233f868d6e57c3a400d", + "TargetNumberOfActivePeers": 20, + "TargetNumberOfEstablishedPeers": 50, + "TargetNumberOfKnownPeers": 150, + "TargetNumberOfRootPeers": 60, + "TestAllegraHardForkAtEpoch": 0, + "TestAlonzoHardForkAtEpoch": 0, + "TestMaryHardForkAtEpoch": 0, + "TestShelleyHardForkAtEpoch": 0, + "TraceAcceptPolicy": true, + "TraceBlockFetchClient": false, + "TraceBlockFetchDecisions": false, + "TraceBlockFetchProtocol": false, + "TraceBlockFetchProtocolSerialised": false, + "TraceBlockFetchServer": false, + "TraceChainDb": true, + "TraceChainSyncBlockServer": false, + "TraceChainSyncClient": false, + "TraceChainSyncHeaderServer": false, + "TraceChainSyncProtocol": false, + "TraceConnectionManager": true, + "TraceDNSResolver": true, + "TraceDNSSubscription": true, + "TraceDiffusionInitialization": true, + "TraceErrorPolicy": true, + "TraceForge": true, + "TraceHandshake": true, + "TraceInboundGovernor": true, + "TraceIpSubscription": true, + "TraceLedgerPeers": true, + "TraceLocalChainSyncProtocol": false, + "TraceLocalConnectionManager": true, + "TraceLocalErrorPolicy": true, + "TraceLocalHandshake": true, + "TraceLocalRootPeers": true, + "TraceLocalTxSubmissionProtocol": false, + "TraceLocalTxSubmissionServer": false, + "TraceMempool": true, + "TraceMux": false, + "TracePeerSelection": true, + "TracePeerSelectionActions": true, + "TracePublicRootPeers": true, + "TraceServer": true, + "TraceTxInbound": false, + "TraceTxOutbound": false, + "TraceTxSubmissionProtocol": false, + "TracingVerbosity": "NormalVerbosity", + "TurnOnLogMetrics": true, + "TurnOnLogging": true, + "defaultBackends": [ + "KatipBK" + ], + "defaultScribes": [ + [ + "StdoutSK", + "stdout" + ] + ], + "hasEKG": 12788, + "hasPrometheus": [ + "127.0.0.1", + 12798 + ], + "minSeverity": "Info", + "options": { + "mapBackends": { + "cardano.node.metrics": [ + "EKGViewBK" + ], + "cardano.node.resources": [ + "EKGViewBK" + ] + }, + "mapSubtrace": { + "cardano.node.metrics": { + "subtrace": "Neutral" + } + } + }, + "rotation": { + "rpKeepFilesNum": 10, + "rpLogLimitBytes": 5000000, + "rpMaxAgeHours": 24 + }, + "setupBackends": [ + "KatipBK" + ], + "setupScribes": [ + { + "scFormat": "ScText", + "scKind": "StdoutSK", + "scName": "stdout", + "scRotation": null + } + ] +} diff --git a/configs/cardano/preview/conway-genesis.json b/configs/cardano/preview/conway-genesis.json new file mode 100644 index 0000000..4f8b1d0 --- /dev/null +++ b/configs/cardano/preview/conway-genesis.json @@ -0,0 +1,297 @@ +{ + "poolVotingThresholds": { + "committeeNormal": 0.51, + "committeeNoConfidence": 0.51, + "hardForkInitiation": 0.51, + "motionNoConfidence": 0.51, + "ppSecurityGroup": 0.51 + }, + "dRepVotingThresholds": { + "motionNoConfidence": 0.67, + "committeeNormal": 0.67, + "committeeNoConfidence": 0.6, + "updateToConstitution": 0.75, + "hardForkInitiation": 0.6, + "ppNetworkGroup": 0.67, + "ppEconomicGroup": 0.67, + "ppTechnicalGroup": 0.67, + "ppGovGroup": 0.75, + "treasuryWithdrawal": 0.67 + }, + "committeeMinSize": 0, + "committeeMaxTermLength": 365, + "govActionLifetime": 30, + "govActionDeposit": 100000000000, + "dRepDeposit": 500000000, + "dRepActivity": 20, + "minFeeRefScriptCostPerByte": 15, + "plutusV3CostModel": [ + 100788, + 420, + 1, + 1, + 1000, + 173, + 0, + 1, + 1000, + 59957, + 4, + 1, + 11183, + 32, + 201305, + 8356, + 4, + 16000, + 100, + 16000, + 100, + 16000, + 100, + 16000, + 100, + 16000, + 100, + 16000, + 100, + 100, + 100, + 16000, + 100, + 94375, + 32, + 132994, + 32, + 61462, + 4, + 72010, + 178, + 0, + 1, + 22151, + 32, + 91189, + 769, + 4, + 2, + 85848, + 123203, + 7305, + -900, + 1716, + 549, + 57, + 85848, + 0, + 1, + 1, + 1000, + 42921, + 4, + 2, + 24548, + 29498, + 38, + 1, + 898148, + 27279, + 1, + 51775, + 558, + 1, + 39184, + 1000, + 60594, + 1, + 141895, + 32, + 83150, + 32, + 15299, + 32, + 76049, + 1, + 13169, + 4, + 22100, + 10, + 28999, + 74, + 1, + 28999, + 74, + 1, + 43285, + 552, + 1, + 44749, + 541, + 1, + 33852, + 32, + 68246, + 32, + 72362, + 32, + 7243, + 32, + 7391, + 32, + 11546, + 32, + 85848, + 123203, + 7305, + -900, + 1716, + 549, + 57, + 85848, + 0, + 1, + 90434, + 519, + 0, + 1, + 74433, + 32, + 85848, + 123203, + 7305, + -900, + 1716, + 549, + 57, + 85848, + 0, + 1, + 1, + 85848, + 123203, + 7305, + -900, + 1716, + 549, + 57, + 85848, + 0, + 1, + 955506, + 213312, + 0, + 2, + 270652, + 22588, + 4, + 1457325, + 64566, + 4, + 20467, + 1, + 4, + 0, + 141992, + 32, + 100788, + 420, + 1, + 1, + 81663, + 32, + 59498, + 32, + 20142, + 32, + 24588, + 32, + 20744, + 32, + 25933, + 32, + 24623, + 32, + 43053543, + 10, + 53384111, + 14333, + 10, + 43574283, + 26308, + 10, + 16000, + 100, + 16000, + 100, + 962335, + 18, + 2780678, + 6, + 442008, + 1, + 52538055, + 3756, + 18, + 267929, + 18, + 76433006, + 8868, + 18, + 52948122, + 18, + 1995836, + 36, + 3227919, + 12, + 901022, + 1, + 166917843, + 4307, + 36, + 284546, + 36, + 158221314, + 26549, + 36, + 74698472, + 36, + 333849714, + 1, + 254006273, + 72, + 2174038, + 72, + 2261318, + 64571, + 4, + 207616, + 8310, + 4, + 1293828, + 28716, + 63, + 0, + 1, + 1006041, + 43623, + 251, + 0, + 1 + ], + "constitution": { + "anchor": { + "dataHash": "ca41a91f399259bcefe57f9858e91f6d00e1a38d6d9c63d4052914ea7bd70cb2", + "url": "ipfs://bafkreifnwj6zpu3ixa4siz2lndqybyc5wnnt3jkwyutci4e2tmbnj3xrdm" + }, + "script": "fa24fb305126805cf2164c161d852a0e7330cf988f1fe558cf7d4a64" + }, + "committee": { + "members": { + "scriptHash-ff9babf23fef3f54ec29132c07a8e23807d7b395b143ecd8ff79f4c7": 1000 + }, + "threshold": { + "numerator": 2, + "denominator": 3 + } + } +} diff --git a/configs/cardano/preview/shelley-genesis.json b/configs/cardano/preview/shelley-genesis.json new file mode 100644 index 0000000..20abba3 --- /dev/null +++ b/configs/cardano/preview/shelley-genesis.json @@ -0,0 +1,68 @@ +{ + "activeSlotsCoeff": 0.05, + "epochLength": 86400, + "genDelegs": { + "12b0f443d02861948a0fce9541916b014e8402984c7b83ad70a834ce": { + "delegate": "7c54a168c731f2f44ced620f3cca7c2bd90731cab223d5167aa994e6", + "vrf": "62d546a35e1be66a2b06e29558ef33f4222f1c466adbb59b52d800964d4e60ec" + }, + "3df542796a64e399b60c74acfbdb5afa1e114532fa36b46d6368ef3a": { + "delegate": "c44bc2f3cc7e98c0f227aa399e4035c33c0d775a0985875fff488e20", + "vrf": "4f9d334decadff6eba258b2df8ae1f02580a2628bce47ae7d957e1acd3f42a3c" + }, + "93fd5083ff20e7ab5570948831730073143bea5a5d5539852ed45889": { + "delegate": "82a02922f10105566b70366b07c758c8134fa91b3d8ae697dfa5e8e0", + "vrf": "8a57e94a9b4c65ec575f35d41edb1df399fa30fdf10775389f5d1ef670ca3f9f" + }, + "a86cab3ea72eabb2e8aafbbf4abbd2ba5bdfd04eea26a39b126a78e4": { + "delegate": "10257f6d3bae913514bdc96c9170b3166bf6838cca95736b0e418426", + "vrf": "1b54aad6b013145a0fc74bb5c2aa368ebaf3999e88637d78e09706d0cc29874a" + }, + "b799804a28885bd49c0e1b99d8b3b26de0fac17a5cf651ecf0c872f0": { + "delegate": "ebe606e22d932d51be2c1ce87e7d7e4c9a7d1f7df4a5535c29e23d22", + "vrf": "b3fc06a1f8ee69ff23185d9af453503be8b15b2652e1f9fb7c3ded6797a2d6f9" + }, + "d125812d6ab973a2c152a0525b7fd32d36ff13555a427966a9cac9b1": { + "delegate": "e302198135fb5b00bfe0b9b5623426f7cf03179ab7ba75f945d5b79b", + "vrf": "b45ca2ed95f92248fa0322ce1fc9f815a5a5aa2f21f1adc2c42c4dccfc7ba631" + }, + "ef27651990a26449a40767d5e06cdef1670a3f3ff4b951d385b51787": { + "delegate": "0e0b11e80d958732e587585d30978d683a061831d1b753878f549d05", + "vrf": "b860ec844f6cd476c4fabb4aa1ca72d5c74d82f3835aed3c9515a35b6e048719" + } + }, + "initialFunds": {}, + "maxKESEvolutions": 62, + "maxLovelaceSupply": 45000000000000000, + "networkId": "Testnet", + "networkMagic": 2, + "protocolParams": { + "protocolVersion": { + "minor": 0, + "major": 6 + }, + "decentralisationParam": 1, + "eMax": 18, + "extraEntropy": { + "tag": "NeutralNonce" + }, + "maxTxSize": 16384, + "maxBlockBodySize": 65536, + "maxBlockHeaderSize": 1100, + "minFeeA": 44, + "minFeeB": 155381, + "minUTxOValue": 1000000, + "poolDeposit": 500000000, + "minPoolCost": 340000000, + "keyDeposit": 2000000, + "nOpt": 150, + "rho": 0.003, + "tau": 0.20, + "a0": 0.3 + }, + "securityParam": 432, + "slotLength": 1, + "slotsPerKESPeriod": 129600, + "systemStart": "2022-10-25T00:00:00Z", + "updateQuorum": 5 +} diff --git a/go.mod b/go.mod index 432f8a7..e2414d1 100644 --- a/go.mod +++ b/go.mod @@ -17,6 +17,7 @@ require ( go.uber.org/automaxprocs v1.6.0 go.uber.org/goleak v1.3.0 golang.org/x/sys v0.25.0 + gopkg.in/yaml.v3 v3.0.1 gorm.io/gorm v1.25.12 gorm.io/plugin/opentelemetry v0.1.7 ) diff --git a/go.sum b/go.sum index fdd2b25..f2fa5d5 100644 --- a/go.sum +++ b/go.sum @@ -92,6 +92,10 @@ github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA= github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw= +github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= github.com/mattn/go-isatty v0.0.17 h1:BTarxUcIeDqL27Mc+vyvdWYSL28zpIhv3RoTdsLMPng= @@ -119,6 +123,8 @@ github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoG github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo= github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE= github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo= +github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8= +github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM= github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y= @@ -239,6 +245,8 @@ google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlba google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg= google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/internal/config/config.go b/internal/config/config.go index 4fdf639..7bb7348 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -23,19 +23,21 @@ import ( ) type Config struct { - BindAddr string `split_words:"true"` - Network string - MetricsPort uint `split_words:"true"` - Port uint - Topology string + BindAddr string `split_words:"true"` + CardanoConfig string `envconfig:"config"` + Network string + MetricsPort uint `split_words:"true"` + Port uint + Topology string } var globalConfig = &Config{ - BindAddr: "0.0.0.0", - Network: "preview", - MetricsPort: 12798, - Port: 3001, - Topology: "", + BindAddr: "0.0.0.0", + CardanoConfig: "./configs/cardano/preview/config.json", + Network: "preview", + MetricsPort: 12798, + Port: 3001, + Topology: "", } func LoadConfig() (*Config, error) { diff --git a/internal/node/node.go b/internal/node/node.go index c5e1600..3a33561 100644 --- a/internal/node/node.go +++ b/internal/node/node.go @@ -22,6 +22,7 @@ import ( "os" "github.com/blinklabs-io/node" + "github.com/blinklabs-io/node/config/cardano" "github.com/blinklabs-io/node/internal/config" "github.com/prometheus/client_golang/prometheus" @@ -63,6 +64,14 @@ func Run(logger *slog.Logger) error { os.Exit(1) } }() + var nodeCfg *cardano.CardanoNodeConfig + if cfg.CardanoConfig != "" { + tmpCfg, err := cardano.NewCardanoNodeConfigFromFile(cfg.CardanoConfig) + if err != nil { + return err + } + nodeCfg = tmpCfg + } n, err := node.New( node.NewConfig( node.WithIntersectTip(true), @@ -70,6 +79,7 @@ func Run(logger *slog.Logger) error { // TODO: uncomment and make this configurable //node.WithDataDir(".data"), node.WithNetwork(cfg.Network), + node.WithCardanoNodeConfig(nodeCfg), node.WithListeners( node.ListenerConfig{ Listener: l,