Skip to content

Commit

Permalink
merged
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenButtolph committed Nov 1, 2023
2 parents 5c4be97 + 168627d commit 90b73c5
Show file tree
Hide file tree
Showing 68 changed files with 1,629 additions and 1,882 deletions.
8 changes: 3 additions & 5 deletions api/keystore/keystore.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"github.com/ava-labs/avalanchego/chains/atomic"
"github.com/ava-labs/avalanchego/database"
"github.com/ava-labs/avalanchego/database/encdb"
"github.com/ava-labs/avalanchego/database/manager"
"github.com/ava-labs/avalanchego/database/prefixdb"
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/utils/json"
Expand Down Expand Up @@ -105,13 +104,12 @@ type keystore struct {
bcDB database.Database
}

func New(log logging.Logger, dbManager manager.Manager) Keystore {
currentDB := dbManager.Current()
func New(log logging.Logger, db database.Database) Keystore {
return &keystore{
log: log,
usernameToPassword: make(map[string]*password.Hash),
userDB: prefixdb.New(usersPrefix, currentDB.Database),
bcDB: prefixdb.New(bcsPrefix, currentDB.Database),
userDB: prefixdb.New(usersPrefix, db),
bcDB: prefixdb.New(bcsPrefix, db),
}
}

Expand Down
17 changes: 0 additions & 17 deletions api/keystore/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,8 @@ import (
"go.uber.org/zap"

"github.com/ava-labs/avalanchego/api"
"github.com/ava-labs/avalanchego/database/manager"
"github.com/ava-labs/avalanchego/database/memdb"
"github.com/ava-labs/avalanchego/utils/formatting"
"github.com/ava-labs/avalanchego/utils/logging"
"github.com/ava-labs/avalanchego/version"
)

type service struct {
Expand Down Expand Up @@ -115,17 +112,3 @@ func (s *service) ExportUser(_ *http.Request, args *ExportUserArgs, reply *Expor
reply.Encoding = args.Encoding
return nil
}

// CreateTestKeystore returns a new keystore that can be utilized for testing
func CreateTestKeystore() (Keystore, error) {
dbManager, err := manager.NewManagerFromDBs([]*manager.VersionedDatabase{
{
Database: memdb.New(),
Version: version.Semantic1_0_0,
},
})
if err != nil {
return nil, err
}
return New(logging.NoLog{}, dbManager), nil
}
36 changes: 14 additions & 22 deletions api/keystore/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ import (
"github.com/stretchr/testify/require"

"github.com/ava-labs/avalanchego/api"
"github.com/ava-labs/avalanchego/database/memdb"
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/utils/formatting"
"github.com/ava-labs/avalanchego/utils/logging"
"github.com/ava-labs/avalanchego/utils/password"
)

Expand All @@ -23,8 +25,7 @@ var strongPassword = "N_+=_jJ;^(<;{4,:*m6CET}'&N;83FYK.wtNpwp-Jt" // #nosec G101
func TestServiceListNoUsers(t *testing.T) {
require := require.New(t)

ks, err := CreateTestKeystore()
require.NoError(err)
ks := New(logging.NoLog{}, memdb.New())
s := service{ks: ks.(*keystore)}

reply := ListUsersReply{}
Expand All @@ -35,8 +36,7 @@ func TestServiceListNoUsers(t *testing.T) {
func TestServiceCreateUser(t *testing.T) {
require := require.New(t)

ks, err := CreateTestKeystore()
require.NoError(err)
ks := New(logging.NoLog{}, memdb.New())
s := service{ks: ks.(*keystore)}

{
Expand Down Expand Up @@ -66,8 +66,7 @@ func genStr(n int) string {
func TestServiceCreateUserArgsCheck(t *testing.T) {
require := require.New(t)

ks, err := CreateTestKeystore()
require.NoError(err)
ks := New(logging.NoLog{}, memdb.New())
s := service{ks: ks.(*keystore)}

{
Expand Down Expand Up @@ -100,8 +99,7 @@ func TestServiceCreateUserArgsCheck(t *testing.T) {
func TestServiceCreateUserWeakPassword(t *testing.T) {
require := require.New(t)

ks, err := CreateTestKeystore()
require.NoError(err)
ks := New(logging.NoLog{}, memdb.New())
s := service{ks: ks.(*keystore)}

{
Expand All @@ -117,8 +115,7 @@ func TestServiceCreateUserWeakPassword(t *testing.T) {
func TestServiceCreateDuplicate(t *testing.T) {
require := require.New(t)

ks, err := CreateTestKeystore()
require.NoError(err)
ks := New(logging.NoLog{}, memdb.New())
s := service{ks: ks.(*keystore)}

{
Expand All @@ -140,12 +137,11 @@ func TestServiceCreateDuplicate(t *testing.T) {
func TestServiceCreateUserNoName(t *testing.T) {
require := require.New(t)

ks, err := CreateTestKeystore()
require.NoError(err)
ks := New(logging.NoLog{}, memdb.New())
s := service{ks: ks.(*keystore)}

reply := api.EmptyReply{}
err = s.CreateUser(nil, &api.UserPass{
err := s.CreateUser(nil, &api.UserPass{
Password: strongPassword,
}, &reply)
require.ErrorIs(err, errEmptyUsername)
Expand All @@ -154,8 +150,7 @@ func TestServiceCreateUserNoName(t *testing.T) {
func TestServiceUseBlockchainDB(t *testing.T) {
require := require.New(t)

ks, err := CreateTestKeystore()
require.NoError(err)
ks := New(logging.NoLog{}, memdb.New())
s := service{ks: ks.(*keystore)}

{
Expand Down Expand Up @@ -185,8 +180,7 @@ func TestServiceExportImport(t *testing.T) {

encodings := []formatting.Encoding{formatting.Hex}
for _, encoding := range encodings {
ks, err := CreateTestKeystore()
require.NoError(err)
ks := New(logging.NoLog{}, memdb.New())
s := service{ks: ks.(*keystore)}

{
Expand All @@ -212,8 +206,7 @@ func TestServiceExportImport(t *testing.T) {
exportReply := ExportUserReply{}
require.NoError(s.ExportUser(nil, &exportArgs, &exportReply))

newKS, err := CreateTestKeystore()
require.NoError(err)
newKS := New(logging.NoLog{}, memdb.New())
newS := service{ks: newKS.(*keystore)}

{
Expand Down Expand Up @@ -324,16 +317,15 @@ func TestServiceDeleteUser(t *testing.T) {
t.Run(tt.desc, func(t *testing.T) {
require := require.New(t)

ksIntf, err := CreateTestKeystore()
require.NoError(err)
ksIntf := New(logging.NoLog{}, memdb.New())
ks := ksIntf.(*keystore)
s := service{ks: ks}

if tt.setup != nil {
require.NoError(tt.setup(ks))
}
got := &api.EmptyReply{}
err = s.DeleteUser(nil, tt.request, got)
err := s.DeleteUser(nil, tt.request, got)
require.ErrorIs(err, tt.expectedErr)
if tt.expectedErr != nil {
return
Expand Down
9 changes: 4 additions & 5 deletions chains/linearizable_vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@ import (
"context"

"github.com/ava-labs/avalanchego/api/metrics"
"github.com/ava-labs/avalanchego/database"
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/snow"
"github.com/ava-labs/avalanchego/snow/engine/avalanche/vertex"
"github.com/ava-labs/avalanchego/snow/engine/common"
"github.com/ava-labs/avalanchego/snow/engine/snowman/block"

dbManager "github.com/ava-labs/avalanchego/database/manager"
)

var (
Expand All @@ -32,7 +31,7 @@ type initializeOnLinearizeVM struct {

registerer metrics.OptionalGatherer
ctx *snow.Context
dbManager dbManager.Manager
db database.Database
genesisBytes []byte
upgradeBytes []byte
configBytes []byte
Expand All @@ -47,7 +46,7 @@ func (vm *initializeOnLinearizeVM) Linearize(ctx context.Context, stopVertexID i
return vm.vmToInitialize.Initialize(
ctx,
vm.ctx,
vm.dbManager,
vm.db,
vm.genesisBytes,
vm.upgradeBytes,
vm.configBytes,
Expand All @@ -74,7 +73,7 @@ func NewLinearizeOnInitializeVM(vm vertex.LinearizableVMWithEngine) *linearizeOn
func (vm *linearizeOnInitializeVM) Initialize(
ctx context.Context,
_ *snow.Context,
_ dbManager.Manager,
_ database.Database,
_ []byte,
_ []byte,
_ []byte,
Expand Down
37 changes: 17 additions & 20 deletions chains/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import (
"github.com/ava-labs/avalanchego/api/metrics"
"github.com/ava-labs/avalanchego/api/server"
"github.com/ava-labs/avalanchego/chains/atomic"
"github.com/ava-labs/avalanchego/database"
"github.com/ava-labs/avalanchego/database/meterdb"
"github.com/ava-labs/avalanchego/database/prefixdb"
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/message"
Expand Down Expand Up @@ -57,7 +59,6 @@ import (
"github.com/ava-labs/avalanchego/vms/proposervm"
"github.com/ava-labs/avalanchego/vms/tracedvm"

dbManager "github.com/ava-labs/avalanchego/database/manager"
timetracker "github.com/ava-labs/avalanchego/snow/networking/tracker"

aveng "github.com/ava-labs/avalanchego/snow/engine/avalanche"
Expand Down Expand Up @@ -180,7 +181,7 @@ type ManagerConfig struct {
BlockAcceptorGroup snow.AcceptorGroup
TxAcceptorGroup snow.AcceptorGroup
VertexAcceptorGroup snow.AcceptorGroup
DBManager dbManager.Manager
DB database.Database
MsgCreator message.OutboundMsgBuilder // message creator, shared with network
Router router.Router // Routes incoming messages to the appropriate chain
Net network.Network // Sends consensus messages to other validators
Expand Down Expand Up @@ -596,18 +597,16 @@ func (m *manager) createAvalancheChain(
State: snow.Initializing,
})

meterDBManager, err := m.DBManager.NewMeterDBManager("db", ctx.Registerer)
meterDB, err := meterdb.New("db", ctx.Registerer, m.DB)
if err != nil {
return nil, err
}
prefixDBManager := meterDBManager.NewPrefixDBManager(ctx.ChainID[:])
vmDBManager := prefixDBManager.NewPrefixDBManager(vmDBPrefix)

db := prefixDBManager.Current()
vertexDB := prefixdb.New(vertexDBPrefix, db.Database)
vertexBootstrappingDB := prefixdb.New(vertexBootstrappingDBPrefix, db.Database)
txBootstrappingDB := prefixdb.New(txBootstrappingDBPrefix, db.Database)
blockBootstrappingDB := prefixdb.New(blockBootstrappingDBPrefix, db.Database)
prefixDB := prefixdb.New(ctx.ChainID[:], meterDB)
vmDB := prefixdb.New(vmDBPrefix, prefixDB)
vertexDB := prefixdb.New(vertexDBPrefix, prefixDB)
vertexBootstrappingDB := prefixdb.New(vertexBootstrappingDBPrefix, prefixDB)
txBootstrappingDB := prefixdb.New(txBootstrappingDBPrefix, prefixDB)
blockBootstrappingDB := prefixdb.New(blockBootstrappingDBPrefix, prefixDB)

vtxBlocker, err := queue.NewWithMissing(vertexBootstrappingDB, "vtx", ctx.AvalancheRegisterer)
if err != nil {
Expand Down Expand Up @@ -730,7 +729,7 @@ func (m *manager) createAvalancheChain(
err = dagVM.Initialize(
context.TODO(),
ctx.Context,
vmDBManager,
vmDB,
genesisData,
chainConfig.Upgrade,
chainConfig.Config,
Expand Down Expand Up @@ -796,7 +795,7 @@ func (m *manager) createAvalancheChain(

registerer: snowmanRegisterer,
ctx: ctx.Context,
dbManager: vmDBManager,
db: vmDB,
genesisBytes: genesisData,
upgradeBytes: chainConfig.Upgrade,
configBytes: chainConfig.Config,
Expand Down Expand Up @@ -1004,15 +1003,13 @@ func (m *manager) createSnowmanChain(
State: snow.Initializing,
})

meterDBManager, err := m.DBManager.NewMeterDBManager("db", ctx.Registerer)
meterDB, err := meterdb.New("db", ctx.Registerer, m.DB)
if err != nil {
return nil, err
}
prefixDBManager := meterDBManager.NewPrefixDBManager(ctx.ChainID[:])
vmDBManager := prefixDBManager.NewPrefixDBManager(vmDBPrefix)

db := prefixDBManager.Current()
bootstrappingDB := prefixdb.New(bootstrappingDB, db.Database)
prefixDB := prefixdb.New(ctx.ChainID[:], meterDB)
vmDB := prefixdb.New(vmDBPrefix, prefixDB)
bootstrappingDB := prefixdb.New(bootstrappingDB, prefixDB)

blocked, err := queue.NewWithMissing(bootstrappingDB, "block", ctx.Registerer)
if err != nil {
Expand Down Expand Up @@ -1145,7 +1142,7 @@ func (m *manager) createSnowmanChain(
if err := vm.Initialize(
context.TODO(),
ctx.Context,
vmDBManager,
vmDB,
genesisData,
chainConfig.Upgrade,
chainConfig.Config,
Expand Down
11 changes: 6 additions & 5 deletions config/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (

"github.com/ava-labs/avalanchego/database/leveldb"
"github.com/ava-labs/avalanchego/database/memdb"
"github.com/ava-labs/avalanchego/database/pebble"
"github.com/ava-labs/avalanchego/genesis"
"github.com/ava-labs/avalanchego/snow/consensus/snowball"
"github.com/ava-labs/avalanchego/trace"
Expand Down Expand Up @@ -103,7 +104,7 @@ func addNodeFlags(fs *pflag.FlagSet) {
fs.Uint64(AddSubnetDelegatorFeeKey, genesis.LocalParams.AddSubnetDelegatorFee, "Transaction fee, in nAVAX, for transactions that add new subnet delegators")

// Database
fs.String(DBTypeKey, leveldb.Name, fmt.Sprintf("Database type to use. Should be one of {%s, %s}", leveldb.Name, memdb.Name))
fs.String(DBTypeKey, leveldb.Name, fmt.Sprintf("Database type to use. Must be one of {%s, %s, %s}", leveldb.Name, memdb.Name, pebble.Name))
fs.String(DBPathKey, defaultDBDir, "Path to database directory")
fs.String(DBConfigFileKey, "", fmt.Sprintf("Path to database config file. Ignored if %s is specified", DBConfigContentKey))
fs.String(DBConfigContentKey, "", "Specifies base64 encoded database config content")
Expand Down Expand Up @@ -204,8 +205,8 @@ func addNodeFlags(fs *pflag.FlagSet) {
fs.Uint64(OutboundThrottlerNodeMaxAtLargeBytesKey, constants.DefaultOutboundThrottlerNodeMaxAtLargeBytes, "Max number of bytes a node can take from the outbound message throttler's at-large allocation. Must be at least the max message size")

// HTTP APIs
fs.String(HTTPHostKey, "127.0.0.1", "Address of the HTTP server")
fs.Uint(HTTPPortKey, DefaultHTTPPort, "Port of the HTTP server")
fs.String(HTTPHostKey, "127.0.0.1", "Address of the HTTP server. If the address is empty or a literal unspecified IP address, the server will bind on all available unicast and anycast IP addresses of the local system")
fs.Uint(HTTPPortKey, DefaultHTTPPort, "Port of the HTTP server. If the port is 0 a port number is automatically chosen")
fs.Bool(HTTPSEnabledKey, false, "Upgrade the HTTP server to HTTPs")
fs.String(HTTPSKeyFileKey, "", fmt.Sprintf("TLS private key file for the HTTPs server. Ignored if %s is specified", HTTPSKeyContentKey))
fs.String(HTTPSKeyContentKey, "", "Specifies base64 encoded TLS private key for the HTTPs server")
Expand Down Expand Up @@ -248,8 +249,8 @@ func addNodeFlags(fs *pflag.FlagSet) {
fs.Duration(NetworkHealthMaxOutstandingDurationKey, 5*time.Minute, "Node reports unhealthy if there has been a request outstanding for this duration")

// Staking
fs.String(StakingHostKey, "", "Address of the consensus server") // Bind to all interfaces by default.
fs.Uint(StakingPortKey, DefaultStakingPort, "Port of the consensus server")
fs.String(StakingHostKey, "", "Address of the consensus server. If the address is empty or a literal unspecified IP address, the server will bind on all available unicast and anycast IP addresses of the local system") // Bind to all interfaces by default.
fs.Uint(StakingPortKey, DefaultStakingPort, "Port of the consensus server. If the port is 0 a port number is automatically chosen")
fs.Bool(StakingEphemeralCertEnabledKey, false, "If true, the node uses an ephemeral staking TLS key and certificate, and has an ephemeral node ID")
fs.String(StakingTLSKeyPathKey, defaultStakingTLSKeyPath, fmt.Sprintf("Path to the TLS private key for staking. Ignored if %s is specified", StakingTLSKeyContentKey))
fs.String(StakingTLSKeyContentKey, "", "Specifies base64 encoded TLS private key for staking")
Expand Down
Loading

0 comments on commit 90b73c5

Please sign in to comment.