begin allowing test framework to generate forks
This commit is contained in:
parent
1ea23da756
commit
fca5a4765d
@ -49,7 +49,7 @@ type ChainGen struct {
|
|||||||
|
|
||||||
w *wallet.Wallet
|
w *wallet.Wallet
|
||||||
|
|
||||||
miners []address.Address
|
Miners []address.Address
|
||||||
mworkers []address.Address
|
mworkers []address.Address
|
||||||
receivers []address.Address
|
receivers []address.Address
|
||||||
banker address.Address
|
banker address.Address
|
||||||
@ -159,7 +159,7 @@ func NewGenerator() (*ChainGen, error) {
|
|||||||
genesis: genb.Genesis,
|
genesis: genb.Genesis,
|
||||||
w: w,
|
w: w,
|
||||||
|
|
||||||
miners: minercfg.MinerAddrs,
|
Miners: minercfg.MinerAddrs,
|
||||||
mworkers: minercfg.Workers,
|
mworkers: minercfg.Workers,
|
||||||
banker: banker,
|
banker: banker,
|
||||||
receivers: receievers,
|
receivers: receievers,
|
||||||
@ -241,18 +241,26 @@ type MinedTipSet struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (cg *ChainGen) NextTipSet() (*MinedTipSet, error) {
|
func (cg *ChainGen) NextTipSet() (*MinedTipSet, error) {
|
||||||
|
mts, err := cg.NextTipSetFromMiners(cg.curTipset.TipSet(), cg.Miners)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
cg.curTipset = mts.TipSet
|
||||||
|
return mts, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (cg *ChainGen) NextTipSetFromMiners(base *types.TipSet, miners []address.Address) (*MinedTipSet, error) {
|
||||||
var blks []*types.FullBlock
|
var blks []*types.FullBlock
|
||||||
ticketSets := make([][]*types.Ticket, len(cg.miners))
|
ticketSets := make([][]*types.Ticket, len(miners))
|
||||||
|
|
||||||
msgs, err := cg.getRandomMessages()
|
msgs, err := cg.getRandomMessages()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
base := cg.curTipset.TipSet()
|
|
||||||
|
|
||||||
for len(blks) == 0 {
|
for len(blks) == 0 {
|
||||||
for i, m := range cg.miners {
|
for i, m := range miners {
|
||||||
proof, t, err := cg.nextBlockProof(context.TODO(), m, ticketSets[i])
|
proof, t, err := cg.nextBlockProof(context.TODO(), m, ticketSets[i])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, xerrors.Errorf("next block proof: %w", err)
|
return nil, xerrors.Errorf("next block proof: %w", err)
|
||||||
@ -274,10 +282,10 @@ func (cg *ChainGen) NextTipSet() (*MinedTipSet, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cg.curTipset = store.NewFullTipSet(blks)
|
fts := store.NewFullTipSet(blks)
|
||||||
|
|
||||||
return &MinedTipSet{
|
return &MinedTipSet{
|
||||||
TipSet: cg.curTipset,
|
TipSet: fts,
|
||||||
Messages: msgs,
|
Messages: msgs,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@ import (
|
|||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"github.com/filecoin-project/go-lotus/api"
|
"github.com/filecoin-project/go-lotus/api"
|
||||||
|
"github.com/filecoin-project/go-lotus/chain/address"
|
||||||
"github.com/filecoin-project/go-lotus/chain/gen"
|
"github.com/filecoin-project/go-lotus/chain/gen"
|
||||||
"github.com/filecoin-project/go-lotus/chain/store"
|
"github.com/filecoin-project/go-lotus/chain/store"
|
||||||
"github.com/filecoin-project/go-lotus/chain/types"
|
"github.com/filecoin-project/go-lotus/chain/types"
|
||||||
@ -91,8 +92,19 @@ func (tu *syncTestUtil) Shutdown() {
|
|||||||
tu.cancel()
|
tu.cancel()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tu *syncTestUtil) mineNewBlock(src int) {
|
func (tu *syncTestUtil) mineNewBlock(src int, miners []int) {
|
||||||
mts, err := tu.g.NextTipSet()
|
if miners == nil {
|
||||||
|
for i := range tu.g.Miners {
|
||||||
|
miners = append(miners, i)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var maddrs []address.Address
|
||||||
|
for i := range miners {
|
||||||
|
maddrs = append(maddrs, tu.g.Miners[i])
|
||||||
|
}
|
||||||
|
|
||||||
|
mts, err := tu.g.NextTipSetFromMiners(maddrs)
|
||||||
require.NoError(tu.t, err)
|
require.NoError(tu.t, err)
|
||||||
|
|
||||||
for _, msg := range mts.Messages {
|
for _, msg := range mts.Messages {
|
||||||
@ -290,12 +302,38 @@ func TestSyncMining(t *testing.T) {
|
|||||||
tu.compareSourceState(client)
|
tu.compareSourceState(client)
|
||||||
|
|
||||||
for i := 0; i < 5; i++ {
|
for i := 0; i < 5; i++ {
|
||||||
tu.mineNewBlock(0)
|
tu.mineNewBlock(0, nil)
|
||||||
tu.waitUntilSync(0, client)
|
tu.waitUntilSync(0, client)
|
||||||
tu.compareSourceState(client)
|
tu.compareSourceState(client)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestSyncFork(t *testing.T) {
|
||||||
|
H := 50
|
||||||
|
tu := prepSyncTest(t, H)
|
||||||
|
|
||||||
|
client := tu.addClientNode()
|
||||||
|
//tu.checkHeight("client", client, 0)
|
||||||
|
|
||||||
|
tu.mineNewBlock(0, []int{0})
|
||||||
|
tu.mineNewBlock(0, []int{0})
|
||||||
|
tu.mineNewBlock(0, []int{0})
|
||||||
|
tu.mineNewBlock(0, []int{0})
|
||||||
|
|
||||||
|
tu.mineNewBlock(1, []int{1})
|
||||||
|
tu.mineNewBlock(1, []int{1})
|
||||||
|
tu.mineNewBlock(1, []int{1})
|
||||||
|
tu.mineNewBlock(1, []int{1})
|
||||||
|
|
||||||
|
require.NoError(t, tu.mn.LinkAll())
|
||||||
|
tu.connect(client, 0)
|
||||||
|
tu.waitUntilSync(0, client)
|
||||||
|
|
||||||
|
//tu.checkHeight("client", client, H)
|
||||||
|
|
||||||
|
tu.compareSourceState(client)
|
||||||
|
}
|
||||||
|
|
||||||
func BenchmarkSyncBasic(b *testing.B) {
|
func BenchmarkSyncBasic(b *testing.B) {
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
runSyncBenchLength(b, 100)
|
runSyncBenchLength(b, 100)
|
||||||
|
@ -99,6 +99,11 @@ func (a *ChainAPI) ChainGetParentMessages(ctx context.Context, bcid cid.Cid) ([]
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// genesis block has no parent messages...
|
||||||
|
if b.Height == 0 {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: need to get the number of messages better than this
|
// TODO: need to get the number of messages better than this
|
||||||
pts, err := a.Chain.LoadTipSet(b.Parents)
|
pts, err := a.Chain.LoadTipSet(b.Parents)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -124,6 +129,10 @@ func (a *ChainAPI) ChainGetParentReceipts(ctx context.Context, bcid cid.Cid) ([]
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if b.Height == 0 {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: need to get the number of messages better than this
|
// TODO: need to get the number of messages better than this
|
||||||
pts, err := a.Chain.LoadTipSet(b.Parents)
|
pts, err := a.Chain.LoadTipSet(b.Parents)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user