Skip to content

Conversation

@bogdan-rosianu
Copy link
Contributor

Reasoning behind the pull request

  • some components used static values for consensus group size

Proposed changes

  • created a chain parameters change notifier and integrate it where needed

Testing procedure

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?

@bogdan-rosianu bogdan-rosianu marked this pull request as ready for review February 2, 2023 09:35
@iulianpascalau iulianpascalau self-requested a review February 2, 2023 09:36
}

// New creates a new instance of a chainParametersNotifier component
func New() *chainParametersNotifier {
Copy link
Contributor

Choose a reason for hiding this comment

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

NewChainParametersNotifier to be consistent with the rest of the project

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok :(

cpn.currentChainParameters = params
cpn.mutData.Unlock()

cpn.mutHandler.RLock()
Copy link
Contributor

Choose a reason for hiding this comment

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

L32-L46 ensures that the handlers are called only once for each epoch change regardless of the number of UpdateCurrentChainParameters calls. However, if the calls for different epochs are called in extremely fast manner in parallel, some calls on the handlers can be made in a different order. I do not think this will be an issue because the processing is done in sync.

SetPeerValidatorMapper(validatorMapper process.PeerValidatorMapper) error
SetTopicsForAll(topics ...string)
ApplyConsensusSize(size int)
SetConsensusSizeNotifier(chainParametersNotifier process.ChainParametersSubscriber, shardID uint32)
Copy link
Contributor

Choose a reason for hiding this comment

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

let's inject this into the constructor. No need for a setter.

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 the shard ID is unknown when creating the antiflood components, I cannot make this change

Copy link
Contributor

Choose a reason for hiding this comment

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

ok

Value: shardID,
}

chainParametersNotifier.RegisterNotifyHandler(af)
Copy link
Contributor

Choose a reason for hiding this comment

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

this can be called on the constructor

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 the shard ID is unknown when creating the antiflood components, I cannot make this change

Copy link
Contributor

Choose a reason for hiding this comment

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

ok


// ChainParametersChanged will be called when new chain parameters are confirmed on the network
func (af *p2pAntiflood) ChainParametersChanged(chainParameters config.ChainParametersByEpochConfig) {
size := chainParameters.ShardConsensusGroupSize
Copy link
Contributor

Choose a reason for hiding this comment

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

concurrency issues on the usage of the af.shardID ?
Also why do we need the set on L76?

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 mutex. the setter is needed for computing the consensus size in case of shard vs meta

"github.com/stretchr/testify/require"
)

func TestNew(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

TestNewChainParametersNotifier ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done


// Close will call the close function on all sub components
func (af *p2pAntiflood) Close() error {
af.mutDebugger.Lock()
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@codecov-commenter
Copy link

codecov-commenter commented Feb 17, 2023

Codecov Report

❗ No coverage uploaded for pull request base (feat/consensus-size-changes@df0b4fd). Click here to learn what that means.
Patch has no changes to coverable lines.

❗ Current head 80d86a8 differs from pull request most recent head 961bb62. Consider uploading reports for the commit 961bb62 to get more accurate results

Additional details and impacted files
@@                      Coverage Diff                       @@
##             feat/consensus-size-changes    #4927   +/-   ##
==============================================================
  Coverage                               ?   70.91%           
==============================================================
  Files                                  ?      677           
  Lines                                  ?    87950           
  Branches                               ?        0           
==============================================================
  Hits                                   ?    62370           
  Misses                                 ?    20897           
  Partials                               ?     4683           

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

iulianpascalau
iulianpascalau previously approved these changes Feb 17, 2023
…fier

# Conflicts:
#	common/interface.go
#	factory/consensus/consensusComponents.go
#	integrationTests/testConsensusNode.go
#	process/throttle/antiflood/p2pAntiflood_test.go
}
cc := &consensusComponents{}

consensusGroupSize, err := getConsensusGroupSize(ccf.coreComponents.GenesisNodesSetup(), ccf.processComponents.ShardCoordinator())
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

Value: shardID,
}

chainParametersNotifier.RegisterNotifyHandler(af)
Copy link
Contributor

Choose a reason for hiding this comment

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

ok

type Node struct {
initialNodesPubkeys map[uint32][]string
roundDuration uint64
consensusGroupSize int
Copy link
Contributor

Choose a reason for hiding this comment

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

minor conflicts here when we will bring the rc/v1.5.0 in rc/v1.6.0 because I've added unit test for the getter & setter of the consensus group size

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll happily delete those unit tests when merging 😄

}, nil
}

if epoch < 9 {
Copy link
Contributor

Choose a reason for hiding this comment

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

👍 nice approach to avoid calls like if (epoch < 9) && (epoch >= 6) {...

EpochStart: block.EpochStart{LastFinalizedHeaders: []block.EpochStartShardData{{}}},
}

// change to epoch 1 - should have 3 eligible per shard, 3 per meta
Copy link
Contributor

Choose a reason for hiding this comment

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

I would also add tests for epochs 2, 3, 4, 6, 8, 9, 10, and 11 to test the correct change conditions

Copy link
Contributor Author

Choose a reason for hiding this comment

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

refactored the unit test and now it checks from epoch 0 to epoch 100

iulianpascalau
iulianpascalau previously approved these changes Apr 3, 2023
gabi-vuls
gabi-vuls previously approved these changes Apr 4, 2023
Copy link
Contributor

@gabi-vuls gabi-vuls left a comment

Choose a reason for hiding this comment

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

@@ Log scanner @@

chain-params-notifier-test-mar30

================================================================================

  • Known Warnings 11
  • New Warnings 5
  • Known Errors 0
  • New Errors 0
  • Panics 0
    ================================================================================
  • block hash does not match 10501
  • wrong nonce in block 3632
  • miniblocks does not match 0
  • num miniblocks does not match 0
  • miniblock hash does not match 0
  • block bodies does not match 0
  • receipts hash missmatch 0
    ================================================================================
  • No jailed nodes on the thestnet
    ================================================================================


afm.ApplyConsensusSize(expectedSize)
chainParamsSubscriber := chainparametersnotifier.NewChainParametersNotifier()
afm.SetConsensusSizeNotifier(chainParamsSubscriber, 5)
Copy link
Contributor

Choose a reason for hiding this comment

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

can you use a variable/constant instead of literal 5?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done


// Close will call the close function on all sub components
func (af *p2pAntiflood) Close() error {
af.mutDebugger.Lock()
Copy link
Contributor

Choose a reason for hiding this comment

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

rlock?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@bogdan-rosianu bogdan-rosianu dismissed stale reviews from gabi-vuls and iulianpascalau via 961bb62 April 11, 2023 11:39
Copy link
Contributor

@gabi-vuls gabi-vuls left a comment

Choose a reason for hiding this comment

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

System test passed

@bogdan-rosianu bogdan-rosianu merged commit ab675e9 into feat/consensus-size-changes Apr 11, 2023
@bogdan-rosianu bogdan-rosianu deleted the chain-parameters-notifier branch April 11, 2023 13:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants