fix all panics from calling NewTipSet on an empty set of blocks
This commit is contained in:
parent
88f46d4539
commit
12eed004ae
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user