aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/bench_test.go4
-rw-r--r--core/block_processor.go26
-rw-r--r--core/block_processor_test.go8
-rw-r--r--core/chain_makers.go6
-rw-r--r--core/chain_makers_test.go4
-rw-r--r--core/chain_manager.go48
-rw-r--r--core/chain_manager_test.go18
-rw-r--r--core/chain_util.go4
-rw-r--r--core/genesis.go18
-rw-r--r--core/manager.go5
-rw-r--r--core/vm/instructions.go19
-rw-r--r--core/vm/jit.go6
-rw-r--r--core/vm/jit_test.go2
-rw-r--r--core/vm/settings.go6
-rw-r--r--core/vm/vm.go2
15 files changed, 81 insertions, 95 deletions
diff --git a/core/bench_test.go b/core/bench_test.go
index 67ba15970..baae8a7a5 100644
--- a/core/bench_test.go
+++ b/core/bench_test.go
@@ -168,8 +168,8 @@ func benchInsertChain(b *testing.B, disk bool, gen func(int, *BlockGen)) {
// Time the insertion of the new chain.
// State and blocks are stored in the same DB.
evmux := new(event.TypeMux)
- chainman, _ := NewChainManager(db, db, db, FakePow{}, evmux)
- chainman.SetProcessor(NewBlockProcessor(db, db, FakePow{}, chainman, evmux))
+ chainman, _ := NewChainManager(db, FakePow{}, evmux)
+ chainman.SetProcessor(NewBlockProcessor(db, FakePow{}, chainman, evmux))
defer chainman.Stop()
b.ReportAllocs()
b.ResetTimer()
diff --git a/core/block_processor.go b/core/block_processor.go
index 6ed1bc8ef..829e4314c 100644
--- a/core/block_processor.go
+++ b/core/block_processor.go
@@ -41,8 +41,7 @@ const (
)
type BlockProcessor struct {
- db common.Database
- extraDb common.Database
+ chainDb common.Database
// Mutex for locking the block processor. Blocks can only be handled one at a time
mutex sync.Mutex
// Canonical block chain
@@ -57,10 +56,9 @@ type BlockProcessor struct {
eventMux *event.TypeMux
}
-func NewBlockProcessor(db, extra common.Database, pow pow.PoW, chainManager *ChainManager, eventMux *event.TypeMux) *BlockProcessor {
+func NewBlockProcessor(db common.Database, pow pow.PoW, chainManager *ChainManager, eventMux *event.TypeMux) *BlockProcessor {
sm := &BlockProcessor{
- db: db,
- extraDb: extra,
+ chainDb: db,
mem: make(map[string]*big.Int),
Pow: pow,
bc: chainManager,
@@ -199,7 +197,7 @@ func (sm *BlockProcessor) Process(block *types.Block) (logs state.Logs, receipts
func (sm *BlockProcessor) processWithParent(block, parent *types.Block) (logs state.Logs, receipts types.Receipts, err error) {
// Create a new state based on the parent's root (e.g., create copy)
- state := state.New(parent.Root(), sm.db)
+ state := state.New(parent.Root(), sm.chainDb)
header := block.Header()
uncles := block.Uncles()
txs := block.Transactions()
@@ -340,7 +338,7 @@ func (sm *BlockProcessor) VerifyUncles(statedb *state.StateDB, block, parent *ty
// GetBlockReceipts returns the receipts beloniging to the block hash
func (sm *BlockProcessor) GetBlockReceipts(bhash common.Hash) types.Receipts {
if block := sm.ChainManager().GetBlock(bhash); block != nil {
- return GetBlockReceipts(sm.extraDb, block.Hash())
+ return GetBlockReceipts(sm.chainDb, block.Hash())
}
return nil
@@ -350,24 +348,14 @@ func (sm *BlockProcessor) GetBlockReceipts(bhash common.Hash) types.Receipts {
// where it tries to get it from the (updated) method which gets them from the receipts or
// the depricated way by re-processing the block.
func (sm *BlockProcessor) GetLogs(block *types.Block) (logs state.Logs, err error) {
- receipts := GetBlockReceipts(sm.extraDb, block.Hash())
+ receipts := GetBlockReceipts(sm.chainDb, block.Hash())
if len(receipts) > 0 {
// coalesce logs
for _, receipt := range receipts {
logs = append(logs, receipt.Logs()...)
}
- return
}
-
- // TODO: remove backward compatibility
- var (
- parent = sm.bc.GetBlock(block.ParentHash())
- state = state.New(parent.Root(), sm.db)
- )
-
- sm.TransitionState(state, parent, block, true)
-
- return state.Logs(), nil
+ return logs, nil
}
// See YP section 4.3.4. "Block Header Validity"
diff --git a/core/block_processor_test.go b/core/block_processor_test.go
index f48ce9607..4525f417b 100644
--- a/core/block_processor_test.go
+++ b/core/block_processor_test.go
@@ -33,19 +33,19 @@ func proc() (*BlockProcessor, *ChainManager) {
db, _ := ethdb.NewMemDatabase()
var mux event.TypeMux
- WriteTestNetGenesisBlock(db, db, 0)
- chainMan, err := NewChainManager(db, db, db, thePow(), &mux)
+ WriteTestNetGenesisBlock(db, 0)
+ chainMan, err := NewChainManager(db, thePow(), &mux)
if err != nil {
fmt.Println(err)
}
- return NewBlockProcessor(db, db, ezp.New(), chainMan, &mux), chainMan
+ return NewBlockProcessor(db, ezp.New(), chainMan, &mux), chainMan
}
func TestNumber(t *testing.T) {
pow := ezp.New()
_, chain := proc()
- statedb := state.New(chain.Genesis().Root(), chain.stateDb)
+ statedb := state.New(chain.Genesis().Root(), chain.chainDb)
header := makeHeader(chain.Genesis(), statedb)
header.Number = big.NewInt(3)
err := ValidateHeader(pow, header, chain.Genesis(), false)
diff --git a/core/chain_makers.go b/core/chain_makers.go
index 85a6175dc..0bb1df95a 100644
--- a/core/chain_makers.go
+++ b/core/chain_makers.go
@@ -184,9 +184,9 @@ func makeHeader(parent *types.Block, state *state.StateDB) *types.Header {
func newCanonical(n int, db common.Database) (*BlockProcessor, error) {
evmux := &event.TypeMux{}
- WriteTestNetGenesisBlock(db, db, 0)
- chainman, _ := NewChainManager(db, db, db, FakePow{}, evmux)
- bman := NewBlockProcessor(db, db, FakePow{}, chainman, evmux)
+ WriteTestNetGenesisBlock(db, 0)
+ chainman, _ := NewChainManager(db, FakePow{}, evmux)
+ bman := NewBlockProcessor(db, FakePow{}, chainman, evmux)
bman.bc.SetProcessor(bman)
parent := bman.bc.CurrentBlock()
if n == 0 {
diff --git a/core/chain_makers_test.go b/core/chain_makers_test.go
index 98a585f9b..1c868624d 100644
--- a/core/chain_makers_test.go
+++ b/core/chain_makers_test.go
@@ -77,8 +77,8 @@ func ExampleGenerateChain() {
// Import the chain. This runs all block validation rules.
evmux := &event.TypeMux{}
- chainman, _ := NewChainManager(db, db, db, FakePow{}, evmux)
- chainman.SetProcessor(NewBlockProcessor(db, db, FakePow{}, chainman, evmux))
+ chainman, _ := NewChainManager(db, FakePow{}, evmux)
+ chainman.SetProcessor(NewBlockProcessor(db, FakePow{}, chainman, evmux))
if i, err := chainman.InsertChain(chain); err != nil {
fmt.Printf("insert error (block %d): %v\n", i, err)
return
diff --git a/core/chain_manager.go b/core/chain_manager.go
index 1b792933c..1647031b1 100644
--- a/core/chain_manager.go
+++ b/core/chain_manager.go
@@ -56,9 +56,7 @@ const (
type ChainManager struct {
//eth EthManager
- blockDb common.Database
- stateDb common.Database
- extraDb common.Database
+ chainDb common.Database
processor types.BlockProcessor
eventMux *event.TypeMux
genesisBlock *types.Block
@@ -85,12 +83,10 @@ type ChainManager struct {
pow pow.PoW
}
-func NewChainManager(blockDb, stateDb, extraDb common.Database, pow pow.PoW, mux *event.TypeMux) (*ChainManager, error) {
+func NewChainManager(chainDb common.Database, pow pow.PoW, mux *event.TypeMux) (*ChainManager, error) {
cache, _ := lru.New(blockCacheLimit)
bc := &ChainManager{
- blockDb: blockDb,
- stateDb: stateDb,
- extraDb: extraDb,
+ chainDb: chainDb,
eventMux: mux,
quit: make(chan struct{}),
cache: cache,
@@ -103,7 +99,7 @@ func NewChainManager(blockDb, stateDb, extraDb common.Database, pow pow.PoW, mux
if err != nil {
return nil, err
}
- bc.genesisBlock, err = WriteGenesisBlock(stateDb, blockDb, reader)
+ bc.genesisBlock, err = WriteGenesisBlock(chainDb, reader)
if err != nil {
return nil, err
}
@@ -195,15 +191,15 @@ func (self *ChainManager) SetProcessor(proc types.BlockProcessor) {
}
func (self *ChainManager) State() *state.StateDB {
- return state.New(self.CurrentBlock().Root(), self.stateDb)
+ return state.New(self.CurrentBlock().Root(), self.chainDb)
}
func (bc *ChainManager) recover() bool {
- data, _ := bc.blockDb.Get([]byte("checkpoint"))
+ data, _ := bc.chainDb.Get([]byte("checkpoint"))
if len(data) != 0 {
block := bc.GetBlock(common.BytesToHash(data))
if block != nil {
- err := bc.blockDb.Put([]byte("LastBlock"), block.Hash().Bytes())
+ err := bc.chainDb.Put([]byte("LastBlock"), block.Hash().Bytes())
if err != nil {
glog.Fatalln("db write err:", err)
}
@@ -217,7 +213,7 @@ func (bc *ChainManager) recover() bool {
}
func (bc *ChainManager) setLastState() error {
- data, _ := bc.blockDb.Get([]byte("LastBlock"))
+ data, _ := bc.chainDb.Get([]byte("LastBlock"))
if len(data) != 0 {
block := bc.GetBlock(common.BytesToHash(data))
if block != nil {
@@ -264,7 +260,7 @@ func (bc *ChainManager) Reset() {
bc.cache, _ = lru.New(blockCacheLimit)
// Prepare the genesis block
- err := WriteBlock(bc.blockDb, bc.genesisBlock)
+ err := WriteBlock(bc.chainDb, bc.genesisBlock)
if err != nil {
glog.Fatalln("db err:", err)
}
@@ -277,7 +273,7 @@ func (bc *ChainManager) Reset() {
}
func (bc *ChainManager) removeBlock(block *types.Block) {
- bc.blockDb.Delete(append(blockHashPre, block.Hash().Bytes()...))
+ bc.chainDb.Delete(append(blockHashPre, block.Hash().Bytes()...))
}
func (bc *ChainManager) ResetWithGenesisBlock(gb *types.Block) {
@@ -292,7 +288,7 @@ func (bc *ChainManager) ResetWithGenesisBlock(gb *types.Block) {
gb.Td = gb.Difficulty()
bc.genesisBlock = gb
- err := WriteBlock(bc.blockDb, bc.genesisBlock)
+ err := WriteBlock(bc.chainDb, bc.genesisBlock)
if err != nil {
glog.Fatalln("db err:", err)
}
@@ -339,14 +335,14 @@ func (self *ChainManager) ExportN(w io.Writer, first uint64, last uint64) error
// insert injects a block into the current chain block chain. Note, this function
// assumes that the `mu` mutex is held!
func (bc *ChainManager) insert(block *types.Block) {
- err := WriteHead(bc.blockDb, block)
+ err := WriteHead(bc.chainDb, block)
if err != nil {
glog.Fatal("db write fail:", err)
}
bc.checkpoint++
if bc.checkpoint > checkpointLimit {
- err = bc.blockDb.Put([]byte("checkpoint"), block.Hash().Bytes())
+ err = bc.chainDb.Put([]byte("checkpoint"), block.Hash().Bytes())
if err != nil {
glog.Fatal("db write fail:", err)
}
@@ -369,7 +365,7 @@ func (bc *ChainManager) HasBlock(hash common.Hash) bool {
return true
}
- data, _ := bc.blockDb.Get(append(blockHashPre, hash[:]...))
+ data, _ := bc.chainDb.Get(append(blockHashPre, hash[:]...))
return len(data) != 0
}
@@ -399,7 +395,7 @@ func (self *ChainManager) GetBlock(hash common.Hash) *types.Block {
return block.(*types.Block)
}
- block := GetBlockByHash(self.blockDb, hash)
+ block := GetBlockByHash(self.chainDb, hash)
if block == nil {
return nil
}
@@ -433,7 +429,7 @@ func (self *ChainManager) GetBlocksFromHash(hash common.Hash, n int) (blocks []*
// non blocking version
func (self *ChainManager) getBlockByNumber(num uint64) *types.Block {
- return GetBlockByNumber(self.blockDb, num)
+ return GetBlockByNumber(self.chainDb, num)
}
func (self *ChainManager) GetUnclesInChain(block *types.Block, length int) (uncles []*types.Header) {
@@ -521,7 +517,7 @@ func (self *ChainManager) WriteBlock(block *types.Block, queued bool) (status wr
status = SideStatTy
}
- err = WriteBlock(self.blockDb, block)
+ err = WriteBlock(self.chainDb, block)
if err != nil {
glog.Fatalln("db err:", err)
}
@@ -638,9 +634,9 @@ func (self *ChainManager) InsertChain(chain types.Blocks) (int, error) {
queueEvent.canonicalCount++
// This puts transactions in a extra db for rpc
- PutTransactions(self.extraDb, block, block.Transactions())
+ PutTransactions(self.chainDb, block, block.Transactions())
// store the receipts
- PutReceipts(self.extraDb, receipts)
+ PutReceipts(self.chainDb, receipts)
case SideStatTy:
if glog.V(logger.Detail) {
glog.Infof("inserted forked block #%d (TD=%v) (%d TXs %d UNCs) (%x...). Took %v\n", block.Number(), block.Difficulty(), len(block.Transactions()), len(block.Uncles()), block.Hash().Bytes()[0:4], time.Since(bstart))
@@ -651,7 +647,7 @@ func (self *ChainManager) InsertChain(chain types.Blocks) (int, error) {
queue[i] = ChainSplitEvent{block, logs}
queueEvent.splitCount++
}
- PutBlockReceipts(self.extraDb, block, receipts)
+ PutBlockReceipts(self.chainDb, block, receipts)
stats.processed++
}
@@ -733,8 +729,8 @@ func (self *ChainManager) merge(oldBlock, newBlock *types.Block) error {
// insert the block in the canonical way, re-writing history
self.insert(block)
// write canonical receipts and transactions
- PutTransactions(self.extraDb, block, block.Transactions())
- PutReceipts(self.extraDb, GetBlockReceipts(self.extraDb, block.Hash()))
+ PutTransactions(self.chainDb, block, block.Transactions())
+ PutReceipts(self.chainDb, GetBlockReceipts(self.chainDb, block.Hash()))
}
self.mu.Unlock()
diff --git a/core/chain_manager_test.go b/core/chain_manager_test.go
index f0c097df6..002dcbe44 100644
--- a/core/chain_manager_test.go
+++ b/core/chain_manager_test.go
@@ -48,14 +48,14 @@ func thePow() pow.PoW {
func theChainManager(db common.Database, t *testing.T) *ChainManager {
var eventMux event.TypeMux
- WriteTestNetGenesisBlock(db, db, 0)
- chainMan, err := NewChainManager(db, db, db, thePow(), &eventMux)
+ WriteTestNetGenesisBlock(db, 0)
+ chainMan, err := NewChainManager(db, thePow(), &eventMux)
if err != nil {
t.Error("failed creating chainmanager:", err)
t.FailNow()
return nil
}
- blockMan := NewBlockProcessor(db, db, nil, chainMan, &eventMux)
+ blockMan := NewBlockProcessor(db, nil, chainMan, &eventMux)
chainMan.SetProcessor(blockMan)
return chainMan
@@ -125,7 +125,7 @@ func testChain(chainB types.Blocks, bman *BlockProcessor) (*big.Int, error) {
bman.bc.mu.Lock()
{
- WriteBlock(bman.bc.blockDb, block)
+ WriteBlock(bman.bc.chainDb, block)
}
bman.bc.mu.Unlock()
}
@@ -387,7 +387,7 @@ func makeChainWithDiff(genesis *types.Block, d []int, seed byte) []*types.Block
func chm(genesis *types.Block, db common.Database) *ChainManager {
var eventMux event.TypeMux
- bc := &ChainManager{extraDb: db, blockDb: db, stateDb: db, genesisBlock: genesis, eventMux: &eventMux, pow: FakePow{}}
+ bc := &ChainManager{chainDb: db, genesisBlock: genesis, eventMux: &eventMux, pow: FakePow{}}
bc.cache, _ = lru.New(100)
bc.futureBlocks, _ = lru.New(100)
bc.processor = bproc{}
@@ -399,7 +399,7 @@ func chm(genesis *types.Block, db common.Database) *ChainManager {
func TestReorgLongest(t *testing.T) {
db, _ := ethdb.NewMemDatabase()
- genesis, err := WriteTestNetGenesisBlock(db, db, 0)
+ genesis, err := WriteTestNetGenesisBlock(db, 0)
if err != nil {
t.Error(err)
t.FailNow()
@@ -422,7 +422,7 @@ func TestReorgLongest(t *testing.T) {
func TestReorgShortest(t *testing.T) {
db, _ := ethdb.NewMemDatabase()
- genesis, err := WriteTestNetGenesisBlock(db, db, 0)
+ genesis, err := WriteTestNetGenesisBlock(db, 0)
if err != nil {
t.Error(err)
t.FailNow()
@@ -446,13 +446,13 @@ func TestReorgShortest(t *testing.T) {
func TestInsertNonceError(t *testing.T) {
for i := 1; i < 25 && !t.Failed(); i++ {
db, _ := ethdb.NewMemDatabase()
- genesis, err := WriteTestNetGenesisBlock(db, db, 0)
+ genesis, err := WriteTestNetGenesisBlock(db, 0)
if err != nil {
t.Error(err)
t.FailNow()
}
bc := chm(genesis, db)
- bc.processor = NewBlockProcessor(db, db, bc.pow, bc, bc.eventMux)
+ bc.processor = NewBlockProcessor(db, bc.pow, bc, bc.eventMux)
blocks := makeChain(bc.currentBlock, i, db, 0)
fail := rand.Int() % len(blocks)
diff --git a/core/chain_util.go b/core/chain_util.go
index 34f6c8d0a..84b462ce3 100644
--- a/core/chain_util.go
+++ b/core/chain_util.go
@@ -32,7 +32,7 @@ import (
var (
blockHashPre = []byte("block-hash-")
blockNumPre = []byte("block-num-")
- expDiffPeriod = big.NewInt(100000)
+ ExpDiffPeriod = big.NewInt(100000)
)
// CalcDifficulty is the difficulty adjustment algorithm. It returns
@@ -57,7 +57,7 @@ func CalcDifficulty(time, parentTime uint64, parentNumber, parentDiff *big.Int)
}
periodCount := new(big.Int).Add(parentNumber, common.Big1)
- periodCount.Div(periodCount, expDiffPeriod)
+ periodCount.Div(periodCount, ExpDiffPeriod)
if periodCount.Cmp(common.Big1) > 0 {
// diff = diff + 2^(periodCount - 2)
expDiff := periodCount.Sub(periodCount, common.Big2)
diff --git a/core/genesis.go b/core/genesis.go
index 4c0323c17..97afb3a4a 100644
--- a/core/genesis.go
+++ b/core/genesis.go
@@ -33,7 +33,7 @@ import (
)
// WriteGenesisBlock writes the genesis block to the database as block number 0
-func WriteGenesisBlock(stateDb, blockDb common.Database, reader io.Reader) (*types.Block, error) {
+func WriteGenesisBlock(chainDb common.Database, reader io.Reader) (*types.Block, error) {
contents, err := ioutil.ReadAll(reader)
if err != nil {
return nil, err
@@ -59,7 +59,7 @@ func WriteGenesisBlock(stateDb, blockDb common.Database, reader io.Reader) (*typ
return nil, err
}
- statedb := state.New(common.Hash{}, stateDb)
+ statedb := state.New(common.Hash{}, chainDb)
for addr, account := range genesis.Alloc {
address := common.HexToAddress(addr)
statedb.AddBalance(address, common.String2Big(account.Balance))
@@ -84,9 +84,9 @@ func WriteGenesisBlock(stateDb, blockDb common.Database, reader io.Reader) (*typ
}, nil, nil, nil)
block.Td = difficulty
- if block := GetBlockByHash(blockDb, block.Hash()); block != nil {
+ if block := GetBlockByHash(chainDb, block.Hash()); block != nil {
glog.V(logger.Info).Infoln("Genesis block already in chain. Writing canonical number")
- err := WriteCanonNumber(blockDb, block)
+ err := WriteCanonNumber(chainDb, block)
if err != nil {
return nil, err
}
@@ -95,11 +95,11 @@ func WriteGenesisBlock(stateDb, blockDb common.Database, reader io.Reader) (*typ
statedb.Sync()
- err = WriteBlock(blockDb, block)
+ err = WriteBlock(chainDb, block)
if err != nil {
return nil, err
}
- err = WriteHead(blockDb, block)
+ err = WriteHead(chainDb, block)
if err != nil {
return nil, err
}
@@ -133,11 +133,11 @@ func WriteGenesisBlockForTesting(db common.Database, addr common.Address, balanc
"0x%x":{"balance":"0x%x"}
}
}`, types.EncodeNonce(0), params.GenesisGasLimit.Bytes(), params.GenesisDifficulty.Bytes(), addr, balance.Bytes())
- block, _ := WriteGenesisBlock(db, db, strings.NewReader(testGenesis))
+ block, _ := WriteGenesisBlock(db, strings.NewReader(testGenesis))
return block
}
-func WriteTestNetGenesisBlock(stateDb, blockDb common.Database, nonce uint64) (*types.Block, error) {
+func WriteTestNetGenesisBlock(chainDb common.Database, nonce uint64) (*types.Block, error) {
testGenesis := fmt.Sprintf(`{
"nonce":"0x%x",
"gasLimit":"0x%x",
@@ -157,5 +157,5 @@ func WriteTestNetGenesisBlock(stateDb, blockDb common.Database, nonce uint64) (*
"1a26338f0d905e295fccb71fa9ea849ffa12aaf4": {"balance": "1606938044258990275541962092341162602522202993782792835301376"}
}
}`, types.EncodeNonce(nonce), params.GenesisGasLimit.Bytes(), params.GenesisDifficulty.Bytes())
- return WriteGenesisBlock(stateDb, blockDb, strings.NewReader(testGenesis))
+ return WriteGenesisBlock(chainDb, strings.NewReader(testGenesis))
}
diff --git a/core/manager.go b/core/manager.go
index a07c32659..8b0401b03 100644
--- a/core/manager.go
+++ b/core/manager.go
@@ -28,8 +28,7 @@ type Backend interface {
BlockProcessor() *BlockProcessor
ChainManager() *ChainManager
TxPool() *TxPool
- BlockDb() common.Database
- StateDb() common.Database
- ExtraDb() common.Database
+ ChainDb() common.Database
+ DappDb() common.Database
EventMux() *event.TypeMux
}
diff --git a/core/vm/instructions.go b/core/vm/instructions.go
index 6b7b41220..2de35a443 100644
--- a/core/vm/instructions.go
+++ b/core/vm/instructions.go
@@ -341,19 +341,19 @@ func opCoinbase(instr instruction, env Environment, context *Context, memory *Me
}
func opTimestamp(instr instruction, env Environment, context *Context, memory *Memory, stack *stack) {
- stack.push(new(big.Int).SetUint64(env.Time()))
+ stack.push(U256(new(big.Int).SetUint64(env.Time())))
}
func opNumber(instr instruction, env Environment, context *Context, memory *Memory, stack *stack) {
- stack.push(U256(env.BlockNumber()))
+ stack.push(U256(new(big.Int).Set(env.BlockNumber())))
}
func opDifficulty(instr instruction, env Environment, context *Context, memory *Memory, stack *stack) {
- stack.push(new(big.Int).Set(env.Difficulty()))
+ stack.push(U256(new(big.Int).Set(env.Difficulty())))
}
func opGasLimit(instr instruction, env Environment, context *Context, memory *Memory, stack *stack) {
- stack.push(new(big.Int).Set(env.GasLimit()))
+ stack.push(U256(new(big.Int).Set(env.GasLimit())))
}
func opPop(instr instruction, env Environment, context *Context, memory *Memory, stack *stack) {
@@ -415,15 +415,12 @@ func opSstore(instr instruction, env Environment, context *Context, memory *Memo
env.State().SetState(context.Address(), loc, common.BigToHash(val))
}
-func opJump(instr instruction, env Environment, context *Context, memory *Memory, stack *stack) {
-}
-func opJumpi(instr instruction, env Environment, context *Context, memory *Memory, stack *stack) {
-}
-func opJumpdest(instr instruction, env Environment, context *Context, memory *Memory, stack *stack) {
-}
+func opJump(instr instruction, env Environment, context *Context, memory *Memory, stack *stack) {}
+func opJumpi(instr instruction, env Environment, context *Context, memory *Memory, stack *stack) {}
+func opJumpdest(instr instruction, env Environment, context *Context, memory *Memory, stack *stack) {}
func opPc(instr instruction, env Environment, context *Context, memory *Memory, stack *stack) {
- stack.push(instr.data)
+ stack.push(new(big.Int).Set(instr.data))
}
func opMsize(instr instruction, env Environment, context *Context, memory *Memory, stack *stack) {
diff --git a/core/vm/jit.go b/core/vm/jit.go
index d5c2d7830..084d2a3f3 100644
--- a/core/vm/jit.go
+++ b/core/vm/jit.go
@@ -83,6 +83,7 @@ type Program struct {
code []byte
}
+// NewProgram returns a new JIT program
func NewProgram(code []byte) *Program {
program := &Program{
Id: crypto.Sha3Hash(code),
@@ -113,6 +114,7 @@ func (p *Program) addInstr(op OpCode, pc uint64, fn instrFn, data *big.Int) {
p.mapping[pc] = len(p.instructions) - 1
}
+// CompileProgram compiles the given program and return an error when it fails
func CompileProgram(program *Program) (err error) {
if progStatus(atomic.LoadInt32(&program.status)) == progCompile {
return nil
@@ -272,6 +274,8 @@ func CompileProgram(program *Program) (err error) {
return nil
}
+// RunProgram runs the program given the enviroment and context and returns an
+// error if the execution failed (non-consensus)
func RunProgram(program *Program, env Environment, context *Context, input []byte) ([]byte, error) {
return runProgram(program, 0, NewMemory(), newstack(), env, context, input)
}
@@ -352,6 +356,8 @@ func runProgram(program *Program, pcstart uint64, mem *Memory, stack *stack, env
pc++
}
+ context.Input = nil
+
return context.Return(nil), nil
}
diff --git a/core/vm/jit_test.go b/core/vm/jit_test.go
index 5b3feea99..b9e2c6999 100644
--- a/core/vm/jit_test.go
+++ b/core/vm/jit_test.go
@@ -46,7 +46,7 @@ func runVmBench(test vmBench, b *testing.B) {
}
env := NewEnv()
- DisableJit = test.nojit
+ EnableJit = !test.nojit
ForceJit = test.forcejit
b.ResetTimer()
diff --git a/core/vm/settings.go b/core/vm/settings.go
index 0cd931b6a..f9296f6c8 100644
--- a/core/vm/settings.go
+++ b/core/vm/settings.go
@@ -17,9 +17,9 @@
package vm
var (
- DisableJit bool = true // Disable the JIT VM
- ForceJit bool // Force the JIT, skip byte VM
- MaxProgSize int // Max cache size for JIT Programs
+ EnableJit bool // Enables the JIT VM
+ ForceJit bool // Force the JIT, skip byte VM
+ MaxProgSize int // Max cache size for JIT Programs
)
const defaultJitMaxCache int = 64
diff --git a/core/vm/vm.go b/core/vm/vm.go
index c292b45d1..da764004a 100644
--- a/core/vm/vm.go
+++ b/core/vm/vm.go
@@ -64,7 +64,7 @@ func (self *Vm) Run(context *Context, input []byte) (ret []byte, err error) {
codehash = crypto.Sha3Hash(context.Code) // codehash is used when doing jump dest caching
program *Program
)
- if !DisableJit {
+ if EnableJit {
// Fetch program status.
// * If ready run using JIT
// * If unknown, compile in a seperate goroutine