Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
7c339ff4
Commit
7c339ff4
authored
Feb 07, 2019
by
Matthew Halpern
Committed by
Péter Szilágyi
Feb 07, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
light: make transaction pool receiver names consistent (#19000)
parent
4097ba6a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
39 additions
and
39 deletions
+39
-39
txpool.go
light/txpool.go
+39
-39
No files found.
light/txpool.go
View file @
7c339ff4
...
...
@@ -390,81 +390,81 @@ func (pool *TxPool) validateTx(ctx context.Context, tx *types.Transaction) error
// add validates a new transaction and sets its state pending if processable.
// It also updates the locally stored nonce if necessary.
func
(
self
*
TxPool
)
add
(
ctx
context
.
Context
,
tx
*
types
.
Transaction
)
error
{
func
(
pool
*
TxPool
)
add
(
ctx
context
.
Context
,
tx
*
types
.
Transaction
)
error
{
hash
:=
tx
.
Hash
()
if
self
.
pending
[
hash
]
!=
nil
{
if
pool
.
pending
[
hash
]
!=
nil
{
return
fmt
.
Errorf
(
"Known transaction (%x)"
,
hash
[
:
4
])
}
err
:=
self
.
validateTx
(
ctx
,
tx
)
err
:=
pool
.
validateTx
(
ctx
,
tx
)
if
err
!=
nil
{
return
err
}
if
_
,
ok
:=
self
.
pending
[
hash
];
!
ok
{
self
.
pending
[
hash
]
=
tx
if
_
,
ok
:=
pool
.
pending
[
hash
];
!
ok
{
pool
.
pending
[
hash
]
=
tx
nonce
:=
tx
.
Nonce
()
+
1
addr
,
_
:=
types
.
Sender
(
self
.
signer
,
tx
)
if
nonce
>
self
.
nonce
[
addr
]
{
self
.
nonce
[
addr
]
=
nonce
addr
,
_
:=
types
.
Sender
(
pool
.
signer
,
tx
)
if
nonce
>
pool
.
nonce
[
addr
]
{
pool
.
nonce
[
addr
]
=
nonce
}
// Notify the subscribers. This event is posted in a goroutine
// because it's possible that somewhere during the post "Remove transaction"
// gets called which will then wait for the global tx pool lock and deadlock.
go
self
.
txFeed
.
Send
(
core
.
NewTxsEvent
{
Txs
:
types
.
Transactions
{
tx
}})
go
pool
.
txFeed
.
Send
(
core
.
NewTxsEvent
{
Txs
:
types
.
Transactions
{
tx
}})
}
// Print a log message if low enough level is set
log
.
Debug
(
"Pooled new transaction"
,
"hash"
,
hash
,
"from"
,
log
.
Lazy
{
Fn
:
func
()
common
.
Address
{
from
,
_
:=
types
.
Sender
(
self
.
signer
,
tx
);
return
from
}},
"to"
,
tx
.
To
())
log
.
Debug
(
"Pooled new transaction"
,
"hash"
,
hash
,
"from"
,
log
.
Lazy
{
Fn
:
func
()
common
.
Address
{
from
,
_
:=
types
.
Sender
(
pool
.
signer
,
tx
);
return
from
}},
"to"
,
tx
.
To
())
return
nil
}
// Add adds a transaction to the pool if valid and passes it to the tx relay
// backend
func
(
self
*
TxPool
)
Add
(
ctx
context
.
Context
,
tx
*
types
.
Transaction
)
error
{
self
.
mu
.
Lock
()
defer
self
.
mu
.
Unlock
()
func
(
pool
*
TxPool
)
Add
(
ctx
context
.
Context
,
tx
*
types
.
Transaction
)
error
{
pool
.
mu
.
Lock
()
defer
pool
.
mu
.
Unlock
()
data
,
err
:=
rlp
.
EncodeToBytes
(
tx
)
if
err
!=
nil
{
return
err
}
if
err
:=
self
.
add
(
ctx
,
tx
);
err
!=
nil
{
if
err
:=
pool
.
add
(
ctx
,
tx
);
err
!=
nil
{
return
err
}
//fmt.Println("Send", tx.Hash())
self
.
relay
.
Send
(
types
.
Transactions
{
tx
})
pool
.
relay
.
Send
(
types
.
Transactions
{
tx
})
self
.
chainDb
.
Put
(
tx
.
Hash
()
.
Bytes
(),
data
)
pool
.
chainDb
.
Put
(
tx
.
Hash
()
.
Bytes
(),
data
)
return
nil
}
// AddTransactions adds all valid transactions to the pool and passes them to
// the tx relay backend
func
(
self
*
TxPool
)
AddBatch
(
ctx
context
.
Context
,
txs
[]
*
types
.
Transaction
)
{
self
.
mu
.
Lock
()
defer
self
.
mu
.
Unlock
()
func
(
pool
*
TxPool
)
AddBatch
(
ctx
context
.
Context
,
txs
[]
*
types
.
Transaction
)
{
pool
.
mu
.
Lock
()
defer
pool
.
mu
.
Unlock
()
var
sendTx
types
.
Transactions
for
_
,
tx
:=
range
txs
{
if
err
:=
self
.
add
(
ctx
,
tx
);
err
==
nil
{
if
err
:=
pool
.
add
(
ctx
,
tx
);
err
==
nil
{
sendTx
=
append
(
sendTx
,
tx
)
}
}
if
len
(
sendTx
)
>
0
{
self
.
relay
.
Send
(
sendTx
)
pool
.
relay
.
Send
(
sendTx
)
}
}
// GetTransaction returns a transaction if it is contained in the pool
// and nil otherwise.
func
(
tp
*
TxPool
)
GetTransaction
(
hash
common
.
Hash
)
*
types
.
Transaction
{
func
(
pool
*
TxPool
)
GetTransaction
(
hash
common
.
Hash
)
*
types
.
Transaction
{
// check the txs first
if
tx
,
ok
:=
tp
.
pending
[
hash
];
ok
{
if
tx
,
ok
:=
pool
.
pending
[
hash
];
ok
{
return
tx
}
return
nil
...
...
@@ -472,13 +472,13 @@ func (tp *TxPool) GetTransaction(hash common.Hash) *types.Transaction {
// GetTransactions returns all currently processable transactions.
// The returned slice may be modified by the caller.
func
(
self
*
TxPool
)
GetTransactions
()
(
txs
types
.
Transactions
,
err
error
)
{
self
.
mu
.
RLock
()
defer
self
.
mu
.
RUnlock
()
func
(
pool
*
TxPool
)
GetTransactions
()
(
txs
types
.
Transactions
,
err
error
)
{
pool
.
mu
.
RLock
()
defer
pool
.
mu
.
RUnlock
()
txs
=
make
(
types
.
Transactions
,
len
(
self
.
pending
))
txs
=
make
(
types
.
Transactions
,
len
(
pool
.
pending
))
i
:=
0
for
_
,
tx
:=
range
self
.
pending
{
for
_
,
tx
:=
range
pool
.
pending
{
txs
[
i
]
=
tx
i
++
}
...
...
@@ -487,14 +487,14 @@ func (self *TxPool) GetTransactions() (txs types.Transactions, err error) {
// Content retrieves the data content of the transaction pool, returning all the
// pending as well as queued transactions, grouped by account and nonce.
func
(
self
*
TxPool
)
Content
()
(
map
[
common
.
Address
]
types
.
Transactions
,
map
[
common
.
Address
]
types
.
Transactions
)
{
self
.
mu
.
RLock
()
defer
self
.
mu
.
RUnlock
()
func
(
pool
*
TxPool
)
Content
()
(
map
[
common
.
Address
]
types
.
Transactions
,
map
[
common
.
Address
]
types
.
Transactions
)
{
pool
.
mu
.
RLock
()
defer
pool
.
mu
.
RUnlock
()
// Retrieve all the pending transactions and sort by account and by nonce
pending
:=
make
(
map
[
common
.
Address
]
types
.
Transactions
)
for
_
,
tx
:=
range
self
.
pending
{
account
,
_
:=
types
.
Sender
(
self
.
signer
,
tx
)
for
_
,
tx
:=
range
pool
.
pending
{
account
,
_
:=
types
.
Sender
(
pool
.
signer
,
tx
)
pending
[
account
]
=
append
(
pending
[
account
],
tx
)
}
// There are no queued transactions in a light pool, just return an empty map
...
...
@@ -503,20 +503,20 @@ func (self *TxPool) Content() (map[common.Address]types.Transactions, map[common
}
// RemoveTransactions removes all given transactions from the pool.
func
(
self
*
TxPool
)
RemoveTransactions
(
txs
types
.
Transactions
)
{
self
.
mu
.
Lock
()
defer
self
.
mu
.
Unlock
()
func
(
pool
*
TxPool
)
RemoveTransactions
(
txs
types
.
Transactions
)
{
pool
.
mu
.
Lock
()
defer
pool
.
mu
.
Unlock
()
var
hashes
[]
common
.
Hash
batch
:=
self
.
chainDb
.
NewBatch
()
batch
:=
pool
.
chainDb
.
NewBatch
()
for
_
,
tx
:=
range
txs
{
hash
:=
tx
.
Hash
()
delete
(
self
.
pending
,
hash
)
delete
(
pool
.
pending
,
hash
)
batch
.
Delete
(
hash
.
Bytes
())
hashes
=
append
(
hashes
,
hash
)
}
batch
.
Write
()
self
.
relay
.
Discard
(
hashes
)
pool
.
relay
.
Discard
(
hashes
)
}
// RemoveTx removes the transaction with the given hash from the pool.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment