Skip to content

Commit

Permalink
Wrap PayForMessages in order to remove WirePayForMessage from the…
Browse files Browse the repository at this point in the history
… mempool (#149)

* register standard interface types while creating encoding config

* implement and add the child tx decoder

* linter: handle error

* update to the latest verison of celestia-core

* use a specific commit instead of a branch to not confuse go

* patch copy bug and add test to double check that protobuf bug

* use latest version of celestia-core
  • Loading branch information
evan-forbes authored Nov 22, 2021
1 parent 3192328 commit 1fcccc4
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 13 deletions.
10 changes: 9 additions & 1 deletion app/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package app

import (
"bytes"
"crypto/sha256"
"sort"

"github.com/celestiaorg/celestia-app/x/payment/types"
Expand All @@ -10,6 +11,7 @@ import (
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/pkg/consts"
core "github.com/tendermint/tendermint/proto/tendermint/types"
coretypes "github.com/tendermint/tendermint/types"
)

// PreprocessTxs fullfills the celestia-core version of the ACBI interface, by
Expand Down Expand Up @@ -84,8 +86,14 @@ func (app *App) PreprocessTxs(txs abci.RequestPreprocessTxs) abci.ResponsePrepro
continue
}

parentHash := sha256.Sum256(rawTx)
wrappedTx, err := coretypes.WrapChildTx(parentHash[:], rawProcessedTx)
if err != nil {
app.Logger().Error("failure to wrap child transaction with parent hash", "Error:", err)
}

shareMsgs = append(shareMsgs, coreMsg)
processedTxs = append(processedTxs, rawProcessedTx)
processedTxs = append(processedTxs, wrappedTx)
}

// sort messages lexigraphically
Expand Down
4 changes: 3 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,9 @@ func New(
cdc := encodingConfig.Amino
interfaceRegistry := encodingConfig.InterfaceRegistry

bApp := baseapp.NewBaseApp(Name, logger, db, encodingConfig.TxConfig.TxDecoder(), baseAppOptions...)
dec := encodingConfig.TxConfig.TxDecoder()

bApp := baseapp.NewBaseApp(Name, logger, db, ChildTxDecoder(dec), baseAppOptions...)
bApp.SetCommitMultiStoreTracer(traceStore)
bApp.SetVersion(version.Version)
bApp.SetInterfaceRegistry(interfaceRegistry)
Expand Down
15 changes: 15 additions & 0 deletions app/child_tx_decoder.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package app

import (
sdk "github.com/cosmos/cosmos-sdk/types"
coretypes "github.com/tendermint/tendermint/types"
)

func ChildTxDecoder(dec sdk.TxDecoder) sdk.TxDecoder {
return func(txBytes []byte) (sdk.Tx, error) {
if _, childTx, has := coretypes.DecodeChildTx(txBytes); has {
return dec(childTx)
}
return dec(txBytes)
}
}
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ require (
github.com/tendermint/tendermint v0.34.13
github.com/tendermint/tm-db v0.6.4
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 // indirect
golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d // indirect
golang.org/x/net v0.0.0-20210903162142-ad29c8ab022f // indirect
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6 // indirect
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
google.golang.org/genproto v0.0.0-20210903162649-d08c68adba83
Expand Down Expand Up @@ -79,6 +79,7 @@ require (
github.com/jmhodges/levigo v1.0.0 // indirect
github.com/keybase/go-keychain v0.0.0-20190712205309-48d3d31d256d // indirect
github.com/klauspost/compress v1.11.7 // indirect
github.com/lib/pq v1.2.0 // indirect
github.com/libp2p/go-buffer-pool v0.0.2 // indirect
github.com/magiconair/properties v1.8.5 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
Expand Down Expand Up @@ -126,6 +127,6 @@ replace (
github.com/99designs/keyring => github.com/cosmos/keyring v1.1.7-0.20210622111912-ef00f8ac3d76
github.com/cosmos/cosmos-sdk => github.com/celestiaorg/cosmos-sdk v0.44.1-celestia
github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1
github.com/tendermint/tendermint v0.34.13 => github.com/celestiaorg/celestia-core v0.34.12-celestia
github.com/tendermint/tendermint v0.34.13 => github.com/celestiaorg/celestia-core v0.34.14-celestia.0.20211121093520-199a1e4232ac
google.golang.org/grpc => google.golang.org/grpc v1.33.2
)
67 changes: 58 additions & 9 deletions go.sum

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions x/payment/types/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/cosmos/cosmos-sdk/types/tx"
authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing"
"github.com/stretchr/testify/require"
coretypes "github.com/tendermint/tendermint/types"
"google.golang.org/grpc"
)

Expand All @@ -32,6 +33,12 @@ func TestBuildPayForMessage(t *testing.T) {
signedTx, err := k.BuildSignedTx(k.NewTxBuilder(), msg)
require.NoError(t, err)

rawTx, err := makeEncodingConfig().TxConfig.TxEncoder()(signedTx)
require.NoError(t, err)

_, _, isChild := coretypes.DecodeChildTx(rawTx)
require.False(t, isChild)

sigs, err := signedTx.GetSignaturesV2()
require.NoError(t, err)

Expand Down
2 changes: 2 additions & 0 deletions x/payment/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/cosmos/cosmos-sdk/codec"
cdctypes "github.com/cosmos/cosmos-sdk/codec/types"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/std"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/msgservice"
"github.com/cosmos/cosmos-sdk/x/auth/tx"
Expand Down Expand Up @@ -48,6 +49,7 @@ func makeEncodingConfig() cosmoscmd.EncodingConfig {
amino := codec.NewLegacyAmino()
interfaceRegistry := codectypes.NewInterfaceRegistry()
RegisterInterfaces(interfaceRegistry)
std.RegisterInterfaces(interfaceRegistry)
marshaler := codec.NewProtoCodec(interfaceRegistry)
txCfg := tx.NewTxConfig(marshaler, tx.DefaultSignModes)

Expand Down

0 comments on commit 1fcccc4

Please sign in to comment.