-
Notifications
You must be signed in to change notification settings - Fork 130
Conversation
The staticnodes.json file resides in the pantheon data directory, is parsed at startup to determine which peers can be connected to (aside from bootnodes), and is updated whenever addPeer/removePeer RPC is invoked. This file is not updated when finding neighbour peers (ONLY on RPC call).
public class PersistentJsonPeerCache extends PersistentPeerCache { | ||
|
||
private static final Logger LOG = LogManager.getLogger(); | ||
private static final Charset UTF_8 = Charset.forName("UTF-8"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JDK constant of StandardCharsets.UTF_8
would be a nicer fit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
final Set<EnodeURL> enodes = StaticNodesParser.fromPath(path); | ||
|
||
assertThat(enodes.size()).isEqualTo(4); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about asserting the contents of the endoes list? ...as not just any old four enode IDs will do
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
import org.junit.Test; | ||
import org.junit.rules.TemporaryFolder; | ||
|
||
public class StaticeNodesParserTest { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo in class name
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
@@ -1161,4 +1164,11 @@ public MetricsSystem getMetricsSystem() { | |||
public PantheonExceptionHandler exceptionHandler() { | |||
return exceptionHandlerSupplier.get(); | |||
} | |||
|
|||
private Set<EnodeURL> loadStaticNodes() throws IOException { | |||
final String STATIC_NODES_FILENAME = "static-nodes.json"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can this be made a constant
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
made is a local variable.
|
||
try { | ||
final JsonArray enodeJsonArray = new JsonArray(new String(staticNodesContent, UTF_8)); | ||
for (Object jsonObj : enodeJsonArray.getList()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
be nicer to use the jsonArray.stream instead of populating a set
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
} | ||
|
||
try { | ||
final JsonArray enodeJsonArray = new JsonArray(new String(staticNodesContent, UTF_8)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: thinking the code would be cleaner to do something similar to what IbftExtraDataCLIAdapter has done and just use objectMapper and do a objectMapper.readValue(path.toFile(), typedef..) to read it straight to Set and then transform to enodes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done - sort of.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
The staticnodes.json file resides in the pantheon data directory,
is parsed at startup to determine which peers can be connected
to (aside from bootnodes), and is updated whenever addPeer/removePeer
RPC is invoked.
This file is not updated when finding neighbour peers (ONLY on RPC
call).