Skip to content

Commit

Permalink
Drop all references to the in-memory transaction store
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaptic committed Apr 16, 2024
1 parent dcbe0c0 commit 17206d1
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 672 deletions.
11 changes: 0 additions & 11 deletions cmd/soroban-rpc/internal/daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
"github.com/stellar/soroban-rpc/cmd/soroban-rpc/internal/ingest"
"github.com/stellar/soroban-rpc/cmd/soroban-rpc/internal/ledgerbucketwindow"
"github.com/stellar/soroban-rpc/cmd/soroban-rpc/internal/preflight"
"github.com/stellar/soroban-rpc/cmd/soroban-rpc/internal/transactions"
"github.com/stellar/soroban-rpc/cmd/soroban-rpc/internal/util"
)

Expand Down Expand Up @@ -190,11 +189,6 @@ func MustNew(cfg *config.Config) *Daemon {
cfg.NetworkPassphrase,
cfg.EventLedgerRetentionWindow,
)
transactionStore := transactions.NewMemoryStore(
daemon,
cfg.NetworkPassphrase,
cfg.TransactionLedgerRetentionWindow,
)

// initialize the stores using what was on the DB
readTxMetaCtx, cancelReadTxMeta := context.WithTimeout(context.Background(), cfg.IngestionTimeout)
Expand All @@ -219,9 +213,6 @@ func MustNew(cfg *config.Config) *Daemon {
if err := eventStore.IngestEvents(txmeta); err != nil {
logger.WithError(err).Fatal("could not initialize event memory store")
}
if err := transactionStore.IngestTransactions(txmeta); err != nil {
logger.WithError(err).Fatal("could not initialize transaction memory store")
}
return nil
})
if currentSeq != 0 {
Expand All @@ -246,7 +237,6 @@ func MustNew(cfg *config.Config) *Daemon {
Logger: logger,
DB: db.NewReadWriter(dbConn, maxLedgerEntryWriteBatchSize, maxRetentionWindow),
EventStore: eventStore,
TransactionStore: transactionStore,
NetworkPassPhrase: cfg.NetworkPassphrase,
Archive: historyArchive,
LedgerBackend: core,
Expand All @@ -269,7 +259,6 @@ func MustNew(cfg *config.Config) *Daemon {
jsonRPCHandler := internal.NewJSONRPCHandler(cfg, internal.HandlerParams{
Daemon: daemon,
EventStore: eventStore,
TransactionStore: transactionStore,
Logger: logger,
LedgerReader: db.NewLedgerReader(dbConn),
LedgerEntryReader: db.NewLedgerEntryReader(dbConn),
Expand Down
32 changes: 18 additions & 14 deletions cmd/soroban-rpc/internal/db/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@ const (
transactionTableName = "transactions"
)

type Transaction struct {
Result []byte // XDR encoded xdr.TransactionResult
Meta []byte // XDR encoded xdr.TransactionMeta
Envelope []byte // XDR encoded xdr.TransactionEnvelope
Events [][]byte // XDR encoded xdr.DiagnosticEvent
FeeBump bool
ApplicationOrder int32
Successful bool
Ledger ledgerbucketwindow.LedgerInfo
}

type TransactionHandler struct {
stmtCache *sq.StmtCache
db db.SessionInterface
Expand Down Expand Up @@ -58,10 +69,7 @@ func (txn *TransactionHandler) InsertTransactions(lcm xdr.LedgerCloseMeta) error
return err
}

func (txn *TransactionHandler) GetLedgerRange() (
ledgerbucketwindow.LedgerRange,
error,
) {
func (txn *TransactionHandler) GetLedgerRange() ledgerbucketwindow.LedgerRange {
var ledgerRange ledgerbucketwindow.LedgerRange
newestQ := sq.
Select("meta").
Expand All @@ -80,18 +88,18 @@ func (txn *TransactionHandler) GetLedgerRange() (

var row1, row2 []byte
if err := newestQ.Scan(&row1); err != nil {
return ledgerRange, err
return ledgerRange
}
if err := oldestQ.Scan(&row2); err != nil {
return ledgerRange, err
return ledgerRange
}

var lcm1, lcm2 xdr.LedgerCloseMeta
if err := lcm1.UnmarshalBinary(row1); err != nil {
return ledgerRange, err
return ledgerRange
}
if err := lcm2.UnmarshalBinary(row2); err != nil {
return ledgerRange, err
return ledgerRange
}

return ledgerbucketwindow.LedgerRange{
Expand All @@ -103,7 +111,7 @@ func (txn *TransactionHandler) GetLedgerRange() (
Sequence: lcm2.LedgerSequence(),
CloseTime: int64(lcm2.LedgerHeaderHistoryEntry().Header.ScpValue.CloseTime),
},
}, nil
}
}

func (txn *TransactionHandler) GetTransactionByHash(hash string) (
Expand Down Expand Up @@ -148,11 +156,7 @@ func (txn *TransactionHandler) GetTransaction(hash xdr.Hash) (
) {
tx := transactions.Transaction{}

ledgerRange, err := txn.GetLedgerRange()
if err != nil {
return tx, false, ledgerRange
}

ledgerRange := txn.GetLedgerRange()
lcm, ingestTx, err := txn.GetTransactionByHash(hex.EncodeToString(hash[:]))
if err != nil {
return tx, false, ledgerRange
Expand Down
8 changes: 0 additions & 8 deletions cmd/soroban-rpc/internal/ingest/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"github.com/stellar/soroban-rpc/cmd/soroban-rpc/internal/util"

"github.com/stellar/soroban-rpc/cmd/soroban-rpc/internal/events"
"github.com/stellar/soroban-rpc/cmd/soroban-rpc/internal/transactions"
)

const (
Expand All @@ -34,7 +33,6 @@ type Config struct {
Logger *log.Entry
DB db.ReadWriter
EventStore *events.MemoryStore
TransactionStore *transactions.MemoryStore
NetworkPassPhrase string
Archive historyarchive.ArchiveInterface
LedgerBackend backends.LedgerBackend
Expand Down Expand Up @@ -82,7 +80,6 @@ func newService(cfg Config) *Service {
logger: cfg.Logger,
db: cfg.DB,
eventStore: cfg.EventStore,
transactionStore: cfg.TransactionStore,
ledgerBackend: cfg.LedgerBackend,
networkPassPhrase: cfg.NetworkPassPhrase,
timeout: cfg.Timeout,
Expand Down Expand Up @@ -134,7 +131,6 @@ type Service struct {
logger *log.Entry
db db.ReadWriter
eventStore *events.MemoryStore
transactionStore *transactions.MemoryStore
ledgerBackend backends.LedgerBackend
timeout time.Duration
networkPassPhrase string
Expand Down Expand Up @@ -317,10 +313,6 @@ func (s *Service) ingestLedgerCloseMeta(tx db.WriteTx, ledgerCloseMeta xdr.Ledge
s.metrics.ingestionDurationMetric.
With(prometheus.Labels{"type": "ledger_close_meta"}).Observe(time.Since(startTime).Seconds())

if err := s.transactionStore.IngestTransactions(ledgerCloseMeta); err != nil {
return err
}

if err := s.eventStore.IngestEvents(ledgerCloseMeta); err != nil {
return err
}
Expand Down
3 changes: 0 additions & 3 deletions cmd/soroban-rpc/internal/ingest/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"github.com/stellar/soroban-rpc/cmd/soroban-rpc/internal/daemon/interfaces"
"github.com/stellar/soroban-rpc/cmd/soroban-rpc/internal/db"
"github.com/stellar/soroban-rpc/cmd/soroban-rpc/internal/events"
"github.com/stellar/soroban-rpc/cmd/soroban-rpc/internal/transactions"
)

type ErrorReadWriter struct {
Expand Down Expand Up @@ -46,7 +45,6 @@ func TestRetryRunningIngestion(t *testing.T) {
Logger: supportlog.New(),
DB: &ErrorReadWriter{},
EventStore: nil,
TransactionStore: nil,
NetworkPassPhrase: "",
Archive: nil,
LedgerBackend: nil,
Expand All @@ -71,7 +69,6 @@ func TestIngestion(t *testing.T) {
Logger: supportlog.New(),
DB: mockDB,
EventStore: events.NewMemoryStore(daemon, network.TestNetworkPassphrase, 1),
TransactionStore: transactions.NewMemoryStore(daemon, network.TestNetworkPassphrase, 1),
LedgerBackend: mockLedgerBackend,
Daemon: daemon,
NetworkPassPhrase: network.TestNetworkPassphrase,
Expand Down
16 changes: 9 additions & 7 deletions cmd/soroban-rpc/internal/jsonrpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"github.com/stellar/soroban-rpc/cmd/soroban-rpc/internal/events"
"github.com/stellar/soroban-rpc/cmd/soroban-rpc/internal/methods"
"github.com/stellar/soroban-rpc/cmd/soroban-rpc/internal/network"
"github.com/stellar/soroban-rpc/cmd/soroban-rpc/internal/transactions"
)

// maxHTTPRequestSize defines the largest request size that the http handler
Expand All @@ -47,7 +46,6 @@ func (h Handler) Close() {

type HandlerParams struct {
EventStore *events.MemoryStore
TransactionStore *transactions.MemoryStore
TransactionGetter *db.TransactionHandler
LedgerEntryReader db.LedgerEntryReader
LedgerReader db.LedgerReader
Expand Down Expand Up @@ -141,7 +139,7 @@ func NewJSONRPCHandler(cfg *config.Config, params HandlerParams) Handler {
var retentionWindow = cfg.EventLedgerRetentionWindow
if cfg.TransactionLedgerRetentionWindow > cfg.EventLedgerRetentionWindow {
retentionWindow = cfg.TransactionLedgerRetentionWindow
ledgerRangeGetter = params.TransactionStore
ledgerRangeGetter = params.TransactionGetter
}

handlers := []struct {
Expand Down Expand Up @@ -201,15 +199,19 @@ func NewJSONRPCHandler(cfg *config.Config, params HandlerParams) Handler {
requestDurationLimit: cfg.MaxGetTransactionExecutionDuration,
},
{
methodName: "sendTransaction",
underlyingHandler: methods.NewSendTransactionHandler(params.Daemon, params.Logger, params.TransactionStore, cfg.NetworkPassphrase),
methodName: "sendTransaction",
underlyingHandler: methods.NewSendTransactionHandler(
params.Daemon, params.Logger, params.TransactionGetter, cfg.NetworkPassphrase,
),
longName: "send_transaction",
queueLimit: cfg.RequestBacklogSendTransactionQueueLimit,
requestDurationLimit: cfg.MaxSendTransactionExecutionDuration,
},
{
methodName: "simulateTransaction",
underlyingHandler: methods.NewSimulateTransactionHandler(params.Logger, params.LedgerEntryReader, params.LedgerReader, params.PreflightGetter),
methodName: "simulateTransaction",
underlyingHandler: methods.NewSimulateTransactionHandler(
params.Logger, params.LedgerEntryReader, params.LedgerReader, params.PreflightGetter,
),
longName: "simulate_transaction",
queueLimit: cfg.RequestBacklogSimulateTransactionQueueLimit,
requestDurationLimit: cfg.MaxSimulateTransactionExecutionDuration,
Expand Down
Loading

0 comments on commit 17206d1

Please sign in to comment.