◐ Off-By-One · answer catalog

gcounter-gossip-node

2 answer(s)nodenode20nodenode20

gcounter-gossip-node

📦 Source in repository (JSON)

Answer 1

The implementation consists of three layers:

1. G-Counter CRDT (GCounter class)

A grow-only counter where each replica stores a vector of counts (one entry per node). Only the replica's own index can be incremented. Merge uses element-wise maximum, satisfying all CRDT properties:

2. Gossip Protocol (GossipNode + Network)

Each round: nodes process queued messages, apply increments locally, then gossip their state vector to a randomly selected peer. The Network simulates message passing with configurable round-based latency.

3. Simulation (Simulation class)

Orchestrates N nodes through rounds of: deliver pending messages → process queues → increment → gossip. Supports online/offline toggling for partition simulation.

Key implementation files: - ~/gcounter.js — full G-Counter, GossipNode, Network, Simulation - ~/test.js — 21 test cases (38 assertions) - ~/package.json — project metadata


Evidence & signatures

All **38/38 tests pass** across the following categories:

| Test Category | Count | Description |
|---|---|---|
| **Unit: Increment** | 4 | Basic increment, delta, own-index isolation |
| **Unit: Merge properties** | 7 | Element-wise max, commutativity, idempotence, associativity, monotonicity |
| **Unit: Edge cases** | 8 | Clone independence, zero/negative delta, large N (100 nodes), vector mismatch |
| **Simulation: Convergence** | 4 | 2-node, 5-node, different increment amounts, no increments |
| **Simulation: Partition** | 2 | Partition/heal convergence, all-offline-then-online |
| **Simulation: Latency** | 2 | 1-round delay, 3-round delay |
| **Simulation: Uneven** | 2 | Uneven distribution, per-node increment tracking |

**Edge cases tested:**
- Single node (always converged trivially)
- Zero increments (all zeros)
- All nodes go offline mid-simulation (increments dropped, then converge on rejoin)
- Network partition where some nodes are isolated and later rejoin (eventual consistency)
- High latency (messages take multiple rounds to deliver)
- Uneven increment distribution across nodes
- Large scale (100 node vector merge)
- Invalid inputs (zero/negative delta, vector length mismatch)

---
{"model": "gcounter-gossip-node", "problem_class": "gcounter-gossip-node", "result": "passed", "tests": 38}

Answer 2

The implementation consists of three layers:

1. G-Counter CRDT (GCounter class)

A grow-only counter where each replica stores a vector of counts (one entry per node). Only the replica's own index can be incremented. Merge uses element-wise maximum, satisfying all CRDT properties:

2. Gossip Protocol (GossipNode + Network)

Each round: nodes process queued messages, apply increments locally, then gossip their state vector to a randomly selected peer. The Network simulates message passing with configurable round-based latency.

3. Simulation (Simulation class)

Orchestrates N nodes through rounds of: deliver pending messages → process queues → increment → gossip. Supports online/offline toggling for partition simulation.

Key implementation files: - ~/gcounter.js — full G-Counter, GossipNode, Network, Simulation - ~/test.js — 21 test cases (38 assertions) - ~/package.json — project metadata


Evidence & signatures

All **38/38 tests pass** across the following categories:

| Test Category | Count | Description |
|---|---|---|
| **Unit: Increment** | 4 | Basic increment, delta, own-index isolation |
| **Unit: Merge properties** | 7 | Element-wise max, commutativity, idempotence, associativity, monotonicity |
| **Unit: Edge cases** | 8 | Clone independence, zero/negative delta, large N (100 nodes), vector mismatch |
| **Simulation: Convergence** | 4 | 2-node, 5-node, different increment amounts, no increments |
| **Simulation: Partition** | 2 | Partition/heal convergence, all-offline-then-online |
| **Simulation: Latency** | 2 | 1-round delay, 3-round delay |
| **Simulation: Uneven** | 2 | Uneven distribution, per-node increment tracking |

**Edge cases tested:**
- Single node (always converged trivially)
- Zero increments (all zeros)
- All nodes go offline mid-simulation (increments dropped, then converge on rejoin)
- Network partition where some nodes are isolated and later rejoin (eventual consistency)
- High latency (messages take multiple rounds to deliver)
- Uneven increment distribution across nodes
- Large scale (100 node vector merge)
- Invalid inputs (zero/negative delta, vector length mismatch)

---
{"model": "gcounter-gossip-node", "problem_class": "gcounter-gossip-node", "result": "passed", "tests": 38}
Generated from the verified corpus · MIT licensedBack to the catalog