Commit Graph

392 Commits

Author SHA1 Message Date
Chris Stewart
16aeb56df5
Remove implicit NodeAppConfig from PeerMessageSender (#5465) 2024-03-09 15:00:58 -06:00
Chris Stewart
567c2400ca
Small refactors to use RunningNodeState methods, improve logs (#5463) 2024-03-09 09:25:34 -06:00
Chris Stewart
5967caeca7
2024 03 07 Add NodeState.FilterOrFilterHeaderSync, refactor PeerManager to use it (#5459)
* Refactor syncHelper() to return SyncNodeState rather than Unit

* Add FilterOrFilterHeaderSync, rework various methods in PeerManager to return Option[FilterOrFilterHeaderSyncState] to indicate if we are syncing rather than Future[Unit]

* Don't use getPeerMessageSender() if we can use syncPeerMessageSender()

* Fix case where syncpeer and new peer are different when creating a filter sync job

* Adjust createFilterSyncJob() return type, throw exception when we try to sync but PeerManager is not started

* Refactor to use SyncNodeState.{toFilterHeaderSync,toFilterSync}

* Cleanup comments
2024-03-08 10:13:58 -06:00
Chris Stewart
e793c53dd7
Add guards on sending blockfilter messages to non-blockfilter peers (#5457)
* Add guards on sending blockfilter messages to non-blockfilter peers

* Simplify logic

* add scaladoc

* Remove misleading log
2024-03-06 08:26:32 -06:00
Chris Stewart
55e4dab86e
Rework NodeApi.downloadBlocks() to use DoubleSha256DigestBE (#5456)
* Rework NodeApi.downloadBlocks() to use DoubleSha256DigestBE rather than DoubleSha256Digest

* Fix test cases

* Fix docs

* Fix compile
2024-03-05 15:19:32 -06:00
Chris Stewart
898d2b44ee
Fix bug where we were executing block callbacks when we hadn't seen a block header (#5455)
* Fix bug where we were executing block callbacks when we hadn't seen a block header

* reduce log to DEBUG
2024-03-05 13:47:03 -06:00
Chris Stewart
238948e185
Remove PeerMessageSenderApi param from DataMessageHandler (#5453) 2024-03-05 11:12:17 -06:00
Chris Stewart
ddb6f01d65
Simplify / reduce log level for compact filter logs (#5452) 2024-03-05 09:20:32 -06:00
Chris Stewart
367285d9b9
Reduce reliance of PeerManager._peerDataMap in favor of NodeState.peerDataMap (#5451)
* Reduce reliance of PeerManager._peerDataMap in favor of NodeState.peerDataMap

* Fix bug where we weren't removing peers from NodeState

* Remove invariants

* Empty commit to run CI

* Empty commit to re-run CI
2024-03-05 08:16:29 -06:00
Chris Stewart
0d2e0a98f0
fix bug where we weren't properly transferring state to FilterHeaderSync, reduce log level of peer we fail to connect to (#5450) 2024-03-04 13:19:22 -06:00
Chris Stewart
ae3a634703
2024 03 01 Fix syncPeer exceptions (#5446)
* Add NodeRunningState.removePeer(), add helper method onDisconnectNodeStateUpdate() to consolidate disconnect logic

* Remove duplicate logic

* Add bitcoin-s.node.maxConnectedPeers test

* Clean up resources in test case

* Remove unecessary replacePeers()

* Add NodeState.addPeer()

* Add NodeRunningState.connectedPeerCount, separate handling of connection slots and filter slots
2024-03-04 09:22:16 -06:00
Chris Stewart
1f0af696f6
Reduce DataMessageHandler log levels (#5447) 2024-03-02 17:06:14 -06:00
Chris Stewart
951bdc5b34
Always try to attempt to connect to our param peers in PeerFinder (#5444) 2024-03-01 11:28:17 -06:00
Chris Stewart
8fb62ad21c
Use NodeCallbackStreamManager when calling NodeCallbacks constructors (#5439)
* Use NodeCallbackStreamManager when calling NodeCallbacks constructors to avoid dropping messages

* Fix handling of CallBackHandler.empty and names

* Empty commit to re-run CI

* Empty commit to re-run CI
2024-02-29 12:01:11 -06:00
Chris Stewart
70f983213c
Ignore invs while in IBD rather than when syncing (#5433)
* Ignore invs while in IBD rather than when syncing

* Ignore bitcoiner.live test case for now
2024-02-28 13:30:08 -06:00
Chris Stewart
d1ecd35e63
Fix PeerDb.lastSeen race condition in unit tests (#5435)
* Disconnect from bitcoind side rather than bitcoin-s side to make sure we don't run into a race condition for updating lastSeen

* Remove usage of CachedAppConfig, switch implicit param args for PeerDAO to be consistent with rest of code base

* Fix bug in getNodeURIFromBitcoind(), disconnect from bitcoind side in PeerManagerTest

* Add println to see why still fialing

* Add PeerConnection.getLocalAddress, add parameter localAddressBitcoinS  to NodeTestUtil.getNodeURIFromBitcoind() to make sure we are getting the correct URI

* Empty commit to run CI
2024-02-28 10:33:01 -06:00
Chris Stewart
ab0b0e2209
Fix bug where we weren't removing peer from NodeRunningState.waitingForDisconnection (#5425)
* Fix bug where we weren't removing peer from NodeRunningState.waitingForDisconnection

* Empty commit to re-run CI

* Remove _peerDataMap.remove(i.peer)

* Empty commit to re-run CI

* Replace state even if client.stop() results in a failed Future
2024-02-27 15:38:16 -06:00
Chris Stewart
0053ccd853
Rework NodeState.toString() (#5432) 2024-02-27 13:59:51 -06:00
Chris Stewart
8a0c00637c
Remove duplicate PeerConnection.disconnect() call (#5426)
* Remove duplicate disconnect() call

* Remove log for case where we haven't set PeerConnection.connectionGraphOpt but call PeerConnection.stop()

* Remove bitcoin-s.node.initialization-timeout
2024-02-27 08:03:37 -06:00
Chris Stewart
6934b33474
Fix bug in health checks were we wouldn't attempt to connect NodeAppConfig.maxConnectedPeers if we didn't have any non compact filter peers connected (#5422) 2024-02-23 16:45:01 -06:00
Chris Stewart
90b9e76e56
Keeping finding peers until all peers are blockfilter peers (#5417)
* Keep attempting to connect to block filter peers until all connection slots are block filter peers

* Empty commit to run CI
2024-02-23 08:33:22 -06:00
Chris Stewart
783ed1903d
Rename bitcoin-s.node.inactivity-timeout -> bitcoin-s.node.health-check-interval (#5418) 2024-02-23 08:31:22 -06:00
Chris Stewart
1dff918848
2023 02 21 pekko (#5413)
* Get dependencies resolving, get tor module compiling

* Get everything compiling with pekko

* Rework configs/logging to use pekko namespace

* Rename AkkaUtil -> PekkoUtil, BitcoinSAkkaAsyncTest -> BitcoinSPekkoAsyncTest
2024-02-22 10:26:21 -06:00
Chris Stewart
3177ee405f
Move away from suredbits provided peers by default (#5390)
* Move away from suredbits provided peers by default

* Remove setting bitcoin-s.node.use-default-peers

* Don't allow peer to stay connected if it doesn't support compact filters

* Move disconnection logic into managePeerAfterInitialization()

* Remove reconnect() when we have no other peers, send getaddr message after we know we are keeping the peer connection

* Remove hasCf flag check, revert log

* Reduce inactivity-timeout to 5 minutes by default, shuffle peers in PeerFinder beforing pushing onto stack

* Add logic to disconnect AttemptToConnect peers after addr mesage is received

* Create PeerFinder.queryForPeerConnections(), call it directly from PeerManager on health checks rather than restarting PeerFinder

* scalafmt

* Move more logic into managePeerAfterInitalization()

* Don't set isPersistent for db peers by default

* Add call to queryForPeerConnections() inside of PeerManager.onDisconnect() to try to attempt to more peers when we have no more connections, fix MisBehavingPeer logic to not start sync, starting sync should happen in onDisconnect()

* Revert logback-test.xml

* Sort peers we are attempting to connect to by lastSeen parameter

* Refactor DoneSyncing.toHeaderSync() to return Option[HeaderSync] to represent the case where we don't have a peer to sync with

* scalafmt

* Remove duplicate PeerFinder.buildPeerData()
2024-02-20 12:12:57 -06:00
Chris Stewart
b89b31fe09
2024 02 18 peerfinder duplicate connect (#5403)
* Pull PeerFinder changes over from #5390

* Filter out peers we are already connected when attempting to discover peers inside of PeerFinder

* Try to work around mutable.Map.isEmpty bug by converting to immutable Map
2024-02-18 11:47:32 -06:00
Chris Stewart
155b4fbc76
Fix case were we weren't cancelling the syncFilter job onDisconnect() (#5402) 2024-02-17 17:41:34 -06:00
Chris Stewart
f5087c5e3f
Remove PeerManager.{getPeerMessageSender(), getPeerConnection()}, use NodeState.{getPeerMessageSender(), getPeerConnection()} (#5400) 2024-02-17 07:37:50 -06:00
Chris Stewart
e4fbfe73e6
2024 02 16 fix get filter sync marker from stop block header bug (#5401)
* Fix bug in getFilterSyncMarkerFromStopBlockHeader where we were previously querying for children rather than the block hashes at the given height for building the FilterSyncMarker for getcfilter request. Also introduce delay in sending getcfheader because of https://github.com/bitcoin/bitcoin/issues/27085

* Only fallback to reorg scenario if we find no headers at height + 1

* Remove the best filter's block header from the candidate headers in reorg scenarios
2024-02-17 06:26:55 -06:00
Chris Stewart
bc94a8b01f
2024 02 15 Fix duplicate sync bug when we have a misbehaving peer (#5399)
* Fix bug where we were attempting to sync twice when we had a MisBehavingPeer, also simplify some logic inside of onDisconnect()

* Pull over more small changes from #5390
2024-02-15 14:56:12 -06:00
Chris Stewart
fe33c2919c
Fix inconsistency of PeerDAO primary key usage (#5398)
* Fix inconsistency of PeerDAO primary key usage

* Add Peer.port helper method
2024-02-14 13:31:56 -06:00
Chris Stewart
536cc26ba5
Update last seen value in PeerDb on disconnect (#5397) 2024-02-13 16:38:18 -06:00
Chris Stewart
05d03e7da6
Remove skipPeers, better PeerFinder.toString() (#5396) 2024-02-13 09:01:50 -06:00
Chris Stewart
2d3e481ce0
Use Future.successful() when removing peer as there is no underlying async computation (#5394) 2024-02-11 11:28:25 -06:00
Chris Stewart
9d58c9eb89
Implement health checks for peers, first check is if we have any blockfilter peers (#5393)
* Implement health checks for peers, first check is if we have any blockfilter peers

* Actually send HealthCheck message to stream
2024-02-11 10:37:57 -06:00
Chris Stewart
d4ae659887
Log instead of throwing exception when sending message to peer without an active connection (#5392) 2024-02-11 09:08:05 -06:00
Chris Stewart
cac546bb57
Fix bug where we were only setting bitcoin-s.node.inactivity-timeout on regtest (#5389)
* Fix bug where we were only setting bitcoin-s.node.inactivity-timeout on regtest

* Remove log, scalafmt
2024-02-08 21:36:15 -06:00
Chris Stewart
451e019225
2024 01 31 Fix PeerManager.connect() bug where PeerFinder was unaware of peer (#5381)
* Fix bug in PeerManager.connect() where we would throw ane xception when our PeerFinder had not seen the peer before

* Remove ReConnectionTest case where we constantly try to reconenct o a peer we disconnected, revert logback-test.xml
2024-01-31 11:10:48 -06:00
Chris Stewart
75881191d1
Guard NeutrinoNode.start() with isStarted flag (#5380) 2024-01-31 09:48:44 -06:00
Chris Stewart
75f6a3b4ec
Refactor PeerFinder.peerConnectionScheduler() into method (#5377) 2024-01-30 14:35:17 -06:00
Chris Stewart
76e468c5c4
2024 01 28 Refactor PeerFinder.start() to avoid initializing connections (#5376)
* Conslidate PeerFinder.start() logic into peerConnectionScheduler, add bitcoins-s.node.try-peers-start-delay config settig to indicate how long until we start attempting to connect to peers in PeerFinder

* Cleanup

* Revert logback-test.xml

* Add documentation

* Empty commit to run CI

* Rework NodeAppConfig.peers to return Vector[Peer] rather than Vector[String]

* Add higher priority to paramPeers
2024-01-29 09:46:31 -06:00
Chris Stewart
9cd60d5366
2024 01 02 encapsulate state p2psink (#5342)
* Move NodeState back to node module

* Refactor peerWithServicesDataMap into NodeState

* More usage of state.peerDataMap in stream

* Fix log message

* Fix compile

* Move PeerFinder into NodeState

* WIP: Move PeerFinder init into NeutrinoNode.start()

* Get things mostly working again after rebase

* Fix bug in handling of headers message where we wouldn't transition to DoneSyncing if a peer sent us 0 headers

* Move SendToPeer into stream

* scalafmt

* Empty commit to run CI

* Re-add DataMessageHandlerTest

* Renable disconnecting portion of NeutrinoNodeTest

* Empty commit to run CI

* Remove disconnection part of test again

* Empty commit to re-run CI

* Empty commit to re-run CI
2024-01-13 17:22:01 -06:00
Chris Stewart
56b1a557a8
Add carve out to ignore ConnectPeer request if state is NodeShuttingDown (#5352) 2024-01-13 14:40:12 -06:00
Chris Stewart
3c5bace825
Dont initiate disconnect logic from bitcoind, its flakey for some reason (#5343)
* Dont initiate disconnect logic from bitcoind, its falky for some reason

* Fix bug where we weren't switching sync to another peer on disconnect for the case where we were waiting for disconnection

* Empty commit to run CI

* Empty commit to run CI
2024-01-05 11:52:39 -06:00
Chris Stewart
d6c1491ba8
2024 01 03 shuttingdown nodestate (#5341)
* Add NodeShuttingDown

* Add NodeShutdown to NodeStreamMessage, use it in PeerManager.stop()

* Add guard to NeutrinoNode.stop() to see if stop() was called when the isStarted flag is set, if we aren't started don't attempt to destroy the akka stream
2024-01-04 14:05:31 -06:00
Chris Stewart
30876c2cde
Move PeerManager.connectPeer() logic into stream (#5340)
* Move PeerManager.connectPeer() logic into stream

* Fix comment
2024-01-03 10:27:35 -06:00
Chris Stewart
d27dcb38f4
Add logging to PeerConnection.handleStreamComplete so exceptions aren't dropping on the floor (#5339) 2024-01-02 13:14:21 -06:00
Chris Stewart
b39736fb8d
Rework NodeTestUtil to use a specific bestBlockHash (#5332)
* Rework NodeTestUtil to use a specific bestBlockHash, this is useful in reorg situations

Use param in reorg test, modify scaladoc

WIP

* Cleanup

* Try to fix usage of stopHashBE

* Cleanup

* WIP: Fix getCompactFilterStartHeight()

* Revert logback-test.xml

* Fix bug with isFiltersSynced() in reorg situations

* scalafmt, fix compile

* Fix another bug with isFiltersSynced()

* Fix compile
2023-12-31 17:38:12 -06:00
Chris Stewart
5e81ec5ed2
Add ChainApi.getBestChainTips() (#5338)
* Add ChainApi.getBestChainTips()

* Implement BitcoindRpcClient.getBestChainTips()

* Revert NodeTestUtil

* Use ChainApi.getBestChainTips() throughout codebase rather than blockHeaderDAO.getBestChainTips()
2023-12-31 16:54:40 -06:00
Chris Stewart
a3e1267484
2023 12 30 isfiltersync bug (#5337)
* Fix another bug with isFiltersSynced()

* Fix compile

* Cleanup uncessary checks

* Empty commit to re-run CI

* Empty commit to re-run CI

* Empty commit to re-run CI
2023-12-31 14:06:21 -06:00
Chris Stewart
06dfd9cea4
Rework randomPeerWithServices() to be inside of NodeState (#5331)
* Rework randomPeerWithServices() to be inside of NodeState, try to move more state into NodeState

* Don't try to sync from peer waitingForDisconnection

* Add PeerWithServices, keep track of ServiceIdentifier in PeerManager and NodeState

* Try to make reorg test more reliable

* Empty commit to run CI
2023-12-29 14:47:29 -06:00