aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-02-01 00:23:50 +0800
committerobscuren <geffobscura@gmail.com>2015-02-01 00:23:50 +0800
commit9016ce8dd8c7460799329ec4eb2b51f4ff3d9291 (patch)
treeddfec9a88209d8986c6949a6f458b35ae931bf42
parent79cd58bdf32c8e4e725480f9d6dc58f7325e07a0 (diff)
parentcb382fa76ba30d213e4707d05bf3a00bc87dec9a (diff)
downloadgo-tangerine-9016ce8dd8c7460799329ec4eb2b51f4ff3d9291.tar.gz
go-tangerine-9016ce8dd8c7460799329ec4eb2b51f4ff3d9291.tar.zst
go-tangerine-9016ce8dd8c7460799329ec4eb2b51f4ff3d9291.zip
Merge branch 'bounty' into develop
-rw-r--r--core/transaction_pool.go20
-rw-r--r--core/transaction_pool_test.go10
2 files changed, 23 insertions, 7 deletions
diff --git a/core/transaction_pool.go b/core/transaction_pool.go
index d3aec9050..7a901fcae 100644
--- a/core/transaction_pool.go
+++ b/core/transaction_pool.go
@@ -1,6 +1,7 @@
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.
diff --git a/core/transaction_pool_test.go b/core/transaction_pool_test.go
index 7f192fc4d..b2d981f01 100644
--- a/core/transaction_pool_test.go
+++ b/core/transaction_pool_test.go
@@ -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)
+ }
+}