Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PoS ConnectionController Routines #911

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
403 changes: 403 additions & 0 deletions integration_testing/connection_controller_routines_test.go

Large diffs are not rendered by default.

12 changes: 8 additions & 4 deletions integration_testing/connection_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,8 @@ func TestConnectionControllerPersistentConnection(t *testing.T) {

// Create a persistent connection from Node1 to Node2
cc := node1.Server.GetConnectionController()
require.NoError(cc.CreateNonValidatorPersistentOutboundConnection(node2.Listeners[0].Addr().String()))
_, err = cc.CreateNonValidatorPersistentOutboundConnection(node2.Listeners[0].Addr().String())
require.NoError(err)
waitForValidatorConnection(t, node1, node2)
waitForNonValidatorInboundConnection(t, node2, node1)
node2.Stop()
Expand All @@ -408,7 +409,8 @@ func TestConnectionControllerPersistentConnection(t *testing.T) {
node3 = startNode(t, node3)

// Create a persistent connection from Node1 to Node3
require.NoError(cc.CreateNonValidatorPersistentOutboundConnection(node3.Listeners[0].Addr().String()))
_, err = cc.CreateNonValidatorPersistentOutboundConnection(node3.Listeners[0].Addr().String())
require.NoError(err)
waitForNonValidatorOutboundConnection(t, node1, node3)
waitForNonValidatorInboundConnection(t, node3, node1)
node3.Stop()
Expand All @@ -429,7 +431,8 @@ func TestConnectionControllerPersistentConnection(t *testing.T) {

// Create a persistent connection from Node4 to Node5
cc = node4.Server.GetConnectionController()
require.NoError(cc.CreateNonValidatorPersistentOutboundConnection(node5.Listeners[0].Addr().String()))
_, err = cc.CreateNonValidatorPersistentOutboundConnection(node5.Listeners[0].Addr().String())
require.NoError(err)
waitForNonValidatorOutboundConnection(t, node4, node5)
waitForValidatorConnection(t, node5, node4)
node5.Stop()
Expand All @@ -444,7 +447,8 @@ func TestConnectionControllerPersistentConnection(t *testing.T) {
defer node6.Stop()

// Create a persistent connection from Node4 to Node6
require.NoError(cc.CreateNonValidatorPersistentOutboundConnection(node6.Listeners[0].Addr().String()))
_, err = cc.CreateNonValidatorPersistentOutboundConnection(node6.Listeners[0].Addr().String())
require.NoError(err)
waitForValidatorConnection(t, node4, node6)
waitForValidatorConnection(t, node6, node4)
t.Logf("Test #4 passed | Successfuly created persistent connection from validator Node4 to validator Node6")
Expand Down
52 changes: 36 additions & 16 deletions integration_testing/connection_controller_utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,24 @@ func waitForValidatorConnection(t *testing.T, node1 *cmd.Node, node2 *cmd.Node)
}
return true
}
waitForCondition(t, fmt.Sprintf("Waiting for Node (%s) to connect to outbound non-validator Node (%s)", userAgentN1, userAgentN2), n1ValidatedN2)
waitForCondition(t, fmt.Sprintf("Waiting for Node (%s) to connect to validator Node (%s)", userAgentN1, userAgentN2), n1ValidatedN2)
}

func waitForNonValidatorOutboundConnection(t *testing.T, node1 *cmd.Node, node2 *cmd.Node) {
userAgentN1 := node1.Params.UserAgent
userAgentN2 := node2.Params.UserAgent
condition := conditionNonValidatorOutboundConnection(t, node1, node2)
waitForCondition(t, fmt.Sprintf("Waiting for Node (%s) to connect to outbound non-validator Node (%s)", userAgentN1, userAgentN2), condition)
}

func conditionNonValidatorOutboundConnection(t *testing.T, node1 *cmd.Node, node2 *cmd.Node) func() bool {
return conditionNonValidatorOutboundConnectionDynamic(t, node1, node2, false)
}

func conditionNonValidatorOutboundConnectionDynamic(t *testing.T, node1 *cmd.Node, node2 *cmd.Node, inactiveValidator bool) func() bool {
userAgentN2 := node2.Params.UserAgent
rnManagerN1 := node1.Server.GetConnectionController().GetRemoteNodeManager()
n1ValidatedN2 := func() bool {
return func() bool {
if true != checkRemoteNodeIndexerUserAgent(rnManagerN1, userAgentN2, false, true, false) {
return false
}
Expand All @@ -44,19 +54,29 @@ func waitForNonValidatorOutboundConnection(t *testing.T, node1 *cmd.Node, node2
if !rnFromN2.IsHandshakeCompleted() {
return false
}
if rnFromN2.GetValidatorPublicKey() != nil {
return false
// inactiveValidator should have the public key.
if inactiveValidator {
return rnFromN2.GetValidatorPublicKey() != nil
}
return true
return rnFromN2.GetValidatorPublicKey() == nil
}
waitForCondition(t, fmt.Sprintf("Waiting for Node (%s) to connect to outbound non-validator Node (%s)", userAgentN1, userAgentN2), n1ValidatedN2)
}

func waitForNonValidatorInboundConnection(t *testing.T, node1 *cmd.Node, node2 *cmd.Node) {
userAgentN1 := node1.Params.UserAgent
userAgentN2 := node2.Params.UserAgent
condition := conditionNonValidatorInboundConnection(t, node1, node2)
waitForCondition(t, fmt.Sprintf("Waiting for Node (%s) to connect to inbound non-validator Node (%s)", userAgentN1, userAgentN2), condition)
}

func conditionNonValidatorInboundConnection(t *testing.T, node1 *cmd.Node, node2 *cmd.Node) func() bool {
return conditionNonValidatorInboundConnectionDynamic(t, node1, node2, false)
}

func conditionNonValidatorInboundConnectionDynamic(t *testing.T, node1 *cmd.Node, node2 *cmd.Node, inactiveValidator bool) func() bool {
userAgentN2 := node2.Params.UserAgent
rnManagerN1 := node1.Server.GetConnectionController().GetRemoteNodeManager()
n1ValidatedN2 := func() bool {
return func() bool {
if true != checkRemoteNodeIndexerUserAgent(rnManagerN1, userAgentN2, false, false, true) {
return false
}
Expand All @@ -67,12 +87,12 @@ func waitForNonValidatorInboundConnection(t *testing.T, node1 *cmd.Node, node2 *
if !rnFromN2.IsHandshakeCompleted() {
return false
}
if rnFromN2.GetValidatorPublicKey() != nil {
return false
// inactiveValidator should have the public key.
if inactiveValidator {
return rnFromN2.GetValidatorPublicKey() != nil
}
return true
return rnFromN2.GetValidatorPublicKey() == nil
}
waitForCondition(t, fmt.Sprintf("Waiting for Node (%s) to connect to inbound non-validator Node (%s)", userAgentN1, userAgentN2), n1ValidatedN2)
}

func waitForEmptyRemoteNodeIndexer(t *testing.T, node1 *cmd.Node) {
Expand All @@ -90,15 +110,15 @@ func waitForEmptyRemoteNodeIndexer(t *testing.T, node1 *cmd.Node) {
func waitForCountRemoteNodeIndexer(t *testing.T, node1 *cmd.Node, allCount int, validatorCount int,
nonValidatorOutboundCount int, nonValidatorInboundCount int) {

userAgentN1 := node1.Params.UserAgent
rnManagerN1 := node1.Server.GetConnectionController().GetRemoteNodeManager()
n1ValidatedN2 := func() bool {
if true != checkRemoteNodeIndexerCount(rnManagerN1, allCount, validatorCount, nonValidatorOutboundCount, nonValidatorInboundCount) {
userAgent := node1.Params.UserAgent
rnManager := node1.Server.GetConnectionController().GetRemoteNodeManager()
condition := func() bool {
if true != checkRemoteNodeIndexerCount(rnManager, allCount, validatorCount, nonValidatorOutboundCount, nonValidatorInboundCount) {
return false
}
return true
}
waitForCondition(t, fmt.Sprintf("Waiting for Node (%s) to have appropriate RemoteNodes counts", userAgentN1), n1ValidatedN2)
waitForCondition(t, fmt.Sprintf("Waiting for Node (%s) to have appropriate RemoteNodes counts", userAgent), condition)
}

func checkRemoteNodeIndexerUserAgent(manager *lib.RemoteNodeManager, userAgent string, validator bool,
Expand Down
2 changes: 1 addition & 1 deletion integration_testing/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func generateConfig(t *testing.T, port uint32, dataDir string, maxPeers uint32)
config.MaxSyncBlockHeight = 0
config.ConnectIPs = []string{}
config.PrivateMode = true
config.GlogV = 0
config.GlogV = 2
config.GlogVmodule = "*bitcoin_manager*=0,*balance*=0,*view*=0,*frontend*=0,*peer*=0,*addr*=0,*network*=0,*utils*=0,*connection*=0,*main*=0,*server*=0,*mempool*=0,*miner*=0,*blockchain*=0"
config.MaxInboundPeers = maxPeers
config.TargetOutboundPeers = maxPeers
Expand Down
Loading
Loading