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

Add newPendingTransactions and syncing to RSKj eth_subscribe JSON-RPC Method #1580

Merged
merged 14 commits into from
Sep 23, 2021

Conversation

Vovchyk
Copy link
Contributor

@Vovchyk Vovchyk commented Jul 6, 2021

Description

Implemented new pending transactions and sync transactions. Both behave the same as when geth is attached (subscribe sync start and end are events have replicated functionality with geth attaching to web3 endpoints). 100% code coverage on new files and increased test coverage percentage in co.rsk.rpc.modules.eth.subscribe package (attached master and current branch code coverage report for reference). Followed existing patterns.

Originated from #1530

Motivation and Context

Resolves rsksmart/rsk-gitcoin-hackathon-2021#15 & resolves rsksmart/rsk-gitcoin-hackathon-2021#16

Personally my participation in the hackathon was driven by:

Interested in cryptocurrency.
Want to continue honing skills in open source software.

How Has This Been Tested?

Subscribe Syncing:

  1. Start rskj node that has not synchronized (clear local data if needed) with --testnet
  2. Connect to rskj ws @ ws://localhost:4445/websocket
  3. Make following request:

JSONRPC Request: {"jsonrpc": "2.0", "method":"eth_subscribe","params":["syncing"],"id":1}

  1. Once the node begins syncing you will see syncing started.
  2. Once the node stops syncing you will see synching ended.

Response examples:
Sync started:
{ "jsonrpc": "2.0", "method": "eth_subscription", "params": { "subscription": "0xfb93f2548a59febf37e77974c65439b5", "result": { "syncing": true, "status": { "startingBlock": 0, "currentBlock": 0, "highestBlock": 24255 } } } }
Sync ended:
{ "jsonrpc": "2.0", "method": "eth_subscription", "params": { "subscription": "0xfb93f2548a59febf37e77974c65439b5", "result": { "syncing": false, } }

Below is an example of same behavior being displayed in geth as in new subscribe functionality (Geth is attached to the RSKj node)

  • The top window is RSKj node running in intelliJ
  • The bottom left window is attached geth node and manually calling eth.syncing
  • The bottom right window is a websocket client subscribed to RSKj syncing method

Syncing

Subscribe new pending transactions

  1. Start rskj node with --regtest
  2. Install geth then attach geth with geth attach http://127.0.0.1:4444
  3. Connect to rskj ws @ ws://localhost:4445/websocket
  4. Make the following request: {"jsonrpc": "2.0", "method":"eth_subscribe","params":["newPendingTransactions"],"id":1}
  5. In geth console send a transaction: eth.sendTransaction({from:eth.accounts[1], to:"0xf6e443fd1c869c6a25d18a9866f3a6c7f8dfb703", value: web3.toWei(300000000000, "ether")})
  6. You should see websocket response:
    { "jsonrpc": "2.0", "method": "eth_subscription", "params": { "subscription": "0x9eec892ee10d588f63a3298dc28ca9ca", "result": "0xe8959f138720de78ef14c5688176c89dd8096546ca04bda698e3ee84e7ff67b1" } }

Below is an example of sending a transaction using attached geth

  • The top window is RSKj node running in intelliJ
  • The bottom left window is attached geth node which will send the transaction
  • The bottom right window is a websocket client subscribed to RSKj newPendingTransactions method

NewPendingTx

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist:

  • My code follows the code style of this project.
  • [] My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • Tests for the changes have been added (for bug fixes / features)
  • Requires Activation Code (Hard Fork)
  • Other information:

@Vovchyk Vovchyk changed the title New pnd tx n syncing Add newPendingTransactions and syncing to RSKj eth_subscribe JSON-RPC Method Jul 6, 2021
@Vovchyk
Copy link
Contributor Author

Vovchyk commented Jul 6, 2021

pipeline: run

@Vovchyk
Copy link
Contributor Author

Vovchyk commented Jul 27, 2021

pipeline: run

2 similar comments
@Vovchyk
Copy link
Contributor Author

Vovchyk commented Jul 27, 2021

pipeline: run

@Vovchyk
Copy link
Contributor Author

Vovchyk commented Jul 27, 2021

pipeline: run

@Vovchyk
Copy link
Contributor Author

Vovchyk commented Sep 3, 2021

pipeline: run

@sonarcloud
Copy link

sonarcloud bot commented Sep 22, 2021

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

99.2% 99.2% Coverage
0.0% 0.0% Duplication

Copy link
Contributor

@nagarev nagarev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Vovchyk Vovchyk merged commit e6e5075 into master Sep 23, 2021
@Vovchyk Vovchyk deleted the new-pnd-tx-n-syncing branch September 23, 2021 08:58
@aeidelman aeidelman added this to the Iris v3.1.0 milestone Oct 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add syncing to RSKj eth_subscribe RPC Method Add newPendingTransactions to RSKj eth_subscribe RPC Method
4 participants