Skip to content

Commit

Permalink
fixed unbond store
Browse files Browse the repository at this point in the history
  • Loading branch information
mtsitrin committed Nov 13, 2024
1 parent d0fb6c8 commit 4918834
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
32 changes: 19 additions & 13 deletions x/sequencer/keeper/msg_server_bond.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,33 +61,39 @@ func (k msgServer) Unbond(goCtx context.Context, msg *types.MsgUnbond) (*types.M
return nil, err
}

// not allowed to unbond immediately, need to serve a notice to allow the rollapp community to organise
// Also, if they already requested to unbond, we don't want to start another notice period, regardless
// of if their notice already elapsed or not.
if k.AwaitingLastProposerBlock(ctx, seq.RollappId) && (k.IsProposer(ctx, seq) || k.IsSuccessor(ctx, seq)) {
return nil, gerrc.ErrFailedPrecondition.Wrap("cannot unbond while rotation in progress")
}

// ensures they will not get chosen as their own successor!
if err := seq.SetOptedIn(ctx, false); err != nil {
return nil, err
}
err = k.TryUnbond(ctx, &seq, seq.TokensCoin())
if errorsmod.IsOf(err, types.ErrUnbondProposerOrSuccessor) {
// not allowed to unbond immediately, need to serve a notice to allow the rollapp community to organise
// Also, if they already requested to unbond, we don't want to start another notice period, regardless
// of if their notice already elapsed or not.
if k.IsSuccessor(ctx, seq) {
return nil, gerrc.ErrFailedPrecondition.Wrap("successor cannot unbond or start notice")
}
// now we know they are proposer
// avoid starting another notice unnecessarily
if !k.RotationInProgress(ctx, seq.RollappId) {
k.StartNoticePeriod(ctx, &seq)

// now we know they are proposer
// avoid starting another notice unnecessarily
if k.IsProposer(ctx, seq) {
if seq.NoticeInProgress(ctx.BlockTime()) {
return nil, gerrc.ErrFailedPrecondition.Wrap("notice period in progress")
}

k.StartNoticePeriod(ctx, &seq)
k.SetSequencer(ctx, seq)
return &types.MsgUnbondResponse{
CompletionTime: &types.MsgUnbondResponse_NoticePeriodCompletionTime{
NoticePeriodCompletionTime: &seq.NoticePeriodTime,
},
}, nil

}

err = k.TryUnbond(ctx, &seq, seq.TokensCoin())
if err != nil {
return nil, errorsmod.Wrap(err, "try unbond")
}

k.SetSequencer(ctx, seq)

return &types.MsgUnbondResponse{}, nil
Expand Down
6 changes: 2 additions & 4 deletions x/sequencer/keeper/rotation.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,19 +84,17 @@ func (k Keeper) OnProposerLastBlock(ctx sdk.Context, proposer types.Sequencer) e
rollapp := proposer.RollappId

successor := k.GetSuccessor(ctx, rollapp)
k.SetSuccessor(ctx, rollapp, types.SentinelSeqAddr) // clear successor
k.SetProposer(ctx, rollapp, successor.Address)

// if proposer is sentinel, prepare new revision for the rollapp
if successor.Sentinel() {
err := k.rollappKeeper.HardForkToLatest(ctx, rollapp)
if err != nil {
return errorsmod.Wrap(err, "hard fork to latest")
}
return nil
}

k.SetProposer(ctx, rollapp, successor.Address)
k.SetSuccessor(ctx, rollapp, types.SentinelSeqAddr) // clear successor

ctx.EventManager().EmitEvent(
sdk.NewEvent(
types.EventTypeProposerRotated,
Expand Down

0 comments on commit 4918834

Please sign in to comment.