fix sync tests by sorting tipsets

This commit is contained in:
whyrusleeping 2019-10-01 12:47:42 -06:00
parent c34968ac8a
commit 317e83a410
4 changed files with 29 additions and 7 deletions

View File

@ -507,7 +507,7 @@ func (syncer *Syncer) collectHeaders(from *types.TipSet, to *types.TipSet) ([]*t
log.Warn("syncing local: ", at)
ts, err := syncer.store.LoadTipSet(at)
if err != nil {
if err == bstore.ErrNotFound {
if xerrors.Is(err, bstore.ErrNotFound) {
log.Info("tipset not found locally, starting sync: ", at)
break
}

View File

@ -283,11 +283,8 @@ func TestSyncMining(t *testing.T) {
require.NoError(t, tu.mn.LinkAll())
tu.connect(client, 0)
fmt.Println("waiting for sync...")
tu.waitUntilSync(0, client)
fmt.Println("after wait until sync")
//tu.checkHeight("client", client, H)
tu.compareSourceState(client)

View File

@ -174,3 +174,7 @@ func PowerCmp(eproof ElectionProof, mpow, totpow BigInt) bool {
hp := BigFromBytes(h[:])
return hp.LessThan(out)
}
func (t *Ticket) Equals(ot *Ticket) bool {
return bytes.Equal(t.VDFResult, ot.VDFResult)
}

View File

@ -4,6 +4,7 @@ import (
"bytes"
"encoding/json"
"fmt"
"sort"
"github.com/ipfs/go-cid"
logging "github.com/ipfs/go-log"
@ -39,13 +40,33 @@ func (ts *TipSet) UnmarshalJSON(b []byte) error {
return err
}
ts.cids = ets.Cids
ts.blks = ets.Blocks
ts.height = ets.Height
ots, err := NewTipSet(ets.Blocks)
if err != nil {
return err
}
*ts = *ots
return nil
}
func tipsetSortFunc(blks []*BlockHeader) func(i, j int) bool {
return func(i, j int) bool {
ti := blks[i].LastTicket()
tj := blks[j].LastTicket()
if ti.Equals(tj) {
log.Warn("blocks have same ticket")
return blks[i].Cid().KeyString() < blks[j].Cid().KeyString()
}
return ti.Less(tj)
}
}
func NewTipSet(blks []*BlockHeader) (*TipSet, error) {
sort.Slice(blks, tipsetSortFunc(blks))
var ts TipSet
ts.cids = []cid.Cid{blks[0].Cid()}
ts.blks = blks