From 217cfc63ec95f3a5207ac820c5237493a9fe70ff Mon Sep 17 00:00:00 2001 From: nabarun Date: Mon, 30 May 2022 17:24:14 +0530 Subject: [PATCH] Return empty headerCIDs and commit db tx --- pkg/eth/cid_retriever.go | 3 --- pkg/eth/ipld_fetcher.go | 4 ++++ pkg/graphql/graphql.go | 21 +++++++++++++++++++++ pkg/graphql/schema.go | 5 ----- 4 files changed, 25 insertions(+), 8 deletions(-) diff --git a/pkg/eth/cid_retriever.go b/pkg/eth/cid_retriever.go index 81190809..206ca791 100644 --- a/pkg/eth/cid_retriever.go +++ b/pkg/eth/cid_retriever.go @@ -644,9 +644,6 @@ func (ecr *CIDRetriever) RetrieveHeaderAndTxCIDsByBlockNumber(blockNumber int64) log.Error("header cid retrieval error") return nil, nil, err } - if len(headerCIDs) < 1 { - return nil, nil, fmt.Errorf("header cid retrieval error, no header CIDs found at block %d", blockNumber) - } var allTxCIDs [][]models.TxModel txCIDs, err := ecr.RetrieveTxCIDsByBlockNumber(tx, blockNumber) diff --git a/pkg/eth/ipld_fetcher.go b/pkg/eth/ipld_fetcher.go index 6b191eb8..965028c1 100644 --- a/pkg/eth/ipld_fetcher.go +++ b/pkg/eth/ipld_fetcher.go @@ -119,6 +119,10 @@ func (f *IPLDFetcher) FetchHeaders(tx *sqlx.Tx, cids []models.HeaderModel) ([]mo log.Debug("fetching header iplds") headerIPLDs := make([]models.IPLDModel, len(cids)) + if len(cids) < 1 { + return headerIPLDs, nil + } + blockNumbers := make([]uint64, len(cids)) mhKeys := make([]string, len(cids)) for i, c := range cids { diff --git a/pkg/graphql/graphql.go b/pkg/graphql/graphql.go index c5553993..19480ab5 100644 --- a/pkg/graphql/graphql.go +++ b/pkg/graphql/graphql.go @@ -36,6 +36,7 @@ import ( "github.com/ethereum/go-ethereum/statediff/indexer/models" "github.com/vulcanize/ipld-eth-server/v3/pkg/eth" + "github.com/vulcanize/ipld-eth-server/v3/pkg/shared" ) var ( @@ -1288,6 +1289,16 @@ func (r *Resolver) AllEthHeaderCids(ctx context.Context, args struct { if err != nil { return nil, err } + defer func() { + if p := recover(); p != nil { + shared.Rollback(tx) + panic(p) + } else if err != nil { + shared.Rollback(tx) + } else { + err = tx.Commit() + } + }() headerIPLDs, err := r.backend.Fetcher.FetchHeaders(tx, headerCIDs) if err != nil { @@ -1357,6 +1368,16 @@ func (r *Resolver) EthTransactionCidByTxHash(ctx context.Context, args struct { if err != nil { return nil, err } + defer func() { + if p := recover(); p != nil { + shared.Rollback(tx) + panic(p) + } else if err != nil { + shared.Rollback(tx) + } else { + err = tx.Commit() + } + }() txIPLDs, err := r.backend.Fetcher.FetchTrxs(tx, []models.TxModel{txCID}) if err != nil { diff --git a/pkg/graphql/schema.go b/pkg/graphql/schema.go index 48a2309c..eb0d89fc 100644 --- a/pkg/graphql/schema.go +++ b/pkg/graphql/schema.go @@ -29,8 +29,6 @@ const schema string = ` scalar BigInt # Long is a 64 bit unsigned integer. scalar Long - # BigFloat is a floating point number. - scalar BigFloat schema { query: Query @@ -313,10 +311,7 @@ const schema string = ` parentHash: String! timestamp: BigInt! stateRoot: String! - - # TODO: Use BigFloat td: BigInt! - txRoot: String! receiptRoot: String! uncleRoot: String!