cmd/swarm, swarm: LocalStore storage integration
This commit is contained in:
committed by
Anton Evangelatov
parent
c94d582aa7
commit
996755c4a8
@ -20,6 +20,7 @@ import (
|
||||
"bytes"
|
||||
"context"
|
||||
"crypto/ecdsa"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"math/big"
|
||||
@ -29,6 +30,11 @@ import (
|
||||
"time"
|
||||
"unicode"
|
||||
|
||||
"github.com/ethereum/go-ethereum/swarm/chunk"
|
||||
|
||||
"github.com/ethereum/go-ethereum/swarm/storage/feed"
|
||||
"github.com/ethereum/go-ethereum/swarm/storage/localstore"
|
||||
|
||||
"github.com/ethereum/go-ethereum/accounts/abi/bind"
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/contracts/chequebook"
|
||||
@ -48,7 +54,6 @@ import (
|
||||
"github.com/ethereum/go-ethereum/swarm/pss"
|
||||
"github.com/ethereum/go-ethereum/swarm/state"
|
||||
"github.com/ethereum/go-ethereum/swarm/storage"
|
||||
"github.com/ethereum/go-ethereum/swarm/storage/feed"
|
||||
"github.com/ethereum/go-ethereum/swarm/storage/mock"
|
||||
"github.com/ethereum/go-ethereum/swarm/swap"
|
||||
"github.com/ethereum/go-ethereum/swarm/tracing"
|
||||
@ -143,11 +148,31 @@ func NewSwarm(config *api.Config, mockStore *mock.NodeStore) (self *Swarm, err e
|
||||
resolver = api.NewMultiResolver(opts...)
|
||||
self.dns = resolver
|
||||
}
|
||||
// check that we are not in the old database schema
|
||||
// if so - fail and exit
|
||||
isLegacy := localstore.IsLegacyDatabase(config.ChunkDbPath)
|
||||
|
||||
lstore, err := storage.NewLocalStore(config.LocalStoreParams, mockStore)
|
||||
if isLegacy {
|
||||
return nil, errors.New("Legacy database format detected! Please read the migration announcement at: https://github.com/ethersphere/go-ethereum/wiki/Swarm-v0.4-local-store-migration")
|
||||
}
|
||||
|
||||
var feedsHandler *feed.Handler
|
||||
fhParams := &feed.HandlerParams{}
|
||||
|
||||
feedsHandler = feed.NewHandler(fhParams)
|
||||
|
||||
localStore, err := localstore.New(config.ChunkDbPath, config.BaseKey, &localstore.Options{
|
||||
MockStore: mockStore,
|
||||
Capacity: config.DbCapacity,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
lstore := chunk.NewValidatorStore(
|
||||
localStore,
|
||||
storage.NewContentAddressValidator(storage.MakeHashFunc(storage.DefaultHash)),
|
||||
feedsHandler,
|
||||
)
|
||||
|
||||
self.netStore, err = storage.NewNetStore(lstore, nil)
|
||||
if err != nil {
|
||||
@ -161,6 +186,8 @@ func NewSwarm(config *api.Config, mockStore *mock.NodeStore) (self *Swarm, err e
|
||||
delivery := stream.NewDelivery(to, self.netStore)
|
||||
self.netStore.NewNetFetcherFunc = network.NewFetcherFactory(delivery.RequestFromPeers, config.DeliverySkipCheck).New
|
||||
|
||||
feedsHandler.SetStore(self.netStore)
|
||||
|
||||
if config.SwapEnabled {
|
||||
balancesStore, err := state.NewDBStore(filepath.Join(config.Path, "balances.db"))
|
||||
if err != nil {
|
||||
@ -194,22 +221,6 @@ func NewSwarm(config *api.Config, mockStore *mock.NodeStore) (self *Swarm, err e
|
||||
// Swarm Hash Merklised Chunking for Arbitrary-length Document/File storage
|
||||
self.fileStore = storage.NewFileStore(self.netStore, self.config.FileStoreParams)
|
||||
|
||||
var feedsHandler *feed.Handler
|
||||
fhParams := &feed.HandlerParams{}
|
||||
|
||||
feedsHandler = feed.NewHandler(fhParams)
|
||||
feedsHandler.SetStore(self.netStore)
|
||||
|
||||
lstore.Validators = []storage.ChunkValidator{
|
||||
storage.NewContentAddressValidator(storage.MakeHashFunc(storage.DefaultHash)),
|
||||
feedsHandler,
|
||||
}
|
||||
|
||||
err = lstore.Migrate()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
log.Debug("Setup local storage")
|
||||
|
||||
self.bzz = network.NewBzz(bzzconfig, to, self.stateStore, self.streamer.GetSpec(), self.streamer.Run)
|
||||
|
Reference in New Issue
Block a user