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

On API, include logs in block (when ?withLogs=true) #4127

Merged
merged 28 commits into from
Jun 2, 2022

Conversation

andreibancioiu
Copy link
Collaborator

@andreibancioiu andreibancioiu commented May 28, 2022

  • On Block API endpoint, include logs when the query parameter withLogs is set to true.

@andreibancioiu andreibancioiu self-assigned this May 28, 2022
@codecov-commenter
Copy link

codecov-commenter commented May 28, 2022

Codecov Report

❗ No coverage uploaded for pull request base (feat/rosetta@d71c33a). Click here to learn what that means.
The diff coverage is n/a.

❗ Current head 1af03c3 differs from pull request most recent head e0fbeee. Consider uploading reports for the commit e0fbeee to get more accurate results

@@               Coverage Diff               @@
##             feat/rosetta    #4127   +/-   ##
===============================================
  Coverage                ?   75.28%           
===============================================
  Files                   ?      626           
  Lines                   ?    82605           
  Branches                ?        0           
===============================================
  Hits                    ?    62187           
  Misses                  ?    15706           
  Partials                ?     4712           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d71c33a...e0fbeee. Read the comment docs.

@andreibancioiu andreibancioiu marked this pull request as ready for review May 29, 2022 22:13
@bogdan-rosianu bogdan-rosianu self-requested a review May 30, 2022 07:33
@bogdan-rosianu bogdan-rosianu added the type:feature New feature or request label May 30, 2022
node/external/blockAPI/baseBlock.go Show resolved Hide resolved
node/external/blockAPI/baseBlock_test.go Outdated Show resolved Hide resolved
node/external/blockAPI/metaBlock.go Outdated Show resolved Hide resolved
node/external/blockAPI/shardBlock.go Show resolved Hide resolved
node/external/logs/logsFacade.go Show resolved Hide resolved
storage/errors.go Outdated Show resolved Hide resolved
storage/pruning/fullHistoryPruningStorer.go Outdated Show resolved Hide resolved
testscommon/genericMocks/chainStorerMock.go Outdated Show resolved Hide resolved
@iulianpascalau iulianpascalau self-requested a review May 30, 2022 10:49
AdoAdoAdo
AdoAdoAdo previously approved these changes May 30, 2022
GetBlockByHash(hash string, withTxs bool) (*api.Block, error)
GetBlockByNonce(nonce uint64, withTxs bool) (*api.Block, error)
GetBlockByRound(round uint64, withTxs bool) (*api.Block, error)
GetBlockByHash(hash string, options api.BlockQueryOptions) (*api.Block, error)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 👍

@@ -410,18 +411,18 @@ func (nf *nodeFacade) GetThrottlerForEndpoint(endpoint string) (core.Throttler,
}

