From ff3433baa1ab35ceedfbefe8255dd0b21e0b15d0 Mon Sep 17 00:00:00 2001 From: whyrusleeping Date: Thu, 1 Aug 2019 23:46:14 -0700 Subject: [PATCH 1/2] fix chain progression after restarting process --- chain/sync.go | 13 ++++--------- node/modules/chain.go | 8 +++----- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/chain/sync.go b/chain/sync.go index 9102a52a0..39aa95f89 100644 --- a/chain/sync.go +++ b/chain/sync.go @@ -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,9 @@ 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, + //head: cs.GetHeaviestTipSet(), + store: cs, + self: self, }, nil } @@ -270,10 +269,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 +508,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 { diff --git a/node/modules/chain.go b/node/modules/chain.go index f72f16d21..1de38d4fa 100644 --- a/node/modules/chain.go +++ b/node/modules/chain.go @@ -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 } From 9f195a175cff2d180082dd8637cff58f9e329842 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Fri, 2 Aug 2019 16:12:20 +0200 Subject: [PATCH 2/2] Update chain/sync.go --- chain/sync.go | 1 - 1 file changed, 1 deletion(-) diff --git a/chain/sync.go b/chain/sync.go index 39aa95f89..4fbb6925b 100644 --- a/chain/sync.go +++ b/chain/sync.go @@ -66,7 +66,6 @@ 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, }, nil