mirror of
https://github.com/tendermint/tendermint.git
synced 2026-09-19 22:44:24 +00:00
begin int64 to uint64 migration
This commit is contained in:
+19
-19
@@ -40,7 +40,7 @@ func NewBlockStore(db dbm.DB) *BlockStore {
|
||||
}
|
||||
|
||||
// Base returns the first known contiguous block height, or 0 for empty block stores.
|
||||
func (bs *BlockStore) Base() int64 {
|
||||
func (bs *BlockStore) Base() uint64 {
|
||||
iter, err := bs.db.Iterator(
|
||||
blockMetaKey(1),
|
||||
blockMetaKey(1<<63-1),
|
||||
@@ -64,7 +64,7 @@ func (bs *BlockStore) Base() int64 {
|
||||
}
|
||||
|
||||
// Height returns the last known contiguous block height, or 0 for empty block stores.
|
||||
func (bs *BlockStore) Height() int64 {
|
||||
func (bs *BlockStore) Height() uint64 {
|
||||
iter, err := bs.db.ReverseIterator(
|
||||
blockMetaKey(1),
|
||||
blockMetaKey(1<<63-1),
|
||||
@@ -88,7 +88,7 @@ func (bs *BlockStore) Height() int64 {
|
||||
}
|
||||
|
||||
// Size returns the number of blocks in the block store.
|
||||
func (bs *BlockStore) Size() int64 {
|
||||
func (bs *BlockStore) Size() uint64 {
|
||||
height := bs.Height()
|
||||
if height == 0 {
|
||||
return 0
|
||||
@@ -127,7 +127,7 @@ func (bs *BlockStore) LoadBaseMeta() *types.BlockMeta {
|
||||
|
||||
// LoadBlock returns the block with the given height.
|
||||
// If no block is found for that height, it returns nil.
|
||||
func (bs *BlockStore) LoadBlock(height int64) *types.Block {
|
||||
func (bs *BlockStore) LoadBlock(height uint64) *types.Block {
|
||||
var blockMeta = bs.LoadBlockMeta(height)
|
||||
if blockMeta == nil {
|
||||
return nil
|
||||
@@ -172,7 +172,7 @@ func (bs *BlockStore) LoadBlockByHash(hash []byte) *types.Block {
|
||||
}
|
||||
|
||||
s := string(bz)
|
||||
height, err := strconv.ParseInt(s, 10, 64)
|
||||
height, err := strconv.ParseUint(s, 10, 64)
|
||||
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("failed to extract height from %s: %v", s, err))
|
||||
@@ -183,7 +183,7 @@ func (bs *BlockStore) LoadBlockByHash(hash []byte) *types.Block {
|
||||
// LoadBlockPart returns the Part at the given index
|
||||
// from the block at the given height.
|
||||
// If no part is found for the given height and index, it returns nil.
|
||||
func (bs *BlockStore) LoadBlockPart(height int64, index int) *types.Part {
|
||||
func (bs *BlockStore) LoadBlockPart(height uint64, index int) *types.Part {
|
||||
var pbpart = new(tmproto.Part)
|
||||
|
||||
bz, err := bs.db.Get(blockPartKey(height, index))
|
||||
@@ -208,7 +208,7 @@ func (bs *BlockStore) LoadBlockPart(height int64, index int) *types.Part {
|
||||
|
||||
// LoadBlockMeta returns the BlockMeta for the given height.
|
||||
// If no block is found for the given height, it returns nil.
|
||||
func (bs *BlockStore) LoadBlockMeta(height int64) *types.BlockMeta {
|
||||
func (bs *BlockStore) LoadBlockMeta(height uint64) *types.BlockMeta {
|
||||
var pbbm = new(tmproto.BlockMeta)
|
||||
bz, err := bs.db.Get(blockMetaKey(height))
|
||||
|
||||
@@ -237,7 +237,7 @@ func (bs *BlockStore) LoadBlockMeta(height int64) *types.BlockMeta {
|
||||
// This commit consists of the +2/3 and other Precommit-votes for block at `height`,
|
||||
// and it comes from the block.LastCommit for `height+1`.
|
||||
// If no commit is found for the given height, it returns nil.
|
||||
func (bs *BlockStore) LoadBlockCommit(height int64) *types.Commit {
|
||||
func (bs *BlockStore) LoadBlockCommit(height uint64) *types.Commit {
|
||||
var pbc = new(tmproto.Commit)
|
||||
bz, err := bs.db.Get(blockCommitKey(height))
|
||||
if err != nil {
|
||||
@@ -260,7 +260,7 @@ func (bs *BlockStore) LoadBlockCommit(height int64) *types.Commit {
|
||||
// LoadSeenCommit returns the locally seen Commit for the given height.
|
||||
// This is useful when we've seen a commit, but there has not yet been
|
||||
// a new block at `height + 1` that includes this commit in its block.LastCommit.
|
||||
func (bs *BlockStore) LoadSeenCommit(height int64) *types.Commit {
|
||||
func (bs *BlockStore) LoadSeenCommit(height uint64) *types.Commit {
|
||||
var pbc = new(tmproto.Commit)
|
||||
bz, err := bs.db.Get(seenCommitKey(height))
|
||||
if err != nil {
|
||||
@@ -282,7 +282,7 @@ func (bs *BlockStore) LoadSeenCommit(height int64) *types.Commit {
|
||||
}
|
||||
|
||||
// PruneBlocks removes block up to (but not including) a height. It returns the number of blocks pruned.
|
||||
func (bs *BlockStore) PruneBlocks(height int64) (uint64, error) {
|
||||
func (bs *BlockStore) PruneBlocks(height uint64) (uint64, error) {
|
||||
if height <= 0 {
|
||||
return 0, fmt.Errorf("height must be greater than 0")
|
||||
}
|
||||
@@ -471,7 +471,7 @@ func (bs *BlockStore) SaveBlock(block *types.Block, blockParts *types.PartSet, s
|
||||
|
||||
}
|
||||
|
||||
func (bs *BlockStore) saveBlockPart(height int64, index int, part *types.Part) {
|
||||
func (bs *BlockStore) saveBlockPart(height uint64, index int, part *types.Part) {
|
||||
pbp, err := part.ToProto()
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("unable to make part into proto: %w", err))
|
||||
@@ -483,7 +483,7 @@ func (bs *BlockStore) saveBlockPart(height int64, index int, part *types.Part) {
|
||||
}
|
||||
|
||||
// SaveSeenCommit saves a seen commit, used by e.g. the state sync reactor when bootstrapping node.
|
||||
func (bs *BlockStore) SaveSeenCommit(height int64, seenCommit *types.Commit) error {
|
||||
func (bs *BlockStore) SaveSeenCommit(height uint64, seenCommit *types.Commit) error {
|
||||
pbc := seenCommit.ToProto()
|
||||
seenCommitBytes, err := proto.Marshal(pbc)
|
||||
if err != nil {
|
||||
@@ -504,7 +504,7 @@ const (
|
||||
prefixBlockHash = int64(4)
|
||||
)
|
||||
|
||||
func blockMetaKey(height int64) []byte {
|
||||
func blockMetaKey(height uint64) []byte {
|
||||
key, err := orderedcode.Append(nil, prefixBlockMeta, height)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
@@ -512,22 +512,22 @@ func blockMetaKey(height int64) []byte {
|
||||
return key
|
||||
}
|
||||
|
||||
func decodeBlockMetaKey(key []byte) (height int64, err error) {
|
||||
func decodeBlockMetaKey(key []byte) (height uint64, err error) {
|
||||
var prefix int64
|
||||
remaining, err := orderedcode.Parse(string(key), &prefix, &height)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if len(remaining) != 0 {
|
||||
return -1, fmt.Errorf("expected complete key but got remainder: %s", remaining)
|
||||
return 0, fmt.Errorf("expected complete key but got remainder: %s", remaining)
|
||||
}
|
||||
if prefix != prefixBlockMeta {
|
||||
return -1, fmt.Errorf("incorrect prefix. Expected %v, got %v", prefixBlockMeta, prefix)
|
||||
return 0, fmt.Errorf("incorrect prefix. Expected %v, got %v", prefixBlockMeta, prefix)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func blockPartKey(height int64, partIndex int) []byte {
|
||||
func blockPartKey(height uint64, partIndex int) []byte {
|
||||
key, err := orderedcode.Append(nil, prefixBlockPart, height, int64(partIndex))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
@@ -535,7 +535,7 @@ func blockPartKey(height int64, partIndex int) []byte {
|
||||
return key
|
||||
}
|
||||
|
||||
func blockCommitKey(height int64) []byte {
|
||||
func blockCommitKey(height uint64) []byte {
|
||||
key, err := orderedcode.Append(nil, prefixBlockCommit, height)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
@@ -543,7 +543,7 @@ func blockCommitKey(height int64) []byte {
|
||||
return key
|
||||
}
|
||||
|
||||
func seenCommitKey(height int64) []byte {
|
||||
func seenCommitKey(height uint64) []byte {
|
||||
key, err := orderedcode.Append(nil, prefixSeenCommit, height)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
||||
+10
-10
@@ -28,7 +28,7 @@ import (
|
||||
type cleanupFunc func()
|
||||
|
||||
// make a Commit with a single vote containing just the height and a timestamp
|
||||
func makeTestCommit(height int64, timestamp time.Time) *types.Commit {
|
||||
func makeTestCommit(height uint64, timestamp time.Time) *types.Commit {
|
||||
commitSigs := []types.CommitSig{{
|
||||
BlockIDFlag: types.BlockIDFlagCommit,
|
||||
ValidatorAddress: tmrand.Bytes(crypto.AddressSize),
|
||||
@@ -39,14 +39,14 @@ func makeTestCommit(height int64, timestamp time.Time) *types.Commit {
|
||||
types.BlockID{Hash: []byte(""), PartSetHeader: types.PartSetHeader{Hash: []byte(""), Total: 2}}, commitSigs)
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
@@ -100,7 +100,7 @@ func TestBlockStoreSaveLoadBlock(t *testing.T) {
|
||||
require.Equal(t, bs.Height(), int64(0), "initially the height should be zero")
|
||||
|
||||
// check there are no blocks at various heights
|
||||
noBlockHeights := []int64{0, -1, 100, 1000, 2}
|
||||
noBlockHeights := []uint64{0, 100, 1000, 2}
|
||||
for i, height := range noBlockHeights {
|
||||
if g := bs.LoadBlock(height); g != nil {
|
||||
t.Errorf("#%d: height(%d) got a block; want nil", i, height)
|
||||
@@ -309,7 +309,7 @@ func TestLoadBaseMeta(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
bs := NewBlockStore(dbm.NewMemDB())
|
||||
|
||||
for h := int64(1); h <= 10; h++ {
|
||||
for h := uint64(1); h <= 10; h++ {
|
||||
block := makeBlock(h, state, new(types.Commit))
|
||||
partSet := block.MakePartSet(2)
|
||||
seenCommit := makeTestCommit(h, tmtime.Now())
|
||||
@@ -327,7 +327,7 @@ func TestLoadBaseMeta(t *testing.T) {
|
||||
|
||||
func TestLoadBlockPart(t *testing.T) {
|
||||
bs, db := freshBlockStore()
|
||||
height, index := int64(10), 1
|
||||
height, index := uint64(10), 1
|
||||
loadPart := func() (interface{}, error) {
|
||||
part := bs.LoadBlockPart(height, index)
|
||||
return part, nil
|
||||
@@ -374,7 +374,7 @@ func TestPruneBlocks(t *testing.T) {
|
||||
require.Error(t, err)
|
||||
|
||||
// make more than 1000 blocks, to test batch deletions
|
||||
for h := int64(1); h <= 1500; h++ {
|
||||
for h := uint64(1); h <= 1500; h++ {
|
||||
block := makeBlock(h, state, new(types.Commit))
|
||||
partSet := block.MakePartSet(2)
|
||||
seenCommit := makeTestCommit(h, tmtime.Now())
|
||||
@@ -402,10 +402,10 @@ func TestPruneBlocks(t *testing.T) {
|
||||
require.Nil(t, bs.LoadBlockMeta(1199))
|
||||
require.Nil(t, bs.LoadBlockPart(1199, 1))
|
||||
|
||||
for i := int64(1); i < 1200; i++ {
|
||||
for i := uint64(1); i < 1200; i++ {
|
||||
require.Nil(t, bs.LoadBlock(i))
|
||||
}
|
||||
for i := int64(1200); i <= 1500; i++ {
|
||||
for i := uint64(1200); i <= 1500; i++ {
|
||||
require.NotNil(t, bs.LoadBlock(i))
|
||||
}
|
||||
|
||||
@@ -439,7 +439,7 @@ func TestPruneBlocks(t *testing.T) {
|
||||
|
||||
func TestLoadBlockMeta(t *testing.T) {
|
||||
bs, db := freshBlockStore()
|
||||
height := int64(10)
|
||||
height := uint64(10)
|
||||
loadMeta := func() (interface{}, error) {
|
||||
meta := bs.LoadBlockMeta(height)
|
||||
return meta, nil
|
||||
|
||||
Reference in New Issue
Block a user