Skip to content

Commit

Permalink
Merge branch 'main' into PRT-add-provider-verification-probing-data
Browse files Browse the repository at this point in the history
  • Loading branch information
ranlavanet authored Jan 29, 2025
2 parents 1203f13 + d582cab commit f9c2007
Show file tree
Hide file tree
Showing 58 changed files with 1,643 additions and 596 deletions.
1 change: 1 addition & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ var Upgrades = []upgrades.Upgrade{
upgrades.Upgrade_4_0_0,
upgrades.Upgrade_4_1_0,
upgrades.Upgrade_4_2_0,
upgrades.Upgrade_5_0_0,
}

// this line is used by starport scaffolding # stargate/wasm/app/enabledProposals
Expand Down
6 changes: 6 additions & 0 deletions app/upgrades/empty_upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,9 @@ var Upgrade_4_2_0 = Upgrade{
CreateUpgradeHandler: v_4_2_0,
StoreUpgrades: store.StoreUpgrades{},
}

var Upgrade_5_0_0 = Upgrade{
UpgradeName: "v5.0.0",
CreateUpgradeHandler: defaultUpgradeHandler,
StoreUpgrades: store.StoreUpgrades{},
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,32 @@ endpoints:
- url: ws://my-eth-node.com/eth/archive/ws
addons:
- archive
- url: http://my-eth-node.com/eth/http/archive
- url: http://my-eth-node.com/eth/http/deubg
addons:
- debug
- url: ws://my-eth-node.com/eth/archive/ws
- url: ws://my-eth-node.com/eth/debug/ws
addons:
- debug
- url: http://my-eth-node.com/eth/http/archive
- url: http://my-eth-node.com/eth/http/trace
addons:
- trace
- url: ws://my-eth-node.com/eth/archive/ws
- url: ws://my-eth-node.com/eth/trace/ws
addons:
- trace
- url: http://my-eth-node.com/eth/http/debug+archive
addons:
- debug
- archive
- url: ws://my-eth-node.com/eth/debug+archive/ws
addons:
- debug
- archive
- url: http://my-eth-node.com/eth/http/trace+archive
addons:
- trace
- archive
- url: ws://my-eth-node.com/eth/trace+archive/ws
addons:
- trace
- archive

8 changes: 8 additions & 0 deletions proto/lavanet/lava/subscription/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ rpc EstimatedValidatorRewards(QueryEstimatedValidatorRewardsRequest) returns (Qu
option (google.api.http).get = "/lavanet/lava/subscription/estimated_validator_rewards/{validator}/{amount_delegator}";
}

rpc EstimatedPoolsRewards(QueryEstimatedPoolsRewardsRequest) returns (QueryEstimatedRewardsResponse) {
option (google.api.http).get = "/lavanet/lava/subscription/estimated_pools_rewards";
}

// this line is used by starport scaffolding # 2
}

Expand Down Expand Up @@ -177,4 +181,8 @@ message QueryEstimatedValidatorRewardsResponse {
(amino.dont_omitempty) = true
];
}

message QueryEstimatedPoolsRewardsRequest {
}

// this line is used by starport scaffolding # 3
7 changes: 7 additions & 0 deletions protocol/chainlib/chain_router.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,13 @@ func newChainRouter(ctx context.Context, nConns uint, rpcProviderEndpoint lavase
}
}
if len(requiredMap) > len(supportedMap) {
missingKeys := []string{}
for key := range requiredMap {
if _, ok := supportedMap[key]; !ok {
missingKeys = append(missingKeys, key)
}
}
utils.LavaFormatError("missing extensions or addons in definitions", nil, utils.Attribute{Key: "missing setups", Value: missingKeys})
return nil, utils.LavaFormatError("not all requirements supported in chainRouter, missing extensions or addons in definitions", nil, utils.Attribute{Key: "required", Value: requiredMap}, utils.Attribute{Key: "supported", Value: supportedMap})
}

Expand Down
4 changes: 2 additions & 2 deletions protocol/chainlib/chainproxy/connector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ func TestConnector(t *testing.T) {
for i := 0; i < increasedClients; i++ {
conn.ReturnRpc(rpcList[i])
}
require.Equal(t, conn.usedClients, int64(0)) // checking we dont have clients used
require.Equal(t, len(conn.freeClients), increasedClients) // checking we cleaned clients
require.Equal(t, conn.usedClients, int64(0)) // checking we dont have clients used
require.Greater(t, len(conn.freeClients), numberOfClients+1) // checking we cleaned clients before disconnecting
}

