aboutsummaryrefslogtreecommitdiffstats
path: root/core/lattice_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'core/lattice_test.go')
-rw-r--r--core/lattice_test.go132
1 files changed, 0 insertions, 132 deletions
diff --git a/core/lattice_test.go b/core/lattice_test.go
index 5c5a667..42b8e06 100644
--- a/core/lattice_test.go
+++ b/core/lattice_test.go
@@ -211,138 +211,6 @@ func (s *LatticeTestSuite) TestBasicUsage() {
}
}
-func (s *LatticeTestSuite) TestSync() {
- // A Lattice prepares blocks on chains randomly selected each time and
- // processes them. Those generated blocks are kept into a buffer, and
- // processed by other Lattice instances with random order.
- var (
- chainNum = uint32(19)
- otherLatticeNum = 50
- )
- if testing.Short() {
- chainNum = 13
- otherLatticeNum = 20
- }
- var (
- blockNum = 500
- // The first `desyncNum` blocks revealed are considered "desynced" and will
- // not be delivered to lattice. After `syncNum` blocks have revealed, the
- // system is considered "synced" and start feeding blocks that are desynced
- // to processFinalizedBlock.
- desyncNum = 50
- syncNum = 150
- req = s.Require()
- err error
- cfg = types.Config{
- NumChains: chainNum,
- NotarySetSize: chainNum,
- PhiRatio: float32(2) / float32(3),
- K: 0,
- MinBlockInterval: 0,
- RoundInterval: time.Hour,
- }
- dMoment = time.Now().UTC()
- master = s.newTestLatticeMgr(&cfg, dMoment)
- revealSeq = map[string]struct{}{}
- )
- // Make sure the test setup is correct.
- req.True(syncNum > desyncNum)
- // Master-lattice generates blocks.
- for i := uint32(0); i < chainNum; i++ {
- // Produced genesis blocks should be delivered before all other blocks,
- // or the consensus time would be wrong.
- b, err := master.prepareBlock(i)
- req.NotNil(b)
- req.NoError(err)
- // Ignore error "acking blocks don't exist".
- req.NoError(master.processBlock(b))
- }
- for i := 0; i < (blockNum - int(chainNum)); i++ {
- b, err := master.prepareBlock(uint32(rand.Intn(int(chainNum))))
- req.NotNil(b)
- req.NoError(err)
- // Ignore error "acking blocks don't exist".
- req.NoError(master.processBlock(b))
- }
- req.NoError(master.app.Verify())
- // Now we have some blocks, replay them on different lattices.
- iter, err := master.db.GetAll()
- req.NoError(err)
- revealer, err := test.NewRandomTipRevealer(iter)
- req.NoError(err)
- for i := 0; i < otherLatticeNum; i++ {
- synced := false
- syncFromHeight := uint64(0)
- revealer.Reset()
- revealed := ""
- other := s.newTestLatticeMgr(&cfg, dMoment)
- chainTip := make([]*types.Block, chainNum)
- for height := 0; ; height++ {
- b, err := revealer.Next()
- if err != nil {
- if err == blockdb.ErrIterationFinished {
- err = nil
- break
- }
- }
- req.NoError(err)
- if height >= syncNum && !synced {
- synced = true
- syncToHeight := uint64(0)
- for _, block := range chainTip {
- if block == nil {
- synced = false
- continue
- }
- result, exist := master.app.Delivered[block.Hash]
- req.True(exist)
- if syncToHeight < result.ConsensusHeight {
- syncToHeight = result.ConsensusHeight
- }
- }
-
- for idx := syncFromHeight; idx < syncToHeight; idx++ {
- block, err := master.db.Get(master.app.DeliverSequence[idx])
- req.Equal(idx+1, block.Finalization.Height)
- req.NoError(err)
- if err = other.db.Put(block); err != nil {
- req.Equal(blockdb.ErrBlockExists, err)
- }
- other.ccModule.processFinalizedBlock(&block)
- }
- extracted := other.ccModule.extractFinalizedBlocks()
- req.Len(extracted, int(syncToHeight-syncFromHeight))
- for _, block := range extracted {
- other.app.StronglyAcked(block.Hash)
- other.lattice.ProcessFinalizedBlock(block)
- }
- syncFromHeight = syncToHeight
- }
- if height > desyncNum {
- if chainTip[b.Position.ChainID] == nil {
- chainTip[b.Position.ChainID] = &b
- }
- if err = other.db.Put(b); err != nil {
- req.Equal(blockdb.ErrBlockExists, err)
- }
- delivered, err := other.lattice.addBlockToLattice(&b)
- req.NoError(err)
- revealed += b.Hash.String() + ","
- revealSeq[revealed] = struct{}{}
- req.NoError(other.lattice.PurgeBlocks(delivered))
- // TODO(jimmy-dexon): check if delivered set is a DAG.
- } else {
- other.app.StronglyAcked(b.Hash)
- }
- }
- for b := range master.app.Acked {
- if _, exist := other.app.Acked[b]; !exist {
- s.FailNowf("Block not delivered", "%s not exists", b)
- }
- }
- }
-}
-
func (s *LatticeTestSuite) TestSanityCheck() {
// This sanity check focuses on hash/signature part.
var (