good morning!!!!
Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
bor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
open
bor
Commits
b95387a0
Commit
b95387a0
authored
Mar 17, 2015
by
Felix Lange
Browse files
Options
Downloads
Patches
Plain Diff
core: convert transaction pool to common.{Address,Hash}
parent
e91ab84d
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
core/transaction_pool.go
+21
-33
21 additions, 33 deletions
core/transaction_pool.go
with
21 additions
and
33 deletions
core/transaction_pool.go
+
21
−
33
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
(
t
x
.
To
()
[
:
4
])
var
to
name
string
if
to
,
valid
:=
tx
.
To
();
valid
{
to
name
=
common
.
Bytes2Hex
(
t
o
[
:
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
()
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment