Skip to content

Commit

Permalink
Merge pull request #5128 from multiversx/fix-rewards-broadcast
Browse files Browse the repository at this point in the history
Fix rewards broadcast
  • Loading branch information
iulianpascalau authored Apr 3, 2023
2 parents 43762fa + 31e621e commit b94c62d
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 6 deletions.
5 changes: 0 additions & 5 deletions process/rewardTransaction/interceptedRewardTransaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,6 @@ func (inRTx *InterceptedRewardTransaction) processFields(rewardTxBuff []byte) er
inRTx.rcvShard = inRTx.coordinator.ComputeId(inRTx.rTx.RcvAddr)
inRTx.sndShard = core.MetachainShardId

if inRTx.coordinator.SelfId() == core.MetachainShardId {
inRTx.isForCurrentShard = false
return nil
}

isForCurrentShardRecv := inRTx.rcvShard == inRTx.coordinator.SelfId()
isForCurrentShardSender := inRTx.sndShard == inRTx.coordinator.SelfId()
inRTx.isForCurrentShard = isForCurrentShardRecv || isForCurrentShardSender
Expand Down
83 changes: 83 additions & 0 deletions process/rewardTransaction/interceptedRewardTransaction_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package rewardTransaction_test

import (
"bytes"
"fmt"
"math/big"
"testing"
Expand Down Expand Up @@ -317,6 +318,88 @@ func TestNewInterceptedRewardTransaction_CheckValidityShouldWork(t *testing.T) {
assert.Nil(t, err)
}

func TestNewInterceptedRewardTransaction_IsForCurrentShard(t *testing.T) {
t.Parallel()

receiverAddress := []byte("receiver address")
testShardID := uint32(2)
value := big.NewInt(100)
rewTx := rewardTx.RewardTx{
Round: 0,
Epoch: 0,
Value: value,
RcvAddr: receiverAddress,
}

mockShardCoordinator := &mock.ShardCoordinatorStub{}
marshalizer := &mock.MarshalizerMock{}
txBuff, _ := marshalizer.Marshal(&rewTx)
t.Run("same shard ID with the receiver should return true", func(t *testing.T) {
mockShardCoordinator.ComputeIdCalled = func(address []byte) uint32 {
if bytes.Equal(address, receiverAddress) {
return testShardID
}

return 0
}
mockShardCoordinator.SelfIdCalled = func() uint32 {
return testShardID
}

irt, err := rewardTransaction.NewInterceptedRewardTransaction(
txBuff,
marshalizer,
&hashingMocks.HasherMock{},
createMockPubkeyConverter(),
mockShardCoordinator)
assert.Nil(t, err)

assert.True(t, irt.IsForCurrentShard())
})
t.Run("metachain should return true", func(t *testing.T) {
mockShardCoordinator.ComputeIdCalled = func(address []byte) uint32 {
if bytes.Equal(address, receiverAddress) {
return testShardID
}

return 0
}
mockShardCoordinator.SelfIdCalled = func() uint32 {
return core.MetachainShardId
}

irt, err := rewardTransaction.NewInterceptedRewardTransaction(
txBuff,
marshalizer,
&hashingMocks.HasherMock{},
createMockPubkeyConverter(),
mockShardCoordinator)
assert.Nil(t, err)
assert.True(t, irt.IsForCurrentShard())
})
t.Run("different shard should return false", func(t *testing.T) {
mockShardCoordinator.ComputeIdCalled = func(address []byte) uint32 {
if bytes.Equal(address, receiverAddress) {
return testShardID
}

return 0
}
mockShardCoordinator.SelfIdCalled = func() uint32 {
return testShardID + 1 // different with the receiver but not metachain
}

irt, err := rewardTransaction.NewInterceptedRewardTransaction(
txBuff,
marshalizer,
&hashingMocks.HasherMock{},
createMockPubkeyConverter(),
mockShardCoordinator)
assert.Nil(t, err)
assert.False(t, irt.IsForCurrentShard())
})
}

func TestInterceptedRewardTransaction_Type(t *testing.T) {
t.Parallel()

Expand Down
2 changes: 1 addition & 1 deletion process/track/miniBlockTrack.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func (mbt *miniBlockTrack) receivedMiniBlock(key []byte, value interface{}) {
return
}

log.Trace("miniBlockTrack.receivedMiniBlock",
log.Debug("received miniblock from network in block tracker",
"hash", key,
"sender", miniBlock.SenderShardID,
"receiver", miniBlock.ReceiverShardID,
Expand Down

0 comments on commit b94c62d

Please sign in to comment.