Skip to content

Commit

Permalink
discovery: Include Pending Os in discovery
Browse files Browse the repository at this point in the history
  • Loading branch information
leszko committed Jan 17, 2022
1 parent a407b90 commit 198c4fd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
15 changes: 11 additions & 4 deletions discovery/db_discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
)
Expand Down Expand Up @@ -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,
},
)
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
9 changes: 5 additions & 4 deletions discovery/discovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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) {
Expand Down

0 comments on commit 198c4fd

Please sign in to comment.