Merge pull request #396 from nspcc-dev/network-reconnections-and-fixes
This one fixes #390 and some connected problems. After this patchset the node reconnects to some other nodes if anything goes wrong and it better senses when something goes wrong. It also fixes some block handling problems based on the testnet connection experience.
This commit is contained in:
commit
adba9e11ee
13 changed files with 427 additions and 119 deletions
|
@ -357,8 +357,7 @@ func (bc *Blockchain) persistBlock(block *Block) error {
|
|||
Email: t.Email,
|
||||
Description: t.Description,
|
||||
}
|
||||
|
||||
fmt.Printf("%+v", contract)
|
||||
_ = contract
|
||||
|
||||
case *transaction.InvocationTX:
|
||||
}
|
||||
|
@ -430,6 +429,15 @@ func (bc *Blockchain) persist(ctx context.Context) (err error) {
|
|||
"blockHeight": bc.BlockHeight(),
|
||||
"took": time.Since(start),
|
||||
}).Info("blockchain persist completed")
|
||||
} else {
|
||||
// So we have some blocks in cache but can't persist them?
|
||||
// Either there are some stale blocks there or the other way
|
||||
// around (which was seen in practice) --- there are some fresh
|
||||
// blocks that we can't persist yet. Some of the latter can be useful
|
||||
// or can be bogus (higher than the header height we expect at
|
||||
// the moment). So try to reap oldies and strange newbies, if
|
||||
// there are any.
|
||||
bc.blockCache.ReapStrangeBlocks(bc.BlockHeight(), bc.HeaderHeight())
|
||||
}
|
||||
|
||||
return
|
||||
|
|
|
@ -71,3 +71,17 @@ func (c *Cache) Delete(h util.Uint256) {
|
|||
defer c.lock.Unlock()
|
||||
delete(c.m, h)
|
||||
}
|
||||
|
||||
// ReapStrangeBlocks drops blocks from cache that don't fit into the
|
||||
// blkHeight-headHeight interval. Cache should only contain blocks that we
|
||||
// expect to get and store.
|
||||
func (c *Cache) ReapStrangeBlocks(blkHeight, headHeight uint32) {
|
||||
c.lock.Lock()
|
||||
defer c.lock.Unlock()
|
||||
for i, b := range c.m {
|
||||
block, ok := b.(*Block)
|
||||
if ok && (block.Index < blkHeight || block.Index > headHeight) {
|
||||
delete(c.m, i)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue