Added chain
tests & minor fixes
* Fork tests (equal and larger chains) * `chain.link` fields are now exported * moved debug function from state to dump.go
This commit is contained in:
@@ -191,8 +191,8 @@ func (self *ChainManager) GetBlock(hash []byte) *types.Block {
|
||||
if self.workingChain != nil {
|
||||
// Check the temp chain
|
||||
for e := self.workingChain.Front(); e != nil; e = e.Next() {
|
||||
if bytes.Compare(e.Value.(*link).block.Hash(), hash) == 0 {
|
||||
return e.Value.(*link).block
|
||||
if bytes.Compare(e.Value.(*link).Block.Hash(), hash) == 0 {
|
||||
return e.Value.(*link).Block
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -275,15 +275,15 @@ func (self *ChainManager) InsertChain(chain *BlockChain, call func(*types.Block,
|
||||
for e := chain.Front(); e != nil; e = e.Next() {
|
||||
link := e.Value.(*link)
|
||||
|
||||
self.add(link.block)
|
||||
self.SetTotalDifficulty(link.td)
|
||||
self.add(link.Block)
|
||||
self.SetTotalDifficulty(link.Td)
|
||||
|
||||
call(link.block, link.messages)
|
||||
call(link.Block, link.Messages)
|
||||
}
|
||||
|
||||
b, e := chain.Front(), chain.Back()
|
||||
if b != nil && e != nil {
|
||||
front, back := b.Value.(*link).block, e.Value.(*link).block
|
||||
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])
|
||||
}
|
||||
}
|
||||
@@ -295,7 +295,7 @@ func (self *ChainManager) TestChain(chain *BlockChain) (td *big.Int, err error)
|
||||
for e := chain.Front(); e != nil; e = e.Next() {
|
||||
var (
|
||||
l = e.Value.(*link)
|
||||
block = l.block
|
||||
block = l.Block
|
||||
parent = self.GetBlock(block.PrevHash)
|
||||
)
|
||||
|
||||
@@ -314,8 +314,8 @@ func (self *ChainManager) TestChain(chain *BlockChain) (td *big.Int, err error)
|
||||
err = fmt.Errorf("incoming chain failed %v\n", err)
|
||||
return
|
||||
}
|
||||
l.td = td
|
||||
l.messages = messages
|
||||
l.Td = td
|
||||
l.Messages = messages
|
||||
}
|
||||
|
||||
if td.Cmp(self.TD) <= 0 {
|
||||
@@ -329,9 +329,9 @@ func (self *ChainManager) TestChain(chain *BlockChain) (td *big.Int, err error)
|
||||
}
|
||||
|
||||
type link struct {
|
||||
block *types.Block
|
||||
messages state.Messages
|
||||
td *big.Int
|
||||
Block *types.Block
|
||||
Messages state.Messages
|
||||
Td *big.Int
|
||||
}
|
||||
|
||||
type BlockChain struct {
|
||||
@@ -351,7 +351,7 @@ func NewChain(blocks types.Blocks) *BlockChain {
|
||||
func (self *BlockChain) RlpEncode() []byte {
|
||||
dat := make([]interface{}, 0)
|
||||
for e := self.Front(); e != nil; e = e.Next() {
|
||||
dat = append(dat, e.Value.(*link).block.RlpData())
|
||||
dat = append(dat, e.Value.(*link).Block.RlpData())
|
||||
}
|
||||
|
||||
return ethutil.Encode(dat)
|
||||
|
Reference in New Issue
Block a user