Skip to content
This repository has been archived by the owner on Aug 2, 2021. It is now read-only.

swarm-network-rewrite conflicts with master #589

Merged
merged 80 commits into from
May 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
80 commits
Select commit Hold shift + click to select a range
86be91b
core/types: avoid duplicating transactions on changing signer (#16435)
countvonzero Apr 24, 2018
b724d1a
core/state: cache missing storage entries (#16584)
fjl Apr 27, 2018
852aa14
cmd/utils: point users to --syncmode under DEPRECATED (#16572)
martinklepsch Apr 27, 2018
cfe8f5f
trie: remove unused `buf` parameter (#16583)
xincaosu Apr 27, 2018
7a7428a
core, eth: fix tracer dirty finalization
karalabe Apr 27, 2018
1da3302
Merge pull request #16588 from karalabe/tracer-dirty-fix
karalabe Apr 27, 2018
ea171d5
travis.yml: remove obsolete brew-cask install
reductionista May 1, 2018
9f6af6f
whisper: Golint fixes in whisper packages (#16637)
roveneliah May 2, 2018
a1949d0
vendor: fix leveldb crash when bigger than 1 TiB
May 1, 2018
9922943
Merge pull request #16636 from reductionista/travis
karalabe May 2, 2018
448d17b
Merge pull request #16630 from tstranex/master
karalabe May 2, 2018
0afd767
core: ensure local transactions aren't discarded as underpriced
Apr 26, 2018
8dfa4f4
evm/main: use blocknumber from genesis
holiman Apr 26, 2018
c1ea527
accounts: golint updates for this or self warning (#16627)
kielbarry May 2, 2018
d76c5ca
tests: golint fixes for tests directory (#16640)
roveneliah May 2, 2018
4a8d5d2
trie: golint iterator fixes (#16639)
roveneliah May 2, 2018
670bae4
internal: golint updates for this or self warning (#16634)
kielbarry May 2, 2018
a7720b5
core: golint updates for this or self warning (#16633)
kielbarry May 2, 2018
579ac62
Merge pull request #16576 from CrispinFlowerday/bugfix/local_underpri…
karalabe May 2, 2018
5449139
Merge pull request #16569 from holiman/evm_blocknum
karalabe May 2, 2018
58c4e03
build: Add ldflags -s -w when building aar
ligi May 2, 2018
6a01363
Merge pull request #16644 from ligi/reduce_aar_size
karalabe May 2, 2018
5d4d79a
cmd/clef: documentation about setup (#16568)
holiman May 2, 2018
66432f3
params: release geth 1.8.7
karalabe May 2, 2018
577d375
VERSION, params: begin v1.8.8 release cycle
karalabe May 2, 2018
ea1724d
log: changed if-else blocks to conform with golint (#16661)
GagziW May 3, 2018
f2447bd
p2p: changed if-else blocks to conform with golint (#16660)
GagziW May 3, 2018
7c02933
les: changed if-else blocks to conform with golint (#16658)
GagziW May 3, 2018
541f299
accounts: changed if-else blocks to conform with golint (#16654)
GagziW May 3, 2018
2ad511c
rpc: golint error with context as last parameter (#16657)
kielbarry May 3, 2018
cd9a1d5
metrics: golint updates for this or self warning (#16635)
kielbarry May 3, 2018
fd3da7c
consensus/ethash: fixed typo (#16665)
YH-Zhou May 3, 2018
60b433a
event: golint updates for this or self warning (#16631)
kielbarry May 3, 2018
5b3af4c
eth: golint updates for this or self warning (#16632)
kielbarry May 3, 2018
16f3c31
signer: fix golint errors (#16653)
roveneliah May 4, 2018
d2fe83d
whisper/mailserver: pass init error to the caller (#16671)
divan May 4, 2018
d7be5c6
common: changed if-else blocks to conform with golint (#16656)
GagziW May 7, 2018
5463ed9
mobile: add GetStatus Method for Receipt (#16598)
erichin May 7, 2018
6cf0ab3
core/rawdb: separate raw database access to own package (#16666)
karalabe May 7, 2018
a42be3b
rlp: fix some golint warnings (#16659)
kielbarry May 8, 2018
864e80a
p2p: fix some golint warnings (#16577)
kielbarry May 8, 2018
fedae95
eth/filters: derive FilterCriteria from ethereum.FilterQuery (#16629)
reductionista May 8, 2018
c4a4613
p2p/simulations/adapters: fix websocket log line parsing in exec adap…
divan May 8, 2018
eab6e5a
build: specify the key to use when invoking gpg:sign-and-deploy-file …
ligi May 8, 2018
ba975dc
crypto: fix golint warnings (#16710)
kielbarry May 8, 2018
c60f6f6
p2p: don't discard reason set by Disconnect (#16559)
gsalgado May 8, 2018
4ea493e
cmd: various golint fixes (#16700)
kielbarry May 9, 2018
4747aad
eth: golint fixes to variable names (#16711)
kielbarry May 9, 2018
4e7dc34
eth/filter: check nil pointer when unsubscribe (#16682)
rjl493456442 May 9, 2018
5dbd8b4
whisper/shhclient: update call to shh_generateSymKeyFromPassword to p…
gravityblast May 9, 2018
7beccb2
all: get rid of error when creating memory database (#16716)
rjl493456442 May 9, 2018
53a18d2
event: document select case slice use and add edge case test (#16680)
fjl May 10, 2018
fcc18f4
travis: use Android NDK 16b (#16562)
ligi May 10, 2018
784aa83
bmt: golint updates for this or self warning (#16628)
kielbarry May 10, 2018
595b47e
light: new CHT for mainnet and ropsten (#16736)
zsfelfoldi May 14, 2018
2688dab
params: release go-ethereum v1.8.8
karalabe May 14, 2018
49ec4f0
VERSION, params: start 1.8.9 release cycle
karalabe May 14, 2018
247b5f0
accounts/abi: allow abi: tags when unpacking structs
gballet May 14, 2018
ff8a033
travis: try to upgrade android builder to trusty
karalabe May 14, 2018
f6bc65f
Merge pull request #16739 from karalabe/android-trusty
karalabe May 14, 2018
6286c25
p2p/enr: updates for discovery v4 compatibility (#16679)
fjl May 17, 2018
a2e43d2
all: collate new transaction events together
rjl493456442 May 10, 2018
49719e2
core, eth: minor txpool event cleanups
karalabe May 18, 2018
579bd0f
travis, appveyor: bump Go release to 1.10.2
karalabe May 18, 2018
f9c456e
Merge pull request #16753 from karalabe/go-1.10.2
karalabe May 18, 2018
f2fdb75
core, consensus: fix some typos in comment code and output log
hadv May 19, 2018
953b5ac
Merge pull request #16720 from rjl493456442/PreTxsEvent
karalabe May 19, 2018
ab6bdbd
Merge pull request #16758 from hadv/fix/typos
karalabe May 19, 2018
d9cee2c
eth: propagate blocks and transactions async
karalabe May 21, 2018
415969f
Merge pull request #16769 from karalabe/async-broadcasts
karalabe May 21, 2018
0fe47e9
trie: fixes to comply with golint (#16771)
kielbarry May 21, 2018
09d4424
log: fixes for golint warnings (#16775)
kielbarry May 22, 2018
9af364e
node: all golint warnings fixed (#16773)
kielbarry May 22, 2018
6ce21a4
vendor, ethdb: print warning log if leveldb is performing compaction …
rjl493456442 May 22, 2018
fbf57d5
core/types: convert status type from uint to uint64 (#16784)
rjl493456442 May 23, 2018
c934c06
trie: support proof generation from the iterator
karalabe May 10, 2018
56de337
Merge pull request #16722 from karalabe/trie-iterator-proofs
karalabe May 23, 2018
be22ee8
core/vm: fix typo in instructions.go (#16788)
abeln May 23, 2018
55b579e
core: use a wrapped map to remove contention in `TxPool.Get`. (#16670)
ryanschneider May 23, 2018
0752dc6
swarm: resolve merge conflicts
nonsense May 24, 2018
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
21 changes: 11 additions & 10 deletions core/tx_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,13 +397,13 @@ func (h *priceHeap) Pop() interface{} {
// txPricedList is a price-sorted heap to allow operating on transactions pool
// contents in a price-incrementing way.
type txPricedList struct {
all *map[common.Hash]*types.Transaction // Pointer to the map of all transactions
items *priceHeap // Heap of prices of all the stored transactions
stales int // Number of stale price points to (re-heap trigger)
all *txLookup // Pointer to the map of all transactions
items *priceHeap // Heap of prices of all the stored transactions
stales int // Number of stale price points to (re-heap trigger)
}

// newTxPricedList creates a new price-sorted transaction heap.
func newTxPricedList(all *map[common.Hash]*types.Transaction) *txPricedList {
func newTxPricedList(all *txLookup) *txPricedList {
return &txPricedList{
all: all,
items: new(priceHeap),
Expand All @@ -425,12 +425,13 @@ func (l *txPricedList) Removed() {
return
}
// Seems we've reached a critical number of stale transactions, reheap
reheap := make(priceHeap, 0, len(*l.all))
reheap := make(priceHeap, 0, l.all.Count())

l.stales, l.items = 0, &reheap
for _, tx := range *l.all {
l.all.Range(func(hash common.Hash, tx *types.Transaction) bool {
*l.items = append(*l.items, tx)
}
return true
})
heap.Init(l.items)
}

Expand All @@ -443,7 +444,7 @@ func (l *txPricedList) Cap(threshold *big.Int, local *accountSet) types.Transact
for len(*l.items) > 0 {
// Discard stale transactions if found during cleanup
tx := heap.Pop(l.items).(*types.Transaction)
if _, ok := (*l.all)[tx.Hash()]; !ok {
if l.all.Get(tx.Hash()) == nil {
l.stales--
continue
}
Expand Down Expand Up @@ -475,7 +476,7 @@ func (l *txPricedList) Underpriced(tx *types.Transaction, local *accountSet) boo
// Discard stale price points if found at the heap start
for len(*l.items) > 0 {
head := []*types.Transaction(*l.items)[0]
if _, ok := (*l.all)[head.Hash()]; !ok {
if l.all.Get(head.Hash()) == nil {
l.stales--
heap.Pop(l.items)
continue
Expand All @@ -500,7 +501,7 @@ func (l *txPricedList) Discard(count int, local *accountSet) types.Transactions
for len(*l.items) > 0 && count > 0 {
// Discard stale transactions if found during cleanup
tx := heap.Pop(l.items).(*types.Transaction)
if _, ok := (*l.all)[tx.Hash()]; !ok {
if l.all.Get(tx.Hash()) == nil {
l.stales--
continue
}
Expand Down
130 changes: 96 additions & 34 deletions core/tx_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,11 @@ type TxPool struct {
locals *accountSet // Set of local transaction to exempt from eviction rules
journal *txJournal // Journal of local transaction to back up to disk

pending map[common.Address]*txList // All currently processable transactions
queue map[common.Address]*txList // Queued but non-processable transactions
beats map[common.Address]time.Time // Last heartbeat from each known account
all map[common.Hash]*types.Transaction // All transactions to allow lookups
priced *txPricedList // All transactions sorted by price
pending map[common.Address]*txList // All currently processable transactions
queue map[common.Address]*txList // Queued but non-processable transactions
beats map[common.Address]time.Time // Last heartbeat from each known account
all *txLookup // All transactions to allow lookups
priced *txPricedList // All transactions sorted by price

wg sync.WaitGroup // for shutdown sync

Expand All @@ -226,12 +226,12 @@ func NewTxPool(config TxPoolConfig, chainconfig *params.ChainConfig, chain block
pending: make(map[common.Address]*txList),
queue: make(map[common.Address]*txList),
beats: make(map[common.Address]time.Time),
all: make(map[common.Hash]*types.Transaction),
all: newTxLookup(),
chainHeadCh: make(chan ChainHeadEvent, chainHeadChanSize),
gasPrice: new(big.Int).SetUint64(config.PriceLimit),
}
pool.locals = newAccountSet(pool.signer)
pool.priced = newTxPricedList(&pool.all)
pool.priced = newTxPricedList(pool.all)
pool.reset(nil, chain.CurrentBlock().Header())

// If local transactions and journaling is enabled, load from disk
Expand Down Expand Up @@ -605,7 +605,7 @@ func (pool *TxPool) validateTx(tx *types.Transaction, local bool) error {
func (pool *TxPool) add(tx *types.Transaction, local bool) (bool, error) {
// If the transaction is already known, discard it
hash := tx.Hash()
if pool.all[hash] != nil {
if pool.all.Get(hash) != nil {
log.Trace("Discarding already known transaction", "hash", hash)
return false, fmt.Errorf("known transaction: %x", hash)
}
Expand All @@ -616,15 +616,15 @@ func (pool *TxPool) add(tx *types.Transaction, local bool) (bool, error) {
return false, err
}
// If the transaction pool is full, discard underpriced transactions
if uint64(len(pool.all)) >= pool.config.GlobalSlots+pool.config.GlobalQueue {
if uint64(pool.all.Count()) >= pool.config.GlobalSlots+pool.config.GlobalQueue {
// If the new transaction is underpriced, don't accept it
if !local && pool.priced.Underpriced(tx, pool.locals) {
log.Trace("Discarding underpriced transaction", "hash", hash, "price", tx.GasPrice())
underpricedTxCounter.Inc(1)
return false, ErrUnderpriced
}
// New transaction is better than our worse ones, make room for it
drop := pool.priced.Discard(len(pool.all)-int(pool.config.GlobalSlots+pool.config.GlobalQueue-1), pool.locals)
drop := pool.priced.Discard(pool.all.Count()-int(pool.config.GlobalSlots+pool.config.GlobalQueue-1), pool.locals)
for _, tx := range drop {
log.Trace("Discarding freshly underpriced transaction", "hash", tx.Hash(), "price", tx.GasPrice())
underpricedTxCounter.Inc(1)
Expand All @@ -642,11 +642,11 @@ func (pool *TxPool) add(tx *types.Transaction, local bool) (bool, error) {
}
// New transaction is better, replace old one
if old != nil {
delete(pool.all, old.Hash())
pool.all.Remove(old.Hash())
pool.priced.Removed()
pendingReplaceCounter.Inc(1)
}
pool.all[tx.Hash()] = tx
pool.all.Add(tx)
pool.priced.Put(tx)
pool.journalTx(from, tx)

Expand Down Expand Up @@ -689,12 +689,12 @@ func (pool *TxPool) enqueueTx(hash common.Hash, tx *types.Transaction) (bool, er
}
// Discard any previous transaction and mark this
if old != nil {
delete(pool.all, old.Hash())
pool.all.Remove(old.Hash())
pool.priced.Removed()
queuedReplaceCounter.Inc(1)
}
if pool.all[hash] == nil {
pool.all[hash] = tx
if pool.all.Get(hash) == nil {
pool.all.Add(tx)
pool.priced.Put(tx)
}
return old != nil, nil
Expand Down Expand Up @@ -726,22 +726,22 @@ func (pool *TxPool) promoteTx(addr common.Address, hash common.Hash, tx *types.T
inserted, old := list.Add(tx, pool.config.PriceBump)
if !inserted {
// An older transaction was better, discard this
delete(pool.all, hash)
pool.all.Remove(hash)
pool.priced.Removed()

pendingDiscardCounter.Inc(1)
return false
}
// Otherwise discard any previous transaction and mark this
if old != nil {
delete(pool.all, old.Hash())
pool.all.Remove(old.Hash())
pool.priced.Removed()

pendingReplaceCounter.Inc(1)
}
// Failsafe to work around direct pending inserts (tests)
if pool.all[hash] == nil {
pool.all[hash] = tx
if pool.all.Get(hash) == nil {
pool.all.Add(tx)
pool.priced.Put(tx)
}
// Set the potentially new pending nonce and notify any subsystems of the new tx
Expand Down Expand Up @@ -840,7 +840,7 @@ func (pool *TxPool) Status(hashes []common.Hash) []TxStatus {

status := make([]TxStatus, len(hashes))
for i, hash := range hashes {
if tx := pool.all[hash]; tx != nil {
if tx := pool.all.Get(hash); tx != nil {
from, _ := types.Sender(pool.signer, tx) // already validated
if pool.pending[from] != nil && pool.pending[from].txs.items[tx.Nonce()] != nil {
status[i] = TxStatusPending
Expand All @@ -855,24 +855,21 @@ func (pool *TxPool) Status(hashes []common.Hash) []TxStatus {
// Get returns a transaction if it is contained in the pool
// and nil otherwise.
func (pool *TxPool) Get(hash common.Hash) *types.Transaction {
pool.mu.RLock()
defer pool.mu.RUnlock()

return pool.all[hash]
return pool.all.Get(hash)
}

// removeTx removes a single transaction from the queue, moving all subsequent
// transactions back to the future queue.
func (pool *TxPool) removeTx(hash common.Hash, outofbound bool) {
// Fetch the transaction we wish to delete
tx, ok := pool.all[hash]
if !ok {
tx := pool.all.Get(hash)
if tx == nil {
return
}
addr, _ := types.Sender(pool.signer, tx) // already validated during insertion

// Remove it from the list of known transactions
delete(pool.all, hash)
pool.all.Remove(hash)
if outofbound {
pool.priced.Removed()
}
Expand Down Expand Up @@ -928,15 +925,15 @@ func (pool *TxPool) promoteExecutables(accounts []common.Address) {
for _, tx := range list.Forward(pool.currentState.GetNonce(addr)) {
hash := tx.Hash()
log.Trace("Removed old queued transaction", "hash", hash)
delete(pool.all, hash)
pool.all.Remove(hash)
pool.priced.Removed()
}
// Drop all transactions that are too costly (low balance or out of gas)
drops, _ := list.Filter(pool.currentState.GetBalance(addr), pool.currentMaxGas)
for _, tx := range drops {
hash := tx.Hash()
log.Trace("Removed unpayable queued transaction", "hash", hash)
delete(pool.all, hash)
pool.all.Remove(hash)
pool.priced.Removed()
queuedNofundsCounter.Inc(1)
}
Expand All @@ -952,7 +949,7 @@ func (pool *TxPool) promoteExecutables(accounts []common.Address) {
if !pool.locals.contains(addr) {
for _, tx := range list.Cap(int(pool.config.AccountQueue)) {
hash := tx.Hash()
delete(pool.all, hash)
pool.all.Remove(hash)
pool.priced.Removed()
queuedRateLimitCounter.Inc(1)
log.Trace("Removed cap-exceeding queued transaction", "hash", hash)
Expand Down Expand Up @@ -1001,7 +998,7 @@ func (pool *TxPool) promoteExecutables(accounts []common.Address) {
for _, tx := range list.Cap(list.Len() - 1) {
// Drop the transaction from the global pools too
hash := tx.Hash()
delete(pool.all, hash)
pool.all.Remove(hash)
pool.priced.Removed()

// Update the account nonce to the dropped transaction
Expand All @@ -1023,7 +1020,7 @@ func (pool *TxPool) promoteExecutables(accounts []common.Address) {
for _, tx := range list.Cap(list.Len() - 1) {
// Drop the transaction from the global pools too
hash := tx.Hash()
delete(pool.all, hash)
pool.all.Remove(hash)
pool.priced.Removed()

// Update the account nonce to the dropped transaction
Expand Down Expand Up @@ -1092,15 +1089,15 @@ func (pool *TxPool) demoteUnexecutables() {
for _, tx := range list.Forward(nonce) {
hash := tx.Hash()
log.Trace("Removed old pending transaction", "hash", hash)
delete(pool.all, hash)
pool.all.Remove(hash)
pool.priced.Removed()
}
// Drop all transactions that are too costly (low balance or out of gas), and queue any invalids back for later
drops, invalids := list.Filter(pool.currentState.GetBalance(addr), pool.currentMaxGas)
for _, tx := range drops {
hash := tx.Hash()
log.Trace("Removed unpayable pending transaction", "hash", hash)
delete(pool.all, hash)
pool.all.Remove(hash)
pool.priced.Removed()
pendingNofundsCounter.Inc(1)
}
Expand Down Expand Up @@ -1172,3 +1169,68 @@ func (as *accountSet) containsTx(tx *types.Transaction) bool {
func (as *accountSet) add(addr common.Address) {
as.accounts[addr] = struct{}{}
}

// txLookup is used internally by TxPool to track transactions while allowing lookup without
// mutex contention.
//
// Note, although this type is properly protected against concurrent access, it
// is **not** a type that should ever be mutated or even exposed outside of the
// transaction pool, since its internal state is tightly coupled with the pools
// internal mechanisms. The sole purpose of the type is to permit out-of-bound
// peeking into the pool in TxPool.Get without having to acquire the widely scoped
// TxPool.mu mutex.
type txLookup struct {
all map[common.Hash]*types.Transaction
lock sync.RWMutex
}

// newTxLookup returns a new txLookup structure.
func newTxLookup() *txLookup {
return &txLookup{
all: make(map[common.Hash]*types.Transaction),
}
}

// Range calls f on each key and value present in the map.
func (t *txLookup) Range(f func(hash common.Hash, tx *types.Transaction) bool) {
t.lock.RLock()
defer t.lock.RUnlock()

for key, value := range t.all {
if !f(key, value) {
break
}
}
}

// Get returns a transaction if it exists in the lookup, or nil if not found.
func (t *txLookup) Get(hash common.Hash) *types.Transaction {
t.lock.RLock()
defer t.lock.RUnlock()

return t.all[hash]
}

// Count returns the current number of items in the lookup.
func (t *txLookup) Count() int {
t.lock.RLock()
defer t.lock.RUnlock()

return len(t.all)
}

// Add adds a transaction to the lookup.
func (t *txLookup) Add(tx *types.Transaction) {
t.lock.Lock()
defer t.lock.Unlock()

t.all[tx.Hash()] = tx
}

// Remove removes a transaction from the lookup.
func (t *txLookup) Remove(hash common.Hash) {
t.lock.Lock()
defer t.lock.Unlock()

delete(t.all, hash)
}
Loading