Skip to content

Commit

Permalink
get nonce from state (#1710)
Browse files Browse the repository at this point in the history
* get nonce from state

* foce block number

* foce block number and nonce
  • Loading branch information
ToniRamirezM committed Feb 28, 2023
1 parent bb57855 commit e84542c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 15 deletions.
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

0 comments on commit e84542c

Please sign in to comment.