Skip to content

Commit

Permalink
Revert "feat(rollapp): store all rollapp revisions (#1476)"
Browse files Browse the repository at this point in the history
This reverts commit 4cad7dc.
  • Loading branch information
danwt authored Nov 18, 2024
1 parent 2295106 commit 177e3d3
Show file tree
Hide file tree
Showing 12 changed files with 103 additions and 318 deletions.
6 changes: 2 additions & 4 deletions app/upgrades/v4/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,10 +361,8 @@ 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
Revisions: []rollapptypes.Revision{{
Number: 0,
StartHeight: 0,
}},
RevisionNumber: 0,
RevisionStartHeight: 0,
}
}

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

// 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;
// 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;
}

// Rollapp summary is a compact representation of Rollapp
Expand Down
5 changes: 2 additions & 3 deletions x/lightclient/ante/ibc_msg_update_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ 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 @@ -70,7 +69,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.LatestRevision().Number {
if header.Header.Version.App != rollapp.RevisionNumber {
return errorsmod.Wrap(gerrc.ErrFailedPrecondition, "client update revision mismatch")
}

Expand Down
3 changes: 1 addition & 2 deletions x/rollapp/keeper/fraud_proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ 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"
"github.com/dymensionxyz/gerr-cosmos/gerrc"
)

// SubmitRollappFraud handles the submission of a fraud proposal
Expand Down
6 changes: 4 additions & 2 deletions x/rollapp/keeper/hard_fork.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ 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 @@ -26,7 +27,8 @@ func (k Keeper) HardFork(ctx sdk.Context, rollappID string, newRevisionHeight ui
newRevisionHeight = lastValidHeight + 1

// update revision number
rollapp.BumpRevision(newRevisionHeight)
rollapp.RevisionNumber += 1
rollapp.RevisionStartHeight = 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.LatestRevision().Number)
suite.Require().Equal(uint64(1), rollapp.RevisionNumber)

// check states were deleted
// the last state should have height less than the fraud height
Expand Down
4 changes: 0 additions & 4 deletions x/rollapp/keeper/msg_server_create_rollapp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,6 @@ 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.LatestRevision().Number > 0
return b.RevisionNumber > 0
}

func FilterNonForked(b types.Rollapp) bool {
return b.LatestRevision().Number == 0
return b.RevisionNumber == 0
}
5 changes: 3 additions & 2 deletions x/rollapp/keeper/msg_server_update_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ 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 @@ -27,10 +28,10 @@ func (k msgServer) UpdateState(goCtx context.Context, msg *types.MsgUpdateState)
}

// validate correct rollapp revision number
if rollapp.LatestRevision().Number != msg.RollappRevision {
if rollapp.RevisionNumber != msg.RollappRevision {
return nil, errorsmod.Wrapf(types.ErrWrongRollappRevision,
"expected revision number (%d), but received (%d)",
rollapp.LatestRevision().Number, msg.RollappRevision)
rollapp.RevisionNumber, 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.LatestRevision().Number)
suite.Zero(rollapp.RevisionNumber)
}

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

Expand Down Expand Up @@ -103,22 +101,6 @@ 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 177e3d3

Please sign in to comment.