[REFACTOR] Clearly Separate Common MessageFrame Fields (#1652)

Signed-off-by: Ratan Rai Sur <ratan.r.sur@gmail.com>
pull/1654/head
Ratan (Rai) Sur 4 years ago committed by GitHub
parent 021ce8ee04
commit e8facd0f1c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 75
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetTransactionProcessor.java
  2. 74
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/privacy/PrivateTransactionProcessor.java

@ -16,6 +16,7 @@ package org.hyperledger.besu.ethereum.mainnet;
import org.hyperledger.besu.ethereum.chain.Blockchain; import org.hyperledger.besu.ethereum.chain.Blockchain;
import org.hyperledger.besu.ethereum.core.Account; import org.hyperledger.besu.ethereum.core.Account;
import org.hyperledger.besu.ethereum.core.AccountState;
import org.hyperledger.besu.ethereum.core.Address; import org.hyperledger.besu.ethereum.core.Address;
import org.hyperledger.besu.ethereum.core.EvmAccount; import org.hyperledger.besu.ethereum.core.EvmAccount;
import org.hyperledger.besu.ethereum.core.Gas; import org.hyperledger.besu.ethereum.core.Gas;
@ -295,75 +296,55 @@ public class MainnetTransactionProcessor {
intrinsicGas); intrinsicGas);
final WorldUpdater worldUpdater = worldState.updater(); final WorldUpdater worldUpdater = worldState.updater();
final MessageFrame initialFrame;
final Deque<MessageFrame> messageFrameStack = new ArrayDeque<>(); final Deque<MessageFrame> messageFrameStack = new ArrayDeque<>();
final ReturnStack returnStack = new ReturnStack(); final MessageFrame.Builder commonMessageFrameBuilder =
MessageFrame.builder()
.messageFrameStack(messageFrameStack)
.maxStackSize(maxStackSize)
.returnStack(new ReturnStack())
.blockchain(blockchain)
.worldState(worldUpdater.updater())
.initialGas(gasAvailable)
.originator(senderAddress)
.gasPrice(transactionGasPrice)
.sender(senderAddress)
.value(transaction.getValue())
.apparentValue(transaction.getValue())
.blockHeader(blockHeader)
.depth(0)
.completer(__ -> {})
.miningBeneficiary(miningBeneficiary)
.blockHashLookup(blockHashLookup)
.isPersistingPrivateState(isPersistingPrivateState)
.transactionHash(transaction.getHash())
.privateMetadataUpdater(privateMetadataUpdater);
final MessageFrame initialFrame;
if (transaction.isContractCreation()) { if (transaction.isContractCreation()) {
final Address contractAddress = final Address contractAddress =
Address.contractAddress(senderAddress, sender.getNonce() - 1L); Address.contractAddress(senderAddress, sender.getNonce() - 1L);
initialFrame = initialFrame =
MessageFrame.builder() commonMessageFrameBuilder
.type(MessageFrame.Type.CONTRACT_CREATION) .type(MessageFrame.Type.CONTRACT_CREATION)
.messageFrameStack(messageFrameStack)
.returnStack(returnStack)
.blockchain(blockchain)
.worldState(worldUpdater.updater())
.initialGas(gasAvailable)
.address(contractAddress) .address(contractAddress)
.originator(senderAddress)
.contract(contractAddress) .contract(contractAddress)
.contractAccountVersion(createContractAccountVersion) .contractAccountVersion(createContractAccountVersion)
.gasPrice(transactionGasPrice)
.inputData(Bytes.EMPTY) .inputData(Bytes.EMPTY)
.sender(senderAddress)
.value(transaction.getValue())
.apparentValue(transaction.getValue())
.code(new Code(transaction.getPayload())) .code(new Code(transaction.getPayload()))
.blockHeader(blockHeader)
.depth(0)
.completer(c -> {})
.miningBeneficiary(miningBeneficiary)
.blockHashLookup(blockHashLookup)
.isPersistingPrivateState(isPersistingPrivateState)
.maxStackSize(maxStackSize)
.transactionHash(transaction.getHash())
.privateMetadataUpdater(privateMetadataUpdater)
.build(); .build();
} else { } else {
final Address to = transaction.getTo().get(); final Address to = transaction.getTo().get();
final Account contract = worldState.get(to); final Optional<Account> maybeContract = Optional.ofNullable(worldState.get(to));
initialFrame = initialFrame =
MessageFrame.builder() commonMessageFrameBuilder
.type(MessageFrame.Type.MESSAGE_CALL) .type(MessageFrame.Type.MESSAGE_CALL)
.messageFrameStack(messageFrameStack)
.returnStack(returnStack)
.blockchain(blockchain)
.worldState(worldUpdater.updater())
.initialGas(gasAvailable)
.address(to) .address(to)
.originator(senderAddress)
.contract(to) .contract(to)
.contractAccountVersion( .contractAccountVersion(
contract != null ? contract.getVersion() : Account.DEFAULT_VERSION) maybeContract.map(AccountState::getVersion).orElse(Account.DEFAULT_VERSION))
.gasPrice(transactionGasPrice)
.inputData(transaction.getPayload()) .inputData(transaction.getPayload())
.sender(senderAddress) .code(new Code(maybeContract.map(AccountState::getCode).orElse(Bytes.EMPTY)))
.value(transaction.getValue())
.apparentValue(transaction.getValue())
.code(new Code(contract != null ? contract.getCode() : Bytes.EMPTY))
.blockHeader(blockHeader)
.depth(0)
.completer(c -> {})
.miningBeneficiary(miningBeneficiary)
.blockHashLookup(blockHashLookup)
.maxStackSize(maxStackSize)
.isPersistingPrivateState(isPersistingPrivateState)
.transactionHash(transaction.getHash())
.privateMetadataUpdater(privateMetadataUpdater)
.build(); .build();
} }

