Skip to content

Commit

Permalink
convert PreprocessTxs to PrepareProposal
Browse files Browse the repository at this point in the history
  • Loading branch information
evan-forbes committed Feb 16, 2022
1 parent cfe3ecf commit 6cce1d0
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 57 deletions.
15 changes: 9 additions & 6 deletions app/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ import (
// PreprocessTxs fullfills the celestia-core version of the ACBI interface, by
// performing basic validation for the incoming txs, and by cleanly separating
// share messages from transactions
func (app *App) PreprocessTxs(txs abci.RequestPreprocessTxs) abci.ResponsePreprocessTxs {
func (app *App) PrepareProposal(req abci.RequestPrepareProposal) abci.ResponsePrepareProposal {
squareSize := app.SquareSize()
shareCounter := uint64(0)
var shareMsgs []*core.Message
var processedTxs [][]byte
for _, rawTx := range txs.Txs {
for _, rawTx := range req.BlockData.Txs {
// decode the Tx
tx, err := app.txConfig.TxDecoder()(rawTx)
if err != nil {
Expand Down Expand Up @@ -101,9 +101,12 @@ func (app *App) PreprocessTxs(txs abci.RequestPreprocessTxs) abci.ResponsePrepro
return bytes.Compare(shareMsgs[i].NamespaceId, shareMsgs[j].NamespaceId) < 0
})

return abci.ResponsePreprocessTxs{
Txs: processedTxs,
Messages: &core.Messages{MessagesList: shareMsgs},
return abci.ResponsePrepareProposal{
BlockData: &core.Data{
Txs: processedTxs,
Evidence: req.BlockData.Evidence,
Messages: core.Messages{MessagesList: shareMsgs},
},
}
}

Expand All @@ -121,4 +124,4 @@ func hasWirePayForMessage(tx sdk.Tx) bool {
// hardcoded. todo(evan): don't hardcode the square size
func (app *App) SquareSize() uint64 {
return consts.MaxSquareSize
}
}
16 changes: 9 additions & 7 deletions app/test/abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
core "github.com/tendermint/tendermint/proto/tendermint/types"
)

func TestPreprocessTxs(t *testing.T) {
func TestPrepareProposal(t *testing.T) {
signer := testutil.GenerateKeyringSigner(t, testAccName)
info := signer.GetSignerInfo()

Expand All @@ -26,7 +26,7 @@ func TestPreprocessTxs(t *testing.T) {
testApp := testutil.SetupTestApp(t, info.GetAddress())

type test struct {
input abci.RequestPreprocessTxs
input abci.RequestPrepareProposal
expectedMessages []*core.Message
expectedTxs int
}
Expand All @@ -45,8 +45,10 @@ func TestPreprocessTxs(t *testing.T) {

tests := []test{
{
input: abci.RequestPreprocessTxs{
Txs: [][]byte{firstRawTx, secondRawTx, thirdRawTx},
input: abci.RequestPrepareProposal{
BlockData: &core.Data{
Txs: [][]byte{firstRawTx, secondRawTx, thirdRawTx},
},
},
expectedMessages: []*core.Message{
{
Expand All @@ -67,9 +69,9 @@ func TestPreprocessTxs(t *testing.T) {
}

for _, tt := range tests {
res := testApp.PreprocessTxs(tt.input)
assert.Equal(t, tt.expectedMessages, res.Messages.MessagesList)
assert.Equal(t, tt.expectedTxs, len(res.Txs))
res := testApp.PrepareProposal(tt.input)
assert.Equal(t, tt.expectedMessages, res.BlockData.Messages.MessagesList)
assert.Equal(t, tt.expectedTxs, len(res.BlockData.Txs))
}
}

Expand Down
14 changes: 7 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ go 1.17

require (
github.com/celestiaorg/nmt v0.8.0
github.com/cosmos/cosmos-sdk v0.44.0
github.com/cosmos/ibc-go v1.2.0
github.com/cosmos/cosmos-sdk v0.44.3
github.com/cosmos/ibc-go v1.2.2
github.com/gogo/protobuf v1.3.3
github.com/golang/protobuf v1.5.2
github.com/gorilla/mux v1.8.0
github.com/grpc-ecosystem/grpc-gateway v1.16.0
github.com/spf13/cast v1.4.1
github.com/spf13/cobra v1.3.0
github.com/stretchr/testify v1.7.0
github.com/tendermint/spm v0.1.5
github.com/tendermint/tendermint v0.34.13
github.com/tendermint/spm v0.1.9
github.com/tendermint/tendermint v0.34.14
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-20211015210444-4f30a5c0130f // indirect
Expand Down Expand Up @@ -78,7 +78,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/lib/pq v1.10.2 // 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 @@ -124,8 +124,8 @@ require (

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/cosmos/cosmos-sdk => github.com/celestiaorg/cosmos-sdk v0.44.2-0.20220216073333-2945fdd40acb
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.14-celestia.0.20220119223021-e54097114e14
github.com/tendermint/tendermint => github.com/celestiaorg/celestia-core v0.34.14-celestia.0.20220216071745-373ca76fcc50
google.golang.org/grpc => google.golang.org/grpc v1.33.2
)
Loading

0 comments on commit 6cce1d0

Please sign in to comment.