Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

p2pv1: change dynamic-nodes connections to static-node connections in static-node mode. #230

Merged
merged 4 commits into from
Aug 20, 2021

Conversation

aucusaga
Copy link
Contributor

@aucusaga aucusaga commented Aug 18, 2021

Description

Add router in static-node mode.

Fixes # (issue)

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Brief of your solution

Nodes can refresh their router info by the function GetPeerInfo.

How Has This Been Tested?

Use testnet and xfront.

@aucusaga aucusaga requested a review from icexin August 19, 2021 06:49
peersChan := make(chan []*pb.PeerInfo, len(addresses))
done := make(chan struct{})

for _, addr := range addresses {
Copy link
Contributor

@icexin icexin Aug 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sync.Mutex来保护remotePeers,直接在闭包里面append remotePeers,可以不用channel来交互

ctx: ctx,
}, nil
}
cp.staticModeOn = len(ctx.P2PConf.BootNodes) == 0 && len(ctx.P2PConf.StaticNodes) > 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

避免一行里面有复杂逻辑,改成

if len(ctx.P2PConf.BootNodes) == 0 && len(ctx.P2PConf.StaticNodes) > 0 {
    cp.staticModeOn = true
}

@@ -202,6 +202,31 @@ func (p *P2PServerV1) GetPeerIdByAccount(account string) (string, error) {
if value, ok := p.accounts.Get(account); ok {
return value.(string), nil
}

// xchain address can not mapping, try getPeerInfo again.
if p.pool.staticModeOn && len(p.accounts.Items()) != 0 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

用提前返回错误的方式来处理这种场景,避免深度嵌套if语句,这里可以改成

if !p.pool.staticModeOn {
   return "", ErrAccountNotExist
}

另外accounts.Items为空判断有逻辑错误,不用判断。

@codecov-commenter
Copy link

Codecov Report

Merging #230 (6acc077) into master (7bf2eb8) will increase coverage by 0.18%.
The diff coverage is 61.11%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #230      +/-   ##
==========================================
+ Coverage   47.33%   47.51%   +0.18%     
==========================================
  Files         133      133              
  Lines       11411    11455      +44     
==========================================
+ Hits         5401     5443      +42     
  Misses       4876     4876              
- Partials     1134     1136       +2     
Impacted Files Coverage Δ
bcs/network/p2pv1/client.go 46.09% <0.00%> (-3.03%) ⬇️
bcs/network/p2pv1/conn.go 53.19% <33.33%> (-1.65%) ⬇️
bcs/network/p2pv1/server.go 57.85% <50.00%> (+0.03%) ⬆️
bcs/network/p2pv1/handler.go 80.35% <93.75%> (+13.69%) ⬆️
bcs/network/p2pv1/filter.go 85.18% <100.00%> (ø)
kernel/consensus/base/driver/chained-bft/smr.go 49.53% <0.00%> (-0.93%) ⬇️
bcs/consensus/tdpos/tdpos.go 40.96% <0.00%> (+0.80%) ⬆️
bcs/ledger/xledger/ledger/ledger.go 56.82% <0.00%> (+0.97%) ⬆️
bcs/consensus/tdpos/common.go 67.18% <0.00%> (+3.12%) ⬆️
... and 1 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7bf2eb8...6acc077. Read the comment docs.

@aucusaga aucusaga changed the title p2pv1: add router in static-node mode. p2pv1: change dynamic-nodes connections to static-node connections in static-node mode. Aug 20, 2021
@aucusaga aucusaga merged commit 4a9d712 into OpenAtomFoundation:master Aug 20, 2021
@aucusaga aucusaga added this to the v5.1.1 milestone Sep 24, 2021
chenfengjin pushed a commit to chenfengjin/xupercore that referenced this pull request Sep 24, 2021
chenfengjin pushed a commit to chenfengjin/xupercore that referenced this pull request Sep 26, 2021
icexin pushed a commit that referenced this pull request Sep 27, 2021
@aucusaga aucusaga deleted the p2pv1 branch October 15, 2021 06:34
vantinfy pushed a commit to superconsensus/matrixcore that referenced this pull request Jan 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants