tessera icon indicating copy to clipboard operation
tessera copied to clipboard

peer {} misconfiguration not flagged

Open macfarla opened this issue 3 years ago • 4 comments

I have 3 tessera nodes. If I configure the peering so that node3 has 2 peers (node 1 and node2) configured:

   "peer": [
       { "url": "http://localhost:8082" ,
        "url": "http://localhost:8081" }
   ],

If I start node3 only, it only logs attempt to connect to the final item in the list - it seems to be parsing the list of strings as a single json object.

2022-02-09 14:12:53.109 [pool-4-thread-1] INFO c.q.t.p.p.PartyInfoBroadcaster - Started PartyInfo polling round 2022-02-09 14:12:53.110 [pool-4-thread-1] INFO c.q.t.p.p.PartyInfoBroadcaster - Finished PartyInfo polling round 2022-02-09 14:12:53.111 [pool-3-thread-1] WARN c.q.t.p.p.PartyInfoBroadcaster - Failed to connect to node http://localhost:8081/, due to java.net.ConnectException: Connection refused (Connection refused)

And if the three nodes are running, node3 only connects to node1 (last item in the list)

However, if I put this into the peers config (note {} for each peer ), it works as expected ie all three peer with each other

   "peer": [
       { "url": "http://localhost:8082" },
        { "url": "http://localhost:8081" }
   ],

Would be nice to flag this misconfiguration to the user on startup.

macfarla avatar Feb 09 '22 04:02 macfarla

Indeed the second definition is the one that works.

[ ] is for a list of values, while { } contains keys/values pairs "key":value, where key is unique.

{"a":xxx,"a":"yyy"} has a conflict in the key, the yyy value might be taken as it redefines the value.

baptiste-b-pegasys avatar Feb 09 '22 08:02 baptiste-b-pegasys

{ } indicates a json object

Your configuration

{ "url": "http://localhost:8082" , "url": "http://localhost:8081" }

is not a list of strings and not a valid json object (contains duplicate key)

Correct json should be

"peer": [ { "url": "http://localhost:9001" }, { "url": "http://localhost:9002" } ]

namtruong avatar Feb 09 '22 10:02 namtruong

if it's not valid json I should get an error though?

macfarla avatar Feb 09 '22 23:02 macfarla

it is a valid JSON syntax, but it is not useful the way it is used.

The JSON parser will not raise an error, but we could had some more intelligent JSON verifier if such exists.

baptiste-b-pegasys avatar Feb 10 '22 05:02 baptiste-b-pegasys