Skip to content

Commit

Permalink
chore(PE-7040): replace gatewayRewardRatioWeight and observerRewardRa…
Browse files Browse the repository at this point in the history
…tioWeight with gatewayPerformanceRatio and observerPerformanceRatio (#341)

Swap out the attribute name. for the handlers we'll support the old ones
until the SDK and network portal are updated.

ar-io/ar-io-sdk#367
  • Loading branch information
dtfiedler authored Jan 31, 2025
2 parents d7b5953 + 9349777 commit 7ca47bd
Show file tree
Hide file tree
Showing 11 changed files with 126 additions and 89 deletions.
12 changes: 6 additions & 6 deletions spec/arns_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ describe("arns", function()
_G.GatewayRegistry[testAddress] = testGateway
_G.GatewayRegistry[testAddress].weights = {
tenureWeight = constants.ARNS_DISCOUNT_TENURE_WEIGHT_ELIGIBILITY_THRESHOLD,
gatewayRewardRatioWeight = constants.ARNS_DISCOUNT_GATEWAY_PERFORMANCE_RATIO_ELIGIBILITY_THRESHOLD,
gatewayPerformanceRatio = constants.ARNS_DISCOUNT_GATEWAY_PERFORMANCE_RATIO_ELIGIBILITY_THRESHOLD,
}
local result = gar.isEligibleForArNSDiscount(testAddress)
assert.is_true(result)
Expand Down Expand Up @@ -450,7 +450,7 @@ describe("arns", function()
_G.GatewayRegistry[testAddress] = testGateway
_G.GatewayRegistry[testAddress].weights = {
tenureWeight = constants.ARNS_DISCOUNT_TENURE_WEIGHT_ELIGIBILITY_THRESHOLD,
gatewayRewardRatioWeight = constants.ARNS_DISCOUNT_GATEWAY_PERFORMANCE_RATIO_ELIGIBILITY_THRESHOLD,
gatewayPerformanceRatio = constants.ARNS_DISCOUNT_GATEWAY_PERFORMANCE_RATIO_ELIGIBILITY_THRESHOLD,
}
assert.is_true(gar.isEligibleForArNSDiscount(testAddress))

Expand Down Expand Up @@ -632,7 +632,7 @@ describe("arns", function()
_G.GatewayRegistry[testAddress] = testGateway
_G.GatewayRegistry[testAddress].weights = {
tenureWeight = constants.ARNS_DISCOUNT_TENURE_WEIGHT_ELIGIBILITY_THRESHOLD,
gatewayRewardRatioWeight = constants.ARNS_DISCOUNT_GATEWAY_PERFORMANCE_RATIO_ELIGIBILITY_THRESHOLD,
gatewayPerformanceRatio = constants.ARNS_DISCOUNT_GATEWAY_PERFORMANCE_RATIO_ELIGIBILITY_THRESHOLD,
}
local result = gar.isEligibleForArNSDiscount(testAddress)
assert.is_true(result)
Expand Down Expand Up @@ -900,7 +900,7 @@ describe("arns", function()
_G.GatewayRegistry[stubRandomAddress] = testGateway
_G.GatewayRegistry[stubRandomAddress].weights = {
tenureWeight = constants.ARNS_DISCOUNT_TENURE_WEIGHT_ELIGIBILITY_THRESHOLD,
gatewayRewardRatioWeight = constants.ARNS_DISCOUNT_GATEWAY_PERFORMANCE_RATIO_ELIGIBILITY_THRESHOLD,
gatewayPerformanceRatio = constants.ARNS_DISCOUNT_GATEWAY_PERFORMANCE_RATIO_ELIGIBILITY_THRESHOLD,
}
local result = gar.isEligibleForArNSDiscount(stubRandomAddress)
assert.is_true(result)
Expand All @@ -925,7 +925,7 @@ describe("arns", function()
_G.GatewayRegistry[stubRandomAddress] = testGateway
_G.GatewayRegistry[stubRandomAddress].weights = {
tenureWeight = 0.1,
gatewayRewardRatioWeight = 0.1,
gatewayPerformanceRatio = 0.1,
}
local result = gar.isEligibleForArNSDiscount(stubRandomAddress)
assert.is_false(result)
Expand Down Expand Up @@ -1407,7 +1407,7 @@ describe("arns", function()
_G.GatewayRegistry[stubRandomAddress] = testGateway
_G.GatewayRegistry[stubRandomAddress].weights = {
tenureWeight = constants.ARNS_DISCOUNT_TENURE_WEIGHT_ELIGIBILITY_THRESHOLD,
gatewayRewardRatioWeight = constants.ARNS_DISCOUNT_GATEWAY_PERFORMANCE_RATIO_ELIGIBILITY_THRESHOLD,
gatewayPerformanceRatio = constants.ARNS_DISCOUNT_GATEWAY_PERFORMANCE_RATIO_ELIGIBILITY_THRESHOLD,
}
_G.NameRegistry.records["upgrade-name"] = {
endTimestamp = 1000000,
Expand Down
48 changes: 24 additions & 24 deletions spec/epochs_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ describe("epochs", function()
normalizedCompositeWeight = 1,
stakeWeight = 1,
tenureWeight = 1,
gatewayRewardRatioWeight = 1,
observerRewardRatioWeight = 1,
gatewayPerformanceRatio = 1,
observerPerformanceRatio = 1,
compositeWeight = 1,
},
}
Expand All @@ -90,8 +90,8 @@ describe("epochs", function()
normalizedCompositeWeight = 1,
stakeWeight = 1,
tenureWeight = 1,
gatewayRewardRatioWeight = 1,
observerRewardRatioWeight = 1,
gatewayPerformanceRatio = 1,
observerPerformanceRatio = 1,
compositeWeight = 1,
stake = gar.getSettings().operators.minStake,
startTimestamp = startTimestamp,
Expand Down Expand Up @@ -126,8 +126,8 @@ describe("epochs", function()
normalizedCompositeWeight = 1,
stakeWeight = 1,
tenureWeight = 1,
gatewayRewardRatioWeight = 1,
observerRewardRatioWeight = 1,
gatewayPerformanceRatio = 1,
observerPerformanceRatio = 1,
compositeWeight = 1,
},
}
Expand Down Expand Up @@ -169,8 +169,8 @@ describe("epochs", function()
normalizedCompositeWeight = 1,
stakeWeight = 1,
tenureWeight = 1,
gatewayRewardRatioWeight = 1,
observerRewardRatioWeight = 1,
gatewayPerformanceRatio = 1,
observerPerformanceRatio = 1,
compositeWeight = 1,
},
}
Expand Down Expand Up @@ -323,8 +323,8 @@ describe("epochs", function()
normalizedCompositeWeight = 1,
stakeWeight = 1,
tenureWeight = 1,
gatewayRewardRatioWeight = 1,
observerRewardRatioWeight = 1,
gatewayPerformanceRatio = 1,
observerPerformanceRatio = 1,
compositeWeight = 1,
},
},
Expand All @@ -350,8 +350,8 @@ describe("epochs", function()
normalizedCompositeWeight = 1,
stakeWeight = 1,
tenureWeight = 1,
gatewayRewardRatioWeight = 1,
observerRewardRatioWeight = 1,
gatewayPerformanceRatio = 1,
observerPerformanceRatio = 1,
compositeWeight = 1,
},
},
Expand All @@ -377,8 +377,8 @@ describe("epochs", function()
normalizedCompositeWeight = 1,
stakeWeight = 1,
tenureWeight = 1,
gatewayRewardRatioWeight = 1,
observerRewardRatioWeight = 1,
gatewayPerformanceRatio = 1,
observerPerformanceRatio = 1,
compositeWeight = 1,
},
},
Expand All @@ -405,8 +405,8 @@ describe("epochs", function()
normalizedCompositeWeight = 1,
stakeWeight = 1,
tenureWeight = 1,
gatewayRewardRatioWeight = 1,
observerRewardRatioWeight = 1,
gatewayPerformanceRatio = 1,
observerPerformanceRatio = 1,
compositeWeight = 1,
},
},
Expand Down Expand Up @@ -482,8 +482,8 @@ describe("epochs", function()
weights = {
stakeWeight = 0,
tenureWeight = 0,
gatewayRewardRatioWeight = 0,
observerRewardRatioWeight = 0,
gatewayPerformanceRatio = 0,
observerPerformanceRatio = 0,
compositeWeight = 0,
normalizedCompositeWeight = 0,
},
Expand All @@ -510,8 +510,8 @@ describe("epochs", function()
weights = {
stakeWeight = 0,
tenureWeight = 0,
gatewayRewardRatioWeight = 0,
observerRewardRatioWeight = 0,
gatewayPerformanceRatio = 0,
observerPerformanceRatio = 0,
compositeWeight = 0,
normalizedCompositeWeight = 0,
},
Expand Down Expand Up @@ -565,17 +565,17 @@ describe("epochs", function()
assert.are.same({
stakeWeight = 1,
tenureWeight = 4,
gatewayRewardRatioWeight = 1,
observerRewardRatioWeight = 1,
gatewayPerformanceRatio = 1,
observerPerformanceRatio = 1,
compositeWeight = 4,
normalizedCompositeWeight = 1,
}, _G.GatewayRegistry["test-this-is-valid-arweave-wallet-address-1"].weights)
-- confirm the leaving gateway weights were not updated
assert.are.same({
stakeWeight = 0,
tenureWeight = 0,
gatewayRewardRatioWeight = 0,
observerRewardRatioWeight = 0,
gatewayPerformanceRatio = 0,
observerPerformanceRatio = 0,
compositeWeight = 0,
normalizedCompositeWeight = 0,
}, _G.GatewayRegistry["test-this-is-valid-arweave-wallet-address-2"].weights)
Expand Down
28 changes: 18 additions & 10 deletions spec/gar_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ local testGateway = {
weights = {
stakeWeight = 0,
tenureWeight = 0,
gatewayRewardRatioWeight = 0,
observerRewardRatioWeight = 0,
gatewayPerformanceRatio = 0,
observerPerformanceRatio = 0,
compositeWeight = 0,
normalizedCompositeWeight = 0,
},
Expand Down Expand Up @@ -1933,8 +1933,8 @@ describe("gar", function()
startTimestamp = 0,
stakeWeight = expectedStakeWeight,
tenureWeight = expectedTenureWeight,
gatewayRewardRatioWeight = expectedGatewayRatioWeight,
observerRewardRatioWeight = expectedObserverRatioWeight,
gatewayPerformanceRatio = expectedGatewayRatioWeight,
observerPerformanceRatio = expectedObserverRatioWeight,
compositeWeight = expectedCompositeWeight,
normalizedCompositeWeight = 1, -- there is only one gateway
},
Expand Down Expand Up @@ -2328,6 +2328,10 @@ describe("gar", function()
local gateway2Copy = utils.deepCopy(gateway2)
gateway2Copy.delegates = nil
gateway2Copy.vaults = nil
-- TODO: add gatewayRewardRatioWeight and observerRewardRatioWeight as gatewayPerformanceRatio and observerPerformanceRatio for backwards compatibility
gateway2Copy.weights.gatewayRewardRatioWeight = gateway2Copy.weights.gatewayPerformanceRatio or 0
gateway2Copy.weights.observerRewardRatioWeight = gateway2Copy.weights.observerPerformanceRatio or 0
-- END TODO
assert.are.same({
limit = 1,
sortBy = "startTimestamp",
Expand All @@ -2344,6 +2348,10 @@ describe("gar", function()
local gateway1Copy = utils.deepCopy(gateway1)
gateway1Copy.delegates = nil
gateway1Copy.vaults = nil
-- TODO: add gatewayRewardRatioWeight and observerRewardRatioWeight as gatewayPerformanceRatio and observerPerformanceRatio for backwards compatibility
gateway1Copy.weights.gatewayRewardRatioWeight = gateway1Copy.weights.gatewayPerformanceRatio or 0
gateway1Copy.weights.observerRewardRatioWeight = gateway1Copy.weights.observerPerformanceRatio or 0
-- END TODO
assert.are.same({
limit = 1,
sortBy = "startTimestamp",
Expand Down Expand Up @@ -2374,9 +2382,9 @@ describe("gar", function()
_G.GatewayRegistry[stubRandomAddress] = testGateway
_G.GatewayRegistry[stubRandomAddress].weights = {
tenureWeight = 0.5,
gatewayRewardRatioWeight = 0.85,
gatewayPerformanceRatio = 0.85,
stakeWeight = 0,
observerRewardRatioWeight = 0,
observerPerformanceRatio = 0,
compositeWeight = 0,
normalizedCompositeWeight = 0,
}
Expand All @@ -2388,9 +2396,9 @@ describe("gar", function()
_G.GatewayRegistry[stubRandomAddress] = testGateway
_G.GatewayRegistry[stubRandomAddress].weights = {
tenureWeight = 1,
gatewayRewardRatioWeight = 0.84,
gatewayPerformanceRatio = 0.84,
stakeWeight = 0,
observerRewardRatioWeight = 0,
observerPerformanceRatio = 0,
compositeWeight = 0,
normalizedCompositeWeight = 0,
}
Expand All @@ -2402,9 +2410,9 @@ describe("gar", function()
_G.GatewayRegistry[stubRandomAddress] = testGateway
_G.GatewayRegistry[stubRandomAddress].weights = {
tenureWeight = 1,
gatewayRewardRatioWeight = 0.85,
gatewayPerformanceRatio = 0.85,
stakeWeight = 0,
observerRewardRatioWeight = 0,
observerPerformanceRatio = 0,
compositeWeight = 0,
normalizedCompositeWeight = 0,
}
Expand Down
8 changes: 4 additions & 4 deletions src/epochs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ local epochs = {}
--- @field observerAddress string The observer address
--- @field stakeWeight number The stake weight
--- @field tenureWeight number The tenure weight
--- @field gatewayRewardRatioWeight number The gateway reward ratio weight
--- @field observerRewardRatioWeight number The observer reward ratio weight
--- @field gatewayPerformanceRatio number The gateway reward ratio weight
--- @field observerPerformanceRatio number The observer reward ratio weight
--- @field compositeWeight number The composite weight
--- @field normalizedCompositeWeight number The normalized composite weight

Expand Down Expand Up @@ -136,8 +136,8 @@ function epochs.getPrescribedObserversWithWeightsForEpoch(epochIndex)
normalizedCompositeWeight = gateway.weights.normalizedCompositeWeight,
stakeWeight = gateway.weights.stakeWeight,
tenureWeight = gateway.weights.tenureWeight,
gatewayRewardRatioWeight = gateway.weights.gatewayRewardRatioWeight,
observerRewardRatioWeight = gateway.weights.observerRewardRatioWeight,
gatewayPerformanceRatio = gateway.weights.gatewayPerformanceRatio,
observerPerformanceRatio = gateway.weights.observerPerformanceRatio,
compositeWeight = gateway.weights.compositeWeight,
stake = gateway.operatorStake,
startTimestamp = gateway.startTimestamp,
Expand Down
Loading

0 comments on commit 7ca47bd

Please sign in to comment.