begin int64 to uint64 migration

This commit is contained in:
Marko Baricevic
2021-02-01 17:23:39 +01:00
parent fc71882f74
commit 0e477c014d
63 changed files with 731 additions and 753 deletions
+1 -1
View File
@@ -348,7 +348,7 @@ func (c *baseRPCClient) ConsensusState(ctx context.Context) (*ctypes.ResultConse
func (c *baseRPCClient) ConsensusParams(
ctx context.Context,
height *int64,
height *uint64,
) (*ctypes.ResultConsensusParams, error) {
result := new(ctypes.ResultConsensusParams)
params := make(map[string]interface{})
+1 -1
View File
@@ -91,7 +91,7 @@ type NetworkClient interface {
NetInfo(context.Context) (*ctypes.ResultNetInfo, error)
DumpConsensusState(context.Context) (*ctypes.ResultDumpConsensusState, error)
ConsensusState(context.Context) (*ctypes.ResultConsensusState, error)
ConsensusParams(ctx context.Context, height *int64) (*ctypes.ResultConsensusParams, error)
ConsensusParams(ctx context.Context, height *uint64) (*ctypes.ResultConsensusParams, error)
Health(context.Context) (*ctypes.ResultHealth, error)
}
+9 -9
View File
@@ -19,8 +19,8 @@ import (
// order (highest first).
//
// More: https://docs.tendermint.com/master/rpc/#/Info/blockchain
func BlockchainInfo(ctx *rpctypes.Context, minHeight, maxHeight int64) (*ctypes.ResultBlockchainInfo, error) {
const limit int64 = 20
func BlockchainInfo(ctx *rpctypes.Context, minHeight, maxHeight uint64) (*ctypes.ResultBlockchainInfo, error) {
const limit uint64 = 20
var err error
minHeight, maxHeight, err = filterMinMax(
@@ -50,7 +50,7 @@ func BlockchainInfo(ctx *rpctypes.Context, minHeight, maxHeight int64) (*ctypes.
// error if either min or max are negative or min > max
// if 0, use blockstore base for min, latest block height for max
// enforce limit.
func filterMinMax(base, height, min, max, limit int64) (int64, int64, error) {
func filterMinMax(base, height, min, max, limit uint64) (uint64, uint64, error) {
// filter negatives
if min < 0 || max < 0 {
return min, max, fmt.Errorf("heights must be non-negative")
@@ -65,14 +65,14 @@ func filterMinMax(base, height, min, max, limit int64) (int64, int64, error) {
}
// limit max to the height
max = tmmath.MinInt64(height, max)
max = tmmath.MinUint64(height, max)
// limit min to the base
min = tmmath.MaxInt64(base, min)
min = tmmath.MaxUint64(base, min)
// limit min to within `limit` of max
// so the total number of blocks returned will be `limit`
min = tmmath.MaxInt64(min, max-limit+1)
min = tmmath.MaxUint64(min, max-limit+1)
if min > max {
return min, max, fmt.Errorf("min height %d can't be greater than max height %d", min, max)
@@ -83,7 +83,7 @@ func filterMinMax(base, height, min, max, limit int64) (int64, int64, error) {
// Block gets block at a given height.
// If no height is provided, it will fetch the latest block.
// More: https://docs.tendermint.com/master/rpc/#/Info/block
func Block(ctx *rpctypes.Context, heightPtr *int64) (*ctypes.ResultBlock, error) {
func Block(ctx *rpctypes.Context, heightPtr *uint64) (*ctypes.ResultBlock, error) {
height, err := getHeight(env.BlockStore.Height(), heightPtr)
if err != nil {
return nil, err
@@ -112,7 +112,7 @@ func BlockByHash(ctx *rpctypes.Context, hash []byte) (*ctypes.ResultBlock, error
// Commit gets block commit at a given height.
// If no height is provided, it will fetch the commit for the latest block.
// More: https://docs.tendermint.com/master/rpc/#/Info/commit
func Commit(ctx *rpctypes.Context, heightPtr *int64) (*ctypes.ResultCommit, error) {
func Commit(ctx *rpctypes.Context, heightPtr *uint64) (*ctypes.ResultCommit, error) {
height, err := getHeight(env.BlockStore.Height(), heightPtr)
if err != nil {
return nil, err
@@ -143,7 +143,7 @@ func Commit(ctx *rpctypes.Context, heightPtr *int64) (*ctypes.ResultCommit, erro
// Thus response.results.deliver_tx[5] is the results of executing
// getBlock(h).Txs[5]
// More: https://docs.tendermint.com/master/rpc/#/Info/block_results
func BlockResults(ctx *rpctypes.Context, heightPtr *int64) (*ctypes.ResultBlockResults, error) {
func BlockResults(ctx *rpctypes.Context, heightPtr *uint64) (*ctypes.ResultBlockResults, error) {
height, err := getHeight(env.BlockStore.Height(), heightPtr)
if err != nil {
return nil, err
+16 -20
View File
@@ -19,9 +19,9 @@ import (
func TestBlockchainInfo(t *testing.T) {
cases := []struct {
min, max int64
base, height int64
limit int64
min, max uint64
base, height uint64
limit uint64
resultLength int64
wantErr bool
}{
@@ -35,9 +35,6 @@ func TestBlockchainInfo(t *testing.T) {
// negative
{1, 10, 0, 14, 10, 10, false}, // control
{-1, 10, 0, 14, 10, 0, true},
{1, -10, 0, 14, 10, 0, true},
{-9223372036854775808, -9223372036854775788, 0, 100, 20, 0, true},
// check base
{1, 1, 1, 1, 1, 1, false},
@@ -87,11 +84,10 @@ func TestBlockResults(t *testing.T) {
env.BlockStore = mockBlockStore{height: 100}
testCases := []struct {
height int64
height uint64
wantErr bool
wantRes *ctypes.ResultBlockResults
}{
{-1, true, nil},
{0, true, nil},
{101, true, nil},
{100, false, &ctypes.ResultBlockResults{
@@ -116,19 +112,19 @@ func TestBlockResults(t *testing.T) {
}
type mockBlockStore struct {
height int64
height uint64
}
func (mockBlockStore) Base() int64 { return 1 }
func (store mockBlockStore) Height() int64 { return store.height }
func (store mockBlockStore) Size() int64 { return store.height }
func (mockBlockStore) LoadBaseMeta() *types.BlockMeta { return nil }
func (mockBlockStore) LoadBlockMeta(height int64) *types.BlockMeta { return nil }
func (mockBlockStore) LoadBlock(height int64) *types.Block { return nil }
func (mockBlockStore) LoadBlockByHash(hash []byte) *types.Block { return nil }
func (mockBlockStore) LoadBlockPart(height int64, index int) *types.Part { return nil }
func (mockBlockStore) LoadBlockCommit(height int64) *types.Commit { return nil }
func (mockBlockStore) LoadSeenCommit(height int64) *types.Commit { return nil }
func (mockBlockStore) PruneBlocks(height int64) (uint64, error) { return 0, nil }
func (mockBlockStore) Base() uint64 { return 1 }
func (store mockBlockStore) Height() uint64 { return store.height }
func (store mockBlockStore) Size() int64 { return int64(store.height) }
func (mockBlockStore) LoadBaseMeta() *types.BlockMeta { return nil }
func (mockBlockStore) LoadBlockMeta(height uint64) *types.BlockMeta { return nil }
func (mockBlockStore) LoadBlock(height uint64) *types.Block { return nil }
func (mockBlockStore) LoadBlockByHash(hash []byte) *types.Block { return nil }
func (mockBlockStore) LoadBlockPart(height uint64, index int) *types.Part { return nil }
func (mockBlockStore) LoadBlockCommit(height uint64) *types.Commit { return nil }
func (mockBlockStore) LoadSeenCommit(height uint64) *types.Commit { return nil }
func (mockBlockStore) PruneBlocks(height uint64) (uint64, error) { return 0, nil }
func (mockBlockStore) SaveBlock(block *types.Block, blockParts *types.PartSet, seenCommit *types.Commit) {
}
+2 -2
View File
@@ -15,7 +15,7 @@ import (
// for the validators in the set as used in computing their Merkle root.
//
// More: https://docs.tendermint.com/master/rpc/#/Info/validators
func Validators(ctx *rpctypes.Context, heightPtr *int64, pagePtr, perPagePtr *int) (*ctypes.ResultValidators, error) {
func Validators(ctx *rpctypes.Context, heightPtr *uint64, pagePtr, perPagePtr *int) (*ctypes.ResultValidators, error) {
// The latest validator that we know is the NextValidator of the last block.
height, err := getHeight(latestUncommittedHeight(), heightPtr)
if err != nil {
@@ -90,7 +90,7 @@ func ConsensusState(ctx *rpctypes.Context) (*ctypes.ResultConsensusState, error)
// ConsensusParams gets the consensus parameters at the given block height.
// If no height is provided, it will fetch the latest consensus params.
// More: https://docs.tendermint.com/master/rpc/#/Info/consensus_params
func ConsensusParams(ctx *rpctypes.Context, heightPtr *int64) (*ctypes.ResultConsensusParams, error) {
func ConsensusParams(ctx *rpctypes.Context, heightPtr *uint64) (*ctypes.ResultConsensusParams, error) {
// The latest consensus params that we know is the consensus params after the
// last block.
height, err := getHeight(latestUncommittedHeight(), heightPtr)
+2 -2
View File
@@ -138,7 +138,7 @@ func validateSkipCount(page, perPage int) int {
}
// latestHeight can be either latest committed or uncommitted (+1) height.
func getHeight(latestHeight int64, heightPtr *int64) (int64, error) {
func getHeight(latestHeight uint64, heightPtr *uint64) (uint64, error) {
if heightPtr != nil {
height := *heightPtr
if height <= 0 {
@@ -158,7 +158,7 @@ func getHeight(latestHeight int64, heightPtr *int64) (int64, error) {
return latestHeight, nil
}
func latestUncommittedHeight() int64 {
func latestUncommittedHeight() uint64 {
nodeIsSyncing := env.ConsensusReactor.WaitSync()
if nodeIsSyncing {
return env.BlockStore.Height()
+1 -1
View File
@@ -14,7 +14,7 @@ import (
// More: https://docs.tendermint.com/master/rpc/#/Info/status
func Status(ctx *rpctypes.Context) (*ctypes.ResultStatus, error) {
var (
earliestBlockHeight int64
earliestBlockHeight uint64
earliestBlockHash tmbytes.HexBytes
earliestAppHash tmbytes.HexBytes
earliestBlockTimeNano int64
+8 -8
View File
@@ -14,7 +14,7 @@ import (
// List of blocks
type ResultBlockchainInfo struct {
LastHeight int64 `json:"last_height"`
LastHeight uint64 `json:"last_height"`
BlockMetas []*types.BlockMeta `json:"block_metas"`
}
@@ -37,7 +37,7 @@ type ResultCommit struct {
// ABCI results from a block
type ResultBlockResults struct {
Height int64 `json:"height"`
Height uint64 `json:"height"`
TxsResults []*abci.ResponseDeliverTx `json:"txs_results"`
BeginBlockEvents []abci.Event `json:"begin_block_events"`
EndBlockEvents []abci.Event `json:"end_block_events"`
@@ -63,12 +63,12 @@ func NewResultCommit(header *types.Header, commit *types.Commit,
type SyncInfo struct {
LatestBlockHash bytes.HexBytes `json:"latest_block_hash"`
LatestAppHash bytes.HexBytes `json:"latest_app_hash"`
LatestBlockHeight int64 `json:"latest_block_height"`
LatestBlockHeight uint64 `json:"latest_block_height"`
LatestBlockTime time.Time `json:"latest_block_time"`
EarliestBlockHash bytes.HexBytes `json:"earliest_block_hash"`
EarliestAppHash bytes.HexBytes `json:"earliest_app_hash"`
EarliestBlockHeight int64 `json:"earliest_block_height"`
EarliestBlockHeight uint64 `json:"earliest_block_height"`
EarliestBlockTime time.Time `json:"earliest_block_time"`
CatchingUp bool `json:"catching_up"`
@@ -124,7 +124,7 @@ type Peer struct {
// Validators for a height.
type ResultValidators struct {
BlockHeight int64 `json:"block_height"`
BlockHeight uint64 `json:"block_height"`
Validators []*types.Validator `json:"validators"`
// Count of actual validators in this result
Count int `json:"count"`
@@ -134,7 +134,7 @@ type ResultValidators struct {
// ConsensusParams for given height
type ResultConsensusParams struct {
BlockHeight int64 `json:"block_height"`
BlockHeight uint64 `json:"block_height"`
ConsensusParams types.ConsensusParams `json:"consensus_params"`
}
@@ -171,7 +171,7 @@ type ResultBroadcastTxCommit struct {
CheckTx abci.ResponseCheckTx `json:"check_tx"`
DeliverTx abci.ResponseDeliverTx `json:"deliver_tx"`
Hash bytes.HexBytes `json:"hash"`
Height int64 `json:"height"`
Height uint64 `json:"height"`
}
// ResultCheckTx wraps abci.ResponseCheckTx.
@@ -182,7 +182,7 @@ type ResultCheckTx struct {
// Result of querying for a tx
type ResultTx struct {
Hash bytes.HexBytes `json:"hash"`
Height int64 `json:"height"`
Height uint64 `json:"height"`
Index uint32 `json:"index"`
TxResult abci.ResponseDeliverTx `json:"tx_result"`
Tx types.Tx `json:"tx"`