Skip to content

Conversation

@gerceboss
Copy link

@gerceboss gerceboss commented Jul 31, 2025

  • update error handling for receive function
  • add constructor for common transport

Question:
Should I add open, close functions for shared port ? @kdeme

@jangko jangko requested a review from kdeme July 31, 2025 09:41
Copy link
Contributor

@kdeme kdeme left a comment

Choose a reason for hiding this comment

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

Question: Should I add open, close functions for shared port ? @kdeme

Yes, that would be required. If you look at closeWait implementation, it will actually assert if the transport is already closed.

# The handling of the message needs to be done after adding the ENR.
d.handleMessage(packet.srcIdHs, a, packet.message, packet.node)
else:
if decoded.isErr:
Copy link
Contributor

@kdeme kdeme Aug 5, 2025

Choose a reason for hiding this comment

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

If we are to restructure this without the big if/else clause (which is indeed cleaner) then it would be even cleaner to use Result's valueOr.

proto.receive(Address(ip: raddr.toIpAddress(), port: raddr.port), buf)
let res = proto.receive(Address(ip: raddr.toIpAddress(), port: raddr.port), buf)
if res.isErr:
debug "Failed to process received packet", error = res.error
Copy link
Contributor

Choose a reason for hiding this comment

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

It is rather redundant to forward the error message to be logged here again, when it already was up (however trace and thus also altering here the log level).

It is also not fully clear what failed processing should include. I would perhaps also consider the unsolicited whoareyou message an processing error. While here it is rather meant for failed decoding of the packet (and the decoding error gets lost in the passed along Result).

Copy link
Author

@gerceboss gerceboss Aug 6, 2025

Choose a reason for hiding this comment

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

Oh right, we can just discard its result then ? As if the functions returns some error , it would have been logeed already.

Copy link
Contributor

Choose a reason for hiding this comment

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

I meant that you can just remove the DiscResult[void] as return value in the receive call in the first place.

Copy link
Author

@gerceboss gerceboss Aug 10, 2025

Choose a reason for hiding this comment

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

This return type was needed at Execution client where we will have to rewrite this receive function again.
That's why I started to changed it here @kdeme as suggested by @jangko in the PR

Copy link
Contributor

Choose a reason for hiding this comment

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

ok, that's fine then.

FYI, you can update your nimbus-eth1 PR (in draft) to use this commit of nim-eth. That way it is easier to see why certain changes are made or how the API should look.

responseTimeout: config.responseTimeout,
rng: rng)

proc newDiscoveryV5*(
Copy link
Contributor

Choose a reason for hiding this comment

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

As we are creating new API here to initialize the discovery protocol I would prefer to go for the func new(T: type Protocol, ... way of doing this (see also https://status-im.github.io/nim-style-guide/language.objconstr.html ).

We can perhaps alias Protocol to DiscoveryV5Protocol to make this more clear (the original Protocol type naming is rather unfortunate).

Copy link
Contributor

Choose a reason for hiding this comment

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

We also need to have the same parameters to be passed along as exist for newProtocol

)

protocol.transp = transp
protocol.seedTable()
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it will become rather confusing for the user considering there are two different types of initialization, one that requires open and one that does not, and seeds the table already in the init. Easy "mistake" for a user would be to call open also after doing newDiscoveryV5WithTransport.

As a possible solution for this we could move everything out of open and deprecate it. However that would mean the TransportOsError moves to the init.
Another possibility is to move the seedTable to the start proc, and for the open call, make it a null operation in case the transport is already open.

Copy link
Author

Choose a reason for hiding this comment

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

@kdeme as I add open close functions according to shared transport as well, then I'll remove the seedTable from the new functions

@gerceboss gerceboss requested a review from kdeme August 6, 2025 12:15
@gerceboss
Copy link
Author

@kdeme

@kdeme
Copy link
Contributor

kdeme commented Aug 9, 2025

So the issue I have with this version is that you can still use the open/close functions no matter which new call you used. The API relies heavily on the naming for the users to use it correctly. I prefer not do rely on naming.

@gerceboss
Copy link
Author

@kdeme can you please suggest some solution ? Either we can alias it with a different typename or something else.

@gerceboss
Copy link
Author

@kdeme I tried updating the submodules at nim-eth1 on my branch , I don't know why it hangs at cloning eth-tests submodule updates . I updated gitmodules nim-eth url and branch in my branch and was trying to update it with the new .gitsubmodules file

@jangko
Copy link
Contributor

jangko commented Aug 26, 2025

Why not use inheritance?

type
     DiscoveryV5Base = ref object of RootRef
          ...
          common fields
     
    DiscoveryV5Ref = ref object of DiscoveryV5Base
         fields
             
    DiscoveryV5WithTransportRef = ref object of DiscoveryV5Base
        fields

# all shared procs will use `DiscoveryV5Base` as their first param

# Specific to DiscoveryV5Ref
proc open(p: DiscoveryV5Ref) = 
    ....
    

jangko added a commit to status-im/nimbus-eth1 that referenced this pull request Aug 26, 2025
This is a workaround to fix #3573.
A better fix is to wait for status-im/nim-eth#809.
jangko added a commit to status-im/nimbus-eth1 that referenced this pull request Aug 27, 2025
This is a workaround to fix #3573.
A better fix is to wait for status-im/nim-eth#809.
@kdeme
Copy link
Contributor

kdeme commented Aug 28, 2025

Why not use inheritance?

Another option could be to just have a external_transport flag in the Protocol object and in case this flag is set not to close it.

@gerceboss
Copy link
Author

I think the flag might be a better option @kdeme @jangko , provides customisation as well and helps maintain code

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