diff --git a/chain/sync.go b/chain/sync.go index e594749e9..b65341825 100644 --- a/chain/sync.go +++ b/chain/sync.go @@ -941,6 +941,12 @@ func (syncer *Syncer) syncFork(ctx context.Context, from *types.TipSet, to *type } for cur := 0; cur < len(tips); { + if nts.Height() == 0 { + if !syncer.Genesis.Equals(nts) { + return nil, xerrors.Errorf("somehow synced chain that linked back to a different genesis (bad genesis: %s)", nts.Key()) + } + return nil, xerrors.Errorf("synced chain forked at genesis, refusing to sync") + } if nts.Equals(tips[cur]) { return tips[:cur+1], nil diff --git a/chain/types/tipset.go b/chain/types/tipset.go index 1ed15289e..e8d830bc5 100644 --- a/chain/types/tipset.go +++ b/chain/types/tipset.go @@ -10,6 +10,7 @@ import ( "github.com/ipfs/go-cid" logging "github.com/ipfs/go-log" cbg "github.com/whyrusleeping/cbor-gen" + "golang.org/x/xerrors" ) var log = logging.Logger("types") @@ -95,6 +96,10 @@ func tipsetSortFunc(blks []*BlockHeader) func(i, j int) bool { } func NewTipSet(blks []*BlockHeader) (*TipSet, error) { + if len(blks) == 0 { + return nil, xerrors.Errorf("NewTipSet called with zero length array of blocks") + } + sort.Slice(blks, tipsetSortFunc(blks)) var ts TipSet