mirror of
https://github.com/tendermint/tendermint.git
synced 2026-09-29 11:15:50 +00:00
types: remove nested evidence field from block (#7765)
* types: replaced EvidenceData in block structure with EvidenceList * types: introduced toProto, fromProto functions to EvidenceList * updated Changelog * Removed comments from tests
This commit is contained in:
@@ -15,6 +15,7 @@ import (
|
||||
"github.com/tendermint/tendermint/crypto/merkle"
|
||||
"github.com/tendermint/tendermint/crypto/tmhash"
|
||||
"github.com/tendermint/tendermint/internal/jsontypes"
|
||||
tmmath "github.com/tendermint/tendermint/libs/math"
|
||||
tmrand "github.com/tendermint/tendermint/libs/rand"
|
||||
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
|
||||
)
|
||||
@@ -554,6 +555,73 @@ func LightClientAttackEvidenceFromProto(lpb *tmproto.LightClientAttackEvidence)
|
||||
// EvidenceList is a list of Evidence. Evidences is not a word.
|
||||
type EvidenceList []Evidence
|
||||
|
||||
// StringIndented returns a string representation of the evidence.
|
||||
func (evl EvidenceList) StringIndented(indent string) string {
|
||||
if evl == nil {
|
||||
return "nil-Evidence"
|
||||
}
|
||||
evStrings := make([]string, tmmath.MinInt(len(evl), 21))
|
||||
for i, ev := range evl {
|
||||
if i == 20 {
|
||||
evStrings[i] = fmt.Sprintf("... (%v total)", len(evl))
|
||||
break
|
||||
}
|
||||
evStrings[i] = fmt.Sprintf("Evidence:%v", ev)
|
||||
}
|
||||
return fmt.Sprintf(`EvidenceList{
|
||||
%s %v
|
||||
%s}#%v`,
|
||||
indent, strings.Join(evStrings, "\n"+indent+" "),
|
||||
indent, evl.Hash())
|
||||
}
|
||||
|
||||
// ByteSize returns the total byte size of all the evidence
|
||||
func (evl EvidenceList) ByteSize() int64 {
|
||||
if len(evl) != 0 {
|
||||
pb, err := evl.ToProto()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return int64(pb.Size())
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
// FromProto sets a protobuf EvidenceList to the given pointer.
|
||||
func (evl *EvidenceList) FromProto(eviList *tmproto.EvidenceList) error {
|
||||
if eviList == nil {
|
||||
return errors.New("nil evidence list")
|
||||
}
|
||||
|
||||
eviBzs := make(EvidenceList, len(eviList.Evidence))
|
||||
for i := range eviList.Evidence {
|
||||
evi, err := EvidenceFromProto(&eviList.Evidence[i])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
eviBzs[i] = evi
|
||||
}
|
||||
*evl = eviBzs
|
||||
return nil
|
||||
}
|
||||
|
||||
// ToProto converts EvidenceList to protobuf
|
||||
func (evl *EvidenceList) ToProto() (*tmproto.EvidenceList, error) {
|
||||
if evl == nil {
|
||||
return nil, errors.New("nil evidence list")
|
||||
}
|
||||
|
||||
eviBzs := make([]tmproto.Evidence, len(*evl))
|
||||
for i, v := range *evl {
|
||||
protoEvi, err := EvidenceToProto(v)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
eviBzs[i] = *protoEvi
|
||||
}
|
||||
return &tmproto.EvidenceList{Evidence: eviBzs}, nil
|
||||
}
|
||||
|
||||
func (evl EvidenceList) MarshalJSON() ([]byte, error) {
|
||||
lst := make([]json.RawMessage, len(evl))
|
||||
for i, ev := range evl {
|
||||
|
||||
Reference in New Issue
Block a user