Skip to content

p2p: introduce peerConn to simplify peer creation#1226

Merged
melekes merged 9 commits intodevelopfrom
peerConn
Feb 27, 2018
Merged

p2p: introduce peerConn to simplify peer creation#1226
melekes merged 9 commits intodevelopfrom
peerConn

Conversation

@ebuchman
Copy link
Contributor

@ebuchman ebuchman commented Feb 20, 2018

  • config.AuthEnc p2p/config: options to require/not-require auth #1157
  • Introduce peerConn containing the known fields of peer
  • peer only created in sw.addPeer once handshake is complete and NodeInfo is checked
  • Eliminates some mutable variables and makes the code flow better
  • Simplifies the newXxxPeer funcs
  • Use ID instead of PubKey where possible.
    * SetPubKeyFilter -> SetIDFilter
    * nodeInfo.Validate takes no args
    * remove peer.PubKey()

@ebuchman ebuchman requested a review from melekes as a code owner February 20, 2018 02:27
@ebuchman ebuchman changed the title p2p: introduce peerConn to clarify peer creation p2p: introduce peerConn to simplify peer creation Feb 20, 2018
return
err := sw.DialPeerWithAddress(netAddr, true)
if err == nil {
return // success
Copy link
Contributor

Choose a reason for hiding this comment

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

don't you think we should log success path too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes it's logged within the DialPeerWithAddress function.

I wanted to avoid returning the peer because we weren't doing anything except logging it.

So I think it makes sense to let the function log it's success case, but the caller logs the error. Does that make sense or am I being silly ?

Copy link
Contributor

Choose a reason for hiding this comment

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

maybe.. but I still think it's important to give user this sequence

[] .... Reconnecting to node A
[] .... Reconnected ...

p2p/switch.go Outdated
if err := sw.FilterConnByAddr(addr); err != nil {
return err
}
if err := sw.FilterConnByID(id); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Have you tried running this with [p2p] auth_enc=false? If it is false, then id will be nil, right? So effectively, filter will not work

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm crap. I think we need some extra work to make this right for AuthEnc=false. We prob dont want the id to be empty, even if it can't be verified, because we use it eg. as a key for the AddrBook. So if we want AddrBook to work with AuthEnc, we need to do something smarter.

OK thanks

r.Switch.Logger.Info("Connected to seed", "peer", peer)
err := r.Switch.DialPeerWithAddress(seedAddr, false)
if err == nil {
return
Copy link
Contributor

Choose a reason for hiding this comment

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

same comment about logging success path

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same response :)

@melekes
Copy link
Contributor

melekes commented Feb 20, 2018

Very clean code ❤️ 💚 💛 but see my comments

@ebuchman ebuchman force-pushed the peerConn branch 2 times, most recently from 4be5554 to d8d7944 Compare February 21, 2018 02:43
@ebuchman ebuchman changed the base branch from 1157-option-to-require-auth to develop February 21, 2018 05:58
melekes and others added 8 commits February 21, 2018 01:05
if AuthEnc is true, dialed peers must have a node ID in the address and
it must match the persistent pubkey from the secret handshake.

Refs #1157
```
p2p/pex/pex_reactor_test.go:288:88: cannot use seed.NodeInfo().NetAddress() (type *p2p.NetAddress) as type string in array or slice literal
```
* Introduce `peerConn` containing the known fields of `peer`
* `peer` only created in `sw.addPeer` once handshake is complete and NodeInfo is checked
* Eliminates some mutable variables and makes the code flow better
* Simplifies the `newXxxPeer` funcs
* Use ID instead of PubKey where possible.
        * SetPubKeyFilter -> SetIDFilter
        * nodeInfo.Validate takes ID
        * remove peer.PubKey()
@melekes
Copy link
Contributor

melekes commented Feb 26, 2018

Testing fastsync on node 2
starting tendermint peer ID=2
ae8356685719cf2899cf7adcd464391182c184e602fae650467c4c9601c57211
starting test client container with CMD=test/p2p/fast_sync/check_peer.sh 2
Other peer is on height 35 with state "0800000000000000"
Waiting for peer 2 to catch up
... 0
... 0
... 3
... 34
... 35
... 35

fast_sync failed for 2nd peer.

2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: panic: runtime error: invalid memory address or nil pointer dereference
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: [signal SIGSEGV: segmentation violation code=0x1 addr=0x20 pc=0x98dd3e]
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]:
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: goroutine 3432 [running]:
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: github.com/tendermint/tendermint/p2p.newOutboundPeerConn(0xc423fd1380, 0xc420933e00, 0x1, 0x1239a60, 0
xc420128c40, 0x2, 0x42caf6, 0xc42001f300, 0xc422831d98, 0xc4227951c0, ...)
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: #011/go/src/github.com/tendermint/tendermint/p2p/peer.go:123 +0x31e
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: github.com/tendermint/tendermint/p2p.(*Switch).addOutboundPeerWithConfig(0xc4200ad040, 0xc423fd1380, 0
xc420933e00, 0xc423f48801, 0x28, 0x2)
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: #011/go/src/github.com/tendermint/tendermint/p2p/switch.go:455 +0x12b
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: github.com/tendermint/tendermint/p2p.(*Switch).DialPeerWithAddress(0xc4200ad040, 0xc423fd1380, 0x1, 0x
0, 0x0)
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: #011/go/src/github.com/tendermint/tendermint/p2p/switch.go:371 +0xdc
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: github.com/tendermint/tendermint/p2p.(*Switch).reconnectToPeer(0xc4200ad040, 0x123e000, 0xc42007bb00)
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: #011/go/src/github.com/tendermint/tendermint/p2p/switch.go:290 +0x25f
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: created by github.com/tendermint/tendermint/p2p.(*Switch).StopPeerForError
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: #011/go/src/github.com/tendermint/tendermint/p2p/switch.go:256 +0x1b7

