Skip to content

Commit 68bbd82

Browse files
committed
feat: implement transactional start slot metadata updates per provider
- Replace simple LatestSlot assignment with new updateStartSlot() function that properly handles per-provider slot tracking - Implement transaction-based metadata updates using BeginTx/SetMetadata/CommitTx pattern for atomicity and consistency - Set LatestSlots for each relay provider instead of single LatestSlot field - Add proper error handling with context cancellation on transaction failure
1 parent dcb8497 commit 68bbd82

1 file changed

Lines changed: 33 additions & 1 deletion

File tree

services/bids/standard/service.go

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,12 @@ func (s *Service) onStart(ctx context.Context,
8484
if err != nil {
8585
return errors.Wrap(err, "failed to obtain metadata")
8686
}
87+
8788
if startSlot >= 0 {
88-
md.LatestSlot = startSlot - 1
89+
err := updateStartSlot(ctx, s, md, startSlot)
90+
if err != nil {
91+
return err
92+
}
8993
}
9094

9195
log.Trace().Msg("Running initial catchup")
@@ -110,6 +114,34 @@ func (s *Service) onStart(ctx context.Context,
110114
return nil
111115
}
112116

117+
func updateStartSlot(ctx context.Context, s *Service, md *metadata, startSlot int64) error {
118+
md.mu.Lock()
119+
defer md.mu.Unlock()
120+
121+
opCtx, cancel, err := s.receivedBidsSetter.BeginTx(ctx)
122+
if err != nil {
123+
return errors.Wrap(err, "failed to begin transaction for metadata update")
124+
}
125+
126+
for _, prov := range s.receivedBidTracesProviders {
127+
name := prov.Name()
128+
if cur, ok := md.LatestSlots[name]; !ok || cur < startSlot-1 {
129+
md.LatestSlots[name] = startSlot - 1
130+
}
131+
}
132+
133+
if err := s.setMetadata(ctx, md); err != nil {
134+
return errors.Wrap(err, "failed to set metadata")
135+
}
136+
137+
if err := s.receivedBidsSetter.CommitTx(opCtx); err != nil {
138+
cancel()
139+
return errors.Wrap(err, "failed to commit metadata transaction")
140+
}
141+
142+
return nil
143+
}
144+
113145
func (s *Service) onTick(ctx context.Context, _ any) {
114146
// Only allow 1 handler to be active.
115147
acquired := s.activitySem.TryAcquire(1)

0 commit comments

Comments
 (0)