-
Notifications
You must be signed in to change notification settings - Fork 199
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
Link inner tx to results #6527
Link inner tx to results #6527
Changes from 1 commit
a4b532d
11422d8
dc57ade
d0c2435
d1235cc
96d44b7
a2de898
666fd47
f6e69dc
a9a0019
3ff37f2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -170,29 +170,7 @@ func (hr *historyRepository) RecordBlock(blockHeaderHash []byte, | |
} | ||
} | ||
|
||
for txHash, tx := range txResultsFromPool { | ||
innerTxs := tx.GetUserTransactions() | ||
if len(innerTxs) == 0 { | ||
continue | ||
} | ||
|
||
for _, innerTx := range innerTxs { | ||
innerTxHash, errCalculateHash := core.CalculateHash(hr.marshalizer, hr.hasher, innerTx) | ||
if errCalculateHash != nil { | ||
logging.LogErrAsWarnExceptAsDebugIfClosingError(log, errCalculateHash, "CalculateHash for inner tx", | ||
"txHash", txHash, "err", errCalculateHash) | ||
continue | ||
} | ||
|
||
relayedHashPrefix := []byte{byte(RelayedTxHash)} | ||
relayedTxHash := append(relayedHashPrefix, []byte(txHash)...) | ||
errPut := hr.miniblockHashByTxHashIndex.Put(innerTxHash, relayedTxHash) | ||
if errPut != nil { | ||
logging.LogErrAsWarnExceptAsDebugIfClosingError(log, errPut, "miniblockHashByTxHashIndex.Put() innerTxHash-relayedTxHash pair", | ||
"txHash", txHash, "innerTxHash", innerTxHash, "err", errPut) | ||
} | ||
} | ||
} | ||
hr.recordInnerTxs(txResultsFromPool) | ||
|
||
err = hr.eventsHashesByTxHashIndex.saveResultsHashes(epoch, scrResultsFromPool, receiptsFromPool) | ||
if err != nil { | ||
|
@@ -262,6 +240,32 @@ func (hr *historyRepository) recordMiniblock(blockHeaderHash []byte, blockHeader | |
return nil | ||
} | ||
|
||
func (hr *historyRepository) recordInnerTxs(txResultsFromPool map[string]data.TransactionHandler) { | ||
for txHash, tx := range txResultsFromPool { | ||
innerTxs := tx.GetUserTransactions() | ||
if len(innerTxs) == 0 { | ||
continue | ||
} | ||
|
||
for _, innerTx := range innerTxs { | ||
innerTxHash, errCalculateHash := core.CalculateHash(hr.marshalizer, hr.hasher, innerTx) | ||
if errCalculateHash != nil { | ||
logging.LogErrAsWarnExceptAsDebugIfClosingError(log, errCalculateHash, "CalculateHash for inner tx", | ||
"txHash", txHash, "err", errCalculateHash) | ||
continue | ||
} | ||
|
||
relayedHashPrefix := []byte{byte(RelayedTxHash)} | ||
relayedTxHashPrefixed := append(relayedHashPrefix, []byte(txHash)...) | ||
errPut := hr.miniblockHashByTxHashIndex.Put(innerTxHash, relayedTxHashPrefixed) | ||
if errPut != nil { | ||
logging.LogErrAsWarnExceptAsDebugIfClosingError(log, errPut, "miniblockHashByTxHashIndex.Put() innerTxHash-relayedTxHash pair", | ||
"txHash", txHash, "innerTxHash", innerTxHash, "err", errPut) | ||
} | ||
} | ||
} | ||
} | ||
|
||
func (hr *historyRepository) computeMiniblockHash(miniblock *block.MiniBlock) ([]byte, error) { | ||
return core.CalculateHash(hr.marshalizer, hr.hasher, miniblock) | ||
} | ||
|
@@ -285,20 +289,21 @@ func (hr *historyRepository) markMiniblockMetadataAsRecentlyInserted(miniblockHa | |
} | ||
|
||
// GetMiniblockMetadataByTxHash will return a history transaction for the given hash from storage | ||
func (hr *historyRepository) GetMiniblockMetadataByTxHash(hash []byte) (*MiniblockMetadata, error) { | ||
func (hr *historyRepository) GetMiniblockMetadataByTxHash(hash []byte) (*MiniblockMetadata, []byte, error) { | ||
miniblockHash, err := hr.miniblockHashByTxHashIndex.Get(hash) | ||
if err != nil { | ||
return nil, err | ||
return nil, nil, err | ||
} | ||
|
||
hashSize := hr.hasher.Size() | ||
if len(miniblockHash) == hashSize { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this adds a previously not needed check between the hasher.Size() and the hashSize. |
||
return hr.getMiniblockMetadataByMiniblockHash(miniblockHash) | ||
metadata, err := hr.getMiniblockMetadataByMiniblockHash(miniblockHash) | ||
return metadata, nil, err | ||
} | ||
|
||
prefixedHashSize := hashSize + 1 | ||
if len(miniblockHash) != prefixedHashSize { | ||
return nil, ErrInvalidHashSize | ||
return nil, nil, ErrInvalidHashSize | ||
} | ||
|
||
prefix := miniblockHash[0] | ||
|
@@ -307,12 +312,13 @@ func (hr *historyRepository) GetMiniblockMetadataByTxHash(hash []byte) (*Miniblo | |
case byte(RelayedTxHash): | ||
miniblockHash, err = hr.miniblockHashByTxHashIndex.Get(actualHash) | ||
if err != nil { | ||
return nil, err | ||
return nil, nil, err | ||
} | ||
|
||
return hr.getMiniblockMetadataByMiniblockHash(miniblockHash) | ||
metadata, err := hr.getMiniblockMetadataByMiniblockHash(miniblockHash) | ||
return metadata, actualHash, err | ||
default: | ||
return nil, ErrInvalidHash | ||
return nil, nil, ErrInvalidHash | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -112,7 +112,7 @@ func (atp *apiTransactionProcessor) GetSCRsByTxHash(txHash string, scrHash strin | |
return nil, fmt.Errorf("cannot return smat contract results: %w", ErrDBLookExtensionIsNotEnabled) | ||
} | ||
|
||
miniblockMetadata, err := atp.historyRepository.GetMiniblockMetadataByTxHash(decodedScrHash) | ||
miniblockMetadata, _, err := atp.historyRepository.GetMiniblockMetadataByTxHash(decodedScrHash) | ||
if err != nil { | ||
return nil, fmt.Errorf("%s: %w", ErrTransactionNotFound.Error(), err) | ||
} | ||
|
@@ -514,7 +514,7 @@ func (atp *apiTransactionProcessor) computeTimestampForRound(round uint64) int64 | |
} | ||
|
||
func (atp *apiTransactionProcessor) lookupHistoricalTransaction(hash []byte, withResults bool) (*transaction.ApiTransactionResult, error) { | ||
miniblockMetadata, err := atp.historyRepository.GetMiniblockMetadataByTxHash(hash) | ||
miniblockMetadata, parentTxHash, err := atp.historyRepository.GetMiniblockMetadataByTxHash(hash) | ||
if err != nil { | ||
return nil, fmt.Errorf("%s: %w", ErrTransactionNotFound.Error(), err) | ||
} | ||
|
@@ -538,6 +538,11 @@ func (atp *apiTransactionProcessor) lookupHistoricalTransaction(hash []byte, wit | |
return nil, fmt.Errorf("%s: %w", ErrCannotRetrieveTransaction.Error(), err) | ||
} | ||
|
||
if len(parentTxHash) > 0 { | ||
tx.OriginalTransactionHash = hex.EncodeToString(parentTxHash) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you are doing twice the same encoding |
||
tx.PreviousTransactionHash = hex.EncodeToString(parentTxHash) | ||
} | ||
|
||
putMiniblockFieldsInTransaction(tx, miniblockMetadata) | ||
tx.Timestamp = atp.computeTimestampForRound(tx.Round) | ||
statusComputer, err := txstatus.NewStatusComputer(atp.shardCoordinator.SelfId(), atp.uint64ByteSliceConverter, atp.storageService) | ||
|
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.
Thus, now we keep heterogeneous data in this storer. In a future PR, we should refactor to adjust its naming.