# Altair changes in Prysm
## Motivation
Add commentary to Altair code changes to improve on review expereince and note importance for anyone to audit and add some updates of current status of Altair branch (`hf1`) merging in to Develop branch (`develop`)
**Update (10/4): Everything is be under `develop` branch**
## Review by Altair branch
The Altair branch is `hf1` and the corresponding PR which targets the branch to `develop` is:
https://github.com/prysmaticlabs/prysm/pull/9123
Note: we have been incrementally been merging `hf1` to `develop` by using smaller PRs. These merges were under more rigorously review by Preston, but they are still worth looking at for anyone that is interested. The following are already merged into `develop` so it won't show up in `9123`:
**Update (10/4): The above work is done, everything is under `develop`. Skip to `Review by Altair packages` section**
* **Core consensus related**
* Validate sync message time: https://github.com/prysmaticlabs/prysm/pull/9325
* Epoch pre compute: https://github.com/prysmaticlabs/prysm/pull/9309
* Block can process sync aggregate: https://github.com/prysmaticlabs/prysm/pull/9308
* Calculate base reward: https://github.com/prysmaticlabs/prysm/pull/9307
* Sync committee helpers: https://github.com/prysmaticlabs/prysm/pull/9269
* Sync commiteee period helpers: https://github.com/prysmaticlabs/prysm/pull/9248
* Sync committee pool: https://github.com/prysmaticlabs/prysm/pull/9203
* Altair deposits: https://github.com/prysmaticlabs/prysm/pull/9227
* **Beacon state pkg related**
* https://github.com/prysmaticlabs/prysm/pull/9283
* https://github.com/prysmaticlabs/prysm/pull/9279
* https://github.com/prysmaticlabs/prysm/pull/9228
## Review by Altair packages
Another way to review at all the Altair changes is to group them by package. The relevant packages are
* Core consensus
* General: https://github.com/prysmaticlabs/prysm/tree/develop/beacon-chain/core/altair
* Some sync committee related helpers that utilize caching are here: https://github.com/prysmaticlabs/prysm/blob/develop/beacon-chain/core/helpers/committee.go
* State transition
* The post state transition for is part of: https://github.com/prysmaticlabs/prysm/blob/develop/beacon-chain/core/state/transition_no_verify_sig.go
* Process slots where the upgrade ot fork happens:
https://github.com/prysmaticlabs/prysm/blob/develop/beacon-chain/core/state/transition.go
* Beacon node (server) <-> validator (client) RPC interaction
* Beacon node RPC end points
* Updated duties end point so Altair validator can get sync committee duty https://github.com/prysmaticlabs/prysm/blob/develop/beacon-chain/rpc/prysm/v1alpha1/validator/assignments.go
* Updated block streaming to support Altair https://github.com/prysmaticlabs/prysm/blob/develop/beacon-chain/rpc/prysm/v1alpha1/validator/blocks.go
* Updated get and submit Altair beacon block end points https://github.com/prysmaticlabs/prysm/blob/develop/beacon-chain/rpc/prysm/v1alpha1/validator/proposer.go
* Optimization to filter out most profitable sync aggregate https://github.com/prysmaticlabs/prysm/blob/develop/beacon-chain/rpc/prysm/v1alpha1/validator/proposer_sync_aggregate.go
* Added new get and submit sync committee message and contribution end points https://github.com/prysmaticlabs/prysm/blob/develop/beacon-chain/rpc/prysm/v1alpha1/validator/sync_committee.go
* Validator client using the new end points
* Can sign Altair block https://github.com/prysmaticlabs/prysm/blob/develop/validator/client/propose.go
* Can sign sync committee message and contribution https://github.com/prysmaticlabs/prysm/blob/develop/validator/client/sync_committee.go
* Can cache sync committee related role for current epoch https://github.com/prysmaticlabs/prysm/blob/develop/validator/client/validator.go
* Networking
* Can broadcast sync committee message https://github.com/prysmaticlabs/prysm/blob/develop/beacon-chain/p2p/broadcaster.go
* Can discover sync committee subnet https://github.com/prysmaticlabs/prysm/blob/develop/beacon-chain/p2p/discovery.go
* Can subscribe to new subnet https://github.com/prysmaticlabs/prysm/blob/develop/beacon-chain/p2p/subnets.go https://github.com/prysmaticlabs/prysm/blob/develop/beacon-chain/sync/subscriber.go
* Can watch for fork https://github.com/prysmaticlabs/prysm/blob/develop/beacon-chain/p2p/fork_watcher.go
* New gossip scoring changes https://github.com/prysmaticlabs/prysm/blob/develop/beacon-chain/p2p/gossip_scoring_params.go
* New metadata handler https://github.com/prysmaticlabs/prysm/blob/develop/beacon-chain/sync/rpc_metadata.go
* Validate sync committee message from p2p https://github.com/prysmaticlabs/prysm/blob/develop/beacon-chain/sync/validate_sync_committee_message.go
* Validate sync contribution message from p2p https://github.com/prysmaticlabs/prysm/blob/develop/beacon-chain/sync/validate_sync_contrbution_proof.go
* Helpers to retrieve fork digest https://github.com/prysmaticlabs/prysm/blob/develop/shared/p2putils/fork.go
* Sync committee pool
* Added a new sync committee pool to cache sync committee objects received from p2p or local rpc. https://github.com/prysmaticlabs/prysm/tree/develop/beacon-chain/operations/synccommittee
* New beacon state v2
* Beacons state v2 that is similar to v1 but with modified altair state fields https://github.com/prysmaticlabs/prysm/tree/develop/beacon-chain/state/v2
* New sync committee related caching
* Caches head state with highest slot:
* https://github.com/prysmaticlabs/prysm/blob/develop/beacon-chain/blockchain/head_sync_committee_info.go
* Caches sync committee positions for current and next period:
* https://github.com/prysmaticlabs/prysm/blob/develop/beacon-chain/cache/sync_committee.go
* Caches are utililzed by these helpers:
* https://github.com/prysmaticlabs/prysm/blob/develop/beacon-chain/core/helpers/committee.go
* Total active balance is also cached now:
* https://github.com/prysmaticlabs/prysm/pull/9123/files#diff-c8ffb6619fa0a80bffcf809110bdb5d6b592bac308387ac12edaa252f184eda7R55
* Beacon state DB changes
* Changes to support Altair. Ensures marshal and unmarshal to the correct protobuf object. https://github.com/prysmaticlabs/prysm/blob/develop/beacon-chain/db/kv/state.go