Fix trielog shipping issue during self destruct (#6340)

* fix trielog shipping issue

Signed-off-by: Karim Taam <karim.t2am@gmail.com>
pull/6347/head
Karim TAAM 11 months ago committed by GitHub
parent 09977ccfe2
commit 2ac9bf8e93
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 39
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/bonsai/BonsaiValue.java
  2. 2
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/bonsai/trielog/TrieLogFactoryImpl.java
  3. 2
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/bonsai/worldview/BonsaiWorldStateUpdateAccumulator.java
  4. 2
      plugin-api/build.gradle
  5. 13
      plugin-api/src/main/java/org/hyperledger/besu/plugin/services/trielogs/TrieLog.java

@ -24,18 +24,22 @@ import org.apache.commons.lang3.builder.HashCodeBuilder;
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
@ -54,18 +58,27 @@ public class BonsaiValue<T> implements TrieLog.LogTuple<T> {
}
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
@ -76,7 +89,7 @@ public class BonsaiValue<T> implements TrieLog.LogTuple<T> {
+ ", updated="
+ updated
+ ", cleared="
+ cleared
+ lastStepCleared
+ '}';
}
@ -90,7 +103,7 @@ public class BonsaiValue<T> implements TrieLog.LogTuple<T> {
}
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 class BonsaiValue<T> implements TrieLog.LogTuple<T> {
@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();
}
}

@ -248,7 +248,7 @@ public class TrieLogFactoryImpl implements TrieLogFactory {
} else {
writer.accept(output, value.getUpdated());
}
if (!value.isCleared()) {
if (!value.isLastStepCleared()) {
output.writeNull();
} else {
output.writeInt(1);

@ -459,7 +459,7 @@ public class BonsaiWorldStateUpdateAccumulator
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();

@ -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')

@ -167,10 +167,17 @@ public interface TrieLog {
}
/**
* 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();
}
}

Loading…
Cancel
Save