Skip to content

Commit

Permalink
fix(rollappparams): change DRS version from commit to int (#585)
Browse files Browse the repository at this point in the history
  • Loading branch information
srene authored Oct 30, 2024
1 parent 5450517 commit 88f668f
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 91 deletions.
4 changes: 2 additions & 2 deletions proto/rollappparams/params.proto
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ option go_package = "github.com/dymensionxyz/dymension-rdk/x/rollappparams/types
message Params {
// data availability type (e.g. celestia) used in the rollapp
string da = 1;
// commit of the version used for the rollapp executable
string version = 2;
// drs version
uint32 drs_version = 2;
}
3 changes: 0 additions & 3 deletions testutil/utils/test_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
app "github.com/dymensionxyz/dymension-rdk/testutil/app"

hubgenesistypes "github.com/dymensionxyz/dymension-rdk/x/hub-genesis/types"
rollappparamstypes "github.com/dymensionxyz/dymension-rdk/x/rollappparams/types"

"github.com/stretchr/testify/require"

Expand Down Expand Up @@ -89,8 +88,6 @@ func setup(withGenesis bool, invCheckPeriod uint) (*app.App, map[string]json.Raw
log.NewNopLogger(), db, nil, true, map[int64]bool{}, "/tmp", invCheckPeriod, encCdc, app.GetEnabledProposals(), EmptyAppOptions{}, emptyWasmOpts,
)
if withGenesis {
// override the rollapp version, so we'll have a valid default genesis
rollappparamstypes.Version = "5f8393904fb1e9c616fe89f013cafe7501a63f86"
return testApp, app.NewDefaultGenesisState(encCdc.Codec)
}
return testApp, map[string]json.RawMessage{}
Expand Down
2 changes: 1 addition & 1 deletion x/rollappparams/keeper/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func TestGenesis(t *testing.T) {

state := types.GenesisState{}

state.Params = types.NewParams("mock", "5f8393904fb1e9c616fe89f013cafe7501a63f86")
state.Params = types.NewParams("mock", 1)

k.InitGenesis(ctx, &state)
got := k.ExportGenesis(ctx)
Expand Down
2 changes: 1 addition & 1 deletion x/rollappparams/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (k Keeper) DA(ctx sdk.Context) (res string) {
return
}

func (k Keeper) Version(ctx sdk.Context) (res string) {
func (k Keeper) Version(ctx sdk.Context) (res uint32) {
k.paramSpace.Get(ctx, types.KeyVersion, &res)
return
}
26 changes: 4 additions & 22 deletions x/rollappparams/types/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

func TestGenesisState(t *testing.T) {

testParams := types.NewParams("mock", "5f8393904fb1e9c616fe89f013cafe7501a63f86")
testParams := types.NewParams("mock", 1)
testCases := []struct {
name string
params func() types.Params
Expand All @@ -24,28 +24,10 @@ func TestGenesisState(t *testing.T) {
},
},
{
name: "missing version",
name: "wrong drs version",
params: func() types.Params {
p := testParams
p.Version = ""
return p
},
expectedErr: true,
},
{
name: "wrong length version",
params: func() types.Params {
p := testParams
p.Version = "fdasfewkq102382w523"
return p
},
expectedErr: true,
},
{
name: "version not alphanumeric",
params: func() types.Params {
p := testParams
p.Version = "3a19edd887_9b576a866750bc9d480ada53d2c0d"
p.DrsVersion = 0
return p
},
expectedErr: true,
Expand All @@ -56,7 +38,7 @@ func TestGenesisState(t *testing.T) {
state := types.NewGenesisState(tc.params())
err := types.ValidateGenesis(state)
if tc.expectedErr {
require.ErrorIs(t, err, gerrc.ErrInvalidArgument)
require.Error(t, err, gerrc.ErrInvalidArgument)
} else {
require.NoError(t, err)
}
Expand Down
38 changes: 15 additions & 23 deletions x/rollappparams/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@ package types

import (
"fmt"
"regexp"

paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
"github.com/dymensionxyz/dymint/da/registry"
"github.com/dymensionxyz/gerr-cosmos/gerrc"
)

const (
// length of the version commit string.
VersionLength = 40

// Data availability used by the RollApp. Default value used is mock da.
DefaultDA = "mock"
)
Expand All @@ -20,12 +18,8 @@ const (
var (
KeyDa = []byte("da")
KeyVersion = []byte("version")

// git commit for the version used for the rollapp binary. it must be overwritten in the build process
Version = "<version>"
// default max block size accepted (equivalent to block max size it can fit into a celestia blob).
// regexp used to validate version commit
VersionRegExp = regexp.MustCompile(`^[a-z0-9]*$`)
// Default version set
DrsVersion = uint32(1)
)

func ParamKeyTable() paramtypes.KeyTable {
Expand All @@ -35,19 +29,19 @@ func ParamKeyTable() paramtypes.KeyTable {
// NewParams creates a new Params object
func NewParams(
da string,
version string,
drsVersion uint32,
) Params {
return Params{
Da: da,
Version: version,
Da: da,
DrsVersion: drsVersion,
}
}

// DefaultParams returns default x/rollappparams module parameters.
func DefaultParams() Params {
return Params{
Da: DefaultDA,
Version: Version,
Da: DefaultDA,
DrsVersion: DrsVersion,
}
}

Expand All @@ -56,10 +50,11 @@ func (p Params) Validate() error {
if err != nil {
return err
}
err = ValidateVersion(p.Version)
err = ValidateVersion(p.DrsVersion)
if err != nil {
return err
}

return nil
}

Expand All @@ -73,25 +68,22 @@ func ValidateDa(i any) error {
}

func ValidateVersion(i any) error {

version, ok := i.(string)
version, ok := i.(uint32)
if !ok {
return fmt.Errorf("invalid version type param type: %w", gerrc.ErrInvalidArgument)
}
if len(version) != VersionLength {
return fmt.Errorf("invalid version length: param length: %d accepted: %d: %w", len(version), VersionLength, gerrc.ErrInvalidArgument)
}
if !VersionRegExp.MatchString(version) {
return fmt.Errorf("invalid version: it must be alphanumeric %w", gerrc.ErrInvalidArgument)
if version <= 0 {
return fmt.Errorf("invalid DRS version: Version must be positive")
}

return nil

}

// Implements params.ParamSet.
func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs {
return paramtypes.ParamSetPairs{
paramtypes.NewParamSetPair(KeyDa, &p.Da, ValidateDa),
paramtypes.NewParamSetPair(KeyVersion, &p.Version, ValidateVersion),
paramtypes.NewParamSetPair(KeyVersion, &p.DrsVersion, ValidateVersion),
}
}
63 changes: 24 additions & 39 deletions x/rollappparams/types/params.pb.go

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

0 comments on commit 88f668f

Please sign in to comment.