Skip to content

Commit

Permalink
fix(gar): update the logic for compute prescribed observers and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dtfiedler authored and dtfiedler committed Aug 5, 2024
1 parent 8075c5c commit 88d5413
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
5 changes: 3 additions & 2 deletions spec/gar_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -524,8 +524,9 @@ describe("gar", function()
local timestamp = 100
local expectedTenureWeight = timestamp / gar.getSettings().observers.tenureWeightPeriod
local expectedStakeWeight = 1
local expectedObserverRatioWeight = 1 / 3
local expectedGatewayRatioWeight = 3 / 10
-- NOTE: we increment by one to avoid division by zero
local expectedObserverRatioWeight = 2 / 4 -- (the stats are 1/3)
local expectedGatewayRatioWeight = 4 / 11 -- (the tats are 3/10)
local expectedCompositeWeight = expectedStakeWeight
* expectedTenureWeight
* expectedGatewayRatioWeight
Expand Down
8 changes: 2 additions & 6 deletions src/gar.lua
Original file line number Diff line number Diff line change
Expand Up @@ -437,14 +437,10 @@ function gar.getGatewayWeightsAtTimestamp(gatewayAddresses, timestamp)

local totalEpochsGatewayPassed = gateway.stats.passedEpochCount or 0
local totalEpochsParticipatedIn = gateway.stats.totalEpochCount or 0
local gatewayRewardRatioWeight = totalEpochsParticipatedIn > 0
and totalEpochsGatewayPassed / totalEpochsParticipatedIn
or 1

local gatewayRewardRatioWeight = (1 + totalEpochsGatewayPassed) / (1 + totalEpochsParticipatedIn)
local totalEpochsPrescribed = gateway.stats.prescribedEpochCount or 0
local totalEpochsSubmitted = gateway.stats.observedEpochCount or 0
local observerRewardRatioWeight = totalEpochsPrescribed > 0 and totalEpochsSubmitted / totalEpochsPrescribed
or 1
local observerRewardRatioWeight = (1 + totalEpochsSubmitted) / (1 + totalEpochsPrescribed)

local compositeWeight = stakeWeightRatio
* gatewayTenureWeight
Expand Down

0 comments on commit 88d5413

Please sign in to comment.