diff --git a/testscommon/txcachemocks/selectionSessionMock.go b/testscommon/txcachemocks/selectionSessionMock.go index 32f852a8..db789b51 100644 --- a/testscommon/txcachemocks/selectionSessionMock.go +++ b/testscommon/txcachemocks/selectionSessionMock.go @@ -12,9 +12,9 @@ import ( type SelectionSessionMock struct { mutex sync.Mutex - AccountStateByAddress map[string]*types.AccountState - GetAccountStateCalled func(address []byte) (*types.AccountState, error) - IsBadlyGuardedCalled func(tx data.TransactionHandler) bool + AccountStateByAddress map[string]*types.AccountState + GetAccountStateCalled func(address []byte) (*types.AccountState, error) + IsIncorrectlyGuardedCalled func(tx data.TransactionHandler) bool } // NewSelectionSessionMock - @@ -69,10 +69,10 @@ func (mock *SelectionSessionMock) GetAccountState(address []byte) (*types.Accoun return newDefaultAccountState(), nil } -// IsBadlyGuarded - -func (mock *SelectionSessionMock) IsBadlyGuarded(tx data.TransactionHandler) bool { - if mock.IsBadlyGuardedCalled != nil { - return mock.IsBadlyGuardedCalled(tx) +// IsIncorrectlyGuarded - +func (mock *SelectionSessionMock) IsIncorrectlyGuarded(tx data.TransactionHandler) bool { + if mock.IsIncorrectlyGuardedCalled != nil { + return mock.IsIncorrectlyGuardedCalled(tx) } return false diff --git a/txcache/README.md b/txcache/README.md index 55d11f88..ee8996c6 100644 --- a/txcache/README.md +++ b/txcache/README.md @@ -185,7 +185,7 @@ Thus, the mempool selects transactions using an efficient and value-driven algor - If a middle nonce gap is detected, the sender is skipped (from now on) in the current selection session. - Transactions with nonces lower than the current nonce of the sender are skipped. - Transactions having the same nonce as a previously selected one (in the scope of a sender) are skipped. Also see paragraph 5. - - Badly guarded transactions are skipped. + - Incorrectly guarded transactions are skipped. - Once the accumulated fees of selected transactions of a given sender exceed the sender's balance, the sender is skipped (from now one). diff --git a/txcache/interface.go b/txcache/interface.go index 6b8b97e0..a77871fa 100644 --- a/txcache/interface.go +++ b/txcache/interface.go @@ -16,7 +16,7 @@ type TxGasHandler interface { // SelectionSession provides blockchain information for transaction selection type SelectionSession interface { GetAccountState(accountKey []byte) (*types.AccountState, error) - IsBadlyGuarded(tx data.TransactionHandler) bool + IsIncorrectlyGuarded(tx data.TransactionHandler) bool IsInterfaceNil() bool } diff --git a/txcache/selection.go b/txcache/selection.go index 50c4881e..f889a3a9 100644 --- a/txcache/selection.go +++ b/txcache/selection.go @@ -112,7 +112,7 @@ func detectSkippableTransaction(session SelectionSession, item *transactionsHeap if item.detectLowerNonce() { return true } - if item.detectBadlyGuarded(session) { + if item.detectIncorrectlyGuarded(session) { return true } if item.detectNonceDuplicate() { diff --git a/txcache/selection_test.go b/txcache/selection_test.go index 80e82686..099e1b3e 100644 --- a/txcache/selection_test.go +++ b/txcache/selection_test.go @@ -224,18 +224,14 @@ func TestTxCache_SelectTransactions_HandlesNotExecutableTransactions(t *testing. require.Equal(t, 200000, int(accumulatedGas)) }) - t.Run("with badly guarded", func(t *testing.T) { + t.Run("with incorrectly guarded", func(t *testing.T) { cache := newUnconstrainedCacheToTest() session := txcachemocks.NewSelectionSessionMock() session.SetNonce([]byte("alice"), 1) session.SetNonce([]byte("bob"), 42) - session.IsBadlyGuardedCalled = func(tx data.TransactionHandler) bool { - if bytes.Equal(tx.GetData(), []byte("t")) { - return true - } - - return false + session.IsIncorrectlyGuardedCalled = func(tx data.TransactionHandler) bool { + return bytes.Equal(tx.GetData(), []byte("t")) } cache.AddTx(createTx([]byte("hash-alice-1"), "alice", 1).withData([]byte("x")).withGasLimit(100000)) diff --git a/txcache/transactionsHeapItem.go b/txcache/transactionsHeapItem.go index cd4e7861..6b72cb79 100644 --- a/txcache/transactionsHeapItem.go +++ b/txcache/transactionsHeapItem.go @@ -157,16 +157,16 @@ func (item *transactionsHeapItem) detectLowerNonce() bool { return isLowerNonce } -func (item *transactionsHeapItem) detectBadlyGuarded(session SelectionSession) bool { - isBadlyGuarded := session.IsBadlyGuarded(item.currentTransaction.Tx) - if isBadlyGuarded { - logSelect.Trace("transactionsHeapItem.detectBadlyGuarded", +func (item *transactionsHeapItem) detectIncorrectlyGuarded(session SelectionSession) bool { + IsIncorrectlyGuarded := session.IsIncorrectlyGuarded(item.currentTransaction.Tx) + if IsIncorrectlyGuarded { + logSelect.Trace("transactionsHeapItem.detectIncorrectlyGuarded", "tx", item.currentTransaction.TxHash, "sender", item.sender, ) } - return isBadlyGuarded + return IsIncorrectlyGuarded } func (item *transactionsHeapItem) detectNonceDuplicate() bool { diff --git a/txcache/transactionsHeapItem_test.go b/txcache/transactionsHeapItem_test.go index 9ab581df..0aeafe44 100644 --- a/txcache/transactionsHeapItem_test.go +++ b/txcache/transactionsHeapItem_test.go @@ -232,29 +232,29 @@ func TestTransactionsHeapItem_detectNonceDuplicate(t *testing.T) { }) } -func TestTransactionsHeapItem_detectBadlyGuarded(t *testing.T) { - t.Run("is not badly guarded", func(t *testing.T) { +func TestTransactionsHeapItem_detectIncorrectlyGuarded(t *testing.T) { + t.Run("is correctly guarded", func(t *testing.T) { session := txcachemocks.NewSelectionSessionMock() - session.IsBadlyGuardedCalled = func(tx data.TransactionHandler) bool { + session.IsIncorrectlyGuardedCalled = func(tx data.TransactionHandler) bool { return false } item, err := newTransactionsHeapItem(bunchOfTransactions{createTx([]byte("tx-1"), "alice", 42)}) require.NoError(t, err) - require.False(t, item.detectBadlyGuarded(session)) + require.False(t, item.detectIncorrectlyGuarded(session)) }) - t.Run("is badly guarded", func(t *testing.T) { + t.Run("is incorrectly guarded", func(t *testing.T) { session := txcachemocks.NewSelectionSessionMock() - session.IsBadlyGuardedCalled = func(tx data.TransactionHandler) bool { + session.IsIncorrectlyGuardedCalled = func(tx data.TransactionHandler) bool { return true } item, err := newTransactionsHeapItem(bunchOfTransactions{createTx([]byte("tx-1"), "alice", 42)}) require.NoError(t, err) - require.True(t, item.detectBadlyGuarded(session)) + require.True(t, item.detectIncorrectlyGuarded(session)) }) }