use blocks we have locally anytime we need them
This commit is contained in:
parent
65b5bf7570
commit
46985246a2
@ -669,33 +669,27 @@ func (syncer *Syncer) collectHeaders(ctx context.Context, from *types.TipSet, to
|
|||||||
// we want to sync all the blocks until the height above the block we have
|
// we want to sync all the blocks until the height above the block we have
|
||||||
untilHeight := to.Height() + 1
|
untilHeight := to.Height() + 1
|
||||||
|
|
||||||
// If, for some reason, we have a suffix of the chain locally, handle that here
|
syncer.syncState.SetHeight(blockSet[len(blockSet)-1].Height())
|
||||||
|
|
||||||
|
loop:
|
||||||
for blockSet[len(blockSet)-1].Height() > untilHeight {
|
for blockSet[len(blockSet)-1].Height() > untilHeight {
|
||||||
log.Warn("syncing local: ", at)
|
|
||||||
for _, bc := range at {
|
for _, bc := range at {
|
||||||
if syncer.bad.Has(bc) {
|
if syncer.bad.Has(bc) {
|
||||||
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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 {
|
||||||
if xerrors.Is(err, bstore.ErrNotFound) {
|
blockSet = append(blockSet, ts)
|
||||||
log.Info("tipset not found locally, starting sync: ", at)
|
at = ts.Parents()
|
||||||
break
|
continue
|
||||||
}
|
}
|
||||||
|
if !xerrors.Is(err, bstore.ErrNotFound) {
|
||||||
log.Warn("loading local tipset: %s", err)
|
log.Warn("loading local tipset: %s", err)
|
||||||
continue // TODO: verify
|
|
||||||
}
|
}
|
||||||
|
|
||||||
blockSet = append(blockSet, ts)
|
|
||||||
at = ts.Parents()
|
|
||||||
}
|
|
||||||
|
|
||||||
syncer.syncState.SetHeight(blockSet[len(blockSet)-1].Height())
|
|
||||||
|
|
||||||
loop:
|
|
||||||
for blockSet[len(blockSet)-1].Height() > untilHeight {
|
|
||||||
// NB: GetBlocks validates that the blocks are in-fact the ones we
|
// NB: GetBlocks validates that the blocks are in-fact the ones we
|
||||||
// requested, and that they are correctly linked to eachother. It does
|
// requested, and that they are correctly linked to eachother. It does
|
||||||
// not validate any state transitions
|
// not validate any state transitions
|
||||||
@ -800,25 +794,19 @@ func (syncer *Syncer) iterFullTipsets(ctx context.Context, headers []*types.TipS
|
|||||||
ctx, span := trace.StartSpan(ctx, "iterFullTipsets")
|
ctx, span := trace.StartSpan(ctx, "iterFullTipsets")
|
||||||
defer span.End()
|
defer span.End()
|
||||||
|
|
||||||
beg := len(headers) - 1
|
windowSize := 200
|
||||||
// handle case where we have a prefix of these locally
|
for i := len(headers) - 1; i >= 0; {
|
||||||
for ; beg >= 0; beg-- {
|
fts, err := syncer.store.TryFillTipSet(headers[i])
|
||||||
fts, err := syncer.store.TryFillTipSet(headers[beg])
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if fts == nil {
|
if fts != nil {
|
||||||
break
|
if err := cb(ctx, fts); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
i--
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
if err := cb(ctx, fts); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
headers = headers[:beg+1]
|
|
||||||
|
|
||||||
windowSize := 200
|
|
||||||
|
|
||||||
for i := len(headers) - 1; i >= 0; i -= windowSize {
|
|
||||||
|
|
||||||
batchSize := windowSize
|
batchSize := windowSize
|
||||||
if i < batchSize {
|
if i < batchSize {
|
||||||
@ -859,6 +847,7 @@ func (syncer *Syncer) iterFullTipsets(ctx context.Context, headers []*types.TipS
|
|||||||
return xerrors.Errorf("message processing failed: %w", err)
|
return xerrors.Errorf("message processing failed: %w", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
i -= windowSize
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
Loading…
Reference in New Issue
Block a user