Skip to content

Commit

Permalink
rm total related stats
Browse files Browse the repository at this point in the history
  • Loading branch information
gusin13 committed Dec 12, 2024
1 parent 040e3b5 commit 88e7ada
Show file tree
Hide file tree
Showing 10 changed files with 4 additions and 91 deletions.
15 changes: 0 additions & 15 deletions docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1297,17 +1297,8 @@ const docTemplate = `{
"active_tvl": {
"type": "integer"
},
"total_delegations": {
"type": "integer"
},
"total_finality_providers": {
"type": "integer"
},
"total_stakers": {
"type": "integer"
},
"total_tvl": {
"type": "integer"
}
}
},
Expand Down Expand Up @@ -1339,12 +1330,6 @@ const docTemplate = `{
},
"staker_pk_hex": {
"type": "string"
},
"total_delegations": {
"type": "integer"
},
"total_tvl": {
"type": "integer"
}
}
},
Expand Down
15 changes: 0 additions & 15 deletions docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -1289,17 +1289,8 @@
"active_tvl": {
"type": "integer"
},
"total_delegations": {
"type": "integer"
},
"total_finality_providers": {
"type": "integer"
},
"total_stakers": {
"type": "integer"
},
"total_tvl": {
"type": "integer"
}
}
},
Expand Down Expand Up @@ -1331,12 +1322,6 @@
},
"staker_pk_hex": {
"type": "string"
},
"total_delegations": {
"type": "integer"
},
"total_tvl": {
"type": "integer"
}
}
},
Expand Down
10 changes: 0 additions & 10 deletions docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -434,14 +434,8 @@ definitions:
type: integer
active_tvl:
type: integer
total_delegations:
type: integer
total_finality_providers:
type: integer
total_stakers:
type: integer
total_tvl:
type: integer
type: object
v2service.ParamsPublic:
properties:
Expand All @@ -462,10 +456,6 @@ definitions:
type: integer
staker_pk_hex:
type: string
total_delegations:
type: integer
total_tvl:
type: integer
type: object
v2service.StakingStatusPublic:
properties:
Expand Down
18 changes: 0 additions & 18 deletions internal/v2/db/client/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ func (v2dbclient *V2Database) IncrementOverallStats(
ctx context.Context, stakingTxHashHex, stakerPkHex string, amount uint64,
) error {
overallStatsClient := v2dbclient.Client.Database(v2dbclient.DbName).Collection(dbmodel.V2OverallStatsCollection)
stakerStatsClient := v2dbclient.Client.Database(v2dbclient.DbName).Collection(dbmodel.V2StakerStatsCollection)

// Start a session
session, sessionErr := v2dbclient.Client.StartSession()
Expand All @@ -63,9 +62,7 @@ func (v2dbclient *V2Database) IncrementOverallStats(
upsertUpdate := bson.M{
"$inc": bson.M{
"active_tvl": int64(amount),
"total_tvl": int64(amount),
"active_delegations": 1,
"total_delegations": 1,
},
}
// Define the work to be done in the transaction
Expand All @@ -75,18 +72,6 @@ func (v2dbclient *V2Database) IncrementOverallStats(
return nil, err
}

// The order of the overall stats and staker stats update is important.
// The staker stats colleciton will need to be processed first to determine if the staker is new
// If the staker stats is the first delegation for the staker, we need to increment the total stakers
var stakerStats v2dbmodel.V2StakerStatsDocument
stakerStatsFilter := bson.M{"_id": stakerPkHex}
stakerErr := stakerStatsClient.FindOne(ctx, stakerStatsFilter).Decode(&stakerStats)
if stakerErr != nil {
return nil, stakerErr
}
if stakerStats.TotalDelegations == 1 {
upsertUpdate["$inc"].(bson.M)["total_stakers"] = 1
}
shardId, err := v2dbclient.generateOverallStatsId()
if err != nil {
return nil, err
Expand Down Expand Up @@ -184,10 +169,7 @@ func (v2dbclient *V2Database) GetOverallStats(ctx context.Context) (*v2dbmodel.V
var result v2dbmodel.V2OverallStatsDocument
for _, stats := range overallStats {
result.ActiveTvl += stats.ActiveTvl
result.TotalTvl += stats.TotalTvl
result.ActiveDelegations += stats.ActiveDelegations
result.TotalDelegations += stats.TotalDelegations
result.TotalStakers += stats.TotalStakers
}

return &result, nil
Expand Down
19 changes: 0 additions & 19 deletions internal/v2/db/model/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,36 +25,17 @@ func NewV2StatsLockDocument(
type V2OverallStatsDocument struct {
Id string `bson:"_id"`
ActiveTvl int64 `bson:"active_tvl"`
TotalTvl int64 `bson:"total_tvl"`
ActiveDelegations int64 `bson:"active_delegations"`
TotalDelegations int64 `bson:"total_delegations"`
TotalStakers uint64 `bson:"total_stakers"`
}

type V2StakerStatsDocument struct {
StakerPkHex string `bson:"_id"`
ActiveTvl int64 `bson:"active_tvl"`
TotalTvl int64 `bson:"total_tvl"`
ActiveDelegations int64 `bson:"active_delegations"`
TotalDelegations int64 `bson:"total_delegations"`
}

type V2FinalityProviderStatsDocument struct {
FinalityProviderPkHex string `bson:"_id"`
ActiveTvl int64 `bson:"active_tvl"`
TotalTvl int64 `bson:"total_tvl"`
ActiveDelegations int64 `bson:"active_delegations"`
TotalDelegations int64 `bson:"total_delegations"`
}

type V2FpSlashingLockDocument struct {
FinalityProviderPkHex string `bson:"_id"` // <fp_btc_pk_hex>
IsProcessed bool `bson:"is_processed"` // true when processing is complete
}

func NewV2FpSlashingLockDocument(fpBtcPkHex string) *V2FpSlashingLockDocument {
return &V2FpSlashingLockDocument{
FinalityProviderPkHex: fpBtcPkHex,
IsProcessed: false,
}
}
10 changes: 0 additions & 10 deletions internal/v2/service/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,16 @@ import (

type OverallStatsPublic struct {
ActiveTvl int64 `json:"active_tvl"`
TotalTvl int64 `json:"total_tvl"`
ActiveDelegations int64 `json:"active_delegations"`
TotalDelegations int64 `json:"total_delegations"`
ActiveStakers uint64 `json:"active_stakers"`
TotalStakers uint64 `json:"total_stakers"`
ActiveFinalityProviders uint64 `json:"active_finality_providers"`
TotalFinalityProviders uint64 `json:"total_finality_providers"`
}

type StakerStatsPublic struct {
StakerPkHex string `json:"staker_pk_hex"`
ActiveTvl int64 `json:"active_tvl"`
TotalTvl int64 `json:"total_tvl"`
ActiveDelegations int64 `json:"active_delegations"`
TotalDelegations int64 `json:"total_delegations"`
}

func (s *V2Service) GetOverallStats(ctx context.Context) (*OverallStatsPublic, *types.Error) {
Expand Down Expand Up @@ -58,11 +53,8 @@ func (s *V2Service) GetOverallStats(ctx context.Context) (*OverallStatsPublic, *

return &OverallStatsPublic{
ActiveTvl: overallStats.ActiveTvl,
TotalTvl: overallStats.TotalTvl,
ActiveDelegations: overallStats.ActiveDelegations,
TotalDelegations: overallStats.TotalDelegations,
ActiveStakers: uint64(activeStakersCount),
TotalStakers: overallStats.TotalStakers,
ActiveFinalityProviders: uint64(activeFinalityProvidersCount),
TotalFinalityProviders: uint64(len(finalityProviders)),
}, nil
Expand All @@ -78,9 +70,7 @@ func (s *V2Service) GetStakerStats(ctx context.Context, stakerPKHex string) (*St
return &StakerStatsPublic{
StakerPkHex: stakerStats.StakerPkHex,
ActiveTvl: stakerStats.ActiveTvl,
TotalTvl: stakerStats.TotalTvl,
ActiveDelegations: stakerStats.ActiveDelegations,
TotalDelegations: stakerStats.TotalDelegations,
}, nil
}

Expand Down
2 changes: 1 addition & 1 deletion tests/mocks/mock_db_client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/mocks/mock_ordinal_client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/mocks/mock_v1_db_client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/mocks/mock_v2_db_client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 88e7ada

Please sign in to comment.