Skip to content

Commit

Permalink
Merge pull request #5576 from onflow/khalil/6959-efm-recvery-epoch-da…
Browse files Browse the repository at this point in the history
…ta-generation

Khalil/6959 Recover Epoch transaction args script
  • Loading branch information
kc1116 authored Apr 17, 2024
2 parents 2d8f653 + e64ad8a commit 9c4c4a3
Show file tree
Hide file tree
Showing 42 changed files with 1,661 additions and 926 deletions.
2 changes: 1 addition & 1 deletion cmd/access/node_builder/access_node_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -1315,7 +1315,7 @@ func (builder *FlowAccessNodeBuilder) InitIDProviders() {
filter.And(
filter.HasRole[flow.Identity](flow.RoleConsensus),
filter.Not(filter.HasNodeID[flow.Identity](node.Me.NodeID())),
underlay.NotEjectedFilter,
filter.NotEjectedFilter,
),
builder.IdentityProvider,
)
Expand Down
11 changes: 9 additions & 2 deletions cmd/bootstrap/cmd/check_machine_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
sdk "github.com/onflow/flow-go-sdk"
client "github.com/onflow/flow-go-sdk/access/grpc"
"github.com/onflow/flow-go/cmd"
"github.com/onflow/flow-go/cmd/util/cmd/common"
model "github.com/onflow/flow-go/model/bootstrap"
"github.com/onflow/flow-go/module/epochs"
)
Expand Down Expand Up @@ -44,7 +45,10 @@ func checkMachineAccountRun(_ *cobra.Command, _ []string) {

// read the private node information - used to get the role
var nodeInfoPriv model.NodeInfoPriv
readJSON(filepath.Join(flagOutdir, fmt.Sprintf(model.PathNodeInfoPriv, nodeID)), &nodeInfoPriv)
err = common.ReadJSON(filepath.Join(flagOutdir, fmt.Sprintf(model.PathNodeInfoPriv, nodeID)), &nodeInfoPriv)
if err != nil {
log.Fatal().Err(err).Msg("failed to read json")
}

// read the machine account info file
machineAccountInfo := readMachineAccountInfo(nodeID)
Expand Down Expand Up @@ -97,7 +101,10 @@ func readMachineAccountInfo(nodeID string) model.NodeMachineAccountInfo {
var machineAccountInfo model.NodeMachineAccountInfo

path := filepath.Join(flagOutdir, fmt.Sprintf(model.PathNodeMachineAccountInfoPriv, nodeID))
readJSON(path, &machineAccountInfo)
err := common.ReadJSON(path, &machineAccountInfo)
if err != nil {
log.Fatal().Err(err).Msg("failed to read json")
}

return machineAccountInfo
}
125 changes: 0 additions & 125 deletions cmd/bootstrap/cmd/clusters.go

This file was deleted.

10 changes: 8 additions & 2 deletions cmd/bootstrap/cmd/db_encryption_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/spf13/cobra"

"github.com/onflow/flow-go/cmd/bootstrap/utils"
"github.com/onflow/flow-go/cmd/util/cmd/common"
model "github.com/onflow/flow-go/model/bootstrap"
)

Expand Down Expand Up @@ -35,7 +36,7 @@ func dbEncryptionKeyRun(_ *cobra.Command, _ []string) {
log = log.With().Str("path", dbEncryptionKeyPath).Logger()

// check if the key already exists
exists, err := pathExists(path.Join(flagOutdir, dbEncryptionKeyPath))
exists, err := common.PathExists(path.Join(flagOutdir, dbEncryptionKeyPath))
if err != nil {
log.Fatal().Err(err).Msg("could not check if db encryption key already exists")
}
Expand All @@ -50,5 +51,10 @@ func dbEncryptionKeyRun(_ *cobra.Command, _ []string) {
}
log.Info().Msg("generated db encryption key")

writeText(dbEncryptionKeyPath, dbEncryptionKey)
err = common.WriteText(dbEncryptionKeyPath, flagOutdir, dbEncryptionKey)
if err != nil {
log.Fatal().Err(err).Msg("failed to write file")
}

log.Info().Msgf("wrote file %s/%s", flagOutdir, dbEncryptionKeyPath)
}
13 changes: 11 additions & 2 deletions cmd/bootstrap/cmd/dkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/onflow/crypto"

bootstrapDKG "github.com/onflow/flow-go/cmd/bootstrap/dkg"
"github.com/onflow/flow-go/cmd/util/cmd/common"
model "github.com/onflow/flow-go/model/bootstrap"
"github.com/onflow/flow-go/model/dkg"
"github.com/onflow/flow-go/model/encodable"
Expand Down Expand Up @@ -38,17 +39,25 @@ func runBeaconKG(nodes []model.NodeInfo) dkg.DKGData {
encKey := encodable.RandomBeaconPrivKey{PrivateKey: privKey}
privKeyShares = append(privKeyShares, encKey)

writeJSON(fmt.Sprintf(model.PathRandomBeaconPriv, nodeID), encKey)
err = common.WriteJSON(fmt.Sprintf(model.PathRandomBeaconPriv, nodeID), flagOutdir, encKey)
if err != nil {
log.Fatal().Err(err).Msg("failed to write json")
}
log.Info().Msgf("wrote file %s/%s", flagOutdir, fmt.Sprintf(model.PathRandomBeaconPriv, nodeID))
}

