-
Notifications
You must be signed in to change notification settings - Fork 683
feat: Add remaining txpool methods #3719
base: develop
Are you sure you want to change the base?
Conversation
3843ec2
to
1b76dc4
Compare
Not sure exactly which params should be displayed for txpool_inspect. Rest can be merged. Also, not sure with naming of processMap(). |
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.
First I want to say thank you so much for making this PR! This is great work and is really appreciated.
I have a few small comments, a lot of which is about legacy code that I'd like to get fixed up before merging 😄
Aside from those comments, I think I'd like to see slightly more robust tests. I think the previous test for txpool_content
are a good starting point to work off of.
If you come to a point where this is too much, let us know, we'd be happy to take over. But we really appreciate the work you've done and would love to have you take it over the finish line.
// The nonce keys are actual decimal numbers (as strings) and not | ||
// hex literals (based on what geth returns). | ||
const nonce = transaction.nonce.toBigInt().toString(); | ||
res[from][nonce] = transaction.toJSON() as Ethereum.Pool.Transaction<"private">; |
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 believe we will still need to pass in a Common
to the transaction's toJSON
field. This is used in the legacy transaction type to determine if the user is running Ganache with EIP-2718 activated. If not, transaction types did not yet exist and should not be included on the return object.
@@ -453,6 +455,33 @@ export default class TransactionPool extends Emittery<{ drain: undefined }> { | |||
return null; | |||
} | |||
|
|||
public processMap(map: Map<string, Heap<TypedTransaction>>, address?: Address) { |
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.
We probably should have come up with a better name for this function when we first reviewed it. But especially now that it's being used elsewhere, I think we should rename this. The trouble is deciding on the name! Perhaps groupTransactionsByOriginAndNonce
? @davidmurdoch opinions?
@@ -453,6 +455,33 @@ export default class TransactionPool extends Emittery<{ drain: undefined }> { | |||
return 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.
I think we'll need a js-doc comment here. Could you add something like this? (feel free to refine)
/** | |
* Iterates over all transactions in each Heap for each key in the map. | |
* Returns the transactions grouped by origin and nonce in the format: `{ | |
* origin1: { nonceA: ...txData, ... }, ...}` | |
* | |
* If `address` is specified, filters the result to only show transactions | |
* from `address` | |
* @param map | |
* @param address | |
* @returns Transactions grouped by origin and nonce. | |
*/ |
for (let i = 0; i < length; ++i) { | ||
const transaction = array[i]; | ||
|
||
if(address && transaction.from.toString() != address.toString()) { |
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.
We're getting transaction.from.toString()
twice, could we store this as a variable?
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.
Could we also store address.toString()
outside of the loop so it's only computed once?
@@ -120,4 +120,110 @@ describe("txpool", () => { | |||
assert.deepStrictEqual(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.
For some reason github isn't formatting this file as typescript. I wonder what's going on with that 🤔
} | ||
|
||
/** | ||
* Returns the number of transactions currently pending for inclusion in the next block(s), as well as the ones that are being scheduled for future execution only. |
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.
* Returns the number of transactions currently pending for inclusion in the next block(s), as well as the ones that are being scheduled for future execution only. | |
* Returns the number of transactions currently pending inclusion in the next blocks, as well as the ones that are scheduled for future execution. |
* Returns the number of transactions created by specified address currently pending for inclusion in the next block(s), as well as the ones that are being scheduled for future execution only. | ||
* | ||
* @param address - The account address | ||
* @returns The transactions currently pending or queued in the transaction pool by address. |
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.
* @returns The transactions currently pending or queued in the transaction pool by address. | |
* @returns The transactions from the specified address that are currently pending or queued in the transaction pool. |
* @param address - The account address | ||
* @returns The transactions currently pending or queued in the transaction pool by address. | ||
* @example | ||
* ```javascript |
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.
For some reason these examples aren't working in the generated docs - but the txpool_content
example isn't working either. I can look into this!
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 found it!
We'll need to add this to the top of all three txpool examples to keep the transactions from being mined so they actually stay in the pool:
await provider.send("miner_stop")
Also, for the txpool_contentFrom
example can we send another transaction from a different address to showcase the fact that it filters by address?
Co-authored-by: Micaiah Reid <[email protected]>
Hello team. Apologies for leaving this PR un-resolved. Is it still needed? If yes, I can complete it. Thanks in advance. |
Resolves #763
Breaking down problem to these sub-tasks:
processMap