Skip to content

Commit

Permalink
improve: adding additional info for txs moved to not ready
Browse files Browse the repository at this point in the history
Signed-off-by: Nikolay Nedkov <[email protected]>
  • Loading branch information
Psykepro committed Mar 15, 2023
1 parent f01dc87 commit b74485d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
2 changes: 1 addition & 1 deletion sequencer/finalizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,6 @@ func (f *finalizer) handleTransactionError(ctx context.Context, result *state.Pr
}
}()
} else if (executor.IsInvalidNonceError(errorCode) || executor.IsInvalidBalanceError(errorCode)) && !tx.IsClaim {
log.Errorf("intrinsic error, moving tx with Hash: %s to NOT READY, err: %s", tx.Hash, txResponse.RomError)
var (
nonce *uint64
balance *big.Int
Expand All @@ -459,6 +458,7 @@ func (f *finalizer) handleTransactionError(ctx context.Context, result *state.Pr
balance = addressInfo.Balance
}
start := time.Now()
log.Errorf("intrinsic error, moving tx with Hash: %s to NOT READY nonce(%d) balance(%s) cost(%s), err: %s", tx.Hash, nonce, balance.String(), tx.Cost.String(), txResponse.RomError)
txsToDelete := f.worker.MoveTxToNotReady(tx.Hash, tx.From, nonce, balance)
for _, txToDelete := range txsToDelete {
err := f.dbManager.UpdateTxStatus(ctx, txToDelete.Hash, pool.TxStatusFailed, false)
Expand Down
2 changes: 1 addition & 1 deletion sequencer/finalizer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ func TestFinalizer_handleTransactionError(t *testing.T) {
// arrange
f = setupFinalizer(true)
nonce := uint64(0)
tx := &TxTracker{Hash: oldHash, From: sender}
tx := &TxTracker{Hash: oldHash, From: sender, Cost: big.NewInt(0)}
testCases := []struct {
name string
error pb.RomError
Expand Down
28 changes: 19 additions & 9 deletions sequencer/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,20 +78,20 @@ func (w *Worker) AddTxTracker(ctx context.Context, tx *TxTracker) {
w.workerMutex.Lock()

w.pool[tx.FromStr] = addr
log.Infof("AddTx new addrQueue created for addr(%s)", tx.FromStr)
log.Infof("AddTx new addrQueue created for addr(%s) nonce(%d) balance(%s)", tx.FromStr, nonce.Uint64(), balance.String())
}

// Add the txTracker to Addr and get the newReadyTx and prevReadyTx
log.Infof("AddTx new tx(%s) to addrQueue(%s)", tx.Hash.String(), tx.FromStr)
log.Infof("AddTx new tx(%s) nonce(%d) cost(%s) to addrQueue(%s)", tx.Hash.String(), tx.Nonce, tx.FromStr, tx.Cost.String())
newReadyTx, prevReadyTx := addr.addTx(tx)

// Update the EfficiencyList (if needed)
if prevReadyTx != nil {
log.Infof("AddTx prevReadyTx(%s) deleted from EfficiencyList", prevReadyTx.Hash.String())
log.Infof("AddTx prevReadyTx(%s) nonce(%d) cost(%s) deleted from EfficiencyList", prevReadyTx.Hash.String(), prevReadyTx.Nonce, prevReadyTx.Cost.String())
w.efficiencyList.delete(prevReadyTx)
}
if newReadyTx != nil {
log.Infof("AddTx newReadyTx(%s) added to EfficiencyList", newReadyTx.Hash.String())
log.Infof("AddTx newReadyTx(%s) nonce(%d) cost(%s) added to EfficiencyList", newReadyTx.Hash.String(), newReadyTx.Nonce, newReadyTx.Cost.String())
w.efficiencyList.add(newReadyTx)
}
}
Expand All @@ -105,11 +105,11 @@ func (w *Worker) applyAddressUpdate(from common.Address, fromNonce *uint64, from

// Update the EfficiencyList (if needed)
if prevReadyTx != nil {
log.Infof("applyAddressUpdate prevReadyTx(%s) deleted from EfficiencyList", prevReadyTx.Hash.String())
log.Infof("applyAddressUpdate prevReadyTx(%s) nonce(%d) cost(%s) deleted from EfficiencyList", prevReadyTx.Hash.String(), prevReadyTx.Nonce, prevReadyTx.Cost.String())
w.efficiencyList.delete(prevReadyTx)
}
if newReadyTx != nil {
log.Infof("applyAddressUpdate newReadyTx(%s) added to EfficiencyList", newReadyTx.Hash.String())
log.Infof("applyAddressUpdate newReadyTx(%s) nonce(%d) cost(%s) added to EfficiencyList", newReadyTx.Hash.String(), newReadyTx.Nonce, newReadyTx.Cost.String())
w.efficiencyList.add(newReadyTx)
}

Expand Down Expand Up @@ -148,6 +148,7 @@ func (w *Worker) UpdateAfterSingleSuccessfulTxExecution(from common.Address, tou
func (w *Worker) MoveTxToNotReady(txHash common.Hash, from common.Address, actualNonce *uint64, actualBalance *big.Int) []*TxTracker {
w.workerMutex.Lock()
defer w.workerMutex.Unlock()
log.Infof("MoveTxToNotReady tx(%s) from(%s) actualNonce(%d) actualBalance(%s)", txHash.String(), from.String(), actualNonce, actualBalance.String())

addrQueue, found := w.pool[from.String()]
if found {
Expand All @@ -157,7 +158,7 @@ func (w *Worker) MoveTxToNotReady(txHash common.Hash, from common.Address, actua
if addrQueue.readyTx != nil {
readyHashStr = addrQueue.readyTx.HashStr
}
log.Errorf("MoveTxToNotReady txHash(s) is not the readyTx(%s)", txHash.String(), readyHashStr)
log.Errorf("MoveTxToNotReady txHash(%s) is not the readyTx(%s)", txHash.String(), readyHashStr)
// TODO: how to manage this?
}
}
Expand Down Expand Up @@ -187,6 +188,15 @@ func (w *Worker) DeleteTx(txHash common.Hash, addr common.Address) {
func (w *Worker) UpdateTx(txHash common.Hash, addr common.Address, counters state.ZKCounters) {
w.workerMutex.Lock()
defer w.workerMutex.Unlock()
log.Infof("UpdateTx tx(%s) addr(%s)", txHash.String(), addr.String())
log.Debugf("UpdateTx counters.CumulativeGasUsed: %s", counters.CumulativeGasUsed)
log.Debugf("UpdateTx counters.UsedKeccakHashes: %s", counters.UsedKeccakHashes)
log.Debugf("UpdateTx counters.UsedPoseidonHashes: %s", counters.UsedPoseidonHashes)
log.Debugf("UpdateTx counters.UsedPoseidonPaddings: %s", counters.UsedPoseidonPaddings)
log.Debugf("UpdateTx counters.UsedMemAligns: %s", counters.UsedMemAligns)
log.Debugf("UpdateTx counters.UsedArithmetics: %s", counters.UsedArithmetics)
log.Debugf("UpdateTx counters.UsedBinaries: %s", counters.UsedBinaries)
log.Debugf("UpdateTx counters.UsedSteps: %s", counters.UsedSteps)

addrQueue, found := w.pool[addr.String()]

Expand All @@ -195,11 +205,11 @@ func (w *Worker) UpdateTx(txHash common.Hash, addr common.Address, counters stat

// Resort the newReadyTx in efficiencyList
if prevReadyTx != nil {
log.Infof("UpdateTx prevReadyTx(%s) deleted from EfficiencyList", prevReadyTx.Hash.String())
log.Infof("UpdateTx prevReadyTx(%s) nonce(%d) cost(%s) deleted from EfficiencyList", prevReadyTx.Hash.String(), prevReadyTx.Nonce, prevReadyTx.Cost.String())
w.efficiencyList.delete(prevReadyTx)
}
if newReadyTx != nil {
log.Infof("UpdateTx newReadyTx(%s) added to EfficiencyList", newReadyTx.Hash.String())
log.Infof("UpdateTx newReadyTx(%s) nonce(%d) cost(%s) added to EfficiencyList", newReadyTx.Hash.String(), newReadyTx.Nonce, newReadyTx.Cost.String())
w.efficiencyList.add(newReadyTx)
}
} else {
Expand Down

0 comments on commit b74485d

Please sign in to comment.