Initial block reorganisation code

This commit is contained in:
Maran
2014-03-21 15:06:23 +01:00
parent ae837c4719
commit b52b1fca89
4 changed files with 210 additions and 31 deletions

View File

@ -61,10 +61,10 @@ func (miner *Miner) listener() {
select {
case chanMessage := <-miner.reactChan:
if block, ok := chanMessage.Resource.(*ethchain.Block); ok {
log.Println("[miner] Got new block via Reactor")
log.Println("[MINER] Got new block via Reactor")
if bytes.Compare(miner.ethereum.BlockChain().CurrentBlock.Hash(), block.Hash()) == 0 {
// TODO: Perhaps continue mining to get some uncle rewards
log.Println("[miner] New top block found resetting state")
log.Println("[MINER] New top block found resetting state")
// Filter out which Transactions we have that were not in this block
var newtxs []*ethchain.Transaction
@ -86,7 +86,7 @@ func (miner *Miner) listener() {
} else {
if bytes.Compare(block.PrevHash, miner.ethereum.BlockChain().CurrentBlock.PrevHash) == 0 {
log.Println("[miner] Adding uncle block")
log.Println("[MINER] Adding uncle block")
miner.uncles = append(miner.uncles, block)
miner.ethereum.StateManager().Prepare(miner.block.State(), miner.block.State())
}
@ -94,7 +94,7 @@ func (miner *Miner) listener() {
}
if tx, ok := chanMessage.Resource.(*ethchain.Transaction); ok {
log.Println("[miner] Got new transaction from Reactor", tx)
log.Println("[MINER] Got new transaction from Reactor", tx)
found := false
for _, ctx := range miner.txs {
if found = bytes.Compare(ctx.Hash(), tx.Hash()) == 0; found {
@ -103,15 +103,15 @@ func (miner *Miner) listener() {
}
if found == false {
log.Println("[miner] We did not know about this transaction, adding")
log.Println("[MINER] We did not know about this transaction, adding")
miner.txs = append(miner.txs, tx)
miner.block.SetTransactions(miner.txs)
} else {
log.Println("[miner] We already had this transaction, ignoring")
log.Println("[MINER] We already had this transaction, ignoring")
}
}
default:
log.Println("[miner] Mining on block. Includes", len(miner.txs), "transactions")
log.Println("[MINER] Mining on block. Includes", len(miner.txs), "transactions")
// Apply uncles
if len(miner.uncles) > 0 {
@ -123,7 +123,7 @@ func (miner *Miner) listener() {
miner.ethereum.StateManager().AccumelateRewards(miner.block)
// Search the nonce
log.Println("[miner] Initialision complete, starting mining")
log.Println("[MINER] Initialision complete, starting mining")
miner.block.Nonce = miner.pow.Search(miner.block, miner.quitChan)
if miner.block.Nonce != nil {
miner.ethereum.StateManager().PrepareDefault(miner.block)
@ -137,8 +137,7 @@ func (miner *Miner) listener() {
log.Printf("Second stage verification error: Block's nonce is invalid (= %v)\n", ethutil.Hex(miner.block.Nonce))
}
miner.ethereum.Broadcast(ethwire.MsgBlockTy, []interface{}{miner.block.Value().Val})
log.Printf("[miner] 🔨 Mined block %x\n", miner.block.Hash())
log.Println(miner.block)
log.Printf("[MINER] 🔨 Mined block %x\n", miner.block.Hash())
miner.txs = []*ethchain.Transaction{} // Move this somewhere neat
miner.block = miner.ethereum.BlockChain().NewBlock(miner.coinbase, miner.txs)