Skip to content

Commit

Permalink
Merge onflow#2263
Browse files Browse the repository at this point in the history
2263: Improve DKG & QC contract logging r=kc1116 a=kc1116

This PR updates the DKG and QC contract client logger initialization to include the node ID of the AN that the flow client being used is connecting to.

Co-authored-by: Khalil Claybon <khalil.claybon@dapperlabs.com>
  • Loading branch information
bors[bot] and kc1116 committed Apr 8, 2022
2 parents 95308c3 + 2ecbb5a commit 7158c70
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 15 deletions.
2 changes: 1 addition & 1 deletion cmd/bootstrap/cmd/partner_infos.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func getFlowClient() *client.Client {
insecureClient = false
}

config, err := common.NewFlowClientConfig(flagANAddress, strings.TrimPrefix(flagANNetworkKey, "0x"), insecureClient)
config, err := common.NewFlowClientConfig(flagANAddress, strings.TrimPrefix(flagANNetworkKey, "0x"), flow.ZeroID, insecureClient)
if err != nil {
log.Fatal().Err(err).Msgf("could not get flow client config with address (%s) and network key (%s)", flagANAddress, flagANNetworkKey)
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/collection/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ func main() {
}

// createQCContractClient creates QC contract client
func createQCContractClient(node *cmd.NodeConfig, machineAccountInfo *bootstrap.NodeMachineAccountInfo, flowClient *client.Client) (module.QCContractClient, error) {
func createQCContractClient(node *cmd.NodeConfig, machineAccountInfo *bootstrap.NodeMachineAccountInfo, flowClient *client.Client, anID flow.Identifier) (module.QCContractClient, error) {

var qcContractClient module.QCContractClient

Expand All @@ -544,7 +544,7 @@ func createQCContractClient(node *cmd.NodeConfig, machineAccountInfo *bootstrap.
txSigner := sdkcrypto.NewInMemorySigner(sk, machineAccountInfo.HashAlgorithm)

// create actual qc contract client, all flags and machine account info file found
qcContractClient = epochs.NewQCContractClient(node.Logger, flowClient, node.Me.NodeID(), machineAccountInfo.Address, machineAccountInfo.KeyIndex, qcContractAddress, txSigner)
qcContractClient = epochs.NewQCContractClient(node.Logger, flowClient, anID, node.Me.NodeID(), machineAccountInfo.Address, machineAccountInfo.KeyIndex, qcContractAddress, txSigner)

return qcContractClient, nil
}
Expand All @@ -559,7 +559,7 @@ func createQCContractClients(node *cmd.NodeConfig, machineAccountInfo *bootstrap
return nil, fmt.Errorf("failed to create flow client for qc contract client with options: %s %w", flowClientOpts, err)
}

qcClient, err := createQCContractClient(node, machineAccountInfo, flowClient)
qcClient, err := createQCContractClient(node, machineAccountInfo, flowClient, opt.AccessNodeID)
if err != nil {
return nil, fmt.Errorf("failed to create qc contract client with flow client options: %s %w", flowClientOpts, err)
}
Expand Down
5 changes: 3 additions & 2 deletions cmd/consensus/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -795,7 +795,7 @@ func loadBeaconPrivateKey(dir string, myID flow.Identifier) (*encodable.RandomBe
}

// createDKGContractClient creates an dkgContractClient
func createDKGContractClient(node *cmd.NodeConfig, machineAccountInfo *bootstrap.NodeMachineAccountInfo, flowClient *client.Client) (module.DKGContractClient, error) {
func createDKGContractClient(node *cmd.NodeConfig, machineAccountInfo *bootstrap.NodeMachineAccountInfo, flowClient *client.Client, anID flow.Identifier) (module.DKGContractClient, error) {
var dkgClient module.DKGContractClient

contracts, err := systemcontracts.SystemContractsForChain(node.RootChainID)
Expand All @@ -815,6 +815,7 @@ func createDKGContractClient(node *cmd.NodeConfig, machineAccountInfo *bootstrap
dkgClient = dkgmodule.NewClient(
node.Logger,
flowClient,
anID,
txSigner,
dkgContractAddress,
machineAccountInfo.Address,
Expand All @@ -835,7 +836,7 @@ func createDKGContractClients(node *cmd.NodeConfig, machineAccountInfo *bootstra
}

node.Logger.Info().Msgf("created dkg contract client with opts: %s", opt.String())
dkgClient, err := createDKGContractClient(node, machineAccountInfo, flowClient)
dkgClient, err := createDKGContractClient(node, machineAccountInfo, flowClient, opt.AccessNodeID)
if err != nil {
return nil, fmt.Errorf("failed to create dkg contract client with flow client options: %s %w", flowClientOpts, err)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/dynamic_startup.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func DynamicStartPreInit(nodeConfig *NodeConfig) error {
}

// get flow client with secure client connection to download protocol snapshot from access node
config, err := common.NewFlowClientConfig(nodeConfig.DynamicStartupANAddress, nodeConfig.DynamicStartupANPubkey, false)
config, err := common.NewFlowClientConfig(nodeConfig.DynamicStartupANAddress, nodeConfig.DynamicStartupANPubkey, flow.ZeroID, false)
if err != nil {
return fmt.Errorf("failed to create flow client config for node dynamic startup pre-init: %w", err)
}
Expand Down
7 changes: 4 additions & 3 deletions cmd/util/cmd/common/flow_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const (
type FlowClientConfig struct {
AccessAddress string
AccessNodePubKey string
AccessNodeID flow.Identifier
Insecure bool
}

Expand All @@ -30,7 +31,7 @@ func (f *FlowClientConfig) String() string {
}

// NewFlowClientConfig returns *FlowClientConfig
func NewFlowClientConfig(accessAddress, accessApiNodePubKey string, insecure bool) (*FlowClientConfig, error) {
func NewFlowClientConfig(accessAddress, accessApiNodePubKey string, accessNodeID flow.Identifier, insecure bool) (*FlowClientConfig, error) {
if accessAddress == "" {
return nil, fmt.Errorf("failed to create flow client connection option invalid access address: %s", accessAddress)
}
Expand All @@ -41,7 +42,7 @@ func NewFlowClientConfig(accessAddress, accessApiNodePubKey string, insecure boo
}
}

return &FlowClientConfig{accessAddress, accessApiNodePubKey, insecure}, nil
return &FlowClientConfig{accessAddress, accessApiNodePubKey, accessNodeID, insecure}, nil
}

// FlowClient will return a secure or insecure flow client depending on *FlowClientConfig.Insecure
Expand Down Expand Up @@ -102,7 +103,7 @@ func FlowClientConfigs(accessNodeIDS []flow.Identifier, insecureAccessAPI bool,
// remove the 0x prefix from network public keys
networkingPubKey := strings.TrimPrefix(identity.NetworkPubKey.String(), "0x")

opt, err := NewFlowClientConfig(accessAddress, networkingPubKey, insecureAccessAPI)
opt, err := NewFlowClientConfig(accessAddress, networkingPubKey, identity.NodeID, insecureAccessAPI)
if err != nil {
return nil, fmt.Errorf("failed to get flow client connection option for access node ID (%d): %s %w", i, identity, err)
}
Expand Down
2 changes: 2 additions & 0 deletions integration/dkg/dkg_emulator_suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ func (s *DKGSuite) deployDKGContract() {
s.adminDKGContractClient = dkg.NewClient(
zerolog.Nop(),
s.adminEmulatorClient,
flow.ZeroID,
s.dkgSigner,
s.dkgAddress.String(),
s.dkgAddress.String(), 0)
Expand Down Expand Up @@ -267,6 +268,7 @@ func (s *DKGSuite) createNode(account *nodeAccount) *node {
contractClient := dkg.NewClient(
zerolog.Nop(),
emulatorClient,
flow.ZeroID,
account.accountSigner,
s.dkgAddress.String(),
account.accountAddress.String(),
Expand Down
2 changes: 1 addition & 1 deletion integration/epochs/epoch_qc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (s *Suite) TestEpochQuorumCertificate() {
address, err := s.blockchain.CreateAccount([]*sdk.AccountKey{key}, []sdktemplates.Contract{})
s.Require().NoError(err)

client := epochs.NewQCContractClient(zerolog.Nop(), s.emulatorClient, nodeID, address.String(), 0, s.qcAddress.String(), signer)
client := epochs.NewQCContractClient(zerolog.Nop(), s.emulatorClient, flow.ZeroID, nodeID, address.String(), 0, s.qcAddress.String(), signer)
s.Require().NoError(err)

local := &modulemock.Local{}
Expand Down
6 changes: 5 additions & 1 deletion module/dkg/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,17 @@ type Client struct {
func NewClient(
log zerolog.Logger,
flowClient module.SDKClientWrapper,
flowClientANID flow.Identifier,
signer sdkcrypto.Signer,
dkgContractAddress,
accountAddress string,
accountKeyIndex uint,
) *Client {

log = log.With().Str("component", "dkg_contract_client").Logger()
log = log.With().
Str("component", "dkg_contract_client").
Str("flow_client_an_id", flowClientANID.String()).
Logger()
base := epochs.NewBaseClient(log, flowClient, accountAddress, accountKeyIndex, signer, dkgContractAddress)

env := templates.Environment{DkgAddress: dkgContractAddress}
Expand Down
4 changes: 2 additions & 2 deletions module/dkg/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (s *ClientSuite) SetupTest() {
// deploy contract
s.deployDKGContract()

s.contractClient = NewClient(zerolog.Nop(), s.emulatorClient, s.dkgSigner, s.dkgAddress.String(), s.dkgAddress.String(), 0)
s.contractClient = NewClient(zerolog.Nop(), s.emulatorClient, flow.ZeroID, s.dkgSigner, s.dkgAddress.String(), s.dkgAddress.String(), 0)
}

func (s *ClientSuite) deployDKGContract() {
Expand Down Expand Up @@ -218,7 +218,7 @@ func (s *ClientSuite) prepareDKG(participants []flow.Identifier) []*Client {
// create clients for each participant
clients := make([]*Client, len(participants))
for index := range participants {
clients[index] = NewClient(zerolog.Nop(), s.emulatorClient, signers[index], s.dkgAddress.String(), addresses[index].String(), 0)
clients[index] = NewClient(zerolog.Nop(), s.emulatorClient, flow.ZeroID, signers[index], s.dkgAddress.String(), addresses[index].String(), 0)
}

return clients
Expand Down
6 changes: 5 additions & 1 deletion module/epochs/qc_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,18 @@ type QCContractClient struct {
func NewQCContractClient(
log zerolog.Logger,
flowClient module.SDKClientWrapper,
flowClientANID flow.Identifier,
nodeID flow.Identifier,
accountAddress string,
accountKeyIndex uint,
qcContractAddress string,
signer sdkcrypto.Signer,
) *QCContractClient {

log = log.With().Str("component", "qc_contract_client").Logger()
log = log.With().
Str("component", "qc_contract_client").
Str("flow_client_an_id", flowClientANID.String()).
Logger()
base := NewBaseClient(log, flowClient, accountAddress, accountKeyIndex, signer, qcContractAddress)

// set QCContractAddress to the contract address given
Expand Down

0 comments on commit 7158c70

Please sign in to comment.