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

services/horizon: Issue #3476, Include claimable balances in asset stats summaries #3502

Merged
merged 20 commits into from
Apr 1, 2021
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
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
2 changes: 2 additions & 0 deletions protocols/horizon/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,13 +185,15 @@ func (res AssetStat) PagingToken() string {
type AssetStatBalances struct {
Authorized string `json:"authorized"`
AuthorizedToMaintainLiabilities string `json:"authorized_to_maintain_liabilities"`
ClaimableBalances string `json:"claimable_balances"`
Unauthorized string `json:"unauthorized"`
}

// AssetStatAccounts represents the summarized acount numbers for a single Asset
type AssetStatAccounts struct {
Authorized int32 `json:"authorized"`
AuthorizedToMaintainLiabilities int32 `json:"authorized_to_maintain_liabilities"`
ClaimableBalances int32 `json:"claimable_balances"`
paulbellamy marked this conversation as resolved.
Show resolved Hide resolved
Unauthorized int32 `json:"unauthorized"`
}

Expand Down
1 change: 1 addition & 0 deletions services/horizon/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ file. This project adheres to [Semantic Versioning](http://semver.org/).

## Unreleased

* Add `claimable_balances` to asset stat summaries at `/assets` ([3502](https://github.com/stellar/go/pull/3502)).
paulbellamy marked this conversation as resolved.
Show resolved Hide resolved
* Add an endpoint which determines if Horizon is healthy enough to receive traffic ([3435](https://github.com/stellar/go/pull/3435)).
* Sanitize route regular expressions for Prometheus metrics ([3459](https://github.com/stellar/go/pull/3459)).
* Add asset stat summaries per trust-line flag category ([3454](https://github.com/stellar/go/pull/3454)).
Expand Down
20 changes: 20 additions & 0 deletions services/horizon/internal/actions/asset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,13 @@ func TestAssetStats(t *testing.T) {
Authorized: 2,
AuthorizedToMaintainLiabilities: 3,
Unauthorized: 4,
ClaimableBalances: 1,
},
Balances: history.ExpAssetStatBalances{
Authorized: "1",
AuthorizedToMaintainLiabilities: "2",
Unauthorized: "3",
ClaimableBalances: "10",
},
Amount: "1",
NumAccounts: 2,
Expand All @@ -143,11 +145,13 @@ func TestAssetStats(t *testing.T) {
Authorized: usdAssetStat.Accounts.Authorized,
AuthorizedToMaintainLiabilities: usdAssetStat.Accounts.AuthorizedToMaintainLiabilities,
Unauthorized: usdAssetStat.Accounts.Unauthorized,
ClaimableBalances: usdAssetStat.Accounts.ClaimableBalances,
},
Balances: horizon.AssetStatBalances{
Authorized: "0.0000001",
AuthorizedToMaintainLiabilities: "0.0000002",
Unauthorized: "0.0000003",
ClaimableBalances: "0.0000010",
},
Amount: "0.0000001",
NumAccounts: usdAssetStat.NumAccounts,
Expand All @@ -168,11 +172,13 @@ func TestAssetStats(t *testing.T) {
Authorized: 1,
AuthorizedToMaintainLiabilities: 2,
Unauthorized: 3,
ClaimableBalances: 0,
},
Balances: history.ExpAssetStatBalances{
Authorized: "23",
AuthorizedToMaintainLiabilities: "46",
Unauthorized: "92",
ClaimableBalances: "0",
},
Amount: "23",
NumAccounts: 1,
Expand All @@ -182,11 +188,13 @@ func TestAssetStats(t *testing.T) {
Authorized: etherAssetStat.Accounts.Authorized,
AuthorizedToMaintainLiabilities: etherAssetStat.Accounts.AuthorizedToMaintainLiabilities,
Unauthorized: etherAssetStat.Accounts.Unauthorized,
ClaimableBalances: etherAssetStat.Accounts.ClaimableBalances,
},
Balances: horizon.AssetStatBalances{
Authorized: "0.0000023",
AuthorizedToMaintainLiabilities: "0.0000046",
Unauthorized: "0.0000092",
ClaimableBalances: "0.0000000",
},
Amount: "0.0000023",
NumAccounts: etherAssetStat.NumAccounts,
Expand All @@ -207,11 +215,13 @@ func TestAssetStats(t *testing.T) {
Authorized: 2,
AuthorizedToMaintainLiabilities: 3,
Unauthorized: 4,
ClaimableBalances: 0,
},
Balances: history.ExpAssetStatBalances{
Authorized: "1",
AuthorizedToMaintainLiabilities: "2",
Unauthorized: "3",
ClaimableBalances: "0",
},
Amount: "1",
NumAccounts: 2,
Expand All @@ -221,11 +231,13 @@ func TestAssetStats(t *testing.T) {
Authorized: otherUSDAssetStat.Accounts.Authorized,
AuthorizedToMaintainLiabilities: otherUSDAssetStat.Accounts.AuthorizedToMaintainLiabilities,
Unauthorized: otherUSDAssetStat.Accounts.Unauthorized,
ClaimableBalances: otherUSDAssetStat.Accounts.ClaimableBalances,
},
Balances: horizon.AssetStatBalances{
Authorized: "0.0000001",
AuthorizedToMaintainLiabilities: "0.0000002",
Unauthorized: "0.0000003",
ClaimableBalances: "0.0000000",
},
Amount: "0.0000001",
NumAccounts: otherUSDAssetStat.NumAccounts,
Expand All @@ -248,11 +260,13 @@ func TestAssetStats(t *testing.T) {
Authorized: 3,
AuthorizedToMaintainLiabilities: 4,
Unauthorized: 5,
ClaimableBalances: 0,
},
Balances: history.ExpAssetStatBalances{
Authorized: "111",
AuthorizedToMaintainLiabilities: "222",
Unauthorized: "333",
ClaimableBalances: "0",
},
Amount: "111",
NumAccounts: 3,
Expand All @@ -262,11 +276,13 @@ func TestAssetStats(t *testing.T) {
Authorized: eurAssetStat.Accounts.Authorized,
AuthorizedToMaintainLiabilities: eurAssetStat.Accounts.AuthorizedToMaintainLiabilities,
Unauthorized: eurAssetStat.Accounts.Unauthorized,
ClaimableBalances: eurAssetStat.Accounts.ClaimableBalances,
},
Balances: horizon.AssetStatBalances{
Authorized: "0.0000111",
AuthorizedToMaintainLiabilities: "0.0000222",
Unauthorized: "0.0000333",
ClaimableBalances: "0.0000000",
},
Amount: "0.0000111",
NumAccounts: eurAssetStat.NumAccounts,
Expand Down Expand Up @@ -419,11 +435,13 @@ func TestAssetStatsIssuerDoesNotExist(t *testing.T) {
Authorized: 2,
AuthorizedToMaintainLiabilities: 3,
Unauthorized: 4,
ClaimableBalances: 0,
},
Balances: history.ExpAssetStatBalances{
Authorized: "1",
AuthorizedToMaintainLiabilities: "2",
Unauthorized: "3",
ClaimableBalances: "0",
},
Amount: "1",
NumAccounts: 2,
Expand All @@ -441,11 +459,13 @@ func TestAssetStatsIssuerDoesNotExist(t *testing.T) {
Authorized: 2,
AuthorizedToMaintainLiabilities: 3,
Unauthorized: 4,
ClaimableBalances: 0,
},
Balances: horizon.AssetStatBalances{
Authorized: "0.0000001",
AuthorizedToMaintainLiabilities: "0.0000002",
Unauthorized: "0.0000003",
ClaimableBalances: "0.0000000",
},
Amount: "0.0000001",
NumAccounts: usdAssetStat.NumAccounts,
Expand Down
5 changes: 4 additions & 1 deletion services/horizon/internal/db2/history/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ func (e ExpAssetStat) PagingToken() string {
type ExpAssetStatAccounts struct {
Authorized int32 `json:"authorized"`
AuthorizedToMaintainLiabilities int32 `json:"authorized_to_maintain_liabilities"`
ClaimableBalances int32 `json:"claimable_balances"`
Unauthorized int32 `json:"unauthorized"`
}

Expand All @@ -367,18 +368,20 @@ func (a ExpAssetStatAccounts) Add(b ExpAssetStatAccounts) ExpAssetStatAccounts {
return ExpAssetStatAccounts{
Authorized: a.Authorized + b.Authorized,
AuthorizedToMaintainLiabilities: a.AuthorizedToMaintainLiabilities + b.AuthorizedToMaintainLiabilities,
ClaimableBalances: a.ClaimableBalances + b.ClaimableBalances,
Unauthorized: a.Unauthorized + b.Unauthorized,
}
}

func (a ExpAssetStatAccounts) IsZero() bool {
return a.Authorized == 0 && a.AuthorizedToMaintainLiabilities == 0 && a.Unauthorized == 0
return a == ExpAssetStatAccounts{}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated to this PR: does Exp stand for experimental? If so, I think it's about time to remove it.

Copy link
Contributor Author

@paulbellamy paulbellamy Mar 31, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like db2 and history are both misnomers as well, given there's only one db, and two "sections" (for lack of a better term) within it, the normal (current? state?) tables and history_* tables.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should try to change exp_asset_stats table name too? Not sure how complicated it is.

}

// ExpAssetStatBalances represents the summarized balances for a single Asset
type ExpAssetStatBalances struct {
Authorized string `json:"authorized"`
AuthorizedToMaintainLiabilities string `json:"authorized_to_maintain_liabilities"`
ClaimableBalances string `json:"claimable_balances"`
Unauthorized string `json:"unauthorized"`
}

Expand Down
16 changes: 11 additions & 5 deletions services/horizon/internal/docs/reference/endpoints/assets-all.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,14 @@ If called normally this endpoint responds with a [page](../resources/page.md) of
"accounts": {
"authorized": 2126,
"authorized_to_maintain_liabilities": 32,
"unauthorized": 5
"unauthorized": 5,
"claimable_balances": 18
},
"balances": {
"authorized": "10000.0000000",
"authorized_to_maintain_liabilities": "3000.0000000",
"unauthorized": "4000.0000000"
"unauthorized": "4000.0000000",
"claimable_balances": "2380.0000000"
},
"flags": {
"auth_required": true,
Expand All @@ -106,12 +108,14 @@ If called normally this endpoint responds with a [page](../resources/page.md) of
"accounts": {
"authorized": 32,
"authorized_to_maintain_liabilities": 124,
"unauthorized": 6
"unauthorized": 6,
"claimable_balances": 18
},
"balances": {
"authorized": "5000.0000000",
"authorized_to_maintain_liabilities": "8000.0000000",
"unauthorized": "2000.0000000"
"claimable_balances": "1200.0000000"
paulbellamy marked this conversation as resolved.
Show resolved Hide resolved
},
"flags": {
"auth_required": false,
Expand All @@ -131,12 +135,14 @@ If called normally this endpoint responds with a [page](../resources/page.md) of
"accounts": {
"authorized": 91547871,
"authorized_to_maintain_liabilities": 45773935,
"unauthorized": 22886967
"unauthorized": 22886967,
"claimable_balances": 11443483
},
"balances": {
"authorized": "1000000000.0000000",
"authorized_to_maintain_liabilities": "500000000.0000000",
"unauthorized": "250000000.0000000"
"unauthorized": "250000000.0000000",
"claimable_balances": "12500000.0000000"
},
"flags": {
"auth_required": false,
Expand Down
10 changes: 6 additions & 4 deletions services/horizon/internal/docs/reference/resources/asset.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ To learn more about the concept of assets in the Stellar network, take a look at
| asset_type | string | The type of this asset: "credit_alphanum4", or "credit_alphanum12". |
| asset_code | string | The code of this asset. |
| asset_issuer | string | The issuer of this asset. |
| accounts | object | The number of accounts holding this asset, summarized by each state of the trust line flags. |
| balances | object | The number of units of credit issued, summarized by each state of the trust line flags. |
| accounts | object | The number of accounts and claimable balances holding this asset. Accounts are summarized by each state of the trust line flags. |
| balances | object | The number of units of credit issued, summarized by each state of the trust line flags, or if they are in a claimable balance. |
| flags | object | The flags denote the enabling/disabling of certain asset issuer privileges. |
| paging_token | string | A [paging token](./page.md) suitable for use as the `cursor` parameter to transaction collection resources. |

Expand Down Expand Up @@ -49,12 +49,14 @@ To learn more about the concept of assets in the Stellar network, take a look at
"accounts": {
"authorized": 91547871,
"authorized_to_maintain_liabilities": 45773935,
"unauthorized": 22886967
"unauthorized": 22886967,
"claimable_balances": 11443483
},
"balances": {
"authorized": "100.0000000",
"authorized_to_maintain_liabilities": "50.0000000",
"unauthorized": "25.0000000"
"unauthorized": "25.0000000",
"claimable_balances": "12.5000000"
},
"flags": {
"auth_required": false,
Expand Down
3 changes: 2 additions & 1 deletion services/horizon/internal/ingest/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ const (
// - 12: Trigger state rebuild due to `absTime` -> `abs_time` rename
// in ClaimableBalances predicates.
// - 13: Trigger state rebuild to include more than just authorized assets.
CurrentVersion = 13
// - 14: Trigger state rebuild to include claimable balances in the asset stats processor.
CurrentVersion = 14

// MaxDBConnections is the size of the postgres connection pool dedicated to Horizon ingestion:
// * Ledger ingestion,
Expand Down
Loading