forked from hyperledger/besu
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create a QbftMetricsService (hyperledger#1861)
Enables QBFT metrics to be exported to an API for reading via a plugin. Signed-off-by: Trent Mohay <[email protected]>
- Loading branch information
Showing
8 changed files
with
209 additions
and
14 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
besu/src/main/java/org/hyperledger/besu/controller/BftQueryPluginServiceFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Copyright 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. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package org.hyperledger.besu.controller; | ||
|
||
import org.hyperledger.besu.consensus.common.BlockInterface; | ||
import org.hyperledger.besu.consensus.common.bft.BftBlockInterface; | ||
import org.hyperledger.besu.consensus.common.bft.queries.BftQueryServiceImpl; | ||
import org.hyperledger.besu.crypto.NodeKey; | ||
import org.hyperledger.besu.ethereum.chain.Blockchain; | ||
import org.hyperledger.besu.plugin.services.metrics.PoAMetricsService; | ||
import org.hyperledger.besu.plugin.services.query.BftQueryService; | ||
import org.hyperledger.besu.plugin.services.query.PoaQueryService; | ||
import org.hyperledger.besu.services.BesuPluginContextImpl; | ||
|
||
public class BftQueryPluginServiceFactory implements PluginServiceFactory { | ||
|
||
private final Blockchain blockchain; | ||
private final NodeKey nodeKey; | ||
private final String consensusMechanismName; | ||
|
||
public BftQueryPluginServiceFactory( | ||
final Blockchain blockchain, final NodeKey nodeKey, final String consensusMechanismName) { | ||
this.blockchain = blockchain; | ||
this.nodeKey = nodeKey; | ||
this.consensusMechanismName = consensusMechanismName; | ||
} | ||
|
||
@Override | ||
public void appendPluginServices(final BesuPluginContextImpl besuContext) { | ||
final BlockInterface blockInterface = new BftBlockInterface(); | ||
|
||
final BftQueryServiceImpl service = | ||
new BftQueryServiceImpl(blockInterface, blockchain, nodeKey, consensusMechanismName); | ||
besuContext.addService(BftQueryService.class, service); | ||
besuContext.addService(PoaQueryService.class, service); | ||
besuContext.addService(PoAMetricsService.class, service); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
.../src/main/java/org/hyperledger/besu/consensus/common/bft/queries/BftQueryServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* Copyright 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. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package org.hyperledger.besu.consensus.common.bft.queries; | ||
|
||
import org.hyperledger.besu.consensus.common.BlockInterface; | ||
import org.hyperledger.besu.consensus.common.PoaQueryServiceImpl; | ||
import org.hyperledger.besu.consensus.common.bft.BftBlockHashing; | ||
import org.hyperledger.besu.consensus.common.bft.BftExtraData; | ||
import org.hyperledger.besu.crypto.NodeKey; | ||
import org.hyperledger.besu.ethereum.chain.Blockchain; | ||
import org.hyperledger.besu.ethereum.core.BlockHeader; | ||
import org.hyperledger.besu.ethereum.core.Hash; | ||
import org.hyperledger.besu.plugin.data.Address; | ||
import org.hyperledger.besu.plugin.services.query.BftQueryService; | ||
|
||
import java.util.Collection; | ||
import java.util.Collections; | ||
|
||
import org.apache.tuweni.bytes.Bytes32; | ||
|
||
public class BftQueryServiceImpl extends PoaQueryServiceImpl implements BftQueryService { | ||
|
||
private final String consensusMechanismName; | ||
|
||
public BftQueryServiceImpl( | ||
final BlockInterface blockInterface, | ||
final Blockchain blockchain, | ||
final NodeKey nodeKey, | ||
final String consensusMechanismName) { | ||
super(blockInterface, blockchain, nodeKey); | ||
this.consensusMechanismName = consensusMechanismName; | ||
} | ||
|
||
@Override | ||
public int getRoundNumberFrom(final org.hyperledger.besu.plugin.data.BlockHeader header) { | ||
final BlockHeader headerFromChain = getHeaderFromChain(header); | ||
final BftExtraData extraData = BftExtraData.decode(headerFromChain); | ||
return extraData.getRound(); | ||
} | ||
|
||
@Override | ||
public Collection<Address> getSignersFrom( | ||
final org.hyperledger.besu.plugin.data.BlockHeader header) { | ||
final BlockHeader headerFromChain = getHeaderFromChain(header); | ||
final BftExtraData extraData = BftExtraData.decode(headerFromChain); | ||
|
||
return Collections.unmodifiableList( | ||
BftBlockHashing.recoverCommitterAddresses(headerFromChain, extraData)); | ||
} | ||
|
||
@Override | ||
public String getConsensusMechanismName() { | ||
return consensusMechanismName; | ||
} | ||
|
||
private BlockHeader getHeaderFromChain( | ||
final org.hyperledger.besu.plugin.data.BlockHeader header) { | ||
if (header instanceof BlockHeader) { | ||
return (BlockHeader) header; | ||
} | ||
|
||
final Hash blockHash = Hash.wrap(Bytes32.wrap(header.getBlockHash().toArray())); | ||
return getBlockchain().getBlockHeader(blockHash).orElseThrow(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
plugin-api/src/main/java/org/hyperledger/besu/plugin/services/query/BftQueryService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright 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. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package org.hyperledger.besu.plugin.services.query; | ||
|
||
import org.hyperledger.besu.plugin.data.Address; | ||
import org.hyperledger.besu.plugin.data.BlockHeader; | ||
|
||
import java.util.Collection; | ||
|
||
/** Allows for the BFT specific aspects of the block chain to be queried. */ | ||
public interface BftQueryService extends PoaQueryService { | ||
|
||
/** | ||
* Extracts the round number from the supplied header and returns it to the caller. | ||
* | ||
* @param header the block header from which the round number is to be extracted | ||
* @return The number of failed rounds executed prior to adding the block to the chain. | ||
*/ | ||
int getRoundNumberFrom(final BlockHeader header); | ||
|
||
/** | ||
* Extracts the collection of signers from the supplied block header and returns them to the | ||
* caller. | ||
* | ||
* @param header the block header from which a list of signers is to be extracted | ||
* @return The addresses of | ||
*/ | ||
Collection<Address> getSignersFrom(final BlockHeader header); | ||
|
||
/** | ||
* Returns the literal name of the BFT consensus mechanism is use (eg ibft or qbft), which forms | ||
* the prefix for all BFT metrics. | ||
* | ||
* @return The name of the consensus mechanism being used by Besu | ||
*/ | ||
String getConsensusMechanismName(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters