diff options
author | Mission Liao <mission.liao@dexon.org> | 2018-08-10 14:27:42 +0800 |
---|---|---|
committer | Wei-Ning Huang <aitjcize@gmail.com> | 2018-08-10 14:27:42 +0800 |
commit | 3cde438f074ffcead89e28b0a83964d1f1a87062 (patch) | |
tree | 5ec9608581e0f2fc27846aadeb85870bb5c3b2e2 /simulation | |
parent | b88d8ddb0eaf48fac1fdf10dcd7db4dc896e6538 (diff) | |
download | tangerine-consensus-3cde438f074ffcead89e28b0a83964d1f1a87062.tar tangerine-consensus-3cde438f074ffcead89e28b0a83964d1f1a87062.tar.gz tangerine-consensus-3cde438f074ffcead89e28b0a83964d1f1a87062.tar.bz2 tangerine-consensus-3cde438f074ffcead89e28b0a83964d1f1a87062.tar.lz tangerine-consensus-3cde438f074ffcead89e28b0a83964d1f1a87062.tar.xz tangerine-consensus-3cde438f074ffcead89e28b0a83964d1f1a87062.tar.zst tangerine-consensus-3cde438f074ffcead89e28b0a83964d1f1a87062.zip |
Fix the bug preventing us from testing large group when using TCP-Local (#42)
* Fix the issue that processing genesis block twice.
- Restore the mechanism to avoid sending block to proposer.
* Fix the 'keep-alive' not working
Quote from comments of net/http/request
For client requests, setting this field prevents re-use of
TCP connections between requests to the same hosts, as if
Transport.DisableKeepAlives were set.
* Remove useless field
* Fix the test bug: I should provide '3' when test K=3
* Fixup: the parent hash of genesis block should be zero
Diffstat (limited to 'simulation')
-rw-r--r-- | simulation/tcp-network.go | 4 | ||||
-rw-r--r-- | simulation/validator.go | 41 |
2 files changed, 24 insertions, 21 deletions
diff --git a/simulation/tcp-network.go b/simulation/tcp-network.go index 47a826e..6e2616b 100644 --- a/simulation/tcp-network.go +++ b/simulation/tcp-network.go @@ -227,7 +227,6 @@ func (n *TCPNetwork) Send(destID types.ValidatorID, msg interface{}) { if err != nil { continue } - req.Close = true req.Header.Add("ID", n.endpoint.GetID().String()) resp, err := n.client.Do(req) @@ -249,6 +248,9 @@ func (n *TCPNetwork) Send(destID types.ValidatorID, msg interface{}) { // BroadcastBlock broadcast blocks into the network. func (n *TCPNetwork) BroadcastBlock(block *types.Block) { for endpoint := range n.endpoints { + if endpoint == block.ProposerID { + continue + } n.Send(endpoint, block.Clone()) } } diff --git a/simulation/validator.go b/simulation/validator.go index 8b59247..215088f 100644 --- a/simulation/validator.go +++ b/simulation/validator.go @@ -42,9 +42,6 @@ type Validator struct { ID types.ValidatorID consensus *core.Consensus compactionChain *core.BlockChain - - genesis *types.Block - current *types.Block } // NewValidator returns a new empty validator. @@ -58,12 +55,14 @@ func NewValidator( if err != nil { panic(err) } + gov := newSimGov(config.Num) + gov.addValidator(id) return &Validator{ ID: id, config: config, network: network, app: NewSimApp(id, network), - gov: newSimGov(config.Num), + gov: gov, db: db, isFinished: make(chan struct{}), } @@ -78,11 +77,21 @@ func (v *Validator) GetID() types.ValidatorID { func (v *Validator) Run() { v.msgChannel = v.network.Join(v) + genesisBlock := &types.Block{ + ProposerID: v.ID, + ParentHash: common.Hash{}, + Hash: common.NewRandomHash(), + Height: 0, + Acks: map[common.Hash]struct{}{}, + Timestamps: map[types.ValidatorID]time.Time{ + v.ID: time.Now().UTC(), + }, + } isStopped := make(chan struct{}, 2) isShutdown := make(chan struct{}) - v.BroadcastGenesisBlock() - go v.MsgServer(isStopped) + v.BroadcastGenesisBlock(genesisBlock) + go v.MsgServer(isStopped, genesisBlock) go v.CheckServerInfo(isShutdown) go v.BlockProposer(isStopped, isShutdown) @@ -116,8 +125,10 @@ func (v *Validator) CheckServerInfo(isShutdown chan struct{}) { } // MsgServer listen to the network channel for message and handle it. -func (v *Validator) MsgServer(isStopped chan struct{}) { - var pendingBlocks []*types.Block +func (v *Validator) MsgServer( + isStopped chan struct{}, genesisBlock *types.Block) { + + pendingBlocks := []*types.Block{genesisBlock} for { var msg interface{} select { @@ -158,22 +169,12 @@ func (v *Validator) MsgServer(isStopped chan struct{}) { } // BroadcastGenesisBlock broadcasts genesis block to all peers. -func (v *Validator) BroadcastGenesisBlock() { +func (v *Validator) BroadcastGenesisBlock(genesisBlock *types.Block) { // Wait until all peer joined the network. for v.network.NumPeers() != v.config.Num { time.Sleep(time.Second) } - b := &types.Block{ - ProposerID: v.ID, - ParentHash: common.Hash{}, - Hash: common.NewRandomHash(), - Height: 0, - Acks: map[common.Hash]struct{}{}, - Timestamps: map[types.ValidatorID]time.Time{ - v.ID: time.Now().UTC(), - }, - } - v.network.BroadcastBlock(b) + v.network.BroadcastBlock(genesisBlock) } // BlockProposer propose blocks to be send to the DEXON network. |