rename to metadata

This commit is contained in:
Callum Waters
2021-08-20 16:41:02 +02:00
parent 508b7f9758
commit beafe7d4f1
37 changed files with 342 additions and 342 deletions

View File

@@ -13,7 +13,7 @@ import (
tmmath "github.com/tendermint/tendermint/libs/math"
"github.com/tendermint/tendermint/pkg/evidence"
"github.com/tendermint/tendermint/pkg/mempool"
"github.com/tendermint/tendermint/pkg/meta"
"github.com/tendermint/tendermint/pkg/metadata"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
"github.com/tendermint/tendermint/version"
)
@@ -22,10 +22,10 @@ import (
type Block struct {
mtx tmsync.Mutex
meta.Header `json:"header"`
metadata.Header `json:"header"`
Data `json:"data"`
Evidence EvidenceData `json:"evidence"`
LastCommit *meta.Commit `json:"last_commit"`
LastCommit *metadata.Commit `json:"last_commit"`
}
// ValidateBasic performs basic validation that doesn't involve state data.
@@ -106,7 +106,7 @@ func (b *Block) Hash() tmbytes.HexBytes {
// MakePartSet returns a PartSet containing parts of a serialized block.
// This is the form in which the block is gossipped to peers.
// CONTRACT: partSize is greater than zero.
func (b *Block) MakePartSet(partSize uint32) *meta.PartSet {
func (b *Block) MakePartSet(partSize uint32) *metadata.PartSet {
if b == nil {
return nil
}
@@ -121,7 +121,7 @@ func (b *Block) MakePartSet(partSize uint32) *meta.PartSet {
if err != nil {
panic(err)
}
return meta.NewPartSetFromData(bz, partSize)
return metadata.NewPartSetFromData(bz, partSize)
}
// HashesTo is a convenience function that checks if a block hashes to the given argument.
@@ -214,7 +214,7 @@ func BlockFromProto(bp *tmproto.Block) (*Block, error) {
}
b := new(Block)
h, err := meta.HeaderFromProto(&bp.Header)
h, err := metadata.HeaderFromProto(&bp.Header)
if err != nil {
return nil, err
}
@@ -229,7 +229,7 @@ func BlockFromProto(bp *tmproto.Block) (*Block, error) {
}
if bp.LastCommit != nil {
lc, err := meta.CommitFromProto(bp.LastCommit)
lc, err := metadata.CommitFromProto(bp.LastCommit)
if err != nil {
return nil, err
}
@@ -246,9 +246,9 @@ func BlockFromProto(bp *tmproto.Block) (*Block, error) {
// XXX: Panics on negative result.
func MaxDataBytes(maxBytes, evidenceBytes int64, valsCount int) int64 {
maxDataBytes := maxBytes -
meta.MaxOverheadForBlock -
meta.MaxHeaderBytes -
meta.MaxCommitBytes(valsCount) -
metadata.MaxOverheadForBlock -
metadata.MaxHeaderBytes -
metadata.MaxCommitBytes(valsCount) -
evidenceBytes
if maxDataBytes < 0 {
@@ -269,9 +269,9 @@ func MaxDataBytes(maxBytes, evidenceBytes int64, valsCount int) int64 {
// XXX: Panics on negative result.
func MaxDataBytesNoEvidence(maxBytes int64, valsCount int) int64 {
maxDataBytes := maxBytes -
meta.MaxOverheadForBlock -
meta.MaxHeaderBytes -
meta.MaxCommitBytes(valsCount)
metadata.MaxOverheadForBlock -
metadata.MaxHeaderBytes -
metadata.MaxCommitBytes(valsCount)
if maxDataBytes < 0 {
panic(fmt.Sprintf(
@@ -287,9 +287,9 @@ func MaxDataBytesNoEvidence(maxBytes int64, valsCount int) int64 {
// MakeBlock returns a new block with an empty header, except what can be
// computed from itself.
// It populates the same set of fields validated by ValidateBasic.
func MakeBlock(height int64, txs []mempool.Tx, lastCommit *meta.Commit, evidence []evidence.Evidence) *Block {
func MakeBlock(height int64, txs []mempool.Tx, lastCommit *metadata.Commit, evidence []evidence.Evidence) *Block {
block := &Block{
Header: meta.Header{
Header: metadata.Header{
Version: version.Consensus{Block: version.BlockProtocol, App: 0},
Height: height,
},

View File

@@ -5,22 +5,22 @@ import (
"errors"
"fmt"
"github.com/tendermint/tendermint/pkg/meta"
"github.com/tendermint/tendermint/pkg/metadata"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
)
// BlockMeta contains meta information.
type BlockMeta struct {
BlockID meta.BlockID `json:"block_id"`
BlockID metadata.BlockID `json:"block_id"`
BlockSize int `json:"block_size"`
Header meta.Header `json:"header"`
Header metadata.Header `json:"header"`
NumTxs int `json:"num_txs"`
}
// NewBlockMeta returns a new BlockMeta.
func NewBlockMeta(block *Block, blockParts *meta.PartSet) *BlockMeta {
func NewBlockMeta(block *Block, blockParts *metadata.PartSet) *BlockMeta {
return &BlockMeta{
BlockID: meta.BlockID{block.Hash(), blockParts.Header()},
BlockID: metadata.BlockID{block.Hash(), blockParts.Header()},
BlockSize: block.Size(),
Header: block.Header,
NumTxs: len(block.Data.Txs),
@@ -48,12 +48,12 @@ func BlockMetaFromProto(pb *tmproto.BlockMeta) (*BlockMeta, error) {
bm := new(BlockMeta)
bi, err := meta.BlockIDFromProto(&pb.BlockID)
bi, err := metadata.BlockIDFromProto(&pb.BlockID)
if err != nil {
return nil, err
}
h, err := meta.HeaderFromProto(&pb.Header)
h, err := metadata.HeaderFromProto(&pb.Header)
if err != nil {
return nil, err
}

View File

@@ -9,12 +9,12 @@ import (
test "github.com/tendermint/tendermint/internal/test/factory"
tmrand "github.com/tendermint/tendermint/libs/rand"
"github.com/tendermint/tendermint/pkg/block"
"github.com/tendermint/tendermint/pkg/meta"
"github.com/tendermint/tendermint/pkg/metadata"
)
func TestBlockMeta_ToProto(t *testing.T) {
h := test.MakeRandomHeader()
bi := meta.BlockID{Hash: h.Hash(), PartSetHeader: meta.PartSetHeader{Total: 123, Hash: tmrand.Bytes(tmhash.Size)}}
bi := metadata.BlockID{Hash: h.Hash(), PartSetHeader: metadata.PartSetHeader{Total: 123, Hash: tmrand.Bytes(tmhash.Size)}}
bm := &block.BlockMeta{
BlockID: bi,
@@ -51,11 +51,11 @@ func TestBlockMeta_ToProto(t *testing.T) {
func TestBlockMeta_ValidateBasic(t *testing.T) {
h := test.MakeRandomHeader()
bi := meta.BlockID{Hash: h.Hash(), PartSetHeader: meta.PartSetHeader{Total: 123, Hash: tmrand.Bytes(tmhash.Size)}}
bi2 := meta.BlockID{Hash: tmrand.Bytes(tmhash.Size),
PartSetHeader: meta.PartSetHeader{Total: 123, Hash: tmrand.Bytes(tmhash.Size)}}
bi3 := meta.BlockID{Hash: []byte("incorrect hash"),
PartSetHeader: meta.PartSetHeader{Total: 123, Hash: []byte("incorrect hash")}}
bi := metadata.BlockID{Hash: h.Hash(), PartSetHeader: metadata.PartSetHeader{Total: 123, Hash: tmrand.Bytes(tmhash.Size)}}
bi2 := metadata.BlockID{Hash: tmrand.Bytes(tmhash.Size),
PartSetHeader: metadata.PartSetHeader{Total: 123, Hash: tmrand.Bytes(tmhash.Size)}}
bi3 := metadata.BlockID{Hash: []byte("incorrect hash"),
PartSetHeader: metadata.PartSetHeader{Total: 123, Hash: []byte("incorrect hash")}}
bm := &block.BlockMeta{
BlockID: bi,

View File

@@ -18,7 +18,7 @@ import (
"github.com/tendermint/tendermint/pkg/block"
"github.com/tendermint/tendermint/pkg/evidence"
"github.com/tendermint/tendermint/pkg/mempool"
"github.com/tendermint/tendermint/pkg/meta"
"github.com/tendermint/tendermint/pkg/metadata"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
)
@@ -89,7 +89,7 @@ func TestBlockValidateBasic(t *testing.T) {
blk.LastCommit = nil
}, true},
{"Invalid LastCommit", func(blk *block.Block) {
blk.LastCommit = meta.NewCommit(-1, 0, test.MakeBlockID(), nil)
blk.LastCommit = metadata.NewCommit(-1, 0, test.MakeBlockID(), nil)
}, true},
{"Invalid Evidence", func(blk *block.Block) {
emptyEv := &evidence.DuplicateVoteEvidence{}
@@ -250,7 +250,7 @@ func TestBlockMaxDataBytesNoEvidence(t *testing.T) {
func TestBlockProtoBuf(t *testing.T) {
h := mrand.Int63()
c1 := test.MakeRandomCommit(time.Now())
b1 := block.MakeBlock(h, []mempool.Tx{mempool.Tx([]byte{1})}, &meta.Commit{Signatures: []meta.CommitSig{}}, []evidence.Evidence{})
b1 := block.MakeBlock(h, []mempool.Tx{mempool.Tx([]byte{1})}, &metadata.Commit{Signatures: []metadata.CommitSig{}}, []evidence.Evidence{})
b1.ProposerAddress = tmrand.Bytes(crypto.AddressSize)
b2 := block.MakeBlock(h, []mempool.Tx{mempool.Tx([]byte{1})}, c1, []evidence.Evidence{})

View File

@@ -1,7 +1,7 @@
package consensus
import (
"github.com/tendermint/tendermint/pkg/meta"
"github.com/tendermint/tendermint/pkg/metadata"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
)
@@ -12,7 +12,7 @@ func CanonicalizeProposal(chainID string, proposal *tmproto.Proposal) tmproto.Ca
Height: proposal.Height, // encoded as sfixed64
Round: int64(proposal.Round), // encoded as sfixed64
POLRound: int64(proposal.PolRound),
BlockID: meta.CanonicalizeBlockID(proposal.BlockID),
BlockID: metadata.CanonicalizeBlockID(proposal.BlockID),
Timestamp: proposal.Timestamp,
ChainID: chainID,
}
@@ -25,7 +25,7 @@ func CanonicalizeVote(chainID string, vote *tmproto.Vote) tmproto.CanonicalVote
Type: vote.Type,
Height: vote.Height, // encoded as sfixed64
Round: int64(vote.Round), // encoded as sfixed64
BlockID: meta.CanonicalizeBlockID(vote.BlockID),
BlockID: metadata.CanonicalizeBlockID(vote.BlockID),
Timestamp: vote.Timestamp,
ChainID: chainID,
}

View File

@@ -12,7 +12,7 @@ import (
tmbytes "github.com/tendermint/tendermint/libs/bytes"
tmjson "github.com/tendermint/tendermint/libs/json"
tmtime "github.com/tendermint/tendermint/libs/time"
"github.com/tendermint/tendermint/pkg/meta"
"github.com/tendermint/tendermint/pkg/metadata"
)
//------------------------------------------------------------
@@ -66,8 +66,8 @@ func (genDoc *GenesisDoc) ValidateAndComplete() error {
if genDoc.ChainID == "" {
return errors.New("genesis doc must include non-empty chain_id")
}
if len(genDoc.ChainID) > meta.MaxChainIDLen {
return fmt.Errorf("chain_id in genesis doc is too long (max: %d)", meta.MaxChainIDLen)
if len(genDoc.ChainID) > metadata.MaxChainIDLen {
return fmt.Errorf("chain_id in genesis doc is too long (max: %d)", metadata.MaxChainIDLen)
}
if genDoc.InitialHeight < 0 {
return fmt.Errorf("initial_height cannot be negative (got %v)", genDoc.InitialHeight)

View File

@@ -10,7 +10,7 @@ import (
"github.com/tendermint/tendermint/crypto/sr25519"
"github.com/tendermint/tendermint/crypto/tmhash"
tmstrings "github.com/tendermint/tendermint/libs/strings"
"github.com/tendermint/tendermint/pkg/meta"
"github.com/tendermint/tendermint/pkg/metadata"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
)
@@ -121,16 +121,16 @@ func (val *ValidatorParams) IsValidPubkeyType(pubkeyType string) bool {
// allowed limits, and returns an error if they are not.
func (params ConsensusParams) ValidateConsensusParams() error {
if params.Block.MaxBytes <= 0 {
return fmt.Errorf("meta.MaxBytes must be greater than 0. Got %d",
return fmt.Errorf("metadata.MaxBytes must be greater than 0. Got %d",
params.Block.MaxBytes)
}
if params.Block.MaxBytes > meta.MaxBlockSizeBytes {
return fmt.Errorf("meta.MaxBytes is too big. %d > %d",
params.Block.MaxBytes, meta.MaxBlockSizeBytes)
if params.Block.MaxBytes > metadata.MaxBlockSizeBytes {
return fmt.Errorf("metadata.MaxBytes is too big. %d > %d",
params.Block.MaxBytes, metadata.MaxBlockSizeBytes)
}
if params.Block.MaxGas < -1 {
return fmt.Errorf("meta.MaxGas must be greater or equal to -1. Got %d",
return fmt.Errorf("metadata.MaxGas must be greater or equal to -1. Got %d",
params.Block.MaxGas)
}

View File

@@ -8,7 +8,7 @@ import (
"github.com/tendermint/tendermint/internal/libs/protoio"
tmbytes "github.com/tendermint/tendermint/libs/bytes"
tmtime "github.com/tendermint/tendermint/libs/time"
"github.com/tendermint/tendermint/pkg/meta"
"github.com/tendermint/tendermint/pkg/metadata"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
)
@@ -28,14 +28,14 @@ type Proposal struct {
Height int64 `json:"height"`
Round int32 `json:"round"` // there can not be greater than 2_147_483_647 rounds
POLRound int32 `json:"pol_round"` // -1 if null.
BlockID meta.BlockID `json:"block_id"`
BlockID metadata.BlockID `json:"block_id"`
Timestamp time.Time `json:"timestamp"`
Signature []byte `json:"signature"`
}
// NewProposal returns a new Proposal.
// If there is no POLRound, polRound should be -1.
func NewProposal(height int64, round int32, polRound int32, blockID meta.BlockID) *Proposal {
func NewProposal(height int64, round int32, polRound int32, blockID metadata.BlockID) *Proposal {
return &Proposal{
Type: tmproto.ProposalType,
Height: height,
@@ -74,8 +74,8 @@ func (p *Proposal) ValidateBasic() error {
return errors.New("signature is missing")
}
if len(p.Signature) > meta.MaxSignatureSize {
return fmt.Errorf("signature is too big (max: %d)", meta.MaxSignatureSize)
if len(p.Signature) > metadata.MaxSignatureSize {
return fmt.Errorf("signature is too big (max: %d)", metadata.MaxSignatureSize)
}
return nil
}
@@ -97,7 +97,7 @@ func (p *Proposal) String() string {
p.BlockID,
p.POLRound,
tmbytes.Fingerprint(p.Signature),
meta.CanonicalTime(p.Timestamp))
metadata.CanonicalTime(p.Timestamp))
}
// ProposalSignBytes returns the proto-encoding of the canonicalized Proposal,
@@ -145,7 +145,7 @@ func ProposalFromProto(pp *tmproto.Proposal) (*Proposal, error) {
p := new(Proposal)
blockID, err := meta.BlockIDFromProto(&pp.BlockID)
blockID, err := metadata.BlockIDFromProto(&pp.BlockID)
if err != nil {
return nil, err
}

View File

@@ -14,7 +14,7 @@ import (
"github.com/tendermint/tendermint/internal/libs/protoio"
tmrand "github.com/tendermint/tendermint/libs/rand"
"github.com/tendermint/tendermint/pkg/consensus"
"github.com/tendermint/tendermint/pkg/meta"
"github.com/tendermint/tendermint/pkg/metadata"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
)
@@ -24,15 +24,15 @@ var (
)
func init() {
var stamp, err = time.Parse(meta.TimeFormat, "2018-02-11T07:09:22.765Z")
var stamp, err = time.Parse(metadata.TimeFormat, "2018-02-11T07:09:22.765Z")
if err != nil {
panic(err)
}
testProposal = &consensus.Proposal{
Height: 12345,
Round: 23456,
BlockID: meta.BlockID{Hash: []byte("--June_15_2020_amino_was_removed"),
PartSetHeader: meta.PartSetHeader{Total: 111, Hash: []byte("--June_15_2020_amino_was_removed")}},
BlockID: metadata.BlockID{Hash: []byte("--June_15_2020_amino_was_removed"),
PartSetHeader: metadata.PartSetHeader{Total: 111, Hash: []byte("--June_15_2020_amino_was_removed")}},
POLRound: -1,
Timestamp: stamp,
}
@@ -64,7 +64,7 @@ func TestProposalVerifySignature(t *testing.T) {
prop := consensus.NewProposal(
4, 2, 2,
meta.BlockID{tmrand.Bytes(tmhash.Size), meta.PartSetHeader{777, tmrand.Bytes(tmhash.Size)}})
metadata.BlockID{tmrand.Bytes(tmhash.Size), metadata.PartSetHeader{777, tmrand.Bytes(tmhash.Size)}})
p := prop.ToProto()
signBytes := consensus.ProposalSignBytes("test_chain_id", p)
@@ -138,16 +138,16 @@ func TestProposalValidateBasic(t *testing.T) {
{"Invalid Round", func(p *consensus.Proposal) { p.Round = -1 }, true},
{"Invalid POLRound", func(p *consensus.Proposal) { p.POLRound = -2 }, true},
{"Invalid BlockId", func(p *consensus.Proposal) {
p.BlockID = meta.BlockID{[]byte{1, 2, 3}, meta.PartSetHeader{111, []byte("blockparts")}}
p.BlockID = metadata.BlockID{[]byte{1, 2, 3}, metadata.PartSetHeader{111, []byte("blockparts")}}
}, true},
{"Invalid Signature", func(p *consensus.Proposal) {
p.Signature = make([]byte, 0)
}, true},
{"Too big Signature", func(p *consensus.Proposal) {
p.Signature = make([]byte, meta.MaxSignatureSize+1)
p.Signature = make([]byte, metadata.MaxSignatureSize+1)
}, true},
}
blockID := meta.BlockID{tmhash.Sum([]byte("blockhash")), meta.PartSetHeader{math.MaxInt32, tmhash.Sum([]byte("partshash"))}}
blockID := metadata.BlockID{tmhash.Sum([]byte("blockhash")), metadata.PartSetHeader{math.MaxInt32, tmhash.Sum([]byte("partshash"))}}
for _, tc := range testCases {
tc := tc
@@ -166,9 +166,9 @@ func TestProposalValidateBasic(t *testing.T) {
}
func TestProposalProtoBuf(t *testing.T) {
proposal := consensus.NewProposal(1, 2, 3, meta.BlockID{[]byte("hash"), meta.PartSetHeader{2, []byte("part_set_hash")}})
proposal := consensus.NewProposal(1, 2, 3, metadata.BlockID{[]byte("hash"), metadata.PartSetHeader{2, []byte("part_set_hash")}})
proposal.Signature = []byte("sig")
proposal2 := consensus.NewProposal(1, 2, 3, meta.BlockID{})
proposal2 := consensus.NewProposal(1, 2, 3, metadata.BlockID{})
testCases := []struct {
msg string

View File

@@ -6,12 +6,12 @@ import (
"github.com/tendermint/tendermint/crypto/batch"
tmmath "github.com/tendermint/tendermint/libs/math"
"github.com/tendermint/tendermint/pkg/meta"
"github.com/tendermint/tendermint/pkg/metadata"
)
const batchVerifyThreshold = 2
func shouldBatchVerify(vals *ValidatorSet, commit *meta.Commit) bool {
func shouldBatchVerify(vals *ValidatorSet, commit *metadata.Commit) bool {
return len(commit.Signatures) >= batchVerifyThreshold && batch.SupportsBatchVerifier(vals.GetProposer().PubKey)
}
@@ -22,8 +22,8 @@ func shouldBatchVerify(vals *ValidatorSet, commit *meta.Commit) bool {
// application that depends on the LastCommitInfo sent in BeginBlock, which
// includes which validators signed. For instance, Gaia incentivizes proposers
// with a bonus for including more than +2/3 of the signatures.
func VerifyCommit(chainID string, vals *ValidatorSet, blockID meta.BlockID,
height int64, commit *meta.Commit) error {
func VerifyCommit(chainID string, vals *ValidatorSet, blockID metadata.BlockID,
height int64, commit *metadata.Commit) error {
// run a basic validation of the arguments
if err := verifyBasicValsAndCommit(vals, commit, height, blockID); err != nil {
return err
@@ -34,10 +34,10 @@ func VerifyCommit(chainID string, vals *ValidatorSet, blockID meta.BlockID,
votingPowerNeeded := vals.TotalVotingPower() * 2 / 3
// ignore all absent signatures
ignore := func(c meta.CommitSig) bool { return c.Absent() }
ignore := func(c metadata.CommitSig) bool { return c.Absent() }
// only count the signatures that are for the block
count := func(c meta.CommitSig) bool { return c.ForBlock() }
count := func(c metadata.CommitSig) bool { return c.ForBlock() }
// attempt to batch verify
if shouldBatchVerify(vals, commit) {
@@ -56,8 +56,8 @@ func VerifyCommit(chainID string, vals *ValidatorSet, blockID meta.BlockID,
//
// This method is primarily used by the light client and does not check all the
// signatures.
func VerifyCommitLight(chainID string, vals *ValidatorSet, blockID meta.BlockID,
height int64, commit *meta.Commit) error {
func VerifyCommitLight(chainID string, vals *ValidatorSet, blockID metadata.BlockID,
height int64, commit *metadata.Commit) error {
// run a basic validation of the arguments
if err := verifyBasicValsAndCommit(vals, commit, height, blockID); err != nil {
return err
@@ -67,10 +67,10 @@ func VerifyCommitLight(chainID string, vals *ValidatorSet, blockID meta.BlockID,
votingPowerNeeded := vals.TotalVotingPower() * 2 / 3
// ignore all commit signatures that are not for the block
ignore := func(c meta.CommitSig) bool { return !c.ForBlock() }
ignore := func(c metadata.CommitSig) bool { return !c.ForBlock() }
// count all the remaining signatures
count := func(c meta.CommitSig) bool { return true }
count := func(c metadata.CommitSig) bool { return true }
// attempt to batch verify
if shouldBatchVerify(vals, commit) {
@@ -91,7 +91,7 @@ func VerifyCommitLight(chainID string, vals *ValidatorSet, blockID meta.BlockID,
//
// This method is primarily used by the light client and does not check all the
// signatures.
func VerifyCommitLightTrusting(chainID string, vals *ValidatorSet, commit *meta.Commit, trustLevel tmmath.Fraction) error {
func VerifyCommitLightTrusting(chainID string, vals *ValidatorSet, commit *metadata.Commit, trustLevel tmmath.Fraction) error {
// sanity checks
if vals == nil {
return errors.New("nil validator set")
@@ -111,10 +111,10 @@ func VerifyCommitLightTrusting(chainID string, vals *ValidatorSet, commit *meta.
votingPowerNeeded := totalVotingPowerMulByNumerator / int64(trustLevel.Denominator)
// ignore all commit signatures that are not for the block
ignore := func(c meta.CommitSig) bool { return !c.ForBlock() }
ignore := func(c metadata.CommitSig) bool { return !c.ForBlock() }
// count all the remaining signatures
count := func(c meta.CommitSig) bool { return true }
count := func(c metadata.CommitSig) bool { return true }
// attempt to batch verify commit. As the validator set doesn't necessarily
// correspond with the validator set that signed the block we need to look
@@ -140,10 +140,10 @@ func VerifyCommitLightTrusting(chainID string, vals *ValidatorSet, commit *meta.
func verifyCommitBatch(
chainID string,
vals *ValidatorSet,
commit *meta.Commit,
commit *metadata.Commit,
votingPowerNeeded int64,
ignoreSig func(meta.CommitSig) bool,
countSig func(meta.CommitSig) bool,
ignoreSig func(metadata.CommitSig) bool,
countSig func(metadata.CommitSig) bool,
countAllSignatures bool,
lookUpByIndex bool,
) error {
@@ -253,10 +253,10 @@ func verifyCommitBatch(
func verifyCommitSingle(
chainID string,
vals *ValidatorSet,
commit *meta.Commit,
commit *metadata.Commit,
votingPowerNeeded int64,
ignoreSig func(meta.CommitSig) bool,
countSig func(meta.CommitSig) bool,
ignoreSig func(metadata.CommitSig) bool,
countSig func(metadata.CommitSig) bool,
countAllSignatures bool,
lookUpByIndex bool,
) error {
@@ -319,7 +319,7 @@ func verifyCommitSingle(
return nil
}
func verifyBasicValsAndCommit(vals *ValidatorSet, commit *meta.Commit, height int64, blockID meta.BlockID) error {
func verifyBasicValsAndCommit(vals *ValidatorSet, commit *metadata.Commit, height int64, blockID metadata.BlockID) error {
if vals == nil {
return errors.New("nil validator set")
}

View File

@@ -11,7 +11,7 @@ import (
test "github.com/tendermint/tendermint/internal/test/factory"
tmmath "github.com/tendermint/tendermint/libs/math"
"github.com/tendermint/tendermint/pkg/consensus"
"github.com/tendermint/tendermint/pkg/meta"
"github.com/tendermint/tendermint/pkg/metadata"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
)
@@ -32,7 +32,7 @@ func TestValidatorSet_VerifyCommit_All(t *testing.T) {
// vote chainID
chainID string
// vote blockID
blockID meta.BlockID
blockID metadata.BlockID
valSize int
// height of the commit
@@ -65,11 +65,11 @@ func TestValidatorSet_VerifyCommit_All(t *testing.T) {
t.Run(tc.description, func(t *testing.T) {
_, valSet, vals := test.RandVoteSet(tc.height, round, tmproto.PrecommitType, tc.valSize, 10)
totalVotes := tc.blockVotes + tc.absentVotes + tc.nilVotes
sigs := make([]meta.CommitSig, totalVotes)
sigs := make([]metadata.CommitSig, totalVotes)
vi := 0
// add absent sigs first
for i := 0; i < tc.absentVotes; i++ {
sigs[vi] = meta.NewCommitSigAbsent()
sigs[vi] = metadata.NewCommitSigAbsent()
vi++
}
for i := 0; i < tc.blockVotes+tc.nilVotes; i++ {
@@ -86,7 +86,7 @@ func TestValidatorSet_VerifyCommit_All(t *testing.T) {
Timestamp: time.Now(),
}
if i >= tc.blockVotes {
vote.BlockID = meta.BlockID{}
vote.BlockID = metadata.BlockID{}
}
v := vote.ToProto()
@@ -98,7 +98,7 @@ func TestValidatorSet_VerifyCommit_All(t *testing.T) {
vi++
}
commit := meta.NewCommit(tc.height, round, tc.blockID, sigs)
commit := metadata.NewCommit(tc.height, round, tc.blockID, sigs)
err := valSet.VerifyCommit(chainID, blockID, height, commit)
if tc.expErr {

View File

@@ -11,7 +11,7 @@ import (
"github.com/tendermint/tendermint/crypto/merkle"
tmmath "github.com/tendermint/tendermint/libs/math"
"github.com/tendermint/tendermint/pkg/meta"
"github.com/tendermint/tendermint/pkg/metadata"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
)
@@ -655,22 +655,22 @@ func (vals *ValidatorSet) UpdateWithChangeSet(changes []*Validator) error {
// VerifyCommit verifies +2/3 of the set had signed the given commit and all
// other signatures are valid
func (vals *ValidatorSet) VerifyCommit(chainID string, blockID meta.BlockID,
height int64, commit *meta.Commit) error {
func (vals *ValidatorSet) VerifyCommit(chainID string, blockID metadata.BlockID,
height int64, commit *metadata.Commit) error {
return VerifyCommit(chainID, vals, blockID, height, commit)
}
// LIGHT CLIENT VERIFICATION METHODS
// VerifyCommitLight verifies +2/3 of the set had signed the given commit.
func (vals *ValidatorSet) VerifyCommitLight(chainID string, blockID meta.BlockID,
height int64, commit *meta.Commit) error {
func (vals *ValidatorSet) VerifyCommitLight(chainID string, blockID metadata.BlockID,
height int64, commit *metadata.Commit) error {
return VerifyCommitLight(chainID, vals, blockID, height, commit)
}
// VerifyCommitLightTrusting verifies that trustLevel of the validator set signed
// this commit.
func (vals *ValidatorSet) VerifyCommitLightTrusting(chainID string, commit *meta.Commit, trustLevel tmmath.Fraction) error {
func (vals *ValidatorSet) VerifyCommitLightTrusting(chainID string, commit *metadata.Commit, trustLevel tmmath.Fraction) error {
return VerifyCommitLightTrusting(chainID, vals, commit, trustLevel)
}

View File

@@ -9,7 +9,7 @@ import (
"github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/internal/libs/protoio"
tmbytes "github.com/tendermint/tendermint/libs/bytes"
"github.com/tendermint/tendermint/pkg/meta"
"github.com/tendermint/tendermint/pkg/metadata"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
)
@@ -52,7 +52,7 @@ type Vote struct {
Type tmproto.SignedMsgType `json:"type"`
Height int64 `json:"height"`
Round int32 `json:"round"` // assume there will not be greater than 2_147_483_647 rounds
BlockID meta.BlockID `json:"block_id"` // zero if vote is nil.
BlockID metadata.BlockID `json:"block_id"` // zero if vote is nil.
Timestamp time.Time `json:"timestamp"`
ValidatorAddress Address `json:"validator_address"`
ValidatorIndex int32 `json:"validator_index"`
@@ -60,22 +60,22 @@ type Vote struct {
}
// CommitSig converts the Vote to a CommitSig.
func (vote *Vote) CommitSig() meta.CommitSig {
func (vote *Vote) CommitSig() metadata.CommitSig {
if vote == nil {
return meta.NewCommitSigAbsent()
return metadata.NewCommitSigAbsent()
}
var blockIDFlag meta.BlockIDFlag
var blockIDFlag metadata.BlockIDFlag
switch {
case vote.BlockID.IsComplete():
blockIDFlag = meta.BlockIDFlagCommit
blockIDFlag = metadata.BlockIDFlagCommit
case vote.BlockID.IsZero():
blockIDFlag = meta.BlockIDFlagNil
blockIDFlag = metadata.BlockIDFlagNil
default:
panic(fmt.Sprintf("Invalid vote %v - expected BlockID to be either empty or complete", vote))
}
return meta.CommitSig{
return metadata.CommitSig{
BlockIDFlag: blockIDFlag,
ValidatorAddress: vote.ValidatorAddress,
Timestamp: vote.Timestamp,
@@ -86,7 +86,7 @@ func (vote *Vote) CommitSig() meta.CommitSig {
// GetVote converts the CommitSig for the given valIdx to a Vote.
// Returns nil if the precommit at valIdx is nil.
// Panics if valIdx >= commit.Size().
func GetVoteFromCommit(commit *meta.Commit, valIdx int32) *Vote {
func GetVoteFromCommit(commit *metadata.Commit, valIdx int32) *Vote {
commitSig := commit.Signatures[valIdx]
return &Vote{
Type: tmproto.PrecommitType,
@@ -132,7 +132,7 @@ func (vote *Vote) Copy() *Vote {
// Panics if valIdx >= commit.Size().
//
// See VoteSignBytes
func VoteSignBytesFromCommit(commit *meta.Commit, chainID string, valIdx int32) []byte {
func VoteSignBytesFromCommit(commit *metadata.Commit, chainID string, valIdx int32) []byte {
v := GetVoteFromCommit(commit, valIdx).ToProto()
return VoteSignBytes(chainID, v)
}
@@ -172,7 +172,7 @@ func (vote *Vote) String() string {
typeString,
tmbytes.Fingerprint(vote.BlockID.Hash),
tmbytes.Fingerprint(vote.Signature),
meta.CanonicalTime(vote.Timestamp),
metadata.CanonicalTime(vote.Timestamp),
)
}
@@ -226,8 +226,8 @@ func (vote *Vote) ValidateBasic() error {
return errors.New("signature is missing")
}
if len(vote.Signature) > meta.MaxSignatureSize {
return fmt.Errorf("signature is too big (max: %d)", meta.MaxSignatureSize)
if len(vote.Signature) > metadata.MaxSignatureSize {
return fmt.Errorf("signature is too big (max: %d)", metadata.MaxSignatureSize)
}
return nil
@@ -259,7 +259,7 @@ func VoteFromProto(pv *tmproto.Vote) (*Vote, error) {
return nil, errors.New("nil vote")
}
blockID, err := meta.BlockIDFromProto(&pv.BlockID)
blockID, err := metadata.BlockIDFromProto(&pv.BlockID)
if err != nil {
return nil, err
}

View File

@@ -8,7 +8,7 @@ import (
tmsync "github.com/tendermint/tendermint/internal/libs/sync"
"github.com/tendermint/tendermint/libs/bits"
tmjson "github.com/tendermint/tendermint/libs/json"
"github.com/tendermint/tendermint/pkg/meta"
"github.com/tendermint/tendermint/pkg/metadata"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
)
@@ -42,10 +42,10 @@ type P2PID string
the first vote seen, but when a 2/3 majority is found, votes for that get
priority and are copied over from `.votesByBlock`.
`.votesByBlock` keeps track of a list of votes for a particular meta. There
`.votesByBlock` keeps track of a list of votes for a particular metadata. There
are two ways a &blockVotes{} gets created in `.votesByBlock`.
1. the first vote seen by a validator was for the particular meta.
2. a peer claims to have seen 2/3 majority for the particular meta.
1. the first vote seen by a validator was for the particular metadata.
2. a peer claims to have seen 2/3 majority for the particular metadata.
Since the first vote from a validator will always get added in `.votesByBlock`
, all votes in `.votes` will have a corresponding entry in `.votesByBlock`.
@@ -70,9 +70,9 @@ type VoteSet struct {
votesBitArray *bits.BitArray
votes []*Vote // Primary votes to share
sum int64 // Sum of voting power for seen votes, discounting conflicts
maj23 *meta.BlockID // First 2/3 majority seen
maj23 *metadata.BlockID // First 2/3 majority seen
votesByBlock map[string]*blockVotes // string(blockHash|blockParts) -> blockVotes
peerMaj23s map[P2PID]meta.BlockID // Maj23 for each peer
peerMaj23s map[P2PID]metadata.BlockID // Maj23 for each peer
}
// Constructs a new VoteSet struct used to accumulate votes for given height/round.
@@ -92,14 +92,14 @@ func NewVoteSet(chainID string, height int64, round int32,
sum: 0,
maj23: nil,
votesByBlock: make(map[string]*blockVotes, valSet.Size()),
peerMaj23s: make(map[P2PID]meta.BlockID),
peerMaj23s: make(map[P2PID]metadata.BlockID),
}
}
// CommitToVoteSet constructs a VoteSet from the Commit and validator set.
// Panics if signatures from the commit can't be added to the voteset.
// Inverse of VoteSet.MakeCommit().
func VoteSetFromCommit(chainID string, commit *meta.Commit, vals *ValidatorSet) *VoteSet {
func VoteSetFromCommit(chainID string, commit *metadata.Commit, vals *ValidatorSet) *VoteSet {
voteSet := NewVoteSet(chainID, commit.Height, commit.Round, tmproto.PrecommitType, vals)
for idx, commitSig := range commit.Signatures {
if commitSig.Absent() {
@@ -324,7 +324,7 @@ func (voteSet *VoteSet) addVerifiedVote(
// this can cause memory issues.
// TODO: implement ability to remove peers too
// NOTE: VoteSet must not be nil
func (voteSet *VoteSet) SetPeerMaj23(peerID P2PID, blockID meta.BlockID) error {
func (voteSet *VoteSet) SetPeerMaj23(peerID P2PID, blockID metadata.BlockID) error {
if voteSet == nil {
panic("SetPeerMaj23() on nil VoteSet")
}
@@ -369,7 +369,7 @@ func (voteSet *VoteSet) BitArray() *bits.BitArray {
return voteSet.votesBitArray.Copy()
}
func (voteSet *VoteSet) BitArrayByBlockID(blockID meta.BlockID) *bits.BitArray {
func (voteSet *VoteSet) BitArrayByBlockID(blockID metadata.BlockID) *bits.BitArray {
if voteSet == nil {
return nil
}
@@ -445,16 +445,16 @@ func (voteSet *VoteSet) HasAll() bool {
// If there was a +2/3 majority for blockID, return blockID and true.
// Else, return the empty BlockID{} and false.
func (voteSet *VoteSet) TwoThirdsMajority() (blockID meta.BlockID, ok bool) {
func (voteSet *VoteSet) TwoThirdsMajority() (blockID metadata.BlockID, ok bool) {
if voteSet == nil {
return meta.BlockID{}, false
return metadata.BlockID{}, false
}
voteSet.mtx.Lock()
defer voteSet.mtx.Unlock()
if voteSet.maj23 != nil {
return *voteSet.maj23, true
}
return meta.BlockID{}, false
return metadata.BlockID{}, false
}
//--------------------------------------------------------------------------------
@@ -523,7 +523,7 @@ func (voteSet *VoteSet) MarshalJSON() ([]byte, error) {
type VoteSetJSON struct {
Votes []string `json:"votes"`
VotesBitArray string `json:"votes_bit_array"`
PeerMaj23s map[P2PID]meta.BlockID `json:"peer_maj_23s"`
PeerMaj23s map[P2PID]metadata.BlockID `json:"peer_maj_23s"`
}
// Return the bit-array of votes including
@@ -607,8 +607,8 @@ func (voteSet *VoteSet) sumTotalFrac() (int64, int64, float64) {
// for the block, which has 2/3+ majority, and nil.
//
// Panics if the vote type is not PrecommitType or if there's no +2/3 votes for
// a single meta.
func (voteSet *VoteSet) MakeCommit() *meta.Commit {
// a single metadata.
func (voteSet *VoteSet) MakeCommit() *metadata.Commit {
if voteSet.signedMsgType != tmproto.PrecommitType {
panic("Cannot MakeCommit() unless VoteSet.Type is PrecommitType")
}
@@ -621,17 +621,17 @@ func (voteSet *VoteSet) MakeCommit() *meta.Commit {
}
// For every validator, get the precommit
commitSigs := make([]meta.CommitSig, len(voteSet.votes))
commitSigs := make([]metadata.CommitSig, len(voteSet.votes))
for i, v := range voteSet.votes {
commitSig := v.CommitSig()
// if block ID exists but doesn't match, exclude sig
if commitSig.ForBlock() && !v.BlockID.Equals(*voteSet.maj23) {
commitSig = meta.NewCommitSigAbsent()
commitSig = metadata.NewCommitSigAbsent()
}
commitSigs[i] = commitSig
}
return meta.NewCommit(voteSet.GetHeight(), voteSet.GetRound(), *voteSet.maj23, commitSigs)
return metadata.NewCommit(voteSet.GetHeight(), voteSet.GetRound(), *voteSet.maj23, commitSigs)
}
//--------------------------------------------------------------------------------

View File

@@ -14,7 +14,7 @@ import (
tmrand "github.com/tendermint/tendermint/libs/rand"
tmtime "github.com/tendermint/tendermint/libs/time"
"github.com/tendermint/tendermint/pkg/consensus"
"github.com/tendermint/tendermint/pkg/meta"
"github.com/tendermint/tendermint/pkg/metadata"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
)
@@ -39,7 +39,7 @@ func TestVoteSet_AddVote_Good(t *testing.T) {
Round: round,
Type: tmproto.PrevoteType,
Timestamp: tmtime.Now(),
BlockID: meta.BlockID{nil, meta.PartSetHeader{}},
BlockID: metadata.BlockID{nil, metadata.PartSetHeader{}},
}
_, err = test.SignAddVote(val0, vote, voteSet)
require.NoError(t, err)
@@ -61,7 +61,7 @@ func TestVoteSet_AddVote_Bad(t *testing.T) {
Round: round,
Timestamp: tmtime.Now(),
Type: tmproto.PrevoteType,
BlockID: meta.BlockID{nil, meta.PartSetHeader{}},
BlockID: metadata.BlockID{nil, metadata.PartSetHeader{}},
}
// val0 votes for nil.
@@ -76,7 +76,7 @@ func TestVoteSet_AddVote_Bad(t *testing.T) {
}
}
// val0 votes again for some meta.
// val0 votes again for some metadata.
{
pubKey, err := privValidators[0].GetPubKey(context.Background())
require.NoError(t, err)
@@ -136,7 +136,7 @@ func TestVoteSet_2_3Majority(t *testing.T) {
Round: round,
Type: tmproto.PrevoteType,
Timestamp: tmtime.Now(),
BlockID: meta.BlockID{nil, meta.PartSetHeader{}},
BlockID: metadata.BlockID{nil, metadata.PartSetHeader{}},
}
// 6 out of 10 voted for nil.
for i := int32(0); i < 6; i++ {
@@ -181,7 +181,7 @@ func TestVoteSet_2_3MajorityRedux(t *testing.T) {
blockHash := crypto.CRandBytes(32)
blockPartsTotal := uint32(123)
blockPartSetHeader := meta.PartSetHeader{blockPartsTotal, crypto.CRandBytes(32)}
blockPartSetHeader := metadata.PartSetHeader{blockPartsTotal, crypto.CRandBytes(32)}
voteProto := &consensus.Vote{
ValidatorAddress: nil, // NOTE: must fill in
@@ -190,7 +190,7 @@ func TestVoteSet_2_3MajorityRedux(t *testing.T) {
Round: round,
Timestamp: tmtime.Now(),
Type: tmproto.PrevoteType,
BlockID: meta.BlockID{blockHash, blockPartSetHeader},
BlockID: metadata.BlockID{blockHash, blockPartSetHeader},
}
// 66 out of 100 voted for nil.
@@ -225,7 +225,7 @@ func TestVoteSet_2_3MajorityRedux(t *testing.T) {
require.NoError(t, err)
addr := pubKey.Address()
vote := withValidator(voteProto, addr, 67)
blockPartsHeader := meta.PartSetHeader{blockPartsTotal, crypto.CRandBytes(32)}
blockPartsHeader := metadata.PartSetHeader{blockPartsTotal, crypto.CRandBytes(32)}
_, err = test.SignAddVote(privValidators[67], withBlockPartSetHeader(vote, blockPartsHeader), voteSet)
require.NoError(t, err)
blockID, ok = voteSet.TwoThirdsMajority()
@@ -239,7 +239,7 @@ func TestVoteSet_2_3MajorityRedux(t *testing.T) {
require.NoError(t, err)
addr := pubKey.Address()
vote := withValidator(voteProto, addr, 68)
blockPartsHeader := meta.PartSetHeader{blockPartsTotal + 1, blockPartSetHeader.Hash}
blockPartsHeader := metadata.PartSetHeader{blockPartsTotal + 1, blockPartSetHeader.Hash}
_, err = test.SignAddVote(privValidators[68], withBlockPartSetHeader(vote, blockPartsHeader), voteSet)
require.NoError(t, err)
blockID, ok = voteSet.TwoThirdsMajority()
@@ -269,7 +269,7 @@ func TestVoteSet_2_3MajorityRedux(t *testing.T) {
_, err = test.SignAddVote(privValidators[70], vote, voteSet)
require.NoError(t, err)
blockID, ok = voteSet.TwoThirdsMajority()
assert.True(t, ok && blockID.Equals(meta.BlockID{blockHash, blockPartSetHeader}),
assert.True(t, ok && blockID.Equals(metadata.BlockID{blockHash, blockPartSetHeader}),
"there should be 2/3 majority")
}
}
@@ -287,7 +287,7 @@ func TestVoteSet_Conflicts(t *testing.T) {
Round: round,
Timestamp: tmtime.Now(),
Type: tmproto.PrevoteType,
BlockID: meta.BlockID{nil, meta.PartSetHeader{}},
BlockID: metadata.BlockID{nil, metadata.PartSetHeader{}},
}
val0, err := privValidators[0].GetPubKey(context.Background())
@@ -312,7 +312,7 @@ func TestVoteSet_Conflicts(t *testing.T) {
}
// start tracking blockHash1
err = voteSet.SetPeerMaj23("peerA", meta.BlockID{blockHash1, meta.PartSetHeader{}})
err = voteSet.SetPeerMaj23("peerA", metadata.BlockID{blockHash1, metadata.PartSetHeader{}})
require.NoError(t, err)
// val0 votes again for blockHash1.
@@ -324,7 +324,7 @@ func TestVoteSet_Conflicts(t *testing.T) {
}
// attempt tracking blockHash2, should fail because already set for peerA.
err = voteSet.SetPeerMaj23("peerA", meta.BlockID{blockHash2, meta.PartSetHeader{}})
err = voteSet.SetPeerMaj23("peerA", metadata.BlockID{blockHash2, metadata.PartSetHeader{}})
require.Error(t, err)
// val0 votes again for blockHash1.
@@ -376,7 +376,7 @@ func TestVoteSet_Conflicts(t *testing.T) {
}
// now attempt tracking blockHash1
err = voteSet.SetPeerMaj23("peerB", meta.BlockID{blockHash1, meta.PartSetHeader{}})
err = voteSet.SetPeerMaj23("peerB", metadata.BlockID{blockHash1, metadata.PartSetHeader{}})
require.NoError(t, err)
// val2 votes for blockHash1.
@@ -406,7 +406,7 @@ func TestVoteSet_Conflicts(t *testing.T) {
func TestVoteSet_MakeCommit(t *testing.T) {
height, round := int64(1), int32(0)
voteSet, _, privValidators := test.RandVoteSet(height, round, tmproto.PrecommitType, 10, 1)
blockHash, blockPartSetHeader := crypto.CRandBytes(32), meta.PartSetHeader{123, crypto.CRandBytes(32)}
blockHash, blockPartSetHeader := crypto.CRandBytes(32), metadata.PartSetHeader{123, crypto.CRandBytes(32)}
voteProto := &consensus.Vote{
ValidatorAddress: nil,
@@ -415,10 +415,10 @@ func TestVoteSet_MakeCommit(t *testing.T) {
Round: round,
Timestamp: tmtime.Now(),
Type: tmproto.PrecommitType,
BlockID: meta.BlockID{blockHash, blockPartSetHeader},
BlockID: metadata.BlockID{blockHash, blockPartSetHeader},
}
// 6 out of 10 voted for some meta.
// 6 out of 10 voted for some metadata.
for i := int32(0); i < 6; i++ {
pv, err := privValidators[i].GetPubKey(context.Background())
assert.NoError(t, err)
@@ -433,14 +433,14 @@ func TestVoteSet_MakeCommit(t *testing.T) {
// MakeCommit should fail.
assert.Panics(t, func() { voteSet.MakeCommit() }, "Doesn't have +2/3 majority")
// 7th voted for some other meta.
// 7th voted for some other metadata.
{
pv, err := privValidators[6].GetPubKey(context.Background())
assert.NoError(t, err)
addr := pv.Address()
vote := withValidator(voteProto, addr, 6)
vote = withBlockHash(vote, tmrand.Bytes(32))
vote = withBlockPartSetHeader(vote, meta.PartSetHeader{123, tmrand.Bytes(32)})
vote = withBlockPartSetHeader(vote, metadata.PartSetHeader{123, tmrand.Bytes(32)})
_, err = test.SignAddVote(privValidators[6], vote, voteSet)
require.NoError(t, err)
@@ -462,7 +462,7 @@ func TestVoteSet_MakeCommit(t *testing.T) {
assert.NoError(t, err)
addr := pv.Address()
vote := withValidator(voteProto, addr, 8)
vote.BlockID = meta.BlockID{}
vote.BlockID = metadata.BlockID{}
_, err = test.SignAddVote(privValidators[8], vote, voteSet)
require.NoError(t, err)
@@ -515,14 +515,14 @@ func TestCommitToVoteSetWithVotesForNilBlock(t *testing.T) {
)
type commitVoteTest struct {
blockIDs []meta.BlockID
blockIDs []metadata.BlockID
numVotes []int // must sum to numValidators
numValidators int
valid bool
}
testCases := []commitVoteTest{
{[]meta.BlockID{blockID, {}}, []int{67, 33}, 100, true},
{[]metadata.BlockID{blockID, {}}, []int{67, 33}, 100, true},
}
for _, tc := range testCases {
@@ -599,7 +599,7 @@ func withBlockHash(vote *consensus.Vote, blockHash []byte) *consensus.Vote {
}
// Convenience: Return new vote with different blockParts
func withBlockPartSetHeader(vote *consensus.Vote, blockPartsHeader meta.PartSetHeader) *consensus.Vote {
func withBlockPartSetHeader(vote *consensus.Vote, blockPartsHeader metadata.PartSetHeader) *consensus.Vote {
vote = vote.Copy()
vote.BlockID.PartSetHeader = blockPartsHeader
return vote

View File

@@ -13,7 +13,7 @@ import (
"github.com/tendermint/tendermint/crypto/ed25519"
"github.com/tendermint/tendermint/crypto/tmhash"
"github.com/tendermint/tendermint/internal/libs/protoio"
"github.com/tendermint/tendermint/pkg/meta"
"github.com/tendermint/tendermint/pkg/metadata"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
)
@@ -26,7 +26,7 @@ func examplePrecommit() *Vote {
}
func exampleVote(t byte) *Vote {
var stamp, err = time.Parse(meta.TimeFormat, "2017-12-25T03:00:01.234Z")
var stamp, err = time.Parse(metadata.TimeFormat, "2017-12-25T03:00:01.234Z")
if err != nil {
panic(err)
}
@@ -36,9 +36,9 @@ func exampleVote(t byte) *Vote {
Height: 12345,
Round: 2,
Timestamp: stamp,
BlockID: meta.BlockID{
BlockID: metadata.BlockID{
Hash: tmhash.Sum([]byte("blockID_hash")),
PartSetHeader: meta.PartSetHeader{
PartSetHeader: metadata.PartSetHeader{
Total: 1000000,
Hash: tmhash.Sum([]byte("blockID_part_set_header_hash")),
},
@@ -245,12 +245,12 @@ func TestVoteValidateBasic(t *testing.T) {
{"Negative Height", func(v *Vote) { v.Height = -1 }, true},
{"Negative Round", func(v *Vote) { v.Round = -1 }, true},
{"Invalid BlockID", func(v *Vote) {
v.BlockID = meta.BlockID{[]byte{1, 2, 3}, meta.PartSetHeader{111, []byte("blockparts")}}
v.BlockID = metadata.BlockID{[]byte{1, 2, 3}, metadata.PartSetHeader{111, []byte("blockparts")}}
}, true},
{"Invalid Address", func(v *Vote) { v.ValidatorAddress = make([]byte, 1) }, true},
{"Invalid ValidatorIndex", func(v *Vote) { v.ValidatorIndex = -1 }, true},
{"Invalid Signature", func(v *Vote) { v.Signature = nil }, true},
{"Too big Signature", func(v *Vote) { v.Signature = make([]byte, meta.MaxSignatureSize+1) }, true},
{"Too big Signature", func(v *Vote) { v.Signature = make([]byte, metadata.MaxSignatureSize+1) }, true},
}
for _, tc := range testCases {
tc := tc

View File

@@ -17,7 +17,7 @@ import (
"github.com/tendermint/tendermint/pkg/events"
"github.com/tendermint/tendermint/pkg/evidence"
"github.com/tendermint/tendermint/pkg/mempool"
"github.com/tendermint/tendermint/pkg/meta"
"github.com/tendermint/tendermint/pkg/metadata"
)
func TestEventBusPublishEventTx(t *testing.T) {
@@ -80,7 +80,7 @@ func TestEventBusPublishEventNewBlock(t *testing.T) {
})
block := block.MakeBlock(0, []mempool.Tx{}, nil, []evidence.Evidence{})
blockID := meta.BlockID{Hash: block.Hash(), PartSetHeader: block.MakePartSet(meta.BlockPartSizeBytes).Header()}
blockID := metadata.BlockID{Hash: block.Hash(), PartSetHeader: block.MakePartSet(metadata.BlockPartSizeBytes).Header()}
resultBeginBlock := abci.ResponseBeginBlock{
Events: []abci.Event{
{Type: "testType", Attributes: []abci.EventAttribute{{Key: "baz", Value: "1"}}},

View File

@@ -13,7 +13,7 @@ import (
"github.com/tendermint/tendermint/pkg/consensus"
"github.com/tendermint/tendermint/pkg/evidence"
"github.com/tendermint/tendermint/pkg/mempool"
"github.com/tendermint/tendermint/pkg/meta"
"github.com/tendermint/tendermint/pkg/metadata"
)
// Reserved event types (alphabetically sorted).
@@ -119,14 +119,14 @@ func init() {
type EventDataNewBlock struct {
Block *block.Block `json:"block"`
BlockID meta.BlockID `json:"block_id"`
BlockID metadata.BlockID `json:"block_id"`
ResultBeginBlock abci.ResponseBeginBlock `json:"result_begin_block"`
ResultEndBlock abci.ResponseEndBlock `json:"result_end_block"`
}
type EventDataNewBlockHeader struct {
Header meta.Header `json:"header"`
Header metadata.Header `json:"header"`
NumTxs int64 `json:"num_txs"` // Number of txs in a block
ResultBeginBlock abci.ResponseBeginBlock `json:"result_begin_block"`
@@ -169,7 +169,7 @@ type EventDataCompleteProposal struct {
Round int32 `json:"round"`
Step string `json:"step"`
BlockID meta.BlockID `json:"block_id"`
BlockID metadata.BlockID `json:"block_id"`
}
type EventDataVote struct {

View File

@@ -17,7 +17,7 @@ import (
tmrand "github.com/tendermint/tendermint/libs/rand"
"github.com/tendermint/tendermint/pkg/consensus"
"github.com/tendermint/tendermint/pkg/light"
"github.com/tendermint/tendermint/pkg/meta"
"github.com/tendermint/tendermint/pkg/metadata"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
)
@@ -364,7 +364,7 @@ func (l *LightClientAttackEvidence) GetByzantineValidators(commonVals *consensus
// to determine whether the conflicting header was the product of a valid state transition
// or not. If it is then all the deterministic fields of the header should be the same.
// If not, it is an invalid header and constitutes a lunatic attack.
func (l *LightClientAttackEvidence) ConflictingHeaderIsInvalid(trustedHeader *meta.Header) bool {
func (l *LightClientAttackEvidence) ConflictingHeaderIsInvalid(trustedHeader *metadata.Header) bool {
return !bytes.Equal(trustedHeader.ValidatorsHash, l.ConflictingBlock.ValidatorsHash) ||
!bytes.Equal(trustedHeader.NextValidatorsHash, l.ConflictingBlock.NextValidatorsHash) ||
!bytes.Equal(trustedHeader.ConsensusHash, l.ConflictingBlock.ConsensusHash) ||
@@ -691,7 +691,7 @@ func NewMockDuplicateVoteEvidenceWithValidator(height int64, time time.Time,
}
func makeMockVote(height int64, round, index int32, addr consensus.Address,
blockID meta.BlockID, time time.Time) *consensus.Vote {
blockID metadata.BlockID, time time.Time) *consensus.Vote {
return &consensus.Vote{
Type: tmproto.SignedMsgType(2),
Height: height,
@@ -703,10 +703,10 @@ func makeMockVote(height int64, round, index int32, addr consensus.Address,
}
}
func randBlockID() meta.BlockID {
return meta.BlockID{
func randBlockID() metadata.BlockID {
return metadata.BlockID{
Hash: tmrand.Bytes(tmhash.Size),
PartSetHeader: meta.PartSetHeader{
PartSetHeader: metadata.PartSetHeader{
Total: 1,
Hash: tmrand.Bytes(tmhash.Size),
},

View File

@@ -19,7 +19,7 @@ import (
"github.com/tendermint/tendermint/pkg/consensus"
"github.com/tendermint/tendermint/pkg/evidence"
"github.com/tendermint/tendermint/pkg/light"
"github.com/tendermint/tendermint/pkg/meta"
"github.com/tendermint/tendermint/pkg/metadata"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
"github.com/tendermint/tendermint/version"
)
@@ -237,7 +237,7 @@ func TestMockEvidenceValidateBasic(t *testing.T) {
}
func makeVote(
t *testing.T, val consensus.PrivValidator, chainID string, valIndex int32, height int64, round int32, step int, blockID meta.BlockID,
t *testing.T, val consensus.PrivValidator, chainID string, valIndex int32, height int64, round int32, step int, blockID metadata.BlockID,
time time.Time) *consensus.Vote {
pubKey, err := val.GetPubKey(context.Background())
require.NoError(t, err)
@@ -260,8 +260,8 @@ func makeVote(
return v
}
func makeHeaderRandom() *meta.Header {
return &meta.Header{
func makeHeaderRandom() *metadata.Header {
return &metadata.Header{
Version: version.Consensus{Block: version.BlockProtocol, App: 1},
ChainID: tmrand.Str(12),
Height: int64(mrand.Uint32() + 1),
@@ -335,12 +335,12 @@ func TestEvidenceVectors(t *testing.T) {
commonHeight := height - 1
nValidators := 10
voteSet, valSet, privVals := test.DeterministicVoteSet(height, 1, tmproto.PrecommitType, 1)
header := &meta.Header{
header := &metadata.Header{
Version: version.Consensus{Block: 1, App: 1},
ChainID: chainID,
Height: height,
Time: time.Date(math.MaxInt64, 0, 0, 0, 0, 0, math.MaxInt64, time.UTC),
LastBlockID: meta.BlockID{},
LastBlockID: metadata.BlockID{},
LastCommitHash: []byte("f2564c78071e26643ae9b3e2a19fa0dc10d4d9e873aa0be808660123f11a1e78"),
DataHash: []byte("f2564c78071e26643ae9b3e2a19fa0dc10d4d9e873aa0be808660123f11a1e78"),
ValidatorsHash: valSet.Hash(),

View File

@@ -6,7 +6,7 @@ import (
"fmt"
"github.com/tendermint/tendermint/pkg/consensus"
"github.com/tendermint/tendermint/pkg/meta"
meta "github.com/tendermint/tendermint/pkg/metadata"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
)

View File

@@ -12,7 +12,7 @@ import (
test "github.com/tendermint/tendermint/internal/test/factory"
"github.com/tendermint/tendermint/pkg/consensus"
"github.com/tendermint/tendermint/pkg/light"
"github.com/tendermint/tendermint/pkg/meta"
"github.com/tendermint/tendermint/pkg/metadata"
"github.com/tendermint/tendermint/version"
)
@@ -118,7 +118,7 @@ func TestSignedHeaderValidateBasic(t *testing.T) {
commit := test.MakeRandomCommit(time.Now())
chainID := "𠜎"
timestamp := time.Date(math.MaxInt64, 0, 0, 0, 0, 0, math.MaxInt64, time.UTC)
h := meta.Header{
h := metadata.Header{
Version: version.Consensus{Block: version.BlockProtocol, App: math.MaxInt64},
ChainID: chainID,
Height: commit.Height,
@@ -141,8 +141,8 @@ func TestSignedHeaderValidateBasic(t *testing.T) {
testCases := []struct {
testName string
shHeader *meta.Header
shCommit *meta.Commit
shHeader *metadata.Header
shCommit *metadata.Commit
expectErr bool
}{
{"Valid Signed Header", validSignedHeader.Header, validSignedHeader.Commit, false},

View File

@@ -1,4 +1,4 @@
package meta
package metadata
import (
"time"

View File

@@ -1,4 +1,4 @@
package meta_test
package metadata_test
import (
"reflect"
@@ -6,7 +6,7 @@ import (
"github.com/tendermint/tendermint/crypto/tmhash"
tmrand "github.com/tendermint/tendermint/libs/rand"
"github.com/tendermint/tendermint/pkg/meta"
"github.com/tendermint/tendermint/pkg/metadata"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
)
@@ -32,7 +32,7 @@ func TestCanonicalizeBlockID(t *testing.T) {
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
if got := meta.CanonicalizeBlockID(tt.args); !reflect.DeepEqual(got, tt.want) {
if got := metadata.CanonicalizeBlockID(tt.args); !reflect.DeepEqual(got, tt.want) {
t.Errorf("CanonicalizeBlockID() = %v, want %v", got, tt.want)
}
})

View File

@@ -1,4 +1,4 @@
package meta
package metadata
import (
"crypto/ed25519"

View File

@@ -1,4 +1,4 @@
package meta_test
package metadata_test
import (
"math"
@@ -13,7 +13,7 @@ import (
test "github.com/tendermint/tendermint/internal/test/factory"
"github.com/tendermint/tendermint/libs/bits"
"github.com/tendermint/tendermint/pkg/consensus"
"github.com/tendermint/tendermint/pkg/meta"
"github.com/tendermint/tendermint/pkg/metadata"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
)
@@ -41,13 +41,13 @@ func TestCommit(t *testing.T) {
func TestCommitValidateBasic(t *testing.T) {
testCases := []struct {
testName string
malleateCommit func(*meta.Commit)
malleateCommit func(*metadata.Commit)
expectErr bool
}{
{"Random Commit", func(com *meta.Commit) {}, false},
{"Incorrect signature", func(com *meta.Commit) { com.Signatures[0].Signature = []byte{0} }, false},
{"Incorrect height", func(com *meta.Commit) { com.Height = int64(-100) }, true},
{"Incorrect round", func(com *meta.Commit) { com.Round = -100 }, true},
{"Random Commit", func(com *metadata.Commit) {}, false},
{"Incorrect signature", func(com *metadata.Commit) { com.Signatures[0].Signature = []byte{0} }, false},
{"Incorrect height", func(com *metadata.Commit) { com.Height = int64(-100) }, true},
{"Incorrect round", func(com *metadata.Commit) { com.Round = -100 }, true},
}
for _, tc := range testCases {
tc := tc
@@ -62,37 +62,37 @@ func TestCommitValidateBasic(t *testing.T) {
func TestCommit_ValidateBasic(t *testing.T) {
testCases := []struct {
name string
commit *meta.Commit
commit *metadata.Commit
expectErr bool
errString string
}{
{
"invalid height",
&meta.Commit{Height: -1},
&metadata.Commit{Height: -1},
true, "negative Height",
},
{
"invalid round",
&meta.Commit{Height: 1, Round: -1},
&metadata.Commit{Height: 1, Round: -1},
true, "negative Round",
},
{
"invalid block ID",
&meta.Commit{
&metadata.Commit{
Height: 1,
Round: 1,
BlockID: meta.BlockID{},
BlockID: metadata.BlockID{},
},
true, "commit cannot be for nil block",
},
{
"no signatures",
&meta.Commit{
&metadata.Commit{
Height: 1,
Round: 1,
BlockID: meta.BlockID{
BlockID: metadata.BlockID{
Hash: make([]byte, tmhash.Size),
PartSetHeader: meta.PartSetHeader{
PartSetHeader: metadata.PartSetHeader{
Hash: make([]byte, tmhash.Size),
},
},
@@ -101,20 +101,20 @@ func TestCommit_ValidateBasic(t *testing.T) {
},
{
"invalid signature",
&meta.Commit{
&metadata.Commit{
Height: 1,
Round: 1,
BlockID: meta.BlockID{
BlockID: metadata.BlockID{
Hash: make([]byte, tmhash.Size),
PartSetHeader: meta.PartSetHeader{
PartSetHeader: metadata.PartSetHeader{
Hash: make([]byte, tmhash.Size),
},
},
Signatures: []meta.CommitSig{
Signatures: []metadata.CommitSig{
{
BlockIDFlag: meta.BlockIDFlagCommit,
BlockIDFlag: metadata.BlockIDFlagCommit,
ValidatorAddress: make([]byte, crypto.AddressSize),
Signature: make([]byte, meta.MaxSignatureSize+1),
Signature: make([]byte, metadata.MaxSignatureSize+1),
},
},
},
@@ -122,20 +122,20 @@ func TestCommit_ValidateBasic(t *testing.T) {
},
{
"valid commit",
&meta.Commit{
&metadata.Commit{
Height: 1,
Round: 1,
BlockID: meta.BlockID{
BlockID: metadata.BlockID{
Hash: make([]byte, tmhash.Size),
PartSetHeader: meta.PartSetHeader{
PartSetHeader: metadata.PartSetHeader{
Hash: make([]byte, tmhash.Size),
},
},
Signatures: []meta.CommitSig{
Signatures: []metadata.CommitSig{
{
BlockIDFlag: meta.BlockIDFlagCommit,
BlockIDFlag: metadata.BlockIDFlagCommit,
ValidatorAddress: make([]byte, crypto.AddressSize),
Signature: make([]byte, meta.MaxSignatureSize),
Signature: make([]byte, metadata.MaxSignatureSize),
},
},
},
@@ -163,34 +163,34 @@ func TestMaxCommitBytes(t *testing.T) {
// year int, month Month, day, hour, min, sec, nsec int, loc *Location
timestamp := time.Date(math.MaxInt64, 0, 0, 0, 0, 0, math.MaxInt64, time.UTC)
cs := meta.CommitSig{
BlockIDFlag: meta.BlockIDFlagNil,
cs := metadata.CommitSig{
BlockIDFlag: metadata.BlockIDFlagNil,
ValidatorAddress: crypto.AddressHash([]byte("validator_address")),
Timestamp: timestamp,
Signature: crypto.CRandBytes(meta.MaxSignatureSize),
Signature: crypto.CRandBytes(metadata.MaxSignatureSize),
}
pbSig := cs.ToProto()
// test that a single commit sig doesn't exceed max commit sig bytes
assert.EqualValues(t, meta.MaxCommitSigBytes, pbSig.Size())
assert.EqualValues(t, metadata.MaxCommitSigBytes, pbSig.Size())
// check size with a single commit
commit := &meta.Commit{
commit := &metadata.Commit{
Height: math.MaxInt64,
Round: math.MaxInt32,
BlockID: meta.BlockID{
BlockID: metadata.BlockID{
Hash: tmhash.Sum([]byte("blockID_hash")),
PartSetHeader: meta.PartSetHeader{
PartSetHeader: metadata.PartSetHeader{
Total: math.MaxInt32,
Hash: tmhash.Sum([]byte("blockID_part_set_header_hash")),
},
},
Signatures: []meta.CommitSig{cs},
Signatures: []metadata.CommitSig{cs},
}
pb := commit.ToProto()
assert.EqualValues(t, meta.MaxCommitBytes(1), int64(pb.Size()))
assert.EqualValues(t, metadata.MaxCommitBytes(1), int64(pb.Size()))
// check the upper bound of the commit size
for i := 1; i < consensus.MaxVotesCount; i++ {
@@ -199,50 +199,50 @@ func TestMaxCommitBytes(t *testing.T) {
pb = commit.ToProto()
assert.EqualValues(t, meta.MaxCommitBytes(consensus.MaxVotesCount), int64(pb.Size()))
assert.EqualValues(t, metadata.MaxCommitBytes(consensus.MaxVotesCount), int64(pb.Size()))
}
func TestCommitSig_ValidateBasic(t *testing.T) {
testCases := []struct {
name string
cs meta.CommitSig
cs metadata.CommitSig
expectErr bool
errString string
}{
{
"invalid ID flag",
meta.CommitSig{BlockIDFlag: meta.BlockIDFlag(0xFF)},
metadata.CommitSig{BlockIDFlag: metadata.BlockIDFlag(0xFF)},
true, "unknown BlockIDFlag",
},
{
"BlockIDFlagAbsent validator address present",
meta.CommitSig{BlockIDFlag: meta.BlockIDFlagAbsent, ValidatorAddress: crypto.Address("testaddr")},
metadata.CommitSig{BlockIDFlag: metadata.BlockIDFlagAbsent, ValidatorAddress: crypto.Address("testaddr")},
true, "validator address is present",
},
{
"BlockIDFlagAbsent timestamp present",
meta.CommitSig{BlockIDFlag: meta.BlockIDFlagAbsent, Timestamp: time.Now().UTC()},
metadata.CommitSig{BlockIDFlag: metadata.BlockIDFlagAbsent, Timestamp: time.Now().UTC()},
true, "time is present",
},
{
"BlockIDFlagAbsent signatures present",
meta.CommitSig{BlockIDFlag: meta.BlockIDFlagAbsent, Signature: []byte{0xAA}},
metadata.CommitSig{BlockIDFlag: metadata.BlockIDFlagAbsent, Signature: []byte{0xAA}},
true, "signature is present",
},
{
"BlockIDFlagAbsent valid BlockIDFlagAbsent",
meta.CommitSig{BlockIDFlag: meta.BlockIDFlagAbsent},
metadata.CommitSig{BlockIDFlag: metadata.BlockIDFlagAbsent},
false, "",
},
{
"non-BlockIDFlagAbsent invalid validator address",
meta.CommitSig{BlockIDFlag: meta.BlockIDFlagCommit, ValidatorAddress: make([]byte, 1)},
metadata.CommitSig{BlockIDFlag: metadata.BlockIDFlagCommit, ValidatorAddress: make([]byte, 1)},
true, "expected ValidatorAddress size",
},
{
"non-BlockIDFlagAbsent invalid signature (zero)",
meta.CommitSig{
BlockIDFlag: meta.BlockIDFlagCommit,
metadata.CommitSig{
BlockIDFlag: metadata.BlockIDFlagCommit,
ValidatorAddress: make([]byte, crypto.AddressSize),
Signature: make([]byte, 0),
},
@@ -250,19 +250,19 @@ func TestCommitSig_ValidateBasic(t *testing.T) {
},
{
"non-BlockIDFlagAbsent invalid signature (too large)",
meta.CommitSig{
BlockIDFlag: meta.BlockIDFlagCommit,
metadata.CommitSig{
BlockIDFlag: metadata.BlockIDFlagCommit,
ValidatorAddress: make([]byte, crypto.AddressSize),
Signature: make([]byte, meta.MaxSignatureSize+1),
Signature: make([]byte, metadata.MaxSignatureSize+1),
},
true, "signature is too big",
},
{
"non-BlockIDFlagAbsent valid",
meta.CommitSig{
BlockIDFlag: meta.BlockIDFlagCommit,
metadata.CommitSig{
BlockIDFlag: metadata.BlockIDFlagCommit,
ValidatorAddress: make([]byte, crypto.AddressSize),
Signature: make([]byte, meta.MaxSignatureSize),
Signature: make([]byte, metadata.MaxSignatureSize),
},
false, "",
},

View File

@@ -1,4 +1,4 @@
package meta
package metadata
import (
"errors"

View File

@@ -1,4 +1,4 @@
package meta_test
package metadata_test
import (
"encoding/hex"
@@ -16,7 +16,7 @@ import (
"github.com/tendermint/tendermint/crypto/tmhash"
test "github.com/tendermint/tendermint/internal/test/factory"
"github.com/tendermint/tendermint/libs/bytes"
"github.com/tendermint/tendermint/pkg/meta"
"github.com/tendermint/tendermint/pkg/metadata"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
tmversion "github.com/tendermint/tendermint/proto/tendermint/version"
"github.com/tendermint/tendermint/version"
@@ -25,17 +25,17 @@ import (
var nilBytes []byte
func TestNilHeaderHashDoesntCrash(t *testing.T) {
assert.Equal(t, nilBytes, []byte((*meta.Header)(nil).Hash()))
assert.Equal(t, nilBytes, []byte((new(meta.Header)).Hash()))
assert.Equal(t, nilBytes, []byte((*metadata.Header)(nil).Hash()))
assert.Equal(t, nilBytes, []byte((new(metadata.Header)).Hash()))
}
func TestHeaderHash(t *testing.T) {
testCases := []struct {
desc string
header *meta.Header
header *metadata.Header
expectHash bytes.HexBytes
}{
{"Generates expected hash", &meta.Header{
{"Generates expected hash", &metadata.Header{
Version: version.Consensus{Block: 1, App: 2},
ChainID: "chainId",
Height: 3,
@@ -52,7 +52,7 @@ func TestHeaderHash(t *testing.T) {
ProposerAddress: crypto.AddressHash([]byte("proposer_address")),
}, hexBytesFromString("F740121F553B5418C3EFBD343C2DBFE9E007BB67B0D020A0741374BAB65242A4")},
{"nil header yields nil", nil, nil},
{"nil ValidatorsHash yields nil", &meta.Header{
{"nil ValidatorsHash yields nil", &metadata.Header{
Version: version.Consensus{Block: 1, App: 2},
ChainID: "chainId",
Height: 3,
@@ -88,7 +88,7 @@ func TestHeaderHash(t *testing.T) {
switch f := f.Interface().(type) {
case int64, bytes.HexBytes, string:
byteSlices = append(byteSlices, meta.CdcEncode(f))
byteSlices = append(byteSlices, metadata.CdcEncode(f))
case time.Time:
bz, err := gogotypes.StdTimeMarshal(f)
require.NoError(t, err)
@@ -101,7 +101,7 @@ func TestHeaderHash(t *testing.T) {
bz, err := pbc.Marshal()
require.NoError(t, err)
byteSlices = append(byteSlices, bz)
case meta.BlockID:
case metadata.BlockID:
pbbi := f.ToProto()
bz, err := pbbi.Marshal()
require.NoError(t, err)
@@ -123,7 +123,7 @@ func TestMaxHeaderBytes(t *testing.T) {
// Each supplementary character takes 4 bytes.
// http://www.i18nguy.com/unicode/supplementary-test.html
maxChainID := ""
for i := 0; i < meta.MaxChainIDLen; i++ {
for i := 0; i < metadata.MaxChainIDLen; i++ {
maxChainID += "𠜎"
}
@@ -131,12 +131,12 @@ func TestMaxHeaderBytes(t *testing.T) {
// year int, month Month, day, hour, min, sec, nsec int, loc *Location
timestamp := time.Date(math.MaxInt64, 0, 0, 0, 0, 0, math.MaxInt64, time.UTC)
h := meta.Header{
h := metadata.Header{
Version: version.Consensus{Block: math.MaxInt64, App: math.MaxInt64},
ChainID: maxChainID,
Height: math.MaxInt64,
Time: timestamp,
LastBlockID: meta.BlockID{make([]byte, tmhash.Size), meta.PartSetHeader{math.MaxInt32, make([]byte, tmhash.Size)}},
LastBlockID: metadata.BlockID{make([]byte, tmhash.Size), metadata.PartSetHeader{math.MaxInt32, make([]byte, tmhash.Size)}},
LastCommitHash: tmhash.Sum([]byte("last_commit_hash")),
DataHash: tmhash.Sum([]byte("data_hash")),
ValidatorsHash: tmhash.Sum([]byte("validators_hash")),
@@ -151,10 +151,10 @@ func TestMaxHeaderBytes(t *testing.T) {
bz, err := h.ToProto().Marshal()
require.NoError(t, err)
assert.EqualValues(t, meta.MaxHeaderBytes, int64(len(bz)))
assert.EqualValues(t, metadata.MaxHeaderBytes, int64(len(bz)))
}
func randCommit(now time.Time) *meta.Commit {
func randCommit(now time.Time) *metadata.Commit {
lastID := test.MakeBlockID()
h := int64(3)
voteSet, _, vals := test.RandVoteSet(h-1, 1, tmproto.PrecommitType, 10, 1)
@@ -176,48 +176,48 @@ func hexBytesFromString(s string) bytes.HexBytes {
func TestHeader_ValidateBasic(t *testing.T) {
testCases := []struct {
name string
header meta.Header
header metadata.Header
expectErr bool
errString string
}{
{
"invalid version block",
meta.Header{Version: version.Consensus{Block: version.BlockProtocol + 1}},
metadata.Header{Version: version.Consensus{Block: version.BlockProtocol + 1}},
true, "block protocol is incorrect",
},
{
"invalid chain ID length",
meta.Header{
metadata.Header{
Version: version.Consensus{Block: version.BlockProtocol},
ChainID: string(make([]byte, meta.MaxChainIDLen+1)),
ChainID: string(make([]byte, metadata.MaxChainIDLen+1)),
},
true, "chainID is too long",
},
{
"invalid height (negative)",
meta.Header{
metadata.Header{
Version: version.Consensus{Block: version.BlockProtocol},
ChainID: string(make([]byte, meta.MaxChainIDLen)),
ChainID: string(make([]byte, metadata.MaxChainIDLen)),
Height: -1,
},
true, "negative Height",
},
{
"invalid height (zero)",
meta.Header{
metadata.Header{
Version: version.Consensus{Block: version.BlockProtocol},
ChainID: string(make([]byte, meta.MaxChainIDLen)),
ChainID: string(make([]byte, metadata.MaxChainIDLen)),
Height: 0,
},
true, "zero Height",
},
{
"invalid block ID hash",
meta.Header{
metadata.Header{
Version: version.Consensus{Block: version.BlockProtocol},
ChainID: string(make([]byte, meta.MaxChainIDLen)),
ChainID: string(make([]byte, metadata.MaxChainIDLen)),
Height: 1,
LastBlockID: meta.BlockID{
LastBlockID: metadata.BlockID{
Hash: make([]byte, tmhash.Size+1),
},
},
@@ -225,13 +225,13 @@ func TestHeader_ValidateBasic(t *testing.T) {
},
{
"invalid block ID parts header hash",
meta.Header{
metadata.Header{
Version: version.Consensus{Block: version.BlockProtocol},
ChainID: string(make([]byte, meta.MaxChainIDLen)),
ChainID: string(make([]byte, metadata.MaxChainIDLen)),
Height: 1,
LastBlockID: meta.BlockID{
LastBlockID: metadata.BlockID{
Hash: make([]byte, tmhash.Size),
PartSetHeader: meta.PartSetHeader{
PartSetHeader: metadata.PartSetHeader{
Hash: make([]byte, tmhash.Size+1),
},
},
@@ -240,13 +240,13 @@ func TestHeader_ValidateBasic(t *testing.T) {
},
{
"invalid last commit hash",
meta.Header{
metadata.Header{
Version: version.Consensus{Block: version.BlockProtocol},
ChainID: string(make([]byte, meta.MaxChainIDLen)),
ChainID: string(make([]byte, metadata.MaxChainIDLen)),
Height: 1,
LastBlockID: meta.BlockID{
LastBlockID: metadata.BlockID{
Hash: make([]byte, tmhash.Size),
PartSetHeader: meta.PartSetHeader{
PartSetHeader: metadata.PartSetHeader{
Hash: make([]byte, tmhash.Size),
},
},
@@ -256,13 +256,13 @@ func TestHeader_ValidateBasic(t *testing.T) {
},
{
"invalid data hash",
meta.Header{
metadata.Header{
Version: version.Consensus{Block: version.BlockProtocol},
ChainID: string(make([]byte, meta.MaxChainIDLen)),
ChainID: string(make([]byte, metadata.MaxChainIDLen)),
Height: 1,
LastBlockID: meta.BlockID{
LastBlockID: metadata.BlockID{
Hash: make([]byte, tmhash.Size),
PartSetHeader: meta.PartSetHeader{
PartSetHeader: metadata.PartSetHeader{
Hash: make([]byte, tmhash.Size),
},
},
@@ -273,13 +273,13 @@ func TestHeader_ValidateBasic(t *testing.T) {
},
{
"invalid evidence hash",
meta.Header{
metadata.Header{
Version: version.Consensus{Block: version.BlockProtocol},
ChainID: string(make([]byte, meta.MaxChainIDLen)),
ChainID: string(make([]byte, metadata.MaxChainIDLen)),
Height: 1,
LastBlockID: meta.BlockID{
LastBlockID: metadata.BlockID{
Hash: make([]byte, tmhash.Size),
PartSetHeader: meta.PartSetHeader{
PartSetHeader: metadata.PartSetHeader{
Hash: make([]byte, tmhash.Size),
},
},
@@ -291,13 +291,13 @@ func TestHeader_ValidateBasic(t *testing.T) {
},
{
"invalid proposer address",
meta.Header{
metadata.Header{
Version: version.Consensus{Block: version.BlockProtocol},
ChainID: string(make([]byte, meta.MaxChainIDLen)),
ChainID: string(make([]byte, metadata.MaxChainIDLen)),
Height: 1,
LastBlockID: meta.BlockID{
LastBlockID: metadata.BlockID{
Hash: make([]byte, tmhash.Size),
PartSetHeader: meta.PartSetHeader{
PartSetHeader: metadata.PartSetHeader{
Hash: make([]byte, tmhash.Size),
},
},
@@ -310,13 +310,13 @@ func TestHeader_ValidateBasic(t *testing.T) {
},
{
"invalid validator hash",
meta.Header{
metadata.Header{
Version: version.Consensus{Block: version.BlockProtocol},
ChainID: string(make([]byte, meta.MaxChainIDLen)),
ChainID: string(make([]byte, metadata.MaxChainIDLen)),
Height: 1,
LastBlockID: meta.BlockID{
LastBlockID: metadata.BlockID{
Hash: make([]byte, tmhash.Size),
PartSetHeader: meta.PartSetHeader{
PartSetHeader: metadata.PartSetHeader{
Hash: make([]byte, tmhash.Size),
},
},
@@ -330,13 +330,13 @@ func TestHeader_ValidateBasic(t *testing.T) {
},
{
"invalid next validator hash",
meta.Header{
metadata.Header{
Version: version.Consensus{Block: version.BlockProtocol},
ChainID: string(make([]byte, meta.MaxChainIDLen)),
ChainID: string(make([]byte, metadata.MaxChainIDLen)),
Height: 1,
LastBlockID: meta.BlockID{
LastBlockID: metadata.BlockID{
Hash: make([]byte, tmhash.Size),
PartSetHeader: meta.PartSetHeader{
PartSetHeader: metadata.PartSetHeader{
Hash: make([]byte, tmhash.Size),
},
},
@@ -351,13 +351,13 @@ func TestHeader_ValidateBasic(t *testing.T) {
},
{
"invalid consensus hash",
meta.Header{
metadata.Header{
Version: version.Consensus{Block: version.BlockProtocol},
ChainID: string(make([]byte, meta.MaxChainIDLen)),
ChainID: string(make([]byte, metadata.MaxChainIDLen)),
Height: 1,
LastBlockID: meta.BlockID{
LastBlockID: metadata.BlockID{
Hash: make([]byte, tmhash.Size),
PartSetHeader: meta.PartSetHeader{
PartSetHeader: metadata.PartSetHeader{
Hash: make([]byte, tmhash.Size),
},
},
@@ -373,13 +373,13 @@ func TestHeader_ValidateBasic(t *testing.T) {
},
{
"invalid last results hash",
meta.Header{
metadata.Header{
Version: version.Consensus{Block: version.BlockProtocol},
ChainID: string(make([]byte, meta.MaxChainIDLen)),
ChainID: string(make([]byte, metadata.MaxChainIDLen)),
Height: 1,
LastBlockID: meta.BlockID{
LastBlockID: metadata.BlockID{
Hash: make([]byte, tmhash.Size),
PartSetHeader: meta.PartSetHeader{
PartSetHeader: metadata.PartSetHeader{
Hash: make([]byte, tmhash.Size),
},
},
@@ -396,13 +396,13 @@ func TestHeader_ValidateBasic(t *testing.T) {
},
{
"valid header",
meta.Header{
metadata.Header{
Version: version.Consensus{Block: version.BlockProtocol},
ChainID: string(make([]byte, meta.MaxChainIDLen)),
ChainID: string(make([]byte, metadata.MaxChainIDLen)),
Height: 1,
LastBlockID: meta.BlockID{
LastBlockID: metadata.BlockID{
Hash: make([]byte, tmhash.Size),
PartSetHeader: meta.PartSetHeader{
PartSetHeader: metadata.PartSetHeader{
Hash: make([]byte, tmhash.Size),
},
},
@@ -438,18 +438,18 @@ func TestHeaderProto(t *testing.T) {
h1 := test.MakeRandomHeader()
tc := []struct {
msg string
h1 *meta.Header
h1 *metadata.Header
expPass bool
}{
{"success", h1, true},
{"failure empty Header", &meta.Header{}, false},
{"failure empty Header", &metadata.Header{}, false},
}
for _, tt := range tc {
tt := tt
t.Run(tt.msg, func(t *testing.T) {
pb := tt.h1.ToProto()
h, err := meta.HeaderFromProto(pb)
h, err := metadata.HeaderFromProto(pb)
if tt.expPass {
require.NoError(t, err, tt.msg)
require.Equal(t, tt.h1, &h, tt.msg)
@@ -463,12 +463,12 @@ func TestHeaderProto(t *testing.T) {
func TestHeaderHashVector(t *testing.T) {
chainID := "test"
h := meta.Header{
h := metadata.Header{
Version: version.Consensus{Block: 1, App: 1},
ChainID: chainID,
Height: 50,
Time: time.Date(math.MaxInt64, 0, 0, 0, 0, 0, math.MaxInt64, time.UTC),
LastBlockID: meta.BlockID{},
LastBlockID: metadata.BlockID{},
LastCommitHash: []byte("f2564c78071e26643ae9b3e2a19fa0dc10d4d9e873aa0be808660123f11a1e78"),
DataHash: []byte("f2564c78071e26643ae9b3e2a19fa0dc10d4d9e873aa0be808660123f11a1e78"),
ValidatorsHash: []byte("f2564c78071e26643ae9b3e2a19fa0dc10d4d9e873aa0be808660123f11a1e78"),
@@ -483,7 +483,7 @@ func TestHeaderHashVector(t *testing.T) {
}
testCases := []struct {
header meta.Header
header metadata.Header
expBytes string
}{
{header: h, expBytes: "87b6117ac7f827d656f178a3d6d30b24b205db2b6a3a053bae8baf4618570bfc"},

View File

@@ -1,4 +1,4 @@
package meta
package metadata
import (
"bytes"

View File

@@ -1,4 +1,4 @@
package meta_test
package metadata_test
import (
"testing"
@@ -8,15 +8,15 @@ import (
test "github.com/tendermint/tendermint/internal/test/factory"
"github.com/tendermint/tendermint/libs/bytes"
"github.com/tendermint/tendermint/pkg/meta"
"github.com/tendermint/tendermint/pkg/metadata"
)
func TestBlockIDEquals(t *testing.T) {
var (
blockID = meta.BlockID{[]byte("hash"), meta.PartSetHeader{2, []byte("part_set_hash")}}
blockIDDuplicate = meta.BlockID{[]byte("hash"), meta.PartSetHeader{2, []byte("part_set_hash")}}
blockIDDifferent = meta.BlockID{[]byte("different_hash"), meta.PartSetHeader{2, []byte("part_set_hash")}}
blockIDEmpty = meta.BlockID{}
blockID = metadata.BlockID{[]byte("hash"), metadata.PartSetHeader{2, []byte("part_set_hash")}}
blockIDDuplicate = metadata.BlockID{[]byte("hash"), metadata.PartSetHeader{2, []byte("part_set_hash")}}
blockIDDifferent = metadata.BlockID{[]byte("different_hash"), metadata.PartSetHeader{2, []byte("part_set_hash")}}
blockIDEmpty = metadata.BlockID{}
)
assert.True(t, blockID.Equals(blockIDDuplicate))
@@ -27,17 +27,17 @@ func TestBlockIDEquals(t *testing.T) {
}
func TestBlockIDValidateBasic(t *testing.T) {
validBlockID := meta.BlockID{
validBlockID := metadata.BlockID{
Hash: bytes.HexBytes{},
PartSetHeader: meta.PartSetHeader{
PartSetHeader: metadata.PartSetHeader{
Total: 1,
Hash: bytes.HexBytes{},
},
}
invalidBlockID := meta.BlockID{
invalidBlockID := metadata.BlockID{
Hash: []byte{0},
PartSetHeader: meta.PartSetHeader{
PartSetHeader: metadata.PartSetHeader{
Total: 1,
Hash: []byte{0},
},
@@ -46,7 +46,7 @@ func TestBlockIDValidateBasic(t *testing.T) {
testCases := []struct {
testName string
blockIDHash bytes.HexBytes
blockIDPartSetHeader meta.PartSetHeader
blockIDPartSetHeader metadata.PartSetHeader
expectErr bool
}{
{"Valid BlockID", validBlockID.Hash, validBlockID.PartSetHeader, false},
@@ -57,7 +57,7 @@ func TestBlockIDValidateBasic(t *testing.T) {
for _, tc := range testCases {
tc := tc
t.Run(tc.testName, func(t *testing.T) {
blockID := meta.BlockID{
blockID := metadata.BlockID{
Hash: tc.blockIDHash,
PartSetHeader: tc.blockIDPartSetHeader,
}
@@ -70,17 +70,17 @@ func TestBlockIDProtoBuf(t *testing.T) {
blockID := test.MakeBlockIDWithHash([]byte("hash"))
testCases := []struct {
msg string
bid1 *meta.BlockID
bid1 *metadata.BlockID
expPass bool
}{
{"success", &blockID, true},
{"success empty", &meta.BlockID{}, true},
{"success empty", &metadata.BlockID{}, true},
{"failure BlockID nil", nil, false},
}
for _, tc := range testCases {
protoBlockID := tc.bid1.ToProto()
bi, err := meta.BlockIDFromProto(&protoBlockID)
bi, err := metadata.BlockIDFromProto(&protoBlockID)
if tc.expPass {
require.NoError(t, err)
require.Equal(t, tc.bid1, bi, tc.msg)

View File

@@ -1,4 +1,4 @@
package meta
package metadata
import (
"bytes"

View File

@@ -1,4 +1,4 @@
package meta
package metadata
import (
"io/ioutil"

View File

@@ -1,4 +1,4 @@
package meta
package metadata
import (
"reflect"