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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
open
bor
Commits
cb382fa7
Commit
cb382fa7
authored
10 years ago
by
Jeffrey Wilcke
Browse files
Options
Downloads
Patches
Plain Diff
Validate transactions sender before adding to pool. Closes #272
parent
0dfe5113
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
core/transaction_pool.go
+13
-7
13 additions, 7 deletions
core/transaction_pool.go
core/transaction_pool_test.go
+10
-0
10 additions, 0 deletions
core/transaction_pool_test.go
with
23 additions
and
7 deletions
core/transaction_pool.go
+
13
−
7
View file @
cb382fa7
package
core
import
(
"errors"
"fmt"
"github.com/ethereum/go-ethereum/core/types"
...
...
@@ -9,7 +10,11 @@ import (
"github.com/ethereum/go-ethereum/logger"
)
var
txplogger
=
logger
.
NewLogger
(
"TXP"
)
var
(
txplogger
=
logger
.
NewLogger
(
"TXP"
)
ErrInvalidSender
=
errors
.
New
(
"Invalid sender"
)
)
const
txPoolQueueSize
=
50
...
...
@@ -60,22 +65,23 @@ func (pool *TxPool) ValidateTransaction(tx *types.Transaction) error {
return
fmt
.
Errorf
(
"Invalid recipient. len = %d"
,
len
(
tx
.
To
()))
}
// 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
}
/* 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
but doesn't necessarily invalidate the tx. Gas can still be payed for and miner
can still be rewarded for their inclusion and processing.
// Get the sender
senderAddr := tx.From()
if senderAddr == nil {
return fmt.Errorf("invalid sender")
}
sender := pool.stateQuery.GetAccount(senderAddr)
totAmount := new(big.Int).Set(tx.Value())
// Make sure there's enough in the sender's account. Having insufficient
// funds won't invalidate this transaction but simple ignores it.
...
...
This diff is collapsed.
Click to expand it.
core/transaction_pool_test.go
+
10
−
0
View file @
cb382fa7
...
...
@@ -85,3 +85,13 @@ func TestRemoveInvalid(t *testing.T) {
t
.
Error
(
"expected pool size to be 1, is"
,
pool
.
Size
())
}
}
func
TestInvalidSender
(
t
*
testing
.
T
)
{
pool
,
_
:=
setup
()
tx
:=
new
(
types
.
Transaction
)
tx
.
V
=
28
err
:=
pool
.
ValidateTransaction
(
tx
)
if
err
!=
ErrInvalidSender
{
t
.
Error
(
"expected %v, got %v"
,
ErrInvalidSender
,
err
)
}
}
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