Skip to content
This repository has been archived by the owner on Sep 26, 2019. It is now read-only.

[PRIV-28] Enable private Tx capability to Clique #1102

Merged
merged 2 commits into from
Mar 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ public class CliqueProtocolSchedule {
private static final int DEFAULT_CHAIN_ID = 4;

public static ProtocolSchedule<CliqueContext> create(
final GenesisConfigOptions config, final KeyPair nodeKeys) {
final GenesisConfigOptions config,
final KeyPair nodeKeys,
final PrivacyParameters privacyParameters) {

final CliqueConfigOptions cliqueConfig = config.getCliqueConfigOptions();

Expand All @@ -48,7 +50,7 @@ public static ProtocolSchedule<CliqueContext> create(
builder ->
applyCliqueSpecificModifications(
epochManager, cliqueConfig.getBlockPeriodSeconds(), localNodeAddress, builder),
PrivacyParameters.noPrivacy())
privacyParameters)
.createProtocolSchedule();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import tech.pegasys.pantheon.config.GenesisConfigFile;
import tech.pegasys.pantheon.config.GenesisConfigOptions;
import tech.pegasys.pantheon.crypto.SECP256K1.KeyPair;
import tech.pegasys.pantheon.ethereum.core.PrivacyParameters;
import tech.pegasys.pantheon.ethereum.core.Wei;
import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSchedule;
import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSpec;
Expand All @@ -41,7 +42,7 @@ public void protocolSpecsAreCreatedAtBlockDefinedInJson() {

final GenesisConfigOptions config = GenesisConfigFile.fromConfig(jsonInput).getConfigOptions();
final ProtocolSchedule<CliqueContext> protocolSchedule =
CliqueProtocolSchedule.create(config, NODE_KEYS);
CliqueProtocolSchedule.create(config, NODE_KEYS, PrivacyParameters.noPrivacy());

final ProtocolSpec<CliqueContext> homesteadSpec = protocolSchedule.getByBlockNumber(1);
final ProtocolSpec<CliqueContext> tangerineWhistleSpec = protocolSchedule.getByBlockNumber(2);
Expand All @@ -56,7 +57,10 @@ public void protocolSpecsAreCreatedAtBlockDefinedInJson() {
@Test
public void parametersAlignWithMainnetWithAdjustments() {
final ProtocolSpec<CliqueContext> homestead =
CliqueProtocolSchedule.create(GenesisConfigFile.DEFAULT.getConfigOptions(), NODE_KEYS)
CliqueProtocolSchedule.create(
GenesisConfigFile.DEFAULT.getConfigOptions(),
NODE_KEYS,
PrivacyParameters.noPrivacy())
.getByBlockNumber(0);

assertThat(homestead.getName()).isEqualTo("Frontier");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import tech.pegasys.pantheon.ethereum.core.BlockBody;
import tech.pegasys.pantheon.ethereum.core.BlockHeaderTestFixture;
import tech.pegasys.pantheon.ethereum.core.PendingTransactions;
import tech.pegasys.pantheon.ethereum.core.PrivacyParameters;
import tech.pegasys.pantheon.ethereum.core.Util;
import tech.pegasys.pantheon.ethereum.core.Wei;
import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSchedule;
Expand Down Expand Up @@ -72,7 +73,9 @@ public class CliqueBlockCreatorTest {
public void setup() {
protocolSchedule =
CliqueProtocolSchedule.create(
GenesisConfigFile.DEFAULT.getConfigOptions(), proposerKeyPair);
GenesisConfigFile.DEFAULT.getConfigOptions(),
proposerKeyPair,
PrivacyParameters.noPrivacy());

final Address otherAddress = Util.publicKeyToAddress(otherKeyPair.getPublicKey());
validatorList.add(otherAddress);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import tech.pegasys.pantheon.ethereum.core.BlockHeaderTestFixture;
import tech.pegasys.pantheon.ethereum.core.MiningParameters;
import tech.pegasys.pantheon.ethereum.core.PendingTransactions;
import tech.pegasys.pantheon.ethereum.core.PrivacyParameters;
import tech.pegasys.pantheon.ethereum.core.Util;
import tech.pegasys.pantheon.ethereum.core.Wei;
import tech.pegasys.pantheon.testutil.TestClock;
Expand Down Expand Up @@ -86,7 +87,8 @@ public void extraDataCreatedOnEpochBlocksContainsValidators() {
new CliqueMinerExecutor(
cliqueProtocolContext,
Executors.newSingleThreadExecutor(),
CliqueProtocolSchedule.create(GENESIS_CONFIG_OPTIONS, proposerKeyPair),
CliqueProtocolSchedule.create(
GENESIS_CONFIG_OPTIONS, proposerKeyPair, PrivacyParameters.noPrivacy()),
new PendingTransactions(1, TestClock.fixed()),
proposerKeyPair,
new MiningParameters(AddressHelpers.ofValue(1), Wei.ZERO, wrappedVanityData, false),
Expand Down Expand Up @@ -116,7 +118,8 @@ public void extraDataForNonEpochBlocksDoesNotContainValidaors() {
new CliqueMinerExecutor(
cliqueProtocolContext,
Executors.newSingleThreadExecutor(),
CliqueProtocolSchedule.create(GENESIS_CONFIG_OPTIONS, proposerKeyPair),
CliqueProtocolSchedule.create(
GENESIS_CONFIG_OPTIONS, proposerKeyPair, PrivacyParameters.noPrivacy()),
new PendingTransactions(1, TestClock.fixed()),
proposerKeyPair,
new MiningParameters(AddressHelpers.ofValue(1), Wei.ZERO, wrappedVanityData, false),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public class CliquePantheonController implements PantheonController<CliqueContex
private final Runnable closer;

private final MiningCoordinator miningCoordinator;
private final PrivacyParameters privacyParameters;

private CliquePantheonController(
final ProtocolSchedule<CliqueContext> protocolSchedule,
Expand All @@ -89,6 +90,7 @@ private CliquePantheonController(
final KeyPair keyPair,
final TransactionPool transactionPool,
final MiningCoordinator miningCoordinator,
final PrivacyParameters privacyParameters,
final Runnable closer) {

this.protocolSchedule = protocolSchedule;
Expand All @@ -100,6 +102,7 @@ private CliquePantheonController(
this.transactionPool = transactionPool;
this.closer = closer;
this.miningCoordinator = miningCoordinator;
this.privacyParameters = privacyParameters;
}

static PantheonController<CliqueContext> init(
Expand All @@ -112,7 +115,8 @@ static PantheonController<CliqueContext> init(
final Path dataDirectory,
final MetricsSystem metricsSystem,
final Clock clock,
final int maxPendingTransactions) {
final int maxPendingTransactions,
final PrivacyParameters privacyParameters) {
final Address localAddress = Util.publicKeyToAddress(nodeKeys.getPublicKey());
final CliqueConfigOptions cliqueConfig =
genesisConfig.getConfigOptions().getCliqueConfigOptions();
Expand All @@ -121,7 +125,8 @@ static PantheonController<CliqueContext> init(

final EpochManager epochManager = new EpochManager(blocksPerEpoch);
final ProtocolSchedule<CliqueContext> protocolSchedule =
CliqueProtocolSchedule.create(genesisConfig.getConfigOptions(), nodeKeys);
CliqueProtocolSchedule.create(
genesisConfig.getConfigOptions(), nodeKeys, privacyParameters);
final GenesisState genesisState = GenesisState.fromConfig(genesisConfig, protocolSchedule);

final ProtocolContext<CliqueContext> protocolContext =
Expand Down Expand Up @@ -208,6 +213,7 @@ static PantheonController<CliqueContext> init(
nodeKeys,
transactionPool,
miningCoordinator,
privacyParameters,
() -> {
miningCoordinator.disable();
minerThreadPool.shutdownNow();
Expand All @@ -218,6 +224,9 @@ static PantheonController<CliqueContext> init(
}
try {
storageProvider.close();
if (privacyParameters.isEnabled()) {
privacyParameters.getPrivateStorageProvider().close();
}
} catch (final IOException e) {
LOG.error("Failed to close storage provider", e);
}
Expand Down Expand Up @@ -266,7 +275,7 @@ public MiningCoordinator getMiningCoordinator() {

@Override
public PrivacyParameters getPrivacyParameters() {
return PrivacyParameters.noPrivacy();
return privacyParameters;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ static PantheonController<?> fromConfig(
dataDirectory,
metricsSystem,
clock,
maxPendingTransactions);
maxPendingTransactions,
privacyParameters);
} else {
throw new IllegalArgumentException("Unknown consensus mechanism defined");
}
Expand Down