-
Notifications
You must be signed in to change notification settings - Fork 870
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ibft queries #138
Ibft queries #138
Conversation
Signed-off-by: Trent Mohay <[email protected]>
consensus/common/src/main/java/org/hyperledger/besu/consensus/common/PoAMetricServiceImpl.java
Outdated
Show resolved
Hide resolved
consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/queries/IbftQueriesImpl.java
Outdated
Show resolved
Hide resolved
Signed-off-by: Trent Mohay <[email protected]>
besuController.getProtocolContext().getBlockchain()); | ||
besuPluginContext.addService(PoAMetricsService.class, service); | ||
if (consensusState != null) { | ||
if (IbftContext.class.isAssignableFrom(consensusState.getClass())) { |
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 know you're following the existing pattern here, but why are we doing isAssignableFrom
checks here? I would have expected this to be pushed into the BesuController
class to register these services as it has the correct context types and doesn't need any casting.
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.
Yeah - way nicer
|
||
import java.util.Collection; | ||
|
||
public interface IbftQueries extends PoAMetricsService { |
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.
Given this is part of the plugin apis it will need comprehensive javadoc.
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.
Agreed - for now just needed to get the code in front of Uzi as he's working on something related.
|
||
public interface IbftQueries extends PoAMetricsService { | ||
|
||
public int getRoundNumberFromCanonicalHead(); |
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 like this as a convenience method but I think it's a bit of an anti-pattern we're developing with only being able to get information about the head block in these PoA APIs. We really should have a variant that accepts a BlockHeader
so you can ask for the round number for any block, not just the canonical head. Also applies to PoAMetricsService.getValidatorsForLatestBlock
. And the naming between the two should be consistent as well - CanonicalHead is probably the right name so maybe need to make a note to rename getValidatorsForLatestBlock
to getValidatorsFromCanonicalHead
at the same time as we rename PoAMetricsService
to remove "metrics" from the name.
Signed-off-by: Trent Mohay <[email protected]>
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.
looks good to me
Signed-off-by: Trent Mohay <[email protected]>
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.
Looks good to me
* | ||
* @return Identities of the validators who formed quorum on the latest block. | ||
* @return Adresses of all validators in the latest canonical 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.
Typo - Addresses
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.
ta
@@ -22,12 +22,12 @@ | |||
/** | |||
* Provides relevant data for producing metrics on the status of a Proof of Authority (PoA) node. |
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.
Comment should likely be updated to remove references to metrics.
@@ -22,12 +22,12 @@ | |||
/** | |||
* Provides relevant data for producing metrics on the status of a Proof of Authority (PoA) node. | |||
*/ | |||
public interface PoAMetricsService { | |||
public interface PoaQueryService { |
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 is a backwards incompatible change on our public, stable plugin APIs. I think we need to deprecate the old interface but keep it around (the same implementation would implement both old and new). We also need to document a deprecation policy so we are clear about when we can remove the old 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.
done
@@ -21,7 +21,10 @@ | |||
|
|||
/** | |||
* Provides relevant data for producing metrics on the status of a Proof of Authority (PoA) node. | |||
* | |||
* @deprecated Classes which inherit from this interface should move to using PoaQueryService. |
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.
nit: It's not just classes which inherit that need to migrate, also users of the interface.
* @deprecated Classes which inherit from this interface should move to using PoaQueryService. | |
* @deprecated This interface has been replaced by {@link PoaQueryService}. |
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.
reworded as below
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
|
||
public class PoAMetricServiceImpl implements PoAMetricsService { | ||
public class PoaQueryServiceImpl implements PoaQueryService { |
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.
Should also implement PoAMetricsService
.
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
final BlockInterface blockInterface = new CliqueBlockInterface(); | ||
|
||
besuContext.addService( | ||
PoaQueryService.class, new PoaQueryServiceImpl(blockInterface, blockchain)); |
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.
We should register the one implementation instance of PoaQueryServiceImpl
under both PoaQueryService
and PoaMetricsService
to preserve backwards compatibility.
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
final BlockInterface blockInterface = new IbftBlockInterface(); | ||
|
||
besuContext.addService( | ||
IbftQueryService.class, new IbftQueryServiceImpl(blockInterface, blockchain)); |
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.
We should register the one implementation instance of PoaQueryServiceImpl
under all of PoaQueryService
, PoaMetricsService
and IbftQueryService
to preserve backwards compatibility.
This ensures users who are currently using pluginContext.getService(PoaMetricsService.class)
or who want to have a plugin that works for both IBFT & Clique requesting PoaQueryService
.
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
Signed-off-by: Trent Mohay <[email protected]>
Signed-off-by: Trent Mohay <[email protected]>
Signed-off-by: Trent Mohay <[email protected]>
Signed-off-by: Trent Mohay <[email protected]>
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 haven't looked at the particular implementation details, just the plugin API changes. I'm happy they're backwards compatible now and the APIs look ok. Probably worth double checking on Poa
vs PoA
capitalisation and a couple of tweaks to comments suggested.
besuContext.addService( | ||
PoaQueryService.class, new PoaQueryServiceImpl(blockInterface, blockchain)); | ||
besuContext.addService( | ||
PoAMetricsService.class, new PoaQueryServiceImpl(blockInterface, blockchain)); |
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.
nit: we could just use the one instance.
final PoaQueryServiceImpl poaQueryServiceImpl = new PoaQueryServiceImpl(blockInterface, blockchain));
besuContext.addService(PoaQueryService.class, poaQueryServiceImpl);
besuContext.addService(PoAMetricsService.class, new PoaQueryServiceImpl(blockInterface, blockchain));
both preserve backwards compatibility correctly though.
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.
oh yeah - nicer.
besuContext.addService( | ||
IbftQueryService.class, new IbftQueryServiceImpl(blockInterface, blockchain)); | ||
besuContext.addService( | ||
PoaQueryService.class, new IbftQueryServiceImpl(blockInterface, blockchain)); | ||
besuContext.addService( | ||
PoAMetricsService.class, new IbftQueryServiceImpl(blockInterface, blockchain)); |
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.
Could use a single instance of IbftQueryServiceImpl
here too.
@@ -69,6 +70,10 @@ | |||
serviceRegistry.put(serviceType, service); | |||
} | |||
|
|||
public void addServicesFrom(final PluginServiceFactory factory) { | |||
factory.appendPluginServices(this); |
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.
nit: Why we we have this level of indirection? Wouldn't it be easier to remove this method and just call factory.appendPluginServices(besuPluginContext);
from the calling site?
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.
that is true in retrospect
import java.util.Collections; | ||
|
||
public class IbftQueryServiceImpl extends PoaQueryServiceImpl | ||
implements IbftQueryService, PoAMetricsService { |
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.
nit: You don't need to have PoAMetricsService
in the implements list here because PoaQueryServiceImpl
already implements it.
implements IbftQueryService, PoAMetricsService { | |
implements IbftQueryService { |
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
*/ | ||
@Deprecated | ||
public interface PoAMetricsService { |
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.
nit: Can we check if we're using PoA
or Poa
to make sure these new APIs match. I think Poa
is strictly right according to the style guide but looks really weird to me - I'd expect PoA
. I can live with it either way, just want to minimise inconsistency.
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 personally am in favour of Poa, then POA then finally PoA (but it doesn't conform to any recognised capitalisation that I can think of)
/** Allows for the IBFT specific aspects of the block chain to be queried from plugins. */ | ||
public interface IbftQueryService extends PoaQueryService { | ||
|
||
/** |
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.
Missing a comment describing the method. I know the @param
and @return
cover it but when JavaDoc is generated this will wind up showing as blank in the summary.
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
|
||
import java.util.Collection; | ||
|
||
/** Allows for the IBFT specific aspects of the block chain to be queried from plugins. */ |
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.
No need to mention plugins.
/** Allows for the IBFT specific aspects of the block chain to be queried from plugins. */ | |
/** Provides access to IBFT2-specific information about the blockchain. This service is only available when using IBFT2. */ |
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
*/ | ||
int getRoundNumberFrom(final BlockHeader header); | ||
|
||
/** |
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.
Needs an overview comment.
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
Backwards compatibility problems have been resolved.
Signed-off-by: Trent Mohay <[email protected]>
Signed-off-by: Trent Mohay <[email protected]>
@Override | ||
public int getRoundNumberFrom(final org.hyperledger.besu.plugin.data.BlockHeader header) { | ||
final BlockHeader headerFromChain = getHeaderFromChain(header); | ||
final IbftExtraData extraData = IbftExtraData.decode(headerFromChain); |
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.
Are we only supporting Ibft 2?
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.
Maybe slack, but as an MVP - only IBFT2 is required.
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.
Signed-off-by: Trent Mohay <[email protected]>
Signed-off-by: Trent Mohay <[email protected]>
Signed-off-by: Trent Mohay <[email protected]>
Signed-off-by: Trent Mohay <[email protected]>
Signed-off-by: Trent Mohay <[email protected]>
Updates to besu to allow for IBFT specific queries to be executed from a plugin