bolt1

Base Lightning protocol, per BOLT #1 (docs.ppad.tech/bolt1).
git clone git://git.ppad.tech/bolt1.git
Log | Files | Refs | README | LICENSE

IMPL4.md (2044B)


      1 # IMPL4 - Type Safety Improvements
      2 
      3 ## Phase 1: ChannelId Newtype
      4 
      5 - Add `ChannelId` newtype to Message module.
      6 - Add `channelId` smart constructor (validates 32 bytes).
      7 - Add `allChannels` constant for the all-zeros channel ID.
      8 - Update `Error` record: `errorChannelId :: !ChannelId`.
      9 - Update `Warning` record: `warningChannelId :: !ChannelId`.
     10 - Update Codec encode/decode functions for Error and Warning.
     11 - Update tests to use new constructors.
     12 
     13 ## Phase 2: ChainHash Newtype
     14 
     15 - Add `ChainHash` newtype to Message module.
     16 - Add `chainHash` smart constructor (validates 32 bytes).
     17 - Update `InitNetworks` variant: `InitNetworks ![ChainHash]`.
     18 - Update TLV `parseInitTlvs` to produce `[ChainHash]`.
     19 - Update TLV `encodeInitTlvs` to accept `[ChainHash]`.
     20 - Update tests to use new constructors.
     21 
     22 ## Phase 3: Ordered TlvStream
     23 
     24 - Add `tlvStream` smart constructor to TLV module.
     25 - Add `unsafeTlvStream` for internal/trusted use.
     26 - Hide `TlvStream` data constructor from public exports.
     27 - Update re-exports in main module.
     28 - Add tests for ordering validation.
     29 
     30 ## Phase 4: Documentation and Cleanup
     31 
     32 - Add Haddock for new types and constructors.
     33 - Update any examples in documentation.
     34 - Verify all tests pass.
     35 - Run benchmarks to ensure no performance regression.
     36 
     37 ## Independent Work Chunks
     38 
     39 Phases 1-3 can be done in parallel:
     40 - Phase 1 (ChannelId) touches Message + Codec + Error/Warning tests.
     41 - Phase 2 (ChainHash) touches Message + TLV + Init tests.
     42 - Phase 3 (TlvStream) touches TLV module + TLV tests.
     43 
     44 Phase 4 depends on 1-3 completing.
     45 
     46 ## Test Updates
     47 
     48 Each phase requires corresponding test updates:
     49 - Phase 1: Error/Warning encode/decode tests.
     50 - Phase 2: Init TLV parsing tests, network chain tests.
     51 - Phase 3: TlvStream construction tests (valid ordering, rejection).
     52 
     53 ## Notes
     54 
     55 - Keep `Eq`, `Show`, `NFData` instances for all new types.
     56 - Consider `IsString` instance for `ChannelId`/`ChainHash` if hex
     57   literals are useful in tests (optional).
     58 - Benchmark decode paths to verify no regression from added
     59   newtype unwrapping.