Skip to content

Commit 32af06f

Browse files
committed
feat: added logs and cache
1 parent ce603db commit 32af06f

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
"test:cov": "jest --coverage",
2424
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
2525
"test:e2e": "jest --config ./test/jest-e2e.json",
26-
"typechain": "typechain --target=ethers-v6 --out-dir ./src/common/contracts/generated ./src/common/contracts/abi/*.json"
26+
"typechain": "typechain --target=ethers-v6 --out-dir ./src/common/contracts/generated ./src/common/contracts/abi/*.json",
27+
"postinstall": "yarn typechain"
2728
},
2829
"dependencies": {
2930
"@ethersproject/bignumber": "^5.7.0",

src/common/sweep/sweep.service.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,12 @@ import { SimpleFallbackJsonRpcBatchProvider } from '@lido-nestjs/execution';
2424

2525
@Injectable()
2626
export class SweepService {
27+
static SERVICE_LOG_NAME = 'sweep';
28+
2729
constructor(
2830
@Inject(LOGGER_PROVIDER) protected readonly logger: LoggerService,
2931
protected readonly consensusClientService: ConsensusClientService,
3032
protected readonly provider: SimpleFallbackJsonRpcBatchProvider,
31-
protected readonly genesisService: GenesisTimeService,
3233
protected readonly configService: ConfigService,
3334
) {}
3435

@@ -46,6 +47,12 @@ export class SweepService {
4647
const isElectraActivate = await this.consensusClientService.isElectraActivated(currentEpoch);
4748
const consensusVersion = await this.getConsensusVersion();
4849

50+
this.logger.log('check electra info', {
51+
isElectraActivate,
52+
consensusVersion,
53+
service: SweepService.SERVICE_LOG_NAME,
54+
});
55+
4956
if (consensusVersion < 3 || !isElectraActivate) {
5057
return this.getSweepDelayInEpochsPreElectra(indexedValidators, currentEpoch);
5158
}
@@ -58,7 +65,10 @@ export class SweepService {
5865
const totalWithdrawableValidators = this.getWithdrawableValidatorsNumber(indexedValidators, epoch);
5966

6067
const fullSweepInEpochs = totalWithdrawableValidators / MAX_WITHDRAWALS_PER_PAYLOAD / SLOTS_PER_EPOCH;
61-
return Math.floor(fullSweepInEpochs * 0.5);
68+
const result = Math.floor(fullSweepInEpochs * 0.5);
69+
70+
this.logger.log('calculated sweep delay in epochs pre electra', { result, service: SweepService.SERVICE_LOG_NAME });
71+
return result;
6272
}
6373

6474
// pre pectra
@@ -80,7 +90,13 @@ export class SweepService {
8090
const fullSweepCycleInEpochs = Math.ceil(
8191
withdrawalsNumberInSweepCycle / MAX_WITHDRAWALS_PER_PAYLOAD / SLOTS_PER_EPOCH,
8292
);
83-
return Math.floor(fullSweepCycleInEpochs / 2);
93+
94+
const result = Math.floor(fullSweepCycleInEpochs * 0.5);
95+
this.logger.log('calculated sweep delay in epochs post electra', {
96+
result,
97+
service: SweepService.SERVICE_LOG_NAME,
98+
});
99+
return result;
84100
}
85101

86102
private predictWithdrawalsNumberInSweepCycle(state: BeaconState, indexedValidators: IndexedValidator[]): number {

src/storage/validators/validators-cache.service.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export class ValidatorsCacheService {
3030
await file.close();
3131
const data: string[] = fileReadResult.split(ValidatorsCacheService.CACHE_DATA_DIVIDER);
3232

33-
if (data.length !== 4) {
33+
if (data.length !== 5) {
3434
this.logger.log(`invalid cache data length`, {
3535
service: ValidatorsCacheService.SERVICE_LOG_NAME,
3636
data,
@@ -52,8 +52,9 @@ export class ValidatorsCacheService {
5252

5353
this.validatorsStorage.setActiveValidatorsCount(Number(data[0]));
5454
this.validatorsStorage.setMaxExitEpoch(data[1]);
55-
this.validatorsStorage.setFrameBalances(this.parseFrameBalances(data[3]));
5655
this.validatorsStorage.setLastUpdate(Number(data[2]));
56+
this.validatorsStorage.setFrameBalances(this.parseFrameBalances(data[3]));
57+
this.validatorsStorage.setSweepMeanEpochs(Number(data[4]));
5758

5859
this.logger.log(`success initialize from cache file ${cacheFileName}`, {
5960
service: ValidatorsCacheService.SERVICE_LOG_NAME,
@@ -77,6 +78,7 @@ export class ValidatorsCacheService {
7778
this.validatorsStorage.getMaxExitEpoch(),
7879
this.validatorsStorage.getLastUpdate(),
7980
stringifyFrameBalances(this.validatorsStorage.getFrameBalances()),
81+
this.validatorsStorage.getSweepMeanEpochs(),
8082
].join(ValidatorsCacheService.CACHE_DATA_DIVIDER);
8183
await writeFile(cacheFileName, data);
8284
this.logger.log(`success save to file ${cacheFileName}`, { service: ValidatorsCacheService.SERVICE_LOG_NAME });

0 commit comments

Comments
 (0)