Skip to content

Enhance blocksmith selection #1243

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

Merged

Conversation

nawikart
Copy link
Contributor

@nawikart nawikart commented Oct 5, 2020

Description

Currently blocksmith is selected by sorting the node registry and assign index of smithing based on their order.

We'll update that behavior to use random number generator to pick an index of sorted node registry (sorted by nodeID so we sort rarely) by using previousBlock.BlockSeed as the seed. With this we open the possibility to let first and second blocksmith be the same node, so we need to handle this carefully given the implementation on mempool and block generate wait time.

note: start tracing this function on BlockService:WillSmith() function.

Breakdown

  • create a candidate struct
Candidate struct {
    Blocksmith Blocksmith
    StartTime int64
    ExpiryTime int64
}
  • WillSmith function will be removed from BlockService
  • Refactor BlocksmithStrategy
type BlocksmithStrategyInterface interface {
    WillSmith(previousBlock *model.Block) bool
    IsSmithingTimeValid(block *model.Block) bool
}

type BlocksmithStrategy struct {
    candidates []Candidate
    lastPreviousBlockHash [32]byte // 
}
  • BlocksmithStrategy.WilSmith should checks if current_time is good for current_node to smith

  • BlocksmithStrategy.IsSmithingTimeValid, should checks if provided Block contain a correct BlocksmithPublicKey and BlockTimestamp regardless the node's current time.

  • generate random number for blocksmith index (still waiting for decision which to choose), by providing:

  • modify skipped blocksmith mechanism to allow 1 blocksmith to skip twice.

  • modify block creation code to handle in case single node selected as blocksmith twice in a row.

  • PushBlock with skipped blocksmith should be faster now, as it won't proccess: admit/expel nodes, participation score calculation, skipped blocksmith calculation before accepted block is marked as persistable

@nawikart nawikart changed the base branch from develop to experimental October 5, 2020 05:26
@nawikart nawikart added ENHANCE WIP CORE core functionalities labels Oct 5, 2020
@nawikart nawikart self-assigned this Oct 5, 2020
@nawikart nawikart marked this pull request as ready for review October 7, 2020 03:28
@nawikart nawikart removed the WIP label Oct 7, 2020
@nawikart nawikart added the WIP label Oct 8, 2020
Copy link
Contributor

@iltoga iltoga left a comment

Choose a reason for hiding this comment

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

lgtm

@andy-shi88
Copy link
Contributor

move back to WIP
unhandled case:

when previousBlock has few skipped blocksmith, the next blocksmith time has not been normalized to start from previousBlock persist time, causing propagated skipped blocksmith for a few first block after skipped blocksmith, and could cause huge smithing time shifting when some nodes are not online for long time.

@andy-shi88 andy-shi88 added the WIP label Nov 6, 2020
@andy-shi88 andy-shi88 self-assigned this Nov 6, 2020
nawikart added 2 commits November 10, 2020 11:01
@abiman7u abiman7u added this to the V.0.0.2.W.02 milestone Nov 12, 2020
@andy-shi88 andy-shi88 changed the base branch from experimental to develop November 13, 2020 08:22
@sukrawidhyawan sukrawidhyawan merged commit 25f48ab into zoobc:develop Nov 16, 2020
@sukrawidhyawan sukrawidhyawan deleted the Enhance-Blocksmith-Selection-1190 branch November 16, 2020 08:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CORE core functionalities ENHANCE WIP
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants