Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep Worldstate Storage open for Bonsai archive latest layer #5039

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
* remove unnecessary worldstate copy in txpool
* unsubscribe from worldstatestorage on close of BonsaiLayeredWorldState
* minor txpool logging improvements

Signed-off-by: garyschulte <garyschulte@gmail.com>
  • Loading branch information
garyschulte committed Feb 3, 2023
commit f6a890050e2a9b27970a8b0b9609c9a684469359
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
import org.apache.tuweni.units.bigints.UInt256;

/** A World State backed first by trie log layer and then by another world state. */
public class BonsaiLayeredWorldState implements MutableWorldState, BonsaiWorldView, WorldState, BonsaiStorageSubscriber {
public class BonsaiLayeredWorldState
implements MutableWorldState, BonsaiWorldView, WorldState, BonsaiStorageSubscriber {
private Optional<BonsaiWorldView> nextWorldView;
private final AtomicLong worldStateSubscription;
protected final long height;
Expand All @@ -64,11 +65,13 @@ public class BonsaiLayeredWorldState implements MutableWorldState, BonsaiWorldVi
this.height = height;
this.worldStateRootHash = worldStateRootHash;
this.trieLog = trieLog;
this.worldStateSubscription = new AtomicLong(nextWorldView
.filter(world -> world instanceof BonsaiPersistedWorldState)
.map(BonsaiPersistedWorldState.class::cast)
.map(ws -> ws.worldStateStorage.subscribe(this))
.orElse(Long.MAX_VALUE));
this.worldStateSubscription =
new AtomicLong(
nextWorldView
.filter(world -> world instanceof BonsaiPersistedWorldState)
.map(BonsaiPersistedWorldState.class::cast)
.map(ws -> ws.worldStateStorage.subscribe(this))
.orElse(Long.MAX_VALUE));
}

public Optional<BonsaiWorldView> getNextWorldView() {
Expand All @@ -89,12 +92,18 @@ public void setNextWorldView(final Optional<BonsaiWorldView> nextWorldView) {

private void maybeUnSubscribe() {
if (worldStateSubscription.get() != Long.MAX_VALUE) {
nextWorldView.map(BonsaiPersistedWorldState.class::cast)
.ifPresent(ws -> ws.worldStateStorage.unSubscribe(worldStateSubscription.get()));
nextWorldView
.map(BonsaiPersistedWorldState.class::cast)
.ifPresent(ws -> ws.worldStateStorage.unSubscribe(worldStateSubscription.get()));
worldStateSubscription.set(Long.MAX_VALUE);
}
}

@Override
public void close() throws Exception {
maybeUnSubscribe();
}

public TrieLogLayer getTrieLog() {
return trieLog;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,13 +328,6 @@ && strictReplayProtectionShouldBeEnforceLocally(chainHeadBlockHeader)
.getWorldStateArchive()
.getMutable(
chainHeadBlockHeader.getStateRoot(), chainHeadBlockHeader.getBlockHash(), false)
.map(
ws -> {
if (!ws.isPersistable()) {
return ws.copy();
}
return ws;
})
.orElseThrow()) {
final Account senderAccount = worldState.get(transaction.getSender());
return new ValidationResultAndAccount(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,11 @@ private TransactionAddedStatus addTransaction(
LOG,
"Transaction {} not added because nonce too far in the future for sender {}",
transaction::toTraceLog,
maybeSenderAccount::toString);
() ->
maybeSenderAccount
.map(Account::getAddress)
.map(Address::toString)
.orElse("unknown"));
return NONCE_TOO_FAR_IN_FUTURE_FOR_SENDER;
}

Expand Down