aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/block_processor.go12
-rw-r--r--core/chain_manager.go10
-rw-r--r--core/error.go18
-rw-r--r--core/execution.go2
-rw-r--r--core/genesis.go2
-rw-r--r--core/state_transition.go19
-rw-r--r--core/types/bloom9.go7
7 files changed, 47 insertions, 23 deletions
diff --git a/core/block_processor.go b/core/block_processor.go
index 3123511f9..17256fe9c 100644
--- a/core/block_processor.go
+++ b/core/block_processor.go
@@ -207,7 +207,6 @@ func (sm *BlockProcessor) processWithParent(block, parent *types.Block) (td *big
// Tre receipt Trie's root (R = (Tr [[H1, R1], ... [Hn, R1]]))
receiptSha := types.DeriveSha(receipts)
if bytes.Compare(receiptSha, header.ReceiptHash) != 0 {
- fmt.Println("receipts", receipts)
err = fmt.Errorf("validating receipt root. received=%x got=%x", header.ReceiptHash, receiptSha)
return
}
@@ -250,9 +249,14 @@ func (sm *BlockProcessor) ValidateBlock(block, parent *types.Block) error {
return fmt.Errorf("Difficulty check failed for block %v, %v", block.Header().Difficulty, expd)
}
- expl := CalcGasLimit(parent, block)
- if expl.Cmp(block.Header().GasLimit) != 0 {
- return fmt.Errorf("GasLimit check failed for block %v, %v", block.Header().GasLimit, expl)
+ //expl := CalcGasLimit(parent, block)
+ //if expl.Cmp(block.Header().GasLimit) != 0 {
+
+ // block.gasLimit - parent.gasLimit <= parent.gasLimit / 1024
+ a := new(big.Int).Sub(block.Header().GasLimit, parent.Header().GasLimit)
+ b := new(big.Int).Div(parent.Header().GasLimit, big.NewInt(1024))
+ if a.Cmp(b) > 0 {
+ return fmt.Errorf("GasLimit check failed for block %v", block.Header().GasLimit)
}
// There can be at most one uncle
diff --git a/core/chain_manager.go b/core/chain_manager.go
index 959bfd398..2f6c36382 100644
--- a/core/chain_manager.go
+++ b/core/chain_manager.go
@@ -28,11 +28,13 @@ type StateQuery interface {
func CalcDifficulty(block, parent *types.Block) *big.Int {
diff := new(big.Int)
- adjust := new(big.Int).Rsh(parent.Difficulty(), 10)
- if block.Time() >= parent.Time()+8 {
- diff.Sub(parent.Difficulty(), adjust)
- } else {
+ //adjust := new(big.Int).Rsh(parent.Difficulty(), 10)
+ //if block.Time() >= parent.Time()+8 {
+ adjust := new(big.Int).Div(parent.Difficulty(), big.NewInt(2048))
+ if (block.Time() - parent.Time()) < 8 {
diff.Add(parent.Difficulty(), adjust)
+ } else {
+ diff.Sub(parent.Difficulty(), adjust)
}
return diff
diff --git a/core/error.go b/core/error.go
index e86bacb2d..fb1eaed84 100644
--- a/core/error.go
+++ b/core/error.go
@@ -87,6 +87,24 @@ func IsNonceErr(err error) bool {
return ok
}
+type InvalidTxErr struct {
+ Message string
+}
+
+func (err *InvalidTxErr) Error() string {
+ return err.Message
+}
+
+func InvalidTxError(err error) *InvalidTxErr {
+ return &InvalidTxErr{fmt.Sprintf("%v", err)}
+}
+
+func IsInvalidTxErr(err error) bool {
+ _, ok := err.(*InvalidTxErr)
+
+ return ok
+}
+
type OutOfGasErr struct {
Message string
}
diff --git a/core/execution.go b/core/execution.go
index 5e0cbd37e..f7d5a8945 100644
--- a/core/execution.go
+++ b/core/execution.go
@@ -61,10 +61,10 @@ func (self *Execution) exec(code, contextAddr []byte, caller vm.ContextRef) (ret
snapshot := env.State().Copy()
start := time.Now()
ret, err = evm.Run(to, caller, code, self.value, self.Gas, self.price, self.input)
+ chainlogger.Debugf("vm took %v\n", time.Since(start))
if err != nil {
env.State().Set(snapshot)
}
- chainlogger.Debugf("vm took %v\n", time.Since(start))
return
}
diff --git a/core/genesis.go b/core/genesis.go
index 75b4fc100..decffc541 100644
--- a/core/genesis.go
+++ b/core/genesis.go
@@ -51,8 +51,6 @@ func GenesisBlock(db ethutil.Database) *types.Block {
statedb.Sync()
genesis.Header().Root = statedb.Root()
- fmt.Printf("+++ genesis +++\nRoot: %x\nHash: %x\n", genesis.Header().Root, genesis.Hash())
-
return genesis
}
diff --git a/core/state_transition.go b/core/state_transition.go
index 7331fdd4a..00e383f3f 100644
--- a/core/state_transition.go
+++ b/core/state_transition.go
@@ -3,7 +3,6 @@ package core
import (
"fmt"
"math/big"
-
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/state"
@@ -12,6 +11,8 @@ import (
const tryJit = false
+var ()
+
/*
* The State transitioning model
*
@@ -144,7 +145,7 @@ func (self *StateTransition) preCheck() (err error) {
// Pre-pay gas / Buy gas of the coinbase account
if err = self.BuyGas(); err != nil {
- return err
+ return InvalidTxError(err)
}
return nil
@@ -165,22 +166,22 @@ func (self *StateTransition) TransitionState() (ret []byte, err error) {
defer self.RefundGas()
- // Increment the nonce for the next transaction
- self.state.SetNonce(sender.Address(), sender.Nonce()+1)
- //sender.Nonce += 1
-
// Transaction gas
if err = self.UseGas(vm.GasTx); err != nil {
- return
+ return nil, InvalidTxError(err)
}
+ // Increment the nonce for the next transaction
+ self.state.SetNonce(sender.Address(), sender.Nonce()+1)
+ //sender.Nonce += 1
+
// Pay data gas
var dgas int64
for _, byt := range self.data {
if byt != 0 {
- dgas += vm.GasData.Int64()
+ dgas += vm.GasTxDataNonzeroByte.Int64()
} else {
- dgas += 1 // This is 1/5. If GasData changes this fails
+ dgas += vm.GasTxDataZeroByte.Int64()
}
}
if err = self.UseGas(big.NewInt(dgas)); err != nil {
diff --git a/core/types/bloom9.go b/core/types/bloom9.go
index c1841e553..578265a34 100644
--- a/core/types/bloom9.go
+++ b/core/types/bloom9.go
@@ -14,7 +14,7 @@ func CreateBloom(receipts Receipts) []byte {
bin.Or(bin, LogsBloom(receipt.logs))
}
- return ethutil.LeftPadBytes(bin.Bytes(), 64)
+ return ethutil.LeftPadBytes(bin.Bytes(), 256)
}
func LogsBloom(logs state.Logs) *big.Int {
@@ -37,9 +37,10 @@ func LogsBloom(logs state.Logs) *big.Int {
func bloom9(b []byte) *big.Int {
r := new(big.Int)
- for _, i := range []int{0, 2, 4} {
+
+ for i := 0; i < 16; i += 2 {
t := big.NewInt(1)
- b := uint(b[i+1]) + 256*(uint(b[i])&1)
+ b := uint(b[i+1]) + 1024*(uint(b[i])&1)
r.Or(r, t.Lsh(t, b))
}