aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.travis.yml1
-rw-r--r--accounts/abi/event.go8
-rw-r--r--cmd/utils/flags.go4
-rw-r--r--core/state/state_object.go5
-rw-r--r--core/state/statedb.go21
-rw-r--r--core/tx_pool.go2
-rw-r--r--core/tx_pool_test.go22
-rw-r--r--core/vm/contract.go14
-rw-r--r--core/vm/evm.go5
-rw-r--r--core/vm/logger.go4
-rw-r--r--core/vm/memory.go12
-rw-r--r--core/vm/opcodes.go6
-rw-r--r--eth/api_tracer.go5
-rw-r--r--internal/jsre/jsre.go54
-rw-r--r--tests/block_test_util.go2
-rw-r--r--tests/init.go2
-rw-r--r--tests/init_test.go11
-rw-r--r--tests/transaction_test_util.go3
-rw-r--r--trie/iterator.go14
-rw-r--r--trie/node.go8
-rw-r--r--vendor/github.com/syndtr/goleveldb/leveldb/storage/mem_storage.go8
-rw-r--r--vendor/github.com/syndtr/goleveldb/leveldb/util.go2
-rw-r--r--vendor/vendor.json52
-rw-r--r--whisper/shhclient/client.go3
-rw-r--r--whisper/whisperv5/api.go4
-rw-r--r--whisper/whisperv5/doc.go2
-rw-r--r--whisper/whisperv5/message.go6
-rw-r--r--whisper/whisperv5/peer.go52
-rw-r--r--whisper/whisperv5/peer_test.go6
-rw-r--r--whisper/whisperv5/topic.go2
-rw-r--r--whisper/whisperv5/whisper.go77
31 files changed, 200 insertions, 217 deletions
diff --git a/.travis.yml b/.travis.yml
index 2ba6f18f2..194ca6396 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -31,7 +31,6 @@ matrix:
script:
- unset -f cd # workaround for https://github.com/travis-ci/travis-ci/issues/8703
- brew update
- - brew install caskroom/cask/brew-cask
- brew cask install osxfuse
- go run build/ci.go install
- go run build/ci.go test -coverage $TEST_PACKAGES
diff --git a/accounts/abi/event.go b/accounts/abi/event.go
index 595f169f3..a3f6be973 100644
--- a/accounts/abi/event.go
+++ b/accounts/abi/event.go
@@ -33,15 +33,15 @@ type Event struct {
Inputs Arguments
}
-func (event Event) String() string {
- inputs := make([]string, len(event.Inputs))
- for i, input := range event.Inputs {
+func (e Event) String() string {
+ inputs := make([]string, len(e.Inputs))
+ for i, input := range e.Inputs {
inputs[i] = fmt.Sprintf("%v %v", input.Name, input.Type)
if input.Indexed {
inputs[i] = fmt.Sprintf("%v indexed %v", input.Name, input.Type)
}
}
- return fmt.Sprintf("event %v(%v)", event.Name, strings.Join(inputs, ", "))
+ return fmt.Sprintf("e %v(%v)", e.Name, strings.Join(inputs, ", "))
}
// Id returns the canonical representation of the event's signature used by the
diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go
index ba8378ef2..ef5f6a9f0 100644
--- a/cmd/utils/flags.go
+++ b/cmd/utils/flags.go
@@ -158,11 +158,11 @@ var (
}
FastSyncFlag = cli.BoolFlag{
Name: "fast",
- Usage: "Enable fast syncing through state downloads",
+ Usage: "Enable fast syncing through state downloads (replaced by --syncmode)",
}
LightModeFlag = cli.BoolFlag{
Name: "light",
- Usage: "Enable light client mode",
+ Usage: "Enable light client mode (replaced by --syncmode)",
}
defaultSyncMode = eth.DefaultConfig.SyncMode
SyncModeFlag = TextMarshalerFlag{
diff --git a/core/state/state_object.go b/core/state/state_object.go
index 3c40c2041..5d203fddd 100644
--- a/core/state/state_object.go
+++ b/core/state/state_object.go
@@ -178,9 +178,7 @@ func (self *stateObject) GetState(db Database, key common.Hash) common.Hash {
}
value.SetBytes(content)
}
- if (value != common.Hash{}) {
- self.cachedStorage[key] = value
- }
+ self.cachedStorage[key] = value
return value
}
@@ -197,7 +195,6 @@ func (self *stateObject) SetState(db Database, key, value common.Hash) {
func (self *stateObject) setState(key, value common.Hash) {
self.cachedStorage[key] = value
self.dirtyStorage[key] = value
-
}
// updateTrie writes cached storage modifications into the object's storage trie.
diff --git a/core/state/statedb.go b/core/state/statedb.go
index 3ae6843d8..a952027d6 100644
--- a/core/state/statedb.go
+++ b/core/state/statedb.go
@@ -572,27 +572,6 @@ func (self *StateDB) Prepare(thash, bhash common.Hash, ti int) {
self.txIndex = ti
}
-// DeleteSuicides flags the suicided objects for deletion so that it
-// won't be referenced again when called / queried up on.
-//
-// DeleteSuicides should not be used for consensus related updates
-// under any circumstances.
-func (s *StateDB) DeleteSuicides() {
- // Reset refund so that any used-gas calculations can use this method.
- s.clearJournalAndRefund()
-
- for addr := range s.stateObjectsDirty {
- stateObject := s.stateObjects[addr]
-
- // If the object has been removed by a suicide
- // flag the object as deleted.
- if stateObject.suicided {
- stateObject.deleted = true
- }
- delete(s.stateObjectsDirty, addr)
- }
-}
-
func (s *StateDB) clearJournalAndRefund() {
s.journal = newJournal()
s.validRevisions = s.validRevisions[:0]
diff --git a/core/tx_pool.go b/core/tx_pool.go
index b21384458..388b40058 100644
--- a/core/tx_pool.go
+++ b/core/tx_pool.go
@@ -618,7 +618,7 @@ func (pool *TxPool) add(tx *types.Transaction, local bool) (bool, error) {
// If the transaction pool is full, discard underpriced transactions
if uint64(len(pool.all)) >= pool.config.GlobalSlots+pool.config.GlobalQueue {
// If the new transaction is underpriced, don't accept it
- if pool.priced.Underpriced(tx, pool.locals) {
+ if !local && pool.priced.Underpriced(tx, pool.locals) {
log.Trace("Discarding underpriced transaction", "hash", hash, "price", tx.GasPrice())
underpricedTxCounter.Inc(1)
return false, ErrUnderpriced
diff --git a/core/tx_pool_test.go b/core/tx_pool_test.go
index 0cb14cb6a..f0f86415d 100644
--- a/core/tx_pool_test.go
+++ b/core/tx_pool_test.go
@@ -1346,7 +1346,7 @@ func TestTransactionPoolUnderpricing(t *testing.T) {
defer sub.Unsubscribe()
// Create a number of test accounts and fund them
- keys := make([]*ecdsa.PrivateKey, 3)
+ keys := make([]*ecdsa.PrivateKey, 4)
for i := 0; i < len(keys); i++ {
keys[i], _ = crypto.GenerateKey()
pool.currentState.AddBalance(crypto.PubkeyToAddress(keys[i].PublicKey), big.NewInt(1000000))
@@ -1406,18 +1406,22 @@ func TestTransactionPoolUnderpricing(t *testing.T) {
t.Fatalf("pool internal state corrupted: %v", err)
}
// Ensure that adding local transactions can push out even higher priced ones
- tx := pricedTransaction(1, 100000, big.NewInt(0), keys[2])
- if err := pool.AddLocal(tx); err != nil {
- t.Fatalf("failed to add underpriced local transaction: %v", err)
+ ltx = pricedTransaction(1, 100000, big.NewInt(0), keys[2])
+ if err := pool.AddLocal(ltx); err != nil {
+ t.Fatalf("failed to append underpriced local transaction: %v", err)
+ }
+ ltx = pricedTransaction(0, 100000, big.NewInt(0), keys[3])
+ if err := pool.AddLocal(ltx); err != nil {
+ t.Fatalf("failed to add new underpriced local transaction: %v", err)
}
pending, queued = pool.Stats()
- if pending != 2 {
- t.Fatalf("pending transactions mismatched: have %d, want %d", pending, 2)
+ if pending != 3 {
+ t.Fatalf("pending transactions mismatched: have %d, want %d", pending, 3)
}
- if queued != 2 {
- t.Fatalf("queued transactions mismatched: have %d, want %d", queued, 2)
+ if queued != 1 {
+ t.Fatalf("queued transactions mismatched: have %d, want %d", queued, 1)
}
- if err := validateEvents(events, 1); err != nil {
+ if err := validateEvents(events, 2); err != nil {
t.Fatalf("local event firing failed: %v", err)
}
if err := validateTxPoolInternals(pool); err != nil {
diff --git a/core/vm/contract.go b/core/vm/contract.go
index 66748e821..b466681db 100644
--- a/core/vm/contract.go
+++ b/core/vm/contract.go
@@ -139,15 +139,15 @@ func (c *Contract) Value() *big.Int {
}
// SetCode sets the code to the contract
-func (self *Contract) SetCode(hash common.Hash, code []byte) {
- self.Code = code
- self.CodeHash = hash
+func (c *Contract) SetCode(hash common.Hash, code []byte) {
+ c.Code = code
+ c.CodeHash = hash
}
// SetCallCode sets the code of the contract and address of the backing data
// object
-func (self *Contract) SetCallCode(addr *common.Address, hash common.Hash, code []byte) {
- self.Code = code
- self.CodeHash = hash
- self.CodeAddr = addr
+func (c *Contract) SetCallCode(addr *common.Address, hash common.Hash, code []byte) {
+ c.Code = code
+ c.CodeHash = hash
+ c.CodeAddr = addr
}
diff --git a/core/vm/evm.go b/core/vm/evm.go
index 96676c314..ea4620974 100644
--- a/core/vm/evm.go
+++ b/core/vm/evm.go
@@ -160,6 +160,11 @@ func (evm *EVM) Call(caller ContractRef, addr common.Address, input []byte, gas
precompiles = PrecompiledContractsByzantium
}
if precompiles[addr] == nil && evm.ChainConfig().IsEIP158(evm.BlockNumber) && value.Sign() == 0 {
+ // Calling a non existing account, don't do antything, but ping the tracer
+ if evm.vmConfig.Debug && evm.depth == 0 {
+ evm.vmConfig.Tracer.CaptureStart(caller.Address(), addr, false, input, gas, value)
+ evm.vmConfig.Tracer.CaptureEnd(ret, 0, 0, nil)
+ }
return nil, gas, nil
}
evm.StateDB.CreateAccount(addr)
diff --git a/core/vm/logger.go b/core/vm/logger.go
index dde1903bf..c32a7b404 100644
--- a/core/vm/logger.go
+++ b/core/vm/logger.go
@@ -31,9 +31,9 @@ import (
type Storage map[common.Hash]common.Hash
-func (self Storage) Copy() Storage {
+func (s Storage) Copy() Storage {
cpy := make(Storage)
- for key, value := range self {
+ for key, value := range s {
cpy[key] = value
}
diff --git a/core/vm/memory.go b/core/vm/memory.go
index 99a84d227..d5cc7870b 100644
--- a/core/vm/memory.go
+++ b/core/vm/memory.go
@@ -51,14 +51,14 @@ func (m *Memory) Resize(size uint64) {
}
// Get returns offset + size as a new slice
-func (self *Memory) Get(offset, size int64) (cpy []byte) {
+func (m *Memory) Get(offset, size int64) (cpy []byte) {
if size == 0 {
return nil
}
- if len(self.store) > int(offset) {
+ if len(m.store) > int(offset) {
cpy = make([]byte, size)
- copy(cpy, self.store[offset:offset+size])
+ copy(cpy, m.store[offset:offset+size])
return
}
@@ -67,13 +67,13 @@ func (self *Memory) Get(offset, size int64) (cpy []byte) {
}
// GetPtr returns the offset + size
-func (self *Memory) GetPtr(offset, size int64) []byte {
+func (m *Memory) GetPtr(offset, size int64) []byte {
if size == 0 {
return nil
}
- if len(self.store) > int(offset) {
- return self.store[offset : offset+size]
+ if len(m.store) > int(offset) {
+ return m.store[offset : offset+size]
}
return nil
diff --git a/core/vm/opcodes.go b/core/vm/opcodes.go
index 7fe55b72f..e3568eb00 100644
--- a/core/vm/opcodes.go
+++ b/core/vm/opcodes.go
@@ -375,10 +375,10 @@ var opCodeToString = map[OpCode]string{
SWAP: "SWAP",
}
-func (o OpCode) String() string {
- str := opCodeToString[o]
+func (op OpCode) String() string {
+ str := opCodeToString[op]
if len(str) == 0 {
- return fmt.Sprintf("Missing opcode 0x%x", int(o))
+ return fmt.Sprintf("Missing opcode 0x%x", int(op))
}
return str
diff --git a/eth/api_tracer.go b/eth/api_tracer.go
index 07c4457bc..80a3ab719 100644
--- a/eth/api_tracer.go
+++ b/eth/api_tracer.go
@@ -201,7 +201,7 @@ func (api *PrivateDebugAPI) traceChain(ctx context.Context, start, end *types.Bl
log.Warn("Tracing failed", "hash", tx.Hash(), "block", task.block.NumberU64(), "err", err)
break
}
- task.statedb.DeleteSuicides()
+ task.statedb.Finalise(true)
task.results[i] = &txTraceResult{Result: res}
}
// Stream the result back to the user or abort on teardown
@@ -640,7 +640,8 @@ func (api *PrivateDebugAPI) computeTxEnv(blockHash common.Hash, txIndex int, ree
if _, _, _, err := core.ApplyMessage(vmenv, msg, new(core.GasPool).AddGas(tx.Gas())); err != nil {
return nil, vm.Context{}, nil, fmt.Errorf("tx %x failed: %v", tx.Hash(), err)
}
- statedb.DeleteSuicides()
+ // Ensure any modifications are committed to the state
+ statedb.Finalise(true)
}
return nil, vm.Context{}, nil, fmt.Errorf("tx index %d out of range for block %x", txIndex, blockHash)
}
diff --git a/internal/jsre/jsre.go b/internal/jsre/jsre.go
index f05865eca..4c7664f1c 100644
--- a/internal/jsre/jsre.go
+++ b/internal/jsre/jsre.go
@@ -102,8 +102,8 @@ func randomSource() *rand.Rand {
// call the functions of the otto vm directly to circumvent the queue. These
// functions should be used if and only if running a routine that was already
// called from JS through an RPC call.
-func (self *JSRE) runEventLoop() {
- defer close(self.closed)
+func (re *JSRE) runEventLoop() {
+ defer close(re.closed)
vm := otto.New()
r := randomSource()
@@ -202,14 +202,14 @@ loop:
break loop
}
}
- case req := <-self.evalQueue:
+ case req := <-re.evalQueue:
// run the code, send the result back
req.fn(vm)
close(req.done)
if waitForCallbacks && (len(registry) == 0) {
break loop
}
- case waitForCallbacks = <-self.stopEventLoop:
+ case waitForCallbacks = <-re.stopEventLoop:
if !waitForCallbacks || (len(registry) == 0) {
break loop
}
@@ -223,31 +223,31 @@ loop:
}
// Do executes the given function on the JS event loop.
-func (self *JSRE) Do(fn func(*otto.Otto)) {
+func (re *JSRE) Do(fn func(*otto.Otto)) {
done := make(chan bool)
req := &evalReq{fn, done}
- self.evalQueue <- req
+ re.evalQueue <- req
<-done
}
// stops the event loop before exit, optionally waits for all timers to expire
-func (self *JSRE) Stop(waitForCallbacks bool) {
+func (re *JSRE) Stop(waitForCallbacks bool) {
select {
- case <-self.closed:
- case self.stopEventLoop <- waitForCallbacks:
- <-self.closed
+ case <-re.closed:
+ case re.stopEventLoop <- waitForCallbacks:
+ <-re.closed
}
}
// Exec(file) loads and runs the contents of a file
// if a relative path is given, the jsre's assetPath is used
-func (self *JSRE) Exec(file string) error {
- code, err := ioutil.ReadFile(common.AbsolutePath(self.assetPath, file))
+func (re *JSRE) Exec(file string) error {
+ code, err := ioutil.ReadFile(common.AbsolutePath(re.assetPath, file))
if err != nil {
return err
}
var script *otto.Script
- self.Do(func(vm *otto.Otto) {
+ re.Do(func(vm *otto.Otto) {
script, err = vm.Compile(file, code)
if err != nil {
return
@@ -259,36 +259,36 @@ func (self *JSRE) Exec(file string) error {
// Bind assigns value v to a variable in the JS environment
// This method is deprecated, use Set.
-func (self *JSRE) Bind(name string, v interface{}) error {
- return self.Set(name, v)
+func (re *JSRE) Bind(name string, v interface{}) error {
+ return re.Set(name, v)
}
// Run runs a piece of JS code.
-func (self *JSRE) Run(code string) (v otto.Value, err error) {
- self.Do(func(vm *otto.Otto) { v, err = vm.Run(code) })
+func (re *JSRE) Run(code string) (v otto.Value, err error) {
+ re.Do(func(vm *otto.Otto) { v, err = vm.Run(code) })
return v, err
}
// Get returns the value of a variable in the JS environment.
-func (self *JSRE) Get(ns string) (v otto.Value, err error) {
- self.Do(func(vm *otto.Otto) { v, err = vm.Get(ns) })
+func (re *JSRE) Get(ns string) (v otto.Value, err error) {
+ re.Do(func(vm *otto.Otto) { v, err = vm.Get(ns) })
return v, err
}
// Set assigns value v to a variable in the JS environment.
-func (self *JSRE) Set(ns string, v interface{}) (err error) {
- self.Do(func(vm *otto.Otto) { err = vm.Set(ns, v) })
+func (re *JSRE) Set(ns string, v interface{}) (err error) {
+ re.Do(func(vm *otto.Otto) { err = vm.Set(ns, v) })
return err
}
// loadScript executes a JS script from inside the currently executing JS code.
-func (self *JSRE) loadScript(call otto.FunctionCall) otto.Value {
+func (re *JSRE) loadScript(call otto.FunctionCall) otto.Value {
file, err := call.Argument(0).ToString()
if err != nil {
// TODO: throw exception
return otto.FalseValue()
}
- file = common.AbsolutePath(self.assetPath, file)
+ file = common.AbsolutePath(re.assetPath, file)
source, err := ioutil.ReadFile(file)
if err != nil {
// TODO: throw exception
@@ -305,10 +305,10 @@ func (self *JSRE) loadScript(call otto.FunctionCall) otto.Value {
// Evaluate executes code and pretty prints the result to the specified output
// stream.
-func (self *JSRE) Evaluate(code string, w io.Writer) error {
+func (re *JSRE) Evaluate(code string, w io.Writer) error {
var fail error
- self.Do(func(vm *otto.Otto) {
+ re.Do(func(vm *otto.Otto) {
val, err := vm.Run(code)
if err != nil {
prettyError(vm, err, w)
@@ -321,8 +321,8 @@ func (self *JSRE) Evaluate(code string, w io.Writer) error {
}
// Compile compiles and then runs a piece of JS code.
-func (self *JSRE) Compile(filename string, src interface{}) (err error) {
- self.Do(func(vm *otto.Otto) { _, err = compileAndRun(vm, filename, src) })
+func (re *JSRE) Compile(filename string, src interface{}) (err error) {
+ re.Do(func(vm *otto.Otto) { _, err = compileAndRun(vm, filename, src) })
return err
}
diff --git a/tests/block_test_util.go b/tests/block_test_util.go
index beba48483..579e783b1 100644
--- a/tests/block_test_util.go
+++ b/tests/block_test_util.go
@@ -104,7 +104,7 @@ func (t *BlockTest) Run() error {
return err
}
if gblock.Hash() != t.json.Genesis.Hash {
- return fmt.Errorf("genesis block hash doesn't match test: computed=%x, test=%x\n", gblock.Hash().Bytes()[:6], t.json.Genesis.Hash[:6])
+ return fmt.Errorf("genesis block hash doesn't match test: computed=%x, test=%x", gblock.Hash().Bytes()[:6], t.json.Genesis.Hash[:6])
}
if gblock.Root() != t.json.Genesis.StateRoot {
return fmt.Errorf("genesis block state root does not match test: computed=%x, test=%x", gblock.Root().Bytes()[:6], t.json.Genesis.StateRoot[:6])
diff --git a/tests/init.go b/tests/init.go
index ff8ee7da1..0bea5ccd6 100644
--- a/tests/init.go
+++ b/tests/init.go
@@ -23,7 +23,7 @@ import (
"github.com/ethereum/go-ethereum/params"
)
-// This table defines supported forks and their chain config.
+// Forks table defines supported forks and their chain config.
var Forks = map[string]*params.ChainConfig{
"Frontier": {
ChainId: big.NewInt(1),
diff --git a/tests/init_test.go b/tests/init_test.go
index fbb214b08..26e919d24 100644
--- a/tests/init_test.go
+++ b/tests/init_test.go
@@ -42,7 +42,7 @@ var (
difficultyTestDir = filepath.Join(baseDir, "BasicTests")
)
-func readJson(reader io.Reader, value interface{}) error {
+func readJSON(reader io.Reader, value interface{}) error {
data, err := ioutil.ReadAll(reader)
if err != nil {
return fmt.Errorf("error reading JSON file: %v", err)
@@ -57,14 +57,14 @@ func readJson(reader io.Reader, value interface{}) error {
return nil
}
-func readJsonFile(fn string, value interface{}) error {
+func readJSONFile(fn string, value interface{}) error {
file, err := os.Open(fn)
if err != nil {
return err
}
defer file.Close()
- err = readJson(file, value)
+ err = readJSON(file, value)
if err != nil {
return fmt.Errorf("%s in file %s", err.Error(), fn)
}
@@ -169,9 +169,8 @@ func (tm *testMatcher) checkFailure(t *testing.T, name string, err error) error
if err != nil {
t.Logf("error: %v", err)
return nil
- } else {
- return fmt.Errorf("test succeeded unexpectedly")
}
+ return fmt.Errorf("test succeeded unexpectedly")
}
return err
}
@@ -213,7 +212,7 @@ func (tm *testMatcher) runTestFile(t *testing.T, path, name string, runTest inte
// Load the file as map[string]<testType>.
m := makeMapFromTestFunc(runTest)
- if err := readJsonFile(path, m.Addr().Interface()); err != nil {
+ if err := readJSONFile(path, m.Addr().Interface()); err != nil {
t.Fatal(err)
}
diff --git a/tests/transaction_test_util.go b/tests/transaction_test_util.go
index 2028d2a27..8c3dac088 100644
--- a/tests/transaction_test_util.go
+++ b/tests/transaction_test_util.go
@@ -72,9 +72,8 @@ func (tt *TransactionTest) Run(config *params.ChainConfig) error {
if err := rlp.DecodeBytes(tt.json.RLP, tx); err != nil {
if tt.json.Transaction == nil {
return nil
- } else {
- return fmt.Errorf("RLP decoding failed: %v", err)
}
+ return fmt.Errorf("RLP decoding failed: %v", err)
}
// Check sender derivation.
signer := types.MakeSigner(config, new(big.Int).SetUint64(uint64(tt.json.BlockNumber)))
diff --git a/trie/iterator.go b/trie/iterator.go
index 76146c0d6..3bae8e186 100644
--- a/trie/iterator.go
+++ b/trie/iterator.go
@@ -303,7 +303,7 @@ func (it *nodeIterator) push(state *nodeIteratorState, parentIndex *int, path []
it.path = path
it.stack = append(it.stack, state)
if parentIndex != nil {
- *parentIndex += 1
+ *parentIndex++
}
}
@@ -380,7 +380,7 @@ func (it *differenceIterator) Next(bool) bool {
if !it.b.Next(true) {
return false
}
- it.count += 1
+ it.count++
if it.eof {
// a has reached eof, so we just return all elements from b
@@ -395,7 +395,7 @@ func (it *differenceIterator) Next(bool) bool {
it.eof = true
return true
}
- it.count += 1
+ it.count++
case 1:
// b is before a
return true
@@ -405,12 +405,12 @@ func (it *differenceIterator) Next(bool) bool {
if !it.b.Next(hasHash) {
return false
}
- it.count += 1
+ it.count++
if !it.a.Next(hasHash) {
it.eof = true
return true
}
- it.count += 1
+ it.count++
}
}
}
@@ -504,14 +504,14 @@ func (it *unionIterator) Next(descend bool) bool {
skipped := heap.Pop(it.items).(NodeIterator)
// Skip the whole subtree if the nodes have hashes; otherwise just skip this node
if skipped.Next(skipped.Hash() == common.Hash{}) {
- it.count += 1
+ it.count++
// If there are more elements, push the iterator back on the heap
heap.Push(it.items, skipped)
}
}
if least.Next(descend) {
- it.count += 1
+ it.count++
heap.Push(it.items, least)
}
diff --git a/trie/node.go b/trie/node.go
index a7697fc0c..02815042c 100644
--- a/trie/node.go
+++ b/trie/node.go
@@ -123,17 +123,17 @@ func decodeNode(hash, buf []byte, cachegen uint16) (node, error) {
}
switch c, _ := rlp.CountValues(elems); c {
case 2:
- n, err := decodeShort(hash, buf, elems, cachegen)
+ n, err := decodeShort(hash, elems, cachegen)
return n, wrapError(err, "short")
case 17:
- n, err := decodeFull(hash, buf, elems, cachegen)
+ n, err := decodeFull(hash, elems, cachegen)
return n, wrapError(err, "full")
default:
return nil, fmt.Errorf("invalid number of list elements: %v", c)
}
}
-func decodeShort(hash, buf, elems []byte, cachegen uint16) (node, error) {
+func decodeShort(hash, elems []byte, cachegen uint16) (node, error) {
kbuf, rest, err := rlp.SplitString(elems)
if err != nil {
return nil, err
@@ -155,7 +155,7 @@ func decodeShort(hash, buf, elems []byte, cachegen uint16) (node, error) {
return &shortNode{key, r, flag}, nil
}
-func decodeFull(hash, buf, elems []byte, cachegen uint16) (*fullNode, error) {
+func decodeFull(hash, elems []byte, cachegen uint16) (*fullNode, error) {
n := &fullNode{flags: nodeFlag{hash: hash, gen: cachegen}}
for i := 0; i < 16; i++ {
cld, rest, err := decodeRef(elems, cachegen)
diff --git a/vendor/github.com/syndtr/goleveldb/leveldb/storage/mem_storage.go b/vendor/github.com/syndtr/goleveldb/leveldb/storage/mem_storage.go
index 9b0421f03..838f1bee1 100644
--- a/vendor/github.com/syndtr/goleveldb/leveldb/storage/mem_storage.go
+++ b/vendor/github.com/syndtr/goleveldb/leveldb/storage/mem_storage.go
@@ -12,7 +12,11 @@ import (
"sync"
)
-const typeShift = 3
+const typeShift = 4
+
+// Verify at compile-time that typeShift is large enough to cover all FileType
+// values by confirming that 0 == 0.
+var _ [0]struct{} = [TypeAll >> typeShift]struct{}{}
type memStorageLock struct {
ms *memStorage
@@ -143,7 +147,7 @@ func (ms *memStorage) Remove(fd FileDesc) error {
}
func (ms *memStorage) Rename(oldfd, newfd FileDesc) error {
- if FileDescOk(oldfd) || FileDescOk(newfd) {
+ if !FileDescOk(oldfd) || !FileDescOk(newfd) {
return ErrInvalidFile
}
if oldfd == newfd {
diff --git a/vendor/github.com/syndtr/goleveldb/leveldb/util.go b/vendor/github.com/syndtr/goleveldb/leveldb/util.go
index e572a329e..0e2b519e5 100644
--- a/vendor/github.com/syndtr/goleveldb/leveldb/util.go
+++ b/vendor/github.com/syndtr/goleveldb/leveldb/util.go
@@ -20,7 +20,7 @@ func shorten(str string) string {
return str[:3] + ".." + str[len(str)-3:]
}
-var bunits = [...]string{"", "Ki", "Mi", "Gi"}
+var bunits = [...]string{"", "Ki", "Mi", "Gi", "Ti"}
func shortenb(bytes int) string {
i := 0
diff --git a/vendor/vendor.json b/vendor/vendor.json
index e083a363b..fdc778936 100644
--- a/vendor/vendor.json
+++ b/vendor/vendor.json
@@ -418,76 +418,76 @@
"revisionTime": "2017-07-05T02:17:15Z"
},
{
- "checksumSHA1": "3QsnhPTXGytTbW3uDvQLgSo9s9M=",
+ "checksumSHA1": "k13cCuMJO7+KhR8ZXx5oUqDKGQA=",
"path": "github.com/syndtr/goleveldb/leveldb",
- "revision": "169b1b37be738edb2813dab48c97a549bcf99bb5",
- "revisionTime": "2018-03-07T11:33:52Z"
+ "revision": "ae970a0732be3a1f5311da86118d37b9f4bd2a5a",
+ "revisionTime": "2018-05-02T07:23:49Z"
},
{
"checksumSHA1": "EKIow7XkgNdWvR/982ffIZxKG8Y=",
"path": "github.com/syndtr/goleveldb/leveldb/cache",
- "revision": "169b1b37be738edb2813dab48c97a549bcf99bb5",
- "revisionTime": "2018-03-07T11:33:52Z"
+ "revision": "ae970a0732be3a1f5311da86118d37b9f4bd2a5a",
+ "revisionTime": "2018-05-02T07:23:49Z"
},
{
"checksumSHA1": "5KPgnvCPlR0ysDAqo6jApzRQ3tw=",
"path": "github.com/syndtr/goleveldb/leveldb/comparer",
- "revision": "169b1b37be738edb2813dab48c97a549bcf99bb5",
- "revisionTime": "2018-03-07T11:33:52Z"
+ "revision": "ae970a0732be3a1f5311da86118d37b9f4bd2a5a",
+ "revisionTime": "2018-05-02T07:23:49Z"
},
{
"checksumSHA1": "1DRAxdlWzS4U0xKN/yQ/fdNN7f0=",
"path": "github.com/syndtr/goleveldb/leveldb/errors",
- "revision": "169b1b37be738edb2813dab48c97a549bcf99bb5",
- "revisionTime": "2018-03-07T11:33:52Z"
+ "revision": "ae970a0732be3a1f5311da86118d37b9f4bd2a5a",
+ "revisionTime": "2018-05-02T07:23:49Z"
},
{
"checksumSHA1": "eqKeD6DS7eNCtxVYZEHHRKkyZrw=",
"path": "github.com/syndtr/goleveldb/leveldb/filter",
- "revision": "169b1b37be738edb2813dab48c97a549bcf99bb5",
- "revisionTime": "2018-03-07T11:33:52Z"
+ "revision": "ae970a0732be3a1f5311da86118d37b9f4bd2a5a",
+ "revisionTime": "2018-05-02T07:23:49Z"
},
{
"checksumSHA1": "weSsccMav4BCerDpSLzh3mMxAYo=",
"path": "github.com/syndtr/goleveldb/leveldb/iterator",
- "revision": "169b1b37be738edb2813dab48c97a549bcf99bb5",
- "revisionTime": "2018-03-07T11:33:52Z"
+ "revision": "ae970a0732be3a1f5311da86118d37b9f4bd2a5a",
+ "revisionTime": "2018-05-02T07:23:49Z"
},
{
"checksumSHA1": "gJY7bRpELtO0PJpZXgPQ2BYFJ88=",
"path": "github.com/syndtr/goleveldb/leveldb/journal",
- "revision": "169b1b37be738edb2813dab48c97a549bcf99bb5",
- "revisionTime": "2018-03-07T11:33:52Z"
+ "revision": "ae970a0732be3a1f5311da86118d37b9f4bd2a5a",
+ "revisionTime": "2018-05-02T07:23:49Z"
},
{
"checksumSHA1": "MtYY1b2234y/MlS+djL8tXVAcQs=",
"path": "github.com/syndtr/goleveldb/leveldb/memdb",
- "revision": "169b1b37be738edb2813dab48c97a549bcf99bb5",
- "revisionTime": "2018-03-07T11:33:52Z"
+ "revision": "ae970a0732be3a1f5311da86118d37b9f4bd2a5a",
+ "revisionTime": "2018-05-02T07:23:49Z"
},
{
"checksumSHA1": "UmQeotV+m8/FduKEfLOhjdp18rs=",
"path": "github.com/syndtr/goleveldb/leveldb/opt",
- "revision": "169b1b37be738edb2813dab48c97a549bcf99bb5",
- "revisionTime": "2018-03-07T11:33:52Z"
+ "revision": "ae970a0732be3a1f5311da86118d37b9f4bd2a5a",
+ "revisionTime": "2018-05-02T07:23:49Z"
},
{
- "checksumSHA1": "QCSae2ub87f8awH+PKMpd8ZYOtg=",
+ "checksumSHA1": "7H3fa12T7WoMAeXq1+qG5O7LD0w=",
"path": "github.com/syndtr/goleveldb/leveldb/storage",
- "revision": "169b1b37be738edb2813dab48c97a549bcf99bb5",
- "revisionTime": "2018-03-07T11:33:52Z"
+ "revision": "ae970a0732be3a1f5311da86118d37b9f4bd2a5a",
+ "revisionTime": "2018-05-02T07:23:49Z"
},
{
"checksumSHA1": "gWFPMz8OQeul0t54RM66yMTX49g=",
"path": "github.com/syndtr/goleveldb/leveldb/table",
- "revision": "169b1b37be738edb2813dab48c97a549bcf99bb5",
- "revisionTime": "2018-03-07T11:33:52Z"
+ "revision": "ae970a0732be3a1f5311da86118d37b9f4bd2a5a",
+ "revisionTime": "2018-05-02T07:23:49Z"
},
{
"checksumSHA1": "V/Dh7NV0/fy/5jX1KaAjmGcNbzI=",
"path": "github.com/syndtr/goleveldb/leveldb/util",
- "revision": "169b1b37be738edb2813dab48c97a549bcf99bb5",
- "revisionTime": "2018-03-07T11:33:52Z"
+ "revision": "ae970a0732be3a1f5311da86118d37b9f4bd2a5a",
+ "revisionTime": "2018-05-02T07:23:49Z"
},
{
"checksumSHA1": "TT1rac6kpQp2vz24m5yDGUNQ/QQ=",
diff --git a/whisper/shhclient/client.go b/whisper/shhclient/client.go
index bbe694baa..7b25e739e 100644
--- a/whisper/shhclient/client.go
+++ b/whisper/shhclient/client.go
@@ -67,7 +67,6 @@ func (sc *Client) SetMaxMessageSize(ctx context.Context, size uint32) error {
}
// SetMinimumPoW (experimental) sets the minimal PoW required by this node.
-
// This experimental function was introduced for the future dynamic adjustment of
// PoW requirement. If the node is overwhelmed with messages, it should raise the
// PoW requirement and notify the peers. The new value should be set relative to
@@ -77,7 +76,7 @@ func (sc *Client) SetMinimumPoW(ctx context.Context, pow float64) error {
return sc.c.CallContext(ctx, &ignored, "shh_setMinPoW", pow)
}
-// Marks specific peer trusted, which will allow it to send historic (expired) messages.
+// MarkTrustedPeer marks specific peer trusted, which will allow it to send historic (expired) messages.
// Note This function is not adding new nodes, the node needs to exists as a peer.
func (sc *Client) MarkTrustedPeer(ctx context.Context, enode string) error {
var ignored bool
diff --git a/whisper/whisperv5/api.go b/whisper/whisperv5/api.go
index 9fb22aa75..c56d13949 100644
--- a/whisper/whisperv5/api.go
+++ b/whisper/whisperv5/api.go
@@ -89,7 +89,7 @@ func (api *PublicWhisperAPI) SetMaxMessageSize(ctx context.Context, size uint32)
return true, api.w.SetMaxMessageSize(size)
}
-// SetMinPow sets the minimum PoW for a message before it is accepted.
+// SetMinPoW sets the minimum PoW for a message before it is accepted.
func (api *PublicWhisperAPI) SetMinPoW(ctx context.Context, pow float64) (bool, error) {
return true, api.w.SetMinimumPoW(pow)
}
@@ -142,7 +142,7 @@ func (api *PublicWhisperAPI) GetPublicKey(ctx context.Context, id string) (hexut
return crypto.FromECDSAPub(&key.PublicKey), nil
}
-// GetPublicKey returns the private key associated with the given key. The key is the hex
+// GetPrivateKey returns the private key associated with the given key. The key is the hex
// encoded representation of a key in the form specified in section 4.3.6 of ANSI X9.62.
func (api *PublicWhisperAPI) GetPrivateKey(ctx context.Context, id string) (hexutil.Bytes, error) {
key, err := api.w.GetPrivateKey(id)
diff --git a/whisper/whisperv5/doc.go b/whisper/whisperv5/doc.go
index 7a57488bd..8161db8ed 100644
--- a/whisper/whisperv5/doc.go
+++ b/whisper/whisperv5/doc.go
@@ -15,7 +15,7 @@
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
/*
-Package whisper implements the Whisper protocol (version 5).
+Package whisperv5 implements the Whisper protocol (version 5).
Whisper combines aspects of both DHTs and datagram messaging systems (e.g. UDP).
As such it may be likened and compared to both, not dissimilar to the
diff --git a/whisper/whisperv5/message.go b/whisper/whisperv5/message.go
index 34ce52e64..35711d724 100644
--- a/whisper/whisperv5/message.go
+++ b/whisper/whisperv5/message.go
@@ -33,7 +33,7 @@ import (
"github.com/ethereum/go-ethereum/log"
)
-// Options specifies the exact way a message should be wrapped into an Envelope.
+// MessageParams specifies the exact way a message should be wrapped into an Envelope.
type MessageParams struct {
TTL uint32
Src *ecdsa.PrivateKey
@@ -86,7 +86,7 @@ func (msg *ReceivedMessage) isAsymmetricEncryption() bool {
return msg.Dst != nil
}
-// NewMessage creates and initializes a non-signed, non-encrypted Whisper message.
+// NewSentMessage creates and initializes a non-signed, non-encrypted Whisper message.
func NewSentMessage(params *MessageParams) (*sentMessage, error) {
msg := sentMessage{}
msg.Raw = make([]byte, 1, len(params.Payload)+len(params.Padding)+signatureLength+padSizeLimit)
@@ -330,7 +330,7 @@ func (msg *ReceivedMessage) extractPadding(end int) (int, bool) {
return paddingSize, true
}
-// Recover retrieves the public key of the message signer.
+// SigToPubKey retrieves the public key of the message signer.
func (msg *ReceivedMessage) SigToPubKey() *ecdsa.PublicKey {
defer func() { recover() }() // in case of invalid signature
diff --git a/whisper/whisperv5/peer.go b/whisper/whisperv5/peer.go
index 179c93179..da0763199 100644
--- a/whisper/whisperv5/peer.go
+++ b/whisper/whisperv5/peer.go
@@ -27,7 +27,7 @@ import (
set "gopkg.in/fatih/set.v0"
)
-// peer represents a whisper protocol peer connection.
+// Peer represents a whisper protocol peer connection.
type Peer struct {
host *Whisper
peer *p2p.Peer
@@ -53,51 +53,51 @@ func newPeer(host *Whisper, remote *p2p.Peer, rw p2p.MsgReadWriter) *Peer {
// start initiates the peer updater, periodically broadcasting the whisper packets
// into the network.
-func (p *Peer) start() {
- go p.update()
- log.Trace("start", "peer", p.ID())
+func (peer *Peer) start() {
+ go peer.update()
+ log.Trace("start", "peer", peer.ID())
}
// stop terminates the peer updater, stopping message forwarding to it.
-func (p *Peer) stop() {
- close(p.quit)
- log.Trace("stop", "peer", p.ID())
+func (peer *Peer) stop() {
+ close(peer.quit)
+ log.Trace("stop", "peer", peer.ID())
}
// handshake sends the protocol initiation status message to the remote peer and
// verifies the remote status too.
-func (p *Peer) handshake() error {
+func (peer *Peer) handshake() error {
// Send the handshake status message asynchronously
errc := make(chan error, 1)
go func() {
- errc <- p2p.Send(p.ws, statusCode, ProtocolVersion)
+ errc <- p2p.Send(peer.ws, statusCode, ProtocolVersion)
}()
// Fetch the remote status packet and verify protocol match
- packet, err := p.ws.ReadMsg()
+ packet, err := peer.ws.ReadMsg()
if err != nil {
return err
}
if packet.Code != statusCode {
- return fmt.Errorf("peer [%x] sent packet %x before status packet", p.ID(), packet.Code)
+ return fmt.Errorf("peer [%x] sent packet %x before status packet", peer.ID(), packet.Code)
}
s := rlp.NewStream(packet.Payload, uint64(packet.Size))
peerVersion, err := s.Uint()
if err != nil {
- return fmt.Errorf("peer [%x] sent bad status message: %v", p.ID(), err)
+ return fmt.Errorf("peer [%x] sent bad status message: %v", peer.ID(), err)
}
if peerVersion != ProtocolVersion {
- return fmt.Errorf("peer [%x]: protocol version mismatch %d != %d", p.ID(), peerVersion, ProtocolVersion)
+ return fmt.Errorf("peer [%x]: protocol version mismatch %d != %d", peer.ID(), peerVersion, ProtocolVersion)
}
// Wait until out own status is consumed too
if err := <-errc; err != nil {
- return fmt.Errorf("peer [%x] failed to send status packet: %v", p.ID(), err)
+ return fmt.Errorf("peer [%x] failed to send status packet: %v", peer.ID(), err)
}
return nil
}
// update executes periodic operations on the peer, including message transmission
// and expiration.
-func (p *Peer) update() {
+func (peer *Peer) update() {
// Start the tickers for the updates
expire := time.NewTicker(expirationCycle)
transmit := time.NewTicker(transmissionCycle)
@@ -106,15 +106,15 @@ func (p *Peer) update() {
for {
select {
case <-expire.C:
- p.expire()
+ peer.expire()
case <-transmit.C:
- if err := p.broadcast(); err != nil {
- log.Trace("broadcast failed", "reason", err, "peer", p.ID())
+ if err := peer.broadcast(); err != nil {
+ log.Trace("broadcast failed", "reason", err, "peer", peer.ID())
return
}
- case <-p.quit:
+ case <-peer.quit:
return
}
}
@@ -148,16 +148,16 @@ func (peer *Peer) expire() {
// broadcast iterates over the collection of envelopes and transmits yet unknown
// ones over the network.
-func (p *Peer) broadcast() error {
+func (peer *Peer) broadcast() error {
var cnt int
- envelopes := p.host.Envelopes()
+ envelopes := peer.host.Envelopes()
for _, envelope := range envelopes {
- if !p.marked(envelope) {
- err := p2p.Send(p.ws, messagesCode, envelope)
+ if !peer.marked(envelope) {
+ err := p2p.Send(peer.ws, messagesCode, envelope)
if err != nil {
return err
} else {
- p.mark(envelope)
+ peer.mark(envelope)
cnt++
}
}
@@ -168,7 +168,7 @@ func (p *Peer) broadcast() error {
return nil
}
-func (p *Peer) ID() []byte {
- id := p.peer.ID()
+func (peer *Peer) ID() []byte {
+ id := peer.peer.ID()
return id[:]
}
diff --git a/whisper/whisperv5/peer_test.go b/whisper/whisperv5/peer_test.go
index bae2adb6f..051b52dcf 100644
--- a/whisper/whisperv5/peer_test.go
+++ b/whisper/whisperv5/peer_test.go
@@ -32,7 +32,7 @@ import (
"github.com/ethereum/go-ethereum/p2p/nat"
)
-var keys []string = []string{
+var keys = []string{
"d49dcf37238dc8a7aac57dc61b9fee68f0a97f062968978b9fafa7d1033d03a9",
"73fd6143c48e80ed3c56ea159fe7494a0b6b393a392227b422f4c3e8f1b54f98",
"119dd32adb1daa7a4c7bf77f847fb28730785aa92947edf42fdd997b54de40dc",
@@ -84,9 +84,9 @@ type TestNode struct {
var result TestData
var nodes [NumNodes]*TestNode
-var sharedKey []byte = []byte("some arbitrary data here")
+var sharedKey = []byte("some arbitrary data here")
var sharedTopic TopicType = TopicType{0xF, 0x1, 0x2, 0}
-var expectedMessage []byte = []byte("per rectum ad astra")
+var expectedMessage = []byte("per rectum ad astra")
// This test does the following:
// 1. creates a chain of whisper nodes,
diff --git a/whisper/whisperv5/topic.go b/whisper/whisperv5/topic.go
index c4ea67eef..c4eda1db4 100644
--- a/whisper/whisperv5/topic.go
+++ b/whisper/whisperv5/topic.go
@@ -23,7 +23,7 @@ import (
"github.com/ethereum/go-ethereum/common/hexutil"
)
-// Topic represents a cryptographically secure, probabilistic partial
+// TopicType represents a cryptographically secure, probabilistic partial
// classifications of a message, determined as the first (left) 4 bytes of the
// SHA3 hash of some arbitrary data given by the original author of the message.
type TopicType [TopicLength]byte
diff --git a/whisper/whisperv5/whisper.go b/whisper/whisperv5/whisper.go
index 85849ccce..62bd1ce17 100644
--- a/whisper/whisperv5/whisper.go
+++ b/whisper/whisperv5/whisper.go
@@ -469,18 +469,18 @@ func (w *Whisper) Stop() error {
// HandlePeer is called by the underlying P2P layer when the whisper sub-protocol
// connection is negotiated.
-func (wh *Whisper) HandlePeer(peer *p2p.Peer, rw p2p.MsgReadWriter) error {
+func (w *Whisper) HandlePeer(peer *p2p.Peer, rw p2p.MsgReadWriter) error {
// Create the new peer and start tracking it
- whisperPeer := newPeer(wh, peer, rw)
+ whisperPeer := newPeer(w, peer, rw)
- wh.peerMu.Lock()
- wh.peers[whisperPeer] = struct{}{}
- wh.peerMu.Unlock()
+ w.peerMu.Lock()
+ w.peers[whisperPeer] = struct{}{}
+ w.peerMu.Unlock()
defer func() {
- wh.peerMu.Lock()
- delete(wh.peers, whisperPeer)
- wh.peerMu.Unlock()
+ w.peerMu.Lock()
+ delete(w.peers, whisperPeer)
+ w.peerMu.Unlock()
}()
// Run the peer handshake and state updates
@@ -490,11 +490,11 @@ func (wh *Whisper) HandlePeer(peer *p2p.Peer, rw p2p.MsgReadWriter) error {
whisperPeer.start()
defer whisperPeer.stop()
- return wh.runMessageLoop(whisperPeer, rw)
+ return w.runMessageLoop(whisperPeer, rw)
}
// runMessageLoop reads and processes inbound messages directly to merge into client-global state.
-func (wh *Whisper) runMessageLoop(p *Peer, rw p2p.MsgReadWriter) error {
+func (w *Whisper) runMessageLoop(p *Peer, rw p2p.MsgReadWriter) error {
for {
// fetch the next packet
packet, err := rw.ReadMsg()
@@ -502,7 +502,7 @@ func (wh *Whisper) runMessageLoop(p *Peer, rw p2p.MsgReadWriter) error {
log.Warn("message loop", "peer", p.peer.ID(), "err", err)
return err
}
- if packet.Size > wh.MaxMessageSize() {
+ if packet.Size > w.MaxMessageSize() {
log.Warn("oversized message received", "peer", p.peer.ID())
return errors.New("oversized message received")
}
@@ -518,7 +518,7 @@ func (wh *Whisper) runMessageLoop(p *Peer, rw p2p.MsgReadWriter) error {
log.Warn("failed to decode envelope, peer will be disconnected", "peer", p.peer.ID(), "err", err)
return errors.New("invalid envelope")
}
- cached, err := wh.add(&envelope)
+ cached, err := w.add(&envelope)
if err != nil {
log.Warn("bad envelope received, peer will be disconnected", "peer", p.peer.ID(), "err", err)
return errors.New("invalid envelope")
@@ -537,17 +537,17 @@ func (wh *Whisper) runMessageLoop(p *Peer, rw p2p.MsgReadWriter) error {
log.Warn("failed to decode direct message, peer will be disconnected", "peer", p.peer.ID(), "err", err)
return errors.New("invalid direct message")
}
- wh.postEvent(&envelope, true)
+ w.postEvent(&envelope, true)
}
case p2pRequestCode:
// Must be processed if mail server is implemented. Otherwise ignore.
- if wh.mailServer != nil {
+ if w.mailServer != nil {
var request Envelope
if err := packet.Decode(&request); err != nil {
log.Warn("failed to decode p2p request message, peer will be disconnected", "peer", p.peer.ID(), "err", err)
return errors.New("invalid p2p request")
}
- wh.mailServer.DeliverMail(p, &request)
+ w.mailServer.DeliverMail(p, &request)
}
default:
// New message types might be implemented in the future versions of Whisper.
@@ -561,29 +561,27 @@ func (wh *Whisper) runMessageLoop(p *Peer, rw p2p.MsgReadWriter) error {
// add inserts a new envelope into the message pool to be distributed within the
// whisper network. It also inserts the envelope into the expiration pool at the
// appropriate time-stamp. In case of error, connection should be dropped.
-func (wh *Whisper) add(envelope *Envelope) (bool, error) {
+func (w *Whisper) add(envelope *Envelope) (bool, error) {
now := uint32(time.Now().Unix())
sent := envelope.Expiry - envelope.TTL
if sent > now {
if sent-SynchAllowance > now {
return false, fmt.Errorf("envelope created in the future [%x]", envelope.Hash())
- } else {
- // recalculate PoW, adjusted for the time difference, plus one second for latency
- envelope.calculatePoW(sent - now + 1)
}
+ // recalculate PoW, adjusted for the time difference, plus one second for latency
+ envelope.calculatePoW(sent - now + 1)
}
if envelope.Expiry < now {
if envelope.Expiry+SynchAllowance*2 < now {
return false, fmt.Errorf("very old message")
- } else {
- log.Debug("expired envelope dropped", "hash", envelope.Hash().Hex())
- return false, nil // drop envelope without error
}
+ log.Debug("expired envelope dropped", "hash", envelope.Hash().Hex())
+ return false, nil // drop envelope without error
}
- if uint32(envelope.size()) > wh.MaxMessageSize() {
+ if uint32(envelope.size()) > w.MaxMessageSize() {
return false, fmt.Errorf("huge messages are not allowed [%x]", envelope.Hash())
}
@@ -598,36 +596,36 @@ func (wh *Whisper) add(envelope *Envelope) (bool, error) {
return false, fmt.Errorf("wrong size of AESNonce: %d bytes [env: %x]", aesNonceSize, envelope.Hash())
}
- if envelope.PoW() < wh.MinPow() {
+ if envelope.PoW() < w.MinPow() {
log.Debug("envelope with low PoW dropped", "PoW", envelope.PoW(), "hash", envelope.Hash().Hex())
return false, nil // drop envelope without error
}
hash := envelope.Hash()
- wh.poolMu.Lock()
- _, alreadyCached := wh.envelopes[hash]
+ w.poolMu.Lock()
+ _, alreadyCached := w.envelopes[hash]
if !alreadyCached {
- wh.envelopes[hash] = envelope
- if wh.expirations[envelope.Expiry] == nil {
- wh.expirations[envelope.Expiry] = set.NewNonTS()
+ w.envelopes[hash] = envelope
+ if w.expirations[envelope.Expiry] == nil {
+ w.expirations[envelope.Expiry] = set.NewNonTS()
}
- if !wh.expirations[envelope.Expiry].Has(hash) {
- wh.expirations[envelope.Expiry].Add(hash)
+ if !w.expirations[envelope.Expiry].Has(hash) {
+ w.expirations[envelope.Expiry].Add(hash)
}
}
- wh.poolMu.Unlock()
+ w.poolMu.Unlock()
if alreadyCached {
log.Trace("whisper envelope already cached", "hash", envelope.Hash().Hex())
} else {
log.Trace("cached whisper envelope", "hash", envelope.Hash().Hex())
- wh.statsMu.Lock()
- wh.stats.memoryUsed += envelope.size()
- wh.statsMu.Unlock()
- wh.postEvent(envelope, false) // notify the local node about the new message
- if wh.mailServer != nil {
- wh.mailServer.Archive(envelope)
+ w.statsMu.Lock()
+ w.stats.memoryUsed += envelope.size()
+ w.statsMu.Unlock()
+ w.postEvent(envelope, false) // notify the local node about the new message
+ if w.mailServer != nil {
+ w.mailServer.Archive(envelope)
}
}
return true, nil
@@ -838,9 +836,8 @@ func deriveKeyMaterial(key []byte, version uint64) (derivedKey []byte, err error
// because it's a once in a session experience
derivedKey := pbkdf2.Key(key, nil, 65356, aesKeyLength, sha256.New)
return derivedKey, nil
- } else {
- return nil, unknownVersionError(version)
}
+ return nil, unknownVersionError(version)
}
// GenerateRandomID generates a random string, which is then returned to be used as a key id