diff options
-rw-r--r-- | core/consensus.go | 6 | ||||
-rw-r--r-- | core/interfaces.go | 16 | ||||
-rw-r--r-- | core/nonblocking.go | 36 | ||||
-rw-r--r-- | core/nonblocking_test.go | 50 | ||||
-rw-r--r-- | core/shard.go | 2 | ||||
-rw-r--r-- | core/shard_test.go | 2 | ||||
-rw-r--r-- | core/test/app.go | 16 | ||||
-rw-r--r-- | core/test/app_test.go | 16 | ||||
-rw-r--r-- | core/test/stopper_test.go | 4 | ||||
-rw-r--r-- | integration_test/node.go | 2 | ||||
-rw-r--r-- | simulation/app.go | 16 |
11 files changed, 83 insertions, 83 deletions
diff --git a/core/consensus.go b/core/consensus.go index 1758507..8ada7ae 100644 --- a/core/consensus.go +++ b/core/consensus.go @@ -560,7 +560,7 @@ func (con *Consensus) processWitnessData() { if err != nil { panic(err) } - con.nbModule.WitnessAckDeliver(witnessAck) + con.nbModule.WitnessAckDelivered(witnessAck) } } } @@ -645,7 +645,7 @@ func (con *Consensus) processBlock(block *types.Block) (err error) { for idx := range deliveredBlocks { hashes[idx] = deliveredBlocks[idx].Hash } - con.nbModule.TotalOrderingDeliver(hashes, earlyDelivered) + con.nbModule.TotalOrderingDelivered(hashes, earlyDelivered) // Perform timestamp generation. err = con.ctModule.processBlocks(deliveredBlocks) if err != nil { @@ -658,7 +658,7 @@ func (con *Consensus) processBlock(block *types.Block) (err error) { if err = con.db.Update(*b); err != nil { return } - con.nbModule.BlockDeliver(*b) + con.nbModule.BlockDelivered(*b) // TODO(mission): Find a way to safely recycle the block. // We should deliver block directly to // nonBlocking and let them recycle the diff --git a/core/interfaces.go b/core/interfaces.go index 03caa63..4e0b4cc 100644 --- a/core/interfaces.go +++ b/core/interfaces.go @@ -30,18 +30,18 @@ type Application interface { // PreparePayload is called when consensus core is preparing a block. PreparePayload(position types.Position) []byte - // VerifyPayloads verifies if the payloads are valid. - VerifyPayloads(payloads []byte) bool + // VerifyPayload verifies if the payloads are valid. + VerifyPayload(payloads []byte) bool - // BlockDeliver is called when a block is add to the compaction chain. - BlockDeliver(block types.Block) + // BlockDelivered is called when a block is add to the compaction chain. + BlockDelivered(block types.Block) // BlockProcessedChan returns a channel to receive the block hashes that have // finished processing by the application. BlockProcessedChan() <-chan types.WitnessResult - // WitnessAckDeliver is called when a witness ack is created. - WitnessAckDeliver(witnessAck *types.WitnessAck) + // WitnessAckDelivered is called when a witness ack is created. + WitnessAckDelivered(witnessAck *types.WitnessAck) } // Debug describes the application interface that requires @@ -53,9 +53,9 @@ type Debug interface { // StronglyAcked is called when a block is strongly acked. StronglyAcked(blockHash common.Hash) - // TotalOrderingDeliver is called when the total ordering algorithm deliver + // TotalOrderingDelivered is called when the total ordering algorithm deliver // a set of block. - TotalOrderingDeliver(blockHashes common.Hashes, early bool) + TotalOrderingDelivered(blockHashes common.Hashes, early bool) } // Network describs the network interface that interacts with DEXON consensus diff --git a/core/nonblocking.go b/core/nonblocking.go index 5d7311e..7c685dc 100644 --- a/core/nonblocking.go +++ b/core/nonblocking.go @@ -33,12 +33,12 @@ type stronglyAckedEvent struct { blockHash common.Hash } -type totalOrderingDeliverEvent struct { +type totalOrderingDeliveredEvent struct { blockHashes common.Hashes early bool } -type blockDeliverEvent struct { +type blockDeliveredEvent struct { block *types.Block } @@ -99,12 +99,12 @@ func (nb *nonBlocking) run() { nb.debug.StronglyAcked(e.blockHash) case blockConfirmedEvent: nb.debug.BlockConfirmed(e.blockHash) - case totalOrderingDeliverEvent: - nb.debug.TotalOrderingDeliver(e.blockHashes, e.early) - case blockDeliverEvent: - nb.app.BlockDeliver(*e.block) + case totalOrderingDeliveredEvent: + nb.debug.TotalOrderingDelivered(e.blockHashes, e.early) + case blockDeliveredEvent: + nb.app.BlockDelivered(*e.block) case witnessAckEvent: - nb.app.WitnessAckDeliver(e.witnessAck) + nb.app.WitnessAckDelivered(e.witnessAck) default: fmt.Printf("Unknown event %v.", e) } @@ -129,9 +129,9 @@ func (nb *nonBlocking) PreparePayload( return nb.app.PreparePayload(position) } -// VerifyPayloads cannot be non-blocking. -func (nb *nonBlocking) VerifyPayloads(payloads []byte) bool { - return nb.app.VerifyPayloads(payloads) +// VerifyPayload cannot be non-blocking. +func (nb *nonBlocking) VerifyPayload(payloads []byte) bool { + return nb.app.VerifyPayload(payloads) } // BlockConfirmed is called when a block is confirmed and added to lattice. @@ -148,18 +148,18 @@ func (nb *nonBlocking) StronglyAcked(blockHash common.Hash) { } } -// TotalOrderingDeliver is called when the total ordering algorithm deliver +// TotalOrderingDelivered is called when the total ordering algorithm deliver // a set of block. -func (nb *nonBlocking) TotalOrderingDeliver( +func (nb *nonBlocking) TotalOrderingDelivered( blockHashes common.Hashes, early bool) { if nb.debug != nil { - nb.addEvent(totalOrderingDeliverEvent{blockHashes, early}) + nb.addEvent(totalOrderingDeliveredEvent{blockHashes, early}) } } -// BlockDeliver is called when a block is add to the compaction chain. -func (nb *nonBlocking) BlockDeliver(block types.Block) { - nb.addEvent(blockDeliverEvent{&block}) +// BlockDelivered is called when a block is add to the compaction chain. +func (nb *nonBlocking) BlockDelivered(block types.Block) { + nb.addEvent(blockDeliveredEvent{&block}) } // BlockProcessedChan returns a channel to receive the block hashes that have @@ -168,7 +168,7 @@ func (nb *nonBlocking) BlockProcessedChan() <-chan types.WitnessResult { return nb.app.BlockProcessedChan() } -// WitnessAckDeliver is called when a witness ack is created. -func (nb *nonBlocking) WitnessAckDeliver(witnessAck *types.WitnessAck) { +// WitnessAckDelivered is called when a witness ack is created. +func (nb *nonBlocking) WitnessAckDelivered(witnessAck *types.WitnessAck) { nb.addEvent(witnessAckEvent{witnessAck}) } diff --git a/core/nonblocking_test.go b/core/nonblocking_test.go index f7dc9bc..d4ffb26 100644 --- a/core/nonblocking_test.go +++ b/core/nonblocking_test.go @@ -28,24 +28,24 @@ import ( ) type slowApp struct { - sleep time.Duration - blockConfirmed map[common.Hash]struct{} - stronglyAcked map[common.Hash]struct{} - totalOrderingDeliver map[common.Hash]struct{} - blockDeliver map[common.Hash]struct{} - witnessAck map[common.Hash]struct{} - witnessResultChan chan types.WitnessResult + sleep time.Duration + blockConfirmed map[common.Hash]struct{} + stronglyAcked map[common.Hash]struct{} + totalOrderingDelivered map[common.Hash]struct{} + blockDelivered map[common.Hash]struct{} + witnessAck map[common.Hash]struct{} + witnessResultChan chan types.WitnessResult } func newSlowApp(sleep time.Duration) *slowApp { return &slowApp{ - sleep: sleep, - blockConfirmed: make(map[common.Hash]struct{}), - stronglyAcked: make(map[common.Hash]struct{}), - totalOrderingDeliver: make(map[common.Hash]struct{}), - blockDeliver: make(map[common.Hash]struct{}), - witnessAck: make(map[common.Hash]struct{}), - witnessResultChan: make(chan types.WitnessResult), + 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{}), + witnessAck: make(map[common.Hash]struct{}), + witnessResultChan: make(chan types.WitnessResult), } } @@ -53,7 +53,7 @@ func (app *slowApp) PreparePayload(_ types.Position) []byte { return []byte{} } -func (app *slowApp) VerifyPayloads(_ []byte) bool { +func (app *slowApp) VerifyPayload(_ []byte) bool { return true } @@ -67,23 +67,23 @@ func (app *slowApp) StronglyAcked(blockHash common.Hash) { app.stronglyAcked[blockHash] = struct{}{} } -func (app *slowApp) TotalOrderingDeliver(blockHashes common.Hashes, early bool) { +func (app *slowApp) TotalOrderingDelivered(blockHashes common.Hashes, early bool) { time.Sleep(app.sleep) for _, hash := range blockHashes { - app.totalOrderingDeliver[hash] = struct{}{} + app.totalOrderingDelivered[hash] = struct{}{} } } -func (app *slowApp) BlockDeliver(block types.Block) { +func (app *slowApp) BlockDelivered(block types.Block) { time.Sleep(app.sleep) - app.blockDeliver[block.Hash] = struct{}{} + app.blockDelivered[block.Hash] = struct{}{} } func (app *slowApp) BlockProcessedChan() <-chan types.WitnessResult { return app.witnessResultChan } -func (app *slowApp) WitnessAckDeliver(witnessAck *types.WitnessAck) { +func (app *slowApp) WitnessAckDelivered(witnessAck *types.WitnessAck) { time.Sleep(app.sleep) app.witnessAck[witnessAck.Hash] = struct{}{} } @@ -107,13 +107,13 @@ func (s *NonBlockingTestSuite) TestNonBlocking() { for _, hash := range hashes { nbModule.BlockConfirmed(hash) nbModule.StronglyAcked(hash) - nbModule.BlockDeliver(types.Block{ + nbModule.BlockDelivered(types.Block{ Hash: hash, Witness: types.Witness{Timestamp: time.Now().UTC()}, }) - nbModule.WitnessAckDeliver(&types.WitnessAck{Hash: hash}) + nbModule.WitnessAckDelivered(&types.WitnessAck{Hash: hash}) } - nbModule.TotalOrderingDeliver(hashes, true) + nbModule.TotalOrderingDelivered(hashes, true) // nonBlocking should be non-blocking. s.True(shouldFinish.After(time.Now().UTC())) @@ -122,8 +122,8 @@ func (s *NonBlockingTestSuite) TestNonBlocking() { for _, hash := range hashes { s.Contains(app.blockConfirmed, hash) s.Contains(app.stronglyAcked, hash) - s.Contains(app.totalOrderingDeliver, hash) - s.Contains(app.blockDeliver, hash) + s.Contains(app.totalOrderingDelivered, hash) + s.Contains(app.blockDelivered, hash) s.Contains(app.witnessAck, hash) } } diff --git a/core/shard.go b/core/shard.go index 13c73d5..270b070 100644 --- a/core/shard.go +++ b/core/shard.go @@ -192,7 +192,7 @@ func (s *Shard) ProcessBlock( hashes[idx] = toDelivered[idx].Hash } if s.debug != nil { - s.debug.TotalOrderingDeliver(hashes, earlyDelivered) + s.debug.TotalOrderingDelivered(hashes, earlyDelivered) } // Perform timestamp generation. if err = s.ctModule.processBlocks(toDelivered); err != nil { diff --git a/core/shard_test.go b/core/shard_test.go index b332f30..42c8d7b 100644 --- a/core/shard_test.go +++ b/core/shard_test.go @@ -77,7 +77,7 @@ func (mgr *testShardMgr) processBlock(b *types.Block) (err error) { if err = mgr.db.Update(*b); err != nil { return } - mgr.app.BlockDeliver(*b) + mgr.app.BlockDelivered(*b) } // Update pending blocks for verified block (pass sanity check). pendings = append(pendings, verified...) diff --git a/core/test/app.go b/core/test/app.go index 7a0ad97..cc2bbe6 100644 --- a/core/test/app.go +++ b/core/test/app.go @@ -109,8 +109,8 @@ func (app *App) PreparePayload(position types.Position) []byte { return []byte{} } -// VerifyPayloads implements Application. -func (app *App) VerifyPayloads(payloads []byte) bool { +// VerifyPayload implements Application. +func (app *App) VerifyPayload(payloads []byte) bool { return true } @@ -126,8 +126,8 @@ func (app *App) StronglyAcked(blockHash common.Hash) { app.Acked[blockHash] = &AppAckedRecord{When: time.Now().UTC()} } -// TotalOrderingDeliver implements Application interface. -func (app *App) TotalOrderingDeliver(blockHashes common.Hashes, early bool) { +// TotalOrderingDelivered implements Application interface. +func (app *App) TotalOrderingDelivered(blockHashes common.Hashes, early bool) { app.totalOrderedLock.Lock() defer app.totalOrderedLock.Unlock() @@ -145,8 +145,8 @@ func (app *App) TotalOrderingDeliver(blockHashes common.Hashes, early bool) { } } -// BlockDeliver implements Application interface. -func (app *App) BlockDeliver(block types.Block) { +// BlockDelivered implements Application interface. +func (app *App) BlockDelivered(block types.Block) { app.deliveredLock.Lock() defer app.deliveredLock.Unlock() @@ -163,8 +163,8 @@ func (app *App) BlockProcessedChan() <-chan types.WitnessResult { return app.witnessResultChan } -// WitnessAckDeliver implements Application interface. -func (app *App) WitnessAckDeliver(witnessAck *types.WitnessAck) { +// WitnessAckDelivered implements Application interface. +func (app *App) WitnessAckDelivered(witnessAck *types.WitnessAck) { app.witnessAckLock.Lock() defer app.witnessAckLock.Unlock() diff --git a/core/test/app_test.go b/core/test/app_test.go index 649ccbe..9d35c67 100644 --- a/core/test/app_test.go +++ b/core/test/app_test.go @@ -62,7 +62,7 @@ func (s *AppTestSuite) setupAppByTotalOrderDeliver( for _, h := range to.BlockHashes { app.StronglyAcked(h) } - app.TotalOrderingDeliver(to.BlockHashes, to.Early) + app.TotalOrderingDelivered(to.BlockHashes, to.Early) for _, h := range to.BlockHashes { // To make it simpler, use the index of hash sequence // as the time. @@ -80,7 +80,7 @@ func (s *AppTestSuite) deliverBlockWithTimeFromSequenceLength( func (s *AppTestSuite) deliverBlock( app *App, hash common.Hash, timestamp time.Time) { - app.BlockDeliver(types.Block{ + app.BlockDelivered(types.Block{ Hash: hash, Witness: types.Witness{ Timestamp: timestamp, @@ -100,7 +100,7 @@ func (s *AppTestSuite) TestCompare() { s.setupAppByTotalOrderDeliver(app2, s.to2) hash := common.NewRandomHash() app2.StronglyAcked(hash) - app2.TotalOrderingDeliver(common.Hashes{hash}, false) + app2.TotalOrderingDelivered(common.Hashes{hash}, false) s.deliverBlockWithTimeFromSequenceLength(app2, hash) req.Equal(ErrMismatchBlockHashSequence, app1.Compare(app2)) // An App with different consensus time for the same block. @@ -110,7 +110,7 @@ func (s *AppTestSuite) TestCompare() { for _, h := range s.to3.BlockHashes { app3.StronglyAcked(h) } - app3.TotalOrderingDeliver(s.to3.BlockHashes, s.to3.Early) + app3.TotalOrderingDelivered(s.to3.BlockHashes, s.to3.Early) wrongTime := time.Time{}.Add( time.Duration(len(app3.DeliverSequence)) * time.Second) wrongTime = wrongTime.Add(1 * time.Second) @@ -141,7 +141,7 @@ func (s *AppTestSuite) TestVerify() { for _, h := range s.to2.BlockHashes { app2.StronglyAcked(h) } - app2.TotalOrderingDeliver(s.to2.BlockHashes, s.to2.Early) + app2.TotalOrderingDelivered(s.to2.BlockHashes, s.to2.Early) s.deliverBlock(app2, s.to2.BlockHashes[0], time.Time{}) req.Equal(ErrConsensusTimestampOutOfOrder, app2.Verify()) // A delivered block is not found in total ordering delivers. @@ -157,15 +157,15 @@ func (s *AppTestSuite) TestVerify() { for _, h := range s.to2.BlockHashes { app4.StronglyAcked(h) } - app4.TotalOrderingDeliver(s.to2.BlockHashes, s.to2.Early) + app4.TotalOrderingDelivered(s.to2.BlockHashes, s.to2.Early) hash = common.NewRandomHash() app4.StronglyAcked(hash) - app4.TotalOrderingDeliver(common.Hashes{hash}, false) + app4.TotalOrderingDelivered(common.Hashes{hash}, false) s.deliverBlockWithTimeFromSequenceLength(app4, hash) // Witness ack on unknown block. app5 := NewApp() s.setupAppByTotalOrderDeliver(app5, s.to1) - app5.WitnessAckDeliver(&types.WitnessAck{ + app5.WitnessAckDelivered(&types.WitnessAck{ Hash: common.NewRandomHash(), WitnessBlockHash: common.NewRandomHash(), }) diff --git a/core/test/stopper_test.go b/core/test/stopper_test.go index cb52032..de1c1a5 100644 --- a/core/test/stopper_test.go +++ b/core/test/stopper_test.go @@ -59,9 +59,9 @@ func (s *StopperTestSuite) TestStopByConfirmedBlocks() { for _, h := range hashes { app.StronglyAcked(h) } - app.TotalOrderingDeliver(hashes, false) + app.TotalOrderingDelivered(hashes, false) for _, h := range hashes { - app.BlockDeliver(types.Block{ + app.BlockDelivered(types.Block{ Hash: h, Witness: types.Witness{Timestamp: time.Time{}}}) } diff --git a/integration_test/node.go b/integration_test/node.go index 2280b18..dff662e 100644 --- a/integration_test/node.go +++ b/integration_test/node.go @@ -204,7 +204,7 @@ func (n *Node) processBlock(b *types.Block) (err error) { if err = n.db.Update(*b); err != nil { return } - n.app.BlockDeliver(*b) + n.app.BlockDelivered(*b) } // Update pending blocks for verified block (pass sanity check). pendings = append(pendings, verified...) diff --git a/simulation/app.go b/simulation/app.go index 36567bf..ab0bfcd 100644 --- a/simulation/app.go +++ b/simulation/app.go @@ -60,8 +60,8 @@ func newSimApp(id types.NodeID, netModule *network) *simApp { func (a *simApp) BlockConfirmed(_ common.Hash) { } -// VerifyPayloads implements core.Application. -func (a *simApp) VerifyPayloads(payloads []byte) bool { +// VerifyPayload implements core.Application. +func (a *simApp) VerifyPayload(payloads []byte) bool { return true } @@ -101,9 +101,9 @@ func (a *simApp) PreparePayload(position types.Position) []byte { func (a *simApp) StronglyAcked(blockHash common.Hash) { } -// TotalOrderingDeliver is called when blocks are delivered by the total +// TotalOrderingDelivered is called when blocks are delivered by the total // ordering algorithm. -func (a *simApp) TotalOrderingDeliver(blockHashes common.Hashes, early bool) { +func (a *simApp) TotalOrderingDelivered(blockHashes common.Hashes, early bool) { fmt.Println("OUTPUT", a.NodeID, early, blockHashes) blockList := &BlockList{ ID: a.DeliverID, @@ -113,8 +113,8 @@ func (a *simApp) TotalOrderingDeliver(blockHashes common.Hashes, early bool) { a.DeliverID++ } -// BlockDeliver is called when a block in compaction chain is delivered. -func (a *simApp) BlockDeliver(block types.Block) { +// BlockDelivered is called when a block in compaction chain is delivered. +func (a *simApp) BlockDelivered(block types.Block) { func() { a.blockByHashMutex.Lock() defer a.blockByHashMutex.Unlock() @@ -165,6 +165,6 @@ func (a *simApp) BlockProcessedChan() <-chan types.WitnessResult { return a.witnessResultChan } -// WitnessAckDeliver is called when a witness ack is created. -func (a *simApp) WitnessAckDeliver(witnessAck *types.WitnessAck) { +// WitnessAckDelivered is called when a witness ack is created. +func (a *simApp) WitnessAckDelivered(witnessAck *types.WitnessAck) { } |