diff options
author | obscuren <geffobscura@gmail.com> | 2015-02-27 01:39:05 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2015-02-27 01:39:05 +0800 |
commit | 37e6870f64437a212fde383ab1538ad1e7e2acd9 (patch) | |
tree | fbcd0c11c1ca9931a6a8f6c74ae02340cb097bb2 | |
parent | a1c830cd3c53bce7748d97e3f99fe6a90d526adb (diff) | |
download | go-tangerine-37e6870f64437a212fde383ab1538ad1e7e2acd9.tar.gz go-tangerine-37e6870f64437a212fde383ab1538ad1e7e2acd9.tar.zst go-tangerine-37e6870f64437a212fde383ab1538ad1e7e2acd9.zip |
wip
-rw-r--r-- | core/block_processor.go | 10 | ||||
-rw-r--r-- | core/state_transition.go | 4 | ||||
-rw-r--r-- | miner/worker.go | 4 | ||||
-rw-r--r-- | state/dump.go | 2 | ||||
-rw-r--r-- | state/state_object.go | 21 | ||||
-rw-r--r-- | vm/vm.go | 4 |
6 files changed, 29 insertions, 16 deletions
diff --git a/core/block_processor.go b/core/block_processor.go index f66d158b2..5e943bda5 100644 --- a/core/block_processor.go +++ b/core/block_processor.go @@ -48,9 +48,8 @@ type BlockProcessor struct { func NewBlockProcessor(db ethutil.Database, txpool *TxPool, chainManager *ChainManager, eventMux *event.TypeMux) *BlockProcessor { sm := &BlockProcessor{ - db: db, - mem: make(map[string]*big.Int), - //Pow: ðash.Ethash{}, + db: db, + mem: make(map[string]*big.Int), Pow: ezp.New(), bc: chainManager, eventMux: eventMux, @@ -100,7 +99,8 @@ func (self *BlockProcessor) ApplyTransaction(coinbase *state.StateObject, stated // Notify all subscribers if !transientProcess { go self.eventMux.Post(TxPostEvent{tx}) - go self.eventMux.Post(statedb.Logs()) + logs := statedb.Logs() + go self.eventMux.Post(logs) } return receipt, txGas, err @@ -205,6 +205,8 @@ func (sm *BlockProcessor) processWithParent(block, parent *types.Block) (td *big receiptSha := types.DeriveSha(receipts) if bytes.Compare(receiptSha, header.ReceiptHash) != 0 { fmt.Println("receipts", receipts) + state.Sync() + chainlogger.Infof("%s\n", state.Dump()) err = fmt.Errorf("validating receipt root. received=%x got=%x", header.ReceiptHash, receiptSha) return } diff --git a/core/state_transition.go b/core/state_transition.go index 36ffa23d9..7331fdd4a 100644 --- a/core/state_transition.go +++ b/core/state_transition.go @@ -126,7 +126,7 @@ func (self *StateTransition) BuyGas() error { self.AddGas(self.msg.Gas()) self.initialGas.Set(self.msg.Gas()) - sender.SubAmount(MessageGasValue(self.msg)) + sender.SubBalance(MessageGasValue(self.msg)) return nil } @@ -251,7 +251,7 @@ func (self *StateTransition) RefundGas() { coinbase, sender := self.Coinbase(), self.From() // Return remaining gas remaining := new(big.Int).Mul(self.gas, self.msg.GasPrice()) - sender.AddAmount(remaining) + sender.AddBalance(remaining) uhalf := new(big.Int).Div(self.GasUsed(), ethutil.Big2) for addr, ref := range self.state.Refunds() { diff --git a/miner/worker.go b/miner/worker.go index 1f3a52ab5..4f0909302 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -197,7 +197,7 @@ gasLimit: } self.eth.TxPool().RemoveSet(remove) - self.current.coinbase.AddAmount(core.BlockReward) + self.current.coinbase.AddBalance(core.BlockReward) self.current.state.Update(ethutil.Big0) self.push() @@ -225,7 +225,7 @@ func (self *worker) commitUncle(uncle *types.Header) error { } uncleAccount := self.current.state.GetAccount(uncle.Coinbase) - uncleAccount.AddAmount(uncleReward) + uncleAccount.AddBalance(uncleReward) self.current.coinbase.AddBalance(uncleReward) diff --git a/state/dump.go b/state/dump.go index 81895f1a3..073f89414 100644 --- a/state/dump.go +++ b/state/dump.go @@ -35,7 +35,7 @@ func (self *StateDB) Dump() []byte { storageIt := stateObject.State.trie.Iterator() for storageIt.Next() { - account.Storage[ethutil.Bytes2Hex(it.Key)] = ethutil.Bytes2Hex(it.Value) + account.Storage[ethutil.Bytes2Hex(storageIt.Key)] = ethutil.Bytes2Hex(storageIt.Value) } world.Accounts[ethutil.Bytes2Hex(it.Key)] = account } diff --git a/state/state_object.go b/state/state_object.go index 477b912a1..487952a02 100644 --- a/state/state_object.go +++ b/state/state_object.go @@ -19,6 +19,14 @@ func (self Code) String() string { type Storage map[string]*ethutil.Value +func (self Storage) String() (str string) { + for key, value := range self { + str += fmt.Sprintf("%X : %X\n", key, value.Bytes()) + } + + return +} + func (self Storage) Copy() Storage { cpy := make(Storage) for key, value := range self { @@ -119,10 +127,9 @@ func (self *StateObject) GetStorage(key *big.Int) *ethutil.Value { } func (self *StateObject) SetStorage(key *big.Int, value *ethutil.Value) { self.SetState(key.Bytes(), value) - self.dirty = true } -func (self *StateObject) Storage() map[string]*ethutil.Value { +func (self *StateObject) Storage() Storage { return self.storage } @@ -172,20 +179,22 @@ func (c *StateObject) AddBalance(amount *big.Int) { statelogger.Debugf("%x: #%d %v (+ %v)\n", c.Address(), c.nonce, c.balance, amount) } -func (c *StateObject) AddAmount(amount *big.Int) { c.AddBalance(amount) } func (c *StateObject) SubBalance(amount *big.Int) { c.SetBalance(new(big.Int).Sub(c.balance, amount)) statelogger.Debugf("%x: #%d %v (- %v)\n", c.Address(), c.nonce, c.balance, amount) } -func (c *StateObject) SubAmount(amount *big.Int) { c.SubBalance(amount) } func (c *StateObject) SetBalance(amount *big.Int) { c.balance = amount c.dirty = true } +func (c *StateObject) St() Storage { + return c.storage +} + // // Gas setters and getters // @@ -198,7 +207,7 @@ func (c *StateObject) ConvertGas(gas, price *big.Int) error { return fmt.Errorf("insufficient amount: %v, %v", c.balance, total) } - c.SubAmount(total) + c.SubBalance(total) c.dirty = true @@ -221,7 +230,7 @@ func (self *StateObject) BuyGas(gas, price *big.Int) error { rGas := new(big.Int).Set(gas) rGas.Mul(rGas, price) - self.AddAmount(rGas) + self.AddBalance(rGas) self.dirty = true @@ -54,6 +54,8 @@ func (self *Vm) Run(me, caller ContextRef, code []byte, value, gas, price *big.I err = fmt.Errorf("%v", r) + } else { + fmt.Println(me.(*state.StateObject).Storage()) } }() } @@ -727,7 +729,7 @@ func (self *Vm) Run(me, caller ContextRef, code []byte, value, gas, price *big.I self.Printf(" => (%x) %v", receiver.Address()[:4], balance) - receiver.AddAmount(balance) + receiver.AddBalance(balance) statedb.Delete(context.Address()) fallthrough |