Browse Source

correctly calculate evidence data size (#5482)

pull/5487/head
Callum Waters 4 years ago
committed by GitHub
parent
commit
6a2a71be07
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 47 additions and 94 deletions
  1. +1
    -1
      blockchain/msgs_test.go
  2. +15
    -2
      node/node_test.go
  3. +26
    -79
      proto/tendermint/types/evidence.pb.go
  4. +0
    -1
      proto/tendermint/types/evidence.proto
  5. +5
    -11
      types/block.go

+ 1
- 1
blockchain/msgs_test.go View File

@ -97,7 +97,7 @@ func TestBlockchainMessageVectors(t *testing.T) {
BlockRequest: &bcproto.BlockRequest{Height: math.MaxInt64}}},
"0a0a08ffffffffffffffff7f"},
{"BlockResponseMessage", &bcproto.Message{Sum: &bcproto.Message_BlockResponse{
BlockResponse: &bcproto.BlockResponse{Block: bpb}}}, "1ab5010ab2010a5b0a02080b1803220b088092b8c398feffffff012a0212003a20c4da88e876062aa1543400d50d0eaa0dac88096057949cfb7bca7f3a48c04bf96a20e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855122f0a0b48656c6c6f20576f726c641220c4da88e876062aa1543400d50d0eaa0dac88096057949cfb7bca7f3a48c04bf91a221220e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"},
BlockResponse: &bcproto.BlockResponse{Block: bpb}}}, "1a93010a90010a5b0a02080b1803220b088092b8c398feffffff012a0212003a20c4da88e876062aa1543400d50d0eaa0dac88096057949cfb7bca7f3a48c04bf96a20e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855122f0a0b48656c6c6f20576f726c641220c4da88e876062aa1543400d50d0eaa0dac88096057949cfb7bca7f3a48c04bf91a00"},
{"NoBlockResponseMessage", &bcproto.Message{Sum: &bcproto.Message_NoBlockResponse{
NoBlockResponse: &bcproto.NoBlockResponse{Height: 1}}}, "12020801"},
{"NoBlockResponseMessage", &bcproto.Message{Sum: &bcproto.Message_NoBlockResponse{


+ 15
- 2
node/node_test.go View File

@ -234,6 +234,7 @@ func TestCreateProposalBlock(t *testing.T) {
state, stateDB, privVals := state(1, height)
stateStore := sm.NewStore(stateDB)
maxBytes := 16384
var partSize uint32 = 256
maxEvidenceBytes := int64(maxBytes / 2)
state.ConsensusParams.Block.MaxBytes = int64(maxBytes)
state.ConsensusParams.Evidence.MaxBytes = maxEvidenceBytes
@ -270,8 +271,8 @@ func TestCreateProposalBlock(t *testing.T) {
// fill the mempool with more txs
// than can fit in a block
txLength := 1000
for i := 0; i < maxBytes/txLength; i++ {
txLength := 100
for i := 0; i <= maxBytes/txLength; i++ {
tx := tmrand.Bytes(txLength)
err := mempool.CheckTx(tx, nil, mempl.TxInfo{})
assert.NoError(t, err)
@ -292,6 +293,18 @@ func TestCreateProposalBlock(t *testing.T) {
proposerAddr,
)
// check that the part set does not exceed the maximum block size
partSet := block.MakePartSet(partSize)
assert.Less(t, partSet.ByteSize(), int64(maxBytes))
partSetFromHeader := types.NewPartSetFromHeader(partSet.Header())
for partSetFromHeader.Count() < partSetFromHeader.Total() {
added, err := partSetFromHeader.AddPart(partSet.GetPart(int(partSetFromHeader.Count())))
require.NoError(t, err)
require.True(t, added)
}
assert.EqualValues(t, partSetFromHeader.ByteSize(), partSet.ByteSize())
err = blockExec.ValidateBlock(state, block)
assert.NoError(t, err)
}


+ 26
- 79
proto/tendermint/types/evidence.pb.go View File

@ -217,7 +217,6 @@ func (*Evidence) XXX_OneofWrappers() []interface{} {
// EvidenceData contains any evidence of malicious wrong-doing by validators
type EvidenceData struct {
Evidence []Evidence `protobuf:"bytes,1,rep,name=evidence,proto3" json:"evidence"`
Hash []byte `protobuf:"bytes,2,opt,name=hash,proto3" json:"hash,omitempty"`
}
func (m *EvidenceData) Reset() { *m = EvidenceData{} }
@ -260,13 +259,6 @@ func (m *EvidenceData) GetEvidence() []Evidence {
return nil
}
func (m *EvidenceData) GetHash() []byte {
if m != nil {
return m.Hash
}
return nil
}
func init() {
proto.RegisterType((*DuplicateVoteEvidence)(nil), "tendermint.types.DuplicateVoteEvidence")
proto.RegisterType((*LightClientAttackEvidence)(nil), "tendermint.types.LightClientAttackEvidence")
@ -277,32 +269,32 @@ func init() {
func init() { proto.RegisterFile("tendermint/types/evidence.proto", fileDescriptor_6825fabc78e0a168) }
var fileDescriptor_6825fabc78e0a168 = []byte{
// 398 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x52, 0xcd, 0x6a, 0xea, 0x40,
0x14, 0x4e, 0xae, 0x3f, 0xc8, 0xe8, 0x05, 0x6f, 0xb8, 0xb6, 0x2a, 0x12, 0x4b, 0xba, 0xa8, 0x50,
0x9a, 0x80, 0x5d, 0x74, 0xd3, 0x8d, 0xa9, 0x05, 0x0b, 0xdd, 0x34, 0x8b, 0x2e, 0xba, 0x49, 0x27,
0x93, 0x69, 0x32, 0x98, 0xcc, 0x88, 0x4e, 0x84, 0x3e, 0x43, 0x37, 0x7d, 0x2c, 0x97, 0x2e, 0xbb,
0x2a, 0x45, 0xfb, 0x20, 0x25, 0x13, 0x8d, 0x62, 0x94, 0x6e, 0x86, 0xc3, 0x39, 0xdf, 0x9c, 0xef,
0x87, 0x03, 0xda, 0x1c, 0x53, 0x17, 0x8f, 0x43, 0x42, 0xb9, 0xc1, 0x5f, 0x47, 0x78, 0x62, 0xe0,
0x29, 0x71, 0x31, 0x45, 0x58, 0x1f, 0x8d, 0x19, 0x67, 0x4a, 0x75, 0x03, 0xd0, 0x05, 0xa0, 0xf9,
0xdf, 0x63, 0x1e, 0x13, 0x43, 0x23, 0xae, 0x12, 0x5c, 0xb3, 0x95, 0x59, 0x24, 0xde, 0x64, 0xaa,
0x45, 0xa0, 0xd6, 0x8f, 0x46, 0x01, 0x41, 0x90, 0xe3, 0x47, 0xc6, 0xf1, 0xed, 0x8a, 0x44, 0xb9,
0x00, 0xc5, 0x29, 0xe3, 0xd8, 0x86, 0x75, 0xf9, 0x44, 0xee, 0x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0xd4, 0xe6, 0xc3, 0x6c, 0xa1, 0xca, 0xf3, 0x85, 0x2a, 0x7f, 0x2d, 0x54, 0xf9,
0x7d, 0xa9, 0x4a, 0xf3, 0xa5, 0x2a, 0x7d, 0x2c, 0x55, 0xe9, 0xe9, 0xca, 0x23, 0xdc, 0x8f, 0x1c,
0x1d, 0xb1, 0xd0, 0xd8, 0x3e, 0xc8, 0x4d, 0x99, 0x1c, 0xee, 0xee, 0xb1, 0x3a, 0x45, 0xd1, 0xbf,
0xfc, 0x09, 0x00, 0x00, 0xff, 0xff, 0xd1, 0x75, 0x06, 0x32, 0x10, 0x03, 0x00, 0x00,
// 388 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x52, 0xc1, 0x6a, 0xea, 0x40,
0x14, 0x4d, 0x9e, 0x4f, 0x91, 0xd1, 0x07, 0xbe, 0xf0, 0x7c, 0x55, 0x91, 0x58, 0xd2, 0x45, 0x85,
0xd2, 0x04, 0xec, 0xa2, 0x9b, 0x6e, 0x4c, 0x2d, 0x58, 0x70, 0xd3, 0x2c, 0xba, 0xe8, 0x26, 0x24,
0x93, 0x69, 0x1c, 0x4c, 0x66, 0x44, 0x6f, 0x84, 0x7e, 0x43, 0x37, 0xfd, 0x2c, 0x97, 0x2e, 0xbb,
0x2a, 0x45, 0xfb, 0x21, 0x25, 0x13, 0x8d, 0x62, 0x94, 0x6e, 0x86, 0xe1, 0xdc, 0x73, 0xef, 0xb9,
0xe7, 0x70, 0x51, 0x0b, 0x08, 0xf3, 0xc8, 0x24, 0xa4, 0x0c, 0x0c, 0x78, 0x19, 0x93, 0xa9, 0x41,
0x66, 0xd4, 0x23, 0x0c, 0x13, 0x7d, 0x3c, 0xe1, 0xc0, 0x95, 0xca, 0x96, 0xa0, 0x0b, 0x42, 0xe3,
0x9f, 0xcf, 0x7d, 0x2e, 0x8a, 0x46, 0xfc, 0x4b, 0x78, 0x8d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0xa0, 0x9e, 0x03, 0x8e, 0x72, 0x83, 0x8a, 0x3b, 0xd6, 0x72, 0xed, 0x52, 0xa7, 0x91, 0x95,
0x4c, 0x87, 0xfc, 0x9e, 0x7f, 0xb4, 0x24, 0x2b, 0xed, 0x30, 0x1f, 0xe6, 0x4b, 0x55, 0x5e, 0x2c,
0x55, 0xf9, 0x73, 0xa9, 0xca, 0x6f, 0x2b, 0x55, 0x5a, 0xac, 0x54, 0xe9, 0x7d, 0xa5, 0x4a, 0x4f,
0xd7, 0x3e, 0x85, 0x61, 0xe4, 0xea, 0x98, 0x87, 0xc6, 0xee, 0xf1, 0x6d, 0xbf, 0xc9, 0x91, 0xee,
0x1f, 0xa6, 0x5b, 0x10, 0xf8, 0xd5, 0x77, 0x00, 0x00, 0x00, 0xff, 0xff, 0xc0, 0x7f, 0xe9, 0x7a,
0xfc, 0x02, 0x00, 0x00,
}
func (m *DuplicateVoteEvidence) Marshal() (dAtA []byte, err error) {
@ -486,13 +478,6 @@ func (m *EvidenceData) MarshalToSizedBuffer(dAtA []byte) (int, error) {
_ = i
var l int
_ = l
if len(m.Hash) > 0 {
i -= len(m.Hash)
copy(dAtA[i:], m.Hash)
i = encodeVarintEvidence(dAtA, i, uint64(len(m.Hash)))
i--
dAtA[i] = 0x12
}
if len(m.Evidence) > 0 {
for iNdEx := len(m.Evidence) - 1; iNdEx >= 0; iNdEx-- {
{
@ -602,10 +587,6 @@ func (m *EvidenceData) Size() (n int) {
n += 1 + l + sovEvidence(uint64(l))
}
}
l = len(m.Hash)
if l > 0 {
n += 1 + l + sovEvidence(uint64(l))
}
return n
}
@ -1034,40 +1015,6 @@ func (m *EvidenceData) Unmarshal(dAtA []byte) error {
return err
}
iNdEx = postIndex
case 2:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field Hash", wireType)
}
var byteLen int
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowEvidence
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
byteLen |= int(b&0x7F) << shift
if b < 0x80 {
break
}
}
if byteLen < 0 {
return ErrInvalidLengthEvidence
}
postIndex := iNdEx + byteLen
if postIndex < 0 {
return ErrInvalidLengthEvidence
}
if postIndex > l {
return io.ErrUnexpectedEOF
}
m.Hash = append(m.Hash[:0], dAtA[iNdEx:postIndex]...)
if m.Hash == nil {
m.Hash = []byte{}
}
iNdEx = postIndex
default:
iNdEx = preIndex
skippy, err := skipEvidence(dAtA[iNdEx:])


+ 0
- 1
proto/tendermint/types/evidence.proto View File

@ -28,5 +28,4 @@ message Evidence {
// EvidenceData contains any evidence of malicious wrong-doing by validators
message EvidenceData {
repeated Evidence evidence = 1 [(gogoproto.nullable) = false];
bytes hash = 2;
}

+ 5
- 11
types/block.go View File

@ -1077,13 +1077,11 @@ func (data *EvidenceData) Hash() tmbytes.HexBytes {
// ByteSize returns the total byte size of all the evidence
func (data *EvidenceData) ByteSize() int64 {
if data.byteSize == 0 && len(data.Evidence) != 0 {
for _, ev := range data.Evidence {
pb, err := EvidenceToProto(ev)
if err != nil {
panic(err)
}
data.byteSize += int64(pb.Size())
pb, err := data.ToProto()
if err != nil {
panic(err)
}
data.byteSize = int64(pb.Size())
}
return data.byteSize
}
@ -1125,10 +1123,6 @@ func (data *EvidenceData) ToProto() (*tmproto.EvidenceData, error) {
}
evi.Evidence = eviBzs
if data.hash != nil {
evi.Hash = data.hash
}
return evi, nil
}
@ -1145,9 +1139,9 @@ func (data *EvidenceData) FromProto(eviData *tmproto.EvidenceData) error {
return err
}
eviBzs[i] = evi
data.byteSize += int64(eviData.Evidence[i].Size())
}
data.Evidence = eviBzs
data.byteSize = int64(eviData.Size())
return nil
}


Loading…
Cancel
Save