Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

switch to current block randomness for ordering transactions #5683

Merged
merged 7 commits into from
Jan 16, 2024

Conversation

AdoAdoAdo
Copy link
Contributor

Reasoning behind the pull request

  • using the current randomness instead of previous randomness increases resistance against front running.

Proposed changes

  • switch to the current randomness for sorting transactions

Testing procedure

  • full system test
  • system test with upgrade

Pre-requisites

Based on the Contributing Guidelines the PR author and the reviewers must check the following requirements are met:

  • was the PR targeted to the correct branch?
  • if this is a larger feature that probably needs more than one PR, is there a feat branch created?
  • if this is a feat branch merging, do all satellite projects have a proper tag inside go.mod?

@AdoAdoAdo AdoAdoAdo self-assigned this Nov 3, 2023
Copy link

codecov bot commented Nov 3, 2023

Codecov Report

Attention: 2 lines in your changes are missing coverage. Please review.

Comparison is base (023a194) 80.31% compared to head (945c4fb) 80.35%.

Files Patch % Lines
process/block/preprocess/transactions.go 33.33% 2 Missing ⚠️
Additional details and impacted files
@@              Coverage Diff              @@
##           rc/v1.7.0    #5683      +/-   ##
=============================================
+ Coverage      80.31%   80.35%   +0.04%     
=============================================
  Files            708      709       +1     
  Lines          93961    93973      +12     
=============================================
+ Hits           75462    75513      +51     
+ Misses         13219    13181      -38     
+ Partials        5280     5279       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -928,7 +928,12 @@ func (mp *metaProcessor) createBlockBody(metaBlock data.HeaderHandler, haveTime
"nonce", metaBlock.GetNonce(),
)

miniBlocks, err := mp.createMiniBlocks(haveTime, metaBlock.GetPrevRandSeed())
randomness := metaBlock.GetPrevRandSeed()
if mp.enableEpochsHandler.IsFlagEnabled(common.CurrentRandomnessOnSortingFlag) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

L932-L934 can be a common function in baseProcess.go, something like:

func (bp *baseProcessor) computeRandomnessForTxSorting(hdr HeaderHandler) []byte {
    if bp.enableEpochsHandler.IsFlagEnabled(common.CurrentRandomnessOnSortingFlag){
        return hdr.GetRandSeed()
    }

    return hdr.GetPrevRandSeed()
}

this function can be then reused in shardblock.go

Or better, an exported "helper" function in the process/block package so it can be reused in preprocess/transactions.go

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added a helper function

@@ -683,6 +683,12 @@ func (handler *enableEpochsHandler) createAllFlagsMap() {
},
activationEpoch: handler.enableEpochsConfig.NFTStopCreateEnableEpoch,
},
common.CurrentRandomnessOnSortingFlag: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing test asserts in tomlConfig_test.go
missing tests in enableEpochsHandler_test.go

@@ -928,7 +928,12 @@ func (mp *metaProcessor) createBlockBody(metaBlock data.HeaderHandler, haveTime
"nonce", metaBlock.GetNonce(),
)

miniBlocks, err := mp.createMiniBlocks(haveTime, metaBlock.GetPrevRandSeed())
randomness := metaBlock.GetPrevRandSeed()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing flag definition in checkProcessorParameters, L518

@@ -332,7 +332,11 @@ func (txs *transactions) ProcessBlockTransactions(
}

if txs.isBodyFromMe(body) {
return txs.processTxsFromMe(body, haveTime, header.GetPrevRandSeed())
randomness := header.GetPrevRandSeed()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing flag definition in checkProcessorParameters, L143

iulianpascalau
iulianpascalau previously approved these changes Nov 28, 2023
@@ -0,0 +1,15 @@
package helpers
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this file could have been placed directly on process/block package so we could have avoid the helper package

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since this needs to be imported from different packages, it's better to be in a separate package to avoid circular dependencies

@@ -824,6 +824,9 @@ func TestEnableEpochConfig(t *testing.T) {
# NFTStopCreateEnableEpoch represents the epoch when NFT stop create feature is enabled
NFTStopCreateEnableEpoch = 89

# CurrentRandomnessOnSortingEnableEpoch represents the epoch when the current randomness on sorting is enabled
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrong alignment

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spaces vs tab, fixed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same issue for the comment

@@ -26,6 +27,8 @@ func TestExecuteBlocksWithTransactionsAndCheckRewards(t *testing.T) {
t.Skip("this is not a short test")
}

_ = logger.SetLogLevel("process:TRACE")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this still needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

# Conflicts:
#	cmd/node/config/enableEpochs.toml
#	common/constants.go
#	common/enablers/enableEpochsHandler.go
#	common/enablers/enableEpochsHandler_test.go
#	config/epochConfig.go
#	config/tomlConfig_test.go
@iulianpascalau iulianpascalau merged commit d49fcca into rc/v1.7.0 Jan 16, 2024
8 checks passed
@iulianpascalau iulianpascalau deleted the sorting-on-current-randomness branch January 16, 2024 12:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants