order+rpcserver: send correct RPC reject message

This commit is contained in:
Oliver Gugger 2020-08-14 17:22:07 +02:00
parent 4c4c5a2e43
commit 02bd5a7ef8
No known key found for this signature in database
GPG key ID: 8E4256593F177720
2 changed files with 15 additions and 3 deletions

View file

@ -278,7 +278,7 @@ func (m *Manager) OrderMatchValidate(batch *Batch) error {
// This error will lead to us sending an OrderMatchReject
// message and canceling all funding shims we might already have
// set up.
return fmt.Errorf("error validating batch: %v", err)
return fmt.Errorf("error validating batch: %w", err)
}
m.pendingBatch = batch

View file

@ -392,7 +392,8 @@ func (s *rpcServer) handleServerMessage(rpcMsg *clmrpc.ServerAuctionMessage) err
// funding shim.
err = s.fundingManager.prepChannelFunding(batch)
if err != nil {
rpcLog.Errorf("Error preparing channel funding: %v", err)
rpcLog.Warnf("Error preparing channel funding: %v",
err)
return s.sendRejectBatch(batch, err)
}
@ -1175,6 +1176,7 @@ func (s *rpcServer) sendRejectBatch(batch *order.Batch, failure error) error {
}
// Attach the status code to the message to give a bit more context.
var partialReject *matchRejectErr
switch {
case errors.Is(failure, order.ErrVersionMismatch):
msg.Reject.ReasonCode = clmrpc.OrderMatchReject_BATCH_VERSION_MISMATCH
@ -1182,6 +1184,13 @@ func (s *rpcServer) sendRejectBatch(batch *order.Batch, failure error) error {
case errors.Is(failure, order.ErrMismatchErr):
msg.Reject.ReasonCode = clmrpc.OrderMatchReject_SERVER_MISBEHAVIOR
case errors.As(failure, &partialReject):
msg.Reject.ReasonCode = clmrpc.OrderMatchReject_PARTIAL_REJECT
msg.Reject.RejectedOrders = make(map[string]*clmrpc.OrderReject)
for nonce, reject := range partialReject.rejectedOrders {
msg.Reject.RejectedOrders[nonce.String()] = reject
}
default:
msg.Reject.ReasonCode = clmrpc.OrderMatchReject_UNKNOWN
}
@ -1199,7 +1208,10 @@ func (s *rpcServer) sendRejectBatch(batch *order.Batch, failure error) error {
if err != nil {
return fmt.Errorf("error sending reject message: %v", err)
}
return failure
// We have handled the batch failure and informed the auctioneer. We
// have done our job so no need to return an error.
return nil
}
// sendAcceptBatch sends an accept message to the server with the list of order