mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-28 20:21:47 +00:00
int64 height
uint64 is considered dangerous. the details will follow in a blog post.
This commit is contained in:
@ -52,22 +52,22 @@ type BlockPool struct {
|
||||
|
||||
mtx sync.Mutex
|
||||
// block requests
|
||||
requesters map[uint64]*bpRequester
|
||||
height uint64 // the lowest key in requesters.
|
||||
numPending int32 // number of requests pending assignment or block response
|
||||
requesters map[int64]*bpRequester
|
||||
height int64 // the lowest key in requesters.
|
||||
numPending int32 // number of requests pending assignment or block response
|
||||
// peers
|
||||
peers map[string]*bpPeer
|
||||
maxPeerHeight uint64
|
||||
maxPeerHeight int64
|
||||
|
||||
requestsCh chan<- BlockRequest
|
||||
timeoutsCh chan<- string
|
||||
}
|
||||
|
||||
func NewBlockPool(start uint64, requestsCh chan<- BlockRequest, timeoutsCh chan<- string) *BlockPool {
|
||||
func NewBlockPool(start int64, requestsCh chan<- BlockRequest, timeoutsCh chan<- string) *BlockPool {
|
||||
bp := &BlockPool{
|
||||
peers: make(map[string]*bpPeer),
|
||||
|
||||
requesters: make(map[uint64]*bpRequester),
|
||||
requesters: make(map[int64]*bpRequester),
|
||||
height: start,
|
||||
numPending: 0,
|
||||
|
||||
@ -132,7 +132,7 @@ func (pool *BlockPool) removeTimedoutPeers() {
|
||||
}
|
||||
}
|
||||
|
||||
func (pool *BlockPool) GetStatus() (height uint64, numPending int32, lenRequesters int) {
|
||||
func (pool *BlockPool) GetStatus() (height int64, numPending int32, lenRequesters int) {
|
||||
pool.mtx.Lock()
|
||||
defer pool.mtx.Unlock()
|
||||
|
||||
@ -195,7 +195,7 @@ func (pool *BlockPool) PopRequest() {
|
||||
|
||||
// Invalidates the block at pool.height,
|
||||
// Remove the peer and redo request from others.
|
||||
func (pool *BlockPool) RedoRequest(height uint64) {
|
||||
func (pool *BlockPool) RedoRequest(height int64) {
|
||||
pool.mtx.Lock()
|
||||
defer pool.mtx.Unlock()
|
||||
|
||||
@ -233,14 +233,14 @@ func (pool *BlockPool) AddBlock(peerID string, block *types.Block, blockSize int
|
||||
}
|
||||
|
||||
// MaxPeerHeight returns the highest height reported by a peer.
|
||||
func (pool *BlockPool) MaxPeerHeight() uint64 {
|
||||
func (pool *BlockPool) MaxPeerHeight() int64 {
|
||||
pool.mtx.Lock()
|
||||
defer pool.mtx.Unlock()
|
||||
return pool.maxPeerHeight
|
||||
}
|
||||
|
||||
// Sets the peer's alleged blockchain height.
|
||||
func (pool *BlockPool) SetPeerHeight(peerID string, height uint64) {
|
||||
func (pool *BlockPool) SetPeerHeight(peerID string, height int64) {
|
||||
pool.mtx.Lock()
|
||||
defer pool.mtx.Unlock()
|
||||
|
||||
@ -279,7 +279,7 @@ func (pool *BlockPool) removePeer(peerID string) {
|
||||
|
||||
// Pick an available peer with at least the given minHeight.
|
||||
// If no peers are available, returns nil.
|
||||
func (pool *BlockPool) pickIncrAvailablePeer(minHeight uint64) *bpPeer {
|
||||
func (pool *BlockPool) pickIncrAvailablePeer(minHeight int64) *bpPeer {
|
||||
pool.mtx.Lock()
|
||||
defer pool.mtx.Unlock()
|
||||
|
||||
@ -317,11 +317,11 @@ func (pool *BlockPool) makeNextRequester() {
|
||||
}
|
||||
}
|
||||
|
||||
func (pool *BlockPool) requestersLen() uint64 {
|
||||
return uint64(len(pool.requesters))
|
||||
func (pool *BlockPool) requestersLen() int64 {
|
||||
return int64(len(pool.requesters))
|
||||
}
|
||||
|
||||
func (pool *BlockPool) sendRequest(height uint64, peerID string) {
|
||||
func (pool *BlockPool) sendRequest(height int64, peerID string) {
|
||||
if !pool.IsRunning() {
|
||||
return
|
||||
}
|
||||
@ -360,7 +360,7 @@ type bpPeer struct {
|
||||
id string
|
||||
recvMonitor *flow.Monitor
|
||||
|
||||
height uint64
|
||||
height int64
|
||||
numPending int32
|
||||
timeout *time.Timer
|
||||
didTimeout bool
|
||||
@ -368,7 +368,7 @@ type bpPeer struct {
|
||||
logger log.Logger
|
||||
}
|
||||
|
||||
func newBPPeer(pool *BlockPool, peerID string, height uint64) *bpPeer {
|
||||
func newBPPeer(pool *BlockPool, peerID string, height int64) *bpPeer {
|
||||
peer := &bpPeer{
|
||||
pool: pool,
|
||||
id: peerID,
|
||||
@ -429,7 +429,7 @@ func (peer *bpPeer) onTimeout() {
|
||||
type bpRequester struct {
|
||||
cmn.BaseService
|
||||
pool *BlockPool
|
||||
height uint64
|
||||
height int64
|
||||
gotBlockCh chan struct{}
|
||||
redoCh chan struct{}
|
||||
|
||||
@ -438,7 +438,7 @@ type bpRequester struct {
|
||||
block *types.Block
|
||||
}
|
||||
|
||||
func newBPRequester(pool *BlockPool, height uint64) *bpRequester {
|
||||
func newBPRequester(pool *BlockPool, height int64) *bpRequester {
|
||||
bpr := &bpRequester{
|
||||
pool: pool,
|
||||
height: height,
|
||||
@ -550,6 +550,6 @@ OUTER_LOOP:
|
||||
//-------------------------------------
|
||||
|
||||
type BlockRequest struct {
|
||||
Height uint64
|
||||
Height int64
|
||||
PeerID string
|
||||
}
|
||||
|
Reference in New Issue
Block a user