Skip to content

Commit

Permalink
feat!: versioned namespaces (#987)
Browse files Browse the repository at this point in the history
* feat!: increase tx namespace id to 32 bytes (#969)

* feat!: increase tx namespace id to 32 bytes

* copy constants

* deduplicate constants

* fix mempool tests

* fix one more test

* feat!: versioned namespaces (#985)

* feat!: versioned namespaces

* fix: share proof test

* fix: check for shareVersion overflow

* test: replace 8 byte namespace IDs in test
  • Loading branch information
rootulp authored Mar 27, 2023
1 parent 2fe81fb commit e3bad3d
Show file tree
Hide file tree
Showing 13 changed files with 314 additions and 196 deletions.
9 changes: 6 additions & 3 deletions mempool/cat/pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/tendermint/tendermint/config"
"github.com/tendermint/tendermint/libs/log"
"github.com/tendermint/tendermint/mempool"
"github.com/tendermint/tendermint/pkg/consts"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
"github.com/tendermint/tendermint/proxy"
"github.com/tendermint/tendermint/types"
Expand Down Expand Up @@ -654,12 +655,14 @@ func TestTxPool_RemoveBlobTx(t *testing.T) {
originalTx := []byte{1, 2, 3, 4}
indexWrapper, err := types.MarshalIndexWrapper(originalTx, 100)
require.NoError(t, err)
namespaceOne := bytes.Repeat([]byte{1}, consts.NamespaceIDSize)

// create the blobTx
b := tmproto.Blob{
NamespaceId: []byte{1, 2, 3, 4, 5, 6, 7, 8},
Data: []byte{1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8, 9},
ShareVersion: 0,
NamespaceId: namespaceOne,
Data: []byte{1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8, 9},
ShareVersion: 0,
NamespaceVersion: 0,
}
bTx, err := types.MarshalBlobTx(originalTx, &b)
require.NoError(t, err)
Expand Down
10 changes: 7 additions & 3 deletions mempool/v0/clist_mempool_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package v0

import (
"bytes"
"crypto/rand"
"encoding/binary"
"fmt"
Expand All @@ -25,6 +26,7 @@ import (
cmtrand "github.com/tendermint/tendermint/libs/rand"
"github.com/tendermint/tendermint/libs/service"
"github.com/tendermint/tendermint/mempool"
"github.com/tendermint/tendermint/pkg/consts"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
"github.com/tendermint/tendermint/proxy"
"github.com/tendermint/tendermint/types"
Expand Down Expand Up @@ -684,6 +686,7 @@ func TestMempoolRemoteAppConcurrency(t *testing.T) {
func TestRemoveBlobTx(t *testing.T) {
app := kvstore.NewApplication()
cc := proxy.NewLocalClientCreator(app)
namespaceOne := bytes.Repeat([]byte{1}, consts.NamespaceIDSize)

cfg := config.ResetTestRoot("mempool_test")

Expand All @@ -697,9 +700,10 @@ func TestRemoveBlobTx(t *testing.T) {

// create the blobTx
b := tmproto.Blob{
NamespaceId: []byte{1, 2, 3, 4, 5, 6, 7, 8},
Data: []byte{1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8, 9},
ShareVersion: 0,
NamespaceId: namespaceOne,
Data: []byte{1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8, 9},
ShareVersion: 0,
NamespaceVersion: 0,
}
bTx, err := types.MarshalBlobTx(originalTx, &b)
require.NoError(t, err)
Expand Down
9 changes: 6 additions & 3 deletions mempool/v1/mempool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/tendermint/tendermint/config"
"github.com/tendermint/tendermint/libs/log"
"github.com/tendermint/tendermint/mempool"
"github.com/tendermint/tendermint/pkg/consts"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
"github.com/tendermint/tendermint/proxy"
"github.com/tendermint/tendermint/types"
Expand Down Expand Up @@ -657,16 +658,18 @@ func TestTxMempool_CheckTxPostCheckError(t *testing.T) {

func TestRemoveBlobTx(t *testing.T) {
txmp := setup(t, 500)
namespaceOne := bytes.Repeat([]byte{1}, consts.NamespaceIDSize)

originalTx := []byte{1, 2, 3, 4}
indexWrapper, err := types.MarshalIndexWrapper(originalTx, 100)
require.NoError(t, err)

// create the blobTx
b := tmproto.Blob{
NamespaceId: []byte{1, 2, 3, 4, 5, 6, 7, 8},
Data: []byte{1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8, 9},
ShareVersion: 0,
NamespaceId: namespaceOne,
Data: []byte{1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8, 9},
ShareVersion: 0,
NamespaceVersion: 0,
}
bTx, err := types.MarshalBlobTx(originalTx, &b)
require.NoError(t, err)
Expand Down
20 changes: 12 additions & 8 deletions pkg/consts/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package consts

import (
"crypto/sha256"

"github.com/celestiaorg/nmt/namespace"
)

const (
Expand All @@ -23,15 +21,21 @@ const (
// ProtoIndexWrapperTypeID is included in each encoded IndexWrapper to help prevent
// decoding binaries that are not actually IndexWrappers.
ProtoIndexWrapperTypeID = "INDX"

// NamespaveVersionSize is the size of a namespace version in bytes.
NamespaceVersionSize = 1

// NamespaceIDSize is the size of a namespace ID in bytes.
NamespaceIDSize = 32

// NamespaceSize is the size of a namespace in bytes.
NamespaceSize = NamespaceIDSize + NamespaceVersionSize
)

var (
// See spec for further details on the types of available data
// https://github.com/celestiaorg/celestia-specs/blob/master/src/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}
// TxNamespaceID is the namespace ID reserved for transaction data. It does
// not contain a leading version byte.
TxNamespaceID = []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}

// NewBaseHashFunc change accordingly if another hash.Hash should be used as a base hasher in the NMT:
NewBaseHashFunc = sha256.New
Expand Down
Loading

0 comments on commit e3bad3d

Please sign in to comment.