Merge pull request #116 from filecoin-project/fix/mining-restart

fix chain progression after restarting process
This commit is contained in:
Łukasz Magiera 2019-08-02 16:12:37 +02:00 committed by GitHub
commit af73ae0b89
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 14 deletions

View File

@ -28,7 +28,6 @@ var log = logging.Logger("chain")
type Syncer struct {
// The heaviest known tipset in the network.
head *types.TipSet
// The interface for accessing and putting tipsets into local storage
store *store.ChainStore
@ -67,9 +66,8 @@ func NewSyncer(cs *store.ChainStore, bsync *BlockSync, self peer.ID) (*Syncer, e
Genesis: gent,
Bsync: bsync,
peerHeads: make(map[peer.ID]*types.TipSet),
head: cs.GetHeaviestTipSet(),
store: cs,
self: self,
store: cs,
self: self,
}, nil
}
@ -270,10 +268,6 @@ func (syncer *Syncer) Sync(maybeHead *store.FullTipSet) error {
return errors.Wrap(err, "failed to put synced tipset to chainstore")
}
if syncer.store.Weight(maybeHead.TipSet()) > syncer.store.Weight(syncer.head) {
fmt.Println("Accepted new head: ", maybeHead.Cids())
syncer.head = maybeHead.TipSet()
}
return nil
}
@ -513,7 +507,7 @@ func persistMessages(bs bstore.Blockstore, bstips []*BSTipSet) error {
}
func (syncer *Syncer) collectChain(fts *store.FullTipSet) error {
curHeight := syncer.head.Height()
curHeight := syncer.store.GetHeaviestTipSet().Height()
headers, err := syncer.collectHeaders(fts.TipSet(), curHeight)
if err != nil {

View File

@ -55,11 +55,9 @@ func ChainBlockservice(bs dtypes.ChainBlockstore, rem dtypes.ChainExchange) dtyp
func ChainStore(lc fx.Lifecycle, bs dtypes.ChainBlockstore, ds dtypes.MetadataDS) *store.ChainStore {
chain := store.NewChainStore(bs, ds)
lc.Append(fx.Hook{
OnStart: func(ctx context.Context) error {
return chain.Load()
},
})
if err := chain.Load(); err != nil {
log.Warnf("loading chain state from disk: %s", err)
}
return chain
}