-
Notifications
You must be signed in to change notification settings - Fork 130
Events Plugin - Add initial "NewBlock" event message #1463
Conversation
* It returns for any block we would broadcast to other peers, when we would broadcast them. * It returns a JSON String containing hask, number, and timestamp * This event data is not set in stone, it may change in type or content. * Acceptance tests and unit tests got a re-work away from the assumption that there is only one plugin type.
make picocli plugin not listen to events.
public void propagate(final Block block, final UInt256 totalDifficulty) { | ||
newBlockSubscribers.forEach(listener -> listener.accept(block)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think you want to add this functionality here. Blockchain.observeBlockAdded
already supports observation of new block events.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This event needs to be fired between when we validate the header and when we validate the entire block.
The stack for this code is in part
Breakpoint reached
at tech.pegasys.pantheon.ethereum.eth.sync.BlockBroadcaster.propagate(BlockBroadcaster.java:46)
at tech.pegasys.pantheon.ethereum.eth.sync.BlockPropagationManager.broadcastBlock(BlockPropagationManager.java:248)
at tech.pegasys.pantheon.ethereum.eth.sync.BlockPropagationManager.lambda$validateAndProcessPendingBlock$6(BlockPropagationManager.java:306)
at ...
And the stack for using the Blockchain.observeBlockAdded
event is
...
at tech.pegasys.pantheon.ethereum.eth.sync.BlockPropagationManager.runImportTask(BlockPropagationManager.java:323)
at tech.pegasys.pantheon.ethereum.eth.sync.BlockPropagationManager.validateAndProcessPendingBlock(BlockPropagationManager.java:307)
at tech.pegasys.pantheon.ethereum.eth.sync.BlockPropagationManager.lambda$importOrSavePendingBlock$5(BlockPropagationManager.java:297)
at tech.pegasys.pantheon.ethereum.eth.sync.BlockPropagationManager$$Lambda$1088.740466537.get(Unknown Source:-1)
...
Like 307 for BlockPropagationManager runs the full block validation, which is later than the requirements we have for when this information should be pushed to the events plugin. We don't want full block validation for this event just header (e.g. proof of work) validation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, that makes sense. I think we just need to change the naming to make it clear what this event is. In the future if we handle NEW_BLOCK_HASHES / NEW_BLOCK messages differently, we may want to expose more events to get all of the new blocks on the network. Most clients don't propagate out NEW_BLOCK messages in response to receiving NEW_BLOCK_HASHES from the network, for example.
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
|
||
public class BlockBroadcaster { | ||
private static final Logger LOG = LogManager.getLogger(); | ||
|
||
private final EthContext ethContext; | ||
private final Subscribers<Consumer<Block>> newBlockSubscribers = new Subscribers<>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
private final Subscribers<Consumer<Block>> newBlockSubscribers = new Subscribers<>(); | |
private final Subscribers<Consumer<Block>> blockPropagatedSubscribers = new Subscribers<>(); |
} | ||
|
||
@Override | ||
public Object addBlockAddedListener(final Consumer<String> blockJSONListener) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public Object addBlockAddedListener(final Consumer<String> blockJSONListener) { | |
public Object observeNewBlockPropagated(final Consumer<String> blockJSONListener) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Listener is more prevalent in our code base than observer. So I added the Propagated but kept the Listener.
} | ||
|
||
@Override | ||
public void removeBlockAddedObserver(final Object listenerIdentifier) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public void removeBlockAddedObserver(final Object listenerIdentifier) { | |
public void removeNewBlockPropagatedObserver(final Object listenerIdentifier) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Listener is more prevalent in our code base than observer. So I added the Propagated but kept the Listener.
} | ||
} | ||
|
||
private void dispatchNewBlockMessage(final Block block, final Consumer<String> callback) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
private void dispatchNewBlockMessage(final Block block, final Consumer<String> callback) { | |
private void dispatchNewBlockPropagatedMessage(final Block block, final Consumer<String> callback) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Listener is more prevalent in our code base than observer. So I added the Propagated but kept the Listener.
public void propagate(final Block block, final UInt256 totalDifficulty) { | ||
newBlockSubscribers.forEach(listener -> listener.accept(block)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, that makes sense. I think we just need to change the naming to make it clear what this event is. In the future if we handle NEW_BLOCK_HASHES / NEW_BLOCK messages differently, we may want to expose more events to get all of the new blocks on the network. Most clients don't propagate out NEW_BLOCK messages in response to receiving NEW_BLOCK_HASHES from the network, for example.
} | ||
|
||
@Override | ||
public Object addBlockAddedListener(final Consumer<String> blockJSONListener) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(optional) Consider adding a functional interface in place of Consumer<String>
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
* added a proper listener interface
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM pending the typo fix
} | ||
|
||
@Override | ||
public Object addNewBlockPropagatedLister(final NewBlockPropagatedListener listener) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public Object addNewBlockPropagatedLister(final NewBlockPropagatedListener listener) { | |
public Object addNewBlockPropagatedListener(final NewBlockPropagatedListener listener) { |
Typo
build.gradle
Outdated
@@ -105,7 +105,7 @@ allprojects { | |||
java { | |||
// This path needs to be relative to each project | |||
target fileTree('.') { | |||
include '**/*.java' | |||
include '**/src/*/java/**/*.java' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what are these changes for??
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
meant for another PR. Spotless was catching intellij generated files from .../out/classes/.... By limiting src to having to live in src directories generated and transient java files don't get style checked.
PR description
we would broadcast them.
that there is only one plugin type.
Fixed Issue(s)