Merge remote-tracking branch 'origin' into wb/abci-process-proposal-synchronize

This commit is contained in:
William Banfield
2022-02-22 16:04:37 -05:00
492 changed files with 65490 additions and 4079 deletions
+3 -2
View File
@@ -329,7 +329,7 @@ func MakeBlock(height int64, txs []Tx, lastCommit *Commit, evidence []Evidence)
// NOTE: changes to the Header should be duplicated in:
// - header.Hash()
// - abci.Header
// - https://github.com/tendermint/spec/blob/master/spec/blockchain/blockchain.md
// - https://github.com/tendermint/tendermint/blob/master/spec/core/data_structures.md
type Header struct {
// basic block info
Version version.Consensus `json:"version"`
@@ -518,7 +518,8 @@ func (h *Header) StringIndented(indent string) string {
indent, h.LastResultsHash,
indent, h.EvidenceHash,
indent, h.ProposerAddress,
indent, h.Hash())
indent, h.Hash(),
)
}
// ToProto converts Header to protobuf
+18 -5
View File
@@ -40,6 +40,10 @@ const (
EventTimeoutWaitValue = "TimeoutWait"
EventValidBlockValue = "ValidBlock"
EventVoteValue = "Vote"
// Events emitted by the evidence reactor when evidence is validated
// and before it is committed
EventEvidenceValidatedValue = "EvidenceValidated"
)
// Pre-populated ABCI Tendermint-reserved events
@@ -104,6 +108,7 @@ func init() {
jsontypes.MustRegister(EventDataTx{})
jsontypes.MustRegister(EventDataValidatorSetUpdates{})
jsontypes.MustRegister(EventDataVote{})
jsontypes.MustRegister(EventDataEvidenceValidated{})
jsontypes.MustRegister(EventDataString(""))
}
@@ -114,8 +119,7 @@ type EventDataNewBlock struct {
Block *Block `json:"block"`
BlockID BlockID `json:"block_id"`
ResultBeginBlock abci.ResponseBeginBlock `json:"result_begin_block"`
ResultEndBlock abci.ResponseEndBlock `json:"result_end_block"`
ResultFinalizeBlock abci.ResponseFinalizeBlock `json:"result_finalize_block"`
}
// TypeTag implements the required method of jsontypes.Tagged.
@@ -124,9 +128,8 @@ func (EventDataNewBlock) TypeTag() string { return "tendermint/event/NewBlock" }
type EventDataNewBlockHeader struct {
Header Header `json:"header"`
NumTxs int64 `json:"num_txs,string"` // Number of txs in a block
ResultBeginBlock abci.ResponseBeginBlock `json:"result_begin_block"`
ResultEndBlock abci.ResponseEndBlock `json:"result_end_block"`
NumTxs int64 `json:"num_txs,string"` // Number of txs in a block
ResultFinalizeBlock abci.ResponseFinalizeBlock `json:"result_finalize_block"`
}
// TypeTag implements the required method of jsontypes.Tagged.
@@ -225,6 +228,15 @@ type EventDataStateSyncStatus struct {
// TypeTag implements the required method of jsontypes.Tagged.
func (EventDataStateSyncStatus) TypeTag() string { return "tendermint/event/StateSyncStatus" }
type EventDataEvidenceValidated struct {
Evidence Evidence `json:"evidence"`
Height int64 `json:"height,string"`
}
// TypeTag implements the required method of jsontypes.Tagged.
func (EventDataEvidenceValidated) TypeTag() string { return "tendermint/event/EvidenceValidated" }
// PUBSUB
const (
@@ -263,6 +275,7 @@ var (
EventQueryVote = QueryForEvent(EventVoteValue)
EventQueryBlockSyncStatus = QueryForEvent(EventBlockSyncStatusValue)
EventQueryStateSyncStatus = QueryForEvent(EventStateSyncStatusValue)
EventQueryEvidenceValidated = QueryForEvent(EventEvidenceValidatedValue)
)
func EventQueryTxFor(tx Tx) *tmquery.Query {
+4 -1
View File
@@ -113,7 +113,10 @@ func (genDoc *GenesisDoc) ValidateAndComplete() error {
if genDoc.ConsensusParams == nil {
genDoc.ConsensusParams = DefaultConsensusParams()
} else if err := genDoc.ConsensusParams.ValidateConsensusParams(); err != nil {
}
genDoc.ConsensusParams.Complete()
if err := genDoc.ConsensusParams.ValidateConsensusParams(); err != nil {
return err
}
+1 -1
View File
@@ -126,7 +126,7 @@ func TestBasicGenesisDoc(t *testing.T) {
}
func TestGenesisSaveAs(t *testing.T) {
tmpfile, err := os.CreateTemp("", "genesis")
tmpfile, err := os.CreateTemp(t.TempDir(), "genesis")
require.NoError(t, err)
defer os.Remove(tmpfile.Name())
+9 -8
View File
@@ -82,10 +82,10 @@ func (info NodeInfo) Validate() error {
}
// Validate Version
if len(info.Version) > 0 &&
(!tmstrings.IsASCIIText(info.Version) || tmstrings.ASCIITrim(info.Version) == "") {
return fmt.Errorf("info.Version must be valid ASCII text without tabs, but got %v", info.Version)
if len(info.Version) > 0 {
if ver, err := tmstrings.ASCIITrim(info.Version); err != nil || ver == "" {
return fmt.Errorf("info.Version must be valid ASCII text without tabs, but got, %q [%s]", info.Version, ver)
}
}
// Validate Channels - ensure max and check for duplicates.
@@ -101,8 +101,7 @@ func (info NodeInfo) Validate() error {
channels[ch] = struct{}{}
}
// Validate Moniker.
if !tmstrings.IsASCIIText(info.Moniker) || tmstrings.ASCIITrim(info.Moniker) == "" {
if m, err := tmstrings.ASCIITrim(info.Moniker); err != nil || m == "" {
return fmt.Errorf("info.Moniker must be valid non-empty ASCII text without tabs, but got %v", info.Moniker)
}
@@ -116,8 +115,10 @@ func (info NodeInfo) Validate() error {
}
// XXX: Should we be more strict about address formats?
rpcAddr := other.RPCAddress
if len(rpcAddr) > 0 && (!tmstrings.IsASCIIText(rpcAddr) || tmstrings.ASCIITrim(rpcAddr) == "") {
return fmt.Errorf("info.Other.RPCAddress=%v must be valid ASCII text without tabs", rpcAddr)
if len(rpcAddr) > 0 {
if a, err := tmstrings.ASCIITrim(rpcAddr); err != nil || a == "" {
return fmt.Errorf("info.Other.RPCAddress=%v must be valid ASCII text without tabs", rpcAddr)
}
}
return nil
+13 -9
View File
@@ -6,6 +6,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/crypto/ed25519"
tmnet "github.com/tendermint/tendermint/libs/net"
"github.com/tendermint/tendermint/version"
@@ -80,15 +81,18 @@ func TestNodeInfoValidate(t *testing.T) {
assert.NoError(t, ni.Validate())
for _, tc := range testCases {
ni := testNodeInfo(t, nodeKeyID, name)
ni.Channels = channels
tc.malleateNodeInfo(&ni)
err := ni.Validate()
if tc.expectErr {
assert.Error(t, err, tc.testName)
} else {
assert.NoError(t, err, tc.testName)
}
t.Run(tc.testName, func(t *testing.T) {
ni := testNodeInfo(t, nodeKeyID, name)
ni.Channels = channels
tc.malleateNodeInfo(&ni)
err := ni.Validate()
if tc.expectErr {
assert.Error(t, err, tc.testName)
} else {
assert.NoError(t, err, tc.testName)
}
})
}
}
+12 -5
View File
@@ -79,7 +79,7 @@ type VersionParams struct {
// SynchronyParams influence the validity of block timestamps.
// For more information on the relationship of the synchrony parameters to
// block validity, see the Proposer-Based Timestamps specification:
// https://github.com/tendermint/spec/blob/master/spec/consensus/proposer-based-timestamp/README.md
// https://github.com/tendermint/tendermint/blob/master/spec/consensus/proposer-based-timestamp/README.md
type SynchronyParams struct {
Precision time.Duration `json:"precision,string"`
MessageDelay time.Duration `json:"message_delay,string"`
@@ -128,11 +128,12 @@ func DefaultVersionParams() VersionParams {
}
func DefaultSynchronyParams() SynchronyParams {
// TODO(@wbanfield): Determine experimental values for these defaults
// https://github.com/tendermint/tendermint/issues/7202
return SynchronyParams{
Precision: 500 * time.Millisecond,
MessageDelay: 3 * time.Second,
// 505ms was selected as the default to enable chains that have validators in
// mixed leap-second handling environments.
// For more information, see: https://github.com/tendermint/tendermint/issues/7724
Precision: 505 * time.Millisecond,
MessageDelay: 12 * time.Second,
}
}
@@ -145,6 +146,12 @@ func (val *ValidatorParams) IsValidPubkeyType(pubkeyType string) bool {
return false
}
func (params *ConsensusParams) Complete() {
if params.Synchrony == (SynchronyParams{}) {
params.Synchrony = DefaultSynchronyParams()
}
}
// Validate validates the ConsensusParams to ensure all values are within their
// allowed limits, and returns an error if they are not.
func (params ConsensusParams) ValidateConsensusParams() error {
+1 -1
View File
@@ -89,7 +89,7 @@ func (p *Proposal) ValidateBasic() error {
// localtime <= proposedBlockTime + MsgDelay + Precision
//
// For more information on the meaning of 'timely', see the proposer-based timestamp specification:
// https://github.com/tendermint/spec/tree/master/spec/consensus/proposer-based-timestamp
// https://github.com/tendermint/tendermint/tree/master/spec/consensus/proposer-based-timestamp
func (p *Proposal) IsTimely(recvTime time.Time, sp SynchronyParams, round int32) bool {
// The message delay values are scaled as rounds progress.
// Every 10 rounds, the message delay is doubled to allow consensus to
+1
View File
@@ -6,6 +6,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/crypto"
)
+16
View File
@@ -326,6 +326,22 @@ func (vote *Vote) ToProto() *tmproto.Vote {
}
}
func VotesToProto(votes []*Vote) []*tmproto.Vote {
if votes == nil {
return nil
}
res := make([]*tmproto.Vote, 0, len(votes))
for _, vote := range votes {
v := vote.ToProto()
// protobuf crashes when serializing "repeated" fields with nil elements
if v != nil {
res = append(res, v)
}
}
return res
}
func VoteExtensionFromProto(pext *tmproto.VoteExtension) VoteExtension {
ext := VoteExtension{}
if pext != nil {
+4
View File
@@ -226,6 +226,10 @@ func (voteSet *VoteSet) getVote(valIndex int32, blockKey string) (vote *Vote, ok
return nil, false
}
func (voteSet *VoteSet) GetVotes() []*Vote {
return voteSet.votes
}
// Assumes signature is valid.
// If conflicting vote exists, returns it.
func (voteSet *VoteSet) addVerifiedVote(