make the rest of the code compile

This commit is contained in:
Callum Waters
2021-08-24 13:26:01 +02:00
parent dcf91478f8
commit 68c54f0676
283 changed files with 3874 additions and 3906 deletions
+15 -14
View File
@@ -9,8 +9,9 @@ import (
"github.com/google/orderedcode"
dbm "github.com/tendermint/tm-db"
types "github.com/tendermint/tendermint/pkg/block"
"github.com/tendermint/tendermint/pkg/metadata"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
"github.com/tendermint/tendermint/types"
)
/*
@@ -148,7 +149,7 @@ func (bs *BlockStore) LoadBlock(height int64) *types.Block {
err := proto.Unmarshal(buf, pbb)
if err != nil {
// NOTE: The existence of meta should imply the existence of the
// block. So, make sure meta is only saved after blocks are saved.
// types. So, make sure meta is only saved after blocks are saved.
panic(fmt.Sprintf("Error reading block: %v", err))
}
@@ -184,7 +185,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 int64, index int) *metadata.Part {
var pbpart = new(tmproto.Part)
bz, err := bs.db.Get(blockPartKey(height, index))
@@ -199,7 +200,7 @@ func (bs *BlockStore) LoadBlockPart(height int64, index int) *types.Part {
if err != nil {
panic(fmt.Errorf("unmarshal to tmproto.Part failed: %w", err))
}
part, err := types.PartFromProto(pbpart)
part, err := metadata.PartFromProto(pbpart)
if err != nil {
panic(fmt.Sprintf("Error reading block part: %v", err))
}
@@ -236,9 +237,9 @@ func (bs *BlockStore) LoadBlockMeta(height int64) *types.BlockMeta {
// LoadBlockCommit returns the Commit for the given height.
// 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`.
// and it comes from the types.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 int64) *metadata.Commit {
var pbc = new(tmproto.Commit)
bz, err := bs.db.Get(blockCommitKey(height))
if err != nil {
@@ -251,7 +252,7 @@ func (bs *BlockStore) LoadBlockCommit(height int64) *types.Commit {
if err != nil {
panic(fmt.Errorf("error reading block commit: %w", err))
}
commit, err := types.CommitFromProto(pbc)
commit, err := metadata.CommitFromProto(pbc)
if err != nil {
panic(fmt.Sprintf("Error reading block commit: %v", err))
}
@@ -261,8 +262,8 @@ func (bs *BlockStore) LoadBlockCommit(height int64) *types.Commit {
// LoadSeenCommit returns the last locally seen Commit before being
// cannonicalized. 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() *types.Commit {
// commit in its types.LastCommit.
func (bs *BlockStore) LoadSeenCommit() *metadata.Commit {
var pbc = new(tmproto.Commit)
bz, err := bs.db.Get(seenCommitKey())
if err != nil {
@@ -276,7 +277,7 @@ func (bs *BlockStore) LoadSeenCommit() *types.Commit {
panic(fmt.Sprintf("error reading block seen commit: %v", err))
}
commit, err := types.CommitFromProto(pbc)
commit, err := metadata.CommitFromProto(pbc)
if err != nil {
panic(fmt.Errorf("error from proto commit: %w", err))
}
@@ -426,7 +427,7 @@ func (bs *BlockStore) batchDelete(
// If all the nodes restart after committing a block,
// we need this to reload the precommits to catch-up nodes to the
// most recent height. Otherwise they'd stall at H-1.
func (bs *BlockStore) SaveBlock(block *types.Block, blockParts *types.PartSet, seenCommit *types.Commit) {
func (bs *BlockStore) SaveBlock(block *types.Block, blockParts *metadata.PartSet, seenCommit *metadata.Commit) {
if block == nil {
panic("BlockStore can only save a non-nil block")
}
@@ -489,7 +490,7 @@ func (bs *BlockStore) SaveBlock(block *types.Block, blockParts *types.PartSet, s
}
}
func (bs *BlockStore) saveBlockPart(height int64, index int, part *types.Part, batch dbm.Batch) {
func (bs *BlockStore) saveBlockPart(height int64, index int, part *metadata.Part, batch dbm.Batch) {
pbp, err := part.ToProto()
if err != nil {
panic(fmt.Errorf("unable to make part into proto: %w", err))
@@ -501,7 +502,7 @@ func (bs *BlockStore) saveBlockPart(height int64, index int, part *types.Part, b
}
// 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 int64, seenCommit *metadata.Commit) error {
pbc := seenCommit.ToProto()
seenCommitBytes, err := proto.Marshal(pbc)
if err != nil {
@@ -510,7 +511,7 @@ func (bs *BlockStore) SaveSeenCommit(height int64, seenCommit *types.Commit) err
return bs.db.Set(seenCommitKey(), seenCommitBytes)
}
func (bs *BlockStore) SaveSignedHeader(sh *types.SignedHeader, blockID types.BlockID) error {
func (bs *BlockStore) SaveSignedHeader(sh *metadata.SignedHeader, blockID metadata.BlockID) error {
// first check that the block store doesn't already have the block
bz, err := bs.db.Get(blockMetaKey(sh.Height))
if err != nil {
+28 -27
View File
@@ -17,9 +17,10 @@ import (
"github.com/tendermint/tendermint/libs/log"
tmrand "github.com/tendermint/tendermint/libs/rand"
tmtime "github.com/tendermint/tendermint/libs/time"
types "github.com/tendermint/tendermint/pkg/block"
"github.com/tendermint/tendermint/pkg/metadata"
sm "github.com/tendermint/tendermint/state"
"github.com/tendermint/tendermint/state/test/factory"
"github.com/tendermint/tendermint/types"
"github.com/tendermint/tendermint/version"
)
@@ -28,19 +29,19 @@ 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 {
commitSigs := []types.CommitSig{{
BlockIDFlag: types.BlockIDFlagCommit,
func makeTestCommit(height int64, timestamp time.Time) *metadata.Commit {
commitSigs := []metadata.CommitSig{{
BlockIDFlag: metadata.BlockIDFlagCommit,
ValidatorAddress: tmrand.Bytes(crypto.AddressSize),
Timestamp: timestamp,
Signature: []byte("Signature"),
}}
return types.NewCommit(
return metadata.NewCommit(
height,
0,
types.BlockID{
metadata.BlockID{
Hash: crypto.CRandBytes(32),
PartSetHeader: types.PartSetHeader{Hash: crypto.CRandBytes(32), Total: 2},
PartSetHeader: metadata.PartSetHeader{Hash: crypto.CRandBytes(32), Total: 2},
},
commitSigs)
}
@@ -63,16 +64,16 @@ func freshBlockStore() (*BlockStore, dbm.DB) {
var (
state sm.State
block *types.Block
partSet *types.PartSet
part1 *types.Part
part2 *types.Part
seenCommit1 *types.Commit
partSet *metadata.PartSet
part1 *metadata.Part
part2 *metadata.Part
seenCommit1 *metadata.Commit
)
func TestMain(m *testing.M) {
var cleanup cleanupFunc
state, _, cleanup = makeStateAndBlockStore(log.NewNopLogger())
block = factory.MakeBlock(state, 1, new(types.Commit))
block = factory.MakeBlock(state, 1, new(metadata.Commit))
partSet = block.MakePartSet(2)
part1 = partSet.GetPart(0)
part2 = partSet.GetPart(1)
@@ -98,19 +99,19 @@ func TestBlockStoreSaveLoadBlock(t *testing.T) {
}
// save a block
block := factory.MakeBlock(state, bs.Height()+1, new(types.Commit))
block := factory.MakeBlock(state, bs.Height()+1, new(metadata.Commit))
validPartSet := block.MakePartSet(2)
seenCommit := makeTestCommit(10, tmtime.Now())
bs.SaveBlock(block, partSet, seenCommit)
require.EqualValues(t, 1, bs.Base(), "expecting the new height to be changed")
require.EqualValues(t, block.Header.Height, bs.Height(), "expecting the new height to be changed")
incompletePartSet := types.NewPartSetFromHeader(types.PartSetHeader{Total: 2})
uncontiguousPartSet := types.NewPartSetFromHeader(types.PartSetHeader{Total: 0})
incompletePartSet := metadata.NewPartSetFromHeader(metadata.PartSetHeader{Total: 2})
uncontiguousPartSet := metadata.NewPartSetFromHeader(metadata.PartSetHeader{Total: 0})
_, err := uncontiguousPartSet.AddPart(part2)
require.Error(t, err)
header1 := types.Header{
header1 := metadata.Header{
Version: version.Consensus{Block: version.BlockProtocol},
Height: 1,
ChainID: "block_test",
@@ -122,8 +123,8 @@ func TestBlockStoreSaveLoadBlock(t *testing.T) {
commitAtH10 := makeTestCommit(10, tmtime.Now())
tuples := []struct {
block *types.Block
parts *types.PartSet
seenCommit *types.Commit
parts *metadata.PartSet
seenCommit *metadata.Commit
wantPanic string
wantErr bool
@@ -146,7 +147,7 @@ func TestBlockStoreSaveLoadBlock(t *testing.T) {
{
block: newBlock( // New block at height 5 in empty block store is fine
types.Header{
metadata.Header{
Version: version.Consensus{Block: version.BlockProtocol},
Height: 5,
ChainID: "block_test",
@@ -210,10 +211,10 @@ func TestBlockStoreSaveLoadBlock(t *testing.T) {
type quad struct {
block *types.Block
commit *types.Commit
commit *metadata.Commit
meta *types.BlockMeta
seenCommit *types.Commit
seenCommit *metadata.Commit
}
for i, tuple := range tuples {
@@ -299,7 +300,7 @@ func TestLoadBaseMeta(t *testing.T) {
bs := NewBlockStore(dbm.NewMemDB())
for h := int64(1); h <= 10; h++ {
block := factory.MakeBlock(state, h, new(types.Commit))
block := factory.MakeBlock(state, h, new(metadata.Commit))
partSet := block.MakePartSet(2)
seenCommit := makeTestCommit(h, tmtime.Now())
bs.SaveBlock(block, partSet, seenCommit)
@@ -343,7 +344,7 @@ func TestLoadBlockPart(t *testing.T) {
gotPart, _, panicErr := doFn(loadPart)
require.Nil(t, panicErr, "an existent and proper block should not panic")
require.Nil(t, res, "a properly saved block should return a proper block")
require.Equal(t, gotPart.(*types.Part), part1,
require.Equal(t, gotPart.(*metadata.Part), part1,
"expecting successful retrieval of previously saved block")
}
@@ -363,7 +364,7 @@ func TestPruneBlocks(t *testing.T) {
// make more than 1000 blocks, to test batch deletions
for h := int64(1); h <= 1500; h++ {
block := factory.MakeBlock(state, h, new(types.Commit))
block := factory.MakeBlock(state, h, new(metadata.Commit))
partSet := block.MakePartSet(2)
seenCommit := makeTestCommit(h, tmtime.Now())
bs.SaveBlock(block, partSet, seenCommit)
@@ -447,7 +448,7 @@ func TestLoadBlockMeta(t *testing.T) {
require.Contains(t, panicErr.Error(), "unmarshal to tmproto.BlockMeta")
// 3. A good blockMeta serialized and saved to the DB should be retrievable
meta := &types.BlockMeta{Header: types.Header{
meta := &types.BlockMeta{Header: metadata.Header{
Version: version.Consensus{
Block: version.BlockProtocol, App: 0}, Height: 1, ProposerAddress: tmrand.Bytes(crypto.AddressSize)}}
pbm := meta.ToProto()
@@ -468,7 +469,7 @@ func TestBlockFetchAtHeight(t *testing.T) {
state, bs, cleanup := makeStateAndBlockStore(log.NewNopLogger())
defer cleanup()
require.Equal(t, bs.Height(), int64(0), "initially the height should be zero")
block := factory.MakeBlock(state, bs.Height()+1, new(types.Commit))
block := factory.MakeBlock(state, bs.Height()+1, new(metadata.Commit))
partSet := block.MakePartSet(2)
seenCommit := makeTestCommit(10, tmtime.Now())
@@ -547,7 +548,7 @@ func doFn(fn func() (interface{}, error)) (res interface{}, err error, panicErr
return res, err, panicErr
}
func newBlock(hdr types.Header, lastCommit *types.Commit) *types.Block {
func newBlock(hdr metadata.Header, lastCommit *metadata.Commit) *types.Block {
return &types.Block{
Header: hdr,
LastCommit: lastCommit,