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
b95387a0
Commit
b95387a0
authored
Mar 17, 2015
by
Felix Lange
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
core: convert transaction pool to common.{Address,Hash}
parent
e91ab84d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
33 deletions
+21
-33
transaction_pool.go
core/transaction_pool.go
+21
-33
No files found.
core/transaction_pool.go
View file @
b95387a0
...
...
@@ -5,8 +5,8 @@ import (
"fmt"
"sync"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/logger"
)
...
...
@@ -20,9 +20,7 @@ var (
const
txPoolQueueSize
=
50
type
TxPoolHook
chan
*
types
.
Transaction
type
TxMsg
struct
{
Tx
*
types
.
Transaction
}
type
TxMsg
struct
{
Tx
*
types
.
Transaction
}
const
(
minGasPrice
=
1000000
...
...
@@ -44,7 +42,7 @@ type TxPool struct {
quit
chan
bool
// The actual pool
//pool *list.List
txs
map
[
string
]
*
types
.
Transaction
txs
map
[
common
.
Hash
]
*
types
.
Transaction
SecondaryProcessor
TxProcessor
...
...
@@ -55,7 +53,7 @@ type TxPool struct {
func
NewTxPool
(
eventMux
*
event
.
TypeMux
)
*
TxPool
{
return
&
TxPool
{
txs
:
make
(
map
[
string
]
*
types
.
Transaction
),
txs
:
make
(
map
[
common
.
Hash
]
*
types
.
Transaction
),
queueChan
:
make
(
chan
*
types
.
Transaction
,
txPoolQueueSize
),
quit
:
make
(
chan
bool
),
eventMux
:
eventMux
,
...
...
@@ -63,21 +61,16 @@ func NewTxPool(eventMux *event.TypeMux) *TxPool {
}
func
(
pool
*
TxPool
)
ValidateTransaction
(
tx
*
types
.
Transaction
)
error
{
if
len
(
tx
.
To
())
!=
0
&&
len
(
tx
.
To
())
!=
20
{
return
fmt
.
Errorf
(
"Invalid recipient. len = %d"
,
len
(
tx
.
To
()))
// Validate sender
if
_
,
err
:=
tx
.
From
();
err
!=
nil
{
return
err
}
// Validate curve param
v
,
_
,
_
:=
tx
.
Curve
()
if
v
>
28
||
v
<
27
{
return
fmt
.
Errorf
(
"tx.v != (28 || 27) => %v"
,
v
)
}
// Validate sender address
senderAddr
:=
tx
.
From
()
if
senderAddr
==
nil
||
len
(
senderAddr
)
!=
20
{
return
ErrInvalidSender
}
return
nil
/* XXX this kind of validation needs to happen elsewhere in the gui when sending txs.
Other clients should do their own validation. Value transfer could throw error
...
...
@@ -91,19 +84,16 @@ func (pool *TxPool) ValidateTransaction(tx *types.Transaction) error {
return fmt.Errorf("Insufficient amount in sender's (%x) account", tx.From())
}
*/
return
nil
}
func
(
self
*
TxPool
)
addTx
(
tx
*
types
.
Transaction
)
{
self
.
txs
[
string
(
tx
.
Hash
()
)]
=
tx
self
.
txs
[
tx
.
Hash
(
)]
=
tx
}
func
(
self
*
TxPool
)
add
(
tx
*
types
.
Transaction
)
error
{
if
self
.
txs
[
string
(
tx
.
Hash
()
)]
!=
nil
{
if
self
.
txs
[
tx
.
Hash
(
)]
!=
nil
{
return
fmt
.
Errorf
(
"Known transaction (%x)"
,
tx
.
Hash
()[
0
:
4
])
}
err
:=
self
.
ValidateTransaction
(
tx
)
if
err
!=
nil
{
return
err
...
...
@@ -111,18 +101,16 @@ func (self *TxPool) add(tx *types.Transaction) error {
self
.
addTx
(
tx
)
var
to
string
if
len
(
tx
.
To
())
>
0
{
to
=
common
.
Bytes2Hex
(
tx
.
To
()
[
:
4
])
var
to
name
string
if
to
,
valid
:=
tx
.
To
();
valid
{
to
name
=
common
.
Bytes2Hex
(
to
[
:
4
])
}
else
{
to
=
"[NEW_CONTRACT]"
}
var
from
string
if
len
(
tx
.
From
())
>
0
{
from
=
common
.
Bytes2Hex
(
tx
.
From
()[
:
4
])
}
else
{
return
errors
.
New
(
fmt
.
Sprintf
(
"FROM ADDRESS MUST BE POSITIVE (was %v)"
,
tx
.
From
()))
toname
=
"[NEW_CONTRACT]"
}
// we can ignore the error here because From is
// verified in ValidateTransaction.
f
,
_
:=
tx
.
From
()
from
:=
common
.
Bytes2Hex
(
f
[
:
4
])
txplogger
.
Debugf
(
"(t) %x => %s (%v) %x
\n
"
,
from
,
to
,
tx
.
Value
,
tx
.
Hash
())
// Notify the subscribers
...
...
@@ -140,6 +128,7 @@ func (self *TxPool) Add(tx *types.Transaction) error {
defer
self
.
mu
.
Unlock
()
return
self
.
add
(
tx
)
}
func
(
self
*
TxPool
)
AddTransactions
(
txs
[]
*
types
.
Transaction
)
{
self
.
mu
.
Lock
()
defer
self
.
mu
.
Unlock
()
...
...
@@ -186,14 +175,13 @@ func (pool *TxPool) RemoveInvalid(query StateQuery) {
func
(
self
*
TxPool
)
RemoveSet
(
txs
types
.
Transactions
)
{
self
.
mu
.
Lock
()
defer
self
.
mu
.
Unlock
()
for
_
,
tx
:=
range
txs
{
delete
(
self
.
txs
,
string
(
tx
.
Hash
()
))
delete
(
self
.
txs
,
tx
.
Hash
(
))
}
}
func
(
pool
*
TxPool
)
Flush
()
{
pool
.
txs
=
make
(
map
[
string
]
*
types
.
Transaction
)
pool
.
txs
=
make
(
map
[
common
.
Hash
]
*
types
.
Transaction
)
}
func
(
pool
*
TxPool
)
Start
()
{
...
...
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