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
|
||||
|
||||
miners []address.Address
|
||||
Miners []address.Address
|
||||
mworkers []address.Address
|
||||
receivers []address.Address
|
||||
banker address.Address
|
||||
@ -159,7 +159,7 @@ func NewGenerator() (*ChainGen, error) {
|
||||
genesis: genb.Genesis,
|
||||
w: w,
|
||||
|
||||
miners: minercfg.MinerAddrs,
|
||||
Miners: minercfg.MinerAddrs,
|
||||
mworkers: minercfg.Workers,
|
||||
banker: banker,
|
||||
receivers: receievers,
|
||||
@ -241,18 +241,26 @@ type MinedTipSet struct {
|
||||
}
|
||||
|
||||
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
|
||||
ticketSets := make([][]*types.Ticket, len(cg.miners))
|
||||
ticketSets := make([][]*types.Ticket, len(miners))
|
||||
|
||||
msgs, err := cg.getRandomMessages()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
base := cg.curTipset.TipSet()
|
||||
|
||||
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])
|
||||
if err != nil {
|
||||
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{
|
||||
TipSet: cg.curTipset,
|
||||
TipSet: fts,
|
||||
Messages: msgs,
|
||||
}, nil
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"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/store"
|
||||
"github.com/filecoin-project/go-lotus/chain/types"
|
||||
@ -91,8 +92,19 @@ func (tu *syncTestUtil) Shutdown() {
|
||||
tu.cancel()
|
||||
}
|
||||
|
||||
func (tu *syncTestUtil) mineNewBlock(src int) {
|
||||
mts, err := tu.g.NextTipSet()
|
||||
func (tu *syncTestUtil) mineNewBlock(src int, miners []int) {
|
||||
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)
|
||||
|
||||
for _, msg := range mts.Messages {
|
||||
@ -290,12 +302,38 @@ func TestSyncMining(t *testing.T) {
|
||||
tu.compareSourceState(client)
|
||||
|
||||
for i := 0; i < 5; i++ {
|
||||
tu.mineNewBlock(0)
|
||||
tu.mineNewBlock(0, nil)
|
||||
tu.waitUntilSync(0, 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) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
runSyncBenchLength(b, 100)
|
||||
|
@ -99,6 +99,11 @@ func (a *ChainAPI) ChainGetParentMessages(ctx context.Context, bcid cid.Cid) ([]
|
||||
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
|
||||
pts, err := a.Chain.LoadTipSet(b.Parents)
|
||||
if err != nil {
|
||||
@ -124,6 +129,10 @@ func (a *ChainAPI) ChainGetParentReceipts(ctx context.Context, bcid cid.Cid) ([]
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if b.Height == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// TODO: need to get the number of messages better than this
|
||||
pts, err := a.Chain.LoadTipSet(b.Parents)
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user