Skip to content

Commit

Permalink
cleaner deadline handling for sends
Browse files Browse the repository at this point in the history
  • Loading branch information
jrick committed Dec 31, 2024
1 parent 20997c8 commit b3df5a9
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions mixing/mixclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -573,13 +573,7 @@ func (c *Client) sendLocalPeerMsgs(ctx context.Context, deadline time.Time, s *s
continue
case <-time.After(time.Until(m.sendTime)):
}
// TODO: handle send deadline in wallet.SubmitMixMessage.
if time.Now().After(m.deadline) {
nilPeerMsg(m.p, m.m)
errs = append(errs, errSendTimeout)
continue
}
err := m.p.signAndSubmit(m.m)
err := m.p.signAndSubmit(m.deadline, m.m)
if err != nil {
nilPeerMsg(m.p, m.m)
errs = append(errs, err)
Expand Down Expand Up @@ -671,19 +665,21 @@ func (p *peer) signAndHash(m mixing.Message) error {
return nil
}

func (p *peer) submit(m mixing.Message) error {
return p.client.wallet.SubmitMixMessage(p.ctx, m)
func (p *peer) submit(deadline time.Time, m mixing.Message) error {
ctx, cancel := context.WithDeadline(p.ctx, deadline)
defer cancel()
return p.client.wallet.SubmitMixMessage(ctx, m)
}

func (p *peer) signAndSubmit(m mixing.Message) error {
func (p *peer) signAndSubmit(deadline time.Time, m mixing.Message) error {
if m == nil {
return nil
}
err := p.signAndHash(m)
if err != nil {
return err
}
return p.submit(m)
return p.submit(deadline, m)
}

func (c *Client) newPendingPairing(pairing []byte) *pendingPairing {
Expand Down Expand Up @@ -866,7 +862,8 @@ func (c *Client) Dicemix(ctx context.Context, cj *CoinJoin) error {
pending.localPeers[*p.id] = p
c.mu.Unlock()

err = p.submit(pr)
deadline := time.Now().Add(timeoutDuration)
err = p.submit(deadline, pr)
if err != nil {
c.mu.Lock()
delete(pending.localPeers, *p.id)
Expand Down

0 comments on commit b3df5a9

Please sign in to comment.