diff options
author | Jeffrey Wilcke <geffobscura@gmail.com> | 2015-08-04 03:57:09 +0800 |
---|---|---|
committer | Jeffrey Wilcke <geffobscura@gmail.com> | 2015-08-05 23:44:19 +0800 |
commit | 35f271b264b8e4a0449eff325fb75a78299cf9a6 (patch) | |
tree | 750fe404c14b6f5e8ef03a07cf3357787c6c9683 /core | |
parent | f12e0161ca7ed2bc5034a7b4904e1b5032e41fe7 (diff) | |
download | go-tangerine-35f271b264b8e4a0449eff325fb75a78299cf9a6.tar go-tangerine-35f271b264b8e4a0449eff325fb75a78299cf9a6.tar.gz go-tangerine-35f271b264b8e4a0449eff325fb75a78299cf9a6.tar.bz2 go-tangerine-35f271b264b8e4a0449eff325fb75a78299cf9a6.tar.lz go-tangerine-35f271b264b8e4a0449eff325fb75a78299cf9a6.tar.xz go-tangerine-35f271b264b8e4a0449eff325fb75a78299cf9a6.tar.zst go-tangerine-35f271b264b8e4a0449eff325fb75a78299cf9a6.zip |
miner, core: sort txs by price, nonce
Diffstat (limited to 'core')
-rw-r--r-- | core/types/transaction.go | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/core/types/transaction.go b/core/types/transaction.go index 85b4c6119..28a7e02b3 100644 --- a/core/types/transaction.go +++ b/core/types/transaction.go @@ -289,3 +289,22 @@ type TxByNonce struct{ Transactions } func (s TxByNonce) Less(i, j int) bool { return s.Transactions[i].data.AccountNonce < s.Transactions[j].data.AccountNonce } + +type TxByPrice struct{ Transactions } + +func (s TxByPrice) Less(i, j int) bool { + return s.Transactions[i].data.Price.Cmp(s.Transactions[j].data.Price) > 0 +} + +type TxByPriceAndNonce struct{ Transactions } + +func (s TxByPriceAndNonce) Less(i, j int) bool { + // we can ignore the error here. Sorting shouldn't care about validness + ifrom, _ := s.Transactions[i].From() + jfrom, _ := s.Transactions[j].From() + // favour nonce if they are from the same recipient + if ifrom == jfrom { + return s.Transactions[i].data.AccountNonce < s.Transactions[j].data.AccountNonce + } + return s.Transactions[i].data.Price.Cmp(s.Transactions[j].data.Price) > 0 +} |