diff options
Diffstat (limited to 'swarm/swarm.go')
-rw-r--r-- | swarm/swarm.go | 47 |
1 files changed, 29 insertions, 18 deletions
diff --git a/swarm/swarm.go b/swarm/swarm.go index 61813e23f..7f5ee8361 100644 --- a/swarm/swarm.go +++ b/swarm/swarm.go @@ -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) + + 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) - lstore, err := storage.NewLocalStore(config.LocalStoreParams, mockStore) + 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) |