-
Notifications
You must be signed in to change notification settings - Fork 197
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
Conversation
Codecov Report
@@ 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.
|
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 👍
facade/nodeFacade.go
Outdated
@@ -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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, my mistake 👍
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) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unit test?
There was a problem hiding this comment.
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()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes
@@ -111,23 +116,21 @@ func (arp *apiTransactionResultsProcessor) putSmartContractResultsInTransactionB | |||
} | |||
|
|||
func (arp *apiTransactionResultsProcessor) putLogsInTransaction(hash []byte, tx *transaction.ApiTransactionResult, epoch uint32) { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed to loadLogsIntoContractResults
.
node/external/blockAPI/baseBlock.go
Outdated
} | ||
|
||
// TODO (important): define a separate proto-structure for "batch of miniblocks from receipts storage". |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed :)
node/external/logs/logsRepository.go
Outdated
@@ -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 { |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes
There was a problem hiding this 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
e0fbeee
withLogs
is set totrue
.