Skip to content

Commit 8149c3d

Browse files
Merge pull request #1583 from multiversx/supernova-execution-results-mb
Supernova execution results mb
2 parents f877465 + 4a10a9c commit 8149c3d

9 files changed

Lines changed: 72 additions & 2 deletions

File tree

src/common/gateway/entities/gateway.component.request.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
export enum GatewayComponentRequest {
22
networkConfig = 'networkConfig',
3+
networkEnableEpochs = 'networkEnableEpochs',
4+
networkEnableEpochsV2 = 'networkEnableEpochsV2',
35
networkStatus = 'networkStatus',
46
networkEsdt = 'networkEsdt',
57
networkEconomics = 'networkEconomics',

src/common/gateway/gateway.service.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,16 @@ export class GatewayService {
9191
});
9292
}
9393

94+
async getNetworkEnableEpochs(): Promise<Record<string,number>> {
95+
const result = await this.get(`network/enable-epochs`, GatewayComponentRequest.networkEnableEpochs);
96+
return result.enableEpochs;
97+
}
98+
99+
async getNetworkEnableEpochsV2(): Promise<Record<string,number>> {
100+
const result = await this.get(`network/enable-epochs-v2`, GatewayComponentRequest.networkEnableEpochsV2);
101+
return result.enableEpochs;
102+
}
103+
94104
async getAddressDetails(address: string): Promise<Account> {
95105
const result = await this.get(`address/${address}`, GatewayComponentRequest.addressDetails);
96106
return result;

src/common/indexer/elastic/elastic.indexer.service.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,10 @@ export class ElasticIndexerService implements IndexerInterface {
251251
return await this.elasticService.getItem('blocks', 'hash', hash);
252252
}
253253

254+
async getExecutionResults(hash: string): Promise<Block> {
255+
return await this.elasticService.getItem('executionresults', 'hash', hash);
256+
}
257+
254258
async getBlockByMiniBlockHash(miniBlockHash: string): Promise<Block | undefined> {
255259
const elasticQuery = ElasticQuery.create()
256260
.withCondition(QueryConditionOptions.must, [QueryType.Match('miniBlocksHashes', miniBlockHash)])

src/common/indexer/indexer.interface.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ export interface IndexerInterface {
7474

7575
getBlock(hash: string): Promise<Block>
7676

77+
getExecutionResults(hash: string): Promise<Block>
78+
7779
getBlockByMiniBlockHash(miniBlockHash: string): Promise<Block | undefined>
7880

7981
getMiniBlock(miniBlockHash: string): Promise<MiniBlock>

src/common/indexer/indexer.service.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,11 @@ export class IndexerService implements IndexerInterface {
166166
return await this.indexerInterface.getBlock(hash);
167167
}
168168

169+
@LogPerformanceAsync(MetricsEvents.SetIndexerDuration)
170+
async getExecutionResults(hash: string): Promise<Block> {
171+
return await this.indexerInterface.getExecutionResults(hash);
172+
}
173+
169174
@LogPerformanceAsync(MetricsEvents.SetIndexerDuration)
170175
async getBlockByMiniBlockHash(miniBlockHash: string): Promise<Block | undefined> {
171176
return await this.indexerInterface.getBlockByMiniBlockHash(miniBlockHash);

src/endpoints/blocks/block.service.ts

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import { NodeService } from "../nodes/node.service";
1111
import { IdentitiesService } from "../identities/identities.service";
1212
import { ApiConfigService } from "../../common/api-config/api.config.service";
1313
import { ConcurrencyUtils } from "src/utils/concurrency.utils";
14+
import { ApiUtils } from "@multiversx/sdk-nestjs-http";
15+
import { GatewayService } from "../../common/gateway/gateway.service";
1416

1517
@Injectable()
1618
export class BlockService {
@@ -23,6 +25,7 @@ export class BlockService {
2325
@Inject(forwardRef(() => IdentitiesService))
2426
private readonly identitiesService: IdentitiesService,
2527
private readonly apiConfigService: ApiConfigService,
28+
private readonly gatewayService: GatewayService,
2629
) { }
2730

2831
async getBlocksCount(filter: BlockFilter): Promise<number> {
@@ -109,11 +112,20 @@ export class BlockService {
109112
}
110113

111114
async getBlock(hash: string): Promise<BlockDetailed> {
112-
const result = await this.indexerService.getBlock(hash) as any;
115+
let result = await this.indexerService.getBlock(hash) as any;
113116

114117
const isChainAndromedaEnabled = this.apiConfigService.isChainAndromedaEnabled()
115118
&& result.epoch >= this.apiConfigService.getChainAndromedaActivationEpoch();
116119

120+
const supernovaEnableEpoch = await this.getSupernovaEnableEpoch();
121+
const isSupernovaEnabled = supernovaEnableEpoch !== -1 && result.epoch >= supernovaEnableEpoch;
122+
if (isSupernovaEnabled) {
123+
const executionResults = await this.indexerService.getExecutionResults(hash);
124+
if (executionResults) {
125+
result = ApiUtils.mergeObjects(result, executionResults);
126+
}
127+
}
128+
117129
if (result.round > 0) {
118130
const publicKeys = await this.blsService.getPublicKeys(result.shardId, result.epoch);
119131
if (result.proposerBlsKey) {
@@ -122,7 +134,7 @@ export class BlockService {
122134
result.proposer = publicKeys[result.proposer];
123135
}
124136
if (!isChainAndromedaEnabled) {
125-
result.validators = result.validators.map((validator: number) => publicKeys[validator]);
137+
result.validators = result.validators?.map((validator: number) => publicKeys[validator]);
126138
} else {
127139
result.validators = publicKeys;
128140
}
@@ -161,4 +173,17 @@ export class BlockService {
161173
}
162174
return blocks[0];
163175
}
176+
177+
async getSupernovaEnableEpoch(): Promise<number> {
178+
const enableEpochs = await this.getNetworkEnableEpochs();
179+
return enableEpochs["erd_supernova_enable_epoch"] ?? -1;
180+
}
181+
182+
async getNetworkEnableEpochs(): Promise<Record<string, number>> {
183+
return await this.cachingService.getOrSet(
184+
CacheInfo.NetworkEnableEpochs.key,
185+
async () => await this.gatewayService.getNetworkEnableEpochs(),
186+
CacheInfo.NetworkEnableEpochs.ttl,
187+
);
188+
}
164189
}

src/endpoints/proxy/gateway.proxy.controller.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,16 @@ export class GatewayProxyController {
233233
return await this.gatewayGet('network/config', GatewayComponentRequest.networkConfig);
234234
}
235235

236+
@Get('/network/enable-epochs')
237+
async getNetworkEnableEpochs() {
238+
return await this.gatewayGet('network/enable-epochs', GatewayComponentRequest.networkEnableEpochs);
239+
}
240+
241+
@Get('/network/enable-epochs-v2')
242+
async getNetworkEnabledEpochsV2() {
243+
return await this.gatewayGet('network/enable-epochs-v2', GatewayComponentRequest.networkEnableEpochsV2);
244+
}
245+
236246
@Get('/network/economics')
237247
async getNetworkEconomics() {
238248
return await this.gatewayGet('network/economics', GatewayComponentRequest.networkEconomics);

src/test/unit/services/blocks.spec.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { NodeService } from "src/endpoints/nodes/node.service";
1111
import { CacheInfo } from "src/utils/cache.info";
1212
import { BlockProofDto } from "../../../endpoints/blocks/entities/block.proof";
1313
import { ApiConfigService } from "../../../common/api-config/api.config.service";
14+
import { GatewayService } from "../../../common/gateway/gateway.service";
1415

1516
describe('Block Service', () => {
1617
let blockService: BlockService;
@@ -65,6 +66,12 @@ describe('Block Service', () => {
6566
getChainAndromedaActivationEpoch: jest.fn(),
6667
},
6768
},
69+
{
70+
provide: GatewayService,
71+
useValue: {
72+
getNetworkEnableEpochs: jest.fn(),
73+
},
74+
},
6875
],
6976
}).compile();
7077

src/utils/cache.info.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,11 @@ export class CacheInfo {
418418
ttl: Constants.oneMinute() * 10,
419419
};
420420

421+
static NetworkEnableEpochs: CacheInfo = {
422+
key: "networkEnableEpochs",
423+
ttl: Constants.oneHour() * 10,
424+
};
425+
421426
static MexPairs: CacheInfo = {
422427
key: "mexPairs",
423428
ttl: Constants.oneMinute() * 10,

0 commit comments

Comments
 (0)