From b29e5bb7590a1a80780cb991432a29cf3ae384c6 Mon Sep 17 00:00:00 2001 From: Ganesh Vanahalli Date: Mon, 27 Jan 2025 16:01:25 +0530 Subject: [PATCH] address PR comments --- execution/gethexec/express_lane_service.go | 29 ++++++++++++---------- timeboost/redis_coordinator.go | 2 +- timeboost/redis_coordinator_test.go | 6 +++++ 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/execution/gethexec/express_lane_service.go b/execution/gethexec/express_lane_service.go index acc42a4030..92bee9d0cd 100644 --- a/execution/gethexec/express_lane_service.go +++ b/execution/gethexec/express_lane_service.go @@ -293,6 +293,13 @@ func (es *expressLaneService) Start(ctxIn context.Context) { }) } +func (es *expressLaneService) StopAndWait() { + es.StopWaiter.StopAndWait() + if es.redisCoordinator != nil { + es.redisCoordinator.StopAndWait() + } +} + func (es *expressLaneService) currentRoundHasController() bool { controller, ok := es.roundControl.Load(es.roundTimingInfo.RoundNumber()) if !ok { @@ -472,25 +479,21 @@ func (es *expressLaneService) syncFromRedis() { return } - es.roundInfoMutex.Lock() currentRound := es.roundTimingInfo.RoundNumber() - - // If expressLaneRoundInfo for current round doesn't exist yet, we'll add it to the cache - if !es.roundInfo.Contains(currentRound) { - es.roundInfo.Add(currentRound, &expressLaneRoundInfo{ - 0, - make(map[uint64]*msgAndResult), - }) - } - roundInfo, _ := es.roundInfo.Get(currentRound) - redisSeqCount, err := es.redisCoordinator.GetSequenceCount(currentRound) if err != nil { log.Error("error fetching current round's global sequence count from redis", "err", err) - } else if redisSeqCount > roundInfo.sequence { - roundInfo.sequence = redisSeqCount } + es.roundInfoMutex.Lock() + roundInfo, exists := es.roundInfo.Get(currentRound) + if !exists { + // If expressLaneRoundInfo for current round doesn't exist yet, we'll add it to the cache + roundInfo = &expressLaneRoundInfo{0, make(map[uint64]*msgAndResult)} + } + if redisSeqCount > roundInfo.sequence { + roundInfo.sequence = redisSeqCount + } es.roundInfo.Add(currentRound, roundInfo) es.roundInfoMutex.Unlock() diff --git a/timeboost/redis_coordinator.go b/timeboost/redis_coordinator.go index a52856bbd0..31a50e4042 100644 --- a/timeboost/redis_coordinator.go +++ b/timeboost/redis_coordinator.go @@ -121,7 +121,7 @@ func (rc *RedisCoordinator) GetAcceptedTxs(round, startSeqNum uint64) []*Express for _, key := range keys { seq, err := strconv.Atoi(strings.TrimPrefix(key, prefix)) if err != nil { - log.Error("") + log.Error("Error getting sequence number from the redis key of accepted timeboost Tx", "key", key, "error", err) continue } // #nosec G115 diff --git a/timeboost/redis_coordinator_test.go b/timeboost/redis_coordinator_test.go index e4834fead6..1a6853cbdb 100644 --- a/timeboost/redis_coordinator_test.go +++ b/timeboost/redis_coordinator_test.go @@ -45,6 +45,12 @@ func TestRedisSeqCoordinatorAtomic(t *testing.T) { t.Fatalf("error setting round number and sequence count: %v", err) } checkSeqCountInRedis(3) + round = 1 + err = redisCoordinator.UpdateSequenceCount(round, 4) // shouldn't succeed as the sequence count is a lower value + if err != nil { + t.Fatalf("error setting round number and sequence count: %v", err) + } + checkSeqCountInRedis(4) // Test adding and retrieval of expressLane messages var addedMsgs []*ExpressLaneSubmission