Skip to content

Conversation

@vpavlin
Copy link
Member

@vpavlin vpavlin commented Mar 11, 2025

  1. This adds option func (https://golang.cafe/blog/golang-functional-options-pattern.html) to WakuNode
  2. Adds ExtraOptions - a map of string -> interface{} of options allowing to configure any of nwaku config options

Example:

node, err := NewWakuNode(&DefaultWakuConfig, "test", 
      WithExtraOptions(common.ExtraOptions{"rlnRelayEthClientAddress": "https://api.zan.top/eth-sepolia"}))

This will configure given URL as RLN RPC for nwaku

Copy link
Contributor

@gabrielmer gabrielmer left a comment

Choose a reason for hiding this comment

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

Thanks so much! Just added a small question :))

Comment on lines +363 to +365
for _, o := range opts {
o(n)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

what does this do? not sure I follow it

Copy link
Member Author

@vpavlin vpavlin Mar 11, 2025

Choose a reason for hiding this comment

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

Which is why I provided a link to the article in the description: https://golang.cafe/blog/golang-functional-options-pattern.html

TL;DR: It allows you to define and passing functions that get called automatically which adds more flexibility to configuration than a custom struct - same approach has been used in go-waku (https://github.com/waku-org/go-waku/blob/master/waku/v2/node/wakuoptions.go#L135), so then you end up with something like:

NewNode(something,
  WithTimeout(..),
  WithRLN(...),
  WIthGabrielsBrain(...),
  ...
 )

Copy link
Contributor

Choose a reason for hiding this comment

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

Oooh makes sense! Thanks so much! 🤩

Copy link
Collaborator

@Ivansete-status Ivansete-status left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks for it! 💯
Maybe interesting to add a simple unit test showing how to use it

@vpavlin
Copy link
Member Author

vpavlin commented Mar 11, 2025

Maybe interesting to add a simple unit test showing how to use it

I am just not sure what the test should test:-) Like how do I "prove" the node is configured properly with that extra config? I am open to suggestions:-)

Co-authored-by: Ivan FB <[email protected]>
@Ivansete-status
Copy link
Collaborator

I am just not sure what the test should test:-) Like how do I "prove" the node is configured properly with that extra config? I am open to suggestions:-)

ah yes good point hehe ^^'
Maybe we could just try to start a node by using correct nodekey param (64-hex) and check that a node doesn't start correctly by setting a 63-long nodekey. That way we could see that the parameter is effectively being pushed to the node.

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.

4 participants