diff options
author | obscuren <geffobscura@gmail.com> | 2014-11-07 19:18:48 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2014-11-07 19:18:48 +0800 |
commit | 429dd2a100f3b9e2b612b59bcb48f79a805cd6f9 (patch) | |
tree | c91fee673e461a192d4d783193c8ddbead4a97d2 /chain | |
parent | 48488017e498916c81122c01cfe1880afdd00d48 (diff) | |
download | dexon-429dd2a100f3b9e2b612b59bcb48f79a805cd6f9.tar.gz dexon-429dd2a100f3b9e2b612b59bcb48f79a805cd6f9.tar.zst dexon-429dd2a100f3b9e2b612b59bcb48f79a805cd6f9.zip |
Implemented new miner w/ ui interface for merged mining. Closes #177
* Miner has been rewritten
* Added new miner pane
* Added option for local txs
* Added option to read from MergeMining contract and list them for
merged mining
Diffstat (limited to 'chain')
-rw-r--r-- | chain/block_manager.go | 16 | ||||
-rw-r--r-- | chain/chain_manager.go | 34 | ||||
-rw-r--r-- | chain/dagger.go | 3 |
3 files changed, 40 insertions, 13 deletions
diff --git a/chain/block_manager.go b/chain/block_manager.go index ed2fbfe8c..79c18fbe3 100644 --- a/chain/block_manager.go +++ b/chain/block_manager.go @@ -228,7 +228,7 @@ func (sm *BlockManager) Process(block *Block) (td *big.Int, err error) { func (sm *BlockManager) ProcessWithParent(block, parent *Block) (td *big.Int, err error) { sm.lastAttemptedBlock = block - state := parent.State() + state := parent.State().Copy() // Defer the Undo on the Trie. If the block processing happened // we don't want to undo but since undo only happens on dirty @@ -240,20 +240,22 @@ func (sm *BlockManager) ProcessWithParent(block, parent *Block) (td *big.Int, er fmt.Printf("## %x %x ##\n", block.Hash(), block.Number) } + _, err = sm.ApplyDiff(state, parent, block) + if err != nil { + return nil, err + } + + /* Go and C++ don't have consensus here. FIXME txSha := DeriveSha(block.transactions) if bytes.Compare(txSha, block.TxSha) != 0 { return nil, fmt.Errorf("Error validating transaction sha. Received %x, got %x", block.TxSha, txSha) } - receipts, err := sm.ApplyDiff(state, parent, block) - if err != nil { - return nil, err - } - receiptSha := DeriveSha(receipts) if bytes.Compare(receiptSha, block.ReceiptSha) != 0 { return nil, fmt.Errorf("Error validating receipt sha. Received %x, got %x", block.ReceiptSha, receiptSha) } + */ // Block validation if err = sm.ValidateBlock(block, parent); err != nil { @@ -374,7 +376,7 @@ func (sm *BlockManager) AccumelateRewards(state *state.State, block, parent *Blo uncleParent := sm.bc.GetBlock(uncle.PrevHash) if uncleParent == nil { - return UncleError("Uncle's parent unknown") + return UncleError(fmt.Sprintf("Uncle's parent unknown (%x)", uncle.PrevHash[0:4])) } if uncleParent.Number.Cmp(new(big.Int).Sub(parent.Number, big.NewInt(6))) < 0 { diff --git a/chain/chain_manager.go b/chain/chain_manager.go index 31f5f7543..5e62e6771 100644 --- a/chain/chain_manager.go +++ b/chain/chain_manager.go @@ -23,6 +23,8 @@ type ChainManager struct { CurrentBlock *Block LastBlockHash []byte + + workingChain *BlockChain } func NewChainManager(ethereum EthManager) *ChainManager { @@ -225,9 +227,18 @@ func (self *ChainManager) CalcTotalDiff(block *Block) (*big.Int, error) { return td, nil } -func (bc *ChainManager) GetBlock(hash []byte) *Block { +func (self *ChainManager) GetBlock(hash []byte) *Block { data, _ := ethutil.Config.Db.Get(hash) if len(data) == 0 { + if self.workingChain != nil { + // Check the temp chain + for e := self.workingChain.Front(); e != nil; e = e.Next() { + if bytes.Compare(e.Value.(*link).block.Hash(), hash) == 0 { + return e.Value.(*link).block + } + } + } + return nil } @@ -310,6 +321,7 @@ func NewChain(blocks Blocks) *BlockChain { } // This function assumes you've done your checking. No checking is done at this stage anymore +/* func (self *ChainManager) InsertChain(chain *BlockChain) { for e := chain.Front(); e != nil; e = e.Next() { link := e.Value.(*link) @@ -318,8 +330,11 @@ func (self *ChainManager) InsertChain(chain *BlockChain) { self.add(link.block) } } +*/ + +func (self *ChainManager) TestChain(chain *BlockChain, imp bool) (td *big.Int, err error) { + self.workingChain = chain -func (self *ChainManager) TestChain(chain *BlockChain) (td *big.Int, err error) { for e := chain.Front(); e != nil; e = e.Next() { var ( l = e.Value.(*link) @@ -348,12 +363,21 @@ func (self *ChainManager) TestChain(chain *BlockChain) (td *big.Int, err error) return } l.td = td + + if imp { + self.SetTotalDifficulty(td) + self.add(block) + } } - if td.Cmp(self.TD) <= 0 { - err = &TDError{td, self.TD} - return + if !imp { + if td.Cmp(self.TD) <= 0 { + err = &TDError{td, self.TD} + return + } } + self.workingChain = nil + return } diff --git a/chain/dagger.go b/chain/dagger.go index 3333e002d..2cf70e091 100644 --- a/chain/dagger.go +++ b/chain/dagger.go @@ -47,6 +47,7 @@ func (pow *EasyPow) Search(block *Block, stop <-chan struct{}) []byte { select { case <-stop: powlogger.Infoln("Breaking from mining") + pow.HashRate = 0 return nil default: i++ @@ -55,7 +56,7 @@ func (pow *EasyPow) Search(block *Block, stop <-chan struct{}) []byte { elapsed := time.Now().UnixNano() - start hashes := ((float64(1e9) / float64(elapsed)) * float64(i)) / 1000 pow.HashRate = int64(hashes) - powlogger.Infoln("Hashing @", int64(pow.HashRate), "khash") + powlogger.Infoln("Hashing @", pow.HashRate, "khash") t = time.Now() } |