updater changes

This commit is contained in:
Raul Jordan
2021-10-21 09:57:40 -04:00
parent a7fc25f2e0
commit a3ad254b78

View File

@@ -19,6 +19,7 @@ const (
FinalizedRootIndexFloorLog2 = 6
NextSyncCommitteeIndex = 55
NextSyncCommitteeIndexFloorLog2 = 5
PREV_DATA_MAX_SIZE = 64
)
type Service struct {
@@ -39,6 +40,32 @@ type signatureData struct {
syncAggregate *ethpb.SyncAggregate
}
/**
* To be called in API route GET /eth/v1/lightclient/best_update/:periods
*/
//async getBestUpdates(periods: SyncPeriod[]): Promise<altair.LightClientUpdate[]> {
//const updates: altair.LightClientUpdate[] = [];
//for (const period of periods) {
//const update = await this.db.bestUpdatePerCommitteePeriod.get(period);
//if (update) updates.push(update);
//}
//return updates;
//}
//
///**
// * To be called in API route GET /eth/v1/lightclient/latest_update_finalized/
// */
//async getLatestUpdateFinalized(): Promise<altair.LightClientUpdate | null> {
//return this.db.latestFinalizedUpdate.get();
//}
//
///**
// * To be called in API route GET /eth/v1/lightclient/latest_update_nonfinalized/
// */
//async getLatestUpdateNonFinalized(): Promise<altair.LightClientUpdate | null> {
//return this.db.latestNonFinalizedUpdate.get();
//}
func (s *Service) onHead(head block.BeaconBlock, postState state.BeaconStateAltair) error {
innerState, ok := postState.InnerStateUnsafe().(*ethpb.BeaconStateAltair)
if !ok {
@@ -75,11 +102,7 @@ func (s *Service) onHead(head block.BeaconBlock, postState state.BeaconStateAlta
if err != nil {
return err
}
// Recover attested data from prevData cache. If not found, this SyncAggregate is useless
syncAttestedData, ok := s.prevHeadData[bytesutil.ToBytes32(syncAttestedBlockRoot)]
if !ok {
return errors.New("useless")
}
fork, err := forks.Fork(slots.ToEpoch(head.Slot()))
if err != nil {
return err
@@ -93,20 +116,36 @@ func (s *Service) onHead(head block.BeaconBlock, postState state.BeaconStateAlta
forkVersion: fork.CurrentVersion,
syncAggregate: syncAggregate,
}
// Recover attested data from prevData cache. If not found, this SyncAggregate is useless
syncAttestedData, ok := s.prevHeadData[bytesutil.ToBytes32(syncAttestedBlockRoot)]
if !ok {
return errors.New("useless")
}
commmitteePeriodWithFinalized, err := s.persistBestFinalizedUpdate(syncAttestedData, sigData)
if err != nil {
return err
}
//// Store the best finalized update per period
//const committeePeriodWithFinalized = await this.persistBestFinalizedUpdate(syncAttestedData, signatureData);
//// Then, store the best non finalized update per period
//await this.persistBestNonFinalizedUpdate(syncAttestedData, signatureData, committeePeriodWithFinalized);
//
//// Prune old prevHeadData
//if (this.prevHeadData.size > PREV_DATA_MAX_SIZE) {
// for (const key of this.prevHeadData.keys()) {
// this.prevHeadData.delete(key);
// if (this.prevHeadData.size <= PREV_DATA_MAX_SIZE) {
// break;
// }
// }
//}
// Then, store the best non finalized update per period
if err := s.persistBestNonFinalizedUpdate(syncAttestedData, sigData, commmitteePeriodWithFinalized); err != nil {
return err
}
// Prune old prevHeadData
if len(s.prevHeadData) > PREV_DATA_MAX_SIZE {
for k := range s.prevHeadData {
delete(s.prevHeadData, k)
if len(s.prevHeadData) <= PREV_DATA_MAX_SIZE {
break
}
}
}
return nil
}
func (s *Service) persistBestFinalizedUpdate(data *update, sigData *signatureData) (types.Epoch, error) {
return 0, nil
}
func (s Service) persistBestNonFinalizedUpdate(data *update, sigData *signatureData, period types.Epoch) error {
return nil
}