Sync status permissioning check conditional on onchain permissioning enabled (#1269)

* only check sync status if onchain node permissioning config is enabled

Signed-off-by: Sally MacFarlane <sally.macfarlane@consensys.net>
pull/1271/head
Sally MacFarlane 4 years ago committed by GitHub
parent 55994b53f6
commit 80efed914d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 24
      ethereum/permissioning/src/main/java/org/hyperledger/besu/ethereum/permissioning/NodePermissioningControllerFactory.java
  2. 2
      ethereum/permissioning/src/main/java/org/hyperledger/besu/ethereum/permissioning/node/InsufficientPeersPermissioningProvider.java
  3. 34
      ethereum/permissioning/src/test/java/org/hyperledger/besu/ethereum/permissioning/node/NodePermissioningControllerFactoryTest.java

@ -43,7 +43,7 @@ public class NodePermissioningControllerFactory {
final TransactionSimulator transactionSimulator, final TransactionSimulator transactionSimulator,
final MetricsSystem metricsSystem) { final MetricsSystem metricsSystem) {
Optional<SyncStatusNodePermissioningProvider> syncStatusProviderOptional; final Optional<SyncStatusNodePermissioningProvider> syncStatusProviderOptional;
List<NodePermissioningProvider> providers = new ArrayList<>(); List<NodePermissioningProvider> providers = new ArrayList<>();
if (permissioningConfiguration.getLocalConfig().isPresent()) { if (permissioningConfiguration.getLocalConfig().isPresent()) {
@ -60,17 +60,20 @@ public class NodePermissioningControllerFactory {
} }
} }
if (permissioningConfiguration.getSmartContractConfig().isPresent()) { if (permissioningConfiguration.getSmartContractConfig().isPresent()
SmartContractPermissioningConfiguration smartContractPermissioningConfiguration = && permissioningConfiguration
permissioningConfiguration.getSmartContractConfig().get(); .getSmartContractConfig()
if (smartContractPermissioningConfiguration.isSmartContractNodeAllowlistEnabled()) { .get()
.isSmartContractNodeAllowlistEnabled()) {
NodeSmartContractPermissioningController smartContractProvider = NodeSmartContractPermissioningController smartContractProvider =
new NodeSmartContractPermissioningController( new NodeSmartContractPermissioningController(
smartContractPermissioningConfiguration.getNodeSmartContractAddress(), permissioningConfiguration
.getSmartContractConfig()
.get()
.getNodeSmartContractAddress(),
transactionSimulator, transactionSimulator,
metricsSystem); metricsSystem);
providers.add(smartContractProvider); providers.add(smartContractProvider);
}
if (fixedNodes.isEmpty()) { if (fixedNodes.isEmpty()) {
syncStatusProviderOptional = Optional.empty(); syncStatusProviderOptional = Optional.empty();
@ -86,7 +89,14 @@ public class NodePermissioningControllerFactory {
NodePermissioningController nodePermissioningController = NodePermissioningController nodePermissioningController =
new NodePermissioningController(syncStatusProviderOptional, providers); new NodePermissioningController(syncStatusProviderOptional, providers);
permissioningConfiguration
.getSmartContractConfig()
.ifPresent(
config -> {
if (config.isSmartContractNodeAllowlistEnabled()) {
validatePermissioningContract(nodePermissioningController); validatePermissioningContract(nodePermissioningController);
}
});
return nodePermissioningController; return nodePermissioningController;
} }

@ -37,7 +37,7 @@ public class InsufficientPeersPermissioningProvider implements ContextualNodePer
* Creates the provider observing the provided p2p network * Creates the provider observing the provided p2p network
* *
* @param p2pNetwork the p2p network to observe * @param p2pNetwork the p2p network to observe
* @param bootnodeEnodes the bootnodes that this node is configured to connection to * @param bootnodeEnodes the bootnodes that this node is configured to connect to
*/ */
public InsufficientPeersPermissioningProvider( public InsufficientPeersPermissioningProvider(
final P2PNetwork p2pNetwork, final Collection<EnodeURL> bootnodeEnodes) { final P2PNetwork p2pNetwork, final Collection<EnodeURL> bootnodeEnodes) {

@ -127,6 +127,40 @@ public class NodePermissioningControllerFactoryTest {
assertThat(controller.getSyncStatusNodePermissioningProvider()).isNotPresent(); assertThat(controller.getSyncStatusNodePermissioningProvider()).isNotPresent();
} }
@Test
public void
testCreateWithLocalNodePermissioningEnabledAndSmartContractPresentButDisabledAndBootnode() {
smartContractPermissioningConfiguration = new SmartContractPermissioningConfiguration();
smartContractPermissioningConfiguration.setNodeSmartContractAddress(
Address.fromHexString("0x0000000000000000000000000000000000001234"));
smartContractPermissioningConfiguration.setSmartContractNodeAllowlistEnabled(false);
final Collection<EnodeURL> fixedNodes = Collections.singleton(selfEnode);
localPermissioningConfig = LocalPermissioningConfiguration.createDefault();
localPermissioningConfig.setNodeAllowlist(Collections.emptyList());
localPermissioningConfig.setNodePermissioningConfigFilePath("fake-file-path");
config =
new PermissioningConfiguration(
Optional.of(localPermissioningConfig),
Optional.of(smartContractPermissioningConfiguration));
NodePermissioningControllerFactory factory = new NodePermissioningControllerFactory();
NodePermissioningController controller =
factory.create(
config,
synchronizer,
fixedNodes,
selfEnode.getNodeId(),
transactionSimulator,
new NoOpMetricsSystem());
List<NodePermissioningProvider> providers = controller.getProviders();
assertThat(providers.size()).isEqualTo(1);
NodePermissioningProvider p1 = providers.get(0);
assertThat(p1).isInstanceOf(NodeLocalConfigPermissioningController.class);
assertThat(controller.getSyncStatusNodePermissioningProvider()).isNotPresent();
}
@Test @Test
public void testCreateWithLocalNodeAndSmartContractPermissioningEnabled() { public void testCreateWithLocalNodeAndSmartContractPermissioningEnabled() {
localPermissioningConfig = LocalPermissioningConfiguration.createDefault(); localPermissioningConfig = LocalPermissioningConfiguration.createDefault();

Loading…
Cancel
Save