aboutsummaryrefslogtreecommitdiffstats
path: root/integration_test
diff options
context:
space:
mode:
authorMission Liao <mission.liao@dexon.org>2018-09-20 09:09:37 +0800
committerGitHub <noreply@github.com>2018-09-20 09:09:37 +0800
commit421d72b2d796195178104a0eb1dedf319ba8664c (patch)
treef32f15c167989905494eca1891c3240b80dac1d6 /integration_test
parent37f117d35c6617e1944d45e001e03813a6a278ed (diff)
downloadtangerine-consensus-421d72b2d796195178104a0eb1dedf319ba8664c.tar
tangerine-consensus-421d72b2d796195178104a0eb1dedf319ba8664c.tar.gz
tangerine-consensus-421d72b2d796195178104a0eb1dedf319ba8664c.tar.bz2
tangerine-consensus-421d72b2d796195178104a0eb1dedf319ba8664c.tar.lz
tangerine-consensus-421d72b2d796195178104a0eb1dedf319ba8664c.tar.xz
tangerine-consensus-421d72b2d796195178104a0eb1dedf319ba8664c.tar.zst
tangerine-consensus-421d72b2d796195178104a0eb1dedf319ba8664c.zip
Rename validator* to node* (#120)
Diffstat (limited to 'integration_test')
-rw-r--r--integration_test/network.go2
-rw-r--r--integration_test/node.go (renamed from integration_test/validator.go)64
-rw-r--r--integration_test/non-byzantine_test.go8
-rw-r--r--integration_test/stats.go42
-rw-r--r--integration_test/stats_test.go8
-rw-r--r--integration_test/utils.go40
6 files changed, 82 insertions, 82 deletions
diff --git a/integration_test/network.go b/integration_test/network.go
index b58cbcd..1c7265d 100644
--- a/integration_test/network.go
+++ b/integration_test/network.go
@@ -38,7 +38,7 @@ func (n *Network) BroadcastWitnessAck(witnessAck *types.WitnessAck) {
// SendDKGPrivateShare sends PrivateShare to a DKG participant.
func (n *Network) SendDKGPrivateShare(
- recv types.ValidatorID, prvShare *types.DKGPrivateShare) {
+ recv types.NodeID, prvShare *types.DKGPrivateShare) {
}
// ReceiveChan returns a channel to receive messages from DEXON network.
diff --git a/integration_test/validator.go b/integration_test/node.go
index 112f986..c0e226b 100644
--- a/integration_test/validator.go
+++ b/integration_test/node.go
@@ -45,8 +45,8 @@ type consensusEventPayload struct {
// NewProposeBlockEvent constructs an test.Event that would trigger
// block proposing.
-func NewProposeBlockEvent(vID types.ValidatorID, when time.Time) *test.Event {
- return test.NewEvent(vID, when, &consensusEventPayload{
+func NewProposeBlockEvent(nID types.NodeID, when time.Time) *test.Event {
+ return test.NewEvent(nID, when, &consensusEventPayload{
Type: evtProposeBlock,
})
}
@@ -54,17 +54,17 @@ func NewProposeBlockEvent(vID types.ValidatorID, when time.Time) *test.Event {
// NewReceiveBlockEvent constructs an test.Event that would trigger
// block received.
func NewReceiveBlockEvent(
- vID types.ValidatorID, when time.Time, block *types.Block) *test.Event {
+ nID types.NodeID, when time.Time, block *types.Block) *test.Event {
- return test.NewEvent(vID, when, &consensusEventPayload{
+ return test.NewEvent(nID, when, &consensusEventPayload{
Type: evtReceiveBlock,
PiggyBack: block,
})
}
-// Validator is designed to work with test.Scheduler.
-type Validator struct {
- ID types.ValidatorID
+// Node is designed to work with test.Scheduler.
+type Node struct {
+ ID types.NodeID
chainID uint32
cons *core.Consensus
gov core.Governance
@@ -72,31 +72,31 @@ type Validator struct {
proposingLatency test.LatencyModel
}
-// NewValidator constructs an instance of Validator.
-func NewValidator(
+// NewNode constructs an instance of Node.
+func NewNode(
app core.Application,
gov core.Governance,
db blockdb.BlockDatabase,
privateKey crypto.PrivateKey,
- vID types.ValidatorID,
+ nID types.NodeID,
networkLatency test.LatencyModel,
- proposingLatency test.LatencyModel) *Validator {
+ proposingLatency test.LatencyModel) *Node {
hashes := make(common.Hashes, 0)
- for vID := range gov.GetNotarySet() {
- hashes = append(hashes, vID.Hash)
+ for nID := range gov.GetNotarySet() {
+ hashes = append(hashes, nID.Hash)
}
sort.Sort(hashes)
chainID := uint32(0)
for i, hash := range hashes {
- if hash == vID.Hash {
+ if hash == nID.Hash {
chainID = uint32(i)
break
}
}
- return &Validator{
- ID: vID,
+ return &Node{
+ ID: nID,
chainID: chainID,
gov: gov,
networkLatency: networkLatency,
@@ -107,53 +107,53 @@ func NewValidator(
}
// Handle implements test.EventHandler interface.
-func (v *Validator) Handle(e *test.Event) (events []*test.Event) {
+func (n *Node) Handle(e *test.Event) (events []*test.Event) {
payload := e.Payload.(*consensusEventPayload)
switch payload.Type {
case evtProposeBlock:
- events, e.ExecError = v.handleProposeBlock(e.Time, payload.PiggyBack)
+ events, e.ExecError = n.handleProposeBlock(e.Time, payload.PiggyBack)
case evtReceiveBlock:
- events, e.ExecError = v.handleReceiveBlock(payload.PiggyBack)
+ events, e.ExecError = n.handleReceiveBlock(payload.PiggyBack)
default:
panic(fmt.Errorf("unknown consensus event type: %v", payload.Type))
}
return
}
-func (v *Validator) handleProposeBlock(when time.Time, piggyback interface{}) (
+func (n *Node) handleProposeBlock(when time.Time, piggyback interface{}) (
events []*test.Event, err error) {
b := &types.Block{
- ProposerID: v.ID,
+ ProposerID: n.ID,
Position: types.Position{
- ChainID: v.chainID,
+ ChainID: n.chainID,
},
}
defer types.RecycleBlock(b)
- if err = v.cons.PrepareBlock(b, when); err != nil {
+ if err = n.cons.PrepareBlock(b, when); err != nil {
return
}
- if err = v.cons.ProcessBlock(b); err != nil {
+ if err = n.cons.ProcessBlock(b); err != nil {
return
}
- // Create 'block received' event for each other validators.
- for vID := range v.gov.GetNotarySet() {
- if vID == v.ID {
+ // Create 'block received' event for each other nodes.
+ for nID := range n.gov.GetNotarySet() {
+ if nID == n.ID {
continue
}
events = append(events, NewReceiveBlockEvent(
- vID, when.Add(v.networkLatency.Delay()), b.Clone()))
+ nID, when.Add(n.networkLatency.Delay()), b.Clone()))
}
- // Create next 'block proposing' event for this validators.
+ // Create next 'block proposing' event for this nodes.
events = append(events, NewProposeBlockEvent(
- v.ID, when.Add(v.proposingLatency.Delay())))
+ n.ID, when.Add(n.proposingLatency.Delay())))
return
}
-func (v *Validator) handleReceiveBlock(piggyback interface{}) (
+func (n *Node) handleReceiveBlock(piggyback interface{}) (
events []*test.Event, err error) {
- err = v.cons.ProcessBlock(piggyback.(*types.Block))
+ err = n.cons.ProcessBlock(piggyback.(*types.Block))
if err != nil {
panic(err)
}
diff --git a/integration_test/non-byzantine_test.go b/integration_test/non-byzantine_test.go
index a5ecff6..34c6be1 100644
--- a/integration_test/non-byzantine_test.go
+++ b/integration_test/non-byzantine_test.go
@@ -41,17 +41,17 @@ func (s *NonByzantineTestSuite) TestNonByzantine() {
Sigma: 30,
Mean: 500,
}
- apps = make(map[types.ValidatorID]*test.App)
- dbs = make(map[types.ValidatorID]blockdb.BlockDatabase)
+ apps = make(map[types.NodeID]*test.App)
+ dbs = make(map[types.NodeID]blockdb.BlockDatabase)
req = s.Require()
)
- apps, dbs, validators, err := PrepareValidators(
+ apps, dbs, nodes, err := PrepareNodes(
25, networkLatency, proposingLatency)
req.Nil(err)
now := time.Now().UTC()
sch := test.NewScheduler(test.NewStopByConfirmedBlocks(50, apps, dbs))
- for vID, v := range validators {
+ for vID, v := range nodes {
sch.RegisterEventHandler(vID, v)
req.Nil(sch.Seed(NewProposeBlockEvent(vID, now)))
}
diff --git a/integration_test/stats.go b/integration_test/stats.go
index ae8ded4..11b1db0 100644
--- a/integration_test/stats.go
+++ b/integration_test/stats.go
@@ -15,7 +15,7 @@ var (
)
// StatsSet represents accumulatee result of a group of related events
-// (ex. All events from one validator).
+// (ex. All events from one node).
type StatsSet struct {
ProposedBlockCount int
ReceivedBlockCount int
@@ -81,16 +81,16 @@ func (s *StatsSet) newBlockReceiveEvent(
// done would divide the latencies we cached with related event count. This way
// to calculate average latency is more accurate.
-func (s *StatsSet) done(validatorCount int) {
- s.ProposingLatency /= time.Duration(s.ProposedBlockCount - validatorCount)
+func (s *StatsSet) done(nodeCount int) {
+ s.ProposingLatency /= time.Duration(s.ProposedBlockCount - nodeCount)
s.ReceivingLatency /= time.Duration(s.ReceivedBlockCount)
s.PrepareExecLatency /= time.Duration(s.ProposedBlockCount)
s.ProcessExecLatency /= time.Duration(s.ReceivedBlockCount)
}
-// Stats is statistics of a slice of test.Event generated by validators.
+// Stats is statistics of a slice of test.Event generated by nodes.
type Stats struct {
- ByValidator map[types.ValidatorID]*StatsSet
+ ByNode map[types.NodeID]*StatsSet
All *StatsSet
BPS float64
ExecutionTime time.Duration
@@ -99,12 +99,12 @@ type Stats struct {
// NewStats constructs an Stats instance by providing a slice of
// test.Event.
func NewStats(
- history []*test.Event, apps map[types.ValidatorID]*test.App) (
+ history []*test.Event, apps map[types.NodeID]*test.App) (
stats *Stats, err error) {
stats = &Stats{
- ByValidator: make(map[types.ValidatorID]*StatsSet),
- All: &StatsSet{},
+ ByNode: make(map[types.NodeID]*StatsSet),
+ All: &StatsSet{},
}
if err = stats.calculate(history, apps); err != nil {
stats = nil
@@ -114,11 +114,11 @@ func NewStats(
}
func (stats *Stats) calculate(
- history []*test.Event, apps map[types.ValidatorID]*test.App) error {
+ history []*test.Event, apps map[types.NodeID]*test.App) error {
defer func() {
- stats.All.done(len(stats.ByValidator))
- for _, set := range stats.ByValidator {
+ stats.All.done(len(stats.ByNode))
+ for _, set := range stats.ByNode {
set.done(1)
}
}()
@@ -132,13 +132,13 @@ func (stats *Stats) calculate(
case evtProposeBlock:
stats.All.newBlockProposeEvent(
e, payload, history)
- stats.getStatsSetByValidator(e.ValidatorID).newBlockProposeEvent(
+ stats.getStatsSetByNode(e.NodeID).newBlockProposeEvent(
e, payload, history)
case evtReceiveBlock:
stats.All.newBlockReceiveEvent(
- e, payload, history, apps[e.ValidatorID])
- stats.getStatsSetByValidator(e.ValidatorID).newBlockReceiveEvent(
- e, payload, history, apps[e.ValidatorID])
+ e, payload, history, apps[e.NodeID])
+ stats.getStatsSetByNode(e.NodeID).newBlockReceiveEvent(
+ e, payload, history, apps[e.NodeID])
default:
return ErrUnknownConsensusEventType
}
@@ -146,13 +146,13 @@ func (stats *Stats) calculate(
return nil
}
-func (stats *Stats) getStatsSetByValidator(
- vID types.ValidatorID) (s *StatsSet) {
+func (stats *Stats) getStatsSetByNode(
+ vID types.NodeID) (s *StatsSet) {
- s = stats.ByValidator[vID]
+ s = stats.ByNode[vID]
if s == nil {
s = &StatsSet{}
- stats.ByValidator[vID] = s
+ stats.ByNode[vID] = s
}
return
}
@@ -160,10 +160,10 @@ func (stats *Stats) getStatsSetByValidator(
func (stats *Stats) summary(history []*test.Event) {
// Find average delivered block count among all blocks.
totalConfirmedBlocks := 0
- for _, s := range stats.ByValidator {
+ for _, s := range stats.ByNode {
totalConfirmedBlocks += s.DeliveredBlockCount
}
- averageConfirmedBlocks := totalConfirmedBlocks / len(stats.ByValidator)
+ averageConfirmedBlocks := totalConfirmedBlocks / len(stats.ByNode)
// Find execution time.
// Note: it's a simplified way to calculate the execution time:
diff --git a/integration_test/stats_test.go b/integration_test/stats_test.go
index 8816e8c..54c827d 100644
--- a/integration_test/stats_test.go
+++ b/integration_test/stats_test.go
@@ -21,13 +21,13 @@ func (s *EventStatsTestSuite) TestCalculate() {
req = s.Require()
)
- apps, dbs, validators, err := PrepareValidators(
+ apps, dbs, nodes, err := PrepareNodes(
7, networkLatency, proposingLatency)
req.Nil(err)
sch := test.NewScheduler(test.NewStopByConfirmedBlocks(50, apps, dbs))
now := time.Now().UTC()
- for vID, v := range validators {
+ for vID, v := range nodes {
sch.RegisterEventHandler(vID, v)
req.Nil(sch.Seed(NewProposeBlockEvent(vID, now)))
}
@@ -43,8 +43,8 @@ func (s *EventStatsTestSuite) TestCalculate() {
req.True(stats.All.DeliveredBlockCount >= 350)
req.Equal(stats.All.ProposingLatency, 300*time.Millisecond)
req.Equal(stats.All.ReceivingLatency, 100*time.Millisecond)
- // Check statistics for each validator.
- for _, vStats := range stats.ByValidator {
+ // Check statistics for each node.
+ for _, vStats := range stats.ByNode {
req.True(vStats.ProposedBlockCount > 50)
req.True(vStats.ReceivedBlockCount > 50)
req.True(vStats.StronglyAckedBlockCount > 50)
diff --git a/integration_test/utils.go b/integration_test/utils.go
index c526bc2..f95d771 100644
--- a/integration_test/utils.go
+++ b/integration_test/utils.go
@@ -9,13 +9,13 @@ import (
"github.com/dexon-foundation/dexon-consensus-core/crypto"
)
-// PrepareValidators setups validators for testing.
-func PrepareValidators(
- validatorCount int,
+// PrepareNodes setups nodes for testing.
+func PrepareNodes(
+ nodeCount int,
networkLatency, proposingLatency test.LatencyModel) (
- apps map[types.ValidatorID]*test.App,
- dbs map[types.ValidatorID]blockdb.BlockDatabase,
- validators map[types.ValidatorID]*Validator,
+ apps map[types.NodeID]*test.App,
+ dbs map[types.NodeID]blockdb.BlockDatabase,
+ nodes map[types.NodeID]*Node,
err error) {
var (
@@ -23,32 +23,32 @@ func PrepareValidators(
key crypto.PrivateKey
)
- apps = make(map[types.ValidatorID]*test.App)
- dbs = make(map[types.ValidatorID]blockdb.BlockDatabase)
- validators = make(map[types.ValidatorID]*Validator)
+ apps = make(map[types.NodeID]*test.App)
+ dbs = make(map[types.NodeID]blockdb.BlockDatabase)
+ nodes = make(map[types.NodeID]*Node)
- gov, err := test.NewGovernance(validatorCount, 700*time.Millisecond)
+ gov, err := test.NewGovernance(nodeCount, 700*time.Millisecond)
if err != nil {
return
}
- for vID := range gov.GetNotarySet() {
- apps[vID] = test.NewApp()
+ for nID := range gov.GetNotarySet() {
+ apps[nID] = test.NewApp()
if db, err = blockdb.NewMemBackedBlockDB(); err != nil {
return
}
- dbs[vID] = db
+ dbs[nID] = db
}
- for vID := range gov.GetNotarySet() {
- if key, err = gov.GetPrivateKey(vID); err != nil {
+ for nID := range gov.GetNotarySet() {
+ if key, err = gov.GetPrivateKey(nID); err != nil {
return
}
- validators[vID] = NewValidator(
- apps[vID],
+ nodes[nID] = NewNode(
+ apps[nID],
gov,
- dbs[vID],
+ dbs[nID],
key,
- vID,
+ nID,
networkLatency,
proposingLatency)
}
@@ -56,7 +56,7 @@ func PrepareValidators(
}
// VerifyApps is a helper to check delivery between test.Apps
-func VerifyApps(apps map[types.ValidatorID]*test.App) (err error) {
+func VerifyApps(apps map[types.NodeID]*test.App) (err error) {
for vFrom, fromApp := range apps {
if err = fromApp.Verify(); err != nil {
return