From da34548a05782982b7a152efc0876cd59d8bc336 Mon Sep 17 00:00:00 2001 From: Aayush Rajasekaran Date: Wed, 7 Oct 2020 21:45:41 -0400 Subject: [PATCH] Set head should unmark blocks as valid --- node/impl/full/chain.go | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/node/impl/full/chain.go b/node/impl/full/chain.go index b405fb3dc..aa2ae4df1 100644 --- a/node/impl/full/chain.go +++ b/node/impl/full/chain.go @@ -254,11 +254,31 @@ func (a *ChainAPI) ChainStatObj(ctx context.Context, obj cid.Cid, base cid.Cid) } func (a *ChainAPI) ChainSetHead(ctx context.Context, tsk types.TipSetKey) error { - ts, err := a.Chain.GetTipSetFromKey(tsk) + newHeadTs, err := a.Chain.GetTipSetFromKey(tsk) if err != nil { return xerrors.Errorf("loading tipset %s: %w", tsk, err) } - return a.Chain.SetHead(ts) + + currentTs, err := a.ChainHead(ctx) + if err != nil { + return xerrors.Errorf("getting head: %w", err) + } + + for currentTs.Height() >= newHeadTs.Height() { + for _, blk := range currentTs.Key().Cids() { + err = a.Chain.UnmarkBlockAsValidated(ctx, blk) + if err != nil { + return xerrors.Errorf("unmarking block as validated %s: %w", blk, err) + } + } + + currentTs, err = a.ChainGetTipSet(ctx, currentTs.Parents()) + if err != nil { + return xerrors.Errorf("loading tipset: %w", err) + } + } + + return a.Chain.SetHead(newHeadTs) } func (a *ChainAPI) ChainGetGenesis(ctx context.Context) (*types.TipSet, error) {