Skip to content

Commit

Permalink
Handle activation epoch where staking v4 flag is checked (#1338)
Browse files Browse the repository at this point in the history
* handle activation epoch where staking v4 flag is checked

* update specs

---------

Co-authored-by: cfaur09 <[email protected]>
  • Loading branch information
tanghel and cfaur09 authored Sep 24, 2024
1 parent 60ec4ae commit 125e1e1
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
5 changes: 5 additions & 0 deletions src/crons/cache.warmer/cache.warmer.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@ export class CacheWarmerService {

@Lock({ name: 'Node auction invalidations', verbose: true })
async handleNodeAuctionInvalidations() {
const currentEpoch = await this.blockService.getCurrentEpoch();
if (currentEpoch < this.apiConfigService.getStakingV4ActivationEpoch()) {
return;
}

// wait randomly between 1 and 2 seconds to avoid all nodes refreshing at the same time
await new Promise(resolve => setTimeout(resolve, 1000 + 1000 * Math.random()));

Expand Down
4 changes: 3 additions & 1 deletion src/endpoints/network/network.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,10 @@ export class NetworkService {
const egldPrice = await this.dataApiService.getEgldPrice();
const tokenMarketCap = await this.tokenService.getTokenMarketCapRaw();

const currentEpoch = await this.blockService.getCurrentEpoch();

let totalWaitingStake: BigInt = BigInt(0);
if (!this.apiConfigService.isStakingV4Enabled()) {
if (!this.apiConfigService.isStakingV4Enabled() || currentEpoch < this.apiConfigService.getStakingV4ActivationEpoch()) {
totalWaitingStake = await this.getTotalWaitingStake();
}

Expand Down
3 changes: 2 additions & 1 deletion src/endpoints/nodes/node.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,8 @@ export class NodeService {

await this.applyNodeStakeInfo(nodes);

if (this.apiConfigService.isStakingV4Enabled()) {
const currentEpoch = await this.blockService.getCurrentEpoch();
if (this.apiConfigService.isStakingV4Enabled() && currentEpoch >= this.apiConfigService.getStakingV4ActivationEpoch()) {
const auctions = await this.gatewayService.getValidatorAuctions();
await this.processAuctions(nodes, auctions);
}
Expand Down
4 changes: 2 additions & 2 deletions src/test/unit/services/nodes.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ describe('NodeService', () => {
const result = await nodeService.deleteOwnersForAddressInCache(address);

expect(result).toEqual([]);
expect(currentEpochSpy).toHaveBeenCalledTimes(1);
expect(currentEpochSpy).toHaveBeenCalledTimes(2);
expect(allNodesSpy).toHaveBeenCalledTimes(1);
});
});
Expand Down Expand Up @@ -539,7 +539,7 @@ describe('NodeService', () => {
undefined,
]
);
expect(currentEpochSpy).toHaveBeenCalledTimes(1);
expect(currentEpochSpy).toHaveBeenCalledTimes(2);
});
});

Expand Down

0 comments on commit 125e1e1

Please sign in to comment.