Skip to content
This repository was archived by the owner on Aug 2, 2021. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from 41 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
df7d887
swarm/storage/localstore: add hasser
janos Feb 27, 2019
c0a4b1b
swarm: merge branch 'master' into localstore-storage-integration
janos Mar 4, 2019
8381e38
swarm: merge branch 'master' into localstore-storage-integration
janos Mar 4, 2019
5ac0f79
cmd/swarm, swarm: integrate localstore partially
janos Mar 4, 2019
a96aeeb
swarm: merge branch 'master' into localstore-storage-integration
janos Mar 5, 2019
44633ce
swarm/network/stream: start of localstore integration
janos Mar 5, 2019
3e6e03a
swarm/storage/localstore: add TestExportImport and fix Export function
janos Mar 5, 2019
6ce3481
cmd/swarm: re-enable TestCLISwarmExportImport
janos Mar 5, 2019
5e69e3d
swarm: extend chunk.Store
janos Mar 5, 2019
5d7f169
swarm/storage/feed: fix TestValidatorInStore
janos Mar 5, 2019
f0a8d3a
swarm: rename ModeGetFeedLookup to ModeGetLookup
janos Mar 5, 2019
5474d30
swarm: minor updates to chunk, storage and localstore packages
janos Mar 6, 2019
9ca71f4
swarm: merge branch 'master' into localstore-storage-integration
janos Mar 11, 2019
83b64ce
swarm/shed: add vector uint64 field
janos Mar 12, 2019
547f30b
cmd/swarm: fix merge issue
janos Mar 12, 2019
970b305
swarm: use BinID for pull syncing index
janos Mar 12, 2019
5a669c6
swarm/network, swarm/storage/localstore: SetNextBatch pull subscription
janos Mar 12, 2019
4594130
swarm/network/stream: fix TestSyncerSimulation
janos Mar 13, 2019
4af1d7a
swarm: change localstore SubscribePull function signature
janos Mar 13, 2019
4df51ee
swarm/storage/localstore: fix SubscribePull comment
janos Mar 14, 2019
804301e
swarm/network/stream: return errors in roundRobinStore
janos Mar 14, 2019
6aa0d0e
swarm/storage/localstore: SubscribePull with both range ends inclusive
janos Mar 14, 2019
c16dcd1
swarm/network/stream: close intervals store in newStreamerTester
janos Mar 15, 2019
14758a4
swarm/storage/localstore: improve TestDB_SubscribePull_since
janos Mar 15, 2019
be1a360
swarm/network/stream: implement new SetNextBatch
janos Mar 15, 2019
36a0d96
swarm/network/stream: update handleChunkDeliveryMsg function
janos Mar 15, 2019
3b3d2b0
swarm/storage: remove unused code
janos Mar 15, 2019
4b8a5c8
swarm: merge branch 'master' into localstore-storage-integration
janos Mar 15, 2019
277ecf9
swarm: minor code cleanups
janos Mar 15, 2019
682eebd
swarm: merge branch 'master' into localstore-storage-integration
janos Mar 15, 2019
5ee9143
Merge branch 'master' into localstore-storage-integration
nonsense Mar 21, 2019
c3a76d1
lint
nonsense Mar 21, 2019
2d20bf9
swarm/storage/localstore: add tags to push index
acud Mar 25, 2019
b828a34
swarm/storage, swarm/shed: add support for persisting push tags
acud Mar 26, 2019
d8c648b
swarm/storage/localstore: TestDB_pushIndex_Tags
janos Mar 26, 2019
e295dc8
swarm: address pr review comments
janos Mar 26, 2019
c9d679d
swarm: merge branch 'master' into localstore-storage-integration
janos Mar 26, 2019
2fe747e
swarm/storage/localstore: implement backward compatible Import function
janos Mar 26, 2019
3e82234
swamr/network/stream: fix handleChunkDeliveryMsg
janos Mar 27, 2019
4c14a09
swarm/storage/localstore: remove getters, setters and putters
acud Mar 27, 2019
31f4b0d
swarm/network/stream: update handleChunkDeliveryMsg
janos Mar 27, 2019
2e24e99
swarm/storage/localstore: only one item in pull and push indexes for …
janos Mar 29, 2019
9c79e26
Revert "swarm/storage/localstore: TestDB_pushIndex_Tags"
acud Apr 8, 2019
ca7dcc2
Revert "swarm/storage, swarm/shed: add support for persisting push tags"
acud Apr 8, 2019
e4d723c
swarm/chunk, swarm/storage: adjust Store.Put interface to return bool…
acud Apr 9, 2019
904df7a
cmd/swarm: new localstore database migration (#1297)
acud Apr 10, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions cmd/swarm/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,15 +252,15 @@ func cmdLineOverride(currentConfig *bzzapi.Config, ctx *cli.Context) *bzzapi.Con
}

