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

fix: accept rollapp initial state with arbitrary height #687

Merged
merged 3 commits into from
Mar 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
25 changes: 8 additions & 17 deletions x/rollapp/keeper/msg_server_update_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,23 +58,13 @@ func (k msgServer) UpdateState(goCtx context.Context, msg *types.MsgUpdateState)
}

// retrieve last updating index
latestStateInfoIndex, isFound := k.GetLatestStateInfoIndex(ctx, msg.RollappId)
var newIndex uint64
if !isFound {
// check to see if it's the first update
if msg.StartHeight != 1 {
// if not, it's an error
return nil, sdkerrors.Wrapf(types.ErrWrongBlockHeight,
"expected height 1, but received (%d)",
msg.StartHeight)
}
// else, it's the first update
newIndex = 1
} else {
var newIndex, lastIndex uint64
latestStateInfoIndex, found := k.GetLatestStateInfoIndex(ctx, msg.RollappId)
if found {
// retrieve last updating index
stateInfo, isFound := k.GetStateInfo(ctx, msg.RollappId, latestStateInfoIndex.Index)
// Check Error: if latestStateInfoIndex exists, there must me an info for this state
if !isFound {
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, sdkerrors.Wrapf(sdkerrors.ErrLogic,
"missing stateInfo for state-index (%d) of rollappId(%s)",
Expand All @@ -90,8 +80,9 @@ func (k msgServer) UpdateState(goCtx context.Context, msg *types.MsgUpdateState)
}

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

// Write new index information to the store
k.SetLatestStateInfoIndex(ctx, types.StateInfoIndex{
Expand Down
42 changes: 2 additions & 40 deletions x/rollapp/keeper/msg_server_update_state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,45 +324,7 @@ func (suite *RollappTestSuite) TestUpdateStateErrLogicUnpermissioned() {
suite.ErrorIs(err, sdkerrors.ErrLogic)
}

func (suite *RollappTestSuite) TestFirstUpdateStateErrWrongBlockHeightInitial() {
suite.SetupTest()
goCtx := sdk.WrapSDKContext(suite.Ctx)

// set rollapp
rollapp := types.Rollapp{
RollappId: "rollapp1",
Creator: alice,
Version: 3,
MaxSequencers: 1,
PermissionedAddresses: []string{},
}
suite.App.RollappKeeper.SetRollapp(suite.Ctx, rollapp)

// set sequencer
sequencer := sequencertypes.Sequencer{
SequencerAddress: bob,
RollappId: "rollapp1",
Status: sequencertypes.Bonded,
Proposer: true,
}
suite.App.SequencerKeeper.SetSequencer(suite.Ctx, sequencer)

// update state
updateState := types.MsgUpdateState{
Creator: bob,
RollappId: rollapp.GetRollappId(),
StartHeight: 0,
NumBlocks: 3,
DAPath: "",
Version: 3,
BDs: types.BlockDescriptors{BD: []types.BlockDescriptor{{Height: 0}, {Height: 1}}},
}

_, err := suite.msgServer.UpdateState(goCtx, &updateState)
suite.ErrorIs(err, types.ErrWrongBlockHeight)
}

func (suite *RollappTestSuite) TestFirstUpdateStateErrWrongBlockHeight() {
func (suite *RollappTestSuite) TestFirstUpdateStateGensisHightGreaterThanZero() {
suite.SetupTest()
goCtx := sdk.WrapSDKContext(suite.Ctx)

Expand Down Expand Up @@ -397,7 +359,7 @@ func (suite *RollappTestSuite) TestFirstUpdateStateErrWrongBlockHeight() {
}

_, err := suite.msgServer.UpdateState(goCtx, &updateState)
suite.ErrorIs(err, types.ErrWrongBlockHeight)
suite.NoError(err)
}

func (suite *RollappTestSuite) TestUpdateStateErrWrongBlockHeight() {
Expand Down
Loading