Skip to content

Commit

Permalink
dkg/sync: support relay reconnect
Browse files Browse the repository at this point in the history
  • Loading branch information
corverroos committed Jul 4, 2022
1 parent 616f4da commit b00cb16
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 6 deletions.
8 changes: 4 additions & 4 deletions dkg/sync/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (c *Client) Run(ctx context.Context) error {
if err != nil {
return err
} else if reconnect {
log.Debug(ctx, "Outgoing sync dropped, reconnecting")
log.Debug(ctx, "Relay connection dropped, reconnecting")
continue
}

Expand Down Expand Up @@ -218,7 +218,7 @@ func (c *Client) connect(ctx context.Context, retry bool) (network.Stream, error
}

// isRelayError returns true if the error is due to temporary relay circuit recycling.
func isRelayError(_ error) bool {
// TODO(corver): Detect circuit relay connection errors
return false
func isRelayError(err error) bool {
return errors.Is(err, network.ErrReset) ||
errors.Is(err, network.ErrResourceScopeClosed)
}
4 changes: 3 additions & 1 deletion dkg/sync/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,9 @@ func (s *Server) Start(ctx context.Context) {
s.tcpNode.SetStreamHandler(protocolID, func(stream network.Stream) {
ctx = log.WithCtx(ctx, z.Str("peer", p2p.PeerName(stream.Conn().RemotePeer())))
err := s.handleStream(ctx, stream)
if err != nil {
if isRelayError(err) {
log.Debug(ctx, "Relay connection dropped, expect reconnect")
} else if err != nil {
log.Warn(ctx, "Error serving sync protocol", err)
}
})
Expand Down
2 changes: 2 additions & 0 deletions testutil/compose/compose/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ func newNewCmd() *cobra.Command {
keygen := cmd.Flags().String("keygen", string(conf.KeyGen), "Key generation process: create, split, dkg")
buildLocal := cmd.Flags().Bool("build-local", conf.BuildBinary, "Enables building a local charon binary from source. Note this requires the CHARON_REPO env var.")
beaconNode := cmd.Flags().String("beacon-node", conf.BeaconNode, "Beacon node URL endpoint or 'mock' for simnet.")
extBootnode := cmd.Flags().String("external-bootnode", conf.BeaconNode, "Optional external bootnode HTTP url.")
splitKeys := cmd.Flags().String("split-keys-dir", conf.SplitKeysDir, "Directory containing keys to split for keygen==create, or empty not to split.")
featureSet := cmd.Flags().String("feature-set", conf.FeatureSet, "Minimum feature set to enable: alpha, beta, stable")

Expand All @@ -277,6 +278,7 @@ func newNewCmd() *cobra.Command {
conf.BeaconNode = *beaconNode
conf.SplitKeysDir = *splitKeys
conf.FeatureSet = *featureSet
conf.ExternalBootnode = *extBootnode

ctx := log.WithTopic(cmd.Context(), "new")
if err := compose.New(ctx, *dir, conf); err != nil {
Expand Down
3 changes: 3 additions & 0 deletions testutil/compose/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ type Config struct {
// BeaconNode url endpoint or "mock" for simnet.
BeaconNode string `json:"beacon_node"`

// ExternalBootnode HTTP url endpoint or empty to disable.
ExternalBootnode string `json:"external_bootnode"`

// VCs define the types of validator clients to use.
VCs []VCType `json:"validator_clients"`

Expand Down
10 changes: 9 additions & 1 deletion testutil/compose/lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,13 @@ func newNodeEnvs(index int, validatorMock bool, conf Config) []kv {
lockFile = fmt.Sprintf("/compose/node%d/cluster-lock.json", index)
}

p2pBootnodes := "http://bootnode:3640/enr"
p2pRelay := "false"
if conf.ExternalBootnode != "" {
p2pBootnodes = conf.ExternalBootnode
p2pRelay = "true"
}

return []kv{
{"data-dir", fmt.Sprintf("/compose/node%d", index)},
{"jaeger-service", fmt.Sprintf("node%d", index)},
Expand All @@ -120,7 +127,8 @@ func newNodeEnvs(index int, validatorMock bool, conf Config) []kv {
{"p2p-external-hostname", fmt.Sprintf("node%d", index)},
{"p2p-tcp-address", "0.0.0.0:3610"},
{"p2p_udp_address", "0.0.0.0:3630"},
{"p2p-bootnodes", "http://bootnode:3640/enr"},
{"p2p-bootnodes", p2pBootnodes},
{"p2p-bootnode-relay", fmt.Sprintf(`"%v"`, p2pRelay)},
{"beacon-node-endpoint", beaconNode},
{"simnet-validator-mock", fmt.Sprintf(`"%v"`, validatorMock)},
{"simnet-beacon_mock", fmt.Sprintf(`"%v"`, beaconMock)},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@
"Key": "p2p-bootnodes",
"Value": "http://bootnode:3640/enr"
},
{
"Key": "p2p-bootnode-relay",
"Value": "\"false\""
},
{
"Key": "beacon-node-endpoint",
"Value": ""
Expand Down Expand Up @@ -123,6 +127,10 @@
"Key": "p2p-bootnodes",
"Value": "http://bootnode:3640/enr"
},
{
"Key": "p2p-bootnode-relay",
"Value": "\"false\""
},
{
"Key": "beacon-node-endpoint",
"Value": ""
Expand Down Expand Up @@ -194,6 +202,10 @@
"Key": "p2p-bootnodes",
"Value": "http://bootnode:3640/enr"
},
{
"Key": "p2p-bootnode-relay",
"Value": "\"false\""
},
{
"Key": "beacon-node-endpoint",
"Value": ""
Expand Down Expand Up @@ -265,6 +277,10 @@
"Key": "p2p-bootnodes",
"Value": "http://bootnode:3640/enr"
},
{
"Key": "p2p-bootnode-relay",
"Value": "\"false\""
},
{
"Key": "beacon-node-endpoint",
"Value": ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ services:
CHARON_P2P_TCP_ADDRESS: 0.0.0.0:3610
CHARON_P2P_UDP_ADDRESS: 0.0.0.0:3630
CHARON_P2P_BOOTNODES: http://bootnode:3640/enr
CHARON_P2P_BOOTNODE_RELAY: "false"
CHARON_BEACON_NODE_ENDPOINT:
CHARON_SIMNET_VALIDATOR_MOCK: "true"
CHARON_SIMNET_BEACON_MOCK: "true"
Expand All @@ -45,6 +46,7 @@ services:
CHARON_P2P_TCP_ADDRESS: 0.0.0.0:3610
CHARON_P2P_UDP_ADDRESS: 0.0.0.0:3630
CHARON_P2P_BOOTNODES: http://bootnode:3640/enr
CHARON_P2P_BOOTNODE_RELAY: "false"
CHARON_BEACON_NODE_ENDPOINT:
CHARON_SIMNET_VALIDATOR_MOCK: "true"
CHARON_SIMNET_BEACON_MOCK: "true"
Expand All @@ -66,6 +68,7 @@ services:
CHARON_P2P_TCP_ADDRESS: 0.0.0.0:3610
CHARON_P2P_UDP_ADDRESS: 0.0.0.0:3630
CHARON_P2P_BOOTNODES: http://bootnode:3640/enr
CHARON_P2P_BOOTNODE_RELAY: "false"
CHARON_BEACON_NODE_ENDPOINT:
CHARON_SIMNET_VALIDATOR_MOCK: "true"
CHARON_SIMNET_BEACON_MOCK: "true"
Expand All @@ -87,6 +90,7 @@ services:
CHARON_P2P_TCP_ADDRESS: 0.0.0.0:3610
CHARON_P2P_UDP_ADDRESS: 0.0.0.0:3630
CHARON_P2P_BOOTNODES: http://bootnode:3640/enr
CHARON_P2P_BOOTNODE_RELAY: "false"
CHARON_BEACON_NODE_ENDPOINT:
CHARON_SIMNET_VALIDATOR_MOCK: "true"
CHARON_SIMNET_BEACON_MOCK: "true"
Expand Down
16 changes: 16 additions & 0 deletions testutil/compose/testdata/TestDockerCompose_run_template.golden
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@
"Key": "p2p-bootnodes",
"Value": "http://bootnode:3640/enr"
},
{
"Key": "p2p-bootnode-relay",
"Value": "\"false\""
},
{
"Key": "beacon-node-endpoint",
"Value": ""
Expand Down Expand Up @@ -123,6 +127,10 @@
"Key": "p2p-bootnodes",
"Value": "http://bootnode:3640/enr"
},
{
"Key": "p2p-bootnode-relay",
"Value": "\"false\""
},
{
"Key": "beacon-node-endpoint",
"Value": ""
Expand Down Expand Up @@ -194,6 +202,10 @@
"Key": "p2p-bootnodes",
"Value": "http://bootnode:3640/enr"
},
{
"Key": "p2p-bootnode-relay",
"Value": "\"false\""
},
{
"Key": "beacon-node-endpoint",
"Value": ""
Expand Down Expand Up @@ -265,6 +277,10 @@
"Key": "p2p-bootnodes",
"Value": "http://bootnode:3640/enr"
},
{
"Key": "p2p-bootnode-relay",
"Value": "\"false\""
},
{
"Key": "beacon-node-endpoint",
"Value": ""
Expand Down
4 changes: 4 additions & 0 deletions testutil/compose/testdata/TestDockerCompose_run_yml.golden
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ services:
CHARON_P2P_TCP_ADDRESS: 0.0.0.0:3610
CHARON_P2P_UDP_ADDRESS: 0.0.0.0:3630
CHARON_P2P_BOOTNODES: http://bootnode:3640/enr
CHARON_P2P_BOOTNODE_RELAY: "false"
CHARON_BEACON_NODE_ENDPOINT:
CHARON_SIMNET_VALIDATOR_MOCK: "false"
CHARON_SIMNET_BEACON_MOCK: "true"
Expand All @@ -45,6 +46,7 @@ services:
CHARON_P2P_TCP_ADDRESS: 0.0.0.0:3610
CHARON_P2P_UDP_ADDRESS: 0.0.0.0:3630
CHARON_P2P_BOOTNODES: http://bootnode:3640/enr
CHARON_P2P_BOOTNODE_RELAY: "false"
CHARON_BEACON_NODE_ENDPOINT:
CHARON_SIMNET_VALIDATOR_MOCK: "false"
CHARON_SIMNET_BEACON_MOCK: "true"
Expand All @@ -66,6 +68,7 @@ services:
CHARON_P2P_TCP_ADDRESS: 0.0.0.0:3610
CHARON_P2P_UDP_ADDRESS: 0.0.0.0:3630
CHARON_P2P_BOOTNODES: http://bootnode:3640/enr
CHARON_P2P_BOOTNODE_RELAY: "false"
CHARON_BEACON_NODE_ENDPOINT:
CHARON_SIMNET_VALIDATOR_MOCK: "true"
CHARON_SIMNET_BEACON_MOCK: "true"
Expand All @@ -87,6 +90,7 @@ services:
CHARON_P2P_TCP_ADDRESS: 0.0.0.0:3610
CHARON_P2P_UDP_ADDRESS: 0.0.0.0:3630
CHARON_P2P_BOOTNODES: http://bootnode:3640/enr
CHARON_P2P_BOOTNODE_RELAY: "false"
CHARON_BEACON_NODE_ENDPOINT:
CHARON_SIMNET_VALIDATOR_MOCK: "false"
CHARON_SIMNET_BEACON_MOCK: "true"
Expand Down
1 change: 1 addition & 0 deletions testutil/compose/testdata/TestNewDefaultConfig.golden
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"key_gen": "create",
"split_keys_dir": "",
"beacon_node": "mock",
"external_bootnode": "",
"validator_clients": [
"teku",
"lighthouse",
Expand Down

0 comments on commit b00cb16

Please sign in to comment.