github.com/MetalBlockchain/metalgo@v1.11.9/snow/engine/common/no_ops_handlers.go (about)

     1  // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved.
     2  // See the file LICENSE for licensing terms.
     3  
     4  package common
     5  
     6  import (
     7  	"context"
     8  	"time"
     9  
    10  	"go.uber.org/zap"
    11  
    12  	"github.com/MetalBlockchain/metalgo/ids"
    13  	"github.com/MetalBlockchain/metalgo/message"
    14  	"github.com/MetalBlockchain/metalgo/utils/logging"
    15  	"github.com/MetalBlockchain/metalgo/utils/set"
    16  	"github.com/MetalBlockchain/metalgo/version"
    17  )
    18  
    19  var (
    20  	_ StateSummaryFrontierHandler = (*noOpStateSummaryFrontierHandler)(nil)
    21  	_ AcceptedStateSummaryHandler = (*noOpAcceptedStateSummaryHandler)(nil)
    22  	_ AcceptedFrontierHandler     = (*noOpAcceptedFrontierHandler)(nil)
    23  	_ AcceptedHandler             = (*noOpAcceptedHandler)(nil)
    24  	_ AncestorsHandler            = (*noOpAncestorsHandler)(nil)
    25  	_ PutHandler                  = (*noOpPutHandler)(nil)
    26  	_ QueryHandler                = (*noOpQueryHandler)(nil)
    27  	_ ChitsHandler                = (*noOpChitsHandler)(nil)
    28  	_ AppHandler                  = (*noOpAppHandler)(nil)
    29  	_ InternalHandler             = (*noOpInternalHandler)(nil)
    30  )
    31  
    32  type noOpStateSummaryFrontierHandler struct {
    33  	log logging.Logger
    34  }
    35  
    36  func NewNoOpStateSummaryFrontierHandler(log logging.Logger) StateSummaryFrontierHandler {
    37  	return &noOpStateSummaryFrontierHandler{log: log}
    38  }
    39  
    40  func (nop *noOpStateSummaryFrontierHandler) StateSummaryFrontier(_ context.Context, nodeID ids.NodeID, requestID uint32, _ []byte) error {
    41  	nop.log.Debug("dropping request",
    42  		zap.String("reason", "unhandled by this gear"),
    43  		zap.Stringer("messageOp", message.StateSummaryFrontierOp),
    44  		zap.Stringer("nodeID", nodeID),
    45  		zap.Uint32("requestID", requestID),
    46  	)
    47  	return nil
    48  }
    49  
    50  func (nop *noOpStateSummaryFrontierHandler) GetStateSummaryFrontierFailed(_ context.Context, nodeID ids.NodeID, requestID uint32) error {
    51  	nop.log.Debug("dropping request",
    52  		zap.String("reason", "unhandled by this gear"),
    53  		zap.Stringer("messageOp", message.GetStateSummaryFrontierFailedOp),
    54  		zap.Stringer("nodeID", nodeID),
    55  		zap.Uint32("requestID", requestID),
    56  	)
    57  	return nil
    58  }
    59  
    60  type noOpAcceptedStateSummaryHandler struct {
    61  	log logging.Logger
    62  }
    63  
    64  func NewNoOpAcceptedStateSummaryHandler(log logging.Logger) AcceptedStateSummaryHandler {
    65  	return &noOpAcceptedStateSummaryHandler{log: log}
    66  }
    67  
    68  func (nop *noOpAcceptedStateSummaryHandler) AcceptedStateSummary(_ context.Context, nodeID ids.NodeID, requestID uint32, _ set.Set[ids.ID]) error {
    69  	nop.log.Debug("dropping request",
    70  		zap.String("reason", "unhandled by this gear"),
    71  		zap.Stringer("messageOp", message.AcceptedStateSummaryOp),
    72  		zap.Stringer("nodeID", nodeID),
    73  		zap.Uint32("requestID", requestID),
    74  	)
    75  	return nil
    76  }
    77  
    78  func (nop *noOpAcceptedStateSummaryHandler) GetAcceptedStateSummaryFailed(_ context.Context, nodeID ids.NodeID, requestID uint32) error {
    79  	nop.log.Debug("dropping request",
    80  		zap.String("reason", "unhandled by this gear"),
    81  		zap.Stringer("messageOp", message.GetAcceptedStateSummaryFailedOp),
    82  		zap.Stringer("nodeID", nodeID),
    83  		zap.Uint32("requestID", requestID),
    84  	)
    85  	return nil
    86  }
    87  
    88  type noOpAcceptedFrontierHandler struct {
    89  	log logging.Logger
    90  }
    91  
    92  func NewNoOpAcceptedFrontierHandler(log logging.Logger) AcceptedFrontierHandler {
    93  	return &noOpAcceptedFrontierHandler{log: log}
    94  }
    95  
    96  func (nop *noOpAcceptedFrontierHandler) AcceptedFrontier(_ context.Context, nodeID ids.NodeID, requestID uint32, containerID ids.ID) error {
    97  	nop.log.Debug("dropping request",
    98  		zap.String("reason", "unhandled by this gear"),
    99  		zap.Stringer("messageOp", message.AcceptedFrontierOp),
   100  		zap.Stringer("nodeID", nodeID),
   101  		zap.Uint32("requestID", requestID),
   102  		zap.Stringer("containerID", containerID),
   103  	)
   104  	return nil
   105  }
   106  
   107  func (nop *noOpAcceptedFrontierHandler) GetAcceptedFrontierFailed(_ context.Context, nodeID ids.NodeID, requestID uint32) error {
   108  	nop.log.Debug("dropping request",
   109  		zap.String("reason", "unhandled by this gear"),
   110  		zap.Stringer("messageOp", message.GetAcceptedFrontierFailedOp),
   111  		zap.Stringer("nodeID", nodeID),
   112  		zap.Uint32("requestID", requestID),
   113  	)
   114  	return nil
   115  }
   116  
   117  type noOpAcceptedHandler struct {
   118  	log logging.Logger
   119  }
   120  
   121  func NewNoOpAcceptedHandler(log logging.Logger) AcceptedHandler {
   122  	return &noOpAcceptedHandler{log: log}
   123  }
   124  
   125  func (nop *noOpAcceptedHandler) Accepted(_ context.Context, nodeID ids.NodeID, requestID uint32, _ set.Set[ids.ID]) error {
   126  	nop.log.Debug("dropping request",
   127  		zap.String("reason", "unhandled by this gear"),
   128  		zap.Stringer("messageOp", message.AcceptedOp),
   129  		zap.Stringer("nodeID", nodeID),
   130  		zap.Uint32("requestID", requestID),
   131  	)
   132  	return nil
   133  }
   134  
   135  func (nop *noOpAcceptedHandler) GetAcceptedFailed(_ context.Context, nodeID ids.NodeID, requestID uint32) error {
   136  	nop.log.Debug("dropping request",
   137  		zap.String("reason", "unhandled by this gear"),
   138  		zap.Stringer("messageOp", message.GetAcceptedFailedOp),
   139  		zap.Stringer("nodeID", nodeID),
   140  		zap.Uint32("requestID", requestID),
   141  	)
   142  	return nil
   143  }
   144  
   145  type noOpAncestorsHandler struct {
   146  	log logging.Logger
   147  }
   148  
   149  func NewNoOpAncestorsHandler(log logging.Logger) AncestorsHandler {
   150  	return &noOpAncestorsHandler{log: log}
   151  }
   152  
   153  func (nop *noOpAncestorsHandler) Ancestors(_ context.Context, nodeID ids.NodeID, requestID uint32, _ [][]byte) error {
   154  	nop.log.Debug("dropping request",
   155  		zap.String("reason", "unhandled by this gear"),
   156  		zap.Stringer("messageOp", message.AncestorsOp),
   157  		zap.Stringer("nodeID", nodeID),
   158  		zap.Uint32("requestID", requestID),
   159  	)
   160  	return nil
   161  }
   162  
   163  func (nop *noOpAncestorsHandler) GetAncestorsFailed(_ context.Context, nodeID ids.NodeID, requestID uint32) error {
   164  	nop.log.Debug("dropping request",
   165  		zap.String("reason", "unhandled by this gear"),
   166  		zap.Stringer("messageOp", message.GetAncestorsFailedOp),
   167  		zap.Stringer("nodeID", nodeID),
   168  		zap.Uint32("requestID", requestID),
   169  	)
   170  	return nil
   171  }
   172  
   173  type noOpPutHandler struct {
   174  	log logging.Logger
   175  }
   176  
   177  func NewNoOpPutHandler(log logging.Logger) PutHandler {
   178  	return &noOpPutHandler{log: log}
   179  }
   180  
   181  func (nop *noOpPutHandler) Put(_ context.Context, nodeID ids.NodeID, requestID uint32, _ []byte) error {
   182  	nop.log.Debug("dropping request",
   183  		zap.String("reason", "unhandled by this gear"),
   184  		zap.Stringer("messageOp", message.PutOp),
   185  		zap.Stringer("nodeID", nodeID),
   186  		zap.Uint32("requestID", requestID),
   187  	)
   188  	return nil
   189  }
   190  
   191  func (nop *noOpPutHandler) GetFailed(_ context.Context, nodeID ids.NodeID, requestID uint32) error {
   192  	nop.log.Debug("dropping request",
   193  		zap.String("reason", "unhandled by this gear"),
   194  		zap.Stringer("messageOp", message.GetFailedOp),
   195  		zap.Stringer("nodeID", nodeID),
   196  		zap.Uint32("requestID", requestID),
   197  	)
   198  	return nil
   199  }
   200  
   201  type noOpQueryHandler struct {
   202  	log logging.Logger
   203  }
   204  
   205  func NewNoOpQueryHandler(log logging.Logger) QueryHandler {
   206  	return &noOpQueryHandler{log: log}
   207  }
   208  
   209  func (nop *noOpQueryHandler) PullQuery(_ context.Context, nodeID ids.NodeID, requestID uint32, containerID ids.ID, requestedHeight uint64) error {
   210  	nop.log.Debug("dropping request",
   211  		zap.String("reason", "unhandled by this gear"),
   212  		zap.Stringer("messageOp", message.PullQueryOp),
   213  		zap.Stringer("nodeID", nodeID),
   214  		zap.Uint32("requestID", requestID),
   215  		zap.Stringer("containerID", containerID),
   216  		zap.Uint64("requestedHeight", requestedHeight),
   217  	)
   218  	return nil
   219  }
   220  
   221  func (nop *noOpQueryHandler) PushQuery(_ context.Context, nodeID ids.NodeID, requestID uint32, _ []byte, requestedHeight uint64) error {
   222  	nop.log.Debug("dropping request",
   223  		zap.String("reason", "unhandled by this gear"),
   224  		zap.Stringer("messageOp", message.PushQueryOp),
   225  		zap.Stringer("nodeID", nodeID),
   226  		zap.Uint32("requestID", requestID),
   227  		zap.Uint64("requestedHeight", requestedHeight),
   228  	)
   229  	return nil
   230  }
   231  
   232  type noOpChitsHandler struct {
   233  	log logging.Logger
   234  }
   235  
   236  func NewNoOpChitsHandler(log logging.Logger) ChitsHandler {
   237  	return &noOpChitsHandler{log: log}
   238  }
   239  
   240  func (nop *noOpChitsHandler) Chits(_ context.Context, nodeID ids.NodeID, requestID uint32, preferredID, preferredIDAtHeight, acceptedID ids.ID) error {
   241  	nop.log.Debug("dropping request",
   242  		zap.String("reason", "unhandled by this gear"),
   243  		zap.Stringer("messageOp", message.ChitsOp),
   244  		zap.Stringer("nodeID", nodeID),
   245  		zap.Uint32("requestID", requestID),
   246  		zap.Stringer("preferredID", preferredID),
   247  		zap.Stringer("preferredIDAtHeight", preferredIDAtHeight),
   248  		zap.Stringer("acceptedID", acceptedID),
   249  	)
   250  	return nil
   251  }
   252  
   253  func (nop *noOpChitsHandler) QueryFailed(_ context.Context, nodeID ids.NodeID, requestID uint32) error {
   254  	nop.log.Debug("dropping request",
   255  		zap.String("reason", "unhandled by this gear"),
   256  		zap.Stringer("messageOp", message.QueryFailedOp),
   257  		zap.Stringer("nodeID", nodeID),
   258  		zap.Uint32("requestID", requestID),
   259  	)
   260  	return nil
   261  }
   262  
   263  type noOpAppHandler struct {
   264  	log logging.Logger
   265  }
   266  
   267  func NewNoOpAppHandler(log logging.Logger) AppHandler {
   268  	return &noOpAppHandler{log: log}
   269  }
   270  
   271  func (nop *noOpAppHandler) CrossChainAppRequest(_ context.Context, chainID ids.ID, requestID uint32, _ time.Time, _ []byte) error {
   272  	nop.log.Debug("dropping request",
   273  		zap.String("reason", "unhandled by this gear"),
   274  		zap.Stringer("messageOp", message.CrossChainAppRequestOp),
   275  		zap.Stringer("chainID", chainID),
   276  		zap.Uint32("requestID", requestID),
   277  	)
   278  	return nil
   279  }
   280  
   281  func (nop *noOpAppHandler) CrossChainAppRequestFailed(_ context.Context, chainID ids.ID, requestID uint32, appErr *AppError) error {
   282  	nop.log.Debug("dropping request",
   283  		zap.String("reason", "unhandled by this gear"),
   284  		zap.Stringer("messageOp", message.CrossChainAppErrorOp),
   285  		zap.Stringer("chainID", chainID),
   286  		zap.Uint32("requestID", requestID),
   287  		zap.Error(appErr),
   288  	)
   289  	return nil
   290  }
   291  
   292  func (nop *noOpAppHandler) CrossChainAppResponse(_ context.Context, chainID ids.ID, requestID uint32, _ []byte) error {
   293  	nop.log.Debug("dropping request",
   294  		zap.String("reason", "unhandled by this gear"),
   295  		zap.Stringer("messageOp", message.CrossChainAppResponseOp),
   296  		zap.Stringer("chainID", chainID),
   297  		zap.Uint32("requestID", requestID),
   298  	)
   299  	return nil
   300  }
   301  
   302  func (nop *noOpAppHandler) AppRequest(_ context.Context, nodeID ids.NodeID, requestID uint32, _ time.Time, _ []byte) error {
   303  	nop.log.Debug("dropping request",
   304  		zap.String("reason", "unhandled by this gear"),
   305  		zap.Stringer("messageOp", message.AppRequestOp),
   306  		zap.Stringer("nodeID", nodeID),
   307  		zap.Uint32("requestID", requestID),
   308  	)
   309  	return nil
   310  }
   311  
   312  func (nop *noOpAppHandler) AppRequestFailed(_ context.Context, nodeID ids.NodeID, requestID uint32, appErr *AppError) error {
   313  	nop.log.Debug("dropping request",
   314  		zap.String("reason", "unhandled by this gear"),
   315  		zap.Stringer("messageOp", message.AppErrorOp),
   316  		zap.Stringer("nodeID", nodeID),
   317  		zap.Uint32("requestID", requestID),
   318  		zap.Error(appErr),
   319  	)
   320  	return nil
   321  }
   322  
   323  func (nop *noOpAppHandler) AppResponse(_ context.Context, nodeID ids.NodeID, requestID uint32, _ []byte) error {
   324  	nop.log.Debug("dropping request",
   325  		zap.String("reason", "unhandled by this gear"),
   326  		zap.Stringer("messageOp", message.AppResponseOp),
   327  		zap.Stringer("nodeID", nodeID),
   328  		zap.Uint32("requestID", requestID),
   329  	)
   330  	return nil
   331  }
   332  
   333  func (nop *noOpAppHandler) AppGossip(_ context.Context, nodeID ids.NodeID, _ []byte) error {
   334  	nop.log.Debug("dropping request",
   335  		zap.String("reason", "unhandled by this gear"),
   336  		zap.Stringer("messageOp", message.AppGossipOp),
   337  		zap.Stringer("nodeID", nodeID),
   338  	)
   339  	return nil
   340  }
   341  
   342  type noOpInternalHandler struct {
   343  	log logging.Logger
   344  }
   345  
   346  func NewNoOpInternalHandler(log logging.Logger) InternalHandler {
   347  	return &noOpInternalHandler{log: log}
   348  }
   349  
   350  func (nop *noOpInternalHandler) Connected(
   351  	_ context.Context,
   352  	nodeID ids.NodeID,
   353  	nodeVersion *version.Application,
   354  ) error {
   355  	nop.log.Debug("dropping request",
   356  		zap.String("reason", "unhandled by this gear"),
   357  		zap.Stringer("messageOp", message.ConnectedOp),
   358  		zap.Stringer("nodeID", nodeID),
   359  		zap.Stringer("version", nodeVersion),
   360  	)
   361  	return nil
   362  }
   363  
   364  func (nop *noOpInternalHandler) Disconnected(_ context.Context, nodeID ids.NodeID) error {
   365  	nop.log.Debug("dropping request",
   366  		zap.String("reason", "unhandled by this gear"),
   367  		zap.Stringer("messageOp", message.DisconnectedOp),
   368  		zap.Stringer("nodeID", nodeID),
   369  	)
   370  	return nil
   371  }
   372  
   373  func (nop *noOpInternalHandler) Timeout(context.Context) error {
   374  	nop.log.Debug("dropping request",
   375  		zap.String("reason", "unhandled by this gear"),
   376  		zap.Stringer("messageOp", message.TimeoutOp),
   377  	)
   378  	return nil
   379  }
   380  
   381  func (nop *noOpInternalHandler) Gossip(context.Context) error {
   382  	nop.log.Debug("dropping request",
   383  		zap.String("reason", "unhandled by this gear"),
   384  		zap.Stringer("messageOp", message.GossipRequestOp),
   385  	)
   386  	return nil
   387  }
   388  
   389  func (nop *noOpInternalHandler) Halt(context.Context) {
   390  	nop.log.Debug("dropping request",
   391  		zap.String("reason", "unhandled by this gear"),
   392  		zap.String("messageOp", "halt"),
   393  	)
   394  }
   395  
   396  func (nop *noOpInternalHandler) Shutdown(context.Context) error {
   397  	nop.log.Debug("dropping request",
   398  		zap.String("reason", "unhandled by this gear"),
   399  		zap.String("messageOp", "shutdown"),
   400  	)
   401  	return nil
   402  }
   403  
   404  func (nop *noOpInternalHandler) Notify(_ context.Context, msg Message) error {
   405  	nop.log.Debug("dropping request",
   406  		zap.String("reason", "unhandled by this gear"),
   407  		zap.Stringer("messageOp", message.NotifyOp),
   408  		zap.Stringer("message", msg),
   409  	)
   410  	return nil
   411  }