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
This commit is contained in:
@@ -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 {
|
||||
|
@@ -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
|
||||
}
|
||||
|
@@ -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()
|
||||
}
|
||||
|
Reference in New Issue
Block a user