5

I read a lot that transactions that pay the higher gas price can get their transactions through quicker. I would like to know how I could amend my miner code to select transactions with small fees.

  • 1
    Which client are you running? Geth, or something else? – Richard Horrocks Dec 19 '17 at 12:27
  • 1
    I am using geth – Lismore Dec 19 '17 at 12:28
4

Have a look in commitNewWork() in worker.go.

In there you have various approaches for how to order transactions within a block.

You'll want to look at the call to SortByPriceAndNonce(), the definition of which is in transaction.go.

I think you'll basically want to invert the part that sorts by price, giving lower-priced transactions higher priority. (Or however you actually want to prioritise things... )

However, there's some complexity in the algorithm because of how the nonces need to be handled, so you'll have to be careful. (I haven't read the algorithm in full.) From the comment in the code:

// SortByPriceAndNonce sorts the transactions by price in such a way that the
// nonce orderings within a single account are maintained.
//
// Note, this is not as trivial as it seems from the first look as there are three
// different criteria that need to be taken into account (price, nonce, account
// match), which cannot be done with any plain sorting method, as certain items
// cannot be compared without context.
| improve this answer | |
  • 1
    Thanks Richard, that's more than enough to continue my research. – Lismore Dec 19 '17 at 12:39
  • 1
    No problem - enjoy :-) – Richard Horrocks Dec 19 '17 at 12:40
  • @Lismore Did you discover how to do this? – nu everest Feb 8 '18 at 15:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.