From 9a98d4f50377eac9b6421125a82ee241d5027e12 Mon Sep 17 00:00:00 2001 From: George Kudrayvtsev Date: Mon, 15 Apr 2024 14:45:25 -0700 Subject: [PATCH] Revert "Add common interface between in-memory and on-disk transaction storage" This reverts commit 3196ade050bfa3ac300dab37fadaa89b2bc08cc4. --- cmd/soroban-rpc/internal/ingest/service.go | 7 ++- cmd/soroban-rpc/internal/jsonrpc.go | 2 +- .../internal/transactions/database.go | 45 ------------------- .../internal/transactions/interface.go | 15 ------- .../{memory.go => transactions.go} | 4 +- 5 files changed, 5 insertions(+), 68 deletions(-) delete mode 100644 cmd/soroban-rpc/internal/transactions/database.go delete mode 100644 cmd/soroban-rpc/internal/transactions/interface.go rename cmd/soroban-rpc/internal/transactions/{memory.go => transactions.go} (99%) diff --git a/cmd/soroban-rpc/internal/ingest/service.go b/cmd/soroban-rpc/internal/ingest/service.go index 2abaf17b..931abfe8 100644 --- a/cmd/soroban-rpc/internal/ingest/service.go +++ b/cmd/soroban-rpc/internal/ingest/service.go @@ -34,7 +34,7 @@ type Config struct { Logger *log.Entry DB db.ReadWriter EventStore *events.MemoryStore - TransactionStore transactions.TransactionStore + TransactionStore *transactions.MemoryStore NetworkPassPhrase string Archive historyarchive.ArchiveInterface LedgerBackend backends.LedgerBackend @@ -134,7 +134,7 @@ type Service struct { logger *log.Entry db db.ReadWriter eventStore *events.MemoryStore - transactionStore transactions.TransactionStore + transactionStore *transactions.MemoryStore ledgerBackend backends.LedgerBackend timeout time.Duration networkPassPhrase string @@ -308,8 +308,7 @@ func (s *Service) ingestLedgerCloseMeta(tx db.WriteTx, ledgerCloseMeta xdr.Ledge return err } s.metrics.ingestionDurationMetric. - With(prometheus.Labels{"type": "ledger_close_meta"}). - Observe(time.Since(startTime).Seconds()) + With(prometheus.Labels{"type": "ledger_close_meta"}).Observe(time.Since(startTime).Seconds()) if err := s.eventStore.IngestEvents(ledgerCloseMeta); err != nil { return err diff --git a/cmd/soroban-rpc/internal/jsonrpc.go b/cmd/soroban-rpc/internal/jsonrpc.go index 1fb5d678..b0ceb372 100644 --- a/cmd/soroban-rpc/internal/jsonrpc.go +++ b/cmd/soroban-rpc/internal/jsonrpc.go @@ -47,7 +47,7 @@ func (h Handler) Close() { type HandlerParams struct { EventStore *events.MemoryStore - TransactionStore transactions.TransactionStore + TransactionStore *transactions.MemoryStore LedgerEntryReader db.LedgerEntryReader LedgerReader db.LedgerReader Logger *log.Entry diff --git a/cmd/soroban-rpc/internal/transactions/database.go b/cmd/soroban-rpc/internal/transactions/database.go deleted file mode 100644 index 40994127..00000000 --- a/cmd/soroban-rpc/internal/transactions/database.go +++ /dev/null @@ -1,45 +0,0 @@ -package transactions - -import ( - "sync" - - "github.com/prometheus/client_golang/prometheus" - "github.com/stellar/go/xdr" - - "github.com/stellar/soroban-rpc/cmd/soroban-rpc/internal/daemon/interfaces" - "github.com/stellar/soroban-rpc/cmd/soroban-rpc/internal/ledgerbucketwindow" -) - -// DatabaseStore is an on-disk (sqlite) store of Stellar transactions. -type DatabaseStore struct { - // passphrase is an immutable string containing the Stellar network - // passphrase and accessing it does not need to be protected by the lock - passphrase string - - lock sync.RWMutex - transactions map[xdr.Hash]transaction - transactionsByLedger *ledgerbucketwindow.LedgerBucketWindow[[]xdr.Hash] - transactionDurationMetric *prometheus.SummaryVec - transactionCountMetric prometheus.Summary -} - -func NewDatabaseStore(daemon interfaces.Daemon, networkPassphrase string, retentionWindow uint32) TransactionStore { - return NewMemoryStore(daemon, networkPassphrase, retentionWindow) -} - -// func (m *DatabaseStore) IngestTransactions(ledgerCloseMeta xdr.LedgerCloseMeta) error { -// // startTime := time.Now() -// return nil -// } - -// // GetLedgerRange returns the first and latest ledger available in the store. -// func (m *DatabaseStore) GetLedgerRange() ledgerbucketwindow.LedgerRange { -// m.lock.RLock() -// defer m.lock.RUnlock() -// return m.transactionsByLedger.GetLedgerRange() -// } - -// // GetTransaction obtains a transaction from the store and whether it's present and the current store range -// func (m *DatabaseStore) GetTransaction(hash xdr.Hash) (Transaction, bool, ledgerbucketwindow.LedgerRange) { -// return Transaction{}, false, ledgerbucketwindow.LedgerRange{} -// } diff --git a/cmd/soroban-rpc/internal/transactions/interface.go b/cmd/soroban-rpc/internal/transactions/interface.go deleted file mode 100644 index 65fc6f13..00000000 --- a/cmd/soroban-rpc/internal/transactions/interface.go +++ /dev/null @@ -1,15 +0,0 @@ -package transactions - -import ( - "github.com/stellar/go/xdr" - - "github.com/stellar/soroban-rpc/cmd/soroban-rpc/internal/ledgerbucketwindow" -) - -// TransactionStore lets you ingest (write) and query (read) transactions from -// an abstract backend storage (i.e. via in-memory or sqlite). -type TransactionStore interface { - IngestTransactions(ledgerCloseMeta xdr.LedgerCloseMeta) error - GetLedgerRange() ledgerbucketwindow.LedgerRange - GetTransaction(hash xdr.Hash) (Transaction, bool, ledgerbucketwindow.LedgerRange) -} diff --git a/cmd/soroban-rpc/internal/transactions/memory.go b/cmd/soroban-rpc/internal/transactions/transactions.go similarity index 99% rename from cmd/soroban-rpc/internal/transactions/memory.go rename to cmd/soroban-rpc/internal/transactions/transactions.go index 3a312363..e5abe55c 100644 --- a/cmd/soroban-rpc/internal/transactions/memory.go +++ b/cmd/soroban-rpc/internal/transactions/transactions.go @@ -43,7 +43,7 @@ type MemoryStore struct { // will be included in the MemoryStore. If the MemoryStore // is full, any transactions from new ledgers will evict // older entries outside the retention window. -func NewMemoryStore(daemon interfaces.Daemon, networkPassphrase string, retentionWindow uint32) TransactionStore { +func NewMemoryStore(daemon interfaces.Daemon, networkPassphrase string, retentionWindow uint32) *MemoryStore { window := ledgerbucketwindow.NewLedgerBucketWindow[[]xdr.Hash](retentionWindow) // transactionDurationMetric is a metric for measuring latency of transaction store operations @@ -75,7 +75,6 @@ func NewMemoryStore(daemon interfaces.Daemon, networkPassphrase string, retentio // removed from the store. func (m *MemoryStore) IngestTransactions(ledgerCloseMeta xdr.LedgerCloseMeta) error { startTime := time.Now() - reader, err := ingest.NewLedgerTransactionReaderFromLedgerCloseMeta(m.networkPassphrase, ledgerCloseMeta) if err != nil { return err @@ -136,7 +135,6 @@ func (m *MemoryStore) IngestTransactions(ledgerCloseMeta xdr.LedgerCloseMeta) er for hash, tx := range hashMap { m.transactions[hash] = tx } - m.transactionDurationMetric.With(prometheus.Labels{"operation": "ingest"}).Observe(time.Since(startTime).Seconds()) m.transactionCountMetric.Observe(float64(txCount)) return nil