diff --git a/blockchain/v0/reactor_test.go b/blockchain/v0/reactor_test.go index 1969f9228..7f396d535 100644 --- a/blockchain/v0/reactor_test.go +++ b/blockchain/v0/reactor_test.go @@ -213,7 +213,7 @@ func TestReactor_AbruptDisconnect(t *testing.T) { defer os.RemoveAll(config.RootDir) genDoc, privVals := randGenesisDoc(config, 1, false, 30) - maxBlockHeight := int64(64) + maxBlockHeight := uint64(64) testSuites := []*reactorTestSuite{ setup(t, genDoc, privVals, maxBlockHeight, 0), setup(t, genDoc, privVals, 0, 0), @@ -260,7 +260,7 @@ func TestReactor_NoBlockResponse(t *testing.T) { defer os.RemoveAll(config.RootDir) genDoc, privVals := randGenesisDoc(config, 1, false, 30) - maxBlockHeight := int64(65) + maxBlockHeight := uint64(65) testSuites := []*reactorTestSuite{ setup(t, genDoc, privVals, maxBlockHeight, 0), setup(t, genDoc, privVals, 0, 0), @@ -283,7 +283,7 @@ func TestReactor_NoBlockResponse(t *testing.T) { } testCases := []struct { - height int64 + height uint64 existent bool }{ {maxBlockHeight + 2, false}, @@ -320,7 +320,7 @@ func TestReactor_BadBlockStopsPeer(t *testing.T) { config := cfg.ResetTestRoot("blockchain_reactor_test") defer os.RemoveAll(config.RootDir) - maxBlockHeight := int64(48) + maxBlockHeight := uint64(48) genDoc, privVals := randGenesisDoc(config, 1, false, 30) testSuites := []*reactorTestSuite{ diff --git a/blockchain/v0/test_util.go b/blockchain/v0/test_util.go index f9b119d14..9ae39ef55 100644 --- a/blockchain/v0/test_util.go +++ b/blockchain/v0/test_util.go @@ -37,14 +37,14 @@ func randGenesisDoc( }, privValidators } -func makeTxs(height int64) (txs []types.Tx) { +func makeTxs(height uint64) (txs []types.Tx) { for i := 0; i < 10; i++ { txs = append(txs, types.Tx([]byte{byte(height), byte(i)})) } return txs } -func makeBlock(height int64, state sm.State, lastCommit *types.Commit) *types.Block { +func makeBlock(height uint64, state sm.State, lastCommit *types.Commit) *types.Block { block, _ := state.MakeBlock(height, makeTxs(height), lastCommit, nil, state.Validators.GetProposer().Address) return block } diff --git a/blockchain/v2/io.go b/blockchain/v2/io.go index d1c7c2256..c5280eb14 100644 --- a/blockchain/v2/io.go +++ b/blockchain/v2/io.go @@ -15,10 +15,10 @@ var ( ) type iIO interface { - sendBlockRequest(peer p2p.Peer, height int64) error + sendBlockRequest(peer p2p.Peer, height uint64) error sendBlockToPeer(block *types.Block, peer p2p.Peer) error - sendBlockNotFound(height int64, peer p2p.Peer) error - sendStatusResponse(base, height int64, peer p2p.Peer) error + sendBlockNotFound(height uint64, peer p2p.Peer) error + sendStatusResponse(base, height uint64, peer p2p.Peer) error sendStatusRequest(peer p2p.Peer) error broadcastStatusRequest() error @@ -47,7 +47,7 @@ type consensusReactor interface { SwitchToConsensus(state state.State, skipWAL bool) } -func (sio *switchIO) sendBlockRequest(peer p2p.Peer, height int64) error { +func (sio *switchIO) sendBlockRequest(peer p2p.Peer, height uint64) error { msgProto := &bcproto.Message{ Sum: &bcproto.Message_BlockRequest{ BlockRequest: &bcproto.BlockRequest{ @@ -68,7 +68,7 @@ func (sio *switchIO) sendBlockRequest(peer p2p.Peer, height int64) error { return nil } -func (sio *switchIO) sendStatusResponse(base int64, height int64, peer p2p.Peer) error { +func (sio *switchIO) sendStatusResponse(base, height uint64, peer p2p.Peer) error { msgProto := &bcproto.Message{ Sum: &bcproto.Message_StatusResponse{ StatusResponse: &bcproto.StatusResponse{ @@ -120,7 +120,7 @@ func (sio *switchIO) sendBlockToPeer(block *types.Block, peer p2p.Peer) error { return nil } -func (sio *switchIO) sendBlockNotFound(height int64, peer p2p.Peer) error { +func (sio *switchIO) sendBlockNotFound(height uint64, peer p2p.Peer) error { msgProto := &bcproto.Message{ Sum: &bcproto.Message_NoBlockResponse{ NoBlockResponse: &bcproto.NoBlockResponse{ diff --git a/blockchain/v2/processor.go b/blockchain/v2/processor.go index c25386cdc..8617db404 100644 --- a/blockchain/v2/processor.go +++ b/blockchain/v2/processor.go @@ -12,7 +12,7 @@ import ( // block execution failure, event will indicate the peer(s) that caused the error type pcBlockVerificationFailure struct { priorityNormal - height int64 + height uint64 firstPeerID p2p.NodeID secondPeerID p2p.NodeID } @@ -25,7 +25,7 @@ func (e pcBlockVerificationFailure) String() string { // successful block execution type pcBlockProcessed struct { priorityNormal - height int64 + height uint64 peerID p2p.NodeID } @@ -49,7 +49,7 @@ type queueItem struct { peerID p2p.NodeID } -type blockQueue map[int64]queueItem +type blockQueue map[uint64]queueItem type pcState struct { // blocks waiting to be processed @@ -95,7 +95,7 @@ func (state *pcState) synced() bool { return len(state.queue) <= 1 } -func (state *pcState) enqueue(peerID p2p.NodeID, block *types.Block, height int64) { +func (state *pcState) enqueue(peerID p2p.NodeID, block *types.Block, height uint64) { 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)", @@ -105,7 +105,7 @@ func (state *pcState) enqueue(peerID p2p.NodeID, block *types.Block, height int6 state.queue[height] = queueItem{block: block, peerID: peerID} } -func (state *pcState) height() int64 { +func (state *pcState) height() uint64 { return state.context.tmState().LastBlockHeight } diff --git a/blockchain/v2/processor_context.go b/blockchain/v2/processor_context.go index 6a0466550..206e34738 100644 --- a/blockchain/v2/processor_context.go +++ b/blockchain/v2/processor_context.go @@ -9,7 +9,7 @@ import ( type processorContext interface { applyBlock(blockID types.BlockID, block *types.Block) error - verifyCommit(chainID string, blockID types.BlockID, height int64, commit *types.Commit) error + verifyCommit(chainID string, blockID types.BlockID, height uint64, commit *types.Commit) error saveBlock(block *types.Block, blockParts *types.PartSet, seenCommit *types.Commit) tmState() state.State setState(state.State) @@ -43,7 +43,7 @@ func (pc *pContext) setState(state state.State) { pc.state = state } -func (pc pContext) verifyCommit(chainID string, blockID types.BlockID, height int64, commit *types.Commit) error { +func (pc pContext) verifyCommit(chainID string, blockID types.BlockID, height uint64, commit *types.Commit) error { return pc.state.Validators.VerifyCommitLight(chainID, blockID, height, commit) } @@ -70,7 +70,7 @@ func newMockProcessorContext( func (mpc *mockPContext) applyBlock(blockID types.BlockID, block *types.Block) error { for _, h := range mpc.applicationBL { - if h == block.Height { + if uint64(h) == block.Height { return fmt.Errorf("generic application error") } } @@ -78,9 +78,9 @@ func (mpc *mockPContext) applyBlock(blockID types.BlockID, block *types.Block) e return nil } -func (mpc *mockPContext) verifyCommit(chainID string, blockID types.BlockID, height int64, commit *types.Commit) error { +func (mpc *mockPContext) verifyCommit(chainID string, blockID types.BlockID, height uint64, commit *types.Commit) error { for _, h := range mpc.verificationBL { - if h == height { + if uint64(h) == height { return fmt.Errorf("generic verification error") } } diff --git a/blockchain/v2/processor_test.go b/blockchain/v2/processor_test.go index f268a0910..a1703718b 100644 --- a/blockchain/v2/processor_test.go +++ b/blockchain/v2/processor_test.go @@ -13,12 +13,12 @@ import ( // pcBlock is a test helper structure with simple types. Its purpose is to help with test readability. type pcBlock struct { pid string - height int64 + height uint64 } // params is a test structure used to create processor state. type params struct { - height int64 + height uint64 items []pcBlock blocksSynced int verBL []int64 @@ -27,7 +27,7 @@ type params struct { } // makePcBlock makes an empty block. -func makePcBlock(height int64) *types.Block { +func makePcBlock(height uint64) *types.Block { return &types.Block{Header: types.Header{Height: height}} } @@ -48,7 +48,7 @@ func makeState(p *params) *pcState { return state } -func mBlockResponse(peerID p2p.NodeID, height int64) scBlockReceived { +func mBlockResponse(peerID p2p.NodeID, height uint64) scBlockReceived { return scBlockReceived{ peerID: peerID, block: makePcBlock(height), diff --git a/blockchain/v2/reactor.go b/blockchain/v2/reactor.go index d1bb709eb..100a9ab77 100644 --- a/blockchain/v2/reactor.go +++ b/blockchain/v2/reactor.go @@ -96,7 +96,7 @@ func (r *BlockchainReactor) SetSwitch(sw *p2p.Switch) { } } -func (r *BlockchainReactor) setMaxPeerHeight(height int64) { +func (r *BlockchainReactor) setMaxPeerHeight(height uint64) { r.mtx.Lock() defer r.mtx.Unlock() if height > r.maxPeerHeight { @@ -104,14 +104,14 @@ func (r *BlockchainReactor) setMaxPeerHeight(height int64) { } } -func (r *BlockchainReactor) setSyncHeight(height int64) { +func (r *BlockchainReactor) setSyncHeight(height uint64) { r.mtx.Lock() defer r.mtx.Unlock() r.syncHeight = height } // SyncHeight returns the height to which the BlockchainReactor has synced. -func (r *BlockchainReactor) SyncHeight() int64 { +func (r *BlockchainReactor) SyncHeight() uint64 { r.mtx.RLock() defer r.mtx.RUnlock() return r.syncHeight @@ -226,7 +226,7 @@ type bcNoBlockResponse struct { priorityNormal time time.Time peerID p2p.NodeID - height int64 + height uint64 } func (resp bcNoBlockResponse) String() string { @@ -239,8 +239,8 @@ type bcStatusResponse struct { priorityNormal time time.Time peerID p2p.NodeID - base int64 - height int64 + base uint64 + height uint64 } func (resp bcStatusResponse) String() string { diff --git a/blockchain/v2/reactor_test.go b/blockchain/v2/reactor_test.go index 099d311a0..abe80cbc2 100644 --- a/blockchain/v2/reactor_test.go +++ b/blockchain/v2/reactor_test.go @@ -61,14 +61,14 @@ func (mp mockPeer) Get(string) interface{} { return struct{}{} } //nolint:unused type mockBlockStore struct { - blocks map[int64]*types.Block + blocks map[uint64]*types.Block } func (ml *mockBlockStore) Height() int64 { return int64(len(ml.blocks)) } -func (ml *mockBlockStore) LoadBlock(height int64) *types.Block { +func (ml *mockBlockStore) LoadBlock(height uint64) *types.Block { return ml.blocks[height] } @@ -82,7 +82,7 @@ type mockBlockApplier struct { // XXX: Add whitelist/blacklist? func (mba *mockBlockApplier) ApplyBlock( state sm.State, blockID types.BlockID, block *types.Block, -) (sm.State, int64, error) { +) (sm.State, uint64, error) { state.LastBlockHeight++ return state, 0, nil } @@ -98,11 +98,11 @@ type mockSwitchIo struct { var _ iIO = (*mockSwitchIo)(nil) -func (sio *mockSwitchIo) sendBlockRequest(_ p2p.Peer, _ int64) error { +func (sio *mockSwitchIo) sendBlockRequest(_ p2p.Peer, _ uint64) error { return nil } -func (sio *mockSwitchIo) sendStatusResponse(_, _ int64, _ p2p.Peer) error { +func (sio *mockSwitchIo) sendStatusResponse(_, _ uint64, _ p2p.Peer) error { sio.mtx.Lock() defer sio.mtx.Unlock() sio.numStatusResponse++ @@ -116,7 +116,7 @@ func (sio *mockSwitchIo) sendBlockToPeer(_ *types.Block, _ p2p.Peer) error { return nil } -func (sio *mockSwitchIo) sendBlockNotFound(_ int64, _ p2p.Peer) error { +func (sio *mockSwitchIo) sendBlockNotFound(_ uint64, _ p2p.Peer) error { sio.mtx.Lock() defer sio.mtx.Unlock() sio.numNoBlockResponse++ @@ -145,7 +145,7 @@ type testReactorParams struct { logger log.Logger genDoc *types.GenesisDoc privVals []types.PrivValidator - startHeight int64 + startHeight uint64 mockA bool } @@ -201,7 +201,7 @@ func newTestReactor(p testReactorParams) *BlockchainReactor { // type testEvent struct { // evType string // peer string -// height int64 +// height uint64 // } // tests := []struct { @@ -469,14 +469,14 @@ func TestReactorSetSwitchNil(t *testing.T) { //---------------------------------------------- // utility funcs -func makeTxs(height int64) (txs []types.Tx) { +func makeTxs(height uint64) (txs []types.Tx) { for i := 0; i < 10; i++ { txs = append(txs, types.Tx([]byte{byte(height), byte(i)})) } return txs } -func makeBlock(height int64, state sm.State, lastCommit *types.Commit) *types.Block { +func makeBlock(height uint64, state sm.State, lastCommit *types.Commit) *types.Block { block, _ := state.MakeBlock(height, makeTxs(height), lastCommit, nil, state.Validators.GetProposer().Address) return block } @@ -511,7 +511,7 @@ func randGenesisDoc(chainID string, numValidators int, randPower bool, minPower func newReactorStore( genDoc *types.GenesisDoc, privVals []types.PrivValidator, - maxBlockHeight int64) (*store.BlockStore, sm.State, *sm.BlockExecutor) { + maxBlockHeight uint64) (*store.BlockStore, sm.State, *sm.BlockExecutor) { if len(privVals) != 1 { panic("only support one validator") } @@ -540,7 +540,7 @@ func newReactorStore( } // add blocks in - for blockHeight := int64(1); blockHeight <= maxBlockHeight; blockHeight++ { + for blockHeight := uint64(1); blockHeight <= maxBlockHeight; blockHeight++ { lastCommit := types.NewCommit(blockHeight-1, 0, types.BlockID{}, nil) if blockHeight > 1 { lastBlockMeta := blockStore.LoadBlockMeta(blockHeight - 1) diff --git a/blockchain/v2/scheduler.go b/blockchain/v2/scheduler.go index f45599728..4a07861be 100644 --- a/blockchain/v2/scheduler.go +++ b/blockchain/v2/scheduler.go @@ -27,7 +27,7 @@ func (e scFinishedEv) String() string { type scBlockRequest struct { priorityNormal peerID p2p.NodeID - height int64 + height uint64 } func (e scBlockRequest) String() string { @@ -132,8 +132,8 @@ type scPeer struct { // updated to Removed when peer is removed state peerState - base int64 // updated when statusResponse is received - height int64 // updated when statusResponse is received + base uint64 // updated when statusResponse is received + height uint64 // updated when statusResponse is received lastTouched time.Time lastRate int64 // last receive rate in bytes } @@ -147,8 +147,8 @@ func newScPeer(peerID p2p.NodeID) *scPeer { return &scPeer{ peerID: peerID, state: peerStateNew, - base: -1, - height: -1, + base: 0, + height: 0, lastTouched: time.Time{}, } } @@ -180,16 +180,16 @@ type scheduler struct { targetPending int // a list of blocks to be scheduled (New), Pending or Received. Its length should be // smaller than targetPending. - blockStates map[int64]blockState + blockStates map[uint64]blockState // a map of heights to the peer we are waiting a response from - pendingBlocks map[int64]p2p.NodeID + pendingBlocks map[uint64]p2p.NodeID // the time at which a block was put in blockStatePending - pendingTime map[int64]time.Time + pendingTime map[uint64]time.Time // a map of heights to the peers that put the block in blockStateReceived - receivedBlocks map[int64]p2p.NodeID + receivedBlocks map[uint64]p2p.NodeID } func (sc scheduler) String() string { @@ -203,11 +203,11 @@ func newScheduler(initHeight uint64, startTime time.Time) *scheduler { lastAdvance: startTime, syncTimeout: 60 * time.Second, height: initHeight, - blockStates: make(map[int64]blockState), + blockStates: make(map[uint64]blockState), peers: make(map[p2p.NodeID]*scPeer), - pendingBlocks: make(map[int64]p2p.NodeID), - pendingTime: make(map[int64]time.Time), - receivedBlocks: make(map[int64]p2p.NodeID), + pendingBlocks: make(map[uint64]p2p.NodeID), + pendingTime: make(map[uint64]time.Time), + receivedBlocks: make(map[uint64]p2p.NodeID), targetPending: 10, // TODO - pass as param peerTimeout: 15 * time.Second, // TODO - pass as param minRecvRate: 0, // int64(7680), TODO - pass as param @@ -264,7 +264,7 @@ func (sc *scheduler) removePeer(peerID p2p.NodeID) { // remove the blocks from blockStates if the peer removal causes the max peer height to be lower. peer.state = peerStateRemoved - maxPeerHeight := int64(0) + maxPeerHeight := uint64(0) for _, otherPeer := range sc.peers { if otherPeer.state != peerStateReady { continue @@ -288,7 +288,7 @@ func (sc *scheduler) addNewBlocks() { return } - for i := sc.height; i < int64(sc.targetPending)+sc.height; i++ { + for i := sc.height; i < uint64(sc.targetPending)+sc.height; i++ { if i > sc.maxHeight() { break } @@ -298,7 +298,7 @@ func (sc *scheduler) addNewBlocks() { } } -func (sc *scheduler) setPeerRange(peerID p2p.NodeID, base int64, height int64) error { +func (sc *scheduler) setPeerRange(peerID p2p.NodeID, base, height uint64) error { peer := sc.ensurePeer(peerID) if peer.state == peerStateRemoved { @@ -323,7 +323,7 @@ func (sc *scheduler) setPeerRange(peerID p2p.NodeID, base int64, height int64) e return nil } -func (sc *scheduler) getStateAtHeight(height int64) blockState { +func (sc *scheduler) getStateAtHeight(height uint64) blockState { if height < sc.height { return blockStateProcessed } else if state, ok := sc.blockStates[height]; ok { @@ -333,7 +333,7 @@ func (sc *scheduler) getStateAtHeight(height int64) blockState { } } -func (sc *scheduler) getPeersWithHeight(height int64) []p2p.NodeID { +func (sc *scheduler) getPeersWithHeight(height uint64) []p2p.NodeID { peers := make([]p2p.NodeID, 0) for _, peer := range sc.peers { if peer.state != peerStateReady { @@ -361,12 +361,12 @@ func (sc *scheduler) prunablePeers(peerTimout time.Duration, minRecvRate int64, return prunable } -func (sc *scheduler) setStateAtHeight(height int64, state blockState) { +func (sc *scheduler) setStateAtHeight(height uint64, state blockState) { sc.blockStates[height] = state } // CONTRACT: peer exists and in Ready state. -func (sc *scheduler) markReceived(peerID p2p.NodeID, height int64, size int64, now time.Time) error { +func (sc *scheduler) markReceived(peerID p2p.NodeID, height uint64, 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.NodeID, height int64, size int64, n return nil } -func (sc *scheduler) markPending(peerID p2p.NodeID, height int64, time time.Time) error { +func (sc *scheduler) markPending(peerID p2p.NodeID, height uint64, 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) @@ -422,7 +422,7 @@ func (sc *scheduler) markPending(peerID p2p.NodeID, height int64, time time.Time return nil } -func (sc *scheduler) markProcessed(height int64) error { +func (sc *scheduler) markProcessed(height uint64) error { // It is possible that a peer error or timeout is handled after the processor // has processed the block but before the scheduler received this event, so // when pcBlockProcessed event is received, the block had been requested @@ -445,7 +445,7 @@ func (sc *scheduler) allBlocksProcessed() bool { } // returns max peer height or the last processed block, i.e. sc.height -func (sc *scheduler) maxHeight() int64 { +func (sc *scheduler) maxHeight() uint64 { max := sc.height - 1 for _, peer := range sc.peers { if peer.state != peerStateReady { @@ -459,21 +459,21 @@ func (sc *scheduler) maxHeight() int64 { } // lowest block in sc.blockStates with state == blockStateNew or -1 if no new blocks -func (sc *scheduler) nextHeightToSchedule() int64 { - var min int64 = math.MaxInt64 +func (sc *scheduler) nextHeightToSchedule() uint64 { + var min uint64 = math.MaxUint64 for height, state := range sc.blockStates { if state == blockStateNew && height < min { min = height } } if min == math.MaxInt64 { - min = -1 + min = 0 //todo: see if this changes logic } return min } -func (sc *scheduler) pendingFrom(peerID p2p.NodeID) []int64 { - var heights []int64 +func (sc *scheduler) pendingFrom(peerID p2p.NodeID) []uint64 { + var heights []uint64 for height, pendingPeerID := range sc.pendingBlocks { if pendingPeerID == peerID { heights = append(heights, height) @@ -482,7 +482,7 @@ func (sc *scheduler) pendingFrom(peerID p2p.NodeID) []int64 { return heights } -func (sc *scheduler) selectPeer(height int64) (p2p.NodeID, error) { +func (sc *scheduler) selectPeer(height uint64) (p2p.NodeID, error) { peers := sc.getPeersWithHeight(height) if len(peers) == 0 { return "", fmt.Errorf("cannot find peer for height %d", height) @@ -651,7 +651,7 @@ func (sc *scheduler) handleTrySchedule(event rTrySchedule) (Event, error) { } nextHeight := sc.nextHeightToSchedule() - if nextHeight == -1 { + if nextHeight == 0 { // todo: see if this changes logic return noOp, nil } diff --git a/blockchain/v2/scheduler_test.go b/blockchain/v2/scheduler_test.go index b864a5303..f09f6bdab 100644 --- a/blockchain/v2/scheduler_test.go +++ b/blockchain/v2/scheduler_test.go @@ -17,12 +17,12 @@ import ( type scTestParams struct { peers map[string]*scPeer - initHeight int64 - height int64 - allB []int64 - pending map[int64]p2p.NodeID - pendingTime map[int64]time.Time - received map[int64]p2p.NodeID + initHeight uint64 + height uint64 + allB []uint64 + pending map[uint64]p2p.NodeID + pendingTime map[uint64]time.Time + received map[uint64]p2p.NodeID peerTimeout time.Duration minRecvRate int64 targetPending int @@ -42,7 +42,7 @@ func verifyScheduler(sc *scheduler) { func newTestScheduler(params scTestParams) *scheduler { peers := make(map[p2p.NodeID]*scPeer) - var maxHeight int64 + var maxHeight uint64 initHeight := params.initHeight if initHeight == 0 { @@ -98,8 +98,8 @@ func newTestScheduler(params scTestParams) *scheduler { func TestScInit(t *testing.T) { var ( - initHeight int64 = 5 - sc = newScheduler(initHeight, time.Now()) + initHeight uint64 = 5 + sc = newScheduler(initHeight, time.Now()) ) assert.Equal(t, blockStateProcessed, sc.getStateAtHeight(initHeight-1)) assert.Equal(t, blockStateUnknown, sc.getStateAtHeight(initHeight)) @@ -151,8 +151,8 @@ func TestScMaxHeights(t *testing.T) { sc: scheduler{ height: 1, peers: map[p2p.NodeID]*scPeer{ - "P1": {base: -1, height: -1, state: peerStateNew}, - "P2": {base: -1, height: -1, state: peerStateNew}}, + "P1": {base: 0, height: 0, state: peerStateNew}, + "P2": {base: 0, height: 0, state: peerStateNew}}, }, wantMax: 0, }, @@ -161,7 +161,7 @@ func TestScMaxHeights(t *testing.T) { sc: scheduler{ height: 1, peers: map[p2p.NodeID]*scPeer{ - "P1": {height: -1, state: peerStateNew}, + "P1": {height: 0, state: peerStateNew}, "P2": {height: 10, state: peerStateReady}, "P3": {height: 20, state: peerStateRemoved}, "P4": {height: 22, state: peerStateReady}, @@ -199,32 +199,32 @@ func TestScEnsurePeer(t *testing.T) { name: "add first peer", fields: scTestParams{}, args: args{peerID: "P1"}, - wantFields: scTestParams{peers: map[string]*scPeer{"P1": {base: -1, height: -1, state: peerStateNew}}}, + wantFields: scTestParams{peers: map[string]*scPeer{"P1": {base: 0, height: 0, state: peerStateNew}}}, }, { name: "add second peer", - fields: scTestParams{peers: map[string]*scPeer{"P1": {base: -1, height: -1, state: peerStateNew}}}, + fields: scTestParams{peers: map[string]*scPeer{"P1": {base: 0, height: 0, state: peerStateNew}}}, args: args{peerID: "P2"}, wantFields: scTestParams{peers: map[string]*scPeer{ - "P1": {base: -1, height: -1, state: peerStateNew}, - "P2": {base: -1, height: -1, state: peerStateNew}}}, + "P1": {base: 0, height: 0, state: peerStateNew}, + "P2": {base: 0, height: 0, state: peerStateNew}}}, }, { name: "add duplicate peer is fine", - fields: scTestParams{peers: map[string]*scPeer{"P1": {height: -1}}}, + fields: scTestParams{peers: map[string]*scPeer{"P1": {height: 0}}}, args: args{peerID: "P1"}, - wantFields: scTestParams{peers: map[string]*scPeer{"P1": {height: -1}}}, + wantFields: scTestParams{peers: map[string]*scPeer{"P1": {height: 0}}}, }, { name: "add duplicate peer with existing peer in Ready state is noop", fields: scTestParams{ peers: map[string]*scPeer{"P1": {state: peerStateReady, height: 3}}, - allB: []int64{1, 2, 3}, + allB: []uint64{1, 2, 3}, }, args: args{peerID: "P1"}, wantFields: scTestParams{ peers: map[string]*scPeer{"P1": {state: peerStateReady, height: 3}}, - allB: []int64{1, 2, 3}, + allB: []uint64{1, 2, 3}, }, }, } @@ -259,11 +259,11 @@ func TestScTouchPeer(t *testing.T) { name: "attempt to touch non existing peer", fields: scTestParams{ peers: map[string]*scPeer{"P1": {state: peerStateReady, height: 5}}, - allB: []int64{1, 2, 3, 4, 5}, + allB: []uint64{1, 2, 3, 4, 5}, }, args: args{peerID: "P2", time: now}, wantFields: scTestParams{peers: map[string]*scPeer{"P1": {state: peerStateReady, height: 5}}, - allB: []int64{1, 2, 3, 4, 5}, + allB: []uint64{1, 2, 3, 4, 5}, }, wantErr: true, }, @@ -370,23 +370,23 @@ func TestScRemovePeer(t *testing.T) { wantFields scTestParams wantErr bool }{ - { + { //todo: probably breaks name: "remove non existing peer", - fields: scTestParams{peers: map[string]*scPeer{"P1": {height: -1}}}, + fields: scTestParams{peers: map[string]*scPeer{"P1": {height: 0}}}, args: args{peerID: "P2"}, - wantFields: scTestParams{peers: map[string]*scPeer{"P1": {height: -1}}}, + wantFields: scTestParams{peers: map[string]*scPeer{"P1": {height: 0}}}, }, { name: "remove single New peer", - fields: scTestParams{peers: map[string]*scPeer{"P1": {height: -1}}}, + fields: scTestParams{peers: map[string]*scPeer{"P1": {height: 0}}}, args: args{peerID: "P1"}, - wantFields: scTestParams{peers: map[string]*scPeer{"P1": {height: -1, state: peerStateRemoved}}}, + wantFields: scTestParams{peers: map[string]*scPeer{"P1": {height: 0, state: peerStateRemoved}}}, }, { name: "remove one of two New peers", - fields: scTestParams{peers: map[string]*scPeer{"P1": {height: -1}, "P2": {height: -1}}}, + fields: scTestParams{peers: map[string]*scPeer{"P1": {height: 0}, "P2": {height: 0}}}, args: args{peerID: "P1"}, - wantFields: scTestParams{peers: map[string]*scPeer{"P1": {height: -1, state: peerStateRemoved}, "P2": {height: -1}}}, + wantFields: scTestParams{peers: map[string]*scPeer{"P1": {height: 0, state: peerStateRemoved}, "P2": {height: 0}}}, }, { name: "remove one Ready peer, all peers removed", @@ -394,7 +394,7 @@ func TestScRemovePeer(t *testing.T) { peers: map[string]*scPeer{ "P1": {height: 10, state: peerStateRemoved}, "P2": {height: 5, state: peerStateReady}}, - allB: []int64{1, 2, 3, 4, 5}, + allB: []uint64{1, 2, 3, 4, 5}, }, args: args{peerID: "P2"}, wantFields: scTestParams{peers: map[string]*scPeer{ @@ -409,7 +409,7 @@ func TestScRemovePeer(t *testing.T) { peers: map[string]*scPeer{ "P1": {height: 10, state: peerStateRemoved}, "P2": {height: 11, state: peerStateReady}}, - allB: []int64{8, 9, 10, 11}, + allB: []uint64{8, 9, 10, 11}, }, args: args{peerID: "P1"}, wantFields: scTestParams{ @@ -417,50 +417,50 @@ func TestScRemovePeer(t *testing.T) { peers: map[string]*scPeer{ "P1": {height: 10, state: peerStateRemoved}, "P2": {height: 11, state: peerStateReady}}, - allB: []int64{8, 9, 10, 11}}, + allB: []uint64{8, 9, 10, 11}}, }, { name: "remove Ready peer with blocks requested", fields: scTestParams{ peers: map[string]*scPeer{"P1": {height: 3, state: peerStateReady}}, - allB: []int64{1, 2, 3}, - pending: map[int64]p2p.NodeID{1: "P1"}, + allB: []uint64{1, 2, 3}, + pending: map[uint64]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.NodeID{}, + allB: []uint64{}, + pending: map[uint64]p2p.NodeID{}, }, }, { name: "remove Ready peer with blocks received", fields: scTestParams{ peers: map[string]*scPeer{"P1": {height: 3, state: peerStateReady}}, - allB: []int64{1, 2, 3}, - received: map[int64]p2p.NodeID{1: "P1"}, + allB: []uint64{1, 2, 3}, + received: map[uint64]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.NodeID{}, + allB: []uint64{}, + received: map[uint64]p2p.NodeID{}, }, }, { name: "remove Ready peer with blocks received and requested (not yet received)", fields: scTestParams{ peers: map[string]*scPeer{"P1": {height: 4, state: peerStateReady}}, - allB: []int64{1, 2, 3, 4}, - pending: map[int64]p2p.NodeID{1: "P1", 3: "P1"}, - received: map[int64]p2p.NodeID{2: "P1", 4: "P1"}, + allB: []uint64{1, 2, 3, 4}, + pending: map[uint64]p2p.NodeID{1: "P1", 3: "P1"}, + received: map[uint64]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.NodeID{}, - received: map[int64]p2p.NodeID{}, + allB: []uint64{}, + pending: map[uint64]p2p.NodeID{}, + received: map[uint64]p2p.NodeID{}, }, }, { @@ -470,9 +470,9 @@ func TestScRemovePeer(t *testing.T) { "P1": {height: 6, state: peerStateReady}, "P2": {height: 6, state: peerStateReady}, }, - allB: []int64{1, 2, 3, 4, 5, 6}, - pending: map[int64]p2p.NodeID{1: "P1", 3: "P2", 6: "P1"}, - received: map[int64]p2p.NodeID{2: "P1", 4: "P2", 5: "P2"}, + allB: []uint64{1, 2, 3, 4, 5, 6}, + pending: map[uint64]p2p.NodeID{1: "P1", 3: "P2", 6: "P1"}, + received: map[uint64]p2p.NodeID{2: "P1", 4: "P2", 5: "P2"}, }, args: args{peerID: "P1"}, wantFields: scTestParams{ @@ -480,9 +480,9 @@ func TestScRemovePeer(t *testing.T) { "P1": {height: 6, state: peerStateRemoved}, "P2": {height: 6, state: peerStateReady}, }, - allB: []int64{1, 2, 3, 4, 5, 6}, - pending: map[int64]p2p.NodeID{3: "P2"}, - received: map[int64]p2p.NodeID{4: "P2", 5: "P2"}, + allB: []uint64{1, 2, 3, 4, 5, 6}, + pending: map[uint64]p2p.NodeID{3: "P2"}, + received: map[uint64]p2p.NodeID{4: "P2", 5: "P2"}, }, }, } @@ -502,8 +502,8 @@ func TestScSetPeerRange(t *testing.T) { type args struct { peerID p2p.NodeID - base int64 - height int64 + base uint64 + height uint64 } tests := []struct { name string @@ -516,14 +516,14 @@ func TestScSetPeerRange(t *testing.T) { name: "change height of non existing peer", fields: scTestParams{ peers: map[string]*scPeer{"P1": {height: 2, state: peerStateReady}}, - allB: []int64{1, 2}}, + allB: []uint64{1, 2}}, args: args{peerID: "P2", height: 4}, wantFields: scTestParams{ peers: map[string]*scPeer{ "P1": {height: 2, state: peerStateReady}, "P2": {height: 4, state: peerStateReady}, }, - allB: []int64{1, 2, 3, 4}}, + allB: []uint64{1, 2, 3, 4}}, }, { name: "increase height of removed peer", @@ -536,50 +536,50 @@ func TestScSetPeerRange(t *testing.T) { name: "decrease height of single peer", fields: scTestParams{ peers: map[string]*scPeer{"P1": {height: 4, state: peerStateReady}}, - allB: []int64{1, 2, 3, 4}}, + allB: []uint64{1, 2, 3, 4}}, args: args{peerID: "P1", height: 2}, wantFields: scTestParams{ peers: map[string]*scPeer{"P1": {height: 4, state: peerStateRemoved}}, - allB: []int64{}}, + allB: []uint64{}}, wantErr: true, }, { name: "increase height of single peer", fields: scTestParams{ peers: map[string]*scPeer{"P1": {height: 2, state: peerStateReady}}, - allB: []int64{1, 2}}, + allB: []uint64{1, 2}}, args: args{peerID: "P1", height: 4}, wantFields: scTestParams{ peers: map[string]*scPeer{"P1": {height: 4, state: peerStateReady}}, - allB: []int64{1, 2, 3, 4}}, + allB: []uint64{1, 2, 3, 4}}, }, { name: "noop height change of single peer", fields: scTestParams{ peers: map[string]*scPeer{"P1": {height: 4, state: peerStateReady}}, - allB: []int64{1, 2, 3, 4}}, + allB: []uint64{1, 2, 3, 4}}, args: args{peerID: "P1", height: 4}, wantFields: scTestParams{ peers: map[string]*scPeer{"P1": {height: 4, state: peerStateReady}}, - allB: []int64{1, 2, 3, 4}}, + allB: []uint64{1, 2, 3, 4}}, }, { name: "add peer with huge height 10**10 ", fields: scTestParams{ - peers: map[string]*scPeer{"P2": {height: -1, state: peerStateNew}}, + peers: map[string]*scPeer{"P2": {height: 0, state: peerStateNew}}, targetPending: 4, }, args: args{peerID: "P2", height: 10000000000}, wantFields: scTestParams{ targetPending: 4, peers: map[string]*scPeer{"P2": {height: 10000000000, state: peerStateReady}}, - allB: []int64{1, 2, 3, 4}}, + allB: []uint64{1, 2, 3, 4}}, }, { name: "add peer with base > height should error", fields: scTestParams{ peers: map[string]*scPeer{"P1": {height: 4, state: peerStateReady}}, - allB: []int64{1, 2, 3, 4}}, + allB: []uint64{1, 2, 3, 4}}, args: args{peerID: "P1", base: 6, height: 5}, wantFields: scTestParams{ peers: map[string]*scPeer{"P1": {height: 4, state: peerStateRemoved}}}, @@ -595,7 +595,7 @@ func TestScSetPeerRange(t *testing.T) { wantFields: scTestParams{ targetPending: 4, peers: map[string]*scPeer{"P1": {base: 6, height: 6, state: peerStateReady}}, - allB: []int64{1, 2, 3, 4}}, + allB: []uint64{1, 2, 3, 4}}, }, } @@ -616,7 +616,7 @@ func TestScSetPeerRange(t *testing.T) { func TestScGetPeersWithHeight(t *testing.T) { type args struct { - height int64 + height uint64 } tests := []struct { name string @@ -632,7 +632,7 @@ func TestScGetPeersWithHeight(t *testing.T) { }, { name: "only new peers", - fields: scTestParams{peers: map[string]*scPeer{"P1": {height: -1, state: peerStateNew}}}, + fields: scTestParams{peers: map[string]*scPeer{"P1": {height: 0, state: peerStateNew}}}, args: args{height: 10}, wantResult: []p2p.NodeID{}, }, @@ -646,7 +646,7 @@ func TestScGetPeersWithHeight(t *testing.T) { name: "one Ready shorter peer", fields: scTestParams{ peers: map[string]*scPeer{"P1": {height: 4, state: peerStateReady}}, - allB: []int64{1, 2, 3, 4}, + allB: []uint64{1, 2, 3, 4}, }, args: args{height: 5}, wantResult: []p2p.NodeID{}, @@ -655,7 +655,7 @@ func TestScGetPeersWithHeight(t *testing.T) { name: "one Ready equal peer", fields: scTestParams{ peers: map[string]*scPeer{"P1": {height: 4, state: peerStateReady}}, - allB: []int64{1, 2, 3, 4}, + allB: []uint64{1, 2, 3, 4}, }, args: args{height: 4}, wantResult: []p2p.NodeID{"P1"}, @@ -665,7 +665,7 @@ func TestScGetPeersWithHeight(t *testing.T) { fields: scTestParams{ targetPending: 4, peers: map[string]*scPeer{"P1": {height: 20, state: peerStateReady}}, - allB: []int64{1, 2, 3, 4}, + allB: []uint64{1, 2, 3, 4}, }, args: args{height: 4}, wantResult: []p2p.NodeID{"P1"}, @@ -675,7 +675,7 @@ func TestScGetPeersWithHeight(t *testing.T) { fields: scTestParams{ targetPending: 4, peers: map[string]*scPeer{"P1": {base: 4, height: 20, state: peerStateReady}}, - allB: []int64{1, 2, 3, 4}, + allB: []uint64{1, 2, 3, 4}, }, args: args{height: 4}, wantResult: []p2p.NodeID{"P1"}, @@ -685,7 +685,7 @@ func TestScGetPeersWithHeight(t *testing.T) { fields: scTestParams{ targetPending: 4, peers: map[string]*scPeer{"P1": {base: 10, height: 20, state: peerStateReady}}, - allB: []int64{1, 2, 3, 4}, + allB: []uint64{1, 2, 3, 4}, }, args: args{height: 4}, wantResult: []p2p.NodeID{}, @@ -695,12 +695,12 @@ func TestScGetPeersWithHeight(t *testing.T) { fields: scTestParams{ height: 8, peers: map[string]*scPeer{ - "P1": {height: -1, state: peerStateNew}, + "P1": {height: 0, state: peerStateNew}, "P2": {height: 10, state: peerStateReady}, "P3": {height: 5, state: peerStateReady}, "P4": {height: 20, state: peerStateRemoved}, "P5": {height: 11, state: peerStateReady}}, - allB: []int64{8, 9, 10, 11}, + allB: []uint64{8, 9, 10, 11}, }, args: args{height: 8}, wantResult: []p2p.NodeID{"P2", "P5"}, @@ -726,7 +726,7 @@ func TestScMarkPending(t *testing.T) { type args struct { peerID p2p.NodeID - height int64 + height uint64 tm time.Time } tests := []struct { @@ -740,33 +740,33 @@ func TestScMarkPending(t *testing.T) { name: "attempt mark pending an unknown block above height", fields: scTestParams{ peers: map[string]*scPeer{"P1": {height: 2, state: peerStateReady}}, - allB: []int64{1, 2}}, + allB: []uint64{1, 2}}, args: args{peerID: "P1", height: 3, tm: now}, wantFields: scTestParams{ peers: map[string]*scPeer{"P1": {height: 2, state: peerStateReady}}, - allB: []int64{1, 2}}, + allB: []uint64{1, 2}}, wantErr: true, }, { name: "attempt mark pending an unknown block below base", fields: scTestParams{ peers: map[string]*scPeer{"P1": {base: 4, height: 6, state: peerStateReady}}, - allB: []int64{1, 2, 3, 4, 5, 6}}, + allB: []uint64{1, 2, 3, 4, 5, 6}}, args: args{peerID: "P1", height: 3, tm: now}, wantFields: scTestParams{ peers: map[string]*scPeer{"P1": {base: 4, height: 6, state: peerStateReady}}, - allB: []int64{1, 2, 3, 4, 5, 6}}, + allB: []uint64{1, 2, 3, 4, 5, 6}}, wantErr: true, }, { name: "attempt mark pending from non existing peer", fields: scTestParams{ peers: map[string]*scPeer{"P1": {height: 2, state: peerStateReady}}, - allB: []int64{1, 2}}, + allB: []uint64{1, 2}}, args: args{peerID: "P2", height: 1, tm: now}, wantFields: scTestParams{ peers: map[string]*scPeer{"P1": {height: 2, state: peerStateReady}}, - allB: []int64{1, 2}}, + allB: []uint64{1, 2}}, wantErr: true, }, { @@ -785,7 +785,7 @@ func TestScMarkPending(t *testing.T) { "P1": {height: 4, state: peerStateReady}, "P2": {height: 4, state: peerStateNew}, }, - allB: []int64{1, 2, 3, 4}, + allB: []uint64{1, 2, 3, 4}, }, args: args{peerID: "P2", height: 2, tm: now}, wantFields: scTestParams{ @@ -793,7 +793,7 @@ func TestScMarkPending(t *testing.T) { "P1": {height: 4, state: peerStateReady}, "P2": {height: 4, state: peerStateNew}, }, - allB: []int64{1, 2, 3, 4}, + allB: []uint64{1, 2, 3, 4}, }, wantErr: true, }, @@ -804,7 +804,7 @@ func TestScMarkPending(t *testing.T) { "P1": {height: 4, state: peerStateReady}, "P2": {height: 2, state: peerStateReady}, }, - allB: []int64{1, 2, 3, 4}, + allB: []uint64{1, 2, 3, 4}, }, args: args{peerID: "P2", height: 3, tm: now}, wantFields: scTestParams{ @@ -812,7 +812,7 @@ func TestScMarkPending(t *testing.T) { "P1": {height: 4, state: peerStateReady}, "P2": {height: 2, state: peerStateReady}, }, - allB: []int64{1, 2, 3, 4}, + allB: []uint64{1, 2, 3, 4}, }, wantErr: true, }, @@ -820,16 +820,16 @@ func TestScMarkPending(t *testing.T) { name: "mark pending all good", fields: scTestParams{ peers: map[string]*scPeer{"P1": {height: 2, state: peerStateReady}}, - allB: []int64{1, 2}, - pending: map[int64]p2p.NodeID{1: "P1"}, - pendingTime: map[int64]time.Time{1: now}, + allB: []uint64{1, 2}, + pending: map[uint64]p2p.NodeID{1: "P1"}, + pendingTime: map[uint64]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.NodeID{1: "P1", 2: "P1"}, - pendingTime: map[int64]time.Time{1: now, 2: now.Add(time.Millisecond)}, + allB: []uint64{1, 2}, + pending: map[uint64]p2p.NodeID{1: "P1", 2: "P1"}, + pendingTime: map[uint64]time.Time{1: now, 2: now.Add(time.Millisecond)}, }, }, } @@ -852,7 +852,7 @@ func TestScMarkReceived(t *testing.T) { type args struct { peerID p2p.NodeID - height int64 + height uint64 size int64 tm time.Time } @@ -867,11 +867,11 @@ func TestScMarkReceived(t *testing.T) { name: "received from non existing peer", fields: scTestParams{ peers: map[string]*scPeer{"P1": {height: 2, state: peerStateReady}}, - allB: []int64{1, 2}}, + allB: []uint64{1, 2}}, args: args{peerID: "P2", height: 1, size: 1000, tm: now}, wantFields: scTestParams{ peers: map[string]*scPeer{"P1": {height: 2, state: peerStateReady}}, - allB: []int64{1, 2}}, + allB: []uint64{1, 2}}, wantErr: true, }, { @@ -890,8 +890,8 @@ func TestScMarkReceived(t *testing.T) { "P1": {height: 4, state: peerStateReady}, "P2": {height: 4, state: peerStateReady}, }, - allB: []int64{1, 2, 3, 4}, - pending: map[int64]p2p.NodeID{1: "P1", 2: "P2", 3: "P2", 4: "P1"}, + allB: []uint64{1, 2, 3, 4}, + pending: map[uint64]p2p.NodeID{1: "P1", 2: "P2", 3: "P2", 4: "P1"}, }, args: args{peerID: "P1", height: 2, size: 1000, tm: now}, wantFields: scTestParams{ @@ -899,8 +899,8 @@ func TestScMarkReceived(t *testing.T) { "P1": {height: 4, state: peerStateReady}, "P2": {height: 4, state: peerStateReady}, }, - allB: []int64{1, 2, 3, 4}, - pending: map[int64]p2p.NodeID{1: "P1", 2: "P2", 3: "P2", 4: "P1"}, + allB: []uint64{1, 2, 3, 4}, + pending: map[uint64]p2p.NodeID{1: "P1", 2: "P2", 3: "P2", 4: "P1"}, }, wantErr: true, }, @@ -908,14 +908,14 @@ func TestScMarkReceived(t *testing.T) { name: "received but blockRequest not sent", fields: scTestParams{ peers: map[string]*scPeer{"P1": {height: 4, state: peerStateReady}}, - allB: []int64{1, 2, 3, 4}, - pending: map[int64]p2p.NodeID{}, + allB: []uint64{1, 2, 3, 4}, + pending: map[uint64]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.NodeID{}, + allB: []uint64{1, 2, 3, 4}, + pending: map[uint64]p2p.NodeID{}, }, wantErr: true, }, @@ -923,16 +923,16 @@ func TestScMarkReceived(t *testing.T) { name: "received with bad timestamp", fields: scTestParams{ peers: map[string]*scPeer{"P1": {height: 2, state: peerStateReady}}, - allB: []int64{1, 2}, - pending: map[int64]p2p.NodeID{1: "P1", 2: "P1"}, - pendingTime: map[int64]time.Time{1: now, 2: now.Add(time.Second)}, + allB: []uint64{1, 2}, + pending: map[uint64]p2p.NodeID{1: "P1", 2: "P1"}, + pendingTime: map[uint64]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.NodeID{1: "P1", 2: "P1"}, - pendingTime: map[int64]time.Time{1: now, 2: now.Add(time.Second)}, + allB: []uint64{1, 2}, + pending: map[uint64]p2p.NodeID{1: "P1", 2: "P1"}, + pendingTime: map[uint64]time.Time{1: now, 2: now.Add(time.Second)}, }, wantErr: true, }, @@ -940,17 +940,17 @@ func TestScMarkReceived(t *testing.T) { name: "received all good", fields: scTestParams{ peers: map[string]*scPeer{"P1": {height: 2, state: peerStateReady}}, - allB: []int64{1, 2}, - pending: map[int64]p2p.NodeID{1: "P1", 2: "P1"}, - pendingTime: map[int64]time.Time{1: now, 2: now}, + allB: []uint64{1, 2}, + pending: map[uint64]p2p.NodeID{1: "P1", 2: "P1"}, + pendingTime: map[uint64]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.NodeID{1: "P1"}, - pendingTime: map[int64]time.Time{1: now}, - received: map[int64]p2p.NodeID{2: "P1"}, + allB: []uint64{1, 2}, + pending: map[uint64]p2p.NodeID{1: "P1"}, + pendingTime: map[uint64]time.Time{1: now}, + received: map[uint64]p2p.NodeID{2: "P1"}, }, }, } @@ -976,7 +976,7 @@ func TestScMarkProcessed(t *testing.T) { now := time.Now() type args struct { - height int64 + height uint64 } tests := []struct { name string @@ -990,16 +990,16 @@ func TestScMarkProcessed(t *testing.T) { fields: scTestParams{ height: 2, peers: map[string]*scPeer{"P1": {height: 4, state: peerStateReady}}, - allB: []int64{2}, - pending: map[int64]p2p.NodeID{2: "P1"}, - pendingTime: map[int64]time.Time{2: now}, + allB: []uint64{2}, + pending: map[uint64]p2p.NodeID{2: "P1"}, + pendingTime: map[uint64]time.Time{2: now}, targetPending: 1, }, args: args{height: 2}, wantFields: scTestParams{ height: 3, peers: map[string]*scPeer{"P1": {height: 4, state: peerStateReady}}, - allB: []int64{3}, + allB: []uint64{3}, targetPending: 1, }, }, @@ -1008,17 +1008,17 @@ func TestScMarkProcessed(t *testing.T) { fields: scTestParams{ height: 1, peers: map[string]*scPeer{"P1": {height: 2, state: peerStateReady}}, - allB: []int64{1, 2}, - pending: map[int64]p2p.NodeID{2: "P1"}, - pendingTime: map[int64]time.Time{2: now}, - received: map[int64]p2p.NodeID{1: "P1"}}, + allB: []uint64{1, 2}, + pending: map[uint64]p2p.NodeID{2: "P1"}, + pendingTime: map[uint64]time.Time{2: now}, + received: map[uint64]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.NodeID{2: "P1"}, - pendingTime: map[int64]time.Time{2: now}}, + allB: []uint64{2}, + pending: map[uint64]p2p.NodeID{2: "P1"}, + pendingTime: map[uint64]time.Time{2: now}}, }, } @@ -1092,7 +1092,7 @@ func TestScAllBlocksProcessed(t *testing.T) { name: "only New blocks", fields: scTestParams{ peers: map[string]*scPeer{"P1": {height: 4, state: peerStateReady}}, - allB: []int64{1, 2, 3, 4}, + allB: []uint64{1, 2, 3, 4}, }, wantResult: false, }, @@ -1100,9 +1100,9 @@ func TestScAllBlocksProcessed(t *testing.T) { name: "only Pending blocks", fields: scTestParams{ peers: map[string]*scPeer{"P1": {height: 4, state: peerStateReady}}, - allB: []int64{1, 2, 3, 4}, - 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}, + allB: []uint64{1, 2, 3, 4}, + pending: map[uint64]p2p.NodeID{1: "P1", 2: "P1", 3: "P1", 4: "P1"}, + pendingTime: map[uint64]time.Time{1: now, 2: now, 3: now, 4: now}, }, wantResult: false, }, @@ -1110,8 +1110,8 @@ func TestScAllBlocksProcessed(t *testing.T) { name: "only Received blocks", fields: scTestParams{ peers: map[string]*scPeer{"P1": {height: 4, state: peerStateReady}}, - allB: []int64{1, 2, 3, 4}, - received: map[int64]p2p.NodeID{1: "P1", 2: "P1", 3: "P1", 4: "P1"}, + allB: []uint64{1, 2, 3, 4}, + received: map[uint64]p2p.NodeID{1: "P1", 2: "P1", 3: "P1", 4: "P1"}, }, wantResult: false, }, @@ -1121,8 +1121,8 @@ func TestScAllBlocksProcessed(t *testing.T) { height: 4, peers: map[string]*scPeer{ "P1": {height: 4, state: peerStateReady}}, - allB: []int64{4}, - received: map[int64]p2p.NodeID{4: "P1"}, + allB: []uint64{4}, + received: map[uint64]p2p.NodeID{4: "P1"}, }, wantResult: true, }, @@ -1130,9 +1130,9 @@ func TestScAllBlocksProcessed(t *testing.T) { name: "mixed block states", fields: scTestParams{ peers: map[string]*scPeer{"P1": {height: 4, state: peerStateReady}}, - allB: []int64{1, 2, 3, 4}, - pending: map[int64]p2p.NodeID{2: "P1", 4: "P1"}, - pendingTime: map[int64]time.Time{2: now, 4: now}, + allB: []uint64{1, 2, 3, 4}, + pending: map[uint64]p2p.NodeID{2: "P1", 4: "P1"}, + pendingTime: map[uint64]time.Time{2: now, 4: now}, }, wantResult: false, }, @@ -1169,7 +1169,7 @@ func TestScNextHeightToSchedule(t *testing.T) { fields: scTestParams{ initHeight: 3, peers: map[string]*scPeer{"P1": {height: 6, state: peerStateReady}}, - allB: []int64{3, 4, 5, 6}, + allB: []uint64{3, 4, 5, 6}, }, wantHeight: 3, }, @@ -1178,9 +1178,9 @@ func TestScNextHeightToSchedule(t *testing.T) { fields: scTestParams{ initHeight: 1, peers: map[string]*scPeer{"P1": {height: 4, state: peerStateReady}}, - allB: []int64{1, 2, 3, 4}, - 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}, + allB: []uint64{1, 2, 3, 4}, + pending: map[uint64]p2p.NodeID{1: "P1", 2: "P1", 3: "P1", 4: "P1"}, + pendingTime: map[uint64]time.Time{1: now, 2: now, 3: now, 4: now}, }, wantHeight: -1, }, @@ -1189,8 +1189,8 @@ func TestScNextHeightToSchedule(t *testing.T) { fields: scTestParams{ initHeight: 1, peers: map[string]*scPeer{"P1": {height: 4, state: peerStateReady}}, - allB: []int64{1, 2, 3, 4}, - received: map[int64]p2p.NodeID{1: "P1", 2: "P1", 3: "P1", 4: "P1"}, + allB: []uint64{1, 2, 3, 4}, + received: map[uint64]p2p.NodeID{1: "P1", 2: "P1", 3: "P1", 4: "P1"}, }, wantHeight: -1, }, @@ -1199,7 +1199,7 @@ func TestScNextHeightToSchedule(t *testing.T) { fields: scTestParams{ initHeight: 1, peers: map[string]*scPeer{"P1": {height: 4, state: peerStateReady}}, - allB: []int64{1, 2, 3, 4}, + allB: []uint64{1, 2, 3, 4}, }, wantHeight: 1, }, @@ -1208,9 +1208,9 @@ func TestScNextHeightToSchedule(t *testing.T) { fields: scTestParams{ initHeight: 1, peers: map[string]*scPeer{"P1": {height: 4, state: peerStateReady}}, - allB: []int64{1, 2, 3, 4}, - pending: map[int64]p2p.NodeID{2: "P1"}, - pendingTime: map[int64]time.Time{2: now}, + allB: []uint64{1, 2, 3, 4}, + pending: map[uint64]p2p.NodeID{2: "P1"}, + pendingTime: map[uint64]time.Time{2: now}, }, wantHeight: 1, }, @@ -1233,7 +1233,7 @@ func TestScNextHeightToSchedule(t *testing.T) { func TestScSelectPeer(t *testing.T) { type args struct { - height int64 + height uint64 } tests := []struct { name string @@ -1251,7 +1251,7 @@ func TestScSelectPeer(t *testing.T) { }, { name: "only new peers", - fields: scTestParams{peers: map[string]*scPeer{"P1": {height: -1, state: peerStateNew}}}, + fields: scTestParams{peers: map[string]*scPeer{"P1": {height: 0, state: peerStateNew}}}, args: args{height: 10}, wantResult: "", wantError: true, @@ -1267,7 +1267,7 @@ func TestScSelectPeer(t *testing.T) { name: "one Ready shorter peer", fields: scTestParams{ peers: map[string]*scPeer{"P1": {height: 4, state: peerStateReady}}, - allB: []int64{1, 2, 3, 4}, + allB: []uint64{1, 2, 3, 4}, }, args: args{height: 5}, wantResult: "", @@ -1276,7 +1276,7 @@ func TestScSelectPeer(t *testing.T) { { name: "one Ready equal peer", fields: scTestParams{peers: map[string]*scPeer{"P1": {height: 4, state: peerStateReady}}, - allB: []int64{1, 2, 3, 4}, + allB: []uint64{1, 2, 3, 4}, }, args: args{height: 4}, wantResult: "P1", @@ -1284,7 +1284,7 @@ func TestScSelectPeer(t *testing.T) { { name: "one Ready higher peer", fields: scTestParams{peers: map[string]*scPeer{"P1": {height: 6, state: peerStateReady}}, - allB: []int64{1, 2, 3, 4, 5, 6}, + allB: []uint64{1, 2, 3, 4, 5, 6}, }, args: args{height: 4}, wantResult: "P1", @@ -1293,7 +1293,7 @@ func TestScSelectPeer(t *testing.T) { name: "one Ready higher peer with higher base", fields: scTestParams{ peers: map[string]*scPeer{"P1": {base: 4, height: 6, state: peerStateReady}}, - allB: []int64{1, 2, 3, 4, 5, 6}, + allB: []uint64{1, 2, 3, 4, 5, 6}, }, args: args{height: 3}, wantResult: "", @@ -1306,8 +1306,8 @@ func TestScSelectPeer(t *testing.T) { peers: map[string]*scPeer{ "P1": {height: 8, state: peerStateReady}, "P2": {height: 9, state: peerStateReady}}, - allB: []int64{4, 5, 6, 7, 8, 9}, - pending: map[int64]p2p.NodeID{ + allB: []uint64{4, 5, 6, 7, 8, 9}, + pending: map[uint64]p2p.NodeID{ 4: "P1", 6: "P1", 5: "P2", }, @@ -1322,8 +1322,8 @@ func TestScSelectPeer(t *testing.T) { "P2": {height: 20, state: peerStateReady}, "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.NodeID{ + allB: []uint64{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, + pending: map[uint64]p2p.NodeID{ 1: "P1", 2: "P1", 3: "P3", 4: "P3", 5: "P2", 6: "P2", @@ -1349,7 +1349,7 @@ func TestScSelectPeer(t *testing.T) { } // makeScBlock makes an empty block. -func makeScBlock(height int64) *types.Block { +func makeScBlock(height uint64) *types.Block { return &types.Block{Header: types.Header{Height: height}} } @@ -1424,7 +1424,7 @@ func TestScHandleBlockResponse(t *testing.T) { name: "block we haven't asked for", fields: scTestParams{ peers: map[string]*scPeer{"P1": {height: 8, state: peerStateReady}}, - allB: []int64{1, 2, 3, 4, 5, 6, 7, 8}}, + allB: []uint64{1, 2, 3, 4, 5, 6, 7, 8}}, args: args{event: block6FromP1}, wantEvent: scPeerError{peerID: "P1", reason: fmt.Errorf("some error")}, }, @@ -1432,9 +1432,9 @@ func TestScHandleBlockResponse(t *testing.T) { name: "block from wrong peer", 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.NodeID{6: "P2"}, - pendingTime: map[int64]time.Time{6: now}, + allB: []uint64{1, 2, 3, 4, 5, 6, 7, 8}, + pending: map[uint64]p2p.NodeID{6: "P2"}, + pendingTime: map[uint64]time.Time{6: now}, }, args: args{event: block6FromP1}, wantEvent: noOpEvent{}, @@ -1443,9 +1443,9 @@ func TestScHandleBlockResponse(t *testing.T) { name: "block with bad timestamp", 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.NodeID{6: "P1"}, - pendingTime: map[int64]time.Time{6: now.Add(time.Second)}, + allB: []uint64{1, 2, 3, 4, 5, 6, 7, 8}, + pending: map[uint64]p2p.NodeID{6: "P1"}, + pendingTime: map[uint64]time.Time{6: now.Add(time.Second)}, }, args: args{event: block6FromP1}, wantEvent: scPeerError{peerID: "P1", reason: fmt.Errorf("some error")}, @@ -1454,9 +1454,9 @@ func TestScHandleBlockResponse(t *testing.T) { name: "good block, accept", 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.NodeID{6: "P1"}, - pendingTime: map[int64]time.Time{6: now}, + allB: []uint64{1, 2, 3, 4, 5, 6, 7, 8}, + pending: map[uint64]p2p.NodeID{6: "P1"}, + pendingTime: map[uint64]time.Time{6: now}, }, args: args{event: block6FromP1}, wantEvent: scBlockReceived{peerID: "P1", block: block6FromP1.block}, @@ -1504,7 +1504,7 @@ func TestScHandleNoBlockResponse(t *testing.T) { name: "for block we haven't asked for", fields: scTestParams{ peers: map[string]*scPeer{"P1": {height: 8, state: peerStateReady}}, - allB: []int64{1, 2, 3, 4, 5, 6, 7, 8}}, + allB: []uint64{1, 2, 3, 4, 5, 6, 7, 8}}, wantEvent: scPeerError{peerID: "P1", reason: fmt.Errorf("some error")}, wantFields: scTestParams{peers: map[string]*scPeer{"P1": {height: 8, state: peerStateRemoved}}}, }, @@ -1512,25 +1512,25 @@ func TestScHandleNoBlockResponse(t *testing.T) { name: "noBlock from peer we don't have", 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.NodeID{6: "P2"}, - pendingTime: map[int64]time.Time{6: now}, + allB: []uint64{1, 2, 3, 4, 5, 6, 7, 8}, + pending: map[uint64]p2p.NodeID{6: "P2"}, + pendingTime: map[uint64]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.NodeID{6: "P2"}, - pendingTime: map[int64]time.Time{6: now}, + allB: []uint64{1, 2, 3, 4, 5, 6, 7, 8}, + pending: map[uint64]p2p.NodeID{6: "P2"}, + pendingTime: map[uint64]time.Time{6: now}, }, }, { name: "noBlock from existing peer", 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.NodeID{6: "P1"}, - pendingTime: map[int64]time.Time{6: now}, + allB: []uint64{1, 2, 3, 4, 5, 6, 7, 8}, + pending: map[uint64]p2p.NodeID{6: "P1"}, + pendingTime: map[uint64]time.Time{6: now}, }, wantEvent: scPeerError{peerID: "P1", reason: fmt.Errorf("some error")}, wantFields: scTestParams{peers: map[string]*scPeer{"P1": {height: 8, state: peerStateRemoved}}}, @@ -1578,9 +1578,9 @@ func TestScHandleBlockProcessed(t *testing.T) { fields: scTestParams{ initHeight: 6, peers: map[string]*scPeer{"P1": {height: 8, state: peerStateReady}}, - allB: []int64{6, 7, 8}, - pending: map[int64]p2p.NodeID{6: "P1"}, - pendingTime: map[int64]time.Time{6: now}, + allB: []uint64{6, 7, 8}, + pending: map[uint64]p2p.NodeID{6: "P1"}, + pendingTime: map[uint64]time.Time{6: now}, }, args: args{event: processed6FromP1}, wantEvent: noOpEvent{}, @@ -1590,8 +1590,8 @@ func TestScHandleBlockProcessed(t *testing.T) { fields: scTestParams{ initHeight: 6, peers: map[string]*scPeer{"P1": {height: 7, state: peerStateReady}}, - allB: []int64{6, 7}, - received: map[int64]p2p.NodeID{6: "P1", 7: "P1"}, + allB: []uint64{6, 7}, + received: map[uint64]p2p.NodeID{6: "P1", 7: "P1"}, }, args: args{event: processed6FromP1}, wantEvent: scFinishedEv{}, @@ -1601,9 +1601,9 @@ func TestScHandleBlockProcessed(t *testing.T) { fields: scTestParams{ initHeight: 6, peers: map[string]*scPeer{"P1": {height: 8, state: peerStateReady}}, - allB: []int64{6, 7, 8}, - pending: map[int64]p2p.NodeID{7: "P1", 8: "P1"}, - received: map[int64]p2p.NodeID{6: "P1"}, + allB: []uint64{6, 7, 8}, + pending: map[uint64]p2p.NodeID{7: "P1", 8: "P1"}, + received: map[uint64]p2p.NodeID{6: "P1"}, }, args: args{event: processed6FromP1}, wantEvent: noOpEvent{}, @@ -1645,9 +1645,9 @@ func TestScHandleBlockVerificationFailure(t *testing.T) { fields: scTestParams{ initHeight: 6, peers: map[string]*scPeer{"P1": {height: 8, state: peerStateReady}}, - allB: []int64{6, 7, 8}, - pending: map[int64]p2p.NodeID{6: "P1"}, - pendingTime: map[int64]time.Time{6: now}, + allB: []uint64{6, 7, 8}, + pending: map[uint64]p2p.NodeID{6: "P1"}, + pendingTime: map[uint64]time.Time{6: now}, }, args: args{event: pcBlockVerificationFailure{height: 10, firstPeerID: "P1", secondPeerID: "P1"}}, wantEvent: scFinishedEv{}, @@ -1657,9 +1657,9 @@ func TestScHandleBlockVerificationFailure(t *testing.T) { fields: scTestParams{ 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.NodeID{6: "P1"}, - pendingTime: map[int64]time.Time{6: now}, + allB: []uint64{6, 7, 8}, + pending: map[uint64]p2p.NodeID{6: "P1"}, + pendingTime: map[uint64]time.Time{6: now}, }, args: args{event: pcBlockVerificationFailure{height: 10, firstPeerID: "P1", secondPeerID: "P1"}}, wantEvent: noOpEvent{}, @@ -1669,8 +1669,8 @@ func TestScHandleBlockVerificationFailure(t *testing.T) { fields: scTestParams{ initHeight: 6, peers: map[string]*scPeer{"P1": {height: 7, state: peerStateReady}}, - allB: []int64{6, 7}, - received: map[int64]p2p.NodeID{6: "P1", 7: "P1"}, + allB: []uint64{6, 7}, + received: map[uint64]p2p.NodeID{6: "P1", 7: "P1"}, }, args: args{event: pcBlockVerificationFailure{height: 7, firstPeerID: "P1", secondPeerID: "P1"}}, wantEvent: scFinishedEv{}, @@ -1680,9 +1680,9 @@ func TestScHandleBlockVerificationFailure(t *testing.T) { fields: scTestParams{ 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.NodeID{7: "P1", 8: "P1"}, - received: map[int64]p2p.NodeID{5: "P1", 6: "P1"}, + allB: []uint64{5, 6, 7, 8}, + pending: map[uint64]p2p.NodeID{7: "P1", 8: "P1"}, + received: map[uint64]p2p.NodeID{5: "P1", 6: "P1"}, }, args: args{event: pcBlockVerificationFailure{height: 5, firstPeerID: "P1", secondPeerID: "P1"}}, wantEvent: noOpEvent{}, @@ -1696,9 +1696,9 @@ func TestScHandleBlockVerificationFailure(t *testing.T) { "P2": {height: 8, state: peerStateReady}, "P3": {height: 8, state: peerStateReady}, }, - allB: []int64{5, 6, 7, 8}, - pending: map[int64]p2p.NodeID{7: "P1", 8: "P1"}, - received: map[int64]p2p.NodeID{5: "P1", 6: "P1"}, + allB: []uint64{5, 6, 7, 8}, + pending: map[uint64]p2p.NodeID{7: "P1", 8: "P1"}, + received: map[uint64]p2p.NodeID{5: "P1", 6: "P1"}, }, args: args{event: pcBlockVerificationFailure{height: 5, firstPeerID: "P1", secondPeerID: "P2"}}, wantEvent: noOpEvent{}, @@ -1741,7 +1741,7 @@ func TestScHandleAddNewPeer(t *testing.T) { fields: scTestParams{ initHeight: 6, peers: map[string]*scPeer{"P1": {height: 8, state: peerStateReady}}, - allB: []int64{6, 7, 8}, + allB: []uint64{6, 7, 8}, }, args: args{event: addP1}, wantEvent: noOpEvent{}, @@ -1751,7 +1751,7 @@ func TestScHandleAddNewPeer(t *testing.T) { fields: scTestParams{ initHeight: 6, peers: map[string]*scPeer{"P2": {height: 8, state: peerStateReady}}, - allB: []int64{6, 7, 8}, + allB: []uint64{6, 7, 8}, }, args: args{event: addP1}, wantEvent: noOpEvent{}, @@ -1825,7 +1825,7 @@ func TestScHandleTryPrunePeer(t *testing.T) { // V - ready, active, slow "P6": {state: peerStateReady, lastTouched: now.Add(time.Second), lastRate: 90, height: 7}, }, - allB: []int64{1, 2, 3, 4, 5, 6, 7}, + allB: []uint64{1, 2, 3, 4, 5, 6, 7}, peerTimeout: time.Second}, args: args{event: pruneEv}, wantEvent: scPeersPruned{peers: []p2p.NodeID{"P4", "P5", "P6"}}, @@ -1849,7 +1849,7 @@ func TestScHandleTryPrunePeer(t *testing.T) { // V - ready, active, slow "P6": {state: peerStateReady, lastTouched: now.Add(time.Second), lastRate: 90, height: 7}, }, - allB: []int64{6, 7}, + allB: []uint64{6, 7}, peerTimeout: time.Second}, args: args{event: pruneEv}, wantEvent: scFinishedEv{}, @@ -1890,7 +1890,7 @@ func TestScHandleTrySchedule(t *testing.T) { }, { name: "only new peers", - fields: scTestParams{startTime: now, peers: map[string]*scPeer{"P1": {height: -1, state: peerStateNew}}}, + fields: scTestParams{startTime: now, peers: map[string]*scPeer{"P1": {height: 0, state: peerStateNew}}}, args: args{event: tryEv}, wantEvent: noOpEvent{}, }, @@ -1914,7 +1914,7 @@ func TestScHandleTrySchedule(t *testing.T) { fields: scTestParams{ startTime: now, peers: map[string]*scPeer{"P1": {height: 4, state: peerStateReady}}, - allB: []int64{1, 2, 3, 4}}, + allB: []uint64{1, 2, 3, 4}}, args: args{event: tryEv}, wantEvent: scBlockRequest{peerID: "P1", height: 1}, }, @@ -1925,8 +1925,8 @@ func TestScHandleTrySchedule(t *testing.T) { peers: map[string]*scPeer{ "P1": {height: 4, state: peerStateReady}, "P2": {height: 5, state: peerStateReady}}, - allB: []int64{1, 2, 3, 4, 5}, - pending: map[int64]p2p.NodeID{ + allB: []uint64{1, 2, 3, 4, 5}, + pending: map[uint64]p2p.NodeID{ 1: "P1", 2: "P1", 3: "P2", }, @@ -1943,8 +1943,8 @@ func TestScHandleTrySchedule(t *testing.T) { "P2": {height: 8, state: peerStateReady}, "P1": {height: 8, state: peerStateReady}, "P3": {height: 8, state: peerStateReady}}, - allB: []int64{1, 2, 3, 4, 5, 6, 7, 8}, - pending: map[int64]p2p.NodeID{ + allB: []uint64{1, 2, 3, 4, 5, 6, 7, 8}, + pending: map[uint64]p2p.NodeID{ 1: "P1", 2: "P1", 3: "P3", 4: "P3", 5: "P2", 6: "P2", @@ -1987,7 +1987,7 @@ func TestScHandleStatusResponse(t *testing.T) { name: "change height of non existing peer", fields: scTestParams{ peers: map[string]*scPeer{"P2": {height: 2, state: peerStateReady}}, - allB: []int64{1, 2}, + allB: []uint64{1, 2}, }, args: args{event: statusRespP1Ev}, wantEvent: noOpEvent{}, @@ -2005,7 +2005,7 @@ func TestScHandleStatusResponse(t *testing.T) { fields: scTestParams{ height: 5, peers: map[string]*scPeer{"P1": {height: 10, state: peerStateReady}}, - allB: []int64{5, 6, 7, 8, 9, 10}, + allB: []uint64{5, 6, 7, 8, 9, 10}, }, args: args{event: statusRespP1Ev}, wantEvent: scPeerError{peerID: "P1", reason: fmt.Errorf("some error")}, @@ -2015,7 +2015,7 @@ func TestScHandleStatusResponse(t *testing.T) { name: "increase height of single peer", fields: scTestParams{ peers: map[string]*scPeer{"P1": {height: 2, state: peerStateReady}}, - allB: []int64{1, 2}}, + allB: []uint64{1, 2}}, args: args{event: statusRespP1Ev}, wantEvent: noOpEvent{}, }, @@ -2023,7 +2023,7 @@ func TestScHandleStatusResponse(t *testing.T) { name: "noop height change of single peer", fields: scTestParams{ peers: map[string]*scPeer{"P1": {height: 6, state: peerStateReady}}, - allB: []int64{1, 2, 3, 4, 5, 6}}, + allB: []uint64{1, 2, 3, 4, 5, 6}}, args: args{event: statusRespP1Ev}, wantEvent: noOpEvent{}, }, @@ -2087,7 +2087,7 @@ func TestScHandle(t *testing.T) { args: args{event: bcAddNewPeer{peerID: "P1"}}, wantEvent: noOpEvent{}, wantSc: &scTestParams{startTime: now, peers: map[string]*scPeer{ - "P1": {base: -1, height: -1, state: peerStateNew}}, height: 1}, + "P1": {base: 0, height: 0, state: peerStateNew}}, height: 1}, }, { // set height of P1 args: args{event: bcStatusResponse{peerID: "P1", time: tick[0], height: 3}}, @@ -2095,7 +2095,7 @@ func TestScHandle(t *testing.T) { wantSc: &scTestParams{ startTime: now, peers: map[string]*scPeer{"P1": {height: 3, state: peerStateReady}}, - allB: []int64{1, 2, 3}, + allB: []uint64{1, 2, 3}, height: 1, }, }, @@ -2105,9 +2105,9 @@ func TestScHandle(t *testing.T) { wantSc: &scTestParams{ startTime: now, peers: map[string]*scPeer{"P1": {height: 3, state: peerStateReady}}, - allB: []int64{1, 2, 3}, - pending: map[int64]p2p.NodeID{1: "P1"}, - pendingTime: map[int64]time.Time{1: tick[1]}, + allB: []uint64{1, 2, 3}, + pending: map[uint64]p2p.NodeID{1: "P1"}, + pendingTime: map[uint64]time.Time{1: tick[1]}, height: 1, }, }, @@ -2117,9 +2117,9 @@ func TestScHandle(t *testing.T) { wantSc: &scTestParams{ startTime: now, peers: map[string]*scPeer{"P1": {height: 3, state: peerStateReady}}, - allB: []int64{1, 2, 3}, - pending: map[int64]p2p.NodeID{1: "P1", 2: "P1"}, - pendingTime: map[int64]time.Time{1: tick[1], 2: tick[2]}, + allB: []uint64{1, 2, 3}, + pending: map[uint64]p2p.NodeID{1: "P1", 2: "P1"}, + pendingTime: map[uint64]time.Time{1: tick[1], 2: tick[2]}, height: 1, }, }, @@ -2129,9 +2129,9 @@ func TestScHandle(t *testing.T) { wantSc: &scTestParams{ startTime: now, peers: map[string]*scPeer{"P1": {height: 3, state: peerStateReady}}, - allB: []int64{1, 2, 3}, - 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]}, + allB: []uint64{1, 2, 3}, + pending: map[uint64]p2p.NodeID{1: "P1", 2: "P1", 3: "P1"}, + pendingTime: map[uint64]time.Time{1: tick[1], 2: tick[2], 3: tick[3]}, height: 1, }, }, @@ -2141,10 +2141,10 @@ func TestScHandle(t *testing.T) { wantSc: &scTestParams{ startTime: now, peers: map[string]*scPeer{"P1": {height: 3, state: peerStateReady, lastTouched: tick[4]}}, - allB: []int64{1, 2, 3}, - pending: map[int64]p2p.NodeID{2: "P1", 3: "P1"}, - pendingTime: map[int64]time.Time{2: tick[2], 3: tick[3]}, - received: map[int64]p2p.NodeID{1: "P1"}, + allB: []uint64{1, 2, 3}, + pending: map[uint64]p2p.NodeID{2: "P1", 3: "P1"}, + pendingTime: map[uint64]time.Time{2: tick[2], 3: tick[3]}, + received: map[uint64]p2p.NodeID{1: "P1"}, height: 1, }, }, @@ -2154,10 +2154,10 @@ func TestScHandle(t *testing.T) { wantSc: &scTestParams{ startTime: now, peers: map[string]*scPeer{"P1": {height: 3, state: peerStateReady, lastTouched: tick[5]}}, - allB: []int64{1, 2, 3}, - pending: map[int64]p2p.NodeID{3: "P1"}, - pendingTime: map[int64]time.Time{3: tick[3]}, - received: map[int64]p2p.NodeID{1: "P1", 2: "P1"}, + allB: []uint64{1, 2, 3}, + pending: map[uint64]p2p.NodeID{3: "P1"}, + pendingTime: map[uint64]time.Time{3: tick[3]}, + received: map[uint64]p2p.NodeID{1: "P1", 2: "P1"}, height: 1, }, }, @@ -2167,8 +2167,8 @@ func TestScHandle(t *testing.T) { wantSc: &scTestParams{ startTime: now, peers: map[string]*scPeer{"P1": {height: 3, state: peerStateReady, lastTouched: tick[6]}}, - allB: []int64{1, 2, 3}, - received: map[int64]p2p.NodeID{1: "P1", 2: "P1", 3: "P1"}, + allB: []uint64{1, 2, 3}, + received: map[uint64]p2p.NodeID{1: "P1", 2: "P1", 3: "P1"}, height: 1, }, }, @@ -2178,8 +2178,8 @@ func TestScHandle(t *testing.T) { wantSc: &scTestParams{ startTime: now, peers: map[string]*scPeer{"P1": {height: 3, state: peerStateReady, lastTouched: tick[6]}}, - allB: []int64{2, 3}, - received: map[int64]p2p.NodeID{2: "P1", 3: "P1"}, + allB: []uint64{2, 3}, + received: map[uint64]p2p.NodeID{2: "P1", 3: "P1"}, height: 2, }, }, @@ -2189,8 +2189,8 @@ func TestScHandle(t *testing.T) { wantSc: &scTestParams{ startTime: now, peers: map[string]*scPeer{"P1": {height: 3, state: peerStateReady, lastTouched: tick[6]}}, - allB: []int64{3}, - received: map[int64]p2p.NodeID{3: "P1"}, + allB: []uint64{3}, + received: map[uint64]p2p.NodeID{3: "P1"}, height: 3, }, }, @@ -2205,8 +2205,8 @@ func TestScHandle(t *testing.T) { peers: map[string]*scPeer{ "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.NodeID{1: "P1", 2: "P1", 3: "P1"}, + allB: []uint64{1, 2, 3, 4}, + received: map[uint64]p2p.NodeID{1: "P1", 2: "P1", 3: "P1"}, height: 1, }, args: args{event: pcBlockVerificationFailure{height: 1, firstPeerID: "P1", secondPeerID: "P1"}}, @@ -2216,8 +2216,8 @@ func TestScHandle(t *testing.T) { peers: map[string]*scPeer{ "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.NodeID{}, + allB: []uint64{1, 2, 3}, + received: map[uint64]p2p.NodeID{}, height: 1, }, }, diff --git a/rpc/core/env.go b/rpc/core/env.go index 93beb21e3..f10ad2f49 100644 --- a/rpc/core/env.go +++ b/rpc/core/env.go @@ -42,8 +42,8 @@ func SetEnvironment(e *Environment) { type Consensus interface { GetState() sm.State - GetValidators() (int64, []*types.Validator) - GetLastHeight() int64 + GetValidators() (uint64, []*types.Validator) + GetLastHeight() uint64 GetRoundStateJSON() ([]byte, error) GetRoundStateSimpleJSON() ([]byte, error) } diff --git a/test/maverick/consensus/state.go b/test/maverick/consensus/state.go index 4d04d0923..f649e0546 100644 --- a/test/maverick/consensus/state.go +++ b/test/maverick/consensus/state.go @@ -504,7 +504,7 @@ func (cs *State) GetState() sm.State { // GetLastHeight returns the last height committed. // If there were no blocks, returns 0. -func (cs *State) GetLastHeight() int64 { +func (cs *State) GetLastHeight() uint64 { cs.mtx.RLock() defer cs.mtx.RUnlock() return cs.RoundState.Height - 1