Skip to content

Commit

Permalink
modified the allocations in p2p
Browse files Browse the repository at this point in the history
fixed encode and decode of blockview and headerview

bugfix that needs to go with f52ce02 enconde/decode of headeview blockview
  • Loading branch information
kiltsonfire committed Jun 4, 2024
1 parent abe20f3 commit 9c1aa24
Show file tree
Hide file tree
Showing 12 changed files with 249 additions and 309 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ mocks:
## generate protobuf files
protogen:
@echo "Generating protobuf files"
@find . -name '*.proto' -exec protoc --go_out=. --go_opt=paths=source_relative {} \;
@find . -name '*.proto' -exec protoc --go_out=. --go_opt=paths=source_relative --experimental_allow_proto3_optional {} \;

debug:
go build -gcflags=all="-N -l" -v -o build/bin/go-quai ./cmd/go-quai
Expand Down
4 changes: 2 additions & 2 deletions common/proto_common.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions core/rawdb/db.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

441 changes: 207 additions & 234 deletions core/types/proto_block.pb.go

Large diffs are not rendered by default.

6 changes: 2 additions & 4 deletions core/types/proto_block.proto
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,11 @@ message ProtoWorkObject {
message ProtoWorkObjects { repeated ProtoWorkObject work_objects = 1; }

message ProtoWorkObjectBlockView {
optional ProtoWorkObjectHeader wo_header = 1;
optional ProtoWorkObjectBody wo_body = 2;
optional ProtoWorkObject work_object = 1;
}

message ProtoWorkObjectHeaderView {
optional ProtoWorkObjectHeader wo_header = 1;
optional ProtoWorkObjectBody wo_body = 2;
optional ProtoWorkObject work_object = 1;
}

message ProtoAccessTuple {
Expand Down
38 changes: 10 additions & 28 deletions core/types/wo.go
Original file line number Diff line number Diff line change
Expand Up @@ -767,60 +767,42 @@ func (wo *WorkObject) ProtoEncode(woType WorkObjectView) (*ProtoWorkObject, erro
}

func (wo *WorkObjectHeaderView) ProtoEncode() (*ProtoWorkObjectHeaderView, error) {
header, err := wo.woHeader.ProtoEncode()
if err != nil {
return nil, err
}
body, err := wo.woBody.ProtoEncode()
protoWo, err := wo.WorkObject.ProtoEncode(HeaderObject)
if err != nil {
return nil, err
}
return &ProtoWorkObjectHeaderView{
WoHeader: header,
WoBody: body,
WorkObject: protoWo,
}, nil
}

func (wo *WorkObjectBlockView) ProtoEncode() (*ProtoWorkObjectBlockView, error) {
header, err := wo.woHeader.ProtoEncode()
if err != nil {
return nil, err
}
body, err := wo.woBody.ProtoEncode()
protoWo, err := wo.WorkObject.ProtoEncode(BlockObject)
if err != nil {
return nil, err
}
return &ProtoWorkObjectBlockView{
WoHeader: header,
WoBody: body,
WorkObject: protoWo,
}, nil
}

func (wo *WorkObjectHeaderView) ProtoDecode(data *ProtoWorkObjectHeaderView, location common.Location) error {
wo.woHeader = new(WorkObjectHeader)
err := wo.woHeader.ProtoDecode(data.GetWoHeader())
if err != nil {
return err
}
wo.woBody = new(WorkObjectBody)
err = wo.woBody.ProtoDecode(data.GetWoBody(), location, BlockObject)
decodeWo := new(WorkObject)
err := decodeWo.ProtoDecode(data.GetWorkObject(), location, HeaderObject)
if err != nil {
return err
}
wo.WorkObject = decodeWo
return nil
}

func (wob *WorkObjectBlockView) ProtoDecode(data *ProtoWorkObjectBlockView, location common.Location) error {
wob.woHeader = new(WorkObjectHeader)
err := wob.woHeader.ProtoDecode(data.GetWoHeader())
if err != nil {
return err
}
wob.woBody = new(WorkObjectBody)
err = wob.woBody.ProtoDecode(data.GetWoBody(), location, BlockObject)
decodeWo := new(WorkObject)
err := decodeWo.ProtoDecode(data.GetWorkObject(), location, BlockObject)
if err != nil {
return err
}
wob.WorkObject = decodeWo
return nil
}

Expand Down
6 changes: 2 additions & 4 deletions p2p/node/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,10 +331,8 @@ func (p *P2PNode) GetTrieNode(hash common.Hash, location common.Location) *trie.
}

func (p *P2PNode) handleBroadcast(sourcePeer peer.ID, topic string, data interface{}, nodeLocation common.Location) {
switch v := data.(type) {
case types.WorkObject:
p.cacheAdd(v.Hash(), &v, nodeLocation)
// TODO: send it to consensus
switch data.(type) {
case types.WorkObjectBlockView:
case types.WorkObjectHeaderView:
case types.Transactions:
case types.WorkObjectHeader:
Expand Down
4 changes: 2 additions & 2 deletions p2p/node/peerManager/peerdb/peer_info.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 14 additions & 21 deletions p2p/pb/proto_services.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,79 +270,72 @@ func ConvertAndMarshal(data interface{}) ([]byte, error) {
func UnmarshalAndConvert(data []byte, sourceLocation common.Location, dataPtr *interface{}, datatype interface{}) error {
switch datatype.(type) {
case *types.WorkObjectBlockView:
protoWorkObject := &types.ProtoWorkObject{}
protoWorkObject := &types.ProtoWorkObjectBlockView{}
err := proto.Unmarshal(data, protoWorkObject)
if err != nil {
return err
}
workObject := &types.WorkObject{}
if protoWorkObject.WoHeader == nil {
return errors.New("woheader is nil")
}
if protoWorkObject.WoHeader.Location == nil {
return errors.New("location is nil")
}
err = workObject.ProtoDecode(protoWorkObject, sourceLocation, types.BlockObject)

workObjectBlockView := types.WorkObjectBlockView{}
workObjectBlockView.WorkObject = &types.WorkObject{}
err = workObjectBlockView.ProtoDecode(protoWorkObject, sourceLocation)
if err != nil {
return err
}
*dataPtr = *workObject
*dataPtr = workObjectBlockView
return nil
case *types.WorkObjectHeaderView:
protoWorkObject := &types.ProtoWorkObjectHeaderView{}
err := proto.Unmarshal(data, protoWorkObject)
if err != nil {
return err
}
workObjectHeaderView := &types.WorkObjectHeaderView{}
if protoWorkObject.WoHeader.Location == nil {
return errors.New("location is nil")
}
workObjectHeaderView := types.WorkObjectHeaderView{}
workObjectHeaderView.WorkObject = &types.WorkObject{}
err = workObjectHeaderView.ProtoDecode(protoWorkObject, sourceLocation)
if err != nil {
return err
}
*dataPtr = *workObjectHeaderView
*dataPtr = workObjectHeaderView
return nil
case *types.WorkObjectHeader:
protoWorkObjectHeader := &types.ProtoWorkObjectHeader{}
err := proto.Unmarshal(data, protoWorkObjectHeader)
if err != nil {
return err
}
workObjectHeader := &types.WorkObjectHeader{}
workObjectHeader := types.WorkObjectHeader{}
err = workObjectHeader.ProtoDecode(protoWorkObjectHeader)
if err != nil {
return err
}
*dataPtr = *workObjectHeader
*dataPtr = workObjectHeader
return nil
case *types.Header:
protoHeader := &types.ProtoHeader{}
err := proto.Unmarshal(data, protoHeader)
if err != nil {
return err
}
header := &types.Header{}
header := types.Header{}
err = header.ProtoDecode(protoHeader, sourceLocation)
if err != nil {
return err
}
*dataPtr = *header
*dataPtr = header
return nil
case *types.Transactions:
protoTransactions := &types.ProtoTransactions{}
err := proto.Unmarshal(data, protoTransactions)
if err != nil {
return err
}
transactions := &types.Transactions{}
transactions := types.Transactions{}
err = transactions.ProtoDecode(protoTransactions, sourceLocation)
if err != nil {
return err
}
*dataPtr = *transactions
*dataPtr = transactions
return nil
case common.Hash:
protoHash := &common.ProtoHash{}
Expand Down
8 changes: 2 additions & 6 deletions p2p/pb/quai_messages.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions quai/p2p_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (qbe *QuaiBackend) GetBackend(location common.Location) *quaiapi.Backend {
func (qbe *QuaiBackend) OnNewBroadcast(sourcePeer p2p.PeerID, topic string, data interface{}, nodeLocation common.Location) bool {
defer types.ObjectPool.Put(data)
switch data := data.(type) {
case types.WorkObject:
case types.WorkObjectBlockView:
backend := *qbe.GetBackend(nodeLocation)
if backend == nil {
log.Global.Error("no backend found")
Expand All @@ -89,7 +89,7 @@ func (qbe *QuaiBackend) OnNewBroadcast(sourcePeer p2p.PeerID, topic string, data
// TODO: Verify the Block before writing it
// TODO: Determine if the block information was lively or stale and rate
// the peer accordingly
backend.WriteBlock(&data)
backend.WriteBlock(data.WorkObject)
// If it was a good broadcast, mark the peer as lively
qbe.p2pBackend.MarkLivelyPeer(sourcePeer, topic)
case types.WorkObjectHeaderView:
Expand All @@ -100,7 +100,7 @@ func (qbe *QuaiBackend) OnNewBroadcast(sourcePeer p2p.PeerID, topic string, data
}
// Only append this in the case of the slice
if !backend.ProcessingState() && backend.NodeCtx() == common.ZONE_CTX {
backend.WriteBlock(data.ConvertToBlockView().WorkObject)
backend.WriteBlock(data.WorkObject)
}
// If it was a good broadcast, mark the peer as lively
qbe.p2pBackend.MarkLivelyPeer(sourcePeer, topic)
Expand Down
4 changes: 2 additions & 2 deletions trie/proto_trienode.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9c1aa24

Please sign in to comment.