sync: Mark chains with bad blocks as bad too

This commit is contained in:
Łukasz Magiera 2019-11-11 23:37:34 +01:00
parent 7514d3e1bd
commit a6135b62ce
2 changed files with 16 additions and 2 deletions

View File

@ -122,8 +122,8 @@ func init() {
} }
// Sync // Sync
const BadBlockCacheSize = 8192 const BadBlockCacheSize = 1 << 15
// assuming 4000 blocks per round, this lets us not lose any messages across a // assuming 4000 blocks per round, this lets us not lose any messages across a
// 10 block reorg. // 10 block reorg.
const BlsSignatureCacheSize = 40000 const BlsSignatureCacheSize = 40000

View File

@ -755,10 +755,16 @@ func (syncer *Syncer) collectHeaders(ctx context.Context, from *types.TipSet, to
syncer.syncState.SetHeight(blockSet[len(blockSet)-1].Height()) syncer.syncState.SetHeight(blockSet[len(blockSet)-1].Height())
var acceptedBlocks []cid.Cid
loop: loop:
for blockSet[len(blockSet)-1].Height() > untilHeight { for blockSet[len(blockSet)-1].Height() > untilHeight {
for _, bc := range at { for _, bc := range at {
if syncer.bad.Has(bc) { if syncer.bad.Has(bc) {
for _, b := range acceptedBlocks {
syncer.bad.Add(b)
}
return nil, xerrors.Errorf("chain contained block marked previously as bad (%s, %s)", from.Cids(), bc) return nil, xerrors.Errorf("chain contained block marked previously as bad (%s, %s)", from.Cids(), bc)
} }
} }
@ -766,6 +772,8 @@ loop:
// If, for some reason, we have a suffix of the chain locally, handle that here // If, for some reason, we have a suffix of the chain locally, handle that here
ts, err := syncer.store.LoadTipSet(at) ts, err := syncer.store.LoadTipSet(at)
if err == nil { if err == nil {
acceptedBlocks = append(acceptedBlocks, at...)
blockSet = append(blockSet, ts) blockSet = append(blockSet, ts)
at = ts.Parents() at = ts.Parents()
continue continue
@ -801,12 +809,18 @@ loop:
} }
for _, bc := range b.Cids() { for _, bc := range b.Cids() {
if syncer.bad.Has(bc) { if syncer.bad.Has(bc) {
for _, b := range acceptedBlocks {
syncer.bad.Add(b)
}
return nil, xerrors.Errorf("chain contained block marked previously as bad (%s, %s)", from.Cids(), bc) return nil, xerrors.Errorf("chain contained block marked previously as bad (%s, %s)", from.Cids(), bc)
} }
} }
blockSet = append(blockSet, b) blockSet = append(blockSet, b)
} }
acceptedBlocks = append(acceptedBlocks, at...)
syncer.syncState.SetHeight(blks[len(blks)-1].Height()) syncer.syncState.SetHeight(blks[len(blks)-1].Height())
at = blks[len(blks)-1].Parents() at = blks[len(blks)-1].Parents()
} }