KomodoPlatform / komodo-defi-framework

This is the official Komodo DeFi Framework repository
https://komodoplatform.com/en/docs/komodo-defi-framework/
103 stars 94 forks source link

MM2 attempts to bind on IP address which is not actually available. #273

Closed artemii235 closed 5 years ago

artemii235 commented 5 years ago
31 11:56:17, mm2:187] BarterDEX MarketMaker UNKNOWN
RPCport.0 remoteport.-1, nanoports 47762 47772 47782
31 11:56:17, lp_native_dex:1558] showwif.0 version: UNKNOWN 2455984605
31 11:56:17, lp_native_dex:1648] lp_init] Trying to fetch the real IP from 'http://checkip.amazonaws.com/' ...
31 11:56:17, lp_native_dex:1701] error binding to (tcp://206.248.64.23:47772).0
31 11:56:17, lp_native_dex:1709] >>>>>>>>> myipaddr.(tcp://206.248.64.23:47772) pubsock.-1
bind to tcp://206.248.64.23:47762 error for tcp://206.248.64.23:47762: Cannot assign requested address

MM2 gets public IP and attempts to bind port on it.


ArtemGr commented 5 years ago

Note that IP detection was ported from MM1.

Correct me if I'm wrong, but the failure is likely due to NAT (this is when the external IP doesn't match the IP of the interface) and the nanomsg binding wouldn't know how to work from behind NAT anyway, unless the user has manual port forwarding configured or something like that.

What's different from MM1 though is that the myipaddr was ignored in some of the MM1 bindings (using 0.0.0.0 instead). We shouldn't repeat this 0.0.0.0 workaround though, because it prevents multiple MM2 instances from coexisting during the automatic testing and such.

I suggest removing the IP detection code and using 0.0.0.0 in place of myipaddr by default, but not ignoring myipaddr like MM1 did.

artemii235 commented 5 years ago

@ArtemGr Hi, the current workaround for users is to explicitly set 127.0.0.1 as myipaddr for such case. Maybe we can bind on 127.0.0.1 if we fail to bind on myipaddr or just do not attempt to bind on it at all?

ArtemGr commented 5 years ago

@artemii235 , sounds good, will try to implement in that order.

artemii235 commented 5 years ago

@ArtemGr I've found where it comes from, this code https://github.com/artemii235/SuperNET/blob/mm2/iguana/exchanges/LP_network.c#L862 does just exit(1) if bind fails, we can change it to return(-1) and then it just works :slightly_smiling_face: I've tested it locally.

artemii235 commented 5 years ago

There's one more place above when it can just exit: https://github.com/artemii235/SuperNET/blob/mm2/iguana/exchanges/LP_network.c#L850

ArtemGr commented 5 years ago

IP detection was improved recently to include the actual HTTP communication.