Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LogMethodDuration calls to host interface #1902

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions go/host/storage/init/sqlite/001_init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,16 @@ create table if not exists batch_host
create index IDX_BATCH_HASH_HOST on batch_host (hash);
create index IDX_BATCH_HEIGHT_HOST on batch_host (height);


create table if not exists transaction_host
(
hash binary(16) PRIMARY KEY,
full_hash binary(32) NOT NULL UNIQUE,
b_sequence int REFERENCES batch_host
);

create index IDX_TX_SEQ_HOST ON transaction_host (b_sequence);

create table if not exists transaction_count
(
id int NOT NULL PRIMARY KEY,
Expand Down
27 changes: 27 additions & 0 deletions go/host/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import (
"fmt"
"github.com/ten-protocol/go-ten/go/common/measure"

Check failure on line 5 in go/host/storage/storage.go

View workflow job for this annotation

GitHub Actions / lint

File is not `goimports`-ed (goimports)
"github.com/ten-protocol/go-ten/go/enclave/core"
"io"
"math/big"

Expand All @@ -22,6 +24,7 @@
}

func (s *storageImpl) AddBatch(batch *common.ExtBatch) error {
defer core.LogMethodDuration(s.logger, measure.NewStopwatch(), "Add batch", log.BatchHashKey, batch.Hash())
// Check if the Batch is already stored
_, err := hostdb.GetBatchHeader(s.db, batch.Hash())
if err == nil {
Expand All @@ -47,6 +50,7 @@
}

func (s *storageImpl) AddRollup(rollup *common.ExtRollup, metadata *common.PublicRollupMetadata, block *common.L1Block) error {
defer core.LogMethodDuration(s.logger, measure.NewStopwatch(), "Add rollup", log.RollupHashKey, rollup.Hash())
// Check if the Header is already stored
_, err := hostdb.GetRollupHeader(s.db, rollup.Header.Hash())
if err == nil {
Expand All @@ -72,6 +76,7 @@
}

func (s *storageImpl) AddBlock(b *types.Header, rollupHash common.L2RollupHash) error {
defer core.LogMethodDuration(s.logger, measure.NewStopwatch(), "Add block", log.BlockHashKey, b.Hash())
dbtx, err := s.db.NewDBTransaction()
if err != nil {
return err
Expand All @@ -91,90 +96,112 @@
}

func (s *storageImpl) FetchBatchBySeqNo(seqNum uint64) (*common.ExtBatch, error) {
defer core.LogMethodDuration(s.logger, measure.NewStopwatch(), "Fetch batch by seq no", log.BatchSeqNoKey, seqNum)
return hostdb.GetBatchBySequenceNumber(s.db, seqNum)
}

func (s *storageImpl) FetchBatchHashByHeight(number *big.Int) (*gethcommon.Hash, error) {
defer core.LogMethodDuration(s.logger, measure.NewStopwatch(), "Fetch batch by height", log.BatchHeightKey, number.Uint64())
return hostdb.GetBatchHashByNumber(s.db, number)
}

func (s *storageImpl) FetchBatchHeaderByHash(hash gethcommon.Hash) (*common.BatchHeader, error) {
defer core.LogMethodDuration(s.logger, measure.NewStopwatch(), "Fetch batch by hash", log.BatchHashKey, hash)
return hostdb.GetBatchHeader(s.db, hash)
}

func (s *storageImpl) FetchHeadBatchHeader() (*common.BatchHeader, error) {
defer core.LogMethodDuration(s.logger, measure.NewStopwatch(), "Fetch head batch header")
return hostdb.GetHeadBatchHeader(s.db)
}

func (s *storageImpl) FetchPublicBatchByHash(batchHash common.L2BatchHash) (*common.PublicBatch, error) {
defer core.LogMethodDuration(s.logger, measure.NewStopwatch(), "Fetch public batch by hash", log.BatchHashKey, batchHash)
return hostdb.GetPublicBatch(s.db, batchHash)
}

func (s *storageImpl) FetchBatch(batchHash gethcommon.Hash) (*common.ExtBatch, error) {
defer core.LogMethodDuration(s.logger, measure.NewStopwatch(), "Fetch batch by hash", log.BatchHashKey, batchHash)
return hostdb.GetBatchByHash(s.db, batchHash)
}

func (s *storageImpl) FetchBatchByTx(txHash gethcommon.Hash) (*common.ExtBatch, error) {
defer core.LogMethodDuration(s.logger, measure.NewStopwatch(), "Fetch batch by transaction", log.TxKey, txHash)
return hostdb.GetBatchByTx(s.db, txHash)
}

func (s *storageImpl) FetchLatestBatch() (*common.BatchHeader, error) {
defer core.LogMethodDuration(s.logger, measure.NewStopwatch(), "Fetch latest batch")
return hostdb.GetLatestBatch(s.db)
}

func (s *storageImpl) FetchBatchHeaderByHeight(height *big.Int) (*common.BatchHeader, error) {
defer core.LogMethodDuration(s.logger, measure.NewStopwatch(), "Fetch batch header by height", log.BatchHeightKey, height.Uint64())
return hostdb.GetBatchHeaderByHeight(s.db, height)
}

func (s *storageImpl) FetchBatchByHeight(height *big.Int) (*common.PublicBatch, error) {
defer core.LogMethodDuration(s.logger, measure.NewStopwatch(), "Fetch batch by height", log.BatchHeightKey, height.Uint64())
return hostdb.GetBatchByHeight(s.db, height)
}

func (s *storageImpl) FetchBatchListing(pagination *common.QueryPagination) (*common.BatchListingResponse, error) {
defer core.LogMethodDuration(s.logger, measure.NewStopwatch(), "Fetch batch listing")
return hostdb.GetBatchListing(s.db, pagination)
}

func (s *storageImpl) FetchBatchListingDeprecated(pagination *common.QueryPagination) (*common.BatchListingResponseDeprecated, error) {
defer core.LogMethodDuration(s.logger, measure.NewStopwatch(), "Fetch batch listing (deprecated)")
return hostdb.GetBatchListingDeprecated(s.db, pagination)
}

func (s *storageImpl) FetchLatestRollupHeader() (*common.RollupHeader, error) {
defer core.LogMethodDuration(s.logger, measure.NewStopwatch(), "Fetch latest rollup header")
return hostdb.GetLatestRollup(s.db)
}

func (s *storageImpl) FetchRollupListing(pagination *common.QueryPagination) (*common.RollupListingResponse, error) {
defer core.LogMethodDuration(s.logger, measure.NewStopwatch(), "Fetch rollup listing")
return hostdb.GetRollupListing(s.db, pagination)
}

func (s *storageImpl) FetchBlockListing(pagination *common.QueryPagination) (*common.BlockListingResponse, error) {
defer core.LogMethodDuration(s.logger, measure.NewStopwatch(), "Fetch block listing")
return hostdb.GetBlockListing(s.db, pagination)
}

func (s *storageImpl) FetchTotalTxCount() (*big.Int, error) {
defer core.LogMethodDuration(s.logger, measure.NewStopwatch(), "Fetch total transaction count")
return hostdb.GetTotalTxCount(s.db)
}

func (s *storageImpl) FetchTransaction(hash gethcommon.Hash) (*common.PublicTransaction, error) {
defer core.LogMethodDuration(s.logger, measure.NewStopwatch(), "Fetch transaction by hash", log.TxKey, hash)
return hostdb.GetTransaction(s.db, hash)
}

func (s *storageImpl) FetchRollupByHash(rollupHash gethcommon.Hash) (*common.PublicRollup, error) {
defer core.LogMethodDuration(s.logger, measure.NewStopwatch(), "Fetch rollup by hash", log.RollupHashKey, rollupHash)
return hostdb.GetRollupByHash(s.db, rollupHash)
}

func (s *storageImpl) FetchRollupBySeqNo(seqNo uint64) (*common.PublicRollup, error) {
defer core.LogMethodDuration(s.logger, measure.NewStopwatch(), "Fetch rollup by sequence number", log.RollupHashKey, seqNo)
return hostdb.GetRollupBySeqNo(s.db, seqNo)
}

func (s *storageImpl) FetchRollupBatches(rollupHash gethcommon.Hash) (*common.BatchListingResponse, error) {
defer core.LogMethodDuration(s.logger, measure.NewStopwatch(), "Fetch rollup batches", log.RollupHashKey, rollupHash)
return hostdb.GetRollupBatches(s.db, rollupHash)
}

func (s *storageImpl) FetchBatchTransactions(batchHash gethcommon.Hash) (*common.TransactionListingResponse, error) {
defer core.LogMethodDuration(s.logger, measure.NewStopwatch(), "Fetch batch transactions", log.BatchHashKey, batchHash)
return hostdb.GetBatchTransactions(s.db, batchHash)
}

func (s *storageImpl) FetchTransactionListing(pagination *common.QueryPagination) (*common.TransactionListingResponse, error) {
defer core.LogMethodDuration(s.logger, measure.NewStopwatch(), "Fetch transaction listing")
return hostdb.GetTransactionListing(s.db, pagination)
}

Expand Down
Loading