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

Add delete finalized state interface #8374

Merged
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 @@ -111,6 +111,12 @@ public void addReconstructedFinalizedState(
}
}

@Override
public void deleteFinalizedState(
final KvStoreTransaction transaction, final S schema, final UInt64 slot) {
transaction.delete(schema.getColumnFinalizedStatesBySlot(), slot);
}

@Override
public void commit() {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ void addFinalizedState(
void addReconstructedFinalizedState(
KvStoreAccessor db, KvStoreTransaction transaction, S schema, BeaconState state);

void deleteFinalizedState(KvStoreTransaction transaction, S schema, UInt64 slot);

void commit();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,14 @@ public void addReconstructedFinalizedState(
addFinalizedState(db, transaction, schema, state);
}

@Override
public void deleteFinalizedState(
final KvStoreTransaction transaction,
final SchemaCombinedTreeState schema,
final UInt64 slot) {
transaction.delete(schema.getColumnFinalizedStateRootsBySlot(), slot);
}

@Override
public void commit() {
if (nodeStore != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,43 @@ void shouldStoreAndLoadMultipleStates() {
assertStateReloads(state4);
}

@Test
void shouldStoreAndLoadNonDeletedStates() {
final BeaconState state1 = dataStructureUtil.randomBeaconState(UInt64.valueOf(3));
final BeaconState state2 = dataStructureUtil.randomBeaconState(UInt64.valueOf(5));
final BeaconState state3 = dataStructureUtil.randomBeaconState(UInt64.valueOf(7));
final BeaconState state4 = dataStructureUtil.randomBeaconState(UInt64.valueOf(10));
try (final KvStoreTransaction transaction = db.startTransaction()) {
final FinalizedStateUpdater<SchemaCombinedTreeState> updater = logic.updater();
updater.addFinalizedState(db, transaction, schema, state1);
updater.addFinalizedState(db, transaction, schema, state2);
updater.addFinalizedState(db, transaction, schema, state3);
updater.addFinalizedState(db, transaction, schema, state4);
transaction.commit();
}

assertStateReloads(state1);
assertStateReloads(state2);

try (final KvStoreTransaction transaction = db.startTransaction()) {
final FinalizedStateUpdater<SchemaCombinedTreeState> updater = logic.updater();
updater.deleteFinalizedState(transaction, schema, state1.getSlot());
updater.deleteFinalizedState(transaction, schema, state2.getSlot());
transaction.commit();
}

assertStateIsDeleted(state1.getSlot());
assertStateIsDeleted(state2.getSlot());
Comment on lines +106 to +107
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i know this is evil, but can we delete state 2 first?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean in theory or you requesting a change there? anyway it's possible and the order doesn't matter at this level of the codebase, I think

assertStateReloads(state3);
assertStateReloads(state4);
}

private void assertStateIsDeleted(final UInt64 slot) {
final Optional<BeaconState> loadedState =
logic.getLatestAvailableFinalizedState(db, schema, slot);
assertThat(loadedState).isEmpty();
}

private void assertStateReloads(final BeaconState state) {
assertStateReloads(state, state.getSlot());
}
Expand Down