Skip to content

Commit

Permalink
Qbft RPCs should be disabled after starting with or switching to use …
Browse files Browse the repository at this point in the history
…validator contract (hyperledger#2817)

Signed-off-by: Simon Dudley <simon.dudley@consensys.net>
  • Loading branch information
siladu authored and eum602 committed Nov 3, 2023
1 parent eb70713 commit 5514ed5
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,15 @@
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.response.JsonRpcError;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse;

import java.util.Optional;

import com.google.common.collect.ImmutableMap;
import org.assertj.core.api.Assertions;
import org.junit.Test;

public abstract class AbstractVoteProposerMethodTest {
Expand Down Expand Up @@ -74,4 +77,18 @@ public void testConversionFromVoteTypeToBoolean() {

assertThat(response).isEqualToComparingFieldByField(expectedResponse);
}

@Test
public void methodNotEnabledWhenNoVoteProvider() {
final JsonRpcRequestContext request =
new JsonRpcRequestContext(
new JsonRpcRequest(JSON_RPC_VERSION, getMethodName(), new Object[] {}));
final JsonRpcResponse expectedResponse =
new JsonRpcErrorResponse(request.getRequest().getId(), JsonRpcError.METHOD_NOT_ENABLED);
when(validatorProvider.getVoteProvider()).thenReturn(Optional.empty());

final JsonRpcResponse response = getMethod().response(request);

Assertions.assertThat(response).usingRecursiveComparison().isEqualTo(expectedResponse);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) {
return new JsonRpcSuccessResponse(requestContext.getRequest().getId(), true);
} else {
return new JsonRpcErrorResponse(
requestContext.getRequest().getId(), JsonRpcError.METHOD_UNIMPLEMENTED);
requestContext.getRequest().getId(), JsonRpcError.METHOD_NOT_ENABLED);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) {
return new JsonRpcSuccessResponse(requestContext.getRequest().getId(), true);
} else {
return new JsonRpcErrorResponse(
requestContext.getRequest().getId(), JsonRpcError.METHOD_UNIMPLEMENTED);
requestContext.getRequest().getId(), JsonRpcError.METHOD_NOT_ENABLED);
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,6 @@ public Collection<Address> getValidatorsForBlock(final BlockHeader header) {

@Override
public Optional<VoteProvider> getVoteProvider() {
return Optional.of(new NoOpTransactionVoteProvider());
return Optional.empty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
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.exception.InvalidJsonRpcParameters;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcError;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse;

Expand Down Expand Up @@ -75,6 +77,18 @@ public void exceptionWhenInvalidAddressParameterSupplied() {
method.response(request);
}

@Test
public void methodNotEnabledWhenNoVoteProvider() {
final JsonRpcRequestContext request = requestWithParams(Address.fromHexString("1"));
final JsonRpcResponse expectedResponse =
new JsonRpcErrorResponse(request.getRequest().getId(), JsonRpcError.METHOD_NOT_ENABLED);
when(validatorProvider.getVoteProvider()).thenReturn(Optional.empty());

final JsonRpcResponse response = method.response(request);

assertThat(response).usingRecursiveComparison().isEqualTo(expectedResponse);
}

@Test
public void discardValidator() {
final Address parameterAddress = Address.fromHexString("1");
Expand All @@ -85,7 +99,7 @@ public void discardValidator() {

final JsonRpcResponse response = method.response(request);

assertThat(response).isEqualToComparingFieldByField(expectedResponse);
assertThat(response).usingRecursiveComparison().isEqualTo(expectedResponse);

verify(voteProvider).discardVote(parameterAddress);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
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.exception.InvalidJsonRpcParameters;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcError;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse;

Expand Down Expand Up @@ -95,6 +97,18 @@ public void exceptionWhenInvalidBoolParameterSupplied() {
method.response(request);
}

@Test
public void methodNotEnabledWhenNoVoteProvider() {
final JsonRpcRequestContext request = requestWithParams(Address.fromHexString("1"));
final JsonRpcResponse expectedResponse =
new JsonRpcErrorResponse(request.getRequest().getId(), JsonRpcError.METHOD_NOT_ENABLED);
when(validatorProvider.getVoteProvider()).thenReturn(Optional.empty());

final JsonRpcResponse response = method.response(request);

assertThat(response).usingRecursiveComparison().isEqualTo(expectedResponse);
}

@Test
public void addValidator() {
final Address parameterAddress = Address.fromHexString("1");
Expand All @@ -104,7 +118,7 @@ public void addValidator() {

final JsonRpcResponse response = method.response(request);

assertThat(response).isEqualToComparingFieldByField(expectedResponse);
assertThat(response).usingRecursiveComparison().isEqualTo(expectedResponse);

verify(voteProvider).authVote(parameterAddress);
}
Expand All @@ -118,7 +132,7 @@ public void removeValidator() {

final JsonRpcResponse response = method.response(request);

assertThat(response).isEqualToComparingFieldByField(expectedResponse);
assertThat(response).usingRecursiveComparison().isEqualTo(expectedResponse);

verify(voteProvider).dropVote(parameterAddress);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,12 @@ public void validatorsMustBeSorted() {
validators.stream().sorted().collect(Collectors.toList());
assertThat(result).containsExactlyElementsOf(expectedValidators);
}

@Test
public void voteProviderIsEmpty() {
TransactionValidatorProvider transactionValidatorProvider =
new TransactionValidatorProvider(blockChain, validatorContractController);

assertThat(transactionValidatorProvider.getVoteProvider()).isEmpty();
}
}

0 comments on commit 5514ed5

Please sign in to comment.