From 2b82e5a118fd2ae5ac35debf9aa5ca19631fc634 Mon Sep 17 00:00:00 2001 From: Jakub Sztandera Date: Tue, 27 Oct 2020 21:23:16 +0100 Subject: [PATCH] Fix tipset coalescing in case of repeated blocks Signed-off-by: Jakub Sztandera --- chain/sync_manager.go | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/chain/sync_manager.go b/chain/sync_manager.go index c1ec4e12d..1fec71eed 100644 --- a/chain/sync_manager.go +++ b/chain/sync_manager.go @@ -7,6 +7,7 @@ import ( "strings" "sync" + "github.com/filecoin-project/go-address" "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/chain/types" @@ -480,9 +481,23 @@ func (stb *syncTargetBucket) add(ts *types.TipSet) { } if coalesceTipsets && t.Height() == ts.Height() && types.CidArrsEqual(t.Blocks()[0].Parents, ts.Blocks()[0].Parents) { + miners := make(map[address.Address]struct{}) + newTs := []*types.BlockHeader{} + for _, b := range t.Blocks() { + _, have := miners[b.Miner] + if !have { + newTs = append(newTs, b) + miners[b.Miner] = struct{}{} + } + } + for _, b := range ts.Blocks() { + _, have := miners[b.Miner] + if !have { + newTs = append(newTs, b) + miners[b.Miner] = struct{}{} + } + } - newTs := append([]*types.BlockHeader{}, ts.Blocks()...) - newTs = append(newTs, t.Blocks()...) ts2, err := types.NewTipSet(newTs) if err != nil { log.Warnf("error while trying to recombine a tipset in a bucket: %+v", err)