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 txpool namespace support #382

Merged
merged 3 commits into from
Oct 9, 2020

Conversation

ksato9700
Copy link
Contributor

This is a PR for the issue #381. Please review and merge it if you like.

Copy link
Owner

@tomusdrw tomusdrw left a comment

Choose a reason for hiding this comment

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

Looks really good for a start, thanks! I'd like to see a bit more strict typing and some documentation pointers.

#[derive(Debug, Default, Clone, PartialEq, Deserialize, Serialize)]
pub struct TxpoolContentInfo {
/// pending tx
pub pending: HashMap<String, HashMap<String, Transaction>>,
Copy link
Owner

Choose a reason for hiding this comment

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

Perhaps better to use BTreeMap here to have the keys deterministically ordered? With HashMap the results would be a bit random. Also we should be using more strict types than String. I believe it's transaction hash and the nonce, right?

Suggested change
pub pending: HashMap<String, HashMap<String, Transaction>>,
pub pending: BTreeMap<H256, BTreeMap<U256, Transaction>>,

/// pending tx
pub pending: HashMap<String, HashMap<String, Transaction>>,
/// queued tx
pub queued: HashMap<String, HashMap<String, Transaction>>,
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
pub queued: HashMap<String, HashMap<String, Transaction>>,
pub queued: BTreeMap<H256, BTreeMap<U256, Transaction>>,

#[derive(Debug, Default, Clone, PartialEq, Deserialize, Serialize)]
pub struct TxpoolInspectInfo {
/// pending tx
pub pending: HashMap<String, HashMap<String, String>>,
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
pub pending: HashMap<String, HashMap<String, String>>,
pub pending: BTreeMap<H256, BTreeMap<U256, String>>,

/// pending tx
pub pending: HashMap<String, HashMap<String, String>>,
/// queued tx
pub queued: HashMap<String, HashMap<String, String>>,
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
pub queued: HashMap<String, HashMap<String, String>>,
pub queued: BTreeMap<H256, BTreeMap<U256, String>>,

pub queued: HashMap<String, HashMap<String, Transaction>>,
}

/// Transaction Pool Inspect Info
Copy link
Owner

Choose a reason for hiding this comment

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

Can we expand on the docs or at least point to documentation of these structs? I'd be more interested in the String format of the transaction inspection info - i.e. what things can be found there and can we actually parse it?

"pending":"0x23",
"queued":"0x20"
}"#;
let _: TxpoolStatus = serde_json::from_str(txpool_status_str).unwrap();
Copy link
Owner

Choose a reason for hiding this comment

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

Re-serialization test would be cool, after switching to BTreeMap you will get consistent results.

@ksato9700
Copy link
Contributor Author

@tomusdrw Thank you for the review comments. I made changes as follows.

  • use BTreeMap instead of HashMap
  • use Address for the type of outer key
  • add some comments with link to a spec document
  • add re-serialization tests

Note that I keep using String for the inner key type. As you said, it is nonce, but strangely enough, decimal number format is used here instead of hex.

Copy link
Owner

@tomusdrw tomusdrw left a comment

Choose a reason for hiding this comment

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

looks awesome, thanks!

@tomusdrw tomusdrw merged commit 2bcd2db into tomusdrw:master Oct 9, 2020
@ksato9700 ksato9700 deleted the txpool-namespace-support branch October 9, 2020 12:28
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