Skip to content

Commit

Permalink
Deeper tracing of self-destructed accounts (hyperledger#7284)
Browse files Browse the repository at this point in the history
Consider previously self-destructed accounts when creating accounts.

Signed-off-by: Danno Ferrin <danno@numisight.com>
Signed-off-by: Daniel Lehrner <daniel.lehrner@consensys.net>
  • Loading branch information
shemnon authored and daniellehrner committed Jul 16, 2024
1 parent e032b60 commit 5a72c85
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ public A getWrappedAccount() {
public void setWrappedAccount(final A account) {
if (this.account == null) {
this.account = account;
storageWasCleared = false;
} else {
throw new IllegalStateException("Already tracking a wrapped account");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,29 @@ default MutableAccount createAccount(final Address address) {
* #createAccount(Address)} (and thus all his fields will be zero/empty).
*/
default MutableAccount getOrCreate(final Address address) {
final MutableAccount account = getAccount(address);
return account == null ? createAccount(address) : account;
MutableAccount account = getAccount(address);
if (account == null) {
account = createAccount(address);
if (parentUpdater().isPresent() && parentUpdater().get().isDeleted(address)) {
account.clearStorage();
account.setCode(Bytes.EMPTY);
}
}
return account;
}

/**
* Check this and parent updaters to see if an address has been deleted since the last persist
*
* @param address address to check
* @return true if any updaters have marked the address as deleted.
*/
default boolean isDeleted(final Address address) {
if (getDeletedAccountAddresses().contains(address)) {
return true;
} else {
return parentUpdater().map(wu -> wu.isDeleted(address)).orElse(false);
}
}

/**
Expand Down

0 comments on commit 5a72c85

Please sign in to comment.