Skip to content

Commit

Permalink
drs version moved to bds
Browse files Browse the repository at this point in the history
  • Loading branch information
srene committed Oct 11, 2024
1 parent 3f08435 commit 795b033
Show file tree
Hide file tree
Showing 10 changed files with 205 additions and 257 deletions.
3 changes: 1 addition & 2 deletions app/apptesting/test_suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func (s *KeeperTestHelper) PostStateUpdateWithDRSVersion(ctx sdk.Context, rollap
var bds rollapptypes.BlockDescriptors
bds.BD = make([]rollapptypes.BlockDescriptor, numOfBlocks)
for k := uint64(0); k < numOfBlocks; k++ {
bds.BD[k] = rollapptypes.BlockDescriptor{Height: startHeight + k, Timestamp: time.Now().UTC()}
bds.BD[k] = rollapptypes.BlockDescriptor{Height: startHeight + k, Timestamp: time.Now().UTC(), DrsVersion: drsVersion}
}

updateState := rollapptypes.MsgUpdateState{
Expand All @@ -133,7 +133,6 @@ func (s *KeeperTestHelper) PostStateUpdateWithDRSVersion(ctx sdk.Context, rollap
DAPath: "",
BDs: bds,
Last: false,
DrsVersion: drsVersion,
}
msgServer := rollappkeeper.NewMsgServerImpl(*s.App.RollappKeeper)
_, err = msgServer.UpdateState(ctx, &updateState)
Expand Down
2 changes: 2 additions & 0 deletions proto/dymensionxyz/dymension/rollapp/block_descriptor.proto
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ message BlockDescriptor {
bytes stateRoot = 2;
// timestamp is the time from the block header
google.protobuf.Timestamp timestamp = 3 [(gogoproto.nullable) = false, (gogoproto.stdtime) = true];
// DrsVersion is a DRS version used by the rollapp.
string drs_version = 4;
}

// BlockDescriptors defines list of BlockDescriptor.
Expand Down
2 changes: 0 additions & 2 deletions proto/dymensionxyz/dymension/rollapp/state_info.proto
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ message StateInfo {
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"created_at\""
];
// DrsVersion is a DRS version used by the rollapp.
string drs_version = 11;
}

// StateInfoSummary is a compact representation of StateInfo
Expand Down
2 changes: 0 additions & 2 deletions proto/dymensionxyz/dymension/rollapp/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,6 @@ message MsgUpdateState {
BlockDescriptors BDs = 7 [(gogoproto.nullable) = false];
// last is true if this is the last batch of the sequencer
bool last = 8;
// DrsVersion is a DRS version used by the rollapp.
string drs_version = 9;
}

message MsgUpdateStateResponse {
Expand Down
25 changes: 14 additions & 11 deletions x/rollapp/keeper/msg_server_mark_vulnerable_rollapps.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,22 @@ func (k Keeper) MarkVulnerableRollapps(ctx sdk.Context, drsVersions []string) (i
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).Info("no DRS version set for rollapp")
}

_, vulnerable := vulnerableVersions[info.DrsVersion]
if vulnerable {
err := k.MarkRollappAsVulnerable(ctx, rollapp.RollappId)
if err != nil {
return 0, fmt.Errorf("freeze rollapp: %w", err)
for _, bd := range info.BDs.BD {
// TODO: this check may be deleted once empty DRS version is marked vulnerable
// https://github.com/dymensionxyz/dymension/issues/1233
if bd.DrsVersion == "" {
logger.With("rollapp_id", rollapp.RollappId).Info("no DRS version set for rollapp")
}

_, vulnerable := vulnerableVersions[bd.DrsVersion]
if vulnerable {
err := k.MarkRollappAsVulnerable(ctx, rollapp.RollappId)
if err != nil {
return 0, fmt.Errorf("freeze rollapp: %w", err)
}
vulnerableNum++
}
vulnerableNum++
}
}

Expand Down
23 changes: 12 additions & 11 deletions x/rollapp/keeper/msg_server_update_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,19 @@ func (k msgServer) UpdateState(goCtx context.Context, msg *types.MsgUpdateState)
return nil, errorsmod.Wrap(err, "before update state")
}

// verify the DRS version is not vulnerable
if k.IsDRSVersionVulnerable(ctx, msg.DrsVersion) {
// 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)
for _, bd := range msg.BDs.BD {
// verify the DRS version is not vulnerable
if k.IsDRSVersionVulnerable(ctx, bd.DrsVersion) {
// 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)
}
k.Logger(ctx).With("rollapp_id", msg.RollappId, "drs_version", bd.DrsVersion).
Info("non-frozen rollapp tried to submit MsgUpdateState with the vulnerable DRS version, mark the rollapp as vulnerable")
// we must return non-error if we want the changes to be saved
return &types.MsgUpdateStateResponse{}, nil
}
k.Logger(ctx).With("rollapp_id", msg.RollappId, "drs_version", msg.DrsVersion).
Info("non-frozen rollapp tried to submit MsgUpdateState with the vulnerable DRS version, mark the rollapp as vulnerable")
// we must return non-error if we want the changes to be saved
return &types.MsgUpdateStateResponse{}, nil
}

// retrieve last updating index
Expand Down Expand Up @@ -107,7 +109,6 @@ func (k msgServer) UpdateState(goCtx context.Context, msg *types.MsgUpdateState)
creationHeight,
msg.BDs,
blockTime,
msg.DrsVersion,
)
// Write new state information to the store indexed by <RollappId,LatestStateInfoIndex>
k.SetStateInfo(ctx, *stateInfo)
Expand Down
94 changes: 74 additions & 20 deletions x/rollapp/types/block_descriptor.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions x/rollapp/types/state_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ func NewStateInfo(
height uint64,
BDs BlockDescriptors,
createdAt time.Time,
drsVersion string,
) *StateInfo {
stateInfoIndex := StateInfoIndex{RollappId: rollappId, Index: newIndex}
status := common.Status_PENDING
Expand All @@ -33,7 +32,6 @@ func NewStateInfo(
Status: status,
BDs: BDs,
CreatedAt: createdAt,
DrsVersion: drsVersion,
}
}

Expand Down
Loading

0 comments on commit 795b033

Please sign in to comment.