a bit more hacking to make the test framework bend to my will
This commit is contained in:
parent
fca5a4765d
commit
76ceb1f25a
@ -45,7 +45,7 @@ type ChainGen struct {
|
||||
sm *stmgr.StateManager
|
||||
|
||||
genesis *types.BlockHeader
|
||||
curTipset *store.FullTipSet
|
||||
CurTipset *store.FullTipSet
|
||||
|
||||
w *wallet.Wallet
|
||||
|
||||
@ -164,7 +164,7 @@ func NewGenerator() (*ChainGen, error) {
|
||||
banker: banker,
|
||||
receivers: receievers,
|
||||
|
||||
curTipset: gents,
|
||||
CurTipset: gents,
|
||||
|
||||
r: mr,
|
||||
lr: lr,
|
||||
@ -192,7 +192,7 @@ func (cg *ChainGen) GenesisCar() ([]byte, error) {
|
||||
}
|
||||
|
||||
func (cg *ChainGen) nextBlockProof(ctx context.Context, m address.Address, ticks []*types.Ticket) (types.ElectionProof, *types.Ticket, error) {
|
||||
pts := cg.curTipset.TipSet()
|
||||
pts := cg.CurTipset.TipSet()
|
||||
|
||||
var lastTicket *types.Ticket
|
||||
if len(ticks) == 0 {
|
||||
@ -201,7 +201,7 @@ func (cg *ChainGen) nextBlockProof(ctx context.Context, m address.Address, ticks
|
||||
lastTicket = ticks[len(ticks)-1]
|
||||
}
|
||||
|
||||
st := cg.curTipset.TipSet().ParentState()
|
||||
st := cg.CurTipset.TipSet().ParentState()
|
||||
|
||||
worker, err := stmgr.GetMinerWorker(ctx, cg.sm, st, m)
|
||||
if err != nil {
|
||||
@ -241,12 +241,12 @@ type MinedTipSet struct {
|
||||
}
|
||||
|
||||
func (cg *ChainGen) NextTipSet() (*MinedTipSet, error) {
|
||||
mts, err := cg.NextTipSetFromMiners(cg.curTipset.TipSet(), cg.Miners)
|
||||
mts, err := cg.NextTipSetFromMiners(cg.CurTipset.TipSet(), cg.Miners)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
cg.curTipset = mts.TipSet
|
||||
cg.CurTipset = mts.TipSet
|
||||
return mts, nil
|
||||
}
|
||||
|
||||
@ -273,7 +273,7 @@ func (cg *ChainGen) NextTipSetFromMiners(base *types.TipSet, miners []address.Ad
|
||||
return nil, xerrors.Errorf("making a block for next tipset failed: %w", err)
|
||||
}
|
||||
|
||||
if err := cg.cs.AddBlock(fblk.Header); err != nil {
|
||||
if err := cg.cs.PersistBlockHeader(fblk.Header); err != nil {
|
||||
return nil, xerrors.Errorf("chainstore AddBlock: %w", err)
|
||||
}
|
||||
|
||||
@ -333,10 +333,6 @@ func (cg *ChainGen) getRandomMessages() ([]*types.SignedMessage, error) {
|
||||
Message: msg,
|
||||
Signature: *sig,
|
||||
}
|
||||
|
||||
if _, err := cg.cs.PutMessage(msgs[m]); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return msgs, nil
|
||||
|
@ -60,8 +60,14 @@ func MinerCreateBlock(ctx context.Context, sm *stmgr.StateManager, w *wallet.Wal
|
||||
|
||||
blsMsgCids = append(blsMsgCids, c)
|
||||
} else {
|
||||
secpkMsgCids = append(secpkMsgCids, msg.Cid())
|
||||
c, err := sm.ChainStore().PutMessage(msg)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
secpkMsgCids = append(secpkMsgCids, c)
|
||||
secpkMessages = append(secpkMessages, msg)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -96,7 +96,7 @@ func (syncer *Syncer) InformNewHead(from peer.ID, fts *store.FullTipSet) {
|
||||
}
|
||||
if from == syncer.self {
|
||||
// TODO: this is kindof a hack...
|
||||
log.Debug("got block from ourselves")
|
||||
log.Info("got block from ourselves")
|
||||
|
||||
if err := syncer.Sync(fts); err != nil {
|
||||
log.Errorf("failed to sync our own block: %+v", err)
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
"testing"
|
||||
|
||||
logging "github.com/ipfs/go-log"
|
||||
"github.com/libp2p/go-libp2p-core/peer"
|
||||
mocknet "github.com/libp2p/go-libp2p/p2p/net/mock"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
@ -15,6 +16,7 @@ import (
|
||||
"github.com/filecoin-project/go-lotus/chain/store"
|
||||
"github.com/filecoin-project/go-lotus/chain/types"
|
||||
"github.com/filecoin-project/go-lotus/node"
|
||||
"github.com/filecoin-project/go-lotus/node/impl"
|
||||
"github.com/filecoin-project/go-lotus/node/modules"
|
||||
"github.com/filecoin-project/go-lotus/node/repo"
|
||||
)
|
||||
@ -32,7 +34,6 @@ func (tu *syncTestUtil) repoWithChain(t testing.TB, h int) (repo.Repo, []byte, [
|
||||
|
||||
ts := mts.TipSet.TipSet()
|
||||
fmt.Printf("tipset at H:%d: %s\n", ts.Height(), ts.Cids())
|
||||
|
||||
}
|
||||
|
||||
r, err := tu.g.YieldRepo()
|
||||
@ -92,7 +93,7 @@ func (tu *syncTestUtil) Shutdown() {
|
||||
tu.cancel()
|
||||
}
|
||||
|
||||
func (tu *syncTestUtil) mineNewBlock(src int, miners []int) {
|
||||
func (tu *syncTestUtil) mineOnBlock(blk *store.FullTipSet, src int, miners []int) *store.FullTipSet {
|
||||
if miners == nil {
|
||||
for i := range tu.g.Miners {
|
||||
miners = append(miners, i)
|
||||
@ -104,7 +105,7 @@ func (tu *syncTestUtil) mineNewBlock(src int, miners []int) {
|
||||
maddrs = append(maddrs, tu.g.Miners[i])
|
||||
}
|
||||
|
||||
mts, err := tu.g.NextTipSetFromMiners(maddrs)
|
||||
mts, err := tu.g.NextTipSetFromMiners(blk.TipSet(), maddrs)
|
||||
require.NoError(tu.t, err)
|
||||
|
||||
for _, msg := range mts.Messages {
|
||||
@ -114,6 +115,13 @@ func (tu *syncTestUtil) mineNewBlock(src int, miners []int) {
|
||||
for _, fblk := range mts.TipSet.Blocks {
|
||||
require.NoError(tu.t, tu.nds[src].ChainSubmitBlock(context.TODO(), fblkToBlkMsg(fblk)))
|
||||
}
|
||||
|
||||
return mts.TipSet
|
||||
}
|
||||
|
||||
func (tu *syncTestUtil) mineNewBlock(src int, miners []int) {
|
||||
mts := tu.mineOnBlock(tu.g.CurTipset, src, miners)
|
||||
tu.g.CurTipset = mts
|
||||
}
|
||||
|
||||
func fblkToBlkMsg(fb *types.FullBlock) *types.BlockMsg {
|
||||
@ -149,6 +157,12 @@ func (tu *syncTestUtil) addSourceNode(gen int) {
|
||||
)
|
||||
require.NoError(tu.t, err)
|
||||
|
||||
lastTs := blocks[len(blocks)-1].Blocks
|
||||
for _, lastB := range lastTs {
|
||||
err = out.(*impl.FullNodeAPI).ChainAPI.Chain.AddBlock(lastB.Header)
|
||||
require.NoError(tu.t, err)
|
||||
}
|
||||
|
||||
tu.genesis = genesis
|
||||
tu.blocks = blocks
|
||||
tu.nds = append(tu.nds, out) // always at 0
|
||||
@ -176,6 +190,13 @@ func (tu *syncTestUtil) addClientNode() int {
|
||||
return len(tu.nds) - 1
|
||||
}
|
||||
|
||||
func (tu *syncTestUtil) pid(n int) peer.ID {
|
||||
nal, err := tu.nds[n].NetAddrsListen(tu.ctx)
|
||||
require.NoError(tu.t, err)
|
||||
|
||||
return nal.ID
|
||||
}
|
||||
|
||||
func (tu *syncTestUtil) connect(from, to int) {
|
||||
toPI, err := tu.nds[to].NetAddrsListen(tu.ctx)
|
||||
require.NoError(tu.t, err)
|
||||
@ -184,6 +205,14 @@ func (tu *syncTestUtil) connect(from, to int) {
|
||||
require.NoError(tu.t, err)
|
||||
}
|
||||
|
||||
func (tu *syncTestUtil) disconnect(from, to int) {
|
||||
toPI, err := tu.nds[to].NetAddrsListen(tu.ctx)
|
||||
require.NoError(tu.t, err)
|
||||
|
||||
err = tu.nds[from].NetDisconnect(tu.ctx, toPI.ID)
|
||||
require.NoError(tu.t, err)
|
||||
}
|
||||
|
||||
func (tu *syncTestUtil) checkHeight(name string, n int, h int) {
|
||||
b, err := tu.nds[n].ChainHead(tu.ctx)
|
||||
require.NoError(tu.t, err)
|
||||
@ -244,32 +273,6 @@ func (tu *syncTestUtil) waitUntilSync(from, to int) {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
func (tu *syncTestUtil) submitSourceBlock(to int, h int) {
|
||||
// utility to simulate incoming blocks without miner process
|
||||
// TODO: should call syncer directly, this won't work correctly in all cases
|
||||
|
||||
var b chain.BlockMsg
|
||||
|
||||
// -1 to match block.Height
|
||||
b.Header = tu.blocks[h-1].Header
|
||||
for _, msg := range tu.blocks[h-1].SecpkMessages {
|
||||
c, err := tu.nds[to].(*impl.FullNodeAPI).ChainAPI.Chain.PutMessage(msg)
|
||||
require.NoError(tu.t, err)
|
||||
|
||||
b.SecpkMessages = append(b.SecpkMessages, c)
|
||||
}
|
||||
|
||||
require.NoError(tu.t, tu.nds[to].ChainSubmitBlock(tu.ctx, &b))
|
||||
}
|
||||
|
||||
func (tu *syncTestUtil) submitSourceBlocks(to int, h int, n int) {
|
||||
for i := 0; i < n; i++ {
|
||||
tu.submitSourceBlock(to, h+i)
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
func TestSyncSimple(t *testing.T) {
|
||||
H := 50
|
||||
tu := prepSyncTest(t, H)
|
||||
@ -308,32 +311,6 @@ func TestSyncMining(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
@ -353,44 +330,3 @@ func runSyncBenchLength(b *testing.B, l int) {
|
||||
|
||||
tu.waitUntilSync(0, client)
|
||||
}
|
||||
|
||||
/*
|
||||
TODO: this is broken because of how tu.submitSourceBlock works now
|
||||
func TestSyncManual(t *testing.T) {
|
||||
H := 20
|
||||
tu := prepSyncTest(t, H)
|
||||
|
||||
client := tu.addClientNode()
|
||||
tu.checkHeight("client", client, 0)
|
||||
|
||||
tu.submitSourceBlocks(client, 1, H)
|
||||
|
||||
time.Sleep(time.Second * 1)
|
||||
|
||||
tu.checkHeight("client", client, H)
|
||||
|
||||
tu.compareSourceState(client)
|
||||
}
|
||||
|
||||
func TestSyncIncoming(t *testing.T) {
|
||||
H := 1
|
||||
tu := prepSyncTest(t, H)
|
||||
|
||||
producer := tu.addClientNode()
|
||||
client := tu.addClientNode()
|
||||
|
||||
tu.mn.LinkAll()
|
||||
tu.connect(client, producer)
|
||||
|
||||
for h := 0; h < H; h++ {
|
||||
tu.submitSourceBlock(producer, h + 1)
|
||||
|
||||
time.Sleep(time.Millisecond * 200)
|
||||
|
||||
}
|
||||
tu.checkHeight("client", client, H)
|
||||
tu.checkHeight("producer", producer, H)
|
||||
|
||||
tu.compareSourceState(client)
|
||||
}
|
||||
*/
|
||||
|
@ -27,9 +27,7 @@ func (a *ChainAPI) ChainNotify(ctx context.Context) (<-chan []*store.HeadChange,
|
||||
}
|
||||
|
||||
func (a *ChainAPI) ChainSubmitBlock(ctx context.Context, blk *types.BlockMsg) error {
|
||||
if err := a.Chain.AddBlock(blk.Header); err != nil {
|
||||
return xerrors.Errorf("AddBlock failed: %w", err)
|
||||
}
|
||||
// TODO: should we have some sort of fast path to adding a local block?
|
||||
|
||||
b, err := blk.Serialize()
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user