github.com/MetalBlockchain/subnet-evm@v0.4.9/plugin/evm/message/handler.go (about)

     1  // (c) 2019-2021, Ava Labs, Inc. All rights reserved.
     2  // See the file LICENSE for licensing terms.
     3  
     4  package message
     5  
     6  import (
     7  	"context"
     8  
     9  	"github.com/ethereum/go-ethereum/log"
    10  
    11  	"github.com/MetalBlockchain/metalgo/ids"
    12  )
    13  
    14  var (
    15  	_ GossipHandler            = NoopMempoolGossipHandler{}
    16  	_ RequestHandler           = NoopRequestHandler{}
    17  	_ CrossChainRequestHandler = NoopCrossChainRequestHandler{}
    18  )
    19  
    20  // GossipHandler handles incoming gossip messages
    21  type GossipHandler interface {
    22  	HandleTxs(nodeID ids.NodeID, msg TxsGossip) error
    23  }
    24  
    25  type NoopMempoolGossipHandler struct{}
    26  
    27  func (NoopMempoolGossipHandler) HandleTxs(nodeID ids.NodeID, _ TxsGossip) error {
    28  	log.Debug("dropping unexpected Txs message", "peerID", nodeID)
    29  	return nil
    30  }
    31  
    32  // RequestHandler interface handles incoming requests from peers
    33  // Must have methods in format of handleType(context.Context, ids.NodeID, uint32, request Type) error
    34  // so that the Request object of relevant Type can invoke its respective handle method
    35  // on this struct.
    36  // Also see GossipHandler for implementation style.
    37  type RequestHandler interface {
    38  	HandleTrieLeafsRequest(ctx context.Context, nodeID ids.NodeID, requestID uint32, leafsRequest LeafsRequest) ([]byte, error)
    39  	HandleBlockRequest(ctx context.Context, nodeID ids.NodeID, requestID uint32, blockRequest BlockRequest) ([]byte, error)
    40  	HandleCodeRequest(ctx context.Context, nodeID ids.NodeID, requestID uint32, codeRequest CodeRequest) ([]byte, error)
    41  	HandleSignatureRequest(ctx context.Context, nodeID ids.NodeID, requestID uint32, signatureRequest SignatureRequest) ([]byte, error)
    42  }
    43  
    44  // ResponseHandler handles response for a sent request
    45  // Only one of OnResponse or OnFailure is called for a given requestID, not both
    46  type ResponseHandler interface {
    47  	// OnResponse is invoked when the peer responded to a request
    48  	OnResponse(response []byte) error
    49  	// OnFailure is invoked when there was a failure in processing a request
    50  	OnFailure() error
    51  }
    52  
    53  type NoopRequestHandler struct{}
    54  
    55  func (NoopRequestHandler) HandleTrieLeafsRequest(ctx context.Context, nodeID ids.NodeID, requestID uint32, leafsRequest LeafsRequest) ([]byte, error) {
    56  	return nil, nil
    57  }
    58  
    59  func (NoopRequestHandler) HandleBlockRequest(ctx context.Context, nodeID ids.NodeID, requestID uint32, request BlockRequest) ([]byte, error) {
    60  	return nil, nil
    61  }
    62  
    63  func (NoopRequestHandler) HandleCodeRequest(ctx context.Context, nodeID ids.NodeID, requestID uint32, codeRequest CodeRequest) ([]byte, error) {
    64  	return nil, nil
    65  }
    66  
    67  func (NoopRequestHandler) HandleSignatureRequest(ctx context.Context, nodeID ids.NodeID, requestID uint32, signatureRequest SignatureRequest) ([]byte, error) {
    68  	return nil, nil
    69  }
    70  
    71  // CrossChainRequestHandler interface handles incoming requests from another chain
    72  type CrossChainRequestHandler interface {
    73  	HandleEthCallRequest(ctx context.Context, requestingchainID ids.ID, requestID uint32, ethCallRequest EthCallRequest) ([]byte, error)
    74  }
    75  
    76  type NoopCrossChainRequestHandler struct{}
    77  
    78  func (NoopCrossChainRequestHandler) HandleEthCallRequest(ctx context.Context, requestingchainID ids.ID, requestID uint32, ethCallRequest EthCallRequest) ([]byte, error) {
    79  	return nil, nil
    80  }