Skip to content

support multiple producers#4580

Merged
CoderZhi merged 3 commits intomasterfrom
multiple_producers
Mar 24, 2025
Merged

support multiple producers#4580
CoderZhi merged 3 commits intomasterfrom
multiple_producers

Conversation

@CoderZhi
Copy link
Collaborator

as title

Fixes #(issue)

Type of change

Please delete options that are not relevant.

  • [] Bug fix (non-breaking change which fixes an issue)
  • [] New feature (non-breaking change which adds functionality)
  • [] Code refactor or improvement
  • [] Breaking change (fix or feature that would cause a new or changed behavior of existing functionality)
  • [] This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • [] make test
  • [] fullsync
  • [] Other test (please specify)

Test Configuration:

  • Firmware version:
  • Hardware:
  • Toolchain:
  • SDK:

Checklist:

  • [] My code follows the style guidelines of this project
  • [] I have performed a self-review of my code
  • [] I have commented my code, particularly in hard-to-understand areas
  • [] I have made corresponding changes to the documentation
  • [] My changes generate no new warnings
  • [] I have added tests that prove my fix is effective or that my feature works
  • [] New and existing unit tests pass locally with my changes
  • [] Any dependent changes have been merged and published in downstream modules

@CoderZhi CoderZhi requested review from a team, Liuhaai, dustinxie and envestcc as code owners March 14, 2025 11:24
@envestcc envestcc requested a review from Copilot March 18, 2025 02:23
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors the consensus and blockchain modules to support multiple producers instead of a single producer by replacing singular fields (e.g. encodedAddr, priKey) with slices (encodedAddrs, priKeys) and updating the associated logic. Key changes include:

  • Updating the rollDPoS context and related functions to handle multiple producer keys and addresses.
  • Refactoring endorsement and block minting routines to work with multiple endorsements and key selections.
  • Modifying tests and configuration functions across consensus, blockchain, and server components to align with the new multi-producer support.

Reviewed Changes

Copilot reviewed 23 out of 23 changed files in this pull request and generated no comments.

Show a summary per file
File Description
consensus/scheme/rolldpos/rolldposctx.go Replaced singular producer fields with slices and updated proposal and endorsement flows accordingly.
blockchain/config.go Updated API calls to use MainProducerAddress/MainProducerPrivateKey in place of single producer functions.
endorsement/endorsement.go Modified the Endorse function to return a slice of endorsements for multiple signers.
blockchain/blockchain.go Revised the MintNewBlock signature and logic to support filtering on multiple producer keys.
consensus/scheme/rolldpos/roundctx.go Updated ReadyToCommit and delegate checks to iterate over multiple producer addresses.
consensus/consensusfsm/* Changed consensus event production routines to return/process slices of events rather than a single event.
Various tests and mocks Adjusted tests, builders, and mocks to remove obsolete SetAddr calls and refer to multi-producer APIs.
Comments suppressed due to low confidence (3)

consensus/scheme/rolldpos/rolldposctx.go:691

  • The check for exactly one endorsement may be too strict now that the system supports multiple producers; consider if multiple valid endorsements should be accepted or if the logic needs updating to handle the new multi-producer scenario.
if len(ens) != 1 {

consensus/scheme/rolldpos/rolldpos.go:123

  • The 'height' parameter is accepted but not used when calling bc.MintNewBlock; verify whether the intended block height should influence block minting or if the parameter should be removed.
func (cm *chainManager) MintNewBlock(height uint64, timestamp time.Time, fs ...blockchain.FilterFunc) (*block.Block, error) {

consensus/consensusfsm/mock_context_test.go:206

  • Ensure that all occurrences and mocks referring to delegate status consistently use 'HasDelegate' instead of the deprecated 'IsDelegate' to avoid confusion in both production and test code.
func (m *MockContext) HasDelegate() bool {

// TODO: we should use keystore in the future
encodedAddr string
priKey crypto.PrivateKey
priKey []crypto.PrivateKey
Copy link
Member

Choose a reason for hiding this comment

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

priKeys

// MintNewBlock creates a new block with given actions
func (cm *chainManager) MintNewBlock(timestamp time.Time) (*block.Block, error) {
return cm.bc.MintNewBlock(timestamp)
func (cm *chainManager) MintNewBlock(height uint64, timestamp time.Time, fs ...blockchain.FilterFunc) (*block.Block, error) {
Copy link
Member

Choose a reason for hiding this comment

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

The height parameter has not been used.

// MintNewBlock creates a new block with given actions
// Note: the coinbase transfer will be added to the given transfers when minting a new block
MintNewBlock(timestamp time.Time) (*block.Block, error)
MintNewBlock(time.Time, ...FilterFunc) (*block.Block, error)
Copy link
Member

Choose a reason for hiding this comment

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

only minter address param maybe enough

Copy link
Member

@envestcc envestcc left a comment

Choose a reason for hiding this comment

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

mainly looks good to me, left two small comments

@CoderZhi CoderZhi force-pushed the multiple_producers branch from 6208d94 to 03c109e Compare March 23, 2025 15:07
@sonarqubecloud
Copy link

@CoderZhi CoderZhi merged commit 52f041d into master Mar 24, 2025
5 checks passed
@CoderZhi CoderZhi deleted the multiple_producers branch March 24, 2025 13:42
envestcc pushed a commit that referenced this pull request Apr 21, 2025
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.

4 participants