Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: CNS-1008 - Optimizer Refactor Part 1: provider optimizer refactor #1784

Open
wants to merge 30 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
e5d9415
CNS-1008: remove raw qos and add selection tier documentation
oren-lava Sep 29, 2024
c4a23d7
Merge branch 'main' into CNS-1008-score-store-refactor
oren-lava Oct 13, 2024
c3e9b04
CNS-1008: implemented new ScoreStore
oren-lava Oct 13, 2024
906dc6e
CNS-1008: adding "_Refactor" prefix to score store
oren-lava Oct 13, 2024
cd6854a
CNS-1008: revert raw qos report code
oren-lava Oct 13, 2024
e6c84d0
CNS-1008: added latency CU factor to ScoreStore config
oren-lava Oct 22, 2024
4615c75
CNS-1008: implemented new QoS compute
oren-lava Oct 28, 2024
66a0a93
CNS-1008: make availability score store never return zero from Resolv…
oren-lava Oct 29, 2024
93ced34
CNS-1008: add safety checks when ScoreStore updates
oren-lava Nov 7, 2024
932323e
wip
oren-lava Nov 18, 2024
c1aebf7
added TODOs
omerlavanet Nov 18, 2024
985bf72
fix tiers assignment to providers
oren-lava Nov 20, 2024
cec0403
fix current optimizer test
oren-lava Nov 20, 2024
39f2733
fix tier algoritm + tier tests
oren-lava Nov 20, 2024
a70aa7c
optimizer refactor
oren-lava Nov 20, 2024
55864d5
Merge branch 'main' into CNS-1008-score-store-refactor
oren-lava Nov 21, 2024
630adc4
CNS-1008: fix imports
oren-lava Nov 21, 2024
797e1bb
CNS-1008: minor fixes
oren-lava Nov 21, 2024
c89fa4a
Merge branch 'main' into CNS-1008-score-store-refactor
oren-lava Nov 21, 2024
daba344
Merge branch 'main' into CNS-1008-score-store-refactor
oren-lava Nov 26, 2024
e7fa12e
use lavaslices instead of slices
oren-lava Dec 1, 2024
9c563b8
lint fix
oren-lava Dec 1, 2024
3aea031
another lint fix
oren-lava Dec 1, 2024
c1f5098
minor fixes
oren-lava Dec 3, 2024
8cf3da7
Merge branch 'main' into CNS-1008-score-store-refactor
oren-lava Dec 3, 2024
8fe023d
CNS-1008: add metrics
oren-lava Dec 3, 2024
a0080ba
CNS-1008: fix small test
oren-lava Dec 5, 2024
ac2bccf
Merge branch 'main' into CNS-1008-score-store-refactor
oren-lava Dec 5, 2024
82a5c31
apply optimizer refactor
oren-lava Dec 9, 2024
11304a1
fix test
oren-lava Dec 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions protocol/chainlib/consumer_ws_subscription_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -722,10 +722,9 @@ func TestConsumerWSSubscriptionManager(t *testing.T) {

func CreateConsumerSessionManager(chainID, apiInterface, consumerPublicAddress string) *lavasession.ConsumerSessionManager {
rand.InitRandomSeed()
baseLatency := common.AverageWorldLatency / 2 // we want performance to be half our timeout or better
return lavasession.NewConsumerSessionManager(
&lavasession.RPCEndpoint{NetworkAddress: "stub", ChainID: chainID, ApiInterface: apiInterface, TLSEnabled: false, HealthCheckPath: "/", Geolocation: 0},
provideroptimizer.NewProviderOptimizer(provideroptimizer.STRATEGY_BALANCED, 0, baseLatency, 1, nil, "dontcare"),
provideroptimizer.NewProviderOptimizer(provideroptimizer.StrategyBalanced, 0, 1, nil, "dontcare"),
nil, nil, consumerPublicAddress,
lavasession.NewActiveSubscriptionProvidersStorage(),
)
Expand Down
3 changes: 1 addition & 2 deletions protocol/integration/protocol_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,7 @@ func createRpcConsumer(t *testing.T, ctx context.Context, rpcConsumerOptions rpc
consumerStateTracker := &mockConsumerStateTracker{}
finalizationConsensus := finalizationconsensus.NewFinalizationConsensus(rpcEndpoint.ChainID)
_, averageBlockTime, _, _ := chainParser.ChainBlockStats()
baseLatency := common.AverageWorldLatency / 2
optimizer := provideroptimizer.NewProviderOptimizer(provideroptimizer.STRATEGY_BALANCED, averageBlockTime, baseLatency, 2, nil, "dontcare")
optimizer := provideroptimizer.NewProviderOptimizer(provideroptimizer.StrategyBalanced, averageBlockTime, 2, nil, "dontcare")
consumerSessionManager := lavasession.NewConsumerSessionManager(rpcEndpoint, optimizer, nil, nil, "test", lavasession.NewActiveSubscriptionProvidersStorage())
consumerSessionManager.UpdateAllProviders(rpcConsumerOptions.epoch, rpcConsumerOptions.pairingList)

Expand Down
14 changes: 9 additions & 5 deletions protocol/lavasession/consumer_session_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -562,15 +562,15 @@ func (csm *ConsumerSessionManager) GetSessions(ctx context.Context, cuNeededForS
sessionInfo.QoSSummeryResult = consumerSession.getQosComputedResultOrZero()
sessions[providerAddress] = sessionInfo

qosReport, rawQosReport := csm.providerOptimizer.GetExcellenceQoSReportForProvider(providerAddress)
qosReport, _ := csm.providerOptimizer.GetExcellenceQoSReportForProvider(providerAddress)
if csm.rpcEndpoint.Geolocation != uint64(endpoint.endpoint.Geolocation) {
// rawQosReport is used only when building the relay payment message to be used to update
// the provider's reputation on-chain. If the consumer and provider don't share geolocation
// (consumer geo: csm.rpcEndpoint.Geolocation, provider geo: endpoint.endpoint.Geolocation)
// we don't want to update the reputation by it, so we null the rawQosReport
rawQosReport = nil
qosReport = nil
}
consumerSession.SetUsageForSession(cuNeededForSession, qosReport, rawQosReport, usedProviders, routerKey)
consumerSession.SetUsageForSession(cuNeededForSession, qosReport, usedProviders, routerKey)
// We successfully added provider, we should ignore it if we need to fetch new
tempIgnoredProviders.providers[providerAddress] = struct{}{}
if len(sessions) == wantedSession {
Expand Down Expand Up @@ -640,7 +640,7 @@ func (csm *ConsumerSessionManager) getValidProviderAddresses(ignoredProvidersLis
}
}
var providers []string
if stateful == common.CONSISTENCY_SELECT_ALL_PROVIDERS && csm.providerOptimizer.Strategy() != provideroptimizer.STRATEGY_COST {
if stateful == common.CONSISTENCY_SELECT_ALL_PROVIDERS && csm.providerOptimizer.Strategy() != provideroptimizer.StrategyCost {
providers = csm.getTopTenProvidersForStatefulCalls(validAddresses, ignoredProvidersList)
} else {
providers, _ = csm.providerOptimizer.ChooseProvider(validAddresses, ignoredProvidersList, cu, requestedBlock)
Expand Down Expand Up @@ -1047,7 +1047,11 @@ func (csm *ConsumerSessionManager) OnSessionDone(
consumerSession.LatestBlock = latestServicedBlock // update latest serviced block
// calculate QoS
consumerSession.CalculateQoS(currentLatency, expectedLatency, expectedBH-latestServicedBlock, numOfProviders, int64(providersCount))
go csm.providerOptimizer.AppendRelayData(consumerSession.Parent.PublicLavaAddress, currentLatency, isHangingApi, specComputeUnits, uint64(latestServicedBlock))
if !isHangingApi {
// append relay data only for non hanging apis
go csm.providerOptimizer.AppendRelayData(consumerSession.Parent.PublicLavaAddress, currentLatency, specComputeUnits, uint64(latestServicedBlock))
}

csm.updateMetricsManager(consumerSession, currentLatency, !isHangingApi) // apply latency only for non hanging apis
return nil
}
Expand Down
3 changes: 1 addition & 2 deletions protocol/lavasession/consumer_session_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,7 @@ func TestEndpointSortingFlow(t *testing.T) {

func CreateConsumerSessionManager() *ConsumerSessionManager {
rand.InitRandomSeed()
baseLatency := common.AverageWorldLatency / 2 // we want performance to be half our timeout or better
return NewConsumerSessionManager(&RPCEndpoint{"stub", "stub", "stub", false, "/", 0}, provideroptimizer.NewProviderOptimizer(provideroptimizer.STRATEGY_BALANCED, 0, baseLatency, 1, nil, "dontcare"), nil, nil, "lava@test", NewActiveSubscriptionProvidersStorage())
return NewConsumerSessionManager(&RPCEndpoint{"stub", "stub", "stub", false, "/", 0}, provideroptimizer.NewProviderOptimizer(provideroptimizer.StrategyBalanced, 0, 1, nil, "dontcare"), nil, nil, "lava@test", NewActiveSubscriptionProvidersStorage())
}

func TestMain(m *testing.M) {
Expand Down
4 changes: 2 additions & 2 deletions protocol/lavasession/consumer_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ type ConsumerSessionsMap map[string]*SessionInfo
type ProviderOptimizer interface {
AppendProbeRelayData(providerAddress string, latency time.Duration, success bool)
AppendRelayFailure(providerAddress string)
AppendRelayData(providerAddress string, latency time.Duration, isHangingApi bool, cu, syncBlock uint64)
AppendRelayData(providerAddress string, latency time.Duration, cu, syncBlock uint64)
ChooseProvider(allAddresses []string, ignoredProviders map[string]struct{}, cu uint64, requestedBlock int64) (addresses []string, tier int)
GetExcellenceQoSReportForProvider(string) (*pairingtypes.QualityOfServiceReport, *pairingtypes.QualityOfServiceReport)
GetExcellenceQoSReportForProvider(string) (*pairingtypes.QualityOfServiceReport, time.Time)
Strategy() provideroptimizer.Strategy
UpdateWeights(map[string]int64, uint64)
}
Expand Down
3 changes: 1 addition & 2 deletions protocol/lavasession/single_consumer_session.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,12 @@ func (cs *SingleConsumerSession) CalculateQoS(latency, expectedLatency time.Dura
}
}

func (scs *SingleConsumerSession) SetUsageForSession(cuNeededForSession uint64, qoSExcellenceReport *pairingtypes.QualityOfServiceReport, rawQoSExcellenceReport *pairingtypes.QualityOfServiceReport, usedProviders UsedProvidersInf, routerKey RouterKey) error {
func (scs *SingleConsumerSession) SetUsageForSession(cuNeededForSession uint64, qoSExcellenceReport *pairingtypes.QualityOfServiceReport, usedProviders UsedProvidersInf, routerKey RouterKey) error {
scs.LatestRelayCu = cuNeededForSession // set latestRelayCu
scs.RelayNum += RelayNumberIncrement // increase relayNum
if scs.RelayNum > 1 {
// we only set excellence for sessions with more than one successful relays, this guarantees data within the epoch exists
scs.QoSInfo.LastExcellenceQoSReport = qoSExcellenceReport
scs.QoSInfo.LastExcellenceQoSReportRaw = rawQoSExcellenceReport
}
scs.usedProviders = usedProviders
scs.routerKey = routerKey
Expand Down
Loading
Loading