Skip to content

Commit

Permalink
threads 2
Browse files Browse the repository at this point in the history
  • Loading branch information
keruch committed Sep 19, 2024
1 parent 7055acb commit 21d2986
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 34 deletions.
12 changes: 6 additions & 6 deletions x/rollapp/keeper/fraud_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,18 @@ func (k Keeper) HandleFraud(ctx sdk.Context, rollappID, clientID string, fraudHe
return errors.Join(types.ErrWrongClientId, err)
}

// slash the sequencer, clean delayed packets
err = k.hooks.FraudSubmitted(ctx, rollappID, fraudHeight, seqAddr)
if err != nil {
return err
}

// freeze the rollapp and revert all pending states
err = k.FreezeRollapp(ctx, rollappID)
if err != nil {
return fmt.Errorf("freeze rollapp: %w", err)
}

// slash the sequencer, clean delayed packets
err = k.hooks.FraudSubmitted(ctx, rollappID, fraudHeight, seqAddr)
if err != nil {
return err
}

ctx.EventManager().EmitEvent(
sdk.NewEvent(
types.EventTypeFraud,
Expand Down
11 changes: 6 additions & 5 deletions x/rollapp/keeper/msg_server_mark_vulnerable_rollapps.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,20 @@ func (k Keeper) MarkVulnerableRollapps(ctx sdk.Context, drsVersions []string) (i
}

var (
logger = k.Logger(ctx)
activeRollapps = k.FilterRollapps(ctx, FilterActive)
vulnerableNum int
logger = k.Logger(ctx)
nonVulnerable = k.FilterRollapps(ctx, FilterNonVulnerable)
vulnerableNum int
)
for _, rollapp := range activeRollapps {
for _, rollapp := range nonVulnerable {
info, found := k.GetLatestStateInfo(ctx, rollapp.RollappId)
if !found {
logger.With("rollapp_id", rollapp.RollappId).Info("no latest state info for rollapp")
continue
}
// TODO: this check may be deleted once empty DRS version is marked vulnerable
// https://github.com/dymensionxyz/dymension/issues/1233
if info.DrsVersion == "" {
logger.With("rollapp_id", rollapp.RollappId).Error("no DRS version set for rollapp")
logger.With("rollapp_id", rollapp.RollappId).Info("no DRS version set for rollapp")
}

_, vulnerable := vulnerableVersions[info.DrsVersion]
Expand Down
4 changes: 2 additions & 2 deletions x/rollapp/keeper/msg_server_mark_vulnerable_rollapps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func (s *RollappTestSuite) TestMarkVulnerableRollapps() {
s.AssertEventEmitted(s.Ctx, eventName, 0)

// check non-vulnerable rollapps: all rollapps are still non-vulnerable
nonVulnRa := s.App.RollappKeeper.FilterRollapps(s.Ctx, keeper.FilterActive)
nonVulnRa := s.App.RollappKeeper.FilterRollapps(s.Ctx, keeper.FilterNonVulnerable)
actualNonVulnRollappIDs := fpslices.Map(nonVulnRa, func(r types.Rollapp) string { return r.RollappId })
allRollapps := fpslices.Merge(expectedVulnRollappIDs, expectedNonVulnRollappIDs)
s.ElementsMatch(allRollapps, actualNonVulnRollappIDs)
Expand All @@ -171,7 +171,7 @@ func (s *RollappTestSuite) TestMarkVulnerableRollapps() {
s.AssertEventEmitted(s.Ctx, eventName, 1)

// check non-vulnerable rollapps
nonVulnRa := s.App.RollappKeeper.FilterRollapps(s.Ctx, keeper.FilterActive)
nonVulnRa := s.App.RollappKeeper.FilterRollapps(s.Ctx, keeper.FilterNonVulnerable)
actualNonVulnRollappIDs := fpslices.Map(nonVulnRa, func(r types.Rollapp) string { return r.RollappId })
s.ElementsMatch(expectedNonVulnRollappIDs, actualNonVulnRollappIDs)

Expand Down
12 changes: 7 additions & 5 deletions x/rollapp/keeper/msg_server_update_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,19 @@ func (k msgServer) UpdateState(goCtx context.Context, msg *types.MsgUpdateState)
return nil, types.ErrUnknownRollappID
}

// verify the rollapp is not vulnerable
if rollapp.IsVulnerable() {
return nil, gerrc.ErrInvalidArgument.
Wrapf("usage of vulnerable DRS version is not allowed for new rollapps, please update your DRS version: version %s", msg.DrsVersion)
}

// verify the DRS version is not vulnerable
vulnerable, err := k.IsDRSVersionVulnerable(ctx, msg.DrsVersion)
if err != nil {
return nil, fmt.Errorf("verify the DRS version is not vulnerable: %w", err)
}
if vulnerable {
if rollapp.IsVulnerable() {
return nil, gerrc.ErrInvalidArgument.
Wrapf("usage of vulnerable DRS version is not allowed for new rollapps, please update your DRS version: version %s", msg.DrsVersion)
}
// if the rollapp is not marked as vulnerable yet, then mark it now
// the rollapp is not marked as vulnerable yet, mark it now
err = k.MarkRollappAsVulnerable(ctx, msg.RollappId)
if err != nil {
return nil, fmt.Errorf("mark rollapp vulnerable: %w", err)
Expand Down
26 changes: 11 additions & 15 deletions x/rollapp/keeper/rollapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,19 +225,8 @@ func (k Keeper) RemoveRollapp(
}

// GetAllRollapps returns all rollapp
func (k Keeper) GetAllRollapps(ctx sdk.Context) (list []types.Rollapp) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.RollappKeyPrefix))
iterator := sdk.KVStorePrefixIterator(store, []byte{})

defer iterator.Close() // nolint: errcheck

for ; iterator.Valid(); iterator.Next() {
var val types.Rollapp
k.cdc.MustUnmarshal(iterator.Value(), &val)
list = append(list, val)
}

return
func (k Keeper) GetAllRollapps(ctx sdk.Context) []types.Rollapp {
return k.FilterRollapps(ctx, func(rollapp types.Rollapp) bool { return true })
}

// IsRollappStarted returns true if the rollapp is started
Expand All @@ -251,6 +240,7 @@ func (k Keeper) MarkRollappAsVulnerable(ctx sdk.Context, rollappId string) error
}

// FreezeRollapp marks the rollapp as frozen and reverts all pending states.
// NB! This method is going to be changed as soon as the "Freezing" ADR is ready.
func (k Keeper) FreezeRollapp(ctx sdk.Context, rollappID string) error {
rollapp, found := k.GetRollapp(ctx, rollappID)
if !found {
Expand All @@ -277,6 +267,12 @@ func (k Keeper) FreezeRollapp(ctx sdk.Context, rollappID string) error {
return nil
}

// verifyClientID verifies that the provided clientID is the same clientID used by the provided rollapp.
// Possible scenarios:
// 1. both channelID and clientID are empty -> okay
// 2. channelID is empty while clientID is not -> error: rollapp does not have a channel
// 3. clientID is empty while channelID is not -> error: rollapp does have a channel, but the provided clientID is empty
// 4. both channelID and clientID are not empty -> okay: compare the provided channelID against the one from IBC
func (k Keeper) verifyClientID(ctx sdk.Context, rollappID, clientID string) error {
rollapp, found := k.GetRollapp(ctx, rollappID)
if !found {
Expand Down Expand Up @@ -332,8 +328,8 @@ func (k Keeper) FilterRollapps(ctx sdk.Context, f func(types.Rollapp) bool) []ty
return result
}

func FilterActive(b types.Rollapp) bool {
return !b.Frozen
func FilterNonVulnerable(b types.Rollapp) bool {
return !b.IsVulnerable()
}

func (k Keeper) IsDRSVersionVulnerable(ctx sdk.Context, version string) (bool, error) {
Expand Down
2 changes: 1 addition & 1 deletion x/rollapp/types/message_update_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (msg *MsgUpdateState) ValidateBasic() error {
}

// TODO: add a validation for DrsVersion once empty DRS version is marked vulnerable
// if msg.DrsVersion == "" { return gerrc.ErrInvalidArgument.Wrap("DRS version must not be empty") }
// https://github.com/dymensionxyz/dymension/issues/1233

// check that the blocks are sequential by height
for bdIndex := uint64(0); bdIndex < msg.NumBlocks; bdIndex += 1 {
Expand Down

0 comments on commit 21d2986

Please sign in to comment.