Merge remote-tracking branch 'upstream/master'

This commit is contained in:
Jim McDonald 2017-10-31 07:46:30 +00:00
commit 8c797574b7
9 changed files with 25 additions and 19 deletions

View file

@ -51,7 +51,7 @@ func main() {
var r io.Reader var r io.Reader
switch { switch {
case *hexMode != "": case *hexMode != "":
data, err := hex.DecodeString(*hexMode) data, err := hex.DecodeString(strings.TrimPrefix(*hexMode, "0x"))
if err != nil { if err != nil {
die(err) die(err)
} }

View file

@ -534,7 +534,10 @@ func (s *MatcherSession) Close() {
// Error returns any failure encountered during the matching session. // Error returns any failure encountered during the matching session.
func (s *MatcherSession) Error() error { func (s *MatcherSession) Error() error {
return s.err.Load().(error) if err := s.err.Load(); err != nil {
return err.(error)
}
return nil
} }
// AllocateRetrieval assigns a bloom bit index to a client process that can either // AllocateRetrieval assigns a bloom bit index to a client process that can either

View file

@ -68,7 +68,7 @@ func (journal *txJournal) load(add func(*types.Transaction) error) error {
} }
defer input.Close() defer input.Close()
// Temporarilly discard any journal additions (don't double add on load) // Temporarily discard any journal additions (don't double add on load)
journal.writer = new(devNull) journal.writer = new(devNull)
defer func() { journal.writer = nil }() defer func() { journal.writer = nil }()

View file

@ -254,7 +254,10 @@ func (l *txList) Add(tx *types.Transaction, priceBump uint64) (bool, *types.Tran
old := l.txs.Get(tx.Nonce()) old := l.txs.Get(tx.Nonce())
if old != nil { if old != nil {
threshold := new(big.Int).Div(new(big.Int).Mul(old.GasPrice(), big.NewInt(100+int64(priceBump))), big.NewInt(100)) threshold := new(big.Int).Div(new(big.Int).Mul(old.GasPrice(), big.NewInt(100+int64(priceBump))), big.NewInt(100))
if threshold.Cmp(tx.GasPrice()) >= 0 { // Have to ensure that the new gas price is higher than the old gas
// price as well as checking the percentage threshold to ensure that
// this is accurate for low (Wei-level) gas price replacements
if old.GasPrice().Cmp(tx.GasPrice()) >= 0 || threshold.Cmp(tx.GasPrice()) > 0 {
return false, nil return false, nil
} }
} }

View file

@ -1411,10 +1411,10 @@ func TestTransactionReplacement(t *testing.T) {
if err := pool.AddRemote(pricedTransaction(0, big.NewInt(100000), big.NewInt(price), key)); err != nil { if err := pool.AddRemote(pricedTransaction(0, big.NewInt(100000), big.NewInt(price), key)); err != nil {
t.Fatalf("failed to add original proper pending transaction: %v", err) t.Fatalf("failed to add original proper pending transaction: %v", err)
} }
if err := pool.AddRemote(pricedTransaction(0, big.NewInt(100000), big.NewInt(threshold), key)); err != ErrReplaceUnderpriced { if err := pool.AddRemote(pricedTransaction(0, big.NewInt(100001), big.NewInt(threshold-1), key)); err != ErrReplaceUnderpriced {
t.Fatalf("original proper pending transaction replacement error mismatch: have %v, want %v", err, ErrReplaceUnderpriced) t.Fatalf("original proper pending transaction replacement error mismatch: have %v, want %v", err, ErrReplaceUnderpriced)
} }
if err := pool.AddRemote(pricedTransaction(0, big.NewInt(100000), big.NewInt(threshold+1), key)); err != nil { if err := pool.AddRemote(pricedTransaction(0, big.NewInt(100000), big.NewInt(threshold), key)); err != nil {
t.Fatalf("failed to replace original proper pending transaction: %v", err) t.Fatalf("failed to replace original proper pending transaction: %v", err)
} }
if err := validateEvents(events, 2); err != nil { if err := validateEvents(events, 2); err != nil {
@ -1422,23 +1422,23 @@ func TestTransactionReplacement(t *testing.T) {
} }
// Add queued transactions, ensuring the minimum price bump is enforced for replacement (for ultra low prices too) // Add queued transactions, ensuring the minimum price bump is enforced for replacement (for ultra low prices too)
if err := pool.AddRemote(pricedTransaction(2, big.NewInt(100000), big.NewInt(1), key)); err != nil { if err := pool.AddRemote(pricedTransaction(2, big.NewInt(100000), big.NewInt(1), key)); err != nil {
t.Fatalf("failed to add original queued transaction: %v", err) t.Fatalf("failed to add original cheap queued transaction: %v", err)
} }
if err := pool.AddRemote(pricedTransaction(2, big.NewInt(100001), big.NewInt(1), key)); err != ErrReplaceUnderpriced { if err := pool.AddRemote(pricedTransaction(2, big.NewInt(100001), big.NewInt(1), key)); err != ErrReplaceUnderpriced {
t.Fatalf("original queued transaction replacement error mismatch: have %v, want %v", err, ErrReplaceUnderpriced) t.Fatalf("original cheap queued transaction replacement error mismatch: have %v, want %v", err, ErrReplaceUnderpriced)
} }
if err := pool.AddRemote(pricedTransaction(2, big.NewInt(100000), big.NewInt(2), key)); err != nil { if err := pool.AddRemote(pricedTransaction(2, big.NewInt(100000), big.NewInt(2), key)); err != nil {
t.Fatalf("failed to replace original queued transaction: %v", err) t.Fatalf("failed to replace original cheap queued transaction: %v", err)
} }
if err := pool.AddRemote(pricedTransaction(2, big.NewInt(100000), big.NewInt(price), key)); err != nil { if err := pool.AddRemote(pricedTransaction(2, big.NewInt(100000), big.NewInt(price), key)); err != nil {
t.Fatalf("failed to add original queued transaction: %v", err) t.Fatalf("failed to add original proper queued transaction: %v", err)
} }
if err := pool.AddRemote(pricedTransaction(2, big.NewInt(100001), big.NewInt(threshold), key)); err != ErrReplaceUnderpriced { if err := pool.AddRemote(pricedTransaction(2, big.NewInt(100001), big.NewInt(threshold-1), key)); err != ErrReplaceUnderpriced {
t.Fatalf("original queued transaction replacement error mismatch: have %v, want %v", err, ErrReplaceUnderpriced) t.Fatalf("original proper queued transaction replacement error mismatch: have %v, want %v", err, ErrReplaceUnderpriced)
} }
if err := pool.AddRemote(pricedTransaction(2, big.NewInt(100000), big.NewInt(threshold+1), key)); err != nil { if err := pool.AddRemote(pricedTransaction(2, big.NewInt(100000), big.NewInt(threshold), key)); err != nil {
t.Fatalf("failed to replace original queued transaction: %v", err) t.Fatalf("failed to replace original proper queued transaction: %v", err)
} }
if err := validateEvents(events, 0); err != nil { if err := validateEvents(events, 0); err != nil {

View file

@ -145,7 +145,7 @@ func lesTopic(genesisHash common.Hash, protocolVersion uint) discv5.Topic {
default: default:
panic(nil) panic(nil)
} }
return discv5.Topic(name + common.Bytes2Hex(genesisHash.Bytes()[0:8])) return discv5.Topic(name + "@" + common.Bytes2Hex(genesisHash.Bytes()[0:8]))
} }
type LightDummyAPI struct{} type LightDummyAPI struct{}

View file

@ -72,7 +72,7 @@ func initErrHandling() {
//ShowMultipeChoices is used when a user requests a resource in a manifest which results //ShowMultipeChoices is used when a user requests a resource in a manifest which results
//in ambiguous results. It returns a HTML page with clickable links of each of the entry //in ambiguous results. It returns a HTML page with clickable links of each of the entry
//in the manifest which fits the request URI ambiguity. //in the manifest which fits the request URI ambiguity.
//For example, if the user requests bzz:/<hash>/read and that manifest containes entries //For example, if the user requests bzz:/<hash>/read and that manifest contains entries
//"readme.md" and "readinglist.txt", a HTML page is returned with this two links. //"readme.md" and "readinglist.txt", a HTML page is returned with this two links.
//This only applies if the manifest has no default entry //This only applies if the manifest has no default entry
func ShowMultipleChoices(w http.ResponseWriter, r *http.Request, list api.ManifestList) { func ShowMultipleChoices(w http.ResponseWriter, r *http.Request, list api.ManifestList) {

View file

@ -132,7 +132,7 @@ func TestJsonResponse(t *testing.T) {
} }
if !isJSON(string(respbody)) { if !isJSON(string(respbody)) {
t.Fatalf("Expected repsonse to be JSON, received invalid JSON: %s", string(respbody)) t.Fatalf("Expected response to be JSON, received invalid JSON: %s", string(respbody))
} }
} }

View file

@ -27,7 +27,7 @@ import (
/* /*
The main idea of a pyramid chunker is to process the input data without knowing the entire size apriori. The main idea of a pyramid chunker is to process the input data without knowing the entire size apriori.
For this to be achieved, the chunker tree is built from the ground up until the data is exhausted. For this to be achieved, the chunker tree is built from the ground up until the data is exhausted.
This opens up new aveneus such as easy append and other sort of modifications to the tree therby avoiding This opens up new aveneus such as easy append and other sort of modifications to the tree thereby avoiding
duplication of data chunks. duplication of data chunks.
@ -451,7 +451,7 @@ func (self *PyramidChunker) prepareChunks(isAppend bool, chunkLevel [][]*TreeEnt
} }
} }
// Data ended in chunk boundry.. just signal to start bulding tree // Data ended in chunk boundary.. just signal to start bulding tree
if n == 0 { if n == 0 {
self.buildTree(isAppend, chunkLevel, parent, chunkWG, jobC, quitC, true, rootKey) self.buildTree(isAppend, chunkLevel, parent, chunkWG, jobC, quitC, true, rootKey)
break break