Skip to content

Commit

Permalink
fix: network subgraph filtering for optimizing over time
Browse files Browse the repository at this point in the history
  • Loading branch information
hopeyen committed Jul 12, 2022
1 parent fd62323 commit 6492f6e
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 23 deletions.
12 changes: 9 additions & 3 deletions scripts/allocationopt
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@ Optimises an indexer's allocations and pushes them to the action queue.
# Pull network state from indexer service network endpoint
indexer, repo = network_state(id, cols..., indexer_service_network_url)

# Pull full network state from indexer service network endpoint
_, fullrepo = network_state(id, String[], String[], String[], String[], indexer_service_network_url)

# Optimize for the indexer
ω = optimize_indexer(repo, indexer, parse(Float64, minimum_allocation_amount), parse(Int64, maximum_new_allocations), parse(Float64, τ))
ω = optimize_indexer(indexer, repo, fullrepo, parse(Float64, minimum_allocation_amount), parse(Int64, maximum_new_allocations), parse(Float64, τ))

# Push results to action queue
_ = push_allocations!(id, management_server_url, indexer_service_network_url, ω, cols...)
Expand Down Expand Up @@ -52,10 +55,13 @@ Optimises an indexer's allocations and generates indexer rules to change allocat
cols = read_filterlists(filepath)

# Pull network state from indexer service network endpoint
indexer, repo = network_state(id, cols..., indexer_service_network_url)
repo, indexer = network_state(id, cols..., indexer_service_network_url)

# Pull full network state from indexer service network endpoint
fullrepo, _ = network_state(id, String[], String[], String[], String[], indexer_service_network_url)

# Optimize for the indexer
ω = optimize_indexer(repo, indexer, parse(Float64, minimum_allocation_amount), parse(Int64, maximum_new_allocations), parse(Float64, τ))
ω = optimize_indexer(indexer, repo, fullrepo, parse(Float64, minimum_allocation_amount), parse(Int64, maximum_new_allocations), parse(Float64, τ))

# Create indexer rules
indexer_rules = create_rules!(id, indexer_service_network_url, ω, cols...)
Expand Down
13 changes: 10 additions & 3 deletions src/AllocationOpt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ end
function optimize_indexer(
indexer::Indexer,
repo::Repository,
fullrepo::Repository,
minimum_allocation_amount::Real,
maximum_new_allocations::Integer,
τ::AbstractFloat,
Expand All @@ -86,11 +87,17 @@ function optimize_indexer(

# Optimise
# ω = optimize(indexer, repo, maximum_new_allocations, minimum_allocation_amount)
Ω = stakes(repo)
Ωfull = stakes(fullrepo)
ψfull = signal.(fullrepo.subgraphs)
σfull = sum(Ωfull)
Ωprime = discount(Ωfull, ψfull, σfull, τ)
# 💻 = Ωprime[intersect(id.(fullrepo.subgraphs),id.(repo.subgraphs))]
ψids = id.(repo.subgraphs)
ψfullids = id.(fullrepo.subgraphs)
Ω = Ωprime[findall(x -> x in ψids, ψfullids)]
ψ = signal.(repo.subgraphs)
σ = indexer.stake
Ωprime = discount(Ω, ψ, σ, τ)
ω = optimize(Ωprime, ψ, σ)
ω = optimize(Ω, ψ, σ)

# Filter results with deployment IPFS hashes
suggested_allocations = Dict(
Expand Down
17 changes: 3 additions & 14 deletions test/example.csv
Original file line number Diff line number Diff line change
@@ -1,15 +1,4 @@
whitelist,blacklist,pinnedlist,frozenlist
QmZfeJYR86UARzp9HiXbURWunYgC9ywvPvoePNbuaATrEK,QmXvEzRJXby7KFuTr7NJsM47hGefM5VckEXZrQyZzL9eJd,,QmWyYetiXyfVDRJdnQtd7avKvAegDnFRJb7sq9oto9oJQU
QmVEV7RA2U6BJT9Ssjxcfyrk4YQUnVqSRNX4TvYagjzh9h,QmWxteQps5mtjAx14XD1uycg6kJkFN8EPW7561iZE3dJz8,,
QmVqMeQUwvQ3XjzCYiMhRvQjRiQLGpVt8C3oHgvDi3agJ2,,,
QmRDGLp6BHwiH9HAE2NYEE3f7LrKuRqziHBv76trT4etgU,,,
QmbvTyvmxqHLahZwS7fZtVWGM85VCpCiKHiagPxQJp5ktS,,,
QmTKXLEdMD6Vq7Nwxo8XAfnHpG6H1TzL1AGwiqLpoae3Pb,,,
QmXdBEUvt2S1GRsp2rhBiDebzUNa4sjMgFyMXVdmdukUif,,,
Qmaz1R8vcv9v3gUfksqiS9JUz7K9G8S5By3JYn8kTiiP5K,,,
QmZdsSbRwVD7VVVm5WGxZZC6HYvbjnFb4hcwvQ4fTs5bxA,,,
Qmav8jkmAeKBLyxmngJVwprN3ZsJA9A57jeoikdCU2Dyrv,,,
QmRhh7rFt3qxfRMTZvHRNK6jCobX4Gx5TkzWXhZkuj57w8,,,
QmNRkaVUwUQAwPwWgdQHYvw53A5gh3CP3giWnWQZdA2BTE,,,
Qmeddd6yYuZUAjJ3Cs2xnbSPRJWPc1rUYN5nXHXhwg9N8t,,,
Qmc8LfCeqBxxSGzc6eRhZ7Wmf3HjiZfDN2PgQxR9Tz3FbV,,,
,QmXvEzRJXby7KFuTr7NJsM47hGefM5VckEXZrQyZzL9eJd,,
,QmWxteQps5mtjAx14XD1uycg6kJkFN8EPW7561iZE3dJz8,,

6 changes: 3 additions & 3 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ using GraphQLClient
repo, optindexer = network_state(
id, String[ipfshash], String[], String[], String[], gateway_url
)
allocs = optimize_indexer(optindexer, repo, 0.0, 10000, τ)
allocs = optimize_indexer(optindexer, repo, repo, 0.0, 10000, τ)
# Sum allocation amounts
ω = sum(values(allocs))
@test isapprox(ω, stake; atol=1e-6)
Expand All @@ -69,7 +69,7 @@ using GraphQLClient
String[],
gateway_url,
)
allocs = optimize_indexer(optindexer, repo, 0.0, 10000, τ)
allocs = optimize_indexer(optindexer, repo, repo, 0.0, 10000, τ)
# Sum allocation amounts
ω = sum(values(allocs))
@test isapprox(ω, stake; atol=1e-6)
Expand All @@ -83,7 +83,7 @@ using GraphQLClient
stake = togrt(indexer["delegatedTokens"]) + togrt(indexer["stakedTokens"])
cols = read_filterlists("example.csv")
repo, optindexer = network_state(id, cols..., gateway_url)
allocs = optimize_indexer(optindexer, repo, 0.0, 10000, τ)
allocs = optimize_indexer(optindexer, repo, repo, 0.0, 10000, τ)
ω = sum(values(allocs))
@test isapprox(ω, stake; atol=1e-6)
end
Expand Down

0 comments on commit 6492f6e

Please sign in to comment.