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 100-500ms of per-peer inventory delay #2383

Merged
merged 1 commit into from
Jun 18, 2024
Merged

Conversation

jrick
Copy link
Member

@jrick jrick commented Jun 18, 2024

Similar to a recent dcrd change, we want published inventory by SPV wallet peers be submitted with a small random amount of delay. In this change we use the same logic that dcrd now uses to pick, for each connected peer, a random delay between 100-500ms before the inventory is sent.

Copy link
Contributor

@matthawkins90 matthawkins90 left a comment

Choose a reason for hiding this comment

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

Something I noticed in decred/dcrd#3363 was that the address list was shuffled.

Should you also shuffle the address list here?

I know you said:

Currently, with every peer using a 500ms ticker, if no changes occur to the graph of connected nodes, messages will always propagate the nodes in the same order. However, if all nodes are randomizing their inventory batching delays, the next peer who will relay a message first during the next hop will always be different.

So it's possible that shuffling the address list is redundant, but I figured I'd ask if it was worth doing.

const d = maxInvTrickleTimeout - minInvTrickleTimeout
return minInvTrickleTimeout + rand.Duration(d)
}
timer := time.NewTimer(timeout())
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the point of setting the variable timer here? It doesn't look like it's used, and you're already using timer.Reset(timeout()) below on line 526.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh I'm sorry, I spoke too soon. You have to wait for timer.C, and then you reset it with a new randomized timeout(). I misread it as doubling-up the time-duration.

@jrick
Copy link
Member Author

jrick commented Jun 18, 2024

Something I noticed in decred/dcrd#3363 was that the address list was shuffled.

Should you also shuffle the address list here?

dcrwallet does not respond to getaddr. It only requests them.

@jrick
Copy link
Member Author

jrick commented Jun 18, 2024

or did you mean this, shuffling the inventory before we publish?

diff /home/jrick/src/dcrwallet
commit - b226415203f66ccaaad9d5e70bdb5adfa2e2e565
path + /home/jrick/src/dcrwallet
blob - 6e4effdee7b8a6306d5b60586d3a498b605aa6a6
file + p2p/peering.go
--- p2p/peering.go
+++ p2p/peering.go
@@ -542,6 +542,7 @@ func (rp *RemotePeer) sendWaitingInventory(ctx context
 	}
 
 	s := rp.waitingInvs
+	rand.ShuffleSlice(s)
 	for len(s) != 0 {
 		l := len(s)
 		if l > wire.MaxInvPerMsg {

@matthawkins90
Copy link
Contributor

Yes, sorry. Shuffling the inventory. Just wondering if it was worth doing.

@jrick
Copy link
Member Author

jrick commented Jun 18, 2024

it's a good idea. we shouldn't need to depend on the order being dependency order, as both mempool and mixpool handle orphans.

Copy link
Contributor

@matthawkins90 matthawkins90 left a comment

Choose a reason for hiding this comment

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

I like the changes to PublishTransactions and PublishMixMessages. A lot easier to read.

p2p/peering.go Outdated Show resolved Hide resolved
p2p/peering.go Outdated Show resolved Hide resolved
@davecgh
Copy link
Member

davecgh commented Jun 18, 2024

it's a good idea. we shouldn't need to depend on the order being dependency order, as both mempool and mixpool handle orphans.

I actually disagree with this. In fact, it's a bad idea, imo. It's true that mempool handles orphans, but only a pretty limited number of them on purpose to prevent malicious actors being able to fill up memory without actually spending any real coins. It assumes that they are going to mostly be advertised in dependency order. Changing that would make it so malicious actors can hinder propagation by intentionally sending a bunch of junk to flush orphan buffers.

p2p/peering.go Outdated Show resolved Hide resolved
Similar to a recent dcrd change, we want published inventory by SPV wallet
peers be submitted with a small random amount of delay.  In this change we use
the same logic that dcrd now uses to pick, for each connected peer, a random
delay between 100-500ms before the inventory is sent.
@jrick jrick merged commit 0399ae4 into decred:master Jun 18, 2024
2 checks passed
@jrick jrick deleted the invdelay branch June 18, 2024 17:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants