# Slot tracking TODO REMOVE
## ~~Добавить флаг devmode~~
можно и просто `--dev` но перепроверить и удалить старую логику связанную с этим флагом если такая еще осталась.
## ~~Add fields to Genesis~~
````go
// Genesis specifies the header fields, state of a genesis block. It also defines hard
// fork switch-over blocks through the chain configuration.
type Genesis struct {
Config *params.ChainConfig `json:"config"`
Timestamp uint64 `json:"timestamp"`
ExtraData []byte `json:"extraData"`
GasLimit uint64 `json:"gasLimit" gencodec:"required"`
Coinbase common.Address `json:"coinbase"`
Alloc GenesisAlloc `json:"alloc" gencodec:"required"`
// Добавляем поля
GenesisTime uint64 `json:"genesisTime"`
SecondsPerSlot uint64 `json:"secondsPerSlot"`
SlotsPerEpoch uint64 `json:"slotsPerEpoch"`
// These fields are used for consensus tests. Please don't use them
// in actual genesis blocks.
GasUsed uint64 `json:"gasUsed"`
ParentHashes []common.Hash `json:"parentHashes"`
Slot uint64 `json:"slot"`
Height uint64 `json:"height"`
BaseFee *big.Int `json:"baseFeePerGas"`
}
````
## ~~В `core/types/block_dag.go` добавить структуру и функционал для работы с данными слота~~
````go
type SlotInfo struct {
GenesisTime uint64 `json:"genesisTime"`
SecondsPerSlot uint64 `json:"secondsPerSlot"`
SlotsPerEpoch uint64 `json:"slotsPerEpoch"`
}
func (si *SlotInfo) CurrentSlot() uint64
func (si *SlotInfo) CurrentEpoch() uint64
/* И что-то типа такого: */
// ToEpoch returns the epoch number of the input slot.
//
// Spec pseudocode definition:
// def compute_epoch_at_slot(slot: Slot) -> Epoch:
// """
// Return the epoch number at ``slot``.
// """
// return Epoch(slot // SLOTS_PER_EPOCH)
func ToEpoch(slot types.Slot) types.Epoch {
return types.Epoch(slot.DivSlot(params.BeaconConfig().SlotsPerEpoch))
}
// EpochStart returns the first slot number of the
// current epoch.
//
// Spec pseudocode definition:
// def compute_start_slot_at_epoch(epoch: Epoch) -> Slot:
// """
// Return the start slot of ``epoch``.
// """
// return Slot(epoch * SLOTS_PER_EPOCH)
func EpochStart(epoch types.Epoch) (types.Slot, error) {
slot, err := params.BeaconConfig().SlotsPerEpoch.SafeMul(uint64(epoch))
if err != nil {
return slot, errors.Errorf("start slot calculation overflows: %v", err)
}
return slot, nil
}
// EpochEnd returns the last slot number of the
// current epoch.
func EpochEnd(epoch types.Epoch) (types.Slot, error) {
if epoch == math.MaxUint64 {
return 0, errors.New("start slot calculation overflows")
}
slot, err := EpochStart(epoch + 1)
if err != nil {
return 0, err
}
return slot - 1, nil
}
// IsEpochStart returns true if the given slot number is an epoch starting slot
// number.
func IsEpochStart(slot types.Slot) bool {
return slot%params.BeaconConfig().SlotsPerEpoch == 0
}
// IsEpochEnd returns true if the given slot number is an epoch ending slot
// number.
func IsEpochEnd(slot types.Slot) bool {
return IsEpochStart(slot + 1)
}
// SinceEpochStarts returns number of slots since the start of the epoch.
func SinceEpochStarts(slot types.Slot) types.Slot {
return slot % params.BeaconConfig().SlotsPerEpoch
}
````
## ~~В `blockchain`~~
1. добаляем поле `slotInfo SlotInfo`
2. добавляем к нему функционал
````go
SetSlotInfo (si SlotInfo)
GetSlotInfo () SlotInfo
````
3. При начальной инициализации блокчейна сетим в slotInfo данные из генезиса
## ~~dev mode доработки~~
1. для `func (d *Dag) HandleHeadSyncReady(checkpoint *types.ConsensusInfo) (bool, error)` создать __новый__ тип параметра который будет содержать `SlotInfo`
````go
type HeadSyncReadyData struct {
checkpoint *types.ConsensusInfo
slotInfo *SlotInfo
}
````
2. внести соответствующие доработки вызова в бикон и обработка в живат
````go
/* beacon-chain/sync/initial-sync/head_sync.go:50 */
func (s *Service) execHeadSyncReady(ctx context.Context) error {
...
isReady, err := s.cfg.ExecutionEngineCaller.ExecutionDagHeadSyncReady(ctx, syncParam)
...
}
````
4. если запуженно с флагом режим разработки - обновить `slotInfo`, иначе - игнорируем
## ~~Использовать Таймстамп вместо ГенезисТайм~~
## ~~Доработать апи консенсуса~~
1. Подчистить параметры апи
2. Перетегать сборку