aboutsummaryrefslogtreecommitdiffstats
path: root/ethchain/state_manager.go
diff options
context:
space:
mode:
authorzelig <viktor.tron@gmail.com>2014-07-31 00:03:20 +0800
committerzelig <viktor.tron@gmail.com>2014-07-31 00:03:20 +0800
commit9831619881c5264c2449ce1b906108d892b6e1e1 (patch)
treef8775b1196fe6b31081a553945377f40bdc8d550 /ethchain/state_manager.go
parent194c58858cd230a9a08b0eb14650720341a5580e (diff)
parent42d47ecfb09ac0b419db5722602d9b02e21f2457 (diff)
downloaddexon-9831619881c5264c2449ce1b906108d892b6e1e1.tar.gz
dexon-9831619881c5264c2449ce1b906108d892b6e1e1.tar.zst
dexon-9831619881c5264c2449ce1b906108d892b6e1e1.zip
merge upstream
Diffstat (limited to 'ethchain/state_manager.go')
-rw-r--r--ethchain/state_manager.go36
1 files changed, 17 insertions, 19 deletions
diff --git a/ethchain/state_manager.go b/ethchain/state_manager.go
index f65bf683a..226b2fe73 100644
--- a/ethchain/state_manager.go
+++ b/ethchain/state_manager.go
@@ -7,6 +7,7 @@ import (
"github.com/ethereum/eth-go/ethcrypto"
"github.com/ethereum/eth-go/ethlog"
"github.com/ethereum/eth-go/ethreact"
+ "github.com/ethereum/eth-go/ethstate"
"github.com/ethereum/eth-go/ethutil"
"github.com/ethereum/eth-go/ethwire"
"math/big"
@@ -50,8 +51,6 @@ type StateManager struct {
mutex sync.Mutex
// Canonical block chain
bc *BlockChain
- // Stack for processing contracts
- stack *Stack
// non-persistent key/value memory storage
mem map[string]*big.Int
// Proof of work used for validating
@@ -62,10 +61,10 @@ type StateManager struct {
// Transiently state. The trans state isn't ever saved, validated and
// it could be used for setting account nonces without effecting
// the main states.
- transState *State
+ transState *ethstate.State
// Mining state. The mining state is used purely and solely by the mining
// operation.
- miningState *State
+ miningState *ethstate.State
// The last attempted block is mainly used for debugging purposes
// This does not have to be a valid block and will be set during
@@ -75,7 +74,6 @@ type StateManager struct {
func NewStateManager(ethereum EthManager) *StateManager {
sm := &StateManager{
- stack: NewStack(),
mem: make(map[string]*big.Int),
Pow: &EasyPow{},
Ethereum: ethereum,
@@ -87,19 +85,19 @@ func NewStateManager(ethereum EthManager) *StateManager {
return sm
}
-func (sm *StateManager) CurrentState() *State {
+func (sm *StateManager) CurrentState() *ethstate.State {
return sm.Ethereum.BlockChain().CurrentBlock.State()
}
-func (sm *StateManager) TransState() *State {
+func (sm *StateManager) TransState() *ethstate.State {
return sm.transState
}
-func (sm *StateManager) MiningState() *State {
+func (sm *StateManager) MiningState() *ethstate.State {
return sm.miningState
}
-func (sm *StateManager) NewMiningState() *State {
+func (sm *StateManager) NewMiningState() *ethstate.State {
sm.miningState = sm.Ethereum.BlockChain().CurrentBlock.State().Copy()
return sm.miningState
@@ -109,7 +107,7 @@ func (sm *StateManager) BlockChain() *BlockChain {
return sm.bc
}
-func (self *StateManager) ProcessTransactions(coinbase *StateObject, state *State, block, parent *Block, txs Transactions) (Receipts, Transactions, Transactions, error) {
+func (self *StateManager) ProcessTransactions(coinbase *ethstate.StateObject, state *ethstate.State, block, parent *Block, txs Transactions) (Receipts, Transactions, Transactions, error) {
var (
receipts Receipts
handled, unhandled Transactions
@@ -123,9 +121,9 @@ done:
cb := state.GetStateObject(coinbase.Address())
st := NewStateTransition(cb, tx, state, block)
- //fmt.Printf("#%d\n", i+1)
err = st.TransitionState()
if err != nil {
+ statelogger.Infoln(err)
switch {
case IsNonceErr(err):
err = nil // ignore error
@@ -225,7 +223,7 @@ func (sm *StateManager) Process(block *Block, dontReact bool) (err error) {
}
if !block.State().Cmp(state) {
- err = fmt.Errorf("Invalid merkle root.\nrec: %x\nis: %x", block.State().trie.Root, state.trie.Root)
+ err = fmt.Errorf("Invalid merkle root.\nrec: %x\nis: %x", block.State().Trie.Root, state.Trie.Root)
return
}
@@ -242,7 +240,7 @@ func (sm *StateManager) Process(block *Block, dontReact bool) (err error) {
if dontReact == false {
sm.Ethereum.Reactor().Post("newBlock", block)
- state.manifest.Reset()
+ state.Manifest().Reset()
}
sm.Ethereum.Broadcast(ethwire.MsgBlockTy, []interface{}{block.Value().Val})
@@ -255,7 +253,7 @@ func (sm *StateManager) Process(block *Block, dontReact bool) (err error) {
return nil
}
-func (sm *StateManager) ApplyDiff(state *State, parent, block *Block) (receipts Receipts, err error) {
+func (sm *StateManager) ApplyDiff(state *ethstate.State, parent, block *Block) (receipts Receipts, err error) {
coinbase := state.GetOrNewStateObject(block.Coinbase)
coinbase.SetGasPool(block.CalcGasLimit(parent))
@@ -340,7 +338,7 @@ func CalculateUncleReward(block *Block) *big.Int {
return UncleReward
}
-func (sm *StateManager) AccumelateRewards(state *State, block *Block) error {
+func (sm *StateManager) AccumelateRewards(state *ethstate.State, block *Block) error {
// Get the account associated with the coinbase
account := state.GetAccount(block.Coinbase)
// Reward amount of ether to the coinbase address
@@ -364,14 +362,14 @@ func (sm *StateManager) Stop() {
sm.bc.Stop()
}
-func (sm *StateManager) notifyChanges(state *State) {
- for addr, stateObject := range state.manifest.objectChanges {
+func (sm *StateManager) notifyChanges(state *ethstate.State) {
+ for addr, stateObject := range state.Manifest().ObjectChanges {
sm.Ethereum.Reactor().Post("object:"+addr, stateObject)
}
- for stateObjectAddr, mappedObjects := range state.manifest.storageChanges {
+ for stateObjectAddr, mappedObjects := range state.Manifest().StorageChanges {
for addr, value := range mappedObjects {
- sm.Ethereum.Reactor().Post("storage:"+stateObjectAddr+":"+addr, &StorageState{[]byte(stateObjectAddr), []byte(addr), value})
+ sm.Ethereum.Reactor().Post("storage:"+stateObjectAddr+":"+addr, &ethstate.StorageState{[]byte(stateObjectAddr), []byte(addr), value})
}
}
}