Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,22 @@
public class BonsaiValue<T> implements TrieLog.LogTuple<T> {
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
Expand All @@ -54,18 +58,27 @@ public BonsaiValue<T> setPrior(final T prior) {
}

public BonsaiValue<T> 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
Expand All @@ -76,7 +89,7 @@ public String toString() {
+ ", updated="
+ updated
+ ", cleared="
+ cleared
+ lastStepCleared
+ '}';
}

Expand All @@ -90,14 +103,18 @@ 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();
}

@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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ public static <T> void writeInnerRlp(
} else {
writer.accept(output, value.getUpdated());
}
if (!value.isCleared()) {
if (!value.isLastStepCleared()) {
output.writeNull();
} else {
output.writeInt(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ public UInt256 getPriorStorageValue(final Address address, final UInt256 storage
if (localAccountStorage != null) {
final BonsaiValue<UInt256> value = localAccountStorage.get(storageSlotKey);
if (value != null) {
if (value.isCleared()) {
if (value.isLastStepCleared()) {
return UInt256.ZERO;
}
final UInt256 updated = value.getUpdated();
Expand Down
2 changes: 1 addition & 1 deletion plugin-api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}