Commit 1f0a0be
fix(blockchain): allow older-but-justified sources in
## Summary
Mirrors
[leanSpec#716](leanEthereum/leanSpec#716). The
fixed-point attestation loop in `build_block` required `att.source` to
equal `current_justified` exactly. When the store's justified checkpoint
has advanced via a sibling fork while the canonical head's chain has
only proven an earlier slot, the head chain's pool holds a gap-closing
attestation whose source differs from the head's `latest_justified`
checkpoint. The exact-match filter dropped it and block production
aborted with `JustifiedDivergenceNotClosed` ("Fixed-point attestation
loop did not converge").
### Scenario (from the spec PR)
```
block_4(4) -- block_5(5) <-- head
/
genesis -- 1 -- 2 -- 3
\
block_6(6)
```
- `block_4`: 6/8 attest `target=block_1` (justifies slot 1).
- `block_5`: 2/8 attest `target=block_4` (fork-choice weight only).
- `block_6` (sibling of block_4): 6/8 attest `target=block_2` (justifies
slot 2 on the store).
Fork choice picks `block_5` as head; the store's `latest_justified` is
`block_2`, but `block_5`'s post-state still sits at `block_1`. The
proposer at slot 7 builds on `block_5` and must absorb `block_6`'s
attestation from the gossip pool to close the gap.
## Changes
In `build_block` (`crates/blockchain/src/store.rs`):
- Relax the source filter from `att.source != current_justified` to
`att.source.slot > current_justified.slot`, so
older-but-already-justified sources can flow through.
- Build a chain view that `process_block_header` would produce on the
candidate block (the head's `historical_block_hashes` plus `parent_root`
at the parent slot plus `H256::ZERO` for each empty slot between parent
and the candidate) and reject attestations whose `source.root` or
`target.root` do not match it. Prevents pulling in attestations about
other forks now that the exact source check is gone.
- Skip attestations whose target slot is already justified on the chain,
with a genesis self-vote (`source.slot == 0 && target.slot == 0`)
exception for fork-choice bootstrapping.
- Track `current_finalized_slot` and `current_justified_slots` alongside
`current_justified`, refreshing them from `post_state` whenever the STF
iteration advances either checkpoint.
In `state_transition`:
- Add a public `attestation_data_matches_chain(&[H256],
&AttestationData) -> bool` helper.
- Make the `justified_slots_ops` module `pub` so `is_slot_justified` can
be reused from `build_block` without duplicating the relative-index
logic.
The existing process_attestations path already factored the
source/target chain match into `checkpoint_exists` and is left
unchanged.
### Test update
`build_block_caps_attestation_data_entries` previously used fake target
roots that don't appear in the chain. Restructured the setup to build a
head state at slot 51 with populated `historical_block_hashes` and vary
`AttestationData.slot` (rather than the target root) to produce distinct
entries. Still verifies the `MAX_ATTESTATIONS_DATA` cap and gossip-size
bound.
## Test plan
- [x] `cargo fmt --all`
- [x] `cargo clippy --workspace --all-targets -- -D warnings`
- [x] `cargo test --workspace --release` (including
`forkchoice_spectests`, `stf_spectests`, `signature_spectests` against
the pinned leanSpec fixtures)
- [ ] Multi-client devnet run to confirm no regression in steady-state
finalization
> Note: the leanSpec spec test for this scenario
(`test_block_production_justification_gap.py`) is not yet in the pinned
`LEAN_SPEC_COMMIT_HASH`. A follow-up commit hash bump in `Makefile` will
pick it up automatically.
---------
Co-authored-by: Pablo Deymonnaz <pdeymon@fi.uba.ar>build_block (lambdaclass#366)1 parent fc66a05 commit 1f0a0be
2 files changed
Lines changed: 264 additions & 55 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
| 6 | + | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
| |||
1050 | 1051 | | |
1051 | 1052 | | |
1052 | 1053 | | |
1053 | | - | |
1054 | | - | |
1055 | | - | |
1056 | | - | |
1057 | | - | |
1058 | | - | |
1059 | | - | |
1060 | | - | |
1061 | | - | |
1062 | | - | |
1063 | | - | |
| 1054 | + | |
| 1055 | + | |
| 1056 | + | |
| 1057 | + | |
| 1058 | + | |
| 1059 | + | |
| 1060 | + | |
| 1061 | + | |
| 1062 | + | |
| 1063 | + | |
| 1064 | + | |
| 1065 | + | |
| 1066 | + | |
| 1067 | + | |
1064 | 1068 | | |
1065 | 1069 | | |
1066 | 1070 | | |
| |||
1082 | 1086 | | |
1083 | 1087 | | |
1084 | 1088 | | |
1085 | | - | |
| 1089 | + | |
| 1090 | + | |
| 1091 | + | |
| 1092 | + | |
| 1093 | + | |
| 1094 | + | |
| 1095 | + | |
| 1096 | + | |
| 1097 | + | |
| 1098 | + | |
| 1099 | + | |
| 1100 | + | |
| 1101 | + | |
| 1102 | + | |
| 1103 | + | |
| 1104 | + | |
| 1105 | + | |
| 1106 | + | |
| 1107 | + | |
| 1108 | + | |
| 1109 | + | |
| 1110 | + | |
| 1111 | + | |
| 1112 | + | |
1086 | 1113 | | |
1087 | 1114 | | |
1088 | 1115 | | |
| |||
1096 | 1123 | | |
1097 | 1124 | | |
1098 | 1125 | | |
1099 | | - | |
| 1126 | + | |
1100 | 1127 | | |
1101 | 1128 | | |
1102 | 1129 | | |
| |||
1114 | 1141 | | |
1115 | 1142 | | |
1116 | 1143 | | |
1117 | | - | |
| 1144 | + | |
| 1145 | + | |
| 1146 | + | |
1118 | 1147 | | |
| 1148 | + | |
| 1149 | + | |
1119 | 1150 | | |
1120 | 1151 | | |
1121 | 1152 | | |
| |||
1396 | 1427 | | |
1397 | 1428 | | |
1398 | 1429 | | |
| 1430 | + | |
| 1431 | + | |
| 1432 | + | |
| 1433 | + | |
1399 | 1434 | | |
1400 | 1435 | | |
1401 | 1436 | | |
| |||
1404 | 1439 | | |
1405 | 1440 | | |
1406 | 1441 | | |
1407 | | - | |
| 1442 | + | |
| 1443 | + | |
| 1444 | + | |
1408 | 1445 | | |
1409 | 1446 | | |
1410 | 1447 | | |
1411 | 1448 | | |
1412 | 1449 | | |
1413 | 1450 | | |
1414 | 1451 | | |
1415 | | - | |
1416 | 1452 | | |
1417 | | - | |
| 1453 | + | |
| 1454 | + | |
| 1455 | + | |
| 1456 | + | |
| 1457 | + | |
| 1458 | + | |
| 1459 | + | |
| 1460 | + | |
| 1461 | + | |
| 1462 | + | |
| 1463 | + | |
| 1464 | + | |
| 1465 | + | |
| 1466 | + | |
| 1467 | + | |
| 1468 | + | |
| 1469 | + | |
| 1470 | + | |
| 1471 | + | |
| 1472 | + | |
| 1473 | + | |
| 1474 | + | |
| 1475 | + | |
| 1476 | + | |
| 1477 | + | |
| 1478 | + | |
| 1479 | + | |
| 1480 | + | |
1418 | 1481 | | |
1419 | 1482 | | |
1420 | 1483 | | |
1421 | 1484 | | |
1422 | 1485 | | |
1423 | | - | |
1424 | | - | |
1425 | | - | |
| 1486 | + | |
| 1487 | + | |
1426 | 1488 | | |
1427 | | - | |
1428 | | - | |
| 1489 | + | |
| 1490 | + | |
| 1491 | + | |
1429 | 1492 | | |
1430 | | - | |
| 1493 | + | |
| 1494 | + | |
| 1495 | + | |
| 1496 | + | |
| 1497 | + | |
| 1498 | + | |
| 1499 | + | |
| 1500 | + | |
| 1501 | + | |
1431 | 1502 | | |
1432 | 1503 | | |
1433 | 1504 | | |
1434 | 1505 | | |
1435 | 1506 | | |
| 1507 | + | |
1436 | 1508 | | |
1437 | 1509 | | |
1438 | | - | |
| 1510 | + | |
1439 | 1511 | | |
1440 | 1512 | | |
1441 | 1513 | | |
1442 | 1514 | | |
1443 | 1515 | | |
1444 | 1516 | | |
1445 | | - | |
1446 | 1517 | | |
1447 | | - | |
1448 | | - | |
1449 | | - | |
1450 | | - | |
1451 | | - | |
1452 | | - | |
1453 | | - | |
1454 | | - | |
1455 | | - | |
| 1518 | + | |
| 1519 | + | |
| 1520 | + | |
1456 | 1521 | | |
1457 | 1522 | | |
1458 | 1523 | | |
| |||
1513 | 1578 | | |
1514 | 1579 | | |
1515 | 1580 | | |
| 1581 | + | |
| 1582 | + | |
| 1583 | + | |
| 1584 | + | |
| 1585 | + | |
| 1586 | + | |
| 1587 | + | |
| 1588 | + | |
| 1589 | + | |
| 1590 | + | |
| 1591 | + | |
| 1592 | + | |
| 1593 | + | |
| 1594 | + | |
| 1595 | + | |
| 1596 | + | |
| 1597 | + | |
| 1598 | + | |
| 1599 | + | |
| 1600 | + | |
| 1601 | + | |
| 1602 | + | |
| 1603 | + | |
| 1604 | + | |
| 1605 | + | |
| 1606 | + | |
| 1607 | + | |
| 1608 | + | |
| 1609 | + | |
| 1610 | + | |
| 1611 | + | |
| 1612 | + | |
| 1613 | + | |
| 1614 | + | |
| 1615 | + | |
| 1616 | + | |
| 1617 | + | |
| 1618 | + | |
| 1619 | + | |
| 1620 | + | |
| 1621 | + | |
| 1622 | + | |
| 1623 | + | |
| 1624 | + | |
| 1625 | + | |
| 1626 | + | |
| 1627 | + | |
| 1628 | + | |
| 1629 | + | |
| 1630 | + | |
| 1631 | + | |
| 1632 | + | |
| 1633 | + | |
| 1634 | + | |
| 1635 | + | |
| 1636 | + | |
| 1637 | + | |
| 1638 | + | |
| 1639 | + | |
| 1640 | + | |
| 1641 | + | |
| 1642 | + | |
| 1643 | + | |
| 1644 | + | |
| 1645 | + | |
| 1646 | + | |
| 1647 | + | |
| 1648 | + | |
| 1649 | + | |
| 1650 | + | |
| 1651 | + | |
| 1652 | + | |
| 1653 | + | |
| 1654 | + | |
| 1655 | + | |
| 1656 | + | |
| 1657 | + | |
| 1658 | + | |
| 1659 | + | |
| 1660 | + | |
| 1661 | + | |
| 1662 | + | |
| 1663 | + | |
| 1664 | + | |
| 1665 | + | |
| 1666 | + | |
| 1667 | + | |
| 1668 | + | |
| 1669 | + | |
| 1670 | + | |
| 1671 | + | |
| 1672 | + | |
| 1673 | + | |
| 1674 | + | |
| 1675 | + | |
| 1676 | + | |
| 1677 | + | |
| 1678 | + | |
| 1679 | + | |
| 1680 | + | |
| 1681 | + | |
| 1682 | + | |
| 1683 | + | |
| 1684 | + | |
| 1685 | + | |
| 1686 | + | |
| 1687 | + | |
| 1688 | + | |
| 1689 | + | |
| 1690 | + | |
| 1691 | + | |
| 1692 | + | |
| 1693 | + | |
| 1694 | + | |
| 1695 | + | |
| 1696 | + | |
| 1697 | + | |
| 1698 | + | |
| 1699 | + | |
| 1700 | + | |
| 1701 | + | |
| 1702 | + | |
| 1703 | + | |
| 1704 | + | |
| 1705 | + | |
| 1706 | + | |
| 1707 | + | |
| 1708 | + | |
1516 | 1709 | | |
1517 | 1710 | | |
1518 | 1711 | | |
| |||
0 commit comments