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
48ee7f9d
Unverified
Commit
48ee7f9d
authored
Jul 05, 2017
by
Péter Szilágyi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
core, eth, les: polish txpool API around local/remote txs
parent
a633a2d7
Changes
9
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
153 additions
and
149 deletions
+153
-149
tx_list.go
core/tx_list.go
+6
-10
tx_pool.go
core/tx_pool.go
+86
-71
tx_pool_test.go
core/tx_pool_test.go
+51
-57
api_backend.go
eth/api_backend.go
+1
-2
handler.go
eth/handler.go
+1
-1
helper_test.go
eth/helper_test.go
+2
-2
protocol.go
eth/protocol.go
+2
-2
protocol_test.go
eth/protocol_test.go
+1
-1
handler.go
les/handler.go
+3
-3
No files found.
core/tx_list.go
View file @
48ee7f9d
...
...
@@ -420,7 +420,7 @@ func (l *txPricedList) Removed() {
heap
.
Init
(
l
.
items
)
}
//
Discard
finds all the transactions below the given price threshold, drops them
//
Cap
finds all the transactions below the given price threshold, drops them
// from the priced list and returs them for further removal from the entire pool.
func
(
l
*
txPricedList
)
Cap
(
threshold
*
big
.
Int
,
local
*
accountSet
)
types
.
Transactions
{
drop
:=
make
(
types
.
Transactions
,
0
,
128
)
// Remote underpriced transactions to drop
...
...
@@ -429,9 +429,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
)
hash
:=
tx
.
Hash
()
if
_
,
ok
:=
(
*
l
.
all
)[
hash
];
!
ok
{
if
_
,
ok
:=
(
*
l
.
all
)[
tx
.
Hash
()];
!
ok
{
l
.
stales
--
continue
}
...
...
@@ -440,7 +438,7 @@ func (l *txPricedList) Cap(threshold *big.Int, local *accountSet) types.Transact
break
}
// Non stale transaction found, discard unless local
if
local
.
contains
(
tx
)
{
if
local
.
contains
Tx
(
tx
)
{
save
=
append
(
save
,
tx
)
}
else
{
drop
=
append
(
drop
,
tx
)
...
...
@@ -456,7 +454,7 @@ func (l *txPricedList) Cap(threshold *big.Int, local *accountSet) types.Transact
// lowest priced transaction currently being tracked.
func
(
l
*
txPricedList
)
Underpriced
(
tx
*
types
.
Transaction
,
local
*
accountSet
)
bool
{
// Local transactions cannot be underpriced
if
local
.
contains
(
tx
)
{
if
local
.
contains
Tx
(
tx
)
{
return
false
}
// Discard stale price points if found at the heap start
...
...
@@ -487,14 +485,12 @@ 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
)
hash
:=
tx
.
Hash
()
if
_
,
ok
:=
(
*
l
.
all
)[
hash
];
!
ok
{
if
_
,
ok
:=
(
*
l
.
all
)[
tx
.
Hash
()];
!
ok
{
l
.
stales
--
continue
}
// Non stale transaction found, discard unless local
if
local
.
contains
(
tx
)
{
if
local
.
contains
Tx
(
tx
)
{
save
=
append
(
save
,
tx
)
}
else
{
drop
=
append
(
drop
,
tx
)
...
...
core/tx_pool.go
View file @
48ee7f9d
This diff is collapsed.
Click to expand it.
core/tx_pool_test.go
View file @
48ee7f9d
This diff is collapsed.
Click to expand it.
eth/api_backend.go
View file @
48ee7f9d
...
...
@@ -119,8 +119,7 @@ func (b *EthApiBackend) SendTx(ctx context.Context, signedTx *types.Transaction)
b
.
eth
.
txMu
.
Lock
()
defer
b
.
eth
.
txMu
.
Unlock
()
b
.
eth
.
txPool
.
SetLocal
(
signedTx
)
return
b
.
eth
.
txPool
.
Add
(
signedTx
)
return
b
.
eth
.
txPool
.
AddLocal
(
signedTx
)
}
func
(
b
*
EthApiBackend
)
RemoveTx
(
txHash
common
.
Hash
)
{
...
...
eth/handler.go
View file @
48ee7f9d
...
...
@@ -661,7 +661,7 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
}
p
.
MarkTransaction
(
tx
.
Hash
())
}
pm
.
txpool
.
Add
Batch
(
txs
)
pm
.
txpool
.
Add
Remotes
(
txs
)
default
:
return
errResp
(
ErrInvalidMsgCode
,
"%v"
,
msg
.
Code
)
...
...
eth/helper_test.go
View file @
48ee7f9d
...
...
@@ -94,9 +94,9 @@ type testTxPool struct {
lock
sync
.
RWMutex
// Protects the transaction pool
}
// Add
Batch
appends a batch of transactions to the pool, and notifies any
// Add
Remotes
appends a batch of transactions to the pool, and notifies any
// listeners if the addition channel is non nil
func
(
p
*
testTxPool
)
Add
Batch
(
txs
[]
*
types
.
Transaction
)
error
{
func
(
p
*
testTxPool
)
Add
Remotes
(
txs
[]
*
types
.
Transaction
)
error
{
p
.
lock
.
Lock
()
defer
p
.
lock
.
Unlock
()
...
...
eth/protocol.go
View file @
48ee7f9d
...
...
@@ -94,8 +94,8 @@ var errorToString = map[int]string{
}
type
txPool
interface
{
// Add
Batch
should add the given transactions to the pool.
Add
Batch
([]
*
types
.
Transaction
)
error
// Add
Remotes
should add the given transactions to the pool.
Add
Remotes
([]
*
types
.
Transaction
)
error
// Pending should return pending transactions.
// The slice should be modifiable by the caller.
...
...
eth/protocol_test.go
View file @
48ee7f9d
...
...
@@ -130,7 +130,7 @@ func testSendTransactions(t *testing.T, protocol int) {
for
nonce
:=
range
alltxs
{
alltxs
[
nonce
]
=
newTestTransaction
(
testAccount
,
uint64
(
nonce
),
txsize
)
}
pm
.
txpool
.
Add
Batch
(
alltxs
)
pm
.
txpool
.
Add
Remotes
(
alltxs
)
// Connect several peers. They should all receive the pending transactions.
var
wg
sync
.
WaitGroup
...
...
les/handler.go
View file @
48ee7f9d
...
...
@@ -87,8 +87,8 @@ type BlockChain interface {
}
type
txPool
interface
{
// Add
Transaction
s should add the given transactions to the pool.
Add
Batch
([]
*
types
.
Transaction
)
error
// Add
Remote
s should add the given transactions to the pool.
Add
Remotes
([]
*
types
.
Transaction
)
error
}
type
ProtocolManager
struct
{
...
...
@@ -803,7 +803,7 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
return
errResp
(
ErrRequestRejected
,
""
)
}
if
err
:=
pm
.
txpool
.
Add
Batch
(
txs
);
err
!=
nil
{
if
err
:=
pm
.
txpool
.
Add
Remotes
(
txs
);
err
!=
nil
{
return
errResp
(
ErrUnexpectedResponse
,
"msg: %v"
,
err
)
}
...
...
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