Merge pull request #2907 from filecoin-project/misc/sync-times

Simplify sync logic around tipset expansions, ff and forking
This commit is contained in:
Jakub Sztandera 2020-08-08 00:23:50 +02:00 committed by GitHub
commit aef3a4d21d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 24 deletions

View File

@ -1301,15 +1301,18 @@ loop:
at = blks[len(blks)-1].Parents() at = blks[len(blks)-1].Parents()
} }
// base is the tipset in the candidate chain at the height equal to our known tipset height. base := blockSet[len(blockSet)-1]
if base := blockSet[len(blockSet)-1]; !types.CidArrsEqual(base.Parents().Cids(), known.Cids()) {
if base.Parents() == known.Parents() { if base.Parents() == known.Parents() {
// common case: receiving a block thats potentially part of the same tipset as our best block // common case: receiving a block thats potentially part of the same tipset as our best block
return blockSet, nil return blockSet, nil
} }
// We have now ascertained that this is *not* a 'fast forward' 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()) 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) fork, err := syncer.syncFork(ctx, base, known)
if err != nil { if err != nil {
@ -1324,7 +1327,6 @@ loop:
} }
blockSet = append(blockSet, fork...) blockSet = append(blockSet, fork...)
}
return blockSet, nil return blockSet, nil
} }

View File

@ -100,12 +100,14 @@ func (fsj *fsJournal) putEntry(je *JournalEntry) error {
return nil return nil
} }
const RFC3339nocolon = "2006-01-02T150405Z0700"
func (fsj *fsJournal) rollJournalFile() error { func (fsj *fsJournal) rollJournalFile() error {
if fsj.fi != nil { if fsj.fi != nil {
fsj.fi.Close() 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 { if err != nil {
return xerrors.Errorf("failed to open journal file: %w", err) return xerrors.Errorf("failed to open journal file: %w", err)
} }

View File

@ -129,6 +129,12 @@ func RecordTipsetPoints(ctx context.Context, api api.FullNode, pl *PointList, ti
p = NewPoint("chain.blocktime", tsTime.Unix()) p = NewPoint("chain.blocktime", tsTime.Unix())
pl.AddPoint(p) 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() { for _, blockheader := range tipset.Blocks() {
bs, err := blockheader.Serialize() bs, err := blockheader.Serialize()
if err != nil { if err != nil {