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

Fix rpcClient.Address() race condition #1607

Merged
merged 2 commits into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions internal/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package node
import (
"fmt"
"log/slog"
"os"

"github.com/ethereum/go-ethereum/common"
"github.com/statechannels/go-nitro/internal/chain"
Expand All @@ -17,7 +16,7 @@ import (
)

func InitializeNode(pkString string, chainOpts chain.ChainOpts,
useDurableStore bool, durableStoreFolder string, msgPort int, logDestination *os.File, bootPeers []string,
useDurableStore bool, durableStoreFolder string, msgPort int, bootPeers []string,
) (*node.Node, *store.Store, *p2pms.P2PMessageService, *chainservice.EthChainService, error) {
if pkString == "" {
panic("pk must be set")
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ func main() {

logging.SetupDefaultLogger(os.Stdout, slog.LevelDebug)

node, _, _, _, err := node.InitializeNode(pkString, chainOpts, useDurableStore, durableStoreFolder, msgPort, os.Stdout, peerSlice)
node, _, _, _, err := node.InitializeNode(pkString, chainOpts, useDurableStore, durableStoreFolder, msgPort, peerSlice)
Copy link
Contributor

Choose a reason for hiding this comment

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

Just checking, but it seems like this change is unrelated to the race condition. Is that correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes it is unrelated to the race condition. Just something I noticed when scanning through the code. Its related to the PR that was merged this morning

if err != nil {
return err
}
Expand Down
21 changes: 10 additions & 11 deletions rpc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,16 @@ func NewRpcClient(trans transport.Requester) (RpcClientApi, error) {

c := &rpcClient{trans, &safesync.Map[chan struct{}]{}, &safesync.Map[chan query.LedgerChannelInfo]{}, &safesync.Map[chan query.PaymentChannelInfo]{}, cancel, &sync.WaitGroup{}, common.Address{}, slog.Default()}

// Retrieve the address and set it on the rpcClient
res, err := waitForRequest[serde.NoPayloadRequest, common.Address](c, serde.GetAddressMethod, serde.NoPayloadRequest{})
if err != nil {
return nil, err
}
c.nodeAddress = res

// Update the logger so we output the address
c.logger = logging.LoggerWithAddress(c.logger, c.nodeAddress)

notificationChan, err := c.transport.Subscribe()
if err != nil {
return nil, err
Expand All @@ -125,17 +135,6 @@ func NewHttpRpcClient(rpcServerUrl string) (RpcClientApi, error) {

// Address returns the address of the the nitro node
func (rc *rpcClient) Address() (common.Address, error) {
if (rc.nodeAddress == common.Address{}) {
res, err := waitForRequest[serde.NoPayloadRequest, common.Address](rc, serde.GetAddressMethod, serde.NoPayloadRequest{})
if err != nil {
return res, err
}

// Update the logger so we output the address
rc.nodeAddress = res
rc.logger = logging.LoggerWithAddress(rc.logger, rc.nodeAddress)
return res, nil
}
return rc.nodeAddress, nil
}

Expand Down
Loading