@ -16,6 +16,7 @@ package org.hyperledger.besu.ethereum.privacy;
import org.hyperledger.besu.ethereum.chain.Blockchain; import org.hyperledger.besu.ethereum.chain.Blockchain;
import org.hyperledger.besu.ethereum.core.Account; import org.hyperledger.besu.ethereum.core.Account;
import org.hyperledger.besu.ethereum.core.AccountState;
import org.hyperledger.besu.ethereum.core.Address; import org.hyperledger.besu.ethereum.core.Address;
import org.hyperledger.besu.ethereum.core.EvmAccount; import org.hyperledger.besu.ethereum.core.EvmAccount;
import org.hyperledger.besu.ethereum.core.Gas; import org.hyperledger.besu.ethereum.core.Gas;
@ -40,6 +41,7 @@ import org.hyperledger.besu.ethereum.worldstate.DefaultMutablePrivateWorldStateU
import java.util.ArrayDeque; import java.util.ArrayDeque;
import java.util.Deque; import java.util.Deque;
import java.util.Optional;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
@ -122,14 +124,30 @@ public class PrivateTransactionProcessor {
previousNonce, previousNonce,
sender.getNonce()); sender.getNonce());
final MessageFrame initialFrame;
final Deque<MessageFrame> messageFrameStack = new ArrayDeque<>();
final WorldUpdater mutablePrivateWorldStateUpdater = final WorldUpdater mutablePrivateWorldStateUpdater =
new DefaultMutablePrivateWorldStateUpdater(publicWorldState, privateWorldState); new DefaultMutablePrivateWorldStateUpdater(publicWorldState, privateWorldState);
final Deque<MessageFrame> messageFrameStack = new ArrayDeque<>();
final MessageFrame.Builder commonMessageFrameBuilder =
MessageFrame.builder()
.messageFrameStack(messageFrameStack)
.maxStackSize(maxStackSize)
.returnStack(new ReturnStack())
.blockchain(blockchain)
.worldState(mutablePrivateWorldStateUpdater)
.initialGas(Gas.MAX_VALUE)
.originator(senderAddress)
.gasPrice(transaction.getGasPrice())
.sender(senderAddress)
.value(transaction.getValue())
.apparentValue(transaction.getValue())
.blockHeader(blockHeader)
.depth(0)
.completer(__ -> {})
.miningBeneficiary(miningBeneficiary)
.blockHashLookup(blockHashLookup)
.transactionHash(pmtHash);
final ReturnStack returnStack = new ReturnStack(); final MessageFrame initialFrame;
if (transaction.isContractCreation()) { if (transaction.isContractCreation()) {
final Address privateContractAddress = final Address privateContractAddress =
Address.privateContractAddress(senderAddress, previousNonce, privacyGroupId); Address.privateContractAddress(senderAddress, previousNonce, privacyGroupId);
@ -142,62 +160,26 @@ public class PrivateTransactionProcessor {
privacyGroupId.toString()); privacyGroupId.toString());
initialFrame = initialFrame =
MessageFrame.builder() commonMessageFrameBuilder
.type(MessageFrame.Type.CONTRACT_CREATION) .type(MessageFrame.Type.CONTRACT_CREATION)
.messageFrameStack(messageFrameStack)
.returnStack(returnStack)
.blockchain(blockchain)
.worldState(mutablePrivateWorldStateUpdater)
.address(privateContractAddress) .address(privateContractAddress)
.originator(senderAddress)
.contract(privateContractAddress) .contract(privateContractAddress)
.contractAccountVersion(createContractAccountVersion) .contractAccountVersion(createContractAccountVersion)
.initialGas(Gas.MAX_VALUE)
.gasPrice(transaction.getGasPrice())
.inputData(Bytes.EMPTY) .inputData(Bytes.EMPTY)
.sender(senderAddress)
.value(transaction.getValue())
.apparentValue(transaction.getValue())
.code(new Code(transaction.getPayload())) .code(new Code(transaction.getPayload()))
.blockHeader(blockHeader)
.depth(0)
.completer(c -> {})
.miningBeneficiary(miningBeneficiary)
.blockHashLookup(blockHashLookup)
.maxStackSize(maxStackSize)
.transactionHash(pmtHash)
.build(); .build();
} else { } else {
final Address to = transaction.getTo().get(); final Address to = transaction.getTo().get();
final Account contract = privateWorldState.get(to); final Optional<Account> maybeContract = Optional.ofNullable(privateWorldState.get(to));
initialFrame = initialFrame =
MessageFrame.builder() commonMessageFrameBuilder
.type(MessageFrame.Type.MESSAGE_CALL) .type(MessageFrame.Type.MESSAGE_CALL)
.messageFrameStack(messageFrameStack)
.returnStack(returnStack)
.blockchain(blockchain)
.worldState(mutablePrivateWorldStateUpdater)
.address(to) .address(to)
.originator(senderAddress)
.contract(to) .contract(to)
.contractAccountVersion( .contractAccountVersion(
contract != null ? contract.getVersion() : Account.DEFAULT_VERSION) maybeContract.map(AccountState::getVersion).orElse(Account.DEFAULT_VERSION))
.initialGas(Gas.MAX_VALUE)
.gasPrice(transaction.getGasPrice())
.inputData(transaction.getPayload()) .inputData(transaction.getPayload())
.sender(senderAddress) .code(new Code(maybeContract.map(AccountState::getCode).orElse(Bytes.EMPTY)))
.value(transaction.getValue())
.apparentValue(transaction.getValue())
.code(new Code(contract != null ? contract.getCode() : Bytes.EMPTY))
.blockHeader(blockHeader)
.depth(0)
.completer(c -> {})
.miningBeneficiary(miningBeneficiary)
.blockHashLookup(blockHashLookup)
.maxStackSize(maxStackSize)
.transactionHash(pmtHash)
.build(); .build();
} }

Loading…
Cancel
Save