mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-10 14:03:46 +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"
|
"encoding/hex"
|
||||||
"math"
|
"math"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
|
@ -47,11 +48,29 @@ func (api *API) GetSnapshot(number *rpc.BlockNumber) (*Snapshot, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
type BlockSigners struct {
|
type BlockSigners struct {
|
||||||
Signers map[common.Address]uint64
|
Signers []difficultiesKV
|
||||||
Diff int
|
Diff int
|
||||||
Author common.Address
|
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
|
// GetSnapshotProposerSequence retrieves the in-turn signers of all sprints in a span
|
||||||
func (api *API) GetSnapshotProposerSequence(number *rpc.BlockNumber) (BlockSigners, error) {
|
func (api *API) GetSnapshotProposerSequence(number *rpc.BlockNumber) (BlockSigners, error) {
|
||||||
snapNumber := *number - 1
|
snapNumber := *number - 1
|
||||||
|
|
@ -72,13 +91,15 @@ func (api *API) GetSnapshotProposerSequence(number *rpc.BlockNumber) (BlockSigne
|
||||||
difficulties[signers[i]] = uint64(len(signers) - (tempIndex - proposerIndex))
|
difficulties[signers[i]] = uint64(len(signers) - (tempIndex - proposerIndex))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
difficulties2 := rankMapDifficulties(difficulties)
|
||||||
|
|
||||||
author, err := api.GetAuthor(number)
|
author, err := api.GetAuthor(number)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return BlockSigners{}, err
|
return BlockSigners{}, err
|
||||||
}
|
}
|
||||||
diff := int(difficulties[*author])
|
diff := int(difficulties[*author])
|
||||||
blockSigners := &BlockSigners{
|
blockSigners := &BlockSigners{
|
||||||
Signers: difficulties,
|
Signers: difficulties2,
|
||||||
Diff: diff,
|
Diff: diff,
|
||||||
Author: *author,
|
Author: *author,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue