Skip to content

Commit ec0eecd

Browse files
committed
prepare execution results data
1 parent 0ec2067 commit ec0eecd

File tree

4 files changed

+148
-50
lines changed

4 files changed

+148
-50
lines changed

data/block.go

Lines changed: 67 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -9,47 +9,73 @@ import (
99
// to be saved for a block. It has all the default fields
1010
// plus some extra information for ease of search and filter
1111
type Block struct {
12-
UUID string `json:"uuid"`
13-
Nonce uint64 `json:"nonce"`
14-
Round uint64 `json:"round"`
15-
Epoch uint32 `json:"epoch"`
16-
Hash string `json:"-"`
17-
MiniBlocksHashes []string `json:"miniBlocksHashes"`
18-
MiniBlocksDetails []*MiniBlocksDetails `json:"miniBlocksDetails,omitempty"`
19-
NotarizedBlocksHashes []string `json:"notarizedBlocksHashes"`
20-
Proposer uint64 `json:"proposer"`
21-
Validators []uint64 `json:"validators,omitempty"`
22-
PubKeyBitmap string `json:"pubKeyBitmap"`
23-
Size int64 `json:"size"`
24-
SizeTxs int64 `json:"sizeTxs"`
25-
Timestamp uint64 `json:"timestamp"`
26-
TimestampMs uint64 `json:"timestampMs,omitempty"`
27-
StateRootHash string `json:"stateRootHash"`
28-
PrevHash string `json:"prevHash"`
29-
ShardID uint32 `json:"shardId"`
30-
TxCount uint32 `json:"txCount"`
31-
NotarizedTxsCount uint32 `json:"notarizedTxsCount"`
32-
AccumulatedFees string `json:"accumulatedFees"`
33-
DeveloperFees string `json:"developerFees"`
34-
EpochStartBlock bool `json:"epochStartBlock"`
35-
SearchOrder uint64 `json:"searchOrder"`
36-
EpochStartInfo *EpochStartInfo `json:"epochStartInfo,omitempty"`
37-
GasProvided uint64 `json:"gasProvided"`
38-
GasRefunded uint64 `json:"gasRefunded"`
39-
GasPenalized uint64 `json:"gasPenalized"`
40-
MaxGasLimit uint64 `json:"maxGasLimit"`
41-
ScheduledData *ScheduledData `json:"scheduledData,omitempty"`
42-
EpochStartShardsData []*EpochStartShardData `json:"epochStartShardsData,omitempty"`
43-
Proof *api.HeaderProof `json:"proof,omitempty"`
44-
RandSeed string `json:"randSeed,omitempty"`
45-
PrevRandSeed string `json:"prevRandSeed,omitempty"`
46-
Signature string `json:"signature,omitempty"`
47-
LeaderSignature string `json:"leaderSignature,omitempty"`
48-
ChainID string `json:"chainID,omitempty"`
49-
SoftwareVersion string `json:"softwareVersion,omitempty"`
50-
ReceiptsHash string `json:"receiptsHash,omitempty"`
51-
Reserved []byte `json:"reserved,omitempty"`
52-
ProposerBlsKey string `json:"proposerBlsKey,omitempty"`
12+
UUID string `json:"uuid"`
13+
Nonce uint64 `json:"nonce"`
14+
Round uint64 `json:"round"`
15+
Epoch uint32 `json:"epoch"`
16+
Hash string `json:"-"`
17+
MiniBlocksHashes []string `json:"miniBlocksHashes"`
18+
MiniBlocksDetails []*MiniBlocksDetails `json:"miniBlocksDetails,omitempty"`
19+
NotarizedBlocksHashes []string `json:"notarizedBlocksHashes"`
20+
Proposer uint64 `json:"proposer"`
21+
Validators []uint64 `json:"validators,omitempty"`
22+
PubKeyBitmap string `json:"pubKeyBitmap"`
23+
Size int64 `json:"size"`
24+
SizeTxs int64 `json:"sizeTxs"`
25+
Timestamp uint64 `json:"timestamp"`
26+
TimestampMs uint64 `json:"timestampMs,omitempty"`
27+
StateRootHash string `json:"stateRootHash"`
28+
PrevHash string `json:"prevHash"`
29+
ShardID uint32 `json:"shardId"`
30+
TxCount uint32 `json:"txCount"`
31+
NotarizedTxsCount uint32 `json:"notarizedTxsCount"`
32+
AccumulatedFees string `json:"accumulatedFees"`
33+
DeveloperFees string `json:"developerFees"`
34+
EpochStartBlock bool `json:"epochStartBlock"`
35+
SearchOrder uint64 `json:"searchOrder"`
36+
EpochStartInfo *EpochStartInfo `json:"epochStartInfo,omitempty"`
37+
GasProvided uint64 `json:"gasProvided"`
38+
GasRefunded uint64 `json:"gasRefunded"`
39+
GasPenalized uint64 `json:"gasPenalized"`
40+
MaxGasLimit uint64 `json:"maxGasLimit"`
41+
ScheduledData *ScheduledData `json:"scheduledData,omitempty"`
42+
EpochStartShardsData []*EpochStartShardData `json:"epochStartShardsData,omitempty"`
43+
Proof *api.HeaderProof `json:"proof,omitempty"`
44+
RandSeed string `json:"randSeed,omitempty"`
45+
PrevRandSeed string `json:"prevRandSeed,omitempty"`
46+
Signature string `json:"signature,omitempty"`
47+
LeaderSignature string `json:"leaderSignature,omitempty"`
48+
ChainID string `json:"chainID,omitempty"`
49+
SoftwareVersion string `json:"softwareVersion,omitempty"`
50+
ReceiptsHash string `json:"receiptsHash,omitempty"`
51+
Reserved []byte `json:"reserved,omitempty"`
52+
ProposerBlsKey string `json:"proposerBlsKey,omitempty"`
53+
ExecutionResultBlockHashes []string `json:"executionResultBlockHashes,omitempty"`
54+
}
55+
56+
// ExecutionResult is a structure containing all the fields that need
57+
//
58+
// to be saved for an execution results.
59+
type ExecutionResult struct {
60+
UUID string `json:"uuid"`
61+
Hash string `json:"-"`
62+
RootHash string `json:"rootHash"`
63+
NotarizedInBlockHash string `json:"notarizedInBlockHash"`
64+
AccumulatedFees string `json:"accumulatedFees"`
65+
DeveloperFees string `json:"developerFees"`
66+
TxCount uint64 `json:"txCount"`
67+
GasUsed uint64 `json:"gasUsed"`
68+
Nonce uint64 `json:"nonce"`
69+
Round uint64 `json:"round"`
70+
Epoch uint32 `json:"epoch"`
71+
MiniBlocksHashes []string `json:"miniBlocksHashes"`
72+
MiniBlocksDetails []*MiniBlocksDetails `json:"miniBlocksDetails,omitempty"`
73+
}
74+
75+
// PreparedBlockResults is the DTO that holds all the results after processing a block
76+
type PreparedBlockResults struct {
77+
Block *Block
78+
ExecutionResults []*ExecutionResult
5379
}
5480

5581
// MiniBlocksDetails is a structure that hold information about mini-blocks execution details

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ require (
88
github.com/gin-gonic/gin v1.10.0
99
github.com/google/uuid v1.6.0
1010
github.com/multiversx/mx-chain-communication-go v1.3.0
11-
github.com/multiversx/mx-chain-core-go v1.4.2-0.20251106121338-e515033290f4
11+
github.com/multiversx/mx-chain-core-go v1.4.2-0.20251110103947-4ba16043fc47
1212
github.com/multiversx/mx-chain-logger-go v1.1.0
1313
github.com/multiversx/mx-chain-vm-common-go v1.6.0
1414
github.com/prometheus/client_model v0.6.1

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ github.com/mr-tron/base58 v1.2.0 h1:T/HDJBh4ZCPbU39/+c3rRvE0uKBQlU27+QI8LJ4t64o=
118118
github.com/mr-tron/base58 v1.2.0/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc=
119119
github.com/multiversx/mx-chain-communication-go v1.3.0 h1:ziNM1dRuiR/7al2L/jGEA/a/hjurtJ/HEqgazHNt9P8=
120120
github.com/multiversx/mx-chain-communication-go v1.3.0/go.mod h1:gDVWn6zUW6aCN1YOm/FbbT5MUmhgn/L1Rmpl8EoH3Yg=
121-
github.com/multiversx/mx-chain-core-go v1.4.2-0.20251106121338-e515033290f4 h1:VQ7wZ5v14yHujpsMbF++ai0JvLzfdJ6aMwHW5TGdt/M=
122-
github.com/multiversx/mx-chain-core-go v1.4.2-0.20251106121338-e515033290f4/go.mod h1:IO+vspNan+gT0WOHnJ95uvWygiziHZvfXpff6KnxV7g=
121+
github.com/multiversx/mx-chain-core-go v1.4.2-0.20251110103947-4ba16043fc47 h1:Vd2y7NbkXLRm6ysErl0iEeG7DWKCBsRdc+exULQ+1XE=
122+
github.com/multiversx/mx-chain-core-go v1.4.2-0.20251110103947-4ba16043fc47/go.mod h1:IO+vspNan+gT0WOHnJ95uvWygiziHZvfXpff6KnxV7g=
123123
github.com/multiversx/mx-chain-crypto-go v1.3.0 h1:0eK2bkDOMi8VbSPrB1/vGJSYT81IBtfL4zw+C4sWe/k=
124124
github.com/multiversx/mx-chain-crypto-go v1.3.0/go.mod h1:nPIkxxzyTP8IquWKds+22Q2OJ9W7LtusC7cAosz7ojM=
125125
github.com/multiversx/mx-chain-logger-go v1.1.0 h1:97x84A6L4RfCa6YOx1HpAFxZp1cf/WI0Qh112whgZNM=

process/elasticproc/block/blockProcessor.go

Lines changed: 78 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func NewBlockProcessor(hasher hashing.Hasher, marshalizer marshal.Marshalizer, v
5757
}
5858

5959
// PrepareBlockForDB will prepare a database block and serialize it for database
60-
func (bp *blockProcessor) PrepareBlockForDB(obh *outport.OutportBlockWithHeader) (*data.Block, error) {
60+
func (bp *blockProcessor) PrepareBlockForDB(obh *outport.OutportBlockWithHeader) (*data.PreparedBlockResults, error) {
6161
if check.IfNil(obh.Header) {
6262
return nil, indexer.ErrNilHeaderHandler
6363
}
@@ -131,14 +131,83 @@ func (bp *blockProcessor) PrepareBlockForDB(obh *outport.OutportBlockWithHeader)
131131
}
132132
}
133133

134+
elasticBlock.ExecutionResultBlockHashes = make([]string, 0, len(obh.Header.GetExecutionResultsHandlers()))
135+
for _, executionResult := range obh.Header.GetExecutionResultsHandlers() {
136+
elasticBlock.ExecutionResultBlockHashes = append(elasticBlock.ExecutionResultBlockHashes, hex.EncodeToString(executionResult.GetHeaderHash()))
137+
}
138+
134139
bp.addEpochStartInfoForMeta(obh.Header, elasticBlock)
135140

136-
appendBlockDetailsFromHeaders(elasticBlock, obh.Header, obh.BlockData.Body, obh.TransactionPool)
141+
elasticBlock.MiniBlocksDetails = prepareMiniBlockDetails(obh.Header.GetMiniBlockHeaderHandlers(), obh.BlockData.Body, obh.TransactionPool)
142+
137143
appendBlockDetailsFromIntraShardMbs(elasticBlock, obh.BlockData.IntraShardMiniBlocks, obh.TransactionPool, len(obh.Header.GetMiniBlockHeaderHandlers()))
138144

139145
addProofs(elasticBlock, obh)
140146

141-
return elasticBlock, nil
147+
executionResultData, err := bp.prepareExecutionResults(obh)
148+
if err != nil {
149+
return nil, err
150+
}
151+
152+
return &data.PreparedBlockResults{
153+
Block: elasticBlock,
154+
ExecutionResults: executionResultData,
155+
}, nil
156+
}
157+
158+
func (bp *blockProcessor) prepareExecutionResults(obh *outport.OutportBlockWithHeader) ([]*data.ExecutionResult, error) {
159+
if !obh.Header.IsHeaderV3() {
160+
return []*data.ExecutionResult{}, nil
161+
}
162+
163+
executionResults := make([]*data.ExecutionResult, 0)
164+
for _, executionResultHandler := range obh.Header.GetExecutionResultsHandlers() {
165+
executionResult := bp.prepareExecutionResult(executionResultHandler, obh)
166+
167+
executionResults = append(executionResults, executionResult)
168+
}
169+
170+
return executionResults, nil
171+
}
172+
173+
func (bp *blockProcessor) prepareExecutionResult(baseExecutionResult coreData.BaseExecutionResultHandler, obh *outport.OutportBlockWithHeader) *data.ExecutionResult {
174+
miniblocksHashes := bp.getEncodedMBSHashes(obh.BlockData.Body, obh.BlockData.IntraShardMiniBlocks)
175+
176+
executionResultsHash := hex.EncodeToString(baseExecutionResult.GetHeaderHash())
177+
executionResult := &data.ExecutionResult{
178+
UUID: converters.GenerateBase64UUID(),
179+
Hash: executionResultsHash,
180+
RootHash: hex.EncodeToString(baseExecutionResult.GetRootHash()),
181+
NotarizedInBlockHash: hex.EncodeToString(obh.BlockData.GetHeaderHash()),
182+
Nonce: baseExecutionResult.GetHeaderNonce(),
183+
Round: baseExecutionResult.GetHeaderRound(),
184+
Epoch: baseExecutionResult.GetHeaderEpoch(),
185+
MiniBlocksHashes: miniblocksHashes,
186+
GasUsed: baseExecutionResult.GetGasUsed(),
187+
}
188+
189+
executionResultData, found := obh.BlockData.Results[executionResultsHash]
190+
if !found {
191+
log.Warn("cannot find execution result data for execution result", "hash", executionResultsHash)
192+
return executionResult
193+
}
194+
195+
switch t := baseExecutionResult.(type) {
196+
case *nodeBlock.MetaExecutionResult:
197+
executionResult.MiniBlocksDetails = prepareMiniBlockDetails(t.GetMiniBlockHeadersHandlers(), executionResultData.Body, obh.TransactionPool)
198+
executionResult.AccumulatedFees = t.AccumulatedFees.String()
199+
executionResult.DeveloperFees = t.DeveloperFees.String()
200+
executionResult.TxCount = t.ExecutedTxCount
201+
case *nodeBlock.ExecutionResult:
202+
executionResult.MiniBlocksDetails = prepareMiniBlockDetails(t.GetMiniBlockHeadersHandlers(), executionResultData.Body, obh.TransactionPool)
203+
executionResult.AccumulatedFees = t.AccumulatedFees.String()
204+
executionResult.DeveloperFees = t.DeveloperFees.String()
205+
executionResult.TxCount = t.ExecutedTxCount
206+
default:
207+
return executionResult
208+
}
209+
210+
return executionResult
142211
}
143212

144213
func getLeaderIndex(obh *outport.OutportBlockWithHeader) uint64 {
@@ -287,15 +356,16 @@ func (bp *blockProcessor) getEncodedMBSHashes(body *nodeBlock.Body, intraShardMb
287356
return miniblocksHashes
288357
}
289358

290-
func appendBlockDetailsFromHeaders(block *data.Block, header coreData.HeaderHandler, body *nodeBlock.Body, pool *outport.TransactionPool) {
291-
for idx, mbHeader := range header.GetMiniBlockHeaderHandlers() {
359+
func prepareMiniBlockDetails(mbHeaders []coreData.MiniBlockHeaderHandler, body *nodeBlock.Body, pool *outport.TransactionPool) []*data.MiniBlocksDetails {
360+
mbsDetails := make([]*data.MiniBlocksDetails, 0, len(mbHeaders))
361+
for idx, mbHeader := range mbHeaders {
292362
mbType := nodeBlock.Type(mbHeader.GetTypeInt32())
293363
if mbType == nodeBlock.PeerBlock {
294364
continue
295365
}
296366

297367
txsHashes := body.MiniBlocks[idx].TxHashes
298-
block.MiniBlocksDetails = append(block.MiniBlocksDetails, &data.MiniBlocksDetails{
368+
mbsDetails = append(mbsDetails, &data.MiniBlocksDetails{
299369
IndexFirstProcessedTx: mbHeader.GetIndexOfFirstTxProcessed(),
300370
IndexLastProcessedTx: mbHeader.GetIndexOfLastTxProcessed(),
301371
MBIndex: idx,
@@ -307,6 +377,8 @@ func appendBlockDetailsFromHeaders(block *data.Block, header coreData.HeaderHand
307377
ExecutionOrderTxsIndices: extractExecutionOrderIndicesFromPool(mbHeader, txsHashes, pool),
308378
})
309379
}
380+
381+
return mbsDetails
310382
}
311383

312384
func appendBlockDetailsFromIntraShardMbs(block *data.Block, intraShardMbs []*nodeBlock.MiniBlock, pool *outport.TransactionPool, offset int) {

0 commit comments

Comments
 (0)