Skip to content
Closed
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 @@ -41,13 +41,17 @@ public class TrieLogLayerConverter {

private static final Logger LOG = LoggerFactory.getLogger(TrieLogLayerConverter.class);

final WorldStateStorage worldStateStorage;
final WorldStateStorage headWorldStateStorage;

public TrieLogLayerConverter(final WorldStateStorage worldStateStorage) {
this.worldStateStorage = worldStateStorage;
public TrieLogLayerConverter(final WorldStateStorage headWorldStateStorage) {
this.headWorldStateStorage = headWorldStateStorage;
}

public TrieLogLayer decodeTrieLog(final RLPInput input) {
return decodeTrieLog(input, headWorldStateStorage);
}

public TrieLogLayer decodeTrieLog(final RLPInput input, WorldStateStorage wss) {

TrieLogLayer trieLogLayer = new TrieLogLayer();

Expand Down Expand Up @@ -80,12 +84,12 @@ public TrieLogLayer decodeTrieLog(final RLPInput input) {
if (input.nextIsNull()) {
input.skipNext();
maybeAccountIndex =
worldStateStorage
wss
.getFlatLeaf(WRAP_ACCOUNT.apply(accountKey.accountHash()))
.map(FlattenedLeaf::leafIndex);
} else {
input.enterList();
final PriorAccount priorAccount = preparePriorTrieLogAccount(accountKey, input);
final PriorAccount priorAccount = preparePriorTrieLogAccount(accountKey, input, wss);
maybeAccountIndex = priorAccount.index;
final ZkAccount newAccountValue =
TrieLogLayer.nullOrValue(
Expand Down Expand Up @@ -122,7 +126,7 @@ public TrieLogLayer decodeTrieLog(final RLPInput input) {
maybeAccountIndex
.flatMap(
index -> {
return new StorageTrieRepositoryWrapper(index, worldStateStorage, null)
return new StorageTrieRepositoryWrapper(index, wss, null)
.getFlatLeaf(storageSlotKey.slotHash())
.map(FlattenedLeaf::leafValue)
.map(UInt256::fromBytes);
Expand Down Expand Up @@ -180,12 +184,12 @@ public TrieLogLayer decodeTrieLog(final RLPInput input) {

record PriorAccount(ZkAccount account, Bytes32 evmStorageRoot, Optional<Long> index) {}

public PriorAccount preparePriorTrieLogAccount(final AccountKey accountKey, final RLPInput in) {
public PriorAccount preparePriorTrieLogAccount(final AccountKey accountKey, final RLPInput in, final WorldStateStorage wss) {

final ZkAccount oldAccountValue;

final Optional<FlattenedLeaf> flatLeaf =
worldStateStorage.getFlatLeaf(WRAP_ACCOUNT.apply(accountKey.accountHash()));
wss.getFlatLeaf(WRAP_ACCOUNT.apply(accountKey.accountHash()));


if (in.nextIsNull() && flatLeaf.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) {
}

// do not have it in cache
if (worldStateArchive.getCachedWorldState(parentBlockNumber).isEmpty()) {
final var optWorldState = worldStateArchive.getCachedWorldState(parentBlockNumber);
if (optWorldState.isEmpty()) {
return new ShomeiJsonRpcErrorResponse(
requestContext.getRequest().getId(),
RpcErrorType.INVALID_PARAMS,
Expand All @@ -90,7 +91,8 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) {

// Decode the trielog
final TrieLogLayer trieLogLayer =
worldStateArchive.getTrieLogLayerConverter().decodeTrieLog(RLP.input(trieLogBytes));
worldStateArchive.getTrieLogLayerConverter().decodeTrieLog(
RLP.input(trieLogBytes), optWorldState.get().getZkEvmWorldStateStorage());
Comment thread
cursor[bot] marked this conversation as resolved.

// Apply the virtual trielog and generate the trace
// This generates a trace without persisting the state
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public void shouldReturnValidResponseWhenSimulationSucceeds() throws Exception {

// Mock the trielog layer converter
when(worldStateArchive.getTrieLogLayerConverter()).thenReturn(trieLogLayerConverter);
when(trieLogLayerConverter.decodeTrieLog(any())).thenReturn(trieLogLayer);
when(trieLogLayerConverter.decodeTrieLog(any(), any())).thenReturn(trieLogLayer);

// Mock virtual trace generation
final List<List<Trace>> mockTraces = List.of(List.of());
Expand Down
Loading