Skip to content

Commit

Permalink
mixclient: Improve error returning
Browse files Browse the repository at this point in the history
When creating the alternate session failed during a run, the wrong error was
being returned to the caller.

To simplify this logic, don't check the alternate session's error field here,
and just return the alternate session (itself implementing the error type) to
the caller (pairSessions, who calls run).

While here, some additional details are included in the wrapped error returned
when receiving KEs, which will aid in future debugging.
  • Loading branch information
jrick authored and davecgh committed May 24, 2024
1 parent 85bca62 commit 9fde00a
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions mixing/mixclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,7 @@ func (c *Client) pairSession(ctx context.Context, ps *pairedSessions, prs []*wir
go func() {
time.Sleep(10 * time.Second)
c.logf("sid=%x removing mixed session completed with transaction %v",
mixedSession.sid[:], mixedSession.cj)
mixedSession.sid[:], mixedSession.cj.txHash)
c.mixpool.RemoveSession(mixedSession.sid, true)
}()
}
Expand Down Expand Up @@ -876,6 +876,11 @@ func (c *Client) pairSession(ctx context.Context, ps *pairedSessions, prs []*wir

var altses *alternateSession
if errors.As(err, &altses) {
if altses.err != nil {
sesLog.logf("Unable to recreate session: %v", altses.err)
return
}

if len(altses.prs) < MinPeers {
sesLog.logf("Aborting session with too few remaining peers")
return
Expand Down Expand Up @@ -1075,7 +1080,8 @@ func (c *Client) run(ctx context.Context, ps *pairedSessions, madePairing *bool)
defer cancel()
err = mp.Receive(ctx, len(sesRun.prs), rcv)
if ctx.Err() != nil {
err = fmt.Errorf("KE receive context cancelled: %w", ctx.Err())
err = fmt.Errorf("session %x run-%d KE receive context cancelled: %w",
sesRun.sid[:], sesRun.run, ctx.Err())
}
return rcv.KEs, err
}
Expand All @@ -1092,7 +1098,7 @@ func (c *Client) run(ctx context.Context, ps *pairedSessions, madePairing *bool)
// may be operable now if all wallets have come to agree on a
// previous session we also tried to form.
kes, err = recvKEs(sesRun)
if len(kes) == len(sesRun.prs) {
if err == nil && len(kes) == len(sesRun.prs) {
break
}

Expand All @@ -1108,11 +1114,7 @@ func (c *Client) run(ctx context.Context, ps *pairedSessions, madePairing *bool)
return errOnlyKEsBroadcasted
}

altses := c.alternateSession(ps.pairing, sesRun.prs, d)
if altses.err != nil {
return err
}
return altses
return c.alternateSession(ps.pairing, sesRun.prs, d)

default:
// Receive KEs only for the agreed-upon session.
Expand Down

0 comments on commit 9fde00a

Please sign in to comment.