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

Starting structure and interface definition for txpool module #471

Merged
merged 2 commits into from
Feb 19, 2018

Conversation

lsebrie
Copy link
Contributor

@lsebrie lsebrie commented Feb 9, 2018

No description provided.

@@ -259,6 +262,11 @@ public PersonalModule getPersonalModuleWallet(RskSystemProperties config, Rsk rs
return new PersonalModuleWalletEnabled(config, rsk, wallet, pendingState);
}

@Bean
public TxPoolModule getTxPoolModule(RskSystemProperties config, Rsk rsk, PendingState pendingState) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't inject config. Also consider using an @Component annotation when a @Bean is not necessary.


public class TxPoolModuleImpl implements TxPoolModule{

private Ethereum eth;
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe you can also be the first one to apply the Check not null preconditions styleguide!


@Override
public String content() {
// return "{"pending": {}, queued: {}}";
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe it would be better to add a JavaDoc explaining the return values, instead of this comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

@@ -169,11 +171,12 @@ public void increaseTimeTwice() {
private static Web3Impl createWeb3(World world, SimpleEthereum ethereum, MinerServer minerServer) {
MinerClientImpl minerClient = new MinerClientImpl(null, minerServer, config);
PersonalModule pm = new PersonalModuleWalletDisabled();
TxPoolModule txm = new TxPoolModuleImpl(null, null);
Copy link
Contributor

Choose a reason for hiding this comment

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

tpm?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

Web3Impl web3 = createWeb3(world);
String result = web3.txpool_content();
ObjectMapper om = new ObjectMapper();
JsonNode node = om.reader().forType(JsonNode.class).readValue(result);
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe this won't scale with harder tests, but how about asserting the exact JSON string?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These tests weren't pretending to test real values, just a basic syntactic structure.

import java.util.HashMap;
import java.util.Map;

public class TxPoolModuleImpl implements TxPoolModule{
Copy link
Contributor

Choose a reason for hiding this comment

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

There is a missing space before {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

@@ -198,6 +198,10 @@ public String toString() {
boolean personal_lockAccount(String key);
String personal_dumpRawKey(String address) throws Exception;

String txpool_content();
Copy link
Contributor

@diega diega Feb 9, 2018

Choose a reason for hiding this comment

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

Maybe we can have something like this

public interface TxPoolWeb3Module {

    default String txpool_content() {
        return getTxPoolModule().content();
    }

    default String txpool_inspect() {
        return getTxPoolModule().inspect();
    }

    default String txpool_status() {
        return getTxPoolModule().inspect();
    }

    TxPoolModule getTxPoolModule();
}

and make org.ethereum.rpc.Web3Impl to implement it. Then this class should only implement the getTxPoolModule() returning the injected TxPoolModuleImpl field and we let the actual forwarding to happen inside the default methods of the interface

Copy link
Contributor

Choose a reason for hiding this comment

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

Interesting, but it makes me wonder whether that will work with jsonrpc4j mapping.
At the same time, this looks like a hack for our contrived architecture, but i'm not against it :)

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, the getModule name would clash with others later on. How about:

public interface Web3 {

    default String txpool_content() {
        return getTxPoolModule().content();
    }

    default String txpool_inspect() {
        return getTxPoolModule().inspect();
    }

    default String txpool_status() {
        return getTxPoolModule().inspect();
    }

    TxPoolModule getTxPoolModule();

    public interface TxPoolModule {

        String content();

        String inspect();

        String status();
    }
}

My concern is that if we followed this pattern for all our modules, the Web3Impl class would do nothing. What would be the responsibility of this class?:

public class Web3Impl implements Web3 {
    public Web3Impl(Module1 m1, Module2 m2, ...) {
        this.m1 = m1;
        this.m2 = m2;
        ...
    }

    public Module1 M1 getModule1() {
        return this.m1;
    }

    public Module2 M2 getModule2() {
        return this.m2;
    }
    ...
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, I edited the getModule method right after sending it :)
I think jsonrpc4j should still work b/c it uses reflection to resolve the method of Web3Impl to execute, but of course that will be the first test to run.
The only responsibility of this class will be to be useful in the context of jsonrpc4j, just that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I like the idea about an interface with a default implementation that web3 require for modules. I don't think it's a good idea to tie both interfaces. I will add default implementation for txpool module. We can in other PR introduce them for others modules

@lsebrie lsebrie force-pushed the web3_txpool branch 2 times, most recently from 12df226 to 800adb8 Compare February 14, 2018 15:39
@rskops
Copy link
Collaborator

rskops commented Feb 14, 2018

SonarQube analysis reported 273 issues

  • BLOCKER 1 blocker
  • MAJOR 162 major
  • MINOR 93 minor
  • INFO 17 info

Top 10 issues

  1. BLOCKER Web3Impl.java#L508: "blockchain" is a method parameter, and should not be used for synchronization. rule
  2. MAJOR RskFactory.java#L115: This block of commented-out lines of code should be removed. rule
  3. MAJOR RskFactory.java#L141: Method has 18 parameters, which is greater than 7 authorized. rule
  4. MAJOR Web3RskImpl.java#L62: Constructor has 18 parameters, which is greater than 7 authorized. rule
  5. MAJOR Web3RskImpl.java#L136: Change this "try" to a try-with-resources. (sonar.java.source not set. Assuming 7 or greater.) rule
  6. MAJOR Web3RskImpl.java#L155: Refactor this code to not nest more than 3 if/for/while/switch/try statements. rule
  7. MAJOR Web3RskImpl.java#L166: Either log or rethrow this exception. rule
  8. MAJOR Web3RskImpl.java#L166: Either remove or fill this block of code. rule
  9. MAJOR Web3.java#L32: Make startingBlock a static final constant or non-public and provide accessors if needed. rule
  10. MAJOR Web3.java#L33: Make currentBlock a static final constant or non-public and provide accessors if needed. rule

@aeidelman aeidelman merged commit 37b4176 into master Feb 19, 2018
@aeidelman aeidelman deleted the web3_txpool branch February 19, 2018 14:51
@aeidelman aeidelman added this to the Bamboo v0.4.1 milestone Mar 18, 2018
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.

6 participants