Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ type chainParametersHandler interface {
IsInterfaceNil() bool
}

// PrepareLogEventsKey will prepare logs key for cacher
func PrepareLogEventsKey(headerHash []byte) []byte {
return append([]byte("logs"), headerHash...)
}

// IsValidRelayedTxV3 returns true if the provided transaction is a valid transaction of type relayed v3
func IsValidRelayedTxV3(tx data.TransactionHandler) bool {
relayedTx, isRelayedV3 := tx.(data.RelayedTransactionHandler)
Expand Down
115 changes: 115 additions & 0 deletions dblookupext/common.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
package dblookupext

import (
"encoding/hex"
"fmt"

"github.com/multiversx/mx-chain-core-go/data"
"github.com/multiversx/mx-chain-core-go/data/block"
"github.com/multiversx/mx-chain-core-go/marshal"
"github.com/multiversx/mx-chain-go/common"
"github.com/multiversx/mx-chain-go/process"
"github.com/multiversx/mx-chain-go/storage"
)

func getIntermediateTxs(cache storage.Cacher, headerHash []byte) (map[string]data.TransactionHandler, map[string]data.TransactionHandler, error) {
cachedIntermediateTxs, ok := cache.Get(headerHash)
if !ok {
log.Warn("intermediateTxs not found in dataPool", "hash", headerHash)
return nil, nil, fmt.Errorf("%w for header %s", process.ErrMissingHeader, hex.EncodeToString(headerHash))
}

cachedIntermediateTxsMap, ok := cachedIntermediateTxs.(map[block.Type]map[string]data.TransactionHandler)
if !ok {
return nil, nil, fmt.Errorf("%w for cached intermediate transaction %s", process.ErrWrongTypeAssertion, hex.EncodeToString(headerHash))
}

scrs := cachedIntermediateTxsMap[block.SmartContractResultBlock]
receipts := cachedIntermediateTxsMap[block.ReceiptBlock]

return scrs, receipts, nil
}

func getLogs(cache storage.Cacher, headerHash []byte) ([]*data.LogData, error) {
logsKey := common.PrepareLogEventsKey(headerHash)
cachedLogs, ok := cache.Get(logsKey)
if !ok {
log.Warn("logs not found in dataPool", "hash", headerHash)
return nil, fmt.Errorf("%w for header %s", process.ErrMissingHeader, hex.EncodeToString(headerHash))
}
cachedLogsSlice, ok := cachedLogs.([]*data.LogData)
if !ok {
return nil, fmt.Errorf("%w for cached logs %s", process.ErrWrongTypeAssertion, hex.EncodeToString(headerHash))
}
return cachedLogsSlice, nil
}

func getIntraMbs(cache storage.Cacher, marshaller marshal.Marshalizer, headerHash []byte) ([]*block.MiniBlock, error) {
cachedIntraMBs, ok := cache.Get(headerHash)
if !ok {
log.Warn("intra miniblocks not found in dataPool", "hash", headerHash)
return nil, fmt.Errorf("%w for header %s", process.ErrMissingHeader, hex.EncodeToString(headerHash))
}
cachedLogsBuff := cachedIntraMBs.([]byte)
var intraMBs []*block.MiniBlock
errUnmarshal := marshaller.Unmarshal(&intraMBs, cachedLogsBuff)
if errUnmarshal != nil {
return nil, fmt.Errorf("%w getIntraMbs: cannot unmarshall", errUnmarshal)
}

return intraMBs, nil
}

func getBody(cache storage.Cacher, marshaller marshal.Marshalizer, baseExecResult data.BaseExecutionResultHandler, shardID uint32) (*block.Body, error) {
miniBlockHeaderHandlers, err := extractMiniBlocksHeaderHandlersFromExecResult(baseExecResult, shardID)
if err != nil {
return nil, err
}

var miniBlocks block.MiniBlockSlice
for _, miniBlockHeaderHandler := range miniBlockHeaderHandlers {
mbHash := miniBlockHeaderHandler.GetHash()
cachedMiniBlock, found := cache.Get(mbHash)
if !found {
log.Warn("mini block from execution result not cached after execution",
"mini block hash", mbHash)
return nil, process.ErrMissingMiniBlock
}

cachedMiniBlockBytes := cachedMiniBlock.([]byte)

var miniBlock *block.MiniBlock
err = marshaller.Unmarshal(&miniBlock, cachedMiniBlockBytes)
if err != nil {
return nil, err
}

miniBlocks = append(miniBlocks, miniBlock)
}

return &block.Body{MiniBlocks: miniBlocks}, nil
}

// TODO reuse the method that was moved into common after PR #7337 is merged
func extractMiniBlocksHeaderHandlersFromExecResult(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

perhaps add a todo to reuse the method that was moved into common here: #7337

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

added TODO

baseExecResult data.BaseExecutionResultHandler,
headerShard uint32,
) ([]data.MiniBlockHeaderHandler, error) {
if headerShard == common.MetachainShardId {
metaExecResult, ok := baseExecResult.(data.MetaExecutionResultHandler)
if !ok {
log.Warn("extractMiniBlocksHeaderHandlersFromExecResult assert failed to MetaExecutionResultHandler")
return nil, process.ErrWrongTypeAssertion
}

return metaExecResult.GetMiniBlockHeadersHandlers(), nil
}

execResult, ok := baseExecResult.(data.ExecutionResultHandler)
if !ok {
log.Warn("extractMiniBlocksHeaderHandlersFromExecResult assert failed to ExecutionResultHandler")
return nil, process.ErrWrongTypeAssertion
}

return execResult.GetMiniBlockHeadersHandlers(), nil
}
Loading
Loading