Compare commits

...

1 Commits

Author SHA1 Message Date
Potuz
e003054788 Only process attestations and update head once per slot 2023-03-06 22:01:46 -03:00
2 changed files with 21 additions and 4 deletions

View File

@@ -45,9 +45,10 @@ func (s *Service) UpdateAndSaveHeadWithBalances(ctx context.Context) error {
// This defines the current chain service's view of head.
type head struct {
root [32]byte // current head root.
block interfaces.ReadOnlySignedBeaconBlock // current head block.
state state.BeaconState // current head state.
root [32]byte // current head root.
block interfaces.ReadOnlySignedBeaconBlock // current head block.
state state.BeaconState // current head state.
lastTick primitives.Slot
}
// This saves head info to the local service cache, it also saves the
@@ -251,6 +252,12 @@ func (s *Service) headRoot() [32]byte {
return s.head.root
}
// This returns the last slot where we have processed attestations
// This is a lock free version
func (s *Service) lastTick() primitives.Slot {
return s.head.lastTick
}
// This returns the head block.
// It does a full copy on head block for immutability.
// This is a lock free version.

View File

@@ -120,6 +120,13 @@ func (s *Service) spawnProcessAttestationsRoutine(stateFeed *event.Feed) {
// The caller of this function MUST hold a lock in forkchoice
func (s *Service) UpdateHead(ctx context.Context, proposingSlot primitives.Slot) {
start := time.Now()
// Only update head once per slot at the beginning of the slot
s.headLock.RLock()
lastTick := s.lastTick()
s.headLock.RUnlock()
if lastTick >= proposingSlot && proposingSlot == s.CurrentSlot() {
return
}
// This function is only called at 10 seconds or 0 seconds into the slot
disparity := params.BeaconNetworkConfig().MaximumGossipClockDisparity
@@ -127,9 +134,12 @@ func (s *Service) UpdateHead(ctx context.Context, proposingSlot primitives.Slot)
disparity += reorgLateBlockCountAttestations
}
s.processAttestations(ctx, disparity)
processAttsElapsedTime.Observe(float64(time.Since(start).Milliseconds()))
s.headLock.Lock()
s.head.lastTick = proposingSlot
s.headLock.Unlock()
start = time.Now()
newHeadRoot, err := s.cfg.ForkChoiceStore.Head(ctx)
if err != nil {