Skip to content

Commit

Permalink
Merge pull request #261 from lidofinance/fix/deposit-events-deletion
Browse files Browse the repository at this point in the history
fix: deposit events deletion
  • Loading branch information
eddort authored Oct 6, 2024
2 parents baf5777 + b3fc128 commit 2829304
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lido-council-daemon",
"version": "3.1.1",
"version": "3.1.2",
"description": "Lido Council Daemon",
"author": "Lido team",
"private": true,
Expand Down
5 changes: 5 additions & 0 deletions src/contracts/deposits-registry/deposits-registry.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,11 @@ export class DepositRegistryService {
// Delete invalid cache only after full synchronization due to:
// - we cannot check root at arbitrary times, only if the backlog is less than 120 blocks
await this.store.clearFromLastValidEvent();
// after deleting invalid data
// it is necessary to restart the process
// further, at reinitialisation a new
// deposit tree and the work cycle will be resumed
process.exit(1);
}

this.logger.log('Deposit events cache is updated', {
Expand Down
26 changes: 17 additions & 9 deletions src/contracts/deposits-registry/store/store.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,24 +204,25 @@ export class DepositsRegistryStoreService {
lastValidEventIndex = event.depositCount;
}

const lastValidEvent = currentCache.data[lastValidEventIndex];

if (!isCacheConsistent) {
const lastValidEvent = currentCache.data[lastValidEventIndex];
const nextEvent = currentCache.data[lastValidEventIndex + 1];

this.logger.warn('Deposit cache is inconsistent', {
lastValidEvent,
nextEvent,
});
}

const headers = this.formDepositEventHeaderForDeletion(
lastValidEvent?.blockNumber,
);
const headers = this.formDepositEventHeaderForDeletion(
lastValidEvent?.blockNumber,
);

await this.deleteDepositsGreaterThanOrEqualNBatch(
lastValidEventIndex + 1,
headers,
);
}
await this.deleteDepositsGreaterThanOrEqualNBatch(
lastValidEventIndex + 1,
headers,
);
}

/**
Expand Down Expand Up @@ -287,6 +288,13 @@ export class DepositsRegistryStoreService {
});
await this.db.batch(ops);
}

this.logger.log('Deposit events deleted', {
depositCount,
headers,
operationsCount: ops.length,
});

await this.setupEventsCache();
}

Expand Down

0 comments on commit 2829304

Please sign in to comment.