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
7 changes: 6 additions & 1 deletion process/block/baseProcess.go
Original file line number Diff line number Diff line change
Expand Up @@ -1224,7 +1224,12 @@ func (bp *baseProcessor) checkMiniBlockWithMiniBlockHeaderProposal(mbHash []byte
if err != nil {
return err
}
return bp.checkConstructionStateProcessingTypeAndIndexesCorrectnessProposal(mbHdr)
err = bp.checkConstructionStateProcessingTypeAndIndexesCorrectnessProposal(mbHdr)
if err != nil {
return err
}

return process.CheckMiniBlock(miniBlock, bp.shardCoordinator)
}

func (bp *baseProcessor) checkMiniBlockWithMiniBlockHeader(mbHash []byte, mbHdr data.MiniBlockHeaderHandler, miniBlock *block.MiniBlock, blockShardID uint32) error {
Expand Down
5 changes: 4 additions & 1 deletion process/block/baseProcess_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/multiversx/mx-chain-core-go/core"
"github.com/multiversx/mx-chain-core-go/core/check"
"github.com/multiversx/mx-chain-core-go/core/keyValStorage"
"github.com/multiversx/mx-chain-core-go/core/sharding"
"github.com/multiversx/mx-chain-core-go/data"
"github.com/multiversx/mx-chain-core-go/data/block"
"github.com/multiversx/mx-chain-core-go/data/rewardTx"
Expand Down Expand Up @@ -4555,7 +4556,9 @@ func TestCheckHeaderBodyCorrelationProposal(t *testing.T) {
})

t.Run("should work", func(t *testing.T) {
arguments := CreateMockArguments(createComponentHolderMocks())
coreComponents, dataComponents, bootstrapComponents, statusComponents := createComponentHolderMocks()
bootstrapComponents.Coordinator, _ = sharding.NewMultiShardCoordinator(3, 0)
arguments := CreateMockArguments(coreComponents, dataComponents, bootstrapComponents, statusComponents)
bp, _ := blproc.NewShardProcessor(arguments)

miniBlock := &block.MiniBlock{
Expand Down
40 changes: 4 additions & 36 deletions process/coordinator/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -439,13 +439,14 @@ func (tc *transactionCoordinator) processMiniBlocksFromMe(
body *block.Body,
haveTime func() bool,
) error {
selfId := tc.shardCoordinator.SelfId()
for _, mb := range body.MiniBlocks {
err := process.CheckMiniBlock(mb, tc.shardCoordinator)
if err != nil {
Comment thread
BeniaminDrasovean marked this conversation as resolved.
return err
}

if mb.SenderShardID != tc.shardCoordinator.SelfId() {
if mb.SenderShardID != selfId {
return process.ErrMiniBlocksInWrongOrder
}
}
Expand Down Expand Up @@ -484,40 +485,6 @@ func (tc *transactionCoordinator) processMiniBlocksFromMe(
return nil
}

// TODO consider calling this from VerifyBlockProposal instead of ProcessBlockProposal
func (tc *transactionCoordinator) checkMiniBlock(
miniBlock *block.MiniBlock,
) error {
// there are checks for non existing shard id at interceptors level

if miniBlock.SenderShardID != tc.shardCoordinator.SelfId() && miniBlock.GetReceiverShardID() != tc.shardCoordinator.SelfId() && miniBlock.GetReceiverShardID() != core.AllShardId {
return fmt.Errorf("%w - not valid shard ids: block type: %s, sender shard id: %d, receiver shard id: %d",
process.ErrInvalidShardId,
miniBlock.Type,
miniBlock.SenderShardID,
miniBlock.ReceiverShardID)
}

if miniBlock.GetType() == block.PeerBlock &&
(miniBlock.GetSenderShardID() != core.MetachainShardId || miniBlock.GetReceiverShardID() != core.AllShardId) {
return fmt.Errorf("%w - peer blocks: block type: %s, sender shard id: %d, receiver shard id: %d",
process.ErrInvalidShardId,
miniBlock.Type,
miniBlock.SenderShardID,
miniBlock.ReceiverShardID)
}

if miniBlock.GetType() != block.PeerBlock && miniBlock.GetReceiverShardID() == core.AllShardId {
return fmt.Errorf("%w - invalid all shard ids: block type: %s, sender shard id: %d, receiver shard id: %d",
process.ErrInvalidShardId,
miniBlock.Type,
miniBlock.SenderShardID,
miniBlock.ReceiverShardID)
}

return nil
}

func (tc *transactionCoordinator) processMiniBlocksToMe(
header data.HeaderHandler,
body *block.Body,
Expand All @@ -537,6 +504,7 @@ func (tc *transactionCoordinator) processMiniBlocksToMe(
// processing has to be done in order, as the order of different type of transactions over the same account is strict
// processing destination ME miniblocks first
mbIndex := 0
selfId := tc.shardCoordinator.SelfId()
for mbIndex = 0; mbIndex < len(body.MiniBlocks); mbIndex++ {
miniBlock := body.MiniBlocks[mbIndex]

Expand All @@ -545,7 +513,7 @@ func (tc *transactionCoordinator) processMiniBlocksToMe(
return mbIndex, err
}

if miniBlock.SenderShardID == tc.shardCoordinator.SelfId() {
if miniBlock.SenderShardID == selfId {
return mbIndex, nil
}

Expand Down
Loading