Skip to content

Commit

Permalink
nit
Browse files Browse the repository at this point in the history
  • Loading branch information
joshua-kim committed Sep 8, 2023
1 parent 1b32de6 commit f5d8a0d
Showing 1 changed file with 3 additions and 15 deletions.
18 changes: 3 additions & 15 deletions peer/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,9 +269,6 @@ func (n *network) CrossChainAppRequest(ctx context.Context, requestingChainID id
// If [requestID] is not known, this function will emit a log and return a nil error.
// If the response handler returns an error it is propagated as a fatal error.
func (n *network) CrossChainAppRequestFailed(ctx context.Context, respondingChainID ids.ID, requestID uint32) error {
n.lock.Lock()
defer n.lock.Unlock()

if n.closed.Get() {
return nil
}
Expand All @@ -296,9 +293,6 @@ func (n *network) CrossChainAppRequestFailed(ctx context.Context, respondingChai
// If [requestID] is not known, this function will emit a log and return a nil error.
// If the response handler returns an error it is propagated as a fatal error.
func (n *network) CrossChainAppResponse(ctx context.Context, respondingChainID ids.ID, requestID uint32, response []byte) error {
n.lock.Lock()
defer n.lock.Unlock()

if n.closed.Get() {
return nil
}
Expand Down Expand Up @@ -364,17 +358,13 @@ func (n *network) AppRequest(ctx context.Context, nodeID ids.NodeID, requestID u
// If [requestID] is not known, this function will emit a log and return a nil error.
// If the response handler returns an error it is propagated as a fatal error.
func (n *network) AppResponse(ctx context.Context, nodeID ids.NodeID, requestID uint32, response []byte) error {
n.lock.Lock()

if n.closed.Get() {
n.lock.Unlock()
return nil
}

log.Debug("received AppResponse from peer", "nodeID", nodeID, "requestID", requestID)

handler, exists := n.markRequestFulfilled(requestID)
n.lock.Unlock()
if !exists {
log.Debug("forwarding AppResponse to SDK router", "nodeID", nodeID, "requestID", requestID, "responseLen", len(response))
return n.router.AppResponse(ctx, nodeID, requestID, response)
Expand All @@ -393,17 +383,13 @@ func (n *network) AppResponse(ctx context.Context, nodeID ids.NodeID, requestID
// error returned by this function is expected to be treated as fatal by the engine
// returns error only when the response handler returns an error
func (n *network) AppRequestFailed(ctx context.Context, nodeID ids.NodeID, requestID uint32) error {
n.lock.Lock()

if n.closed.Get() {
n.lock.Unlock()
return nil
}

log.Debug("received AppRequestFailed from peer", "nodeID", nodeID, "requestID", requestID)

handler, exists := n.markRequestFulfilled(requestID)
n.lock.Unlock()
if !exists {
log.Debug("forwarding AppRequestFailed to SDK router", "nodeID", nodeID, "requestID", requestID)
return n.router.AppRequestFailed(ctx, nodeID, requestID)
Expand Down Expand Up @@ -439,8 +425,10 @@ func calculateTimeUntilDeadline(deadline time.Time, stats stats.RequestHandlerSt

// markRequestFulfilled fetches the handler for [requestID] and marks the request with [requestID] as having been fulfilled.
// This is called by either [AppResponse] or [AppRequestFailed].
// Assumes that the write lock is held.
func (n *network) markRequestFulfilled(requestID uint32) (message.ResponseHandler, bool) {
n.lock.Lock()
defer n.lock.Unlock()

handler, exists := n.outstandingRequestHandlers[requestID]
if !exists {
return nil, false
Expand Down

0 comments on commit f5d8a0d

Please sign in to comment.