Skip to content

Commit

Permalink
just for testing, gonna revert this commit soon
Browse files Browse the repository at this point in the history
  • Loading branch information
charithabandi committed Feb 21, 2025
1 parent 91bfebd commit fcd5902
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 8 deletions.
1 change: 1 addition & 0 deletions core/types/results.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions node/services/jsonrpc/usersvc/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions node/txapp/mempool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand All @@ -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")
}
2 changes: 1 addition & 1 deletion node/types/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 10 additions & 5 deletions test/stress/harness.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit fcd5902

Please sign in to comment.