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

Commit

Permalink
Enable private Tx capability to IBFT
Browse files Browse the repository at this point in the history
  • Loading branch information
Puneetha17 committed Mar 20, 2019
1 parent 25b3a49 commit 63f2517
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
import tech.pegasys.pantheon.ethereum.core.Hash;
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.ethereum.mainnet.ProtocolSchedule;
Expand Down Expand Up @@ -258,7 +259,7 @@ private static ControllerAndState createControllerAndFinalState(
genesisConfigOptions.byzantiumBlock(0);

final ProtocolSchedule<IbftContext> protocolSchedule =
IbftProtocolSchedule.create(genesisConfigOptions);
IbftProtocolSchedule.create(genesisConfigOptions, PrivacyParameters.noPrivacy());

/////////////////////////////////////////////////////////////////////////////////////
// From here down is BASICALLY taken from IbftPantheonController
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,16 @@ public class IbftProtocolSchedule {

private static final int DEFAULT_CHAIN_ID = 1;

public static ProtocolSchedule<IbftContext> create(final GenesisConfigOptions config) {
public static ProtocolSchedule<IbftContext> create(
final GenesisConfigOptions config, final PrivacyParameters privacyParameters) {
final IbftConfigOptions ibftConfig = config.getIbftLegacyConfigOptions();
final long blockPeriod = ibftConfig.getBlockPeriodSeconds();

return new ProtocolScheduleBuilder<>(
config,
DEFAULT_CHAIN_ID,
builder -> applyIbftChanges(blockPeriod, builder),
PrivacyParameters.noPrivacy())
privacyParameters)
.createProtocolSchedule();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import tech.pegasys.pantheon.ethereum.core.BlockHeader;
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.Wei;
import tech.pegasys.pantheon.ethereum.mainnet.BlockHeaderValidator;
import tech.pegasys.pantheon.ethereum.mainnet.HeaderValidationMode;
Expand Down Expand Up @@ -71,7 +72,8 @@ public void createdBlockPassesValidationRulesAndHasAppropriateHashAndMixHash() {
final ProtocolSchedule<IbftContext> protocolSchedule =
IbftProtocolSchedule.create(
GenesisConfigFile.fromConfig("{\"config\": {\"spuriousDragonBlock\":0}}")
.getConfigOptions());
.getConfigOptions(),
PrivacyParameters.noPrivacy());
final ProtocolContext<IbftContext> protContext =
new ProtocolContext<>(
blockchain,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,16 @@ public class IbftProtocolSchedule {

private static final int DEFAULT_CHAIN_ID = 1;

public static ProtocolSchedule<IbftContext> create(final GenesisConfigOptions config) {
public static ProtocolSchedule<IbftContext> create(
final GenesisConfigOptions config, final PrivacyParameters privacyParameters) {
final IbftConfigOptions ibftConfig = config.getIbftLegacyConfigOptions();
final long blockPeriod = ibftConfig.getBlockPeriodSeconds();

return new ProtocolScheduleBuilder<>(
config,
DEFAULT_CHAIN_ID,
builder -> applyIbftChanges(blockPeriod, builder),
PrivacyParameters.noPrivacy())
privacyParameters)
.createProtocolSchedule();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import tech.pegasys.pantheon.ethereum.core.BlockHeaderTestFixture;
import tech.pegasys.pantheon.ethereum.core.Hash;
import tech.pegasys.pantheon.ethereum.core.PendingTransactions;
import tech.pegasys.pantheon.ethereum.core.PrivacyParameters;
import tech.pegasys.pantheon.ethereum.core.Wei;
import tech.pegasys.pantheon.ethereum.mainnet.BlockHeaderValidator;
import tech.pegasys.pantheon.ethereum.mainnet.HeaderValidationMode;
Expand Down Expand Up @@ -77,7 +78,8 @@ public void headerProducedPassesValidationRules() {
final ProtocolSchedule<IbftContext> protocolSchedule =
IbftProtocolSchedule.create(
GenesisConfigFile.fromConfig("{\"config\": {\"spuriousDragonBlock\":0}}")
.getConfigOptions());
.getConfigOptions(),
PrivacyParameters.noPrivacy());
final ProtocolContext<IbftContext> protContext =
new ProtocolContext<>(
blockchain,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public class IbftLegacyPantheonController implements PantheonController<IbftCont
private final KeyPair keyPair;
private final TransactionPool transactionPool;
private final Runnable closer;
private final PrivacyParameters privacyParameters;

private IbftLegacyPantheonController(
final ProtocolSchedule<IbftContext> protocolSchedule,
Expand All @@ -80,6 +81,7 @@ private IbftLegacyPantheonController(
final Synchronizer synchronizer,
final KeyPair keyPair,
final TransactionPool transactionPool,
final PrivacyParameters privacyParameters,
final Runnable closer) {

this.protocolSchedule = protocolSchedule;
Expand All @@ -90,6 +92,7 @@ private IbftLegacyPantheonController(
this.synchronizer = synchronizer;
this.keyPair = keyPair;
this.transactionPool = transactionPool;
this.privacyParameters = privacyParameters;
this.closer = closer;
}

Expand All @@ -102,9 +105,10 @@ static PantheonController<IbftContext> init(
final Path dataDirectory,
final MetricsSystem metricsSystem,
final Clock clock,
final int maxPendingTransactions) {
final int maxPendingTransactions,
final PrivacyParameters privacyParameters) {
final ProtocolSchedule<IbftContext> protocolSchedule =
IbftProtocolSchedule.create(genesisConfig.getConfigOptions());
IbftProtocolSchedule.create(genesisConfig.getConfigOptions(), privacyParameters);
final GenesisState genesisState = GenesisState.fromConfig(genesisConfig, protocolSchedule);
final IbftConfigOptions ibftConfig =
genesisConfig.getConfigOptions().getIbftLegacyConfigOptions();
Expand Down Expand Up @@ -162,6 +166,9 @@ static PantheonController<IbftContext> init(
() -> {
try {
storageProvider.close();
if (privacyParameters.isEnabled()) {
privacyParameters.getPrivateStorageProvider().close();
}
} catch (final IOException e) {
LOG.error("Failed to close storage provider", e);
}
Expand All @@ -184,6 +191,7 @@ static PantheonController<IbftContext> init(
synchronizer,
nodeKeys,
transactionPool,
privacyParameters,
closer);
}

Expand Down Expand Up @@ -230,7 +238,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 @@ -104,6 +104,7 @@ public class IbftPantheonController implements PantheonController<IbftContext> {
private final TransactionPool transactionPool;
private final MiningCoordinator ibftMiningCoordinator;
private final Runnable closer;
private final PrivacyParameters privacyParameters;

private IbftPantheonController(
final ProtocolSchedule<IbftContext> protocolSchedule,
Expand All @@ -116,6 +117,7 @@ private IbftPantheonController(
final KeyPair keyPair,
final TransactionPool transactionPool,
final MiningCoordinator ibftMiningCoordinator,
final PrivacyParameters privacyParameters,
final Runnable closer) {
this.protocolSchedule = protocolSchedule;
this.context = context;
Expand All @@ -127,6 +129,7 @@ private IbftPantheonController(
this.keyPair = keyPair;
this.transactionPool = transactionPool;
this.ibftMiningCoordinator = ibftMiningCoordinator;
this.privacyParameters = privacyParameters;
this.closer = closer;
}

Expand All @@ -140,9 +143,10 @@ static PantheonController<IbftContext> init(
final Path dataDirectory,
final MetricsSystem metricsSystem,
final Clock clock,
final int maxPendingTransactions) {
final int maxPendingTransactions,
final PrivacyParameters privacyParameters) {
final ProtocolSchedule<IbftContext> protocolSchedule =
IbftProtocolSchedule.create(genesisConfig.getConfigOptions());
IbftProtocolSchedule.create(genesisConfig.getConfigOptions(), privacyParameters);
final GenesisState genesisState = GenesisState.fromConfig(genesisConfig, protocolSchedule);

final BlockInterface blockInterface = new IbftBlockInterface();
Expand Down Expand Up @@ -299,6 +303,9 @@ static PantheonController<IbftContext> init(
}
try {
storageProvider.close();
if (privacyParameters.isEnabled()) {
privacyParameters.getPrivateStorageProvider().close();
}
} catch (final IOException e) {
LOG.error("Failed to close storage provider", e);
}
Expand All @@ -315,6 +322,7 @@ static PantheonController<IbftContext> init(
nodeKeys,
transactionPool,
ibftMiningCoordinator,
privacyParameters,
closer);
}

Expand Down Expand Up @@ -362,7 +370,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 @@ -82,7 +82,8 @@ static PantheonController<?> fromConfig(
dataDirectory,
metricsSystem,
clock,
maxPendingTransactions);
maxPendingTransactions,
privacyParameters);
} else if (configOptions.isIbftLegacy()) {
return IbftLegacyPantheonController.init(
storageProvider,
Expand All @@ -93,7 +94,8 @@ static PantheonController<?> fromConfig(
dataDirectory,
metricsSystem,
clock,
maxPendingTransactions);
maxPendingTransactions,
privacyParameters);
} else if (configOptions.isClique()) {
return CliquePantheonController.init(
storageProvider,
Expand Down

0 comments on commit 63f2517

Please sign in to comment.