From 8e7d431f6fcfc3f1c6755607085b7112a92087f1 Mon Sep 17 00:00:00 2001 From: Erik Grinaker Date: Wed, 23 Dec 2020 13:30:29 +0100 Subject: [PATCH] p2p: rename ID to NodeID --- behaviour/peer_behaviour.go | 10 +- behaviour/reporter.go | 6 +- behaviour/reporter_test.go | 14 +- blockchain/v0/pool.go | 38 +++--- blockchain/v0/pool_test.go | 14 +- blockchain/v0/reactor.go | 2 +- blockchain/v2/processor.go | 12 +- blockchain/v2/processor_test.go | 4 +- blockchain/v2/reactor.go | 10 +- blockchain/v2/reactor_test.go | 10 +- blockchain/v2/scheduler.go | 52 ++++---- blockchain/v2/scheduler_test.go | 208 ++++++++++++++--------------- consensus/msgs.go | 2 +- consensus/msgs_test.go | 2 +- consensus/state.go | 18 +-- consensus/types/height_vote_set.go | 8 +- mempool/clist_mempool.go | 4 +- mempool/mempool.go | 2 +- mempool/reactor.go | 4 +- p2p/errors.go | 6 +- p2p/key.go | 16 +-- p2p/mock/peer.go | 4 +- p2p/mocks/peer.go | 8 +- p2p/netaddress.go | 20 +-- p2p/node_info.go | 6 +- p2p/peer.go | 6 +- p2p/peer_set.go | 12 +- p2p/peer_set_test.go | 4 +- p2p/peer_test.go | 2 +- p2p/pex/addrbook.go | 18 +-- p2p/pex/addrbook_test.go | 2 +- p2p/pex/known_address.go | 2 +- p2p/pex/pex_reactor.go | 6 +- p2p/shim.go | 4 +- p2p/shim_test.go | 2 +- p2p/switch.go | 14 +- p2p/switch_test.go | 2 +- p2p/test_util.go | 6 +- p2p/transport.go | 2 +- p2p/transport_mconn.go | 2 +- p2p/transport_memory.go | 10 +- p2p/transport_memory_test.go | 2 +- test/maverick/consensus/msgs.go | 2 +- test/maverick/consensus/state.go | 18 +-- 44 files changed, 298 insertions(+), 298 deletions(-) diff --git a/behaviour/peer_behaviour.go b/behaviour/peer_behaviour.go index f7cfd00f0..dd45a0d2f 100644 --- a/behaviour/peer_behaviour.go +++ b/behaviour/peer_behaviour.go @@ -8,7 +8,7 @@ import ( // `peerID` identifies the peer and reason characterizes the specific // behaviour performed by the peer. type PeerBehaviour struct { - peerID p2p.ID + peerID p2p.NodeID reason interface{} } @@ -17,7 +17,7 @@ type badMessage struct { } // BadMessage returns a badMessage PeerBehaviour. -func BadMessage(peerID p2p.ID, explanation string) PeerBehaviour { +func BadMessage(peerID p2p.NodeID, explanation string) PeerBehaviour { return PeerBehaviour{peerID: peerID, reason: badMessage{explanation}} } @@ -26,7 +26,7 @@ type messageOutOfOrder struct { } // MessageOutOfOrder returns a messagOutOfOrder PeerBehaviour. -func MessageOutOfOrder(peerID p2p.ID, explanation string) PeerBehaviour { +func MessageOutOfOrder(peerID p2p.NodeID, explanation string) PeerBehaviour { return PeerBehaviour{peerID: peerID, reason: messageOutOfOrder{explanation}} } @@ -35,7 +35,7 @@ type consensusVote struct { } // ConsensusVote returns a consensusVote PeerBehaviour. -func ConsensusVote(peerID p2p.ID, explanation string) PeerBehaviour { +func ConsensusVote(peerID p2p.NodeID, explanation string) PeerBehaviour { return PeerBehaviour{peerID: peerID, reason: consensusVote{explanation}} } @@ -44,6 +44,6 @@ type blockPart struct { } // BlockPart returns blockPart PeerBehaviour. -func BlockPart(peerID p2p.ID, explanation string) PeerBehaviour { +func BlockPart(peerID p2p.NodeID, explanation string) PeerBehaviour { return PeerBehaviour{peerID: peerID, reason: blockPart{explanation}} } diff --git a/behaviour/reporter.go b/behaviour/reporter.go index 8dc10389e..a6fbf7d20 100644 --- a/behaviour/reporter.go +++ b/behaviour/reporter.go @@ -51,14 +51,14 @@ func (spbr *SwitchReporter) Report(behaviour PeerBehaviour) error { // behaviour in manufactured scenarios. type MockReporter struct { mtx tmsync.RWMutex - pb map[p2p.ID][]PeerBehaviour + pb map[p2p.NodeID][]PeerBehaviour } // NewMockReporter returns a Reporter which records all reported // behaviours in memory. func NewMockReporter() *MockReporter { return &MockReporter{ - pb: map[p2p.ID][]PeerBehaviour{}, + pb: map[p2p.NodeID][]PeerBehaviour{}, } } @@ -72,7 +72,7 @@ func (mpbr *MockReporter) Report(behaviour PeerBehaviour) error { } // GetBehaviours returns all behaviours reported on the peer identified by peerID. -func (mpbr *MockReporter) GetBehaviours(peerID p2p.ID) []PeerBehaviour { +func (mpbr *MockReporter) GetBehaviours(peerID p2p.NodeID) []PeerBehaviour { mpbr.mtx.RLock() defer mpbr.mtx.RUnlock() if items, ok := mpbr.pb[peerID]; ok { diff --git a/behaviour/reporter_test.go b/behaviour/reporter_test.go index 330505bd2..2680cc233 100644 --- a/behaviour/reporter_test.go +++ b/behaviour/reporter_test.go @@ -11,7 +11,7 @@ import ( // TestMockReporter tests the MockReporter's ability to store reported // peer behaviour in memory indexed by the peerID. func TestMockReporter(t *testing.T) { - var peerID p2p.ID = "MockPeer" + var peerID p2p.NodeID = "MockPeer" pr := bh.NewMockReporter() behaviours := pr.GetBehaviours(peerID) @@ -34,7 +34,7 @@ func TestMockReporter(t *testing.T) { } type scriptItem struct { - peerID p2p.ID + peerID p2p.NodeID behaviour bh.PeerBehaviour } @@ -76,10 +76,10 @@ func equalBehaviours(a []bh.PeerBehaviour, b []bh.PeerBehaviour) bool { // freequencies that those behaviours occur. func TestEqualPeerBehaviours(t *testing.T) { var ( - peerID p2p.ID = "MockPeer" - consensusVote = bh.ConsensusVote(peerID, "voted") - blockPart = bh.BlockPart(peerID, "blocked") - equals = []struct { + peerID p2p.NodeID = "MockPeer" + consensusVote = bh.ConsensusVote(peerID, "voted") + blockPart = bh.BlockPart(peerID, "blocked") + equals = []struct { left []bh.PeerBehaviour right []bh.PeerBehaviour }{ @@ -128,7 +128,7 @@ func TestEqualPeerBehaviours(t *testing.T) { func TestMockPeerBehaviourReporterConcurrency(t *testing.T) { var ( behaviourScript = []struct { - peerID p2p.ID + peerID p2p.NodeID behaviours []bh.PeerBehaviour }{ {"1", []bh.PeerBehaviour{bh.ConsensusVote("1", "")}}, diff --git a/blockchain/v0/pool.go b/blockchain/v0/pool.go index 7d61438a0..7541c06f9 100644 --- a/blockchain/v0/pool.go +++ b/blockchain/v0/pool.go @@ -62,7 +62,7 @@ var peerTimeout = 15 * time.Second // not const so we can override with tests // PeerID responsible for delivering the block. type BlockRequest struct { Height int64 - PeerID p2p.ID + PeerID p2p.NodeID } // BlockPool keeps track of the fast sync peers, block requests and block responses. @@ -75,7 +75,7 @@ type BlockPool struct { requesters map[int64]*bpRequester height int64 // the lowest key in requesters. // peers - peers map[p2p.ID]*bpPeer + peers map[p2p.NodeID]*bpPeer maxPeerHeight int64 // the biggest reported height // atomic @@ -89,7 +89,7 @@ type BlockPool struct { // requests and errors will be sent to requestsCh and errorsCh accordingly. func NewBlockPool(start int64, requestsCh chan<- BlockRequest, errorsCh chan<- peerError) *BlockPool { bp := &BlockPool{ - peers: make(map[p2p.ID]*bpPeer), + peers: make(map[p2p.NodeID]*bpPeer), requesters: make(map[int64]*bpRequester), height: start, @@ -223,13 +223,13 @@ func (pool *BlockPool) PopRequest() { // RedoRequest invalidates the block at pool.height, // Remove the peer and redo request from others. // Returns the ID of the removed peer. -func (pool *BlockPool) RedoRequest(height int64) p2p.ID { +func (pool *BlockPool) RedoRequest(height int64) p2p.NodeID { pool.mtx.Lock() defer pool.mtx.Unlock() request := pool.requesters[height] peerID := request.getPeerID() - if peerID != p2p.ID("") { + if peerID != p2p.NodeID("") { // RemovePeer will redo all requesters associated with this peer. pool.removePeer(peerID) } @@ -238,7 +238,7 @@ func (pool *BlockPool) RedoRequest(height int64) p2p.ID { // AddBlock validates that the block comes from the peer it was expected from and calls the requester to store it. // TODO: ensure that blocks come in order for each peer. -func (pool *BlockPool) AddBlock(peerID p2p.ID, block *types.Block, blockSize int) { +func (pool *BlockPool) AddBlock(peerID p2p.NodeID, block *types.Block, blockSize int) { pool.mtx.Lock() defer pool.mtx.Unlock() @@ -285,7 +285,7 @@ func (pool *BlockPool) LastAdvance() time.Time { } // SetPeerRange sets the peer's alleged blockchain base and height. -func (pool *BlockPool) SetPeerRange(peerID p2p.ID, base int64, height int64) { +func (pool *BlockPool) SetPeerRange(peerID p2p.NodeID, base int64, height int64) { pool.mtx.Lock() defer pool.mtx.Unlock() @@ -306,14 +306,14 @@ func (pool *BlockPool) SetPeerRange(peerID p2p.ID, base int64, height int64) { // RemovePeer removes the peer with peerID from the pool. If there's no peer // with peerID, function is a no-op. -func (pool *BlockPool) RemovePeer(peerID p2p.ID) { +func (pool *BlockPool) RemovePeer(peerID p2p.NodeID) { pool.mtx.Lock() defer pool.mtx.Unlock() pool.removePeer(peerID) } -func (pool *BlockPool) removePeer(peerID p2p.ID) { +func (pool *BlockPool) removePeer(peerID p2p.NodeID) { for _, requester := range pool.requesters { if requester.getPeerID() == peerID { requester.redo(peerID) @@ -394,14 +394,14 @@ func (pool *BlockPool) requestersLen() int64 { return int64(len(pool.requesters)) } -func (pool *BlockPool) sendRequest(height int64, peerID p2p.ID) { +func (pool *BlockPool) sendRequest(height int64, peerID p2p.NodeID) { if !pool.IsRunning() { return } pool.requestsCh <- BlockRequest{height, peerID} } -func (pool *BlockPool) sendError(err error, peerID p2p.ID) { +func (pool *BlockPool) sendError(err error, peerID p2p.NodeID) { if !pool.IsRunning() { return } @@ -435,7 +435,7 @@ type bpPeer struct { height int64 base int64 pool *BlockPool - id p2p.ID + id p2p.NodeID recvMonitor *flow.Monitor timeout *time.Timer @@ -443,7 +443,7 @@ type bpPeer struct { logger log.Logger } -func newBPPeer(pool *BlockPool, peerID p2p.ID, base int64, height int64) *bpPeer { +func newBPPeer(pool *BlockPool, peerID p2p.NodeID, base int64, height int64) *bpPeer { peer := &bpPeer{ pool: pool, id: peerID, @@ -508,10 +508,10 @@ type bpRequester struct { pool *BlockPool height int64 gotBlockCh chan struct{} - redoCh chan p2p.ID // redo may send multitime, add peerId to identify repeat + redoCh chan p2p.NodeID // redo may send multitime, add peerId to identify repeat mtx tmsync.Mutex - peerID p2p.ID + peerID p2p.NodeID block *types.Block } @@ -520,7 +520,7 @@ func newBPRequester(pool *BlockPool, height int64) *bpRequester { pool: pool, height: height, gotBlockCh: make(chan struct{}, 1), - redoCh: make(chan p2p.ID, 1), + redoCh: make(chan p2p.NodeID, 1), peerID: "", block: nil, @@ -535,7 +535,7 @@ func (bpr *bpRequester) OnStart() error { } // Returns true if the peer matches and block doesn't already exist. -func (bpr *bpRequester) setBlock(block *types.Block, peerID p2p.ID) bool { +func (bpr *bpRequester) setBlock(block *types.Block, peerID p2p.NodeID) bool { bpr.mtx.Lock() if bpr.block != nil || bpr.peerID != peerID { bpr.mtx.Unlock() @@ -557,7 +557,7 @@ func (bpr *bpRequester) getBlock() *types.Block { return bpr.block } -func (bpr *bpRequester) getPeerID() p2p.ID { +func (bpr *bpRequester) getPeerID() p2p.NodeID { bpr.mtx.Lock() defer bpr.mtx.Unlock() return bpr.peerID @@ -579,7 +579,7 @@ func (bpr *bpRequester) reset() { // Tells bpRequester to pick another peer and try again. // NOTE: Nonblocking, and does nothing if another redo // was already requested. -func (bpr *bpRequester) redo(peerID p2p.ID) { +func (bpr *bpRequester) redo(peerID p2p.NodeID) { select { case bpr.redoCh <- peerID: default: diff --git a/blockchain/v0/pool_test.go b/blockchain/v0/pool_test.go index 1653fe74a..d02df0326 100644 --- a/blockchain/v0/pool_test.go +++ b/blockchain/v0/pool_test.go @@ -19,7 +19,7 @@ func init() { } type testPeer struct { - id p2p.ID + id p2p.NodeID base int64 height int64 inputChan chan inputData // make sure each peer's data is sequential @@ -49,7 +49,7 @@ func (p testPeer) simulateInput(input inputData) { // input.t.Logf("Added block from peer %v (height: %v)", input.request.PeerID, input.request.Height) } -type testPeers map[p2p.ID]testPeer +type testPeers map[p2p.NodeID]testPeer func (ps testPeers) start() { for _, v := range ps { @@ -66,7 +66,7 @@ func (ps testPeers) stop() { func makePeers(numPeers int, minHeight, maxHeight int64) testPeers { peers := make(testPeers, numPeers) for i := 0; i < numPeers; i++ { - peerID := p2p.ID(tmrand.Str(12)) + peerID := p2p.NodeID(tmrand.Str(12)) height := minHeight + tmrand.Int63n(maxHeight-minHeight) base := minHeight + int64(i) if base > height { @@ -182,7 +182,7 @@ func TestBlockPoolTimeout(t *testing.T) { // Pull from channels counter := 0 - timedOut := map[p2p.ID]struct{}{} + timedOut := map[p2p.NodeID]struct{}{} for { select { case err := <-errorsCh: @@ -203,7 +203,7 @@ func TestBlockPoolTimeout(t *testing.T) { func TestBlockPoolRemovePeer(t *testing.T) { peers := make(testPeers, 10) for i := 0; i < 10; i++ { - peerID := p2p.ID(fmt.Sprintf("%d", i+1)) + peerID := p2p.NodeID(fmt.Sprintf("%d", i+1)) height := int64(i + 1) peers[peerID] = testPeer{peerID, 0, height, make(chan inputData)} } @@ -227,10 +227,10 @@ func TestBlockPoolRemovePeer(t *testing.T) { assert.EqualValues(t, 10, pool.MaxPeerHeight()) // remove not-existing peer - assert.NotPanics(t, func() { pool.RemovePeer(p2p.ID("Superman")) }) + assert.NotPanics(t, func() { pool.RemovePeer(p2p.NodeID("Superman")) }) // remove peer with biggest height - pool.RemovePeer(p2p.ID("10")) + pool.RemovePeer(p2p.NodeID("10")) assert.EqualValues(t, 9, pool.MaxPeerHeight()) // remove all peers diff --git a/blockchain/v0/reactor.go b/blockchain/v0/reactor.go index 0184d926a..770963793 100644 --- a/blockchain/v0/reactor.go +++ b/blockchain/v0/reactor.go @@ -41,7 +41,7 @@ type consensusReactor interface { type peerError struct { err error - peerID p2p.ID + peerID p2p.NodeID } func (e peerError) Error() string { diff --git a/blockchain/v2/processor.go b/blockchain/v2/processor.go index f9036f3b9..c25386cdc 100644 --- a/blockchain/v2/processor.go +++ b/blockchain/v2/processor.go @@ -13,8 +13,8 @@ import ( type pcBlockVerificationFailure struct { priorityNormal height int64 - firstPeerID p2p.ID - secondPeerID p2p.ID + firstPeerID p2p.NodeID + secondPeerID p2p.NodeID } func (e pcBlockVerificationFailure) String() string { @@ -26,7 +26,7 @@ func (e pcBlockVerificationFailure) String() string { type pcBlockProcessed struct { priorityNormal height int64 - peerID p2p.ID + peerID p2p.NodeID } func (e pcBlockProcessed) String() string { @@ -46,7 +46,7 @@ func (p pcFinished) Error() string { type queueItem struct { block *types.Block - peerID p2p.ID + peerID p2p.NodeID } type blockQueue map[int64]queueItem @@ -95,7 +95,7 @@ func (state *pcState) synced() bool { return len(state.queue) <= 1 } -func (state *pcState) enqueue(peerID p2p.ID, block *types.Block, height int64) { +func (state *pcState) enqueue(peerID p2p.NodeID, block *types.Block, height int64) { if item, ok := state.queue[height]; ok { panic(fmt.Sprintf( "duplicate block %d (%X) enqueued by processor (sent by %v; existing block %X from %v)", @@ -110,7 +110,7 @@ func (state *pcState) height() int64 { } // purgePeer moves all unprocessed blocks from the queue -func (state *pcState) purgePeer(peerID p2p.ID) { +func (state *pcState) purgePeer(peerID p2p.NodeID) { // what if height is less than state.height? for height, item := range state.queue { if item.peerID == peerID { diff --git a/blockchain/v2/processor_test.go b/blockchain/v2/processor_test.go index 6bc36b2d3..f268a0910 100644 --- a/blockchain/v2/processor_test.go +++ b/blockchain/v2/processor_test.go @@ -40,7 +40,7 @@ func makeState(p *params) *pcState { state := newPcState(context) for _, item := range p.items { - state.enqueue(p2p.ID(item.pid), makePcBlock(item.height), item.height) + state.enqueue(p2p.NodeID(item.pid), makePcBlock(item.height), item.height) } state.blocksSynced = p.blocksSynced @@ -48,7 +48,7 @@ func makeState(p *params) *pcState { return state } -func mBlockResponse(peerID p2p.ID, height int64) scBlockReceived { +func mBlockResponse(peerID p2p.NodeID, height int64) scBlockReceived { return scBlockReceived{ peerID: peerID, block: makePcBlock(height), diff --git a/blockchain/v2/reactor.go b/blockchain/v2/reactor.go index cc9671bd0..6386b0f1b 100644 --- a/blockchain/v2/reactor.go +++ b/blockchain/v2/reactor.go @@ -209,7 +209,7 @@ func (e rProcessBlock) String() string { type bcBlockResponse struct { priorityNormal time time.Time - peerID p2p.ID + peerID p2p.NodeID size int64 block *types.Block } @@ -223,7 +223,7 @@ func (resp bcBlockResponse) String() string { type bcNoBlockResponse struct { priorityNormal time time.Time - peerID p2p.ID + peerID p2p.NodeID height int64 } @@ -236,7 +236,7 @@ func (resp bcNoBlockResponse) String() string { type bcStatusResponse struct { priorityNormal time time.Time - peerID p2p.ID + peerID p2p.NodeID base int64 height int64 } @@ -249,7 +249,7 @@ func (resp bcStatusResponse) String() string { // new peer is connected type bcAddNewPeer struct { priorityNormal - peerID p2p.ID + peerID p2p.NodeID } func (resp bcAddNewPeer) String() string { @@ -259,7 +259,7 @@ func (resp bcAddNewPeer) String() string { // existing peer is removed type bcRemovePeer struct { priorityHigh - peerID p2p.ID + peerID p2p.NodeID reason interface{} } diff --git a/blockchain/v2/reactor_test.go b/blockchain/v2/reactor_test.go index 94f83625f..7427fb3a6 100644 --- a/blockchain/v2/reactor_test.go +++ b/blockchain/v2/reactor_test.go @@ -32,11 +32,11 @@ import ( type mockPeer struct { service.Service - id p2p.ID + id p2p.NodeID } func (mp mockPeer) FlushStop() {} -func (mp mockPeer) ID() p2p.ID { return mp.id } +func (mp mockPeer) ID() p2p.NodeID { return mp.id } func (mp mockPeer) RemoteIP() net.IP { return net.IP{} } func (mp mockPeer) RemoteAddr() net.Addr { return &net.TCPAddr{IP: mp.RemoteIP(), Port: 8800} } @@ -411,21 +411,21 @@ func TestReactorHelperMode(t *testing.T) { old := mockSwitch.numStatusResponse msg, err := bc.EncodeMsg(&ev) assert.NoError(t, err) - reactor.Receive(channelID, mockPeer{id: p2p.ID(step.peer)}, msg) + reactor.Receive(channelID, mockPeer{id: p2p.NodeID(step.peer)}, msg) assert.Equal(t, old+1, mockSwitch.numStatusResponse) case bcproto.BlockRequest: if ev.Height > params.startHeight { old := mockSwitch.numNoBlockResponse msg, err := bc.EncodeMsg(&ev) assert.NoError(t, err) - reactor.Receive(channelID, mockPeer{id: p2p.ID(step.peer)}, msg) + reactor.Receive(channelID, mockPeer{id: p2p.NodeID(step.peer)}, msg) assert.Equal(t, old+1, mockSwitch.numNoBlockResponse) } else { old := mockSwitch.numBlockResponse msg, err := bc.EncodeMsg(&ev) assert.NoError(t, err) assert.NoError(t, err) - reactor.Receive(channelID, mockPeer{id: p2p.ID(step.peer)}, msg) + reactor.Receive(channelID, mockPeer{id: p2p.NodeID(step.peer)}, msg) assert.Equal(t, old+1, mockSwitch.numBlockResponse) } } diff --git a/blockchain/v2/scheduler.go b/blockchain/v2/scheduler.go index 75fe9d46d..1aa9acd3c 100644 --- a/blockchain/v2/scheduler.go +++ b/blockchain/v2/scheduler.go @@ -26,7 +26,7 @@ func (e scFinishedEv) String() string { // send a blockRequest message type scBlockRequest struct { priorityNormal - peerID p2p.ID + peerID p2p.NodeID height int64 } @@ -37,7 +37,7 @@ func (e scBlockRequest) String() string { // a block has been received and validated by the scheduler type scBlockReceived struct { priorityNormal - peerID p2p.ID + peerID p2p.NodeID block *types.Block } @@ -48,7 +48,7 @@ func (e scBlockReceived) String() string { // scheduler detected a peer error type scPeerError struct { priorityHigh - peerID p2p.ID + peerID p2p.NodeID reason error } @@ -59,7 +59,7 @@ func (e scPeerError) String() string { // scheduler removed a set of peers (timed out or slow peer) type scPeersPruned struct { priorityHigh - peers []p2p.ID + peers []p2p.NodeID } func (e scPeersPruned) String() string { @@ -126,7 +126,7 @@ func (e peerState) String() string { } type scPeer struct { - peerID p2p.ID + peerID p2p.NodeID // initialized as New when peer is added, updated to Ready when statusUpdate is received, // updated to Removed when peer is removed @@ -143,7 +143,7 @@ func (p scPeer) String() string { p.state, p.base, p.height, p.lastTouched, p.lastRate, p.peerID) } -func newScPeer(peerID p2p.ID) *scPeer { +func newScPeer(peerID p2p.NodeID) *scPeer { return &scPeer{ peerID: peerID, state: peerStateNew, @@ -171,7 +171,7 @@ type scheduler struct { // a map of peerID to scheduler specific peer struct `scPeer` used to keep // track of peer specific state - peers map[p2p.ID]*scPeer + peers map[p2p.NodeID]*scPeer peerTimeout time.Duration // maximum response time from a peer otherwise prune minRecvRate int64 // minimum receive rate from peer otherwise prune @@ -183,13 +183,13 @@ type scheduler struct { blockStates map[int64]blockState // a map of heights to the peer we are waiting a response from - pendingBlocks map[int64]p2p.ID + pendingBlocks map[int64]p2p.NodeID // the time at which a block was put in blockStatePending pendingTime map[int64]time.Time // a map of heights to the peers that put the block in blockStateReceived - receivedBlocks map[int64]p2p.ID + receivedBlocks map[int64]p2p.NodeID } func (sc scheduler) String() string { @@ -204,10 +204,10 @@ func newScheduler(initHeight int64, startTime time.Time) *scheduler { syncTimeout: 60 * time.Second, height: initHeight, blockStates: make(map[int64]blockState), - peers: make(map[p2p.ID]*scPeer), - pendingBlocks: make(map[int64]p2p.ID), + peers: make(map[p2p.NodeID]*scPeer), + pendingBlocks: make(map[int64]p2p.NodeID), pendingTime: make(map[int64]time.Time), - receivedBlocks: make(map[int64]p2p.ID), + receivedBlocks: make(map[int64]p2p.NodeID), targetPending: 10, // TODO - pass as param peerTimeout: 15 * time.Second, // TODO - pass as param minRecvRate: 0, // int64(7680), TODO - pass as param @@ -216,14 +216,14 @@ func newScheduler(initHeight int64, startTime time.Time) *scheduler { return &sc } -func (sc *scheduler) ensurePeer(peerID p2p.ID) *scPeer { +func (sc *scheduler) ensurePeer(peerID p2p.NodeID) *scPeer { if _, ok := sc.peers[peerID]; !ok { sc.peers[peerID] = newScPeer(peerID) } return sc.peers[peerID] } -func (sc *scheduler) touchPeer(peerID p2p.ID, time time.Time) error { +func (sc *scheduler) touchPeer(peerID p2p.NodeID, time time.Time) error { peer, ok := sc.peers[peerID] if !ok { return fmt.Errorf("couldn't find peer %s", peerID) @@ -238,7 +238,7 @@ func (sc *scheduler) touchPeer(peerID p2p.ID, time time.Time) error { return nil } -func (sc *scheduler) removePeer(peerID p2p.ID) { +func (sc *scheduler) removePeer(peerID p2p.NodeID) { peer, ok := sc.peers[peerID] if !ok { return @@ -298,7 +298,7 @@ func (sc *scheduler) addNewBlocks() { } } -func (sc *scheduler) setPeerRange(peerID p2p.ID, base int64, height int64) error { +func (sc *scheduler) setPeerRange(peerID p2p.NodeID, base int64, height int64) error { peer := sc.ensurePeer(peerID) if peer.state == peerStateRemoved { @@ -333,8 +333,8 @@ func (sc *scheduler) getStateAtHeight(height int64) blockState { } } -func (sc *scheduler) getPeersWithHeight(height int64) []p2p.ID { - peers := make([]p2p.ID, 0) +func (sc *scheduler) getPeersWithHeight(height int64) []p2p.NodeID { + peers := make([]p2p.NodeID, 0) for _, peer := range sc.peers { if peer.state != peerStateReady { continue @@ -346,8 +346,8 @@ func (sc *scheduler) getPeersWithHeight(height int64) []p2p.ID { return peers } -func (sc *scheduler) prunablePeers(peerTimout time.Duration, minRecvRate int64, now time.Time) []p2p.ID { - prunable := make([]p2p.ID, 0) +func (sc *scheduler) prunablePeers(peerTimout time.Duration, minRecvRate int64, now time.Time) []p2p.NodeID { + prunable := make([]p2p.NodeID, 0) for peerID, peer := range sc.peers { if peer.state != peerStateReady { continue @@ -366,7 +366,7 @@ func (sc *scheduler) setStateAtHeight(height int64, state blockState) { } // CONTRACT: peer exists and in Ready state. -func (sc *scheduler) markReceived(peerID p2p.ID, height int64, size int64, now time.Time) error { +func (sc *scheduler) markReceived(peerID p2p.NodeID, height int64, size int64, now time.Time) error { peer := sc.peers[peerID] if state := sc.getStateAtHeight(height); state != blockStatePending || sc.pendingBlocks[height] != peerID { @@ -390,7 +390,7 @@ func (sc *scheduler) markReceived(peerID p2p.ID, height int64, size int64, now t return nil } -func (sc *scheduler) markPending(peerID p2p.ID, height int64, time time.Time) error { +func (sc *scheduler) markPending(peerID p2p.NodeID, height int64, time time.Time) error { state := sc.getStateAtHeight(height) if state != blockStateNew { return fmt.Errorf("block %d should be in blockStateNew but is %s", height, state) @@ -472,7 +472,7 @@ func (sc *scheduler) nextHeightToSchedule() int64 { return min } -func (sc *scheduler) pendingFrom(peerID p2p.ID) []int64 { +func (sc *scheduler) pendingFrom(peerID p2p.NodeID) []int64 { var heights []int64 for height, pendingPeerID := range sc.pendingBlocks { if pendingPeerID == peerID { @@ -482,7 +482,7 @@ func (sc *scheduler) pendingFrom(peerID p2p.ID) []int64 { return heights } -func (sc *scheduler) selectPeer(height int64) (p2p.ID, error) { +func (sc *scheduler) selectPeer(height int64) (p2p.NodeID, error) { peers := sc.getPeersWithHeight(height) if len(peers) == 0 { return "", fmt.Errorf("cannot find peer for height %d", height) @@ -490,7 +490,7 @@ func (sc *scheduler) selectPeer(height int64) (p2p.ID, error) { // create a map from number of pending requests to a list // of peers having that number of pending requests. - pendingFrom := make(map[int][]p2p.ID) + pendingFrom := make(map[int][]p2p.NodeID) for _, peerID := range peers { numPending := len(sc.pendingFrom(peerID)) pendingFrom[numPending] = append(pendingFrom[numPending], peerID) @@ -509,7 +509,7 @@ func (sc *scheduler) selectPeer(height int64) (p2p.ID, error) { } // PeerByID is a list of peers sorted by peerID. -type PeerByID []p2p.ID +type PeerByID []p2p.NodeID func (peers PeerByID) Len() int { return len(peers) diff --git a/blockchain/v2/scheduler_test.go b/blockchain/v2/scheduler_test.go index d2b2c9595..b864a5303 100644 --- a/blockchain/v2/scheduler_test.go +++ b/blockchain/v2/scheduler_test.go @@ -20,9 +20,9 @@ type scTestParams struct { initHeight int64 height int64 allB []int64 - pending map[int64]p2p.ID + pending map[int64]p2p.NodeID pendingTime map[int64]time.Time - received map[int64]p2p.ID + received map[int64]p2p.NodeID peerTimeout time.Duration minRecvRate int64 targetPending int @@ -41,7 +41,7 @@ func verifyScheduler(sc *scheduler) { } func newTestScheduler(params scTestParams) *scheduler { - peers := make(map[p2p.ID]*scPeer) + peers := make(map[p2p.NodeID]*scPeer) var maxHeight int64 initHeight := params.initHeight @@ -54,8 +54,8 @@ func newTestScheduler(params scTestParams) *scheduler { } for id, peer := range params.peers { - peer.peerID = p2p.ID(id) - peers[p2p.ID(id)] = peer + peer.peerID = p2p.NodeID(id) + peers[p2p.NodeID(id)] = peer if maxHeight < peer.height { maxHeight = peer.height } @@ -122,7 +122,7 @@ func TestScMaxHeights(t *testing.T) { name: "one ready peer", sc: scheduler{ height: 3, - peers: map[p2p.ID]*scPeer{"P1": {height: 6, state: peerStateReady}}, + peers: map[p2p.NodeID]*scPeer{"P1": {height: 6, state: peerStateReady}}, }, wantMax: 6, }, @@ -130,7 +130,7 @@ func TestScMaxHeights(t *testing.T) { name: "ready and removed peers", sc: scheduler{ height: 1, - peers: map[p2p.ID]*scPeer{ + peers: map[p2p.NodeID]*scPeer{ "P1": {height: 4, state: peerStateReady}, "P2": {height: 10, state: peerStateRemoved}}, }, @@ -140,7 +140,7 @@ func TestScMaxHeights(t *testing.T) { name: "removed peers", sc: scheduler{ height: 1, - peers: map[p2p.ID]*scPeer{ + peers: map[p2p.NodeID]*scPeer{ "P1": {height: 4, state: peerStateRemoved}, "P2": {height: 10, state: peerStateRemoved}}, }, @@ -150,7 +150,7 @@ func TestScMaxHeights(t *testing.T) { name: "new peers", sc: scheduler{ height: 1, - peers: map[p2p.ID]*scPeer{ + peers: map[p2p.NodeID]*scPeer{ "P1": {base: -1, height: -1, state: peerStateNew}, "P2": {base: -1, height: -1, state: peerStateNew}}, }, @@ -160,7 +160,7 @@ func TestScMaxHeights(t *testing.T) { name: "mixed peers", sc: scheduler{ height: 1, - peers: map[p2p.ID]*scPeer{ + peers: map[p2p.NodeID]*scPeer{ "P1": {height: -1, state: peerStateNew}, "P2": {height: 10, state: peerStateReady}, "P3": {height: 20, state: peerStateRemoved}, @@ -187,7 +187,7 @@ func TestScMaxHeights(t *testing.T) { func TestScEnsurePeer(t *testing.T) { type args struct { - peerID p2p.ID + peerID p2p.NodeID } tests := []struct { name string @@ -244,7 +244,7 @@ func TestScTouchPeer(t *testing.T) { now := time.Now() type args struct { - peerID p2p.ID + peerID p2p.NodeID time time.Time } @@ -316,13 +316,13 @@ func TestScPrunablePeers(t *testing.T) { name string fields scTestParams args args - wantResult []p2p.ID + wantResult []p2p.NodeID }{ { name: "no peers", fields: scTestParams{peers: map[string]*scPeer{}}, args: args{threshold: time.Second, time: now.Add(time.Second + time.Millisecond), minSpeed: 100}, - wantResult: []p2p.ID{}, + wantResult: []p2p.NodeID{}, }, { name: "mixed peers", @@ -341,7 +341,7 @@ func TestScPrunablePeers(t *testing.T) { "P6": {state: peerStateReady, lastTouched: now.Add(time.Second), lastRate: 90}, }}, args: args{threshold: time.Second, time: now.Add(time.Second + time.Millisecond), minSpeed: 100}, - wantResult: []p2p.ID{"P4", "P5", "P6"}, + wantResult: []p2p.NodeID{"P4", "P5", "P6"}, }, } @@ -361,7 +361,7 @@ func TestScPrunablePeers(t *testing.T) { func TestScRemovePeer(t *testing.T) { type args struct { - peerID p2p.ID + peerID p2p.NodeID } tests := []struct { name string @@ -424,13 +424,13 @@ func TestScRemovePeer(t *testing.T) { fields: scTestParams{ peers: map[string]*scPeer{"P1": {height: 3, state: peerStateReady}}, allB: []int64{1, 2, 3}, - pending: map[int64]p2p.ID{1: "P1"}, + pending: map[int64]p2p.NodeID{1: "P1"}, }, args: args{peerID: "P1"}, wantFields: scTestParams{ peers: map[string]*scPeer{"P1": {height: 3, state: peerStateRemoved}}, allB: []int64{}, - pending: map[int64]p2p.ID{}, + pending: map[int64]p2p.NodeID{}, }, }, { @@ -438,13 +438,13 @@ func TestScRemovePeer(t *testing.T) { fields: scTestParams{ peers: map[string]*scPeer{"P1": {height: 3, state: peerStateReady}}, allB: []int64{1, 2, 3}, - received: map[int64]p2p.ID{1: "P1"}, + received: map[int64]p2p.NodeID{1: "P1"}, }, args: args{peerID: "P1"}, wantFields: scTestParams{ peers: map[string]*scPeer{"P1": {height: 3, state: peerStateRemoved}}, allB: []int64{}, - received: map[int64]p2p.ID{}, + received: map[int64]p2p.NodeID{}, }, }, { @@ -452,15 +452,15 @@ func TestScRemovePeer(t *testing.T) { fields: scTestParams{ peers: map[string]*scPeer{"P1": {height: 4, state: peerStateReady}}, allB: []int64{1, 2, 3, 4}, - pending: map[int64]p2p.ID{1: "P1", 3: "P1"}, - received: map[int64]p2p.ID{2: "P1", 4: "P1"}, + pending: map[int64]p2p.NodeID{1: "P1", 3: "P1"}, + received: map[int64]p2p.NodeID{2: "P1", 4: "P1"}, }, args: args{peerID: "P1"}, wantFields: scTestParams{ peers: map[string]*scPeer{"P1": {height: 4, state: peerStateRemoved}}, allB: []int64{}, - pending: map[int64]p2p.ID{}, - received: map[int64]p2p.ID{}, + pending: map[int64]p2p.NodeID{}, + received: map[int64]p2p.NodeID{}, }, }, { @@ -471,8 +471,8 @@ func TestScRemovePeer(t *testing.T) { "P2": {height: 6, state: peerStateReady}, }, allB: []int64{1, 2, 3, 4, 5, 6}, - pending: map[int64]p2p.ID{1: "P1", 3: "P2", 6: "P1"}, - received: map[int64]p2p.ID{2: "P1", 4: "P2", 5: "P2"}, + pending: map[int64]p2p.NodeID{1: "P1", 3: "P2", 6: "P1"}, + received: map[int64]p2p.NodeID{2: "P1", 4: "P2", 5: "P2"}, }, args: args{peerID: "P1"}, wantFields: scTestParams{ @@ -481,8 +481,8 @@ func TestScRemovePeer(t *testing.T) { "P2": {height: 6, state: peerStateReady}, }, allB: []int64{1, 2, 3, 4, 5, 6}, - pending: map[int64]p2p.ID{3: "P2"}, - received: map[int64]p2p.ID{4: "P2", 5: "P2"}, + pending: map[int64]p2p.NodeID{3: "P2"}, + received: map[int64]p2p.NodeID{4: "P2", 5: "P2"}, }, }, } @@ -501,7 +501,7 @@ func TestScRemovePeer(t *testing.T) { func TestScSetPeerRange(t *testing.T) { type args struct { - peerID p2p.ID + peerID p2p.NodeID base int64 height int64 } @@ -622,25 +622,25 @@ func TestScGetPeersWithHeight(t *testing.T) { name string fields scTestParams args args - wantResult []p2p.ID + wantResult []p2p.NodeID }{ { name: "no peers", fields: scTestParams{peers: map[string]*scPeer{}}, args: args{height: 10}, - wantResult: []p2p.ID{}, + wantResult: []p2p.NodeID{}, }, { name: "only new peers", fields: scTestParams{peers: map[string]*scPeer{"P1": {height: -1, state: peerStateNew}}}, args: args{height: 10}, - wantResult: []p2p.ID{}, + wantResult: []p2p.NodeID{}, }, { name: "only Removed peers", fields: scTestParams{peers: map[string]*scPeer{"P1": {height: 4, state: peerStateRemoved}}}, args: args{height: 2}, - wantResult: []p2p.ID{}, + wantResult: []p2p.NodeID{}, }, { name: "one Ready shorter peer", @@ -649,7 +649,7 @@ func TestScGetPeersWithHeight(t *testing.T) { allB: []int64{1, 2, 3, 4}, }, args: args{height: 5}, - wantResult: []p2p.ID{}, + wantResult: []p2p.NodeID{}, }, { name: "one Ready equal peer", @@ -658,7 +658,7 @@ func TestScGetPeersWithHeight(t *testing.T) { allB: []int64{1, 2, 3, 4}, }, args: args{height: 4}, - wantResult: []p2p.ID{"P1"}, + wantResult: []p2p.NodeID{"P1"}, }, { name: "one Ready higher peer", @@ -668,7 +668,7 @@ func TestScGetPeersWithHeight(t *testing.T) { allB: []int64{1, 2, 3, 4}, }, args: args{height: 4}, - wantResult: []p2p.ID{"P1"}, + wantResult: []p2p.NodeID{"P1"}, }, { name: "one Ready higher peer at base", @@ -678,7 +678,7 @@ func TestScGetPeersWithHeight(t *testing.T) { allB: []int64{1, 2, 3, 4}, }, args: args{height: 4}, - wantResult: []p2p.ID{"P1"}, + wantResult: []p2p.NodeID{"P1"}, }, { name: "one Ready higher peer with higher base", @@ -688,7 +688,7 @@ func TestScGetPeersWithHeight(t *testing.T) { allB: []int64{1, 2, 3, 4}, }, args: args{height: 4}, - wantResult: []p2p.ID{}, + wantResult: []p2p.NodeID{}, }, { name: "multiple mixed peers", @@ -703,7 +703,7 @@ func TestScGetPeersWithHeight(t *testing.T) { allB: []int64{8, 9, 10, 11}, }, args: args{height: 8}, - wantResult: []p2p.ID{"P2", "P5"}, + wantResult: []p2p.NodeID{"P2", "P5"}, }, } @@ -725,7 +725,7 @@ func TestScMarkPending(t *testing.T) { now := time.Now() type args struct { - peerID p2p.ID + peerID p2p.NodeID height int64 tm time.Time } @@ -821,14 +821,14 @@ func TestScMarkPending(t *testing.T) { fields: scTestParams{ peers: map[string]*scPeer{"P1": {height: 2, state: peerStateReady}}, allB: []int64{1, 2}, - pending: map[int64]p2p.ID{1: "P1"}, + pending: map[int64]p2p.NodeID{1: "P1"}, pendingTime: map[int64]time.Time{1: now}, }, args: args{peerID: "P1", height: 2, tm: now.Add(time.Millisecond)}, wantFields: scTestParams{ peers: map[string]*scPeer{"P1": {height: 2, state: peerStateReady}}, allB: []int64{1, 2}, - pending: map[int64]p2p.ID{1: "P1", 2: "P1"}, + pending: map[int64]p2p.NodeID{1: "P1", 2: "P1"}, pendingTime: map[int64]time.Time{1: now, 2: now.Add(time.Millisecond)}, }, }, @@ -851,7 +851,7 @@ func TestScMarkReceived(t *testing.T) { now := time.Now() type args struct { - peerID p2p.ID + peerID p2p.NodeID height int64 size int64 tm time.Time @@ -891,7 +891,7 @@ func TestScMarkReceived(t *testing.T) { "P2": {height: 4, state: peerStateReady}, }, allB: []int64{1, 2, 3, 4}, - pending: map[int64]p2p.ID{1: "P1", 2: "P2", 3: "P2", 4: "P1"}, + pending: map[int64]p2p.NodeID{1: "P1", 2: "P2", 3: "P2", 4: "P1"}, }, args: args{peerID: "P1", height: 2, size: 1000, tm: now}, wantFields: scTestParams{ @@ -900,7 +900,7 @@ func TestScMarkReceived(t *testing.T) { "P2": {height: 4, state: peerStateReady}, }, allB: []int64{1, 2, 3, 4}, - pending: map[int64]p2p.ID{1: "P1", 2: "P2", 3: "P2", 4: "P1"}, + pending: map[int64]p2p.NodeID{1: "P1", 2: "P2", 3: "P2", 4: "P1"}, }, wantErr: true, }, @@ -909,13 +909,13 @@ func TestScMarkReceived(t *testing.T) { fields: scTestParams{ peers: map[string]*scPeer{"P1": {height: 4, state: peerStateReady}}, allB: []int64{1, 2, 3, 4}, - pending: map[int64]p2p.ID{}, + pending: map[int64]p2p.NodeID{}, }, args: args{peerID: "P1", height: 2, size: 1000, tm: now}, wantFields: scTestParams{ peers: map[string]*scPeer{"P1": {height: 4, state: peerStateReady}}, allB: []int64{1, 2, 3, 4}, - pending: map[int64]p2p.ID{}, + pending: map[int64]p2p.NodeID{}, }, wantErr: true, }, @@ -924,14 +924,14 @@ func TestScMarkReceived(t *testing.T) { fields: scTestParams{ peers: map[string]*scPeer{"P1": {height: 2, state: peerStateReady}}, allB: []int64{1, 2}, - pending: map[int64]p2p.ID{1: "P1", 2: "P1"}, + pending: map[int64]p2p.NodeID{1: "P1", 2: "P1"}, pendingTime: map[int64]time.Time{1: now, 2: now.Add(time.Second)}, }, args: args{peerID: "P1", height: 2, size: 1000, tm: now}, wantFields: scTestParams{ peers: map[string]*scPeer{"P1": {height: 2, state: peerStateReady}}, allB: []int64{1, 2}, - pending: map[int64]p2p.ID{1: "P1", 2: "P1"}, + pending: map[int64]p2p.NodeID{1: "P1", 2: "P1"}, pendingTime: map[int64]time.Time{1: now, 2: now.Add(time.Second)}, }, wantErr: true, @@ -941,16 +941,16 @@ func TestScMarkReceived(t *testing.T) { fields: scTestParams{ peers: map[string]*scPeer{"P1": {height: 2, state: peerStateReady}}, allB: []int64{1, 2}, - pending: map[int64]p2p.ID{1: "P1", 2: "P1"}, + pending: map[int64]p2p.NodeID{1: "P1", 2: "P1"}, pendingTime: map[int64]time.Time{1: now, 2: now}, }, args: args{peerID: "P1", height: 2, size: 1000, tm: now.Add(time.Millisecond)}, wantFields: scTestParams{ peers: map[string]*scPeer{"P1": {height: 2, state: peerStateReady}}, allB: []int64{1, 2}, - pending: map[int64]p2p.ID{1: "P1"}, + pending: map[int64]p2p.NodeID{1: "P1"}, pendingTime: map[int64]time.Time{1: now}, - received: map[int64]p2p.ID{2: "P1"}, + received: map[int64]p2p.NodeID{2: "P1"}, }, }, } @@ -991,7 +991,7 @@ func TestScMarkProcessed(t *testing.T) { height: 2, peers: map[string]*scPeer{"P1": {height: 4, state: peerStateReady}}, allB: []int64{2}, - pending: map[int64]p2p.ID{2: "P1"}, + pending: map[int64]p2p.NodeID{2: "P1"}, pendingTime: map[int64]time.Time{2: now}, targetPending: 1, }, @@ -1009,15 +1009,15 @@ func TestScMarkProcessed(t *testing.T) { height: 1, peers: map[string]*scPeer{"P1": {height: 2, state: peerStateReady}}, allB: []int64{1, 2}, - pending: map[int64]p2p.ID{2: "P1"}, + pending: map[int64]p2p.NodeID{2: "P1"}, pendingTime: map[int64]time.Time{2: now}, - received: map[int64]p2p.ID{1: "P1"}}, + received: map[int64]p2p.NodeID{1: "P1"}}, args: args{height: 1}, wantFields: scTestParams{ height: 2, peers: map[string]*scPeer{"P1": {height: 2, state: peerStateReady}}, allB: []int64{2}, - pending: map[int64]p2p.ID{2: "P1"}, + pending: map[int64]p2p.NodeID{2: "P1"}, pendingTime: map[int64]time.Time{2: now}}, }, } @@ -1101,7 +1101,7 @@ func TestScAllBlocksProcessed(t *testing.T) { fields: scTestParams{ peers: map[string]*scPeer{"P1": {height: 4, state: peerStateReady}}, allB: []int64{1, 2, 3, 4}, - pending: map[int64]p2p.ID{1: "P1", 2: "P1", 3: "P1", 4: "P1"}, + pending: map[int64]p2p.NodeID{1: "P1", 2: "P1", 3: "P1", 4: "P1"}, pendingTime: map[int64]time.Time{1: now, 2: now, 3: now, 4: now}, }, wantResult: false, @@ -1111,7 +1111,7 @@ func TestScAllBlocksProcessed(t *testing.T) { fields: scTestParams{ peers: map[string]*scPeer{"P1": {height: 4, state: peerStateReady}}, allB: []int64{1, 2, 3, 4}, - received: map[int64]p2p.ID{1: "P1", 2: "P1", 3: "P1", 4: "P1"}, + received: map[int64]p2p.NodeID{1: "P1", 2: "P1", 3: "P1", 4: "P1"}, }, wantResult: false, }, @@ -1122,7 +1122,7 @@ func TestScAllBlocksProcessed(t *testing.T) { peers: map[string]*scPeer{ "P1": {height: 4, state: peerStateReady}}, allB: []int64{4}, - received: map[int64]p2p.ID{4: "P1"}, + received: map[int64]p2p.NodeID{4: "P1"}, }, wantResult: true, }, @@ -1131,7 +1131,7 @@ func TestScAllBlocksProcessed(t *testing.T) { fields: scTestParams{ peers: map[string]*scPeer{"P1": {height: 4, state: peerStateReady}}, allB: []int64{1, 2, 3, 4}, - pending: map[int64]p2p.ID{2: "P1", 4: "P1"}, + pending: map[int64]p2p.NodeID{2: "P1", 4: "P1"}, pendingTime: map[int64]time.Time{2: now, 4: now}, }, wantResult: false, @@ -1179,7 +1179,7 @@ func TestScNextHeightToSchedule(t *testing.T) { initHeight: 1, peers: map[string]*scPeer{"P1": {height: 4, state: peerStateReady}}, allB: []int64{1, 2, 3, 4}, - pending: map[int64]p2p.ID{1: "P1", 2: "P1", 3: "P1", 4: "P1"}, + pending: map[int64]p2p.NodeID{1: "P1", 2: "P1", 3: "P1", 4: "P1"}, pendingTime: map[int64]time.Time{1: now, 2: now, 3: now, 4: now}, }, wantHeight: -1, @@ -1190,7 +1190,7 @@ func TestScNextHeightToSchedule(t *testing.T) { initHeight: 1, peers: map[string]*scPeer{"P1": {height: 4, state: peerStateReady}}, allB: []int64{1, 2, 3, 4}, - received: map[int64]p2p.ID{1: "P1", 2: "P1", 3: "P1", 4: "P1"}, + received: map[int64]p2p.NodeID{1: "P1", 2: "P1", 3: "P1", 4: "P1"}, }, wantHeight: -1, }, @@ -1209,7 +1209,7 @@ func TestScNextHeightToSchedule(t *testing.T) { initHeight: 1, peers: map[string]*scPeer{"P1": {height: 4, state: peerStateReady}}, allB: []int64{1, 2, 3, 4}, - pending: map[int64]p2p.ID{2: "P1"}, + pending: map[int64]p2p.NodeID{2: "P1"}, pendingTime: map[int64]time.Time{2: now}, }, wantHeight: 1, @@ -1239,7 +1239,7 @@ func TestScSelectPeer(t *testing.T) { name string fields scTestParams args args - wantResult p2p.ID + wantResult p2p.NodeID wantError bool }{ { @@ -1307,7 +1307,7 @@ func TestScSelectPeer(t *testing.T) { "P1": {height: 8, state: peerStateReady}, "P2": {height: 9, state: peerStateReady}}, allB: []int64{4, 5, 6, 7, 8, 9}, - pending: map[int64]p2p.ID{ + pending: map[int64]p2p.NodeID{ 4: "P1", 6: "P1", 5: "P2", }, @@ -1323,7 +1323,7 @@ func TestScSelectPeer(t *testing.T) { "P1": {height: 15, state: peerStateReady}, "P3": {height: 15, state: peerStateReady}}, allB: []int64{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, - pending: map[int64]p2p.ID{ + pending: map[int64]p2p.NodeID{ 1: "P1", 2: "P1", 3: "P3", 4: "P3", 5: "P2", 6: "P2", @@ -1392,7 +1392,7 @@ func TestScHandleBlockResponse(t *testing.T) { now := time.Now() block6FromP1 := bcBlockResponse{ time: now.Add(time.Millisecond), - peerID: p2p.ID("P1"), + peerID: p2p.NodeID("P1"), size: 100, block: makeScBlock(6), } @@ -1433,7 +1433,7 @@ func TestScHandleBlockResponse(t *testing.T) { fields: scTestParams{ peers: map[string]*scPeer{"P2": {height: 8, state: peerStateReady}}, allB: []int64{1, 2, 3, 4, 5, 6, 7, 8}, - pending: map[int64]p2p.ID{6: "P2"}, + pending: map[int64]p2p.NodeID{6: "P2"}, pendingTime: map[int64]time.Time{6: now}, }, args: args{event: block6FromP1}, @@ -1444,7 +1444,7 @@ func TestScHandleBlockResponse(t *testing.T) { fields: scTestParams{ peers: map[string]*scPeer{"P1": {height: 8, state: peerStateReady}}, allB: []int64{1, 2, 3, 4, 5, 6, 7, 8}, - pending: map[int64]p2p.ID{6: "P1"}, + pending: map[int64]p2p.NodeID{6: "P1"}, pendingTime: map[int64]time.Time{6: now.Add(time.Second)}, }, args: args{event: block6FromP1}, @@ -1455,7 +1455,7 @@ func TestScHandleBlockResponse(t *testing.T) { fields: scTestParams{ peers: map[string]*scPeer{"P1": {height: 8, state: peerStateReady}}, allB: []int64{1, 2, 3, 4, 5, 6, 7, 8}, - pending: map[int64]p2p.ID{6: "P1"}, + pending: map[int64]p2p.NodeID{6: "P1"}, pendingTime: map[int64]time.Time{6: now}, }, args: args{event: block6FromP1}, @@ -1477,7 +1477,7 @@ func TestScHandleNoBlockResponse(t *testing.T) { now := time.Now() noBlock6FromP1 := bcNoBlockResponse{ time: now.Add(time.Millisecond), - peerID: p2p.ID("P1"), + peerID: p2p.NodeID("P1"), height: 6, } @@ -1513,14 +1513,14 @@ func TestScHandleNoBlockResponse(t *testing.T) { fields: scTestParams{ peers: map[string]*scPeer{"P2": {height: 8, state: peerStateReady}}, allB: []int64{1, 2, 3, 4, 5, 6, 7, 8}, - pending: map[int64]p2p.ID{6: "P2"}, + pending: map[int64]p2p.NodeID{6: "P2"}, pendingTime: map[int64]time.Time{6: now}, }, wantEvent: noOpEvent{}, wantFields: scTestParams{ peers: map[string]*scPeer{"P2": {height: 8, state: peerStateReady}}, allB: []int64{1, 2, 3, 4, 5, 6, 7, 8}, - pending: map[int64]p2p.ID{6: "P2"}, + pending: map[int64]p2p.NodeID{6: "P2"}, pendingTime: map[int64]time.Time{6: now}, }, }, @@ -1529,7 +1529,7 @@ func TestScHandleNoBlockResponse(t *testing.T) { fields: scTestParams{ peers: map[string]*scPeer{"P1": {height: 8, state: peerStateReady}}, allB: []int64{1, 2, 3, 4, 5, 6, 7, 8}, - pending: map[int64]p2p.ID{6: "P1"}, + pending: map[int64]p2p.NodeID{6: "P1"}, pendingTime: map[int64]time.Time{6: now}, }, wantEvent: scPeerError{peerID: "P1", reason: fmt.Errorf("some error")}, @@ -1552,7 +1552,7 @@ func TestScHandleNoBlockResponse(t *testing.T) { func TestScHandleBlockProcessed(t *testing.T) { now := time.Now() processed6FromP1 := pcBlockProcessed{ - peerID: p2p.ID("P1"), + peerID: p2p.NodeID("P1"), height: 6, } @@ -1579,7 +1579,7 @@ func TestScHandleBlockProcessed(t *testing.T) { initHeight: 6, peers: map[string]*scPeer{"P1": {height: 8, state: peerStateReady}}, allB: []int64{6, 7, 8}, - pending: map[int64]p2p.ID{6: "P1"}, + pending: map[int64]p2p.NodeID{6: "P1"}, pendingTime: map[int64]time.Time{6: now}, }, args: args{event: processed6FromP1}, @@ -1591,7 +1591,7 @@ func TestScHandleBlockProcessed(t *testing.T) { initHeight: 6, peers: map[string]*scPeer{"P1": {height: 7, state: peerStateReady}}, allB: []int64{6, 7}, - received: map[int64]p2p.ID{6: "P1", 7: "P1"}, + received: map[int64]p2p.NodeID{6: "P1", 7: "P1"}, }, args: args{event: processed6FromP1}, wantEvent: scFinishedEv{}, @@ -1602,8 +1602,8 @@ func TestScHandleBlockProcessed(t *testing.T) { initHeight: 6, peers: map[string]*scPeer{"P1": {height: 8, state: peerStateReady}}, allB: []int64{6, 7, 8}, - pending: map[int64]p2p.ID{7: "P1", 8: "P1"}, - received: map[int64]p2p.ID{6: "P1"}, + pending: map[int64]p2p.NodeID{7: "P1", 8: "P1"}, + received: map[int64]p2p.NodeID{6: "P1"}, }, args: args{event: processed6FromP1}, wantEvent: noOpEvent{}, @@ -1646,7 +1646,7 @@ func TestScHandleBlockVerificationFailure(t *testing.T) { initHeight: 6, peers: map[string]*scPeer{"P1": {height: 8, state: peerStateReady}}, allB: []int64{6, 7, 8}, - pending: map[int64]p2p.ID{6: "P1"}, + pending: map[int64]p2p.NodeID{6: "P1"}, pendingTime: map[int64]time.Time{6: now}, }, args: args{event: pcBlockVerificationFailure{height: 10, firstPeerID: "P1", secondPeerID: "P1"}}, @@ -1658,7 +1658,7 @@ func TestScHandleBlockVerificationFailure(t *testing.T) { initHeight: 6, peers: map[string]*scPeer{"P1": {height: 8, state: peerStateReady}, "P2": {height: 8, state: peerStateReady}}, allB: []int64{6, 7, 8}, - pending: map[int64]p2p.ID{6: "P1"}, + pending: map[int64]p2p.NodeID{6: "P1"}, pendingTime: map[int64]time.Time{6: now}, }, args: args{event: pcBlockVerificationFailure{height: 10, firstPeerID: "P1", secondPeerID: "P1"}}, @@ -1670,7 +1670,7 @@ func TestScHandleBlockVerificationFailure(t *testing.T) { initHeight: 6, peers: map[string]*scPeer{"P1": {height: 7, state: peerStateReady}}, allB: []int64{6, 7}, - received: map[int64]p2p.ID{6: "P1", 7: "P1"}, + received: map[int64]p2p.NodeID{6: "P1", 7: "P1"}, }, args: args{event: pcBlockVerificationFailure{height: 7, firstPeerID: "P1", secondPeerID: "P1"}}, wantEvent: scFinishedEv{}, @@ -1681,8 +1681,8 @@ func TestScHandleBlockVerificationFailure(t *testing.T) { initHeight: 5, peers: map[string]*scPeer{"P1": {height: 8, state: peerStateReady}, "P2": {height: 8, state: peerStateReady}}, allB: []int64{5, 6, 7, 8}, - pending: map[int64]p2p.ID{7: "P1", 8: "P1"}, - received: map[int64]p2p.ID{5: "P1", 6: "P1"}, + pending: map[int64]p2p.NodeID{7: "P1", 8: "P1"}, + received: map[int64]p2p.NodeID{5: "P1", 6: "P1"}, }, args: args{event: pcBlockVerificationFailure{height: 5, firstPeerID: "P1", secondPeerID: "P1"}}, wantEvent: noOpEvent{}, @@ -1697,8 +1697,8 @@ func TestScHandleBlockVerificationFailure(t *testing.T) { "P3": {height: 8, state: peerStateReady}, }, allB: []int64{5, 6, 7, 8}, - pending: map[int64]p2p.ID{7: "P1", 8: "P1"}, - received: map[int64]p2p.ID{5: "P1", 6: "P1"}, + pending: map[int64]p2p.NodeID{7: "P1", 8: "P1"}, + received: map[int64]p2p.NodeID{5: "P1", 6: "P1"}, }, args: args{event: pcBlockVerificationFailure{height: 5, firstPeerID: "P1", secondPeerID: "P2"}}, wantEvent: noOpEvent{}, @@ -1717,7 +1717,7 @@ func TestScHandleBlockVerificationFailure(t *testing.T) { func TestScHandleAddNewPeer(t *testing.T) { addP1 := bcAddNewPeer{ - peerID: p2p.ID("P1"), + peerID: p2p.NodeID("P1"), } type args struct { event bcAddNewPeer @@ -1828,7 +1828,7 @@ func TestScHandleTryPrunePeer(t *testing.T) { allB: []int64{1, 2, 3, 4, 5, 6, 7}, peerTimeout: time.Second}, args: args{event: pruneEv}, - wantEvent: scPeersPruned{peers: []p2p.ID{"P4", "P5", "P6"}}, + wantEvent: scPeersPruned{peers: []p2p.NodeID{"P4", "P5", "P6"}}, }, { name: "mixed peers, finish after pruning", @@ -1926,7 +1926,7 @@ func TestScHandleTrySchedule(t *testing.T) { "P1": {height: 4, state: peerStateReady}, "P2": {height: 5, state: peerStateReady}}, allB: []int64{1, 2, 3, 4, 5}, - pending: map[int64]p2p.ID{ + pending: map[int64]p2p.NodeID{ 1: "P1", 2: "P1", 3: "P2", }, @@ -1944,7 +1944,7 @@ func TestScHandleTrySchedule(t *testing.T) { "P1": {height: 8, state: peerStateReady}, "P3": {height: 8, state: peerStateReady}}, allB: []int64{1, 2, 3, 4, 5, 6, 7, 8}, - pending: map[int64]p2p.ID{ + pending: map[int64]p2p.NodeID{ 1: "P1", 2: "P1", 3: "P3", 4: "P3", 5: "P2", 6: "P2", @@ -2106,7 +2106,7 @@ func TestScHandle(t *testing.T) { startTime: now, peers: map[string]*scPeer{"P1": {height: 3, state: peerStateReady}}, allB: []int64{1, 2, 3}, - pending: map[int64]p2p.ID{1: "P1"}, + pending: map[int64]p2p.NodeID{1: "P1"}, pendingTime: map[int64]time.Time{1: tick[1]}, height: 1, }, @@ -2118,7 +2118,7 @@ func TestScHandle(t *testing.T) { startTime: now, peers: map[string]*scPeer{"P1": {height: 3, state: peerStateReady}}, allB: []int64{1, 2, 3}, - pending: map[int64]p2p.ID{1: "P1", 2: "P1"}, + pending: map[int64]p2p.NodeID{1: "P1", 2: "P1"}, pendingTime: map[int64]time.Time{1: tick[1], 2: tick[2]}, height: 1, }, @@ -2130,7 +2130,7 @@ func TestScHandle(t *testing.T) { startTime: now, peers: map[string]*scPeer{"P1": {height: 3, state: peerStateReady}}, allB: []int64{1, 2, 3}, - pending: map[int64]p2p.ID{1: "P1", 2: "P1", 3: "P1"}, + pending: map[int64]p2p.NodeID{1: "P1", 2: "P1", 3: "P1"}, pendingTime: map[int64]time.Time{1: tick[1], 2: tick[2], 3: tick[3]}, height: 1, }, @@ -2142,9 +2142,9 @@ func TestScHandle(t *testing.T) { startTime: now, peers: map[string]*scPeer{"P1": {height: 3, state: peerStateReady, lastTouched: tick[4]}}, allB: []int64{1, 2, 3}, - pending: map[int64]p2p.ID{2: "P1", 3: "P1"}, + pending: map[int64]p2p.NodeID{2: "P1", 3: "P1"}, pendingTime: map[int64]time.Time{2: tick[2], 3: tick[3]}, - received: map[int64]p2p.ID{1: "P1"}, + received: map[int64]p2p.NodeID{1: "P1"}, height: 1, }, }, @@ -2155,9 +2155,9 @@ func TestScHandle(t *testing.T) { startTime: now, peers: map[string]*scPeer{"P1": {height: 3, state: peerStateReady, lastTouched: tick[5]}}, allB: []int64{1, 2, 3}, - pending: map[int64]p2p.ID{3: "P1"}, + pending: map[int64]p2p.NodeID{3: "P1"}, pendingTime: map[int64]time.Time{3: tick[3]}, - received: map[int64]p2p.ID{1: "P1", 2: "P1"}, + received: map[int64]p2p.NodeID{1: "P1", 2: "P1"}, height: 1, }, }, @@ -2168,29 +2168,29 @@ func TestScHandle(t *testing.T) { startTime: now, peers: map[string]*scPeer{"P1": {height: 3, state: peerStateReady, lastTouched: tick[6]}}, allB: []int64{1, 2, 3}, - received: map[int64]p2p.ID{1: "P1", 2: "P1", 3: "P1"}, + received: map[int64]p2p.NodeID{1: "P1", 2: "P1", 3: "P1"}, height: 1, }, }, { // processed block 1 - args: args{event: pcBlockProcessed{peerID: p2p.ID("P1"), height: 1}}, + args: args{event: pcBlockProcessed{peerID: p2p.NodeID("P1"), height: 1}}, wantEvent: noOpEvent{}, wantSc: &scTestParams{ startTime: now, peers: map[string]*scPeer{"P1": {height: 3, state: peerStateReady, lastTouched: tick[6]}}, allB: []int64{2, 3}, - received: map[int64]p2p.ID{2: "P1", 3: "P1"}, + received: map[int64]p2p.NodeID{2: "P1", 3: "P1"}, height: 2, }, }, { // processed block 2 - args: args{event: pcBlockProcessed{peerID: p2p.ID("P1"), height: 2}}, + args: args{event: pcBlockProcessed{peerID: p2p.NodeID("P1"), height: 2}}, wantEvent: scFinishedEv{}, wantSc: &scTestParams{ startTime: now, peers: map[string]*scPeer{"P1": {height: 3, state: peerStateReady, lastTouched: tick[6]}}, allB: []int64{3}, - received: map[int64]p2p.ID{3: "P1"}, + received: map[int64]p2p.NodeID{3: "P1"}, height: 3, }, }, @@ -2206,7 +2206,7 @@ func TestScHandle(t *testing.T) { "P1": {height: 4, state: peerStateReady, lastTouched: tick[6]}, "P2": {height: 3, state: peerStateReady, lastTouched: tick[6]}}, allB: []int64{1, 2, 3, 4}, - received: map[int64]p2p.ID{1: "P1", 2: "P1", 3: "P1"}, + received: map[int64]p2p.NodeID{1: "P1", 2: "P1", 3: "P1"}, height: 1, }, args: args{event: pcBlockVerificationFailure{height: 1, firstPeerID: "P1", secondPeerID: "P1"}}, @@ -2217,7 +2217,7 @@ func TestScHandle(t *testing.T) { "P1": {height: 4, state: peerStateRemoved, lastTouched: tick[6]}, "P2": {height: 3, state: peerStateReady, lastTouched: tick[6]}}, allB: []int64{1, 2, 3}, - received: map[int64]p2p.ID{}, + received: map[int64]p2p.NodeID{}, height: 1, }, }, diff --git a/consensus/msgs.go b/consensus/msgs.go index 91c091ba1..65bf81aa0 100644 --- a/consensus/msgs.go +++ b/consensus/msgs.go @@ -358,7 +358,7 @@ func WALFromProto(msg *tmcons.WALMessage) (WALMessage, error) { } pb = msgInfo{ Msg: walMsg, - PeerID: p2p.ID(msg.MsgInfo.PeerID), + PeerID: p2p.NodeID(msg.MsgInfo.PeerID), } case *tmcons.WALMessage_TimeoutInfo: diff --git a/consensus/msgs_test.go b/consensus/msgs_test.go index b1f32e67d..52aea7e27 100644 --- a/consensus/msgs_test.go +++ b/consensus/msgs_test.go @@ -249,7 +249,7 @@ func TestWALMsgProto(t *testing.T) { Round: 1, Part: &parts, }, - PeerID: p2p.ID("string"), + PeerID: p2p.NodeID("string"), }, &tmcons.WALMessage{ Sum: &tmcons.WALMessage_MsgInfo{ MsgInfo: &tmcons.MsgInfo{ diff --git a/consensus/state.go b/consensus/state.go index 045c5dd53..b542ae6c7 100644 --- a/consensus/state.go +++ b/consensus/state.go @@ -50,8 +50,8 @@ var ( // msgs from the reactor which may update the state type msgInfo struct { - Msg Message `json:"msg"` - PeerID p2p.ID `json:"peer_key"` + Msg Message `json:"msg"` + PeerID p2p.NodeID `json:"peer_key"` } // internally generated messages which may update the state @@ -449,7 +449,7 @@ func (cs *State) OpenWAL(walFile string) (WAL, error) { // TODO: should these return anything or let callers just use events? // AddVote inputs a vote. -func (cs *State) AddVote(vote *types.Vote, peerID p2p.ID) (added bool, err error) { +func (cs *State) AddVote(vote *types.Vote, peerID p2p.NodeID) (added bool, err error) { if peerID == "" { cs.internalMsgQueue <- msgInfo{&VoteMessage{vote}, ""} } else { @@ -461,7 +461,7 @@ func (cs *State) AddVote(vote *types.Vote, peerID p2p.ID) (added bool, err error } // SetProposal inputs a proposal. -func (cs *State) SetProposal(proposal *types.Proposal, peerID p2p.ID) error { +func (cs *State) SetProposal(proposal *types.Proposal, peerID p2p.NodeID) error { if peerID == "" { cs.internalMsgQueue <- msgInfo{&ProposalMessage{proposal}, ""} @@ -474,7 +474,7 @@ func (cs *State) SetProposal(proposal *types.Proposal, peerID p2p.ID) error { } // AddProposalBlockPart inputs a part of the proposal block. -func (cs *State) AddProposalBlockPart(height int64, round int32, part *types.Part, peerID p2p.ID) error { +func (cs *State) AddProposalBlockPart(height int64, round int32, part *types.Part, peerID p2p.NodeID) error { if peerID == "" { cs.internalMsgQueue <- msgInfo{&BlockPartMessage{height, round, part}, ""} @@ -491,7 +491,7 @@ func (cs *State) SetProposalAndBlock( proposal *types.Proposal, block *types.Block, parts *types.PartSet, - peerID p2p.ID, + peerID p2p.NodeID, ) error { if err := cs.SetProposal(proposal, peerID); err != nil { return err @@ -1757,7 +1757,7 @@ func (cs *State) defaultSetProposal(proposal *types.Proposal) error { // NOTE: block is not necessarily valid. // Asynchronously triggers either enterPrevote (before we timeout of propose) or tryFinalizeCommit, // once we have the full block. -func (cs *State) addProposalBlockPart(msg *BlockPartMessage, peerID p2p.ID) (added bool, err error) { +func (cs *State) addProposalBlockPart(msg *BlockPartMessage, peerID p2p.NodeID) (added bool, err error) { height, round, part := msg.Height, msg.Round, msg.Part // Blocks might be reused, so round mismatch is OK @@ -1842,7 +1842,7 @@ func (cs *State) addProposalBlockPart(msg *BlockPartMessage, peerID p2p.ID) (add } // Attempt to add the vote. if its a duplicate signature, dupeout the validator -func (cs *State) tryAddVote(vote *types.Vote, peerID p2p.ID) (bool, error) { +func (cs *State) tryAddVote(vote *types.Vote, peerID p2p.NodeID) (bool, error) { added, err := cs.addVote(vote, peerID) if err != nil { // If the vote height is off, we'll just ignore it, @@ -1900,7 +1900,7 @@ func (cs *State) tryAddVote(vote *types.Vote, peerID p2p.ID) (bool, error) { func (cs *State) addVote( vote *types.Vote, - peerID p2p.ID) (added bool, err error) { + peerID p2p.NodeID) (added bool, err error) { cs.Logger.Debug( "addVote", "voteHeight", diff --git a/consensus/types/height_vote_set.go b/consensus/types/height_vote_set.go index 6a5c0b495..a9d65a457 100644 --- a/consensus/types/height_vote_set.go +++ b/consensus/types/height_vote_set.go @@ -46,7 +46,7 @@ type HeightVoteSet struct { mtx sync.Mutex round int32 // max tracked round roundVoteSets map[int32]RoundVoteSet // keys: [0...round] - peerCatchupRounds map[p2p.ID][]int32 // keys: peer.ID; values: at most 2 rounds + peerCatchupRounds map[p2p.NodeID][]int32 // keys: peer.ID; values: at most 2 rounds } func NewHeightVoteSet(chainID string, height int64, valSet *types.ValidatorSet) *HeightVoteSet { @@ -64,7 +64,7 @@ func (hvs *HeightVoteSet) Reset(height int64, valSet *types.ValidatorSet) { hvs.height = height hvs.valSet = valSet hvs.roundVoteSets = make(map[int32]RoundVoteSet) - hvs.peerCatchupRounds = make(map[p2p.ID][]int32) + hvs.peerCatchupRounds = make(map[p2p.NodeID][]int32) hvs.addRound(0) hvs.round = 0 @@ -114,7 +114,7 @@ func (hvs *HeightVoteSet) addRound(round int32) { // Duplicate votes return added=false, err=nil. // By convention, peerID is "" if origin is self. -func (hvs *HeightVoteSet) AddVote(vote *types.Vote, peerID p2p.ID) (added bool, err error) { +func (hvs *HeightVoteSet) AddVote(vote *types.Vote, peerID p2p.NodeID) (added bool, err error) { hvs.mtx.Lock() defer hvs.mtx.Unlock() if !types.IsVoteTypeValid(vote.Type) { @@ -185,7 +185,7 @@ func (hvs *HeightVoteSet) getVoteSet(round int32, voteType tmproto.SignedMsgType func (hvs *HeightVoteSet) SetPeerMaj23( round int32, voteType tmproto.SignedMsgType, - peerID p2p.ID, + peerID p2p.NodeID, blockID types.BlockID) error { hvs.mtx.Lock() defer hvs.mtx.Unlock() diff --git a/mempool/clist_mempool.go b/mempool/clist_mempool.go index 892590b6c..5e610ed4b 100644 --- a/mempool/clist_mempool.go +++ b/mempool/clist_mempool.go @@ -334,7 +334,7 @@ func (mem *CListMempool) globalCb(req *abci.Request, res *abci.Response) { func (mem *CListMempool) reqResCb( tx []byte, peerID uint16, - peerP2PID p2p.ID, + peerP2PID p2p.NodeID, externalCb func(*abci.Response), ) func(res *abci.Response) { return func(res *abci.Response) { @@ -411,7 +411,7 @@ func (mem *CListMempool) isFull(txSize int) error { func (mem *CListMempool) resCbFirstTime( tx []byte, peerID uint16, - peerP2PID p2p.ID, + peerP2PID p2p.NodeID, res *abci.Response, ) { switch r := res.Value.(type) { diff --git a/mempool/mempool.go b/mempool/mempool.go index f6ce722b6..b7a315d30 100644 --- a/mempool/mempool.go +++ b/mempool/mempool.go @@ -98,7 +98,7 @@ type TxInfo struct { // sender, storing 2 bytes with each tx instead of 20 bytes for the p2p.ID. SenderID uint16 // SenderP2PID is the actual p2p.ID of the sender, used e.g. for logging. - SenderP2PID p2p.ID + SenderP2PID p2p.NodeID // Context is the optional context to cancel CheckTx Context context.Context } diff --git a/mempool/reactor.go b/mempool/reactor.go index da5d330f0..e969aeb69 100644 --- a/mempool/reactor.go +++ b/mempool/reactor.go @@ -39,7 +39,7 @@ type Reactor struct { type mempoolIDs struct { mtx tmsync.RWMutex - peerMap map[p2p.ID]uint16 + peerMap map[p2p.NodeID]uint16 nextID uint16 // assumes that a node will never have over 65536 active peers activeIDs map[uint16]struct{} // used to check if a given peerID key is used, the value doesn't matter } @@ -94,7 +94,7 @@ func (ids *mempoolIDs) GetForPeer(peer p2p.Peer) uint16 { func newMempoolIDs() *mempoolIDs { return &mempoolIDs{ - peerMap: make(map[p2p.ID]uint16), + peerMap: make(map[p2p.NodeID]uint16), activeIDs: map[uint16]struct{}{0: {}}, nextID: 1, // reserve unknownPeerID(0) for mempoolReactor.BroadcastTx } diff --git a/p2p/errors.go b/p2p/errors.go index 3650a7a0a..9300fee0f 100644 --- a/p2p/errors.go +++ b/p2p/errors.go @@ -18,7 +18,7 @@ type ErrRejected struct { addr NetAddress conn net.Conn err error - id ID + id NodeID isAuthFailure bool isDuplicate bool isFiltered bool @@ -99,7 +99,7 @@ func (e ErrRejected) IsSelf() bool { return e.isSelf } // ErrSwitchDuplicatePeerID to be raised when a peer is connecting with a known // ID. type ErrSwitchDuplicatePeerID struct { - ID ID + ID NodeID } func (e ErrSwitchDuplicatePeerID) Error() string { @@ -127,7 +127,7 @@ func (e ErrSwitchConnectToSelf) Error() string { type ErrSwitchAuthenticationFailure struct { Dialed *NetAddress - Got ID + Got NodeID } func (e ErrSwitchAuthenticationFailure) Error() string { diff --git a/p2p/key.go b/p2p/key.go index 4693430f5..d970794d4 100644 --- a/p2p/key.go +++ b/p2p/key.go @@ -10,12 +10,12 @@ import ( tmos "github.com/tendermint/tendermint/libs/os" ) -// ID is a hex-encoded crypto.Address -type ID string +// NodeID is a hex-encoded crypto.Address. +type NodeID string -// IDByteLength is the length of a crypto.Address. Currently only 20. -// TODO: support other length addresses ? -const IDByteLength = crypto.AddressSize +// NodeIDByteLength is the length of a crypto.Address. Currently only 20. +// TODO: support other length addresses? +const NodeIDByteLength = crypto.AddressSize //------------------------------------------------------------------------------ // Persistent peer ID @@ -25,7 +25,7 @@ const IDByteLength = crypto.AddressSize // It contains the nodes private key for authentication. type NodeKey struct { // Canonical ID - hex-encoded pubkey's address (IDByteLength bytes) - ID ID `json:"id"` + ID NodeID `json:"id"` // Private key PrivKey crypto.PrivKey `json:"priv_key"` } @@ -50,8 +50,8 @@ func (nodeKey NodeKey) SaveAs(filePath string) error { // PubKeyToID returns the ID corresponding to the given PubKey. // It's the hex-encoding of the pubKey.Address(). -func PubKeyToID(pubKey crypto.PubKey) ID { - return ID(hex.EncodeToString(pubKey.Address())) +func PubKeyToID(pubKey crypto.PubKey) NodeID { + return NodeID(hex.EncodeToString(pubKey.Address())) } // LoadOrGenNodeKey attempts to load the NodeKey from the given filePath. If diff --git a/p2p/mock/peer.go b/p2p/mock/peer.go index 081b9e525..4a8988f47 100644 --- a/p2p/mock/peer.go +++ b/p2p/mock/peer.go @@ -11,7 +11,7 @@ import ( type Peer struct { *service.BaseService ip net.IP - id p2p.ID + id p2p.NodeID addr *p2p.NetAddress kv map[string]interface{} Outbound, Persistent bool @@ -51,7 +51,7 @@ func (mp *Peer) NodeInfo() p2p.NodeInfo { } } func (mp *Peer) Status() conn.ConnectionStatus { return conn.ConnectionStatus{} } -func (mp *Peer) ID() p2p.ID { return mp.id } +func (mp *Peer) ID() p2p.NodeID { return mp.id } func (mp *Peer) IsOutbound() bool { return mp.Outbound } func (mp *Peer) IsPersistent() bool { return mp.Persistent } func (mp *Peer) Get(key string) interface{} { diff --git a/p2p/mocks/peer.go b/p2p/mocks/peer.go index 704f965cd..85ef16995 100644 --- a/p2p/mocks/peer.go +++ b/p2p/mocks/peer.go @@ -54,14 +54,14 @@ func (_m *Peer) Get(_a0 string) interface{} { } // ID provides a mock function with given fields: -func (_m *Peer) ID() p2p.ID { +func (_m *Peer) ID() p2p.NodeID { ret := _m.Called() - var r0 p2p.ID - if rf, ok := ret.Get(0).(func() p2p.ID); ok { + var r0 p2p.NodeID + if rf, ok := ret.Get(0).(func() p2p.NodeID); ok { r0 = rf() } else { - r0 = ret.Get(0).(p2p.ID) + r0 = ret.Get(0).(p2p.NodeID) } return r0 diff --git a/p2p/netaddress.go b/p2p/netaddress.go index c14c3753a..5da34507c 100644 --- a/p2p/netaddress.go +++ b/p2p/netaddress.go @@ -23,14 +23,14 @@ const EmptyNetAddress = "" // NetAddress defines information about a peer on the network // including its ID, IP address, and port. type NetAddress struct { - ID ID `json:"id"` + ID NodeID `json:"id"` IP net.IP `json:"ip"` Port uint16 `json:"port"` } // IDAddressString returns id@hostPort. It strips the leading // protocol from protocolHostPort if it exists. -func IDAddressString(id ID, protocolHostPort string) string { +func IDAddressString(id NodeID, protocolHostPort string) string { hostPort := removeProtocolIfDefined(protocolHostPort) return fmt.Sprintf("%s@%s", id, hostPort) } @@ -40,7 +40,7 @@ func IDAddressString(id ID, protocolHostPort string) string { // using 0.0.0.0:0. When normal run, other net.Addr (except TCP) will // panic. Panics if ID is invalid. // TODO: socks proxies? -func NewNetAddress(id ID, addr net.Addr) *NetAddress { +func NewNetAddress(id NodeID, addr net.Addr) *NetAddress { tcpAddr, ok := addr.(*net.TCPAddr) if !ok { if flag.Lookup("test.v") == nil { // normal run @@ -75,11 +75,11 @@ func NewNetAddressString(addr string) (*NetAddress, error) { } // get ID - if err := validateID(ID(spl[0])); err != nil { + if err := validateID(NodeID(spl[0])); err != nil { return nil, ErrNetAddressInvalid{addrWithoutProtocol, err} } - var id ID - id, addrWithoutProtocol = ID(spl[0]), spl[1] + var id NodeID + id, addrWithoutProtocol = NodeID(spl[0]), spl[1] // get host and port host, portStr, err := net.SplitHostPort(addrWithoutProtocol) @@ -146,7 +146,7 @@ func NetAddressFromProto(pb tmp2p.NetAddress) (*NetAddress, error) { return nil, fmt.Errorf("invalid port number %v", pb.Port) } return &NetAddress{ - ID: ID(pb.ID), + ID: NodeID(pb.ID), IP: ip, Port: uint16(pb.Port), }, nil @@ -415,7 +415,7 @@ func removeProtocolIfDefined(addr string) string { } -func validateID(id ID) error { +func validateID(id NodeID) error { if len(id) == 0 { return errors.New("no ID") } @@ -423,8 +423,8 @@ func validateID(id ID) error { if err != nil { return err } - if len(idBytes) != IDByteLength { - return fmt.Errorf("invalid hex length - got %d, expected %d", len(idBytes), IDByteLength) + if len(idBytes) != NodeIDByteLength { + return fmt.Errorf("invalid hex length - got %d, expected %d", len(idBytes), NodeIDByteLength) } return nil } diff --git a/p2p/node_info.go b/p2p/node_info.go index ef3d3fe5f..6c1c8f81a 100644 --- a/p2p/node_info.go +++ b/p2p/node_info.go @@ -53,7 +53,7 @@ type NodeInfo struct { // Authenticate // TODO: replace with NetAddress - DefaultNodeID ID `json:"id"` // authenticated identifier + DefaultNodeID NodeID `json:"id"` // authenticated identifier ListenAddr string `json:"listen_addr"` // accepting incoming // Check compatibility. @@ -74,7 +74,7 @@ type NodeInfoOther struct { } // ID returns the node's peer ID. -func (info NodeInfo) ID() ID { +func (info NodeInfo) ID() NodeID { return info.DefaultNodeID } @@ -223,7 +223,7 @@ func NodeInfoFromProto(pb *tmp2p.NodeInfo) (NodeInfo, error) { Block: pb.ProtocolVersion.Block, App: pb.ProtocolVersion.App, }, - DefaultNodeID: ID(pb.DefaultNodeID), + DefaultNodeID: NodeID(pb.DefaultNodeID), ListenAddr: pb.ListenAddr, Network: pb.Network, Version: pb.Version, diff --git a/p2p/peer.go b/p2p/peer.go index 3ef8240c5..0d65dad39 100644 --- a/p2p/peer.go +++ b/p2p/peer.go @@ -154,7 +154,7 @@ type Peer interface { service.Service FlushStop() - ID() ID // peer's cryptographic ID + ID() NodeID // peer's cryptographic ID RemoteIP() net.IP // remote IP of the connection RemoteAddr() net.Addr // remote address of the connection @@ -193,7 +193,7 @@ func newPeerConn(outbound, persistent bool, conn Connection) peerConn { } // ID only exists for SecretConnection. -func (pc peerConn) ID() ID { +func (pc peerConn) ID() NodeID { return PubKeyToID(pc.conn.PubKey()) } @@ -339,7 +339,7 @@ func (p *peer) OnStop() { // Implements Peer // ID returns the peer's ID - the hex encoded hash of its pubkey. -func (p *peer) ID() ID { +func (p *peer) ID() NodeID { return p.nodeInfo.ID() } diff --git a/p2p/peer_set.go b/p2p/peer_set.go index 38dff7a9f..d2c8aedab 100644 --- a/p2p/peer_set.go +++ b/p2p/peer_set.go @@ -8,9 +8,9 @@ import ( // IPeerSet has a (immutable) subset of the methods of PeerSet. type IPeerSet interface { - Has(key ID) bool + Has(key NodeID) bool HasIP(ip net.IP) bool - Get(key ID) Peer + Get(key NodeID) Peer List() []Peer Size() int } @@ -21,7 +21,7 @@ type IPeerSet interface { // Iteration over the peers is super fast and thread-safe. type PeerSet struct { mtx tmsync.Mutex - lookup map[ID]*peerSetItem + lookup map[NodeID]*peerSetItem list []Peer } @@ -33,7 +33,7 @@ type peerSetItem struct { // NewPeerSet creates a new peerSet with a list of initial capacity of 256 items. func NewPeerSet() *PeerSet { return &PeerSet{ - lookup: make(map[ID]*peerSetItem), + lookup: make(map[NodeID]*peerSetItem), list: make([]Peer, 0, 256), } } @@ -58,7 +58,7 @@ func (ps *PeerSet) Add(peer Peer) error { // Has returns true if the set contains the peer referred to by this // peerKey, otherwise false. -func (ps *PeerSet) Has(peerKey ID) bool { +func (ps *PeerSet) Has(peerKey NodeID) bool { ps.mtx.Lock() _, ok := ps.lookup[peerKey] ps.mtx.Unlock() @@ -88,7 +88,7 @@ func (ps *PeerSet) hasIP(peerIP net.IP) bool { // Get looks up a peer by the provided peerKey. Returns nil if peer is not // found. -func (ps *PeerSet) Get(peerKey ID) Peer { +func (ps *PeerSet) Get(peerKey NodeID) Peer { ps.mtx.Lock() defer ps.mtx.Unlock() item, ok := ps.lookup[peerKey] diff --git a/p2p/peer_set_test.go b/p2p/peer_set_test.go index a962d9e7f..018e4f001 100644 --- a/p2p/peer_set_test.go +++ b/p2p/peer_set_test.go @@ -14,7 +14,7 @@ import ( type mockPeer struct { service.BaseService ip net.IP - id ID + id NodeID } func (mp *mockPeer) FlushStop() { mp.Stop() } //nolint:errcheck // ignore error @@ -22,7 +22,7 @@ func (mp *mockPeer) TrySend(chID byte, msgBytes []byte) bool { return true } func (mp *mockPeer) Send(chID byte, msgBytes []byte) bool { return true } func (mp *mockPeer) NodeInfo() NodeInfo { return NodeInfo{} } func (mp *mockPeer) Status() ConnectionStatus { return ConnectionStatus{} } -func (mp *mockPeer) ID() ID { return mp.id } +func (mp *mockPeer) ID() NodeID { return mp.id } func (mp *mockPeer) IsOutbound() bool { return false } func (mp *mockPeer) IsPersistent() bool { return true } func (mp *mockPeer) Get(s string) interface{} { return s } diff --git a/p2p/peer_test.go b/p2p/peer_test.go index 415176c91..0bfc0002f 100644 --- a/p2p/peer_test.go +++ b/p2p/peer_test.go @@ -198,7 +198,7 @@ func (rp *remotePeer) Addr() *NetAddress { return rp.addr } -func (rp *remotePeer) ID() ID { +func (rp *remotePeer) ID() NodeID { return PubKeyToID(rp.PrivKey.PubKey()) } diff --git a/p2p/pex/addrbook.go b/p2p/pex/addrbook.go index 6726d15aa..49daec014 100644 --- a/p2p/pex/addrbook.go +++ b/p2p/pex/addrbook.go @@ -60,7 +60,7 @@ type AddrBook interface { PickAddress(biasTowardsNewAddrs int) *p2p.NetAddress // Mark address - MarkGood(p2p.ID) + MarkGood(p2p.NodeID) MarkAttempt(*p2p.NetAddress) MarkBad(*p2p.NetAddress, time.Duration) // Move peer to bad peers list // Add bad peers back to addrBook @@ -91,9 +91,9 @@ type addrBook struct { mtx tmsync.Mutex rand *tmrand.Rand ourAddrs map[string]struct{} - privateIDs map[p2p.ID]struct{} - addrLookup map[p2p.ID]*knownAddress // new & old - badPeers map[p2p.ID]*knownAddress // blacklisted peers + privateIDs map[p2p.NodeID]struct{} + addrLookup map[p2p.NodeID]*knownAddress // new & old + badPeers map[p2p.NodeID]*knownAddress // blacklisted peers bucketsOld []map[string]*knownAddress bucketsNew []map[string]*knownAddress nOld int @@ -120,9 +120,9 @@ func NewAddrBook(filePath string, routabilityStrict bool) AddrBook { am := &addrBook{ rand: tmrand.NewRand(), ourAddrs: make(map[string]struct{}), - privateIDs: make(map[p2p.ID]struct{}), - addrLookup: make(map[p2p.ID]*knownAddress), - badPeers: make(map[p2p.ID]*knownAddress), + privateIDs: make(map[p2p.NodeID]struct{}), + addrLookup: make(map[p2p.NodeID]*knownAddress), + badPeers: make(map[p2p.NodeID]*knownAddress), filePath: filePath, routabilityStrict: routabilityStrict, hashKey: newHashKey(), @@ -201,7 +201,7 @@ func (a *addrBook) AddPrivateIDs(ids []string) { defer a.mtx.Unlock() for _, id := range ids { - a.privateIDs[p2p.ID(id)] = struct{}{} + a.privateIDs[p2p.NodeID(id)] = struct{}{} } } @@ -318,7 +318,7 @@ func (a *addrBook) PickAddress(biasTowardsNewAddrs int) *p2p.NetAddress { // MarkGood implements AddrBook - it marks the peer as good and // moves it into an "old" bucket. -func (a *addrBook) MarkGood(id p2p.ID) { +func (a *addrBook) MarkGood(id p2p.NodeID) { a.mtx.Lock() defer a.mtx.Unlock() diff --git a/p2p/pex/addrbook_test.go b/p2p/pex/addrbook_test.go index 21e098499..0f1b2b5c8 100644 --- a/p2p/pex/addrbook_test.go +++ b/p2p/pex/addrbook_test.go @@ -193,7 +193,7 @@ func randIPv4Address(t *testing.T) *p2p.NetAddress { tmrand.Intn(255), ) port := tmrand.Intn(65535-1) + 1 - id := p2p.ID(hex.EncodeToString(tmrand.Bytes(p2p.IDByteLength))) + id := p2p.NodeID(hex.EncodeToString(tmrand.Bytes(p2p.NodeIDByteLength))) idAddr := p2p.IDAddressString(id, fmt.Sprintf("%v:%v", ip, port)) addr, err := p2p.NewNetAddressString(idAddr) assert.Nil(t, err, "error generating rand network address") diff --git a/p2p/pex/known_address.go b/p2p/pex/known_address.go index e98a9e97e..e956f3e97 100644 --- a/p2p/pex/known_address.go +++ b/p2p/pex/known_address.go @@ -30,7 +30,7 @@ func newKnownAddress(addr *p2p.NetAddress, src *p2p.NetAddress) *knownAddress { } } -func (ka *knownAddress) ID() p2p.ID { +func (ka *knownAddress) ID() p2p.NodeID { return ka.Addr.ID } diff --git a/p2p/pex/pex_reactor.go b/p2p/pex/pex_reactor.go index 64e3f9ec8..20b1c848b 100644 --- a/p2p/pex/pex_reactor.go +++ b/p2p/pex/pex_reactor.go @@ -97,7 +97,7 @@ type Reactor struct { attemptsToDial sync.Map // address (string) -> {number of attempts (int), last time dialed (time.Time)} // seed/crawled mode fields - crawlPeerInfos map[p2p.ID]crawlPeerInfo + crawlPeerInfos map[p2p.NodeID]crawlPeerInfo } func (r *Reactor) minReceiveRequestInterval() time.Duration { @@ -137,7 +137,7 @@ func NewReactor(b AddrBook, config *ReactorConfig) *Reactor { ensurePeersPeriod: defaultEnsurePeersPeriod, requestsSent: cmap.NewCMap(), lastReceivedRequests: cmap.NewCMap(), - crawlPeerInfos: make(map[p2p.ID]crawlPeerInfo), + crawlPeerInfos: make(map[p2p.NodeID]crawlPeerInfo), } r.BaseReactor = *p2p.NewBaseReactor("PEX", r) return r @@ -475,7 +475,7 @@ func (r *Reactor) ensurePeers() { // NOTE: range here is [10, 90]. Too high ? newBias := tmmath.MinInt(out, 8)*10 + 10 - toDial := make(map[p2p.ID]*p2p.NetAddress) + toDial := make(map[p2p.NodeID]*p2p.NetAddress) // Try maxAttempts times to pick numToDial addresses to dial maxAttempts := numToDial * 3 diff --git a/p2p/shim.go b/p2p/shim.go index ed3be90b1..bf57ac8fa 100644 --- a/p2p/shim.go +++ b/p2p/shim.go @@ -124,7 +124,7 @@ func (rs *ReactorShim) proxyPeerEnvelopes() { rs.Switch.Broadcast(cs.Descriptor.ID, bz) case !e.To.Empty(): - src := rs.Switch.peers.Get(ID(e.To.String())) + src := rs.Switch.peers.Get(NodeID(e.To.String())) if src == nil { rs.Logger.Error( "failed to proxy envelope; failed to find peer", @@ -161,7 +161,7 @@ func (rs *ReactorShim) handlePeerErrors() { go func(cs *ChannelShim) { for pErr := range cs.Channel.errCh { if !pErr.PeerID.Empty() { - peer := rs.Switch.peers.Get(ID(pErr.PeerID.String())) + peer := rs.Switch.peers.Get(NodeID(pErr.PeerID.String())) if peer == nil { rs.Logger.Error("failed to handle peer error; failed to find peer", "peer", pErr.PeerID.String()) continue diff --git a/p2p/shim_test.go b/p2p/shim_test.go index 218fa8d99..918666d5b 100644 --- a/p2p/shim_test.go +++ b/p2p/shim_test.go @@ -80,7 +80,7 @@ func simplePeer(t *testing.T, id string) (*p2pmocks.Peer, p2p.PeerID) { t.Helper() peer := &p2pmocks.Peer{} - peer.On("ID").Return(p2p.ID(id)) + peer.On("ID").Return(p2p.NodeID(id)) pID, err := p2p.PeerIDFromString(string(peer.ID())) require.NoError(t, err) diff --git a/p2p/switch.go b/p2p/switch.go index 9eff790be..54841f9c0 100644 --- a/p2p/switch.go +++ b/p2p/switch.go @@ -50,7 +50,7 @@ type AddrBook interface { AddPrivateIDs([]string) AddOurAddress(*NetAddress) OurAddress(*NetAddress) bool - MarkGood(ID) + MarkGood(NodeID) RemoveAddress(*NetAddress) HasAddress(*NetAddress) bool Save() @@ -81,7 +81,7 @@ type Switch struct { addrBook AddrBook // peers addresses with whom we'll maintain constant connection persistentPeersAddrs []*NetAddress - unconditionalPeerIDs map[ID]struct{} + unconditionalPeerIDs map[NodeID]struct{} transport Transport @@ -124,7 +124,7 @@ func NewSwitch( transport: transport, filterTimeout: defaultFilterTimeout, persistentPeersAddrs: make([]*NetAddress, 0), - unconditionalPeerIDs: make(map[ID]struct{}), + unconditionalPeerIDs: make(map[NodeID]struct{}), } // Ensure we have a completely undeterministic PRNG. @@ -314,7 +314,7 @@ func (sw *Switch) NumPeers() (outbound, inbound, dialing int) { return } -func (sw *Switch) IsPeerUnconditional(id ID) bool { +func (sw *Switch) IsPeerUnconditional(id NodeID) bool { _, ok := sw.unconditionalPeerIDs[id] return ok } @@ -592,11 +592,11 @@ func (sw *Switch) AddPersistentPeers(addrs []string) error { func (sw *Switch) AddUnconditionalPeerIDs(ids []string) error { sw.Logger.Info("Adding unconditional peer ids", "ids", ids) for i, id := range ids { - err := validateID(ID(id)) + err := validateID(NodeID(id)) if err != nil { return fmt.Errorf("wrong ID #%d: %w", i, err) } - sw.unconditionalPeerIDs[ID(id)] = struct{}{} + sw.unconditionalPeerIDs[NodeID(id)] = struct{}{} } return nil } @@ -604,7 +604,7 @@ func (sw *Switch) AddUnconditionalPeerIDs(ids []string) error { func (sw *Switch) AddPrivatePeerIDs(ids []string) error { validIDs := make([]string, 0, len(ids)) for i, id := range ids { - err := validateID(ID(id)) + err := validateID(NodeID(id)) if err != nil { return fmt.Errorf("wrong ID #%d: %w", i, err) } diff --git a/p2p/switch_test.go b/p2p/switch_test.go index 01dce5c8b..a0d76f11d 100644 --- a/p2p/switch_test.go +++ b/p2p/switch_test.go @@ -39,7 +39,7 @@ func init() { } type PeerMessage struct { - PeerID ID + PeerID NodeID Bytes []byte Counter int } diff --git a/p2p/test_util.go b/p2p/test_util.go index 2736d7f74..a9bff36b9 100644 --- a/p2p/test_util.go +++ b/p2p/test_util.go @@ -217,11 +217,11 @@ func testPeerConn( //---------------------------------------------------------------- // rand node info -func testNodeInfo(id ID, name string) NodeInfo { +func testNodeInfo(id NodeID, name string) NodeInfo { return testNodeInfoWithNetwork(id, name, "testing") } -func testNodeInfoWithNetwork(id ID, name, network string) NodeInfo { +func testNodeInfoWithNetwork(id NodeID, name, network string) NodeInfo { return NodeInfo{ ProtocolVersion: defaultProtocolVersion, DefaultNodeID: id, @@ -262,7 +262,7 @@ func (book *AddrBookMock) OurAddress(addr *NetAddress) bool { _, ok := book.OurAddrs[addr.String()] return ok } -func (book *AddrBookMock) MarkGood(ID) {} +func (book *AddrBookMock) MarkGood(NodeID) {} func (book *AddrBookMock) HasAddress(addr *NetAddress) bool { _, ok := book.Addrs[addr.String()] return ok diff --git a/p2p/transport.go b/p2p/transport.go index 3c16f8c2c..5a27a13a4 100644 --- a/p2p/transport.go +++ b/p2p/transport.go @@ -42,7 +42,7 @@ type Endpoint struct { // FIXME: This is here for backwards-compatibility with the existing MConn // protocol, we should consider moving this higher in the stack (i.e. to // the router). - PeerID ID + PeerID NodeID // Protocol specifies the transport protocol, used by the router to pick a // transport for an endpoint. diff --git a/p2p/transport_mconn.go b/p2p/transport_mconn.go index 7baabb2eb..324746a39 100644 --- a/p2p/transport_mconn.go +++ b/p2p/transport_mconn.go @@ -401,7 +401,7 @@ type mConnMessage struct { func newMConnConnection( transport *MConnTransport, tcpConn net.Conn, - expectPeerID ID, + expectPeerID NodeID, ) (c *mConnConnection, err error) { // FIXME: Since the MConnection code panics, we need to recover here // and turn it into an error. Be careful not to alias err, so we can diff --git a/p2p/transport_memory.go b/p2p/transport_memory.go index bad025b28..43b6d1438 100644 --- a/p2p/transport_memory.go +++ b/p2p/transport_memory.go @@ -24,14 +24,14 @@ type MemoryNetwork struct { logger log.Logger mtx sync.RWMutex - transports map[ID]*MemoryTransport + transports map[NodeID]*MemoryTransport } // NewMemoryNetwork creates a new in-memory network. func NewMemoryNetwork(logger log.Logger) *MemoryNetwork { return &MemoryNetwork{ logger: logger, - transports: map[ID]*MemoryTransport{}, + transports: map[NodeID]*MemoryTransport{}, } } @@ -80,14 +80,14 @@ func (n *MemoryNetwork) GenerateTransport() *MemoryTransport { } // GetTransport looks up a transport in the network, returning nil if not found. -func (n *MemoryNetwork) GetTransport(id ID) *MemoryTransport { +func (n *MemoryNetwork) GetTransport(id NodeID) *MemoryTransport { n.mtx.RLock() defer n.mtx.RUnlock() return n.transports[id] } // RemoveTransport removes a transport from the network and closes it. -func (n *MemoryNetwork) RemoveTransport(id ID) error { +func (n *MemoryNetwork) RemoveTransport(id NodeID) error { n.mtx.Lock() t, ok := n.transports[id] delete(n.transports, id) @@ -161,7 +161,7 @@ func (t *MemoryTransport) Dial(ctx context.Context, endpoint Endpoint) (Connecti } t.logger.Info("dialing peer", "remote", endpoint) - peerTransport := t.network.GetTransport(ID(endpoint.Path)) + peerTransport := t.network.GetTransport(NodeID(endpoint.Path)) if peerTransport == nil { return nil, fmt.Errorf("unknown peer %q", endpoint.Path) } diff --git a/p2p/transport_memory_test.go b/p2p/transport_memory_test.go index e882f8690..a9f8761ae 100644 --- a/p2p/transport_memory_test.go +++ b/p2p/transport_memory_test.go @@ -20,7 +20,7 @@ func TestMemoryTransport(t *testing.T) { // Dialing a missing endpoint should fail. _, err := a.Dial(ctx, p2p.Endpoint{ Protocol: p2p.MemoryProtocol, - PeerID: p2p.ID("foo"), + PeerID: p2p.NodeID("foo"), Path: "foo", }) require.Error(t, err) diff --git a/test/maverick/consensus/msgs.go b/test/maverick/consensus/msgs.go index a1ac7c1a4..9f132798b 100644 --- a/test/maverick/consensus/msgs.go +++ b/test/maverick/consensus/msgs.go @@ -359,7 +359,7 @@ func WALFromProto(msg *tmcons.WALMessage) (WALMessage, error) { } pb = msgInfo{ Msg: walMsg, - PeerID: p2p.ID(msg.MsgInfo.PeerID), + PeerID: p2p.NodeID(msg.MsgInfo.PeerID), } case *tmcons.WALMessage_TimeoutInfo: diff --git a/test/maverick/consensus/state.go b/test/maverick/consensus/state.go index a1385bd1e..13bc98954 100644 --- a/test/maverick/consensus/state.go +++ b/test/maverick/consensus/state.go @@ -345,7 +345,7 @@ func (cs *State) enterPrecommit(height int64, round int32) { func (cs *State) addVote( vote *types.Vote, - peerID p2p.ID) (added bool, err error) { + peerID p2p.NodeID) (added bool, err error) { cs.Logger.Debug( "addVote", "voteHeight", @@ -442,8 +442,8 @@ var ( // msgs from the reactor which may update the state type msgInfo struct { - Msg Message `json:"msg"` - PeerID p2p.ID `json:"peer_key"` + Msg Message `json:"msg"` + PeerID p2p.NodeID `json:"peer_key"` } // internally generated messages which may update the state @@ -708,7 +708,7 @@ func (cs *State) OpenWAL(walFile string) (WAL, error) { // TODO: should these return anything or let callers just use events? // AddVote inputs a vote. -func (cs *State) AddVote(vote *types.Vote, peerID p2p.ID) (added bool, err error) { +func (cs *State) AddVote(vote *types.Vote, peerID p2p.NodeID) (added bool, err error) { if peerID == "" { cs.internalMsgQueue <- msgInfo{&VoteMessage{vote}, ""} } else { @@ -720,7 +720,7 @@ func (cs *State) AddVote(vote *types.Vote, peerID p2p.ID) (added bool, err error } // SetProposal inputs a proposal. -func (cs *State) SetProposal(proposal *types.Proposal, peerID p2p.ID) error { +func (cs *State) SetProposal(proposal *types.Proposal, peerID p2p.NodeID) error { if peerID == "" { cs.internalMsgQueue <- msgInfo{&ProposalMessage{proposal}, ""} @@ -733,7 +733,7 @@ func (cs *State) SetProposal(proposal *types.Proposal, peerID p2p.ID) error { } // AddProposalBlockPart inputs a part of the proposal block. -func (cs *State) AddProposalBlockPart(height int64, round int32, part *types.Part, peerID p2p.ID) error { +func (cs *State) AddProposalBlockPart(height int64, round int32, part *types.Part, peerID p2p.NodeID) error { if peerID == "" { cs.internalMsgQueue <- msgInfo{&BlockPartMessage{height, round, part}, ""} @@ -750,7 +750,7 @@ func (cs *State) SetProposalAndBlock( proposal *types.Proposal, block *types.Block, parts *types.PartSet, - peerID p2p.ID, + peerID p2p.NodeID, ) error { if err := cs.SetProposal(proposal, peerID); err != nil { return err @@ -1659,7 +1659,7 @@ func (cs *State) recordMetrics(height int64, block *types.Block) { // NOTE: block is not necessarily valid. // Asynchronously triggers either enterPrevote (before we timeout of propose) or tryFinalizeCommit, // once we have the full block. -func (cs *State) addProposalBlockPart(msg *BlockPartMessage, peerID p2p.ID) (added bool, err error) { +func (cs *State) addProposalBlockPart(msg *BlockPartMessage, peerID p2p.NodeID) (added bool, err error) { height, round, part := msg.Height, msg.Round, msg.Part // Blocks might be reused, so round mismatch is OK @@ -1744,7 +1744,7 @@ func (cs *State) addProposalBlockPart(msg *BlockPartMessage, peerID p2p.ID) (add } // Attempt to add the vote. if its a duplicate signature, dupeout the validator -func (cs *State) tryAddVote(vote *types.Vote, peerID p2p.ID) (bool, error) { +func (cs *State) tryAddVote(vote *types.Vote, peerID p2p.NodeID) (bool, error) { added, err := cs.addVote(vote, peerID) if err != nil { // If the vote height is off, we'll just ignore it,