Skip to content

Commit

Permalink
fix queryTx not checking db
Browse files Browse the repository at this point in the history
  • Loading branch information
tok-kkk committed Jun 17, 2022
1 parent dc07e80 commit 949e5cf
Showing 1 changed file with 30 additions and 20 deletions.
50 changes: 30 additions & 20 deletions resolver/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -373,37 +373,46 @@ func (resolver *Resolver) QueryTx(ctx context.Context, id interface{}, params *j
v0tx = true
}

if newHash, err := resolver.gpubkeyStore.UpdatedHash(params.TxHash); err == nil {
// A gpubkey compat hash exists in the cache, so we use that to perform
// the query instead.
params.TxHash = newHash
}

// Check the tx hash before the compat mapping
status, err := resolver.db.TxStatus(params.TxHash)
if err != nil {
if err != sql.ErrNoRows {
resolver.logger.Errorf("[responder] cannot get tx status from db: %v", err)
// some error handling
jsonErr := jsonrpc.NewError(jsonrpc.ErrorCodeInternal, "failed to read tx from db", nil)
return jsonrpc.NewResponse(id, nil, &jsonErr)
}
// Try to get the standard tx hash if tx not found from db
if newHash, err := resolver.compatStore.GetStandardHash(params.TxHash); err == nil {
}

// Try the gpubkeyStore
if status == db.TxStatusNil {
if newHash, err := resolver.gpubkeyStore.UpdatedHash(params.TxHash); err == nil {
// A gpubkey compat hash exists in the cache, so we use that to perform
// the query instead.
params.TxHash = newHash

status, err = resolver.db.TxStatus(params.TxHash)
if err != nil {
if err != sql.ErrNoRows {
resolver.logger.Errorf("[responder] cannot get tx status from db: %v", err)
jsonErr := jsonrpc.NewError(jsonrpc.ErrorCodeInternal, "failed to read tx from db", nil)
return jsonrpc.NewResponse(id, nil, &jsonErr)
}
}
}
}

// Retrieve transaction status from the database.
status, err = resolver.db.TxStatus(params.TxHash)
if err != nil {
// Send the request to the Darknodes if we do not have it in our
// database.
if err != sql.ErrNoRows {
resolver.logger.Errorf("[responder] cannot get tx status from db: %v", err)
// some error handling
jsonErr := jsonrpc.NewError(jsonrpc.ErrorCodeInternal, "failed to read tx from db", nil)
return jsonrpc.NewResponse(id, nil, &jsonErr)
// Try the compat store
if status == db.TxStatusNil {
if newHash, err := resolver.compatStore.GetStandardHash(params.TxHash); err == nil {
params.TxHash = newHash

status, err = resolver.db.TxStatus(params.TxHash)
if err != nil {
if err != sql.ErrNoRows {
resolver.logger.Errorf("[responder] cannot get tx status from db: %v", err)
jsonErr := jsonrpc.NewError(jsonrpc.ErrorCodeInternal, "failed to read tx from db", nil)
return jsonrpc.NewResponse(id, nil, &jsonErr)
}
}
}
}

Expand Down Expand Up @@ -445,6 +454,7 @@ func (resolver *Resolver) QueryTx(ctx context.Context, id interface{}, params *j
query = req.URL.Query()
}

// Send the request to the Darknodes if we do not have it in our database.
reqWithResponder := lhttp.NewRequestWithResponder(ctx, id, jsonrpc.MethodQueryTx, params, query)
if ok := resolver.cacher.Send(reqWithResponder); !ok {
resolver.logger.Error("failed to send request to cacher, too much back pressure")
Expand Down

0 comments on commit 949e5cf

Please sign in to comment.