Skip to content

Commit

Permalink
Merge pull request #2943 from freimair/monitor-bsqblocks
Browse files Browse the repository at this point in the history
Monitor reports BSQBlock head
  • Loading branch information
ripcurlx authored Jul 8, 2019
2 parents 07205a2 + 761c302 commit e953cfb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
15 changes: 11 additions & 4 deletions monitor/src/main/java/bisq/monitor/metric/P2PSeedNodeSnapshot.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
Expand All @@ -52,6 +53,7 @@
import java.util.TreeSet;
import java.util.concurrent.ConcurrentHashMap;

import lombok.Getter;
import lombok.extern.slf4j.Slf4j;

import static com.google.common.base.Preconditions.checkNotNull;
Expand Down Expand Up @@ -222,15 +224,16 @@ void report() {
// - process dao data
perType.forEach((type, nodeAddressTupleMap) -> {
// - find head
int head = (int) nodeAddressTupleMap.values().stream().sorted((o1, o2) -> Long.compare(o1.height, o2.height)).findFirst().get().height;
int head = (int) nodeAddressTupleMap.values().stream().max(Comparator.comparingLong(Tuple::getHeight)).get().height;
int oldest = (int) nodeAddressTupleMap.values().stream().min(Comparator.comparingLong(Tuple::getHeight)).get().height;

// - update queried height
if(type.contains("DaoState"))
daostateheight = head - 20;
daostateheight = oldest - 20;
else if(type.contains("Proposal"))
proposalheight = head - 20;
proposalheight = oldest - 20;
else
blindvoteheight = head - 20;
blindvoteheight = oldest - 20;

// - calculate diffs
nodeAddressTupleMap.forEach((nodeAddress, tuple) -> daoreport.put(type + "." + OnionParser.prettyPrint(nodeAddress) + ".head", Long.toString(tuple.height - head)));
Expand All @@ -239,6 +242,9 @@ else if(type.contains("Proposal"))
Set<ByteBuffer> states = new HashSet<>();
nodeAddressTupleMap.forEach((nodeAddress, tuple) -> states.add(ByteBuffer.wrap(tuple.hash)));
nodeAddressTupleMap.forEach((nodeAddress, tuple) -> daoreport.put(type + "." + OnionParser.prettyPrint(nodeAddress) + ".hash", Integer.toString(Arrays.asList(states.toArray()).indexOf(ByteBuffer.wrap(tuple.hash)))));

// - report reference head
daoreport.put(type + ".referenceHead", Integer.toString(head));
});

daoData.clear();
Expand All @@ -248,6 +254,7 @@ else if(type.contains("Proposal"))
}

private class Tuple {
@Getter
private final long height;
private final byte[] hash;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ protected void send(NetworkNode networkNode, NetworkEnvelope message) {
Futures.addCallback(future, new FutureCallback<>() {
@Override
public void onSuccess(Connection connection) {
connection.removeMessageListener(P2PSeedNodeSnapshotBase.this);
connection.addMessageListener(P2PSeedNodeSnapshotBase.this);
}

Expand Down

0 comments on commit e953cfb

Please sign in to comment.