core: return the index of the block that failed when inserting a chain

This commit is contained in:
obscuren
2015-04-29 14:00:24 +02:00
parent 764e81bf12
commit 735b029db9
7 changed files with 15 additions and 14 deletions

View File

@ -497,7 +497,9 @@ func (self *ChainManager) procFutureBlocks() {
self.InsertChain(blocks)
}
func (self *ChainManager) InsertChain(chain types.Blocks) error {
// InsertChain will attempt to insert the given chain in to the canonical chain or, otherwise, create a fork. It an error is returned
// it will return the index number of the failing block as well an error describing what went wrong (for possible errors see core/errors.go).
func (self *ChainManager) InsertChain(chain types.Blocks) (int, error) {
// A queued approach to delivering events. This is generally faster than direct delivery and requires much less mutex acquiring.
var (
queue = make([]interface{}, len(chain))
@ -540,7 +542,7 @@ func (self *ChainManager) InsertChain(chain types.Blocks) error {
glog.V(logger.Error).Infoln(err)
glog.V(logger.Debug).Infoln(block)
return err
return i, err
}
block.Td = new(big.Int).Set(CalculateTD(block, self.GetBlock(block.ParentHash())))
@ -613,7 +615,7 @@ func (self *ChainManager) InsertChain(chain types.Blocks) error {
go self.eventMux.Post(queueEvent)
return nil
return 0, nil
}
// diff takes two blocks, an old chain and a new chain and will reconstruct the blocks and inserts them