Skip to content

Commit 34d0af6

Browse files
small refactor and fix failing tests
1 parent 60bc94b commit 34d0af6

File tree

3 files changed

+37
-25
lines changed

3 files changed

+37
-25
lines changed

data/block/blockV3_test.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,16 @@ func TestHeaderV3_GetOrderedCrossMiniblocksWithDst(t *testing.T) {
171171
hash1 := []byte("hash1")
172172
hash2 := []byte("hash2")
173173
hv3 := &block.HeaderV3{
174-
Round: 42,
175-
MiniBlockHeaders: []block.MiniBlockHeader{
176-
{ReceiverShardID: 1, SenderShardID: 0, Hash: hash1},
177-
{ReceiverShardID: 2, SenderShardID: 1, Hash: hash2},
174+
ExecutionResults: []*block.ExecutionResult{
175+
{
176+
BaseExecutionResult: &block.BaseExecutionResult{
177+
HeaderRound: 42,
178+
},
179+
MiniBlockHeaders: []block.MiniBlockHeader{
180+
{ReceiverShardID: 1, SenderShardID: 0, Hash: hash1},
181+
{ReceiverShardID: 2, SenderShardID: 1, Hash: hash2},
182+
},
183+
},
178184
},
179185
}
180186
expected := []*data.MiniBlockInfo{

data/block/metaBlockV3.go

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package block
55
import (
66
"fmt"
77
"math/big"
8+
"sort"
89

910
"github.com/multiversx/mx-chain-core-go/core"
1011
"github.com/multiversx/mx-chain-core-go/core/check"
@@ -320,35 +321,33 @@ func (m *MetaBlockV3) GetOrderedCrossMiniblocksWithDst(destID uint32) []*data.Mi
320321
}
321322

322323
miniBlockHeaders := m.getMiniBlocksWithDstFromMetaExecutionResults(destID)
323-
for _, mb := range miniBlockHeaders {
324-
isDestinationShard := (mb.ReceiverShardID == destID ||
325-
mb.ReceiverShardID == core.AllShardId) &&
326-
mb.SenderShardID != destID
327-
if isDestinationShard {
328-
miniBlocks = append(miniBlocks, &data.MiniBlockInfo{
329-
Hash: mb.Hash,
330-
SenderShardID: mb.SenderShardID,
331-
Round: m.Round,
332-
})
333-
}
334-
}
324+
miniBlocks = append(miniBlocks, miniBlockHeaders...)
325+
326+
sort.Slice(miniBlocks, func(i, j int) bool {
327+
return miniBlocks[i].Round < miniBlocks[j].Round
328+
})
335329

336330
return miniBlocks
337331
}
338332

339-
func (m *MetaBlockV3) getMiniBlocksWithDstFromMetaExecutionResults(destID uint32) []MiniBlockHeader {
340-
miniBlocks := make([]MiniBlockHeader, 0)
333+
func (m *MetaBlockV3) getMiniBlocksWithDstFromMetaExecutionResults(destID uint32) []*data.MiniBlockInfo {
334+
miniBlocks := make([]*data.MiniBlockInfo, 0)
341335

342336
for _, execResults := range m.ExecutionResults {
343337
for _, mb := range execResults.MiniBlockHeaders {
344338
isDestinationShard := (mb.ReceiverShardID == destID ||
345339
mb.ReceiverShardID == core.AllShardId) &&
346340
mb.SenderShardID != destID
347341
if isDestinationShard {
348-
miniBlocks = append(miniBlocks, mb)
342+
miniBlocks = append(miniBlocks, &data.MiniBlockInfo{
343+
Hash: mb.Hash,
344+
SenderShardID: mb.SenderShardID,
345+
Round: execResults.GetHeaderRound(),
346+
})
349347
}
350348
}
351349
}
350+
352351
return miniBlocks
353352
}
354353

data/block/metaBlockV3_test.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -407,23 +407,30 @@ func TestMetaBlockV3_GetOrderedCrossMiniblocksWithDst(t *testing.T) {
407407

408408
metaHdr.ShardInfo = append(metaHdr.ShardInfo, shData1, shData2, shData3, shData4, shData5)
409409

410-
metaHdr.MiniBlockHeaders = append(metaHdr.MiniBlockHeaders, block.MiniBlockHeader{
410+
mb1 := block.MiniBlockHeader{
411411
Hash: []byte("hash6"),
412412
SenderShardID: core.MetachainShardId,
413413
ReceiverShardID: 1,
414-
})
414+
}
415415

416-
metaHdr.MiniBlockHeaders = append(metaHdr.MiniBlockHeaders, block.MiniBlockHeader{
416+
mb2 := block.MiniBlockHeader{
417417
Hash: []byte("hash7"),
418418
SenderShardID: core.MetachainShardId,
419419
ReceiverShardID: core.AllShardId,
420-
})
420+
}
421421

422-
metaHdr.MiniBlockHeaders = append(metaHdr.MiniBlockHeaders, block.MiniBlockHeader{
422+
mb3 := block.MiniBlockHeader{
423423
Hash: []byte("hash8"),
424424
SenderShardID: core.MetachainShardId,
425425
ReceiverShardID: 2,
426-
})
426+
}
427+
metaHdr.ExecutionResults = make([]*block.MetaExecutionResult, 1)
428+
metaHdr.ExecutionResults[0] = &block.MetaExecutionResult{
429+
MiniBlockHeaders: []block.MiniBlockHeader{mb1, mb2, mb3},
430+
ExecutionResult: &block.BaseMetaExecutionResult{
431+
BaseExecutionResult: &block.BaseExecutionResult{HeaderRound: 6},
432+
},
433+
}
427434

428435
miniBlocksInfo := metaHdr.GetOrderedCrossMiniblocksWithDst(1)
429436
require.Equal(t, 6, len(miniBlocksInfo))

0 commit comments

Comments
 (0)