From f7452d82498434ec288eb71e39d93dff97633343 Mon Sep 17 00:00:00 2001 From: ssd04 Date: Tue, 30 Sep 2025 15:59:20 +0300 Subject: [PATCH 1/6] add root hash for state accesses event --- data/outport.go | 2 ++ process/eventsHandler.go | 2 ++ 2 files changed, 4 insertions(+) diff --git a/data/outport.go b/data/outport.go index 18ec51a..7ca5a73 100644 --- a/data/outport.go +++ b/data/outport.go @@ -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"` } diff --git a/process/eventsHandler.go b/process/eventsHandler.go index 0c8856b..9fd35ea 100644 --- a/process/eventsHandler.go +++ b/process/eventsHandler.go @@ -135,6 +135,8 @@ func (eh *eventsHandler) HandleSaveBlockEvents(allEvents data.ArgsSaveBlockData) ShardID: eventsData.Header.GetShardID(), TimeStampMs: headerTimeStampMs, Nonce: eventsData.Header.GetNonce(), + RootHash: eventsData.Header.GetRootHash(), + ScheduledRootHash: eventsData.Header.GetAdditionalData().GetScheduledRootHash(), StateAccessesPerAccounts: eventsData.StateAccessesPerAccounts, } eh.handleStateAccesses(stateAccesses) From d182636a9093dd3fd62a83c6e7cac60b618f6d26 Mon Sep 17 00:00:00 2001 From: BeniaminDrasovean Date: Tue, 30 Sep 2025 20:05:25 +0300 Subject: [PATCH 2/6] fix scheduled root hash --- process/eventsHandler.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/process/eventsHandler.go b/process/eventsHandler.go index 9fd35ea..adf2510 100644 --- a/process/eventsHandler.go +++ b/process/eventsHandler.go @@ -130,13 +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: eventsData.Header.GetAdditionalData().GetScheduledRootHash(), + ScheduledRootHash: scheduledRootHash, StateAccessesPerAccounts: eventsData.StateAccessesPerAccounts, } eh.handleStateAccesses(stateAccesses) From 625139a58e2bfe13e518f29f2037df2ba6f1a8c2 Mon Sep 17 00:00:00 2001 From: BeniaminDrasovean Date: Tue, 7 Oct 2025 12:02:56 +0300 Subject: [PATCH 3/6] update logging --- process/eventsInterceptor.go | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/process/eventsInterceptor.go b/process/eventsInterceptor.go index 9043fc9..b299067 100644 --- a/process/eventsInterceptor.go +++ b/process/eventsInterceptor.go @@ -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" @@ -174,6 +176,8 @@ func (ei *eventsInterceptor) getStateAccessesPerAccounts(eventsData *data.ArgsSa } stateAccessesPerAccounts[accKey].StateAccess = append(stateAccessesPerAccounts[accKey].StateAccess, stateAccess) + // TODO: remove this log after testing + log.Trace("added state access to account", "account", stateAccess.MainTrieKey, "stateAccess", stateAccessToString(stateAccess), "txHash", txInfo.hash) } } @@ -199,14 +203,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 { From 456819deb789365de05d5701a5f72c646501a204 Mon Sep 17 00:00:00 2001 From: BeniaminDrasovean Date: Tue, 7 Oct 2025 15:05:51 +0300 Subject: [PATCH 4/6] update logging --- process/eventsInterceptor.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/process/eventsInterceptor.go b/process/eventsInterceptor.go index b299067..60d2a0b 100644 --- a/process/eventsInterceptor.go +++ b/process/eventsInterceptor.go @@ -100,30 +100,38 @@ func getTxsWithOrder(transactionsPool *outport.TransactionPool) []txWithOrder { hash: txHash, index: txInfo.ExecutionOrder, }) + log.Trace("tx with order before sort - normal", "txHash", txHash, "index", txInfo.ExecutionOrder) } for txHash, txInfo := range transactionsPool.SmartContractResults { txsWithOrder = append(txsWithOrder, txWithOrder{ hash: txHash, index: txInfo.ExecutionOrder, }) + log.Trace("tx with order before sort - scr", "txHash", txHash, "index", txInfo.ExecutionOrder) } for txHash, txInfo := range transactionsPool.Rewards { txsWithOrder = append(txsWithOrder, txWithOrder{ hash: txHash, index: txInfo.ExecutionOrder, }) + log.Trace("tx with order before sort - rewards", "txHash", txHash, "index", txInfo.ExecutionOrder) } for txHash, txInfo := range transactionsPool.InvalidTxs { txsWithOrder = append(txsWithOrder, txWithOrder{ hash: txHash, index: txInfo.ExecutionOrder, }) + log.Trace("tx with order before sort - invalid tx", "txHash", txHash, "index", txInfo.ExecutionOrder) } sort.Slice(txsWithOrder, func(i, j int) bool { 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 } @@ -146,6 +154,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) @@ -184,6 +193,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 } From 885db0390db7f0ab870e327303ee5f1670de5687 Mon Sep 17 00:00:00 2001 From: BeniaminDrasovean Date: Tue, 7 Oct 2025 16:19:30 +0300 Subject: [PATCH 5/6] remove duplicates from txsWithOrder --- process/eventsInterceptor.go | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/process/eventsInterceptor.go b/process/eventsInterceptor.go index 60d2a0b..46eca0e 100644 --- a/process/eventsInterceptor.go +++ b/process/eventsInterceptor.go @@ -93,35 +93,31 @@ func (ei *eventsInterceptor) ProcessBlockEvents(eventsData *data.ArgsSaveBlockDa } func getTxsWithOrder(transactionsPool *outport.TransactionPool) []txWithOrder { - txsWithOrder := make([]txWithOrder, 0) + txsWithOrderMap := make(map[string]uint32) for txHash, txInfo := range transactionsPool.Transactions { - txsWithOrder = append(txsWithOrder, txWithOrder{ - hash: txHash, - index: txInfo.ExecutionOrder, - }) + txsWithOrderMap[txHash] = txInfo.ExecutionOrder log.Trace("tx with order before sort - normal", "txHash", txHash, "index", txInfo.ExecutionOrder) } for txHash, txInfo := range transactionsPool.SmartContractResults { - txsWithOrder = append(txsWithOrder, txWithOrder{ - hash: txHash, - index: txInfo.ExecutionOrder, - }) + txsWithOrderMap[txHash] = txInfo.ExecutionOrder log.Trace("tx with order before sort - scr", "txHash", txHash, "index", txInfo.ExecutionOrder) } for txHash, txInfo := range transactionsPool.Rewards { - txsWithOrder = append(txsWithOrder, txWithOrder{ - hash: txHash, - index: txInfo.ExecutionOrder, - }) + 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)) + for txHash, index := range txsWithOrderMap { txsWithOrder = append(txsWithOrder, txWithOrder{ hash: txHash, - index: txInfo.ExecutionOrder, + index: index, }) - log.Trace("tx with order before sort - invalid tx", "txHash", txHash, "index", txInfo.ExecutionOrder) } sort.Slice(txsWithOrder, func(i, j int) bool { From d2d0ae146141590251cb6195b0b3facaef844b2f Mon Sep 17 00:00:00 2001 From: ssd04 Date: Fri, 10 Oct 2025 11:39:21 +0300 Subject: [PATCH 6/6] fixes after merge --- process/eventsInterceptor.go | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/process/eventsInterceptor.go b/process/eventsInterceptor.go index 56501ba..f9a356b 100644 --- a/process/eventsInterceptor.go +++ b/process/eventsInterceptor.go @@ -97,7 +97,6 @@ func getTxsWithOrder(transactionsPool *outport.TransactionPool) []txWithOrder { for txHash, txInfo := range transactionsPool.Transactions { txsWithOrderMap[txHash] = txInfo.ExecutionOrder -<<<<<<< HEAD log.Trace("tx with order before sort - normal", "txHash", txHash, "index", txInfo.ExecutionOrder) } for txHash, txInfo := range transactionsPool.SmartContractResults { @@ -111,17 +110,6 @@ func getTxsWithOrder(transactionsPool *outport.TransactionPool) []txWithOrder { for txHash, txInfo := range transactionsPool.InvalidTxs { txsWithOrderMap[txHash] = txInfo.ExecutionOrder log.Trace("tx with order before sort - invalid tx", "txHash", txHash, "index", txInfo.ExecutionOrder) -======= - } - for txHash, txInfo := range transactionsPool.SmartContractResults { - txsWithOrderMap[txHash] = txInfo.ExecutionOrder - } - for txHash, txInfo := range transactionsPool.Rewards { - txsWithOrderMap[txHash] = txInfo.ExecutionOrder - } - for txHash, txInfo := range transactionsPool.InvalidTxs { - txsWithOrderMap[txHash] = txInfo.ExecutionOrder ->>>>>>> rc/supernova } txsWithOrder := make([]txWithOrder, 0, len(txsWithOrderMap)) @@ -193,8 +181,6 @@ func (ei *eventsInterceptor) getStateAccessesPerAccounts(eventsData *data.ArgsSa } stateAccessesPerAccounts[accKey].StateAccess = append(stateAccessesPerAccounts[accKey].StateAccess, stateAccess) - // TODO: remove this log after testing - log.Trace("added state access to account", "account", stateAccess.MainTrieKey, "stateAccess", stateAccessToString(stateAccess), "txHash", txInfo.hash) } }