From 720632cce8a4f7094d3cd66b77716cf9b0faa0da Mon Sep 17 00:00:00 2001 From: Piotr Nojszewski <29924594+AeonSw4n@users.noreply.github.com> Date: Sun, 28 Jan 2024 20:53:26 -0800 Subject: [PATCH 1/5] Some fixes --- integration_testing/blocksync_test.go | 50 ++++--------------- integration_testing/connection_bridge.go | 9 ---- .../network_manager_utils_test.go | 13 +++++ lib/peer.go | 34 +++++-------- lib/remote_node_manager.go | 2 +- lib/server.go | 9 +++- 6 files changed, 44 insertions(+), 73 deletions(-) diff --git a/integration_testing/blocksync_test.go b/integration_testing/blocksync_test.go index be87aae3a..04775d8ec 100644 --- a/integration_testing/blocksync_test.go +++ b/integration_testing/blocksync_test.go @@ -16,40 +16,21 @@ import ( // 4. node2 syncs MaxSyncBlockHeight blocks from node1. // 5. compare node1 db matches node2 db. func TestSimpleBlockSync(t *testing.T) { - require := require.New(t) - _ = require - - dbDir1 := getDirectory(t) - dbDir2 := getDirectory(t) - defer os.RemoveAll(dbDir1) - defer os.RemoveAll(dbDir2) - - config1 := generateConfig(t, 18000, dbDir1, 10) - config1.SyncType = lib.NodeSyncTypeBlockSync - config2 := generateConfig(t, 18001, dbDir2, 10) - config2.SyncType = lib.NodeSyncTypeBlockSync - - config1.ConnectIPs = []string{"deso-seed-2.io:17000"} - - node1 := cmd.NewNode(config1) - node2 := cmd.NewNode(config2) - + node1 := spawnNodeProtocol1(t, 18000, "node1") + node1.Config.ConnectIPs = []string{"deso-seed-2.io:17000"} + node2 := spawnNodeProtocol1(t, 18001, "node2") node1 = startNode(t, node1) + node2.Config.ConnectIPs = []string{"127.0.0.1:18000"} node2 = startNode(t, node2) // wait for node1 to sync blocks waitForNodeToFullySync(node1) - // TODO: Dial an outbound connection from node2 to node1 - // Fix other integration tests. - // wait for node2 to sync blocks. waitForNodeToFullySync(node2) compareNodesByDB(t, node1, node2, 0) fmt.Println("Databases match!") - node1.Stop() - node2.Stop() } // TestSimpleSyncRestart tests if a node can successfully restart while syncing blocks. @@ -62,24 +43,13 @@ func TestSimpleBlockSync(t *testing.T) { // 7. compare node1 db matches node2 db. func TestSimpleSyncRestart(t *testing.T) { require := require.New(t) - _ = require - - dbDir1 := getDirectory(t) - dbDir2 := getDirectory(t) - defer os.RemoveAll(dbDir1) - defer os.RemoveAll(dbDir2) - - config1 := generateConfig(t, 18000, dbDir1, 10) - config1.SyncType = lib.NodeSyncTypeBlockSync - config2 := generateConfig(t, 18001, dbDir2, 10) - config2.SyncType = lib.NodeSyncTypeBlockSync - - config1.ConnectIPs = []string{"deso-seed-2.io:17000"} - - node1 := cmd.NewNode(config1) - node2 := cmd.NewNode(config2) + node1 := spawnNodeProtocol1(t, 18000, "node1") + node1.Config.ConnectIPs = []string{"deso-seed-2.io:17000"} node1 = startNode(t, node1) + + node2 := spawnNodeProtocol1(t, 18001, "node2") + node2.Config.ConnectIPs = []string{"127.0.0.1:18000"} node2 = startNode(t, node2) // wait for node1 to sync blocks @@ -89,7 +59,7 @@ func TestSimpleSyncRestart(t *testing.T) { bridge := NewConnectionBridge(node1, node2) require.NoError(bridge.Start()) - randomHeight := randomUint32Between(t, 10, config2.MaxSyncBlockHeight) + randomHeight := randomUint32Between(t, 10, node2.Config.MaxSyncBlockHeight) fmt.Println("Random height for a restart (re-use if test failed):", randomHeight) // Reboot node2 at a specific height and reconnect it with node1 node2, bridge = restartAtHeightAndReconnectNode(t, node2, node1, bridge, randomHeight) diff --git a/integration_testing/connection_bridge.go b/integration_testing/connection_bridge.go index 139c7cafb..b93fabac5 100644 --- a/integration_testing/connection_bridge.go +++ b/integration_testing/connection_bridge.go @@ -201,7 +201,6 @@ func ReadWithTimeout(readFunc func() error, readTimeout time.Duration) error { func (bridge *ConnectionBridge) startConnection(connection *lib.Peer, otherNode *cmd.Node) error { // Prepare the version message. versionMessage := bridge.getVersionMessage(otherNode) - connection.VersionNonceSent = versionMessage.Nonce // Send the version message. fmt.Println("Sending version message:", versionMessage, versionMessage.LatestBlockHeight) @@ -222,7 +221,6 @@ func (bridge *ConnectionBridge) startConnection(connection *lib.Peer, otherNode return err } - connection.VersionNonceReceived = verMsg.Nonce connection.TimeConnected = time.Unix(verMsg.TstampSecs, 0) connection.TimeOffsetSecs = verMsg.TstampSecs - time.Now().Unix() return nil @@ -233,7 +231,6 @@ func (bridge *ConnectionBridge) startConnection(connection *lib.Peer, otherNode // Now prepare the verack message. verackMsg := lib.NewMessage(lib.MsgTypeVerack) - verackMsg.(*lib.MsgDeSoVerack).NonceReceived = connection.VersionNonceReceived // And send it to the connection. if err := connection.WriteDeSoMessage(verackMsg); err != nil { @@ -251,17 +248,11 @@ func (bridge *ConnectionBridge) startConnection(connection *lib.Peer, otherNode if msg.GetMsgType() != lib.MsgTypeVerack { return fmt.Errorf("message is not verack! Type: %v", msg.GetMsgType()) } - verackMsg := msg.(*lib.MsgDeSoVerack) - if verackMsg.NonceReceived != connection.VersionNonceSent { - return fmt.Errorf("verack message nonce doesn't match (received: %v, sent: %v)", - verackMsg.NonceReceived, connection.VersionNonceSent) - } return nil }, lib.DeSoMainnetParams.VersionNegotiationTimeout); err != nil { return err } - connection.VersionNegotiated = true return nil } diff --git a/integration_testing/network_manager_utils_test.go b/integration_testing/network_manager_utils_test.go index f14cb39d9..d46b5a22f 100644 --- a/integration_testing/network_manager_utils_test.go +++ b/integration_testing/network_manager_utils_test.go @@ -253,6 +253,19 @@ func getRemoteNodeWithUserAgent(node *cmd.Node, userAgent string) *lib.RemoteNod return nil } +func spawnNodeProtocol1(t *testing.T, port uint32, id string) *cmd.Node { + dbDir := getDirectory(t) + t.Cleanup(func() { + os.RemoveAll(dbDir) + }) + config := generateConfig(t, port, dbDir, 10) + config.SyncType = lib.NodeSyncTypeBlockSync + node := cmd.NewNode(config) + node.Params.UserAgent = id + node.Params.ProtocolVersion = lib.ProtocolVersion1 + return node +} + func spawnNonValidatorNodeProtocol2(t *testing.T, port uint32, id string) *cmd.Node { dbDir := getDirectory(t) t.Cleanup(func() { diff --git a/lib/peer.go b/lib/peer.go index 996d2632d..b9cd9bfa2 100644 --- a/lib/peer.go +++ b/lib/peer.go @@ -64,32 +64,15 @@ type Peer struct { Params *DeSoParams MessageChan chan *ServerMessage - // In order to complete a version negotiation successfully, the peer must - // reply to the initial version message we send them with a verack message - // containing the nonce from that initial version message. This ensures that - // the peer's IP isn't being spoofed since the only way to actually produce - // a verack with the appropriate response is to actually own the IP that - // the peer claims it has. As such, we maintain the version nonce we sent - // the peer and the version nonce they sent us here. - // - // TODO: The way we synchronize the version nonce is currently a bit - // messy; ideally we could do it without keeping global state. - VersionNonceSent uint64 - VersionNonceReceived uint64 - // A pointer to the Server srv *Server // Basic state. - PeerInfoMtx deadlock.Mutex - serviceFlags ServiceFlag - addrStr string - netAddr *wire.NetAddress - userAgent string - advertisedProtocolVersion uint64 - negotiatedProtocolVersion uint64 - VersionNegotiated bool - minTxFeeRateNanosPerKB uint64 + PeerInfoMtx deadlock.Mutex + serviceFlags ServiceFlag + addrStr string + netAddr *wire.NetAddress + minTxFeeRateNanosPerKB uint64 // Messages for which we are expecting a reply within a fixed // amount of time. This list is always sorted by ExpectedTime, // with the item having the earliest time at the front. @@ -910,6 +893,13 @@ func (pp *Peer) _setKnownAddressesMap(key string, val bool) { pp.knownAddressesMap[key] = val } +func (pp *Peer) SetServiceFlag(sf ServiceFlag) { + pp.PeerInfoMtx.Lock() + defer pp.PeerInfoMtx.Unlock() + + pp.serviceFlags = sf +} + func (pp *Peer) outHandler() { pp.startGroup.Done() glog.V(1).Infof("Peer.outHandler: Starting outHandler for Peer %v", pp) diff --git a/lib/remote_node_manager.go b/lib/remote_node_manager.go index bd23908bf..2dfb77431 100644 --- a/lib/remote_node_manager.go +++ b/lib/remote_node_manager.go @@ -78,7 +78,7 @@ func (manager *RemoteNodeManager) ProcessCompletedHandshake(remoteNode *RemoteNo manager.UnsetValidator(remoteNode) manager.SetNonValidator(remoteNode) } - manager.srv.HandleAcceptedPeer(remoteNode.GetPeer()) + manager.srv.HandleAcceptedPeer(remoteNode) manager.srv.maybeRequestAddresses(remoteNode) } diff --git a/lib/server.go b/lib/server.go index e54296739..d5a8c3147 100644 --- a/lib/server.go +++ b/lib/server.go @@ -442,6 +442,7 @@ func NewServer( nodeMessageChannel: _nodeMessageChan, forceChecksum: _forceChecksum, AddrMgr: _desoAddrMgr, + params: _params, } if stateChangeSyncer != nil { @@ -1602,7 +1603,13 @@ func (srv *Server) _startSync() { } -func (srv *Server) HandleAcceptedPeer(pp *Peer) { +func (srv *Server) HandleAcceptedPeer(rn *RemoteNode) { + if rn == nil || rn.GetPeer() == nil { + return + } + pp := rn.GetPeer() + pp.SetServiceFlag(rn.GetServiceFlag()) + isSyncCandidate := pp.IsSyncCandidate() isSyncing := srv.blockchain.isSyncing() chainState := srv.blockchain.chainState() From 441dba6c862986ae0f98792f16080c82bf5970ec Mon Sep 17 00:00:00 2001 From: Piotr Nojszewski <29924594+AeonSw4n@users.noreply.github.com> Date: Sun, 28 Jan 2024 21:03:12 -0800 Subject: [PATCH 2/5] Fixes --- integration_testing/blocksync_test.go | 28 +++++++++++---------------- integration_testing/tools.go | 5 +++++ 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/integration_testing/blocksync_test.go b/integration_testing/blocksync_test.go index 04775d8ec..aeb989f47 100644 --- a/integration_testing/blocksync_test.go +++ b/integration_testing/blocksync_test.go @@ -18,14 +18,15 @@ import ( func TestSimpleBlockSync(t *testing.T) { node1 := spawnNodeProtocol1(t, 18000, "node1") node1.Config.ConnectIPs = []string{"deso-seed-2.io:17000"} - node2 := spawnNodeProtocol1(t, 18001, "node2") node1 = startNode(t, node1) - node2.Config.ConnectIPs = []string{"127.0.0.1:18000"} - node2 = startNode(t, node2) // wait for node1 to sync blocks waitForNodeToFullySync(node1) + node2 := spawnNodeProtocol1(t, 18001, "node2") + node2.Config.ConnectIPs = []string{"127.0.0.1:18000"} + node2 = startNode(t, node2) + // wait for node2 to sync blocks. waitForNodeToFullySync(node2) @@ -42,33 +43,26 @@ func TestSimpleBlockSync(t *testing.T) { // 6. node2 reconnects with node1 and syncs remaining blocks. // 7. compare node1 db matches node2 db. func TestSimpleSyncRestart(t *testing.T) { - require := require.New(t) - node1 := spawnNodeProtocol1(t, 18000, "node1") node1.Config.ConnectIPs = []string{"deso-seed-2.io:17000"} node1 = startNode(t, node1) - node2 := spawnNodeProtocol1(t, 18001, "node2") - node2.Config.ConnectIPs = []string{"127.0.0.1:18000"} - node2 = startNode(t, node2) - // wait for node1 to sync blocks waitForNodeToFullySync(node1) - // bridge the nodes together. - bridge := NewConnectionBridge(node1, node2) - require.NoError(bridge.Start()) + node2 := spawnNodeProtocol1(t, 18001, "node2") + node2.Config.ConnectIPs = []string{"127.0.0.1:18000"} + node2 = startNode(t, node2) randomHeight := randomUint32Between(t, 10, node2.Config.MaxSyncBlockHeight) - fmt.Println("Random height for a restart (re-use if test failed):", randomHeight) + t.Logf("Random height for a restart (re-use if test failed): %v", randomHeight) // Reboot node2 at a specific height and reconnect it with node1 - node2, bridge = restartAtHeightAndReconnectNode(t, node2, node1, bridge, randomHeight) + restartAtHeight(t, node2, randomHeight) waitForNodeToFullySync(node2) compareNodesByDB(t, node1, node2, 0) - fmt.Println("Random restart successful! Random height was", randomHeight) - fmt.Println("Databases match!") - bridge.Disconnect() + t.Logf("Random restart successful! Random height was: %v", randomHeight) + t.Logf("Databases match!") node1.Stop() node2.Stop() } diff --git a/integration_testing/tools.go b/integration_testing/tools.go index df9aad581..00469cc2e 100644 --- a/integration_testing/tools.go +++ b/integration_testing/tools.go @@ -427,6 +427,11 @@ func restartAtHeightAndReconnectNode(t *testing.T, node *cmd.Node, source *cmd.N return newNode, bridge } +func restartAtHeight(t *testing.T, node *cmd.Node, height uint32) *cmd.Node { + <-listenForBlockHeight(node, height) + return restartNode(t, node) +} + // listenForSyncPrefix will wait until the node starts downloading the provided syncPrefix in hypersync, and then sends // a message to the provided signal channel. func listenForSyncPrefix(t *testing.T, node *cmd.Node, syncPrefix []byte, signal chan<- bool) { From 437ea4487fc43297ef3485d970cd3bd198b0335f Mon Sep 17 00:00:00 2001 From: Piotr Nojszewski <29924594+AeonSw4n@users.noreply.github.com> Date: Sun, 28 Jan 2024 21:24:11 -0800 Subject: [PATCH 3/5] Fix another integration test --- integration_testing/blocksync_test.go | 2 +- integration_testing/tools.go | 2 +- lib/peer.go | 13 ++++++++++--- lib/remote_node.go | 4 ++++ lib/server.go | 8 +++++--- 5 files changed, 21 insertions(+), 8 deletions(-) diff --git a/integration_testing/blocksync_test.go b/integration_testing/blocksync_test.go index aeb989f47..b2dbaf03a 100644 --- a/integration_testing/blocksync_test.go +++ b/integration_testing/blocksync_test.go @@ -57,7 +57,7 @@ func TestSimpleSyncRestart(t *testing.T) { randomHeight := randomUint32Between(t, 10, node2.Config.MaxSyncBlockHeight) t.Logf("Random height for a restart (re-use if test failed): %v", randomHeight) // Reboot node2 at a specific height and reconnect it with node1 - restartAtHeight(t, node2, randomHeight) + node2 = restartAtHeight(t, node2, randomHeight) waitForNodeToFullySync(node2) compareNodesByDB(t, node1, node2, 0) diff --git a/integration_testing/tools.go b/integration_testing/tools.go index 00469cc2e..59de71663 100644 --- a/integration_testing/tools.go +++ b/integration_testing/tools.go @@ -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 = 2 + config.GlogV = 0 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 diff --git a/lib/peer.go b/lib/peer.go index b9cd9bfa2..6bc683382 100644 --- a/lib/peer.go +++ b/lib/peer.go @@ -48,7 +48,6 @@ type Peer struct { StatsMtx deadlock.RWMutex TimeOffsetSecs int64 TimeConnected time.Time - startingHeight uint32 ID uint64 // Ping-related fields. LastPingNonce uint64 @@ -70,6 +69,7 @@ type Peer struct { // Basic state. PeerInfoMtx deadlock.Mutex serviceFlags ServiceFlag + latestHeight uint64 addrStr string netAddr *wire.NetAddress minTxFeeRateNanosPerKB uint64 @@ -665,10 +665,10 @@ func (pp *Peer) MinFeeRateNanosPerKB() uint64 { } // StartingBlockHeight is the height of the peer's blockchain tip. -func (pp *Peer) StartingBlockHeight() uint32 { +func (pp *Peer) StartingBlockHeight() uint64 { pp.StatsMtx.RLock() defer pp.StatsMtx.RUnlock() - return pp.startingHeight + return pp.latestHeight } // NumBlocksToSend is the number of blocks the Peer has requested from @@ -893,6 +893,13 @@ func (pp *Peer) _setKnownAddressesMap(key string, val bool) { pp.knownAddressesMap[key] = val } +func (pp *Peer) SetLatestBlockHeight(height uint64) { + pp.StatsMtx.Lock() + defer pp.StatsMtx.Unlock() + + pp.latestHeight = height +} + func (pp *Peer) SetServiceFlag(sf ServiceFlag) { pp.PeerInfoMtx.Lock() defer pp.PeerInfoMtx.Unlock() diff --git a/lib/remote_node.go b/lib/remote_node.go index b8f378d07..6fb5e13ba 100644 --- a/lib/remote_node.go +++ b/lib/remote_node.go @@ -203,6 +203,10 @@ func (rn *RemoteNode) GetServiceFlag() ServiceFlag { return rn.handshakeMetadata.serviceFlag } +func (rn *RemoteNode) GetLatestBlockHeight() uint64 { + return rn.handshakeMetadata.latestBlockHeight +} + func (rn *RemoteNode) GetUserAgent() string { return rn.handshakeMetadata.userAgent } diff --git a/lib/server.go b/lib/server.go index d5a8c3147..5efd755f6 100644 --- a/lib/server.go +++ b/lib/server.go @@ -838,8 +838,8 @@ func (srv *Server) GetBlocks(pp *Peer, maxHeight int) { func (srv *Server) _handleHeaderBundle(pp *Peer, msg *MsgDeSoHeaderBundle) { printHeight := pp.StartingBlockHeight() - if srv.blockchain.headerTip().Height > printHeight { - printHeight = srv.blockchain.headerTip().Height + if uint64(srv.blockchain.headerTip().Height) > printHeight { + printHeight = uint64(srv.blockchain.headerTip().Height) } glog.Infof(CLog(Yellow, fmt.Sprintf("Received header bundle with %v headers "+ "in state %s from peer %v. Downloaded ( %v / %v ) total headers", @@ -1546,6 +1546,7 @@ func (srv *Server) _startSync() { // Find a peer with StartingHeight bigger than our best header tip. var bestPeer *Peer for _, peer := range srv.cmgr.GetAllPeers() { + if !peer.IsSyncCandidate() { glog.Infof("Peer is not sync candidate: %v (isOutbound: %v)", peer, peer.isOutbound) continue @@ -1553,7 +1554,7 @@ func (srv *Server) _startSync() { // Choose the peer with the best height out of everyone who's a // valid sync candidate. - if peer.StartingBlockHeight() < bestHeight { + if peer.StartingBlockHeight() < uint64(bestHeight) { continue } @@ -1609,6 +1610,7 @@ func (srv *Server) HandleAcceptedPeer(rn *RemoteNode) { } pp := rn.GetPeer() pp.SetServiceFlag(rn.GetServiceFlag()) + pp.SetLatestBlockHeight(rn.GetLatestBlockHeight()) isSyncCandidate := pp.IsSyncCandidate() isSyncing := srv.blockchain.isSyncing() From a6795833542cf96426a11705932398cbbf14c161 Mon Sep 17 00:00:00 2001 From: Piotr Nojszewski <29924594+AeonSw4n@users.noreply.github.com> Date: Mon, 29 Jan 2024 23:08:53 -0800 Subject: [PATCH 4/5] Fix integration tests --- integration_testing/blocksync_test.go | 69 ++---- integration_testing/hypersync_test.go | 302 +++++++------------------ integration_testing/migrations_test.go | 56 ++--- integration_testing/mining_test.go | 26 +-- integration_testing/rollback_test.go | 3 + integration_testing/tools.go | 19 ++ integration_testing/txindex_test.go | 49 +--- 7 files changed, 153 insertions(+), 371 deletions(-) diff --git a/integration_testing/blocksync_test.go b/integration_testing/blocksync_test.go index b2dbaf03a..e03aef152 100644 --- a/integration_testing/blocksync_test.go +++ b/integration_testing/blocksync_test.go @@ -2,10 +2,6 @@ package integration_testing import ( "fmt" - "github.com/deso-protocol/core/cmd" - "github.com/deso-protocol/core/lib" - "github.com/stretchr/testify/require" - "os" "testing" ) @@ -63,8 +59,6 @@ func TestSimpleSyncRestart(t *testing.T) { compareNodesByDB(t, node1, node2, 0) t.Logf("Random restart successful! Random height was: %v", randomHeight) t.Logf("Databases match!") - node1.Stop() - node2.Stop() } // TestSimpleSyncDisconnectWithSwitchingToNewPeer tests if a node can successfully restart while syncing blocks, and @@ -78,62 +72,35 @@ func TestSimpleSyncRestart(t *testing.T) { // 7. compare node1 state matches node2 state. // 8. compare node3 state matches node2 state. func TestSimpleSyncDisconnectWithSwitchingToNewPeer(t *testing.T) { - require := require.New(t) - _ = require - - dbDir1 := getDirectory(t) - dbDir2 := getDirectory(t) - dbDir3 := getDirectory(t) - defer os.RemoveAll(dbDir1) - defer os.RemoveAll(dbDir2) - defer os.RemoveAll(dbDir3) - - config1 := generateConfig(t, 18000, dbDir1, 10) - config1.SyncType = lib.NodeSyncTypeBlockSync - config2 := generateConfig(t, 18001, dbDir2, 10) - config2.SyncType = lib.NodeSyncTypeBlockSync - config3 := generateConfig(t, 18002, dbDir3, 10) - config3.SyncType = lib.NodeSyncTypeBlockSync - - config1.ConnectIPs = []string{"deso-seed-2.io:17000"} - config3.ConnectIPs = []string{"deso-seed-2.io:17000"} - - node1 := cmd.NewNode(config1) - node2 := cmd.NewNode(config2) - node3 := cmd.NewNode(config3) - + node1 := spawnNodeProtocol1(t, 18000, "node1") + node1.Config.ConnectIPs = []string{"deso-seed-2.io:17000"} node1 = startNode(t, node1) - node2 = startNode(t, node2) - node3 = startNode(t, node3) // wait for node1 to sync blocks waitForNodeToFullySync(node1) + + node3 := spawnNodeProtocol1(t, 18002, "node3") + node3.Config.ConnectIPs = []string{"deso-seed-2.io:17000"} + node3 = startNode(t, node3) + // wait for node3 to sync blocks waitForNodeToFullySync(node3) - // bridge the nodes together. - bridge12 := NewConnectionBridge(node1, node2) - require.NoError(bridge12.Start()) - - randomHeight := randomUint32Between(t, 10, config2.MaxSyncBlockHeight) - fmt.Println("Random height for a restart (re-use if test failed):", randomHeight) - disconnectAtBlockHeight(node2, bridge12, randomHeight) + node2 := spawnNodeProtocol1(t, 18001, "node2") + node2.Config.ConnectIPs = []string{"127.0.0.1:18000"} + node2 = startNode(t, node2) - // bridge the nodes together. - bridge23 := NewConnectionBridge(node2, node3) - require.NoError(bridge23.Start()) + randomHeight := randomUint32Between(t, 10, node2.Config.MaxSyncBlockHeight) + t.Logf("Random height for a restart (re-use if test failed): %v", randomHeight) - // Reboot node2 at a specific height and reconnect it with node1 - //node2, bridge12 = restartAtHeightAndReconnectNode(t, node2, node1, bridge12, randomHeight) + // Reboot node2 at a specific height and reconnect it with node3 + node2 = shutdownAtHeight(t, node2, randomHeight) + node2.Config.ConnectIPs = []string{"127.0.0.1:18002"} + node2 = startNode(t, node2) waitForNodeToFullySync(node2) compareNodesByDB(t, node1, node2, 0) compareNodesByDB(t, node3, node2, 0) - fmt.Println("Random restart successful! Random height was", randomHeight) - fmt.Println("Databases match!") - bridge12.Disconnect() - bridge23.Disconnect() - node1.Stop() - node2.Stop() - node3.Stop() + t.Logf("Random restart successful! Random height was %v", randomHeight) + t.Logf("Databases match!") } diff --git a/integration_testing/hypersync_test.go b/integration_testing/hypersync_test.go index bc4c8a7c0..b76b1db48 100644 --- a/integration_testing/hypersync_test.go +++ b/integration_testing/hypersync_test.go @@ -1,11 +1,7 @@ package integration_testing import ( - "fmt" - "github.com/deso-protocol/core/cmd" "github.com/deso-protocol/core/lib" - "github.com/stretchr/testify/require" - "os" "testing" ) @@ -16,35 +12,19 @@ import ( // 4. node2 hypersyncs from node1 // 5. once done, compare node1 state, db, and checksum matches node2. func TestSimpleHyperSync(t *testing.T) { - require := require.New(t) - _ = require - - dbDir1 := getDirectory(t) - dbDir2 := getDirectory(t) - defer os.RemoveAll(dbDir1) - defer os.RemoveAll(dbDir2) - - config1 := generateConfig(t, 18000, dbDir1, 10) - config1.SyncType = lib.NodeSyncTypeBlockSync - config2 := generateConfig(t, 18001, dbDir2, 10) - config2.SyncType = lib.NodeSyncTypeHyperSync - - config1.HyperSync = true - config2.HyperSync = true - config1.ConnectIPs = []string{"deso-seed-2.io:17000"} - - node1 := cmd.NewNode(config1) - node2 := cmd.NewNode(config2) - + node1 := spawnNodeProtocol1(t, 18000, "node1") + node1.Config.HyperSync = true + node1.Config.ConnectIPs = []string{"deso-seed-2.io:17000"} node1 = startNode(t, node1) - node2 = startNode(t, node2) // wait for node1 to sync blocks waitForNodeToFullySync(node1) - // bridge the nodes together. - bridge := NewConnectionBridge(node1, node2) - require.NoError(bridge.Start()) + node2 := spawnNodeProtocol1(t, 18001, "node2") + node2.Config.SyncType = lib.NodeSyncTypeHyperSync + node2.Config.HyperSync = true + node2.Config.ConnectIPs = []string{"127.0.0.1:18000"} + node2 = startNode(t, node2) // wait for node2 to sync blocks. waitForNodeToFullySync(node2) @@ -52,10 +32,7 @@ func TestSimpleHyperSync(t *testing.T) { compareNodesByState(t, node1, node2, 0) //compareNodesByDB(t, node1, node2, 0) compareNodesByChecksum(t, node1, node2) - fmt.Println("Databases match!") - bridge.Disconnect() - node1.Stop() - node2.Stop() + t.Logf("Databases match!") } // TestHyperSyncFromHyperSyncedNode test if a node can successfully hypersync from another hypersynced node: @@ -66,49 +43,28 @@ func TestSimpleHyperSync(t *testing.T) { // 5. once done, bridge node3 and node2 so that node3 hypersyncs from node2. // 6. compare node1 state, db, and checksum matches node2, and node3. func TestHyperSyncFromHyperSyncedNode(t *testing.T) { - require := require.New(t) - _ = require - - dbDir1 := getDirectory(t) - dbDir2 := getDirectory(t) - dbDir3 := getDirectory(t) - defer os.RemoveAll(dbDir1) - defer os.RemoveAll(dbDir2) - defer os.RemoveAll(dbDir3) - - config1 := generateConfig(t, 18000, dbDir1, 10) - config1.SyncType = lib.NodeSyncTypeBlockSync - config2 := generateConfig(t, 18001, dbDir2, 10) - config2.SyncType = lib.NodeSyncTypeHyperSyncArchival - config3 := generateConfig(t, 18002, dbDir3, 10) - config3.SyncType = lib.NodeSyncTypeHyperSyncArchival - - config1.HyperSync = true - config2.HyperSync = true - config3.HyperSync = true - config1.ConnectIPs = []string{"deso-seed-2.io:17000"} - - node1 := cmd.NewNode(config1) - node2 := cmd.NewNode(config2) - node3 := cmd.NewNode(config3) - + node1 := spawnNodeProtocol1(t, 18000, "node1") + node1.Config.HyperSync = true + node1.Config.ConnectIPs = []string{"deso-seed-2.io:17000"} node1 = startNode(t, node1) - node2 = startNode(t, node2) - node3 = startNode(t, node3) // wait for node1 to sync blocks waitForNodeToFullySync(node1) - // bridge the nodes together. - bridge12 := NewConnectionBridge(node1, node2) - require.NoError(bridge12.Start()) + node2 := spawnNodeProtocol1(t, 18001, "node2") + node2.Config.SyncType = lib.NodeSyncTypeHyperSyncArchival + node2.Config.HyperSync = true + node2.Config.ConnectIPs = []string{"127.0.0.1:18000"} + node2 = startNode(t, node2) // wait for node2 to sync blocks. waitForNodeToFullySync(node2) - // bridge node3 to node2 to kick off hyper sync from a hyper synced node - bridge23 := NewConnectionBridge(node2, node3) - require.NoError(bridge23.Start()) + node3 := spawnNodeProtocol1(t, 18002, "node3") + node3.Config.SyncType = lib.NodeSyncTypeHyperSyncArchival + node3.Config.HyperSync = true + node3.Config.ConnectIPs = []string{"127.0.0.1:18001"} + node3 = startNode(t, node3) // wait for node2 to sync blocks. waitForNodeToFullySync(node3) @@ -122,12 +78,7 @@ func TestHyperSyncFromHyperSyncedNode(t *testing.T) { //compareNodesByDB(t, node2, node3, 0) compareNodesByChecksum(t, node2, node3) - fmt.Println("Databases match!") - bridge12.Disconnect() - bridge23.Disconnect() - node1.Stop() - node2.Stop() - node3.Stop() + t.Logf("Databases match!") } // TestSimpleHyperSyncRestart test if a node can successfully hyper sync from another node: @@ -138,52 +89,34 @@ func TestHyperSyncFromHyperSyncedNode(t *testing.T) { // 5. node2 reconnects to node1 and hypersyncs again. // 6. Once node2 finishes sync, compare node1 state, db, and checksum matches node2. func TestSimpleHyperSyncRestart(t *testing.T) { - require := require.New(t) - _ = require - - dbDir1 := getDirectory(t) - dbDir2 := getDirectory(t) - defer os.RemoveAll(dbDir1) - defer os.RemoveAll(dbDir2) - - config1 := generateConfig(t, 18000, dbDir1, 10) - config2 := generateConfig(t, 18001, dbDir2, 10) - - config1.HyperSync = true - config1.SyncType = lib.NodeSyncTypeBlockSync - config2.HyperSync = true - config2.SyncType = lib.NodeSyncTypeHyperSyncArchival - config1.ConnectIPs = []string{"deso-seed-2.io:17000"} - - node1 := cmd.NewNode(config1) - node2 := cmd.NewNode(config2) - + node1 := spawnNodeProtocol1(t, 18000, "node1") + node1.Config.HyperSync = true + node1.Config.ConnectIPs = []string{"deso-seed-2.io:17000"} node1 = startNode(t, node1) - node2 = startNode(t, node2) // wait for node1 to sync blocks waitForNodeToFullySync(node1) - // bridge the nodes together. - bridge := NewConnectionBridge(node1, node2) - require.NoError(bridge.Start()) + node2 := spawnNodeProtocol1(t, 18001, "node2") + node2.Config.SyncType = lib.NodeSyncTypeHyperSyncArchival + node2.Config.HyperSync = true + node2.Config.ConnectIPs = []string{"127.0.0.1:18000"} + node2 = startNode(t, node2) syncIndex := randomUint32Between(t, 0, uint32(len(lib.StatePrefixes.StatePrefixesList))) syncPrefix := lib.StatePrefixes.StatePrefixesList[syncIndex] - fmt.Println("Random sync prefix for a restart (re-use if test failed):", syncPrefix) + t.Logf("Random sync prefix for a restart (re-use if test failed): %v", syncPrefix) + // Reboot node2 at a specific sync prefix and reconnect it with node1 - node2, bridge = restartAtSyncPrefixAndReconnectNode(t, node2, node1, bridge, syncPrefix) + node2 = restartAtSyncPrefix(t, node2, syncPrefix) // wait for node2 to sync blocks. waitForNodeToFullySync(node2) compareNodesByState(t, node1, node2, 0) //compareNodesByDB(t, node1, node2, 0) compareNodesByChecksum(t, node1, node2) - fmt.Println("Random restart successful! Random sync prefix was", syncPrefix) - fmt.Println("Databases match!") - bridge.Disconnect() - node1.Stop() - node2.Stop() + t.Logf("Random restart successful! Random sync prefix was: %v", syncPrefix) + t.Logf("Databases match!") } // TestSimpleHyperSyncDisconnectWithSwitchingToNewPeer tests if a node can successfully restart while hypersyncing. @@ -194,57 +127,34 @@ func TestSimpleHyperSyncRestart(t *testing.T) { // 5. after restart, bridge node2 with node3 and resume hypersync. // 6. once node2 finishes, compare node1, node2, node3 state, db, and checksums are identical. func TestSimpleHyperSyncDisconnectWithSwitchingToNewPeer(t *testing.T) { - require := require.New(t) - _ = require - - dbDir1 := getDirectory(t) - dbDir2 := getDirectory(t) - dbDir3 := getDirectory(t) - defer os.RemoveAll(dbDir1) - defer os.RemoveAll(dbDir2) - defer os.RemoveAll(dbDir3) - - config1 := generateConfig(t, 18000, dbDir1, 10) - config1.SyncType = lib.NodeSyncTypeBlockSync - config2 := generateConfig(t, 18001, dbDir2, 10) - config2.SyncType = lib.NodeSyncTypeHyperSyncArchival - config3 := generateConfig(t, 18002, dbDir3, 10) - config3.SyncType = lib.NodeSyncTypeBlockSync - - config1.HyperSync = true - config2.HyperSync = true - config3.HyperSync = true - config1.ConnectIPs = []string{"deso-seed-2.io:17000"} - config3.ConnectIPs = []string{"deso-seed-2.io:17000"} - - node1 := cmd.NewNode(config1) - node2 := cmd.NewNode(config2) - node3 := cmd.NewNode(config3) - + node1 := spawnNodeProtocol1(t, 18000, "node1") + node1.Config.HyperSync = true + node1.Config.ConnectIPs = []string{"deso-seed-2.io:17000"} node1 = startNode(t, node1) - node2 = startNode(t, node2) - node3 = startNode(t, node3) - // wait for node1 to sync blocks waitForNodeToFullySync(node1) + + node3 := spawnNodeProtocol1(t, 18002, "node3") + node3.Config.HyperSync = true + node3.Config.ConnectIPs = []string{"127.0.0.1:18000"} + node3 = startNode(t, node3) // wait for node3 to sync blocks waitForNodeToFullySync(node3) - // bridge the nodes together. - bridge12 := NewConnectionBridge(node1, node2) - require.NoError(bridge12.Start()) + node2 := spawnNodeProtocol1(t, 18001, "node2") + node2.Config.SyncType = lib.NodeSyncTypeHyperSyncArchival + node2.Config.HyperSync = true + node2.Config.ConnectIPs = []string{"127.0.0.1:18000"} + node2 = startNode(t, node2) + // Reboot node2 at a specific height and reconnect it with node1 syncIndex := randomUint32Between(t, 0, uint32(len(lib.StatePrefixes.StatePrefixesList))) syncPrefix := lib.StatePrefixes.StatePrefixesList[syncIndex] - fmt.Println("Random prefix for a restart (re-use if test failed):", syncPrefix) - disconnectAtSyncPrefix(t, node2, bridge12, syncPrefix) - - // bridge the nodes together. - bridge23 := NewConnectionBridge(node2, node3) - require.NoError(bridge23.Start()) + t.Logf("Random prefix for a restart (re-use if test failed): %v", syncPrefix) + node2 = shutdownAtSyncPrefix(t, node2, syncPrefix) + node2.Config.ConnectIPs = []string{"127.0.0.1:18002"} + node2 = startNode(t, node2) - // Reboot node2 at a specific height and reconnect it with node1 - //node2, bridge12 = restartAtHeightAndReconnectNode(t, node2, node1, bridge12, randomHeight) // wait for node2 to sync blocks. waitForNodeToFullySync(node2) @@ -257,13 +167,8 @@ func TestSimpleHyperSyncDisconnectWithSwitchingToNewPeer(t *testing.T) { compareNodesByState(t, node1, node2, 0) //compareNodesByDB(t, node1, node2, 0) compareNodesByChecksum(t, node1, node2) - fmt.Println("Random restart successful! Random sync prefix was", syncPrefix) - fmt.Println("Databases match!") - bridge12.Disconnect() - bridge23.Disconnect() - node1.Stop() - node2.Stop() - node3.Stop() + t.Logf("Random restart successful! Random sync prefix was: %v", syncPrefix) + t.Logf("Databases match!") } // TODO: disconnecting the provider peer during hypersync doesn't work. @@ -317,93 +222,49 @@ func TestSimpleHyperSyncDisconnectWithSwitchingToNewPeer(t *testing.T) { //} func TestArchivalMode(t *testing.T) { - require := require.New(t) - _ = require - - dbDir1 := getDirectory(t) - dbDir2 := getDirectory(t) - defer os.RemoveAll(dbDir1) - defer os.RemoveAll(dbDir2) - - config1 := generateConfig(t, 18000, dbDir1, 10) - config2 := generateConfig(t, 18001, dbDir2, 10) - - config1.HyperSync = true - config2.HyperSync = true - config1.ConnectIPs = []string{"deso-seed-2.io:17000"} - config1.SyncType = lib.NodeSyncTypeBlockSync - config2.SyncType = lib.NodeSyncTypeHyperSyncArchival - - node1 := cmd.NewNode(config1) - node2 := cmd.NewNode(config2) - + node1 := spawnNodeProtocol1(t, 18000, "node1") + node1.Config.HyperSync = true + node1.Config.ConnectIPs = []string{"deso-seed-2.io:17000"} node1 = startNode(t, node1) - node2 = startNode(t, node2) // wait for node1 to sync blocks waitForNodeToFullySync(node1) - // bridge the nodes together. - bridge := NewConnectionBridge(node1, node2) - require.NoError(bridge.Start()) + node2 := spawnNodeProtocol1(t, 18001, "node2") + node2.Config.SyncType = lib.NodeSyncTypeHyperSyncArchival + node2.Config.HyperSync = true + node2.Config.ConnectIPs = []string{"127.0.0.1:18000"} + node2 = startNode(t, node2) // wait for node2 to sync blocks. waitForNodeToFullySync(node2) compareNodesByDB(t, node1, node2, 0) - - //compareNodesByDB(t, node1, node2, 0) compareNodesByChecksum(t, node1, node2) - fmt.Println("Databases match!") - bridge.Disconnect() - node1.Stop() - node2.Stop() + t.Logf("Databases match!") } func TestBlockSyncFromArchivalModeHyperSync(t *testing.T) { - require := require.New(t) - _ = require - - dbDir1 := getDirectory(t) - dbDir2 := getDirectory(t) - dbDir3 := getDirectory(t) - defer os.RemoveAll(dbDir1) - defer os.RemoveAll(dbDir2) - defer os.RemoveAll(dbDir3) - - config1 := generateConfig(t, 18000, dbDir1, 10) - config2 := generateConfig(t, 18001, dbDir2, 10) - config3 := generateConfig(t, 18002, dbDir3, 10) - - config1.HyperSync = true - config1.SyncType = lib.NodeSyncTypeBlockSync - config2.HyperSync = true - config2.SyncType = lib.NodeSyncTypeHyperSyncArchival - config3.HyperSync = false - config3.SyncType = lib.NodeSyncTypeBlockSync - config1.ConnectIPs = []string{"deso-seed-2.io:17000"} - - node1 := cmd.NewNode(config1) - node2 := cmd.NewNode(config2) - node3 := cmd.NewNode(config3) - + node1 := spawnNodeProtocol1(t, 18000, "node1") + node1.Config.HyperSync = true + node1.Config.ConnectIPs = []string{"deso-seed-2.io:17000"} node1 = startNode(t, node1) - node2 = startNode(t, node2) - node3 = startNode(t, node3) - // wait for node1 to sync blocks waitForNodeToFullySync(node1) - // bridge the nodes together. - bridge12 := NewConnectionBridge(node1, node2) - require.NoError(bridge12.Start()) - + node2 := spawnNodeProtocol1(t, 18001, "node2") + node2.Config.SyncType = lib.NodeSyncTypeHyperSyncArchival + node2.Config.HyperSync = true + node2.Config.ConnectIPs = []string{"127.0.0.1:18000"} + node2 = startNode(t, node2) // wait for node2 to sync blocks. waitForNodeToFullySync(node2) - bridge23 := NewConnectionBridge(node2, node3) - require.NoError(bridge23.Start()) - + node3 := spawnNodeProtocol1(t, 18002, "node3") + node3.Config.SyncType = lib.NodeSyncTypeBlockSync + node3.Config.HyperSync = true + node3.Config.ConnectIPs = []string{"127.0.0.1:18001"} + node3 = startNode(t, node3) // wait for node3 to sync blocks. waitForNodeToFullySync(node3) @@ -412,10 +273,5 @@ func TestBlockSyncFromArchivalModeHyperSync(t *testing.T) { //compareNodesByDB(t, node1, node2, 0) compareNodesByChecksum(t, node1, node2) - fmt.Println("Databases match!") - bridge12.Disconnect() - bridge23.Disconnect() - node1.Stop() - node2.Stop() - node3.Stop() + t.Logf("Databases match!") } diff --git a/integration_testing/migrations_test.go b/integration_testing/migrations_test.go index 1419d483e..067a2f3b6 100644 --- a/integration_testing/migrations_test.go +++ b/integration_testing/migrations_test.go @@ -1,65 +1,39 @@ package integration_testing import ( - "fmt" - "github.com/deso-protocol/core/cmd" - "github.com/deso-protocol/core/lib" "github.com/stretchr/testify/require" - "os" "testing" ) // TODO: Add an encoder migration height in constants.go then modify some // random struct like UtxoEntry. Until we have a migration, we can't fully test this. func TestEncoderMigrations(t *testing.T) { - require := require.New(t) - _ = require - - dbDir1 := getDirectory(t) - dbDir2 := getDirectory(t) - defer os.RemoveAll(dbDir1) - defer os.RemoveAll(dbDir2) - - config1 := generateConfig(t, 18000, dbDir1, 10) - config1.SyncType = lib.NodeSyncTypeBlockSync - config2 := generateConfig(t, 18001, dbDir2, 10) - config2.SyncType = lib.NodeSyncTypeHyperSync - - config1.ConnectIPs = []string{"deso-seed-2.io:17000"} - config1.HyperSync = true - config2.HyperSync = true - - node1 := cmd.NewNode(config1) - node2 := cmd.NewNode(config2) - + node1 := spawnNodeProtocol1(t, 18000, "node1") + node1.Config.HyperSync = true + node1.Config.ConnectIPs = []string{"deso-seed-2.io:17000"} node1 = startNode(t, node1) - node2 = startNode(t, node2) - // wait for node1 to sync blocks waitForNodeToFullySync(node1) - // bridge the nodes together. - bridge := NewConnectionBridge(node1, node2) - require.NoError(bridge.Start()) - + node2 := spawnNodeProtocol1(t, 18001, "node2") + node2.Config.HyperSync = true + node2.Config.ConnectIPs = []string{"127.0.0.1:18000"} + node2 = startNode(t, node2) // wait for node2 to sync blocks. waitForNodeToFullySync(node2) - fmt.Println("Chain state and operation channel", node2.Server.GetBlockchain().ChainState(), + t.Logf("Chain state and operation channel (state: %v), (len: %v)", node2.Server.GetBlockchain().ChainState(), len(node2.Server.GetBlockchain().Snapshot().OperationChannel.OperationChannel)) compareNodesByState(t, node1, node2, 0) - fmt.Println("node1 checksum:", computeNodeStateChecksum(t, node1, 1500)) - fmt.Println("node2 checksum:", computeNodeStateChecksum(t, node2, 1500)) + t.Logf("node1 checksum: %v", computeNodeStateChecksum(t, node1, 1500)) + t.Logf("node2 checksum: %v", computeNodeStateChecksum(t, node2, 1500)) checksum1, err := node1.Server.GetBlockchain().Snapshot().Checksum.ToBytes() - require.NoError(err) + require.NoError(t, err) checksum2, err := node2.Server.GetBlockchain().Snapshot().Checksum.ToBytes() - require.NoError(err) - fmt.Println("node1 server checksum:", checksum1) - fmt.Println("node2 server checksum:", checksum2) + require.NoError(t, err) + t.Logf("node1 server checksum: %v", checksum1) + t.Logf("node2 server checksum: %v", checksum2) compareNodesByChecksum(t, node1, node2) - fmt.Println("Databases match!") - bridge.Disconnect() - node1.Stop() - node2.Stop() + t.Logf("Databases match!") } diff --git a/integration_testing/mining_test.go b/integration_testing/mining_test.go index 88de5e097..3e7137b34 100644 --- a/integration_testing/mining_test.go +++ b/integration_testing/mining_test.go @@ -1,35 +1,23 @@ package integration_testing import ( - "github.com/deso-protocol/core/cmd" "github.com/deso-protocol/core/lib" - "github.com/stretchr/testify/require" - "os" "testing" ) // TestSimpleBlockSync test if a node can mine blocks on regtest +// TODO: This test doesn't work, we should investigate why. func TestRegtestMiner(t *testing.T) { - require := require.New(t) - _ = require + t.Skipf("TestRegtestMiner doesn't work in PoS") - dbDir1 := getDirectory(t) - defer os.RemoveAll(dbDir1) - - config1 := generateConfig(t, 18000, dbDir1, 10) - config1.SyncType = lib.NodeSyncTypeBlockSync - config1.Params = &lib.DeSoTestnetParams - config1.MaxSyncBlockHeight = 0 - config1.MinerPublicKeys = []string{"tBCKVERmG9nZpHTk2AVPqknWc1Mw9HHAnqrTpW1RnXpXMQ4PsQgnmV"} - - config1.Regtest = true - - node1 := cmd.NewNode(config1) + node1 := spawnNodeProtocol1(t, 18000, "node1") + node1.Config.Params = &lib.DeSoTestnetParams + node1.Config.MaxSyncBlockHeight = 0 + node1.Config.MinerPublicKeys = []string{"tBCKVERmG9nZpHTk2AVPqknWc1Mw9HHAnqrTpW1RnXpXMQ4PsQgnmV"} + node1.Config.Regtest = true node1 = startNode(t, node1) // wait for node1 to sync blocks mineHeight := uint32(40) <-listenForBlockHeight(node1, mineHeight) - - node1.Stop() } diff --git a/integration_testing/rollback_test.go b/integration_testing/rollback_test.go index 8028866ac..c7b440b2b 100644 --- a/integration_testing/rollback_test.go +++ b/integration_testing/rollback_test.go @@ -10,7 +10,10 @@ import ( ) // Start blocks to height 5000 and then disconnect +// TODO: This test won't work now. func TestStateRollback(t *testing.T) { + t.Skipf("DisconnectBlocksToHeight doesn't work in PoS") + require := require.New(t) _ = require diff --git a/integration_testing/tools.go b/integration_testing/tools.go index 59de71663..42cb6c11f 100644 --- a/integration_testing/tools.go +++ b/integration_testing/tools.go @@ -432,6 +432,11 @@ func restartAtHeight(t *testing.T, node *cmd.Node, height uint32) *cmd.Node { return restartNode(t, node) } +func shutdownAtHeight(t *testing.T, node *cmd.Node, height uint32) *cmd.Node { + <-listenForBlockHeight(node, height) + return shutdownNode(t, node) +} + // listenForSyncPrefix will wait until the node starts downloading the provided syncPrefix in hypersync, and then sends // a message to the provided signal channel. func listenForSyncPrefix(t *testing.T, node *cmd.Node, syncPrefix []byte, signal chan<- bool) { @@ -475,6 +480,20 @@ func restartAtSyncPrefixAndReconnectNode(t *testing.T, node *cmd.Node, source *c return newNode, bridge } +func restartAtSyncPrefix(t *testing.T, node *cmd.Node, syncPrefix []byte) *cmd.Node { + listener := make(chan bool) + listenForSyncPrefix(t, node, syncPrefix, listener) + <-listener + return restartNode(t, node) +} + +func shutdownAtSyncPrefix(t *testing.T, node *cmd.Node, syncPrefix []byte) *cmd.Node { + listener := make(chan bool) + listenForSyncPrefix(t, node, syncPrefix, listener) + <-listener + return shutdownNode(t, node) +} + func randomUint32Between(t *testing.T, min, max uint32) uint32 { require := require.New(t) randomNumber, err := wire.RandomUint64() diff --git a/integration_testing/txindex_test.go b/integration_testing/txindex_test.go index dfd398557..702e63c10 100644 --- a/integration_testing/txindex_test.go +++ b/integration_testing/txindex_test.go @@ -1,11 +1,7 @@ package integration_testing import ( - "fmt" - "github.com/deso-protocol/core/cmd" "github.com/deso-protocol/core/lib" - "github.com/stretchr/testify/require" - "os" "testing" ) @@ -16,39 +12,21 @@ import ( // 4. node2 syncs MaxSyncBlockHeight blocks from node1, and builds txindex afterwards. // 5. compare node1 db and txindex matches node2. func TestSimpleTxIndex(t *testing.T) { - require := require.New(t) - _ = require - - dbDir1 := getDirectory(t) - dbDir2 := getDirectory(t) - defer os.RemoveAll(dbDir1) - defer os.RemoveAll(dbDir2) - - config1 := generateConfig(t, 18000, dbDir1, 10) - config1.HyperSync = true - config1.SyncType = lib.NodeSyncTypeBlockSync - config2 := generateConfig(t, 18001, dbDir2, 10) - config2.HyperSync = true - config2.SyncType = lib.NodeSyncTypeHyperSyncArchival - - config1.TXIndex = true - config2.TXIndex = true - config1.ConnectIPs = []string{"deso-seed-2.io:17000"} - - node1 := cmd.NewNode(config1) - node2 := cmd.NewNode(config2) - + node1 := spawnNodeProtocol1(t, 18000, "node1") + node1.Config.ConnectIPs = []string{"deso-seed-2.io:17000"} + node1.Config.HyperSync = true + node1.Config.TXIndex = true node1 = startNode(t, node1) - node2 = startNode(t, node2) - // wait for node1 to sync blocks waitForNodeToFullySync(node1) - // bridge the nodes together. - bridge := NewConnectionBridge(node1, node2) - require.NoError(bridge.Start()) - - // wait for node2 to sync blocks. + node2 := spawnNodeProtocol1(t, 18001, "node2") + node2.Config.SyncType = lib.NodeSyncTypeHyperSyncArchival + node2.Config.ConnectIPs = []string{"127.0.0.1:18000"} + node2.Config.HyperSync = true + node2.Config.TXIndex = true + node2 = startNode(t, node2) + // wait for node1 to sync blocks waitForNodeToFullySync(node2) waitForNodeToFullySyncTxIndex(node1) @@ -56,8 +34,5 @@ func TestSimpleTxIndex(t *testing.T) { compareNodesByDB(t, node1, node2, 0) compareNodesByTxIndex(t, node1, node2, 0) - fmt.Println("Databases match!") - bridge.Disconnect() - node1.Stop() - node2.Stop() + t.Logf("Databases match!") } From 04205db0c1dddbbe5d1001036a93dfb24c861571 Mon Sep 17 00:00:00 2001 From: Piotr Nojszewski <29924594+AeonSw4n@users.noreply.github.com> Date: Tue, 30 Jan 2024 12:18:58 -0800 Subject: [PATCH 5/5] Fix RegtestMiner --- integration_testing/mining_test.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/integration_testing/mining_test.go b/integration_testing/mining_test.go index 3e7137b34..facbce226 100644 --- a/integration_testing/mining_test.go +++ b/integration_testing/mining_test.go @@ -6,12 +6,11 @@ import ( ) // TestSimpleBlockSync test if a node can mine blocks on regtest -// TODO: This test doesn't work, we should investigate why. func TestRegtestMiner(t *testing.T) { - t.Skipf("TestRegtestMiner doesn't work in PoS") - node1 := spawnNodeProtocol1(t, 18000, "node1") - node1.Config.Params = &lib.DeSoTestnetParams + params := lib.DeSoTestnetParams + node1.Config.Params = ¶ms + node1.Params = ¶ms node1.Config.MaxSyncBlockHeight = 0 node1.Config.MinerPublicKeys = []string{"tBCKVERmG9nZpHTk2AVPqknWc1Mw9HHAnqrTpW1RnXpXMQ4PsQgnmV"} node1.Config.Regtest = true