Skip to content

Enhance: Blocksmith Selection #1190

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

Closed
andy-shi88 opened this issue Sep 22, 2020 · 0 comments · Fixed by #1357
Closed

Enhance: Blocksmith Selection #1190

andy-shi88 opened this issue Sep 22, 2020 · 0 comments · Fixed by #1357
Assignees
Labels
CORE core functionalities ENHANCE

Comments

@andy-shi88
Copy link
Contributor

andy-shi88 commented Sep 22, 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.

@andy-shi88 andy-shi88 added CORE core functionalities ENHANCE labels Sep 22, 2020
@andy-shi88 andy-shi88 changed the title Enhance: Blocksmith Selection [PENDING] Enhance: Blocksmith Selection Sep 29, 2020
iltoga pushed a commit that referenced this issue Nov 3, 2020
* remove active node registry when participation score reach 0

* calculateNodeOrder divide by 1, it is not used anymore, will be removed in new blocksmith selection implementation #1190

* omit division

* fix tests

* remove outdated test
astaphobia pushed a commit that referenced this issue Nov 4, 2020
…- this fix will be omitted in next beta since blocksmith strategy will be revamped in #1190 (#1334)
@abiman7u abiman7u added this to the V.0.0.2.W.02 milestone Nov 12, 2020
sukrawidhyawan pushed a commit that referenced this issue Nov 16, 2020
* update func WillSmith, isMe, IsBlockValid on BlocksmithStrategySpine

* create func CumulativeDifficulty on strategy

* add getRound and temporary-CanPersist function

* remove func GetSortedBlocksmithsMap from package strategy

* add getSkippedBlocksmith functioon

* add new func , remove func , change blocksmithIndex to round

* remove parameter 'block' in isMe func
* #1190 inject random number generator to strategy main

* #1190 fix candidate time calculation

* #1190 separate get smithing round and smithing index function

* #1190 temporarily disable spinechain smithing

* Implementated the new blocksmith selection on spinechain

* #1190 handle previous block skipped blocksmith - blocktime offset.

* #1190 avoid process node-admit, node-expel, blocksmith reward, and skipped blocksmith before accepted/generated block is sure to be persisted to database

* #1190 use estimated persist timestamp for block validation

Co-authored-by: andy-shi88 <[email protected]>
sukrawidhyawan pushed a commit that referenced this issue Nov 17, 2020
iltoga pushed a commit that referenced this issue Nov 18, 2020
* #1190 fix: inconsistent previous block timestamp + fix cumulative difficulty calculated too early in the block

* #1190 remove unused variables
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CORE core functionalities ENHANCE
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants