Skip to content

Commit

Permalink
exp/ingest/io: Fix LedgerTransactionReader tx meta check (#2936)
Browse files Browse the repository at this point in the history
Due to a bug in Stellar-Core (more info in #2099) we check if the meta
version is at least 2 for protocol version < 10. However, some backend
like `HistoryArchiveBackend` do not return tx meta. For such backends we
should skip the check. The check is safe because each transaction has
fee changes associated with it so it will be empty if no meta is
available.
  • Loading branch information
bartekn authored Aug 20, 2020
1 parent a22aced commit f57b478
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
20 changes: 18 additions & 2 deletions exp/ingest/io/ledger_change_reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,11 +259,27 @@ func TestLedgerChangeReaderOrder(t *testing.T) {
t,
err,
"error extracting transactions from ledger close meta: TransactionMeta.V=2 is required in protocol"+
" version older than version 10. Please process ledgers again using stellar-core with "+
"SUPPORTED_META_VERSION=2 in the config file.",
" version older than version 10. Please process ledgers again using the latest stellar-core version.",
)
mock.AssertExpectations(t)

ledger.V0.LedgerHeader.Header.LedgerVersion = 9
ledger.V0.TxProcessing[0].FeeProcessing = xdr.LedgerEntryChanges{}
ledger.V0.TxProcessing[1].FeeProcessing = xdr.LedgerEntryChanges{}
mock.On("GetLedger", seq).Return(true, ledger, nil).Once()

assertChangesEqual(t, seq, mock, []balanceEntry{
{metaAddress, 300},
{metaAddress, 400},
{metaAddress, 600},
{metaAddress, 700},
{metaAddress, 800},
{metaAddress, 900},
{upgradeAddress, 2},
{upgradeAddress, 3},
})
mock.AssertExpectations(t)

ledger.V0.LedgerHeader.Header.LedgerVersion = 10
ledger.V0.TxProcessing[0].FeeProcessing = xdr.LedgerEntryChanges{}
ledger.V0.TxProcessing[1].FeeProcessing = xdr.LedgerEntryChanges{}
Expand Down
7 changes: 5 additions & 2 deletions exp/ingest/io/ledger_transaction_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,13 @@ func (reader *LedgerTransactionReader) storeTransactions(lcm xdr.LedgerCloseMeta
return errors.Errorf("unknown tx hash in LedgerCloseMeta: %v", hexHash)
}

if lcm.V0.LedgerHeader.Header.LedgerVersion < 10 && lcm.V0.TxProcessing[i].TxApplyProcessing.V != 2 {
// We check the version only if FeeProcessing are non empty because some backends
// (like HistoryArchiveBackend) do not return meta.
if lcm.V0.LedgerHeader.Header.LedgerVersion < 10 && lcm.V0.TxProcessing[i].TxApplyProcessing.V != 2 &&
len(lcm.V0.TxProcessing[i].FeeProcessing) > 0 {
return errors.New(
"TransactionMeta.V=2 is required in protocol version older than version 10. " +
"Please process ledgers again using stellar-core with SUPPORTED_META_VERSION=2 in the config file.",
"Please process ledgers again using the latest stellar-core version.",
)
}

Expand Down

0 comments on commit f57b478

Please sign in to comment.