// write full DKG info that will be used to construct QC
writeJSON(model.PathRootDKGData, inmem.EncodableFullDKG{
err = common.WriteJSON(model.PathRootDKGData, flagOutdir, inmem.EncodableFullDKG{
GroupKey: encodable.RandomBeaconPubKey{
PublicKey: dkgData.PubGroupKey,
},
PubKeyShares: pubKeyShares,
PrivKeyShares: privKeyShares,
})
if err != nil {
log.Fatal().Err(err).Msg("failed to write json")
}
log.Info().Msgf("wrote file %s/%s", flagOutdir, model.PathRootDKGData)

return dkgData
}
59 changes: 44 additions & 15 deletions cmd/bootstrap/cmd/final_list.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package cmd

import (
"fmt"

"github.com/spf13/cobra"

"github.com/onflow/flow-go/cmd"
"github.com/onflow/flow-go/cmd/util/cmd/common"
model "github.com/onflow/flow-go/model/bootstrap"
"github.com/onflow/flow-go/model/flow"
)
Expand Down Expand Up @@ -65,7 +68,11 @@ func finalList(cmd *cobra.Command, args []string) {
validateNodes(localNodes, registeredNodes)

// write node-config.json with the new list of nodes to be used for the `finalize` command
writeJSON(model.PathFinallist, model.ToPublicNodeInfoList(localNodes))
err := common.WriteJSON(model.PathFinallist, flagOutdir, model.ToPublicNodeInfoList(localNodes))
if err != nil {
log.Fatal().Err(err).Msg("failed to write json")
}
log.Info().Msgf("wrote file %s/%s", flagOutdir, model.PathFinallist)
}

func validateNodes(localNodes []model.NodeInfo, registeredNodes []model.NodeInfo) {
Expand Down Expand Up @@ -229,18 +236,25 @@ func checkMismatchingNodes(localNodes []model.NodeInfo, registeredNodes []model.
}

func assembleInternalNodesWithoutWeight() []model.NodeInfo {
privInternals := readInternalNodes()
privInternals, err := common.ReadInternalNodeInfos(flagInternalNodePrivInfoDir)
if err != nil {
log.Fatal().Err(err).Msg("failed to read internal node infos")
}
log.Info().Msgf("read %v internal private node-info files", len(privInternals))

var nodes []model.NodeInfo
for _, internal := range privInternals {
// check if address is valid format
validateAddressFormat(internal.Address)
common.ValidateAddressFormat(log, internal.Address)

// validate every single internal node
nodeID := validateNodeID(internal.NodeID)
err := common.ValidateNodeID(internal.NodeID)
if err != nil {
log.Fatal().Err(err).Msg(fmt.Sprintf("invalid node ID: %s", internal.NodeID))
}

node := model.NewPrivateNodeInfo(
nodeID,
internal.NodeID,
internal.Role,
internal.Address,
flow.DefaultInitialWeight,
Expand All @@ -255,35 +269,50 @@ func assembleInternalNodesWithoutWeight() []model.NodeInfo {
}

func assemblePartnerNodesWithoutWeight() []model.NodeInfo {
partners := readPartnerNodes()
partners, err := common.ReadPartnerNodeInfos(flagPartnerNodeInfoDir)
if err != nil {
log.Fatal().Err(err).Msg("failed to read partner node infos")
}
log.Info().Msgf("read %v partner node configuration files", len(partners))
return createPublicNodeInfo(partners)
}

func readStakingContractDetails() []model.NodeInfo {
var stakingNodes []model.NodeInfoPub
readJSON(flagStakingNodesPath, &stakingNodes)
err := common.ReadJSON(flagStakingNodesPath, &stakingNodes)
if err != nil {
log.Fatal().Err(err).Msg("failed to read json")
}
return createPublicNodeInfo(stakingNodes)
}

func createPublicNodeInfo(nodes []model.NodeInfoPub) []model.NodeInfo {
var publicInfoNodes []model.NodeInfo
for _, n := range nodes {
validateAddressFormat(n.Address)
common.ValidateAddressFormat(log, n.Address)

// validate every single partner node
nodeID := validateNodeID(n.NodeID)
networkPubKey := validateNetworkPubKey(n.NetworkPubKey)
stakingPubKey := validateStakingPubKey(n.StakingPubKey)
err := common.ValidateNodeID(n.NodeID)
if err != nil {
log.Fatal().Err(err).Msg(fmt.Sprintf("invalid node ID: %s", n.NodeID))
}
err = common.ValidateNetworkPubKey(n.NetworkPubKey)
if err != nil {
log.Fatal().Err(err).Msg(fmt.Sprintf("invalid network public key: %s", n.NetworkPubKey))
}
err = common.ValidateStakingPubKey(n.StakingPubKey)
if err != nil {
log.Fatal().Err(err).Msg(fmt.Sprintf("invalid staking public key: %s", n.StakingPubKey))
}

// all nodes should have equal weight
// all nodes should have equal weight (this might change in the future)
node := model.NewPublicNodeInfo(
nodeID,
n.NodeID,
n.Role,
n.Address,
flow.DefaultInitialWeight,
networkPubKey,
stakingPubKey,
n.NetworkPubKey,
n.StakingPubKey,
)

publicInfoNodes = append(publicInfoNodes, node)
Expand Down
Loading

0 comments on commit 9c4c4a3

Please sign in to comment.