Skip to content

Commit

Permalink
feat(rollapp): store all rollapp revisions (#1476)
Browse files Browse the repository at this point in the history
  • Loading branch information
keruch authored Nov 18, 2024
1 parent f74b114 commit 4cad7dc
Show file tree
Hide file tree
Showing 12 changed files with 318 additions and 103 deletions.
6 changes: 4 additions & 2 deletions app/upgrades/v4/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,8 +349,10 @@ func ConvertOldRollappToNew(oldRollapp rollapptypes.Rollapp) rollapptypes.Rollap
PreLaunchTime: nil, // We can just let it be zero. Existing rollapps are already launched.
LivenessEventHeight: 0, // Filled lazily in runtime
LastStateUpdateHeight: 0, // Filled lazily in runtime
RevisionNumber: 0,
RevisionStartHeight: 0,
Revisions: []rollapptypes.Revision{{
Number: 0,
StartHeight: 0,
}},
}
}

Expand Down
14 changes: 10 additions & 4 deletions proto/dymensionxyz/dymension/rollapp/rollapp.proto
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,16 @@ message Rollapp {
// received
int64 last_state_update_height = 18;

// The revision number of the rollapp. starts always with 0 revision
uint64 revision_number = 19;
// The first height of the rollapp when the revision started
uint64 revision_start_height = 20;
// Revisions is a list of all the rollapp revisions.
repeated Revision revisions = 19 [ (gogoproto.nullable) = false ];
}

// Revision is a representation of the rollapp revision.
message Revision {
// Number is the revision number of the rollapp. Always start with 0 revision.
uint64 number = 19;
// StartHeight is the first height of the rollapp when the revision started.
uint64 start_height = 20;
}

// Rollapp summary is a compact representation of Rollapp
Expand Down
5 changes: 3 additions & 2 deletions x/lightclient/ante/ibc_msg_update_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
ibcclienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types"
ibctm "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint"
"github.com/dymensionxyz/gerr-cosmos/gerrc"

"github.com/dymensionxyz/dymension/v3/x/lightclient/types"
rollapptypes "github.com/dymensionxyz/dymension/v3/x/rollapp/types"
sequencertypes "github.com/dymensionxyz/dymension/v3/x/sequencer/types"
"github.com/dymensionxyz/gerr-cosmos/gerrc"
)

