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

Node API hotfixes for Rosetta #4187

Merged
merged 38 commits into from
Jun 22, 2022
Merged

Node API hotfixes for Rosetta #4187

merged 38 commits into from
Jun 22, 2022

Conversation

andreibancioiu
Copy link
Collaborator

@andreibancioiu andreibancioiu commented Jun 10, 2022

  • On API, return the following extra fields of miniblocks: ProcessingType and ConstructionState.
  • When account is missing, also return the precise blockInfo when / where the account it's missing.
  • Populate apiTx.Epoch before the initial fee is computed (workaround)
  • Adjusted log level for important operations (e.g. starting snapshots).
  • Improved error handling / error propagation.

@andreibancioiu andreibancioiu self-assigned this Jun 10, 2022
@andreibancioiu andreibancioiu changed the title Rosetta hotfixes (do not review yet) Rosetta hotfixes Jun 10, 2022
@codecov-commenter
Copy link

codecov-commenter commented Jun 10, 2022

Codecov Report

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

❗ Current head da9a8ae differs from pull request most recent head 3ccf41f. Consider uploading reports for the commit 3ccf41f to get more accurate results

@@               Coverage Diff               @@
##             feat/rosetta    #4187   +/-   ##
===============================================
  Coverage                ?   75.34%           
===============================================
  Files                   ?      634           
  Lines                   ?    82576           
  Branches                ?        0           
===============================================
  Hits                    ?    62214           
  Misses                  ?    15624           
  Partials                ?     4738           

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 540ce5c...3ccf41f. Read the comment docs.

@andreibancioiu andreibancioiu marked this pull request as ready for review June 15, 2022 08:04
@andreibancioiu andreibancioiu changed the title (do not review yet) Rosetta hotfixes Node API hotfixes for Rosetta Jun 15, 2022
@bogdan-rosianu bogdan-rosianu self-requested a review June 15, 2022 09:38
@@ -29,7 +33,13 @@ func (tu *txUnmarshaller) unmarshalReceipt(receiptBytes []byte) (*transaction.Ap
return nil, err
}

receiptHash, err := core.CalculateHash(tu.marshalizer, tu.hasher, rec)
Copy link
Contributor

@bogdan-rosianu bogdan-rosianu Jun 15, 2022

Choose a reason for hiding this comment

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

why do you have to calculate the receipt, since you fetch it from storage via a key? That key is the hash of the receipt. Am I missing anything?

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 storage key is, actually, the hash of the transaction that generated the receipt. However, moved the receipt hash computation to rosetta, since the "hash of a single receipt" is not meaningful on Node's side.

@@ -382,12 +382,13 @@ func (atp *apiTransactionProcessor) castObjToTransaction(txObj interface{}, txTy
}

