Commit d302c0d
fix(blockfetch): deliver undecodable blocks to BlockRawFunc (#2186)
* fix(blockfetch): deliver undecodable blocks to BlockRawFunc
handleBlock decoded every block with ledger.NewBlockFromCbor and failed the
request on error, so a payload the generic type decoder cannot represent
never reached BlockRawFunc. Musashi peers tag Dijkstra-shaped blocks as
Conway; the strict Conway decoder rejects their 12-field Leios-extended
header body, tearing down the connection before a consumer that understands
the layout could decode it.
When the raw callback is the consumer that would receive the block, a decode
failure now falls back to raw delivery. Range correlation still applies: its
inputs are read straight from the block header CBOR, which is era-agnostic
for the fields involved, so a peer cannot inject an unrelated block by
sending one the type decoder rejects. recordBlock takes a point and previous
hash rather than a decoded block to serve both paths.
Every other consumer is unchanged and still fails on an undecodable block:
GetBlock, BlockFunc, and the block pipeline, which takes precedence over
BlockRawFunc and runs its own typed decode.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018DcqSoDCsANbPVamS3iuYU
Signed-off-by: Chris Guiney <chris@guiney.net>
* fix(blockfetch): guard the failed-decode block against nil dereference
nilaway flagged the decoded block as dereferenced without a guard: the
restructure that added the raw fallback moved the deref away from the
`decodeErr != nil` return that had guarded it.
Adding the guard exposed a real panic behind it. The era decoders return a
typed nil pointer alongside their error, so the interface holding one is not
itself nil and passes `block != nil`; every method call on it then panics.
Normalize a failed decode to an untyped nil so the raw path is taken, and
reject a decoder that returns neither a block nor an error rather than
handing nil to a consumer.
Also assert the CBOR element counts in the range test helper before indexing.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018DcqSoDCsANbPVamS3iuYU
Signed-off-by: Chris Guiney <chris@guiney.net>
* fix(blockfetch): keep the raw fallback out of validation verdicts
The fallback treated every decode failure as an unrepresentable layout, but
that set includes blocks the decoder read and then rejected. With validation
enabled, which is the default, a peer could keep a valid header and replace
the body: the typed decode failed on the body hash, header-only correlation
still passed, and the tampered bytes reached BlockRawFunc.
Gate the fallback on whether the layout is representable at all, by decoding
once with validation disabled. A block that then decodes was understood and
refused, so the refusal stands; one that still fails could not be read, which
is the case the raw callback exists for.
Keying on that rather than on the error type covers the whole class: the
body-hash checks return a typed common.ValidationError, but the nil-header
checks beside them return a plain error, and both are now refused.
Reported by CodeRabbit.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018DcqSoDCsANbPVamS3iuYU
Signed-off-by: Chris Guiney <chris@guiney.net>
* test(blockfetch): cover the origin prev_hash branch and await shutdown
The agreement test claimed to exercise an origin prev_hash, but an encoded
zero Blake2b256 is a 32-byte bytestring, not CBOR null, so the null branch in
decodeRawPrevHash was never reached. Add a case that rewrites prev_hash to
null; it fails without that branch.
runTestExpectingError checked for leaked goroutines straight after Close,
which only starts teardown, so the error-path tests could report a connection
still unwinding as a leak. Wait for shutdown first, as runTest does.
Reported by Cubic.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018DcqSoDCsANbPVamS3iuYU
Signed-off-by: Chris Guiney <chris@guiney.net>
---------
Signed-off-by: Chris Guiney <chris@guiney.net>
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>1 parent e3354f1 commit d302c0d
4 files changed
Lines changed: 1142 additions & 13 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1100 | 1100 | | |
1101 | 1101 | | |
1102 | 1102 | | |
1103 | | - | |
| 1103 | + | |
1104 | 1104 | | |
1105 | 1105 | | |
1106 | 1106 | | |
1107 | 1107 | | |
1108 | 1108 | | |
1109 | 1109 | | |
1110 | | - | |
1111 | | - | |
| 1110 | + | |
| 1111 | + | |
| 1112 | + | |
| 1113 | + | |
| 1114 | + | |
| 1115 | + | |
| 1116 | + | |
| 1117 | + | |
| 1118 | + | |
| 1119 | + | |
| 1120 | + | |
| 1121 | + | |
| 1122 | + | |
| 1123 | + | |
| 1124 | + | |
| 1125 | + | |
| 1126 | + | |
| 1127 | + | |
| 1128 | + | |
| 1129 | + | |
| 1130 | + | |
| 1131 | + | |
| 1132 | + | |
| 1133 | + | |
| 1134 | + | |
| 1135 | + | |
| 1136 | + | |
| 1137 | + | |
| 1138 | + | |
| 1139 | + | |
| 1140 | + | |
| 1141 | + | |
| 1142 | + | |
| 1143 | + | |
| 1144 | + | |
| 1145 | + | |
| 1146 | + | |
| 1147 | + | |
| 1148 | + | |
| 1149 | + | |
| 1150 | + | |
| 1151 | + | |
| 1152 | + | |
| 1153 | + | |
| 1154 | + | |
| 1155 | + | |
| 1156 | + | |
| 1157 | + | |
| 1158 | + | |
| 1159 | + | |
| 1160 | + | |
| 1161 | + | |
| 1162 | + | |
| 1163 | + | |
| 1164 | + | |
| 1165 | + | |
| 1166 | + | |
| 1167 | + | |
| 1168 | + | |
| 1169 | + | |
| 1170 | + | |
| 1171 | + | |
1112 | 1172 | | |
1113 | | - | |
1114 | | - | |
1115 | | - | |
1116 | | - | |
1117 | 1173 | | |
1118 | | - | |
| 1174 | + | |
1119 | 1175 | | |
1120 | 1176 | | |
1121 | 1177 | | |
| |||
1217 | 1273 | | |
1218 | 1274 | | |
1219 | 1275 | | |
1220 | | - | |
1221 | | - | |
| 1276 | + | |
| 1277 | + | |
| 1278 | + | |
| 1279 | + | |
1222 | 1280 | | |
1223 | | - | |
1224 | 1281 | | |
| 1282 | + | |
1225 | 1283 | | |
1226 | 1284 | | |
1227 | 1285 | | |
| |||
1257 | 1315 | | |
1258 | 1316 | | |
1259 | 1317 | | |
1260 | | - | |
1261 | | - | |
| 1318 | + | |
1262 | 1319 | | |
1263 | 1320 | | |
1264 | 1321 | | |
| |||
0 commit comments