-
Notifications
You must be signed in to change notification settings - Fork 203
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5683 from multiversx/sorting-on-current-randomness
switch to current block randomness for ordering transactions
- Loading branch information
Showing
13 changed files
with
90 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package helpers | ||
|
||
import ( | ||
"github.com/multiversx/mx-chain-core-go/data" | ||
"github.com/multiversx/mx-chain-go/common" | ||
) | ||
|
||
// ComputeRandomnessForTxSorting returns the randomness for transactions sorting | ||
func ComputeRandomnessForTxSorting(header data.HeaderHandler, enableEpochsHandler common.EnableEpochsHandler) []byte { | ||
if enableEpochsHandler.IsFlagEnabled(common.CurrentRandomnessOnSortingFlag) { | ||
return header.GetRandSeed() | ||
} | ||
|
||
return header.GetPrevRandSeed() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package helpers | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/multiversx/mx-chain-core-go/core" | ||
"github.com/multiversx/mx-chain-core-go/data/block" | ||
"github.com/multiversx/mx-chain-go/testscommon/enableEpochsHandlerMock" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestComputeRandomnessForTxSorting(t *testing.T) { | ||
t.Parallel() | ||
|
||
header := &block.Header{ | ||
RandSeed: []byte{0x01}, | ||
PrevRandSeed: []byte{0x02}, | ||
} | ||
|
||
t.Run("flag not active should return previous randomness", func(t *testing.T) { | ||
t.Parallel() | ||
|
||
enableEpochsHandler := &enableEpochsHandlerMock.EnableEpochsHandlerStub{ | ||
IsFlagEnabledCalled: func(flag core.EnableEpochFlag) bool { | ||
return false | ||
}, | ||
} | ||
require.Equal(t, header.PrevRandSeed, ComputeRandomnessForTxSorting(header, enableEpochsHandler)) | ||
}) | ||
t.Run("flag active should return current randomness", func(t *testing.T) { | ||
t.Parallel() | ||
|
||
enableEpochsHandler := &enableEpochsHandlerMock.EnableEpochsHandlerStub{ | ||
IsFlagEnabledCalled: func(flag core.EnableEpochFlag) bool { | ||
return true | ||
}, | ||
} | ||
require.Equal(t, header.RandSeed, ComputeRandomnessForTxSorting(header, enableEpochsHandler)) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters