From bf774fc29b6910cadc4a21726aa68d324a54df7a Mon Sep 17 00:00:00 2001 From: Jakub Sztandera Date: Fri, 7 Aug 2020 23:01:28 +0200 Subject: [PATCH 1/2] Simplify sync logic around tipset expansions, ff and forking Signed-off-by: Jakub Sztandera --- chain/sync.go | 48 ++++++++++++++++++++++++---------------------- journal/journal.go | 4 +++- 2 files changed, 28 insertions(+), 24 deletions(-) diff --git a/chain/sync.go b/chain/sync.go index 4e8cce146..582446193 100644 --- a/chain/sync.go +++ b/chain/sync.go @@ -1301,31 +1301,33 @@ loop: at = blks[len(blks)-1].Parents() } - // base is the tipset in the candidate chain at the height equal to our known tipset height. - if base := blockSet[len(blockSet)-1]; !types.CidArrsEqual(base.Parents().Cids(), known.Cids()) { - if base.Parents() == known.Parents() { - // common case: receiving a block thats potentially part of the same tipset as our best block - return blockSet, nil - } - - // We have now ascertained that this is *not* a 'fast forward' - - log.Warnf("(fork detected) synced header chain (%s - %d) does not link to our best block (%s - %d)", incoming.Cids(), incoming.Height(), known.Cids(), known.Height()) - fork, err := syncer.syncFork(ctx, base, known) - if err != nil { - if xerrors.Is(err, ErrForkTooLong) { - // TODO: we're marking this block bad in the same way that we mark invalid blocks bad. Maybe distinguish? - log.Warn("adding forked chain to our bad tipset cache") - for _, b := range incoming.Blocks() { - syncer.bad.Add(b.Cid(), NewBadBlockReason(incoming.Cids(), "fork past finality")) - } - } - return nil, xerrors.Errorf("failed to sync fork: %w", err) - } - - blockSet = append(blockSet, fork...) + base := blockSet[len(blockSet)-1] + if base.Parents() == known.Parents() { + // common case: receiving a block thats potentially part of the same tipset as our best block + return blockSet, nil } + if types.CidArrsEqual(base.Parents().Cids(), known.Cids()) { + // common case: receiving blocks that are building on top of our best tipset + return blockSet, nil + } + + // We have now ascertained that this is *not* a 'fast forward' + log.Warnf("(fork detected) synced header chain (%s - %d) does not link to our best block (%s - %d)", incoming.Cids(), incoming.Height(), known.Cids(), known.Height()) + fork, err := syncer.syncFork(ctx, base, known) + if err != nil { + if xerrors.Is(err, ErrForkTooLong) { + // TODO: we're marking this block bad in the same way that we mark invalid blocks bad. Maybe distinguish? + log.Warn("adding forked chain to our bad tipset cache") + for _, b := range incoming.Blocks() { + syncer.bad.Add(b.Cid(), NewBadBlockReason(incoming.Cids(), "fork past finality")) + } + } + return nil, xerrors.Errorf("failed to sync fork: %w", err) + } + + blockSet = append(blockSet, fork...) + return blockSet, nil } diff --git a/journal/journal.go b/journal/journal.go index 8d509d51c..74208c62e 100644 --- a/journal/journal.go +++ b/journal/journal.go @@ -100,12 +100,14 @@ func (fsj *fsJournal) putEntry(je *JournalEntry) error { return nil } +const RFC3339nocolon = "2006-01-02T150405Z0700" + func (fsj *fsJournal) rollJournalFile() error { if fsj.fi != nil { fsj.fi.Close() } - nfi, err := os.Create(filepath.Join(fsj.journalDir, fmt.Sprintf("lotus-journal-%s.ndjson", build.Clock.Now().Format(time.RFC3339)))) + nfi, err := os.Create(filepath.Join(fsj.journalDir, fmt.Sprintf("lotus-journal-%s.ndjson", build.Clock.Now().Format(RFC3339nocolon)))) if err != nil { return xerrors.Errorf("failed to open journal file: %w", err) } From 239b5f547ac105964045f402f04336ef40aa892d Mon Sep 17 00:00:00 2001 From: Jakub Sztandera Date: Fri, 7 Aug 2020 23:53:11 +0200 Subject: [PATCH 2/2] Add chain.basefee Signed-off-by: Jakub Sztandera --- tools/stats/metrics.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tools/stats/metrics.go b/tools/stats/metrics.go index e4e557e59..15c28039d 100644 --- a/tools/stats/metrics.go +++ b/tools/stats/metrics.go @@ -129,6 +129,12 @@ func RecordTipsetPoints(ctx context.Context, api api.FullNode, pl *PointList, ti p = NewPoint("chain.blocktime", tsTime.Unix()) pl.AddPoint(p) + baseFeeBig := tipset.Blocks()[0].ParentBaseFee.Copy() + baseFeeRat := new(big.Rat).SetFrac(baseFeeBig.Int, new(big.Int).SetUint64(build.FilecoinPrecision)) + baseFeeFloat, _ := baseFeeRat.Float64() + p = NewPoint("chain.basefee", baseFeeFloat) + pl.AddPoint(p) + for _, blockheader := range tipset.Blocks() { bs, err := blockheader.Serialize() if err != nil {