diff --git a/core/types/results.go b/core/types/results.go index c21851144..f42841c52 100644 --- a/core/types/results.go +++ b/core/types/results.go @@ -43,6 +43,7 @@ var ( ErrInvalidNonce = errors.New("invalid nonce") ErrInvalidAmount = errors.New("invalid amount") ErrInsufficientBalance = errors.New("insufficient balance") + ErrMempoolFull = errors.New("mempool is full") ) // TxResult is the result of a transaction execution on chain. diff --git a/node/services/jsonrpc/usersvc/service.go b/node/services/jsonrpc/usersvc/service.go index a27d909a8..69fde191c 100644 --- a/node/services/jsonrpc/usersvc/service.go +++ b/node/services/jsonrpc/usersvc/service.go @@ -569,6 +569,7 @@ func (svc *Service) Account(ctx context.Context, req *userjson.AccountRequest) ( return nil, jsonrpc.NewError(jsonrpc.ErrorAccountInternal, "account info error", nil) } + svc.log.Info("account info", "account", req.ID, "balance", balance, "nonce", nonce) var ident *types.AccountID var zeroBal big.Int if nonce > 0 || balance.Cmp(&zeroBal) > 0 { // return nil pubkey for non-existent account diff --git a/node/txapp/mempool.go b/node/txapp/mempool.go index 3541b67d4..02a40949d 100644 --- a/node/txapp/mempool.go +++ b/node/txapp/mempool.go @@ -42,17 +42,19 @@ func (m *mempool) accountInfo(ctx context.Context, tx sql.Executor, acctID *type } if acctInfo, ok := m.accounts[string(id)]; ok { + m.log.Info("retrieved account from mempool records", "account", acctID, "nonce", acctInfo.Nonce, "balance", acctInfo.Balance) return acctInfo, nil // there are unconfirmed txs for this account } // get account from account store acct, err := m.accountMgr.GetAccount(ctx, tx, acctID) if err != nil { + m.log.Info("failed to retrieve account from account store", "account", acctID, "error", err) return nil, err } m.accounts[string(id)] = acct - m.log.Debug("added new account to mempool records", "account", acctID, "nonce", acct.Nonce, "balance", acct.Balance) + m.log.Info("added new account to mempool records", "account", acctID, "nonce", acct.Nonce, "balance", acct.Balance) return acct, nil } @@ -254,7 +256,7 @@ func (m *mempool) applyTransaction(ctx *common.TxContext, tx *types.Transaction, // (but Tx with nonce is never pushed to the consensus pool). acct.Nonce = int64(tx.Body.Nonce) - m.log.Debug("applied transaction to mempool state", "account", log.LazyHex(tx.Sender), + m.log.Info("applied transaction to mempool state", "account", log.LazyHex(tx.Sender), "nonce", acct.Nonce, "balance", acct.Balance) return nil @@ -267,4 +269,5 @@ func (m *mempool) reset() { defer m.acctsMtx.Unlock() m.accounts = make(map[string]*types.Account) + m.log.Infof("mempool state reset") } diff --git a/node/types/interfaces.go b/node/types/interfaces.go index 599654c0c..067451fb7 100644 --- a/node/types/interfaces.go +++ b/node/types/interfaces.go @@ -17,7 +17,7 @@ var ( ErrStillProcessing = errors.New("block still being executed") ErrNoResponse = errors.New("stream closed without response") ErrPeersNotFound = errors.New("no peers available") - ErrMempoolFull = errors.New("mempool is full") + ErrMempoolFull = types.ErrMempoolFull ) const HashLen = types.HashLen diff --git a/test/stress/harness.go b/test/stress/harness.go index 0bc015573..4fd288045 100644 --- a/test/stress/harness.go +++ b/test/stress/harness.go @@ -7,6 +7,7 @@ import ( "math/rand" "strings" "sync" + "time" clientType "github.com/kwilteam/kwil-db/core/client/types" "github.com/kwilteam/kwil-db/core/crypto/auth" @@ -64,11 +65,15 @@ func (h *harness) underNonceLock(ctx context.Context, fn func(int64) error) erro nonce := h.nonce + randNonceJitter(h.nonceChaos) h.nonceMtx.Unlock() if err := fn(nonce); err != nil { - if errors.Is(err, types.ErrInvalidNonce) { - // Note: several goroutines may all try to do this if they all hit the nonce error - h.recoverNonce(ctx) - h.printf("error, nonce %d was wrong, reverting to %d\n", nonce, h.nonce) + if errors.Is(err, types.ErrMempoolFull) { + time.Sleep(1 * time.Second) } + h.recoverNonce(ctx) + // if errors.Is(err, types.ErrInvalidNonce) { + // // Note: several goroutines may all try to do this if they all hit the nonce error + // h.recoverNonce(ctx) + // h.printf("error, nonce %d was wrong, reverting to %d\n", nonce, h.nonce) + // } return err } return nil @@ -81,7 +86,7 @@ func (h *harness) underNonceLock(ctx context.Context, fn func(int64) error) erro h.printf("using next nonce %d", h.nonce) if err := fn(h.nonce); err != nil { - if errors.Is(err, types.ErrInvalidNonce) { // this alone should not happen + if errors.Is(err, types.ErrInvalidNonce) || errors.Is(err, types.ErrMempoolFull) { // this alone should not happen // NOTE: if GetAccount returns only the confirmed nonce, we'll error // again shortly if there are others already in mempool. acct, err := h.GetAccount(ctx, h.acctID, types.AccountStatusPending)