func TestConnectorGrpc(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions protocol/chaintracker/chain_tracker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -516,13 +516,13 @@ func TestChainTrackerPollingTimeUpdate(t *testing.T) {
time.Sleep(play.updateTime)
}
}
require.InDelta(t, play.updateTime, updatedTime, float64(play.updateTime)*0.2)
require.InDelta(t, play.updateTime, updatedTime, float64(play.updateTime)*0.3)
// if we wait more time we expect this to stay correct
for i := 0; i < iterations*4; i++ {
mockChainFetcher.AdvanceBlock()
time.Sleep(play.updateTime)
}
require.InDelta(t, play.updateTime, updatedTime, float64(play.updateTime)*0.2)
require.InDelta(t, play.updateTime, updatedTime, float64(play.updateTime)*0.3)
})
}
}
Expand Down
6 changes: 3 additions & 3 deletions protocol/common/endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,9 @@ type ConflictHandlerInterface interface {
}

type ProviderInfo struct {
ProviderAddress string
ProviderQoSExcellenceSummery sdk.Dec // the number represents the average qos for this provider session
ProviderStake sdk.Coin
ProviderAddress string
ProviderReputationSummary sdk.Dec // the number represents the average qos for this provider session
ProviderStake sdk.Coin
}

type RelayResult struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/lavanet/lava/v4/protocol/chainlib"
"github.com/lavanet/lava/v4/protocol/lavasession"
"github.com/lavanet/lava/v4/protocol/qos"
pairingtypes "github.com/lavanet/lava/v4/x/pairing/types"
spectypes "github.com/lavanet/lava/v4/x/spec/types"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -202,9 +203,10 @@ func TestConsensusHashesInsertion(t *testing.T) {

func TestQoS(t *testing.T) {
decToSet, _ := sdk.NewDecFromStr("0.05") // test values fit 0.05 Availability requirements
lavasession.AvailabilityPercentage = decToSet
qos.AvailabilityPercentage = decToSet
rand.InitRandomSeed()
chainsToTest := []string{"APT1", "LAV1", "ETH1"}

for i := 0; i < 10; i++ {
for _, chainID := range chainsToTest {
t.Run(chainID, func(t *testing.T) {
Expand Down Expand Up @@ -282,54 +284,63 @@ func TestQoS(t *testing.T) {
currentLatency := time.Millisecond
expectedLatency := time.Millisecond
latestServicedBlock := expectedBH
singleConsumerSession.CalculateQoS(currentLatency, expectedLatency, expectedBH-latestServicedBlock, numOfProviders, 1)
require.Equal(t, uint64(1), singleConsumerSession.QoSInfo.AnsweredRelays)
require.Equal(t, uint64(1), singleConsumerSession.QoSInfo.TotalRelays)
require.Equal(t, int64(1), singleConsumerSession.QoSInfo.SyncScoreSum)
require.Equal(t, int64(1), singleConsumerSession.QoSInfo.TotalSyncScore)
require.Equal(t, sdk.OneDec(), singleConsumerSession.QoSInfo.LastQoSReport.Availability)
require.Equal(t, sdk.OneDec(), singleConsumerSession.QoSInfo.LastQoSReport.Sync)
require.Equal(t, sdk.OneDec(), singleConsumerSession.QoSInfo.LastQoSReport.Latency)
singleConsumerSession.QoSManager.CalculateQoS(epoch, singleConsumerSession.SessionId, "", currentLatency, expectedLatency, expectedBH-latestServicedBlock, numOfProviders, 1)
require.Equal(t, uint64(1), singleConsumerSession.QoSManager.GetAnsweredRelays(epoch, singleConsumerSession.SessionId))
require.Equal(t, uint64(1), singleConsumerSession.QoSManager.GetTotalRelays(epoch, singleConsumerSession.SessionId))
require.Equal(t, int64(1), singleConsumerSession.QoSManager.GetSyncScoreSum(epoch, singleConsumerSession.SessionId))
require.Equal(t, int64(1), singleConsumerSession.QoSManager.GetTotalSyncScore(epoch, singleConsumerSession.SessionId))

lastQoSReport := singleConsumerSession.QoSManager.GetLastQoSReport(epoch, singleConsumerSession.SessionId)
require.Equal(t, sdk.OneDec(), lastQoSReport.Availability)
require.Equal(t, sdk.OneDec(), lastQoSReport.Sync)
require.Equal(t, sdk.OneDec(), lastQoSReport.Latency)

latestServicedBlock = expectedBH + 1
singleConsumerSession.CalculateQoS(currentLatency, expectedLatency, expectedBH-latestServicedBlock, numOfProviders, 1)
require.Equal(t, uint64(2), singleConsumerSession.QoSInfo.AnsweredRelays)
require.Equal(t, uint64(2), singleConsumerSession.QoSInfo.TotalRelays)
require.Equal(t, int64(2), singleConsumerSession.QoSInfo.SyncScoreSum)
require.Equal(t, int64(2), singleConsumerSession.QoSInfo.TotalSyncScore)
require.Equal(t, sdk.OneDec(), singleConsumerSession.QoSInfo.LastQoSReport.Availability)
require.Equal(t, sdk.OneDec(), singleConsumerSession.QoSInfo.LastQoSReport.Sync)
require.Equal(t, sdk.OneDec(), singleConsumerSession.QoSInfo.LastQoSReport.Latency)

singleConsumerSession.QoSInfo.TotalRelays++ // this is how we add a failure
singleConsumerSession.CalculateQoS(currentLatency, expectedLatency, expectedBH-latestServicedBlock, numOfProviders, 1)
require.Equal(t, uint64(3), singleConsumerSession.QoSInfo.AnsweredRelays)
require.Equal(t, uint64(4), singleConsumerSession.QoSInfo.TotalRelays)
require.Equal(t, int64(3), singleConsumerSession.QoSInfo.SyncScoreSum)
require.Equal(t, int64(3), singleConsumerSession.QoSInfo.TotalSyncScore)

require.Equal(t, sdk.ZeroDec(), singleConsumerSession.QoSInfo.LastQoSReport.Availability) // because availability below 95% is 0
require.Equal(t, sdk.OneDec(), singleConsumerSession.QoSInfo.LastQoSReport.Sync)
require.Equal(t, sdk.OneDec(), singleConsumerSession.QoSInfo.LastQoSReport.Latency)
singleConsumerSession.QoSManager.CalculateQoS(epoch, singleConsumerSession.SessionId, "", currentLatency, expectedLatency, expectedBH-latestServicedBlock, numOfProviders, 1)
require.Equal(t, uint64(2), singleConsumerSession.QoSManager.GetAnsweredRelays(epoch, singleConsumerSession.SessionId))
require.Equal(t, uint64(2), singleConsumerSession.QoSManager.GetTotalRelays(epoch, singleConsumerSession.SessionId))
require.Equal(t, int64(2), singleConsumerSession.QoSManager.GetSyncScoreSum(epoch, singleConsumerSession.SessionId))
require.Equal(t, int64(2), singleConsumerSession.QoSManager.GetTotalSyncScore(epoch, singleConsumerSession.SessionId))

lastQoSReport = singleConsumerSession.QoSManager.GetLastQoSReport(epoch, singleConsumerSession.SessionId)
require.Equal(t, sdk.OneDec(), lastQoSReport.Availability)
require.Equal(t, sdk.OneDec(), lastQoSReport.Sync)
require.Equal(t, sdk.OneDec(), lastQoSReport.Latency)

singleConsumerSession.QoSManager.AddFailedRelay(epoch, singleConsumerSession.SessionId) // this is how we add a failure
singleConsumerSession.QoSManager.CalculateQoS(epoch, singleConsumerSession.SessionId, "", currentLatency, expectedLatency, expectedBH-latestServicedBlock, numOfProviders, 1)
require.Equal(t, uint64(3), singleConsumerSession.QoSManager.GetAnsweredRelays(epoch, singleConsumerSession.SessionId))
require.Equal(t, uint64(4), singleConsumerSession.QoSManager.GetTotalRelays(epoch, singleConsumerSession.SessionId))
require.Equal(t, int64(3), singleConsumerSession.QoSManager.GetSyncScoreSum(epoch, singleConsumerSession.SessionId))
require.Equal(t, int64(3), singleConsumerSession.QoSManager.GetTotalSyncScore(epoch, singleConsumerSession.SessionId))

lastQoSReport = singleConsumerSession.QoSManager.GetLastQoSReport(epoch, singleConsumerSession.SessionId)
require.Equal(t, sdk.ZeroDec(), lastQoSReport.Availability) // because availability below 95% is 0
require.Equal(t, sdk.OneDec(), lastQoSReport.Sync)
require.Equal(t, sdk.OneDec(), lastQoSReport.Latency)

latestServicedBlock = expectedBH - 1 // is one block below threshold
singleConsumerSession.CalculateQoS(currentLatency, expectedLatency*2, expectedBH-latestServicedBlock, numOfProviders, 1)
require.Equal(t, uint64(4), singleConsumerSession.QoSInfo.AnsweredRelays)
require.Equal(t, uint64(5), singleConsumerSession.QoSInfo.TotalRelays)
require.Equal(t, int64(3), singleConsumerSession.QoSInfo.SyncScoreSum)
require.Equal(t, int64(4), singleConsumerSession.QoSInfo.TotalSyncScore)

require.Equal(t, sdk.ZeroDec(), singleConsumerSession.QoSInfo.LastQoSReport.Availability) // because availability below 95% is 0
require.Equal(t, sdk.MustNewDecFromStr("0.75"), singleConsumerSession.QoSInfo.LastQoSReport.Sync)
require.Equal(t, sdk.OneDec(), singleConsumerSession.QoSInfo.LastQoSReport.Latency)
singleConsumerSession.QoSManager.CalculateQoS(epoch, singleConsumerSession.SessionId, "", currentLatency, expectedLatency*2, expectedBH-latestServicedBlock, numOfProviders, 1)
require.Equal(t, uint64(4), singleConsumerSession.QoSManager.GetAnsweredRelays(epoch, singleConsumerSession.SessionId))
require.Equal(t, uint64(5), singleConsumerSession.QoSManager.GetTotalRelays(epoch, singleConsumerSession.SessionId))
require.Equal(t, int64(3), singleConsumerSession.QoSManager.GetSyncScoreSum(epoch, singleConsumerSession.SessionId))
require.Equal(t, int64(4), singleConsumerSession.QoSManager.GetTotalSyncScore(epoch, singleConsumerSession.SessionId))

lastQoSReport = singleConsumerSession.QoSManager.GetLastQoSReport(epoch, singleConsumerSession.SessionId)
require.Equal(t, sdk.ZeroDec(), lastQoSReport.Availability) // because availability below 95% is 0
require.Equal(t, sdk.MustNewDecFromStr("0.75"), lastQoSReport.Sync)
require.Equal(t, sdk.OneDec(), lastQoSReport.Latency)

latestServicedBlock = expectedBH + 1
// add in a loop so availability goes above 95%
for i := 5; i < 100; i++ {
singleConsumerSession.CalculateQoS(currentLatency, expectedLatency*2, expectedBH-latestServicedBlock, numOfProviders, 1)
singleConsumerSession.QoSManager.CalculateQoS(epoch, singleConsumerSession.SessionId, "", currentLatency, expectedLatency*2, expectedBH-latestServicedBlock, numOfProviders, 1)
}
require.Equal(t, sdk.MustNewDecFromStr("0.8"), singleConsumerSession.QoSInfo.LastQoSReport.Availability) // because availability below 95% is 0
require.Equal(t, sdk.MustNewDecFromStr("0.989898989898989898"), singleConsumerSession.QoSInfo.LastQoSReport.Sync)
require.Equal(t, sdk.OneDec(), singleConsumerSession.QoSInfo.LastQoSReport.Latency)

lastQoSReport = singleConsumerSession.QoSManager.GetLastQoSReport(epoch, singleConsumerSession.SessionId)
require.Equal(t, sdk.MustNewDecFromStr("0.8"), lastQoSReport.Availability) // because availability below 95% is 0
require.Equal(t, sdk.MustNewDecFromStr("0.989898989898989898"), lastQoSReport.Sync)
require.Equal(t, sdk.OneDec(), lastQoSReport.Latency)

finalizationInsertionsSpreadBlocks := []finalizationTestInsertion{
finalizationInsertionForProviders(chainID, epoch, 200, 0, 1, true, "", blocksInFinalizationProof, blockDistanceForFinalizedData)[0],
Expand Down
6 changes: 3 additions & 3 deletions protocol/lavaprotocol/request_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ func ConstructRelaySession(lavaChainID string, relayRequestData *pairingtypes.Re
return nil
}

copiedQOS := copyQoSServiceReport(singleConsumerSession.QoSInfo.LastQoSReport)
copiedExcellenceQOS := copyQoSServiceReport(singleConsumerSession.QoSInfo.LastExcellenceQoSReportRaw) // copy raw report for the node
copiedQOS := copyQoSServiceReport(singleConsumerSession.QoSManager.GetLastQoSReport(uint64(epoch), singleConsumerSession.SessionId))
copiedReputation := copyQoSServiceReport(singleConsumerSession.QoSManager.GetLastReputationQoSReport(uint64(epoch), singleConsumerSession.SessionId)) // copy reputation report for the node

return &pairingtypes.RelaySession{
SpecId: chainID,
Expand All @@ -87,7 +87,7 @@ func ConstructRelaySession(lavaChainID string, relayRequestData *pairingtypes.Re
LavaChainId: lavaChainID,
Sig: nil,
Badge: nil,
QosExcellenceReport: copiedExcellenceQOS,
QosExcellenceReport: copiedReputation,
}
}

Expand Down
5 changes: 3 additions & 2 deletions protocol/lavaprotocol/response_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/lavanet/lava/v4/protocol/lavaprotocol/finalizationverification"
"github.com/lavanet/lava/v4/protocol/lavasession"
"github.com/lavanet/lava/v4/protocol/qos"
"github.com/lavanet/lava/v4/utils/sigs"
pairingtypes "github.com/lavanet/lava/v4/x/pairing/types"
spectypes "github.com/lavanet/lava/v4/x/spec/types"
Expand All @@ -29,7 +30,7 @@ func TestSignAndExtractResponse(t *testing.T) {
singleConsumerSession := &lavasession.SingleConsumerSession{
CuSum: 20,
LatestRelayCu: 10, // set by GetSessions cuNeededForSession
QoSInfo: lavasession.QoSReport{LastQoSReport: &pairingtypes.QualityOfServiceReport{}},
QoSManager: qos.NewQoSManager(),
SessionId: 123,
Parent: nil,
RelayNum: 1,
Expand Down Expand Up @@ -77,7 +78,7 @@ func TestSignAndExtractResponseLatest(t *testing.T) {
singleConsumerSession := &lavasession.SingleConsumerSession{
CuSum: 20,
LatestRelayCu: 10, // set by GetSessions cuNeededForSession
QoSInfo: lavasession.QoSReport{LastQoSReport: &pairingtypes.QualityOfServiceReport{}},
QoSManager: qos.NewQoSManager(),
SessionId: 123,
Parent: nil,
RelayNum: 1,
Expand Down
3 changes: 2 additions & 1 deletion protocol/lavaprotocol/reuqest_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"testing"

"github.com/lavanet/lava/v4/protocol/lavasession"
"github.com/lavanet/lava/v4/protocol/qos"
"github.com/lavanet/lava/v4/utils/sigs"
pairingtypes "github.com/lavanet/lava/v4/x/pairing/types"
"github.com/stretchr/testify/require"
Expand All @@ -18,7 +19,7 @@ func TestSignAndExtract(t *testing.T) {
singleConsumerSession := &lavasession.SingleConsumerSession{
CuSum: 20,
LatestRelayCu: 10, // set by GetSessions cuNeededForSession
QoSInfo: lavasession.QoSReport{LastQoSReport: &pairingtypes.QualityOfServiceReport{}},
QoSManager: qos.NewQoSManager(),
SessionId: 123,
Parent: nil,
RelayNum: 1,
Expand Down
12 changes: 4 additions & 8 deletions protocol/lavasession/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
sdkerrors "cosmossdk.io/errors"
"golang.org/x/exp/slices"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/gogo/status"
"github.com/lavanet/lava/v4/protocol/chainlib/chainproxy"
"github.com/lavanet/lava/v4/utils"
Expand Down Expand Up @@ -48,14 +47,11 @@ const (
unixPrefix = "unix:"
)

var AvailabilityPercentage sdk.Dec = sdk.NewDecWithPrec(1, 1) // TODO move to params pairing
const (
PercentileToCalculateLatency = 0.9
MinProvidersForSync = 0.6
OptimizerPerturbation = 0.10
LatencyThresholdStatic = 1 * time.Second
LatencyThresholdSlope = 1 * time.Millisecond
StaleEpochDistance = 3 // relays done 3 epochs back are ready to be rewarded
OptimizerPerturbation = 0.10
LatencyThresholdStatic = 1 * time.Second
LatencyThresholdSlope = 1 * time.Millisecond
StaleEpochDistance = 3 // relays done 3 epochs back are ready to be rewarded

)

Expand Down
Loading

0 comments on commit f9c2007

Please sign in to comment.