diff --git a/CHANGELOG_PENDING.md b/CHANGELOG_PENDING.md index 38d5e2ab12..6654021d23 100644 --- a/CHANGELOG_PENDING.md +++ b/CHANGELOG_PENDING.md @@ -10,6 +10,8 @@ #### Broadcaster +- \#2188 Include pending Os in the discovery mechanism (@leszko) + #### Orchestrator #### Transcoder diff --git a/discovery/db_discovery.go b/discovery/db_discovery.go index b2d4ee8875..69130625db 100644 --- a/discovery/db_discovery.go +++ b/discovery/db_discovery.go @@ -70,7 +70,7 @@ func (dbo *DBOrchestratorPoolCache) getURLs() ([]*url.URL, error) { orchs, err := dbo.store.SelectOrchs( &common.DBOrchFilter{ MaxPrice: server.BroadcastCfg.MaxPrice(), - CurrentRound: dbo.rm.LastInitializedRound(), + CurrentRound: dbo.nextRound(), UpdatedLastDay: true, }, ) @@ -168,7 +168,7 @@ func (dbo *DBOrchestratorPoolCache) Size() int { count, _ := dbo.store.OrchCount( &common.DBOrchFilter{ MaxPrice: server.BroadcastCfg.MaxPrice(), - CurrentRound: dbo.rm.LastInitializedRound(), + CurrentRound: dbo.nextRound(), UpdatedLastDay: true, }, ) @@ -200,7 +200,7 @@ func (dbo *DBOrchestratorPoolCache) cacheTranscoderPool() error { func (dbo *DBOrchestratorPoolCache) cacheOrchestratorStake() error { orchs, err := dbo.store.SelectOrchs( &common.DBOrchFilter{ - CurrentRound: dbo.rm.LastInitializedRound(), + CurrentRound: dbo.nextRound(), }, ) if err != nil { @@ -276,7 +276,7 @@ func (dbo *DBOrchestratorPoolCache) pollOrchestratorInfo(ctx context.Context) er func (dbo *DBOrchestratorPoolCache) cacheDBOrchs() error { orchs, err := dbo.store.SelectOrchs( &common.DBOrchFilter{ - CurrentRound: dbo.rm.LastInitializedRound(), + CurrentRound: dbo.nextRound(), }, ) if err != nil { @@ -353,6 +353,13 @@ func (dbo *DBOrchestratorPoolCache) cacheDBOrchs() error { return nil } +func (dbo *DBOrchestratorPoolCache) nextRound() *big.Int { + if dbo.rm.LastInitializedRound() == nil { + return nil + } + return new(big.Int).Add(dbo.rm.LastInitializedRound(), big.NewInt(1)) +} + func parseURI(addr string) (*url.URL, error) { if !strings.HasPrefix(addr, "http") { addr = "https://" + addr diff --git a/discovery/discovery_test.go b/discovery/discovery_test.go index 36bfa27da4..cafde76940 100644 --- a/discovery/discovery_test.go +++ b/discovery/discovery_test.go @@ -1070,12 +1070,13 @@ func TestCachedPool_GetOrchestrators_OnlyActiveOrchestrators(t *testing.T) { } // check size - assert.Equal(25, pool.Size()) + // 25 active Os + 1 pending O + assert.Equal(26, pool.Size()) infos := pool.GetInfos() - assert.Len(infos, 25) + assert.Len(infos, 26) for _, info := range infos { - assert.Contains(addresses[:25], info.URL.String()) + assert.Contains(addresses[:26], info.URL.String()) } oinfos, err := pool.GetOrchestrators(context.TODO(), 50, newStubSuspender(), newStubCapabilities(), common.ScoreAtLeast(0)) for _, info := range oinfos { @@ -1084,7 +1085,7 @@ func TestCachedPool_GetOrchestrators_OnlyActiveOrchestrators(t *testing.T) { } assert.Nil(err, "Should not be error") - assert.Len(infos, 25) + assert.Len(infos, 26) } func TestNewWHOrchestratorPoolCache(t *testing.T) {