From 6dc46d3341dc5fa25bd005f9606de258874139be Mon Sep 17 00:00:00 2001 From: obscuren Date: Mon, 1 Dec 2014 20:18:09 +0100 Subject: Changed the way transactions are being added to the transaction pool --- chain/chain_manager.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'chain/chain_manager.go') diff --git a/chain/chain_manager.go b/chain/chain_manager.go index 0c3a7a928..75c8b22a2 100644 --- a/chain/chain_manager.go +++ b/chain/chain_manager.go @@ -321,6 +321,24 @@ func NewChain(blocks Blocks) *BlockChain { return chain } +// This function assumes you've done your checking. No checking is done at this stage anymore +func (self *ChainManager) InsertChain(chain Blocks) error { + for _, block := range chain { + td, messages, err := self.Ethereum.BlockManager().Process(block) + if err != nil { + return err + } + + self.add(block) + self.SetTotalDifficulty(td) + self.Ethereum.EventMux().Post(NewBlockEvent{block}) + self.Ethereum.EventMux().Post(messages) + } + + return nil +} + +/* // 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() { @@ -338,7 +356,9 @@ func (self *ChainManager) InsertChain(chain *BlockChain) { chainlogger.Infof("Imported %d blocks. #%v (%x) / %#v (%x)", chain.Len(), front.Number, front.Hash()[0:4], back.Number, back.Hash()[0:4]) } } +*/ +/* func (self *ChainManager) TestChain(chain *BlockChain) (td *big.Int, err error) { self.workingChain = chain defer func() { self.workingChain = nil }() @@ -381,3 +401,4 @@ func (self *ChainManager) TestChain(chain *BlockChain) (td *big.Int, err error) return } +*/ -- cgit v1.2.3 From 99481a245adc2c4814ab6b38d94d63114f7bbb15 Mon Sep 17 00:00:00 2001 From: obscuren Date: Tue, 2 Dec 2014 11:37:33 +0100 Subject: Check for known block err and ignore --- chain/chain_manager.go | 70 ++++---------------------------------------------- 1 file changed, 5 insertions(+), 65 deletions(-) (limited to 'chain/chain_manager.go') diff --git a/chain/chain_manager.go b/chain/chain_manager.go index 75c8b22a2..3448b02dd 100644 --- a/chain/chain_manager.go +++ b/chain/chain_manager.go @@ -326,9 +326,14 @@ func (self *ChainManager) InsertChain(chain Blocks) error { for _, block := range chain { td, messages, err := self.Ethereum.BlockManager().Process(block) if err != nil { + if IsKnownBlockErr(err) { + continue + } + return err } + fmt.Println(td, messages, err) self.add(block) self.SetTotalDifficulty(td) self.Ethereum.EventMux().Post(NewBlockEvent{block}) @@ -337,68 +342,3 @@ func (self *ChainManager) InsertChain(chain Blocks) error { return nil } - -/* -// 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.add(link.block) - self.SetTotalDifficulty(link.td) - self.Ethereum.EventMux().Post(NewBlockEvent{link.block}) - self.Ethereum.EventMux().Post(link.messages) - } - - b, e := chain.Front(), chain.Back() - if b != nil && e != nil { - front, back := b.Value.(*link).block, e.Value.(*link).block - chainlogger.Infof("Imported %d blocks. #%v (%x) / %#v (%x)", chain.Len(), front.Number, front.Hash()[0:4], back.Number, back.Hash()[0:4]) - } -} -*/ - -/* -func (self *ChainManager) TestChain(chain *BlockChain) (td *big.Int, err error) { - self.workingChain = chain - defer func() { self.workingChain = nil }() - - for e := chain.Front(); e != nil; e = e.Next() { - var ( - l = e.Value.(*link) - block = l.block - parent = self.GetBlock(block.PrevHash) - ) - - //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]) - return - } - - var messages state.Messages - td, messages, err = self.Ethereum.BlockManager().ProcessWithParent(block, parent) - if err != nil { - chainlogger.Infoln(err) - chainlogger.Debugf("Block #%v failed (%x...)\n", block.Number, block.Hash()[0:4]) - chainlogger.Debugln(block) - - err = fmt.Errorf("incoming chain failed %v\n", err) - return - } - l.td = td - l.messages = messages - } - - if td.Cmp(self.TD) <= 0 { - err = &TDError{td, self.TD} - return - } - - self.workingChain = nil - - return -} -*/ -- cgit v1.2.3