Skip to content

Commit

Permalink
fix(state-version): should be uint8 instead of uint32 (#3779)
Browse files Browse the repository at this point in the history
  • Loading branch information
radkomih committed Mar 1, 2024
1 parent f5e48a9 commit c8fdb14
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 18 deletions.
6 changes: 3 additions & 3 deletions cmd/gossamer/commands/import_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import (
func init() {
ImportStateCmd.Flags().String("chain", "", "Chain id used to load default configuration for specified chain")
ImportStateCmd.Flags().String("state-file", "", "Path to JSON file consisting of key-value pairs")
ImportStateCmd.Flags().Uint32("state-version",
uint32(trie.DefaultStateVersion),
ImportStateCmd.Flags().Uint8("state-version",
uint8(trie.DefaultStateVersion),
"State version to use when importing state",
)
ImportStateCmd.Flags().String("header-file", "", "Path to JSON file of block header corresponding to the given state")
Expand Down Expand Up @@ -60,7 +60,7 @@ func execImportState(cmd *cobra.Command) error {
return fmt.Errorf("state-file must be specified")
}

stateVersion, err := cmd.Flags().GetUint32("state-version")
stateVersion, err := cmd.Flags().GetUint8("state-version")
if err != nil {
return fmt.Errorf("failed to get state-version: %s", err)
}
Expand Down
2 changes: 1 addition & 1 deletion dot/core/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func Test_Service_StorageRoot(t *testing.T) {
retErr error
expErr error
expErrMsg string
stateVersion uint32
stateVersion uint8
}{
{
name: "storage trie state error",
Expand Down
2 changes: 1 addition & 1 deletion lib/runtime/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type Version struct {
ImplVersion uint32
APIItems []APIItem
TransactionVersion uint32
StateVersion uint32
StateVersion uint8
}

var (
Expand Down
2 changes: 1 addition & 1 deletion lib/runtime/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func Test_Version_Scale(t *testing.T) {
encoding: []byte{
0x4, 0x1, 0x4, 0x2, 0x3, 0x0, 0x0, 0x0, 0x4, 0x0, 0x0, 0x0,
0x5, 0x0, 0x0, 0x0, 0x4, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7,
0x8, 0x6, 0x0, 0x0, 0x0, 0x7, 0x0, 0x0, 0x0, 0x4, 0x0, 0x0, 0x0},
0x8, 0x6, 0x0, 0x0, 0x0, 0x7, 0x0, 0x0, 0x0, 0x4},
decoded: Version{
SpecName: []byte{1},
ImplName: []byte{2},
Expand Down
8 changes: 4 additions & 4 deletions lib/runtime/wazero/imports.go
Original file line number Diff line number Diff line change
Expand Up @@ -795,7 +795,7 @@ func ext_trie_blake2_256_root_version_2(ctx context.Context, m api.Module, dataS
panic("nil runtime context")
}

stateVersion, err := trie.ParseVersion(version)
stateVersion, err := trie.ParseVersion(uint8(version))
if err != nil {
logger.Errorf("failed parsing state version: %s", err)
return 0
Expand Down Expand Up @@ -841,7 +841,7 @@ func ext_trie_blake2_256_ordered_root_version_2(

data := read(m, dataSpan)

stateVersion, err := trie.ParseVersion(version)
stateVersion, err := trie.ParseVersion(uint8(version))
if err != nil {
logger.Errorf("failed parsing state version: %s", err)
return 0
Expand Down Expand Up @@ -923,7 +923,7 @@ func ext_trie_blake2_256_verify_proof_version_2(
panic("nil runtime context")
}

_, err := trie.ParseVersion(version)
_, err := trie.ParseVersion(uint8(version))
if err != nil {
logger.Errorf("failed parsing state version: %s", err)
return 0
Expand Down Expand Up @@ -1275,7 +1275,7 @@ func ext_default_child_storage_root_version_2(ctx context.Context, m api.Module,
return mustWrite(m, rtCtx.Allocator, emptyByteVectorEncoded)
}

stateVersion, err := trie.ParseVersion(version)
stateVersion, err := trie.ParseVersion(uint8(version))
if err != nil {
logger.Errorf("failed parsing state version: %s", err)
return 0
Expand Down
4 changes: 2 additions & 2 deletions pkg/trie/layout.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,12 @@ func (v TrieLayout) MustHash(t Trie) common.Hash {
}

// ParseVersion parses a state trie version string.
func ParseVersion[T string | uint32](v T) (version TrieLayout, err error) {
func ParseVersion[T string | uint8](v T) (version TrieLayout, err error) {
var s string
switch value := any(v).(type) {
case string:
s = value
case uint32:
case uint8:
s = fmt.Sprintf("V%d", value)
}

Expand Down
12 changes: 6 additions & 6 deletions pkg/trie/layout_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func Test_ParseVersion(t *testing.T) {
version: V0,
},
"0": {
v: uint32(0),
v: uint8(0),
version: V0,
},
"v1": {
Expand All @@ -76,18 +76,18 @@ func Test_ParseVersion(t *testing.T) {
version: V1,
},
"1": {
v: uint32(1),
v: uint8(1),
version: V1,
},
"invalid": {
v: "xyz",
errWrapped: ErrParseVersion,
errMessage: "parsing version failed: \"xyz\" must be one of [v0, v1]",
},
"invalid_uint32": {
v: uint32(999),
"invalid_uint8": {
v: uint8(99),
errWrapped: ErrParseVersion,
errMessage: "parsing version failed: \"V999\" must be one of [v0, v1]",
errMessage: "parsing version failed: \"V99\" must be one of [v0, v1]",
},
}

Expand All @@ -102,7 +102,7 @@ func Test_ParseVersion(t *testing.T) {
switch typed := testCase.v.(type) {
case string:
version, err = ParseVersion(typed)
case uint32:
case uint8:
version, err = ParseVersion(typed)
default:
t.Fail()
Expand Down

0 comments on commit c8fdb14

Please sign in to comment.