if storePath := ctx.GlobalString(SwarmStorePath.Name); storePath != "" {
currentConfig.LocalStoreParams.ChunkDbPath = storePath
currentConfig.ChunkDbPath = storePath
}

if storeCapacity := ctx.GlobalUint64(SwarmStoreCapacity.Name); storeCapacity != 0 {
currentConfig.LocalStoreParams.DbCapacity = storeCapacity
currentConfig.DbCapacity = storeCapacity
}

if ctx.GlobalIsSet(SwarmStoreCacheCapacity.Name) {
currentConfig.LocalStoreParams.CacheCapacity = ctx.GlobalUint(SwarmStoreCacheCapacity.Name)
currentConfig.CacheCapacity = ctx.GlobalUint(SwarmStoreCacheCapacity.Name)
}

if ctx.GlobalIsSet(SwarmBootnodeModeFlag.Name) {
Expand Down
4 changes: 2 additions & 2 deletions cmd/swarm/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,8 +447,8 @@ func TestConfigCmdLineOverridesFile(t *testing.T) {
t.Fatal("Expected Sync to be disabled, but is true")
}

if info.LocalStoreParams.DbCapacity != 9000000 {
t.Fatalf("Expected Capacity to be %d, got %d", 9000000, info.LocalStoreParams.DbCapacity)
if info.DbCapacity != 9000000 {
t.Fatalf("Expected Capacity to be %d, got %d", 9000000, info.DbCapacity)
}

if info.HiveParams.KeepAliveInterval != 6000000000 {
Expand Down
9 changes: 3 additions & 6 deletions cmd/swarm/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"github.com/ethereum/go-ethereum/cmd/utils"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/swarm/storage"
"github.com/ethereum/go-ethereum/swarm/storage/localstore"
"gopkg.in/urfave/cli.v1"
)

Expand Down Expand Up @@ -135,13 +135,10 @@ func dbImport(ctx *cli.Context) {
log.Info(fmt.Sprintf("successfully imported %d chunks", count))
}

func openLDBStore(path string, basekey []byte) (*storage.LDBStore, error) {
func openLDBStore(path string, basekey []byte) (*localstore.DB, error) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could this not be in the localstore pkg as one of the constructors?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I am not sure that we need it. It only checks if goleveldb data is present in a directory. Is it really necessary to have that check for export and import?

if _, err := os.Stat(filepath.Join(path, "CURRENT")); err != nil {
return nil, fmt.Errorf("invalid chunkdb path: %s", err)
}

storeparams := storage.NewDefaultStoreParams()
ldbparams := storage.NewLDBStoreParams(storeparams, path)
ldbparams.BaseKey = basekey
return storage.NewLDBStore(ldbparams)
return localstore.New(path, basekey, nil)
}
14 changes: 10 additions & 4 deletions swarm/api/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,13 @@ const (
type Config struct {
// serialised/persisted fields
*storage.FileStoreParams
*storage.LocalStoreParams

// LocalStore
ChunkDbPath string
DbCapacity uint64
CacheCapacity uint
BaseKey []byte

*network.HiveParams
Swap *swap.LocalProfile
Pss *pss.PssParams
Expand Down Expand Up @@ -78,7 +84,6 @@ type Config struct {
func NewConfig() (c *Config) {

c = &Config{
LocalStoreParams: storage.NewDefaultLocalStoreParams(),
FileStoreParams: storage.NewFileStoreParams(),
HiveParams: network.NewHiveParams(),
Swap: swap.NewDefaultSwapParams(),
Expand Down Expand Up @@ -130,8 +135,9 @@ func (c *Config) Init(prvKey *ecdsa.PrivateKey, nodeKey *ecdsa.PrivateKey) error
c.Swap.Init(c.Contract, prvKey)
}

c.LocalStoreParams.Init(c.Path)
c.LocalStoreParams.BaseKey = common.FromHex(c.BzzKey)
c.privateKey = prvKey
c.ChunkDbPath = filepath.Join(c.Path, "chunks")
c.BaseKey = common.FromHex(c.BzzKey)

c.Pss = c.Pss.WithPrivateKey(c.privateKey)
return nil
Expand Down
1 change: 0 additions & 1 deletion swarm/api/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ func TestConfig(t *testing.T) {
one := NewConfig()
two := NewConfig()

one.LocalStoreParams = two.LocalStoreParams
Comment thread
acud marked this conversation as resolved.
if equal := reflect.DeepEqual(one, two); !equal {
t.Fatal("Two default configs are not equal")
}
Expand Down
8 changes: 3 additions & 5 deletions swarm/api/http/test_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/ethereum/go-ethereum/swarm/api"
"github.com/ethereum/go-ethereum/swarm/storage"
"github.com/ethereum/go-ethereum/swarm/storage/feed"
"github.com/ethereum/go-ethereum/swarm/storage/localstore"
)

type TestServer interface {
Expand All @@ -37,15 +38,12 @@ func NewTestSwarmServer(t *testing.T, serverFunc func(*api.API) TestServer, reso
if err != nil {
t.Fatal(err)
}
storeparams := storage.NewDefaultLocalStoreParams()
storeparams.DbCapacity = 5000000
storeparams.CacheCapacity = 5000
storeparams.Init(dir)
localStore, err := storage.NewLocalStore(storeparams, nil)
localStore, err := localstore.New(dir, make([]byte, 32), nil)
if err != nil {
os.RemoveAll(dir)
t.Fatal(err)
}

fileStore := storage.NewFileStore(localStore, storage.NewFileStoreParams())

// Swarm feeds test setup
Expand Down
6 changes: 5 additions & 1 deletion swarm/api/inspector.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ func (inspector *Inspector) Has(chunkAddresses []storage.Address) []HasInfo {
for _, addr := range chunkAddresses {
res := HasInfo{}
res.Addr = addr.String()
res.Has = inspector.netStore.Has(context.Background(), addr)
has, err := inspector.netStore.Has(context.Background(), addr)
if err != nil {
has = false
}
res.Has = has
results = append(results, res)
}
return results
Expand Down
105 changes: 104 additions & 1 deletion swarm/chunk/chunk.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package chunk

import (
"context"
"errors"
"fmt"

Expand Down Expand Up @@ -28,7 +29,7 @@ type chunk struct {
sdata []byte
}

func NewChunk(addr Address, data []byte) *chunk {
func NewChunk(addr Address, data []byte) Chunk {
return &chunk{
addr: addr,
sdata: data,
Expand Down Expand Up @@ -107,3 +108,105 @@ func Proximity(one, other []byte) (ret int) {
}
return MaxPO
}

// ModeGet enumerates different Getter modes.
type ModeGet int

// Getter modes.
const (
// ModeGetRequest: when accessed for retrieval
ModeGetRequest ModeGet = iota
// ModeGetSync: when accessed for syncing or proof of custody request
ModeGetSync
// ModeGetLookup: when accessed to lookup a a chunk in feeds or other places
ModeGetLookup
)

// ModePut enumerates different Putter modes.
type ModePut int

// Putter modes.
const (
// ModePutRequest: when a chunk is received as a result of retrieve request and delivery
ModePutRequest ModePut = iota
// ModePutSync: when a chunk is received via syncing
ModePutSync
// ModePutUpload: when a chunk is created by local upload
ModePutUpload
)

// ModeSet enumerates different Setter modes.
type ModeSet int

// Setter modes.
const (
// ModeSetAccess: when an update request is received for a chunk or chunk is retrieved for delivery
ModeSetAccess ModeSet = iota
// ModeSetSync: when push sync receipt is received
ModeSetSync
// ModeSetRemove: when a chunk is removed
ModeSetRemove
)

// Descriptor holds information required for Pull syncing. This struct
// is provided by subscribing to pull index.
type Descriptor struct {
Address Address
BinID uint64
}

func (d *Descriptor) String() string {
if d == nil {
return ""
}
return fmt.Sprintf("%s bin id %v", d.Address.Hex(), d.BinID)
}

type Store interface {
Get(ctx context.Context, mode ModeGet, addr Address) (ch Chunk, err error)
Comment thread
acud marked this conversation as resolved.
Put(ctx context.Context, mode ModePut, ch Chunk) (err error)
Has(ctx context.Context, addr Address) (yes bool, err error)
Set(ctx context.Context, mode ModeSet, addr Address) (err error)
LastPullSubscriptionBinID(bin uint8) (id uint64, err error)
SubscribePull(ctx context.Context, bin uint8, since, until uint64) (c <-chan Descriptor, stop func())
Close() (err error)
}

// FetchStore is a Store which supports syncing
type FetchStore interface {
Store
FetchFunc(ctx context.Context, addr Address) func(context.Context) error
}

// Validator validates a chunk.
type Validator interface {
Validate(ch Chunk) bool
}

// ValidatorStore encapsulates Store by decorting the Put method
// with validators check.
type ValidatorStore struct {
Store
validators []Validator
}

// NewValidatorStore returns a new ValidatorStore which uses
// provided validators to validate chunks on Put.
func NewValidatorStore(store Store, validators ...Validator) (s *ValidatorStore) {
return &ValidatorStore{
Store: store,
validators: validators,
}
}

// Put overrides Store put method with validators check. If one of the validators
// return true, the chunk is considered valid and Store Put method is called.
// If all validators return false, ErrChunkInvalid is returned.
func (s *ValidatorStore) Put(ctx context.Context, mode ModePut, ch Chunk) (err error) {
for _, v := range s.validators {
if v.Validate(ch) {
return s.Store.Put(ctx, mode, ch)
}
}
return ErrChunkInvalid
}
Loading