Skip to content

Commit 42abafc

Browse files
Rename "AccountStateProvider" to "SelectionSession".
1 parent 65f6207 commit 42abafc

10 files changed

+117
-96
lines changed

testscommon/txcachemocks/accountStateProviderMock.go testscommon/txcachemocks/selectionSessionMock.go

+10-10
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,24 @@ import (
88
"github.com/multiversx/mx-chain-storage-go/types"
99
)
1010

11-
// AccountStateProviderMock -
12-
type AccountStateProviderMock struct {
11+
// SelectionSessionMock -
12+
type SelectionSessionMock struct {
1313
mutex sync.Mutex
1414

1515
AccountStateByAddress map[string]*types.AccountState
1616
GetAccountStateCalled func(address []byte) (*types.AccountState, error)
1717
IsBadlyGuardedCalled func(tx data.TransactionHandler) bool
1818
}
1919

20-
// NewAccountStateProviderMock -
21-
func NewAccountStateProviderMock() *AccountStateProviderMock {
22-
return &AccountStateProviderMock{
20+
// NewSelectionSessionMock -
21+
func NewSelectionSessionMock() *SelectionSessionMock {
22+
return &SelectionSessionMock{
2323
AccountStateByAddress: make(map[string]*types.AccountState),
2424
}
2525
}
2626

2727
// SetNonce -
28-
func (mock *AccountStateProviderMock) SetNonce(address []byte, nonce uint64) {
28+
func (mock *SelectionSessionMock) SetNonce(address []byte, nonce uint64) {
2929
mock.mutex.Lock()
3030
defer mock.mutex.Unlock()
3131

@@ -39,7 +39,7 @@ func (mock *AccountStateProviderMock) SetNonce(address []byte, nonce uint64) {
3939
}
4040

4141
// SetBalance -
42-
func (mock *AccountStateProviderMock) SetBalance(address []byte, balance *big.Int) {
42+
func (mock *SelectionSessionMock) SetBalance(address []byte, balance *big.Int) {
4343
mock.mutex.Lock()
4444
defer mock.mutex.Unlock()
4545

@@ -53,7 +53,7 @@ func (mock *AccountStateProviderMock) SetBalance(address []byte, balance *big.In
5353
}
5454

5555
// GetAccountState -
56-
func (mock *AccountStateProviderMock) GetAccountState(address []byte) (*types.AccountState, error) {
56+
func (mock *SelectionSessionMock) GetAccountState(address []byte) (*types.AccountState, error) {
5757
mock.mutex.Lock()
5858
defer mock.mutex.Unlock()
5959

@@ -70,7 +70,7 @@ func (mock *AccountStateProviderMock) GetAccountState(address []byte) (*types.Ac
7070
}
7171

7272
// IsBadlyGuarded -
73-
func (mock *AccountStateProviderMock) IsBadlyGuarded(tx data.TransactionHandler) bool {
73+
func (mock *SelectionSessionMock) IsBadlyGuarded(tx data.TransactionHandler) bool {
7474
if mock.IsBadlyGuardedCalled != nil {
7575
return mock.IsBadlyGuardedCalled(tx)
7676
}
@@ -79,7 +79,7 @@ func (mock *AccountStateProviderMock) IsBadlyGuarded(tx data.TransactionHandler)
7979
}
8080

8181
// IsInterfaceNil -
82-
func (mock *AccountStateProviderMock) IsInterfaceNil() bool {
82+
func (mock *SelectionSessionMock) IsInterfaceNil() bool {
8383
return mock == nil
8484
}
8585

txcache/errors.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ package txcache
33
import "errors"
44

55
var errNilTxGasHandler = errors.New("nil tx gas handler")
6-
var errNilAccountStateProvider = errors.New("nil account state provider")
6+
var errNilSelectionSession = errors.New("nil selection session")
77
var errItemAlreadyInCache = errors.New("item already in cache")
88
var errEmptyBunchOfTransactions = errors.New("empty bunch of transactions")

txcache/interface.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ type TxGasHandler interface {
1313
IsInterfaceNil() bool
1414
}
1515

16-
// AccountStateProvider defines the behavior of a component able to provide the state of an account
17-
type AccountStateProvider interface {
16+
// SelectionSession provides blockchain information for transaction selection
17+
type SelectionSession interface {
1818
GetAccountState(accountKey []byte) (*types.AccountState, error)
1919
IsBadlyGuarded(tx data.TransactionHandler) bool
2020
IsInterfaceNil() bool

txcache/selection.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,19 @@ import (
55
"time"
66
)
77

8-
func (cache *TxCache) doSelectTransactions(accountStateProvider AccountStateProvider, gasRequested uint64, maxNum int, selectionLoopMaximumDuration time.Duration) (bunchOfTransactions, uint64) {
8+
func (cache *TxCache) doSelectTransactions(session SelectionSession, gasRequested uint64, maxNum int, selectionLoopMaximumDuration time.Duration) (bunchOfTransactions, uint64) {
99
senders := cache.getSenders()
1010
bunches := make([]bunchOfTransactions, 0, len(senders))
1111

1212
for _, sender := range senders {
1313
bunches = append(bunches, sender.getTxs())
1414
}
1515

16-
return selectTransactionsFromBunches(accountStateProvider, bunches, gasRequested, maxNum, selectionLoopMaximumDuration)
16+
return selectTransactionsFromBunches(session, bunches, gasRequested, maxNum, selectionLoopMaximumDuration)
1717
}
1818

1919
// Selection tolerates concurrent transaction additions / removals.
20-
func selectTransactionsFromBunches(accountStateProvider AccountStateProvider, bunches []bunchOfTransactions, gasRequested uint64, maxNum int, selectionLoopMaximumDuration time.Duration) (bunchOfTransactions, uint64) {
20+
func selectTransactionsFromBunches(session SelectionSession, bunches []bunchOfTransactions, gasRequested uint64, maxNum int, selectionLoopMaximumDuration time.Duration) (bunchOfTransactions, uint64) {
2121
selectedTransactions := make(bunchOfTransactions, 0, initialCapacityOfSelectionSlice)
2222

2323
// Items popped from the heap are added to "selectedTransactions".
@@ -57,7 +57,7 @@ func selectTransactionsFromBunches(accountStateProvider AccountStateProvider, bu
5757
}
5858
}
5959

60-
err := item.requestAccountStateIfNecessary(accountStateProvider)
60+
err := item.requestAccountStateIfNecessary(session)
6161
if err != nil {
6262
// Skip this sender.
6363
logSelect.Debug("TxCache.selectTransactionsFromBunches, could not retrieve account state", "sender", item.sender, "err", err)
@@ -71,7 +71,7 @@ func selectTransactionsFromBunches(accountStateProvider AccountStateProvider, bu
7171
continue
7272
}
7373

74-
shouldSkipTransaction := detectSkippableTransaction(accountStateProvider, item)
74+
shouldSkipTransaction := detectSkippableTransaction(session, item)
7575
if shouldSkipTransaction {
7676
// Transaction isn't selected, but the sender is still in the game (will contribute with other transactions).
7777
} else {
@@ -104,11 +104,11 @@ func detectSkippableSender(item *transactionsHeapItem) bool {
104104
return false
105105
}
106106

107-
func detectSkippableTransaction(accountStateProvider AccountStateProvider, item *transactionsHeapItem) bool {
107+
func detectSkippableTransaction(session SelectionSession, item *transactionsHeapItem) bool {
108108
if item.detectLowerNonce() {
109109
return true
110110
}
111-
if item.detectBadlyGuarded(accountStateProvider) {
111+
if item.detectBadlyGuarded(session) {
112112
return true
113113
}
114114
if item.detectNonceDuplicate() {

0 commit comments

Comments
 (0)