Skip to content
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

Merged
merged 18 commits into from
Oct 31, 2019
Merged

Ibft queries #138

merged 18 commits into from
Oct 31, 2019

Conversation

rain-on
Copy link
Contributor

@rain-on rain-on commented Oct 25, 2019

Updates to besu to allow for IBFT specific queries to be executed from a plugin

@rain-on rain-on requested a review from usmansaleem October 25, 2019 05:49
Signed-off-by: Trent Mohay <[email protected]>
Signed-off-by: Trent Mohay <[email protected]>
besuController.getProtocolContext().getBlockchain());
besuPluginContext.addService(PoAMetricsService.class, service);
if (consensusState != null) {
if (IbftContext.class.isAssignableFrom(consensusState.getClass())) {
Copy link
Contributor

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.

Copy link
Contributor Author

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 {
Copy link
Contributor

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.

Copy link
Contributor Author

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();
Copy link
Contributor

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]>
Copy link
Member

@usmansaleem usmansaleem left a 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]>
Copy link
Member

@usmansaleem usmansaleem left a 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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo - Addresses

Copy link
Contributor Author

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.
Copy link
Contributor

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 {
Copy link
Contributor

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.

Copy link
Contributor Author

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.
Copy link
Contributor

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.

Suggested change
* @deprecated Classes which inherit from this interface should move to using PoaQueryService.
* @deprecated This interface has been replaced by {@link PoaQueryService}.

Copy link
Contributor Author

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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should also implement PoAMetricsService.

Copy link
Contributor Author

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));
Copy link
Contributor

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.

Copy link
Contributor Author

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));
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Trent Mohay added 4 commits October 30, 2019 12:53
Signed-off-by: Trent Mohay <[email protected]>
Signed-off-by: Trent Mohay <[email protected]>
Signed-off-by: Trent Mohay <[email protected]>
Copy link
Contributor

@ajsutton ajsutton left a 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.

Comment on lines 37 to 40
besuContext.addService(
PoaQueryService.class, new PoaQueryServiceImpl(blockInterface, blockchain));
besuContext.addService(
PoAMetricsService.class, new PoaQueryServiceImpl(blockInterface, blockchain));
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh yeah - nicer.

Comment on lines 38 to 43
besuContext.addService(
IbftQueryService.class, new IbftQueryServiceImpl(blockInterface, blockchain));
besuContext.addService(
PoaQueryService.class, new IbftQueryServiceImpl(blockInterface, blockchain));
besuContext.addService(
PoAMetricsService.class, new IbftQueryServiceImpl(blockInterface, blockchain));
Copy link
Contributor

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);
Copy link
Contributor

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?

Copy link
Contributor Author

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 {
Copy link
Contributor

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.

Suggested change
implements IbftQueryService, PoAMetricsService {
implements IbftQueryService {

Copy link
Contributor Author

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 {
Copy link
Contributor

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.

Copy link
Contributor Author

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 {

/**
Copy link
Contributor

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.

Copy link
Contributor Author

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. */
Copy link
Contributor

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.

Suggested change
/** 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. */

Copy link
Contributor Author

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);

/**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs an overview comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@ajsutton ajsutton dismissed their stale review October 30, 2019 04:45

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);
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

@mark-terry mark-terry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@rain-on rain-on merged commit 38462bb into hyperledger:master Oct 31, 2019
@rain-on rain-on deleted the ibft_queries branch October 31, 2019 22:22
@gconnect gconnect mentioned this pull request Sep 18, 2024
8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants