diff --git a/client/consensus/grandpa/aux_schema.go b/client/consensus/grandpa/aux_schema.go index b91073a38c..57333e91bb 100644 --- a/client/consensus/grandpa/aux_schema.go +++ b/client/consensus/grandpa/aux_schema.go @@ -13,10 +13,10 @@ import ( ) var ( - SET_STATE_KEY = []byte("grandpa_completed_round") - CONCLUDED_ROUNDS = []byte("grandpa_concluded_rounds") - AUTHORITY_SET_KEY = []byte("grandpa_voters") - BEST_JUSTIFICATION = []byte("grandpa_best_justification") + setStateKey = []byte("grandpa_completed_round") + concludedRounds = []byte("grandpa_concluded_rounds") + authoritySetKey = []byte("grandpa_voters") + bestJustification = []byte("grandpa_best_justification") errValueNotFound = errors.New("value not found") ) @@ -54,7 +54,7 @@ func loadDecoded(store api.AuxStore, key []byte, destination any) (any, error) { // genesis := grandpa.HashNumber[H, N]{Hash: genesisHash, Number: genesisNumber} // makeGenesisRound := grandpa.NewRoundState[H, N] // -// authSetOld, err := loadDecoded(store, AUTHORITY_SET_KEY, AuthoritySet[H, N]{}) +// authSetOld, err := loadDecoded(store, authoritySetKey, AuthoritySet[H, N]{}) // if err != nil && !errors.Is(err, errValueNotFound) { // return nil, err // } @@ -63,7 +63,7 @@ func loadDecoded(store api.AuxStore, key []byte, destination any) (any, error) { // // if !errors.Is(err, errValueNotFound) { // // This fails currently -// setStateOld, err := loadDecoded(store, SET_STATE_KEY, voterSetState[H, N]{}) +// setStateOld, err := loadDecoded(store, setStateKey, voterSetState[H, N]{}) // if err != nil && !errors.Is(err, errValueNotFound) { // return nil, err // } @@ -117,8 +117,8 @@ func loadDecoded(store api.AuxStore, key []byte, destination any) (any, error) { // } // // insert := []api.KeyValue{ -// {AUTHORITY_SET_KEY, scale.MustMarshal(*genesisSet)}, -// {SET_STATE_KEY, scale.MustMarshal(genesisState)}, +// {authoritySetKey, scale.MustMarshal(*genesisSet)}, +// {setStateKey, scale.MustMarshal(genesisState)}, // } // // err = store.Insert(insert, nil) @@ -144,7 +144,7 @@ func loadPersistent[H comparable, N constraints.Unsigned](store api.AuxStore, ge PendingStandardChanges: NewChangeTree[H, N](), } var setState voterSetState[H, N] - encodedAuthSet, err := store.Get(AUTHORITY_SET_KEY) + encodedAuthSet, err := store.Get(authoritySetKey) if err != nil { return nil, err } @@ -156,7 +156,7 @@ func loadPersistent[H comparable, N constraints.Unsigned](store api.AuxStore, ge return nil, err } - encodedSetState, err := store.Get(SET_STATE_KEY) + encodedSetState, err := store.Get(setStateKey) if err != nil { return nil, err } @@ -215,8 +215,8 @@ func loadPersistent[H comparable, N constraints.Unsigned](store api.AuxStore, ge } insert := []api.KeyValue{ - {AUTHORITY_SET_KEY, scale.MustMarshal(*genesisSet)}, - {SET_STATE_KEY, scale.MustMarshal(genesisState)}, + {authoritySetKey, scale.MustMarshal(*genesisSet)}, + {setStateKey, scale.MustMarshal(genesisState)}, } err = store.Insert(insert, nil) @@ -264,8 +264,8 @@ func UpdateAuthoritySet[H comparable, N constraints.Unsigned](set AuthoritySet[H } insert := []api.KeyValue{ - {AUTHORITY_SET_KEY, encodedAuthSet}, - {SET_STATE_KEY, encodedVoterSet}, + {authoritySetKey, encodedAuthSet}, + {setStateKey, encodedVoterSet}, } err = write(insert) if err != nil { @@ -274,7 +274,7 @@ func UpdateAuthoritySet[H comparable, N constraints.Unsigned](set AuthoritySet[H } else { insert := []api.KeyValue{ - {AUTHORITY_SET_KEY, encodedAuthSet}, + {authoritySetKey, encodedAuthSet}, } err = write(insert) @@ -308,7 +308,7 @@ func WriteVoterSetState[H comparable, N constraints.Unsigned](setState voterSetS return err } insert := []api.KeyValue{ - {SET_STATE_KEY, encodedVoterSet}, + {setStateKey, encodedVoterSet}, } err = write(insert) if err != nil { @@ -319,7 +319,7 @@ func WriteVoterSetState[H comparable, N constraints.Unsigned](setState voterSetS // WriteConcludedRound Write concluded round. func WriteConcludedRound[H comparable, N constraints.Unsigned](roundData completedRound[H, N], write writeAux) error { - key := CONCLUDED_ROUNDS + key := concludedRounds encodedRoundNumber, err := scale.Marshal(roundData.Number) if err != nil { return err diff --git a/client/consensus/grandpa/aux_schema_test.go b/client/consensus/grandpa/aux_schema_test.go index 7fcfcfbeb6..3a8b6ee914 100644 --- a/client/consensus/grandpa/aux_schema_test.go +++ b/client/consensus/grandpa/aux_schema_test.go @@ -65,25 +65,25 @@ func newDummyStore(t *testing.T) *dummyStore { func TestDummyStore(t *testing.T) { store := newDummyStore(t) insert := []api.KeyValue{ - {AUTHORITY_SET_KEY, scale.MustMarshal([]byte{1})}, - {SET_STATE_KEY, scale.MustMarshal([]byte{2})}, + {authoritySetKey, scale.MustMarshal([]byte{1})}, + {setStateKey, scale.MustMarshal([]byte{2})}, } err := store.Insert(insert, nil) require.NoError(t, err) require.True(t, len(*store) == 2) - del := []api.Key{SET_STATE_KEY} + del := []api.Key{setStateKey} err = store.Insert(nil, del) require.NoError(t, err) require.True(t, len(*store) == 1) - data, err := store.Get(AUTHORITY_SET_KEY) + data, err := store.Get(authoritySetKey) require.NoError(t, err) require.NotNil(t, data) require.Equal(t, scale.MustMarshal([]byte{1}), *data) - data, err = store.Get(SET_STATE_KEY) + data, err = store.Get(setStateKey) require.NoError(t, err) require.Nil(t, data) } @@ -118,11 +118,11 @@ func TestLoadPersistentGenesis(t *testing.T) { require.Equal(t, persistentData.setState.Inner.Inner, genesisState) // Assert db values - encAuthData, err := store.Get(AUTHORITY_SET_KEY) + encAuthData, err := store.Get(authoritySetKey) require.NoError(t, err) require.NotNil(t, encAuthData) - encSetData, err := store.Get(SET_STATE_KEY) + encSetData, err := store.Get(setStateKey) require.NoError(t, err) require.NotNil(t, encSetData) @@ -152,8 +152,8 @@ func TestLoadPersistentNotGenesis(t *testing.T) { require.NoError(t, err) insert := []api.KeyValue{ - {AUTHORITY_SET_KEY, scale.MustMarshal(*genesisSet)}, - {SET_STATE_KEY, scale.MustMarshal(genesisState)}, + {authoritySetKey, scale.MustMarshal(*genesisSet)}, + {setStateKey, scale.MustMarshal(genesisState)}, } err = store.Insert(insert, nil) @@ -172,7 +172,7 @@ func TestLoadPersistentNotGenesis(t *testing.T) { // Auth set written but not set state store = newDummyStore(t) insert = []api.KeyValue{ - {AUTHORITY_SET_KEY, scale.MustMarshal(*genesisSet)}, + {authoritySetKey, scale.MustMarshal(*genesisSet)}, } err = store.Insert(insert, nil) @@ -202,7 +202,7 @@ func TestUpdateAuthoritySet(t *testing.T) { err := UpdateAuthoritySet[string, uint](authorities, nil, write(store)) require.NoError(t, err) - encData, err := store.Get(AUTHORITY_SET_KEY) + encData, err := store.Get(authoritySetKey) require.NoError(t, err) require.NotNil(t, encData) @@ -228,7 +228,7 @@ func TestUpdateAuthoritySet(t *testing.T) { err = UpdateAuthoritySet[string, uint](authorities, newAuthSet, write(store)) require.NoError(t, err) - encData, err = store.Get(AUTHORITY_SET_KEY) + encData, err = store.Get(authoritySetKey) require.NoError(t, err) require.NotNil(t, encData) @@ -239,7 +239,7 @@ func TestUpdateAuthoritySet(t *testing.T) { require.NoError(t, err) require.Equal(t, authorities, newAuthorities) - encState, err := store.Get(SET_STATE_KEY) + encState, err := store.Get(setStateKey) require.NoError(t, err) require.NotNil(t, encState) @@ -300,7 +300,7 @@ func TestWriteVoterSetState(t *testing.T) { encVoterSet, err := scale.Marshal(*voterSetState) require.NoError(t, err) - val, err := store.Get(SET_STATE_KEY) + val, err := store.Get(setStateKey) require.NoError(t, err) require.NotNil(t, val) require.Equal(t, encVoterSet, *val) @@ -348,7 +348,7 @@ func TestWriteConcludedRound(t *testing.T) { err = WriteConcludedRound[string, uint](*completedRound, write(store)) require.NoError(t, err) - key := CONCLUDED_ROUNDS + key := concludedRounds encodedRoundNumber := scale.MustMarshal(completedRound.Number) key = append(key, encodedRoundNumber...)