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

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

Loading…
Cancel
Save