-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
deleting extra file and add missing pkg
- Loading branch information
Matthew Lam
committed
Aug 25, 2023
1 parent
a83a29e
commit 477703c
Showing
4 changed files
with
53 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
This package contains functions and types that are implemented in various dev branches. They are copied here to aid in concurrent development, and to keep this repo's dependencies limited to tagged releases |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// (c) 2023, Ava Labs, Inc. All rights reserved. | ||
// See the file LICENSE for licensing terms. | ||
|
||
package temp | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/ava-labs/avalanchego/utils" | ||
"github.com/ava-labs/avalanchego/utils/math" | ||
"github.com/ava-labs/avalanchego/vms/platformvm" | ||
"github.com/ava-labs/avalanchego/vms/platformvm/warp" | ||
"golang.org/x/exp/maps" | ||
) | ||
|
||
// Keep this function here until we're able to get a validators.State object from the P-Chain API. | ||
// Then, we can call warp.GetCanonicalValidatorSet | ||
func GetCanonicalValidatorSet(vdrSet []platformvm.ClientPermissionlessValidator) ([]*warp.Validator, uint64, error) { | ||
var ( | ||
vdrs = make(map[string]*warp.Validator, len(vdrSet)) | ||
totalWeight uint64 | ||
err error | ||
) | ||
for _, vdr := range vdrSet { | ||
totalWeight, err = math.Add64(totalWeight, vdr.Weight) | ||
if err != nil { | ||
return nil, 0, fmt.Errorf("%w: %s", warp.ErrWeightOverflow, err) | ||
} | ||
pk := vdr.Signer.Key() | ||
if pk == nil { | ||
continue | ||
} | ||
pkBytes := pk.Serialize() | ||
uniqueVdr, ok := vdrs[string(pkBytes)] | ||
if !ok { | ||
uniqueVdr = &warp.Validator{ | ||
PublicKey: pk, | ||
PublicKeyBytes: pkBytes, | ||
} | ||
vdrs[string(pkBytes)] = uniqueVdr | ||
} | ||
uniqueVdr.Weight += vdr.Weight // Impossible to overflow here | ||
uniqueVdr.NodeIDs = append(uniqueVdr.NodeIDs, vdr.NodeID) | ||
|
||
} | ||
|
||
// Sort validators by public key | ||
vdrList := maps.Values(vdrs) | ||
utils.Sort(vdrList) | ||
return vdrList, totalWeight, nil | ||
} |