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

Merge release-horizon v0.23.0 into master #1946

Merged
merged 45 commits into from
Nov 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
6675d2d
services/horizon/internal/actions: Add /order_book ingestion endpoint…
tamirms Sep 26, 2019
08dc117
Merge pull request #1793 from stellar/master
bartekn Sep 30, 2019
705917b
services/horizon/expingest: Update DatabaseProcessor with trust lines…
bartekn Oct 8, 2019
79b78fa
Merge branch 'master' into release-horizon-v0.22.0
bartekn Oct 9, 2019
6c29c31
services/horizon/internal/db2/history: Asset stats ingestion table (#…
tamirms Oct 11, 2019
730ee8c
Merge branch 'master' into release-horizon-v0.23.0
bartekn Oct 11, 2019
c4601c0
protocols/horizon: Remove deprecated fee_paid field from Transaction …
tamirms Oct 11, 2019
2ac805c
services/horizon/internal/actions: Refactor accounts to use new actio…
abuiles Oct 11, 2019
9161997
services/horizon/internal/actions: Add latest ingested ledger header …
tamirms Oct 15, 2019
64a400f
services/horizon/internal/expingest: Execute all ledger processors in…
tamirms Oct 16, 2019
1301cd5
services/horizon: Add accounts and account data to ingestion pipeline…
bartekn Oct 16, 2019
fbc3c26
services/horizon/internal/actions: Implement experimental ingestion a…
tamirms Oct 17, 2019
d585fad
Move get offer by id endpoint to actions package (#1846)
tamirms Oct 17, 2019
f3b2896
services/horizon: Use percentile_disc in fee stats query (#1857)
bartekn Oct 17, 2019
19fde30
services/horizon/internal, services/horizon/internal/expingest: Inges…
tamirms Oct 17, 2019
739f165
Fix bug in strict send path finding search (#1863)
tamirms Oct 21, 2019
717c5ab
Automate query parameters parsing and validation. (#1755)
abuiles Oct 21, 2019
b0804f1
Add resource adapter for history.AccountEntry. (#1859)
abuiles Oct 21, 2019
8a5e148
Do not start repeatable read sessions for streaming endpoints (#1865)
tamirms Oct 22, 2019
458fb52
services/horizon: Set for empty referer (#1869)
bartekn Oct 23, 2019
dc438fc
services/horizon/internal: Use custom timeout middleware (#1870)
tamirms Oct 24, 2019
e496540
all: Revert "protocols/horizon: Remove deprecated fee_paid field" (#1…
tamirms Oct 24, 2019
dd6194a
services/horizon/internal/actions: Find all accounts who are trustee…
abuiles Oct 24, 2019
8c07c2b
services/horizon/internal/actions: Update payload for "Accounts For S…
abuiles Oct 25, 2019
8b3c152
exp/ingest: Process ledger upgrade meta (#1862)
bartekn Oct 25, 2019
a46046b
Add API documentation for experimental endpoints (#1887)
abuiles Oct 30, 2019
34c7cf0
services/horizon/internal: Automate root url generation with query st…
abuiles Oct 30, 2019
233c512
services/horizon: Use new ingestion data in `/accounts/{account_id}` …
bartekn Oct 30, 2019
3c24bf6
services/horizon: Rename column names to be consistent (#1893)
bartekn Oct 31, 2019
5c424b6
services/horizon/internal/actions: Update asset filter on accounts (#…
abuiles Oct 31, 2019
5f4d1e8
services/horizon/internal/actions: Update strict send path action to …
abuiles Nov 1, 2019
bc33b43
services/horizon/internal/actions: Update strict receive path action …
abuiles Nov 2, 2019
4f1a9bf
Merge branch 'master' into release-horizon-v0.23.0
bartekn Nov 13, 2019
963033b
services/horizon: Clean and update CHANGELOG for 0.23.0 (#1925)
bartekn Nov 14, 2019
443af18
Fix invalid account params message. (#1927)
abuiles Nov 14, 2019
9354224
services/horizon: Update "Action needed" tags (#1929)
bartekn Nov 14, 2019
24b3a94
services/horizon/internal/actions: Fix asset issuer does not exist bu…
tamirms Nov 14, 2019
5d4f3ee
services/horizon: Use http.NewServeMux to create mux (#1935)
bartekn Nov 15, 2019
168dd5d
services/horizon/internal: remove unused layer of router
leighmcculloch Nov 15, 2019
5a98483
add links to 0.23 Horizon changelog (#1931)
ire-and-curses Nov 15, 2019
e402e29
services/horizon/internal: remove unused layer of router (#1937)
leighmcculloch Nov 15, 2019
d222515
services/horizon/internal/expingest/processors: Only process authoriz…
tamirms Nov 15, 2019
142d26b
services/horizon: Bump expingest version (#1939)
bartekn Nov 15, 2019
4db3479
services/horizon: Truncate exp_asset_stats table when reingesting sta…
bartekn Nov 15, 2019
921e8ec
Send bye bye event before exiting a StreamHandler (#1942)
tamirms Nov 15, 2019
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
67 changes: 45 additions & 22 deletions exp/ingest/io/ledger_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,18 @@ import (
)

// DBLedgerReader is a database-backed implementation of the io.LedgerReader interface.
// Use NewDBLedgerReader to create a new instance.
type DBLedgerReader struct {
sequence uint32
backend ledgerbackend.LedgerBackend
header xdr.LedgerHeaderHistoryEntry
transactions []LedgerTransaction
readIdx int
initOnce sync.Once
readMutex sync.Mutex
sequence uint32
backend ledgerbackend.LedgerBackend
header xdr.LedgerHeaderHistoryEntry
transactions []LedgerTransaction
upgradeChanges []Change
readMutex sync.Mutex
readIdx int
upgradeReadIdx int
readUpgradeChangeCalled bool
ignoreUpgradeChanges bool
}

// Ensure DBLedgerReader implements LedgerReader
Expand All @@ -30,8 +34,7 @@ func NewDBLedgerReader(sequence uint32, backend ledgerbackend.LedgerBackend) (*D
backend: backend,
}

var err error
reader.initOnce.Do(func() { err = reader.init() })
err := reader.init()
if err != nil {
return nil, err
}
Expand All @@ -46,25 +49,12 @@ func (dblrc *DBLedgerReader) GetSequence() uint32 {

// GetHeader returns the XDR Header data associated with the stored ledger.
func (dblrc *DBLedgerReader) GetHeader() xdr.LedgerHeaderHistoryEntry {
var err error
dblrc.initOnce.Do(func() { err = dblrc.init() })
if err != nil {
// TODO, object should be initialized in constructor.
// Not returning error here, makes this much simpler.
panic(err)
}
return dblrc.header
}

// Read returns the next transaction in the ledger, ordered by tx number, each time it is called. When there
// are no more transactions to return, an EOF error is returned.
func (dblrc *DBLedgerReader) Read() (LedgerTransaction, error) {
var err error
dblrc.initOnce.Do(func() { err = dblrc.init() })
if err != nil {
return LedgerTransaction{}, err
}

// Protect all accesses to dblrc.readIdx
dblrc.readMutex.Lock()
defer dblrc.readMutex.Unlock()
Expand All @@ -76,10 +66,38 @@ func (dblrc *DBLedgerReader) Read() (LedgerTransaction, error) {
return LedgerTransaction{}, io.EOF
}

// ReadUpgradeChange returns the next upgrade change in the ledger, each time it
// is called. When there are no more upgrades to return, an EOF error is returned.
func (dblrc *DBLedgerReader) ReadUpgradeChange() (Change, error) {
// Protect all accesses to dblrc.upgradeReadIdx
dblrc.readMutex.Lock()
defer dblrc.readMutex.Unlock()
dblrc.readUpgradeChangeCalled = true

if dblrc.upgradeReadIdx < len(dblrc.upgradeChanges) {
dblrc.upgradeReadIdx++
return dblrc.upgradeChanges[dblrc.upgradeReadIdx-1], nil
}
return Change{}, io.EOF
}

// GetUpgradeChanges returns all ledger upgrade changes.
func (dblrc *DBLedgerReader) GetUpgradeChanges() []Change {
return dblrc.upgradeChanges
}

func (dblrc *DBLedgerReader) IgnoreUpgradeChanges() {
dblrc.ignoreUpgradeChanges = true
}

// Close moves the read pointer so that subsequent calls to Read() will return EOF.
func (dblrc *DBLedgerReader) Close() error {
dblrc.readMutex.Lock()
dblrc.readIdx = len(dblrc.transactions)
if !dblrc.ignoreUpgradeChanges &&
(!dblrc.readUpgradeChangeCalled || dblrc.upgradeReadIdx != len(dblrc.upgradeChanges)) {
return errors.New("Ledger upgrade changes not read! Use ReadUpgradeChange() method.")
}
dblrc.readMutex.Unlock()

return nil
Expand All @@ -100,6 +118,11 @@ func (dblrc *DBLedgerReader) init() error {

dblrc.storeTransactions(ledgerCloseMeta)

for _, upgradeChanges := range ledgerCloseMeta.UpgradesMeta {
changes := getChangesFromLedgerEntryChanges(upgradeChanges)
dblrc.upgradeChanges = append(dblrc.upgradeChanges, changes...)
}

return nil
}

Expand Down
115 changes: 98 additions & 17 deletions exp/ingest/io/ledger_transaction.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package io

import (
"bytes"

"github.com/stellar/go/support/errors"
"github.com/stellar/go/xdr"
)

Expand All @@ -13,8 +16,77 @@ import (
// If an entry is removed: Pre is not nil and Post is nil.
type Change struct {
Type xdr.LedgerEntryType
Pre *xdr.LedgerEntryData
Post *xdr.LedgerEntryData
Pre *xdr.LedgerEntry
Post *xdr.LedgerEntry
}

// AccountChangedExceptSigners returns true if account has changed WITHOUT
// checking the signers (except master key weight!). In other words, if the only
// change is connected to signers, this function will return false.
func (c *Change) AccountChangedExceptSigners() (bool, error) {
if c.Type != xdr.LedgerEntryTypeAccount {
panic("This should not be called on changes other than Account changes")
}

// New account
if c.Pre == nil {
return true, nil
}

// Account merged
// c.Pre != nil at this point.
if c.Post == nil {
return true, nil
}

// c.Pre != nil && c.Post != nil at this point.
if c.Pre.LastModifiedLedgerSeq != c.Post.LastModifiedLedgerSeq {
return true, nil
}

// Don't use short assignment statement (:=) to ensure variables below
// are not pointers (if `xdr` package changes in the future)!
var preAccountEntry, postAccountEntry xdr.AccountEntry
preAccountEntry = c.Pre.Data.MustAccount()
postAccountEntry = c.Post.Data.MustAccount()

// preAccountEntry and postAccountEntry are copies so it's fine to
// modify them here, EXCEPT pointers inside them!
if preAccountEntry.Ext.V == 0 {
preAccountEntry.Ext.V = 1
preAccountEntry.Ext.V1 = &xdr.AccountEntryV1{
Liabilities: xdr.Liabilities{
Buying: 0,
Selling: 0,
},
}
}

preAccountEntry.Signers = nil

if postAccountEntry.Ext.V == 0 {
postAccountEntry.Ext.V = 1
postAccountEntry.Ext.V1 = &xdr.AccountEntryV1{
Liabilities: xdr.Liabilities{
Buying: 0,
Selling: 0,
},
}
}

postAccountEntry.Signers = nil

preBinary, err := preAccountEntry.MarshalBinary()
if err != nil {
return false, errors.Wrap(err, "Error running preAccountEntry.MarshalBinary")
}

postBinary, err := postAccountEntry.MarshalBinary()
if err != nil {
return false, errors.Wrap(err, "Error running postAccountEntry.MarshalBinary")
}

return !bytes.Equal(preBinary, postBinary), nil
}

// AccountSignersChanged returns true if account signers have changed.
Expand All @@ -36,8 +108,8 @@ func (c *Change) AccountSignersChanged() bool {
}

// c.Pre != nil && c.Post != nil at this point.
preAccountEntry := c.Pre.MustAccount()
postAccountEntry := c.Post.MustAccount()
preAccountEntry := c.Pre.Data.MustAccount()
postAccountEntry := c.Post.Data.MustAccount()

preSigners := preAccountEntry.SignerSummary()
postSigners := postAccountEntry.SignerSummary()
Expand Down Expand Up @@ -68,18 +140,27 @@ func (t *LedgerTransaction) GetChanges() []Change {
changes := getChangesFromLedgerEntryChanges(t.FeeChanges)

// Transaction meta
v1Meta, ok := t.Meta.GetV1()
if ok {
switch t.Meta.V {
case 0:
for _, operationMeta := range *t.Meta.Operations {
opChanges := getChangesFromLedgerEntryChanges(
operationMeta.Changes,
)
changes = append(changes, opChanges...)
}
case 1:
v1Meta := t.Meta.MustV1()
txChanges := getChangesFromLedgerEntryChanges(v1Meta.TxChanges)
changes = append(changes, txChanges...)
}

// Operation meta
for _, operationMeta := range t.Meta.OperationsMeta() {
ledgerEntryChanges := operationMeta.Changes
opChanges := getChangesFromLedgerEntryChanges(ledgerEntryChanges)

changes = append(changes, opChanges...)
for _, operationMeta := range v1Meta.Operations {
opChanges := getChangesFromLedgerEntryChanges(
operationMeta.Changes,
)
changes = append(changes, opChanges...)
}
default:
panic("Unkown TransactionMeta version")
}

return changes
Expand All @@ -106,21 +187,21 @@ func getChangesFromLedgerEntryChanges(ledgerEntryChanges xdr.LedgerEntryChanges)
changes = append(changes, Change{
Type: created.Data.Type,
Pre: nil,
Post: &created.Data,
Post: &created,
})
case xdr.LedgerEntryChangeTypeLedgerEntryUpdated:
state := ledgerEntryChanges[i-1].MustState()
updated := entryChange.MustUpdated()
changes = append(changes, Change{
Type: state.Data.Type,
Pre: &state.Data,
Post: &updated.Data,
Pre: &state,
Post: &updated,
})
case xdr.LedgerEntryChangeTypeLedgerEntryRemoved:
state := ledgerEntryChanges[i-1].MustState()
changes = append(changes, Change{
Type: state.Data.Type,
Pre: &state.Data,
Pre: &state,
Post: nil,
})
case xdr.LedgerEntryChangeTypeLedgerEntryState:
Expand Down
Loading