Skip to content

Commit

Permalink
Keep Worldstate Storage open for Bonsai archive latest layer (hyperle…
Browse files Browse the repository at this point in the history
…dger#5039)

* bonsai layered worldstate subscription
* unsubscribe from worldstatestorage on close of BonsaiLayeredWorldState
* minor txpool logging improvements

Signed-off-by: garyschulte <[email protected]>
  • Loading branch information
garyschulte committed Feb 4, 2023
1 parent 7245e01 commit e715010
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ tests are updated to use EC private keys instead of RSA keys.

### Bug Fixes
- Mitigation fix for stale bonsai code storage leading to log rolling issues on contract recreates [#4906](https://github.com/hyperledger/besu/pull/4906)
- Ensure latest cached layered worldstate is subscribed to storage, fix problem with RPC calls using 'latest' [#5039](https://github.com/hyperledger/besu/pull/5039)


## 23.1.0-RC1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,12 @@ public void persist(final BlockHeader blockHeader) {
final Hash newWorldStateRootHash = rootHash(localUpdater);
archive
.getTrieLogManager()
.saveTrieLog(archive, localUpdater, newWorldStateRootHash, blockHeader, this);
.saveTrieLog(
archive,
localUpdater,
newWorldStateRootHash,
blockHeader,
(BonsaiPersistedWorldState) this.copy());
worldStateRootHash = newWorldStateRootHash;
worldStateBlockHash = blockHeader.getBlockHash();
isPersisted = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,29 @@ public Optional<BonsaiWorldView> getNextWorldView() {
}

public void setNextWorldView(final Optional<BonsaiWorldView> nextWorldView) {
maybeUnSubscribe();
this.nextWorldView = nextWorldView;
}

private void maybeUnSubscribe() {
nextWorldView
.filter(WorldState.class::isInstance)
.map(WorldState.class::cast)
.ifPresent(
ws -> {
try {
ws.close();
} catch (final Exception e) {
// no-op
}
});
}

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

0 comments on commit e715010

Please sign in to comment.