diff --git a/CHANGELOG.md b/CHANGELOG.md index 39aec2f15f..e37654c305 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -46,6 +46,7 @@ - Upgrade Mockito [#6397](https://github.com/hyperledger/besu/pull/6397) - Upgrade `tech.pegasys.discovery:discovery` [#6414](https://github.com/hyperledger/besu/pull/6414) - Options to tune the max allowed time that can be spent selecting transactions during block creation are now stable [#6423](https://github.com/hyperledger/besu/pull/6423) +- Support for "pending" in `qbft_getValidatorsByBlockNumber` [#6436](https://github.com/hyperledger/besu/pull/6436) ### Bug fixes - INTERNAL_ERROR from `eth_estimateGas` JSON/RPC calls [#6344](https://github.com/hyperledger/besu/issues/6344) diff --git a/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftGetValidatorsByBlockNumber.java b/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftGetValidatorsByBlockNumber.java index 6210d97bbb..804ecc6b5a 100644 --- a/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftGetValidatorsByBlockNumber.java +++ b/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftGetValidatorsByBlockNumber.java @@ -53,6 +53,15 @@ public class QbftGetValidatorsByBlockNumber extends AbstractBlockParameterMethod return request.getRequiredParameter(0, BlockParameter.class); } + @Override + protected Object pendingResult(final JsonRpcRequestContext request) { + final BlockHeader blockHeader = getBlockchainQueries().headBlockHeader(); + LOG.trace("Received RPC rpcName={} block={}", getName(), blockHeader.getNumber()); + return validatorProvider.getValidatorsAfterBlock(blockHeader).stream() + .map(Address::toString) + .collect(Collectors.toList()); + } + @Override protected Object resultByBlockNumber( final JsonRpcRequestContext request, final long blockNumber) { diff --git a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftGetValidatorsByBlockNumberTest.java b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftGetValidatorsByBlockNumberTest.java index b2e1c2b3d4..a0235723bf 100644 --- a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftGetValidatorsByBlockNumberTest.java +++ b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftGetValidatorsByBlockNumberTest.java @@ -23,6 +23,7 @@ import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequest; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.BlockParameter; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; import org.hyperledger.besu.ethereum.core.BlockHeader; @@ -73,4 +74,33 @@ public class QbftGetValidatorsByBlockNumberTest { Object result = method.resultByBlockNumber(request, 12); assertThat(result).isEqualTo(expectedOutput); } + + @Test + public void shouldReturnListOfValidatorsFromLatestBlock() { + request = + new JsonRpcRequestContext( + new JsonRpcRequest("2.0", "qbft_getValidatorsByBlockNumber", new String[] {"latest"})); + when(blockchainQueries.headBlockNumber()).thenReturn(12L); + when(blockchainQueries.getBlockHeaderByNumber(12)).thenReturn(Optional.of(blockHeader)); + final List
addresses = Collections.singletonList(Address.ID); + final List