```
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: panic: runtime error: invalid memory address or nil pointer dereference
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: [signal SIGSEGV: segmentation violation code=0x1 addr=0x20 pc=0x98dd3e]
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]:
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: goroutine 3432 [running]:
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: github.com/tendermint/tendermint/p2p.newOutboundPeerConn(0xc423fd1380, 0xc420933e00, 0x1, 0x1239a60, 0
xc420128c40, 0x2, 0x42caf6, 0xc42001f300, 0xc422831d98, 0xc4227951c0, ...)
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: #11/go/src/github.com/tendermint/tendermint/p2p/peer.go:123 +0x31e
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: github.com/tendermint/tendermint/p2p.(*Switch).addOutboundPeerWithConfig(0xc4200ad040, 0xc423fd1380, 0
xc420933e00, 0xc423f48801, 0x28, 0x2)
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: #11/go/src/github.com/tendermint/tendermint/p2p/switch.go:455 +0x12b
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: github.com/tendermint/tendermint/p2p.(*Switch).DialPeerWithAddress(0xc4200ad040, 0xc423fd1380, 0x1, 0x
0, 0x0)
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: #11/go/src/github.com/tendermint/tendermint/p2p/switch.go:371 +0xdc
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: github.com/tendermint/tendermint/p2p.(*Switch).reconnectToPeer(0xc4200ad040, 0x123e000, 0xc42007bb00)
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: #11/go/src/github.com/tendermint/tendermint/p2p/switch.go:290 +0x25f
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: created by github.com/tendermint/tendermint/p2p.(*Switch).StopPeerForError
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: #11/go/src/github.com/tendermint/tendermint/p2p/switch.go:256 +0x1b7
```
@codecov-io
Copy link

Codecov Report

Merging #1226 into develop will increase coverage by 0.2%.
The diff coverage is 58.33%.

@@            Coverage Diff             @@
##           develop    #1226     +/-   ##
==========================================
+ Coverage    59.49%   59.69%   +0.2%     
==========================================
  Files          121      122      +1     
  Lines        11046    11047      +1     
==========================================
+ Hits          6572     6595     +23     
+ Misses        3863     3846     -17     
+ Partials       611      606      -5

@melekes melekes merged commit 9293ae7 into develop Feb 27, 2018
@melekes melekes deleted the peerConn branch February 27, 2018 11:55
pc, err = newPeerConn(conn, config, true, persistent, ourNodePrivKey)
if err != nil {
if err2 := conn.Close(); err != nil {
if err2 := conn.Close(); err2 != nil {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

:o !!! thanks

Copy link
Contributor Author

Choose a reason for hiding this comment

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

is there a good paradigm/tactic we can use to avoid this kind of thing ?

Copy link
Contributor

Choose a reason for hiding this comment

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

always use err? metalinter?

cboh4 pushed a commit to scrtlabs/tendermint that referenced this pull request Apr 7, 2025
* CV OnStop close evidenceStore

* CV OnStop print db close

* CV add changelog

* CV update changelog with attribution

(cherry picked from commit 48335a0)

Co-authored-by: Chill Validation <92176880+chillyvee@users.noreply.github.com>
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