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 block proof support #1454

Merged
merged 2 commits into from
Mar 4, 2025
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
37 changes: 37 additions & 0 deletions src/endpoints/blocks/entities/block.proof.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { ApiProperty } from '@nestjs/swagger';

export class BlockProofDto {
constructor(init?: Partial<BlockProofDto>) {
Object.assign(this, init);
}

@ApiProperty({
type: String,
description: "Bitmap representing public keys involved in the proof",
example: "7702",
})
pubKeysBitmap?: string;

@ApiProperty({
type: String,
description: "Aggregated BLS signature for the proof",
example: "50224d66a42a019991d16f25dba375b581f279d4394d4c254876c1484f61bed90fb20456f8af107c54e4eed1763e2a92",
})
aggregatedSignature?: string;

@ApiProperty({
type: String,
description: "Hash of the block header being proven",
example: "414d526161587ae9f53453aa0392971272c48dbb3cc54a33448972d388e0deeb",
})
headerHash?: string;

@ApiProperty({type: Number, description: "Epoch number of the block header", example: 130})
headerEpoch?: number;

@ApiProperty({type: Number, description: "Nonce value of the block header", example: 13137})
headerNonce?: number;

@ApiProperty({type: Number, description: "Round number of the block header", example: 13163})
headerRound?: number;
}
7 changes: 7 additions & 0 deletions src/endpoints/blocks/entities/block.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ApiUtils } from "@multiversx/sdk-nestjs-http";
import { ApiProperty } from "@nestjs/swagger";
import { Identity } from "src/endpoints/identities/entities/identity";
import { BlockProofDto } from "./block.proof";

export class Block {
constructor(init?: Partial<Block>) {
Expand Down Expand Up @@ -64,6 +65,12 @@ export class Block {
@ApiProperty({ type: String, nullable: true, required: false })
scheduledRootHash: string | undefined = undefined;

@ApiProperty({ type: BlockProofDto, nullable: true, required: false })
previousHeaderProof: BlockProofDto | undefined = undefined;

@ApiProperty({ type: BlockProofDto, nullable: true, required: false })
proof: BlockProofDto | undefined = undefined;

static mergeWithElasticResponse<T extends Block>(newBlock: T, blockRaw: any): T {
blockRaw.shard = blockRaw.shardId;

Expand Down
12 changes: 11 additions & 1 deletion src/test/unit/services/blocks.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { BlsService } from "src/endpoints/bls/bls.service";
import { IdentitiesService } from "src/endpoints/identities/identities.service";
import { NodeService } from "src/endpoints/nodes/node.service";
import { CacheInfo } from "src/utils/cache.info";
import { BlockProofDto } from "../../../endpoints/blocks/entities/block.proof";

describe('Block Service', () => {
let blockService: BlockService;
Expand Down Expand Up @@ -128,6 +129,15 @@ describe('Block Service', () => {
gasPenalized: 0,
maxGasLimit: 15000000000,
scheduledRootHash: undefined,
proof: undefined,
previousHeaderProof: new BlockProofDto({
pubKeysBitmap: '7702',
aggregatedSignature: '50224d66a42a019991d16f25dba375b581f279d4394d4c254876c1484f61bed90fb20456f8af107c54e4eed1763e2a92',
headerHash: '414d526161587ae9f53453aa0392971272c48dbb3cc54a33448972d388e0deeb',
headerEpoch: 100,
headerRound: 12500,
headerNonce: 10500,
}),
};

it('should call cachingService.getOrSet with the correct arguments and return the result', async () => {
Expand Down Expand Up @@ -173,7 +183,7 @@ describe('Block Service', () => {
);
});

it('should retur current epoch', async () => {
it('should return current epoch', async () => {
blockService.getBlocks = jest.fn().mockResolvedValue([block]);

const result = await blockService.getCurrentEpoch();
Expand Down