aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-05-27 08:07:03 +0800
committerobscuren <geffobscura@gmail.com>2015-05-27 08:07:03 +0800
commit70867904a0255bd044851585a9ad2dc34391ced2 (patch)
tree9c5dfc6a9b8944c37f874a81cc9f8fd3d697ad4e /core
parentceea1a7051ddc7d2660117204aeb3392b7cf8314 (diff)
parent2c532a7255919bc09e01cca6866bfc15682509a3 (diff)
downloaddexon-70867904a0255bd044851585a9ad2dc34391ced2.tar
dexon-70867904a0255bd044851585a9ad2dc34391ced2.tar.gz
dexon-70867904a0255bd044851585a9ad2dc34391ced2.tar.bz2
dexon-70867904a0255bd044851585a9ad2dc34391ced2.tar.lz
dexon-70867904a0255bd044851585a9ad2dc34391ced2.tar.xz
dexon-70867904a0255bd044851585a9ad2dc34391ced2.tar.zst
dexon-70867904a0255bd044851585a9ad2dc34391ced2.zip
Merge branch 'release/0.9.25'
Diffstat (limited to 'core')
-rw-r--r--core/block_processor.go7
-rw-r--r--core/chain_manager.go2
-rw-r--r--core/transaction_pool.go5
-rw-r--r--core/transaction_pool_test.go14
4 files changed, 25 insertions, 3 deletions
diff --git a/core/block_processor.go b/core/block_processor.go
index 3f10e5efd..e808c03da 100644
--- a/core/block_processor.go
+++ b/core/block_processor.go
@@ -21,7 +21,7 @@ import (
const (
// must be bumped when consensus algorithm is changed, this forces the upgradedb
// command to be run (forces the blocks to be imported again using the new algorithm)
- BlockChainVersion = 2
+ BlockChainVersion = 3
)
var receiptsPre = []byte("receipts-")
@@ -159,6 +159,9 @@ func (sm *BlockProcessor) RetryProcess(block *types.Block) (logs state.Logs, err
return nil, ParentError(header.ParentHash)
}
parent := sm.bc.GetBlock(header.ParentHash)
+ if !sm.Pow.Verify(block) {
+ return nil, ValidationError("Block's nonce is invalid (= %x)", block.Nonce)
+ }
return sm.processWithParent(block, parent)
}
@@ -299,7 +302,7 @@ func (sm *BlockProcessor) ValidateHeader(block, parent *types.Header, checkPow b
a := new(big.Int).Sub(block.GasLimit, parent.GasLimit)
a.Abs(a)
b := new(big.Int).Div(parent.GasLimit, params.GasLimitBoundDivisor)
- if !(a.Cmp(b) < 0) || (block.GasLimit.Cmp(params.MinGasLimit) == -1) {
+ if !(a.Cmp(b) <= 0) || (block.GasLimit.Cmp(params.MinGasLimit) == -1) {
return fmt.Errorf("GasLimit check failed for block %v (%v > %v)", block.GasLimit, a, b)
}
diff --git a/core/chain_manager.go b/core/chain_manager.go
index 2b86bb794..ec479db25 100644
--- a/core/chain_manager.go
+++ b/core/chain_manager.go
@@ -750,7 +750,7 @@ out:
func blockErr(block *types.Block, err error) {
h := block.Header()
- glog.V(logger.Error).Infof("INVALID block #%v (%x)\n", h.Number, h.Hash().Bytes())
+ glog.V(logger.Error).Infof("Bad block #%v (%x)\n", h.Number, h.Hash().Bytes())
glog.V(logger.Error).Infoln(err)
glog.V(logger.Debug).Infoln(block)
}
diff --git a/core/transaction_pool.go b/core/transaction_pool.go
index e68f7406a..c896488d1 100644
--- a/core/transaction_pool.go
+++ b/core/transaction_pool.go
@@ -25,6 +25,7 @@ var (
ErrInsufficientFunds = errors.New("Insufficient funds for gas * price + value")
ErrIntrinsicGas = errors.New("Intrinsic gas too low")
ErrGasLimit = errors.New("Exceeds block gas limit")
+ ErrNegativeValue = errors.New("Negative value")
)
const txPoolQueueSize = 50
@@ -125,6 +126,10 @@ func (pool *TxPool) ValidateTransaction(tx *types.Transaction) error {
return ErrGasLimit
}
+ if tx.Amount.Cmp(common.Big0) < 0 {
+ return ErrNegativeValue
+ }
+
total := new(big.Int).Mul(tx.Price, tx.GasLimit)
total.Add(total, tx.Value())
if pool.currentState().GetBalance(from).Cmp(total) < 0 {
diff --git a/core/transaction_pool_test.go b/core/transaction_pool_test.go
index 49224be5b..d6ea4a2a9 100644
--- a/core/transaction_pool_test.go
+++ b/core/transaction_pool_test.go
@@ -138,3 +138,17 @@ func TestRemoveTx(t *testing.T) {
t.Error("expected txs to be 0, got", len(pool.txs))
}
}
+
+func TestNegativeValue(t *testing.T) {
+ pool, key := setupTxPool()
+
+ tx := transaction()
+ tx.Value().Set(big.NewInt(-1))
+ tx.SignECDSA(key)
+ from, _ := tx.From()
+ pool.currentState().AddBalance(from, big.NewInt(1))
+ err := pool.Add(tx)
+ if err != ErrNegativeValue {
+ t.Error("expected", ErrNegativeValue, "got", err)
+ }
+}