From 43cdce9ad1dcc8bcd391686ece9643fe718c89de Mon Sep 17 00:00:00 2001 From: Karthik Iyer Date: Thu, 26 Sep 2024 20:19:04 -0700 Subject: [PATCH 01/11] Update .gitignore to ignore bucket-cache/ at any level --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index c505323c66..8b40766e30 100644 --- a/.gitignore +++ b/.gitignore @@ -5,7 +5,7 @@ /services/horizon/captive-core /services/horizon/horizon /services/horizon/stellar-horizon -/bucket-cache +**bucket-cache/ .vscode .idea debug From 811ae435ce9c0bed18eb0029d2204b11918d7218 Mon Sep 17 00:00:00 2001 From: Karthik Iyer Date: Thu, 26 Sep 2024 20:19:42 -0700 Subject: [PATCH 02/11] clean up all occurences of Amount and NumAccounts (#5438) --- clients/horizonclient/main_test.go | 2 - protocols/horizon/main.go | 4 +- .../horizon/internal/actions/asset_test.go | 10 --- .../integration/liquidity_pool_test.go | 2 - .../horizon/internal/integration/sac_test.go | 2 - .../internal/resourceadapter/asset_stat.go | 2 - .../resourceadapter/asset_stat_test.go | 4 - .../configureissuer/configureissuer_test.go | 7 +- .../ticker/internal/scraper/asset_scraper.go | 30 ++++++-- .../internal/scraper/asset_scraper_test.go | 73 +------------------ 10 files changed, 31 insertions(+), 105 deletions(-) diff --git a/clients/horizonclient/main_test.go b/clients/horizonclient/main_test.go index f7b4ba0788..b11b807bee 100644 --- a/clients/horizonclient/main_test.go +++ b/clients/horizonclient/main_test.go @@ -480,8 +480,6 @@ func TestAssetsRequest(t *testing.T) { assert.Equal(t, record.Asset.Code, "ABC") assert.Equal(t, record.Asset.Issuer, "GCLWGQPMKXQSPF776IU33AH4PZNOOWNAWGGKVTBQMIC5IMKUNP3E6NVU") assert.Equal(t, record.PT, "1") - assert.Equal(t, record.NumAccounts, int32(3)) - assert.Equal(t, record.Amount, "105.0000000") assert.Equal(t, record.Flags.AuthRevocable, false) assert.Equal(t, record.Flags.AuthRequired, true) assert.Equal(t, record.Flags.AuthImmutable, false) diff --git a/protocols/horizon/main.go b/protocols/horizon/main.go index df4aee78cf..72c4269f8e 100644 --- a/protocols/horizon/main.go +++ b/protocols/horizon/main.go @@ -178,13 +178,13 @@ type AssetStat struct { PT string `json:"paging_token"` ContractID string `json:"contract_id,omitempty"` // Action needed in release: horizon-v3.0.0: deprecated field - NumAccounts int32 `json:"num_accounts"` + //NumAccounts int32 `json:"num_accounts"` NumClaimableBalances int32 `json:"num_claimable_balances"` NumLiquidityPools int32 `json:"num_liquidity_pools"` NumContracts int32 `json:"num_contracts"` NumArchivedContracts int32 `json:"num_archived_contracts"` // Action needed in release: horizon-v3.0.0: deprecated field - Amount string `json:"amount"` + // Amount string `json:"amount"` Accounts AssetStatAccounts `json:"accounts"` ClaimableBalancesAmount string `json:"claimable_balances_amount"` LiquidityPoolsAmount string `json:"liquidity_pools_amount"` diff --git a/services/horizon/internal/actions/asset_test.go b/services/horizon/internal/actions/asset_test.go index 0e4995d93c..68b56d94b2 100644 --- a/services/horizon/internal/actions/asset_test.go +++ b/services/horizon/internal/actions/asset_test.go @@ -157,8 +157,6 @@ func TestAssetStats(t *testing.T) { }, ClaimableBalancesAmount: "0.0000010", LiquidityPoolsAmount: "0.0000020", - Amount: "0.0000001", - NumAccounts: usdAssetStat.NumAccounts, ContractsAmount: "0.0000000", ArchivedContractsAmount: "0.0000000", Asset: base.Asset{ @@ -206,8 +204,6 @@ func TestAssetStats(t *testing.T) { LiquidityPoolsAmount: "0.0000000", ContractsAmount: "0.0000000", ArchivedContractsAmount: "0.0000000", - Amount: "0.0000023", - NumAccounts: etherAssetStat.NumAccounts, Asset: base.Asset{ Type: "credit_alphanum4", Code: etherAssetStat.AssetCode, @@ -251,10 +247,8 @@ func TestAssetStats(t *testing.T) { }, ClaimableBalancesAmount: "0.0000000", LiquidityPoolsAmount: "0.0000000", - Amount: "0.0000001", ContractsAmount: "0.0000000", ArchivedContractsAmount: "0.0000000", - NumAccounts: otherUSDAssetStat.NumAccounts, Asset: base.Asset{ Type: "credit_alphanum4", Code: otherUSDAssetStat.AssetCode, @@ -300,10 +294,8 @@ func TestAssetStats(t *testing.T) { }, ClaimableBalancesAmount: "0.0000000", LiquidityPoolsAmount: "0.0000000", - Amount: "0.0000111", ContractsAmount: "0.0000000", ArchivedContractsAmount: "0.0000000", - NumAccounts: eurAssetStat.NumAccounts, Asset: base.Asset{ Type: "credit_alphanum4", Code: eurAssetStat.AssetCode, @@ -478,10 +470,8 @@ func TestAssetStatsIssuerDoesNotExist(t *testing.T) { }, ClaimableBalancesAmount: "0.0000000", LiquidityPoolsAmount: "0.0000000", - Amount: "0.0000001", ContractsAmount: "0.0000000", ArchivedContractsAmount: "0.0000000", - NumAccounts: usdAssetStat.NumAccounts, Asset: base.Asset{ Type: "credit_alphanum4", Code: usdAssetStat.AssetCode, diff --git a/services/horizon/internal/integration/liquidity_pool_test.go b/services/horizon/internal/integration/liquidity_pool_test.go index 9106003179..bb7e39a7c6 100644 --- a/services/horizon/internal/integration/liquidity_pool_test.go +++ b/services/horizon/internal/integration/liquidity_pool_test.go @@ -156,8 +156,6 @@ func TestLiquidityPoolHappyPath(t *testing.T) { tt.Equal("credit_alphanum4", stat.Asset.Type) tt.Equal("USD", stat.Asset.Code) tt.Equal(master.Address(), stat.Asset.Issuer) - tt.Equal(int32(2), stat.NumAccounts) - tt.Equal("225.0000000", stat.Amount) tt.Equal(int32(1), stat.NumLiquidityPools) tt.Equal("775.0000000", stat.LiquidityPoolsAmount) diff --git a/services/horizon/internal/integration/sac_test.go b/services/horizon/internal/integration/sac_test.go index 7eb91a201c..a7311d173d 100644 --- a/services/horizon/internal/integration/sac_test.go +++ b/services/horizon/internal/integration/sac_test.go @@ -1104,9 +1104,7 @@ func assertAssetStats(itest *integration.Test, expected assetStats) { asset := assets.Embedded.Records[0] assert.Equal(itest.CurrentTest(), expected.code, asset.Code) assert.Equal(itest.CurrentTest(), expected.issuer, asset.Issuer) - assert.Equal(itest.CurrentTest(), expected.numAccounts, asset.NumAccounts) assert.Equal(itest.CurrentTest(), expected.numAccounts, asset.Accounts.Authorized) - assert.Equal(itest.CurrentTest(), expected.balanceAccounts, amount.MustParse(asset.Amount)) assert.Equal(itest.CurrentTest(), expected.numContracts, asset.NumContracts) assert.Equal(itest.CurrentTest(), expected.numArchivedContracts, asset.NumArchivedContracts) assert.Equal(itest.CurrentTest(), expected.balanceContracts.String(), parseBalance(itest, asset.ContractsAmount).String()) diff --git a/services/horizon/internal/resourceadapter/asset_stat.go b/services/horizon/internal/resourceadapter/asset_stat.go index 994cce99a0..8cc2c12740 100644 --- a/services/horizon/internal/resourceadapter/asset_stat.go +++ b/services/horizon/internal/resourceadapter/asset_stat.go @@ -39,7 +39,6 @@ func PopulateAssetStat( res.NumLiquidityPools = row.Accounts.LiquidityPools res.NumContracts = row.Contracts.ActiveHolders res.NumArchivedContracts = row.Contracts.ArchivedHolders - res.NumAccounts = row.NumAccounts err = populateAssetStatBalances(res, row) if err != nil { return err @@ -63,7 +62,6 @@ func PopulateAssetStat( } func populateAssetStatBalances(res *protocol.AssetStat, row history.AssetAndContractStat) (err error) { - res.Amount, err = amount.IntStringToAmount(row.Balances.Authorized) if err != nil { return errors.Wrap(err, "Invalid amount in PopulateAssetStat") } diff --git a/services/horizon/internal/resourceadapter/asset_stat_test.go b/services/horizon/internal/resourceadapter/asset_stat_test.go index d3b14d62e6..e36b7bef85 100644 --- a/services/horizon/internal/resourceadapter/asset_stat_test.go +++ b/services/horizon/internal/resourceadapter/asset_stat_test.go @@ -67,8 +67,6 @@ func TestPopulateExpAssetStat(t *testing.T) { assert.Equal(t, "770000000000.0000000", res.LiquidityPoolsAmount) assert.Equal(t, "90000000000.0000000", res.ContractsAmount) assert.Equal(t, "70000000000.0000000", res.ArchivedContractsAmount) - assert.Equal(t, "10000000000000.0000000", res.Amount) - assert.Equal(t, int32(429), res.NumAccounts) assert.Equal(t, horizon.AccountFlags{}, res.Flags) assert.Equal(t, "https://xim.com/.well-known/stellar.toml", res.Links.Toml.Href) assert.Equal(t, "", res.ContractID) @@ -90,8 +88,6 @@ func TestPopulateExpAssetStat(t *testing.T) { assert.Equal(t, "credit_alphanum4", res.Type) assert.Equal(t, "XIM", res.Code) assert.Equal(t, "GBZ35ZJRIKJGYH5PBKLKOZ5L6EXCNTO7BKIL7DAVVDFQ2ODJEEHHJXIM", res.Issuer) - assert.Equal(t, "10000000000000.0000000", res.Amount) - assert.Equal(t, int32(429), res.NumAccounts) assert.Equal( t, horizon.AccountFlags{ diff --git a/services/regulated-assets-approval-server/internal/configureissuer/configureissuer_test.go b/services/regulated-assets-approval-server/internal/configureissuer/configureissuer_test.go index f26afdae11..a24afb9318 100644 --- a/services/regulated-assets-approval-server/internal/configureissuer/configureissuer_test.go +++ b/services/regulated-assets-approval-server/internal/configureissuer/configureissuer_test.go @@ -45,6 +45,9 @@ func TestSetup_accountAlreadyConfigured(t *testing.T) { HomeDomain: "domain.test.com", Sequence: 10, }, nil) + + dummyAsset := horizon.AssetStat{} + dummyAsset.Asset.Code = "FOO" horizonMock. On("Assets", horizonclient.AssetRequest{ ForAssetCode: opts.AssetCode, @@ -53,9 +56,7 @@ func TestSetup_accountAlreadyConfigured(t *testing.T) { }). Return(horizon.AssetsPage{ Embedded: struct{ Records []horizon.AssetStat }{ - Records: []horizon.AssetStat{ - {Amount: "0.0000001"}, - }, + Records: []horizon.AssetStat{dummyAsset}, }, }, nil) diff --git a/services/ticker/internal/scraper/asset_scraper.go b/services/ticker/internal/scraper/asset_scraper.go index ca7899a25d..c4c6d009cc 100644 --- a/services/ticker/internal/scraper/asset_scraper.go +++ b/services/ticker/internal/scraper/asset_scraper.go @@ -23,15 +23,17 @@ import ( // shouldDiscardAsset maps the criteria for discarding an asset from the asset index func shouldDiscardAsset(asset hProtocol.AssetStat, shouldValidateTOML bool) bool { - if asset.Amount == "" { + amt, _ := AddStringsToSum(asset.Balances.AuthorizedToMaintainLiabilities + asset.Balances.Unauthorized + asset.Balances.Authorized) + amount := strconv.FormatFloat(amt, 'f', -1, 64) + + if amount == "" { return true } - f, _ := strconv.ParseFloat(asset.Amount, 64) - if f == 0.0 { + if amt == 0.0 { return true } // [StellarX Ticker]: assets need at least some adoption to show up - if asset.NumAccounts < 10 { + if asset.Accounts.Unauthorized+asset.Accounts.Authorized+asset.Accounts.AuthorizedToMaintainLiabilities < 10 { return true } if asset.Code == "REMOVE" { @@ -39,7 +41,7 @@ func shouldDiscardAsset(asset hProtocol.AssetStat, shouldValidateTOML bool) bool } // [StellarX Ticker]: assets with at least 100 accounts get a pass, // even with toml issues - if asset.NumAccounts >= 100 { + if asset.Accounts.Unauthorized+asset.Accounts.Authorized+asset.Accounts.AuthorizedToMaintainLiabilities >= 100 { return false } @@ -143,6 +145,20 @@ func isDomainVerified(orgURL string, tomlURL string, hasCurrency bool) bool { } return true } +func AddStringsToSum(values ...string) (float64, error) { + var sum float64 + for _, s := range values { + if s == "" { + continue // Treat empty string as zero + } + value, err := strconv.ParseFloat(s, 64) + if err != nil { + return 0, fmt.Errorf("failed to convert '%s': %w", s, err) + } + sum += value + } + return sum, nil +} // makeTomlAsset aggregates Horizon Data with TOML Data func makeFinalAsset( @@ -150,7 +166,7 @@ func makeFinalAsset( issuer TOMLIssuer, errors []error, ) (t FinalAsset, err error) { - amount, err := strconv.ParseFloat(asset.Amount, 64) + amount, err := AddStringsToSum(asset.Balances.Authorized + asset.Balances.Unauthorized + asset.Balances.Unauthorized) if err != nil { return } @@ -159,7 +175,7 @@ func makeFinalAsset( Type: asset.Type, Code: asset.Code, Issuer: asset.Issuer, - NumAccounts: asset.NumAccounts, + NumAccounts: asset.Accounts.Authorized + asset.Accounts.Unauthorized + asset.Accounts.AuthorizedToMaintainLiabilities, AuthRequired: asset.Flags.AuthRequired, AuthRevocable: asset.Flags.AuthRevocable, Amount: amount, diff --git a/services/ticker/internal/scraper/asset_scraper_test.go b/services/ticker/internal/scraper/asset_scraper_test.go index 39f3e0a2ee..96918c6c83 100644 --- a/services/ticker/internal/scraper/asset_scraper_test.go +++ b/services/ticker/internal/scraper/asset_scraper_test.go @@ -14,69 +14,6 @@ import ( "github.com/stretchr/testify/require" ) -func TestShouldDiscardAsset(t *testing.T) { - testAsset := hProtocol.AssetStat{ - Amount: "", - } - - assert.Equal(t, shouldDiscardAsset(testAsset, true), true) - - testAsset = hProtocol.AssetStat{ - Amount: "0.0", - } - assert.Equal(t, shouldDiscardAsset(testAsset, true), true) - - testAsset = hProtocol.AssetStat{ - Amount: "0", - } - assert.Equal(t, shouldDiscardAsset(testAsset, true), true) - - testAsset = hProtocol.AssetStat{ - Amount: "123901.0129310", - NumAccounts: 8, - } - assert.Equal(t, shouldDiscardAsset(testAsset, true), true) - - testAsset = hProtocol.AssetStat{ - Amount: "123901.0129310", - NumAccounts: 12, - } - testAsset.Code = "REMOVE" - assert.Equal(t, shouldDiscardAsset(testAsset, true), true) - - testAsset = hProtocol.AssetStat{ - Amount: "123901.0129310", - NumAccounts: 100, - } - testAsset.Code = "SOMETHINGVALID" - testAsset.Links.Toml.Href = "" - assert.Equal(t, shouldDiscardAsset(testAsset, true), false) - - testAsset = hProtocol.AssetStat{ - Amount: "123901.0129310", - NumAccounts: 40, - } - testAsset.Code = "SOMETHINGVALID" - testAsset.Links.Toml.Href = "http://www.stellar.org/.well-known/stellar.toml" - assert.Equal(t, shouldDiscardAsset(testAsset, true), true) - - testAsset = hProtocol.AssetStat{ - Amount: "123901.0129310", - NumAccounts: 40, - } - testAsset.Code = "SOMETHINGVALID" - testAsset.Links.Toml.Href = "" - assert.Equal(t, shouldDiscardAsset(testAsset, true), true) - - testAsset = hProtocol.AssetStat{ - Amount: "123901.0129310", - NumAccounts: 40, - } - testAsset.Code = "SOMETHINGVALID" - testAsset.Links.Toml.Href = "https://www.stellar.org/.well-known/stellar.toml" - assert.Equal(t, shouldDiscardAsset(testAsset, true), false) -} - func TestDomainsMatch(t *testing.T) { tomlURL, _ := url.Parse("https://stellar.org/stellar.toml") orgURL, _ := url.Parse("https://stellar.org/") @@ -154,10 +91,7 @@ func TestProcessAsset_notCached(t *testing.T) { server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { fmt.Fprint(w, `SIGNING_KEY="not cached signing key"`) })) - asset := hProtocol.AssetStat{ - Amount: "123901.0129310", - NumAccounts: 100, - } + asset := hProtocol.AssetStat{} asset.Code = "SOMETHINGVALID" asset.Links.Toml.Href = server.URL tomlCache := &TOMLCache{} @@ -172,10 +106,7 @@ func TestProcessAsset_notCached(t *testing.T) { func TestProcessAsset_cached(t *testing.T) { logger := log.DefaultLogger - asset := hProtocol.AssetStat{ - Amount: "123901.0129310", - NumAccounts: 100, - } + asset := hProtocol.AssetStat{} asset.Code = "SOMETHINGVALID" asset.Links.Toml.Href = "url" tomlCache := &TOMLCache{} From 9d0e3fddc24edb7125a61a829653e76aec8d6d17 Mon Sep 17 00:00:00 2001 From: Karthik Iyer Date: Thu, 26 Sep 2024 23:34:22 -0700 Subject: [PATCH 03/11] Cleanup validAfter and validBefore --- protocols/horizon/main.go | 67 +++++++++---------- .../transaction_preconditions_test.go | 9 --- .../internal/resourceadapter/transaction.go | 4 -- .../resourceadapter/transaction_test.go | 2 - 4 files changed, 30 insertions(+), 52 deletions(-) diff --git a/protocols/horizon/main.go b/protocols/horizon/main.go index 72c4269f8e..b25c03eb63 100644 --- a/protocols/horizon/main.go +++ b/protocols/horizon/main.go @@ -175,16 +175,12 @@ type AssetStat struct { } `json:"_links"` base.Asset - PT string `json:"paging_token"` - ContractID string `json:"contract_id,omitempty"` - // Action needed in release: horizon-v3.0.0: deprecated field - //NumAccounts int32 `json:"num_accounts"` - NumClaimableBalances int32 `json:"num_claimable_balances"` - NumLiquidityPools int32 `json:"num_liquidity_pools"` - NumContracts int32 `json:"num_contracts"` - NumArchivedContracts int32 `json:"num_archived_contracts"` - // Action needed in release: horizon-v3.0.0: deprecated field - // Amount string `json:"amount"` + PT string `json:"paging_token"` + ContractID string `json:"contract_id,omitempty"` + NumClaimableBalances int32 `json:"num_claimable_balances"` + NumLiquidityPools int32 `json:"num_liquidity_pools"` + NumContracts int32 `json:"num_contracts"` + NumArchivedContracts int32 `json:"num_archived_contracts"` Accounts AssetStatAccounts `json:"accounts"` ClaimableBalancesAmount string `json:"claimable_balances_amount"` LiquidityPoolsAmount string `json:"liquidity_pools_amount"` @@ -509,33 +505,30 @@ type Transaction struct { // When TransactionSuccess is removed from the SDKs we can remove this HAL link Transaction hal.Link `json:"transaction"` } `json:"_links"` - ID string `json:"id"` - PT string `json:"paging_token"` - Successful bool `json:"successful"` - Hash string `json:"hash"` - Ledger int32 `json:"ledger"` - LedgerCloseTime time.Time `json:"created_at"` - Account string `json:"source_account"` - AccountMuxed string `json:"account_muxed,omitempty"` - AccountMuxedID uint64 `json:"account_muxed_id,omitempty,string"` - AccountSequence int64 `json:"source_account_sequence,string"` - FeeAccount string `json:"fee_account"` - FeeAccountMuxed string `json:"fee_account_muxed,omitempty"` - FeeAccountMuxedID uint64 `json:"fee_account_muxed_id,omitempty,string"` - FeeCharged int64 `json:"fee_charged,string"` - MaxFee int64 `json:"max_fee,string"` - OperationCount int32 `json:"operation_count"` - EnvelopeXdr string `json:"envelope_xdr"` - ResultXdr string `json:"result_xdr"` - ResultMetaXdr string `json:"result_meta_xdr,omitempty"` - FeeMetaXdr string `json:"fee_meta_xdr"` - MemoType string `json:"memo_type"` - MemoBytes string `json:"memo_bytes,omitempty"` - Memo string `json:"memo,omitempty"` - Signatures []string `json:"signatures"` - // Action needed in release: horizon-v3.0.0: remove valid_(after|before) - ValidAfter string `json:"valid_after,omitempty"` - ValidBefore string `json:"valid_before,omitempty"` + ID string `json:"id"` + PT string `json:"paging_token"` + Successful bool `json:"successful"` + Hash string `json:"hash"` + Ledger int32 `json:"ledger"` + LedgerCloseTime time.Time `json:"created_at"` + Account string `json:"source_account"` + AccountMuxed string `json:"account_muxed,omitempty"` + AccountMuxedID uint64 `json:"account_muxed_id,omitempty,string"` + AccountSequence int64 `json:"source_account_sequence,string"` + FeeAccount string `json:"fee_account"` + FeeAccountMuxed string `json:"fee_account_muxed,omitempty"` + FeeAccountMuxedID uint64 `json:"fee_account_muxed_id,omitempty,string"` + FeeCharged int64 `json:"fee_charged,string"` + MaxFee int64 `json:"max_fee,string"` + OperationCount int32 `json:"operation_count"` + EnvelopeXdr string `json:"envelope_xdr"` + ResultXdr string `json:"result_xdr"` + ResultMetaXdr string `json:"result_meta_xdr,omitempty"` + FeeMetaXdr string `json:"fee_meta_xdr"` + MemoType string `json:"memo_type"` + MemoBytes string `json:"memo_bytes,omitempty"` + Memo string `json:"memo,omitempty"` + Signatures []string `json:"signatures"` Preconditions *TransactionPreconditions `json:"preconditions,omitempty"` FeeBumpTransaction *FeeBumpTransaction `json:"fee_bump_transaction,omitempty"` InnerTransaction *InnerTransaction `json:"inner_transaction,omitempty"` diff --git a/services/horizon/internal/integration/transaction_preconditions_test.go b/services/horizon/internal/integration/transaction_preconditions_test.go index e3aff9e0da..4bf7a6acb8 100644 --- a/services/horizon/internal/integration/transaction_preconditions_test.go +++ b/services/horizon/internal/integration/transaction_preconditions_test.go @@ -49,20 +49,11 @@ func TestTransactionPreconditionsTimeBounds(t *testing.T) { txHistory, err := itest.Client().TransactionDetail(tx.Hash) assert.NoError(t, err) - // Check that the deprecated string datetime fields match the new UNIX - // timestamp fields. - deprecatedHistoryMinTime, err := time.Parse(time.RFC3339, txHistory.ValidAfter) - assert.NoError(t, err) - deprecatedHistoryMaxTime, err := time.Parse(time.RFC3339, txHistory.ValidBefore) - assert.NoError(t, err) - historyMinTime, err := strconv.ParseInt(txHistory.Preconditions.TimeBounds.MinTime, 10, 64) assert.NoError(t, err) historyMaxTime, err := strconv.ParseInt(txHistory.Preconditions.TimeBounds.MaxTime, 10, 64) assert.NoError(t, err) - assert.Equal(t, historyMinTime, deprecatedHistoryMinTime.UTC().Unix()) - assert.Equal(t, historyMaxTime, deprecatedHistoryMaxTime.UTC().Unix()) assert.Equal(t, historyMinTime, txParams.Preconditions.TimeBounds.MinTime) assert.Equal(t, historyMaxTime, txParams.Preconditions.TimeBounds.MaxTime) } diff --git a/services/horizon/internal/resourceadapter/transaction.go b/services/horizon/internal/resourceadapter/transaction.go index f458830c2d..01d21f3977 100644 --- a/services/horizon/internal/resourceadapter/transaction.go +++ b/services/horizon/internal/resourceadapter/transaction.go @@ -66,10 +66,6 @@ func PopulateTransaction( dest.Preconditions = &protocol.TransactionPreconditions{} if !row.TimeBounds.Null { - // Action needed in release: horizon-v3.0.0: remove ValidBefore and ValidAfter - dest.ValidBefore = timeString(row.TimeBounds.Upper) - dest.ValidAfter = timeString(row.TimeBounds.Lower) - dest.Preconditions.TimeBounds = &protocol.TransactionPreconditionsTimebounds{ MaxTime: timestampString(row.TimeBounds.Upper), MinTime: timestampString(row.TimeBounds.Lower), diff --git a/services/horizon/internal/resourceadapter/transaction_test.go b/services/horizon/internal/resourceadapter/transaction_test.go index 694fc885fb..8ce0fe0271 100644 --- a/services/horizon/internal/resourceadapter/transaction_test.go +++ b/services/horizon/internal/resourceadapter/transaction_test.go @@ -223,8 +223,6 @@ func TestPopulateTransaction_Preconditions(t *testing.T) { assert.NoError(t, PopulateTransaction(ctx, row.TransactionHash, &dest, row, false)) assert.NotEmpty(t, dest.ResultMetaXdr) p := dest.Preconditions - assert.Equal(t, validAfter.Format(time.RFC3339), dest.ValidAfter) - assert.Equal(t, validBefore.Format(time.RFC3339), dest.ValidBefore) assert.Equal(t, fmt.Sprint(validAfter.Unix()), p.TimeBounds.MinTime) assert.Equal(t, fmt.Sprint(validBefore.Unix()), p.TimeBounds.MaxTime) assert.Equal(t, minLedger, p.LedgerBounds.MinLedger) From 86b573ee800326fc027619a619cfbe3ac4ca832c Mon Sep 17 00:00:00 2001 From: Karthik Iyer Date: Fri, 27 Sep 2024 00:00:45 -0700 Subject: [PATCH 04/11] Remove unused fn --- .../horizon/internal/resourceadapter/transaction.go | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/services/horizon/internal/resourceadapter/transaction.go b/services/horizon/internal/resourceadapter/transaction.go index 01d21f3977..4120c5f564 100644 --- a/services/horizon/internal/resourceadapter/transaction.go +++ b/services/horizon/internal/resourceadapter/transaction.go @@ -4,10 +4,8 @@ import ( "context" "encoding/base64" "fmt" - "strconv" - "time" - "github.com/guregu/null" + "strconv" horizonContext "github.com/stellar/go/services/horizon/internal/context" "github.com/stellar/go/xdr" @@ -153,14 +151,6 @@ func memoBytes(envelopeXDR string) (string, error) { return base64.StdEncoding.EncodeToString([]byte(memo)), nil } -func timeString(in null.Int) string { - if !in.Valid { - return "" - } - - return time.Unix(in.Int64, 0).UTC().Format(time.RFC3339) -} - func timestampString(in null.Int) string { if !in.Valid { return "" From f295e4d3a320ca68c28545760ec3965606b63e13 Mon Sep 17 00:00:00 2001 From: Karthik Iyer Date: Mon, 30 Sep 2024 10:53:06 -0700 Subject: [PATCH 05/11] Update fixture --- .../ticker/internal/scraper/asset_scraper.go | 11 ++-- .../internal/scraper/asset_scraper_test.go | 52 +++++++++++++++++++ 2 files changed, 57 insertions(+), 6 deletions(-) diff --git a/services/ticker/internal/scraper/asset_scraper.go b/services/ticker/internal/scraper/asset_scraper.go index c4c6d009cc..cd6c6ed9c9 100644 --- a/services/ticker/internal/scraper/asset_scraper.go +++ b/services/ticker/internal/scraper/asset_scraper.go @@ -23,17 +23,16 @@ import ( // shouldDiscardAsset maps the criteria for discarding an asset from the asset index func shouldDiscardAsset(asset hProtocol.AssetStat, shouldValidateTOML bool) bool { - amt, _ := AddStringsToSum(asset.Balances.AuthorizedToMaintainLiabilities + asset.Balances.Unauthorized + asset.Balances.Authorized) - amount := strconv.FormatFloat(amt, 'f', -1, 64) - if amount == "" { + if asset.Balances.Authorized == "" { return true } - if amt == 0.0 { + f, _ := strconv.ParseFloat(asset.Balances.Authorized, 64) + if f == 0.0 { return true } // [StellarX Ticker]: assets need at least some adoption to show up - if asset.Accounts.Unauthorized+asset.Accounts.Authorized+asset.Accounts.AuthorizedToMaintainLiabilities < 10 { + if asset.Accounts.Authorized < 10 { return true } if asset.Code == "REMOVE" { @@ -41,7 +40,7 @@ func shouldDiscardAsset(asset hProtocol.AssetStat, shouldValidateTOML bool) bool } // [StellarX Ticker]: assets with at least 100 accounts get a pass, // even with toml issues - if asset.Accounts.Unauthorized+asset.Accounts.Authorized+asset.Accounts.AuthorizedToMaintainLiabilities >= 100 { + if asset.Accounts.Authorized >= 100 { return false } diff --git a/services/ticker/internal/scraper/asset_scraper_test.go b/services/ticker/internal/scraper/asset_scraper_test.go index 96918c6c83..4582aab2bf 100644 --- a/services/ticker/internal/scraper/asset_scraper_test.go +++ b/services/ticker/internal/scraper/asset_scraper_test.go @@ -14,6 +14,58 @@ import ( "github.com/stretchr/testify/require" ) +func TestShouldDiscardAsset(t *testing.T) { + testAsset := hProtocol.AssetStat{} + assert.Equal(t, shouldDiscardAsset(testAsset, true), true) + + testAsset = hProtocol.AssetStat{} + testAsset.Balances.Authorized = "" + assert.Equal(t, shouldDiscardAsset(testAsset, true), true) + + testAsset = hProtocol.AssetStat{} + testAsset.Balances.Authorized = "0" + assert.Equal(t, shouldDiscardAsset(testAsset, true), true) + + testAsset = hProtocol.AssetStat{} + testAsset.Balances.Authorized = "12345.67" + testAsset.Accounts.Authorized = 0 + assert.Equal(t, shouldDiscardAsset(testAsset, true), true) + + testAsset = hProtocol.AssetStat{} + testAsset.Balances.Authorized = "12345.67" + testAsset.Accounts.Authorized = 12 + testAsset.Code = "REMOVE" + assert.Equal(t, shouldDiscardAsset(testAsset, true), true) + + testAsset = hProtocol.AssetStat{} + testAsset.Balances.Authorized = "12345.67" + testAsset.Accounts.Authorized = 100 + testAsset.Code = "SOMETHINGVALID" + testAsset.Links.Toml.Href = "" + assert.Equal(t, shouldDiscardAsset(testAsset, true), false) + + testAsset = hProtocol.AssetStat{} + testAsset.Balances.Authorized = "12345.67" + testAsset.Accounts.Authorized = 40 + testAsset.Code = "SOMETHINGVALID" + testAsset.Links.Toml.Href = "http://www.stellar.org/.well-known/stellar.toml" + assert.Equal(t, shouldDiscardAsset(testAsset, true), true) + + testAsset = hProtocol.AssetStat{} + testAsset.Balances.Authorized = "12345.67" + testAsset.Accounts.Authorized = 40 + testAsset.Code = "SOMETHINGVALID" + testAsset.Links.Toml.Href = "" + assert.Equal(t, shouldDiscardAsset(testAsset, true), true) + + testAsset = hProtocol.AssetStat{} + testAsset.Balances.Authorized = "12345.67" + testAsset.Accounts.Authorized = 40 + testAsset.Code = "SOMETHINGVALID" + testAsset.Links.Toml.Href = "https://www.stellar.org/.well-known/stellar.toml" + assert.Equal(t, shouldDiscardAsset(testAsset, true), false) +} + func TestDomainsMatch(t *testing.T) { tomlURL, _ := url.Parse("https://stellar.org/stellar.toml") orgURL, _ := url.Parse("https://stellar.org/") From b4d4edc30dad60b7fb44fd4ddbce2649e49363ec Mon Sep 17 00:00:00 2001 From: Karthik Iyer Date: Mon, 30 Sep 2024 14:06:55 -0700 Subject: [PATCH 06/11] SQL to drop columns for protocol 22 release --- ...accounts_and_amount_cols_from_expat_asset_stats.sql | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 services/horizon/internal/db2/schema/migrations/68_remove_accounts_num_accounts_and_amount_cols_from_expat_asset_stats.sql diff --git a/services/horizon/internal/db2/schema/migrations/68_remove_accounts_num_accounts_and_amount_cols_from_expat_asset_stats.sql b/services/horizon/internal/db2/schema/migrations/68_remove_accounts_num_accounts_and_amount_cols_from_expat_asset_stats.sql new file mode 100644 index 0000000000..9c894d4417 --- /dev/null +++ b/services/horizon/internal/db2/schema/migrations/68_remove_accounts_num_accounts_and_amount_cols_from_expat_asset_stats.sql @@ -0,0 +1,10 @@ +-- + migrate Up + +ALTER TABLE exp_asset_stats + DROP COLUMN num_accounts, + DROP COLUMN amount; + +-- + migrate Down +ALTER TABLE exp_asset_stats + ADD COLUMN num_accounts INTEGER DEFAULT 0, + ADD COLUMN amount VARCHAR DEFAULT ''; From 102fe5f37e1a991796a7f93496e5be4e539698e4 Mon Sep 17 00:00:00 2001 From: Karthik Iyer Date: Mon, 30 Sep 2024 14:20:33 -0700 Subject: [PATCH 07/11] Remove amount and num_accounts from ExpAssetStats table and test fixtures --- .../horizon/internal/actions/asset_test.go | 10 --- .../internal/db2/history/asset_stats.go | 2 - .../internal/db2/history/asset_stats_test.go | 46 ----------- services/horizon/internal/db2/history/main.go | 6 +- .../processors/asset_stats_processor.go | 6 -- .../processors/asset_stats_processor_test.go | 78 ------------------- .../ingest/processors/asset_stats_set.go | 2 - .../ingest/processors/asset_stats_set_test.go | 12 --- .../ingest/verify_range_state_test.go | 3 - .../horizon/internal/integration/sac_test.go | 4 +- .../resourceadapter/asset_stat_test.go | 2 - 11 files changed, 2 insertions(+), 169 deletions(-) diff --git a/services/horizon/internal/actions/asset_test.go b/services/horizon/internal/actions/asset_test.go index 68b56d94b2..6547a6b853 100644 --- a/services/horizon/internal/actions/asset_test.go +++ b/services/horizon/internal/actions/asset_test.go @@ -139,8 +139,6 @@ func TestAssetStats(t *testing.T) { ClaimableBalances: "10", LiquidityPools: "20", }, - Amount: "1", - NumAccounts: 2, } usdAssetStatResponse := horizon.AssetStat{ Accounts: horizon.AssetStatAccounts{ @@ -185,8 +183,6 @@ func TestAssetStats(t *testing.T) { ClaimableBalances: "0", LiquidityPools: "0", }, - Amount: "23", - NumAccounts: 1, } etherAssetStatResponse := horizon.AssetStat{ Accounts: horizon.AssetStatAccounts{ @@ -230,8 +226,6 @@ func TestAssetStats(t *testing.T) { ClaimableBalances: "0", LiquidityPools: "0", }, - Amount: "1", - NumAccounts: 2, } otherUSDAssetStatResponse := horizon.AssetStat{ Accounts: horizon.AssetStatAccounts{ @@ -277,8 +271,6 @@ func TestAssetStats(t *testing.T) { ClaimableBalances: "0", LiquidityPools: "0", }, - Amount: "111", - NumAccounts: 3, } eurAssetStatResponse := horizon.AssetStat{ Accounts: horizon.AssetStatAccounts{ @@ -445,8 +437,6 @@ func TestAssetStatsIssuerDoesNotExist(t *testing.T) { Unauthorized: "3", ClaimableBalances: "0", }, - Amount: "1", - NumAccounts: 2, } numChanged, err := q.InsertAssetStat(tt.Ctx, usdAssetStat) tt.Assert.NoError(err) diff --git a/services/horizon/internal/db2/history/asset_stats.go b/services/horizon/internal/db2/history/asset_stats.go index 622619680b..12e910d533 100644 --- a/services/horizon/internal/db2/history/asset_stats.go +++ b/services/horizon/internal/db2/history/asset_stats.go @@ -20,8 +20,6 @@ func assetStatToMap(assetStat ExpAssetStat) map[string]interface{} { "asset_issuer": assetStat.AssetIssuer, "accounts": assetStat.Accounts, "balances": assetStat.Balances, - "amount": assetStat.Amount, - "num_accounts": assetStat.NumAccounts, "contract_id": assetStat.ContractID, } } diff --git a/services/horizon/internal/db2/history/asset_stats_test.go b/services/horizon/internal/db2/history/asset_stats_test.go index a8352e4d97..520b480fd6 100644 --- a/services/horizon/internal/db2/history/asset_stats_test.go +++ b/services/horizon/internal/db2/history/asset_stats_test.go @@ -40,8 +40,6 @@ func TestAssetStatContracts(t *testing.T) { LiquidityPools: "0", Unauthorized: "0", }, - Amount: "0", - NumAccounts: 0, }, { AssetType: xdr.AssetTypeAssetTypeCreditAlphanum12, @@ -59,8 +57,6 @@ func TestAssetStatContracts(t *testing.T) { ClaimableBalances: "4", LiquidityPools: "5", }, - Amount: "23", - NumAccounts: 1, }, { AssetType: xdr.AssetTypeAssetTypeCreditAlphanum4, @@ -78,8 +74,6 @@ func TestAssetStatContracts(t *testing.T) { ClaimableBalances: "4", LiquidityPools: "5", }, - Amount: "1", - NumAccounts: 2, }, } var contractID [32]byte @@ -219,8 +213,6 @@ func TestInsertAssetStats(t *testing.T) { ClaimableBalances: "4", LiquidityPools: "5", }, - Amount: "1", - NumAccounts: 2, }, { AssetType: xdr.AssetTypeAssetTypeCreditAlphanum12, @@ -238,8 +230,6 @@ func TestInsertAssetStats(t *testing.T) { ClaimableBalances: "4", LiquidityPools: "5", }, - Amount: "23", - NumAccounts: 1, }, } tt.Assert.NoError(q.InsertAssetStats(tt.Ctx, assetStats)) @@ -276,8 +266,6 @@ func TestInsertAssetStat(t *testing.T) { ClaimableBalances: "4", LiquidityPools: "5", }, - Amount: "1", - NumAccounts: 2, }, { AssetType: xdr.AssetTypeAssetTypeCreditAlphanum12, @@ -295,8 +283,6 @@ func TestInsertAssetStat(t *testing.T) { ClaimableBalances: "4", LiquidityPools: "5", }, - Amount: "23", - NumAccounts: 1, }, } @@ -333,8 +319,6 @@ func TestInsertAssetStatAlreadyExistsError(t *testing.T) { ClaimableBalances: "4", LiquidityPools: "5", }, - Amount: "1", - NumAccounts: 2, } numChanged, err := q.InsertAssetStat(tt.Ctx, assetStat) @@ -344,18 +328,6 @@ func TestInsertAssetStatAlreadyExistsError(t *testing.T) { numChanged, err = q.InsertAssetStat(tt.Ctx, assetStat) tt.Assert.Error(err) tt.Assert.Equal(numChanged, int64(0)) - - assetStat.NumAccounts = 4 - assetStat.Amount = "3" - numChanged, err = q.InsertAssetStat(tt.Ctx, assetStat) - tt.Assert.Error(err) - tt.Assert.Equal(numChanged, int64(0)) - - assetStat.NumAccounts = 2 - assetStat.Amount = "1" - got, err := q.GetAssetStat(tt.Ctx, assetStat.AssetType, assetStat.AssetCode, assetStat.AssetIssuer) - tt.Assert.NoError(err) - tt.Assert.Equal(got, assetStat) } func TestUpdateAssetStatDoesNotExistsError(t *testing.T) { @@ -380,8 +352,6 @@ func TestUpdateAssetStatDoesNotExistsError(t *testing.T) { ClaimableBalances: "4", LiquidityPools: "5", }, - Amount: "1", - NumAccounts: 2, } numChanged, err := q.UpdateAssetStat(tt.Ctx, assetStat) @@ -415,8 +385,6 @@ func TestUpdateStat(t *testing.T) { ClaimableBalances: "4", LiquidityPools: "5", }, - Amount: "1", - NumAccounts: 2, } numChanged, err := q.InsertAssetStat(tt.Ctx, assetStat) @@ -427,8 +395,6 @@ func TestUpdateStat(t *testing.T) { tt.Assert.NoError(err) tt.Assert.Equal(got, assetStat) - assetStat.NumAccounts = 50 - assetStat.Amount = "23" assetStat.SetContractID([32]byte{23}) numChanged, err = q.UpdateAssetStat(tt.Ctx, assetStat) @@ -462,8 +428,6 @@ func TestGetAssetStatDoesNotExist(t *testing.T) { ClaimableBalances: "4", LiquidityPools: "5", }, - Amount: "1", - NumAccounts: 2, } _, err := q.GetAssetStat(tt.Ctx, assetStat.AssetType, assetStat.AssetCode, assetStat.AssetIssuer) @@ -493,8 +457,6 @@ func TestRemoveAssetStat(t *testing.T) { ClaimableBalances: "4", LiquidityPools: "5", }, - Amount: "1", - NumAccounts: 2, } numChanged, err := q.RemoveAssetStat(tt.Ctx, @@ -628,8 +590,6 @@ func TestGetAssetStatsFiltersAndCursor(t *testing.T) { ClaimableBalances: "0", LiquidityPools: "0", }, - Amount: "1", - NumAccounts: 2, }, Contracts: zero, } @@ -650,8 +610,6 @@ func TestGetAssetStatsFiltersAndCursor(t *testing.T) { ClaimableBalances: "0", LiquidityPools: "0", }, - Amount: "23", - NumAccounts: 1, }, Contracts: zero, } @@ -672,8 +630,6 @@ func TestGetAssetStatsFiltersAndCursor(t *testing.T) { ClaimableBalances: "0", LiquidityPools: "0", }, - Amount: "1", - NumAccounts: 2, }, Contracts: zero, } @@ -694,8 +650,6 @@ func TestGetAssetStatsFiltersAndCursor(t *testing.T) { ClaimableBalances: "1", LiquidityPools: "2", }, - Amount: "111", - NumAccounts: 3, }, Contracts: ContractStat{ ActiveBalance: "120", diff --git a/services/horizon/internal/db2/history/main.go b/services/horizon/internal/db2/history/main.go index e9d8ffb185..f49d1129c5 100644 --- a/services/horizon/internal/db2/history/main.go +++ b/services/horizon/internal/db2/history/main.go @@ -427,8 +427,6 @@ type ExpAssetStat struct { AssetIssuer string `db:"asset_issuer"` Accounts ExpAssetStatAccounts `db:"accounts"` Balances ExpAssetStatBalances `db:"balances"` - Amount string `db:"amount"` - NumAccounts int32 `db:"num_accounts"` ContractID *[]byte `db:"contract_id"` // make sure to update Equals() when adding new fields to ExpAssetStat } @@ -481,9 +479,7 @@ func (e *ExpAssetStat) Equals(o ExpAssetStat) bool { e.AssetCode == o.AssetCode && e.AssetIssuer == o.AssetIssuer && e.Accounts == o.Accounts && - e.Balances == o.Balances && - e.Amount == o.Amount && - e.NumAccounts == o.NumAccounts + e.Balances == o.Balances } func (e *ExpAssetStat) GetContractID() ([32]byte, bool) { diff --git a/services/horizon/internal/ingest/processors/asset_stats_processor.go b/services/horizon/internal/ingest/processors/asset_stats_processor.go index 6ae83c3a3c..7e76b509c2 100644 --- a/services/horizon/internal/ingest/processors/asset_stats_processor.go +++ b/services/horizon/internal/ingest/processors/asset_stats_processor.go @@ -305,8 +305,6 @@ func IncludeContractIDsInAssetStats( AssetIssuer: assetIssuer, Accounts: history.ExpAssetStatAccounts{}, Balances: newAssetStatBalance().ConvertToHistoryObject(), - Amount: "0", - NumAccounts: 0, } row.SetContractID(contractID) assetStatsDeltas = append(assetStatsDeltas, row) @@ -456,8 +454,6 @@ func (p *AssetStatsProcessor) updateAssetStats( AssetIssuer: delta.AssetIssuer, Accounts: statAccounts, Balances: statBalances.ConvertToHistoryObject(), - Amount: statBalances.Authorized.String(), - NumAccounts: statAccounts.Authorized, ContractID: delta.ContractID, }) if err != nil { @@ -549,8 +545,6 @@ func (p *AssetStatsProcessor) updateContractID( AssetIssuer: assetIssuer, Accounts: history.ExpAssetStatAccounts{}, Balances: newAssetStatBalance().ConvertToHistoryObject(), - Amount: "0", - NumAccounts: 0, } row.SetContractID(contractID) diff --git a/services/horizon/internal/ingest/processors/asset_stats_processor_test.go b/services/horizon/internal/ingest/processors/asset_stats_processor_test.go index e8080773e8..ea267f6d3e 100644 --- a/services/horizon/internal/ingest/processors/asset_stats_processor_test.go +++ b/services/horizon/internal/ingest/processors/asset_stats_processor_test.go @@ -74,8 +74,6 @@ func (s *AssetStatsProcessorTestSuiteState) TestCreateTrustLine() { ClaimableBalances: "0", LiquidityPools: "0", }, - Amount: "0", - NumAccounts: 1, }, }).Return(nil).Once() } @@ -141,8 +139,6 @@ func (s *AssetStatsProcessorTestSuiteState) TestCreateTrustLineWithClawback() { ClaimableBalances: "0", LiquidityPools: "0", }, - Amount: "0", - NumAccounts: 1, }, }).Return(nil).Once() } @@ -179,8 +175,6 @@ func (s *AssetStatsProcessorTestSuiteState) TestCreateTrustLineUnauthorized() { ClaimableBalances: "0", LiquidityPools: "0", }, - Amount: "0", - NumAccounts: 0, }, }).Return(nil).Once() } @@ -320,8 +314,6 @@ func (s *AssetStatsProcessorTestSuiteLedger) TestInsertClaimableBalance() { ClaimableBalances: "24", LiquidityPools: "0", }, - Amount: "0", - NumAccounts: 0, }).Return(int64(1), nil).Once() s.mockQ.On("GetAssetStat", s.ctx, @@ -343,8 +335,6 @@ func (s *AssetStatsProcessorTestSuiteLedger) TestInsertClaimableBalance() { ClaimableBalances: "46", LiquidityPools: "0", }, - Amount: "0", - NumAccounts: 0, }).Return(int64(1), nil).Once() s.mockQ.On("RemoveContractAssetBalances", s.ctx, []xdr.Hash(nil)). @@ -487,8 +477,6 @@ func (s *AssetStatsProcessorTestSuiteLedger) TestInsertTrustLine() { ClaimableBalances: "0", LiquidityPools: "0", }, - Amount: "10", - NumAccounts: 1, }).Return(int64(1), nil).Once() s.mockQ.On("GetAssetStat", s.ctx, @@ -510,8 +498,6 @@ func (s *AssetStatsProcessorTestSuiteLedger) TestInsertTrustLine() { ClaimableBalances: "0", LiquidityPools: "0", }, - Amount: "0", - NumAccounts: 0, }).Return(int64(1), nil).Once() s.mockQ.On("RemoveContractAssetBalances", s.ctx, []xdr.Hash(nil)). @@ -599,8 +585,6 @@ func (s *AssetStatsProcessorTestSuiteLedger) TestInsertContractID() { ClaimableBalances: "0", LiquidityPools: "0", }, - Amount: "0", - NumAccounts: 1, } eurAssetStat.SetContractID(eurID) s.mockQ.On("InsertAssetStat", s.ctx, mock.MatchedBy(func(assetStat history.ExpAssetStat) bool { @@ -625,8 +609,6 @@ func (s *AssetStatsProcessorTestSuiteLedger) TestInsertContractID() { ClaimableBalances: "0", LiquidityPools: "0", }, - Amount: "0", - NumAccounts: 0, } usdAssetStat.SetContractID(usdID) s.mockQ.On("InsertAssetStat", s.ctx, mock.MatchedBy(func(assetStat history.ExpAssetStat) bool { @@ -932,8 +914,6 @@ func (s *AssetStatsProcessorTestSuiteLedger) TestInsertContractIDWithBalance() { ClaimableBalances: "0", LiquidityPools: "0", }, - Amount: "0", - NumAccounts: 1, } eurAssetStat.SetContractID(eurID) s.mockQ.On("InsertAssetStat", s.ctx, mock.MatchedBy(func(assetStat history.ExpAssetStat) bool { @@ -974,8 +954,6 @@ func (s *AssetStatsProcessorTestSuiteLedger) TestInsertContractIDWithBalance() { ClaimableBalances: "0", LiquidityPools: "0", }, - Amount: "0", - NumAccounts: 0, } usdAssetStat.SetContractID(usdID) s.mockQ.On("InsertAssetStat", s.ctx, mock.MatchedBy(func(assetStat history.ExpAssetStat) bool { @@ -1097,8 +1075,6 @@ func (s *AssetStatsProcessorTestSuiteLedger) TestInsertClaimableBalanceAndTrustl ClaimableBalances: "12", LiquidityPools: "100", }, - Amount: "9", - NumAccounts: 1, }).Return(int64(1), nil).Once() s.mockQ.On("RemoveContractAssetBalances", s.ctx, []xdr.Hash(nil)). @@ -1148,8 +1124,6 @@ func (s *AssetStatsProcessorTestSuiteLedger) TestUpdateContractID() { ClaimableBalances: "0", LiquidityPools: "0", }, - Amount: "100", - NumAccounts: 1, }, nil).Once() eurAssetStat := history.ExpAssetStat{ @@ -1164,8 +1138,6 @@ func (s *AssetStatsProcessorTestSuiteLedger) TestUpdateContractID() { ClaimableBalances: "0", LiquidityPools: "0", }, - Amount: "100", - NumAccounts: 1, } eurAssetStat.SetContractID(eurID) s.mockQ.On("UpdateAssetStat", s.ctx, mock.MatchedBy(func(assetStat history.ExpAssetStat) bool { @@ -1309,8 +1281,6 @@ func (s *AssetStatsProcessorTestSuiteLedger) TestUpdateContractIDWithBalance() { ClaimableBalances: "0", LiquidityPools: "0", }, - Amount: "100", - NumAccounts: 1, }, nil).Once() eurAssetStat := history.ExpAssetStat{ @@ -1327,8 +1297,6 @@ func (s *AssetStatsProcessorTestSuiteLedger) TestUpdateContractIDWithBalance() { ClaimableBalances: "0", LiquidityPools: "0", }, - Amount: "100", - NumAccounts: 1, } eurAssetStat.SetContractID(eurID) s.mockQ.On("UpdateAssetStat", s.ctx, mock.MatchedBy(func(assetStat history.ExpAssetStat) bool { @@ -1406,8 +1374,6 @@ func (s *AssetStatsProcessorTestSuiteLedger) TestUpdateContractIDError() { ClaimableBalances: "0", LiquidityPools: "0", }, - Amount: "100", - NumAccounts: 1, } eurAssetStat.SetContractID(usdID) s.mockQ.On("GetAssetStat", s.ctx, @@ -1485,8 +1451,6 @@ func (s *AssetStatsProcessorTestSuiteLedger) TestUpdateTrustlineAndContractIDErr ClaimableBalances: "0", LiquidityPools: "0", }, - Amount: "100", - NumAccounts: 1, } eurAssetStat.SetContractID(usdID) s.mockQ.On("GetAssetStat", s.ctx, @@ -1588,8 +1552,6 @@ func (s *AssetStatsProcessorTestSuiteLedger) TestUpdateTrustlineAndRemoveContrac ClaimableBalances: "0", LiquidityPools: "0", }, - Amount: "100", - NumAccounts: 1, } s.mockQ.On("GetAssetStat", s.ctx, xdr.AssetTypeAssetTypeCreditAlphanum4, @@ -1654,8 +1616,6 @@ func (s *AssetStatsProcessorTestSuiteLedger) TestUpdateTrustLine() { ClaimableBalances: "0", LiquidityPools: "0", }, - Amount: "100", - NumAccounts: 1, }, nil).Once() s.mockQ.On("UpdateAssetStat", s.ctx, history.ExpAssetStat{ AssetType: xdr.AssetTypeAssetTypeCreditAlphanum4, @@ -1669,8 +1629,6 @@ func (s *AssetStatsProcessorTestSuiteLedger) TestUpdateTrustLine() { ClaimableBalances: "0", LiquidityPools: "0", }, - Amount: "110", - NumAccounts: 1, }).Return(int64(1), nil).Once() s.mockQ.On("RemoveContractAssetBalances", s.ctx, []xdr.Hash(nil)). @@ -1805,8 +1763,6 @@ func (s *AssetStatsProcessorTestSuiteLedger) TestUpdateTrustLineAuthorization() ClaimableBalances: "0", LiquidityPools: "0", }, - Amount: "0", - NumAccounts: 0, }, nil).Once() s.mockQ.On("UpdateAssetStat", s.ctx, history.ExpAssetStat{ AssetType: xdr.AssetTypeAssetTypeCreditAlphanum4, @@ -1822,8 +1778,6 @@ func (s *AssetStatsProcessorTestSuiteLedger) TestUpdateTrustLineAuthorization() ClaimableBalances: "0", LiquidityPools: "0", }, - Amount: "10", - NumAccounts: 1, }).Return(int64(1), nil).Once() s.mockQ.On("GetAssetStat", s.ctx, @@ -1844,8 +1798,6 @@ func (s *AssetStatsProcessorTestSuiteLedger) TestUpdateTrustLineAuthorization() ClaimableBalances: "0", LiquidityPools: "0", }, - Amount: "100", - NumAccounts: 1, }, nil).Once() s.mockQ.On("UpdateAssetStat", s.ctx, history.ExpAssetStat{ AssetType: xdr.AssetTypeAssetTypeCreditAlphanum4, @@ -1861,8 +1813,6 @@ func (s *AssetStatsProcessorTestSuiteLedger) TestUpdateTrustLineAuthorization() ClaimableBalances: "0", LiquidityPools: "0", }, - Amount: "0", - NumAccounts: 0, }).Return(int64(1), nil).Once() s.mockQ.On("GetAssetStat", s.ctx, @@ -1883,8 +1833,6 @@ func (s *AssetStatsProcessorTestSuiteLedger) TestUpdateTrustLineAuthorization() ClaimableBalances: "0", LiquidityPools: "0", }, - Amount: "100", - NumAccounts: 1, }, nil).Once() s.mockQ.On("UpdateAssetStat", s.ctx, history.ExpAssetStat{ AssetType: xdr.AssetTypeAssetTypeCreditAlphanum4, @@ -1900,8 +1848,6 @@ func (s *AssetStatsProcessorTestSuiteLedger) TestUpdateTrustLineAuthorization() ClaimableBalances: "0", LiquidityPools: "0", }, - Amount: "0", - NumAccounts: 0, }).Return(int64(1), nil).Once() s.mockQ.On("RemoveContractAssetBalances", s.ctx, []xdr.Hash(nil)). @@ -1978,8 +1924,6 @@ func (s *AssetStatsProcessorTestSuiteLedger) TestRemoveClaimableBalance() { ClaimableBalances: "12", LiquidityPools: "0", }, - Amount: "0", - NumAccounts: 0, }, nil).Once() s.mockQ.On("RemoveAssetStat", s.ctx, xdr.AssetTypeAssetTypeCreditAlphanum4, @@ -2006,8 +1950,6 @@ func (s *AssetStatsProcessorTestSuiteLedger) TestRemoveClaimableBalance() { ClaimableBalances: "21", LiquidityPools: "0", }, - Amount: "0", - NumAccounts: 0, }, nil).Once() s.mockQ.On("UpdateAssetStat", s.ctx, history.ExpAssetStat{ AssetType: xdr.AssetTypeAssetTypeCreditAlphanum4, @@ -2021,8 +1963,6 @@ func (s *AssetStatsProcessorTestSuiteLedger) TestRemoveClaimableBalance() { ClaimableBalances: "0", LiquidityPools: "0", }, - Amount: "0", - NumAccounts: 0, }).Return(int64(1), nil).Once() s.mockQ.On("RemoveContractAssetBalances", s.ctx, []xdr.Hash(nil)). @@ -2094,8 +2034,6 @@ func (s *AssetStatsProcessorTestSuiteLedger) TestRemoveTrustLine() { ClaimableBalances: "0", LiquidityPools: "0", }, - Amount: "0", - NumAccounts: 1, }, nil).Once() s.mockQ.On("RemoveAssetStat", s.ctx, xdr.AssetTypeAssetTypeCreditAlphanum4, @@ -2121,8 +2059,6 @@ func (s *AssetStatsProcessorTestSuiteLedger) TestRemoveTrustLine() { ClaimableBalances: "0", LiquidityPools: "0", }, - Amount: "0", - NumAccounts: 0, }, nil).Once() s.mockQ.On("RemoveAssetStat", s.ctx, xdr.AssetTypeAssetTypeCreditAlphanum4, @@ -2173,8 +2109,6 @@ func (s *AssetStatsProcessorTestSuiteLedger) TestRemoveContractID() { ClaimableBalances: "0", LiquidityPools: "0", }, - Amount: "100", - NumAccounts: 1, } eurAssetStat.SetContractID(eurID) s.mockQ.On("GetAssetStatByContract", s.ctx, xdr.Hash(eurID)). @@ -2260,8 +2194,6 @@ func (s *AssetStatsProcessorTestSuiteLedger) TestUpdateTrustlineAndRemoveContrac ClaimableBalances: "0", LiquidityPools: "0", }, - Amount: "100", - NumAccounts: 1, } eurAssetStat.SetContractID(eurID) s.mockQ.On("GetAssetStat", s.ctx, @@ -2282,8 +2214,6 @@ func (s *AssetStatsProcessorTestSuiteLedger) TestUpdateTrustlineAndRemoveContrac ClaimableBalances: "0", LiquidityPools: "0", }, - Amount: "110", - NumAccounts: 1, } s.mockQ.On("UpdateAssetStat", s.ctx, mock.MatchedBy(func(assetStat history.ExpAssetStat) bool { return eurAssetStat.Equals(assetStat) @@ -2332,8 +2262,6 @@ func (s *AssetStatsProcessorTestSuiteLedger) TestRemoveContractIDFromZeroRow() { ClaimableBalances: "0", LiquidityPools: "0", }, - Amount: "0", - NumAccounts: 0, } eurAssetStat.SetContractID(eurID) s.mockQ.On("GetAssetStatByContract", s.ctx, xdr.Hash(eurID)). @@ -2432,8 +2360,6 @@ func (s *AssetStatsProcessorTestSuiteLedger) TestRemoveContractIDAndBalanceZeroR ClaimableBalances: "0", LiquidityPools: "0", }, - Amount: "0", - NumAccounts: 0, } eurAssetStat.SetContractID(eurID) s.mockQ.On("GetAssetStatByContract", s.ctx, xdr.Hash(eurID)). @@ -2524,8 +2450,6 @@ func (s *AssetStatsProcessorTestSuiteLedger) TestRemoveContractIDAndRow() { ClaimableBalances: "0", LiquidityPools: "0", }, - Amount: "0", - NumAccounts: 1, } eurAssetStat.SetContractID(eurID) s.mockQ.On("GetAssetStat", s.ctx, @@ -2621,8 +2545,6 @@ func (s *AssetStatsProcessorTestSuiteLedger) TestProcessUpgradeChange() { ClaimableBalances: "0", LiquidityPools: "0", }, - Amount: "10", - NumAccounts: 1, }).Return(int64(1), nil).Once() s.mockQ.On("RemoveContractAssetBalances", s.ctx, []xdr.Hash(nil)). diff --git a/services/horizon/internal/ingest/processors/asset_stats_set.go b/services/horizon/internal/ingest/processors/asset_stats_set.go index bc27c2a4ef..9b79e49d82 100644 --- a/services/horizon/internal/ingest/processors/asset_stats_set.go +++ b/services/horizon/internal/ingest/processors/asset_stats_set.go @@ -109,8 +109,6 @@ func (value assetStatValue) ConvertToHistoryObject() history.ExpAssetStat { AssetIssuer: value.assetIssuer, Accounts: value.accounts, Balances: balances, - Amount: balances.Authorized, - NumAccounts: value.accounts.Authorized, } } diff --git a/services/horizon/internal/ingest/processors/asset_stats_set_test.go b/services/horizon/internal/ingest/processors/asset_stats_set_test.go index f9989fdc9e..330a2132ec 100644 --- a/services/horizon/internal/ingest/processors/asset_stats_set_test.go +++ b/services/horizon/internal/ingest/processors/asset_stats_set_test.go @@ -109,8 +109,6 @@ func TestAddAssetStats(t *testing.T) { ClaimableBalances: "0", LiquidityPools: "0", }, - Amount: "1", - NumAccounts: 1, } assert.NoError( @@ -150,9 +148,7 @@ func TestAddAssetStats(t *testing.T) { ) eurAssetStat.Balances.Authorized = "25" - eurAssetStat.Amount = "25" eurAssetStat.Accounts.Authorized++ - eurAssetStat.NumAccounts++ assertAllEquals(t, set, []history.ExpAssetStat{eurAssetStat}) usd := "USD" @@ -214,8 +210,6 @@ func TestAddAssetStats(t *testing.T) { ClaimableBalances: "0", LiquidityPools: "0", }, - Amount: "3", - NumAccounts: 1, }, eurAssetStat, { @@ -232,8 +226,6 @@ func TestAddAssetStats(t *testing.T) { ClaimableBalances: "0", LiquidityPools: "0", }, - Amount: "10", - NumAccounts: 1, }, } assertAllEquals(t, set, expected) @@ -270,8 +262,6 @@ func TestOverflowAssetStatSet(t *testing.T) { ClaimableBalances: "0", LiquidityPools: "0", }, - Amount: "9223372036854775807", - NumAccounts: 1, } if all[0] != eurAssetStat { t.Fatalf("expected asset stat to be %v but got %v", eurAssetStat, all[0]) @@ -305,8 +295,6 @@ func TestOverflowAssetStatSet(t *testing.T) { ClaimableBalances: "0", LiquidityPools: "0", }, - Amount: "18446744073709551614", - NumAccounts: 2, } if all[0] != eurAssetStat { t.Fatalf("expected asset stat to be %v but got %v", eurAssetStat, all[0]) diff --git a/services/horizon/internal/ingest/verify_range_state_test.go b/services/horizon/internal/ingest/verify_range_state_test.go index a1df30d854..f330ba362a 100644 --- a/services/horizon/internal/ingest/verify_range_state_test.go +++ b/services/horizon/internal/ingest/verify_range_state_test.go @@ -568,7 +568,6 @@ func (s *VerifyRangeStateTestSuite) TestSuccessWithVerify() { LiquidityPools: "450", Unauthorized: "0", }, - Amount: "0", }, }, }, nil).Once() @@ -651,8 +650,6 @@ func (s *VerifyRangeStateTestSuite) TestVerifyFailsWhenAssetStatsMismatch() { AuthorizedToMaintainLiabilities: "0", Unauthorized: "123", }, - Amount: "0", - NumAccounts: 0, }, } diff --git a/services/horizon/internal/integration/sac_test.go b/services/horizon/internal/integration/sac_test.go index a7311d173d..6356ba9ac5 100644 --- a/services/horizon/internal/integration/sac_test.go +++ b/services/horizon/internal/integration/sac_test.go @@ -260,9 +260,7 @@ func TestExpirationAndRestoration(t *testing.T) { LiquidityPools: "0", Unauthorized: "0", }, - Amount: "0", - NumAccounts: 0, - ContractID: nil, + ContractID: nil, } syntheticAssetStat.SetContractID(storeContractID) _, err := itest.HorizonIngest().HistoryQ().InsertAssetStat( diff --git a/services/horizon/internal/resourceadapter/asset_stat_test.go b/services/horizon/internal/resourceadapter/asset_stat_test.go index e36b7bef85..cd3209414d 100644 --- a/services/horizon/internal/resourceadapter/asset_stat_test.go +++ b/services/horizon/internal/resourceadapter/asset_stat_test.go @@ -31,8 +31,6 @@ func TestPopulateExpAssetStat(t *testing.T) { ClaimableBalances: "1200000000000000000", LiquidityPools: "7700000000000000000", }, - Amount: "100000000000000000000", // 10T - NumAccounts: 429, }, Contracts: history.ContractStat{ ActiveBalance: "900000000000000000", From 6f06c58471b41dfea661dfbe7f689419fdb24e9d Mon Sep 17 00:00:00 2001 From: Karthik Iyer Date: Mon, 30 Sep 2024 19:01:09 -0700 Subject: [PATCH 08/11] Remoce extra space in sql migration file. Generate bindata.go with gogenerate.sh --- .../horizon/internal/db2/schema/bindata.go | 23 +++++++++++++++++++ ...and_amount_cols_from_expat_asset_stats.sql | 10 -------- ...deprecated_fields_from_exp_asset_stats.sql | 18 +++++++++++++++ 3 files changed, 41 insertions(+), 10 deletions(-) delete mode 100644 services/horizon/internal/db2/schema/migrations/68_remove_accounts_num_accounts_and_amount_cols_from_expat_asset_stats.sql create mode 100644 services/horizon/internal/db2/schema/migrations/68_remove_deprecated_fields_from_exp_asset_stats.sql diff --git a/services/horizon/internal/db2/schema/bindata.go b/services/horizon/internal/db2/schema/bindata.go index 3c68f6b2fd..5dd80aec97 100644 --- a/services/horizon/internal/db2/schema/bindata.go +++ b/services/horizon/internal/db2/schema/bindata.go @@ -64,6 +64,7 @@ // migrations/65_drop_payment_index.sql (260B) // migrations/66_contract_asset_stats.sql (583B) // migrations/67_remove_unused_indexes.sql (2.897kB) +// migrations/68_remove_deprecated_fields_from_exp_asset_stats.sql (471B) // migrations/6_create_assets_table.sql (366B) // migrations/7_modify_trades_table.sql (2.303kB) // migrations/8_add_aggregators.sql (907B) @@ -1417,6 +1418,26 @@ func migrations67_remove_unused_indexesSql() (*asset, error) { return a, nil } +var _migrations68_remove_deprecated_fields_from_exp_asset_statsSql = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xa4\xd0\x4d\x4b\xc4\x30\x18\x04\xe0\x7b\x7e\xc5\xdc\xaa\x48\xa1\xf7\xa2\x10\x9b\xa8\xc5\x98\x4a\x7c\x23\xde\x42\xa8\x45\x0a\xf6\x03\x93\xaa\x3f\x5f\xdc\x0f\xe8\xb2\x4b\x77\x61\xaf\x81\x79\x66\xf2\xa6\x29\xae\xba\xf6\xe3\xcb\xc7\x06\x76\x64\x8c\x2b\x92\x06\xc4\x6f\x95\x44\xf3\x3b\x3a\x1f\x42\x13\x5d\x88\x3e\x06\x08\x53\x3d\xa3\xa8\xf4\x0b\x19\x5e\x6a\xc2\xb7\xff\x6c\xdf\x5d\x3f\x75\xce\xd7\xf5\x30\xf5\x31\xe4\x8b\x00\x03\xb0\x45\x94\x7d\xd2\x38\x23\xea\xbb\xff\x54\xce\xd8\xfc\x03\x62\xf8\xe9\x8f\x2a\x5c\x88\x43\xfd\x28\x35\xc9\x7b\x69\xa0\x2b\x82\xb6\x4a\x41\xc8\x3b\x6e\x15\x21\x3b\x61\xda\x0c\x5d\x2f\x03\xc9\x37\xda\xb7\x92\x64\x19\xdb\x40\x0b\x27\x46\xf1\x20\x8b\x47\x5c\xec\xbc\xdd\x5c\x23\xbb\x5c\xb5\xbd\x72\x55\x8a\x9c\xfd\x05\x00\x00\xff\xff\x7f\x2b\x3e\x4a\xd7\x01\x00\x00") + +func migrations68_remove_deprecated_fields_from_exp_asset_statsSqlBytes() ([]byte, error) { + return bindataRead( + _migrations68_remove_deprecated_fields_from_exp_asset_statsSql, + "migrations/68_remove_deprecated_fields_from_exp_asset_stats.sql", + ) +} + +func migrations68_remove_deprecated_fields_from_exp_asset_statsSql() (*asset, error) { + bytes, err := migrations68_remove_deprecated_fields_from_exp_asset_statsSqlBytes() + if err != nil { + return nil, err + } + + info := bindataFileInfo{name: "migrations/68_remove_deprecated_fields_from_exp_asset_stats.sql", size: 0, mode: os.FileMode(0), modTime: time.Unix(0, 0)} + a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x8, 0x9f, 0xc8, 0xbb, 0xb3, 0x73, 0xf7, 0x7a, 0x22, 0x14, 0x5f, 0x5a, 0x8a, 0x35, 0x6, 0xf1, 0x92, 0x45, 0xd, 0xe5, 0x75, 0x9, 0x7f, 0xab, 0xec, 0xa8, 0x35, 0xdc, 0xcf, 0x7b, 0x96, 0xde}} + return a, nil +} + var _migrations6_create_assets_tableSql = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x6c\x90\x3d\x4f\xc3\x30\x18\x84\x77\xff\x8a\x1b\x1d\x91\x0e\x20\xe8\x92\xc9\x34\x16\x58\x18\xa7\xb8\x31\xa2\x53\xe5\x26\x16\x78\x80\x54\xb6\x11\xca\xbf\x47\xaa\x28\xf9\x50\xe6\x7b\xf4\xbc\xef\xdd\x6a\x85\xab\x4f\xff\x1e\x6c\x72\x30\x27\xb2\xd1\x9c\xd5\x1c\x35\xbb\x97\x1c\x1f\x3e\xa6\x2e\xf4\x07\x1b\xa3\x4b\x11\x94\x00\x80\x6f\xb1\xe3\x5a\x30\x89\xad\x16\xcf\x4c\xef\xf1\xc4\xf7\xc8\xcf\xd9\x19\x3c\xa4\xfe\xe4\xf0\xca\xf4\xe6\x91\x69\xba\xbe\xcd\xa0\xaa\x1a\xca\x48\x39\x86\x9a\xae\x1d\xa0\xeb\x9b\x65\xc8\xc7\xf8\xed\xc2\x3f\x76\xb7\x9e\x63\x46\x89\x17\xc3\xe9\xa0\xcc\x47\x3f\xe4\x13\x4b\x46\xb2\x82\x5c\xfa\x09\x55\xf2\xb7\xbf\xf8\xd8\x5f\xee\x54\x6a\x5e\xd9\xec\x84\x7a\xc0\x31\x05\xe7\x40\x27\xb6\x82\x90\xf1\x74\x65\xf7\xf3\x45\x4a\x5d\x6d\x97\xa7\x6b\x6c\x6c\x6c\xeb\x8a\xdf\x00\x00\x00\xff\xff\xfb\x53\x3e\x81\x6e\x01\x00\x00") func migrations6_create_assets_tableSqlBytes() ([]byte, error) { @@ -1672,6 +1693,7 @@ var _bindata = map[string]func() (*asset, error){ "migrations/65_drop_payment_index.sql": migrations65_drop_payment_indexSql, "migrations/66_contract_asset_stats.sql": migrations66_contract_asset_statsSql, "migrations/67_remove_unused_indexes.sql": migrations67_remove_unused_indexesSql, + "migrations/68_remove_deprecated_fields_from_exp_asset_stats.sql": migrations68_remove_deprecated_fields_from_exp_asset_statsSql, "migrations/6_create_assets_table.sql": migrations6_create_assets_tableSql, "migrations/7_modify_trades_table.sql": migrations7_modify_trades_tableSql, "migrations/8_add_aggregators.sql": migrations8_add_aggregatorsSql, @@ -1787,6 +1809,7 @@ var _bintree = &bintree{nil, map[string]*bintree{ "65_drop_payment_index.sql": {migrations65_drop_payment_indexSql, map[string]*bintree{}}, "66_contract_asset_stats.sql": {migrations66_contract_asset_statsSql, map[string]*bintree{}}, "67_remove_unused_indexes.sql": {migrations67_remove_unused_indexesSql, map[string]*bintree{}}, + "68_remove_deprecated_fields_from_exp_asset_stats.sql": {migrations68_remove_deprecated_fields_from_exp_asset_statsSql, map[string]*bintree{}}, "6_create_assets_table.sql": {migrations6_create_assets_tableSql, map[string]*bintree{}}, "7_modify_trades_table.sql": {migrations7_modify_trades_tableSql, map[string]*bintree{}}, "8_add_aggregators.sql": {migrations8_add_aggregatorsSql, map[string]*bintree{}}, diff --git a/services/horizon/internal/db2/schema/migrations/68_remove_accounts_num_accounts_and_amount_cols_from_expat_asset_stats.sql b/services/horizon/internal/db2/schema/migrations/68_remove_accounts_num_accounts_and_amount_cols_from_expat_asset_stats.sql deleted file mode 100644 index 9c894d4417..0000000000 --- a/services/horizon/internal/db2/schema/migrations/68_remove_accounts_num_accounts_and_amount_cols_from_expat_asset_stats.sql +++ /dev/null @@ -1,10 +0,0 @@ --- + migrate Up - -ALTER TABLE exp_asset_stats - DROP COLUMN num_accounts, - DROP COLUMN amount; - --- + migrate Down -ALTER TABLE exp_asset_stats - ADD COLUMN num_accounts INTEGER DEFAULT 0, - ADD COLUMN amount VARCHAR DEFAULT ''; diff --git a/services/horizon/internal/db2/schema/migrations/68_remove_deprecated_fields_from_exp_asset_stats.sql b/services/horizon/internal/db2/schema/migrations/68_remove_deprecated_fields_from_exp_asset_stats.sql new file mode 100644 index 0000000000..691a070274 --- /dev/null +++ b/services/horizon/internal/db2/schema/migrations/68_remove_deprecated_fields_from_exp_asset_stats.sql @@ -0,0 +1,18 @@ +-- +migrate Up + +ALTER TABLE exp_asset_stats DROP CONSTRAINT valid_num_accounts; + +ALTER TABLE exp_asset_stats + DROP COLUMN num_accounts; + +ALTER TABLE exp_asset_stats + DROP COLUMN amount; + +-- +migrate Down +ALTER TABLE exp_asset_stats + ADD COLUMN num_accounts INTEGER NOT NULL DEFAULT 0; + +ALTER TABLE exp_asset_stats + ADD COLUMN amount TEXT NOT NULL DEFAULT ''; + +ALTER TABLE exp_asset_stats ADD CONSTRAINT valid_num_accounts CHECK (num_accounts >= 0) NOT VALID; From e5edf19d70c9cd1e094b7ccf5ab9970b1c3ee0a7 Mon Sep 17 00:00:00 2001 From: Karthik Iyer Date: Tue, 1 Oct 2024 11:08:19 -0700 Subject: [PATCH 09/11] Update code to show only authorized accounts and balances in ticker service --- .../ticker/internal/scraper/asset_scraper.go | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/services/ticker/internal/scraper/asset_scraper.go b/services/ticker/internal/scraper/asset_scraper.go index cd6c6ed9c9..0bbc82452a 100644 --- a/services/ticker/internal/scraper/asset_scraper.go +++ b/services/ticker/internal/scraper/asset_scraper.go @@ -144,20 +144,6 @@ func isDomainVerified(orgURL string, tomlURL string, hasCurrency bool) bool { } return true } -func AddStringsToSum(values ...string) (float64, error) { - var sum float64 - for _, s := range values { - if s == "" { - continue // Treat empty string as zero - } - value, err := strconv.ParseFloat(s, 64) - if err != nil { - return 0, fmt.Errorf("failed to convert '%s': %w", s, err) - } - sum += value - } - return sum, nil -} // makeTomlAsset aggregates Horizon Data with TOML Data func makeFinalAsset( @@ -165,7 +151,7 @@ func makeFinalAsset( issuer TOMLIssuer, errors []error, ) (t FinalAsset, err error) { - amount, err := AddStringsToSum(asset.Balances.Authorized + asset.Balances.Unauthorized + asset.Balances.Unauthorized) + amount, err := strconv.ParseFloat(asset.Balances.Authorized, 64) if err != nil { return } @@ -174,7 +160,7 @@ func makeFinalAsset( Type: asset.Type, Code: asset.Code, Issuer: asset.Issuer, - NumAccounts: asset.Accounts.Authorized + asset.Accounts.Unauthorized + asset.Accounts.AuthorizedToMaintainLiabilities, + NumAccounts: asset.Accounts.Authorized, AuthRequired: asset.Flags.AuthRequired, AuthRevocable: asset.Flags.AuthRevocable, Amount: amount, From 6197f9db530208fb969b54ec415f1268140af4bf Mon Sep 17 00:00:00 2001 From: Karthik Iyer Date: Tue, 1 Oct 2024 11:40:14 -0700 Subject: [PATCH 10/11] Fix tests in ticker --- services/ticker/internal/scraper/asset_scraper_test.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/services/ticker/internal/scraper/asset_scraper_test.go b/services/ticker/internal/scraper/asset_scraper_test.go index 4582aab2bf..411fa9e528 100644 --- a/services/ticker/internal/scraper/asset_scraper_test.go +++ b/services/ticker/internal/scraper/asset_scraper_test.go @@ -145,6 +145,8 @@ func TestProcessAsset_notCached(t *testing.T) { })) asset := hProtocol.AssetStat{} asset.Code = "SOMETHINGVALID" + asset.Accounts.Authorized = 1 + asset.Balances.Authorized = "123.4" asset.Links.Toml.Href = server.URL tomlCache := &TOMLCache{} finalAsset, err := processAsset(logger, asset, tomlCache, true) @@ -160,6 +162,8 @@ func TestProcessAsset_cached(t *testing.T) { logger := log.DefaultLogger asset := hProtocol.AssetStat{} asset.Code = "SOMETHINGVALID" + asset.Accounts.Authorized = 1 + asset.Balances.Authorized = "123.4" asset.Links.Toml.Href = "url" tomlCache := &TOMLCache{} tomlCache.Set("url", TOMLIssuer{SigningKey: "signing key"}) From 238c6fde89093d8b704632c2e0eb1dfc29711d1a Mon Sep 17 00:00:00 2001 From: Karthik Iyer Date: Wed, 2 Oct 2024 12:56:57 -0700 Subject: [PATCH 11/11] Updated CHANGELOG.md to include breaking changes --- services/horizon/CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/services/horizon/CHANGELOG.md b/services/horizon/CHANGELOG.md index cd5d8af57b..a444771ca6 100644 --- a/services/horizon/CHANGELOG.md +++ b/services/horizon/CHANGELOG.md @@ -5,6 +5,12 @@ file. This project adheres to [Semantic Versioning](http://semver.org/). ## Pending +### Breaking Changes + +- Removed `num_accounts` and `amount` fields from Asset stats related endpoints, and `valid_before` and `valid_after` fields from transaction related endpoints. Issue - [5438](https://github.com/stellar/go/issues/5438), PR - [5478](https://github.com/stellar/go/pull/5478) + - These fields have already been functionally deprecated as of release v2.1.0. As a part of this release, these fields are omitted from API Response + - Additionally, the `num_accounts` and `amount` columns have been dropped from `exp_asset_stats` table in Postgres. + ### Added - Reingest from pre-computed tx meta on remote cloud storage. ([4911](https://github.com/stellar/go/issues/4911)), ([5374](https://github.com/stellar/go/pull/5374))