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: Batch remove accounts, move ingestion to AccountsProcessor #3945

Merged
merged 7 commits into from
Sep 21, 2021
Merged
Show file tree
Hide file tree
Changes from 6 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
193 changes: 68 additions & 125 deletions services/horizon/internal/actions/account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"testing"
"time"

"github.com/guregu/null"
"github.com/stretchr/testify/assert"

protocol "github.com/stellar/go/protocols/horizon"
Expand All @@ -20,94 +21,58 @@ var (
accountOne = "GABGMPEKKDWR2WFH5AJOZV5PDKLJEHGCR3Q24ALETWR5H3A7GI3YTS7V"
accountTwo = "GADTXHUTHIAESMMQ2ZWSTIIGBZRLHUCBLCHPLLUEIAWDEFRDC4SYDKOZ"
signer = "GCXKG6RN4ONIEPCMNFB732A436Z5PNDSRLGWK7GBLCMQLIFO4S7EYWVU"
sponsor = xdr.MustAddress("GCO26ZSBD63TKYX45H2C7D2WOFWOUSG5BMTNC3BG4QMXM3PAYI6WHKVZ")
sponsor = "GCO26ZSBD63TKYX45H2C7D2WOFWOUSG5BMTNC3BG4QMXM3PAYI6WHKVZ"
usd = xdr.MustNewCreditAsset("USD", trustLineIssuer)
euro = xdr.MustNewCreditAsset("EUR", trustLineIssuer)

account1 = xdr.LedgerEntry{
LastModifiedLedgerSeq: 1234,
Data: xdr.LedgerEntryData{
Type: xdr.LedgerEntryTypeAccount,
Account: &xdr.AccountEntry{
AccountId: xdr.MustAddress(accountOne),
Balance: 20000,
SeqNum: 223456789,
NumSubEntries: 10,
Flags: 1,
HomeDomain: "stellar.org",
Thresholds: xdr.Thresholds{1, 2, 3, 4},
Ext: xdr.AccountEntryExt{
V: 1,
V1: &xdr.AccountEntryExtensionV1{
Liabilities: xdr.Liabilities{
Buying: 3,
Selling: 4,
},
},
},
},
},
account1 = history.AccountEntry{
LastModifiedLedger: 1234,
AccountID: accountOne,
Balance: 20000,
SequenceNumber: 223456789,
NumSubEntries: 10,
Flags: 1,
HomeDomain: "stellar.org",
MasterWeight: 1,
ThresholdLow: 2,
ThresholdMedium: 3,
ThresholdHigh: 4,
BuyingLiabilities: 3,
SellingLiabilities: 3,
}

account2 = xdr.LedgerEntry{
LastModifiedLedgerSeq: 1234,
Data: xdr.LedgerEntryData{
Type: xdr.LedgerEntryTypeAccount,
Account: &xdr.AccountEntry{
AccountId: xdr.MustAddress(accountTwo),
Balance: 50000,
SeqNum: 648736,
NumSubEntries: 10,
Flags: 2,
HomeDomain: "meridian.stellar.org",
Thresholds: xdr.Thresholds{5, 6, 7, 8},
Ext: xdr.AccountEntryExt{
V: 1,
V1: &xdr.AccountEntryExtensionV1{
Liabilities: xdr.Liabilities{
Buying: 30,
Selling: 40,
},
},
},
},
},
account2 = history.AccountEntry{
LastModifiedLedger: 1234,
AccountID: accountTwo,
Balance: 50000,
SequenceNumber: 648736,
NumSubEntries: 10,
Flags: 2,
HomeDomain: "meridian.stellar.org",
MasterWeight: 5,
ThresholdLow: 6,
ThresholdMedium: 7,
ThresholdHigh: 8,
BuyingLiabilities: 30,
SellingLiabilities: 40,
}

account3 = xdr.LedgerEntry{
LastModifiedLedgerSeq: 1234,
Data: xdr.LedgerEntryData{
Type: xdr.LedgerEntryTypeAccount,
Account: &xdr.AccountEntry{
AccountId: xdr.MustAddress(signer),
Balance: 50000,
SeqNum: 648736,
NumSubEntries: 10,
Flags: 2,
Thresholds: xdr.Thresholds{5, 6, 7, 8},
Ext: xdr.AccountEntryExt{
V: 1,
V1: &xdr.AccountEntryExtensionV1{
Liabilities: xdr.Liabilities{
Buying: 30,
Selling: 40,
},
Ext: xdr.AccountEntryExtensionV1Ext{
V2: &xdr.AccountEntryExtensionV2{
NumSponsored: 1,
NumSponsoring: 2,
},
},
},
},
},
},
Ext: xdr.LedgerEntryExt{
V: 1,
V1: &xdr.LedgerEntryExtensionV1{
SponsoringId: &sponsor,
},
},
account3 = history.AccountEntry{
LastModifiedLedger: 1234,
AccountID: signer,
Balance: 50000,
SequenceNumber: 648736,
NumSubEntries: 10,
Flags: 2,
MasterWeight: 5,
ThresholdLow: 6,
ThresholdMedium: 7,
ThresholdHigh: 8,
BuyingLiabilities: 30,
SellingLiabilities: 40,
NumSponsored: 1,
NumSponsoring: 2,
Sponsor: null.StringFrom(sponsor),
}

eurTrustLine = xdr.LedgerEntry{
Expand Down Expand Up @@ -220,29 +185,23 @@ func TestAccountInfo(t *testing.T) {
tt.Assert.NoError(
xdr.SafeUnmarshalBase64("AQAAAA==", &thresholds),
)
accountID := xdr.MustAddress(
"GCXKG6RN4ONIEPCMNFB732A436Z5PNDSRLGWK7GBLCMQLIFO4S7EYWVU",
)
accountEntry := xdr.LedgerEntry{
LastModifiedLedgerSeq: 4,
Data: xdr.LedgerEntryData{
Type: xdr.LedgerEntryTypeAccount,
Account: &xdr.AccountEntry{
AccountId: accountID,
Balance: 9999999900,
SeqNum: 8589934593,
NumSubEntries: 1,
InflationDest: nil,
HomeDomain: "",
Thresholds: thresholds,
Flags: 0,
},
},
accountID := "GCXKG6RN4ONIEPCMNFB732A436Z5PNDSRLGWK7GBLCMQLIFO4S7EYWVU"
accountEntry := history.AccountEntry{
LastModifiedLedger: 4,
AccountID: accountID,
Balance: 9999999900,
SequenceNumber: 8589934593,
NumSubEntries: 1,
InflationDestination: "",
HomeDomain: "",
MasterWeight: thresholds[0],
ThresholdLow: thresholds[1],
ThresholdMedium: thresholds[2],
ThresholdHigh: thresholds[3],
Flags: 0,
}
batch := q.NewAccountsBatchInsertBuilder(0)
err := batch.Add(tt.Ctx, accountEntry)
err := q.UpsertAccounts(tt.Ctx, []history.AccountEntry{accountEntry})
assert.NoError(t, err)
assert.NoError(t, batch.Exec(tt.Ctx))

tt.Assert.NoError(err)

Expand All @@ -251,7 +210,7 @@ func TestAccountInfo(t *testing.T) {
Data: xdr.LedgerEntryData{
Type: xdr.LedgerEntryTypeTrustline,
TrustLine: &xdr.TrustLineEntry{
AccountId: accountID,
AccountId: xdr.MustAddress(accountID),
Asset: xdr.MustNewCreditAsset(
"USD",
"GC23QF2HUE52AMXUFUH3AYJAXXGXXV2VHXYYR6EYXETPKDXZSAW67XO4",
Expand All @@ -269,7 +228,7 @@ func TestAccountInfo(t *testing.T) {
Data: xdr.LedgerEntryData{
Type: xdr.LedgerEntryTypeTrustline,
TrustLine: &xdr.TrustLineEntry{
AccountId: accountID,
AccountId: xdr.MustAddress(accountID),
Asset: xdr.MustNewCreditAsset(
"EUR",
"GC23QF2HUE52AMXUFUH3AYJAXXGXXV2VHXYYR6EYXETPKDXZSAW67XO4",
Expand All @@ -293,7 +252,7 @@ func TestAccountInfo(t *testing.T) {
}, 0, 0, 0, 0, 0)
assert.NoError(t, err)

account, err := AccountInfo(tt.Ctx, &history.Q{tt.HorizonSession()}, accountID.Address())
account, err := AccountInfo(tt.Ctx, &history.Q{tt.HorizonSession()}, accountID)
tt.Assert.NoError(err)

tt.Assert.Equal("8589934593", account.Sequence)
Expand Down Expand Up @@ -354,14 +313,8 @@ func TestGetAccountsHandlerPageResultsBySigner(t *testing.T) {
q := &history.Q{tt.HorizonSession()}
handler := &GetAccountsHandler{}

batch := q.NewAccountsBatchInsertBuilder(0)
err := batch.Add(tt.Ctx, account1)
err := q.UpsertAccounts(tt.Ctx, []history.AccountEntry{account1, account2, account3})
assert.NoError(t, err)
err = batch.Add(tt.Ctx, account2)
assert.NoError(t, err)
err = batch.Add(tt.Ctx, account3)
assert.NoError(t, err)
assert.NoError(t, batch.Exec(tt.Ctx))

for _, row := range accountSigners {
q.CreateAccountSigner(tt.Ctx, row.Account, row.Signer, row.Weight, nil)
Expand Down Expand Up @@ -434,14 +387,8 @@ func TestGetAccountsHandlerPageResultsBySponsor(t *testing.T) {
q := &history.Q{tt.HorizonSession()}
handler := &GetAccountsHandler{}

batch := q.NewAccountsBatchInsertBuilder(0)
err := batch.Add(tt.Ctx, account1)
assert.NoError(t, err)
err = batch.Add(tt.Ctx, account2)
err := q.UpsertAccounts(tt.Ctx, []history.AccountEntry{account1, account2, account3})
assert.NoError(t, err)
err = batch.Add(tt.Ctx, account3)
assert.NoError(t, err)
assert.NoError(t, batch.Exec(tt.Ctx))

for _, row := range accountSigners {
q.CreateAccountSigner(tt.Ctx, row.Account, row.Signer, row.Weight, nil)
Expand All @@ -452,7 +399,7 @@ func TestGetAccountsHandlerPageResultsBySponsor(t *testing.T) {
makeRequest(
t,
map[string]string{
"sponsor": sponsor.Address(),
"sponsor": sponsor,
},
map[string]string{},
q,
Expand All @@ -472,12 +419,8 @@ func TestGetAccountsHandlerPageResultsByAsset(t *testing.T) {
q := &history.Q{tt.HorizonSession()}
handler := &GetAccountsHandler{}

batch := q.NewAccountsBatchInsertBuilder(0)
err := batch.Add(tt.Ctx, account1)
assert.NoError(t, err)
err = batch.Add(tt.Ctx, account2)
err := q.UpsertAccounts(tt.Ctx, []history.AccountEntry{account1, account2})
assert.NoError(t, err)
assert.NoError(t, batch.Exec(tt.Ctx))
ledgerCloseTime := time.Now().Unix()
_, err = q.InsertLedger(tt.Ctx, xdr.LedgerHeaderHistoryEntry{
Header: xdr.LedgerHeader{
Expand Down
22 changes: 7 additions & 15 deletions services/horizon/internal/actions/asset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,23 +312,15 @@ func TestAssetStats(t *testing.T) {
issuer,
otherIssuer,
} {
accountEntry := xdr.LedgerEntry{
LastModifiedLedgerSeq: 100,
Data: xdr.LedgerEntryData{
Type: xdr.LedgerEntryTypeAccount,
Account: &xdr.AccountEntry{
Flags: xdr.Uint32(account.Flags),
HomeDomain: xdr.String32(account.HomeDomain),
},
},
}
if err := accountEntry.Data.Account.AccountId.SetAddress(account.AccountID); err != nil {
t.Fatalf("unexpected error %v", err)
accountEntry := history.AccountEntry{
LastModifiedLedger: 100,
AccountID: account.AccountID,
Flags: account.Flags,
HomeDomain: account.HomeDomain,
}
batch := q.NewAccountsBatchInsertBuilder(0)
err := batch.Add(tt.Ctx, accountEntry)

err := q.UpsertAccounts(tt.Ctx, []history.AccountEntry{accountEntry})
tt.Assert.NoError(err)
tt.Assert.NoError(batch.Exec(tt.Ctx))
}

for _, testCase := range []struct {
Expand Down
4 changes: 2 additions & 2 deletions services/horizon/internal/actions/offer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ var (
Price: float64(2),
Flags: 2,
LastModifiedLedger: uint32(4),
Sponsor: null.StringFrom(sponsor.Address()),
Sponsor: null.StringFrom(sponsor),
}
usdOffer = history.Offer{
SellerID: issuer.Address(),
Expand Down Expand Up @@ -268,7 +268,7 @@ func TestGetOffersHandler(t *testing.T) {
makeRequest(
t,
map[string]string{
"sponsor": sponsor.Address(),
"sponsor": sponsor,
},
map[string]string{},
q,
Expand Down
Loading