Merge pull request #136 from filecoin-project/fix/best-tip-init

ensure best tipset is set during genesis init
This commit is contained in:
Whyrusleeping 2019-08-16 10:44:55 -07:00 committed by GitHub
commit 608885f87d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -151,18 +151,12 @@ func (cs *ChainStore) SubscribeHeadChanges(f func(rev, app []*types.TipSet) erro
} }
func (cs *ChainStore) SetGenesis(b *types.BlockHeader) error { func (cs *ChainStore) SetGenesis(b *types.BlockHeader) error {
gents, err := types.NewTipSet([]*types.BlockHeader{b})
if err != nil {
return err
}
fts := &FullTipSet{ fts := &FullTipSet{
Blocks: []*types.FullBlock{ Blocks: []*types.FullBlock{
{Header: b}, {Header: b},
}, },
} }
cs.heaviest = gents
if err := cs.PutTipSet(fts); err != nil { if err := cs.PutTipSet(fts); err != nil {
return err return err
} }
@ -190,6 +184,7 @@ func (cs *ChainStore) MaybeTakeHeavierTipSet(ts *types.TipSet) error {
// TODO: don't do this for initial sync. Now that we don't have a // TODO: don't do this for initial sync. Now that we don't have a
// difference between 'bootstrap sync' and 'caught up' sync, we need // difference between 'bootstrap sync' and 'caught up' sync, we need
// some other heuristic. // some other heuristic.
if cs.heaviest != nil {
revert, apply, err := cs.ReorgOps(cs.heaviest, ts) revert, apply, err := cs.ReorgOps(cs.heaviest, ts)
if err != nil { if err != nil {
return errors.Wrap(err, "computing reorg ops failed") return errors.Wrap(err, "computing reorg ops failed")
@ -199,6 +194,10 @@ func (cs *ChainStore) MaybeTakeHeavierTipSet(ts *types.TipSet) error {
return errors.Wrap(err, "head change func errored (BAD)") return errors.Wrap(err, "head change func errored (BAD)")
} }
} }
} else {
log.Warn("no heaviest tipset found, using %s", ts.Cids())
}
log.Infof("New heaviest tipset! %s", ts.Cids()) log.Infof("New heaviest tipset! %s", ts.Cids())
cs.heaviest = ts cs.heaviest = ts