-
Notifications
You must be signed in to change notification settings - Fork 21.5k
consensus/clique: add clique_status API method #20103
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,8 @@ | |
| package clique | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| "github.com/ethereum/go-ethereum/common" | ||
| "github.com/ethereum/go-ethereum/consensus" | ||
| "github.com/ethereum/go-ethereum/core/types" | ||
|
|
@@ -117,3 +119,60 @@ func (api *API) Discard(address common.Address) { | |
|
|
||
| delete(api.clique.proposals, address) | ||
| } | ||
|
|
||
| type CliqueStatus struct { | ||
| InturnPercent float64 `json:"inturnPercent"` | ||
| SigningStatus map[common.Address]int `json:"sealerActivity""` | ||
| NumBlocks uint64 `json:"numBlocks"` | ||
| } | ||
|
|
||
| // Status returns the status of the last N blocks, | ||
| // - the number of active signers, | ||
| // - the number of signers, | ||
| // - the percentage of in-turn blocks | ||
| func (api *API) Status() (*CliqueStatus, error) { | ||
| var ( | ||
| numBlocks = uint64(64) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hard coding 64 seems overly arbitrary. We should probably convert it into an optional parameter, defaulting to 64 if unspecified perhaps. Though even then 64 blocks is 16 minutes, not sure if that's relevant enough.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps it would be cleaner to make this a mandatory argument (and also drop the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree that |
||
| header = api.chain.CurrentHeader() | ||
| diff = uint64(0) | ||
| optimals = 0 | ||
| ) | ||
| snap, err := api.clique.snapshot(api.chain, header.Number.Uint64(), header.Hash(), nil) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| var ( | ||
| signers = snap.signers() | ||
| end = header.Number.Uint64() | ||
| start = end - numBlocks | ||
| ) | ||
| if numBlocks > end { | ||
| start = 1 | ||
| numBlocks = end - start | ||
| } | ||
| signStatus := make(map[common.Address]int) | ||
| for _, s := range signers { | ||
| signStatus[s] = 0 | ||
| } | ||
| for n := start; n < end; n++ { | ||
| h := api.chain.GetHeaderByNumber(n) | ||
| if h != nil { | ||
| if h.Difficulty.Cmp(diffInTurn) == 0 { | ||
| optimals += 1 | ||
| } | ||
| diff += h.Difficulty.Uint64() | ||
| if sealer, err := api.clique.Author(h); err != nil { | ||
| return nil, err | ||
| } else { | ||
holiman marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| signStatus[sealer] += 1 | ||
holiman marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| } else { | ||
| return nil, fmt.Errorf("missing block %d", n) | ||
holiman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
| return &CliqueStatus{ | ||
| InturnPercent: float64((100 * optimals)) / float64(numBlocks), | ||
| SigningStatus: signStatus, | ||
| NumBlocks: numBlocks, | ||
| }, nil | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.