Skip to content

Commit

Permalink
fix: rounding to avoid !capacity contract error
Browse files Browse the repository at this point in the history
  • Loading branch information
hopeyen committed Oct 19, 2022
1 parent 672dc0b commit b16af80
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/AllocationOpt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ function apply_preferences(
end

"""
function optimize_indexer(indexer, repo, maximum_new_allocations, pinnedlist)
function optimize_indexer(indexer, repo, maximum_new_allocations,τ, filter_function, pinnedlist)
# Arguments
- `indexer::Indexer`: The indexer being optimised.
Expand Down Expand Up @@ -200,7 +200,7 @@ function optimize_indexer(

# Filter results with deployment IPFS hashes
suggested_allocations = Dict(
ipfshash(k) => v for (k, v) in zip(repo.subgraphs, ω) if v > 0.0
ipfshash(k) => round(v; digits=3) for (k, v) in zip(repo.subgraphs, ω) if v > 0.0
)
return suggested_allocations
end
Expand Down
10 changes: 5 additions & 5 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ using GraphQLClient
id, network_id, String[ipfshash], String[], String[], String[], gateway_url
)
# Check stake
@test isapprox(stake, optindexer.stake; atol=1e-6)
@test isapprox(stake, optindexer.stake; atol=1e-3)
allocs = optimize_indexer(optindexer, repo, repo, 2, τ, filter_fn, String[])
# Sum allocation amounts
ω = sum(values(allocs))
@test isapprox(ω, stake; atol=1e-6)
@test isapprox(ω, stake; atol=1e-3)
# Length of allocations is 1
@test length(allocs) == 1
# run optimize_indexer
Expand All @@ -80,7 +80,7 @@ using GraphQLClient
allocs = optimize_indexer(optindexer, repo, repo, 2, τ, filter_fn, String[])
# Sum allocation amounts
ω = sum(values(allocs))
@test isapprox(ω, stake; atol=1e-6)
@test isapprox(ω, stake; atol=1e-3)
# Length of allocations ≤ length of whitelist
@test length(allocs) 2

Expand All @@ -96,7 +96,7 @@ using GraphQLClient
@test pinned_allocs[another_ipfshash] == 0.1
# Sum allocation amounts still satisfy stake constraint
ω = sum(values(pinned_allocs))
@test isapprox(ω, stake; atol=1e-6)
@test isapprox(ω, stake; atol=1e-3)

# run optimize_indexer with pinnedlist when pinned subgraph is optimal
pinnedlist = String[ipfshash]
Expand All @@ -116,7 +116,7 @@ using GraphQLClient
@test isapprox(pinned_allocs[ipfshash], allocs[ipfshash]; atol=1e-9)
# Sum allocation amounts still satisfy stake constraint
ω = sum(values(pinned_allocs))
@test isapprox(ω, stake; atol=1e-6)
@test isapprox(ω, stake; atol=1e-3)
end

@testset "read_filterlists" begin
Expand Down

0 comments on commit b16af80

Please sign in to comment.