Skip to content

Commit 9c9121a

Browse files
committed
persist accounts that have storage updates, but no nonce, balance nor code
Signed-off-by: Daniel Lehrner <daniel.lehrner@consensys.net>
1 parent 37606f2 commit 9c9121a

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetTransactionProcessor.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,6 @@ public TransactionProcessingResult processTransaction(
501501
coinbaseCalculator.price(usedGas, transactionGasPrice, blockHeader.getBaseFee());
502502

503503
coinbase.incrementBalance(coinbaseWeiDelta);
504-
authorizedCodeService.resetAuthorities();
505504

506505
operationTracer.traceEndTransaction(
507506
worldUpdater,
@@ -516,8 +515,13 @@ public TransactionProcessingResult processTransaction(
516515
initialFrame.getSelfDestructs().forEach(worldState::deleteAccount);
517516

518517
if (clearEmptyAccounts) {
519-
worldState.clearAccountsThatAreEmpty();
518+
// TODO remove for devnet-2 and later as in the new version of 7702 the nonce of the
519+
// authorities is increased
520+
// and will not be cleared anymore in case of storage change only
521+
worldState.clearAccountsThatAreEmpty(authorizedCodeService.getAuthorities());
522+
// worldState.clearAccountsThatAreEmpty();
520523
}
524+
authorizedCodeService.resetAuthorities();
521525

522526
if (initialFrame.getState() == MessageFrame.State.COMPLETED_SUCCESS) {
523527
return TransactionProcessingResult.successful(

evm/src/main/java/org/hyperledger/besu/evm/worldstate/WorldUpdater.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.util.ArrayList;
2424
import java.util.Collection;
2525
import java.util.Optional;
26+
import java.util.Set;
2627

2728
import org.apache.tuweni.bytes.Bytes;
2829

@@ -175,6 +176,19 @@ default void clearAccountsThatAreEmpty() {
175176
.stream().filter(Account::isEmpty).forEach(a -> deleteAccount(a.getAddress()));
176177
}
177178

179+
/**
180+
* Clears any accounts that are empty, excluding those in the provided set
181+
*
182+
* @param excludedAddresses the addresses to exclude from deletion
183+
*/
184+
default void clearAccountsThatAreEmpty(final Set<Address> excludedAddresses) {
185+
new ArrayList<>(getTouchedAccounts())
186+
.stream()
187+
.filter(a -> !excludedAddresses.contains(a.getAddress()))
188+
.filter(Account::isEmpty)
189+
.forEach(a -> deleteAccount(a.getAddress()));
190+
}
191+
178192
/** Mark transaction boundary. */
179193
default void markTransactionBoundary() {
180194
// default is to ignore

0 commit comments

Comments
 (0)