Fixed bloom, updated mining & block processing

* Reverted back to process blocks in batches method
* Bloom generation and lookup fix
* Minor UI changed (mainly debug)
This commit is contained in:
obscuren 2014-11-10 01:17:31 +01:00
parent f538ea25e4
commit cbeebcd47d
14 changed files with 76 additions and 57 deletions

View File

@ -317,7 +317,7 @@ out:
chainManager := self.eth.ChainManager() chainManager := self.eth.ChainManager()
// Test and import // Test and import
chain := chain.NewChain(blocks) chain := chain.NewChain(blocks)
_, err := chainManager.TestChain(chain, true) _, err := chainManager.TestChain(chain)
if err != nil { if err != nil {
poollogger.Debugln(err) poollogger.Debugln(err)
@ -330,7 +330,7 @@ out:
self.td = ethutil.Big0 self.td = ethutil.Big0
self.peer = nil self.peer = nil
} else { } else {
//chainManager.InsertChain(chain) chainManager.InsertChain(chain)
for _, block := range blocks { for _, block := range blocks {
self.Remove(block.Hash()) self.Remove(block.Hash())
} }

View File

@ -21,18 +21,18 @@ func CreateBloom(block *Block) []byte {
func LogsBloom(logs state.Logs) *big.Int { func LogsBloom(logs state.Logs) *big.Int {
bin := new(big.Int) bin := new(big.Int)
for _, log := range logs { for _, log := range logs {
data := [][]byte{crypto.Sha3(log.Address)} data := [][]byte{log.Address}
for _, topic := range log.Topics { for _, topic := range log.Topics {
data = append(data, topic) data = append(data, topic)
} }
if log.Data != nil { for _, b := range data {
data = append(data, log.Data) bin.Or(bin, ethutil.BigD(bloom9(crypto.Sha3(b)).Bytes()))
} }
for _, b := range data { //if log.Data != nil {
bin.Or(bin, bloom9(b)) // data = append(data, log.Data)
} //}
} }
return bin return bin
@ -51,7 +51,7 @@ func bloom9(b []byte) *big.Int {
func BloomLookup(bin, topic []byte) bool { func BloomLookup(bin, topic []byte) bool {
bloom := ethutil.BigD(bin) bloom := ethutil.BigD(bin)
cmp := bloom9(topic) cmp := bloom9(crypto.Sha3(topic))
return bloom.And(bloom, cmp).Cmp(cmp) == 0 return bloom.And(bloom, cmp).Cmp(cmp) == 0
} }

View File

@ -138,6 +138,7 @@ func (self *ChainManager) GetChainHashesFromHash(hash []byte, max uint64) (chain
// XXX Could be optimised by using a different database which only holds hashes (i.e., linked list) // XXX Could be optimised by using a different database which only holds hashes (i.e., linked list)
for i := uint64(0); i < max; i++ { for i := uint64(0); i < max; i++ {
chain = append(chain, block.Hash()) chain = append(chain, block.Hash())
if block.Number.Cmp(ethutil.Big0) <= 0 { if block.Number.Cmp(ethutil.Big0) <= 0 {
@ -321,32 +322,28 @@ func NewChain(blocks Blocks) *BlockChain {
} }
// This function assumes you've done your checking. No checking is done at this stage anymore // This function assumes you've done your checking. No checking is done at this stage anymore
/*
func (self *ChainManager) InsertChain(chain *BlockChain) { func (self *ChainManager) InsertChain(chain *BlockChain) {
for e := chain.Front(); e != nil; e = e.Next() { for e := chain.Front(); e != nil; e = e.Next() {
link := e.Value.(*link) link := e.Value.(*link)
self.SetTotalDifficulty(link.td) self.SetTotalDifficulty(link.td)
self.add(link.block) self.add(link.block)
self.Ethereum.EventMux().Post(NewBlockEvent{link.block})
} }
} }
*/
func (self *ChainManager) TestChain(chain *BlockChain, imp bool) (td *big.Int, err error) { func (self *ChainManager) TestChain(chain *BlockChain) (td *big.Int, err error) {
self.workingChain = chain self.workingChain = chain
for e := chain.Front(); e != nil; e = e.Next() { for e := chain.Front(); e != nil; e = e.Next() {
var ( var (
l = e.Value.(*link) l = e.Value.(*link)
block = l.block block = l.block
parent *Block
prev = e.Prev()
)
if prev == nil {
parent = self.GetBlock(block.PrevHash) parent = self.GetBlock(block.PrevHash)
} else { )
parent = prev.Value.(*link).block
} //fmt.Println("parent", parent)
//fmt.Println("current", block)
if parent == nil { if parent == nil {
err = fmt.Errorf("incoming chain broken on hash %x\n", block.PrevHash[0:4]) err = fmt.Errorf("incoming chain broken on hash %x\n", block.PrevHash[0:4])
@ -363,19 +360,12 @@ func (self *ChainManager) TestChain(chain *BlockChain, imp bool) (td *big.Int, e
return return
} }
l.td = td l.td = td
if imp {
self.SetTotalDifficulty(td)
self.add(block)
}
} }
if !imp {
if td.Cmp(self.TD) <= 0 { if td.Cmp(self.TD) <= 0 {
err = &TDError{td, self.TD} err = &TDError{td, self.TD}
return return
} }
}
self.workingChain = nil self.workingChain = nil

View File

@ -2,8 +2,11 @@ package chain
import ( import (
"bytes" "bytes"
"fmt"
"math" "math"
"math/big"
"github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/state" "github.com/ethereum/go-ethereum/state"
) )
@ -99,6 +102,7 @@ func (self *Filter) Find() []*state.Message {
// Use bloom filtering to see if this block is interesting given the // Use bloom filtering to see if this block is interesting given the
// current parameters // current parameters
if self.bloomFilter(block) { if self.bloomFilter(block) {
fmt.Println("block", block.Number, "has something interesting")
// Get the messages of the block // Get the messages of the block
msgs, err := self.eth.BlockManager().GetMessages(block) msgs, err := self.eth.BlockManager().GetMessages(block)
if err != nil { if err != nil {
@ -184,7 +188,7 @@ func (self *Filter) bloomFilter(block *Block) bool {
if len(self.to) > 0 { if len(self.to) > 0 {
for _, to := range self.to { for _, to := range self.to {
if BloomLookup(block.LogsBloom, to) { if BloomLookup(block.LogsBloom, ethutil.U256(new(big.Int).Add(ethutil.Big1, ethutil.BigD(to))).Bytes()) {
toIncluded = true toIncluded = true
break break
} }

View File

@ -117,7 +117,7 @@ func (tx *Transaction) Sender() []byte {
// Validate the returned key. // Validate the returned key.
// Return nil if public key isn't in full format // Return nil if public key isn't in full format
if pubkey[0] != 4 { if len(pubkey) != 0 && pubkey[0] != 4 {
return nil return nil
} }

View File

@ -46,8 +46,8 @@ ApplicationWindow {
Component.onCompleted: { Component.onCompleted: {
var wallet = addPlugin("./views/wallet.qml", {noAdd: true, close: false, section: "ethereum", active: true}); var wallet = addPlugin("./views/wallet.qml", {noAdd: true, close: false, section: "ethereum", active: true});
var browser = addPlugin("./webapp.qml", {noAdd: true, close: false, section: "ethereum", active: true}); var browser = addPlugin("./webapp.qml", {noAdd: true, close: false, section: "ethereum", active: true});
var browser = addPlugin("./views/miner.qml", {noAdd: true, close: false, section: "ethereum", active: true});
root.browser = browser; root.browser = browser;
addPlugin("./views/miner.qml", {noAdd: true, close: false, section: "ethereum", active: true});
addPlugin("./views/transaction.qml", {noAdd: true, close: false, section: "legacy"}); addPlugin("./views/transaction.qml", {noAdd: true, close: false, section: "legacy"});
addPlugin("./views/chain.qml", {noAdd: true, close: false, section: "legacy"}); addPlugin("./views/chain.qml", {noAdd: true, close: false, section: "legacy"});

View File

@ -109,9 +109,9 @@ Rectangle {
} }
if(initial){ if(initial){
blockModel.append({size: block.size, number: block.number, name: block.name, gasLimit: block.gasLimit, gasUsed: block.gasUsed, coinbase: block.coinbase, hash: block.hash, txs: txs, txAmount: amount, time: block.time, prettyTime: convertToPretty(block.time)}) blockModel.append({raw: block.raw, bloom: block.bloom, size: block.size, number: block.number, name: block.name, gasLimit: block.gasLimit, gasUsed: block.gasUsed, coinbase: block.coinbase, hash: block.hash, txs: txs, txAmount: amount, time: block.time, prettyTime: convertToPretty(block.time)})
} else { } else {
blockModel.insert(0, {size: block.size, number: block.number, name: block.name, gasLimit: block.gasLimit, gasUsed: block.gasUsed, coinbase: block.coinbase, hash: block.hash, txs: txs, txAmount: amount, time: block.time, prettyTime: convertToPretty(block.time)}) blockModel.insert(0, {bloom: block.bloom, size: block.size, number: block.number, name: block.name, gasLimit: block.gasLimit, gasUsed: block.gasUsed, coinbase: block.coinbase, hash: block.hash, txs: txs, txAmount: amount, time: block.time, prettyTime: convertToPretty(block.time)})
} }
} }
@ -136,6 +136,7 @@ Rectangle {
Text { text: '<h3>Block details</h3>'; color: "#F2F2F2"} Text { text: '<h3>Block details</h3>'; color: "#F2F2F2"}
Text { text: '<b>Block number:</b> ' + number + " (Size: " + size + ")"; color: "#F2F2F2"} Text { text: '<b>Block number:</b> ' + number + " (Size: " + size + ")"; color: "#F2F2F2"}
Text { text: '<b>Hash:</b> ' + hash; color: "#F2F2F2"} Text { text: '<b>Hash:</b> ' + hash; color: "#F2F2F2"}
Text { text: '<b>Bloom:</b> ' + bloom; color: "#F2F2F2"}
Text { text: '<b>Coinbase:</b> &lt;' + name + '&gt; ' + coinbase; color: "#F2F2F2"} Text { text: '<b>Coinbase:</b> &lt;' + name + '&gt; ' + coinbase; color: "#F2F2F2"}
Text { text: '<b>Block found at:</b> ' + prettyTime; color: "#F2F2F2"} Text { text: '<b>Block found at:</b> ' + prettyTime; color: "#F2F2F2"}
Text { text: '<b>Gas used:</b> ' + gasUsed + " / " + gasLimit; color: "#F2F2F2"} Text { text: '<b>Gas used:</b> ' + gasUsed + " / " + gasLimit; color: "#F2F2F2"}
@ -222,11 +223,17 @@ Rectangle {
text: "Contract" text: "Contract"
anchors.top: contractLabel.bottom anchors.top: contractLabel.bottom
anchors.left: parent.left anchors.left: parent.left
anchors.bottom: popup.bottom anchors.right: parent.right
wrapMode: Text.Wrap wrapMode: Text.Wrap
width: parent.width - 30
height: 80 height: 80
anchors.leftMargin: 10 }
TextArea {
id: dumpData
anchors.top: contractData.bottom
anchors.left: parent.left
anchors.right: parent.right
anchors.bottom: parent.bottom
height: 300
} }
} }
property var transactionModel: ListModel { property var transactionModel: ListModel {
@ -248,6 +255,7 @@ Rectangle {
} }
} }
txView.forceActiveFocus() txView.forceActiveFocus()
dumpData.text = bl.raw;
} }
} }
} }

View File

@ -119,14 +119,12 @@ Rectangle {
} }
} }
Component.onCompleted: { Component.onCompleted: {
/* interface test stuff
// XXX Temp. replace with above eventually // XXX Temp. replace with above eventually
var tmpItems = ["JEVCoin", "Some coin", "Other coin", "Etc coin"]; var tmpItems = ["JEVCoin", "Some coin", "Other coin", "Etc coin"];
var address = "e6716f9544a56c530d868e4bfbacb172315bdead"; var address = "e6716f9544a56c530d868e4bfbacb172315bdead";
for (var i = 0; i < tmpItems.length; i++) { for (var i = 0; i < tmpItems.length; i++) {
mergedMiningModel.append({checked: false, name: tmpItems[i], address: address, id: 0, itemId: i}); mergedMiningModel.append({checked: false, name: tmpItems[i], address: address, id: 0, itemId: i});
} }
*/
} }
} }
} }

View File

@ -250,17 +250,6 @@ func (gui *Gui) setInitialChainManager() {
blk := gui.eth.ChainManager().GetBlock(sBlk) blk := gui.eth.ChainManager().GetBlock(sBlk)
for ; blk != nil; blk = gui.eth.ChainManager().GetBlock(sBlk) { for ; blk != nil; blk = gui.eth.ChainManager().GetBlock(sBlk) {
sBlk = blk.PrevHash sBlk = blk.PrevHash
addr := gui.address()
// Loop through all transactions to see if we missed any while being offline
for _, tx := range blk.Transactions() {
if bytes.Compare(tx.Sender(), addr) == 0 || bytes.Compare(tx.Recipient, addr) == 0 {
if ok, _ := gui.txDb.Get(tx.Hash()); ok == nil {
gui.txDb.Put(tx.Hash(), tx.RlpEncode())
}
}
}
gui.processBlock(blk, true) gui.processBlock(blk, true)
} }
@ -404,7 +393,7 @@ func (gui *Gui) update() {
gui.loadAddressBook() gui.loadAddressBook()
gui.loadMergedMiningOptions() gui.loadMergedMiningOptions()
gui.setPeerInfo() gui.setPeerInfo()
gui.readPreviousTransactions() //gui.readPreviousTransactions()
}() }()
for _, plugin := range gui.plugins { for _, plugin := range gui.plugins {

View File

@ -229,7 +229,11 @@ func (self *UiLib) NewFilter(object map[string]interface{}) (id int) {
func (self *UiLib) NewFilterString(typ string) (id int) { func (self *UiLib) NewFilterString(typ string) (id int) {
filter := chain.NewFilter(self.eth) filter := chain.NewFilter(self.eth)
filter.BlockCallback = func(block *chain.Block) { filter.BlockCallback = func(block *chain.Block) {
if self.win != nil && self.win.Root() != nil {
self.win.Root().Call("invokeFilterCallback", "{}", id) self.win.Root().Call("invokeFilterCallback", "{}", id)
} else {
fmt.Println("QML is lagging")
}
} }
id = self.eth.InstallFilter(filter) id = self.eth.InstallFilter(filter)
return id return id

View File

@ -419,6 +419,7 @@ func (s *Ethereum) Start(seed bool) {
if seed { if seed {
s.Seed() s.Seed()
} }
s.ConnectToPeer("localhost:40404")
loggerger.Infoln("Server started") loggerger.Infoln("Server started")
} }
@ -471,7 +472,6 @@ func (s *Ethereum) Seed() {
s.ProcessPeerList(peers) s.ProcessPeerList(peers)
} }
// XXX tmp
s.ConnectToPeer(seedNodeAddress) s.ConnectToPeer(seedNodeAddress)
} }
} }

View File

@ -1,3 +1,26 @@
/*
This file is part of go-ethereum
go-ethereum is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
go-ethereum is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* @authors
* Jeffrey Wilcke <i@jev.io>
* @date 2014
*
*/
package miner package miner
import ( import (
@ -190,12 +213,12 @@ func (self *Miner) mine() {
if nonce != nil { if nonce != nil {
block.Nonce = nonce block.Nonce = nonce
lchain := chain.NewChain(chain.Blocks{block}) lchain := chain.NewChain(chain.Blocks{block})
_, err := chainMan.TestChain(lchain, true) _, err := chainMan.TestChain(lchain)
if err != nil { if err != nil {
minerlogger.Infoln(err) minerlogger.Infoln(err)
} else { } else {
//chainMan.InsertChain(lchain) chainMan.InsertChain(lchain)
self.eth.EventMux().Post(chain.NewBlockEvent{block}) //self.eth.EventMux().Post(chain.NewBlockEvent{block})
self.eth.Broadcast(wire.MsgBlockTy, []interface{}{block.Value().Val}) self.eth.Broadcast(wire.MsgBlockTy, []interface{}{block.Value().Val})
minerlogger.Infof("🔨 Mined block %x\n", block.Hash()) minerlogger.Infof("🔨 Mined block %x\n", block.Hash())

View File

@ -673,7 +673,6 @@ func (p *Peer) pushPeers() {
} }
func (self *Peer) pushStatus() { func (self *Peer) pushStatus() {
fmt.Println("push status")
msg := wire.NewMessage(wire.MsgStatusTy, []interface{}{ msg := wire.NewMessage(wire.MsgStatusTy, []interface{}{
uint32(ProtocolVersion), uint32(ProtocolVersion),
uint32(NetVersion), uint32(NetVersion),

View File

@ -26,6 +26,8 @@ type JSBlock struct {
GasLimit string `json:"gasLimit"` GasLimit string `json:"gasLimit"`
GasUsed string `json:"gasUsed"` GasUsed string `json:"gasUsed"`
PrevHash string `json:"prevHash"` PrevHash string `json:"prevHash"`
Bloom string `json:"bloom"`
Raw string `json:"raw"`
} }
// Creates a new QML Block from a chain block // Creates a new QML Block from a chain block
@ -54,6 +56,8 @@ func NewJSBlock(block *chain.Block) *JSBlock {
Time: block.Time, Time: block.Time,
Coinbase: ethutil.Bytes2Hex(block.Coinbase), Coinbase: ethutil.Bytes2Hex(block.Coinbase),
PrevHash: ethutil.Bytes2Hex(block.PrevHash), PrevHash: ethutil.Bytes2Hex(block.PrevHash),
Bloom: ethutil.Bytes2Hex(block.LogsBloom),
Raw: block.String(),
} }
} }