Skip to content

Commit

Permalink
Drop Soroban metadata from being stored
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaptic committed Jan 19, 2024
1 parent 33bf9b6 commit acb854f
Show file tree
Hide file tree
Showing 2 changed files with 132 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,33 @@ func transactionToRow(transaction ingest.LedgerTransaction, sequence uint32, enc
if err != nil {
return TransactionWithoutLedger{}, err
}
metaBase64, err := encodingBuffer.MarshalBase64(transaction.UnsafeMeta)

// We intentionally avoid ingestion of transaction metadata for Soroban
// transactions after Protocol 20 due to performance concerns:
// - Soroban @ 10/tps adds 30-100% txmeta/ledger
// - Soroban @ 150/tps means Horizon is unable to ingest meta
// - the data is not ergonomic
// - this data is available in Soroban RPC
//
// https://stellarfoundation.slack.com/archives/C02B04RMK/p1705624375148539
//
// In order to avoid breakage, we instead just make the meta appear empty.
var metaBase64 string
if transaction.UnsafeMeta.V == 3 &&
transaction.UnsafeMeta.MustV3().SorobanMeta != nil {
transaction.UnsafeMeta.V3 = &xdr.TransactionMetaV3{
Ext: xdr.ExtensionPoint{},
TxChangesBefore: xdr.LedgerEntryChanges{},
Operations: []xdr.OperationMeta{},
TxChangesAfter: xdr.LedgerEntryChanges{},
SorobanMeta: nil,
}
}
metaBase64, err = encodingBuffer.MarshalBase64(transaction.UnsafeMeta)
if err != nil {
return TransactionWithoutLedger{}, err
}

feeMetaBase64, err := encodingBuffer.MarshalBase64(transaction.FeeChanges)
if err != nil {
return TransactionWithoutLedger{}, err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/guregu/null"
"github.com/lib/pq"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/stellar/go/ingest"
"github.com/stellar/go/xdr"
Expand Down Expand Up @@ -276,3 +277,110 @@ func TestTransactionToMap_Preconditions(t *testing.T) {
assert.Equal(t, null.IntFrom(3), row.MinAccountSequenceLedgerGap)
assert.Equal(t, pq.StringArray{signerKey.Address()}, row.ExtraSigners)
}

func TestTransactionsDropSorobanTxMeta(t *testing.T) {

Check failure on line 281 in services/horizon/internal/db2/history/transaction_batch_insert_builder_test.go

View workflow job for this annotation

GitHub Actions / golangci

Function 'TestTransactionsDropSorobanTxMeta' is too long (104 > 100) (funlen)
truth := true
minSeqNum := xdr.SequenceNumber(math.MaxInt64)
source := xdr.MuxedAccount{
Type: xdr.CryptoKeyTypeKeyTypeEd25519,
Ed25519: &xdr.Uint256{3, 2, 1},
}
signerKey := xdr.SignerKey{
Type: xdr.SignerKeyTypeSignerKeyTypeEd25519,
Ed25519: source.Ed25519,
}
tx := ingest.LedgerTransaction{
Index: 1,
Envelope: xdr.TransactionEnvelope{

Check failure on line 294 in services/horizon/internal/db2/history/transaction_batch_insert_builder_test.go

View workflow job for this annotation

GitHub Actions / golangci

294-332 lines are duplicate of `services/horizon/internal/db2/history/transaction_batch_insert_builder_test.go:201-239` (dupl)
Type: xdr.EnvelopeTypeEnvelopeTypeTx,
V1: &xdr.TransactionV1Envelope{
Tx: xdr.Transaction{
SourceAccount: source,
Operations: []xdr.Operation{
{
SourceAccount: &source,
Body: xdr.OperationBody{
Type: xdr.OperationTypePayment,
PaymentOp: &xdr.PaymentOp{
Destination: source,
Asset: xdr.Asset{Type: xdr.AssetTypeAssetTypeNative},
Amount: 100,
},
},
},
},
Cond: xdr.Preconditions{
Type: xdr.PreconditionTypePrecondV2,
V2: &xdr.PreconditionsV2{
// The important bit.
TimeBounds: &xdr.TimeBounds{
MinTime: 1000,
MaxTime: 2000,
},
LedgerBounds: &xdr.LedgerBounds{
MinLedger: 5,
MaxLedger: 10,
},
MinSeqNum: &minSeqNum,
MinSeqAge: xdr.Duration(math.MaxUint64),
MinSeqLedgerGap: xdr.Uint32(3),
ExtraSigners: []xdr.SignerKey{signerKey},
},
},
},
},
},
Result: xdr.TransactionResultPair{
TransactionHash: xdr.Hash{1, 2, 3},
Result: xdr.TransactionResult{
Result: xdr.TransactionResultResult{
Code: xdr.TransactionResultCodeTxFeeBumpInnerSuccess,
InnerResultPair: &xdr.InnerTransactionResultPair{
TransactionHash: xdr.Hash{3, 2, 1},
Result: xdr.InnerTransactionResult{
Result: xdr.InnerTransactionResultResult{
Results: &[]xdr.OperationResult{},
},
},
},
Results: &[]xdr.OperationResult{},
},
},
},
UnsafeMeta: xdr.TransactionMeta{
V: 3,
Operations: &[]xdr.OperationMeta{},
V3: &xdr.TransactionMetaV3{
TxChangesBefore: []xdr.LedgerEntryChange{
{
Type: xdr.LedgerEntryChangeTypeLedgerEntryUpdated,
},
{
Type: xdr.LedgerEntryChangeTypeLedgerEntryCreated,
},
},
Operations: []xdr.OperationMeta{{}},
TxChangesAfter: []xdr.LedgerEntryChange{{
Type: xdr.LedgerEntryChangeTypeLedgerEntryRemoved,
}},
SorobanMeta: &xdr.SorobanTransactionMeta{
ReturnValue: xdr.ScVal{Type: xdr.ScValTypeScvBool, B: &truth},
},
},
},
}

encoder := xdr.NewEncodingBuffer()
processedTx, err := transactionToRow(tx, 123, encoder)
require.NoError(t, err)

var meta xdr.TransactionMeta
err = xdr.SafeUnmarshalBase64(processedTx.TxMeta, &meta)
require.NoError(t, err)

require.NotNil(t, meta.V3)
require.Empty(t, meta.V3.Operations)
require.Empty(t, meta.V3.TxChangesAfter)
require.Empty(t, meta.V3.TxChangesBefore)
require.Nil(t, meta.V3.SorobanMeta)
}

0 comments on commit acb854f

Please sign in to comment.