diff options
-rw-r--r-- | core/consensus_test.go | 17 | ||||
-rw-r--r-- | core/interfaces.go | 3 | ||||
-rw-r--r-- | core/lattice.go | 4 | ||||
-rw-r--r-- | core/nonblocking.go | 13 | ||||
-rw-r--r-- | core/nonblocking_test.go | 9 | ||||
-rw-r--r-- | core/test/app.go | 62 | ||||
-rw-r--r-- | core/test/app_test.go | 19 | ||||
-rw-r--r-- | core/test/stopper_test.go | 2 | ||||
-rw-r--r-- | integration_test/stats.go | 25 | ||||
-rw-r--r-- | integration_test/stats_test.go | 4 | ||||
-rw-r--r-- | simulation/app.go | 5 |
11 files changed, 53 insertions, 110 deletions
diff --git a/core/consensus_test.go b/core/consensus_test.go index f5f1182..7d4d6b4 100644 --- a/core/consensus_test.go +++ b/core/consensus_test.go @@ -372,15 +372,14 @@ func (s *ConsensusTestSuite) TestSimpleDeliverBlock() { // Verify the cached status of each app. verify := func(app *test.App) { - // Check blocks that are strongly acked. - req.Contains(app.Acked, b00.Hash) - req.Contains(app.Acked, b10.Hash) - req.Contains(app.Acked, b20.Hash) - req.Contains(app.Acked, b30.Hash) - req.Contains(app.Acked, b01.Hash) - req.Contains(app.Acked, b11.Hash) - req.Contains(app.Acked, b21.Hash) - req.Contains(app.Acked, b31.Hash) + req.Contains(app.Confirmed, b00.Hash) + req.Contains(app.Confirmed, b10.Hash) + req.Contains(app.Confirmed, b20.Hash) + req.Contains(app.Confirmed, b30.Hash) + req.Contains(app.Confirmed, b01.Hash) + req.Contains(app.Confirmed, b11.Hash) + req.Contains(app.Confirmed, b21.Hash) + req.Contains(app.Confirmed, b31.Hash) // Genesis blocks are delivered by total ordering as a set. delivered0 := common.Hashes{b00.Hash, b10.Hash, b20.Hash, b30.Hash} sort.Sort(delivered0) diff --git a/core/interfaces.go b/core/interfaces.go index e07476d..6979854 100644 --- a/core/interfaces.go +++ b/core/interfaces.go @@ -49,9 +49,6 @@ type Application interface { // Debug describes the application interface that requires // more detailed consensus execution. type Debug interface { - // StronglyAcked is called when a block is strongly acked. - StronglyAcked(blockHash common.Hash) - // TotalOrderingDelivered is called when the total ordering algorithm deliver // a set of block. TotalOrderingDelivered(common.Hashes, uint32) diff --git a/core/lattice.go b/core/lattice.go index f76813d..f94ca5a 100644 --- a/core/lattice.go +++ b/core/lattice.go @@ -211,10 +211,6 @@ func (l *Lattice) addBlockToLattice( } for _, b := range outputBlocks { - // TODO(jimmy-dexon): change this name of classic DEXON algorithm. - if l.debug != nil { - l.debug.StronglyAcked(b.Hash) - } l.logger.Debug("Calling Application.BlockConfirmed", "block", b) l.app.BlockConfirmed(*b.Clone()) // Purge blocks in pool with the same chainID and lower height. diff --git a/core/nonblocking.go b/core/nonblocking.go index a73331f..f94d3c6 100644 --- a/core/nonblocking.go +++ b/core/nonblocking.go @@ -29,10 +29,6 @@ type blockConfirmedEvent struct { block *types.Block } -type stronglyAckedEvent struct { - blockHash common.Hash -} - type totalOrderingDeliveredEvent struct { blockHashes common.Hashes mode uint32 @@ -93,8 +89,6 @@ func (nb *nonBlocking) run() { nb.running.Add(1) }() switch e := event.(type) { - case stronglyAckedEvent: - nb.debug.StronglyAcked(e.blockHash) case blockConfirmedEvent: nb.app.BlockConfirmed(*e.block) case totalOrderingDeliveredEvent: @@ -139,13 +133,6 @@ func (nb *nonBlocking) BlockConfirmed(block types.Block) { nb.addEvent(blockConfirmedEvent{&block}) } -// StronglyAcked is called when a block is strongly acked. -func (nb *nonBlocking) StronglyAcked(blockHash common.Hash) { - if nb.debug != nil { - nb.addEvent(stronglyAckedEvent{blockHash}) - } -} - // TotalOrderingDelivered is called when the total ordering algorithm deliver // a set of block. func (nb *nonBlocking) TotalOrderingDelivered( diff --git a/core/nonblocking_test.go b/core/nonblocking_test.go index d486ca2..cec1d8d 100644 --- a/core/nonblocking_test.go +++ b/core/nonblocking_test.go @@ -31,7 +31,6 @@ import ( type slowApp struct { sleep time.Duration blockConfirmed map[common.Hash]struct{} - stronglyAcked map[common.Hash]struct{} totalOrderingDelivered map[common.Hash]struct{} blockDelivered map[common.Hash]struct{} } @@ -40,7 +39,6 @@ func newSlowApp(sleep time.Duration) *slowApp { return &slowApp{ sleep: sleep, blockConfirmed: make(map[common.Hash]struct{}), - stronglyAcked: make(map[common.Hash]struct{}), totalOrderingDelivered: make(map[common.Hash]struct{}), blockDelivered: make(map[common.Hash]struct{}), } @@ -63,11 +61,6 @@ func (app *slowApp) BlockConfirmed(block types.Block) { app.blockConfirmed[block.Hash] = struct{}{} } -func (app *slowApp) StronglyAcked(blockHash common.Hash) { - time.Sleep(app.sleep) - app.stronglyAcked[blockHash] = struct{}{} -} - func (app *slowApp) TotalOrderingDelivered(blockHashes common.Hashes, mode uint32) { time.Sleep(app.sleep) for _, hash := range blockHashes { @@ -137,7 +130,6 @@ func (s *NonBlockingTestSuite) TestNonBlocking() { Hash: hash, Witness: types.Witness{}, }) - nbModule.StronglyAcked(hash) nbModule.BlockDelivered( hash, types.Position{}, types.FinalizationResult{}) } @@ -149,7 +141,6 @@ func (s *NonBlockingTestSuite) TestNonBlocking() { nbModule.wait() for _, hash := range hashes { s.Contains(app.blockConfirmed, hash) - s.Contains(app.stronglyAcked, hash) s.Contains(app.totalOrderingDelivered, hash) s.Contains(app.blockDelivered, hash) } diff --git a/core/test/app.go b/core/test/app.go index e67d5c9..327555b 100644 --- a/core/test/app.go +++ b/core/test/app.go @@ -47,21 +47,15 @@ var ( // consensus height not equal to height of previous block plus one. ErrConsensusHeightOutOfOrder = fmt.Errorf( "consensus height out of order") - // ErrDeliveredBlockNotAcked means some block delivered (confirmed) but - // not strongly acked. - ErrDeliveredBlockNotAcked = fmt.Errorf("delivered block not acked") + // ErrDeliveredBlockNotConfirmed means some block delivered (confirmed) but + // not confirmed. + ErrDeliveredBlockNotConfirmed = fmt.Errorf("delivered block not confirmed") // ErrMismatchTotalOrderingAndDelivered mean the sequence of total ordering // and delivered are different. ErrMismatchTotalOrderingAndDelivered = fmt.Errorf( "mismatch total ordering and delivered sequence") ) -// AppAckedRecord caches information when this application received -// a strongly-acked notification. -type AppAckedRecord struct { - When time.Time -} - // AppTotalOrderRecord caches information when this application received // a total-ordering deliver notification. type AppTotalOrderRecord struct { @@ -81,28 +75,25 @@ type AppDeliveredRecord struct { // App implements Application interface for testing purpose. type App struct { - Acked map[common.Hash]*AppAckedRecord - ackedLock sync.RWMutex + Confirmed map[common.Hash]*types.Block + confirmedLock sync.RWMutex TotalOrdered []*AppTotalOrderRecord TotalOrderedByHash map[common.Hash]*AppTotalOrderRecord totalOrderedLock sync.RWMutex Delivered map[common.Hash]*AppDeliveredRecord DeliverSequence common.Hashes deliveredLock sync.RWMutex - blocks map[common.Hash]*types.Block - blocksLock sync.RWMutex state *State } // NewApp constructs a TestApp instance. func NewApp(state *State) *App { return &App{ - Acked: make(map[common.Hash]*AppAckedRecord), + Confirmed: make(map[common.Hash]*types.Block), TotalOrdered: []*AppTotalOrderRecord{}, TotalOrderedByHash: make(map[common.Hash]*AppTotalOrderRecord), Delivered: make(map[common.Hash]*AppDeliveredRecord), DeliverSequence: common.Hashes{}, - blocks: make(map[common.Hash]*types.Block), state: state, } } @@ -129,17 +120,9 @@ func (app *App) VerifyBlock(block *types.Block) types.BlockVerifyStatus { // BlockConfirmed implements Application interface. func (app *App) BlockConfirmed(b types.Block) { - app.blocksLock.Lock() - defer app.blocksLock.Unlock() - app.blocks[b.Hash] = &b -} - -// StronglyAcked implements Application interface. -func (app *App) StronglyAcked(blockHash common.Hash) { - app.ackedLock.Lock() - defer app.ackedLock.Unlock() - - app.Acked[blockHash] = &AppAckedRecord{When: time.Now().UTC()} + app.confirmedLock.Lock() + defer app.confirmedLock.Unlock() + app.Confirmed[b.Hash] = &b } // TotalOrderingDelivered implements Application interface. @@ -180,9 +163,9 @@ func (app *App) BlockDelivered( if app.state == nil { return } - app.blocksLock.RLock() - defer app.blocksLock.RUnlock() - b := app.blocks[blockHash] + app.confirmedLock.RLock() + defer app.confirmedLock.RUnlock() + b := app.Confirmed[blockHash] if err := app.state.Apply(b.Payload); err != nil { if err != ErrDuplicatedChange { panic(err) @@ -196,12 +179,12 @@ func (app *App) BlockDelivered( func (app *App) GetLatestDeliveredPosition() types.Position { app.deliveredLock.RLock() defer app.deliveredLock.RUnlock() - app.blocksLock.RLock() - defer app.blocksLock.RUnlock() + app.confirmedLock.RLock() + defer app.confirmedLock.RUnlock() if len(app.DeliverSequence) == 0 { return types.Position{} } - return app.blocks[app.DeliverSequence[len(app.DeliverSequence)-1]].Position + return app.Confirmed[app.DeliverSequence[len(app.DeliverSequence)-1]].Position } // Compare performs these checks against another App instance @@ -236,6 +219,8 @@ func (app *App) Compare(other *App) error { // Verify checks the integrity of date received by this App instance. func (app *App) Verify() error { // TODO(mission): verify blocks' position when delivered. + app.confirmedLock.RLock() + defer app.confirmedLock.RUnlock() app.deliveredLock.RLock() defer app.deliveredLock.RUnlock() @@ -245,16 +230,11 @@ func (app *App) Verify() error { if len(app.DeliverSequence) != len(app.Delivered) { return ErrApplicationIntegrityFailed } - - app.ackedLock.RLock() - defer app.ackedLock.RUnlock() - expectHeight := uint64(1) prevTime := time.Time{} for _, h := range app.DeliverSequence { - // Make sure delivered block is strongly acked. - if _, acked := app.Acked[h]; !acked { - return ErrDeliveredBlockNotAcked + if _, exists := app.Confirmed[h]; !exists { + return ErrDeliveredBlockNotConfirmed } rec, exists := app.Delivered[h] if !exists { @@ -302,8 +282,8 @@ Loop: // Check provides a backdoor to check status of App with reader lock. func (app *App) Check(checker func(*App)) { - app.ackedLock.RLock() - defer app.ackedLock.RUnlock() + app.confirmedLock.RLock() + defer app.confirmedLock.RUnlock() app.totalOrderedLock.RLock() defer app.totalOrderedLock.RUnlock() app.deliveredLock.RLock() diff --git a/core/test/app_test.go b/core/test/app_test.go index 4a7c4b9..61672a4 100644 --- a/core/test/app_test.go +++ b/core/test/app_test.go @@ -59,9 +59,8 @@ func (s *AppTestSuite) SetupSuite() { func (s *AppTestSuite) setupAppByTotalOrderDeliver( app *App, to *AppTotalOrderRecord) { - for _, h := range to.BlockHashes { - app.StronglyAcked(h) + app.BlockConfirmed(types.Block{Hash: h}) } app.TotalOrderingDelivered(to.BlockHashes, to.Mode) for _, h := range to.BlockHashes { @@ -100,7 +99,7 @@ func (s *AppTestSuite) TestCompare() { s.setupAppByTotalOrderDeliver(app2, s.to1) s.setupAppByTotalOrderDeliver(app2, s.to2) hash := common.NewRandomHash() - app2.StronglyAcked(hash) + app2.BlockConfirmed(types.Block{Hash: hash}) app2.TotalOrderingDelivered(common.Hashes{hash}, core.TotalOrderingModeNormal) s.deliverBlockWithTimeFromSequenceLength(app2, hash) req.Equal(ErrMismatchBlockHashSequence, app1.Compare(app2)) @@ -109,7 +108,7 @@ func (s *AppTestSuite) TestCompare() { s.setupAppByTotalOrderDeliver(app3, s.to1) s.setupAppByTotalOrderDeliver(app3, s.to2) for _, h := range s.to3.BlockHashes { - app3.StronglyAcked(h) + app3.BlockConfirmed(types.Block{Hash: h}) } app3.TotalOrderingDelivered(s.to3.BlockHashes, s.to3.Mode) wrongTime := time.Time{}.Add( @@ -137,12 +136,12 @@ func (s *AppTestSuite) TestVerify() { // A delivered block without strongly ack s.deliverBlock(app1, common.NewRandomHash(), time.Time{}, uint64(len(app1.DeliverSequence))) - req.Equal(ErrDeliveredBlockNotAcked, app1.Verify()) + req.Equal(ErrDeliveredBlockNotConfirmed, app1.Verify()) // The consensus time is out of order. app2 := NewApp(nil) s.setupAppByTotalOrderDeliver(app2, s.to1) for _, h := range s.to2.BlockHashes { - app2.StronglyAcked(h) + app2.BlockConfirmed(types.Block{Hash: h}) } app2.TotalOrderingDelivered(s.to2.BlockHashes, s.to2.Mode) s.deliverBlock(app2, s.to2.BlockHashes[0], time.Time{}, @@ -152,18 +151,18 @@ func (s *AppTestSuite) TestVerify() { app3 := NewApp(nil) s.setupAppByTotalOrderDeliver(app3, s.to1) hash := common.NewRandomHash() - app3.StronglyAcked(hash) + app3.BlockConfirmed(types.Block{Hash: hash}) s.deliverBlockWithTimeFromSequenceLength(app3, hash) req.Equal(ErrMismatchTotalOrderingAndDelivered, app3.Verify()) // A delivered block is not found in total ordering delivers. app4 := NewApp(nil) s.setupAppByTotalOrderDeliver(app4, s.to1) for _, h := range s.to2.BlockHashes { - app4.StronglyAcked(h) + app4.BlockConfirmed(types.Block{Hash: h}) } app4.TotalOrderingDelivered(s.to2.BlockHashes, s.to2.Mode) hash = common.NewRandomHash() - app4.StronglyAcked(hash) + app4.BlockConfirmed(types.Block{Hash: hash}) app4.TotalOrderingDelivered(common.Hashes{hash}, core.TotalOrderingModeNormal) s.deliverBlockWithTimeFromSequenceLength(app4, hash) // Witness ack on unknown block. @@ -173,7 +172,7 @@ func (s *AppTestSuite) TestVerify() { app6 := NewApp(nil) s.setupAppByTotalOrderDeliver(app6, s.to1) for _, h := range s.to2.BlockHashes { - app6.StronglyAcked(h) + app6.BlockConfirmed(types.Block{Hash: h}) } app6.TotalOrderingDelivered(s.to2.BlockHashes, s.to2.Mode) s.deliverBlock(app6, s.to2.BlockHashes[0], time.Time{}.Add( diff --git a/core/test/stopper_test.go b/core/test/stopper_test.go index d823f59..b34e7b2 100644 --- a/core/test/stopper_test.go +++ b/core/test/stopper_test.go @@ -40,7 +40,7 @@ func (s *StopperTestSuite) deliver( s.Require().NoError(db.Put(*b)) } for _, h := range hashes { - app.StronglyAcked(h) + app.BlockConfirmed(types.Block{Hash: h}) } app.TotalOrderingDelivered(hashes, core.TotalOrderingModeNormal) for _, h := range hashes { diff --git a/integration_test/stats.go b/integration_test/stats.go index 311e21a..79f1c20 100644 --- a/integration_test/stats.go +++ b/integration_test/stats.go @@ -17,15 +17,15 @@ var ( // StatsSet represents accumulatee result of a group of related events // (ex. All events from one node). type StatsSet struct { - ProposedBlockCount int - ReceivedBlockCount int - StronglyAckedBlockCount int - TotalOrderedBlockCount int - DeliveredBlockCount int - ProposingLatency time.Duration - ReceivingLatency time.Duration - PrepareExecLatency time.Duration - ProcessExecLatency time.Duration + ProposedBlockCount int + ReceivedBlockCount int + ConfirmedBlockCount int + TotalOrderedBlockCount int + DeliveredBlockCount int + ProposingLatency time.Duration + ReceivingLatency time.Duration + PrepareExecLatency time.Duration + ProcessExecLatency time.Duration } // newBlockProposeEvent accumulates a block proposing event. @@ -59,12 +59,11 @@ func (s *StatsSet) newBlockReceiveEvent( // Find statistics from test.App block := payload.PiggyBack.(*types.Block) app.Check(func(app *test.App) { - // Is this block strongly acked? - if _, exists := app.Acked[block.Hash]; !exists { + // Is this block confirmed? + if _, exists := app.Confirmed[block.Hash]; !exists { return } - s.StronglyAckedBlockCount++ - + s.ConfirmedBlockCount++ // Is this block total ordered? if _, exists := app.TotalOrderedByHash[block.Hash]; !exists { return diff --git a/integration_test/stats_test.go b/integration_test/stats_test.go index 1830501..d61799b 100644 --- a/integration_test/stats_test.go +++ b/integration_test/stats_test.go @@ -42,7 +42,7 @@ func (s *EventStatsTestSuite) TestCalculate() { req.Nil(err) req.True(stats.All.ProposedBlockCount > 350) req.True(stats.All.ReceivedBlockCount > 350) - req.True(stats.All.StronglyAckedBlockCount > 350) + req.True(stats.All.ConfirmedBlockCount > 350) req.True(stats.All.TotalOrderedBlockCount >= 350) req.True(stats.All.DeliveredBlockCount >= 350) req.Equal(stats.All.ProposingLatency, 300*time.Millisecond) @@ -51,7 +51,7 @@ func (s *EventStatsTestSuite) TestCalculate() { for _, vStats := range stats.ByNode { req.True(vStats.ProposedBlockCount > 50) req.True(vStats.ReceivedBlockCount > 50) - req.True(vStats.StronglyAckedBlockCount > 50) + req.True(vStats.ConfirmedBlockCount > 50) req.True(vStats.TotalOrderedBlockCount >= 50) req.True(vStats.DeliveredBlockCount >= 50) req.Equal(vStats.ProposingLatency, 300*time.Millisecond) diff --git a/simulation/app.go b/simulation/app.go index 9195619..89d76ae 100644 --- a/simulation/app.go +++ b/simulation/app.go @@ -132,11 +132,6 @@ func (a *simApp) PrepareWitness(height uint64) (types.Witness, error) { return a.latestWitness, nil } -// StronglyAcked is called when a block is strongly acked by DEXON -// Reliabe Broadcast algorithm. -func (a *simApp) StronglyAcked(blockHash common.Hash) { -} - // TotalOrderingDelivered is called when blocks are delivered by the total // ordering algorithm. func (a *simApp) TotalOrderingDelivered( |