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 RPC Method #1516

Open
wants to merge 21 commits into
base: master
Choose a base branch
from

Conversation

elmol
Copy link
Contributor

@elmol elmol commented May 1, 2021

Add NewPendingTransactions To RSKj Eth_subscribe RPC Method

According to   rsk-gitcoin-hackathon-2021 - Add NewPendingTransactions To RSKj Eth_subscribe RPC Method , I worked on newPendingTransactions subscription event

Code Coverage

Attached coverage.zip you can find all the code coverage reports.

You can find the main change in coverage/ns-33/sources/source-e.html in the attached coverage reports.

Demonstration

Here you can see a demonstration about a new pending transactions notification.
demostration

new transaction created
tx-done

rskj-node initialization
rskj-node-init

The following code was used for the demo.


const urlRSK = "ws://localhost:4445/websocket";

// Using web3js
const web3 = new Web3(urlRSK);

web3.eth.getBlockNumber().then((result) => {
  console.log("Latest Ethereum Block is ", result);
});

console.log("newPendingTxs...");

var subscription = web3.eth
  .subscribe("pendingTransactions", function (error, result) {
    if (!error) {
      console.log(result);
    } 
});

setTimeout(() => {
  console.log("unsubscribe");
  // unsubscribes the subscription
  subscription.unsubscribe(function (error, success) {
    if (success) console.log("Successfully unsubscribed!");
  });
}, 60000);


setTimeout(() => {
  console.log("GoodBye!");
  process.exit();
}, 61000); 

elmol added 14 commits May 1, 2021 00:33
…d message on pending transaction received based on json serializer
…for each pending transaction received missing tests added and unsuscription form subscription implementation
…ngTransactions emitter to EthSubscriptionNotificationEmitter
…PendingTransactions added to EthSubscriptionNotificationEmitter
…ngTransactions as subscriptionTypes in EthSubscribeParamsDeserializer
@elmol elmol changed the title Add NewPendingTransactions To RSKj Eth_subscribe RPC Method Add newPendingTransactions and syncing To RSKj Eth_subscribe RPC Method May 2, 2021
@elmol
Copy link
Contributor Author

elmol commented May 2, 2021

Add Syncing To RSKj Eth_subscribe RPC Method

This pull request was updated with the rsksmart/rsk-gitcoin-hackathon-2021#16 implementation .

@Vovchyk
Copy link
Contributor

Vovchyk commented Jun 1, 2021

pipeline: run

2 similar comments
@Vovchyk
Copy link
Contributor

Vovchyk commented Jun 1, 2021

pipeline: run

@Vovchyk
Copy link
Contributor

Vovchyk commented Jun 1, 2021

pipeline: run

Copy link
Contributor

@Vovchyk Vovchyk left a comment

Choose a reason for hiding this comment

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

@elmol thanks for your submission. Good work. There are a few comments. Please check.


private void emit(SubscriptionId id, Channel channel, boolean isStarted, Map<String, String> status) {

SyncingNotification syncStatus = new SyncingNotification(isStarted,status);
Copy link
Contributor

Choose a reason for hiding this comment

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

according to the docs, result could either be false or an object with sync statistics. Could you please return false, if syncing is not active? Please refer to the examples of responses below:

< {"jsonrpc":"2.0","method":"eth_subscription","params":{"subscription":"0x8a70b5d09d8284c507b1cd1340330f73","result":false}}

< {"jsonrpc":"2.0","method":"eth_subscription","params":{"subscription":"0x8a70b5d09d8284c507b1cd1340330f73","result":{"syncing": true, "status": { "startingBlock": 0, "currentBlock": 0, "highestBlock": 24255}}}

pay attention that in the first example result is false, not {"syncing":false}

as reference, you can also check what the eth_syncing method does

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks Vovchyk, I've fixed.

@@ -116,6 +118,8 @@ public void start() {
}, WORKER_TIMEOUT, WORKER_TIMEOUT, TimeUnit.SECONDS
);

emmitStartEvent();
Copy link
Contributor

Choose a reason for hiding this comment

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

not sure this is a good place to emit start / stop events for the case of syncing. This SyncPool service is being started even if a node is already fully synced. I guess we should mimic the behaviour of the eth_syncing method

I believe a good candidate where this can be done is the SyncProcessor class. E.g. emitting start event in the startDownloadingBodies and stop - in stopSyncing. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, totally agreed! I've moved from the events from SyncPool to SyncProcessor.

@Vovchyk
Copy link
Contributor

Vovchyk commented Jun 7, 2021

pipeline: run

1 similar comment
@Vovchyk
Copy link
Contributor

Vovchyk commented Jun 7, 2021

pipeline: run

Copy link
Contributor

@Vovchyk Vovchyk left a comment

Choose a reason for hiding this comment

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

thanks @elmol for your corrections. Just posted a few minor comments. In general, LGTM

elmol and others added 2 commits June 8, 2021 11:41
…ngNotification.java

Co-authored-by: Vovchyk <volodymyr.kravets@outlook.com>
…ngNotification.java

Co-authored-by: Vovchyk <volodymyr.kravets@outlook.com>
elmol and others added 2 commits June 8, 2021 11:42
…ngNotificationEmitter.java

Co-authored-by: Vovchyk <volodymyr.kravets@outlook.com>
…ngNotificationEmitter.java

Co-authored-by: Vovchyk <volodymyr.kravets@outlook.com>
@elmol
Copy link
Contributor Author

elmol commented Jun 8, 2021

Thank you very much @Vovchyk for your comments and corrections.

@Vovchyk
Copy link
Contributor

Vovchyk commented Jun 9, 2021

pipeline: run

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.

2 participants