Skip to content

Commit

Permalink
chore!: rename malleatedTx -> indexWrapper (celestiaorg#905)
Browse files Browse the repository at this point in the history
  • Loading branch information
evan-forbes authored Dec 9, 2022
1 parent 74d234e commit de02bda
Show file tree
Hide file tree
Showing 9 changed files with 165 additions and 167 deletions.
4 changes: 2 additions & 2 deletions mempool/v0/clist_mempool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,7 @@ func TestRemoveBlobTx(t *testing.T) {
defer cleanup()

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

// create the blobTx
Expand All @@ -707,7 +707,7 @@ func TestRemoveBlobTx(t *testing.T) {
err = mp.CheckTx(bTx, nil, mempool.TxInfo{})
require.NoError(t, err)

err = mp.Update(1, []types.Tx{malleatedTx}, abciResponses(1, abci.CodeTypeOK), nil, nil)
err = mp.Update(1, []types.Tx{indexWrapper}, abciResponses(1, abci.CodeTypeOK), nil, nil)
require.NoError(t, err)
assert.EqualValues(t, 0, mp.Size())
assert.EqualValues(t, 0, mp.SizeBytes())
Expand Down
4 changes: 2 additions & 2 deletions mempool/v1/mempool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ func TestRemoveBlobTx(t *testing.T) {
txmp := setup(t, 500)

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

// create the blobTx
Expand All @@ -674,7 +674,7 @@ func TestRemoveBlobTx(t *testing.T) {
err = txmp.CheckTx(bTx, nil, mempool.TxInfo{})
require.NoError(t, err)

err = txmp.Update(1, []types.Tx{malleatedTx}, abciResponses(1, abci.CodeTypeOK), nil, nil)
err = txmp.Update(1, []types.Tx{indexWrapper}, abciResponses(1, abci.CodeTypeOK), nil, nil)
require.NoError(t, err)
assert.EqualValues(t, 0, txmp.Size())
assert.EqualValues(t, 0, txmp.SizeBytes())
Expand Down
6 changes: 3 additions & 3 deletions pkg/consts/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ const (
// decoding binaries that are not actually BlobTxs.
ProtoBlobTxTypeID = "BLOB"

// ProtoMalleatedTxTypeID is included in each encoded MalleatedTx to help prevent
// decoding binaries that are not actually MalleatedTxs.
ProtoMalleatedTxTypeID = "MLTD"
// ProtoIndexWrapperTypeID is included in each encoded IndexWrapper to help prevent
// decoding binaries that are not actually IndexWrappers.
ProtoIndexWrapperTypeID = "INDX"
)

var (
Expand Down
249 changes: 124 additions & 125 deletions proto/tendermint/types/types.pb.go

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions proto/tendermint/types/types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,9 @@ message TxProof {
repeated NMTProof proofs = 3;
}

// MalleatedTx wraps a transaction that was derived from a different original
// transaction. This allows for tendermint to track malleated and original
// transactions
message MalleatedTx {
// IndexWrapper adds index metadata to a transaction. This is used to track
// transactions that pay for blobs, and where the blobs start in the square.
message IndexWrapper {
bytes tx = 1;
uint32 share_index = 2;
string type_id = 3;
Expand Down
2 changes: 1 addition & 1 deletion state/txindex/kv/kv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func TestWrappedTxIndex(t *testing.T) {
indexer := NewTxIndex(db.NewMemDB())

tx := types.Tx("HELLO WORLD")
wrappedTx, err := types.MarshalMalleatedTx(11, tx)
wrappedTx, err := types.MarshalIndexWrapper(11, tx)
require.NoError(t, err)
txResult := &abci.TxResult{
Height: 1,
Expand Down
2 changes: 1 addition & 1 deletion types/event_bus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func TestEventBusPublishEventTx(t *testing.T) {
}
}

func TestEventBusPublishEventMalleatedTx(t *testing.T) {
func TestEventBusPublishEventIndexWrapper(t *testing.T) {
eventBus := NewEventBus()
err := eventBus.Start()
require.NoError(t, err)
Expand Down
42 changes: 21 additions & 21 deletions types/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ type (
)

// Hash computes the TMHASH hash of the wire encoded transaction. It attempts to
// unwrap the transaction if it is a MalleatedTx or a BlobTx.
// unwrap the transaction if it is a IndexWrapper or a BlobTx.
func (tx Tx) Hash() []byte {
if malleatedTx, isMalleated := UnmarshalMalleatedTx(tx); isMalleated {
return tmhash.Sum(malleatedTx.Tx)
if indexWrapper, isIndexWrapper := UnmarshalIndexWrapper(tx); isIndexWrapper {
return tmhash.Sum(indexWrapper.Tx)
}
if blobTx, isBlobTx := UnmarshalBlobTx(tx); isBlobTx {
return tmhash.Sum(blobTx.Tx)
Expand All @@ -41,13 +41,13 @@ func (tx Tx) Hash() []byte {
}

// Key returns the sha256 hash of the wire encoded transaction. It attempts to
// unwrap the transaction if it is a BlobTx or a MalleatedTx.
// unwrap the transaction if it is a BlobTx or a IndexWrapper.
func (tx Tx) Key() TxKey {
if blobTx, isBlobTx := UnmarshalBlobTx(tx); isBlobTx {
return sha256.Sum256(blobTx.Tx)
}
if malleatedTx, isMalleated := UnmarshalMalleatedTx(tx); isMalleated {
return sha256.Sum256(malleatedTx.Tx)
if indexWrapper, isIndexWrapper := UnmarshalIndexWrapper(tx); isIndexWrapper {
return sha256.Sum256(indexWrapper.Tx)
}
return sha256.Sum256(tx)
}
Expand Down Expand Up @@ -208,36 +208,36 @@ func ComputeProtoSizeForTxs(txs []Tx) int64 {
return int64(pdData.Size())
}

// UnmarshalMalleatedTx attempts to unmarshal the provided transaction into a
// malleated transaction. It returns true if the provided transaction is a
// malleated transaction. A malleated transaction is a transaction that contains
// UnmarshalIndexWrapper attempts to unmarshal the provided transaction into an
// IndexWrapper transaction. It returns true if the provided transaction is an
// IndexWrapper transaction. An IndexWrapper transaction is a transaction that contains
// a MsgPayForBlob that has been wrapped with a share index.
//
// NOTE: protobuf sometimes does not throw an error if the transaction passed is
// not a tmproto.MalleatedTx, since the protobuf definition for MsgPayForBlob is
// not a tmproto.IndexWrapper, since the protobuf definition for MsgPayForBlob is
// kept in the app, we cannot perform further checks without creating an import
// cycle.
func UnmarshalMalleatedTx(tx Tx) (malleatedTx tmproto.MalleatedTx, isMalleated bool) {
// attempt to unmarshal into a a malleated transaction
err := proto.Unmarshal(tx, &malleatedTx)
func UnmarshalIndexWrapper(tx Tx) (indexWrapper tmproto.IndexWrapper, isIndexWrapper bool) {
// attempt to unmarshal into an IndexWrapper transaction
err := proto.Unmarshal(tx, &indexWrapper)
if err != nil {
return malleatedTx, false
return indexWrapper, false
}
if malleatedTx.TypeId != consts.ProtoMalleatedTxTypeID {
return malleatedTx, false
if indexWrapper.TypeId != consts.ProtoIndexWrapperTypeID {
return indexWrapper, false
}
return malleatedTx, true
return indexWrapper, true
}

// MarshalMalleatedTx creates a wrapped Tx that includes the original transaction
// MarshalIndexWrapper creates a wrapped Tx that includes the original transaction
// and the share index of the start of its blob.
//
// NOTE: must be unwrapped to be a viable sdk.Tx
func MarshalMalleatedTx(shareIndex uint32, tx Tx) (Tx, error) {
wTx := tmproto.MalleatedTx{
func MarshalIndexWrapper(shareIndex uint32, tx Tx) (Tx, error) {
wTx := tmproto.IndexWrapper{
Tx: tx,
ShareIndex: shareIndex,
TypeId: consts.ProtoMalleatedTxTypeID,
TypeId: consts.ProtoIndexWrapperTypeID,
}
return proto.Marshal(&wTx)
}
Expand Down
16 changes: 8 additions & 8 deletions types/tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ func TestTxIndexByHash(t *testing.T) {
}
}

func TestUnmarshalMalleatedTx(t *testing.T) {
func TestUnmarshalIndexWrapper(t *testing.T) {
// perform a simple test for being unable to decode a non
// malleated transaction
// IndexWrapper transaction
tx := Tx{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0}
_, ok := UnmarshalMalleatedTx(tx)
_, ok := UnmarshalIndexWrapper(tx)
require.False(t, ok)

data := Data{
Expand Down Expand Up @@ -77,19 +77,19 @@ func TestUnmarshalMalleatedTx(t *testing.T) {

// due to protobuf not actually requiring type compatibility
// we need to make sure that there is some check
_, ok = UnmarshalMalleatedTx(rawBlock)
_, ok = UnmarshalIndexWrapper(rawBlock)
require.False(t, ok)

MalleatedTx, err := MarshalMalleatedTx(0, rawBlock)
IndexWrapper, err := MarshalIndexWrapper(0, rawBlock)
require.NoError(t, err)

// finally, ensure that the unwrapped bytes are identical to the input
malleated, ok := UnmarshalMalleatedTx(MalleatedTx)
indexWrapper, ok := UnmarshalIndexWrapper(IndexWrapper)
require.True(t, ok)
require.Equal(t, rawBlock, malleated.Tx)
require.Equal(t, rawBlock, indexWrapper.Tx)
}

func TestWrapUnmarshalBlobTx(t *testing.T) {
func TestUnmarshalBlobTx(t *testing.T) {
tx := []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9}
blob := tmproto.Blob{
NamespaceId: []byte{1, 2, 3, 4, 5, 6, 7, 8},
Expand Down

0 comments on commit de02bda

Please sign in to comment.