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
9dd12a64
Commit
9dd12a64
authored
Jun 04, 2015
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
core: renamed txs to pending
parent
9b27fb91
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
24 deletions
+24
-24
transaction_pool.go
core/transaction_pool.go
+16
-16
transaction_pool_test.go
core/transaction_pool_test.go
+8
-8
No files found.
core/transaction_pool.go
View file @
9dd12a64
...
@@ -44,14 +44,14 @@ type TxPool struct {
...
@@ -44,14 +44,14 @@ type TxPool struct {
eventMux
*
event
.
TypeMux
eventMux
*
event
.
TypeMux
events
event
.
Subscription
events
event
.
Subscription
mu
sync
.
RWMutex
mu
sync
.
RWMutex
txs
map
[
common
.
Hash
]
*
types
.
Transaction
// processable transactions
pending
map
[
common
.
Hash
]
*
types
.
Transaction
// processable transactions
queue
map
[
common
.
Address
]
map
[
common
.
Hash
]
*
types
.
Transaction
queue
map
[
common
.
Address
]
map
[
common
.
Hash
]
*
types
.
Transaction
}
}
func
NewTxPool
(
eventMux
*
event
.
TypeMux
,
currentStateFn
stateFn
,
gasLimitFn
func
()
*
big
.
Int
)
*
TxPool
{
func
NewTxPool
(
eventMux
*
event
.
TypeMux
,
currentStateFn
stateFn
,
gasLimitFn
func
()
*
big
.
Int
)
*
TxPool
{
return
&
TxPool
{
return
&
TxPool
{
txs
:
make
(
map
[
common
.
Hash
]
*
types
.
Transaction
),
pending
:
make
(
map
[
common
.
Hash
]
*
types
.
Transaction
),
queue
:
make
(
map
[
common
.
Address
]
map
[
common
.
Hash
]
*
types
.
Transaction
),
queue
:
make
(
map
[
common
.
Address
]
map
[
common
.
Hash
]
*
types
.
Transaction
),
quit
:
make
(
chan
bool
),
quit
:
make
(
chan
bool
),
eventMux
:
eventMux
,
eventMux
:
eventMux
,
...
@@ -67,7 +67,7 @@ func (pool *TxPool) Start() {
...
@@ -67,7 +67,7 @@ func (pool *TxPool) Start() {
pool
.
mu
.
Lock
()
pool
.
mu
.
Lock
()
pool
.
state
=
state
.
ManageState
(
pool
.
currentState
())
pool
.
state
=
state
.
ManageState
(
pool
.
currentState
())
for
_
,
tx
:=
range
pool
.
txs
{
for
_
,
tx
:=
range
pool
.
pending
{
if
addr
,
err
:=
tx
.
From
();
err
==
nil
{
if
addr
,
err
:=
tx
.
From
();
err
==
nil
{
pool
.
state
.
SetNonce
(
addr
,
tx
.
Nonce
())
pool
.
state
.
SetNonce
(
addr
,
tx
.
Nonce
())
}
}
...
@@ -79,7 +79,7 @@ func (pool *TxPool) Start() {
...
@@ -79,7 +79,7 @@ func (pool *TxPool) Start() {
}
}
func
(
pool
*
TxPool
)
Stop
()
{
func
(
pool
*
TxPool
)
Stop
()
{
pool
.
txs
=
make
(
map
[
common
.
Hash
]
*
types
.
Transaction
)
pool
.
pending
=
make
(
map
[
common
.
Hash
]
*
types
.
Transaction
)
close
(
pool
.
quit
)
close
(
pool
.
quit
)
pool
.
events
.
Unsubscribe
()
pool
.
events
.
Unsubscribe
()
glog
.
V
(
logger
.
Info
)
.
Infoln
(
"TX Pool stopped"
)
glog
.
V
(
logger
.
Info
)
.
Infoln
(
"TX Pool stopped"
)
...
@@ -143,7 +143,7 @@ func (self *TxPool) add(tx *types.Transaction) error {
...
@@ -143,7 +143,7 @@ func (self *TxPool) add(tx *types.Transaction) error {
return fmt.Errorf("Invalid transaction (%x)", hash[:4])
return fmt.Errorf("Invalid transaction (%x)", hash[:4])
}
}
*/
*/
if
self
.
txs
[
hash
]
!=
nil
{
if
self
.
pending
[
hash
]
!=
nil
{
return
fmt
.
Errorf
(
"Known transaction (%x)"
,
hash
[
:
4
])
return
fmt
.
Errorf
(
"Known transaction (%x)"
,
hash
[
:
4
])
}
}
err
:=
self
.
validateTx
(
tx
)
err
:=
self
.
validateTx
(
tx
)
...
@@ -199,7 +199,7 @@ func (self *TxPool) AddTransactions(txs []*types.Transaction) {
...
@@ -199,7 +199,7 @@ func (self *TxPool) AddTransactions(txs []*types.Transaction) {
// and nil otherwise.
// and nil otherwise.
func
(
tp
*
TxPool
)
GetTransaction
(
hash
common
.
Hash
)
*
types
.
Transaction
{
func
(
tp
*
TxPool
)
GetTransaction
(
hash
common
.
Hash
)
*
types
.
Transaction
{
// check the txs first
// check the txs first
if
tx
,
ok
:=
tp
.
txs
[
hash
];
ok
{
if
tx
,
ok
:=
tp
.
pending
[
hash
];
ok
{
return
tx
return
tx
}
}
// check queue
// check queue
...
@@ -221,9 +221,9 @@ func (self *TxPool) GetTransactions() (txs types.Transactions) {
...
@@ -221,9 +221,9 @@ func (self *TxPool) GetTransactions() (txs types.Transactions) {
// invalidate any txs
// invalidate any txs
self
.
validatePool
()
self
.
validatePool
()
txs
=
make
(
types
.
Transactions
,
len
(
self
.
txs
))
txs
=
make
(
types
.
Transactions
,
len
(
self
.
pending
))
i
:=
0
i
:=
0
for
_
,
tx
:=
range
self
.
txs
{
for
_
,
tx
:=
range
self
.
pending
{
txs
[
i
]
=
tx
txs
[
i
]
=
tx
i
++
i
++
}
}
...
@@ -263,8 +263,8 @@ func (self *TxPool) queueTx(hash common.Hash, tx *types.Transaction) {
...
@@ -263,8 +263,8 @@ func (self *TxPool) queueTx(hash common.Hash, tx *types.Transaction) {
}
}
func
(
pool
*
TxPool
)
addTx
(
hash
common
.
Hash
,
addr
common
.
Address
,
tx
*
types
.
Transaction
)
{
func
(
pool
*
TxPool
)
addTx
(
hash
common
.
Hash
,
addr
common
.
Address
,
tx
*
types
.
Transaction
)
{
if
_
,
ok
:=
pool
.
txs
[
hash
];
!
ok
{
if
_
,
ok
:=
pool
.
pending
[
hash
];
!
ok
{
pool
.
txs
[
hash
]
=
tx
pool
.
pending
[
hash
]
=
tx
pool
.
state
.
SetNonce
(
addr
,
tx
.
AccountNonce
)
pool
.
state
.
SetNonce
(
addr
,
tx
.
AccountNonce
)
// Notify the subscribers. This event is posted in a goroutine
// Notify the subscribers. This event is posted in a goroutine
...
@@ -311,7 +311,7 @@ func (pool *TxPool) checkQueue() {
...
@@ -311,7 +311,7 @@ func (pool *TxPool) checkQueue() {
func
(
pool
*
TxPool
)
removeTx
(
hash
common
.
Hash
)
{
func
(
pool
*
TxPool
)
removeTx
(
hash
common
.
Hash
)
{
// delete from pending pool
// delete from pending pool
delete
(
pool
.
txs
,
hash
)
delete
(
pool
.
pending
,
hash
)
// delete from queue
// delete from queue
for
address
,
txs
:=
range
pool
.
queue
{
for
address
,
txs
:=
range
pool
.
queue
{
if
_
,
ok
:=
txs
[
hash
];
ok
{
if
_
,
ok
:=
txs
[
hash
];
ok
{
...
@@ -328,12 +328,12 @@ func (pool *TxPool) removeTx(hash common.Hash) {
...
@@ -328,12 +328,12 @@ func (pool *TxPool) removeTx(hash common.Hash) {
// validatePool removes invalid and processed transactions from the main pool.
// validatePool removes invalid and processed transactions from the main pool.
func
(
pool
*
TxPool
)
validatePool
()
{
func
(
pool
*
TxPool
)
validatePool
()
{
for
hash
,
tx
:=
range
pool
.
txs
{
for
hash
,
tx
:=
range
pool
.
pending
{
if
err
:=
pool
.
validateTx
(
tx
);
err
!=
nil
{
if
err
:=
pool
.
validateTx
(
tx
);
err
!=
nil
{
if
glog
.
V
(
logger
.
Info
)
{
if
glog
.
V
(
logger
.
Core
)
{
glog
.
Infof
(
"removed tx (%x) from pool: %v
\n
"
,
hash
[
:
4
],
err
)
glog
.
Infof
(
"removed tx (%x) from pool: %v
\n
"
,
hash
[
:
4
],
err
)
}
}
delete
(
pool
.
txs
,
hash
)
delete
(
pool
.
pending
,
hash
)
}
}
}
}
}
}
...
...
core/transaction_pool_test.go
View file @
9dd12a64
...
@@ -71,8 +71,8 @@ func TestTransactionQueue(t *testing.T) {
...
@@ -71,8 +71,8 @@ func TestTransactionQueue(t *testing.T) {
pool
.
queueTx
(
tx
.
Hash
(),
tx
)
pool
.
queueTx
(
tx
.
Hash
(),
tx
)
pool
.
checkQueue
()
pool
.
checkQueue
()
if
len
(
pool
.
txs
)
!=
1
{
if
len
(
pool
.
pending
)
!=
1
{
t
.
Error
(
"expected valid txs to be 1 is"
,
len
(
pool
.
txs
))
t
.
Error
(
"expected valid txs to be 1 is"
,
len
(
pool
.
pending
))
}
}
tx
=
transaction
()
tx
=
transaction
()
...
@@ -82,7 +82,7 @@ func TestTransactionQueue(t *testing.T) {
...
@@ -82,7 +82,7 @@ func TestTransactionQueue(t *testing.T) {
pool
.
state
.
SetNonce
(
from
,
2
)
pool
.
state
.
SetNonce
(
from
,
2
)
pool
.
queueTx
(
tx
.
Hash
(),
tx
)
pool
.
queueTx
(
tx
.
Hash
(),
tx
)
pool
.
checkQueue
()
pool
.
checkQueue
()
if
_
,
ok
:=
pool
.
txs
[
tx
.
Hash
()];
ok
{
if
_
,
ok
:=
pool
.
pending
[
tx
.
Hash
()];
ok
{
t
.
Error
(
"expected transaction to be in tx pool"
)
t
.
Error
(
"expected transaction to be in tx pool"
)
}
}
...
@@ -104,7 +104,7 @@ func TestTransactionQueue(t *testing.T) {
...
@@ -104,7 +104,7 @@ func TestTransactionQueue(t *testing.T) {
pool
.
checkQueue
()
pool
.
checkQueue
()
if
len
(
pool
.
txs
)
!=
1
{
if
len
(
pool
.
pending
)
!=
1
{
t
.
Error
(
"expected tx pool to be 1 ="
)
t
.
Error
(
"expected tx pool to be 1 ="
)
}
}
if
len
(
pool
.
queue
[
from
])
!=
2
{
if
len
(
pool
.
queue
[
from
])
!=
2
{
...
@@ -124,8 +124,8 @@ func TestRemoveTx(t *testing.T) {
...
@@ -124,8 +124,8 @@ func TestRemoveTx(t *testing.T) {
t
.
Error
(
"expected queue to be 1, got"
,
len
(
pool
.
queue
))
t
.
Error
(
"expected queue to be 1, got"
,
len
(
pool
.
queue
))
}
}
if
len
(
pool
.
txs
)
!=
1
{
if
len
(
pool
.
pending
)
!=
1
{
t
.
Error
(
"expected txs to be 1, got"
,
len
(
pool
.
txs
))
t
.
Error
(
"expected txs to be 1, got"
,
len
(
pool
.
pending
))
}
}
pool
.
removeTx
(
tx
.
Hash
())
pool
.
removeTx
(
tx
.
Hash
())
...
@@ -134,8 +134,8 @@ func TestRemoveTx(t *testing.T) {
...
@@ -134,8 +134,8 @@ func TestRemoveTx(t *testing.T) {
t
.
Error
(
"expected queue to be 0, got"
,
len
(
pool
.
queue
))
t
.
Error
(
"expected queue to be 0, got"
,
len
(
pool
.
queue
))
}
}
if
len
(
pool
.
txs
)
>
0
{
if
len
(
pool
.
pending
)
>
0
{
t
.
Error
(
"expected txs to be 0, got"
,
len
(
pool
.
txs
))
t
.
Error
(
"expected txs to be 0, got"
,
len
(
pool
.
pending
))
}
}
}
}
...
...
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