teku icon indicating copy to clipboard operation
teku copied to clipboard

Reject duplicate sidecars in BlobSidecarsByRoot

Open jtraglia opened this issue 1 year ago • 15 comments

PR Description

After sending a BlobSidecarsByRoot request to a peer, it would be possible for the peer to send the same blob sidecar multiple times. Not necessarily a problem, but I think it would be a good idea to disallow this. We expect peers to send unique sidecars like they're supposed to.

I was initially concerned with this function because I thought it would be possible to send the same sidecar forever. This isn't possible though because Eth2OutgoingRequestHandler handles this properly. Nice.

https://github.com/Consensys/teku/blob/f31b239f7788f07d8e9c2b6e7544c5e16b01a259/networking/eth2/src/main/java/tech/pegasys/teku/networking/eth2/rpc/core/Eth2OutgoingRequestHandler.java#L131-L133

Documentation

  • [x] I thought about documentation and added the doc-change-required label to this PR if updates are required.

Changelog

  • [x] I thought about adding a changelog entry, and added one if I deemed necessary.

jtraglia avatar Nov 03 '23 19:11 jtraglia

Nice catch! I was also thinking on checking the order, but decided it's too paranoid for now. And it's a bit complicated while delivering low value because we allow gaps in the response.

zilm13 avatar Nov 06 '23 15:11 zilm13

not super super about synchronization though

tbenr avatar Nov 06 '23 15:11 tbenr

@zilm13: I was also thinking on checking the order, but decided it's too paranoid for now.

I also had this thought. I checked the specs and didn't see anything about ordering. I can imagine a situation where a peer returns the sidecars in a different order due to some optimizations or something.

@tbenr: not super super about synchronization though

Yeah I agree. Is there a better way to do this?

jtraglia avatar Nov 06 '23 15:11 jtraglia

Since AsyncResponseProcessor is designed to run the response processing strictly one by one, we can avoid synchronization and just have a thread safe Set that can be used by different threads (threads can still change from one chunk to the other). I pushed a commit. WDYT @zilm13 @jtraglia ?

tbenr avatar Nov 06 '23 16:11 tbenr

I think that looks good! But maybe we do need to check order after all. Chatting with colleagues some about it and it seems that it does matter. Checking order might simplify this too, as we wouldn't need to delete entries.

jtraglia avatar Nov 06 '23 16:11 jtraglia

Made a PR to the consensus specs to bring this up:

  • https://github.com/ethereum/consensus-specs/pull/3544

jtraglia avatar Nov 06 '23 17:11 jtraglia

Ok let's freeze it for a while (until spec resolution) and we could do order check without any synchronization. volatile Optional<> previous could be enough

zilm13 avatar Nov 06 '23 17:11 zilm13

@StefanBratanov are we circling back on this one?

rolfyone avatar Dec 05 '23 03:12 rolfyone

@StefanBratanov are we circling back on this one?

There is a spec PR https://github.com/ethereum/consensus-specs/pull/3544 that we would like to be closed/merged, before circling back on this one, so will leave this PR open for now.

StefanBratanov avatar Dec 05 '23 09:12 StefanBratanov

Btw I've checked our code and if we get a response in a wrong order we will fail on import because for BlobSidecars it could mean that you request [b0s0,b0s1,b0s2] and receive [b0s2, b0s0, b0s1]. So if MUST is not added to the spec, we need to add sorting somewhere.

zilm13 avatar Dec 05 '23 21:12 zilm13

I've pulled in changes from master & addressed Stefan's review comments. If the team is still interested in merging this PR, it should be ready now. If not, happy to close it. I don't think we're going to make this change in the consensus-specs.

jtraglia avatar Mar 11 '24 17:03 jtraglia

Hi @jtraglia rejection of duplicates makes sense to me and I think it's a good one. @tbenr @zilm13 what's your take?

StefanBratanov avatar Mar 11 '24 19:03 StefanBratanov

It's better than nothing as otherwise we will add it twice here https://github.com/Consensys/teku/blob/94d37825e1fb4e2f14c3e964fa8eb68d5f8e4f1b/beacon/sync/src/main/java/tech/pegasys/teku/beacon/sync/historical/HistoricalBatchFetcher.java#L250-L254 But I'm also concerning on this https://github.com/Consensys/teku/pull/7658#issuecomment-1841614085 though we could address it separately

zilm13 avatar Mar 14 '24 15:03 zilm13

By spec we cannot require what we really want, so we should do it in our HistoricalBatchFetcher instead, but I'm thinking on something like this, which is more or less up to the spec and looks like covering all needed validations What do you think @StefanBratanov @jtraglia https://github.com/zilm13/teku/commit/7b140b75105dba779580505822b17e21f5dcd3b5

Or we shouldn't require the same order? If we cannot require the same order, existing PR by @jtraglia is good

zilm13 avatar Mar 14 '24 17:03 zilm13

okay, I've reread your discussion in consensus-specs, looks like there is no consensus about the order, so I'm happy to merge this one PR We just need extra sorting in HistoricalBatchFetcher, we cannot put all our needs in the spec.  Actually I see there is an area of possible improvements in the fetcher, so we will do it in some separate PR

zilm13 avatar Mar 14 '24 18:03 zilm13