-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add common interface between in-memory and on-disk transaction storage
- Loading branch information
Showing
5 changed files
with
68 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
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{} | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters