From ba1e811181dabc11cbd153176ce96034fb427e45 Mon Sep 17 00:00:00 2001 From: Evan Forbes <42654277+evan-forbes@users.noreply.github.com> Date: Fri, 17 Sep 2021 06:05:06 -0500 Subject: [PATCH] add celestia specific consts (#530) * Move consts, ipfs, and ipld to pkg (#508) * move ipfs and ipld packages to new pkg/da/ * moved consts to pkg * clean up * go mod tidy --- go.mod | 1 + go.sum | 7 +++++ pkg/consts/consts.go | 64 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 72 insertions(+) create mode 100644 pkg/consts/consts.go diff --git a/go.mod b/go.mod index 0c90a71445..79f573f96a 100644 --- a/go.mod +++ b/go.mod @@ -8,6 +8,7 @@ require ( github.com/adlio/schema v1.1.13 github.com/btcsuite/btcd v0.22.0-beta github.com/btcsuite/btcutil v1.0.3-0.20201208143702-a53e38424cce + github.com/celestiaorg/nmt v0.7.0 github.com/fortytw2/leaktest v1.3.0 github.com/go-kit/kit v0.11.0 github.com/gogo/protobuf v1.3.2 diff --git a/go.sum b/go.sum index c00fc24ea5..bd0a0e1d83 100644 --- a/go.sum +++ b/go.sum @@ -135,6 +135,9 @@ github.com/btcsuite/snappy-go v1.0.0/go.mod h1:8woku9dyThutzjeg+3xrA5iCpBRH8XEEg github.com/btcsuite/websocket v0.0.0-20150119174127-31079b680792/go.mod h1:ghJtEyQwv5/p4Mg4C0fgbePVuGr935/5ddU9Z3TmDRY= github.com/btcsuite/winsvc v1.0.0/go.mod h1:jsenWakMcC0zFBFurPLEAyrnc/teJEM1O46fmI40EZs= github.com/casbin/casbin/v2 v2.31.6/go.mod h1:vByNa/Fchek0KZUgG5wEsl7iFsiviAYKRtgrQfcJqHg= +github.com/celestiaorg/merkletree v0.0.0-20210714075610-a84dc3ddbbe4/go.mod h1:fzuHnhzj1pUygGz+1ZkB3uQbEUL4htqCGJ4Qs2LwMZA= +github.com/celestiaorg/nmt v0.7.0 h1:XRYh7F7TH6ewD3Gybk1L1zjyvgkWPt1iGqWtbMtB2Lk= +github.com/celestiaorg/nmt v0.7.0/go.mod h1:3bqzTj8xKj0DgQUpOgZzoxvtNkC3MS/hTbQ6dn8SIa0= github.com/cenkalti/backoff v2.2.1+incompatible h1:tNowT99t7UNflLxfYYSlKYsBpXdEet03Pg2g16Swow4= github.com/cenkalti/backoff v2.2.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= @@ -371,6 +374,7 @@ github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= +github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= github.com/google/martian/v3 v3.0.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0= github.com/google/martian/v3 v3.1.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0= @@ -912,6 +916,8 @@ github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9de github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= github.com/zenazn/goji v0.9.0/go.mod h1:7S9M489iMyHBNxwZnk9/EHS098H4/F6TATF2mIxtB1Q= +gitlab.com/NebulousLabs/errors v0.0.0-20171229012116-7ead97ef90b8/go.mod h1:ZkMZ0dpQyWwlENaeZVBiQRjhMEZvk6VTXquzl3FOFP8= +gitlab.com/NebulousLabs/fastrand v0.0.0-20181126182046-603482d69e40/go.mod h1:rOnSnoRyxMI3fe/7KIbVcsHRGxe30OONv8dEgo+vCfA= go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= go.etcd.io/bbolt v1.3.3/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= go.etcd.io/bbolt v1.3.4/go.mod h1:G5EMThwa9y8QZGBClrRx5EY+Yw9kAhnjy3bSjsnlVTQ= @@ -954,6 +960,7 @@ golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8U golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190923035154-9ee001bba392/go.mod h1:/lpIB1dKB+9EgE3H3cr1v9wB50oz8l4C4h62xy7jSTY= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20200109152110-61a87790db17/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200115085410-6d4e4cb37c7d/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200323165209-0ec3e9974c59/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= diff --git a/pkg/consts/consts.go b/pkg/consts/consts.go new file mode 100644 index 0000000000..703fa0a8bf --- /dev/null +++ b/pkg/consts/consts.go @@ -0,0 +1,64 @@ +package consts + +import ( + "crypto/sha256" + + "github.com/celestiaorg/nmt/namespace" +) + +// This contains all constants of: +// https://github.com/celestiaorg/celestia-specs/blob/master/specs/consensus.md#constants +const ( + // ShareSize is the size of a share (in bytes). + // see: https://github.com/celestiaorg/celestia-specs/blob/master/specs/consensus.md#constants + ShareSize = 256 + + // NamespaceSize is the namespace size in bytes. + NamespaceSize = 8 + + // ShareReservedBytes is the reserved bytes for contiguous appends. + ShareReservedBytes = 1 + + // TxShareSize is the number of bytes usable for tx/evidence/ISR shares. + TxShareSize = ShareSize - NamespaceSize - ShareReservedBytes + // MsgShareSize is the number of bytes usable for message shares. + MsgShareSize = ShareSize - NamespaceSize + + // MaxSquareSize is the maximum number of + // rows/columns of the original data shares in square layout. + // Corresponds to AVAILABLE_DATA_ORIGINAL_SQUARE_MAX in the spec. + // 128*128*256 = 4 Megabytes + // TODO(ismail): settle on a proper max square + MaxSquareSize = 128 + + // MinSquareSize depicts the smallest original square width. + MinSquareSize = 1 + MinSharecount = MinSquareSize * MinSquareSize +) + +var ( + // See spec for further details on the types of available data + // https://github.com/celestiaorg/celestia-specs/blob/master/specs/consensus.md#reserved-namespace-ids + // https://github.com/celestiaorg/celestia-specs/blob/de5f4f74f56922e9fa735ef79d9e6e6492a2bad1/specs/data_structures.md#availabledata + + // TxNamespaceID is the namespace reserved for transaction data + TxNamespaceID = namespace.ID{0, 0, 0, 0, 0, 0, 0, 1} + // IntermediateStateRootsNamespaceID is the namespace reserved for + // intermediate state root data + IntermediateStateRootsNamespaceID = namespace.ID{0, 0, 0, 0, 0, 0, 0, 2} + // EvidenceNamespaceID is the namespace reserved for evidence + EvidenceNamespaceID = namespace.ID{0, 0, 0, 0, 0, 0, 0, 3} + // MaxReservedNamespace is the lexicographically largest namespace that is + // reserved for protocol use. It is derived from NAMESPACE_ID_MAX_RESERVED + // https://github.com/celestiaorg/celestia-specs/blob/master/specs/consensus.md#constants + MaxReservedNamespace = namespace.ID{0, 0, 0, 0, 0, 0, 0, 255} + // TailPaddingNamespaceID is the namespace ID for tail padding. All data + // with this namespace will be ignored + TailPaddingNamespaceID = namespace.ID{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE} + + // ParitySharesNamespaceID indicates that share contains erasure data + ParitySharesNamespaceID = namespace.ID{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF} + + // NewBaseHashFunc change accordingly if another hash.Hash should be used as a base hasher in the NMT: + NewBaseHashFunc = sha256.New +)