diff options
author | obscuren <geffobscura@gmail.com> | 2014-05-21 17:42:20 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2014-05-21 17:42:20 +0800 |
commit | cbf221f6b7a48ece543d6141d8a7e9dbf9b8d86d (patch) | |
tree | f94c450b2213bfecba7c102cd247ff98f70ea5f6 | |
parent | 734b2e4cf7a2e6ed3ab0815b795730c62e235a6b (diff) | |
download | go-tangerine-cbf221f6b7a48ece543d6141d8a7e9dbf9b8d86d.tar go-tangerine-cbf221f6b7a48ece543d6141d8a7e9dbf9b8d86d.tar.gz go-tangerine-cbf221f6b7a48ece543d6141d8a7e9dbf9b8d86d.tar.bz2 go-tangerine-cbf221f6b7a48ece543d6141d8a7e9dbf9b8d86d.tar.lz go-tangerine-cbf221f6b7a48ece543d6141d8a7e9dbf9b8d86d.tar.xz go-tangerine-cbf221f6b7a48ece543d6141d8a7e9dbf9b8d86d.tar.zst go-tangerine-cbf221f6b7a48ece543d6141d8a7e9dbf9b8d86d.zip |
Fixed competing block method
-rw-r--r-- | ethchain/state_manager.go | 15 | ||||
-rw-r--r-- | ethminer/miner.go | 2 | ||||
-rw-r--r-- | peer.go | 4 |
3 files changed, 16 insertions, 5 deletions
diff --git a/ethchain/state_manager.go b/ethchain/state_manager.go index 27eaa5e60..8c442cf44 100644 --- a/ethchain/state_manager.go +++ b/ethchain/state_manager.go @@ -132,8 +132,19 @@ func (sm *StateManager) ApplyTransaction(state *State, block *Block, tx *Transac } } +func (sm *StateManager) Process(block *Block, dontReact bool) error { + if !sm.bc.HasBlock(block.PrevHash) { + return ParentError(block.PrevHash) + } + + parent := sm.bc.GetBlock(block.PrevHash) + + return sm.ProcessBlock(parent.State(), parent, block, dontReact) + +} + // Block processing and validating with a given (temporarily) state -func (sm *StateManager) ProcessBlock(state *State, block *Block, dontReact bool) error { +func (sm *StateManager) ProcessBlock(state *State, parent, block *Block, dontReact bool) error { // Processing a blocks may never happen simultaneously sm.mutex.Lock() defer sm.mutex.Unlock() @@ -186,7 +197,7 @@ func (sm *StateManager) ProcessBlock(state *State, block *Block, dontReact bool) sm.bc.Add(block) sm.notifyChanges(state) - ethutil.Config.Log.Infof("[STATE] Added block #%d (%x)\n", block.BlockInfo().Number, block.Hash()) + ethutil.Config.Log.Infof("[STATE] Added block #%d (%x)\n", block.Number, block.Hash()) if dontReact == false { sm.Ethereum.Reactor().Post("newBlock", block) diff --git a/ethminer/miner.go b/ethminer/miner.go index 26b28d82f..e052d0207 100644 --- a/ethminer/miner.go +++ b/ethminer/miner.go @@ -126,7 +126,7 @@ func (miner *Miner) listener() { // Search the nonce miner.block.Nonce = miner.pow.Search(miner.block, miner.quitChan) if miner.block.Nonce != nil { - err := miner.ethereum.StateManager().ProcessBlock(miner.ethereum.StateManager().CurrentState(), miner.block, true) + err := miner.ethereum.StateManager().Process(miner.block, true) if err != nil { ethutil.Config.Log.Infoln(err) miner.txs = []*ethchain.Transaction{} // Move this somewhere neat @@ -335,8 +335,8 @@ func (p *Peer) HandleInbound() { block = ethchain.NewBlockFromRlpValue(msg.Data.Get(i)) //p.ethereum.StateManager().PrepareDefault(block) - state := p.ethereum.StateManager().CurrentState() - err = p.ethereum.StateManager().ProcessBlock(state, block, false) + //state := p.ethereum.StateManager().CurrentState() + err = p.ethereum.StateManager().Process(block, false) if err != nil { if ethutil.Config.Debug { |