|
| 1 | +--- |
| 2 | +name: readme-writer |
| 3 | +description: Guidelines for writing module READMEs that explain how a module works to developers who need to use it or understand its internals. Use when documenting a module, package, or subsystem. |
| 4 | +--- |
| 5 | + |
| 6 | +# Module README Writing Guide |
| 7 | + |
| 8 | +## File Placement |
| 9 | + |
| 10 | +Place the README in the same folder as the module it explains, not at the package root. |
| 11 | + |
| 12 | +``` |
| 13 | +# Good: README next to the module it documents |
| 14 | +sequencer-client/src/sequencer/README.md |
| 15 | +archiver/src/archiver/l1/README.md |
| 16 | +
|
| 17 | +# Also good: Package-level README for small packages |
| 18 | +slasher/README.md |
| 19 | +``` |
| 20 | + |
| 21 | +Use package-level READMEs when the package is small or you want to explain the package as a whole. |
| 22 | + |
| 23 | +## Structure |
| 24 | + |
| 25 | +### 1. Overview |
| 26 | + |
| 27 | +Start with 2-4 sentences explaining what the module does and where it fits in the system. |
| 28 | + |
| 29 | +```markdown |
| 30 | +# L1 Transaction Utils |
| 31 | + |
| 32 | +This module handles sending L1 txs, including simulating txs, choosing gas prices, |
| 33 | +estimating gas limits, monitoring sent txs, speeding them up, and cancelling them. |
| 34 | +Each instance of `L1TxUtils` is stateful, corresponds to a given publisher EOA, |
| 35 | +and tracks its in-flight txs. |
| 36 | +``` |
| 37 | + |
| 38 | +### 2. Usage Context |
| 39 | + |
| 40 | +Explain when and how this module is used. Who calls it? Under what conditions? |
| 41 | + |
| 42 | +```markdown |
| 43 | +## Usage |
| 44 | + |
| 45 | +The slasher is integrated into the Aztec node and activates when: |
| 46 | +1. The node is configured as a validator |
| 47 | +2. The validator is selected as proposer for a slot |
| 48 | +3. Slashable offenses have been detected |
| 49 | +``` |
| 50 | + |
| 51 | +### 3. Code Examples |
| 52 | + |
| 53 | +For utility-like modules, include a code snippet showing typical usage: |
| 54 | + |
| 55 | +```typescript |
| 56 | +const versionManager = new version.VersionManager(DB_VERSION, rollupAddress, { |
| 57 | + dataDir: '/path/to/data', |
| 58 | + serviceName: 'my-database', |
| 59 | +}); |
| 60 | + |
| 61 | +await versionManager.checkVersionAndHandle( |
| 62 | + async () => await initializeFreshDatabase(), |
| 63 | + async (oldVersion, newVersion) => await migrate(oldVersion, newVersion), |
| 64 | +); |
| 65 | +``` |
| 66 | + |
| 67 | +### 4. Core Concepts |
| 68 | + |
| 69 | +Define domain-specific terms and objects (blocks, checkpoints, slots, proposals, offenses, etc.). Explain relationships between them. |
| 70 | + |
| 71 | +```markdown |
| 72 | +### Slot vs Block vs Checkpoint |
| 73 | + |
| 74 | +- **Slot**: A fixed time window (e.g., 72 seconds) during which a proposer can build blocks |
| 75 | +- **Block**: A single batch of transactions, executed and validated |
| 76 | +- **Checkpoint**: The collection of all blocks built in a slot, attested by validators |
| 77 | +``` |
| 78 | + |
| 79 | +### 5. Main API |
| 80 | + |
| 81 | +List main methods without exhaustive parameter/return documentation. Focus on what each does: |
| 82 | + |
| 83 | +```markdown |
| 84 | +## API |
| 85 | + |
| 86 | +- `sendTransaction`: Sends an L1 tx and returns the tx hash. Consumes a nonce. |
| 87 | +- `monitorTransaction`: Monitors a sent tx and speeds up or cancels it. |
| 88 | +- `sendAndMonitorTransaction`: Combines sending and monitoring in a single call. |
| 89 | +``` |
| 90 | + |
| 91 | +### 6. State Lifecycle |
| 92 | + |
| 93 | +Use tables to document object states and transitions: |
| 94 | + |
| 95 | +```markdown |
| 96 | +| From | To | Condition | Effect | |
| 97 | +|-|-|-|-| |
| 98 | +| `idle` | `sent` | `send_tx` | A new tx is sent and nonce is consumed | |
| 99 | +| `sent` | `speed-up` | `stall_time exceeded` | Tx replaced with higher gas | |
| 100 | +| `sent` | `mined` | `get_nonce(latest) > tx_nonce` | Tx confirmed | |
| 101 | +``` |
| 102 | + |
| 103 | +### 7. Timing and Sequence |
| 104 | + |
| 105 | +Use ASCII diagrams or tables for temporal flows: |
| 106 | + |
| 107 | +```markdown |
| 108 | +T=0s Slot begins |
| 109 | +T=0-2s SYNCHRONIZING, PROPOSER_CHECK |
| 110 | +T=2s Start building Block 1 |
| 111 | +T=10s Block 1 deadline, start Block 2 |
| 112 | +... |
| 113 | +T=72s Slot ends |
| 114 | +``` |
| 115 | + |
| 116 | +For parallel operations, use multi-column timelines: |
| 117 | + |
| 118 | +```markdown |
| 119 | +Time | Proposer | Validators |
| 120 | +-----|----------------------|------------------ |
| 121 | +10s | Finish Block 1 | (idle) |
| 122 | +12s | | Receive Block 1 |
| 123 | +18s | Finish Block 2 | Re-executing Block 1 |
| 124 | +``` |
| 125 | + |
| 126 | +### 8. Dependencies |
| 127 | + |
| 128 | +Explain what other modules this connects to: |
| 129 | + |
| 130 | +```markdown |
| 131 | +## Integration Flow |
| 132 | + |
| 133 | +1. **Offense Detection**: Watchers emit `WANT_TO_SLASH_EVENT` when they detect violations |
| 134 | +2. **Offense Collection**: SlashOffensesCollector stores offenses in SlasherOffensesStore |
| 135 | +3. **Action Execution**: SequencerPublisher executes actions on L1 |
| 136 | +``` |
| 137 | + |
| 138 | +### 9. Error Handling |
| 139 | + |
| 140 | +Dedicate a section to unhappy paths and how deviations are handled: |
| 141 | + |
| 142 | +```markdown |
| 143 | +## Handling Timing Variations |
| 144 | + |
| 145 | +### Slow Initialization |
| 146 | + |
| 147 | +If initialization completes at 3s instead of 2s: |
| 148 | +- Block 1 has 1s less time (7s instead of 8s) |
| 149 | +- Sub-slot deadlines remain fixed |
| 150 | +- Still enough time to build, just with fewer transactions |
| 151 | +``` |
| 152 | + |
| 153 | +### 10. Configuration |
| 154 | + |
| 155 | +Document configuration options with their purpose and constraints: |
| 156 | + |
| 157 | +```markdown |
| 158 | +## Configuration |
| 159 | + |
| 160 | +| Parameter | Default | Purpose | |
| 161 | +|-----------|---------|---------| |
| 162 | +| `slotDuration` | 72s | Total time for checkpoint | |
| 163 | +| `blockDuration` | 8s | Duration of each sub-slot | |
| 164 | +``` |
| 165 | + |
| 166 | +Include considerations for how values relate to each other: |
| 167 | + |
| 168 | +```markdown |
| 169 | +The `slashingOffsetInRounds` needs to be strictly greater than the proof |
| 170 | +submission window to be able to slash for epoch prunes or data withholding. |
| 171 | +``` |
| 172 | + |
| 173 | +### 11. Security |
| 174 | + |
| 175 | +Include when the module has security implications: |
| 176 | + |
| 177 | +```markdown |
| 178 | +## Vetoing |
| 179 | + |
| 180 | +The slashing system includes a veto mechanism that allows designated vetoers |
| 181 | +to block slash payloads during the execution delay period. This provides a |
| 182 | +safety valve for incorrectly proposed slashes. |
| 183 | +``` |
| 184 | + |
| 185 | +## Writing Style |
| 186 | + |
| 187 | +### Explain Rationale |
| 188 | + |
| 189 | +Don't just document what happens—explain why: |
| 190 | + |
| 191 | +```markdown |
| 192 | +# Bad |
| 193 | +The last sub-slot is reserved for validator re-execution. |
| 194 | + |
| 195 | +# Good |
| 196 | +The last sub-slot is reserved for validator re-execution. Validators execute |
| 197 | +blocks sequentially with a ~2s propagation delay. For the last block, there's |
| 198 | +no next block to build while validators re-execute, so we must wait for them |
| 199 | +to finish before collecting attestations. |
| 200 | +``` |
| 201 | + |
| 202 | +### Avoid Subjective Qualifiers |
| 203 | + |
| 204 | +```markdown |
| 205 | +# Bad |
| 206 | +This is a key aspect of the design with critical security implications. |
| 207 | + |
| 208 | +# Good |
| 209 | +This provides a safety valve for incorrectly proposed slashes. |
| 210 | +``` |
| 211 | + |
| 212 | +### Be Succinct |
| 213 | + |
| 214 | +```markdown |
| 215 | +# Bad |
| 216 | +It is important to note that the configuration values must satisfy certain |
| 217 | +constraints which will be explained in detail in the following section. |
| 218 | + |
| 219 | +# Good |
| 220 | +These values must satisfy certain constraints (explained below). |
| 221 | +``` |
| 222 | + |
| 223 | +### Include Only Relevant Sections |
| 224 | + |
| 225 | +Not every module needs every section. Skip sections that don't apply: |
| 226 | +- Small utilities don't need architecture sections |
| 227 | +- Stateless modules don't need lifecycle tables |
| 228 | +- Internal modules don't need usage examples |
| 229 | +- Not everything has security implications |
| 230 | + |
| 231 | +Ask yourself: "Does this section help someone understand or use this module?" If not, skip it. |
0 commit comments