-
Couldn't load subscription status.
- Fork 70
RPC: add the ping RPC
#509
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
0faec39
node_interface: add a ping request
Davidson-Souza fc95289
ping: add the server side implementation
Davidson-Souza 5f4f4f0
ping: add it to floresta-cli
Davidson-Souza 78043e7
add ping to the docs
Davidson-Souza 635a886
add a simple functional test for ping
Davidson-Souza File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,3 +4,4 @@ pub mod server; | |
| // endpoint impls | ||
| mod blockchain; | ||
| mod control; | ||
| mod network; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| //! This module holds all RPC server side methods for interacting with our node's network stack. | ||
|
|
||
| use super::res::Error as RpcError; | ||
| use super::server::RpcChain; | ||
| use super::server::RpcImpl; | ||
|
|
||
| impl<Blockchain: RpcChain> RpcImpl<Blockchain> { | ||
| pub(crate) async fn ping(&self) -> Result<bool, RpcError> { | ||
| self.node | ||
| .ping() | ||
| .await | ||
| .map_err(|e| RpcError::Node(e.to_string())) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| """ | ||
| A test that creates a florestad and a bitcoind node, and connects them. We then | ||
| send a ping to bitcoind and check if bitcoind receives it, by calling | ||
| `getpeerinfo` and checking that we've received a ping from floresta. | ||
| """ | ||
|
|
||
| from test_framework import FlorestaRPC, BitcoinRPC, FlorestaTestFramework | ||
| from test_framework.rpc.floresta import REGTEST_RPC_SERVER as florestad_rpc | ||
| from test_framework.rpc.bitcoin import REGTEST_RPC_SERVER as bitcoind_rpc | ||
|
|
||
|
|
||
| class PingTest(FlorestaTestFramework): | ||
| index = [-1, -1] | ||
| expected_chain = "regtest" | ||
|
|
||
| def set_test_params(self): | ||
| PingTest.index[0] = self.add_node(variant="florestad", rpcserver=florestad_rpc) | ||
| PingTest.index[1] = self.add_node(variant="bitcoind", rpcserver=bitcoind_rpc) | ||
Davidson-Souza marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| def run_test(self): | ||
| # Start the nodes | ||
| self.run_node(PingTest.index[0]) | ||
| self.run_node(PingTest.index[1]) | ||
|
|
||
| bitcoind: BitcoinRPC = self.get_node(PingTest.index[1]).rpc | ||
| florestad: FlorestaRPC = self.get_node(PingTest.index[0]).rpc | ||
|
|
||
| # Connect floresta to bitcoind | ||
| florestad.addnode( | ||
| f"{bitcoind_rpc['host']}:{bitcoind_rpc['ports']['p2p']}", "onetry" | ||
| ) | ||
|
|
||
| # Check that we have a connection, but no ping yet | ||
| peer_info = bitcoind.get_peerinfo() | ||
| self.assertTrue( | ||
| "ping" not in peer_info[0]["bytesrecv_per_msg"], | ||
| ) | ||
|
|
||
| # Send a ping to bitcoind | ||
| self.log("Sending ping to bitcoind...") | ||
| florestad.ping() | ||
|
|
||
| # Check that bitcoind received the ping | ||
| peer_info = bitcoind.get_peerinfo() | ||
| self.assertTrue(peer_info[0]["bytesrecv_per_msg"]["ping"]) | ||
|
|
||
| self.stop() | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| PingTest().main() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.