Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into sanaz/use-latest-main…
Browse files Browse the repository at this point in the history
…-for-benchmark-tests
  • Loading branch information
staheri14 committed Sep 19, 2024
2 parents 95b7ebd + 6137f2d commit 102cc65
Show file tree
Hide file tree
Showing 32 changed files with 787 additions and 421 deletions.
43 changes: 26 additions & 17 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/celestiaorg/celestia-app/v3/app/posthandler"
appv1 "github.com/celestiaorg/celestia-app/v3/pkg/appconsts/v1"
appv2 "github.com/celestiaorg/celestia-app/v3/pkg/appconsts/v2"
appv3 "github.com/celestiaorg/celestia-app/v3/pkg/appconsts/v3"
"github.com/celestiaorg/celestia-app/v3/pkg/proof"
blobkeeper "github.com/celestiaorg/celestia-app/v3/x/blob/keeper"
blobtypes "github.com/celestiaorg/celestia-app/v3/x/blob/types"
Expand Down Expand Up @@ -108,6 +109,7 @@ var maccPerms = map[string][]string{
const (
v1 = appv1.Version
v2 = appv2.Version
v3 = appv3.Version
DefaultInitialVersion = v1
)

Expand Down Expand Up @@ -340,11 +342,11 @@ func New(
packetforwardkeeper.DefaultForwardTransferPacketTimeoutTimestamp, // forward timeout
packetforwardkeeper.DefaultRefundTransferPacketTimeoutTimestamp, // refund timeout
)
// PacketForwardMiddleware is used only for version 2.
transferStack = module.NewVersionedIBCModule(packetForwardMiddleware, transferStack, v2, v2)
// PacketForwardMiddleware is used only for version >= 2.
transferStack = module.NewVersionedIBCModule(packetForwardMiddleware, transferStack, v2, v3)
// Token filter wraps packet forward middleware and is thus the first module in the transfer stack.
tokenFilterMiddelware := tokenfilter.NewIBCMiddleware(transferStack)
transferStack = module.NewVersionedIBCModule(tokenFilterMiddelware, transferStack, v1, v2)
transferStack = module.NewVersionedIBCModule(tokenFilterMiddelware, transferStack, v1, v3)

app.EvidenceKeeper = *evidencekeeper.NewKeeper(
appCodec,
Expand Down Expand Up @@ -541,17 +543,8 @@ func (app *App) Info(req abci.RequestInfo) abci.ResponseInfo {
//
// Side-effect: calls baseapp.Init()
func (app *App) InitChain(req abci.RequestInitChain) (res abci.ResponseInitChain) {
// genesis must always contain the consensus params. The validator set however is derived from the
// initial genesis state. The genesis must always contain a non zero app version which is the initial
// version that the chain starts on
if req.ConsensusParams == nil || req.ConsensusParams.Version == nil {
panic("no consensus params set")
}
if req.ConsensusParams.Version.AppVersion == 0 {
panic("app version 0 is not accepted. Please set an app version in the genesis")
}
req = setDefaultAppVersion(req)
appVersion := req.ConsensusParams.Version.AppVersion

// mount the stores for the provided app version if it has not already been mounted
if app.AppVersion() == 0 && !app.IsSealed() {
app.mountKeysAndInit(appVersion)
Expand All @@ -567,10 +560,26 @@ func (app *App) InitChain(req abci.RequestInitChain) (res abci.ResponseInitChain
return res
}

// setDefaultAppVersion sets the default app version in the consensus params if
// it was 0. This is needed because chains (e.x. mocha-4) did not explicitly set
// an app version in genesis.json.
func setDefaultAppVersion(req abci.RequestInitChain) abci.RequestInitChain {
if req.ConsensusParams == nil {
panic("no consensus params set")
}
if req.ConsensusParams.Version == nil {
panic("no version set in consensus params")
}
if req.ConsensusParams.Version.AppVersion == 0 {
req.ConsensusParams.Version.AppVersion = v1
}
return req
}

// mountKeysAndInit mounts the keys for the provided app version and then
// invokes baseapp.Init().
func (app *App) mountKeysAndInit(appVersion uint64) {
app.BaseApp.Logger().Debug(fmt.Sprintf("mounting KV stores for app version %v", appVersion))
app.BaseApp.Logger().Info(fmt.Sprintf("mounting KV stores for app version %v", appVersion))
app.MountKVStores(app.versionedKeys(appVersion))

// Invoke load latest version for its side-effect of invoking baseapp.Init()
Expand All @@ -585,9 +594,9 @@ func (app *App) InitChainer(ctx sdk.Context, req abci.RequestInitChain) abci.Res
if err := tmjson.Unmarshal(req.AppStateBytes, &genesisState); err != nil {
panic(err)
}

app.UpgradeKeeper.SetModuleVersionMap(ctx, app.manager.GetVersionMap(req.ConsensusParams.Version.AppVersion))
return app.manager.InitGenesis(ctx, app.appCodec, genesisState, req.ConsensusParams.Version.AppVersion)
appVersion := req.ConsensusParams.Version.AppVersion
app.UpgradeKeeper.SetModuleVersionMap(ctx, app.manager.GetVersionMap(appVersion))
return app.manager.InitGenesis(ctx, app.appCodec, genesisState, appVersion)
}

// LoadHeight loads a particular height
Expand Down
59 changes: 59 additions & 0 deletions app/app_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package app_test

import (
"encoding/json"
"testing"

"github.com/celestiaorg/celestia-app/v3/app"
"github.com/celestiaorg/celestia-app/v3/app/encoding"
"github.com/celestiaorg/celestia-app/v3/test/util"
"github.com/celestiaorg/celestia-app/v3/test/util/testnode"
"github.com/celestiaorg/celestia-app/v3/x/minfee"
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/snapshots"
Expand All @@ -13,6 +16,7 @@ import (
"github.com/stretchr/testify/require"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/libs/log"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
tmdb "github.com/tendermint/tm-db"
)

Expand Down Expand Up @@ -52,6 +56,61 @@ func TestNew(t *testing.T) {
})
}

func TestInitChain(t *testing.T) {
logger := log.NewNopLogger()
db := tmdb.NewMemDB()
traceStore := &NoopWriter{}
invCheckPeriod := uint(1)
encodingConfig := encoding.MakeConfig(app.ModuleEncodingRegisters...)
upgradeHeight := int64(0)
appOptions := NoopAppOptions{}
testApp := app.New(logger, db, traceStore, invCheckPeriod, encodingConfig, upgradeHeight, appOptions)
genesisState, _, _ := util.GenesisStateWithSingleValidator(testApp, "account")
appStateBytes, err := json.MarshalIndent(genesisState, "", " ")
require.NoError(t, err)
genesis := testnode.DefaultConfig().Genesis

type testCase struct {
name string
request abci.RequestInitChain
wantPanic bool
}
testCases := []testCase{
{
name: "should panic if consensus params not set",
request: abci.RequestInitChain{},
wantPanic: true,
},
{
name: "should not panic on a genesis that does not contain an app version",
request: abci.RequestInitChain{
Time: genesis.GenesisTime,
ChainId: genesis.ChainID,
ConsensusParams: &abci.ConsensusParams{
Block: &abci.BlockParams{},
Evidence: &genesis.ConsensusParams.Evidence,
Validator: &genesis.ConsensusParams.Validator,
Version: &tmproto.VersionParams{}, // explicitly set to empty to remove app version.,
},
AppStateBytes: appStateBytes,
InitialHeight: 0,
},
wantPanic: false,
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
application := app.New(logger, db, traceStore, invCheckPeriod, encodingConfig, upgradeHeight, appOptions)
if tc.wantPanic {
assert.Panics(t, func() { application.InitChain(tc.request) })
} else {
assert.NotPanics(t, func() { application.InitChain(tc.request) })
}
})
}
}

func TestOfferSnapshot(t *testing.T) {
logger := log.NewNopLogger()
db := tmdb.NewMemDB()
Expand Down
5 changes: 2 additions & 3 deletions app/check_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,8 @@ func (app *App) CheckTx(req abci.RequestCheckTx) abci.ResponseCheckTx {
switch req.Type {
// new transactions must be checked in their entirety
case abci.CheckTxType_New:
// FIXME: we have a hardcoded subtree root threshold here. This is because we can't access
// the app version because the context is not initialized
err := blobtypes.ValidateBlobTx(app.txConfig, btx, appconsts.DefaultSubtreeRootThreshold)
appVersion := app.AppVersion()
err := blobtypes.ValidateBlobTx(app.txConfig, btx, appconsts.SubtreeRootThreshold(appVersion), appVersion)
if err != nil {
return sdkerrors.ResponseCheckTxWithEvents(err, 0, 0, []abci.Event{}, false)
}
Expand Down
2 changes: 1 addition & 1 deletion app/module/versioned_ibc_module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func TestVersionedIBCModule(t *testing.T) {
mockWrappedModule := mocks.NewMockIBCModule(ctrl)
mockNextModule := mocks.NewMockIBCModule(ctrl)

versionedModule := module.NewVersionedIBCModule(mockWrappedModule, mockNextModule, 2, 2)
versionedModule := module.NewVersionedIBCModule(mockWrappedModule, mockNextModule, 2, 3)

testCases := []struct {
name string
Expand Down
68 changes: 44 additions & 24 deletions app/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,95 +96,95 @@ func (app *App) setupModuleManager(skipGenesisInvariants bool) error {
app.manager, err = module.NewManager([]module.VersionedModule{
{
Module: genutil.NewAppModule(app.AccountKeeper, app.StakingKeeper, app.BaseApp.DeliverTx, app.txConfig),
FromVersion: v1, ToVersion: v2,
FromVersion: v1, ToVersion: v3,
},
{
Module: auth.NewAppModule(app.appCodec, app.AccountKeeper, nil),
FromVersion: v1, ToVersion: v2,
FromVersion: v1, ToVersion: v3,
},
{
Module: vesting.NewAppModule(app.AccountKeeper, app.BankKeeper),
FromVersion: v1, ToVersion: v2,
FromVersion: v1, ToVersion: v3,
},
{
Module: bank.NewAppModule(app.appCodec, app.BankKeeper, app.AccountKeeper),
FromVersion: v1, ToVersion: v2,
FromVersion: v1, ToVersion: v3,
},
{
Module: capability.NewAppModule(app.appCodec, *app.CapabilityKeeper),
FromVersion: v1, ToVersion: v2,
FromVersion: v1, ToVersion: v3,
},
{
Module: feegrantmodule.NewAppModule(app.appCodec, app.AccountKeeper, app.BankKeeper, app.FeeGrantKeeper, app.interfaceRegistry),
FromVersion: v1, ToVersion: v2,
FromVersion: v1, ToVersion: v3,
},
{
Module: crisis.NewAppModule(&app.CrisisKeeper, skipGenesisInvariants),
FromVersion: v1, ToVersion: v2,
FromVersion: v1, ToVersion: v3,
},
{
Module: gov.NewAppModule(app.appCodec, app.GovKeeper, app.AccountKeeper, app.BankKeeper),
FromVersion: v1, ToVersion: v2,
FromVersion: v1, ToVersion: v3,
},
{
Module: mint.NewAppModule(app.appCodec, app.MintKeeper, app.AccountKeeper),
FromVersion: v1, ToVersion: v2,
FromVersion: v1, ToVersion: v3,
},
{
Module: slashing.NewAppModule(app.appCodec, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper),
FromVersion: v1, ToVersion: v2,
FromVersion: v1, ToVersion: v3,
},
{
Module: distr.NewAppModule(app.appCodec, app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper),
FromVersion: v1, ToVersion: v2,
FromVersion: v1, ToVersion: v3,
},
{
Module: staking.NewAppModule(app.appCodec, app.StakingKeeper, app.AccountKeeper, app.BankKeeper),
FromVersion: v1, ToVersion: v2,
FromVersion: v1, ToVersion: v3,
},
{
Module: evidence.NewAppModule(app.EvidenceKeeper),
FromVersion: v1, ToVersion: v2,
FromVersion: v1, ToVersion: v3,
},
{
Module: authzmodule.NewAppModule(app.appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry),
FromVersion: v1, ToVersion: v2,
FromVersion: v1, ToVersion: v3,
},
{
Module: ibc.NewAppModule(app.IBCKeeper),
FromVersion: v1, ToVersion: v2,
FromVersion: v1, ToVersion: v3,
},
{
Module: params.NewAppModule(app.ParamsKeeper),
FromVersion: v1, ToVersion: v2,
FromVersion: v1, ToVersion: v3,
},
{
Module: transfer.NewAppModule(app.TransferKeeper),
FromVersion: v1, ToVersion: v2,
FromVersion: v1, ToVersion: v3,
},
{
Module: blob.NewAppModule(app.appCodec, app.BlobKeeper),
FromVersion: v1, ToVersion: v2,
FromVersion: v1, ToVersion: v3,
},
{
Module: blobstream.NewAppModule(app.appCodec, app.BlobstreamKeeper),
FromVersion: v1, ToVersion: v1,
},
{
Module: signal.NewAppModule(app.SignalKeeper),
FromVersion: v2, ToVersion: v2,
FromVersion: v2, ToVersion: v3,
},
{
Module: minfee.NewAppModule(app.ParamsKeeper),
FromVersion: v2, ToVersion: v2,
FromVersion: v2, ToVersion: v3,
},
{
Module: packetforward.NewAppModule(app.PacketForwardKeeper),
FromVersion: v2, ToVersion: v2,
FromVersion: v2, ToVersion: v3,
},
{
Module: ica.NewAppModule(nil, &app.ICAHostKeeper),
FromVersion: v2, ToVersion: v2,
FromVersion: v2, ToVersion: v3,
},
})
if err != nil {
Expand Down Expand Up @@ -303,7 +303,7 @@ func allStoreKeys() []string {
// versionedStoreKeys returns the store keys for each app version.
func versionedStoreKeys() map[uint64][]string {
return map[uint64][]string{
1: {
v1: {
authtypes.StoreKey,
authzkeeper.StoreKey,
banktypes.StoreKey,
Expand All @@ -321,7 +321,7 @@ func versionedStoreKeys() map[uint64][]string {
stakingtypes.StoreKey,
upgradetypes.StoreKey,
},
2: {
v2: {
authtypes.StoreKey,
authzkeeper.StoreKey,
banktypes.StoreKey,
Expand All @@ -341,6 +341,26 @@ func versionedStoreKeys() map[uint64][]string {
stakingtypes.StoreKey,
upgradetypes.StoreKey,
},
v3: { // same as v2
authtypes.StoreKey,
authzkeeper.StoreKey,
banktypes.StoreKey,
blobtypes.StoreKey,
capabilitytypes.StoreKey,
distrtypes.StoreKey,
evidencetypes.StoreKey,
feegrant.StoreKey,
govtypes.StoreKey,
ibchost.StoreKey,
ibctransfertypes.StoreKey,
icahosttypes.StoreKey,
minttypes.StoreKey,
packetforwardtypes.StoreKey,
signaltypes.StoreKey,
slashingtypes.StoreKey,
stakingtypes.StoreKey,
upgradetypes.StoreKey,
},
}
}

Expand Down
Loading

0 comments on commit 102cc65

Please sign in to comment.