func (i IBCMessagesDecorator) HandleMsgUpdateClient(ctx sdk.Context, msg *ibcclienttypes.MsgUpdateClient) error {
Expand Down Expand Up @@ -69,7 +70,7 @@ func (i IBCMessagesDecorator) HandleMsgUpdateClient(ctx sdk.Context, msg *ibccli

// this disallows LC updates from previous revisions but should be fine since new state roots can be used to prove
// state older than the one in the current state root.
if header.Header.Version.App != rollapp.RevisionNumber {
if header.Header.Version.App != rollapp.LatestRevision().Number {
return errorsmod.Wrap(gerrc.ErrFailedPrecondition, "client update revision mismatch")
}

Expand Down
3 changes: 2 additions & 1 deletion x/rollapp/keeper/fraud_proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import (
errorsmod "cosmossdk.io/errors"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/dymensionxyz/dymension/v3/x/rollapp/types"
"github.com/dymensionxyz/gerr-cosmos/gerrc"

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

// SubmitRollappFraud handles the submission of a fraud proposal
Expand Down
6 changes: 2 additions & 4 deletions x/rollapp/keeper/hard_fork.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ import (
"sort"

errorsmod "cosmossdk.io/errors"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/dymensionxyz/gerr-cosmos/gerrc"

common "github.com/dymensionxyz/dymension/v3/x/common/types"
"github.com/dymensionxyz/dymension/v3/x/rollapp/types"
"github.com/dymensionxyz/gerr-cosmos/gerrc"
)

// HardFork handles the fraud evidence submitted by the user.
Expand All @@ -27,8 +26,7 @@ func (k Keeper) HardFork(ctx sdk.Context, rollappID string, newRevisionHeight ui
newRevisionHeight = lastValidHeight + 1

// update revision number
rollapp.RevisionNumber += 1
rollapp.RevisionStartHeight = newRevisionHeight
rollapp.BumpRevision(newRevisionHeight)

// stop liveness events
k.ResetLivenessClock(ctx, &rollapp)
Expand Down
2 changes: 1 addition & 1 deletion x/rollapp/keeper/hard_fork_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func (suite *RollappTestSuite) TestHardFork_AlreadyFinalized() {
func (suite *RollappTestSuite) assertFraudHandled(rollappId string, height uint64) {
rollapp, found := suite.App.RollappKeeper.GetRollapp(suite.Ctx, rollappId)
suite.Require().True(found)
suite.Require().Equal(uint64(1), rollapp.RevisionNumber)
suite.Require().Equal(uint64(1), rollapp.LatestRevision().Number)

// check states were deleted
// the last state should have height less than the fraud height
Expand Down
4 changes: 4 additions & 0 deletions x/rollapp/keeper/msg_server_create_rollapp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,10 @@ func (suite *RollappTestSuite) createRollappWithCreatorAndVerify(
VmType: types.Rollapp_EVM,
Metadata: rollapp.GetMetadata(),
GenesisInfo: *rollapp.GetGenesisInfo(),
Revisions: []types.Revision{{
Number: 0,
StartHeight: 0,
}},
}

// create rollapp
Expand Down
4 changes: 2 additions & 2 deletions x/rollapp/keeper/msg_server_mark_obsolete_rollapps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,9 @@ func (s *RollappTestSuite) TestMarkObsoleteRollapps() {
}

func FilterForked(b types.Rollapp) bool {
return b.RevisionNumber > 0
return b.LatestRevision().Number > 0
}

func FilterNonForked(b types.Rollapp) bool {
return b.RevisionNumber == 0
return b.LatestRevision().Number == 0
}
5 changes: 2 additions & 3 deletions x/rollapp/keeper/msg_server_update_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (

errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/dymensionxyz/gerr-cosmos/gerrc"

"github.com/dymensionxyz/dymension/v3/x/rollapp/types"
Expand All @@ -28,10 +27,10 @@ func (k msgServer) UpdateState(goCtx context.Context, msg *types.MsgUpdateState)
}

// validate correct rollapp revision number
if rollapp.RevisionNumber != msg.RollappRevision {
if rollapp.LatestRevision().Number != msg.RollappRevision {
return nil, errorsmod.Wrapf(types.ErrWrongRollappRevision,
"expected revision number (%d), but received (%d)",
rollapp.RevisionNumber, msg.RollappRevision)
rollapp.LatestRevision().Number, msg.RollappRevision)
}

// retrieve last updating index
Expand Down
2 changes: 1 addition & 1 deletion x/rollapp/keeper/rollapp_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func TestRollappKeeperTestSuite(t *testing.T) {

func (suite *RollappTestSuite) assertNotForked(rollappID string) {
rollapp, _ := suite.App.RollappKeeper.GetRollapp(suite.Ctx, rollappID)
suite.Zero(rollapp.RevisionNumber)
suite.Zero(rollapp.LatestRevision().Number)
}

func (suite *RollappTestSuite) GetRollappLastHeight(rollappID string) uint64 {
Expand Down
22 changes: 20 additions & 2 deletions x/rollapp/types/rollapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,10 @@ func NewRollapp(
GenesisState: RollappGenesisState{
TransfersEnabled: transfersEnabled,
},
RevisionNumber: 0,
RevisionStartHeight: 0,
Revisions: []Revision{{
Number: 0,
StartHeight: 0,
}},
}
}

Expand Down Expand Up @@ -101,6 +103,22 @@ func (r Rollapp) GenesisInfoFieldsAreSet() bool {
return r.GenesisInfo.AllSet()
}

func (r Rollapp) LatestRevision() Revision {
if len(r.Revisions) == 0 {
// Revision 0 if no revisions exist.
// Should happen only in tests.
return Revision{}
}
return r.Revisions[len(r.Revisions)-1]
}

func (r *Rollapp) BumpRevision(nextRevisionStartHeight uint64) {
r.Revisions = append(r.Revisions, Revision{
Number: r.LatestRevision().Number + 1,
StartHeight: nextRevisionStartHeight,
})
}

func validateInitialSequencer(initialSequencer string) error {
if initialSequencer == "" || initialSequencer == "*" {
return nil
Expand Down
Loading

0 comments on commit 4cad7dc

Please sign in to comment.