Skip to content

Commit

Permalink
Have clients notice when the server is on another network
Browse files Browse the repository at this point in the history
  • Loading branch information
fireduck64 committed Oct 23, 2018
1 parent 3545c02 commit bf986e6
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 5 deletions.
18 changes: 16 additions & 2 deletions client/src/GetUTXOUtil.java
Expand Up @@ -29,18 +29,32 @@ public class GetUTXOUtil
private UserServiceBlockingStub stub;
private long utxo_root_time = 0;
private ChainHash last_utxo_root = null;
private NetworkParams params;

public GetUTXOUtil(UserServiceBlockingStub stub)
public GetUTXOUtil(UserServiceBlockingStub stub, NetworkParams params)
{
this.stub = stub;
this.params = params;
}

public synchronized ChainHash getCurrentUtxoRootHash()
{

if (utxo_root_time + UTXO_ROOT_EXPIRE < System.currentTimeMillis())
{
last_utxo_root= new ChainHash(stub.getNodeStatus( NullRequest.newBuilder().build() ).getHeadSummary().getHeader().getUtxoRootHash());
NodeStatus ns = stub.getNodeStatus( NullRequest.newBuilder().build() );
if (ns.getNetwork().length() > 0)
{
if (!ns.getNetwork().equals(params.getNetworkName()))
{
throw new RuntimeException(String.format("Network name mismatch. Expected %s, got %s",
params.getNetworkName(),
ns.getNetwork()));
}

}

last_utxo_root= new ChainHash(ns.getHeadSummary().getHeader().getUtxoRootHash());
utxo_root_time = System.currentTimeMillis();
logger.log(Level.FINE, "UTXO root hash: " + last_utxo_root);
}
Expand Down
2 changes: 1 addition & 1 deletion client/src/SnowBlossomClient.java
Expand Up @@ -288,7 +288,7 @@ public SnowBlossomClient(Config config) throws Exception
asyncStub = UserServiceGrpc.newStub(channel);
blockingStub = UserServiceGrpc.newBlockingStub(channel);

get_utxo_util = new GetUTXOUtil(blockingStub);
get_utxo_util = new GetUTXOUtil(blockingStub, params);

if (config.isSet("wallet_path"))
{
Expand Down
2 changes: 2 additions & 0 deletions node/src/SnowUserService.java
Expand Up @@ -212,6 +212,8 @@ public void getNodeStatus(NullRequest null_request, StreamObserver<NodeStatus> r
.setNodeVersion(Globals.VERSION)
.putAllVersionMap(node.getPeerage().getVersionMap());

ns.setNetwork( node.getParams().getNetworkName() );

if (node.getBlockIngestor().getHead() != null)
{
ns.setHeadSummary(node.getBlockIngestor().getHead());
Expand Down
1 change: 1 addition & 0 deletions protolib/snowblossom.proto
Expand Up @@ -286,6 +286,7 @@ message NodeStatus {
int32 estimated_nodes = 4;
string node_version = 5;
map<string, int32> version_map = 6;
string network = 7;
}

// -------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion shackleton/src/RichList.java
Expand Up @@ -67,7 +67,7 @@ public RichList(Config config)
asyncStub = UserServiceGrpc.newStub(channel);
stub = UserServiceGrpc.newBlockingStub(channel);

get_utxo_util = new GetUTXOUtil(stub);
get_utxo_util = new GetUTXOUtil(stub, params);

NodeStatus node_status = stub.getNodeStatus(QueryUtil.nr());

Expand Down
2 changes: 1 addition & 1 deletion shackleton/src/Shackleton.java
Expand Up @@ -65,7 +65,7 @@ public Shackleton(Config config)

asyncStub = UserServiceGrpc.newStub(channel);
blockingStub = UserServiceGrpc.newBlockingStub(channel);
get_utxo_util = new GetUTXOUtil(blockingStub);
get_utxo_util = new GetUTXOUtil(blockingStub, params);

web_server.start();

Expand Down

0 comments on commit bf986e6

Please sign in to comment.