Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Describe Petri block signing as verify-then-sign in the docs
consensus.md and VADEMECUM.md still described the accept-and-sign model
that the signing fix replaced. Also drop the uint8ArrayToHex import that
the removed accept-and-sign branch used.
  • Loading branch information
hackobi committed Oct 11, 2026
commit db4472b3e2b87d9f2a31c65a54b073b079335e13
2 changes: 1 addition & 1 deletion petri/VADEMECUM.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ src/libs/consensus/petri/
arbitration/bftArbitrator.ts
routing/petriRouter.ts
routing/shardMapper.ts
coordination/petriSecretary.ts # Secretary election + accept-and-sign
coordination/petriSecretary.ts # Secretary election + hash collection
```

### Existing Code We Touch
Expand Down
10 changes: 5 additions & 5 deletions petri/consensus.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

## Overview

Petri runs a **secretary-driven, accept-and-sign** consensus model. Every ~10 seconds, the deterministically elected secretary compiles a block from the mempool, broadcasts its hash to shard peers, collects BFT signatures, and inserts the finalized block. Members sign the secretary's hash without independent verification (accept-and-sign), then wait for the finalized block via sync.
Petri runs a **secretary-driven, verify-then-sign** consensus model. Every ~10 seconds, the deterministically elected secretary compiles a block from the mempool, broadcasts its hash to shard peers, collects BFT signatures, and inserts the finalized block. Members sign the secretary's hash only if it matches the block they compiled themselves (verify-then-sign), then wait for the finalized block via sync.

```
mainLoop (1s tick)
Expand Down Expand Up @@ -145,16 +145,16 @@ Secretary broadcasts block hash to all shard peers in parallel:
- Add valid signatures to `block.validation_data.signatures`
4. Return `[proCount, conCount]`

### 8. Accept-and-Sign Handler
### 8. Verify-then-Sign Handler

**File:** `src/libs/consensus/v2/routines/manageProposeBlockHash.ts` — `manageProposeBlockHash()`

RPC handler invoked when secretary broadcasts. Dual-mode:

**Petri mode** (`getSharedState.petriConsensus === true`):
- Sign the secretary's hash directly without verification
- Return signature in response — **accept-and-sign model**
- Trusts the secretary because only one deterministic secretary proposes per round
- Refuse if the claimed proposer differs from the authenticated sender
- Refuse if the proposer is not the elected secretary
- Compare the hash with our own compiled candidate block and sign only if they match — **verify-then-sign model**

**PoRBFT v2 mode** (fallback):
- Compile own candidate block, compare hashes
Expand Down
2 changes: 1 addition & 1 deletion src/libs/consensus/v2/routines/manageProposeBlockHash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
import { RPCResponse } from "@kynesyslabs/demosdk/types"
import _ from "lodash"
import ensureCandidateBlockFormed from "./ensureCandidateBlockFormed"
import { hexToUint8Array, ucrypto, uint8ArrayToHex } from "@kynesyslabs/demosdk/encryption"
import { hexToUint8Array, ucrypto } from "@kynesyslabs/demosdk/encryption"
import PeerManager from "@/libs/peer/PeerManager"
import getCommonValidatorSeed from "./getCommonValidatorSeed"
import getShard from "./getShard"
import { getSecretaryIdentity } from "@/libs/consensus/petri/coordination/petriSecretary"

export default async function manageProposeBlockHash(

Check failure on line 14 in src/libs/consensus/v2/routines/manageProposeBlockHash.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this function to reduce its Cognitive Complexity from 21 to the 15 allowed.

See more on https://sonarcloud.io/project/issues?id=kynesyslabs_node&issues=AaEx26eKiS5bZ3Lbknjo&open=AaEx26eKiS5bZ3Lbknjo&pullRequest=1043
blockHash: string,
validationData: ValidationData,
peerId: string,
Expand Down
Loading