diff --git a/go.sum b/go.sum index 79be52c717..f68a1802e3 100644 --- a/go.sum +++ b/go.sum @@ -454,6 +454,7 @@ github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.5.7 h1:81/ik6ipDQS2aGcBfIN5dHDB36BwrStyeAQquSYCV4o= github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE= 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= 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 +)