// UnmarshalTransaction will try to unmarshal the transaction bytes based on the transaction type
func (atp *apiTransactionProcessor) UnmarshalTransaction(txBytes []byte, txType transaction.TxType) (*transaction.ApiTransactionResult, error) {
func (atp *apiTransactionProcessor) UnmarshalTransaction(epoch uint32, txBytes []byte, txType transaction.TxType) (*transaction.ApiTransactionResult, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

a little bit misleading, since I understand from the function's signature that a transaction unmarshals differently in regards to the epoch. this is not true, because you only set the Epoch field. might add a TODO and refactor in another PR with an interface that has populateEpochField(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.

right, we need some refactoring here as this function does more than one thing: unmarshal + setting up different things

@iulianpascalau iulianpascalau self-requested a review June 15, 2022 10:10
@@ -382,12 +382,13 @@ func (atp *apiTransactionProcessor) castObjToTransaction(txObj interface{}, txTy
}

// UnmarshalTransaction will try to unmarshal the transaction bytes based on the transaction type
func (atp *apiTransactionProcessor) UnmarshalTransaction(txBytes []byte, txType transaction.TxType) (*transaction.ApiTransactionResult, error) {
func (atp *apiTransactionProcessor) UnmarshalTransaction(epoch uint32, txBytes []byte, txType transaction.TxType) (*transaction.ApiTransactionResult, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

right, we need some refactoring here as this function does more than one thing: unmarshal + setting up different things

@@ -39,6 +39,9 @@ func checkNilArgs(arg *ArgAPITransactionProcessor) error {
if check.IfNil(arg.LogsFacade) {
return ErrNilLogsFacade
}
if check.IfNil(arg.Hasher) {
return process.ErrNilHasher
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 for this?

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 unit test was in apiTransactionProcessor_test.go, but removed now - hash computation moved to rosetta.

miiu96
miiu96 previously approved these changes Jun 15, 2022
return bap.getAndAttachTxsToMbByEpoch(miniblockHash, miniBlock, epoch, apiMiniblock, options)
}

func (bap *baseAPIBlockProcessor) getMiniblockByHash(miniblockHash []byte, epoch uint32) (*block.MiniBlock, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe this method can be renamed in getMiniblockByHashAndEpoch

@@ -12,6 +12,7 @@ type HistoryRepositoryFactory interface {
}

// HistoryRepository provides methods needed for the history data processing
// TODO: Move interface where it's needed, not in the package where it's implemented
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

UnmarshalReceipt(receiptBytes []byte) (*transaction.ApiReceipt, error)
PopulateComputedFields(tx *transaction.ApiTransactionResult)
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

}

arp.putSmartContractResultsInTransaction(tx, resultsHashes.ScResultsHashesAndEpoch)
// Question for review: if there's a receipt, why cannot there by any SCRs, as well?
Copy link
Contributor

Choose a reason for hiding this comment

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

I do not understand. We might only have receipts without scrs, for instance: execution in the same shard
This does not exclude the case in which we have both receipts and scrs: A calls B that calls C, A and B being 2 contracts in the same shard, C being in another shard

@@ -19,3 +19,6 @@ var ErrNilFeeComputer = errors.New("nil fee computer")

// ErrNilLogsFacade signals that the logs facade is nil
var ErrNilLogsFacade = errors.New("nil logs facade")

var errCannotLoadReceipts = errors.New("cannot load receipt(s)")
var errCannotContractResults = errors.New("cannot load contract result(s)")
Copy link
Contributor

Choose a reason for hiding this comment

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

typo: errCannotContractResults => errCannotLoadContractResults

@@ -1169,7 +1169,12 @@ func (sp *shardProcessor) updateState(headers []data.HeaderHandler, currentHeade

sp.setFinalizedHeaderHashInIndexer(header.GetPrevHash())

sp.blockChain.SetFinalBlockInfo(header.GetNonce(), headerHash, scheduledHeaderRootHash)
finalRootHash := scheduledHeaderRootHash
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@@ -17,7 +17,7 @@ import (
"github.com/ElrondNetwork/elrond-go-core/data/block"
"github.com/ElrondNetwork/elrond-go-core/hashing"
"github.com/ElrondNetwork/elrond-go-core/marshal"
"github.com/ElrondNetwork/elrond-go-logger"
logger "github.com/ElrondNetwork/elrond-go-logger"
Copy link
Contributor

Choose a reason for hiding this comment

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

"cessary" (unnecessary) alias

state/errors.go Outdated

// Error returns the error as string
func (e *ErrAccountNotFoundAtBlock) Error() string {
return fmt.Sprintf("account was not found at block = %d", e.BlockInfo.GetNonce())
Copy link
Contributor

Choose a reason for hiding this comment

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

provide more info from the blockinfo struct?

@andreibancioiu andreibancioiu merged commit c8dabac into feat/rosetta Jun 22, 2022
@andreibancioiu andreibancioiu deleted the rosetta-hotfixes branch June 22, 2022 16:28
Type: block.TxBlock.String(),
Hash: hex.EncodeToString(miniblockHeader),
Type: block.TxBlock.String(),
ProcessingType: "Normal",
Copy link
Contributor

Choose a reason for hiding this comment

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

can you use the constants instead?
same for below.

GasPrice: gasPrice,
tx := &transaction.ApiTransactionResult{
Epoch: uint32(epoch),
Tx: &transaction.Transaction{
Copy link
Contributor

Choose a reason for hiding this comment

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

TODO: this will also have to change after freeze account feature activation

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

7 participants