Skip to content

Commit

Permalink
Try #6170:
Browse files Browse the repository at this point in the history
  • Loading branch information
spacemesh-bors[bot] authored Jul 23, 2024
2 parents 036969c + 6d3256a commit 835a7c6
Showing 1 changed file with 4 additions and 45 deletions.
49 changes: 4 additions & 45 deletions txs/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,6 @@ func (ac *accountCache) precheck(logger *zap.Logger, ntx *NanoTX) (*list.Element
}
if balance < ntx.MaxSpending() {
ac.moreInDB = true
logger.Debug("insufficient balance",
zap.Stringer("tx_id", ntx.ID),
zap.Stringer("address", ntx.Principal),
zap.Uint64("nonce", ntx.Nonce),
zap.Uint64("cons_balance", balance),
zap.Uint64("cons_spending", ntx.MaxSpending()),
)
return nil, nil, errInsufficientBalance
}
return prev, &candidate{best: ntx, postBalance: balance - ntx.MaxSpending()}, nil
Expand Down Expand Up @@ -256,30 +249,6 @@ func (ac *accountCache) addBatch(logger *zap.Logger, nonce2TXs map[uint64][]*Nan
}

ac.moreInDB = len(sortedNonce) > len(added)
if len(added) > 0 {
logger.Debug("added batch to account pool",
zap.Stringer("address", ac.addr),
zap.Array("batch", zapcore.ArrayMarshalerFunc(func(encoder zapcore.ArrayEncoder) error {
slices.Sort(added)
for _, nonce := range added {
encoder.AppendUint64(nonce)
}
return nil
})),
)
} else {
logger.Debug("no feasible txs from batch",
zap.Stringer("address", ac.addr),
zap.Array("batch", zapcore.ArrayMarshalerFunc(func(encoder zapcore.ArrayEncoder) error {
nonces := maps.Keys(nonce2TXs)
slices.Sort(nonces)
for _, nonce := range nonces {
encoder.AppendUint64(nonce)
}
return nil
})),
)
}
return nil
}

Expand All @@ -302,11 +271,6 @@ func findBest(ntxs []*NanoTX, balance uint64, blockSeed []byte) *NanoTX {
// - nonce not present: add to cache.
func (ac *accountCache) add(logger *zap.Logger, tx *types.Transaction, received time.Time) error {
if tx.Nonce < ac.startNonce {
logger.Debug("nonce too small",
zap.Stringer("tx_id", tx.ID),
zap.Uint64("next_nonce", ac.startNonce),
zap.Uint64("tx_nonce", tx.Nonce),
)
return errBadNonce
}

Expand Down Expand Up @@ -338,11 +302,7 @@ func (ac *accountCache) addPendingFromNonce(
) error {
mtxs, err := transactions.GetAcctPendingFromNonce(db, ac.addr, nonce)
if err != nil {
logger.Error("failed to get more pending txs from db",
zap.Stringer("address", ac.addr),
zap.Error(err),
)
return err
return fmt.Errorf("account pending txs: %w", err)
}

if len(mtxs) == 0 {
Expand All @@ -357,7 +317,7 @@ func (ac *accountCache) addPendingFromNonce(
}
nextLayer, nextBlock, err := getNextIncluded(db, mtx.ID, applied)
if err != nil {
return err
return fmt.Errorf("get next included: %w", err)
}
mtx.LayerID = nextLayer
mtx.BlockID = nextBlock
Expand Down Expand Up @@ -512,7 +472,7 @@ func (c *Cache) buildFromScratch(db *sql.Database) error {
}
nextLayer, nextBlock, err := getNextIncluded(db, mtx.ID, applied)
if err != nil {
return err
return fmt.Errorf("get next included: %w", err)
}
mtx.LayerID = nextLayer
mtx.BlockID = nextBlock
Expand Down Expand Up @@ -662,8 +622,7 @@ func (c *Cache) LinkTXsWithProposal(
return nil
}
if err := addToProposal(db, lid, pid, tids); err != nil {
c.logger.Error("failed to link txs to proposal in db", zap.Error(err))
return err
return fmt.Errorf("add tx to proposal: %w", err)
}
return c.updateLayer(lid, types.EmptyBlockID, tids)
}
Expand Down

0 comments on commit 835a7c6

Please sign in to comment.