diff --git a/docs/src/index.md b/docs/src/index.md index 67b566b..d708801 100644 --- a/docs/src/index.md +++ b/docs/src/index.md @@ -47,7 +47,7 @@ We recommend making queries to the network subgraph served by your own indexer s Alternatively, you can supply an API url to `indexer_service_network_url` from the decentralized gateway or hosted service. To provide the network subgraph to the optimiser, set the indexer-service flag `--serve-network-subgraph` to `true`. -Populate your preferred lists (whitelist, blacklist, pinnedlist, frozenlist) into a CSV and remember its file path +Populate your preferred lists (whitelist, blacklist, pinnedlist, frozenlist) into a CSV and take note of its file path. If you choose to supply specific deployment preferences through this list, please read list definitions in detail and keep the file updated to your expectations as it changes the problem statement for the optimiser. !!! note You can access the help for the optimiser by running the script with the `--help` flag. diff --git a/scripts/allocationopt b/scripts/allocationopt index b37792b..d2bf9e8 100755 --- a/scripts/allocationopt +++ b/scripts/allocationopt @@ -69,7 +69,8 @@ Optimise an indexer's allocations and generates indexer rules to change allocati pinnedlist = cols[3] # Pull network state from indexer service network endpoint - println("Reading network state.") repo, indexer, network = network_state(id, parse(Int, network_id), cols..., indexer_service_network_url) + println("Reading network state.") + repo, indexer, network = network_state(id, parse(Int, network_id), cols..., indexer_service_network_url) # Pull full network state from indexer service network endpoint fullrepo, _, _ = network_state(id, parse(Int, network_id), String[], String[], String[], String[], indexer_service_network_url) diff --git a/src/AllocationOpt.jl b/src/AllocationOpt.jl index e5db150..84479a3 100644 --- a/src/AllocationOpt.jl +++ b/src/AllocationOpt.jl @@ -121,7 +121,7 @@ function optimize_indexer( throw(ArgumentError("τ must be between 0 and 1.")) end if maximum_new_allocations > length(repo.subgraphs) - @warn "Maximum new allocations is more than the number of available subgraph deployments; setting it to the number of subgraphs" + @warn "Maximum new allocations is more than the number of available subgraph deployments; setting it to the number of subgraphs: $(length(repo.subgraphs))" maximum_new_allocations = length(repo.subgraphs) end diff --git a/src/domainmodel.jl b/src/domainmodel.jl index 424341d..1c6fb07 100644 --- a/src/domainmodel.jl +++ b/src/domainmodel.jl @@ -30,10 +30,16 @@ struct Indexer <: GraphEntity stake::Real allocations::AbstractVector{Allocation} - function Indexer(id, delegation::AbstractString, stake::AbstractString, allocation) + function Indexer( + id, + delegation::AbstractString, + stake::AbstractString, + locked_tokens::AbstractString, + allocation, + ) return new( id, - togrt(stake) + togrt(delegation), + togrt(stake) + togrt(delegation) - togrt(locked_tokens), map( x -> Allocation( x["subgraphDeployment"]["ipfsHash"], diff --git a/src/query.jl b/src/query.jl index 21ec0bb..27121b9 100644 --- a/src/query.jl +++ b/src/query.jl @@ -96,12 +96,19 @@ function query_indexers(client::Client, subgraphs::AbstractVector{SubgraphDeploy "id", "delegatedTokens", "stakedTokens", + "lockedTokens", "allocations($allocations_query){allocatedTokens,createdAtEpoch,subgraphDeployment{ipfsHash}}", ], ) indexers_data = query(client, "indexers"; query_args=indexer_query.args, output_fields=indexer_query.fields).data["indexers"] indexers = map( - x -> Indexer(x["id"], x["delegatedTokens"], x["stakedTokens"], x["allocations"]), + x -> Indexer( + x["id"], + x["delegatedTokens"], + x["stakedTokens"], + x["lockedTokens"], + x["allocations"], + ), indexers_data, ) return indexers diff --git a/src/service.jl b/src/service.jl index 43e33c8..a993a19 100644 --- a/src/service.jl +++ b/src/service.jl @@ -65,7 +65,7 @@ end function optimize( Ω::AbstractVector{T}, ψ::AbstractVector{T}, - σ::Real, + σ::T, max_allocations::Int, filter_fn::Function, ) where {T<:Real} diff --git a/test/example.csv b/test/example.csv index f4bbed5..86d31ab 100644 --- a/test/example.csv +++ b/test/example.csv @@ -1,4 +1,3 @@ whitelist,blacklist,pinnedlist,frozenlist -QmXvEzRJXby7KFuTr7NJsM47hGefM5VckEXZrQyZzL9eJd,,, -QmWxteQps5mtjAx14XD1uycg6kJkFN8EPW7561iZE3dJz8,,, - +QmXvEzRJXby7KFuTr7NJsM47hGefM5VckEXZrQyZzL9eJd,,, +QmWxteQps5mtjAx14XD1uycg6kJkFN8EPW7561iZE3dJz8,,, \ No newline at end of file diff --git a/test/runtests.jl b/test/runtests.jl index 6ed799c..75b71eb 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -50,13 +50,17 @@ using GraphQLClient # Indexer stake should be equal to the sum of allocations # query indexer's stake - indexer = query(client, "indexers"; query_args=Dict("where" => Dict("id" => id)), output_fields=["delegatedTokens", "stakedTokens"]).data["indexers"][1] - stake = togrt(indexer["delegatedTokens"]) + togrt(indexer["stakedTokens"]) + indexer = query(client, "indexers"; query_args=Dict("where" => Dict("id" => id)), output_fields=["delegatedTokens", "stakedTokens", "lockedTokens"]).data["indexers"][1] + stake = + togrt(indexer["delegatedTokens"]) + togrt(indexer["stakedTokens"]) - + togrt(indexer["lockedTokens"]) # run optimize_indexer repo, optindexer, network = network_state( id, network_id, String[ipfshash], String[], String[], String[], gateway_url ) + # Check stake + @test isapprox(stake, optindexer.stake; atol=1e-6) allocs = optimize_indexer(optindexer, repo, repo, 2, τ, filter_fn, String[]) # Sum allocation amounts ω = sum(values(allocs)) @@ -94,7 +98,7 @@ using GraphQLClient ω = sum(values(pinned_allocs)) @test isapprox(ω, stake; atol=1e-6) - # run optimize_indexer with pinnedlist when allocation is optimal + # run optimize_indexer with pinnedlist when pinned subgraph is optimal pinnedlist = String[ipfshash] repo, optindexer, network = network_state( id, diff --git a/test/semiotic.csv b/test/semiotic.csv index 0e440dc..1521984 100644 --- a/test/semiotic.csv +++ b/test/semiotic.csv @@ -1,4 +1 @@ whitelist,blacklist,pinnedlist,frozenlist -QmVqMeQUwvQ3XjzCYiMhRvQjRiQLGpVt8C3oHgvDi3agJ2,,, -QmbvTyvmxqHLahZwS7fZtVWGM85VCpCiKHiagPxQJp5ktS,,, -QmXYZnggrnRpQe5ZGK2VzdhNyTgFqAP4AziQgxEZFk7fJm,,,