github.com/koko1123/flow-go-1@v0.29.6/module/epochs/epoch_config.go (about)

     1  package epochs
     2  
     3  import (
     4  	"github.com/onflow/cadence"
     5  	jsoncdc "github.com/onflow/cadence/encoding/json"
     6  
     7  	"github.com/onflow/flow-go/crypto"
     8  	"github.com/koko1123/flow-go-1/model/flow"
     9  )
    10  
    11  // EpochConfig is a placeholder for config values used to deploy the epochs
    12  // smart-contract.
    13  type EpochConfig struct {
    14  	EpochTokenPayout             cadence.UFix64
    15  	RewardCut                    cadence.UFix64
    16  	CurrentEpochCounter          cadence.UInt64
    17  	NumViewsInEpoch              cadence.UInt64
    18  	NumViewsInStakingAuction     cadence.UInt64
    19  	NumViewsInDKGPhase           cadence.UInt64
    20  	NumCollectorClusters         cadence.UInt16
    21  	FLOWsupplyIncreasePercentage cadence.UFix64
    22  	RandomSource                 cadence.String
    23  	CollectorClusters            flow.AssignmentList
    24  	ClusterQCs                   []*flow.QuorumCertificate
    25  	DKGPubKeys                   []crypto.PublicKey
    26  }
    27  
    28  // DefaultEpochConfig returns an EpochConfig with default values used for
    29  // testing.
    30  func DefaultEpochConfig() EpochConfig {
    31  	return EpochConfig{
    32  		CurrentEpochCounter:          cadence.UInt64(0),
    33  		NumViewsInEpoch:              cadence.UInt64(100),
    34  		NumViewsInStakingAuction:     cadence.UInt64(10),
    35  		NumViewsInDKGPhase:           cadence.UInt64(10),
    36  		NumCollectorClusters:         cadence.UInt16(3),
    37  		FLOWsupplyIncreasePercentage: cadence.UFix64(5),
    38  	}
    39  }
    40  
    41  // EncodeClusterAssignments encodes a slice of QuorumCertificates into an encoded
    42  // transaction argument for the deployEpoch transaction used during execution
    43  // state bootstrapping.
    44  //
    45  // The resulting argument has type [{String: UInt64}] which represents a list
    46  // of weight mappings for each cluster. The full Cluster struct is constructed
    47  // within the transaction in Cadence for simplicity here.
    48  func EncodeClusterAssignments(clusterAssignments flow.AssignmentList) []byte {
    49  
    50  	weightMappingPerCluster := []cadence.Value{}
    51  	for _, cluster := range clusterAssignments {
    52  
    53  		weightsByNodeID := []cadence.KeyValuePair{}
    54  		for _, id := range cluster {
    55  			cdcNodeID, err := cadence.NewString(id.String())
    56  			if err != nil {
    57  				panic(err)
    58  			}
    59  			kvp := cadence.KeyValuePair{
    60  				Key:   cdcNodeID,
    61  				Value: cadence.NewUInt64(1),
    62  			}
    63  			weightsByNodeID = append(weightsByNodeID, kvp)
    64  		}
    65  
    66  		weightMappingPerCluster = append(weightMappingPerCluster, cadence.NewDictionary(weightsByNodeID))
    67  	}
    68  
    69  	asArray := cadence.NewArray(weightMappingPerCluster)
    70  	return jsoncdc.MustEncode(asArray)
    71  }