Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions core/txpool/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,16 @@ type ItxPool interface {
CheckTxn(stxn *SignedTxn) error

Insert(txn *SignedTxn) error
InsertWithTopic(topic string, stxn *SignedTxn) error

SetOrder(order map[int]Hash)
SortTxns(fn func(txns []*SignedTxn) []*SignedTxn)

InsertWithTopic(topic string, stxn *SignedTxn) error
GetWithTopic(topic string, numLimit uint64) []*SignedTxn
GetWithTopicFor(topic string, numLimit uint64, filter func(txn *SignedTxn) bool) []*SignedTxn

// Pack packs some txns to send to tripods
Pack(numLimit uint64) ([]*SignedTxn, error)

PackFor(numLimit uint64, filter func(txn *SignedTxn) bool) ([]*SignedTxn, error)
PackWithTopic(topic string, numLimit uint64) ([]*SignedTxn, error)
PackWithTopicFor(topic string, numLimit uint64, filter func(txn *SignedTxn) bool) ([]*SignedTxn, error)

// GetTxn returns unpacked txn
GetTxn(hash Hash) (*SignedTxn, error)
Expand Down
12 changes: 6 additions & 6 deletions core/txpool/txpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,20 +110,20 @@ func (tp *TxPool) InsertWithTopic(topic string, stxn *SignedTxn) error {
return tp.topicUnpackedTxns[topic].Insert(stxn)
}

func (tp *TxPool) GetWithTopic(topic string, numLimit uint64) []*SignedTxn {
func (tp *TxPool) PackWithTopic(topic string, numLimit uint64) ([]*SignedTxn, error) {
if unpack, ok := tp.topicUnpackedTxns[topic]; ok {
return unpack.Gets(numLimit, tp.filter)
return unpack.Gets(numLimit, tp.filter), nil
}
return nil
return nil, nil
}

func (tp *TxPool) GetWithTopicFor(topic string, numLimit uint64, filter func(txn *SignedTxn) bool) []*SignedTxn {
func (tp *TxPool) PackWithTopicFor(topic string, numLimit uint64, filter func(txn *SignedTxn) bool) ([]*SignedTxn, error) {
tp.topicLock.RLock()
defer tp.topicLock.RUnlock()
if unpack, ok := tp.topicUnpackedTxns[topic]; ok {
return unpack.Gets(numLimit, filter)
return unpack.Gets(numLimit, filter), nil
}
return nil
return nil, nil
}

func (tp *TxPool) SetOrder(order map[int]Hash) {
Expand Down