Skip to content
Open
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
2 changes: 2 additions & 0 deletions data/outport.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ type BlockStateAccesses struct {
ShardID uint32 `json:"shardID"`
TimeStampMs uint64 `json:"timestampMs"`
Nonce uint64 `json:"nonce"`
RootHash []byte `json:"rootHash"`
ScheduledRootHash []byte `json:"scheduledRootHash"`
StateAccessesPerAccounts map[string]*stateChange.StateAccesses `json:"stateAccessesPerAccounts"`
}

Expand Down
7 changes: 7 additions & 0 deletions process/eventsHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,18 @@ func (eh *eventsHandler) HandleSaveBlockEvents(allEvents data.ArgsSaveBlockData)
}
eh.handleBlockEventsWithOrder(txsWithOrder)

var scheduledRootHash []byte
if eventsData.Header.GetAdditionalData() != nil {
scheduledRootHash = eventsData.Header.GetAdditionalData().GetScheduledRootHash()
}

stateAccesses := data.BlockStateAccesses{
Hash: eventsData.Hash,
ShardID: eventsData.Header.GetShardID(),
TimeStampMs: headerTimeStampMs,
Nonce: eventsData.Header.GetNonce(),
RootHash: eventsData.Header.GetRootHash(),
ScheduledRootHash: scheduledRootHash,
StateAccessesPerAccounts: eventsData.StateAccessesPerAccounts,
}
eh.handleStateAccesses(stateAccesses)
Expand Down
41 changes: 37 additions & 4 deletions process/eventsInterceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package process

import (
"encoding/hex"
"fmt"
"sort"
"strings"

"github.com/multiversx/mx-chain-core-go/core"
"github.com/multiversx/mx-chain-core-go/core/check"
Expand Down Expand Up @@ -95,15 +97,19 @@ func getTxsWithOrder(transactionsPool *outport.TransactionPool) []txWithOrder {

for txHash, txInfo := range transactionsPool.Transactions {
txsWithOrderMap[txHash] = txInfo.ExecutionOrder
log.Trace("tx with order before sort - normal", "txHash", txHash, "index", txInfo.ExecutionOrder)
}
for txHash, txInfo := range transactionsPool.SmartContractResults {
txsWithOrderMap[txHash] = txInfo.ExecutionOrder
log.Trace("tx with order before sort - scr", "txHash", txHash, "index", txInfo.ExecutionOrder)
}
for txHash, txInfo := range transactionsPool.Rewards {
txsWithOrderMap[txHash] = txInfo.ExecutionOrder
log.Trace("tx with order before sort - rewards", "txHash", txHash, "index", txInfo.ExecutionOrder)
}
for txHash, txInfo := range transactionsPool.InvalidTxs {
txsWithOrderMap[txHash] = txInfo.ExecutionOrder
log.Trace("tx with order before sort - invalid tx", "txHash", txHash, "index", txInfo.ExecutionOrder)
}

txsWithOrder := make([]txWithOrder, 0, len(txsWithOrderMap))
Expand All @@ -118,6 +124,10 @@ func getTxsWithOrder(transactionsPool *outport.TransactionPool) []txWithOrder {
return txsWithOrder[i].index < txsWithOrder[j].index
})

for i, txInfo := range txsWithOrder {
log.Trace("tx with order after sort", "txHash", txInfo.hash, "index", txInfo.index, "position in slice", i)
}

return txsWithOrder
}

Expand All @@ -140,6 +150,7 @@ func (ei *eventsInterceptor) getStateAccessesPerAccounts(eventsData *data.ArgsSa

stateAccessesPerAccounts := make(map[string]*stateChange.StateAccesses)
for _, txInfo := range txsWithOrder {
log.Trace("tx with order", "txHash", txInfo.hash, "index", txInfo.index)
txHash, err := hex.DecodeString(txInfo.hash)
if err != nil {
log.Error("failed to decode tx hash", "txHash", txInfo.hash)
Expand Down Expand Up @@ -176,6 +187,15 @@ func (ei *eventsInterceptor) getStateAccessesPerAccounts(eventsData *data.ArgsSa
log.Trace("getStateAccessesPerAccounts",
"num stateAccessesPerAccounts", len(stateAccessesPerAccounts),
)
for accKey, sts := range stateAccessesPerAccounts {
log.Trace("stateAccessesPerAccount",
"account", accKey,
"num stateAccesses", len(sts.StateAccess),
)
for _, st := range sts.StateAccess {
log.Trace("state access", "stateChange", stateAccessToString(st))
}
}

return stateAccessesPerAccounts
}
Expand All @@ -195,14 +215,27 @@ func logStateAccessesPerTxs(stateAccesses map[string]*stateChange.StateAccesses)
)

for _, st := range sts.StateAccess {
log.Trace("st",
"actionType", st.GetType(),
"operation", st.GetOperation(),
)
log.Trace("state access", "stateChange", stateAccessToString(st))
}
}
}

func stateAccessToString(stateAccess *stateChange.StateAccess) string {
dataTrieChanges := make([]string, len(stateAccess.GetDataTrieChanges()))
for i, dataTrieChange := range stateAccess.GetDataTrieChanges() {
dataTrieChanges[i] = fmt.Sprintf("key: %v, val: %v, type: %v, operation %v, version %v", hex.EncodeToString(dataTrieChange.Key), hex.EncodeToString(dataTrieChange.Val), dataTrieChange.Type, dataTrieChange.Operation, dataTrieChange.Version)
}
return fmt.Sprintf("type: %v, operation: %v, mainTrieKey: %v, mainTrieVal: %v, index: %v, dataTrieChanges: %v, accountChanges %v",
stateAccess.GetType(),
stateAccess.GetOperation(),
hex.EncodeToString(stateAccess.GetMainTrieKey()),
hex.EncodeToString(stateAccess.GetMainTrieVal()),
stateAccess.GetIndex(),
strings.Join(dataTrieChanges, ", "),
stateAccess.GetAccountChanges(),
)
}

func (ei *eventsInterceptor) getLogEventsFromTransactionsPool(logs []*outport.LogData) []data.Event {
var logEvents []*logEvent
for _, logData := range logs {
Expand Down
Loading