Skip to content

Conversation

@envestcc
Copy link
Member

Description

base #4593

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

@envestcc envestcc mentioned this pull request Mar 26, 2025
@envestcc envestcc mentioned this pull request Mar 28, 2025
@envestcc envestcc marked this pull request as ready for review April 2, 2025 02:40
@envestcc envestcc requested review from a team, CoderZhi, Liuhaai and dustinxie as code owners April 2, 2025 02:40
return sAcceptBlockProposal, nil
}

if err := m.ctx.PrepareNextProposal(cEvt.Data()); err != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

var privateKey crypto.PrivateKey = nil
if idx := slices.Index(ctx.encodedAddrs, nextProposer); idx < 0 {
return nil
} else {
Copy link
Collaborator

Choose a reason for hiding this comment

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

delete else

} else if ctx.round.IsLocked() {
blockHash = ctx.round.HashOfBlockInLock()
} else {
if err := ctx.prepareNextProposal(ctx.round.Height()-1, ctx.round.PrevHash()); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

why now need to prepareNextProposal() in this case?

Copy link
Member Author

Choose a reason for hiding this comment

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

msg == nil means that the proposal for this round was not received in time; in this case, it's possible to mint the proposal for round +1 in advance.

privateKey = ctx.priKeys[idx]
}
ctx.logger().Debug("prepare next proposal", log.Hex("prevHash", prevHash[:]), zap.Uint64("height", ctx.round.height+1), zap.Time("timestamp", startTime), zap.String("nextproposer", nextProposer))
go func() {
Copy link
Contributor

Choose a reason for hiding this comment

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

why use go func() here

Copy link
Contributor

Choose a reason for hiding this comment

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

minor:
if fork.MintNewBlock() errs out, the error won't be captured and handled

Copy link
Member Author

Choose a reason for hiding this comment

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

MintNewBlock keep mint result in memory, and will return it if mint same block. Here is to just to start the next proposal mint in advance, which can be run in background.

@sonarqubecloud
Copy link

@CoderZhi CoderZhi merged commit f7a636c into iotexproject:master Apr 21, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants