Skip to content

Commit

Permalink
Removed the unused request and response types
Browse files Browse the repository at this point in the history
  • Loading branch information
gameofpointers committed Jun 13, 2024
1 parent e7400a5 commit f77a069
Show file tree
Hide file tree
Showing 10 changed files with 102 additions and 270 deletions.
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.

4 changes: 2 additions & 2 deletions core/types/proto_block.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 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: 0 additions & 35 deletions p2p/pb/proto_services.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"github.com/dominant-strategies/go-quai/common"
"github.com/dominant-strategies/go-quai/core/types"
"github.com/dominant-strategies/go-quai/log"
"github.com/dominant-strategies/go-quai/trie"
)

func DecodeQuaiMessage(data []byte) (*QuaiMessage, error) {
Expand Down Expand Up @@ -42,12 +41,8 @@ func EncodeQuaiRequest(id uint32, location common.Location, reqData interface{},
reqMsg.Request = &QuaiRequestMessage_WorkObjectBlock{}
case *types.WorkObjectHeaderView:
reqMsg.Request = &QuaiRequestMessage_WorkObjectHeader{}
case *types.Transaction:
reqMsg.Request = &QuaiRequestMessage_Transaction{}
case common.Hash:
reqMsg.Request = &QuaiRequestMessage_BlockHash{}
case trie.TrieNodeRequest:
reqMsg.Request = &QuaiRequestMessage_TrieNode{}
default:
return nil, errors.Errorf("unsupported request data type: %T", respDataType)
}
Expand Down Expand Up @@ -87,12 +82,8 @@ func DecodeQuaiRequest(reqMsg *QuaiRequestMessage) (uint32, interface{}, common.
reqType = &types.WorkObjectBlockView{}
case *QuaiRequestMessage_WorkObjectHeader:
reqType = &types.WorkObjectHeaderView{}
case *QuaiRequestMessage_Transaction:
reqType = &types.Transaction{}
case *QuaiRequestMessage_BlockHash:
reqType = &common.Hash{}
case *QuaiRequestMessage_TrieNode:
reqType = trie.TrieNodeRequest{}
default:
return reqMsg.Id, nil, common.Location{}, common.Hash{}, errors.Errorf("unsupported request type: %T", reqMsg.Request)
}
Expand Down Expand Up @@ -124,17 +115,6 @@ func EncodeQuaiResponse(id uint32, location common.Location, data interface{}) (
}
respMsg.Response = &QuaiResponseMessage_WorkObjectHeaderView{WorkObjectHeaderView: protoWorkObjectHeader}

case *types.Transaction:
protoTransaction, err := data.ProtoEncode()
if err != nil {
return nil, err
}
respMsg.Response = &QuaiResponseMessage_Transaction{Transaction: protoTransaction}

case *trie.TrieNodeResponse:
protoTrieNode := &trie.ProtoTrieNode{ProtoNodeData: data.NodeData}
respMsg.Response = &QuaiResponseMessage_TrieNode{TrieNode: protoTrieNode}

case *common.Hash:
respMsg.Response = &QuaiResponseMessage_BlockHash{BlockHash: data.ProtoEncode()}

Expand Down Expand Up @@ -192,26 +172,11 @@ func DecodeQuaiResponse(respMsg *QuaiResponseMessage) (uint32, interface{}, erro
messageMetrics.WithLabelValues("blocks").Inc()
}
return id, block, nil
case *QuaiResponseMessage_Transaction:
protoTransaction := respMsg.GetTransaction()
transaction := &types.Transaction{}
err := transaction.ProtoDecode(protoTransaction, *sourceLocation)
if err != nil {
return id, nil, err
}
if messageMetrics != nil {
messageMetrics.WithLabelValues("transactions").Inc()
}
return id, transaction, nil
case *QuaiResponseMessage_BlockHash:
blockHash := respMsg.GetBlockHash()
hash := common.Hash{}
hash.ProtoDecode(blockHash)
return id, hash, nil
case *QuaiResponseMessage_TrieNode:
protoTrieNode := respMsg.GetTrieNode()
trieNode := &trie.TrieNodeResponse{NodeData: protoTrieNode.ProtoNodeData}
return id, trieNode, nil
default:
return id, nil, errors.Errorf("unsupported response type: %T", respMsg.Response)
}
Expand Down
258 changes: 90 additions & 168 deletions p2p/pb/quai_messages.pb.go

