Skip to content

Commit

Permalink
Revert "Code split"
Browse files Browse the repository at this point in the history
This reverts commit 104c3ec.

Some cleanup and documenting

Cleanup; document more

nit

ConnectIps test

Better connectIps test; simplify ConnectionController tests

refactor
  • Loading branch information
AeonSw4n committed Jan 18, 2024
1 parent 3f72440 commit 18fcca7
Show file tree
Hide file tree
Showing 7 changed files with 403 additions and 15 deletions.
106 changes: 106 additions & 0 deletions integration_testing/connection_controller_routines_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
package integration_testing

import (
"github.com/deso-protocol/core/bls"
"github.com/deso-protocol/core/cmd"
"github.com/deso-protocol/core/lib"
"github.com/stretchr/testify/require"
"testing"
)

func TestConnectionControllerInitiatePersistentConnections(t *testing.T) {
require := require.New(t)

// NonValidator Node1 will set its --connect-ips to two non-validators node2 and node3,
// and two validators node4 and node5.
node1 := spawnNonValidatorNodeProtocol2(t, 18000, "node1")
node2 := spawnNonValidatorNodeProtocol2(t, 18001, "node2")
node3 := spawnNonValidatorNodeProtocol2(t, 18002, "node3")
blsPriv4, err := bls.NewPrivateKey()
require.NoError(err)
node4 := spawnValidatorNodeProtocol2(t, 18003, "node4", blsPriv4)
blsPriv5, err := bls.NewPrivateKey()
require.NoError(err)
node5 := spawnValidatorNodeProtocol2(t, 18004, "node5", blsPriv5)

node2 = startNode(t, node2)
node3 = startNode(t, node3)
node4 = startNode(t, node4)
node5 = startNode(t, node5)

oldGetActiveValidatorImpl := lib.GetActiveValidatorImpl
defer func() {
setGetActiveValidatorImpl(oldGetActiveValidatorImpl)
}()
setGetActiveValidatorImpl(func() map[bls.SerializedPublicKey]*lib.ValidatorEntry {
return map[bls.SerializedPublicKey]*lib.ValidatorEntry{
blsPriv4.PublicKey().Serialize(): createSimpleValidatorEntry(node4),
blsPriv5.PublicKey().Serialize(): createSimpleValidatorEntry(node5),
}
})

node1.Config.ConnectIPs = []string{
node2.Listeners[0].Addr().String(),
node3.Listeners[0].Addr().String(),
node4.Listeners[0].Addr().String(),
node5.Listeners[0].Addr().String(),
}
node1 = startNode(t, node1)
waitForNonValidatorOutboundConnection(t, node1, node2)
waitForNonValidatorOutboundConnection(t, node1, node3)
waitForValidatorConnection(t, node1, node4)
waitForValidatorConnection(t, node1, node5)
waitForValidatorConnection(t, node4, node5)
waitForCountRemoteNodeIndexer(t, node1, 4, 2, 2, 0)
waitForCountRemoteNodeIndexer(t, node2, 1, 0, 0, 1)
waitForCountRemoteNodeIndexer(t, node3, 1, 0, 0, 1)
waitForCountRemoteNodeIndexer(t, node4, 2, 1, 0, 1)
waitForCountRemoteNodeIndexer(t, node5, 2, 1, 0, 1)
node1.Stop()
t.Logf("Test #1 passed | Successfully run non-validator node1 with --connect-ips set to node2, node3, node4, node5")

// Now try again with a validator node6, with connect-ips set to node2, node3, node4, node5.
blsPriv6, err := bls.NewPrivateKey()
require.NoError(err)
node6 := spawnValidatorNodeProtocol2(t, 18005, "node6", blsPriv6)
node6.Config.ConnectIPs = []string{
node2.Listeners[0].Addr().String(),
node3.Listeners[0].Addr().String(),
node4.Listeners[0].Addr().String(),
node5.Listeners[0].Addr().String(),
}
node6 = startNode(t, node6)
setGetActiveValidatorImpl(func() map[bls.SerializedPublicKey]*lib.ValidatorEntry {
return map[bls.SerializedPublicKey]*lib.ValidatorEntry{
blsPriv4.PublicKey().Serialize(): createSimpleValidatorEntry(node4),
blsPriv5.PublicKey().Serialize(): createSimpleValidatorEntry(node5),
blsPriv6.PublicKey().Serialize(): createSimpleValidatorEntry(node6),
}
})
waitForNonValidatorOutboundConnection(t, node6, node2)
waitForNonValidatorOutboundConnection(t, node6, node3)
waitForValidatorConnection(t, node6, node4)
waitForValidatorConnection(t, node6, node5)
waitForValidatorConnection(t, node4, node5)
waitForCountRemoteNodeIndexer(t, node6, 4, 2, 2, 0)
waitForCountRemoteNodeIndexer(t, node2, 1, 1, 0, 0)
waitForCountRemoteNodeIndexer(t, node3, 1, 1, 0, 0)
waitForCountRemoteNodeIndexer(t, node4, 2, 2, 0, 0)
waitForCountRemoteNodeIndexer(t, node5, 2, 2, 0, 0)
node6.Stop()
node2.Stop()
node3.Stop()
node4.Stop()
node5.Stop()
t.Logf("Test #2 passed | Successfully run validator node6 with --connect-ips set to node2, node3, node4, node5")
}

func setGetActiveValidatorImpl(mapping func() map[bls.SerializedPublicKey]*lib.ValidatorEntry) {
lib.GetActiveValidatorImpl = mapping
}

func createSimpleValidatorEntry(node *cmd.Node) *lib.ValidatorEntry {
return &lib.ValidatorEntry{
Domains: [][]byte{[]byte(node.Listeners[0].Addr().String())},
}
}
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

0 comments on commit 18fcca7

Please sign in to comment.