mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-28 07:36:44 +00:00
Sorted Difficulties
This commit is contained in:
parent
e0b43b0116
commit
b172ba8fbf
1 changed files with 23 additions and 2 deletions
|
|
@ -4,6 +4,7 @@ import (
|
|||
"encoding/hex"
|
||||
"math"
|
||||
"math/big"
|
||||
"sort"
|
||||
"strconv"
|
||||
"sync"
|
||||
|
||||
|
|
@ -47,11 +48,29 @@ func (api *API) GetSnapshot(number *rpc.BlockNumber) (*Snapshot, error) {
|
|||
}
|
||||
|
||||
type BlockSigners struct {
|
||||
Signers map[common.Address]uint64
|
||||
Signers []difficultiesKV
|
||||
Diff int
|
||||
Author common.Address
|
||||
}
|
||||
|
||||
type difficultiesKV struct {
|
||||
Signer common.Address
|
||||
Difficulty uint64
|
||||
}
|
||||
|
||||
func rankMapDifficulties(values map[common.Address]uint64) []difficultiesKV {
|
||||
|
||||
var ss []difficultiesKV
|
||||
for k, v := range values {
|
||||
ss = append(ss, difficultiesKV{k, v})
|
||||
}
|
||||
sort.Slice(ss, func(i, j int) bool {
|
||||
return ss[i].Difficulty > ss[j].Difficulty
|
||||
})
|
||||
|
||||
return ss
|
||||
}
|
||||
|
||||
// GetSnapshotProposerSequence retrieves the in-turn signers of all sprints in a span
|
||||
func (api *API) GetSnapshotProposerSequence(number *rpc.BlockNumber) (BlockSigners, error) {
|
||||
snapNumber := *number - 1
|
||||
|
|
@ -72,13 +91,15 @@ func (api *API) GetSnapshotProposerSequence(number *rpc.BlockNumber) (BlockSigne
|
|||
difficulties[signers[i]] = uint64(len(signers) - (tempIndex - proposerIndex))
|
||||
}
|
||||
|
||||
difficulties2 := rankMapDifficulties(difficulties)
|
||||
|
||||
author, err := api.GetAuthor(number)
|
||||
if err != nil {
|
||||
return BlockSigners{}, err
|
||||
}
|
||||
diff := int(difficulties[*author])
|
||||
blockSigners := &BlockSigners{
|
||||
Signers: difficulties,
|
||||
Signers: difficulties2,
|
||||
Diff: diff,
|
||||
Author: *author,
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue