Implement "pending" for qbft_getValidatorsByBlockNumber (#6436)

* Implement 'pending' for qbft_getValidatorsByBlockNumber

Signed-off-by: Matthew Whitehead <matthew1001@gmail.com>

* Update change log

Signed-off-by: Matthew Whitehead <matthew1001@gmail.com>

* Update consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftGetValidatorsByBlockNumber.java

Co-authored-by: Jason Frame <jasonwframe@gmail.com>
Signed-off-by: Matt Whitehead <matthew1001@hotmail.com>

* Refactoring

Signed-off-by: Matthew Whitehead <matthew1001@gmail.com>

---------

Signed-off-by: Matthew Whitehead <matthew1001@gmail.com>
Signed-off-by: Matt Whitehead <matthew1001@hotmail.com>
Co-authored-by: Jason Frame <jasonwframe@gmail.com>
pull/6487/head
Matt Whitehead 10 months ago committed by GitHub
parent a563cf23c1
commit 3646d78c2f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 1
      CHANGELOG.md
  2. 9
      consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftGetValidatorsByBlockNumber.java
  3. 30
      consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftGetValidatorsByBlockNumberTest.java

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

@ -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) {

@ -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<Address> addresses = Collections.singletonList(Address.ID);
final List<String> expectedOutput = Collections.singletonList(Address.ID.toString());
when(validatorProvider.getValidatorsForBlock(any())).thenReturn(addresses);
Object result = method.response(request);
assertThat(result).isInstanceOf(JsonRpcSuccessResponse.class);
assertThat(((JsonRpcSuccessResponse) result).getResult()).isEqualTo(expectedOutput);
}
@Test
public void shouldReturnListOfValidatorsFromPendingBlock() {
request =
new JsonRpcRequestContext(
new JsonRpcRequest("2.0", "qbft_getValidatorsByBlockNumber", new String[] {"pending"}));
when(blockchainQueries.headBlockHeader()).thenReturn(blockHeader);
final List<Address> addresses = Collections.singletonList(Address.ID);
final List<String> expectedOutput = Collections.singletonList(Address.ID.toString());
when(validatorProvider.getValidatorsAfterBlock(any())).thenReturn(addresses);
Object result = method.response(request);
assertThat(result).isInstanceOf(JsonRpcSuccessResponse.class);
assertThat(((JsonRpcSuccessResponse) result).getResult()).isEqualTo(expectedOutput);
}
}

Loading…
Cancel
Save