Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(rollapp): Updating x/rollapp to accommodate generalized DA layer interface #974

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
0e18a9d
replacing tendermint with cometbft
spoo-bar Jun 13, 2024
f1c703c
replace tm-db with cometbft-db
spoo-bar Jun 13, 2024
1d91b32
upgrading ibc-go and pfm
spoo-bar Jun 13, 2024
67038a8
updating proto-gen to latest image and regenerating
spoo-bar Jun 13, 2024
d86f0bb
feat: Remove deprecated functions and modules
spoo-bar Jun 13, 2024
d008518
replace simapp
spoo-bar Jun 17, 2024
3f225ce
fixing the breaking apis
spoo-bar Jun 19, 2024
983bfcd
feat: Add consensus and ibctm modules
spoo-bar Jun 19, 2024
1e51da3
adding v4 upgrade handler
spoo-bar Jun 19, 2024
3943b38
feat: Migrate param key table for params module
spoo-bar Jun 19, 2024
68a6cee
feat: Add autocli and reflection services
spoo-bar Jun 19, 2024
fe4e6ee
refactor: Update Feemarket keeper initialization
spoo-bar Jun 19, 2024
7301f40
fixing tests
spoo-bar Jun 19, 2024
a2bd7be
linting 🧹
spoo-bar Jun 20, 2024
39bc258
refactor: Update Feemarket keeper initialization
spoo-bar Jun 20, 2024
cf524f0
updating with latest osmosis
spoo-bar Jun 26, 2024
bd93ab6
updatign go mod to use osmosis fork tag
spoo-bar Jun 27, 2024
b9299e9
updating changelog
spoo-bar Jun 27, 2024
b066b44
Merge branch 'main' into spoorthi/upgrade-sdk-to-v.47
spoo-bar Jun 27, 2024
eb83c9e
fixing merge conflicts pending stuff
spoo-bar Jun 27, 2024
103845a
linting 🧹
spoo-bar Jun 27, 2024
824c82d
adding proto tx for MsgUpdateState
spoo-bar Jun 28, 2024
b9e6dfa
adding v2.msgupdatestate type
spoo-bar Jun 28, 2024
b75d85e
implementing msgsrvr v2 and their tests
spoo-bar Jun 28, 2024
b597c81
adding encoding tests
spoo-bar Jun 28, 2024
8d2fa5e
implementing the da layer
spoo-bar Jun 28, 2024
44395fb
feat: Add simulation for updating state v2
spoo-bar Jun 28, 2024
0110286
chore: Register v2 message server in module's service registration
spoo-bar Jun 28, 2024
6f1393d
linting 🧹
spoo-bar Jul 1, 2024
c733289
ensuring tests dont fail while umimplemented
spoo-bar Jul 3, 2024
ee5f98d
Merge remote-tracking branch 'upstream/main' into spoorthi/generalize…
spoo-bar Jul 17, 2024
3b4a7b4
fixing missing protobuf reference
spoo-bar Jul 17, 2024
1e3391c
linting 🧹
spoo-bar Jul 17, 2024
4b73be7
Merge branch 'main' into spoorthi/generalized-rollapp
spoo-bar Jul 19, 2024
747a18c
linting 🧹
spoo-bar Jul 24, 2024
27ec2c1
Merge branch 'main' into spoorthi/generalized-rollapp
spoo-bar Aug 5, 2024
df133dc
updating to main changes
spoo-bar Aug 5, 2024
4ce5a21
Merge branch 'main' into spoorthi/generalized-rollapp
spoo-bar Aug 6, 2024
6dde975
regenerate proto
spoo-bar Aug 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ import (
"github.com/cosmos/cosmos-sdk/server/config"
servertypes "github.com/cosmos/cosmos-sdk/server/types"
"github.com/cosmos/cosmos-sdk/store/streaming"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil"
Expand Down
8 changes: 8 additions & 0 deletions proto/dymensionxyz/dymension/rollapp/rollapp.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ syntax = "proto3";
package dymensionxyz.dymension.rollapp;

option go_package = "github.com/dymensionxyz/dymension/v3/x/rollapp/types";
import "google/protobuf/any.proto";

import "gogoproto/gogo.proto";
import "cosmos/base/v1beta1/coin.proto";
Expand Down Expand Up @@ -67,3 +68,10 @@ message RollappSummary {
StateInfoIndex latestFinalizedStateIndex = 3;
}

// DAPath defines the location on the DA layer where the blob is posted.
message DAPath {
// daType identifies the DA type being used by the sequencer to post the blob.
string daType = 1;
// commitment defines a generic commitment interpreted by the DA Layer.
google.protobuf.Any commitment = 2;
}
40 changes: 40 additions & 0 deletions proto/dymensionxyz/dymension/rollapp/v2/tx.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
syntax = "proto3";
package dymensionxyz.dymension.rollapp.v2;

// this line is used by starport scaffolding # proto/tx/import
import "cosmos/msg/v1/msg.proto";
import "dymensionxyz/dymension/rollapp/block_descriptor.proto";
import "dymensionxyz/dymension/rollapp/rollapp.proto";

option go_package = "github.com/dymensionxyz/dymension/v3/x/rollapp/types/v2";

import "gogoproto/gogo.proto";

// Msg defines the Msg service.
service Msg {
rpc UpdateState(MsgUpdateState) returns (MsgUpdateStateResponse);
}


// MsgUpdateState updates a rollapp state with a block batch.
// a block batch is a list of ordered blocks (by height)
message MsgUpdateState {
option (cosmos.msg.v1.signer) = "creator";
// creator is the bech32-encoded address of the sequencer sending the update
string creator = 1;
// rollappId is the rollapp that the sequencer belongs to and asking to update
// The rollappId follows the same standard as cosmos chain_id
string rollappId = 2;
// startHeight is the block height of the first block in the batch
uint64 startHeight = 3;
// numBlocks is the number of blocks included in this batch update
uint64 numBlocks = 4;
// DAPath is the description of the location on the DA layer
DAPath DAPath = 5;
// BDs is a list of block description objects (one per block)
// the list must be ordered by height, starting from startHeight to startHeight+numBlocks-1
BlockDescriptors BDs = 6 [(gogoproto.nullable) = false];
}

message MsgUpdateStateResponse {
}
1 change: 0 additions & 1 deletion x/delayedack/keeper/hooks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package keeper_test

import (
channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types"

commontypes "github.com/dymensionxyz/dymension/v3/x/common/types"
"github.com/dymensionxyz/dymension/v3/x/delayedack/types"
)
Expand Down
1 change: 0 additions & 1 deletion x/rollapp/keeper/invariants_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package keeper_test

import (
"github.com/cometbft/cometbft/libs/rand"

commontypes "github.com/dymensionxyz/dymension/v3/x/common/types"
"github.com/dymensionxyz/dymension/v3/x/rollapp/keeper"
"github.com/dymensionxyz/dymension/v3/x/rollapp/types"
Expand Down
6 changes: 6 additions & 0 deletions x/rollapp/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ type Keeper struct {
channelKeeper types.ChannelKeeper
bankKeeper types.BankKeeper

daLayers map[string]types.DALayer

finalizePending func(ctx sdk.Context, stateInfoIndex types.StateInfoIndex) error
}

Expand All @@ -39,6 +41,9 @@ func NewKeeper(
ps = ps.WithKeyTable(types.ParamKeyTable())
}

daLayers := make(map[string]types.DALayer)
daLayers[types.InterchainDALayerName] = types.NewInterchainDALayer()

k := &Keeper{
cdc: cdc,
storeKey: storeKey,
Expand All @@ -47,6 +52,7 @@ func NewKeeper(
channelKeeper: channelKeeper,
ibcClientKeeper: ibcclientKeeper,
bankKeeper: bankKeeper,
daLayers: daLayers,
}
k.SetFinalizePendingFn(k.finalizePendingState)
return k
Expand Down
16 changes: 15 additions & 1 deletion x/rollapp/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,30 @@ package keeper

import (
"github.com/dymensionxyz/dymension/v3/x/rollapp/types"
v2types "github.com/dymensionxyz/dymension/v3/x/rollapp/types/v2"
)

type msgServer struct {
Keeper
}

type msgServerV2 struct {
Keeper
}

var (
_ types.MsgServer = msgServer{}
_ v2types.MsgServer = msgServerV2{}
)

// NewMsgServerImpl returns an implementation of the MsgServer interface
// for the provided Keeper.
func NewMsgServerImpl(keeper Keeper) types.MsgServer {
return &msgServer{Keeper: keeper}
}

var _ types.MsgServer = msgServer{}
// NewMsgServerV2Impl returns an implementation of the MsgServer interface
// for the provided Keeper.
func NewMsgServerV2Impl(keeper Keeper) v2types.MsgServer {
return &msgServerV2{Keeper: keeper}
}
108 changes: 108 additions & 0 deletions x/rollapp/keeper/msg_server_update_state_v2.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
package keeper

import (
"context"

errorsmod "cosmossdk.io/errors"

sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/dymensionxyz/dymension/v3/x/rollapp/types"
v2types "github.com/dymensionxyz/dymension/v3/x/rollapp/types/v2"
)

// UpdateState updates the state of a rollapp
func (k msgServerV2) UpdateState(goCtx context.Context, msg *v2types.MsgUpdateState) (*v2types.MsgUpdateStateResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)

// load rollapp object for stateful validations
_, isFound := k.GetRollapp(ctx, msg.RollappId)
if !isFound {
return nil, types.ErrUnknownRollappID
}

// call the before-update-state hook
// checks if:
// 1. creator is the sequencer
// 2. sequencer rollappId matches the rollappId
// 3. sequencer is bonded
// 4. sequencer is the proposer
err := k.hooks.BeforeUpdateState(ctx, msg.Creator, msg.RollappId)
if err != nil {
return nil, err
}

// retrieve last updating index
var newIndex, lastIndex uint64
latestStateInfoIndex, found := k.GetLatestStateInfoIndex(ctx, msg.RollappId)
if found {
// retrieve last updating index
stateInfo, found := k.GetStateInfo(ctx, msg.RollappId, latestStateInfoIndex.Index)
// if latestStateInfoIndex exists, there must be an info for this state
if !found {
// if not, it's a logic error
return nil, errorsmod.Wrapf(types.ErrLogic,
"missing stateInfo for state-index (%d) of rollappId(%s)",
latestStateInfoIndex.Index, msg.RollappId)
}

// check to see if received height is the one we expected
expectedStartHeight := stateInfo.StartHeight + stateInfo.NumBlocks
if expectedStartHeight != msg.StartHeight {
return nil, errorsmod.Wrapf(types.ErrWrongBlockHeight,
"expected height (%d), but received (%d)",
expectedStartHeight, msg.StartHeight)
}

// bump state index
lastIndex = latestStateInfoIndex.Index
}
newIndex = lastIndex + 1

daLayer, exists := k.daLayers[msg.DAPath.DaType]
if !exists {
return nil, errorsmod.Wrapf(types.ErrInvalidDAClientType, "unknown da layer: %s", msg.DAPath.DaType)
}
if err = daLayer.OnRollappStateUpdate(ctx, msg.DAPath.Commitment); err != nil {
return nil, errorsmod.Wrapf(types.ErrDAClientValidationFailed, "da layer commitment validation failed: %s", err)
}

// Write new index information to the store
k.SetLatestStateInfoIndex(ctx, types.StateInfoIndex{
RollappId: msg.RollappId,
Index: newIndex,
})

creationHeight := uint64(ctx.BlockHeight())
daPath, err := msg.DAPath.Marshal()
if err != nil {
return nil, errorsmod.Wrapf(types.ErrInvalidDAClientType, "failed to marshal DAPath: %s", err)
}
stateInfo := types.NewStateInfo(msg.RollappId, newIndex, msg.Creator, msg.StartHeight, msg.NumBlocks, string(daPath), creationHeight, msg.BDs)
// Write new state information to the store indexed by <RollappId,LatestStateInfoIndex>
k.SetStateInfo(ctx, *stateInfo)

stateInfoIndex := stateInfo.GetIndex()
newFinalizationQueue := []types.StateInfoIndex{stateInfoIndex}

k.Logger(ctx).Debug("Adding state to finalization queue at ", creationHeight)
// load FinalizationQueue and update
blockHeightToFinalizationQueue, found := k.GetBlockHeightToFinalizationQueue(ctx, creationHeight)
if found {
newFinalizationQueue = append(blockHeightToFinalizationQueue.FinalizationQueue, newFinalizationQueue...)
}

// Write new BlockHeightToFinalizationQueue
k.SetBlockHeightToFinalizationQueue(ctx, types.BlockHeightToFinalizationQueue{
CreationHeight: creationHeight,
FinalizationQueue: newFinalizationQueue,
})

ctx.EventManager().EmitEvent(
sdk.NewEvent(types.EventTypeStateUpdate,
stateInfo.GetEvents()...,
),
)

return &v2types.MsgUpdateStateResponse{}, nil
}
Loading
Loading