From 3abddc78c0581c832a2754f21acf8215ee6e0f59 Mon Sep 17 00:00:00 2001 From: Tatiana Nesterenko Date: Wed, 26 Jul 2023 17:18:24 +0100 Subject: [PATCH] core: split ErrAlreadyExists into ErrAlreadyExists and ErrAlreadyInPool ErrAlreadyExists is in blockchain and ErrAlreadyInPool is in mempool. Signed-off-by: Tatiana Nesterenko --- cli/server/server.go | 2 +- pkg/core/blockchain.go | 14 ++++++++------ pkg/core/blockchain_neotest_test.go | 2 +- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/cli/server/server.go b/cli/server/server.go index 8aba05454..3f090cbda 100644 --- a/cli/server/server.go +++ b/cli/server/server.go @@ -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 diff --git a/pkg/core/blockchain.go b/pkg/core/blockchain.go index b5ca036dd..bd28047e4 100644 --- a/pkg/core/blockchain.go +++ b/pkg/core/blockchain.go @@ -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): diff --git a/pkg/core/blockchain_neotest_test.go b/pkg/core/blockchain_neotest_test.go index c00f4b0e9..d636ce2b5 100644 --- a/pkg/core/blockchain_neotest_test.go +++ b/pkg/core/blockchain_neotest_test.go @@ -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)