From b53db47dab5f509d775a681dc8aff4d477049441 Mon Sep 17 00:00:00 2001 From: daniellehrner Date: Mon, 12 Aug 2024 23:28:06 +0200 Subject: [PATCH] Wrapped WorldUpdater into `EVMWorldupdater` (#7434) * wrapped WorldUpdater into `EVMWorldupdater` to remove the authority code injection from the implementation of the actual world updaters Signed-off-by: Daniel Lehrner * add CHANGELOG entry Signed-off-by: Daniel Lehrner --------- Signed-off-by: Daniel Lehrner Co-authored-by: Justin Florentine Co-authored-by: Sally MacFarlane --- CHANGELOG.md | 1 + .../ethereum/mainnet/AuthorityProcessor.java | 20 +-- .../mainnet/MainnetTransactionProcessor.java | 34 ++--- .../PrivateMutableWorldStateUpdater.java | 20 +-- .../DiffBasedWorldStateUpdateAccumulator.java | 6 +- .../besu/evm/fluent/SimpleWorld.java | 23 +--- .../besu/evm/frame/MessageFrame.java | 36 +---- .../evm/operation/AbstractCallOperation.java | 1 - .../operation/AbstractCreateOperation.java | 1 - .../operation/AbstractExtCallOperation.java | 1 - .../evm/worldstate/AbstractWorldUpdater.java | 22 +-- .../besu/evm/worldstate/EVMWorldUpdater.java | 127 ++++++++++++++++++ .../besu/evm/worldstate/JournaledUpdater.java | 22 +-- .../besu/evm/worldstate/WorldUpdater.java | 8 -- .../hyperledger/besu/evm/toy/ToyWorld.java | 22 +-- 15 files changed, 188 insertions(+), 156 deletions(-) create mode 100644 evm/src/main/java/org/hyperledger/besu/evm/worldstate/EVMWorldUpdater.java diff --git a/CHANGELOG.md b/CHANGELOG.md index e7921fac5f..616ac3d1dc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ ### Additions and Improvements - Expose set finalized/safe block in plugin api BlockchainService. These method can be used by plugins to set finalized/safe block for a PoA network (such as QBFT, IBFT and Clique).[#7382](https://github.com/hyperledger/besu/pull/7382) - In process RPC service [#7395](https://github.com/hyperledger/besu/pull/7395) +- Wrap WorldUpdater into EVMWorldupdater [#7434](https://github.com/hyperledger/besu/pull/7434) ### Bug fixes - Correct entrypoint in Docker evmtool [#7430](https://github.com/hyperledger/besu/pull/7430) diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/AuthorityProcessor.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/AuthorityProcessor.java index c40eca0f74..1d25d2d34f 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/AuthorityProcessor.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/AuthorityProcessor.java @@ -18,8 +18,7 @@ import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.evm.account.Account; import org.hyperledger.besu.evm.account.AccountState; import org.hyperledger.besu.evm.account.MutableAccount; -import org.hyperledger.besu.evm.worldstate.AuthorizedCodeService; -import org.hyperledger.besu.evm.worldstate.WorldUpdater; +import org.hyperledger.besu.evm.worldstate.EVMWorldUpdater; import java.math.BigInteger; import java.util.Optional; @@ -38,10 +37,7 @@ public class AuthorityProcessor { } public void addContractToAuthority( - final WorldUpdater worldState, - final AuthorizedCodeService authorizedCodeService, - final Transaction transaction) { - + final EVMWorldUpdater evmWorldUpdater, final Transaction transaction) { transaction .getAuthorizationList() .get() @@ -60,7 +56,7 @@ public class AuthorityProcessor { } final Optional maybeAccount = - Optional.ofNullable(worldState.getAccount(authorityAddress)); + Optional.ofNullable(evmWorldUpdater.getAccount(authorityAddress)); final long accountNonce = maybeAccount.map(AccountState::getNonce).orElse(0L); @@ -69,12 +65,14 @@ public class AuthorityProcessor { return; } - if (authorizedCodeService.hasAuthorizedCode(authorityAddress)) { + if (evmWorldUpdater + .authorizedCodeService() + .hasAuthorizedCode(authorityAddress)) { return; } Optional codeAccount = - Optional.ofNullable(worldState.get(payload.address())); + Optional.ofNullable(evmWorldUpdater.get(payload.address())); final Bytes code; if (codeAccount.isPresent()) { code = codeAccount.get().getCode(); @@ -82,7 +80,9 @@ public class AuthorityProcessor { code = Bytes.EMPTY; } - authorizedCodeService.addAuthorizedCode(authorityAddress, code); + evmWorldUpdater + .authorizedCodeService() + .addAuthorizedCode(authorityAddress, code); })); } } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetTransactionProcessor.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetTransactionProcessor.java index cb9cd24e23..b008a8d5f6 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetTransactionProcessor.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetTransactionProcessor.java @@ -42,7 +42,7 @@ import org.hyperledger.besu.evm.frame.MessageFrame; import org.hyperledger.besu.evm.gascalculator.GasCalculator; import org.hyperledger.besu.evm.processor.AbstractMessageProcessor; import org.hyperledger.besu.evm.tracing.OperationTracer; -import org.hyperledger.besu.evm.worldstate.AuthorizedCodeService; +import org.hyperledger.besu.evm.worldstate.EVMWorldUpdater; import org.hyperledger.besu.evm.worldstate.WorldUpdater; import java.util.Deque; @@ -286,9 +286,8 @@ public class MainnetTransactionProcessor { final TransactionValidationParams transactionValidationParams, final PrivateMetadataUpdater privateMetadataUpdater, final Wei blobGasPrice) { + final EVMWorldUpdater evmWorldUpdater = new EVMWorldUpdater(worldState); try { - final AuthorizedCodeService authorizedCodeService = new AuthorizedCodeService(); - worldState.setAuthorizedCodeService(authorizedCodeService); final var transactionValidator = transactionValidatorFactory.get(); LOG.trace("Starting execution of {}", transaction); ValidationResult validationResult = @@ -306,7 +305,7 @@ public class MainnetTransactionProcessor { } final Address senderAddress = transaction.getSender(); - final MutableAccount sender = worldState.getOrCreateSenderAccount(senderAddress); + final MutableAccount sender = evmWorldUpdater.getOrCreateSenderAccount(senderAddress); validationResult = transactionValidator.validateForSender(transaction, sender, transactionValidationParams); @@ -315,7 +314,7 @@ public class MainnetTransactionProcessor { return TransactionProcessingResult.invalid(validationResult); } - operationTracer.tracePrepareTransaction(worldState, transaction); + operationTracer.tracePrepareTransaction(evmWorldUpdater, transaction); final Set
addressList = new BytesTrieSet<>(Address.SIZE); @@ -324,10 +323,8 @@ public class MainnetTransactionProcessor { throw new RuntimeException("Authority processor is required for 7702 transactions"); } - maybeAuthorityProcessor - .get() - .addContractToAuthority(worldState, authorizedCodeService, transaction); - addressList.addAll(authorizedCodeService.getAuthorities()); + maybeAuthorityProcessor.get().addContractToAuthority(evmWorldUpdater, transaction); + addressList.addAll(evmWorldUpdater.authorizedCodeService().getAuthorities()); } final long previousNonce = sender.incrementNonce(); @@ -384,8 +381,7 @@ public class MainnetTransactionProcessor { accessListGas, setCodeGas); - final WorldUpdater worldUpdater = worldState.updater(); - worldUpdater.setAuthorizedCodeService(authorizedCodeService); + final WorldUpdater worldUpdater = evmWorldUpdater.updater(); final ImmutableMap.Builder contextVariablesBuilder = ImmutableMap.builder() .put(KEY_IS_PERSISTING_PRIVATE_STATE, isPersistingPrivateState) @@ -437,12 +433,11 @@ public class MainnetTransactionProcessor { .contract(contractAddress) .inputData(initCodeBytes.slice(code.getSize())) .code(code) - .authorizedCodeService(authorizedCodeService) .build(); } else { @SuppressWarnings("OptionalGetWithoutIsPresent") // isContractCall tests isPresent final Address to = transaction.getTo().get(); - final Optional maybeContract = Optional.ofNullable(worldState.get(to)); + final Optional maybeContract = Optional.ofNullable(evmWorldUpdater.get(to)); initialFrame = commonMessageFrameBuilder .type(MessageFrame.Type.MESSAGE_CALL) @@ -453,7 +448,6 @@ public class MainnetTransactionProcessor { maybeContract .map(c -> messageCallProcessor.getCodeFromEVM(c.getCodeHash(), c.getCode())) .orElse(CodeV0.EMPTY_CODE)) - .authorizedCodeService(authorizedCodeService) .build(); } Deque messageFrameStack = initialFrame.getMessageFrameStack(); @@ -532,9 +526,9 @@ public class MainnetTransactionProcessor { operationTracer.traceBeforeRewardTransaction(worldUpdater, transaction, coinbaseWeiDelta); - final var coinbase = worldState.getOrCreate(miningBeneficiary); + final var coinbase = evmWorldUpdater.getOrCreate(miningBeneficiary); coinbase.incrementBalance(coinbaseWeiDelta); - authorizedCodeService.resetAuthorities(); + evmWorldUpdater.authorizedCodeService().resetAuthorities(); operationTracer.traceEndTransaction( worldUpdater, @@ -546,10 +540,10 @@ public class MainnetTransactionProcessor { initialFrame.getSelfDestructs(), 0L); - initialFrame.getSelfDestructs().forEach(worldState::deleteAccount); + initialFrame.getSelfDestructs().forEach(evmWorldUpdater::deleteAccount); if (clearEmptyAccounts) { - worldState.clearAccountsThatAreEmpty(); + evmWorldUpdater.clearAccountsThatAreEmpty(); } if (initialFrame.getState() == MessageFrame.State.COMPLETED_SUCCESS) { @@ -577,7 +571,7 @@ public class MainnetTransactionProcessor { } } catch (final MerkleTrieException re) { operationTracer.traceEndTransaction( - worldState.updater(), + evmWorldUpdater.updater(), transaction, false, Bytes.EMPTY, @@ -590,7 +584,7 @@ public class MainnetTransactionProcessor { throw re; } catch (final RuntimeException re) { operationTracer.traceEndTransaction( - worldState.updater(), + evmWorldUpdater.updater(), transaction, false, Bytes.EMPTY, diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/privacy/PrivateMutableWorldStateUpdater.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/privacy/PrivateMutableWorldStateUpdater.java index b4e8e28561..fc20db7f81 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/privacy/PrivateMutableWorldStateUpdater.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/privacy/PrivateMutableWorldStateUpdater.java @@ -18,7 +18,6 @@ import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.evm.account.Account; import org.hyperledger.besu.evm.account.MutableAccount; -import org.hyperledger.besu.evm.worldstate.AuthorizedCodeService; import org.hyperledger.besu.evm.worldstate.WorldUpdater; import java.util.Collection; @@ -31,39 +30,35 @@ public class PrivateMutableWorldStateUpdater implements WorldUpdater { protected final WorldUpdater publicWorldUpdater; protected final WorldUpdater privateWorldUpdater; - private AuthorizedCodeService authorizedCodeService; public PrivateMutableWorldStateUpdater( final WorldUpdater publicWorldUpdater, final WorldUpdater privateWorldUpdater) { this.publicWorldUpdater = publicWorldUpdater; this.privateWorldUpdater = privateWorldUpdater; - this.authorizedCodeService = new AuthorizedCodeService(); } @Override public MutableAccount createAccount(final Address address, final long nonce, final Wei balance) { - return authorizedCodeService.processMutableAccount( - this, privateWorldUpdater.createAccount(address, nonce, balance), address); + return privateWorldUpdater.createAccount(address, nonce, balance); } @Override public MutableAccount createAccount(final Address address) { - return authorizedCodeService.processMutableAccount( - this, privateWorldUpdater.createAccount(address), address); + return privateWorldUpdater.createAccount(address); } @Override public MutableAccount getAccount(final Address address) { final MutableAccount privateAccount = privateWorldUpdater.getAccount(address); if (privateAccount != null && !privateAccount.isEmpty()) { - return authorizedCodeService.processMutableAccount(this, privateAccount, address); + return privateAccount; } final MutableAccount publicAccount = publicWorldUpdater.getAccount(address); if (publicAccount != null && !publicAccount.isEmpty()) { publicAccount.becomeImmutable(); - return authorizedCodeService.processMutableAccount(this, publicAccount, address); + return publicAccount; } - return authorizedCodeService.processMutableAccount(this, privateAccount, address); + return privateAccount; } @Override @@ -109,9 +104,4 @@ public class PrivateMutableWorldStateUpdater implements WorldUpdater { public Optional parentUpdater() { return privateWorldUpdater.parentUpdater(); } - - @Override - public void setAuthorizedCodeService(final AuthorizedCodeService authorizedCodeService) { - this.authorizedCodeService = authorizedCodeService; - } } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/diffbased/common/worldview/accumulator/DiffBasedWorldStateUpdateAccumulator.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/diffbased/common/worldview/accumulator/DiffBasedWorldStateUpdateAccumulator.java index 0799ed3db2..c28bb731b5 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/diffbased/common/worldview/accumulator/DiffBasedWorldStateUpdateAccumulator.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/diffbased/common/worldview/accumulator/DiffBasedWorldStateUpdateAccumulator.java @@ -250,8 +250,7 @@ public abstract class DiffBasedWorldStateUpdateAccumulator(diffBasedValue.getUpdated())), address); + return track(new UpdateTrackingAccount<>(diffBasedValue.getUpdated())); } else { throw new IllegalStateException("Cannot create an account when one already exists"); } @@ -268,8 +267,7 @@ public abstract class DiffBasedWorldStateUpdateAccumulator(newAccount)), address); + return track(new UpdateTrackingAccount<>(newAccount)); } @Override diff --git a/evm/src/main/java/org/hyperledger/besu/evm/fluent/SimpleWorld.java b/evm/src/main/java/org/hyperledger/besu/evm/fluent/SimpleWorld.java index c64ca3744f..f52e788bab 100644 --- a/evm/src/main/java/org/hyperledger/besu/evm/fluent/SimpleWorld.java +++ b/evm/src/main/java/org/hyperledger/besu/evm/fluent/SimpleWorld.java @@ -18,7 +18,6 @@ import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.evm.account.Account; import org.hyperledger.besu.evm.account.MutableAccount; -import org.hyperledger.besu.evm.worldstate.AuthorizedCodeService; import org.hyperledger.besu.evm.worldstate.WorldUpdater; import java.util.Collection; @@ -35,8 +34,6 @@ public class SimpleWorld implements WorldUpdater { /** The Accounts. */ Map accounts = new HashMap<>(); - private AuthorizedCodeService authorizedCodeService; - /** Instantiates a new Simple world. */ public SimpleWorld() { this(null); @@ -49,7 +46,6 @@ public class SimpleWorld implements WorldUpdater { */ public SimpleWorld(final SimpleWorld parent) { this.parent = parent; - this.authorizedCodeService = new AuthorizedCodeService(); } @Override @@ -60,11 +56,11 @@ public class SimpleWorld implements WorldUpdater { @Override public Account get(final Address address) { if (accounts.containsKey(address)) { - return authorizedCodeService.processAccount(this, accounts.get(address), address); + return accounts.get(address); } else if (parent != null) { - return authorizedCodeService.processAccount(this, parent.get(address), address); + return parent.get(address); } else { - return authorizedCodeService.processAccount(this, null, address); + return null; } } @@ -75,14 +71,14 @@ public class SimpleWorld implements WorldUpdater { } SimpleAccount account = new SimpleAccount(address, nonce, balance); accounts.put(address, account); - return authorizedCodeService.processMutableAccount(this, account, address); + return account; } @Override public MutableAccount getAccount(final Address address) { SimpleAccount account = accounts.get(address); if (account != null) { - return authorizedCodeService.processMutableAccount(this, account, address); + return account; } Account parentAccount = parent == null ? null : parent.getAccount(address); if (parentAccount != null) { @@ -94,9 +90,9 @@ public class SimpleWorld implements WorldUpdater { parentAccount.getBalance(), parentAccount.getCode()); accounts.put(address, account); - return authorizedCodeService.processMutableAccount(this, account, address); + return account; } - return authorizedCodeService.processMutableAccount(this, null, address); + return null; } @Override @@ -136,9 +132,4 @@ public class SimpleWorld implements WorldUpdater { public Optional parentUpdater() { return Optional.ofNullable(parent); } - - @Override - public void setAuthorizedCodeService(final AuthorizedCodeService authorizedCodeService) { - this.authorizedCodeService = authorizedCodeService; - } } diff --git a/evm/src/main/java/org/hyperledger/besu/evm/frame/MessageFrame.java b/evm/src/main/java/org/hyperledger/besu/evm/frame/MessageFrame.java index fe44664d85..16551876d2 100644 --- a/evm/src/main/java/org/hyperledger/besu/evm/frame/MessageFrame.java +++ b/evm/src/main/java/org/hyperledger/besu/evm/frame/MessageFrame.java @@ -33,7 +33,6 @@ import org.hyperledger.besu.evm.internal.UnderflowException; import org.hyperledger.besu.evm.log.Log; import org.hyperledger.besu.evm.operation.BlockHashOperation.BlockHashLookup; import org.hyperledger.besu.evm.operation.Operation; -import org.hyperledger.besu.evm.worldstate.AuthorizedCodeService; import org.hyperledger.besu.evm.worldstate.WorldUpdater; import java.util.ArrayDeque; @@ -202,7 +201,6 @@ public class MessageFrame { // Global data fields. private final WorldUpdater worldUpdater; - private final AuthorizedCodeService authorizedCodeService; // Metadata fields. private final Type type; @@ -272,8 +270,7 @@ public class MessageFrame { final Consumer completer, final Map contextVariables, final Optional revertReason, - final TxValues txValues, - final AuthorizedCodeService authorizedCodeService) { + final TxValues txValues) { this.txValues = txValues; this.type = type; @@ -293,7 +290,6 @@ public class MessageFrame { this.completer = completer; this.contextVariables = contextVariables; this.revertReason = revertReason; - this.authorizedCodeService = authorizedCodeService; this.undoMark = txValues.transientStorage().mark(); } @@ -427,15 +423,6 @@ public class MessageFrame { return returnData; } - /** - * Return the authorized account service. - * - * @return the authorized account service - */ - public AuthorizedCodeService getAuthorizedCodeService() { - return authorizedCodeService; - } - /** * Set the return data. * @@ -1360,7 +1347,6 @@ public class MessageFrame { private Optional reason = Optional.empty(); private Set
accessListWarmAddresses = emptySet(); private Multimap accessListWarmStorage = HashMultimap.create(); - private AuthorizedCodeService authorizedCodeService; private Optional> versionedHashes = Optional.empty(); @@ -1645,17 +1631,6 @@ public class MessageFrame { return this; } - /** - * Sets authorized account service. - * - * @param authorizedCodeService the authorized account service - * @return the builder - */ - public Builder authorizedCodeService(final AuthorizedCodeService authorizedCodeService) { - this.authorizedCodeService = authorizedCodeService; - return this; - } - private void validate() { if (parentMessageFrame == null) { checkState(worldUpdater != null, "Missing message frame world updater"); @@ -1690,10 +1665,6 @@ public class MessageFrame { boolean newStatic; TxValues newTxValues; - if (authorizedCodeService == null) { - authorizedCodeService = new AuthorizedCodeService(); - } - if (parentMessageFrame == null) { newTxValues = new TxValues( @@ -1721,8 +1692,6 @@ public class MessageFrame { parentMessageFrame.warmUpAddress(contract); } - updater.setAuthorizedCodeService(authorizedCodeService); - MessageFrame messageFrame = new MessageFrame( type, @@ -1739,8 +1708,7 @@ public class MessageFrame { completer, contextVariables == null ? Map.of() : contextVariables, reason, - newTxValues, - authorizedCodeService); + newTxValues); newTxValues.messageFrameStack().addFirst(messageFrame); messageFrame.warmUpAddress(sender); messageFrame.warmUpAddress(contract); diff --git a/evm/src/main/java/org/hyperledger/besu/evm/operation/AbstractCallOperation.java b/evm/src/main/java/org/hyperledger/besu/evm/operation/AbstractCallOperation.java index 68ded6793e..12cb06eaa6 100644 --- a/evm/src/main/java/org/hyperledger/besu/evm/operation/AbstractCallOperation.java +++ b/evm/src/main/java/org/hyperledger/besu/evm/operation/AbstractCallOperation.java @@ -230,7 +230,6 @@ public abstract class AbstractCallOperation extends AbstractOperation { .code(code) .isStatic(isStatic(frame)) .completer(child -> complete(frame, child)) - .authorizedCodeService(frame.getAuthorizedCodeService()) .build(); // see note in stack depth check about incrementing cost frame.incrementRemainingGas(cost); diff --git a/evm/src/main/java/org/hyperledger/besu/evm/operation/AbstractCreateOperation.java b/evm/src/main/java/org/hyperledger/besu/evm/operation/AbstractCreateOperation.java index 901f7ff9de..3bc712341b 100644 --- a/evm/src/main/java/org/hyperledger/besu/evm/operation/AbstractCreateOperation.java +++ b/evm/src/main/java/org/hyperledger/besu/evm/operation/AbstractCreateOperation.java @@ -195,7 +195,6 @@ public abstract class AbstractCreateOperation extends AbstractOperation { .apparentValue(value) .code(code) .completer(child -> complete(parent, child, evm)) - .authorizedCodeService(parent.getAuthorizedCodeService()) .build(); parent.setState(MessageFrame.State.CODE_SUSPENDED); diff --git a/evm/src/main/java/org/hyperledger/besu/evm/operation/AbstractExtCallOperation.java b/evm/src/main/java/org/hyperledger/besu/evm/operation/AbstractExtCallOperation.java index e19b6cd8a2..43d7e343ff 100644 --- a/evm/src/main/java/org/hyperledger/besu/evm/operation/AbstractExtCallOperation.java +++ b/evm/src/main/java/org/hyperledger/besu/evm/operation/AbstractExtCallOperation.java @@ -180,7 +180,6 @@ public abstract class AbstractExtCallOperation extends AbstractCallOperation { .code(code) .isStatic(isStatic(frame)) .completer(child -> complete(frame, child)) - .authorizedCodeService(frame.getAuthorizedCodeService()) .build(); frame.setState(MessageFrame.State.CODE_SUSPENDED); diff --git a/evm/src/main/java/org/hyperledger/besu/evm/worldstate/AbstractWorldUpdater.java b/evm/src/main/java/org/hyperledger/besu/evm/worldstate/AbstractWorldUpdater.java index 00cd67ddb8..9623eaf89e 100644 --- a/evm/src/main/java/org/hyperledger/besu/evm/worldstate/AbstractWorldUpdater.java +++ b/evm/src/main/java/org/hyperledger/besu/evm/worldstate/AbstractWorldUpdater.java @@ -43,9 +43,6 @@ public abstract class AbstractWorldUpdater> updatedAccounts = new ConcurrentHashMap<>(); @@ -62,7 +59,6 @@ public abstract class AbstractWorldUpdater account = new UpdateTrackingAccount<>(address); account.setNonce(nonce); account.setBalance(balance); - return authorizedCodeService.processMutableAccount(this, track(account), address); + return track(account); } @Override @@ -99,12 +95,12 @@ public abstract class AbstractWorldUpdater(origin)), address); + return track(new UpdateTrackingAccount<>(origin)); } } @@ -170,11 +165,6 @@ public abstract class AbstractWorldUpdater getTouchedAccounts() { + return rootWorldUpdater.getTouchedAccounts(); + } + + @Override + public Collection
getDeletedAccountAddresses() { + return rootWorldUpdater.getDeletedAccountAddresses(); + } + + @Override + public void revert() { + rootWorldUpdater.revert(); + } + + @Override + public void commit() { + rootWorldUpdater.commit(); + } + + @Override + public Optional parentUpdater() { + return rootWorldUpdater.parentUpdater(); + } + + @Override + public WorldUpdater updater() { + return new EVMWorldUpdater(rootWorldUpdater.updater(), authorizedCodeService); + } + + @Override + public Account get(final Address address) { + return authorizedCodeService.processAccount(this, rootWorldUpdater.get(address), address); + } +} diff --git a/evm/src/main/java/org/hyperledger/besu/evm/worldstate/JournaledUpdater.java b/evm/src/main/java/org/hyperledger/besu/evm/worldstate/JournaledUpdater.java index 2497ed348d..9987a5be75 100644 --- a/evm/src/main/java/org/hyperledger/besu/evm/worldstate/JournaledUpdater.java +++ b/evm/src/main/java/org/hyperledger/besu/evm/worldstate/JournaledUpdater.java @@ -41,7 +41,6 @@ public class JournaledUpdater implements WorldUpdater { final UndoMap accounts; final UndoSet
deleted; final long undoMark; - private AuthorizedCodeService authorizedCodeService; /** * Instantiates a new Stacked updater. @@ -67,7 +66,6 @@ public class JournaledUpdater implements WorldUpdater { "WorldUpdater must be a JournaledWorldUpdater or an AbstractWorldUpdater"); } undoMark = accounts.mark(); - this.authorizedCodeService = new AuthorizedCodeService(); } /** @@ -128,18 +126,12 @@ public class JournaledUpdater implements WorldUpdater { accounts.values().forEach(JournaledAccount::markTransactionBoundary); } - @Override - public void setAuthorizedCodeService(final AuthorizedCodeService authorizedCodeService) { - this.authorizedCodeService = authorizedCodeService; - } - @Override public MutableAccount createAccount(final Address address, final long nonce, final Wei balance) { JournaledAccount journaledAccount = new JournaledAccount(rootWorld.createAccount(address, nonce, balance)); accounts.put(address, journaledAccount); - return authorizedCodeService.processMutableAccount( - this, new JournaledAccount(journaledAccount), address); + return new JournaledAccount(journaledAccount); } @Override @@ -147,7 +139,7 @@ public class JournaledUpdater implements WorldUpdater { // We may have updated it already, so check that first. final JournaledAccount existing = accounts.get(address); if (existing != null) { - return authorizedCodeService.processMutableAccount(this, existing, address); + return existing; } if (deleted.contains(address)) { return null; @@ -156,11 +148,11 @@ public class JournaledUpdater implements WorldUpdater { // Otherwise, get it from our wrapped view and create a new update tracker. final MutableAccount origin = rootWorld.getAccount(address); if (origin == null) { - return authorizedCodeService.processMutableAccount(this, null, address); + return null; } else { var newAccount = new JournaledAccount(origin); accounts.put(address, newAccount); - return authorizedCodeService.processMutableAccount(this, newAccount, address); + return newAccount; } } @@ -177,12 +169,12 @@ public class JournaledUpdater implements WorldUpdater { public Account get(final Address address) { final MutableAccount existing = accounts.get(address); if (existing != null) { - return authorizedCodeService.processAccount(this, existing, address); + return existing; } if (deleted.contains(address)) { - return authorizedCodeService.processAccount(this, null, address); + return null; } - return authorizedCodeService.processAccount(this, rootWorld.get(address), address); + return rootWorld.get(address); } @Override diff --git a/evm/src/main/java/org/hyperledger/besu/evm/worldstate/WorldUpdater.java b/evm/src/main/java/org/hyperledger/besu/evm/worldstate/WorldUpdater.java index 5144176e79..4cbda73279 100644 --- a/evm/src/main/java/org/hyperledger/besu/evm/worldstate/WorldUpdater.java +++ b/evm/src/main/java/org/hyperledger/besu/evm/worldstate/WorldUpdater.java @@ -179,12 +179,4 @@ public interface WorldUpdater extends MutableWorldView { default void markTransactionBoundary() { // default is to ignore } - - /** - * Sets the {@link AuthorizedCodeService} associated with this {@link WorldUpdater}. - * - * @param authorizedCodeService the {@link AuthorizedCodeService} to associate with this {@link - * WorldUpdater} - */ - void setAuthorizedCodeService(AuthorizedCodeService authorizedCodeService); } diff --git a/evm/src/test/java/org/hyperledger/besu/evm/toy/ToyWorld.java b/evm/src/test/java/org/hyperledger/besu/evm/toy/ToyWorld.java index 479376a8fe..e1e9c4c3ad 100644 --- a/evm/src/test/java/org/hyperledger/besu/evm/toy/ToyWorld.java +++ b/evm/src/test/java/org/hyperledger/besu/evm/toy/ToyWorld.java @@ -18,7 +18,6 @@ import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.evm.account.Account; import org.hyperledger.besu.evm.account.MutableAccount; -import org.hyperledger.besu.evm.worldstate.AuthorizedCodeService; import org.hyperledger.besu.evm.worldstate.WorldUpdater; import java.util.Collection; @@ -33,7 +32,6 @@ public class ToyWorld implements WorldUpdater { ToyWorld parent; Map accounts = new HashMap<>(); - private AuthorizedCodeService authorizedCodeService; public ToyWorld() { this(null); @@ -41,7 +39,6 @@ public class ToyWorld implements WorldUpdater { public ToyWorld(final ToyWorld parent) { this.parent = parent; - this.authorizedCodeService = new AuthorizedCodeService(); } @Override @@ -52,11 +49,11 @@ public class ToyWorld implements WorldUpdater { @Override public Account get(final Address address) { if (accounts.containsKey(address)) { - return authorizedCodeService.processAccount(this, accounts.get(address), address); + return accounts.get(address); } else if (parent != null) { - return authorizedCodeService.processAccount(this, parent.get(address), address); + return parent.get(address); } else { - return authorizedCodeService.processAccount(this, null, address); + return null; } } @@ -73,17 +70,17 @@ public class ToyWorld implements WorldUpdater { final Bytes code) { ToyAccount account = new ToyAccount(parentAccount, address, nonce, balance, code); accounts.put(address, account); - return authorizedCodeService.processMutableAccount(this, account, address); + return account; } @Override public MutableAccount getAccount(final Address address) { if (accounts.containsKey(address)) { - return authorizedCodeService.processMutableAccount(this, accounts.get(address), address); + return accounts.get(address); } else if (parent != null) { Account parentAccount = parent.getAccount(address); if (parentAccount == null) { - return authorizedCodeService.processMutableAccount(this, null, address); + return null; } else { return createAccount( parentAccount, @@ -93,7 +90,7 @@ public class ToyWorld implements WorldUpdater { parentAccount.getCode()); } } else { - return authorizedCodeService.processMutableAccount(this, null, address); + return null; } } @@ -131,9 +128,4 @@ public class ToyWorld implements WorldUpdater { public Optional parentUpdater() { return Optional.empty(); } - - @Override - public void setAuthorizedCodeService(final AuthorizedCodeService authorizedCodeService) { - this.authorizedCodeService = authorizedCodeService; - } }