Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get nonce from state #1710

Merged
merged 3 commits into from
Feb 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pool/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@ type stateInterface interface {
GetLastL2BlockNumber(ctx context.Context, dbTx pgx.Tx) (uint64, error)
GetNonce(ctx context.Context, address common.Address, batchNumber uint64, dbTx pgx.Tx) (uint64, error)
GetTransactionByHash(ctx context.Context, transactionHash common.Hash, dbTx pgx.Tx) (*types.Transaction, error)
PreProcessTransaction(ctx context.Context, tx *types.Transaction, forcedNonce uint64, dbTx pgx.Tx) (*state.ProcessBatchResponse, error)
PreProcessTransaction(ctx context.Context, tx *types.Transaction, dbTx pgx.Tx) (*state.ProcessBatchResponse, error)
}
14 changes: 1 addition & 13 deletions pool/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"math/big"
"time"

"github.com/0xPolygonHermez/zkevm-node/log"
"github.com/0xPolygonHermez/zkevm-node/state"
"github.com/0xPolygonHermez/zkevm-node/state/runtime/executor"
"github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -94,18 +93,7 @@ func (p *Pool) AddTx(ctx context.Context, tx types.Transaction) error {

// PreExecuteTx executes a transaction to calculate its zkCounters
func (p *Pool) PreExecuteTx(ctx context.Context, tx types.Transaction) (state.ZKCounters, error) {
sender, err := state.GetSender(tx)
if err != nil {
return state.ZKCounters{}, err
}

nonce, err := p.storage.GetNonce(ctx, sender)
if err != nil {
log.Errorf("Error getting nonce for sender %s: %v", sender.Hex(), err)
return state.ZKCounters{}, err
}

processBatchResponse, err := p.state.PreProcessTransaction(ctx, &tx, nonce, nil)
processBatchResponse, err := p.state.PreProcessTransaction(ctx, &tx, nil)
if err != nil {
return state.ZKCounters{}, err
}
Expand Down
7 changes: 6 additions & 1 deletion state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -1163,7 +1163,7 @@ func (s *State) ParseTheTraceUsingTheTracer(env *fakevm.FakeEVM, trace instrumen
}

// PreProcessTransaction processes the transaction in order to calculate its zkCounters before adding it to the pool
func (s *State) PreProcessTransaction(ctx context.Context, tx *types.Transaction, nonce uint64, dbTx pgx.Tx) (*ProcessBatchResponse, error) {
func (s *State) PreProcessTransaction(ctx context.Context, tx *types.Transaction, dbTx pgx.Tx) (*ProcessBatchResponse, error) {
sender, err := GetSender(*tx)
if err != nil {
return nil, err
Expand All @@ -1174,6 +1174,11 @@ func (s *State) PreProcessTransaction(ctx context.Context, tx *types.Transaction
return nil, err
}

nonce, err := s.GetNonce(ctx, sender, lastL2BlockNumber, nil)
if err != nil {
return nil, err
}

return s.internalProcessUnsignedTransaction(ctx, tx, sender, &lastL2BlockNumber, false, &nonce, dbTx)
}

Expand Down