Skip to content

Commit

Permalink
deleting extra file and add missing pkg
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew Lam committed Aug 25, 2023
1 parent a83a29e commit 477703c
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 44 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ require (
github.com/spf13/viper v1.16.0
github.com/stretchr/testify v1.8.4
go.uber.org/zap v1.25.0
golang.org/x/exp v0.0.0-20230206171751-46f607a40771
)

require (
Expand All @@ -27,7 +28,6 @@ require (
github.com/spf13/cast v1.5.1 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/subosito/gotenv v1.4.2 // indirect
golang.org/x/exp v0.0.0-20230206171751-46f607a40771 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
)

Expand Down
43 changes: 0 additions & 43 deletions relayer/canonical_validator_client.go

This file was deleted.

1 change: 1 addition & 0 deletions temp/README.md
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
51 changes: 51 additions & 0 deletions temp/temp.go
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
}

0 comments on commit 477703c

Please sign in to comment.