diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/bonsai/BonsaiValue.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/bonsai/BonsaiValue.java index 5d14c882750..c4f8ab0efd0 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/bonsai/BonsaiValue.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/bonsai/BonsaiValue.java @@ -24,18 +24,22 @@ public class BonsaiValue implements TrieLog.LogTuple { private T prior; private T updated; - private boolean cleared; + private boolean lastStepCleared; + + private boolean clearedAtLeastOnce; public BonsaiValue(final T prior, final T updated) { this.prior = prior; this.updated = updated; - this.cleared = false; + this.lastStepCleared = false; + this.clearedAtLeastOnce = false; } - public BonsaiValue(final T prior, final T updated, final boolean cleared) { + public BonsaiValue(final T prior, final T updated, final boolean lastStepCleared) { this.prior = prior; this.updated = updated; - this.cleared = cleared; + this.lastStepCleared = lastStepCleared; + this.clearedAtLeastOnce = lastStepCleared; } @Override @@ -54,18 +58,27 @@ public BonsaiValue setPrior(final T prior) { } public BonsaiValue setUpdated(final T updated) { - this.cleared = updated == null; + this.lastStepCleared = updated == null; + if (lastStepCleared) { + this.clearedAtLeastOnce = true; + } this.updated = updated; return this; } public void setCleared() { - this.cleared = true; + this.lastStepCleared = true; + this.clearedAtLeastOnce = true; + } + + @Override + public boolean isLastStepCleared() { + return lastStepCleared; } @Override - public boolean isCleared() { - return cleared; + public boolean isClearedAtLeastOnce() { + return clearedAtLeastOnce; } @Override @@ -76,7 +89,7 @@ public String toString() { + ", updated=" + updated + ", cleared=" - + cleared + + lastStepCleared + '}'; } @@ -90,7 +103,7 @@ public boolean equals(final Object o) { } BonsaiValue that = (BonsaiValue) o; return new EqualsBuilder() - .append(cleared, that.cleared) + .append(lastStepCleared, that.lastStepCleared) .append(prior, that.prior) .append(updated, that.updated) .isEquals(); @@ -98,6 +111,10 @@ public boolean equals(final Object o) { @Override public int hashCode() { - return new HashCodeBuilder(17, 37).append(prior).append(updated).append(cleared).toHashCode(); + return new HashCodeBuilder(17, 37) + .append(prior) + .append(updated) + .append(lastStepCleared) + .toHashCode(); } } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/bonsai/trielog/TrieLogFactoryImpl.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/bonsai/trielog/TrieLogFactoryImpl.java index 36a6510c91e..2915a671820 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/bonsai/trielog/TrieLogFactoryImpl.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/bonsai/trielog/TrieLogFactoryImpl.java @@ -248,7 +248,7 @@ public static void writeInnerRlp( } else { writer.accept(output, value.getUpdated()); } - if (!value.isCleared()) { + if (!value.isLastStepCleared()) { output.writeNull(); } else { output.writeInt(1); diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/bonsai/worldview/BonsaiWorldStateUpdateAccumulator.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/bonsai/worldview/BonsaiWorldStateUpdateAccumulator.java index 1c8cf159168..9f0dd07d3b1 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/bonsai/worldview/BonsaiWorldStateUpdateAccumulator.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/bonsai/worldview/BonsaiWorldStateUpdateAccumulator.java @@ -459,7 +459,7 @@ public UInt256 getPriorStorageValue(final Address address, final UInt256 storage if (localAccountStorage != null) { final BonsaiValue value = localAccountStorage.get(storageSlotKey); if (value != null) { - if (value.isCleared()) { + if (value.isLastStepCleared()) { return UInt256.ZERO; } final UInt256 updated = value.getUpdated(); diff --git a/plugin-api/build.gradle b/plugin-api/build.gradle index 4ce23dfe351..d271094604d 100644 --- a/plugin-api/build.gradle +++ b/plugin-api/build.gradle @@ -69,7 +69,7 @@ Calculated : ${currentHash} tasks.register('checkAPIChanges', FileStateChecker) { description = "Checks that the API for the Plugin-API project does not change without deliberate thought" files = sourceSets.main.allJava.files - knownHash = 'nB1LhUpMWYFQpBdNJ/3Q79c8kLgUgPmEFzlRMlLUl1Y=' + knownHash = 'N583pqJipDs4kJkgL0cPq9PBsYdsLzvUlu2I8Kk+w7g=' } check.dependsOn('checkAPIChanges') diff --git a/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/trielogs/TrieLog.java b/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/trielogs/TrieLog.java index 1a763ade96e..9bfe505fb1c 100644 --- a/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/trielogs/TrieLog.java +++ b/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/trielogs/TrieLog.java @@ -167,10 +167,17 @@ default boolean isUnchanged() { } /** - * Checks if the updated value represents a cleared state. + * Checks if the last step performed a 'clear'. * - * @return true if the updated value is cleared, false otherwise + * @return true if the last step performed a 'clear', false otherwise. */ - boolean isCleared(); + boolean isLastStepCleared(); + + /** + * Checks if a 'clear' has been performed at least once. + * + * @return true if a 'clear' has been performed at least once, false otherwise. + */ + boolean isClearedAtLeastOnce(); } }