Skip to content

Commit

Permalink
Upgrade to tendermint v0.35.4 and cosmos-sdk v0.46.0 (#399)
Browse files Browse the repository at this point in the history
* update app to be v0.46.0 compat

* remove store and mem keys as we shouldn't use these

* comment out the IBC modules for now as it is not ready

* use patch version of core and the sdk

* more small changes to get to compile

* replace cosmoscmd with local cmd infra

* add missing modules to set begin,init,end methods

* linter

* fix validate basic test

* comment out extra test case for now

* add a validator set to the genesis state of the testapp

* use default tx handler for middleware

* uncomment out test

* rename encoding config var to not overwrite encoding package

* use patched version of core that removes malleated txs from the v1 mempool

* linter

* docs

* remove commented code

* fix makefile

* add a command to change the mode to validator in script

* use a release instead of a commit

* add commets to ibc uninstall to point to issue #412

* get rid of all starport scaffolding comments

* add comment describing panic

* use a constant for env prefix

* include comment for picking default snapshot interval

* patch merge

* fix integration test

* remove print statement

* use release and not a specific commit
  • Loading branch information
evan-forbes authored May 18, 2022
1 parent 6080046 commit 5e4a1dc
Show file tree
Hide file tree
Showing 36 changed files with 1,170 additions and 794 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ BUILD_FLAGS := -ldflags '$(ldflags)'
all: install

mod:
@go mod tidy
@go mod tidy -compat=1.17

pre-build:
@echo "Fetching latest tags"
Expand All @@ -34,7 +34,7 @@ build: mod
@mkdir -p build/
@go build -o build/ ./cmd/celestia-appd
@packr2 clean
@go mod tidy
@go mod tidy -compat=1.17

install: go.sum
@echo "--> Installing celestia-appd"
Expand Down
294 changes: 171 additions & 123 deletions app/app.go

Large diffs are not rendered by default.

39 changes: 39 additions & 0 deletions app/encoding/encoding.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package encoding

import (
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/std"
"github.com/cosmos/cosmos-sdk/x/auth/tx"
)

type InterfaceRegister func(codectypes.InterfaceRegistry)

// EncodingConfig specifies the concrete encoding types to use for a given app.
// This is provided for compatibility between protobuf and amino implementations.
type EncodingConfig struct {
InterfaceRegistry codectypes.InterfaceRegistry
Codec codec.Codec
TxConfig client.TxConfig
Amino *codec.LegacyAmino
}

// MakeEncodingConfig creates an encoding config for the app.
func MakeEncodingConfig(regs ...InterfaceRegister) EncodingConfig {
amino := codec.NewLegacyAmino()
interfaceRegistry := codectypes.NewInterfaceRegistry()
std.RegisterInterfaces(interfaceRegistry)
for _, reg := range regs {
reg(interfaceRegistry)
}
marshaler := codec.NewProtoCodec(interfaceRegistry)
txCfg := tx.NewTxConfig(marshaler, tx.DefaultSignModes)

return EncodingConfig{
InterfaceRegistry: interfaceRegistry,
Codec: marshaler,
TxConfig: txCfg,
Amino: amino,
}
}
28 changes: 22 additions & 6 deletions app/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ func (app *App) ExportAppStateAndValidators(
height := app.LastBlockHeight() + 1
if forZeroHeight {
height = 0
app.prepForZeroHeightGenesis(ctx, jailAllowedAddrs)
err := app.prepForZeroHeightGenesis(ctx, jailAllowedAddrs)
if err != nil {
return servertypes.ExportedApp{}, err
}
}

genState := app.mm.ExportGenesis(ctx, app.appCodec)
Expand All @@ -51,7 +54,7 @@ func (app *App) ExportAppStateAndValidators(
// prepare for fresh start at zero height
// NOTE zero height genesis is a temporary feature which will be deprecated
// in favour of export at a block height
func (app *App) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []string) {
func (app *App) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []string) error {
applyAllowedAddrs := false

// check if there is a allowed address list
Expand Down Expand Up @@ -110,14 +113,25 @@ func (app *App) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []str
feePool.CommunityPool = feePool.CommunityPool.Add(scraps...)
app.DistrKeeper.SetFeePool(ctx, feePool)

app.DistrKeeper.Hooks().AfterValidatorCreated(ctx, val.GetOperator())
err := app.DistrKeeper.Hooks().AfterValidatorCreated(ctx, val.GetOperator())
if err != nil {
// we can panic here as we do not know how to handle invalid validator state
panic(err)
}
return false
})

// reinitialize all delegations
for _, del := range dels {
app.DistrKeeper.Hooks().BeforeDelegationCreated(ctx, del.GetDelegatorAddr(), del.GetValidatorAddr())
app.DistrKeeper.Hooks().AfterDelegationModified(ctx, del.GetDelegatorAddr(), del.GetValidatorAddr())
err := app.DistrKeeper.Hooks().BeforeDelegationCreated(ctx, del.GetDelegatorAddr(), del.GetValidatorAddr())
// note: these errors aren't handled by the cosmos-sdk,
if err != nil {
return err
}
err = app.DistrKeeper.Hooks().AfterDelegationModified(ctx, del.GetDelegatorAddr(), del.GetValidatorAddr())
if err != nil {
return err
}
}

// reset context height
Expand Down Expand Up @@ -168,7 +182,7 @@ func (app *App) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []str
iter.Close()

if _, err := app.StakingKeeper.ApplyAndReturnValidatorSetUpdates(ctx); err != nil {
panic(err)
return err
}

/* Handle slashing state. */
Expand All @@ -182,4 +196,6 @@ func (app *App) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []str
return false
},
)

