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
7138404c
Commit
7138404c
authored
Apr 21, 2015
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
core: only post event once per tx & fixed test
parent
4feb5f6f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
15 deletions
+21
-15
transaction_pool.go
core/transaction_pool.go
+15
-9
transaction_pool_test.go
core/transaction_pool_test.go
+6
-6
No files found.
core/transaction_pool.go
View file @
7138404c
...
...
@@ -125,11 +125,6 @@ func (pool *TxPool) ValidateTransaction(tx *types.Transaction) error {
return
nil
}
func
(
self
*
TxPool
)
addTx
(
tx
*
types
.
Transaction
)
{
from
,
_
:=
tx
.
From
()
self
.
queue
[
from
]
=
append
(
self
.
queue
[
from
],
tx
)
}
func
(
self
*
TxPool
)
add
(
tx
*
types
.
Transaction
)
error
{
hash
:=
tx
.
Hash
()
...
...
@@ -147,7 +142,7 @@ func (self *TxPool) add(tx *types.Transaction) error {
return
err
}
self
.
add
Tx
(
tx
)
self
.
queue
Tx
(
tx
)
var
toname
string
if
to
:=
tx
.
To
();
to
!=
nil
{
...
...
@@ -226,6 +221,19 @@ func (pool *TxPool) Stop() {
glog
.
V
(
logger
.
Info
)
.
Infoln
(
"TX Pool stopped"
)
}
func
(
self
*
TxPool
)
queueTx
(
tx
*
types
.
Transaction
)
{
from
,
_
:=
tx
.
From
()
self
.
queue
[
from
]
=
append
(
self
.
queue
[
from
],
tx
)
}
func
(
pool
*
TxPool
)
addTx
(
tx
*
types
.
Transaction
)
{
if
_
,
ok
:=
pool
.
txs
[
tx
.
Hash
()];
!
ok
{
pool
.
txs
[
tx
.
Hash
()]
=
tx
// Notify the subscribers
pool
.
eventMux
.
Post
(
TxPreEvent
{
tx
})
}
}
// check queue will attempt to insert
func
(
pool
*
TxPool
)
checkQueue
()
{
pool
.
mu
.
Lock
()
...
...
@@ -257,9 +265,7 @@ func (pool *TxPool) checkQueue() {
}
enonce
++
pool
.
txs
[
tx
.
Hash
()]
=
tx
// Notify the subscribers
go
pool
.
eventMux
.
Post
(
TxPreEvent
{
tx
})
pool
.
addTx
(
tx
)
}
//pool.queue[address] = txs[i:]
// delete the entire queue entry if it's empty. There's no need to keep it
...
...
core/transaction_pool_test.go
View file @
7138404c
...
...
@@ -67,7 +67,7 @@ func TestTransactionQueue(t *testing.T) {
tx
.
SignECDSA
(
key
)
from
,
_
:=
tx
.
From
()
pool
.
currentState
()
.
AddBalance
(
from
,
big
.
NewInt
(
1
))
pool
.
add
Tx
(
tx
)
pool
.
queue
Tx
(
tx
)
pool
.
checkQueue
()
if
len
(
pool
.
txs
)
!=
1
{
...
...
@@ -79,7 +79,7 @@ func TestTransactionQueue(t *testing.T) {
from
,
_
=
tx
.
From
()
pool
.
currentState
()
.
SetNonce
(
from
,
10
)
tx
.
SetNonce
(
1
)
pool
.
add
Tx
(
tx
)
pool
.
queue
Tx
(
tx
)
pool
.
checkQueue
()
if
_
,
ok
:=
pool
.
txs
[
tx
.
Hash
()];
ok
{
t
.
Error
(
"expected transaction to be in tx pool"
)
...
...
@@ -96,9 +96,9 @@ func TestTransactionQueue(t *testing.T) {
tx1
.
SignECDSA
(
key
)
tx2
.
SignECDSA
(
key
)
tx3
.
SignECDSA
(
key
)
pool
.
add
Tx
(
tx1
)
pool
.
add
Tx
(
tx2
)
pool
.
add
Tx
(
tx3
)
pool
.
queue
Tx
(
tx1
)
pool
.
queue
Tx
(
tx2
)
pool
.
queue
Tx
(
tx3
)
from
,
_
=
tx1
.
From
()
pool
.
checkQueue
()
...
...
@@ -106,7 +106,7 @@ func TestTransactionQueue(t *testing.T) {
t
.
Error
(
"expected tx pool to be 1 ="
)
}
if
len
(
pool
.
queue
[
from
])
!=
2
{
if
len
(
pool
.
queue
[
from
])
!=
3
{
t
.
Error
(
"expected transaction queue to be empty. is"
,
len
(
pool
.
queue
[
from
]))
}
}
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