diff options
author | obscuren <geffobscura@gmail.com> | 2014-11-10 08:17:31 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2014-11-10 08:17:31 +0800 |
commit | cbeebcd47da846e1b8990313f1ff1ffe7d0bf00f (patch) | |
tree | 95db04f468e66ebb26afd81bc72abea8fbcf7c0e /chain | |
parent | f538ea25e46d59dfa225ed105343d9c6a9909c2c (diff) | |
download | dexon-cbeebcd47da846e1b8990313f1ff1ffe7d0bf00f.tar dexon-cbeebcd47da846e1b8990313f1ff1ffe7d0bf00f.tar.gz dexon-cbeebcd47da846e1b8990313f1ff1ffe7d0bf00f.tar.bz2 dexon-cbeebcd47da846e1b8990313f1ff1ffe7d0bf00f.tar.lz dexon-cbeebcd47da846e1b8990313f1ff1ffe7d0bf00f.tar.xz dexon-cbeebcd47da846e1b8990313f1ff1ffe7d0bf00f.tar.zst dexon-cbeebcd47da846e1b8990313f1ff1ffe7d0bf00f.zip |
Fixed bloom, updated mining & block processing
* Reverted back to process blocks in batches method
* Bloom generation and lookup fix
* Minor UI changed (mainly debug)
Diffstat (limited to 'chain')
-rw-r--r-- | chain/bloom9.go | 14 | ||||
-rw-r--r-- | chain/chain_manager.go | 30 | ||||
-rw-r--r-- | chain/filter.go | 6 | ||||
-rw-r--r-- | chain/transaction.go | 2 |
4 files changed, 23 insertions, 29 deletions
diff --git a/chain/bloom9.go b/chain/bloom9.go index 2bbc9409d..4c029b56b 100644 --- a/chain/bloom9.go +++ b/chain/bloom9.go @@ -21,18 +21,18 @@ func CreateBloom(block *Block) []byte { func LogsBloom(logs state.Logs) *big.Int { bin := new(big.Int) for _, log := range logs { - data := [][]byte{crypto.Sha3(log.Address)} + data := [][]byte{log.Address} for _, topic := range log.Topics { data = append(data, topic) } - if log.Data != nil { - data = append(data, log.Data) - } - for _, b := range data { - bin.Or(bin, bloom9(b)) + bin.Or(bin, ethutil.BigD(bloom9(crypto.Sha3(b)).Bytes())) } + + //if log.Data != nil { + // data = append(data, log.Data) + //} } return bin @@ -51,7 +51,7 @@ func bloom9(b []byte) *big.Int { func BloomLookup(bin, topic []byte) bool { bloom := ethutil.BigD(bin) - cmp := bloom9(topic) + cmp := bloom9(crypto.Sha3(topic)) return bloom.And(bloom, cmp).Cmp(cmp) == 0 } diff --git a/chain/chain_manager.go b/chain/chain_manager.go index 5e62e6771..18961400c 100644 --- a/chain/chain_manager.go +++ b/chain/chain_manager.go @@ -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) for i := uint64(0); i < max; i++ { + chain = append(chain, block.Hash()) 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 -/* func (self *ChainManager) InsertChain(chain *BlockChain) { for e := chain.Front(); e != nil; e = e.Next() { link := e.Value.(*link) self.SetTotalDifficulty(link.td) 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 for e := chain.Front(); e != nil; e = e.Next() { var ( l = e.Value.(*link) block = l.block - parent *Block - prev = e.Prev() - ) - if prev == nil { parent = self.GetBlock(block.PrevHash) - } else { - parent = prev.Value.(*link).block - } + ) + + //fmt.Println("parent", parent) + //fmt.Println("current", block) if parent == nil { err = fmt.Errorf("incoming chain broken on hash %x\n", block.PrevHash[0:4]) @@ -363,18 +360,11 @@ func (self *ChainManager) TestChain(chain *BlockChain, imp bool) (td *big.Int, e return } l.td = td - - if imp { - self.SetTotalDifficulty(td) - self.add(block) - } } - if !imp { - if td.Cmp(self.TD) <= 0 { - err = &TDError{td, self.TD} - return - } + if td.Cmp(self.TD) <= 0 { + err = &TDError{td, self.TD} + return } self.workingChain = nil diff --git a/chain/filter.go b/chain/filter.go index 3494e4dcc..71e32c32f 100644 --- a/chain/filter.go +++ b/chain/filter.go @@ -2,8 +2,11 @@ package chain import ( "bytes" + "fmt" "math" + "math/big" + "github.com/ethereum/go-ethereum/ethutil" "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 // current parameters if self.bloomFilter(block) { + fmt.Println("block", block.Number, "has something interesting") // Get the messages of the block msgs, err := self.eth.BlockManager().GetMessages(block) if err != nil { @@ -184,7 +188,7 @@ func (self *Filter) bloomFilter(block *Block) bool { if len(self.to) > 0 { 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 break } diff --git a/chain/transaction.go b/chain/transaction.go index d393f0384..d2d6a8e14 100644 --- a/chain/transaction.go +++ b/chain/transaction.go @@ -117,7 +117,7 @@ func (tx *Transaction) Sender() []byte { // Validate the returned key. // Return nil if public key isn't in full format - if pubkey[0] != 4 { + if len(pubkey) != 0 && pubkey[0] != 4 { return nil } |