-
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
Node API hotfixes for Rosetta #4187
Conversation
Codecov Report
@@ 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.
|
@@ -29,7 +33,13 @@ func (tu *txUnmarshaller) unmarshalReceipt(receiptBytes []byte) (*transaction.Ap | |||
return nil, err | |||
} | |||
|
|||
receiptHash, err := core.CalculateHash(tu.marshalizer, tu.hasher, rec) |
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.
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?
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 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) { |
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.
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)
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.
right, we need some refactoring here as this function does more than one thing: unmarshal + setting up different things
@@ -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) { |
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.
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 |
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 for this?
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 unit test was in apiTransactionProcessor_test.go
, but removed now - hash computation moved to rosetta.
node/external/blockAPI/baseBlock.go
Outdated
return bap.getAndAttachTxsToMbByEpoch(miniblockHash, miniBlock, epoch, apiMiniblock, options) | ||
} | ||
|
||
func (bap *baseAPIBlockProcessor) getMiniblockByHash(miniblockHash []byte, epoch uint32) (*block.MiniBlock, 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.
maybe this method can be renamed in getMiniblockByHashAndEpoch
… into rosetta-hotfixes
@@ -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 |
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.
👍
UnmarshalReceipt(receiptBytes []byte) (*transaction.ApiReceipt, error) | ||
PopulateComputedFields(tx *transaction.ApiTransactionResult) |
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.
👍
} | ||
|
||
arp.putSmartContractResultsInTransaction(tx, resultsHashes.ScResultsHashesAndEpoch) | ||
// Question for review: if there's a receipt, why cannot there by any SCRs, as well? |
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.
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)") |
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.
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 |
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.
👍
process/coordinator/process.go
Outdated
@@ -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" |
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.
"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()) |
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.
provide more info from the blockinfo struct?
Type: block.TxBlock.String(), | ||
Hash: hex.EncodeToString(miniblockHeader), | ||
Type: block.TxBlock.String(), | ||
ProcessingType: "Normal", |
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.
can you use the constants instead?
same for below.
GasPrice: gasPrice, | ||
tx := &transaction.ApiTransactionResult{ | ||
Epoch: uint32(epoch), | ||
Tx: &transaction.Transaction{ |
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: this will also have to change after freeze account feature activation
ProcessingType
andConstructionState
.blockInfo
when / where the account it's missing.apiTx.Epoch
before the initial fee is computed (workaround)