return nil
}
7 changes: 3 additions & 4 deletions app/test/prepare_proposal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,23 @@ import (
"testing"

"github.com/celestiaorg/celestia-app/app"
"github.com/celestiaorg/celestia-app/app/encoding"
"github.com/celestiaorg/celestia-app/testutil"
"github.com/celestiaorg/celestia-app/x/payment/types"
"github.com/cosmos/cosmos-sdk/client"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/tendermint/spm/cosmoscmd"
abci "github.com/tendermint/tendermint/abci/types"
core "github.com/tendermint/tendermint/proto/tendermint/types"
)

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

encCfg := cosmoscmd.MakeEncodingConfig(app.ModuleBasics)
encCfg := encoding.MakeEncodingConfig(app.ModuleBasics.RegisterInterfaces)

testApp := testutil.SetupTestApp(t, info.GetAddress())
testApp := testutil.SetupTestAppWithGenesisValSet(t)

type test struct {
input abci.RequestPrepareProposal
Expand Down
15 changes: 10 additions & 5 deletions app/test/process_proposal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@ package app_test

import (
"crypto/rand"
"math/big"
"testing"

"github.com/celestiaorg/celestia-app/app"
"github.com/celestiaorg/celestia-app/app/encoding"
"github.com/celestiaorg/celestia-app/testutil"
"github.com/celestiaorg/celestia-app/x/payment/types"
"github.com/cosmos/cosmos-sdk/client"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/tendermint/spm/cosmoscmd"
abci "github.com/tendermint/tendermint/abci/types"
tmrand "github.com/tendermint/tendermint/libs/rand"
"github.com/tendermint/tendermint/pkg/consts"
Expand All @@ -22,11 +23,10 @@ import (

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

testApp := testutil.SetupTestApp(t, info.GetAddress())
testApp := testutil.SetupTestAppWithGenesisValSet(t)

encConf := cosmoscmd.MakeEncodingConfig(app.ModuleBasics)
encConf := encoding.MakeEncodingConfig(app.ModuleBasics.RegisterInterfaces)

firstValidPFD, msg1 := genRandMsgPayForData(t, signer, 8)
secondValidPFD, msg2 := genRandMsgPayForData(t, signer, 8)
Expand Down Expand Up @@ -170,7 +170,7 @@ func genRandMsgPayForData(t *testing.T, signer *types.KeyringSigner, squareSize
_, err := rand.Read(ns)
require.NoError(t, err)

message := make([]byte, 20)
message := make([]byte, randomInt(20))
_, err = rand.Read(message)
require.NoError(t, err)

Expand All @@ -194,3 +194,8 @@ func buildTx(t *testing.T, signer *types.KeyringSigner, txCfg client.TxConfig, m

return rawTx
}

func randomInt(max int64) int64 {
i, _ := rand.Int(rand.Reader, big.NewInt(max))
return i.Int64()
}
8 changes: 2 additions & 6 deletions app/test/split_shares_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,21 @@ package app_test

import (
"bytes"
"fmt"
"testing"

"github.com/celestiaorg/celestia-app/app"
"github.com/celestiaorg/celestia-app/app/encoding"
"github.com/celestiaorg/celestia-app/testutil"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/tendermint/spm/cosmoscmd"
"github.com/tendermint/tendermint/pkg/consts"
"github.com/tendermint/tendermint/pkg/da"
core "github.com/tendermint/tendermint/proto/tendermint/types"
coretypes "github.com/tendermint/tendermint/types"
)

func TestSplitShares(t *testing.T) {
encCfg := cosmoscmd.MakeEncodingConfig(app.ModuleBasics)
encCfg := encoding.MakeEncodingConfig(app.ModuleBasics.RegisterInterfaces)

type test struct {
squareSize uint64
Expand Down Expand Up @@ -99,9 +98,6 @@ func TestSplitShares(t *testing.T) {
parsedShares, _, err := parsedData.ComputeShares(tt.squareSize)
require.NoError(t, err)

rawParsedShares := parsedShares.RawShares()
fmt.Println(len(square), len(rawParsedShares))

require.Equal(t, square, parsedShares.RawShares())
}
}
49 changes: 4 additions & 45 deletions cmd/celestia-appd/main.go
Original file line number Diff line number Diff line change
@@ -1,58 +1,17 @@
package main

import (
"io"
"os"

"github.com/celestiaorg/celestia-app/app"
"github.com/cosmos/cosmos-sdk/baseapp"
svrcmd "github.com/cosmos/cosmos-sdk/server/cmd"
servertypes "github.com/cosmos/cosmos-sdk/server/types"
"github.com/tendermint/spm/cosmoscmd"
"github.com/tendermint/tendermint/libs/log"
dbm "github.com/tendermint/tm-db"
)

const envPrefix = "CELESTIA"

func main() {
rootCmd, _ := cosmoscmd.NewRootCmd(
app.Name,
app.AccountAddressPrefix,
app.DefaultNodeHome,
app.Name,
app.ModuleBasics,
appBuilder,
// this line is used by starport scaffolding # root/arguments
)
if err := svrcmd.Execute(rootCmd, app.DefaultNodeHome); err != nil {
rootCmd := NewRootCmd()
if err := svrcmd.Execute(rootCmd, envPrefix, app.DefaultNodeHome); err != nil {
os.Exit(1)
}
}

// appBuilder wraps the app.New func to return a cosmoscmd.App interface instead
// of the raw app.App. The New func has to return a raw app.App, because we need
// to call PrepareProposal
func appBuilder(
logger log.Logger,
db dbm.DB,
traceStore io.Writer,
loadLatest bool,
skipUpgradeHeights map[int64]bool,
homePath string,
invCheckPeriod uint,
encodingConfig cosmoscmd.EncodingConfig,
appOpts servertypes.AppOptions,
baseAppOptions ...func(*baseapp.BaseApp),
) cosmoscmd.App {
return app.New(
logger,
db,
traceStore,
loadLatest,
skipUpgradeHeights,
homePath,
invCheckPeriod,
encodingConfig,
appOpts,
baseAppOptions...,
)
}
Loading

0 comments on commit 5e4a1dc

Please sign in to comment.