aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README.md2
-rw-r--r--core/blockchain.go6
-rw-r--r--core/tx_pool.go2
-rw-r--r--swarm/network/simulations/overlay.go4
-rw-r--r--swarm/network/stream/common_test.go16
-rw-r--r--swarm/network/stream/delivery.go2
-rw-r--r--swarm/network/stream/snapshot_sync_test.go27
-rw-r--r--swarm/network/stream/syncer_test.go21
-rw-r--r--swarm/state/dbstore.go21
-rw-r--r--swarm/state/inmemorystore.go94
-rw-r--r--swarm/state/store.go26
-rw-r--r--whisper/mailserver/mailserver.go12
12 files changed, 52 insertions, 181 deletions
diff --git a/README.md b/README.md
index f308fb101..4b62bfde0 100644
--- a/README.md
+++ b/README.md
@@ -18,7 +18,7 @@ For prerequisites and detailed build instructions please read the
[Installation Instructions](https://github.com/ethereum/go-ethereum/wiki/Building-Ethereum)
on the wiki.
-Building geth requires both a Go (version 1.7 or later) and a C compiler.
+Building geth requires both a Go (version 1.9 or later) and a C compiler.
You can install them using your favourite package manager.
Once the dependencies are installed, run
diff --git a/core/blockchain.go b/core/blockchain.go
index d78946791..3a9caf01e 100644
--- a/core/blockchain.go
+++ b/core/blockchain.go
@@ -1537,8 +1537,10 @@ func (bc *BlockChain) reportBlock(block *types.Block, receipts types.Receipts, e
bc.addBadBlock(block)
var receiptString string
- for _, receipt := range receipts {
- receiptString += fmt.Sprintf("\t%v\n", receipt)
+ for i, receipt := range receipts {
+ receiptString += fmt.Sprintf("\t %d: cumulative: %v gas: %v contract: %v status: %v tx: %v logs: %v bloom: %x state: %x\n",
+ i, receipt.CumulativeGasUsed, receipt.GasUsed, receipt.ContractAddress.Hex(),
+ receipt.Status, receipt.TxHash.Hex(), receipt.Logs, receipt.Bloom, receipt.PostState)
}
log.Error(fmt.Sprintf(`
########## BAD BLOCK #########
diff --git a/core/tx_pool.go b/core/tx_pool.go
index f6da5da2a..fc35d1f24 100644
--- a/core/tx_pool.go
+++ b/core/tx_pool.go
@@ -825,7 +825,7 @@ func (pool *TxPool) addTxs(txs []*types.Transaction, local bool) []error {
// addTxsLocked attempts to queue a batch of transactions if they are valid,
// whilst assuming the transaction pool lock is already held.
func (pool *TxPool) addTxsLocked(txs []*types.Transaction, local bool) []error {
- // Add the batch of transaction, tracking the accepted ones
+ // Add the batch of transactions, tracking the accepted ones
dirty := make(map[common.Address]struct{})
errs := make([]error, len(txs))
diff --git a/swarm/network/simulations/overlay.go b/swarm/network/simulations/overlay.go
index caf7ff1f2..284ae6398 100644
--- a/swarm/network/simulations/overlay.go
+++ b/swarm/network/simulations/overlay.go
@@ -64,12 +64,12 @@ func init() {
type Simulation struct {
mtx sync.Mutex
- stores map[enode.ID]*state.InmemoryStore
+ stores map[enode.ID]state.Store
}
func NewSimulation() *Simulation {
return &Simulation{
- stores: make(map[enode.ID]*state.InmemoryStore),
+ stores: make(map[enode.ID]state.Store),
}
}
diff --git a/swarm/network/stream/common_test.go b/swarm/network/stream/common_test.go
index c5f1fa176..e0a7f7e12 100644
--- a/swarm/network/stream/common_test.go
+++ b/swarm/network/stream/common_test.go
@@ -38,7 +38,6 @@ import (
"github.com/ethereum/go-ethereum/swarm/pot"
"github.com/ethereum/go-ethereum/swarm/state"
"github.com/ethereum/go-ethereum/swarm/storage"
- mockdb "github.com/ethereum/go-ethereum/swarm/storage/mock/db"
"github.com/ethereum/go-ethereum/swarm/testutil"
colorable "github.com/mattn/go-colorable"
)
@@ -69,21 +68,6 @@ func init() {
log.Root().SetHandler(log.LvlFilterHandler(log.Lvl(*loglevel), log.StreamHandler(colorable.NewColorableStderr(), log.TerminalFormat(true))))
}
-func createGlobalStore() (string, *mockdb.GlobalStore, error) {
- var globalStore *mockdb.GlobalStore
- globalStoreDir, err := ioutil.TempDir("", "global.store")
- if err != nil {
- log.Error("Error initiating global store temp directory!", "err", err)
- return "", nil, err
- }
- globalStore, err = mockdb.NewGlobalStore(globalStoreDir)
- if err != nil {
- log.Error("Error initiating global store!", "err", err)
- return "", nil, err
- }
- return globalStoreDir, globalStore, nil
-}
-
func newStreamerTester(t *testing.T, registryOptions *RegistryOptions) (*p2ptest.ProtocolTester, *Registry, *storage.LocalStore, func(), error) {
// setup
addr := network.RandomAddr() // tested peers peer address
diff --git a/swarm/network/stream/delivery.go b/swarm/network/stream/delivery.go
index 0109fbdef..64d754336 100644
--- a/swarm/network/stream/delivery.go
+++ b/swarm/network/stream/delivery.go
@@ -169,7 +169,7 @@ func (d *Delivery) handleRetrieveRequestMsg(ctx context.Context, sp *Peer, req *
go func() {
chunk, err := d.chunkStore.Get(ctx, req.Addr)
if err != nil {
- log.Warn("ChunkStore.Get can not retrieve chunk", "err", err)
+ log.Warn("ChunkStore.Get can not retrieve chunk", "peer", sp.ID().String(), "addr", req.Addr, "hopcount", req.HopCount, "err", err)
return
}
if req.SkipCheck {
diff --git a/swarm/network/stream/snapshot_sync_test.go b/swarm/network/stream/snapshot_sync_test.go
index 6b92c32ae..4e56f71b5 100644
--- a/swarm/network/stream/snapshot_sync_test.go
+++ b/swarm/network/stream/snapshot_sync_test.go
@@ -35,7 +35,8 @@ import (
"github.com/ethereum/go-ethereum/swarm/pot"
"github.com/ethereum/go-ethereum/swarm/state"
"github.com/ethereum/go-ethereum/swarm/storage"
- mockdb "github.com/ethereum/go-ethereum/swarm/storage/mock/db"
+ "github.com/ethereum/go-ethereum/swarm/storage/mock"
+ mockmem "github.com/ethereum/go-ethereum/swarm/storage/mock/mem"
"github.com/ethereum/go-ethereum/swarm/testutil"
)
@@ -268,20 +269,9 @@ func runSim(conf *synctestConfig, ctx context.Context, sim *simulation.Simulatio
// File retrieval check is repeated until all uploaded files are retrieved from all nodes
// or until the timeout is reached.
- var gDir string
- var globalStore *mockdb.GlobalStore
+ var globalStore mock.GlobalStorer
if *useMockStore {
- gDir, globalStore, err = createGlobalStore()
- if err != nil {
- return fmt.Errorf("Something went wrong; using mockStore enabled but globalStore is nil")
- }
- defer func() {
- os.RemoveAll(gDir)
- err := globalStore.Close()
- if err != nil {
- log.Error("Error closing global store! %v", "err", err)
- }
- }()
+ globalStore = mockmem.NewGlobalStore()
}
REPEAT:
for {
@@ -476,14 +466,9 @@ func testSyncingViaDirectSubscribe(t *testing.T, chunkCount int, nodeCount int)
return err
}
- var gDir string
- var globalStore *mockdb.GlobalStore
+ var globalStore mock.GlobalStorer
if *useMockStore {
- gDir, globalStore, err = createGlobalStore()
- if err != nil {
- return fmt.Errorf("Something went wrong; using mockStore enabled but globalStore is nil")
- }
- defer os.RemoveAll(gDir)
+ globalStore = mockmem.NewGlobalStore()
}
// File retrieval check is repeated until all uploaded files are retrieved from all nodes
// or until the timeout is reached.
diff --git a/swarm/network/stream/syncer_test.go b/swarm/network/stream/syncer_test.go
index fe20bab26..5764efc92 100644
--- a/swarm/network/stream/syncer_test.go
+++ b/swarm/network/stream/syncer_test.go
@@ -35,7 +35,8 @@ import (
"github.com/ethereum/go-ethereum/swarm/network/simulation"
"github.com/ethereum/go-ethereum/swarm/state"
"github.com/ethereum/go-ethereum/swarm/storage"
- mockdb "github.com/ethereum/go-ethereum/swarm/storage/mock/db"
+ "github.com/ethereum/go-ethereum/swarm/storage/mock"
+ mockmem "github.com/ethereum/go-ethereum/swarm/storage/mock/mem"
"github.com/ethereum/go-ethereum/swarm/testutil"
)
@@ -48,7 +49,7 @@ func TestSyncerSimulation(t *testing.T) {
testSyncBetweenNodes(t, 16, 1, dataChunkCount, true, 1)
}
-func createMockStore(globalStore *mockdb.GlobalStore, id enode.ID, addr *network.BzzAddr) (lstore storage.ChunkStore, datadir string, err error) {
+func createMockStore(globalStore mock.GlobalStorer, id enode.ID, addr *network.BzzAddr) (lstore storage.ChunkStore, datadir string, err error) {
address := common.BytesToAddress(id.Bytes())
mockStore := globalStore.NewNodeStore(address)
params := storage.NewDefaultLocalStoreParams()
@@ -70,8 +71,7 @@ func testSyncBetweenNodes(t *testing.T, nodes, conns, chunkCount int, skipCheck
sim := simulation.New(map[string]simulation.ServiceFunc{
"streamer": func(ctx *adapters.ServiceContext, bucket *sync.Map) (s node.Service, cleanup func(), err error) {
var store storage.ChunkStore
- var globalStore *mockdb.GlobalStore
- var gDir, datadir string
+ var datadir string
node := ctx.Config.Node()
addr := network.NewAddr(node)
@@ -79,11 +79,7 @@ func testSyncBetweenNodes(t *testing.T, nodes, conns, chunkCount int, skipCheck
addr.OAddr[0] = byte(0)
if *useMockStore {
- gDir, globalStore, err = createGlobalStore()
- if err != nil {
- return nil, nil, fmt.Errorf("Something went wrong; using mockStore enabled but globalStore is nil")
- }
- store, datadir, err = createMockStore(globalStore, node.ID(), addr)
+ store, datadir, err = createMockStore(mockmem.NewGlobalStore(), node.ID(), addr)
} else {
store, datadir, err = createTestLocalStorageForID(node.ID(), addr)
}
@@ -94,13 +90,6 @@ func testSyncBetweenNodes(t *testing.T, nodes, conns, chunkCount int, skipCheck
cleanup = func() {
store.Close()
os.RemoveAll(datadir)
- if *useMockStore {
- err := globalStore.Close()
- if err != nil {
- log.Error("Error closing global store! %v", "err", err)
- }
- os.RemoveAll(gDir)
- }
}
localStore := store.(*storage.LocalStore)
netStore, err := storage.NewNetStore(localStore, nil)
diff --git a/swarm/state/dbstore.go b/swarm/state/dbstore.go
index b0aa92e27..fc5dd8f7c 100644
--- a/swarm/state/dbstore.go
+++ b/swarm/state/dbstore.go
@@ -22,6 +22,7 @@ import (
"errors"
"github.com/syndtr/goleveldb/leveldb"
+ "github.com/syndtr/goleveldb/leveldb/storage"
)
// ErrNotFound is returned when no results are returned from the database
@@ -30,6 +31,15 @@ var ErrNotFound = errors.New("ErrorNotFound")
// ErrInvalidArgument is returned when the argument type does not match the expected type
var ErrInvalidArgument = errors.New("ErrorInvalidArgument")
+// Store defines methods required to get, set, delete values for different keys
+// and close the underlying resources.
+type Store interface {
+ Get(key string, i interface{}) (err error)
+ Put(key string, i interface{}) (err error)
+ Delete(key string) (err error)
+ Close() error
+}
+
// DBStore uses LevelDB to store values.
type DBStore struct {
db *leveldb.DB
@@ -46,6 +56,17 @@ func NewDBStore(path string) (s *DBStore, err error) {
}, nil
}
+// NewInmemoryStore returns a new instance of DBStore. To be used only in tests and simulations.
+func NewInmemoryStore() *DBStore {
+ db, err := leveldb.Open(storage.NewMemStorage(), nil)
+ if err != nil {
+ panic(err)
+ }
+ return &DBStore{
+ db: db,
+ }
+}
+
// Get retrieves a persisted value for a specific key. If there is no results
// ErrNotFound is returned. The provided parameter should be either a byte slice or
// a struct that implements the encoding.BinaryUnmarshaler interface
diff --git a/swarm/state/inmemorystore.go b/swarm/state/inmemorystore.go
deleted file mode 100644
index 3ba48592b..000000000
--- a/swarm/state/inmemorystore.go
+++ /dev/null
@@ -1,94 +0,0 @@
-// Copyright 2018 The go-ethereum Authors
-// This file is part of the go-ethereum library.
-//
-// The go-ethereum library is free software: you can redistribute it and/or modify
-// it under the terms of the GNU Lesser General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// The go-ethereum library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public License
-// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
-
-package state
-
-import (
- "encoding"
- "encoding/json"
- "sync"
-)
-
-// InmemoryStore is the reference implementation of Store interface that is supposed
-// to be used in tests.
-type InmemoryStore struct {
- db map[string][]byte
- mu sync.RWMutex
-}
-
-// NewInmemoryStore returns a new instance of InmemoryStore.
-func NewInmemoryStore() *InmemoryStore {
- return &InmemoryStore{
- db: make(map[string][]byte),
- }
-}
-
-// Get retrieves a value stored for a specific key. If there is no value found,
-// ErrNotFound is returned.
-func (s *InmemoryStore) Get(key string, i interface{}) (err error) {
- s.mu.RLock()
- defer s.mu.RUnlock()
-
- bytes, ok := s.db[key]
- if !ok {
- return ErrNotFound
- }
-
- unmarshaler, ok := i.(encoding.BinaryUnmarshaler)
- if !ok {
- return json.Unmarshal(bytes, i)
- }
-
- return unmarshaler.UnmarshalBinary(bytes)
-}
-
-// Put stores a value for a specific key.
-func (s *InmemoryStore) Put(key string, i interface{}) (err error) {
- s.mu.Lock()
- defer s.mu.Unlock()
- var bytes []byte
-
- marshaler, ok := i.(encoding.BinaryMarshaler)
- if !ok {
- if bytes, err = json.Marshal(i); err != nil {
- return err
- }
- } else {
- if bytes, err = marshaler.MarshalBinary(); err != nil {
- return err
- }
- }
-
- s.db[key] = bytes
- return nil
-}
-
-// Delete removes value stored under a specific key.
-func (s *InmemoryStore) Delete(key string) (err error) {
- s.mu.Lock()
- defer s.mu.Unlock()
-
- if _, ok := s.db[key]; !ok {
- return ErrNotFound
- }
- delete(s.db, key)
- return nil
-}
-
-// Close does not do anything.
-func (s *InmemoryStore) Close() error {
- return nil
-}
diff --git a/swarm/state/store.go b/swarm/state/store.go
deleted file mode 100644
index fb7fe258f..000000000
--- a/swarm/state/store.go
+++ /dev/null
@@ -1,26 +0,0 @@
-// Copyright 2018 The go-ethereum Authors
-// This file is part of the go-ethereum library.
-//
-// The go-ethereum library is free software: you can redistribute it and/or modify
-// it under the terms of the GNU Lesser General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// The go-ethereum library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public License
-// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
-
-package state
-
-// Store defines methods required to get, set, delete values for different keys
-// and close the underlying resources.
-type Store interface {
- Get(key string, i interface{}) (err error)
- Put(key string, i interface{}) (err error)
- Delete(key string) (err error)
- Close() error
-}
diff --git a/whisper/mailserver/mailserver.go b/whisper/mailserver/mailserver.go
index af9418d9f..d7af4baae 100644
--- a/whisper/mailserver/mailserver.go
+++ b/whisper/mailserver/mailserver.go
@@ -14,6 +14,7 @@
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
+// Package mailserver provides a naive, example mailserver implementation
package mailserver
import (
@@ -26,9 +27,11 @@ import (
"github.com/ethereum/go-ethereum/rlp"
whisper "github.com/ethereum/go-ethereum/whisper/whisperv6"
"github.com/syndtr/goleveldb/leveldb"
+ "github.com/syndtr/goleveldb/leveldb/opt"
"github.com/syndtr/goleveldb/leveldb/util"
)
+// WMailServer represents the state data of the mailserver.
type WMailServer struct {
db *leveldb.DB
w *whisper.Whisper
@@ -42,6 +45,8 @@ type DBKey struct {
raw []byte
}
+// NewDbKey is a helper function that creates a levelDB
+// key from a hash and an integer.
func NewDbKey(t uint32, h common.Hash) *DBKey {
const sz = common.HashLength + 4
var k DBKey
@@ -53,6 +58,7 @@ func NewDbKey(t uint32, h common.Hash) *DBKey {
return &k
}
+// Init initializes the mail server.
func (s *WMailServer) Init(shh *whisper.Whisper, path string, password string, pow float64) error {
var err error
if len(path) == 0 {
@@ -63,7 +69,7 @@ func (s *WMailServer) Init(shh *whisper.Whisper, path string, password string, p
return fmt.Errorf("password is not specified")
}
- s.db, err = leveldb.OpenFile(path, nil)
+ s.db, err = leveldb.OpenFile(path, &opt.Options{OpenFilesCacheCapacity: 32})
if err != nil {
return fmt.Errorf("open DB file: %s", err)
}
@@ -82,12 +88,14 @@ func (s *WMailServer) Init(shh *whisper.Whisper, path string, password string, p
return nil
}
+// Close cleans up before shutdown.
func (s *WMailServer) Close() {
if s.db != nil {
s.db.Close()
}
}
+// Archive stores the
func (s *WMailServer) Archive(env *whisper.Envelope) {
key := NewDbKey(env.Expiry-env.TTL, env.Hash())
rawEnvelope, err := rlp.EncodeToBytes(env)
@@ -101,6 +109,8 @@ func (s *WMailServer) Archive(env *whisper.Envelope) {
}
}
+// DeliverMail responds with saved messages upon request by the
+// messages' owner.
func (s *WMailServer) DeliverMail(peer *whisper.Peer, request *whisper.Envelope) {
if peer == nil {
log.Error("Whisper peer is nil")