Browse Source

p2p: cleanup unused arguments (#7079)

This is mostly just reading through the output of uparam, after
noticing that there were a few places where we were ignoring some arguments.
pull/7088/head
Sam Kleinman 3 years ago
committed by GitHub
parent
commit
1b5bb5348f
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 22 additions and 25 deletions
  1. +9
    -9
      internal/p2p/router.go
  2. +1
    -1
      internal/statesync/block_queue.go
  3. +4
    -4
      internal/statesync/block_queue_test.go
  4. +1
    -1
      internal/statesync/reactor.go
  5. +5
    -5
      node/node.go
  6. +0
    -3
      node/setup.go
  7. +2
    -2
      test/e2e/node/main.go

+ 9
- 9
internal/p2p/router.go View File

@ -610,7 +610,7 @@ func (r *Router) openConnection(ctx context.Context, conn Connection) {
// The Router should do the handshake and have a final ack/fail
// message to make sure both ends have accepted the connection, such
// that it can be coordinated with the peer manager.
peerInfo, _, err := r.handshakePeer(ctx, conn, "")
peerInfo, err := r.handshakePeer(ctx, conn, "")
switch {
case errors.Is(err, context.Canceled):
return
@ -704,7 +704,7 @@ func (r *Router) connectPeer(ctx context.Context, address NodeAddress) {
return
}
peerInfo, _, err := r.handshakePeer(ctx, conn, address.NodeID)
peerInfo, err := r.handshakePeer(ctx, conn, address.NodeID)
switch {
case errors.Is(err, context.Canceled):
conn.Close()
@ -799,7 +799,7 @@ func (r *Router) handshakePeer(
ctx context.Context,
conn Connection,
expectID types.NodeID,
) (types.NodeInfo, crypto.PubKey, error) {
) (types.NodeInfo, error) {
if r.options.HandshakeTimeout > 0 {
var cancel context.CancelFunc
@ -809,27 +809,27 @@ func (r *Router) handshakePeer(
peerInfo, peerKey, err := conn.Handshake(ctx, r.nodeInfo, r.privKey)
if err != nil {
return peerInfo, peerKey, err
return peerInfo, err
}
if err = peerInfo.Validate(); err != nil {
return peerInfo, peerKey, fmt.Errorf("invalid handshake NodeInfo: %w", err)
return peerInfo, fmt.Errorf("invalid handshake NodeInfo: %w", err)
}
if types.NodeIDFromPubKey(peerKey) != peerInfo.NodeID {
return peerInfo, peerKey, fmt.Errorf("peer's public key did not match its node ID %q (expected %q)",
return peerInfo, fmt.Errorf("peer's public key did not match its node ID %q (expected %q)",
peerInfo.NodeID, types.NodeIDFromPubKey(peerKey))
}
if expectID != "" && expectID != peerInfo.NodeID {
return peerInfo, peerKey, fmt.Errorf("expected to connect with peer %q, got %q",
return peerInfo, fmt.Errorf("expected to connect with peer %q, got %q",
expectID, peerInfo.NodeID)
}
if err := r.nodeInfo.CompatibleWith(peerInfo); err != nil {
return peerInfo, peerKey, ErrRejected{
return peerInfo, ErrRejected{
err: err,
id: peerInfo.ID(),
isIncompatible: true,
}
}
return peerInfo, peerKey, nil
return peerInfo, nil
}
func (r *Router) runWithPeerMutex(fn func() error) error {


+ 1
- 1
internal/statesync/block_queue.go View File

@ -200,7 +200,7 @@ func (q *blockQueue) retry(height int64) {
// Success is called when a light block has been successfully verified and
// processed
func (q *blockQueue) success(height int64) {
func (q *blockQueue) success() {
q.mtx.Lock()
defer q.mtx.Unlock()
if q.terminal != nil && q.verifyHeight == q.terminal.Height {


+ 4
- 4
internal/statesync/block_queue_test.go View File

@ -58,7 +58,7 @@ loop:
// assert that the queue serializes the blocks
require.Equal(t, resp.block.Height, trackingHeight)
trackingHeight--
queue.success(resp.block.Height)
queue.success()
}
}
@ -105,7 +105,7 @@ func TestBlockQueueWithFailures(t *testing.T) {
queue.retry(resp.block.Height)
} else {
trackingHeight--
queue.success(resp.block.Height)
queue.success()
}
case <-queue.done():
@ -223,7 +223,7 @@ func TestBlockQueueStopTime(t *testing.T) {
// assert that the queue serializes the blocks
assert.Equal(t, resp.block.Height, trackingHeight)
trackingHeight--
queue.success(resp.block.Height)
queue.success()
case <-queue.done():
wg.Wait()
@ -268,7 +268,7 @@ loop:
case resp := <-queue.verifyNext():
require.GreaterOrEqual(t, resp.block.Height, initialHeight)
queue.success(resp.block.Height)
queue.success()
}
}
}


+ 1
- 1
internal/statesync/reactor.go View File

@ -509,7 +509,7 @@ func (r *Reactor) backfill(
}
trustedBlockID = resp.block.LastBlockID
queue.success(resp.block.Height)
queue.success()
r.Logger.Info("backfill: verified and stored light block", "height", resp.block.Height)
lastValidatorSet = resp.block.ValidatorSet


+ 5
- 5
node/node.go View File

@ -235,7 +235,7 @@ func makeNode(cfg *config.Config,
p2pLogger := logger.With("module", "p2p")
transport := createTransport(p2pLogger, cfg)
peerManager, err := createPeerManager(cfg, dbProvider, p2pLogger, nodeKey.ID)
peerManager, err := createPeerManager(cfg, dbProvider, nodeKey.ID)
if err != nil {
return nil, fmt.Errorf("failed to create peer manager: %w", err)
}
@ -283,7 +283,7 @@ func makeNode(cfg *config.Config,
// Create the blockchain reactor. Note, we do not start block sync if we're
// doing a state sync first.
bcReactorShim, bcReactor, err := createBlockchainReactor(
logger, cfg, state, blockExec, blockStore, csReactor,
logger, state, blockExec, blockStore, csReactor,
peerManager, router, blockSync && !stateSync, nodeMetrics.consensus,
)
if err != nil {
@ -352,7 +352,7 @@ func makeNode(cfg *config.Config,
pexCh := pex.ChannelDescriptor()
transport.AddChannelDescriptors([]*p2p.ChannelDescriptor{&pexCh})
pexReactor, err = createPEXReactorV2(cfg, logger, peerManager, router)
pexReactor, err = createPEXReactorV2(logger, peerManager, router)
if err != nil {
return nil, err
}
@ -446,7 +446,7 @@ func makeSeedNode(cfg *config.Config,
p2pLogger := logger.With("module", "p2p")
transport := createTransport(p2pLogger, cfg)
peerManager, err := createPeerManager(cfg, dbProvider, p2pLogger, nodeKey.ID)
peerManager, err := createPeerManager(cfg, dbProvider, nodeKey.ID)
if err != nil {
return nil, fmt.Errorf("failed to create peer manager: %w", err)
}
@ -466,7 +466,7 @@ func makeSeedNode(cfg *config.Config,
pexCh := pex.ChannelDescriptor()
transport.AddChannelDescriptors([]*p2p.ChannelDescriptor{&pexCh})
pexReactor, err = createPEXReactorV2(cfg, logger, peerManager, router)
pexReactor, err = createPEXReactorV2(logger, peerManager, router)
if err != nil {
return nil, err
}


+ 0
- 3
node/setup.go View File

@ -254,7 +254,6 @@ func createEvidenceReactor(
func createBlockchainReactor(
logger log.Logger,
cfg *config.Config,
state sm.State,
blockExec *sm.BlockExecutor,
blockStore *store.BlockStore,
@ -354,7 +353,6 @@ func createTransport(logger log.Logger, cfg *config.Config) *p2p.MConnTransport
func createPeerManager(
cfg *config.Config,
dbProvider config.DBProvider,
p2pLogger log.Logger,
nodeID types.NodeID,
) (*p2p.PeerManager, error) {
@ -443,7 +441,6 @@ func createRouter(
}
func createPEXReactorV2(
cfg *config.Config,
logger log.Logger,
peerManager *p2p.PeerManager,
router *p2p.Router,


+ 2
- 2
test/e2e/node/main.go View File

@ -79,7 +79,7 @@ func run(configFile string) error {
case string(e2e.ModeLight):
err = startLightNode(cfg)
case string(e2e.ModeSeed):
err = startSeedNode(cfg)
err = startSeedNode()
default:
err = startNode(cfg)
}
@ -140,7 +140,7 @@ func startNode(cfg *Config) error {
return n.Start()
}
func startSeedNode(cfg *Config) error {
func startSeedNode() error {
tmcfg, nodeLogger, err := setupNode()
if err != nil {
return fmt.Errorf("failed to setup config: %w", err)


Loading…
Cancel
Save