Skip to content

Commit 43f6e98

Browse files
committed
feat(node): add block mining endpoint
1 parent 50ca7f9 commit 43f6e98

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

node/src/app.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { fetchPeerInfo } from "./gossip/utils/fetchPeerInfo.js";
88
import { nodeState } from "./state/nodeState.js";
99
import { runGDV } from "./verifier/gdvVerifier.js";
1010
import { getVerificationResultId } from "./merkle/verificationMerkleTree.js";
11+
import { minePendingVerificationResults } from "./mining/blockMiner.js";
1112

1213
import type { MessageType, BaseMessage, PayloadByMessageType, NetworkMessageOf, NewPeerPayload, NetworkMessage} from "./types/messages.js";
1314
import type { ProofRecord } from "./types/proof.js";
@@ -312,4 +313,23 @@ app.get("/mempool", (_req, res) => {
312313
verifiedAt: result.verifiedAt,
313314
})),
314315
});
316+
});
317+
318+
app.post("/mine-block", async (_req, res) => {
319+
const block = await minePendingVerificationResults({
320+
blockManager: nodeState.blockManager,
321+
mempool: nodeState.verificationMempool,
322+
difficulty: 2,
323+
maxResultsPerBlock: 10,
324+
});
325+
326+
if (!block) {
327+
return res.status(400).json({
328+
error: "NO_PENDING_VERIFICATION_RESULTS",
329+
});
330+
}
331+
332+
return res.json({
333+
block,
334+
});
315335
});

node/src/state/nodeState.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@ import { MessageStore } from "../gossip/messageStore.js";
33
import { ProofManager } from "./proofManager.js";
44
import { VerificationManager } from "./verificationManager.js";
55
import { VerificationMempool } from "./verificationMempool.js";
6-
6+
import { BlockManager } from "./blockManager.js";
77

88
export class NodeState {
99
public readonly peers = new PeerManager();
1010
public readonly messages = new MessageStore();
1111
public readonly proofs = new ProofManager();
1212
public readonly verifications = new VerificationManager();
1313
public readonly verificationMempool = new VerificationMempool();
14+
public readonly blockManager = new BlockManager();
1415
}
1516

1617
export const nodeState = new NodeState();

0 commit comments

Comments
 (0)