mirror of
https://github.com/tendermint/tendermint.git
synced 2026-10-01 12:15:45 +00:00
spec: merge spec repo into tendermint repo (#7804)
This commit is contained in:
+3
-2
@@ -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
|
||||
|
||||
+3
-5
@@ -114,8 +114,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 +123,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.
|
||||
|
||||
@@ -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
@@ -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
@@ -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)
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+1
-1
@@ -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"`
|
||||
|
||||
+1
-1
@@ -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
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/tendermint/tendermint/crypto"
|
||||
)
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user