Large diffs are not rendered by default.

9 changes: 2 additions & 7 deletions p2p/pb/quai_messages.proto
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package quaiprotocol;
option go_package = "github.com/dominant-strategies/go-quai/p2p/pb";

import "common/proto_common.proto";
import "trie/proto_trienode.proto";
import "core/types/proto_block.proto";

// GossipSub messages for broadcasting blocks and transactions
Expand All @@ -23,9 +22,7 @@ message QuaiRequestMessage {
oneof request {
block.ProtoWorkObjectBlockView work_object_block = 5;
block.ProtoWorkObjectHeaderView work_object_header = 6;
block.ProtoTransaction transaction = 7;
common.ProtoHash block_hash = 8;
trie.ProtoTrieNode trie_node = 9;
common.ProtoHash block_hash = 7;
}
}

Expand All @@ -36,9 +33,7 @@ message QuaiResponseMessage {
oneof response {
block.ProtoWorkObjectHeaderView work_object_header_view = 3;
block.ProtoWorkObjectBlockView work_object_block_view = 4;
block.ProtoTransaction transaction = 5;
common.ProtoHash block_hash = 6;
trie.ProtoTrieNode trie_node = 7;
common.ProtoHash block_hash = 5;
}
}

Expand Down
41 changes: 0 additions & 41 deletions p2p/protocol/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"github.com/dominant-strategies/go-quai/core/types"
"github.com/dominant-strategies/go-quai/log"
"github.com/dominant-strategies/go-quai/p2p/pb"
"github.com/dominant-strategies/go-quai/trie"
)

const (
Expand Down Expand Up @@ -199,30 +198,13 @@ func handleRequest(quaiMsg *pb.QuaiRequestMessage, stream network.Stream, node Q
if messageMetrics != nil {
messageMetrics.WithLabelValues("blocks").Inc()
}
case *types.Transaction:
requestedHash := query.(*common.Hash)
err = handleTransactionRequest(id, loc, *requestedHash, stream, node)
if err != nil {
log.Global.WithField("err", err).Error("error handling transaction request")
// TODO: handle error
return
}
if messageMetrics != nil {
messageMetrics.WithLabelValues("transactions").Inc()
}
case *common.Hash:
number := query.(*big.Int)
err = handleBlockNumberRequest(id, loc, number, stream, node)
if err != nil {
log.Global.WithField("err", err).Error("error handling block number request")
return
}
case trie.TrieNodeRequest:
requestedHash := query.(*common.Hash)
err := handleTrieNodeRequest(id, loc, *requestedHash, stream, node)
if err != nil {
log.Global.WithField("err", err).Error("error handling trie node request")
}
default:
log.Global.WithField("request type", decodedType).Error("unsupported request data type")
// TODO: handle error
Expand Down Expand Up @@ -283,10 +265,6 @@ func handleBlockRequest(id uint32, loc common.Location, hash common.Hash, stream
return nil
}

func handleTransactionRequest(id uint32, loc common.Location, hash common.Hash, stream network.Stream, node QuaiP2PNode) error {
panic("TODO: implement")
}

// Seeks the block in the cache or database and sends it to the peer in a pb.QuaiResponseMessage
func handleBlockNumberRequest(id uint32, loc common.Location, number *big.Int, stream network.Stream, node QuaiP2PNode) error {
// check if we have the block in our cache or database
Expand All @@ -309,22 +287,3 @@ func handleBlockNumberRequest(id uint32, loc common.Location, number *big.Int, s
log.Global.Tracef("Sent block hash %s to peer %s", blockHash, stream.Conn().RemotePeer())
return nil
}

func handleTrieNodeRequest(id uint32, loc common.Location, hash common.Hash, stream network.Stream, node QuaiP2PNode) error {
trieNode := node.GetTrieNode(hash, loc)
if trieNode == nil {
log.Global.Tracef("trie node not found")
return nil
}
log.Global.Tracef("trie node found")
data, err := pb.EncodeQuaiResponse(id, loc, trieNode)
if err != nil {
return err
}
err = common.WriteMessageToStream(stream, data)
if err != nil {
return err
}
log.Global.Tracef("Sent trie node to peer %s", stream.Conn().RemotePeer())
return nil
}
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.

9 changes: 0 additions & 9 deletions trie/proto_trienode.proto

This file was deleted.

0 comments on commit f77a069

Please sign in to comment.