ethereum / devp2p

Ethereum peer-to-peer networking specifications
995 stars 277 forks source link

discv5: need more info on global topic queue limit #110

Closed FrankSzendzielarz closed 5 years ago

FrankSzendzielarz commented 5 years ago

The topic discovery mechanism has a global limit on topic advertisements:

There is also a global limit on the number of ads regardless of the topic queue which contains them. When the global limit is reached, the last entry of the least recently requested topic queue is removed.

There are three possible issues with this that I can see:

  1. An attack where malicious nodes can conspire to continuously register random, new topics, and request the ads placed in those topics to make them no 'least recently requested'
  2. A similar attack but where the topic registrations are made concurrently, as if I understand correctly there is no prevention over issuing concurrent ad requests for 1000 different new topics (eg)
  3. Legitimate advertisers placing ads on a server with the global limit at threshold may find their ads being selected for immediate removal.
FrankSzendzielarz commented 5 years ago

I suggest a global limiter that applies to the overall rate of new topic creations.

FrankSzendzielarz commented 5 years ago

Open question: how to decide which ad is least valuable and so which is evicted.

fjl commented 5 years ago

@zsfelfoldi says:

I've been thinking a bit more about the global limit eviction priority. Now I think it is perfectly fine and simple if we just enforce the same 10 min lifetime for every ad and if registration is limited by the global limit then evict the first ad (regardless of topic importance) whose guaranteed lifetime is over. We just need a per-topic FIFO and a global FIFO. For more popular topics the length of the topic queue will still be limited by per-topic limit. For less popular ones it will be proportional to the total global efforts to register that topic and I think that is fine. Filling most of the table's total allowance with junk is possible but the important thing is that it will not significantly hinder the registration of important and popular topics. For popular topics (where the topic queue size is at its limit) the time of the next round of "competition" only depends on the first expiring ad from the same queue. The only trick is that we should mark the soonest expiring ad for eviction when we first issue a ticket for the next registration in that queue and until that happens we do not select it for eviction based on global limit (which happens much more frequently). So we can be sure that in the next round for "important" topic registration we are actually have an ad to evict and we can register one of the candidates.