GetPrivateWorldState refactor (#2042)

Signed-off-by: Mark Terry <mark.terry@consensys.net>
pull/2053/head
mark-terry 4 years ago committed by GitHub
parent 6dc740e4ec
commit bf54b6c0b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/MainnetBlockValidator.java
  2. 22
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/goquorum/GoQuorumBlockValidator.java
  3. 17
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/goquorum/GoQuorumPrivateStateUtil.java
  4. 8
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetProtocolSpecs.java
  5. 5
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/transaction/TransactionSimulator.java
  6. 6
      ethereum/core/src/test/java/org/hyperledger/besu/ethereum/MainnetBlockValidatorTest.java
  7. 3
      ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/NoRewardProtocolScheduleWrapper.java

@ -20,7 +20,6 @@ import org.hyperledger.besu.ethereum.chain.BadBlockManager;
import org.hyperledger.besu.ethereum.chain.MutableBlockchain;
import org.hyperledger.besu.ethereum.core.Block;
import org.hyperledger.besu.ethereum.core.BlockHeader;
import org.hyperledger.besu.ethereum.core.GoQuorumPrivacyParameters;
import org.hyperledger.besu.ethereum.core.MutableWorldState;
import org.hyperledger.besu.ethereum.core.TransactionReceipt;
import org.hyperledger.besu.ethereum.mainnet.BlockBodyValidator;
@ -48,8 +47,7 @@ public class MainnetBlockValidator implements BlockValidator {
final BlockHeaderValidator blockHeaderValidator,
final BlockBodyValidator blockBodyValidator,
final BlockProcessor blockProcessor,
final BadBlockManager badBlockManager,
final Optional<GoQuorumPrivacyParameters> goQuorumPrivacyParameters) {
final BadBlockManager badBlockManager) {
this.blockHeaderValidator = blockHeaderValidator;
this.blockBodyValidator = blockBodyValidator;
this.blockProcessor = blockProcessor;

@ -26,14 +26,12 @@ import org.hyperledger.besu.ethereum.mainnet.BlockBodyValidator;
import org.hyperledger.besu.ethereum.mainnet.BlockHeaderValidator;
import org.hyperledger.besu.ethereum.mainnet.BlockProcessor;
import org.hyperledger.besu.ethereum.mainnet.BlockProcessor.Result;
import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive;
import java.util.Optional;
public class GoQuorumBlockValidator extends MainnetBlockValidator {
private final GoQuorumPrivateStorage goQuorumPrivateStorage;
private final WorldStateArchive goQuorumWorldStateArchive;
private final Optional<GoQuorumPrivacyParameters> goQuorumPrivacyParameters;
public GoQuorumBlockValidator(
final BlockHeaderValidator blockHeaderValidator,
@ -41,31 +39,21 @@ public class GoQuorumBlockValidator extends MainnetBlockValidator {
final BlockProcessor blockProcessor,
final BadBlockManager badBlockManager,
final Optional<GoQuorumPrivacyParameters> goQuorumPrivacyParameters) {
super(
blockHeaderValidator,
blockBodyValidator,
blockProcessor,
badBlockManager,
goQuorumPrivacyParameters);
super(blockHeaderValidator, blockBodyValidator, blockProcessor, badBlockManager);
this.goQuorumPrivacyParameters = goQuorumPrivacyParameters;
if (!(blockProcessor instanceof GoQuorumBlockProcessor)) {
throw new IllegalStateException(
"GoQuorumBlockValidator requires an instance of GoQuorumBlockProcessor");
}
goQuorumPrivateStorage = goQuorumPrivacyParameters.orElseThrow().privateStorage();
goQuorumWorldStateArchive = goQuorumPrivacyParameters.orElseThrow().worldStateArchive();
}
@Override
protected Result processBlock(
final ProtocolContext context, final MutableWorldState worldState, final Block block) {
final MutableWorldState privateWorldState =
getPrivateWorldState(
goQuorumPrivateStorage,
goQuorumWorldStateArchive,
worldState.rootHash(),
block.getHash());
getPrivateWorldState(goQuorumPrivacyParameters, worldState.rootHash(), block.getHash());
return ((GoQuorumBlockProcessor) blockProcessor)
.processBlock(context.getBlockchain(), worldState, privateWorldState, block);

@ -30,22 +30,21 @@ import org.apache.logging.log4j.Logger;
public class GoQuorumPrivateStateUtil {
private static final Logger LOG = getLogger();
public static MutableWorldState getPrivateWorldState(
public static MutableWorldState getPrivateWorldStateAtBlock(
final Optional<GoQuorumPrivacyParameters> goQuorumPrivacyParameters,
final BlockHeader header) {
final GoQuorumPrivateStorage goQuorumPrivateStorage =
goQuorumPrivacyParameters.orElseThrow().privateStorage();
final WorldStateArchive goQuorumWorldStateArchive =
goQuorumPrivacyParameters.orElseThrow().worldStateArchive();
return getPrivateWorldState(
goQuorumPrivateStorage, goQuorumWorldStateArchive, header.getStateRoot(), header.getHash());
return getPrivateWorldState(goQuorumPrivacyParameters, header.getStateRoot(), header.getHash());
}
public static MutableWorldState getPrivateWorldState(
final GoQuorumPrivateStorage goQuorumPrivateStorage,
final WorldStateArchive goQuorumWorldStateArchive,
final Optional<GoQuorumPrivacyParameters> goQuorumPrivacyParameters,
final Hash worldStateRootHash,
final Hash publicBlockHash) {
final GoQuorumPrivateStorage goQuorumPrivateStorage =
goQuorumPrivacyParameters.orElseThrow().privateStorage();
final WorldStateArchive goQuorumWorldStateArchive =
goQuorumPrivacyParameters.orElseThrow().worldStateArchive();
final Hash privateStateRootHash =
goQuorumPrivateStorage
.getPrivateStateRootHash(worldStateRootHash)

@ -171,7 +171,13 @@ public abstract class MainnetProtocolSpecs {
if (goQuorumMode) {
return GoQuorumBlockValidator::new;
} else {
return MainnetBlockValidator::new;
return (blockHeaderValidator,
blockBodyValidator,
blockProcessor,
badBlockManager,
goQuorumPrivacyParameters) ->
new MainnetBlockValidator(
blockHeaderValidator, blockBodyValidator, blockProcessor, badBlockManager);
}
}

@ -14,7 +14,7 @@
*/
package org.hyperledger.besu.ethereum.transaction;
import static org.hyperledger.besu.ethereum.goquorum.GoQuorumPrivateStateUtil.getPrivateWorldState;
import static org.hyperledger.besu.ethereum.goquorum.GoQuorumPrivateStateUtil.getPrivateWorldStateAtBlock;
import org.hyperledger.besu.crypto.SECPSignature;
import org.hyperledger.besu.crypto.SignatureAlgorithm;
@ -206,7 +206,8 @@ public class TransactionSimulator {
&& maybePrivacyParameters.get().getGoQuorumPrivacyParameters().isPresent()) {
final MutableWorldState privateWorldState =
getPrivateWorldState(maybePrivacyParameters.get().getGoQuorumPrivacyParameters(), header);
getPrivateWorldStateAtBlock(
maybePrivacyParameters.get().getGoQuorumPrivacyParameters(), header);
return new GoQuorumMutablePrivateAndPublicWorldStateUpdater(
publicWorldState.updater(), privateWorldState.updater());
}

@ -63,11 +63,7 @@ public class MainnetBlockValidatorTest {
when(protocolContext.getWorldStateArchive()).thenReturn(worldStateArchive);
mainnetBlockValidator =
new MainnetBlockValidator(
blockHeaderValidator,
blockBodyValidator,
blockProcessor,
badBlockManager,
Optional.empty());
blockHeaderValidator, blockBodyValidator, blockProcessor, badBlockManager);
badBlock =
new BlockDataGenerator()
.block(

@ -56,8 +56,7 @@ public class NoRewardProtocolScheduleWrapper implements ProtocolSchedule {
original.getBlockHeaderValidator(),
original.getBlockBodyValidator(),
noRewardBlockProcessor,
original.getBadBlocksManager(),
Optional.empty());
original.getBadBlocksManager());
final BlockImporter noRewardBlockImporter = new MainnetBlockImporter(noRewardBlockValidator);
return new ProtocolSpec(
original.getName(),

Loading…
Cancel
Save