// GetBlockByHash return the block for a given hash
func (nf *nodeFacade) GetBlockByHash(hash string, withTxs bool) (*apiData.Block, error) {
return nf.apiResolver.GetBlockByHash(hash, withTxs)
func (nf *nodeFacade) GetBlockByHash(hash string, options api.BlockQueryOptions) (*apiData.Block, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you glued the facade with the api package. Please define the BlockQueryOptions here or in the common area.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The package was already dependent on elrond-go-core/data/api. Fixed to use the already defined import alias.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, my mistake 👍

api/groups/blockGroup_test.go Outdated Show resolved Hide resolved
api/groups/blockGroup_test.go Outdated Show resolved Hide resolved
node/external/blockAPI/baseBlock.go Show resolved Hide resolved
tx.Logs = logsAPI
tx.Logs, err = arp.logsFacade.GetLog(hash, epoch)
if err != nil && !errors.Is(err, storage.ErrKeyNotFound) {
log.Warn("putLogsInTransaction()", "hash", hash, "epoch", epoch, "err", err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is ok to silent these? Also on L132

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the original error is "key not found in storage", that should normally be tolerated, even ignored (there are transactions without logs).

Indeed, if the original error is something different, we should not tolerate the error.

However, since we've reverted the pruningStorer / fullHistoryPruningStorer to not emit storage.ErrKeyNotFound anymore, it's a bit tricky to reason about the error type in this piece of code.

As a temporary workaround, I've changed to emit a "debug" log entry on all errors (even though, as previously stated, it's should be quite normal for some transactions to not have any events & logs attached).

Is this all right?

@@ -36,6 +36,9 @@ func checkNilArgs(arg *ArgAPITransactionProcessor) error {
if check.IfNil(arg.TxTypeHandler) {
return process.ErrNilTxTypeHandler
}
if check.IfNil(arg.LogsFacade) {
return ErrNilLogsFacade
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unit test?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test is located in apiTransactionProcessor_test.go: NilLogsFacade.

Is it all right, as defined using t.Run()?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

storage/pruning/fullHistoryPruningStorer.go Outdated Show resolved Hide resolved
storage/pruning/pruningStorer.go Outdated Show resolved Hide resolved
testscommon/genericMocks/chainStorerMock.go Outdated Show resolved Hide resolved
@@ -111,23 +116,21 @@ func (arp *apiTransactionResultsProcessor) putSmartContractResultsInTransactionB
}

func (arp *apiTransactionResultsProcessor) putLogsInTransaction(hash []byte, tx *transaction.ApiTransactionResult, epoch uint32) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe you can change the function name
this functions load something from storage and set a field in the transactions structure

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed to loadLogsIntoTransaction.

tx.Logs, err = arp.logsFacade.GetLog(hash, epoch)
if err != nil && !errors.Is(err, storage.ErrKeyNotFound) {
log.Warn("putLogsInTransaction()", "hash", hash, "epoch", epoch, "err", err)
}
}

func (arp *apiTransactionResultsProcessor) putLogsInSCR(scrHash []byte, epoch uint32, scr *transaction.ApiSmartContractResult) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also this maybe can be renamed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed to loadLogsIntoContractResults.

}

// TODO (important): define a separate proto-structure for "batch of miniblocks from receipts storage".
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO no longer relevant. As searched through the code it is ok to be as it is. My mistake, again :D

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed :)

@@ -12,25 +15,25 @@ type logsRepository struct {
marshalizer marshal.Marshalizer
}

func newLogsRepository(args argsNewLogsRepository) *logsRepository {
storer := args.StorageService.GetStorer(dataRetriever.TxLogsUnit)
func newLogsRepository(storageService dataRetriever.StorageService, marshalizer marshal.Marshalizer) *logsRepository {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could have been renamed to marshaller (we are slowly move away from the "marshalizer" naming)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed (but only in package /logs for now).


tx.SmartContractResults = append(tx.SmartContractResults, scrAPI)
}
}

func (arp *apiTransactionResultsProcessor) putLogsInTransaction(hash []byte, tx *transaction.ApiTransactionResult, epoch uint32) {
func (arp *apiTransactionResultsProcessor) loadLogsIntoTransaction(hash []byte, tx *transaction.ApiTransactionResult, epoch uint32) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

if err != nil && !errors.Is(err, storage.ErrKeyNotFound) {
log.Warn("putLogsInTransaction()", "hash", hash, "epoch", epoch, "err", err)
if err != nil {
// TODO: We should unwrap the error, reason about its type and possibly ignore "key not found in storage" errors.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if those errors are to be expected in some cases, we might print them as TRACE and remove TODOs: valid for all occurrences. Can be done in another PR

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed TODO. Switched to TRACE.

@@ -36,6 +36,9 @@ func checkNilArgs(arg *ArgAPITransactionProcessor) error {
if check.IfNil(arg.TxTypeHandler) {
return process.ErrNilTxTypeHandler
}
if check.IfNil(arg.LogsFacade) {
return ErrNilLogsFacade
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

iulianpascalau
iulianpascalau previously approved these changes Jun 2, 2022
iulianpascalau
iulianpascalau previously approved these changes Jun 2, 2022
Copy link
Contributor

@iulianpascalau iulianpascalau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

forgotten change in node/external/transactionAPI/apiTransactionResults.go L130. Can be done in another PR

miiu96
miiu96 previously approved these changes Jun 2, 2022
bogdan-rosianu
bogdan-rosianu previously approved these changes Jun 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants