From 602ea159f1d73023d32feeab4a302fadf83fff04 Mon Sep 17 00:00:00 2001 From: Ratan Rai Sur Date: Thu, 5 Sep 2019 20:11:33 +0300 Subject: [PATCH 01/22] move new event types over from api repo --- .../pantheon/ethereum/core/SyncStatus.java | 6 +- .../pantheon/services/PantheonEventsImpl.java | 42 ++++---- .../plugins/TestPantheonEventsPlugin.java | 4 +- .../services/PantheonEventsImplTest.java | 24 ++--- plugin-api/build.gradle | 2 +- .../pantheon/plugin/data/SyncStatus.java | 47 ++++++++ .../plugin/services/PantheonEvents.java | 100 ++++++++++++++---- 7 files changed, 170 insertions(+), 55 deletions(-) create mode 100644 plugin-api/src/main/java/tech/pegasys/pantheon/plugin/data/SyncStatus.java diff --git a/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/core/SyncStatus.java b/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/core/SyncStatus.java index 165df0e95d..72596546b1 100644 --- a/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/core/SyncStatus.java +++ b/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/core/SyncStatus.java @@ -14,7 +14,7 @@ import java.util.Objects; -public final class SyncStatus { +public final class SyncStatus implements tech.pegasys.pantheon.plugin.data.SyncStatus { private final long startingBlock; private final long currentBlock; @@ -26,18 +26,22 @@ public SyncStatus(final long startingBlock, final long currentBlock, final long this.highestBlock = highestBlock; } + @Override public long getStartingBlock() { return startingBlock; } + @Override public long getCurrentBlock() { return currentBlock; } + @Override public long getHighestBlock() { return highestBlock; } + @Override public boolean inSync() { return currentBlock == highestBlock; } diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/services/PantheonEventsImpl.java b/pantheon/src/main/java/tech/pegasys/pantheon/services/PantheonEventsImpl.java index db2a27f079..5e59b1a0ab 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/services/PantheonEventsImpl.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/services/PantheonEventsImpl.java @@ -12,8 +12,6 @@ */ package tech.pegasys.pantheon.services; -import tech.pegasys.pantheon.ethereum.core.Block; -import tech.pegasys.pantheon.ethereum.core.Transaction; import tech.pegasys.pantheon.ethereum.eth.sync.BlockBroadcaster; import tech.pegasys.pantheon.ethereum.eth.transactions.TransactionPool; import tech.pegasys.pantheon.plugin.services.PantheonEvents; @@ -29,39 +27,33 @@ public PantheonEventsImpl( } @Override - public Object addNewBlockPropagatedListener(final NewBlockPropagatedListener listener) { + public Object addBlockPropagatedListener(final BlockPropagatedListener listener) { return blockBroadcaster.subscribePropagateNewBlocks( - block -> dispatchNewBlockPropagatedMessage(block, listener)); + block -> listener.newBlockPropagated(block.getHeader())); } @Override - public void removeNewBlockPropagatedListener(final Object listenerIdentifier) { + public void removeBlockPropagatedListener(final Object listenerIdentifier) { if (listenerIdentifier instanceof Long) { blockBroadcaster.unsubscribePropagateNewBlocks((Long) listenerIdentifier); } } - private void dispatchNewBlockPropagatedMessage( - final Block block, final NewBlockPropagatedListener listener) { - listener.newBlockPropagated(block.getHeader()); - } - @Override - public Object addNewTransactionAddedListener(final NewTransactionAddedListener listener) { - return transactionPool.subscribePendingTransactions( - transaction -> dispatchTransactionAddedMessage(transaction, listener)); + public Object addTransactionAddedListener(final TransactionAddedListener listener) { + return transactionPool.subscribePendingTransactions(listener::transactionAdded); } @Override - public void removeNewTransactionAddedListener(final Object listenerIdentifier) { + public void removeTransactionAddedListener(final Object listenerIdentifier) { if (listenerIdentifier instanceof Long) { transactionPool.unsubscribePendingTransactions((Long) listenerIdentifier); } } @Override - public Object addNewTransactionDroppedListener( - final TransactionDroppedListener newTransactionDroppedListener) { + public Object addTransactionDroppedListener( + final TransactionDroppedListener transactionDroppedListener) { throw new UnsupportedOperationException(); } @@ -70,8 +62,20 @@ public void removeTransactionDroppedListener(final Object listenerIdentifier) { throw new UnsupportedOperationException(); } - private void dispatchTransactionAddedMessage( - final Transaction transaction, final NewTransactionAddedListener listener) { - listener.newTransactionAdded(transaction); + @Override + public Object addLogsListener(final LogsListener logsListener) { + return null; + } + + @Override + public void removeLogsListener(final Object listenerIdentifier) {} + + @Override + public Object addSynchronizerStatusListener( + final SynchronizerStatusListener synchronizerStatusListener) { + return null; } + + @Override + public void removeSynchronizerStatusListener(final Object listenerIdentifier) {} } diff --git a/pantheon/src/test/java/tech/pegasys/pantheon/plugins/TestPantheonEventsPlugin.java b/pantheon/src/test/java/tech/pegasys/pantheon/plugins/TestPantheonEventsPlugin.java index d2716fb456..f0c69faa90 100644 --- a/pantheon/src/test/java/tech/pegasys/pantheon/plugins/TestPantheonEventsPlugin.java +++ b/pantheon/src/test/java/tech/pegasys/pantheon/plugins/TestPantheonEventsPlugin.java @@ -50,7 +50,7 @@ public void start() { subscriptionId = context .getService(PantheonEvents.class) - .map(events -> events.addNewBlockPropagatedListener(this::onBlockAnnounce)); + .map(events -> events.addBlockPropagatedListener(this::onBlockAnnounce)); LOG.info("Listening with ID#" + subscriptionId); } @@ -60,7 +60,7 @@ public void stop() { id -> context .getService(PantheonEvents.class) - .ifPresent(pantheonEvents -> pantheonEvents.removeNewBlockPropagatedListener(id))); + .ifPresent(pantheonEvents -> pantheonEvents.removeBlockPropagatedListener(id))); LOG.info("No longer listening with ID#" + subscriptionId); } diff --git a/pantheon/src/test/java/tech/pegasys/pantheon/services/PantheonEventsImplTest.java b/pantheon/src/test/java/tech/pegasys/pantheon/services/PantheonEventsImplTest.java index 112eb1fe90..6cba8583a7 100644 --- a/pantheon/src/test/java/tech/pegasys/pantheon/services/PantheonEventsImplTest.java +++ b/pantheon/src/test/java/tech/pegasys/pantheon/services/PantheonEventsImplTest.java @@ -119,7 +119,7 @@ public void setUp() { @Test public void newBlockEventFiresAfterSubscribe() { final AtomicReference result = new AtomicReference<>(); - serviceImpl.addNewBlockPropagatedListener(result::set); + serviceImpl.addBlockPropagatedListener(result::set); assertThat(result.get()).isNull(); blockBroadcaster.propagate(generateBlock(), UInt256.of(1)); @@ -130,12 +130,12 @@ public void newBlockEventFiresAfterSubscribe() { @Test public void newBlockEventDoesNotFireAfterUnsubscribe() { final AtomicReference result = new AtomicReference<>(); - final Object id = serviceImpl.addNewBlockPropagatedListener(result::set); + final Object id = serviceImpl.addBlockPropagatedListener(result::set); assertThat(result.get()).isNull(); blockBroadcaster.propagate(generateBlock(), UInt256.of(1)); - serviceImpl.removeNewBlockPropagatedListener(id); + serviceImpl.removeBlockPropagatedListener(id); result.set(null); blockBroadcaster.propagate(generateBlock(), UInt256.of(1)); @@ -149,15 +149,15 @@ public void propagationWithoutSubscriptionsCompletes() { @Test public void newBlockEventUselessUnsubscribesCompletes() { - serviceImpl.removeNewBlockPropagatedListener("doesNotExist"); - serviceImpl.removeNewBlockPropagatedListener(5); - serviceImpl.removeNewBlockPropagatedListener(5L); + serviceImpl.removeBlockPropagatedListener("doesNotExist"); + serviceImpl.removeBlockPropagatedListener(5); + serviceImpl.removeBlockPropagatedListener(5L); } @Test public void newTransactionEventFiresAfterSubscribe() { final AtomicReference result = new AtomicReference<>(); - serviceImpl.addNewTransactionAddedListener(result::set); + serviceImpl.addTransactionAddedListener(result::set); assertThat(result.get()).isNull(); transactionPool.addLocalTransaction(TX1); @@ -168,12 +168,12 @@ public void newTransactionEventFiresAfterSubscribe() { @Test public void newTransactionEventDoesNotFireAfterUnsubscribe() { final AtomicReference result = new AtomicReference<>(); - final Object id = serviceImpl.addNewTransactionAddedListener(result::set); + final Object id = serviceImpl.addTransactionAddedListener(result::set); assertThat(result.get()).isNull(); transactionPool.addLocalTransaction(TX1); - serviceImpl.removeNewTransactionAddedListener(id); + serviceImpl.removeTransactionAddedListener(id); result.set(null); transactionPool.addLocalTransaction(TX2); @@ -182,9 +182,9 @@ public void newTransactionEventDoesNotFireAfterUnsubscribe() { @Test public void newTransactionEventUselessUnsubscribesCompletes() { - serviceImpl.removeNewTransactionAddedListener("doesNotExist"); - serviceImpl.removeNewTransactionAddedListener(5); - serviceImpl.removeNewTransactionAddedListener(5L); + serviceImpl.removeTransactionAddedListener("doesNotExist"); + serviceImpl.removeTransactionAddedListener(5); + serviceImpl.removeTransactionAddedListener(5L); } private Block generateBlock() { diff --git a/plugin-api/build.gradle b/plugin-api/build.gradle index 6c2bad3b13..567e0b1ecf 100644 --- a/plugin-api/build.gradle +++ b/plugin-api/build.gradle @@ -56,7 +56,7 @@ Calculated : ${currentHash} tasks.register('checkAPIChanges', FileStateChecker) { description = "Checks that the API for the Plugin-API project does not change without deliberate thought" files = sourceSets.main.allJava.files - knownHash = 'PBo0D4R6/1EYXEn+k0nmWHW4TkklUWQbQGNqgWzslfw=' + knownHash = 'KE03HxdYXU3W/pWOVwjUX22vk67OXokCYvlzoXykOqY=' } check.dependsOn('checkAPIChanges') diff --git a/plugin-api/src/main/java/tech/pegasys/pantheon/plugin/data/SyncStatus.java b/plugin-api/src/main/java/tech/pegasys/pantheon/plugin/data/SyncStatus.java new file mode 100644 index 0000000000..753972b325 --- /dev/null +++ b/plugin-api/src/main/java/tech/pegasys/pantheon/plugin/data/SyncStatus.java @@ -0,0 +1,47 @@ +/* + * Copyright 2019 ConsenSys AG. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package tech.pegasys.pantheon.plugin.data; + +import tech.pegasys.pantheon.plugin.Unstable; + +@Unstable +public interface SyncStatus { + + /** + * Get the height of the block at which this synchronization attempt began. + * + * @return height of the block at which this synchronization attempt began. + */ + long getStartingBlock(); + + /** + * Get the height of the last block the synchronizer received + * + * @return the height of the last block the synchronizer received + */ + long getCurrentBlock(); + + /** + * Get the height of the highest known block. + * + * @return the height of the highest known block. + */ + long getHighestBlock(); + + /** + * Checks if the synchronizer is within a default sync tolerance of the highest known block + * + * @return true if it is within the tolerance, false otherwise + */ + boolean inSync(); +} diff --git a/plugin-api/src/main/java/tech/pegasys/pantheon/plugin/services/PantheonEvents.java b/plugin-api/src/main/java/tech/pegasys/pantheon/plugin/services/PantheonEvents.java index 18a99fa343..786a2e16b5 100644 --- a/plugin-api/src/main/java/tech/pegasys/pantheon/plugin/services/PantheonEvents.java +++ b/plugin-api/src/main/java/tech/pegasys/pantheon/plugin/services/PantheonEvents.java @@ -14,18 +14,25 @@ import tech.pegasys.pantheon.plugin.Unstable; import tech.pegasys.pantheon.plugin.data.BlockHeader; +import tech.pegasys.pantheon.plugin.data.Log; +import tech.pegasys.pantheon.plugin.data.SyncStatus; import tech.pegasys.pantheon.plugin.data.Transaction; +import java.util.List; + /** * This service allows plugins to attach to various events during the normal operation of Pantheon. * *

Currently supported events * *

    - *
  • newBlockPropagated - Fired when a new block header has been received and validated - * and is about to be sent out to other peers, but before the body of the block has been - * evaluated and validated. - *
  • newTransactionAdded - Fired when a new transaction has been added to the node. + *
  • BlockPropagated - Fired when a new block header has been received and validated and + * is about to be sent out to other peers, but before the body of the block has been evaluated + * and validated. + *
  • TransactionAdded - Fired when a new transaction has been added to the node. + *
  • TransactionDropped - Fired when a new transaction has been dropped from the node. + *
  • Logs - Fired when a new block containing logs is received. + *
  • SynchronizerStatus - Fired when the status of the synchronizer changes. *
*/ @Unstable @@ -34,42 +41,42 @@ public interface PantheonEvents { /** * Add a listener watching new blocks propagated. * - * @param newBlockPropagatedListener The listener that will accept a BlockHeader as the event. + * @param blockPropagatedListener The listener that will accept a BlockHeader as the event. * @return an object to be used as an identifier when de-registering the event. */ - Object addNewBlockPropagatedListener(NewBlockPropagatedListener newBlockPropagatedListener); + Object addBlockPropagatedListener(BlockPropagatedListener blockPropagatedListener); /** * Remove the blockAdded listener from pantheon notifications. * * @param listenerIdentifier The instance that was returned from addBlockAddedListener; */ - void removeNewBlockPropagatedListener(Object listenerIdentifier); + void removeBlockPropagatedListener(Object listenerIdentifier); /** * Add a listener watching new transactions added to the node. * - * @param newTransactionAddedListener The listener that will accept the Transaction object as the + * @param transactionAddedListener The listener that will accept the Transaction object as the * event. * @return an object to be used as an identifier when de-registering the event. */ - Object addNewTransactionAddedListener(NewTransactionAddedListener newTransactionAddedListener); + Object addTransactionAddedListener(TransactionAddedListener transactionAddedListener); /** * Remove the blockAdded listener from pantheon notifications. * - * @param listenerIdentifier The instance that was returned from addNewTransactionAddedListener; + * @param listenerIdentifier The instance that was returned from addTransactionAddedListener; */ - void removeNewTransactionAddedListener(Object listenerIdentifier); + void removeTransactionAddedListener(Object listenerIdentifier); /** * Add a listener watching dropped transactions. * - * @param newTransactionDroppedListener The listener that will accept the Transaction object as - * the event. + * @param transactionDroppedListener The listener that will accept the Transaction object as the + * event. * @return an object to be used as an identifier when de-registering the event. */ - Object addNewTransactionDroppedListener(TransactionDroppedListener newTransactionDroppedListener); + Object addTransactionDroppedListener(TransactionDroppedListener transactionDroppedListener); /** * Remove the transactionDropped listener from pantheon notifications. @@ -78,8 +85,39 @@ public interface PantheonEvents { */ void removeTransactionDroppedListener(Object listenerIdentifier); + /** + * Add a listener watching logs included in new blocks. + * + * @param logsListener The listener that will accept the Logs object as the event. + * @return an object to be used as an identifier when de-registering the event. + */ + Object addLogsListener(LogsListener logsListener); + + /** + * Remove the logs listener from pantheon notifications. + * + * @param listenerIdentifier The instance that was returned from addTransactionDroppedListener; + */ + void removeLogsListener(Object listenerIdentifier); + + /** + * Add a listener watching the synchronizer status. + * + * @param synchronizerStatusListener The listener that will accept the SyncStatus object as the + * event. + * @return an object to be used as an identifier when de-registering the event. + */ + Object addSynchronizerStatusListener(SynchronizerStatusListener synchronizerStatusListener); + + /** + * Remove the logs listener from pantheon notifications. + * + * @param listenerIdentifier The instance that was returned from addTransactionDroppedListener; + */ + void removeSynchronizerStatusListener(Object listenerIdentifier); + /** The listener interface for receiving new block propagated events. */ - interface NewBlockPropagatedListener { + interface BlockPropagatedListener { /** * Invoked when a new block header has been received and validated and is about to be sent out @@ -88,20 +126,20 @@ interface NewBlockPropagatedListener { *

The block may not have been imported to the local chain yet and may fail later * validations. * - * @param newBlockHeader the new block header. + * @param blockHeader the new block header. */ - void newBlockPropagated(BlockHeader newBlockHeader); + void newBlockPropagated(BlockHeader blockHeader); } /** The listener interface for receiving new transaction added events. */ - interface NewTransactionAddedListener { + interface TransactionAddedListener { /** * Invoked when a new transaction has been added to the node. * * @param transaction the new transaction. */ - void newTransactionAdded(Transaction transaction); + void transactionAdded(Transaction transaction); } /** The listener interface for receiving transaction dropped events. */ @@ -112,6 +150,28 @@ interface TransactionDroppedListener { * * @param transaction the dropped transaction. */ - void newTransactionDropped(Transaction transaction); + void transactionDropped(Transaction transaction); + } + + /** The listener interface for receiving logs from new blocks. */ + interface LogsListener { + + /** + * Invoked when a new block is added. + * + * @param logs the new logs from the block added event + */ + void logsAdded(List logs); + } + + /** The listener interface for receiving sync status events. */ + interface SynchronizerStatusListener { + + /** + * Invoked when the synchronizer status changes + * + * @param syncStatus the sync status + */ + void synchronizerStatusChanged(SyncStatus syncStatus); } } From e1d9900060f8964c6ae0cffe33d46c1d1211e592 Mon Sep 17 00:00:00 2001 From: Ratan Rai Sur Date: Fri, 6 Sep 2019 11:48:25 +0300 Subject: [PATCH 02/22] add LogWithMetadata to API --- .../graphql/internal/LogWithMetadata.java | 15 +++-- .../internal/pojoadapter/LogAdapter.java | 2 +- plugin-api/build.gradle | 2 +- .../pantheon/plugin/data/LogWithMetadata.java | 63 +++++++++++++++++++ .../plugin/services/PantheonEvents.java | 4 +- 5 files changed, 78 insertions(+), 8 deletions(-) create mode 100644 plugin-api/src/main/java/tech/pegasys/pantheon/plugin/data/LogWithMetadata.java diff --git a/ethereum/graphql/src/main/java/tech/pegasys/pantheon/ethereum/graphql/internal/LogWithMetadata.java b/ethereum/graphql/src/main/java/tech/pegasys/pantheon/ethereum/graphql/internal/LogWithMetadata.java index 7ef808d1c7..4d4803b215 100644 --- a/ethereum/graphql/src/main/java/tech/pegasys/pantheon/ethereum/graphql/internal/LogWithMetadata.java +++ b/ethereum/graphql/src/main/java/tech/pegasys/pantheon/ethereum/graphql/internal/LogWithMetadata.java @@ -21,7 +21,7 @@ import com.google.common.base.MoreObjects; -public class LogWithMetadata { +public class LogWithMetadata implements tech.pegasys.pantheon.plugin.data.LogWithMetadata { private final int logIndex; private final long blockNumber; @@ -54,40 +54,47 @@ public class LogWithMetadata { this.removed = removed; } - // The index of this log within the entire ordered list of logs associated with the block this log - // belongs to. + @Override public int getLogIndex() { return logIndex; } + @Override public long getBlockNumber() { return blockNumber; } + @Override public Hash getBlockHash() { return blockHash; } + @Override public Hash getTransactionHash() { return transactionHash; } + @Override public int getTransactionIndex() { return transactionIndex; } - public Address getAddress() { + @Override + public Address getLogger() { return address; } + @Override public BytesValue getData() { return data; } + @Override public List getTopics() { return topics; } + @Override public boolean isRemoved() { return removed; } diff --git a/ethereum/graphql/src/main/java/tech/pegasys/pantheon/ethereum/graphql/internal/pojoadapter/LogAdapter.java b/ethereum/graphql/src/main/java/tech/pegasys/pantheon/ethereum/graphql/internal/pojoadapter/LogAdapter.java index 8775f99936..4102096d9f 100644 --- a/ethereum/graphql/src/main/java/tech/pegasys/pantheon/ethereum/graphql/internal/pojoadapter/LogAdapter.java +++ b/ethereum/graphql/src/main/java/tech/pegasys/pantheon/ethereum/graphql/internal/pojoadapter/LogAdapter.java @@ -68,6 +68,6 @@ public Optional getAccount(final DataFetchingEnvironment environ return query .getWorldState(blockNumber) - .map(ws -> new AccountAdapter(ws.get(logWithMetadata.getAddress()))); + .map(ws -> new AccountAdapter(ws.get(logWithMetadata.getLogger()))); } } diff --git a/plugin-api/build.gradle b/plugin-api/build.gradle index 567e0b1ecf..1e8ef83ae6 100644 --- a/plugin-api/build.gradle +++ b/plugin-api/build.gradle @@ -56,7 +56,7 @@ Calculated : ${currentHash} tasks.register('checkAPIChanges', FileStateChecker) { description = "Checks that the API for the Plugin-API project does not change without deliberate thought" files = sourceSets.main.allJava.files - knownHash = 'KE03HxdYXU3W/pWOVwjUX22vk67OXokCYvlzoXykOqY=' + knownHash = 'M75os+C4iBGdtQpqnxz4GDPs4sQmklYNmAElFq7pH9E=' } check.dependsOn('checkAPIChanges') diff --git a/plugin-api/src/main/java/tech/pegasys/pantheon/plugin/data/LogWithMetadata.java b/plugin-api/src/main/java/tech/pegasys/pantheon/plugin/data/LogWithMetadata.java new file mode 100644 index 0000000000..9a31559d20 --- /dev/null +++ b/plugin-api/src/main/java/tech/pegasys/pantheon/plugin/data/LogWithMetadata.java @@ -0,0 +1,63 @@ +/* + * Copyright 2019 ConsenSys AG. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package tech.pegasys.pantheon.plugin.data; + +import tech.pegasys.pantheon.plugin.Unstable; + +/** A Log entry from a transaction execution. */ +@Unstable +public interface LogWithMetadata extends Log { + + /** + * The index of this log within the entire ordered list of logs associated with the block this log + * belongs to. + * + * @return The block's number. + */ + int getLogIndex(); + + /** + * The number of the block to which the log belongs. + * + * @return The block's number. + */ + long getBlockNumber(); + + /** + * The hash of the block to which this block belongs. + * + * @return The block's hash. + */ + Hash getBlockHash(); + + /** + * The hash of the transaction that issued this log. + * + * @return The transaction's hash. + */ + Hash getTransactionHash(); + + /** + * The index in the block of the transaction that issued this log. + * + * @return An int representing the index. + */ + int getTransactionIndex(); + + /** + * Whether the log was removed. + * + * @return true when the log was removed, due to a chain reorganization. false if its a valid log. + */ + boolean isRemoved(); +} diff --git a/plugin-api/src/main/java/tech/pegasys/pantheon/plugin/services/PantheonEvents.java b/plugin-api/src/main/java/tech/pegasys/pantheon/plugin/services/PantheonEvents.java index 786a2e16b5..14d15c4470 100644 --- a/plugin-api/src/main/java/tech/pegasys/pantheon/plugin/services/PantheonEvents.java +++ b/plugin-api/src/main/java/tech/pegasys/pantheon/plugin/services/PantheonEvents.java @@ -14,7 +14,7 @@ import tech.pegasys.pantheon.plugin.Unstable; import tech.pegasys.pantheon.plugin.data.BlockHeader; -import tech.pegasys.pantheon.plugin.data.Log; +import tech.pegasys.pantheon.plugin.data.LogWithMetadata; import tech.pegasys.pantheon.plugin.data.SyncStatus; import tech.pegasys.pantheon.plugin.data.Transaction; @@ -161,7 +161,7 @@ interface LogsListener { * * @param logs the new logs from the block added event */ - void logsAdded(List logs); + void logsAdded(List logs); } /** The listener interface for receiving sync status events. */ From 3fdfa6c7fd78161eea94f124fbc4659b9e3c379b Mon Sep 17 00:00:00 2001 From: Ratan Rai Sur Date: Fri, 6 Sep 2019 12:17:05 +0300 Subject: [PATCH 03/22] type and naming changes to api --- .../pantheon/services/PantheonEventsImpl.java | 35 +++++++++---------- plugin-api/build.gradle | 2 +- .../plugin/services/PantheonEvents.java | 35 ++++++++++--------- 3 files changed, 35 insertions(+), 37 deletions(-) diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/services/PantheonEventsImpl.java b/pantheon/src/main/java/tech/pegasys/pantheon/services/PantheonEventsImpl.java index 5e59b1a0ab..eae2c76686 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/services/PantheonEventsImpl.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/services/PantheonEventsImpl.java @@ -27,55 +27,52 @@ public PantheonEventsImpl( } @Override - public Object addBlockPropagatedListener(final BlockPropagatedListener listener) { + public long addBlockPropagatedListener(final BlockPropagatedListener listener) { return blockBroadcaster.subscribePropagateNewBlocks( block -> listener.newBlockPropagated(block.getHeader())); } @Override - public void removeBlockPropagatedListener(final Object listenerIdentifier) { - if (listenerIdentifier instanceof Long) { - blockBroadcaster.unsubscribePropagateNewBlocks((Long) listenerIdentifier); - } + public void removeBlockPropagatedListener(final long listenerIdentifier) { + blockBroadcaster.unsubscribePropagateNewBlocks(listenerIdentifier); } @Override - public Object addTransactionAddedListener(final TransactionAddedListener listener) { - return transactionPool.subscribePendingTransactions(listener::transactionAdded); + public long addTransactionAddedListener(final TransactionAddedListener listener) { + return transactionPool.subscribePendingTransactions(listener::onTransactionAdded); } @Override - public void removeTransactionAddedListener(final Object listenerIdentifier) { - if (listenerIdentifier instanceof Long) { - transactionPool.unsubscribePendingTransactions((Long) listenerIdentifier); - } + public void removeTransactionAddedListener(final long listenerIdentifier) { + transactionPool.unsubscribePendingTransactions(listenerIdentifier); } @Override - public Object addTransactionDroppedListener( + public long addTransactionDroppedListener( final TransactionDroppedListener transactionDroppedListener) { - throw new UnsupportedOperationException(); + return transactionPool.subscribeDroppedTransactions( + transactionDroppedListener::onTransactionDropped); } @Override - public void removeTransactionDroppedListener(final Object listenerIdentifier) { - throw new UnsupportedOperationException(); + public void removeTransactionDroppedListener(final long listenerIdentifier) { + transactionPool.unsubscribeDroppedTransactions(listenerIdentifier); } @Override - public Object addLogsListener(final LogsListener logsListener) { + public long addLogWithMetadataListener(final LogWithMetadataListener logWithMetaDataListener) { return null; } @Override - public void removeLogsListener(final Object listenerIdentifier) {} + public void removeLogWithMetadataListener(final long listenerIdentifier) {} @Override - public Object addSynchronizerStatusListener( + public long addSynchronizerStatusListener( final SynchronizerStatusListener synchronizerStatusListener) { return null; } @Override - public void removeSynchronizerStatusListener(final Object listenerIdentifier) {} + public void removeSynchronizerStatusListener(final long listenerIdentifier) {} } diff --git a/plugin-api/build.gradle b/plugin-api/build.gradle index 1e8ef83ae6..1f1bce9ee8 100644 --- a/plugin-api/build.gradle +++ b/plugin-api/build.gradle @@ -56,7 +56,7 @@ Calculated : ${currentHash} tasks.register('checkAPIChanges', FileStateChecker) { description = "Checks that the API for the Plugin-API project does not change without deliberate thought" files = sourceSets.main.allJava.files - knownHash = 'M75os+C4iBGdtQpqnxz4GDPs4sQmklYNmAElFq7pH9E=' + knownHash = 'iafQAh/5R4PIyKFfVeQ9+3T12Ql2GLm8ZUYsZ9gUCTc=' } check.dependsOn('checkAPIChanges') diff --git a/plugin-api/src/main/java/tech/pegasys/pantheon/plugin/services/PantheonEvents.java b/plugin-api/src/main/java/tech/pegasys/pantheon/plugin/services/PantheonEvents.java index 14d15c4470..c6ab46d5b1 100644 --- a/plugin-api/src/main/java/tech/pegasys/pantheon/plugin/services/PantheonEvents.java +++ b/plugin-api/src/main/java/tech/pegasys/pantheon/plugin/services/PantheonEvents.java @@ -44,14 +44,14 @@ public interface PantheonEvents { * @param blockPropagatedListener The listener that will accept a BlockHeader as the event. * @return an object to be used as an identifier when de-registering the event. */ - Object addBlockPropagatedListener(BlockPropagatedListener blockPropagatedListener); + long addBlockPropagatedListener(BlockPropagatedListener blockPropagatedListener); /** * Remove the blockAdded listener from pantheon notifications. * * @param listenerIdentifier The instance that was returned from addBlockAddedListener; */ - void removeBlockPropagatedListener(Object listenerIdentifier); + void removeBlockPropagatedListener(long listenerIdentifier); /** * Add a listener watching new transactions added to the node. @@ -60,14 +60,14 @@ public interface PantheonEvents { * event. * @return an object to be used as an identifier when de-registering the event. */ - Object addTransactionAddedListener(TransactionAddedListener transactionAddedListener); + long addTransactionAddedListener(TransactionAddedListener transactionAddedListener); /** * Remove the blockAdded listener from pantheon notifications. * * @param listenerIdentifier The instance that was returned from addTransactionAddedListener; */ - void removeTransactionAddedListener(Object listenerIdentifier); + void removeTransactionAddedListener(long listenerIdentifier); /** * Add a listener watching dropped transactions. @@ -76,29 +76,30 @@ public interface PantheonEvents { * event. * @return an object to be used as an identifier when de-registering the event. */ - Object addTransactionDroppedListener(TransactionDroppedListener transactionDroppedListener); + long addTransactionDroppedListener(TransactionDroppedListener transactionDroppedListener); /** * Remove the transactionDropped listener from pantheon notifications. * * @param listenerIdentifier The instance that was returned from addTransactionDroppedListener; */ - void removeTransactionDroppedListener(Object listenerIdentifier); + void removeTransactionDroppedListener(long listenerIdentifier); /** - * Add a listener watching logs included in new blocks. + * Add a listener watching logs (plus metadata about them) included in new blocks. * - * @param logsListener The listener that will accept the Logs object as the event. + * @param logWithMetadataListener The listener that will accept the LogWithMetadata object as the + * event. * @return an object to be used as an identifier when de-registering the event. */ - Object addLogsListener(LogsListener logsListener); + long addLogWithMetadataListener(LogWithMetadataListener logWithMetadataListener); /** * Remove the logs listener from pantheon notifications. * * @param listenerIdentifier The instance that was returned from addTransactionDroppedListener; */ - void removeLogsListener(Object listenerIdentifier); + void removeLogWithMetadataListener(long listenerIdentifier); /** * Add a listener watching the synchronizer status. @@ -107,14 +108,14 @@ public interface PantheonEvents { * event. * @return an object to be used as an identifier when de-registering the event. */ - Object addSynchronizerStatusListener(SynchronizerStatusListener synchronizerStatusListener); + long addSynchronizerStatusListener(SynchronizerStatusListener synchronizerStatusListener); /** * Remove the logs listener from pantheon notifications. * * @param listenerIdentifier The instance that was returned from addTransactionDroppedListener; */ - void removeSynchronizerStatusListener(Object listenerIdentifier); + void removeSynchronizerStatusListener(long listenerIdentifier); /** The listener interface for receiving new block propagated events. */ interface BlockPropagatedListener { @@ -139,7 +140,7 @@ interface TransactionAddedListener { * * @param transaction the new transaction. */ - void transactionAdded(Transaction transaction); + void onTransactionAdded(Transaction transaction); } /** The listener interface for receiving transaction dropped events. */ @@ -150,18 +151,18 @@ interface TransactionDroppedListener { * * @param transaction the dropped transaction. */ - void transactionDropped(Transaction transaction); + void onTransactionDropped(Transaction transaction); } /** The listener interface for receiving logs from new blocks. */ - interface LogsListener { + interface LogWithMetadataListener { /** * Invoked when a new block is added. * * @param logs the new logs from the block added event */ - void logsAdded(List logs); + void onLogWithMetadatasAdded(List logs); } /** The listener interface for receiving sync status events. */ @@ -172,6 +173,6 @@ interface SynchronizerStatusListener { * * @param syncStatus the sync status */ - void synchronizerStatusChanged(SyncStatus syncStatus); + void onSynchronizerStatusChanged(SyncStatus syncStatus); } } From b6df067296067e1fef8b69e86008252a7f2910df Mon Sep 17 00:00:00 2001 From: Ratan Rai Sur Date: Fri, 6 Sep 2019 21:23:40 +0300 Subject: [PATCH 04/22] sync related changes --- .../dsl/node/ThreadPantheonNodeRunner.java | 3 ++- .../pantheon/ethereum/core/Synchronizer.java | 10 ++++------ .../ethereum/eth/sync/DefaultSynchronizer.java | 9 +++++---- .../ethereum/eth/sync/state/SyncState.java | 8 ++++---- .../ethereum/graphql/GraphQLDataFetchers.java | 2 +- .../internal/pojoadapter/SyncStateAdapter.java | 2 +- .../ethereum/jsonrpc/health/ReadinessCheck.java | 2 +- .../jsonrpc/internal/results/SyncingResult.java | 2 +- .../syncing/SyncingSubscriptionService.java | 2 +- .../SyncStatusNodePermissioningProvider.java | 2 +- .../pegasys/pantheon/cli/PantheonCommand.java | 3 ++- .../pantheon/services/PantheonEventsImpl.java | 15 +++++++++++---- .../pantheon/services/PantheonEventsImplTest.java | 2 +- plugin-api/build.gradle | 2 +- 14 files changed, 36 insertions(+), 28 deletions(-) diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/ThreadPantheonNodeRunner.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/ThreadPantheonNodeRunner.java index 8bb574c720..c0e84c390c 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/ThreadPantheonNodeRunner.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/ThreadPantheonNodeRunner.java @@ -137,7 +137,8 @@ public void startNode(final PantheonNode node) { PantheonEvents.class, new PantheonEventsImpl( pantheonController.getProtocolManager().getBlockBroadcaster(), - pantheonController.getTransactionPool())); + pantheonController.getTransactionPool(), + synchronizer)); pantheonPluginContext.startPlugins(); final Runner runner = diff --git a/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/core/Synchronizer.java b/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/core/Synchronizer.java index 408674be8b..32b61298cd 100644 --- a/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/core/Synchronizer.java +++ b/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/core/Synchronizer.java @@ -12,6 +12,9 @@ */ package tech.pegasys.pantheon.ethereum.core; +import tech.pegasys.pantheon.plugin.data.SyncStatus; +import tech.pegasys.pantheon.plugin.services.PantheonEvents; + import java.util.Optional; /** Provides an interface to block synchronization processes. */ @@ -27,12 +30,7 @@ public interface Synchronizer { */ Optional getSyncStatus(); - long observeSyncStatus(final SyncStatusListener listener); + long observeSyncStatus(final PantheonEvents.SynchronizerStatusListener listener); boolean removeObserver(long observerId); - - @FunctionalInterface - interface SyncStatusListener { - void onSyncStatus(final SyncStatus status); - } } diff --git a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/DefaultSynchronizer.java b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/DefaultSynchronizer.java index 528705a4fa..40554cd1b1 100644 --- a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/DefaultSynchronizer.java +++ b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/DefaultSynchronizer.java @@ -15,7 +15,6 @@ import static com.google.common.base.Preconditions.checkNotNull; import tech.pegasys.pantheon.ethereum.ProtocolContext; -import tech.pegasys.pantheon.ethereum.core.SyncStatus; import tech.pegasys.pantheon.ethereum.core.Synchronizer; import tech.pegasys.pantheon.ethereum.eth.manager.EthContext; import tech.pegasys.pantheon.ethereum.eth.sync.fastsync.FastDownloaderFactory; @@ -29,7 +28,9 @@ import tech.pegasys.pantheon.ethereum.worldstate.Pruner; import tech.pegasys.pantheon.ethereum.worldstate.WorldStateStorage; import tech.pegasys.pantheon.metrics.PantheonMetricCategory; +import tech.pegasys.pantheon.plugin.data.SyncStatus; import tech.pegasys.pantheon.plugin.services.MetricsSystem; +import tech.pegasys.pantheon.plugin.services.PantheonEvents.SynchronizerStatusListener; import tech.pegasys.pantheon.util.ExceptionUtils; import tech.pegasys.pantheon.util.Subscribers; @@ -48,7 +49,7 @@ public class DefaultSynchronizer implements Synchronizer { private final Optional maybePruner; private final SyncState syncState; private final AtomicBoolean running = new AtomicBoolean(false); - private final Subscribers syncStatusListeners = Subscribers.create(); + private final Subscribers syncStatusListeners = Subscribers.create(); private final BlockPropagationManager blockPropagationManager; private final Optional> fastSyncDownloader; private final FullSyncDownloader fullSyncDownloader; @@ -183,7 +184,7 @@ public Optional getSyncStatus() { } @Override - public long observeSyncStatus(final SyncStatusListener listener) { + public long observeSyncStatus(final SynchronizerStatusListener listener) { checkNotNull(listener); return syncStatusListeners.subscribe(listener); } @@ -194,6 +195,6 @@ public boolean removeObserver(final long observerId) { } private void syncStatusCallback(final SyncStatus status) { - syncStatusListeners.forEach(c -> c.onSyncStatus(status)); + syncStatusListeners.forEach(c -> c.onSynchronizerStatusChanged(status)); } } diff --git a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/state/SyncState.java b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/state/SyncState.java index 257a83803c..8d5ca39a1f 100644 --- a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/state/SyncState.java +++ b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/state/SyncState.java @@ -16,10 +16,10 @@ import tech.pegasys.pantheon.ethereum.chain.ChainHead; import tech.pegasys.pantheon.ethereum.core.BlockHeader; import tech.pegasys.pantheon.ethereum.core.SyncStatus; -import tech.pegasys.pantheon.ethereum.core.Synchronizer.SyncStatusListener; import tech.pegasys.pantheon.ethereum.eth.manager.EthPeer; import tech.pegasys.pantheon.ethereum.eth.manager.EthPeers; import tech.pegasys.pantheon.ethereum.p2p.rlpx.wire.messages.DisconnectMessage.DisconnectReason; +import tech.pegasys.pantheon.plugin.services.PantheonEvents.SynchronizerStatusListener; import tech.pegasys.pantheon.util.Subscribers; import java.util.Optional; @@ -32,7 +32,7 @@ public class SyncState { private final long startingBlock; private boolean lastInSync = true; private final Subscribers inSyncListeners = Subscribers.create(); - private final Subscribers syncStatusListeners = Subscribers.create(); + private final Subscribers syncStatusListeners = Subscribers.create(); private Optional syncTarget = Optional.empty(); private long chainHeightListenerId; @@ -51,14 +51,14 @@ public SyncState(final Blockchain blockchain, final EthPeers ethPeers) { private void publishSyncStatus() { final SyncStatus syncStatus = syncStatus(); - syncStatusListeners.forEach(c -> c.onSyncStatus(syncStatus)); + syncStatusListeners.forEach(c -> c.onSynchronizerStatusChanged(syncStatus)); } public void addInSyncListener(final InSyncListener observer) { inSyncListeners.subscribe(observer); } - public void addSyncStatusListener(final SyncStatusListener observer) { + public void addSyncStatusListener(final SynchronizerStatusListener observer) { syncStatusListeners.subscribe(observer); } diff --git a/ethereum/graphql/src/main/java/tech/pegasys/pantheon/ethereum/graphql/GraphQLDataFetchers.java b/ethereum/graphql/src/main/java/tech/pegasys/pantheon/ethereum/graphql/GraphQLDataFetchers.java index f85953ec35..f5bdae7ded 100644 --- a/ethereum/graphql/src/main/java/tech/pegasys/pantheon/ethereum/graphql/GraphQLDataFetchers.java +++ b/ethereum/graphql/src/main/java/tech/pegasys/pantheon/ethereum/graphql/GraphQLDataFetchers.java @@ -18,7 +18,6 @@ import tech.pegasys.pantheon.ethereum.core.Account; import tech.pegasys.pantheon.ethereum.core.Address; import tech.pegasys.pantheon.ethereum.core.Hash; -import tech.pegasys.pantheon.ethereum.core.SyncStatus; import tech.pegasys.pantheon.ethereum.core.Synchronizer; import tech.pegasys.pantheon.ethereum.core.Transaction; import tech.pegasys.pantheon.ethereum.core.WorldState; @@ -38,6 +37,7 @@ import tech.pegasys.pantheon.ethereum.p2p.rlpx.wire.Capability; import tech.pegasys.pantheon.ethereum.rlp.RLP; import tech.pegasys.pantheon.ethereum.rlp.RLPException; +import tech.pegasys.pantheon.plugin.data.SyncStatus; import tech.pegasys.pantheon.util.bytes.Bytes32; import tech.pegasys.pantheon.util.bytes.BytesValue; import tech.pegasys.pantheon.util.uint.UInt256; diff --git a/ethereum/graphql/src/main/java/tech/pegasys/pantheon/ethereum/graphql/internal/pojoadapter/SyncStateAdapter.java b/ethereum/graphql/src/main/java/tech/pegasys/pantheon/ethereum/graphql/internal/pojoadapter/SyncStateAdapter.java index 9aa1505d13..97d7df27b7 100644 --- a/ethereum/graphql/src/main/java/tech/pegasys/pantheon/ethereum/graphql/internal/pojoadapter/SyncStateAdapter.java +++ b/ethereum/graphql/src/main/java/tech/pegasys/pantheon/ethereum/graphql/internal/pojoadapter/SyncStateAdapter.java @@ -12,7 +12,7 @@ */ package tech.pegasys.pantheon.ethereum.graphql.internal.pojoadapter; -import tech.pegasys.pantheon.ethereum.core.SyncStatus; +import tech.pegasys.pantheon.plugin.data.SyncStatus; import java.util.Optional; diff --git a/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/health/ReadinessCheck.java b/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/health/ReadinessCheck.java index 70645f0875..d623d6390f 100644 --- a/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/health/ReadinessCheck.java +++ b/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/health/ReadinessCheck.java @@ -12,11 +12,11 @@ */ package tech.pegasys.pantheon.ethereum.jsonrpc.health; -import tech.pegasys.pantheon.ethereum.core.SyncStatus; import tech.pegasys.pantheon.ethereum.core.Synchronizer; import tech.pegasys.pantheon.ethereum.jsonrpc.health.HealthService.HealthCheck; import tech.pegasys.pantheon.ethereum.jsonrpc.health.HealthService.ParamSource; import tech.pegasys.pantheon.ethereum.p2p.network.P2PNetwork; +import tech.pegasys.pantheon.plugin.data.SyncStatus; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; diff --git a/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/results/SyncingResult.java b/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/results/SyncingResult.java index 7887d527c8..35ead9a3da 100644 --- a/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/results/SyncingResult.java +++ b/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/results/SyncingResult.java @@ -12,7 +12,7 @@ */ package tech.pegasys.pantheon.ethereum.jsonrpc.internal.results; -import tech.pegasys.pantheon.ethereum.core.SyncStatus; +import tech.pegasys.pantheon.plugin.data.SyncStatus; import java.util.Objects; diff --git a/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/websocket/subscription/syncing/SyncingSubscriptionService.java b/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/websocket/subscription/syncing/SyncingSubscriptionService.java index 64382f243e..c90ac19504 100644 --- a/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/websocket/subscription/syncing/SyncingSubscriptionService.java +++ b/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/websocket/subscription/syncing/SyncingSubscriptionService.java @@ -12,12 +12,12 @@ */ package tech.pegasys.pantheon.ethereum.jsonrpc.websocket.subscription.syncing; -import tech.pegasys.pantheon.ethereum.core.SyncStatus; import tech.pegasys.pantheon.ethereum.core.Synchronizer; import tech.pegasys.pantheon.ethereum.jsonrpc.internal.results.SyncingResult; import tech.pegasys.pantheon.ethereum.jsonrpc.websocket.subscription.Subscription; import tech.pegasys.pantheon.ethereum.jsonrpc.websocket.subscription.SubscriptionManager; import tech.pegasys.pantheon.ethereum.jsonrpc.websocket.subscription.request.SubscriptionType; +import tech.pegasys.pantheon.plugin.data.SyncStatus; public class SyncingSubscriptionService { diff --git a/ethereum/permissioning/src/main/java/tech/pegasys/pantheon/ethereum/permissioning/node/provider/SyncStatusNodePermissioningProvider.java b/ethereum/permissioning/src/main/java/tech/pegasys/pantheon/ethereum/permissioning/node/provider/SyncStatusNodePermissioningProvider.java index 9493c132fb..e531d0bfc0 100644 --- a/ethereum/permissioning/src/main/java/tech/pegasys/pantheon/ethereum/permissioning/node/provider/SyncStatusNodePermissioningProvider.java +++ b/ethereum/permissioning/src/main/java/tech/pegasys/pantheon/ethereum/permissioning/node/provider/SyncStatusNodePermissioningProvider.java @@ -14,11 +14,11 @@ import static com.google.common.base.Preconditions.checkNotNull; -import tech.pegasys.pantheon.ethereum.core.SyncStatus; import tech.pegasys.pantheon.ethereum.core.Synchronizer; import tech.pegasys.pantheon.ethereum.p2p.peers.EnodeURL; import tech.pegasys.pantheon.ethereum.permissioning.node.NodePermissioningProvider; import tech.pegasys.pantheon.metrics.PantheonMetricCategory; +import tech.pegasys.pantheon.plugin.data.SyncStatus; import tech.pegasys.pantheon.plugin.services.MetricsSystem; import tech.pegasys.pantheon.plugin.services.metrics.Counter; diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java b/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java index 7071a8f127..998a5771c7 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java @@ -823,7 +823,8 @@ private PantheonCommand startPlugins() { PantheonEvents.class, new PantheonEventsImpl( (pantheonController.getProtocolManager().getBlockBroadcaster()), - pantheonController.getTransactionPool())); + pantheonController.getTransactionPool(), + pantheonController.getSynchronizer())); pantheonPluginContext.startPlugins(); return this; } diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/services/PantheonEventsImpl.java b/pantheon/src/main/java/tech/pegasys/pantheon/services/PantheonEventsImpl.java index eae2c76686..4b4c8efb4f 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/services/PantheonEventsImpl.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/services/PantheonEventsImpl.java @@ -12,6 +12,7 @@ */ package tech.pegasys.pantheon.services; +import tech.pegasys.pantheon.ethereum.core.Synchronizer; import tech.pegasys.pantheon.ethereum.eth.sync.BlockBroadcaster; import tech.pegasys.pantheon.ethereum.eth.transactions.TransactionPool; import tech.pegasys.pantheon.plugin.services.PantheonEvents; @@ -19,11 +20,15 @@ public class PantheonEventsImpl implements PantheonEvents { private final BlockBroadcaster blockBroadcaster; private final TransactionPool transactionPool; + private final Synchronizer synchronizer; public PantheonEventsImpl( - final BlockBroadcaster blockBroadcaster, final TransactionPool transactionPool) { + final BlockBroadcaster blockBroadcaster, + final TransactionPool transactionPool, + final Synchronizer synchronizer) { this.blockBroadcaster = blockBroadcaster; this.transactionPool = transactionPool; + this.synchronizer = synchronizer; } @Override @@ -61,7 +66,7 @@ public void removeTransactionDroppedListener(final long listenerIdentifier) { @Override public long addLogWithMetadataListener(final LogWithMetadataListener logWithMetaDataListener) { - return null; + return 0; } @Override @@ -70,9 +75,11 @@ public void removeLogWithMetadataListener(final long listenerIdentifier) {} @Override public long addSynchronizerStatusListener( final SynchronizerStatusListener synchronizerStatusListener) { - return null; + return synchronizer.observeSyncStatus(synchronizerStatusListener); } @Override - public void removeSynchronizerStatusListener(final long listenerIdentifier) {} + public void removeSynchronizerStatusListener(final long listenerIdentifier) { + synchronizer.removeObserver(listenerIdentifier); + } } diff --git a/pantheon/src/test/java/tech/pegasys/pantheon/services/PantheonEventsImplTest.java b/pantheon/src/test/java/tech/pegasys/pantheon/services/PantheonEventsImplTest.java index 6cba8583a7..377bb75ef0 100644 --- a/pantheon/src/test/java/tech/pegasys/pantheon/services/PantheonEventsImplTest.java +++ b/pantheon/src/test/java/tech/pegasys/pantheon/services/PantheonEventsImplTest.java @@ -113,7 +113,7 @@ public void setUp() { Wei.ZERO, TransactionPoolConfiguration.builder().build()); - serviceImpl = new PantheonEventsImpl(blockBroadcaster, transactionPool); + serviceImpl = new PantheonEventsImpl(blockBroadcaster, transactionPool, synchronizer); } @Test diff --git a/plugin-api/build.gradle b/plugin-api/build.gradle index 1f1bce9ee8..185d82c519 100644 --- a/plugin-api/build.gradle +++ b/plugin-api/build.gradle @@ -56,7 +56,7 @@ Calculated : ${currentHash} tasks.register('checkAPIChanges', FileStateChecker) { description = "Checks that the API for the Plugin-API project does not change without deliberate thought" files = sourceSets.main.allJava.files - knownHash = 'iafQAh/5R4PIyKFfVeQ9+3T12Ql2GLm8ZUYsZ9gUCTc=' + knownHash = '4HGcEmt5tf7fhGd4n3erv5oo6eVfA+wpi93pV5G3njo=' } check.dependsOn('checkAPIChanges') From d23607c82d1da332766c8537f46d18782febfa97 Mon Sep 17 00:00:00 2001 From: Ratan Rai Sur Date: Mon, 9 Sep 2019 14:35:57 +0300 Subject: [PATCH 05/22] cosmetic --- .../pantheon/ethereum/eth/sync/DefaultSynchronizer.java | 5 +++-- .../pantheon/ethereum/eth/sync/state/SyncState.java | 8 ++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/DefaultSynchronizer.java b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/DefaultSynchronizer.java index 40554cd1b1..08fd5b650e 100644 --- a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/DefaultSynchronizer.java +++ b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/DefaultSynchronizer.java @@ -177,10 +177,11 @@ public Optional getSyncStatus() { if (!running.get()) { return Optional.empty(); } - if (syncState.syncStatus().getCurrentBlock() == syncState.syncStatus().getHighestBlock()) { + final SyncStatus syncStatus = syncState.syncStatus(); + if (syncStatus.inSync()) { return Optional.empty(); } - return Optional.of(syncState.syncStatus()); + return Optional.of(syncStatus); } @Override diff --git a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/state/SyncState.java b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/state/SyncState.java index 8d5ca39a1f..b057d96ca6 100644 --- a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/state/SyncState.java +++ b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/state/SyncState.java @@ -141,10 +141,10 @@ public long bestChainHeight(final long localChainHeight) { } private synchronized void checkInSync() { - final boolean currentSyncStatus = isInSync(); - if (lastInSync != currentSyncStatus) { - lastInSync = currentSyncStatus; - inSyncListeners.forEach(c -> c.onSyncStatusChanged(currentSyncStatus)); + final boolean currentInSync = isInSync(); + if (lastInSync != currentInSync) { + lastInSync = currentInSync; + inSyncListeners.forEach(c -> c.onSyncStatusChanged(currentInSync)); } } From 5f8703652f2c8772361fb6cbbae4496ec1ec7623 Mon Sep 17 00:00:00 2001 From: Ratan Rai Sur Date: Mon, 9 Sep 2019 14:53:20 +0300 Subject: [PATCH 06/22] change from Object to Long in test --- .../pegasys/pantheon/plugins/TestPantheonEventsPlugin.java | 3 ++- .../pegasys/pantheon/services/PantheonEventsImplTest.java | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/pantheon/src/test/java/tech/pegasys/pantheon/plugins/TestPantheonEventsPlugin.java b/pantheon/src/test/java/tech/pegasys/pantheon/plugins/TestPantheonEventsPlugin.java index f0c69faa90..afb1da2f00 100644 --- a/pantheon/src/test/java/tech/pegasys/pantheon/plugins/TestPantheonEventsPlugin.java +++ b/pantheon/src/test/java/tech/pegasys/pantheon/plugins/TestPantheonEventsPlugin.java @@ -22,6 +22,7 @@ import java.nio.file.Files; import java.util.Collections; import java.util.Optional; +import java.util.OptionalLong; import java.util.concurrent.atomic.AtomicInteger; import com.google.auto.service.AutoService; @@ -34,7 +35,7 @@ public class TestPantheonEventsPlugin implements PantheonPlugin { private PantheonContext context; - private Optional subscriptionId; + private Optional subscriptionId; private final AtomicInteger blockCounter = new AtomicInteger(); private File callbackDir; diff --git a/pantheon/src/test/java/tech/pegasys/pantheon/services/PantheonEventsImplTest.java b/pantheon/src/test/java/tech/pegasys/pantheon/services/PantheonEventsImplTest.java index 377bb75ef0..5be2fbf69f 100644 --- a/pantheon/src/test/java/tech/pegasys/pantheon/services/PantheonEventsImplTest.java +++ b/pantheon/src/test/java/tech/pegasys/pantheon/services/PantheonEventsImplTest.java @@ -130,7 +130,7 @@ public void newBlockEventFiresAfterSubscribe() { @Test public void newBlockEventDoesNotFireAfterUnsubscribe() { final AtomicReference result = new AtomicReference<>(); - final Object id = serviceImpl.addBlockPropagatedListener(result::set); + final long id = serviceImpl.addBlockPropagatedListener(result::set); assertThat(result.get()).isNull(); blockBroadcaster.propagate(generateBlock(), UInt256.of(1)); @@ -168,7 +168,7 @@ public void newTransactionEventFiresAfterSubscribe() { @Test public void newTransactionEventDoesNotFireAfterUnsubscribe() { final AtomicReference result = new AtomicReference<>(); - final Object id = serviceImpl.addTransactionAddedListener(result::set); + final long id = serviceImpl.addTransactionAddedListener(result::set); assertThat(result.get()).isNull(); transactionPool.addLocalTransaction(TX1); From 2dff648ed5ab323e77c4f3d2286d5704153fb728 Mon Sep 17 00:00:00 2001 From: Ratan Rai Sur Date: Mon, 9 Sep 2019 14:54:16 +0300 Subject: [PATCH 07/22] remove test conditions from Object listeners --- .../tech/pegasys/pantheon/services/PantheonEventsImplTest.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/pantheon/src/test/java/tech/pegasys/pantheon/services/PantheonEventsImplTest.java b/pantheon/src/test/java/tech/pegasys/pantheon/services/PantheonEventsImplTest.java index 5be2fbf69f..8f6e921dc6 100644 --- a/pantheon/src/test/java/tech/pegasys/pantheon/services/PantheonEventsImplTest.java +++ b/pantheon/src/test/java/tech/pegasys/pantheon/services/PantheonEventsImplTest.java @@ -149,7 +149,6 @@ public void propagationWithoutSubscriptionsCompletes() { @Test public void newBlockEventUselessUnsubscribesCompletes() { - serviceImpl.removeBlockPropagatedListener("doesNotExist"); serviceImpl.removeBlockPropagatedListener(5); serviceImpl.removeBlockPropagatedListener(5L); } @@ -182,7 +181,6 @@ public void newTransactionEventDoesNotFireAfterUnsubscribe() { @Test public void newTransactionEventUselessUnsubscribesCompletes() { - serviceImpl.removeTransactionAddedListener("doesNotExist"); serviceImpl.removeTransactionAddedListener(5); serviceImpl.removeTransactionAddedListener(5L); } From 2ca5f37225896fd24733779319e9de14e2f04f68 Mon Sep 17 00:00:00 2001 From: Ratan Rai Sur Date: Mon, 9 Sep 2019 16:57:43 +0300 Subject: [PATCH 08/22] implement listener directly on sync state + tests --- .../dsl/node/ThreadPantheonNodeRunner.java | 2 +- .../ethereum/eth/sync/state/SyncState.java | 10 ++++--- .../pegasys/pantheon/cli/PantheonCommand.java | 2 +- .../controller/PantheonController.java | 14 +++++++--- .../controller/PantheonControllerBuilder.java | 7 ++--- .../pantheon/services/PantheonEventsImpl.java | 12 ++++----- .../plugins/TestPantheonEventsPlugin.java | 1 - .../services/PantheonEventsImplTest.java | 27 ++++++++++++++++--- 8 files changed, 54 insertions(+), 21 deletions(-) diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/ThreadPantheonNodeRunner.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/ThreadPantheonNodeRunner.java index c0e84c390c..0f36207bae 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/ThreadPantheonNodeRunner.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/ThreadPantheonNodeRunner.java @@ -138,7 +138,7 @@ public void startNode(final PantheonNode node) { new PantheonEventsImpl( pantheonController.getProtocolManager().getBlockBroadcaster(), pantheonController.getTransactionPool(), - synchronizer)); + pantheonController.getSyncState())); pantheonPluginContext.startPlugins(); final Runner runner = diff --git a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/state/SyncState.java b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/state/SyncState.java index b057d96ca6..e1077f3423 100644 --- a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/state/SyncState.java +++ b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/state/SyncState.java @@ -49,7 +49,7 @@ public SyncState(final Blockchain blockchain, final EthPeers ethPeers) { }); } - private void publishSyncStatus() { + public void publishSyncStatus() { final SyncStatus syncStatus = syncStatus(); syncStatusListeners.forEach(c -> c.onSynchronizerStatusChanged(syncStatus)); } @@ -58,8 +58,12 @@ public void addInSyncListener(final InSyncListener observer) { inSyncListeners.subscribe(observer); } - public void addSyncStatusListener(final SynchronizerStatusListener observer) { - syncStatusListeners.subscribe(observer); + public long addSyncStatusListener(final SynchronizerStatusListener observer) { + return syncStatusListeners.subscribe(observer); + } + + public void removeSyncStatusListener(final long listenerId) { + syncStatusListeners.unsubscribe(listenerId); } public SyncStatus syncStatus() { diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java b/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java index 998a5771c7..eb0893d167 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java @@ -824,7 +824,7 @@ private PantheonCommand startPlugins() { new PantheonEventsImpl( (pantheonController.getProtocolManager().getBlockBroadcaster()), pantheonController.getTransactionPool(), - pantheonController.getSynchronizer())); + pantheonController.getSyncState())); pantheonPluginContext.startPlugins(); return this; } diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/controller/PantheonController.java b/pantheon/src/main/java/tech/pegasys/pantheon/controller/PantheonController.java index 0b75529f32..84cacc53a7 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/controller/PantheonController.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/controller/PantheonController.java @@ -21,6 +21,7 @@ import tech.pegasys.pantheon.ethereum.core.PrivacyParameters; import tech.pegasys.pantheon.ethereum.core.Synchronizer; import tech.pegasys.pantheon.ethereum.eth.manager.EthProtocolManager; +import tech.pegasys.pantheon.ethereum.eth.sync.state.SyncState; import tech.pegasys.pantheon.ethereum.eth.transactions.TransactionPool; import tech.pegasys.pantheon.ethereum.jsonrpc.RpcApi; import tech.pegasys.pantheon.ethereum.jsonrpc.internal.methods.JsonRpcMethod; @@ -48,6 +49,7 @@ public class PantheonController implements java.io.Closeable { private final MiningCoordinator miningCoordinator; private final PrivacyParameters privacyParameters; private final Runnable close; + private final SyncState syncState; PantheonController( final ProtocolSchedule protocolSchedule, @@ -56,18 +58,20 @@ public class PantheonController implements java.io.Closeable { final GenesisConfigOptions genesisConfigOptions, final SubProtocolConfiguration subProtocolConfiguration, final Synchronizer synchronizer, - final JsonRpcMethodFactory additionalJsonRpcMethodsFactory, - final KeyPair keyPair, + final SyncState syncState, final TransactionPool transactionPool, final MiningCoordinator miningCoordinator, final PrivacyParameters privacyParameters, - final Runnable close) { + final Runnable close, + final JsonRpcMethodFactory additionalJsonRpcMethodsFactory, + final KeyPair keyPair) { this.protocolSchedule = protocolSchedule; this.protocolContext = protocolContext; this.ethProtocolManager = ethProtocolManager; this.genesisConfigOptions = genesisConfigOptions; this.subProtocolConfiguration = subProtocolConfiguration; this.synchronizer = synchronizer; + this.syncState = syncState; this.additionalJsonRpcMethodsFactory = additionalJsonRpcMethodsFactory; this.keyPair = keyPair; this.transactionPool = transactionPool; @@ -126,6 +130,10 @@ public Map getAdditionalJsonRpcMethods( return additionalJsonRpcMethodsFactory.createJsonRpcMethods(enabledRpcApis); } + public SyncState getSyncState() { + return syncState; + } + public static class Builder { public PantheonControllerBuilder fromEthNetworkConfig( diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/controller/PantheonControllerBuilder.java b/pantheon/src/main/java/tech/pegasys/pantheon/controller/PantheonControllerBuilder.java index c855fbd862..576d5b1895 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/controller/PantheonControllerBuilder.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/controller/PantheonControllerBuilder.java @@ -323,8 +323,7 @@ public PantheonController build() throws IOException { genesisConfig.getConfigOptions(genesisConfigOverrides), subProtocolConfiguration, synchronizer, - additionalJsonRpcMethodFactory, - nodeKeys, + syncState, transactionPool, miningCoordinator, privacyParameters, @@ -338,7 +337,9 @@ public PantheonController build() throws IOException { } catch (final IOException e) { LOG.error("Failed to close storage provider", e); } - }); + }, + additionalJsonRpcMethodFactory, + nodeKeys); } protected void prepForBuild() {} diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/services/PantheonEventsImpl.java b/pantheon/src/main/java/tech/pegasys/pantheon/services/PantheonEventsImpl.java index 4b4c8efb4f..ac129b5d34 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/services/PantheonEventsImpl.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/services/PantheonEventsImpl.java @@ -12,23 +12,23 @@ */ package tech.pegasys.pantheon.services; -import tech.pegasys.pantheon.ethereum.core.Synchronizer; import tech.pegasys.pantheon.ethereum.eth.sync.BlockBroadcaster; +import tech.pegasys.pantheon.ethereum.eth.sync.state.SyncState; import tech.pegasys.pantheon.ethereum.eth.transactions.TransactionPool; import tech.pegasys.pantheon.plugin.services.PantheonEvents; public class PantheonEventsImpl implements PantheonEvents { private final BlockBroadcaster blockBroadcaster; private final TransactionPool transactionPool; - private final Synchronizer synchronizer; + private final SyncState syncState; public PantheonEventsImpl( final BlockBroadcaster blockBroadcaster, final TransactionPool transactionPool, - final Synchronizer synchronizer) { + final SyncState syncState) { this.blockBroadcaster = blockBroadcaster; this.transactionPool = transactionPool; - this.synchronizer = synchronizer; + this.syncState = syncState; } @Override @@ -75,11 +75,11 @@ public void removeLogWithMetadataListener(final long listenerIdentifier) {} @Override public long addSynchronizerStatusListener( final SynchronizerStatusListener synchronizerStatusListener) { - return synchronizer.observeSyncStatus(synchronizerStatusListener); + return syncState.addSyncStatusListener(synchronizerStatusListener); } @Override public void removeSynchronizerStatusListener(final long listenerIdentifier) { - synchronizer.removeObserver(listenerIdentifier); + syncState.removeSyncStatusListener(listenerIdentifier); } } diff --git a/pantheon/src/test/java/tech/pegasys/pantheon/plugins/TestPantheonEventsPlugin.java b/pantheon/src/test/java/tech/pegasys/pantheon/plugins/TestPantheonEventsPlugin.java index afb1da2f00..9aee3803e2 100644 --- a/pantheon/src/test/java/tech/pegasys/pantheon/plugins/TestPantheonEventsPlugin.java +++ b/pantheon/src/test/java/tech/pegasys/pantheon/plugins/TestPantheonEventsPlugin.java @@ -22,7 +22,6 @@ import java.nio.file.Files; import java.util.Collections; import java.util.Optional; -import java.util.OptionalLong; import java.util.concurrent.atomic.AtomicInteger; import com.google.auto.service.AutoService; diff --git a/pantheon/src/test/java/tech/pegasys/pantheon/services/PantheonEventsImplTest.java b/pantheon/src/test/java/tech/pegasys/pantheon/services/PantheonEventsImplTest.java index 8f6e921dc6..7ed67b0960 100644 --- a/pantheon/src/test/java/tech/pegasys/pantheon/services/PantheonEventsImplTest.java +++ b/pantheon/src/test/java/tech/pegasys/pantheon/services/PantheonEventsImplTest.java @@ -42,6 +42,7 @@ import tech.pegasys.pantheon.ethereum.worldstate.WorldStateArchive; import tech.pegasys.pantheon.metrics.noop.NoOpMetricsSystem; import tech.pegasys.pantheon.plugin.data.BlockHeader; +import tech.pegasys.pantheon.plugin.data.SyncStatus; import tech.pegasys.pantheon.plugin.data.Transaction; import tech.pegasys.pantheon.testutil.TestClock; import tech.pegasys.pantheon.util.uint.UInt256; @@ -66,7 +67,7 @@ public class PantheonEventsImplTest { @Mock private ProtocolSchedule mockProtocolSchedule; @Mock private ProtocolContext mockProtocolContext; - @Mock private SyncState mockSyncState; + private SyncState syncState; @Mock private EthPeers mockEthPeers; @Mock private EthContext mockEthContext; @Mock private EthMessages mockEthMessages; @@ -109,11 +110,31 @@ public void setUp() { mockEthContext, TestClock.fixed(), new NoOpMetricsSystem(), - mockSyncState, + syncState, Wei.ZERO, TransactionPoolConfiguration.builder().build()); + syncState = new SyncState(mockBlockchain, mockEthPeers); - serviceImpl = new PantheonEventsImpl(blockBroadcaster, transactionPool, synchronizer); + serviceImpl = new PantheonEventsImpl(blockBroadcaster, transactionPool, syncState); + } + + @Test + public void newSyncStatusEventFiresAfterSubscribe() { + final AtomicReference result = new AtomicReference<>(); + serviceImpl.addSynchronizerStatusListener(result::set); + + assertThat(result.get()).isNull(); + syncState.publishSyncStatus(); + assertThat(result.get()).isNotNull(); + } + + @Test + public void newSyncStatusEventDoesNotFireAfterUnsubscribe() { + final AtomicReference result = new AtomicReference<>(); + final long id = serviceImpl.addSynchronizerStatusListener(result::set); + serviceImpl.removeSynchronizerStatusListener(id); + syncState.publishSyncStatus(); + assertThat(result.get()).isNull(); } @Test From ff88a712f979fa39300f3ec09245e132aeea0724 Mon Sep 17 00:00:00 2001 From: Ratan Rai Sur Date: Mon, 9 Sep 2019 18:56:44 +0300 Subject: [PATCH 09/22] flatMap --- .../subscription/logs/LogsSubscriptionService.java | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/websocket/subscription/logs/LogsSubscriptionService.java b/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/websocket/subscription/logs/LogsSubscriptionService.java index eb6d6e608e..3c7ef7c546 100644 --- a/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/websocket/subscription/logs/LogsSubscriptionService.java +++ b/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/websocket/subscription/logs/LogsSubscriptionService.java @@ -47,9 +47,7 @@ public void onBlockAdded(final BlockAddedEvent event, final Blockchain blockchai } event.getAddedTransactions().stream() - .map(tx -> blockchainQueries.transactionReceiptByTransactionHash(tx.hash())) - .filter(Optional::isPresent) - .map(Optional::get) + .flatMap(tx -> blockchainQueries.transactionReceiptByTransactionHash(tx.hash()).stream()) .forEachOrdered( receiptWithMetadata -> { final List logs = receiptWithMetadata.getReceipt().getLogs(); @@ -57,9 +55,7 @@ public void onBlockAdded(final BlockAddedEvent event, final Blockchain blockchai }); event.getRemovedTransactions().stream() - .map(tx -> blockchainQueries.transactionReceiptByTransactionHash(tx.hash())) - .filter(Optional::isPresent) - .map(Optional::get) + .flatMap(tx -> blockchainQueries.transactionReceiptByTransactionHash(tx.hash()).stream()) .forEachOrdered( receiptWithMetadata -> { final List logs = receiptWithMetadata.getReceipt().getLogs(); From 095106edf598afef980c75156731080cd468b9c5 Mon Sep 17 00:00:00 2001 From: Ratan Rai Sur Date: Tue, 10 Sep 2019 16:23:22 +0300 Subject: [PATCH 10/22] fix typo --- .../jsonrpc/websocket/subscription/SubscriptionManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/websocket/subscription/SubscriptionManager.java b/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/websocket/subscription/SubscriptionManager.java index 4225f15deb..2298420283 100644 --- a/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/websocket/subscription/SubscriptionManager.java +++ b/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/websocket/subscription/SubscriptionManager.java @@ -37,7 +37,7 @@ /** * The SubscriptionManager is responsible for managing subscriptions and sending messages to the - * clients that have an active subscription subscription. + * clients that have an active subscription. */ public class SubscriptionManager extends AbstractVerticle { From a8e6ce15c4ff9f6f65f0386c4a986f92e551bb36 Mon Sep 17 00:00:00 2001 From: Ratan Rai Sur Date: Tue, 10 Sep 2019 17:34:24 +0300 Subject: [PATCH 11/22] change logs api --- plugin-api/build.gradle | 2 +- .../tech/pegasys/pantheon/plugin/services/PantheonEvents.java | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/plugin-api/build.gradle b/plugin-api/build.gradle index 185d82c519..9b75ada248 100644 --- a/plugin-api/build.gradle +++ b/plugin-api/build.gradle @@ -56,7 +56,7 @@ Calculated : ${currentHash} tasks.register('checkAPIChanges', FileStateChecker) { description = "Checks that the API for the Plugin-API project does not change without deliberate thought" files = sourceSets.main.allJava.files - knownHash = '4HGcEmt5tf7fhGd4n3erv5oo6eVfA+wpi93pV5G3njo=' + knownHash = 'MTtCPDgLCAkpd/8Nzt+WU+JAFDCFApFtM4kieZ308t8=' } check.dependsOn('checkAPIChanges') diff --git a/plugin-api/src/main/java/tech/pegasys/pantheon/plugin/services/PantheonEvents.java b/plugin-api/src/main/java/tech/pegasys/pantheon/plugin/services/PantheonEvents.java index c6ab46d5b1..01a80856a8 100644 --- a/plugin-api/src/main/java/tech/pegasys/pantheon/plugin/services/PantheonEvents.java +++ b/plugin-api/src/main/java/tech/pegasys/pantheon/plugin/services/PantheonEvents.java @@ -18,6 +18,7 @@ import tech.pegasys.pantheon.plugin.data.SyncStatus; import tech.pegasys.pantheon.plugin.data.Transaction; +import java.util.Collections; import java.util.List; /** @@ -92,7 +93,7 @@ public interface PantheonEvents { * event. * @return an object to be used as an identifier when de-registering the event. */ - long addLogWithMetadataListener(LogWithMetadataListener logWithMetadataListener); + long addLogWithMetadataListener(List address, List topics, LogWithMetadataListener logWithMetadataListener); /** * Remove the logs listener from pantheon notifications. From b71bbb8965442d7e7eee9c1ed104c4b31aa3e873 Mon Sep 17 00:00:00 2001 From: Ratan Rai Sur Date: Tue, 10 Sep 2019 17:36:19 +0300 Subject: [PATCH 12/22] remove optional import --- .../websocket/subscription/logs/LogsSubscriptionService.java | 1 - 1 file changed, 1 deletion(-) diff --git a/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/websocket/subscription/logs/LogsSubscriptionService.java b/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/websocket/subscription/logs/LogsSubscriptionService.java index 3c7ef7c546..3139ef0acf 100644 --- a/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/websocket/subscription/logs/LogsSubscriptionService.java +++ b/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/websocket/subscription/logs/LogsSubscriptionService.java @@ -24,7 +24,6 @@ import tech.pegasys.pantheon.ethereum.jsonrpc.websocket.subscription.request.SubscriptionType; import java.util.List; -import java.util.Optional; public class LogsSubscriptionService implements BlockAddedObserver { From b55406eb865ee28952f8613bb1c174277cdc5bc1 Mon Sep 17 00:00:00 2001 From: Ratan Rai Sur Date: Tue, 10 Sep 2019 17:36:33 +0300 Subject: [PATCH 13/22] spotless --- plugin-api/build.gradle | 2 +- .../tech/pegasys/pantheon/plugin/services/PantheonEvents.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/plugin-api/build.gradle b/plugin-api/build.gradle index 9b75ada248..6e4ca6bf02 100644 --- a/plugin-api/build.gradle +++ b/plugin-api/build.gradle @@ -56,7 +56,7 @@ Calculated : ${currentHash} tasks.register('checkAPIChanges', FileStateChecker) { description = "Checks that the API for the Plugin-API project does not change without deliberate thought" files = sourceSets.main.allJava.files - knownHash = 'MTtCPDgLCAkpd/8Nzt+WU+JAFDCFApFtM4kieZ308t8=' + knownHash = 'jMIJkZwamrrgvXaZA4Oqc/JnuT5NFg12d5UKb3NELcw=' } check.dependsOn('checkAPIChanges') diff --git a/plugin-api/src/main/java/tech/pegasys/pantheon/plugin/services/PantheonEvents.java b/plugin-api/src/main/java/tech/pegasys/pantheon/plugin/services/PantheonEvents.java index 01a80856a8..55e5c8ad37 100644 --- a/plugin-api/src/main/java/tech/pegasys/pantheon/plugin/services/PantheonEvents.java +++ b/plugin-api/src/main/java/tech/pegasys/pantheon/plugin/services/PantheonEvents.java @@ -18,7 +18,6 @@ import tech.pegasys.pantheon.plugin.data.SyncStatus; import tech.pegasys.pantheon.plugin.data.Transaction; -import java.util.Collections; import java.util.List; /** @@ -93,7 +92,8 @@ public interface PantheonEvents { * event. * @return an object to be used as an identifier when de-registering the event. */ - long addLogWithMetadataListener(List address, List topics, LogWithMetadataListener logWithMetadataListener); + long addLogWithMetadataListener( + List address, List topics, LogWithMetadataListener logWithMetadataListener); /** * Remove the logs listener from pantheon notifications. From 2f7edd6bdf33abd40d7a7693820f0c71be39d6af Mon Sep 17 00:00:00 2001 From: Ratan Rai Sur Date: Tue, 10 Sep 2019 23:45:34 +0300 Subject: [PATCH 14/22] rename Sync related stuff and remove logs for now --- .../dsl/node/ThreadPantheonNodeRunner.java | 2 +- .../pantheon/ethereum/core/Synchronizer.java | 2 +- .../eth/sync/DefaultSynchronizer.java | 8 ++-- .../ethereum/eth/sync/state/SyncState.java | 8 ++-- .../pegasys/pantheon/cli/PantheonCommand.java | 2 +- .../pantheon/services/PantheonEventsImpl.java | 16 ++------ .../services/PantheonEventsImplTest.java | 6 +-- .../plugin/services/PantheonEvents.java | 41 +++---------------- 8 files changed, 23 insertions(+), 62 deletions(-) diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/ThreadPantheonNodeRunner.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/ThreadPantheonNodeRunner.java index 0f36207bae..9f0d63f6b2 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/ThreadPantheonNodeRunner.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/ThreadPantheonNodeRunner.java @@ -136,7 +136,7 @@ public void startNode(final PantheonNode node) { pantheonPluginContext.addService( PantheonEvents.class, new PantheonEventsImpl( - pantheonController.getProtocolManager().getBlockBroadcaster(), + pantheonController.getProtocolManager().getBlockBroadcaster(), pantheonController.getTransactionPool(), pantheonController.getSyncState())); pantheonPluginContext.startPlugins(); diff --git a/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/core/Synchronizer.java b/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/core/Synchronizer.java index 32b61298cd..eb2ed49400 100644 --- a/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/core/Synchronizer.java +++ b/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/core/Synchronizer.java @@ -30,7 +30,7 @@ public interface Synchronizer { */ Optional getSyncStatus(); - long observeSyncStatus(final PantheonEvents.SynchronizerStatusListener listener); + long observeSyncStatus(final PantheonEvents.SyncStatusListener listener); boolean removeObserver(long observerId); } diff --git a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/DefaultSynchronizer.java b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/DefaultSynchronizer.java index 08fd5b650e..20993cd01c 100644 --- a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/DefaultSynchronizer.java +++ b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/DefaultSynchronizer.java @@ -30,7 +30,7 @@ import tech.pegasys.pantheon.metrics.PantheonMetricCategory; import tech.pegasys.pantheon.plugin.data.SyncStatus; import tech.pegasys.pantheon.plugin.services.MetricsSystem; -import tech.pegasys.pantheon.plugin.services.PantheonEvents.SynchronizerStatusListener; +import tech.pegasys.pantheon.plugin.services.PantheonEvents.SyncStatusListener; import tech.pegasys.pantheon.util.ExceptionUtils; import tech.pegasys.pantheon.util.Subscribers; @@ -49,7 +49,7 @@ public class DefaultSynchronizer implements Synchronizer { private final Optional maybePruner; private final SyncState syncState; private final AtomicBoolean running = new AtomicBoolean(false); - private final Subscribers syncStatusListeners = Subscribers.create(); + private final Subscribers syncStatusListeners = Subscribers.create(); private final BlockPropagationManager blockPropagationManager; private final Optional> fastSyncDownloader; private final FullSyncDownloader fullSyncDownloader; @@ -185,7 +185,7 @@ public Optional getSyncStatus() { } @Override - public long observeSyncStatus(final SynchronizerStatusListener listener) { + public long observeSyncStatus(final SyncStatusListener listener) { checkNotNull(listener); return syncStatusListeners.subscribe(listener); } @@ -196,6 +196,6 @@ public boolean removeObserver(final long observerId) { } private void syncStatusCallback(final SyncStatus status) { - syncStatusListeners.forEach(c -> c.onSynchronizerStatusChanged(status)); + syncStatusListeners.forEach(c -> c.onSyncStatusChanged(status)); } } diff --git a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/state/SyncState.java b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/state/SyncState.java index e1077f3423..5033cd81fa 100644 --- a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/state/SyncState.java +++ b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/state/SyncState.java @@ -19,7 +19,7 @@ import tech.pegasys.pantheon.ethereum.eth.manager.EthPeer; import tech.pegasys.pantheon.ethereum.eth.manager.EthPeers; import tech.pegasys.pantheon.ethereum.p2p.rlpx.wire.messages.DisconnectMessage.DisconnectReason; -import tech.pegasys.pantheon.plugin.services.PantheonEvents.SynchronizerStatusListener; +import tech.pegasys.pantheon.plugin.services.PantheonEvents.SyncStatusListener; import tech.pegasys.pantheon.util.Subscribers; import java.util.Optional; @@ -32,7 +32,7 @@ public class SyncState { private final long startingBlock; private boolean lastInSync = true; private final Subscribers inSyncListeners = Subscribers.create(); - private final Subscribers syncStatusListeners = Subscribers.create(); + private final Subscribers syncStatusListeners = Subscribers.create(); private Optional syncTarget = Optional.empty(); private long chainHeightListenerId; @@ -51,14 +51,14 @@ public SyncState(final Blockchain blockchain, final EthPeers ethPeers) { public void publishSyncStatus() { final SyncStatus syncStatus = syncStatus(); - syncStatusListeners.forEach(c -> c.onSynchronizerStatusChanged(syncStatus)); + syncStatusListeners.forEach(c -> c.onSyncStatusChanged(syncStatus)); } public void addInSyncListener(final InSyncListener observer) { inSyncListeners.subscribe(observer); } - public long addSyncStatusListener(final SynchronizerStatusListener observer) { + public long addSyncStatusListener(final SyncStatusListener observer) { return syncStatusListeners.subscribe(observer); } diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java b/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java index eb0893d167..cec7bcd6dc 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java @@ -822,7 +822,7 @@ private PantheonCommand startPlugins() { pantheonPluginContext.addService( PantheonEvents.class, new PantheonEventsImpl( - (pantheonController.getProtocolManager().getBlockBroadcaster()), + pantheonController.getProtocolManager().getBlockBroadcaster(), pantheonController.getTransactionPool(), pantheonController.getSyncState())); pantheonPluginContext.startPlugins(); diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/services/PantheonEventsImpl.java b/pantheon/src/main/java/tech/pegasys/pantheon/services/PantheonEventsImpl.java index ac129b5d34..663fdb247e 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/services/PantheonEventsImpl.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/services/PantheonEventsImpl.java @@ -65,21 +65,13 @@ public void removeTransactionDroppedListener(final long listenerIdentifier) { } @Override - public long addLogWithMetadataListener(final LogWithMetadataListener logWithMetaDataListener) { - return 0; + public long addSyncStatusListener( + final SyncStatusListener syncStatusListener) { + return syncState.addSyncStatusListener(syncStatusListener); } @Override - public void removeLogWithMetadataListener(final long listenerIdentifier) {} - - @Override - public long addSynchronizerStatusListener( - final SynchronizerStatusListener synchronizerStatusListener) { - return syncState.addSyncStatusListener(synchronizerStatusListener); - } - - @Override - public void removeSynchronizerStatusListener(final long listenerIdentifier) { + public void removeSyncStatusListener(final long listenerIdentifier) { syncState.removeSyncStatusListener(listenerIdentifier); } } diff --git a/pantheon/src/test/java/tech/pegasys/pantheon/services/PantheonEventsImplTest.java b/pantheon/src/test/java/tech/pegasys/pantheon/services/PantheonEventsImplTest.java index 7ed67b0960..1865167a17 100644 --- a/pantheon/src/test/java/tech/pegasys/pantheon/services/PantheonEventsImplTest.java +++ b/pantheon/src/test/java/tech/pegasys/pantheon/services/PantheonEventsImplTest.java @@ -121,7 +121,7 @@ public void setUp() { @Test public void newSyncStatusEventFiresAfterSubscribe() { final AtomicReference result = new AtomicReference<>(); - serviceImpl.addSynchronizerStatusListener(result::set); + serviceImpl.addSyncStatusListener(result::set); assertThat(result.get()).isNull(); syncState.publishSyncStatus(); @@ -131,8 +131,8 @@ public void newSyncStatusEventFiresAfterSubscribe() { @Test public void newSyncStatusEventDoesNotFireAfterUnsubscribe() { final AtomicReference result = new AtomicReference<>(); - final long id = serviceImpl.addSynchronizerStatusListener(result::set); - serviceImpl.removeSynchronizerStatusListener(id); + final long id = serviceImpl.addSyncStatusListener(result::set); + serviceImpl.removeSyncStatusListener(id); syncState.publishSyncStatus(); assertThat(result.get()).isNull(); } diff --git a/plugin-api/src/main/java/tech/pegasys/pantheon/plugin/services/PantheonEvents.java b/plugin-api/src/main/java/tech/pegasys/pantheon/plugin/services/PantheonEvents.java index 55e5c8ad37..793b8a4875 100644 --- a/plugin-api/src/main/java/tech/pegasys/pantheon/plugin/services/PantheonEvents.java +++ b/plugin-api/src/main/java/tech/pegasys/pantheon/plugin/services/PantheonEvents.java @@ -14,12 +14,9 @@ import tech.pegasys.pantheon.plugin.Unstable; import tech.pegasys.pantheon.plugin.data.BlockHeader; -import tech.pegasys.pantheon.plugin.data.LogWithMetadata; import tech.pegasys.pantheon.plugin.data.SyncStatus; import tech.pegasys.pantheon.plugin.data.Transaction; -import java.util.List; - /** * This service allows plugins to attach to various events during the normal operation of Pantheon. * @@ -85,38 +82,21 @@ public interface PantheonEvents { */ void removeTransactionDroppedListener(long listenerIdentifier); - /** - * Add a listener watching logs (plus metadata about them) included in new blocks. - * - * @param logWithMetadataListener The listener that will accept the LogWithMetadata object as the - * event. - * @return an object to be used as an identifier when de-registering the event. - */ - long addLogWithMetadataListener( - List address, List topics, LogWithMetadataListener logWithMetadataListener); - - /** - * Remove the logs listener from pantheon notifications. - * - * @param listenerIdentifier The instance that was returned from addTransactionDroppedListener; - */ - void removeLogWithMetadataListener(long listenerIdentifier); - /** * Add a listener watching the synchronizer status. * - * @param synchronizerStatusListener The listener that will accept the SyncStatus object as the + * @param syncStatusListener The listener that will accept the SyncStatus object as the * event. * @return an object to be used as an identifier when de-registering the event. */ - long addSynchronizerStatusListener(SynchronizerStatusListener synchronizerStatusListener); + long addSyncStatusListener(SyncStatusListener syncStatusListener); /** * Remove the logs listener from pantheon notifications. * * @param listenerIdentifier The instance that was returned from addTransactionDroppedListener; */ - void removeSynchronizerStatusListener(long listenerIdentifier); + void removeSyncStatusListener(long listenerIdentifier); /** The listener interface for receiving new block propagated events. */ interface BlockPropagatedListener { @@ -155,25 +135,14 @@ interface TransactionDroppedListener { void onTransactionDropped(Transaction transaction); } - /** The listener interface for receiving logs from new blocks. */ - interface LogWithMetadataListener { - - /** - * Invoked when a new block is added. - * - * @param logs the new logs from the block added event - */ - void onLogWithMetadatasAdded(List logs); - } - /** The listener interface for receiving sync status events. */ - interface SynchronizerStatusListener { + interface SyncStatusListener { /** * Invoked when the synchronizer status changes * * @param syncStatus the sync status */ - void onSynchronizerStatusChanged(SyncStatus syncStatus); + void onSyncStatusChanged(SyncStatus syncStatus); } } From 1d373050a43e1b9152b0b20fc0df1fe423843680 Mon Sep 17 00:00:00 2001 From: Ratan Rai Sur Date: Tue, 10 Sep 2019 23:58:07 +0300 Subject: [PATCH 15/22] add transaction dropped testing --- .../services/PantheonEventsImplTest.java | 34 +++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/pantheon/src/test/java/tech/pegasys/pantheon/services/PantheonEventsImplTest.java b/pantheon/src/test/java/tech/pegasys/pantheon/services/PantheonEventsImplTest.java index 1865167a17..dadf6f605c 100644 --- a/pantheon/src/test/java/tech/pegasys/pantheon/services/PantheonEventsImplTest.java +++ b/pantheon/src/test/java/tech/pegasys/pantheon/services/PantheonEventsImplTest.java @@ -112,7 +112,7 @@ public void setUp() { new NoOpMetricsSystem(), syncState, Wei.ZERO, - TransactionPoolConfiguration.builder().build()); + TransactionPoolConfiguration.builder().txPoolMaxSize(1).build()); syncState = new SyncState(mockBlockchain, mockEthPeers); serviceImpl = new PantheonEventsImpl(blockBroadcaster, transactionPool, syncState); @@ -201,11 +201,41 @@ public void newTransactionEventDoesNotFireAfterUnsubscribe() { } @Test - public void newTransactionEventUselessUnsubscribesCompletes() { + public void transactionAddedEventUselessUnsubscribesCompletes() { serviceImpl.removeTransactionAddedListener(5); serviceImpl.removeTransactionAddedListener(5L); } + @Test + public void transactionDroppedEventFiresAfterSubscribe() { + final AtomicReference result = new AtomicReference<>(); + serviceImpl.addTransactionDroppedListener(result::set); + + assertThat(result.get()).isNull(); + // The max pool size is configured to 1 so adding two transactions should trigger a drop + transactionPool.addLocalTransaction(TX1); + transactionPool.addLocalTransaction(TX2); + + assertThat(result.get()).isNotNull(); + } + + @Test + public void transactionDroppedEventDoesNotFireAfterUnsubscribe() { + final AtomicReference result = new AtomicReference<>(); + final long id = serviceImpl.addTransactionDroppedListener(result::set); + + assertThat(result.get()).isNull(); + transactionPool.addLocalTransaction(TX1); + transactionPool.addLocalTransaction(TX2); + + assertThat(result.get()).isNotNull(); + serviceImpl.removeTransactionAddedListener(id); + result.set(null); + + transactionPool.addLocalTransaction(TX2); + assertThat(result.get()).isNull(); + } + private Block generateBlock() { final BlockBody body = new BlockBody(Collections.emptyList(), Collections.emptyList()); return new Block(new BlockHeaderTestFixture().buildHeader(), body); From e85d86d70145fde72701333ddd814be7f6aea9a2 Mon Sep 17 00:00:00 2001 From: Ratan Rai Sur Date: Tue, 10 Sep 2019 23:58:23 +0300 Subject: [PATCH 16/22] add isNotNull checks --- .../pegasys/pantheon/services/PantheonEventsImplTest.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pantheon/src/test/java/tech/pegasys/pantheon/services/PantheonEventsImplTest.java b/pantheon/src/test/java/tech/pegasys/pantheon/services/PantheonEventsImplTest.java index dadf6f605c..09a4cf06b4 100644 --- a/pantheon/src/test/java/tech/pegasys/pantheon/services/PantheonEventsImplTest.java +++ b/pantheon/src/test/java/tech/pegasys/pantheon/services/PantheonEventsImplTest.java @@ -132,6 +132,9 @@ public void newSyncStatusEventFiresAfterSubscribe() { public void newSyncStatusEventDoesNotFireAfterUnsubscribe() { final AtomicReference result = new AtomicReference<>(); final long id = serviceImpl.addSyncStatusListener(result::set); + syncState.publishSyncStatus(); + assertThat(result.get()).isNotNull(); + result.set(null); serviceImpl.removeSyncStatusListener(id); syncState.publishSyncStatus(); assertThat(result.get()).isNull(); @@ -156,6 +159,7 @@ public void newBlockEventDoesNotFireAfterUnsubscribe() { assertThat(result.get()).isNull(); blockBroadcaster.propagate(generateBlock(), UInt256.of(1)); + assertThat(result.get()).isNotNull(); serviceImpl.removeBlockPropagatedListener(id); result.set(null); @@ -186,12 +190,13 @@ public void newTransactionEventFiresAfterSubscribe() { } @Test - public void newTransactionEventDoesNotFireAfterUnsubscribe() { + public void transactionAddedEventDoesNotFireAfterUnsubscribe() { final AtomicReference result = new AtomicReference<>(); final long id = serviceImpl.addTransactionAddedListener(result::set); assertThat(result.get()).isNull(); transactionPool.addLocalTransaction(TX1); + assertThat(result.get()).isNotNull(); serviceImpl.removeTransactionAddedListener(id); result.set(null); From b1612ce66cba1be12272744fe5d447608d0ef283 Mon Sep 17 00:00:00 2001 From: Ratan Rai Sur Date: Tue, 10 Sep 2019 23:59:43 +0300 Subject: [PATCH 17/22] rename --- .../pegasys/pantheon/services/PantheonEventsImplTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pantheon/src/test/java/tech/pegasys/pantheon/services/PantheonEventsImplTest.java b/pantheon/src/test/java/tech/pegasys/pantheon/services/PantheonEventsImplTest.java index 09a4cf06b4..194984e79c 100644 --- a/pantheon/src/test/java/tech/pegasys/pantheon/services/PantheonEventsImplTest.java +++ b/pantheon/src/test/java/tech/pegasys/pantheon/services/PantheonEventsImplTest.java @@ -119,7 +119,7 @@ public void setUp() { } @Test - public void newSyncStatusEventFiresAfterSubscribe() { + public void syncStatusEventFiresAfterSubscribe() { final AtomicReference result = new AtomicReference<>(); serviceImpl.addSyncStatusListener(result::set); @@ -129,7 +129,7 @@ public void newSyncStatusEventFiresAfterSubscribe() { } @Test - public void newSyncStatusEventDoesNotFireAfterUnsubscribe() { + public void syncStatusEventDoesNotFireAfterUnsubscribe() { final AtomicReference result = new AtomicReference<>(); final long id = serviceImpl.addSyncStatusListener(result::set); syncState.publishSyncStatus(); @@ -179,7 +179,7 @@ public void newBlockEventUselessUnsubscribesCompletes() { } @Test - public void newTransactionEventFiresAfterSubscribe() { + public void transactionAddedEventFiresAfterSubscribe() { final AtomicReference result = new AtomicReference<>(); serviceImpl.addTransactionAddedListener(result::set); From 96f26fc8a2f3c0e9cc0c3aad436ebf0182d65f2c Mon Sep 17 00:00:00 2001 From: Ratan Rai Sur Date: Wed, 11 Sep 2019 00:00:40 +0300 Subject: [PATCH 18/22] spotless --- .../tests/acceptance/dsl/node/ThreadPantheonNodeRunner.java | 2 +- .../main/java/tech/pegasys/pantheon/cli/PantheonCommand.java | 2 +- .../tech/pegasys/pantheon/services/PantheonEventsImpl.java | 3 +-- plugin-api/build.gradle | 2 +- .../tech/pegasys/pantheon/plugin/services/PantheonEvents.java | 3 +-- 5 files changed, 5 insertions(+), 7 deletions(-) diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/ThreadPantheonNodeRunner.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/ThreadPantheonNodeRunner.java index 9f0d63f6b2..0f36207bae 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/ThreadPantheonNodeRunner.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/ThreadPantheonNodeRunner.java @@ -136,7 +136,7 @@ public void startNode(final PantheonNode node) { pantheonPluginContext.addService( PantheonEvents.class, new PantheonEventsImpl( - pantheonController.getProtocolManager().getBlockBroadcaster(), + pantheonController.getProtocolManager().getBlockBroadcaster(), pantheonController.getTransactionPool(), pantheonController.getSyncState())); pantheonPluginContext.startPlugins(); diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java b/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java index cec7bcd6dc..a678c57b0d 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java @@ -822,7 +822,7 @@ private PantheonCommand startPlugins() { pantheonPluginContext.addService( PantheonEvents.class, new PantheonEventsImpl( - pantheonController.getProtocolManager().getBlockBroadcaster(), + pantheonController.getProtocolManager().getBlockBroadcaster(), pantheonController.getTransactionPool(), pantheonController.getSyncState())); pantheonPluginContext.startPlugins(); diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/services/PantheonEventsImpl.java b/pantheon/src/main/java/tech/pegasys/pantheon/services/PantheonEventsImpl.java index 663fdb247e..da78154ba2 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/services/PantheonEventsImpl.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/services/PantheonEventsImpl.java @@ -65,8 +65,7 @@ public void removeTransactionDroppedListener(final long listenerIdentifier) { } @Override - public long addSyncStatusListener( - final SyncStatusListener syncStatusListener) { + public long addSyncStatusListener(final SyncStatusListener syncStatusListener) { return syncState.addSyncStatusListener(syncStatusListener); } diff --git a/plugin-api/build.gradle b/plugin-api/build.gradle index 6e4ca6bf02..b161afecc6 100644 --- a/plugin-api/build.gradle +++ b/plugin-api/build.gradle @@ -56,7 +56,7 @@ Calculated : ${currentHash} tasks.register('checkAPIChanges', FileStateChecker) { description = "Checks that the API for the Plugin-API project does not change without deliberate thought" files = sourceSets.main.allJava.files - knownHash = 'jMIJkZwamrrgvXaZA4Oqc/JnuT5NFg12d5UKb3NELcw=' + knownHash = 'XRlGqJaLS7+xkU26aCme+c+kt3sTCkvmWRyDw2BaINg=' } check.dependsOn('checkAPIChanges') diff --git a/plugin-api/src/main/java/tech/pegasys/pantheon/plugin/services/PantheonEvents.java b/plugin-api/src/main/java/tech/pegasys/pantheon/plugin/services/PantheonEvents.java index 793b8a4875..344364917d 100644 --- a/plugin-api/src/main/java/tech/pegasys/pantheon/plugin/services/PantheonEvents.java +++ b/plugin-api/src/main/java/tech/pegasys/pantheon/plugin/services/PantheonEvents.java @@ -85,8 +85,7 @@ public interface PantheonEvents { /** * Add a listener watching the synchronizer status. * - * @param syncStatusListener The listener that will accept the SyncStatus object as the - * event. + * @param syncStatusListener The listener that will accept the SyncStatus object as the event. * @return an object to be used as an identifier when de-registering the event. */ long addSyncStatusListener(SyncStatusListener syncStatusListener); From 3feaf7036c6f28186a8a8129ff25b9d75bf91796 Mon Sep 17 00:00:00 2001 From: Ratan Rai Sur Date: Wed, 11 Sep 2019 01:17:21 +0300 Subject: [PATCH 19/22] Revert "flatMap" This reverts commit 95f019a4b38bfbffeb6d56de9214400c9fca8c44. --- .../subscription/logs/LogsSubscriptionService.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/websocket/subscription/logs/LogsSubscriptionService.java b/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/websocket/subscription/logs/LogsSubscriptionService.java index 3139ef0acf..ee20741834 100644 --- a/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/websocket/subscription/logs/LogsSubscriptionService.java +++ b/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/websocket/subscription/logs/LogsSubscriptionService.java @@ -46,7 +46,9 @@ public void onBlockAdded(final BlockAddedEvent event, final Blockchain blockchai } event.getAddedTransactions().stream() - .flatMap(tx -> blockchainQueries.transactionReceiptByTransactionHash(tx.hash()).stream()) + .map(tx -> blockchainQueries.transactionReceiptByTransactionHash(tx.hash())) + .filter(Optional::isPresent) + .map(Optional::get) .forEachOrdered( receiptWithMetadata -> { final List logs = receiptWithMetadata.getReceipt().getLogs(); @@ -54,7 +56,9 @@ public void onBlockAdded(final BlockAddedEvent event, final Blockchain blockchai }); event.getRemovedTransactions().stream() - .flatMap(tx -> blockchainQueries.transactionReceiptByTransactionHash(tx.hash()).stream()) + .map(tx -> blockchainQueries.transactionReceiptByTransactionHash(tx.hash())) + .filter(Optional::isPresent) + .map(Optional::get) .forEachOrdered( receiptWithMetadata -> { final List logs = receiptWithMetadata.getReceipt().getLogs(); From 72a7ba7b82b7b3c76c0c55facb8b0655cb6db1aa Mon Sep 17 00:00:00 2001 From: Ratan Rai Sur Date: Wed, 11 Sep 2019 01:22:02 +0300 Subject: [PATCH 20/22] remove log related stuff --- .../ethereum/eth/sync/state/SyncState.java | 3 + .../graphql/internal/LogWithMetadata.java | 11 +--- .../logs/LogsSubscriptionService.java | 1 + plugin-api/build.gradle | 2 +- .../pantheon/plugin/data/LogWithMetadata.java | 63 ------------------- 5 files changed, 6 insertions(+), 74 deletions(-) delete mode 100644 plugin-api/src/main/java/tech/pegasys/pantheon/plugin/data/LogWithMetadata.java diff --git a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/state/SyncState.java b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/state/SyncState.java index 5033cd81fa..c3cbc57546 100644 --- a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/state/SyncState.java +++ b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/state/SyncState.java @@ -24,6 +24,8 @@ import java.util.Optional; +import com.google.common.annotations.VisibleForTesting; + public class SyncState { private static final long SYNC_TOLERANCE = 5; private final Blockchain blockchain; @@ -49,6 +51,7 @@ public SyncState(final Blockchain blockchain, final EthPeers ethPeers) { }); } + @VisibleForTesting public void publishSyncStatus() { final SyncStatus syncStatus = syncStatus(); syncStatusListeners.forEach(c -> c.onSyncStatusChanged(syncStatus)); diff --git a/ethereum/graphql/src/main/java/tech/pegasys/pantheon/ethereum/graphql/internal/LogWithMetadata.java b/ethereum/graphql/src/main/java/tech/pegasys/pantheon/ethereum/graphql/internal/LogWithMetadata.java index 4d4803b215..86e9a61230 100644 --- a/ethereum/graphql/src/main/java/tech/pegasys/pantheon/ethereum/graphql/internal/LogWithMetadata.java +++ b/ethereum/graphql/src/main/java/tech/pegasys/pantheon/ethereum/graphql/internal/LogWithMetadata.java @@ -21,7 +21,7 @@ import com.google.common.base.MoreObjects; -public class LogWithMetadata implements tech.pegasys.pantheon.plugin.data.LogWithMetadata { +public class LogWithMetadata { private final int logIndex; private final long blockNumber; @@ -54,47 +54,38 @@ public class LogWithMetadata implements tech.pegasys.pantheon.plugin.data.LogWit this.removed = removed; } - @Override public int getLogIndex() { return logIndex; } - @Override public long getBlockNumber() { return blockNumber; } - @Override public Hash getBlockHash() { return blockHash; } - @Override public Hash getTransactionHash() { return transactionHash; } - @Override public int getTransactionIndex() { return transactionIndex; } - @Override public Address getLogger() { return address; } - @Override public BytesValue getData() { return data; } - @Override public List getTopics() { return topics; } - @Override public boolean isRemoved() { return removed; } diff --git a/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/websocket/subscription/logs/LogsSubscriptionService.java b/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/websocket/subscription/logs/LogsSubscriptionService.java index ee20741834..eb6d6e608e 100644 --- a/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/websocket/subscription/logs/LogsSubscriptionService.java +++ b/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/websocket/subscription/logs/LogsSubscriptionService.java @@ -24,6 +24,7 @@ import tech.pegasys.pantheon.ethereum.jsonrpc.websocket.subscription.request.SubscriptionType; import java.util.List; +import java.util.Optional; public class LogsSubscriptionService implements BlockAddedObserver { diff --git a/plugin-api/build.gradle b/plugin-api/build.gradle index b161afecc6..898cd952bf 100644 --- a/plugin-api/build.gradle +++ b/plugin-api/build.gradle @@ -56,7 +56,7 @@ Calculated : ${currentHash} tasks.register('checkAPIChanges', FileStateChecker) { description = "Checks that the API for the Plugin-API project does not change without deliberate thought" files = sourceSets.main.allJava.files - knownHash = 'XRlGqJaLS7+xkU26aCme+c+kt3sTCkvmWRyDw2BaINg=' + knownHash = 'j39vjVpNEK0kTpk/MLK8BHnqkFoRO9BWajrm9WoejWM=' } check.dependsOn('checkAPIChanges') diff --git a/plugin-api/src/main/java/tech/pegasys/pantheon/plugin/data/LogWithMetadata.java b/plugin-api/src/main/java/tech/pegasys/pantheon/plugin/data/LogWithMetadata.java deleted file mode 100644 index 9a31559d20..0000000000 --- a/plugin-api/src/main/java/tech/pegasys/pantheon/plugin/data/LogWithMetadata.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright 2019 ConsenSys AG. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - */ -package tech.pegasys.pantheon.plugin.data; - -import tech.pegasys.pantheon.plugin.Unstable; - -/** A Log entry from a transaction execution. */ -@Unstable -public interface LogWithMetadata extends Log { - - /** - * The index of this log within the entire ordered list of logs associated with the block this log - * belongs to. - * - * @return The block's number. - */ - int getLogIndex(); - - /** - * The number of the block to which the log belongs. - * - * @return The block's number. - */ - long getBlockNumber(); - - /** - * The hash of the block to which this block belongs. - * - * @return The block's hash. - */ - Hash getBlockHash(); - - /** - * The hash of the transaction that issued this log. - * - * @return The transaction's hash. - */ - Hash getTransactionHash(); - - /** - * The index in the block of the transaction that issued this log. - * - * @return An int representing the index. - */ - int getTransactionIndex(); - - /** - * Whether the log was removed. - * - * @return true when the log was removed, due to a chain reorganization. false if its a valid log. - */ - boolean isRemoved(); -} From 7a27061ca651e8c8e26eb3d26d14bd00678b996f Mon Sep 17 00:00:00 2001 From: Ratan Rai Sur Date: Wed, 11 Sep 2019 01:26:48 +0300 Subject: [PATCH 21/22] revert LogWithMetadata change --- .../pantheon/ethereum/graphql/internal/LogWithMetadata.java | 4 +++- .../ethereum/graphql/internal/pojoadapter/LogAdapter.java | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/ethereum/graphql/src/main/java/tech/pegasys/pantheon/ethereum/graphql/internal/LogWithMetadata.java b/ethereum/graphql/src/main/java/tech/pegasys/pantheon/ethereum/graphql/internal/LogWithMetadata.java index 86e9a61230..7ef808d1c7 100644 --- a/ethereum/graphql/src/main/java/tech/pegasys/pantheon/ethereum/graphql/internal/LogWithMetadata.java +++ b/ethereum/graphql/src/main/java/tech/pegasys/pantheon/ethereum/graphql/internal/LogWithMetadata.java @@ -54,6 +54,8 @@ public class LogWithMetadata { this.removed = removed; } + // The index of this log within the entire ordered list of logs associated with the block this log + // belongs to. public int getLogIndex() { return logIndex; } @@ -74,7 +76,7 @@ public int getTransactionIndex() { return transactionIndex; } - public Address getLogger() { + public Address getAddress() { return address; } diff --git a/ethereum/graphql/src/main/java/tech/pegasys/pantheon/ethereum/graphql/internal/pojoadapter/LogAdapter.java b/ethereum/graphql/src/main/java/tech/pegasys/pantheon/ethereum/graphql/internal/pojoadapter/LogAdapter.java index 4102096d9f..8775f99936 100644 --- a/ethereum/graphql/src/main/java/tech/pegasys/pantheon/ethereum/graphql/internal/pojoadapter/LogAdapter.java +++ b/ethereum/graphql/src/main/java/tech/pegasys/pantheon/ethereum/graphql/internal/pojoadapter/LogAdapter.java @@ -68,6 +68,6 @@ public Optional getAccount(final DataFetchingEnvironment environ return query .getWorldState(blockNumber) - .map(ws -> new AccountAdapter(ws.get(logWithMetadata.getLogger()))); + .map(ws -> new AccountAdapter(ws.get(logWithMetadata.getAddress()))); } } From d890325f8a160ddb80e2f0bf93e815c575b7f3a7 Mon Sep 17 00:00:00 2001 From: Ratan Rai Sur Date: Wed, 11 Sep 2019 11:53:32 +0300 Subject: [PATCH 22/22] fix test compile errors --- .../eth/sync/state/SyncStateTest.java | 4 ++-- .../jsonrpc/health/ReadinessCheckTest.java | 5 +++-- .../internal/methods/EthSyncingTest.java | 5 +++-- .../SyncingSubscriptionServiceTest.java | 6 ++--- ...ncStatusNodePermissioningProviderTest.java | 22 +++++++++---------- 5 files changed, 22 insertions(+), 20 deletions(-) diff --git a/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/sync/state/SyncStateTest.java b/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/sync/state/SyncStateTest.java index f5caa86a94..06d5f7711e 100644 --- a/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/sync/state/SyncStateTest.java +++ b/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/sync/state/SyncStateTest.java @@ -31,10 +31,10 @@ import tech.pegasys.pantheon.ethereum.core.BlockHeader; import tech.pegasys.pantheon.ethereum.core.BlockHeaderTestFixture; import tech.pegasys.pantheon.ethereum.core.Hash; -import tech.pegasys.pantheon.ethereum.core.Synchronizer.SyncStatusListener; import tech.pegasys.pantheon.ethereum.eth.manager.ChainState; import tech.pegasys.pantheon.ethereum.eth.manager.EthPeer; import tech.pegasys.pantheon.ethereum.eth.manager.EthPeers; +import tech.pegasys.pantheon.plugin.services.PantheonEvents.SyncStatusListener; import tech.pegasys.pantheon.util.uint.UInt256; import java.util.Collections; @@ -237,7 +237,7 @@ public void shouldSendSyncStatusWhenBlockIsAddedToTheChain() { new BlockBody(Collections.emptyList(), Collections.emptyList()))), blockchain); - verify(syncStatusListener).onSyncStatus(eq(syncState.syncStatus())); + verify(syncStatusListener).onSyncStatusChanged(eq(syncState.syncStatus())); } private void setupOutOfSyncState() { diff --git a/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/health/ReadinessCheckTest.java b/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/health/ReadinessCheckTest.java index b5856c4263..ca8e6472b1 100644 --- a/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/health/ReadinessCheckTest.java +++ b/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/health/ReadinessCheckTest.java @@ -16,10 +16,10 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import tech.pegasys.pantheon.ethereum.core.SyncStatus; import tech.pegasys.pantheon.ethereum.core.Synchronizer; import tech.pegasys.pantheon.ethereum.jsonrpc.health.HealthService.ParamSource; import tech.pegasys.pantheon.ethereum.p2p.network.P2PNetwork; +import tech.pegasys.pantheon.plugin.data.SyncStatus; import java.util.HashMap; import java.util.Map; @@ -141,6 +141,7 @@ public void shouldNotBeReadyWhenCustomMaxBlocksBehindIsInvalid() { } private Optional createSyncStatus(final int currentBlock, final int highestBlock) { - return Optional.of(new SyncStatus(0, currentBlock, highestBlock)); + return Optional.of( + new tech.pegasys.pantheon.ethereum.core.SyncStatus(0, currentBlock, highestBlock)); } } diff --git a/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/EthSyncingTest.java b/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/EthSyncingTest.java index 7425a64ccb..5f41b4f158 100644 --- a/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/EthSyncingTest.java +++ b/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/EthSyncingTest.java @@ -17,12 +17,12 @@ import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.when; -import tech.pegasys.pantheon.ethereum.core.SyncStatus; import tech.pegasys.pantheon.ethereum.core.Synchronizer; import tech.pegasys.pantheon.ethereum.jsonrpc.internal.JsonRpcRequest; import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcResponse; import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcSuccessResponse; import tech.pegasys.pantheon.ethereum.jsonrpc.internal.results.SyncingResult; +import tech.pegasys.pantheon.plugin.data.SyncStatus; import java.util.Optional; @@ -66,7 +66,8 @@ public void shouldReturnFalseWhenSyncStatusIsEmpty() { @Test public void shouldReturnExpectedValueWhenSyncStatusIsNotEmpty() { final JsonRpcRequest request = requestWithParams(); - final SyncStatus expectedSyncStatus = new SyncStatus(0, 1, 2); + final SyncStatus expectedSyncStatus = + new tech.pegasys.pantheon.ethereum.core.SyncStatus(0, 1, 2); final JsonRpcResponse expectedResponse = new JsonRpcSuccessResponse(request.getId(), new SyncingResult(expectedSyncStatus)); final Optional optionalSyncStatus = Optional.of(expectedSyncStatus); diff --git a/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/websocket/subscription/syncing/SyncingSubscriptionServiceTest.java b/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/websocket/subscription/syncing/SyncingSubscriptionServiceTest.java index 830ec0d2ca..2ed3b407ff 100644 --- a/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/websocket/subscription/syncing/SyncingSubscriptionServiceTest.java +++ b/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/websocket/subscription/syncing/SyncingSubscriptionServiceTest.java @@ -20,10 +20,10 @@ import tech.pegasys.pantheon.ethereum.core.SyncStatus; import tech.pegasys.pantheon.ethereum.core.Synchronizer; -import tech.pegasys.pantheon.ethereum.core.Synchronizer.SyncStatusListener; import tech.pegasys.pantheon.ethereum.jsonrpc.internal.results.SyncingResult; import tech.pegasys.pantheon.ethereum.jsonrpc.websocket.subscription.SubscriptionManager; import tech.pegasys.pantheon.ethereum.jsonrpc.websocket.subscription.request.SubscriptionType; +import tech.pegasys.pantheon.plugin.services.PantheonEvents.SyncStatusListener; import java.util.Collections; import java.util.List; @@ -69,7 +69,7 @@ public void shouldSendSyncStatusWhenReceiveSyncStatus() { .when(subscriptionManager) .notifySubscribersOnWorkerThread(any(), any(), any()); - syncStatusListener.onSyncStatus(syncStatus); + syncStatusListener.onSyncStatusChanged(syncStatus); verify(subscriptionManager) .sendMessage(eq(subscription.getSubscriptionId()), eq(expectedSyncingResult)); @@ -91,7 +91,7 @@ public void shouldSendNotSyncingStatusWhenReceiveSyncStatusAtHead() { .when(subscriptionManager) .notifySubscribersOnWorkerThread(any(), any(), any()); - syncStatusListener.onSyncStatus(syncStatus); + syncStatusListener.onSyncStatusChanged(syncStatus); verify(subscriptionManager) .sendMessage(eq(subscription.getSubscriptionId()), any(NotSynchronisingResult.class)); diff --git a/ethereum/permissioning/src/test/java/tech/pegasys/pantheon/ethereum/permissioning/node/provider/SyncStatusNodePermissioningProviderTest.java b/ethereum/permissioning/src/test/java/tech/pegasys/pantheon/ethereum/permissioning/node/provider/SyncStatusNodePermissioningProviderTest.java index c62fc53159..3fdbaa69da 100644 --- a/ethereum/permissioning/src/test/java/tech/pegasys/pantheon/ethereum/permissioning/node/provider/SyncStatusNodePermissioningProviderTest.java +++ b/ethereum/permissioning/src/test/java/tech/pegasys/pantheon/ethereum/permissioning/node/provider/SyncStatusNodePermissioningProviderTest.java @@ -21,10 +21,10 @@ import tech.pegasys.pantheon.ethereum.core.SyncStatus; import tech.pegasys.pantheon.ethereum.core.Synchronizer; -import tech.pegasys.pantheon.ethereum.core.Synchronizer.SyncStatusListener; import tech.pegasys.pantheon.ethereum.p2p.peers.EnodeURL; import tech.pegasys.pantheon.metrics.PantheonMetricCategory; import tech.pegasys.pantheon.plugin.services.MetricsSystem; +import tech.pegasys.pantheon.plugin.services.PantheonEvents.SyncStatusListener; import tech.pegasys.pantheon.plugin.services.metrics.Counter; import java.util.ArrayList; @@ -104,7 +104,7 @@ public void before() { @Test public void whenIsNotInSyncHasReachedSyncShouldReturnFalse() { - syncStatusListener.onSyncStatus(new SyncStatus(0, 1, 2)); + syncStatusListener.onSyncStatusChanged(new SyncStatus(0, 1, 2)); assertThat(provider.hasReachedSync()).isFalse(); assertThat(syncGauge.getAsInt()).isEqualTo(0); @@ -112,7 +112,7 @@ public void whenIsNotInSyncHasReachedSyncShouldReturnFalse() { @Test public void whenInSyncHasReachedSyncShouldReturnTrue() { - syncStatusListener.onSyncStatus(new SyncStatus(0, 1, 1)); + syncStatusListener.onSyncStatusChanged(new SyncStatus(0, 1, 1)); assertThat(provider.hasReachedSync()).isTrue(); assertThat(syncGauge.getAsInt()).isEqualTo(1); @@ -120,22 +120,22 @@ public void whenInSyncHasReachedSyncShouldReturnTrue() { @Test public void whenInSyncChangesFromTrueToFalseHasReachedSyncShouldReturnTrue() { - syncStatusListener.onSyncStatus(new SyncStatus(0, 1, 2)); + syncStatusListener.onSyncStatusChanged(new SyncStatus(0, 1, 2)); assertThat(provider.hasReachedSync()).isFalse(); assertThat(syncGauge.getAsInt()).isEqualTo(0); - syncStatusListener.onSyncStatus(new SyncStatus(0, 2, 1)); + syncStatusListener.onSyncStatusChanged(new SyncStatus(0, 2, 1)); assertThat(provider.hasReachedSync()).isTrue(); assertThat(syncGauge.getAsInt()).isEqualTo(1); - syncStatusListener.onSyncStatus(new SyncStatus(0, 2, 3)); + syncStatusListener.onSyncStatusChanged(new SyncStatus(0, 2, 3)); assertThat(provider.hasReachedSync()).isTrue(); assertThat(syncGauge.getAsInt()).isEqualTo(1); } @Test public void whenHasNotSyncedNonBootnodeShouldNotBePermitted() { - syncStatusListener.onSyncStatus(new SyncStatus(0, 1, 2)); + syncStatusListener.onSyncStatusChanged(new SyncStatus(0, 1, 2)); assertThat(provider.hasReachedSync()).isFalse(); assertThat(syncGauge.getAsInt()).isEqualTo(0); @@ -149,7 +149,7 @@ public void whenHasNotSyncedNonBootnodeShouldNotBePermitted() { @Test public void whenHasNotSyncedBootnodeIncomingConnectionShouldNotBePermitted() { - syncStatusListener.onSyncStatus(new SyncStatus(0, 1, 2)); + syncStatusListener.onSyncStatusChanged(new SyncStatus(0, 1, 2)); assertThat(provider.hasReachedSync()).isFalse(); assertThat(syncGauge.getAsInt()).isEqualTo(0); @@ -163,7 +163,7 @@ public void whenHasNotSyncedBootnodeIncomingConnectionShouldNotBePermitted() { @Test public void whenHasNotSyncedBootnodeOutgoingConnectionShouldBePermitted() { - syncStatusListener.onSyncStatus(new SyncStatus(0, 1, 2)); + syncStatusListener.onSyncStatusChanged(new SyncStatus(0, 1, 2)); assertThat(provider.hasReachedSync()).isFalse(); assertThat(syncGauge.getAsInt()).isEqualTo(0); @@ -177,7 +177,7 @@ public void whenHasNotSyncedBootnodeOutgoingConnectionShouldBePermitted() { @Test public void whenHasSyncedIsPermittedShouldReturnTrue() { - syncStatusListener.onSyncStatus(new SyncStatus(0, 1, 1)); + syncStatusListener.onSyncStatusChanged(new SyncStatus(0, 1, 1)); assertThat(provider.hasReachedSync()).isTrue(); assertThat(syncGauge.getAsInt()).isEqualTo(1); @@ -191,7 +191,7 @@ public void whenHasSyncedIsPermittedShouldReturnTrue() { @Test public void syncStatusPermissioningCheckShouldIgnoreEnodeURLDiscoveryPort() { - syncStatusListener.onSyncStatus(new SyncStatus(0, 1, 2)); + syncStatusListener.onSyncStatusChanged(new SyncStatus(0, 1, 2)); assertThat(provider.hasReachedSync()).isFalse(); final EnodeURL bootnode =