-
Notifications
You must be signed in to change notification settings - Fork 266
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
Conversation
@@ -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) { |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer private final fields for dependencies
: https://github.com/rsksmart/rskj/blob/contributing/CONTRIBUTING.md#java-styleguide
There was a problem hiding this comment.
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: {}}"; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tpm?
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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{ |
There was a problem hiding this comment.
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 {
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 :)
There was a problem hiding this comment.
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;
}
...
}
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
12df226
to
800adb8
Compare
SonarQube analysis reported 273 issues Top 10 issues
|
No description provided.