Skip to content

Commit b49bdc5

Browse files
committed
address comment: versioned namespace should not be an option
1 parent 2969aaa commit b49bdc5

File tree

6 files changed

+20
-44
lines changed

6 files changed

+20
-44
lines changed

blockchain/config.go

-5
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,6 @@ type (
5252
EnableStateDBCaching bool `yaml:"enableStateDBCaching"`
5353
// EnableArchiveMode is only meaningful when EnableTrielessStateDB is false
5454
EnableArchiveMode bool `yaml:"enableArchiveMode"`
55-
// VersionedNamespaces specifies the versioned namespaces for versioned state DB
56-
VersionedNamespaces []string `yaml:"versionedNamespaces"`
57-
// VersionedMetadata specifies the metadata namespace for versioned state DB
58-
VersionedMetadata string `yaml:"versionedMetadata"`
5955
// EnableAsyncIndexWrite enables writing the block actions' and receipts' index asynchronously
6056
EnableAsyncIndexWrite bool `yaml:"enableAsyncIndexWrite"`
6157
// deprecated
@@ -111,7 +107,6 @@ var (
111107
GravityChainAPIs: []string{},
112108
},
113109
EnableTrielessStateDB: true,
114-
VersionedNamespaces: []string{},
115110
EnableStateDBCaching: false,
116111
EnableArchiveMode: false,
117112
EnableAsyncIndexWrite: true,

chainservice/builder.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,7 @@ func (builder *Builder) createFactory(forTest bool) (factory.Factory, error) {
174174
factory.DefaultPatchOption(),
175175
}
176176
if builder.cfg.Chain.EnableArchiveMode {
177-
dao, err = db.CreateKVStoreVersioned(factoryDBCfg, builder.cfg.Chain.TrieDBPath, builder.cfg.Chain.VersionedNamespaces)
178-
opts = append(opts, factory.MetadataNamespaceOption(builder.cfg.Chain.VersionedMetadata))
177+
dao, err = db.CreateKVStoreVersioned(factoryDBCfg, builder.cfg.Chain.TrieDBPath, factory.VersionedNamespaces)
179178
} else if builder.cfg.Chain.EnableStateDBCaching {
180179
dao, err = db.CreateKVStoreWithCache(factoryDBCfg, builder.cfg.Chain.TrieDBPath, builder.cfg.Chain.StateDBCacheSize)
181180
} else {

config/config.go

-10
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ var (
9292
// Validates is the collection config validation functions
9393
Validates = []Validate{
9494
ValidateRollDPoS,
95-
ValidateArchiveMode,
9695
ValidateDispatcher,
9796
ValidateAPI,
9897
ValidateActPool,
@@ -254,15 +253,6 @@ func ValidateRollDPoS(cfg Config) error {
254253
return nil
255254
}
256255

257-
// ValidateArchiveMode validates the state factory setting
258-
func ValidateArchiveMode(cfg Config) error {
259-
if !cfg.Chain.EnableArchiveMode || !cfg.Chain.EnableTrielessStateDB {
260-
return nil
261-
}
262-
263-
return errors.Wrap(ErrInvalidCfg, "Archive mode is incompatible with trieless state DB")
264-
}
265-
266256
// ValidateAPI validates the api configs
267257
func ValidateAPI(cfg Config) error {
268258
if cfg.API.TpsWindow <= 0 {

config/config_test.go

-17
Original file line numberDiff line numberDiff line change
@@ -253,23 +253,6 @@ func TestValidateRollDPoS(t *testing.T) {
253253
)
254254
}
255255

256-
func TestValidateArchiveMode(t *testing.T) {
257-
cfg := Default
258-
cfg.Chain.EnableArchiveMode = true
259-
cfg.Chain.EnableTrielessStateDB = true
260-
require.Error(t, ErrInvalidCfg, errors.Cause(ValidateArchiveMode(cfg)))
261-
require.EqualError(t, ValidateArchiveMode(cfg), "Archive mode is incompatible with trieless state DB: invalid config value")
262-
cfg.Chain.EnableArchiveMode = false
263-
cfg.Chain.EnableTrielessStateDB = true
264-
require.NoError(t, errors.Cause(ValidateArchiveMode(cfg)))
265-
cfg.Chain.EnableArchiveMode = true
266-
cfg.Chain.EnableTrielessStateDB = false
267-
require.NoError(t, errors.Cause(ValidateArchiveMode(cfg)))
268-
cfg.Chain.EnableArchiveMode = false
269-
cfg.Chain.EnableTrielessStateDB = false
270-
require.NoError(t, errors.Cause(ValidateArchiveMode(cfg)))
271-
}
272-
273256
func TestValidateActPool(t *testing.T) {
274257
cfg := Default
275258
cfg.ActPool.MaxNumActsPerAcct = 0

db/builder.go

+10
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import "github.com/pkg/errors"
55
var (
66
// ErrEmptyDBPath is the error when db path is empty
77
ErrEmptyDBPath = errors.New("empty db path")
8+
// ErrEmptyVersionedNamespace is the error of empty versioned namespace
9+
ErrEmptyVersionedNamespace = errors.New("cannot create versioned KVStore with empty versioned namespace")
810
)
911

1012
// CreateKVStore creates db from config and db path
@@ -38,6 +40,14 @@ func CreateKVStoreVersioned(cfg Config, dbPath string, vns []string) (KVStore, e
3840
if len(dbPath) == 0 {
3941
return nil, ErrEmptyDBPath
4042
}
43+
if len(vns) == 0 {
44+
return nil, ErrEmptyVersionedNamespace
45+
}
46+
for i := range vns {
47+
if len(vns[i]) == 0 {
48+
return nil, ErrEmptyVersionedNamespace
49+
}
50+
}
4151
cfg.DbPath = dbPath
4252
return NewKVStoreWithVersion(cfg, VersionedNamespaceOption(vns...)), nil
4353
}

state/factory/statedb.go

+9-10
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020

2121
"github.com/iotexproject/iotex-core/v2/action"
2222
"github.com/iotexproject/iotex-core/v2/action/protocol"
23+
"github.com/iotexproject/iotex-core/v2/action/protocol/execution/evm"
2324
"github.com/iotexproject/iotex-core/v2/actpool"
2425
"github.com/iotexproject/iotex-core/v2/blockchain/block"
2526
"github.com/iotexproject/iotex-core/v2/blockchain/genesis"
@@ -31,6 +32,13 @@ import (
3132
"github.com/iotexproject/iotex-core/v2/state"
3233
)
3334

35+
var (
36+
// VersionedMetadata is the metadata namespace for versioned stateDB
37+
VersionedMetadata = "Meta"
38+
// VersionedNamespaces are the versioned namespaces for versioned stateDB
39+
VersionedNamespaces = []string{AccountKVNamespace, evm.ContractKVNameSpace}
40+
)
41+
3442
type (
3543
// daoRetrofitter represents the DAO-related methods to accommodate archive-mode
3644
daoRetrofitter interface {
@@ -53,7 +61,6 @@ type (
5361
protocolView protocol.View
5462
skipBlockValidationOnPut bool
5563
ps *patchStore
56-
metaNS string // metadata namespace, only meaningful when archive-mode enabled
5764
}
5865
)
5966

@@ -92,14 +99,6 @@ func DisableWorkingSetCacheOption() StateDBOption {
9299
}
93100
}
94101

95-
// MetadataNamespaceOption specifies the metadat namespace for versioned DB
96-
func MetadataNamespaceOption(ns string) StateDBOption {
97-
return func(sdb *stateDB, cfg *Config) error {
98-
sdb.metaNS = ns
99-
return nil
100-
}
101-
}
102-
103102
// NewStateDB creates a new state db
104103
func NewStateDB(cfg Config, dao db.KVStore, opts ...StateDBOption) (Factory, error) {
105104
sdb := stateDB{
@@ -120,7 +119,7 @@ func NewStateDB(cfg Config, dao db.KVStore, opts ...StateDBOption) (Factory, err
120119
if !ok {
121120
return nil, errors.Wrap(ErrNotSupported, "cannot enable archive mode StateDB with non-versioned DB")
122121
}
123-
sdb.dao = newDaoRetrofitterArchive(daoVersioned, sdb.metaNS)
122+
sdb.dao = newDaoRetrofitterArchive(daoVersioned, VersionedMetadata)
124123
} else {
125124
sdb.dao = newDaoRetrofitter(dao)
126125
}

0 commit comments

Comments
 (0)