Skip to content

Commit

Permalink
[release-v2.0] mixclient: Introduce random message jitter
Browse files Browse the repository at this point in the history
In this change, random per-peer (per-identity) and per-message jitter are
added to add additional delay to all message broadcasts.  The jitter delay
will range from 0-3s, with a random 0-2700ms of that being per-peer and
0-300ms being per-message.  The total delay is calculated as 1/10 of the stage
timeout duration, and the per-message delay is calculated is both the mean and
median of dcrd's inventory trickling delay.

While here, pair request messages are also submitted to the network with
random delays spanning over the entire epoch duration, while avoiding any PR
sends during the 30s before and after the epoch.
  • Loading branch information
jrick authored and davecgh committed Jun 19, 2024
1 parent c21c33a commit b0b96e4
Show file tree
Hide file tree
Showing 3 changed files with 237 additions and 63 deletions.
12 changes: 7 additions & 5 deletions mixing/mixclient/blame.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ func (c *Client) blame(ctx context.Context, sesRun *sessionRun) (err error) {
}
}()

err = c.forLocalPeers(ctx, sesRun, func(p *peer) error {
err = c.sendLocalPeerMsgs(ctx, sesRun, true, func(p *peer) mixing.Message {
// Send initial secrets messages from any peers who detected
// misbehavior.
if !p.triggeredBlame {
return nil
}
return p.signAndSubmit(p.rs)
return p.rs
})
if err != nil {
return err
Expand All @@ -88,21 +88,23 @@ func (c *Client) blame(ctx context.Context, sesRun *sessionRun) (err error) {
}

// Send remaining secrets messages.
err = c.forLocalPeers(ctx, sesRun, func(p *peer) error {
err = c.sendLocalPeerMsgs(ctx, sesRun, true, func(p *peer) mixing.Message {
if p.triggeredBlame {
p.triggeredBlame = false
return nil
}
p.rs.SeenSecrets = rsHashes
return p.signAndSubmit(p.rs)
return p.rs
})
if err != nil {
return err
}

// Wait for all secrets, or timeout.
rcv.RSs = make([]*wire.MsgMixSecrets, 0, len(sesRun.prs))
_ = mp.Receive(ctx, rcv)
rcvCtx, rcvCtxCancel := context.WithTimeout(ctx, timeoutDuration)
_ = mp.Receive(rcvCtx, rcv)
rcvCtxCancel()
rss := rcv.RSs
for _, rs := range rcv.RSs {
if idx, ok := identityIndices[rs.Identity]; ok {
Expand Down
Loading

0 comments on commit b0b96e4

Please sign in to comment.