Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add signature collection logs #330

Merged
merged 1 commit into from
Jun 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 37 additions & 2 deletions relayer/application_relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,11 +317,17 @@ func (r *ApplicationRelayer) createSignedMessage(unsignedMessage *avalancheWarp.

// createSignedMessageAppRequest collects signatures from nodes by directly querying them via AppRequest, then aggregates the signatures, and constructs the signed warp message.
func (r *ApplicationRelayer) createSignedMessageAppRequest(unsignedMessage *avalancheWarp.UnsignedMessage, requestID uint32) (*avalancheWarp.Message, error) {
r.logger.Info("Fetching aggregate signature from the source chain validators via AppRequest")
r.logger.Info(
"Fetching aggregate signature from the source chain validators via AppRequest",
zap.String("warpMessageID", unsignedMessage.ID().String()),
zap.String("sourceBlockchainID", r.sourceBlockchain.GetBlockchainID().String()),
zap.String("destinationBlockchainID", r.relayerID.DestinationBlockchainID.String()),
Comment on lines +322 to +324
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not necessary in this PR, but could be cleaner to have some logging helpers for repeated variables (such as "warpMessageID") to avoid the string literals in so many places.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've thought about this some, but haven't found any satisfying solution. Helpers would reduce repitition in the code, but aren't the most extensible or generic. A decorator-type extension to logger.Logger that always logs certain fields and still takes additional arguments would be ideal.

)
connectedValidators, err := r.network.ConnectToCanonicalValidators(r.signingSubnetID)
if err != nil {
r.logger.Error(
"Failed to connect to canonical validators",
zap.String("warpMessageID", unsignedMessage.ID().String()),
zap.Error(err),
)
return nil, err
Expand Down Expand Up @@ -368,6 +374,7 @@ func (r *ApplicationRelayer) createSignedMessageAppRequest(unsignedMessage *aval
if err != nil {
r.logger.Error(
"Failed to create app request message",
zap.String("warpMessageID", unsignedMessage.ID().String()),
zap.Error(err),
)
return nil, err
Expand All @@ -382,6 +389,7 @@ func (r *ApplicationRelayer) createSignedMessageAppRequest(unsignedMessage *aval
r.logger.Debug(
"Relayer collecting signatures from peers.",
zap.Int("attempt", attempt),
zap.String("sourceBlockchainID", r.sourceBlockchain.GetBlockchainID().String()),
zap.String("destinationBlockchainID", r.relayerID.DestinationBlockchainID.String()),
zap.Int("validatorSetSize", len(connectedValidators.ValidatorSet)),
zap.Int("signatureMapSize", len(signatureMap)),
Expand All @@ -401,6 +409,9 @@ func (r *ApplicationRelayer) createSignedMessageAppRequest(unsignedMessage *aval
r.logger.Debug(
"Added node ID to query.",
zap.String("nodeID", nodeID.String()),
zap.String("warpMessageID", unsignedMessage.ID().String()),
zap.String("destinationBlockchainID", r.relayerID.DestinationBlockchainID.String()),
zap.String("sourceBlockchainID", r.sourceBlockchain.GetBlockchainID().String()),
)

// Register a timeout response for each queried node
Expand All @@ -418,8 +429,10 @@ func (r *ApplicationRelayer) createSignedMessageAppRequest(unsignedMessage *aval
sentTo := r.network.Network.Send(outMsg, vdrSet, r.sourceBlockchain.GetSubnetID(), subnets.NoOpAllower)
r.logger.Debug(
"Sent signature request to network",
zap.String("messageID", unsignedMessage.ID().String()),
zap.String("warpMessageID", unsignedMessage.ID().String()),
zap.Any("sentTo", sentTo),
zap.String("sourceBlockchainID", r.sourceBlockchain.GetBlockchainID().String()),
zap.String("destinationBlockchainID", r.relayerID.DestinationBlockchainID.String()),
)
for nodeID := range vdrSet {
if !sentTo.Contains(nodeID) {
Expand All @@ -440,6 +453,9 @@ func (r *ApplicationRelayer) createSignedMessageAppRequest(unsignedMessage *aval
r.logger.Debug(
"Processing response from node",
zap.String("nodeID", response.NodeID().String()),
zap.String("warpMessageID", unsignedMessage.ID().String()),
zap.String("sourceBlockchainID", r.sourceBlockchain.GetBlockchainID().String()),
zap.String("destinationBlockchainID", r.relayerID.DestinationBlockchainID.String()),
)
signedMsg, relevant, err := r.handleResponse(
response,
Expand All @@ -460,6 +476,9 @@ func (r *ApplicationRelayer) createSignedMessageAppRequest(unsignedMessage *aval
if signedMsg != nil {
r.logger.Info(
"Created signed message.",
zap.String("warpMessageID", unsignedMessage.ID().String()),
zap.Uint64("signatureWeight", accumulatedSignatureWeight.Uint64()),
zap.String("sourceBlockchainID", r.sourceBlockchain.GetBlockchainID().String()),
zap.String("destinationBlockchainID", r.relayerID.DestinationBlockchainID.String()),
)
return signedMsg, nil
Expand All @@ -480,6 +499,9 @@ func (r *ApplicationRelayer) createSignedMessageAppRequest(unsignedMessage *aval
r.logger.Warn(
"Failed to collect a threshold of signatures",
zap.Int("attempts", maxRelayerQueryAttempts),
zap.String("warpMessageID", unsignedMessage.ID().String()),
zap.Uint64("accumulatedWeight", accumulatedSignatureWeight.Uint64()),
zap.String("sourceBlockchainID", r.sourceBlockchain.GetBlockchainID().String()),
zap.String("destinationBlockchainID", r.relayerID.DestinationBlockchainID.String()),
)
return nil, errNotEnoughSignatures
Expand Down Expand Up @@ -528,13 +550,21 @@ func (r *ApplicationRelayer) handleResponse(
r.logger.Debug(
"Got valid signature response",
zap.String("nodeID", nodeID.String()),
zap.Uint64("stakeWeight", validator.Weight),
zap.String("warpMessageID", unsignedMessage.ID().String()),
zap.String("sourceBlockchainID", r.sourceBlockchain.GetBlockchainID().String()),
zap.String("destinationBlockchainID", r.relayerID.DestinationBlockchainID.String()),
)
signatureMap[vdrIndex] = signature
accumulatedSignatureWeight.Add(accumulatedSignatureWeight, new(big.Int).SetUint64(validator.Weight))
} else {
r.logger.Debug(
"Got invalid signature response",
zap.String("nodeID", nodeID.String()),
zap.Uint64("stakeWeight", validator.Weight),
zap.String("warpMessageID", unsignedMessage.ID().String()),
zap.String("sourceBlockchainID", r.sourceBlockchain.GetBlockchainID().String()),
zap.String("destinationBlockchainID", r.relayerID.DestinationBlockchainID.String()),
)
return nil, true, nil
}
Expand All @@ -550,7 +580,9 @@ func (r *ApplicationRelayer) handleResponse(
if err != nil {
r.logger.Error(
"Failed to aggregate signature.",
zap.String("sourceBlockchainID", r.sourceBlockchain.GetBlockchainID().String()),
zap.String("destinationBlockchainID", r.relayerID.DestinationBlockchainID.String()),
zap.String("warpMessageID", unsignedMessage.ID().String()),
zap.Error(err),
)
return nil, true, err
Expand All @@ -563,6 +595,9 @@ func (r *ApplicationRelayer) handleResponse(
if err != nil {
r.logger.Error(
"Failed to create new signed message",
zap.String("sourceBlockchainID", r.sourceBlockchain.GetBlockchainID().String()),
zap.String("destinationBlockchainID", r.relayerID.DestinationBlockchainID.String()),
zap.String("warpMessageID", unsignedMessage.ID().String()),
zap.Error(err),
)
return nil, true, err
Expand Down