Skip to content

Commit

Permalink
update variable names for db keys
Browse files Browse the repository at this point in the history
  • Loading branch information
jimjbrettj committed Oct 2, 2023
1 parent 7a15586 commit 3d3fc50
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 32 deletions.
34 changes: 17 additions & 17 deletions client/consensus/grandpa/aux_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
)
Expand Down Expand Up @@ -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
// }
Expand All @@ -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
// }
Expand Down Expand Up @@ -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)
Expand All @@ -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
}
Expand All @@ -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
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
Expand Down Expand Up @@ -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 {
Expand All @@ -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
Expand Down
30 changes: 15 additions & 15 deletions client/consensus/grandpa/aux_schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)

Expand All @@ -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)

Expand All @@ -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)

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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...)

Expand Down

0 comments on commit 3d3fc50

Please sign in to comment.