stacks-network / stacks-core

The Stacks blockchain implementation
https://docs.stacks.co
GNU General Public License v3.0
3.01k stars 672 forks source link

Add info logs for adding and removing a neighbor #5459

Closed ASuciuX closed 22 hours ago

ASuciuX commented 1 week ago

I got the display from adding a new neighbor. How could I reproduce the removal of a neighbor in order to check it is displayed as intended?

New neighbor added

INFO [1731602152.246766] [stackslib/src/net/neighbors/walk.rs:1089] [p2p-(0.0.0.0:20444,0.0.0.0:20443)] New neighbor added: public key: 233691638c08a3f8450f304c5ae7e487alda48 address: 00000000000000000000fff8e6a0db
jcnelson commented 1 week ago

Hi @ASuciuX, the best place to do this is actually in PeerNetwork::register_peer() and PeerNetwork::deregister_peer(). The neighbor walk state machine is only one of several state machines that can add or remove neighbors.

ASuciuX commented 1 week ago

Thank you! I will update it. How can I test a removal of a neighbor? I was running a mainnet instance but I could set up anything else if needed.

jcnelson commented 1 week ago

@ASuciuX Check out struct P2PSession in stackslib/src/main.rs. It sets up a p2p session with a running node (getting you to register_peer()). Simply dropping the PeerSession instance will trigger a call to deregister_peer() since the socket will close.

ASuciuX commented 3 days ago

@jcnelson I've moved them to p2p session, the output is the following:

For new neighbor accepted. The public key is an optional, which was always none in what I've run. Can this be Some(public_key) if the node is a miner or in what context would that be not none when adding a neighbor?

INFO [1731696282.438126] [stackslib/src/net/p2p.rs:1811] [p2p-(0.0.0.0:20444,0.0.0.0:20443)] Neighbor accepted! public key: None address: 00000000000000000000ffff8fc63cb8

For neighbor removed.

INFO [1731696340.243120] [stackslib/src/net/p2p.rs:1906] [p2p-(0.0.0.0:20444,0.0.0.0:20443)] Dropping neighbor! event id: 7 public address: b8db004e2928a10bf85d84071c0c9d398cee7dcf public key: 00000000000000000000ffff225662f3