core: split ErrAlreadyExists into ErrAlreadyExists and ErrAlreadyInPool

ErrAlreadyExists is in blockchain and ErrAlreadyInPool is in mempool.

Signed-off-by: Tatiana Nesterenko <tatiana@nspcc.io>
This commit is contained in:
Tatiana Nesterenko 2023-07-26 17:18:24 +01:00
parent 16d1d1e5eb
commit 3abddc78c0
3 changed files with 10 additions and 8 deletions

View file

@ -423,7 +423,7 @@ func mkP2PNotary(config config.P2PNotary, chain *core.Blockchain, serv *network.
}
n, err := notary.NewNotary(cfg, serv.Net, serv.GetNotaryPool(), func(tx *transaction.Transaction) error {
err := serv.RelayTxn(tx)
if err != nil && !errors.Is(err, core.ErrAlreadyExists) {
if err != nil && !errors.Is(err, core.ErrAlreadyExists) && !errors.Is(err, core.ErrAlreadyInPool) {
return fmt.Errorf("can't relay completed notary transaction: hash %s, error: %w", tx.Hash().StringLE(), err)
}
return nil

View file

@ -88,10 +88,12 @@ const (
)
var (
// ErrAlreadyExists is returned when trying to add some already existing
// transaction into the pool (not specifying whether it exists in the
// chain or mempool).
ErrAlreadyExists = errors.New("already exists")
// ErrAlreadyExists is returned when trying to add some transaction
// that already exists on chain.
ErrAlreadyExists = errors.New("already exists in blockchain")
// ErrAlreadyInPool is returned when trying to add some already existing
// transaction into the mempool.
ErrAlreadyInPool = errors.New("already exists in mempool")
// ErrOOM is returned when adding transaction to the memory pool because
// it reached its full capacity.
ErrOOM = errors.New("no space left in the memory pool")
@ -2480,7 +2482,7 @@ func (bc *Blockchain) verifyAndPoolTx(t *transaction.Transaction, pool *mempool.
if err := bc.dao.HasTransaction(t.Hash(), t.Signers); err != nil {
switch {
case errors.Is(err, dao.ErrAlreadyExists):
return fmt.Errorf("blockchain: %w", ErrAlreadyExists)
return ErrAlreadyExists
case errors.Is(err, dao.ErrHasConflicts):
return fmt.Errorf("blockchain: %w", ErrHasConflicts)
default:
@ -2500,7 +2502,7 @@ func (bc *Blockchain) verifyAndPoolTx(t *transaction.Transaction, pool *mempool.
case errors.Is(err, mempool.ErrConflict):
return ErrMemPoolConflict
case errors.Is(err, mempool.ErrDup):
return fmt.Errorf("mempool: %w", ErrAlreadyExists)
return ErrAlreadyInPool
case errors.Is(err, mempool.ErrInsufficientFunds):
return ErrInsufficientFunds
case errors.Is(err, mempool.ErrOOM):

View file

@ -1358,7 +1358,7 @@ func TestBlockchain_VerifyTx(t *testing.T) {
require.NoError(t, bc.PoolTx(tx))
err := bc.PoolTx(tx)
require.ErrorIs(t, err, core.ErrAlreadyExists)
require.ErrorIs(t, err, core.ErrAlreadyInPool)
})
t.Run("MemPoolOOM", func(t *testing.T) {
mp := mempool.New(1, 0, false, nil)