From 603c160842437bcad66f9c184656b1b9261e30f2 Mon Sep 17 00:00:00 2001 From: Sergi Rene Date: Mon, 12 Aug 2024 11:27:39 +0200 Subject: [PATCH] refactor(p2p): rename p2p block event (#1006) --- block/p2p.go | 4 +- p2p/block.go | 74 +++++++++ p2p/block_sync.go | 10 +- p2p/block_sync_test.go | 2 +- p2p/client.go | 4 +- p2p/p2p_block.go | 74 --------- .../{gossiped_block.pb.go => blockdata.pb.go} | 140 +++++++++--------- p2p/validator.go | 2 +- p2p/validator_test.go | 2 +- .../{gossiped_block.proto => blockdata.proto} | 2 +- 10 files changed, 157 insertions(+), 157 deletions(-) create mode 100644 p2p/block.go delete mode 100644 p2p/p2p_block.go rename p2p/pb/{gossiped_block.pb.go => blockdata.pb.go} (56%) rename proto/p2p/{gossiped_block.proto => blockdata.proto} (88%) diff --git a/block/p2p.go b/block/p2p.go index 7de670b11..2522a4099 100644 --- a/block/p2p.go +++ b/block/p2p.go @@ -11,7 +11,7 @@ import ( // onReceivedBlock receives a block received event from P2P, saves the block to a cache and tries to apply the blocks from the cache. func (m *Manager) onReceivedBlock(event pubsub.Message) { - eventData, ok := event.Data().(p2p.P2PBlockEvent) + eventData, ok := event.Data().(p2p.BlockData) if !ok { m.logger.Error("onReceivedBlock", "err", "wrong event data received") return @@ -64,7 +64,7 @@ func (m *Manager) onReceivedBlock(event pubsub.Message) { // gossipBlock sends created blocks by the sequencer to full-nodes using P2P gossipSub func (m *Manager) gossipBlock(ctx context.Context, block types.Block, commit types.Commit) error { m.logger.Info("Gossipping block", "height", block.Header.Height) - gossipedBlock := p2p.P2PBlockEvent{Block: block, Commit: commit} + gossipedBlock := p2p.BlockData{Block: block, Commit: commit} gossipedBlockBytes, err := gossipedBlock.MarshalBinary() if err != nil { return fmt.Errorf("marshal binary: %w: %w", err, ErrNonRecoverable) diff --git a/p2p/block.go b/p2p/block.go new file mode 100644 index 000000000..099dcad53 --- /dev/null +++ b/p2p/block.go @@ -0,0 +1,74 @@ +package p2p + +import ( + "github.com/dymensionxyz/dymint/p2p/pb" + "github.com/dymensionxyz/dymint/types" + tmtypes "github.com/tendermint/tendermint/types" +) + +/* -------------------------------------------------------------------------- */ +/* Event Data */ +/* -------------------------------------------------------------------------- */ + +// BlockData defines the struct of the data for each block sent via P2P +type BlockData struct { + // Block is the block that was gossiped + Block types.Block + // Commit is the commit that was gossiped + Commit types.Commit +} + +// MarshalBinary encodes BlockData into binary form and returns it. +func (b *BlockData) MarshalBinary() ([]byte, error) { + return b.ToProto().Marshal() +} + +// UnmarshalBinary decodes binary form of p2p received block into object. +func (b *BlockData) UnmarshalBinary(data []byte) error { + var pbBlock pb.BlockData + err := pbBlock.Unmarshal(data) + if err != nil { + return err + } + err = b.FromProto(&pbBlock) + return err +} + +// ToProto converts Data into protobuf representation and returns it. +func (b *BlockData) ToProto() *pb.BlockData { + return &pb.BlockData{ + Block: b.Block.ToProto(), + Commit: b.Commit.ToProto(), + } +} + +// FromProto fills BlockData with data from its protobuf representation. +func (b *BlockData) FromProto(other *pb.BlockData) error { + if err := b.Block.FromProto(other.Block); err != nil { + return err + } + if err := b.Commit.FromProto(other.Commit); err != nil { + return err + } + return nil +} + +// Validate run basic validation on the p2p block received +func (b *BlockData) Validate(proposer *types.Sequencer) error { + if err := b.Block.ValidateBasic(); err != nil { + return err + } + if err := b.Commit.ValidateBasic(); err != nil { + return err + } + if err := b.Commit.ValidateWithHeader(proposer, &b.Block.Header); err != nil { + return err + } + abciData := tmtypes.Data{ + Txs: types.ToABCIBlockDataTxs(&b.Block.Data), + } + if b.Block.Header.DataHash != [32]byte(abciData.Hash()) { + return types.ErrInvalidHeaderDataHash + } + return nil +} diff --git a/p2p/block_sync.go b/p2p/block_sync.go index e562fcfda..e7bda4bf2 100644 --- a/p2p/block_sync.go +++ b/p2p/block_sync.go @@ -39,7 +39,7 @@ type BlockSync struct { logger types.Logger } -type BlockSyncMessageHandler func(block *P2PBlockEvent) +type BlockSyncMessageHandler func(block *BlockData) // SetupBlockSync initializes all services required to provide and retrieve block data in the P2P network. func SetupBlockSync(ctx context.Context, h host.Host, store datastore.Datastore, logger types.Logger) *BlockSync { @@ -99,14 +99,14 @@ func (blocksync *BlockSync) SaveBlock(ctx context.Context, block []byte) (cid.Ci } // LoadBlock retrieves the blocks (from the local blockstore or the network) using the DAGService to discover all data chunks that are part of the same block. -func (blocksync *BlockSync) LoadBlock(ctx context.Context, cid cid.Cid) (P2PBlockEvent, error) { +func (blocksync *BlockSync) LoadBlock(ctx context.Context, cid cid.Cid) (BlockData, error) { blockBytes, err := blocksync.dsrv.LoadBlock(ctx, cid) if err != nil { - return P2PBlockEvent{}, err + return BlockData{}, err } - var block P2PBlockEvent + var block BlockData if err := block.UnmarshalBinary(blockBytes); err != nil { - return P2PBlockEvent{}, fmt.Errorf("deserialize blocksync block %w", err) + return BlockData{}, fmt.Errorf("deserialize blocksync block %w", err) } return block, nil } diff --git a/p2p/block_sync_test.go b/p2p/block_sync_test.go index 3baf01cef..6b61f2ebf 100644 --- a/p2p/block_sync_test.go +++ b/p2p/block_sync_test.go @@ -33,7 +33,7 @@ func TestBlockSync(t *testing.T) { commits, err := testutil.GenerateCommits(blocks, manager.LocalKey) require.NoError(t, err) - gossipedBlock := p2p.P2PBlockEvent{Block: *blocks[0], Commit: *commits[0]} + gossipedBlock := p2p.BlockData{Block: *blocks[0], Commit: *commits[0]} gossipedBlockbytes, err := gossipedBlock.MarshalBinary() require.NoError(t, err) diff --git a/p2p/client.go b/p2p/client.go index ed08f8565..e257f4523 100644 --- a/p2p/client.go +++ b/p2p/client.go @@ -499,7 +499,7 @@ func (c *Client) NewTxValidator() GossipValidator { } // blockSyncReceived is called on reception of new block via block-sync protocol -func (c *Client) blockSyncReceived(block *P2PBlockEvent) { +func (c *Client) blockSyncReceived(block *BlockData) { err := c.localPubsubServer.PublishWithEvents(context.Background(), *block, map[string][]string{EventTypeKey: {EventNewBlockSyncBlock}}) if err != nil { c.logger.Error("Publishing event.", "err", err) @@ -510,7 +510,7 @@ func (c *Client) blockSyncReceived(block *P2PBlockEvent) { // blockSyncReceived is called on reception of new block via gossip protocol func (c *Client) blockGossipReceived(ctx context.Context, block []byte) { - var gossipedBlock P2PBlockEvent + var gossipedBlock BlockData if err := gossipedBlock.UnmarshalBinary(block); err != nil { c.logger.Error("Deserialize gossiped block", "error", err) } diff --git a/p2p/p2p_block.go b/p2p/p2p_block.go deleted file mode 100644 index ac814d51c..000000000 --- a/p2p/p2p_block.go +++ /dev/null @@ -1,74 +0,0 @@ -package p2p - -import ( - "github.com/dymensionxyz/dymint/p2p/pb" - "github.com/dymensionxyz/dymint/types" - tmtypes "github.com/tendermint/tendermint/types" -) - -/* -------------------------------------------------------------------------- */ -/* Event Data */ -/* -------------------------------------------------------------------------- */ - -// P2PBlockEvent defines the struct of the event data for the Block sent via P2P -type P2PBlockEvent struct { - // Block is the block that was gossiped - Block types.Block - // Commit is the commit that was gossiped - Commit types.Commit -} - -// MarshalBinary encodes GossipedBlock into binary form and returns it. -func (e *P2PBlockEvent) MarshalBinary() ([]byte, error) { - return e.ToProto().Marshal() -} - -// UnmarshalBinary decodes binary form of GossipedBlock into object. -func (e *P2PBlockEvent) UnmarshalBinary(data []byte) error { - var pbGossipedBlock pb.GossipedBlock - err := pbGossipedBlock.Unmarshal(data) - if err != nil { - return err - } - err = e.FromProto(&pbGossipedBlock) - return err -} - -// ToProto converts Data into protobuf representation and returns it. -func (e *P2PBlockEvent) ToProto() *pb.GossipedBlock { - return &pb.GossipedBlock{ - Block: e.Block.ToProto(), - Commit: e.Commit.ToProto(), - } -} - -// FromProto fills P2PBlock with data from its protobuf representation. -func (e *P2PBlockEvent) FromProto(other *pb.GossipedBlock) error { - if err := e.Block.FromProto(other.Block); err != nil { - return err - } - if err := e.Commit.FromProto(other.Commit); err != nil { - return err - } - return nil -} - -// Validate run basic validation on the p2p block -func (e *P2PBlockEvent) Validate(proposer *types.Sequencer) error { - if err := e.Block.ValidateBasic(); err != nil { - return err - } - if err := e.Commit.ValidateBasic(); err != nil { - return err - } - if err := e.Commit.ValidateWithHeader(proposer, &e.Block.Header); err != nil { - return err - } - abciData := tmtypes.Data{ - Txs: types.ToABCIBlockDataTxs(&e.Block.Data), - } - if e.Block.Header.DataHash != [32]byte(abciData.Hash()) { - return types.ErrInvalidHeaderDataHash - } - return nil -} diff --git a/p2p/pb/gossiped_block.pb.go b/p2p/pb/blockdata.pb.go similarity index 56% rename from p2p/pb/gossiped_block.pb.go rename to p2p/pb/blockdata.pb.go index ebcd12548..23f78739c 100644 --- a/p2p/pb/gossiped_block.pb.go +++ b/p2p/pb/blockdata.pb.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: p2p/gossiped_block.proto +// source: p2p/blockdata.proto package pb @@ -23,23 +23,23 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package -type GossipedBlock struct { +type BlockData struct { Block *dymint.Block `protobuf:"bytes,1,opt,name=block,proto3" json:"block,omitempty"` Commit *dymint.Commit `protobuf:"bytes,2,opt,name=commit,proto3" json:"commit,omitempty"` } -func (m *GossipedBlock) Reset() { *m = GossipedBlock{} } -func (m *GossipedBlock) String() string { return proto.CompactTextString(m) } -func (*GossipedBlock) ProtoMessage() {} -func (*GossipedBlock) Descriptor() ([]byte, []int) { - return fileDescriptor_e39a70b849e02fbf, []int{0} +func (m *BlockData) Reset() { *m = BlockData{} } +func (m *BlockData) String() string { return proto.CompactTextString(m) } +func (*BlockData) ProtoMessage() {} +func (*BlockData) Descriptor() ([]byte, []int) { + return fileDescriptor_3cee9514a66baf30, []int{0} } -func (m *GossipedBlock) XXX_Unmarshal(b []byte) error { +func (m *BlockData) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *GossipedBlock) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *BlockData) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_GossipedBlock.Marshal(b, m, deterministic) + return xxx_messageInfo_BlockData.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -49,26 +49,26 @@ func (m *GossipedBlock) XXX_Marshal(b []byte, deterministic bool) ([]byte, error return b[:n], nil } } -func (m *GossipedBlock) XXX_Merge(src proto.Message) { - xxx_messageInfo_GossipedBlock.Merge(m, src) +func (m *BlockData) XXX_Merge(src proto.Message) { + xxx_messageInfo_BlockData.Merge(m, src) } -func (m *GossipedBlock) XXX_Size() int { +func (m *BlockData) XXX_Size() int { return m.Size() } -func (m *GossipedBlock) XXX_DiscardUnknown() { - xxx_messageInfo_GossipedBlock.DiscardUnknown(m) +func (m *BlockData) XXX_DiscardUnknown() { + xxx_messageInfo_BlockData.DiscardUnknown(m) } -var xxx_messageInfo_GossipedBlock proto.InternalMessageInfo +var xxx_messageInfo_BlockData proto.InternalMessageInfo -func (m *GossipedBlock) GetBlock() *dymint.Block { +func (m *BlockData) GetBlock() *dymint.Block { if m != nil { return m.Block } return nil } -func (m *GossipedBlock) GetCommit() *dymint.Commit { +func (m *BlockData) GetCommit() *dymint.Commit { if m != nil { return m.Commit } @@ -76,29 +76,29 @@ func (m *GossipedBlock) GetCommit() *dymint.Commit { } func init() { - proto.RegisterType((*GossipedBlock)(nil), "p2p.events.GossipedBlock") + proto.RegisterType((*BlockData)(nil), "p2p.events.BlockData") } -func init() { proto.RegisterFile("p2p/gossiped_block.proto", fileDescriptor_e39a70b849e02fbf) } +func init() { proto.RegisterFile("p2p/blockdata.proto", fileDescriptor_3cee9514a66baf30) } -var fileDescriptor_e39a70b849e02fbf = []byte{ - // 197 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x28, 0x30, 0x2a, 0xd0, - 0x4f, 0xcf, 0x2f, 0x2e, 0xce, 0x2c, 0x48, 0x4d, 0x89, 0x4f, 0xca, 0xc9, 0x4f, 0xce, 0xd6, 0x2b, - 0x28, 0xca, 0x2f, 0xc9, 0x17, 0xe2, 0x2a, 0x30, 0x2a, 0xd0, 0x4b, 0x2d, 0x4b, 0xcd, 0x2b, 0x29, - 0x96, 0x92, 0x2c, 0xa9, 0x2c, 0x48, 0x2d, 0xd6, 0x4f, 0xa9, 0xcc, 0xcd, 0xcc, 0x2b, 0x81, 0x52, - 0x10, 0x65, 0x4a, 0x31, 0x5c, 0xbc, 0xee, 0x50, 0xed, 0x4e, 0x20, 0xdd, 0x42, 0xca, 0x5c, 0xac, - 0x60, 0x63, 0x24, 0x18, 0x15, 0x18, 0x35, 0xb8, 0x8d, 0x78, 0xf5, 0xa0, 0xca, 0xc1, 0xb2, 0x41, - 0x10, 0x39, 0x21, 0x35, 0x2e, 0xb6, 0xe4, 0xfc, 0xdc, 0xdc, 0xcc, 0x12, 0x09, 0x26, 0xb0, 0x2a, - 0x3e, 0x98, 0x2a, 0x67, 0xb0, 0x68, 0x10, 0x54, 0xd6, 0xc9, 0xfe, 0xc4, 0x23, 0x39, 0xc6, 0x0b, - 0x8f, 0xe4, 0x18, 0x1f, 0x3c, 0x92, 0x63, 0x9c, 0xf0, 0x58, 0x8e, 0xe1, 0xc2, 0x63, 0x39, 0x86, - 0x1b, 0x8f, 0xe5, 0x18, 0xa2, 0x54, 0xd3, 0x33, 0x4b, 0x32, 0x4a, 0x93, 0xf4, 0x92, 0xf3, 0x73, - 0x41, 0x0e, 0x4a, 0xcd, 0x2b, 0xce, 0xcc, 0xcf, 0xab, 0xa8, 0xac, 0x82, 0x39, 0x12, 0xe4, 0xaf, - 0x82, 0xa4, 0x24, 0x36, 0xb0, 0x2b, 0x8d, 0x01, 0x01, 0x00, 0x00, 0xff, 0xff, 0xf3, 0x0e, 0xf1, - 0x19, 0xe8, 0x00, 0x00, 0x00, +var fileDescriptor_3cee9514a66baf30 = []byte{ + // 193 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0x2e, 0x30, 0x2a, 0xd0, + 0x4f, 0xca, 0xc9, 0x4f, 0xce, 0x4e, 0x49, 0x2c, 0x49, 0xd4, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, + 0xe2, 0x2a, 0x30, 0x2a, 0xd0, 0x4b, 0x2d, 0x4b, 0xcd, 0x2b, 0x29, 0x96, 0x92, 0x2c, 0xa9, 0x2c, + 0x48, 0x2d, 0xd6, 0x4f, 0xa9, 0xcc, 0xcd, 0xcc, 0x2b, 0x81, 0x52, 0x10, 0x65, 0x4a, 0x11, 0x5c, + 0x9c, 0x4e, 0x20, 0x9d, 0x2e, 0x89, 0x25, 0x89, 0x42, 0xca, 0x5c, 0xac, 0x60, 0x63, 0x24, 0x18, + 0x15, 0x18, 0x35, 0xb8, 0x8d, 0x78, 0xf5, 0xa0, 0x4a, 0xc1, 0x2a, 0x82, 0x20, 0x72, 0x42, 0x6a, + 0x5c, 0x6c, 0xc9, 0xf9, 0xb9, 0xb9, 0x99, 0x25, 0x12, 0x4c, 0x60, 0x55, 0x7c, 0x30, 0x55, 0xce, + 0x60, 0xd1, 0x20, 0xa8, 0xac, 0x93, 0xfd, 0x89, 0x47, 0x72, 0x8c, 0x17, 0x1e, 0xc9, 0x31, 0x3e, + 0x78, 0x24, 0xc7, 0x38, 0xe1, 0xb1, 0x1c, 0xc3, 0x85, 0xc7, 0x72, 0x0c, 0x37, 0x1e, 0xcb, 0x31, + 0x44, 0xa9, 0xa6, 0x67, 0x96, 0x64, 0x94, 0x26, 0xe9, 0x25, 0xe7, 0xe7, 0x82, 0x1c, 0x93, 0x9a, + 0x57, 0x9c, 0x99, 0x9f, 0x57, 0x51, 0x59, 0x05, 0x73, 0x20, 0xc8, 0x3b, 0x05, 0x49, 0x49, 0x6c, + 0x60, 0x17, 0x1a, 0x03, 0x02, 0x00, 0x00, 0xff, 0xff, 0x81, 0x13, 0x29, 0x7e, 0xdf, 0x00, 0x00, + 0x00, } -func (m *GossipedBlock) Marshal() (dAtA []byte, err error) { +func (m *BlockData) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -108,12 +108,12 @@ func (m *GossipedBlock) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *GossipedBlock) MarshalTo(dAtA []byte) (int, error) { +func (m *BlockData) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *GossipedBlock) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *BlockData) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int @@ -125,7 +125,7 @@ func (m *GossipedBlock) MarshalToSizedBuffer(dAtA []byte) (int, error) { return 0, err } i -= size - i = encodeVarintGossipedBlock(dAtA, i, uint64(size)) + i = encodeVarintBlockdata(dAtA, i, uint64(size)) } i-- dAtA[i] = 0x12 @@ -137,7 +137,7 @@ func (m *GossipedBlock) MarshalToSizedBuffer(dAtA []byte) (int, error) { return 0, err } i -= size - i = encodeVarintGossipedBlock(dAtA, i, uint64(size)) + i = encodeVarintBlockdata(dAtA, i, uint64(size)) } i-- dAtA[i] = 0xa @@ -145,8 +145,8 @@ func (m *GossipedBlock) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } -func encodeVarintGossipedBlock(dAtA []byte, offset int, v uint64) int { - offset -= sovGossipedBlock(v) +func encodeVarintBlockdata(dAtA []byte, offset int, v uint64) int { + offset -= sovBlockdata(v) base := offset for v >= 1<<7 { dAtA[offset] = uint8(v&0x7f | 0x80) @@ -156,7 +156,7 @@ func encodeVarintGossipedBlock(dAtA []byte, offset int, v uint64) int { dAtA[offset] = uint8(v) return base } -func (m *GossipedBlock) Size() (n int) { +func (m *BlockData) Size() (n int) { if m == nil { return 0 } @@ -164,22 +164,22 @@ func (m *GossipedBlock) Size() (n int) { _ = l if m.Block != nil { l = m.Block.Size() - n += 1 + l + sovGossipedBlock(uint64(l)) + n += 1 + l + sovBlockdata(uint64(l)) } if m.Commit != nil { l = m.Commit.Size() - n += 1 + l + sovGossipedBlock(uint64(l)) + n += 1 + l + sovBlockdata(uint64(l)) } return n } -func sovGossipedBlock(x uint64) (n int) { +func sovBlockdata(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } -func sozGossipedBlock(x uint64) (n int) { - return sovGossipedBlock(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +func sozBlockdata(x uint64) (n int) { + return sovBlockdata(uint64((x << 1) ^ uint64((int64(x) >> 63)))) } -func (m *GossipedBlock) Unmarshal(dAtA []byte) error { +func (m *BlockData) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -187,7 +187,7 @@ func (m *GossipedBlock) Unmarshal(dAtA []byte) error { var wire uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflowGossipedBlock + return ErrIntOverflowBlockdata } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -202,10 +202,10 @@ func (m *GossipedBlock) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: GossipedBlock: wiretype end group for non-group") + return fmt.Errorf("proto: BlockData: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: GossipedBlock: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: BlockData: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: @@ -215,7 +215,7 @@ func (m *GossipedBlock) Unmarshal(dAtA []byte) error { var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflowGossipedBlock + return ErrIntOverflowBlockdata } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -228,11 +228,11 @@ func (m *GossipedBlock) Unmarshal(dAtA []byte) error { } } if msglen < 0 { - return ErrInvalidLengthGossipedBlock + return ErrInvalidLengthBlockdata } postIndex := iNdEx + msglen if postIndex < 0 { - return ErrInvalidLengthGossipedBlock + return ErrInvalidLengthBlockdata } if postIndex > l { return io.ErrUnexpectedEOF @@ -251,7 +251,7 @@ func (m *GossipedBlock) Unmarshal(dAtA []byte) error { var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflowGossipedBlock + return ErrIntOverflowBlockdata } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -264,11 +264,11 @@ func (m *GossipedBlock) Unmarshal(dAtA []byte) error { } } if msglen < 0 { - return ErrInvalidLengthGossipedBlock + return ErrInvalidLengthBlockdata } postIndex := iNdEx + msglen if postIndex < 0 { - return ErrInvalidLengthGossipedBlock + return ErrInvalidLengthBlockdata } if postIndex > l { return io.ErrUnexpectedEOF @@ -282,12 +282,12 @@ func (m *GossipedBlock) Unmarshal(dAtA []byte) error { iNdEx = postIndex default: iNdEx = preIndex - skippy, err := skipGossipedBlock(dAtA[iNdEx:]) + skippy, err := skipBlockdata(dAtA[iNdEx:]) if err != nil { return err } if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthGossipedBlock + return ErrInvalidLengthBlockdata } if (iNdEx + skippy) > l { return io.ErrUnexpectedEOF @@ -301,7 +301,7 @@ func (m *GossipedBlock) Unmarshal(dAtA []byte) error { } return nil } -func skipGossipedBlock(dAtA []byte) (n int, err error) { +func skipBlockdata(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 depth := 0 @@ -309,7 +309,7 @@ func skipGossipedBlock(dAtA []byte) (n int, err error) { var wire uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return 0, ErrIntOverflowGossipedBlock + return 0, ErrIntOverflowBlockdata } if iNdEx >= l { return 0, io.ErrUnexpectedEOF @@ -326,7 +326,7 @@ func skipGossipedBlock(dAtA []byte) (n int, err error) { case 0: for shift := uint(0); ; shift += 7 { if shift >= 64 { - return 0, ErrIntOverflowGossipedBlock + return 0, ErrIntOverflowBlockdata } if iNdEx >= l { return 0, io.ErrUnexpectedEOF @@ -342,7 +342,7 @@ func skipGossipedBlock(dAtA []byte) (n int, err error) { var length int for shift := uint(0); ; shift += 7 { if shift >= 64 { - return 0, ErrIntOverflowGossipedBlock + return 0, ErrIntOverflowBlockdata } if iNdEx >= l { return 0, io.ErrUnexpectedEOF @@ -355,14 +355,14 @@ func skipGossipedBlock(dAtA []byte) (n int, err error) { } } if length < 0 { - return 0, ErrInvalidLengthGossipedBlock + return 0, ErrInvalidLengthBlockdata } iNdEx += length case 3: depth++ case 4: if depth == 0 { - return 0, ErrUnexpectedEndOfGroupGossipedBlock + return 0, ErrUnexpectedEndOfGroupBlockdata } depth-- case 5: @@ -371,7 +371,7 @@ func skipGossipedBlock(dAtA []byte) (n int, err error) { return 0, fmt.Errorf("proto: illegal wireType %d", wireType) } if iNdEx < 0 { - return 0, ErrInvalidLengthGossipedBlock + return 0, ErrInvalidLengthBlockdata } if depth == 0 { return iNdEx, nil @@ -381,7 +381,7 @@ func skipGossipedBlock(dAtA []byte) (n int, err error) { } var ( - ErrInvalidLengthGossipedBlock = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowGossipedBlock = fmt.Errorf("proto: integer overflow") - ErrUnexpectedEndOfGroupGossipedBlock = fmt.Errorf("proto: unexpected end of group") + ErrInvalidLengthBlockdata = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowBlockdata = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupBlockdata = fmt.Errorf("proto: unexpected end of group") ) diff --git a/p2p/validator.go b/p2p/validator.go index 0b1362b6a..cb8ac890f 100644 --- a/p2p/validator.go +++ b/p2p/validator.go @@ -71,7 +71,7 @@ func (v *Validator) TxValidator(mp mempool.Mempool, mpoolIDS *nodemempool.Mempoo // BlockValidator runs basic checks on the gossiped block func (v *Validator) BlockValidator() GossipValidator { return func(blockMsg *GossipMessage) bool { - var gossipedBlock P2PBlockEvent + var gossipedBlock BlockData if err := gossipedBlock.UnmarshalBinary(blockMsg.Data); err != nil { v.logger.Error("Deserialize gossiped block.", "error", err) return false diff --git a/p2p/validator_test.go b/p2p/validator_test.go index d025c1314..ef8abf804 100644 --- a/p2p/validator_test.go +++ b/p2p/validator_test.go @@ -168,7 +168,7 @@ func TestValidator_BlockValidator(t *testing.T) { } // Create gossiped block - gossipedBlock := p2p.P2PBlockEvent{Block: *block, Commit: *commit} + gossipedBlock := p2p.BlockData{Block: *block, Commit: *commit} gossipedBlockBytes, err := gossipedBlock.MarshalBinary() require.NoError(t, err) blockMsg := &p2p.GossipMessage{ diff --git a/proto/p2p/gossiped_block.proto b/proto/p2p/blockdata.proto similarity index 88% rename from proto/p2p/gossiped_block.proto rename to proto/p2p/blockdata.proto index e006b60e2..53480612a 100644 --- a/proto/p2p/gossiped_block.proto +++ b/proto/p2p/blockdata.proto @@ -5,7 +5,7 @@ option go_package = "github.com/dymensionxyz/dymint/p2p/pb"; import "types/dymint/dymint.proto"; -message GossipedBlock { +message BlockData { dymint.Block block = 1; dymint.Commit commit = 2; }