This repository has been archived by the owner on Jan 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from itzmeanjan/develop
Limiting Pending/ Queued Pool Size
- Loading branch information
Showing
13 changed files
with
748 additions
and
444 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package data | ||
|
||
// TxsFromAddressAsc - List of txs, sent from same address | ||
// sorted by their nonce | ||
type TxsFromAddressAsc []*MemPoolTx | ||
|
||
// len - Number of tx(s) living in pool, from this address | ||
func (t TxsFromAddressAsc) len() int { | ||
return len(t) | ||
} | ||
|
||
// cap - How many txs can be kept in slice, without further allocation | ||
func (t TxsFromAddressAsc) cap() int { | ||
return cap(t) | ||
} | ||
|
||
// get - Return all txs living in pool, sent from specific address | ||
func (t TxsFromAddressAsc) get() []*MemPoolTx { | ||
return t | ||
} | ||
|
||
// findInsertionPoint - When attempting to insert new tx into this slice, | ||
// find index where to insert, so that it stays sorted ( ascending ), as per | ||
// nonce field of tx | ||
func (t TxsFromAddressAsc) findInsertionPoint(low int, high int, tx *MemPoolTx) int { | ||
|
||
if low > high { | ||
return 0 | ||
} | ||
|
||
if low == high { | ||
|
||
if t[low].Nonce > tx.Nonce { | ||
return low | ||
} | ||
|
||
return low + 1 | ||
|
||
} | ||
|
||
mid := (low + high) / 2 | ||
if t[mid].Nonce > tx.Nonce { | ||
|
||
return t.findInsertionPoint(low, mid, tx) | ||
|
||
} | ||
|
||
return t.findInsertionPoint(mid+1, high, tx) | ||
|
||
} | ||
|
||
// findTx - Find index of tx, which is already present in this sorted slice | ||
// of txs, sent from some specific address | ||
func (t TxsFromAddressAsc) findTx(low int, high int, tx *MemPoolTx) int { | ||
|
||
if low > high { | ||
return -1 | ||
} | ||
|
||
if low == high { | ||
|
||
if idx := findTxFromSlice(t[low:], tx); idx != -1 { | ||
return low + idx | ||
} | ||
|
||
return -1 | ||
|
||
} | ||
|
||
mid := (low + high) / 2 | ||
if t[mid].Nonce >= tx.Nonce { | ||
return t.findTx(low, mid, tx) | ||
} | ||
|
||
return t.findTx(mid+1, high, tx) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.