Merge pull request #258 from filecoin-project/fix/sort-tipsets
fix sync tests by sorting tipsets
This commit is contained in:
commit
6a729263a4
@ -507,7 +507,7 @@ func (syncer *Syncer) collectHeaders(from *types.TipSet, to *types.TipSet) ([]*t
|
|||||||
log.Warn("syncing local: ", at)
|
log.Warn("syncing local: ", at)
|
||||||
ts, err := syncer.store.LoadTipSet(at)
|
ts, err := syncer.store.LoadTipSet(at)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err == bstore.ErrNotFound {
|
if xerrors.Is(err, bstore.ErrNotFound) {
|
||||||
log.Info("tipset not found locally, starting sync: ", at)
|
log.Info("tipset not found locally, starting sync: ", at)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
@ -283,11 +283,8 @@ func TestSyncMining(t *testing.T) {
|
|||||||
|
|
||||||
require.NoError(t, tu.mn.LinkAll())
|
require.NoError(t, tu.mn.LinkAll())
|
||||||
tu.connect(client, 0)
|
tu.connect(client, 0)
|
||||||
fmt.Println("waiting for sync...")
|
|
||||||
tu.waitUntilSync(0, client)
|
tu.waitUntilSync(0, client)
|
||||||
|
|
||||||
fmt.Println("after wait until sync")
|
|
||||||
|
|
||||||
//tu.checkHeight("client", client, H)
|
//tu.checkHeight("client", client, H)
|
||||||
|
|
||||||
tu.compareSourceState(client)
|
tu.compareSourceState(client)
|
||||||
|
@ -174,3 +174,7 @@ func PowerCmp(eproof ElectionProof, mpow, totpow BigInt) bool {
|
|||||||
hp := BigFromBytes(h[:])
|
hp := BigFromBytes(h[:])
|
||||||
return hp.LessThan(out)
|
return hp.LessThan(out)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t *Ticket) Equals(ot *Ticket) bool {
|
||||||
|
return bytes.Equal(t.VDFResult, ot.VDFResult)
|
||||||
|
}
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"sort"
|
||||||
|
|
||||||
"github.com/ipfs/go-cid"
|
"github.com/ipfs/go-cid"
|
||||||
logging "github.com/ipfs/go-log"
|
logging "github.com/ipfs/go-log"
|
||||||
@ -39,13 +40,33 @@ func (ts *TipSet) UnmarshalJSON(b []byte) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
ts.cids = ets.Cids
|
ots, err := NewTipSet(ets.Blocks)
|
||||||
ts.blks = ets.Blocks
|
if err != nil {
|
||||||
ts.height = ets.Height
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
*ts = *ots
|
||||||
|
|
||||||
return nil
|
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) {
|
func NewTipSet(blks []*BlockHeader) (*TipSet, error) {
|
||||||
|
sort.Slice(blks, tipsetSortFunc(blks))
|
||||||
|
|
||||||
var ts TipSet
|
var ts TipSet
|
||||||
ts.cids = []cid.Cid{blks[0].Cid()}
|
ts.cids = []cid.Cid{blks[0].Cid()}
|
||||||
ts.blks = blks
|
ts.blks = blks
|
||||||
|
Loading…
Reference in New Issue
Block a user