mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-30 05:01:44 +00:00
use rand.Int63n, remove underflow check, remove unnecessary cast
This commit is contained in:
@ -23,7 +23,7 @@ func makePeers(numPeers int, minHeight, maxHeight int64) map[string]testPeer {
|
|||||||
peers := make(map[string]testPeer, numPeers)
|
peers := make(map[string]testPeer, numPeers)
|
||||||
for i := 0; i < numPeers; i++ {
|
for i := 0; i < numPeers; i++ {
|
||||||
peerID := cmn.RandStr(12)
|
peerID := cmn.RandStr(12)
|
||||||
height := minHeight + int64(rand.Intn(int(maxHeight-minHeight)))
|
height := minHeight + rand.Int63n(maxHeight-minHeight)
|
||||||
peers[peerID] = testPeer{peerID, height}
|
peers[peerID] = testPeer{peerID, height}
|
||||||
}
|
}
|
||||||
return peers
|
return peers
|
||||||
|
@ -74,9 +74,7 @@ func BlockchainInfo(minHeight, maxHeight int64) (*ctypes.ResultBlockchainInfo, e
|
|||||||
|
|
||||||
// maximum 20 block metas
|
// maximum 20 block metas
|
||||||
const limit int64 = 20
|
const limit int64 = 20
|
||||||
if maxHeight >= limit { // to prevent underflow
|
minHeight = cmn.MaxInt64(minHeight, maxHeight-limit)
|
||||||
minHeight = cmn.MaxInt64(minHeight, maxHeight-limit)
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.Debug("BlockchainInfoHandler", "maxHeight", maxHeight, "minHeight", minHeight)
|
logger.Debug("BlockchainInfoHandler", "maxHeight", maxHeight, "minHeight", minHeight)
|
||||||
|
|
||||||
|
@ -88,8 +88,8 @@ func Tx(hash []byte, prove bool) (*ctypes.ResultTx, error) {
|
|||||||
|
|
||||||
var proof types.TxProof
|
var proof types.TxProof
|
||||||
if prove {
|
if prove {
|
||||||
// TODO: handle overflow
|
|
||||||
block := blockStore.LoadBlock(height)
|
block := blockStore.LoadBlock(height)
|
||||||
|
// TODO: handle overflow
|
||||||
proof = block.Data.Txs.Proof(index)
|
proof = block.Data.Txs.Proof(index)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -187,8 +187,8 @@ func TxSearch(query string, prove bool) ([]*ctypes.ResultTx, error) {
|
|||||||
index := r.Index
|
index := r.Index
|
||||||
|
|
||||||
if prove {
|
if prove {
|
||||||
// TODO: handle overflow
|
|
||||||
block := blockStore.LoadBlock(height)
|
block := blockStore.LoadBlock(height)
|
||||||
|
// TODO: handle overflow
|
||||||
proof = block.Data.Txs.Proof(int(index))
|
proof = block.Data.Txs.Proof(int(index))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ func (valSet *ValidatorSet) IncrementAccum(times int) {
|
|||||||
// Add VotingPower * times to each validator and order into heap.
|
// Add VotingPower * times to each validator and order into heap.
|
||||||
validatorsHeap := cmn.NewHeap()
|
validatorsHeap := cmn.NewHeap()
|
||||||
for _, val := range valSet.Validators {
|
for _, val := range valSet.Validators {
|
||||||
val.Accum += int64(val.VotingPower) * int64(times) // TODO: mind overflow
|
val.Accum += val.VotingPower * int64(times) // TODO: mind overflow
|
||||||
validatorsHeap.Push(val, accumComparable{val})
|
validatorsHeap.Push(val, accumComparable{val})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user