diff --git a/convex-peer/src/main/java/convex/peer/BeliefPropagator.java b/convex-peer/src/main/java/convex/peer/BeliefPropagator.java index c7d988cdb..9ba7e5798 100644 --- a/convex-peer/src/main/java/convex/peer/BeliefPropagator.java +++ b/convex-peer/src/main/java/convex/peer/BeliefPropagator.java @@ -276,37 +276,27 @@ protected boolean maybeMergeBeliefs(Belief... newBeliefs) { */ private Belief awaitBelief() throws InterruptedException { ArrayList beliefMessages=new ArrayList<>(); - try { - // if we did a belief merge recently, pause for a bit to await more Beliefs - LoadMonitor.down(); - Message firstEvent=beliefQueue.poll(AWAIT_BELIEFS_PAUSE, TimeUnit.MILLISECONDS); - LoadMonitor.up(); - if (firstEvent==null) return null; // nothing arrived - - beliefMessages.add(firstEvent); - beliefQueue.drainTo(beliefMessages); - HashMap> newOrders=belief.getOrdersHashMap(); - // log.info("Merging Beliefs: "+allBeliefs.size()); - - boolean anyOrderChanged=false; - for (Message m: beliefMessages) { - boolean changed=mergeBeliefMessage(newOrders,m); - if (changed) anyOrderChanged=true; - } - if (!anyOrderChanged) return null; - - Belief newBelief= Belief.create(newOrders); - return newBelief; - - } catch (InterruptedException e) { - // This is expected sometimes, e.g. peer shutdown - throw e; - } catch (Exception e) { - // we didn't expect this! - log.warn("UNEXPECTED error awaiting Belief",e); - return null; + // if we did a belief merge recently, pause for a bit to await more Beliefs + LoadMonitor.down(); + Message firstEvent=beliefQueue.poll(AWAIT_BELIEFS_PAUSE, TimeUnit.MILLISECONDS); + LoadMonitor.up(); + if (firstEvent==null) return null; // nothing arrived + + beliefMessages.add(firstEvent); + beliefQueue.drainTo(beliefMessages); + HashMap> newOrders=belief.getOrdersHashMap(); + // log.info("Merging Beliefs: "+allBeliefs.size()); + + boolean anyOrderChanged=false; + for (Message m: beliefMessages) { + boolean changed=mergeBeliefMessage(newOrders,m); + if (changed) anyOrderChanged=true; } + if (!anyOrderChanged) return null; + + Belief newBelief= Belief.create(newOrders); + return newBelief; } diff --git a/convex-peer/src/test/java/convex/peer/TestNetwork.java b/convex-peer/src/test/java/convex/peer/TestNetwork.java index ae2f081cd..55347f490 100644 --- a/convex-peer/src/test/java/convex/peer/TestNetwork.java +++ b/convex-peer/src/test/java/convex/peer/TestNetwork.java @@ -1,8 +1,10 @@ package convex.peer; +import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.concurrent.TimeoutException; import java.util.stream.Collectors; import org.slf4j.Logger; @@ -16,6 +18,7 @@ import convex.core.crypto.AKeyPair; import convex.core.data.AccountKey; import convex.core.data.Address; +import convex.core.exceptions.ResultException; import convex.core.init.Init; import convex.core.util.Utils; @@ -98,8 +101,11 @@ public synchronized ConvexRemote getClient(AKeyPair kp) { network.CONVEX.transferSync(addr, Coin.GOLD); ConvexRemote client=Convex.connect(network.SERVER.getHostAddress(),addr,kp); return client; - } catch (Exception t) { + } catch (IOException | ResultException | TimeoutException t) { throw Utils.sneakyThrow(t); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + return null; } }