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

allow GetL2TxHashByTxHash to return null for txs prior to Etrog #3209

Merged
merged 2 commits into from
Feb 5, 2024
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
6 changes: 3 additions & 3 deletions jsonrpc/endpoints_eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ func (e *EthEndpoints) GetTransactionByBlockHashAndIndex(hash types.ArgHash, ind
if err != nil {
return RPCErrorResponse(types.DefaultErrorCode, "failed to get l2 transaction hash", err, true)
}
l2Hash = &l2h
l2Hash = l2h
}

res, err := types.NewTransaction(*tx, receipt, false, l2Hash)
Expand Down Expand Up @@ -628,7 +628,7 @@ func (e *EthEndpoints) GetTransactionByBlockNumberAndIndex(number *types.BlockNu
if err != nil {
return RPCErrorResponse(types.DefaultErrorCode, "failed to get l2 transaction hash", err, true)
}
l2Hash = &l2h
l2Hash = l2h
}

res, err := types.NewTransaction(*tx, receipt, false, l2Hash)
Expand Down Expand Up @@ -662,7 +662,7 @@ func (e *EthEndpoints) GetTransactionByHash(hash types.ArgHash, includeExtraInfo
if err != nil {
return RPCErrorResponse(types.DefaultErrorCode, "failed to get l2 transaction hash", err, true)
}
l2Hash = &l2h
l2Hash = l2h
}

res, err := types.NewTransaction(*tx, receipt, false, l2Hash)
Expand Down
4 changes: 2 additions & 2 deletions jsonrpc/endpoints_eth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1309,7 +1309,7 @@ func TestGetL2BlockByNumber(t *testing.T) {
for _, signedTx := range signedTransactions {
m.State.
On("GetL2TxHashByTxHash", context.Background(), signedTx.Hash(), m.DbTx).
Return(signedTx.Hash(), nil).
Return(state.Ptr(signedTx.Hash()), nil).
Once()
}
},
Expand Down Expand Up @@ -1349,7 +1349,7 @@ func TestGetL2BlockByNumber(t *testing.T) {
for _, signedTx := range signedTransactions {
m.State.
On("GetL2TxHashByTxHash", context.Background(), signedTx.Hash(), m.DbTx).
Return(signedTx.Hash(), nil).
Return(state.Ptr(signedTx.Hash()), nil).
Once()
}
},
Expand Down
4 changes: 2 additions & 2 deletions jsonrpc/endpoints_zkevm.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ func (z *ZKEVMEndpoints) GetTransactionByL2Hash(hash types.ArgHash) (interface{}
return RPCErrorResponse(types.DefaultErrorCode, "failed to get l2 transaction hash", err, true)
}

res, err := types.NewTransaction(*tx, receipt, false, &l2Hash)
res, err := types.NewTransaction(*tx, receipt, false, l2Hash)
if err != nil {
return RPCErrorResponse(types.DefaultErrorCode, "failed to build transaction response", err, true)
}
Expand Down Expand Up @@ -381,7 +381,7 @@ func (z *ZKEVMEndpoints) GetTransactionReceiptByL2Hash(hash types.ArgHash) (inte
return RPCErrorResponse(types.DefaultErrorCode, "failed to get l2 transaction hash", err, true)
}

receipt, err := types.NewReceipt(*tx, r, &l2Hash)
receipt, err := types.NewReceipt(*tx, r, l2Hash)
if err != nil {
return RPCErrorResponse(types.DefaultErrorCode, "failed to build the receipt response", err, true)
}
Expand Down
10 changes: 5 additions & 5 deletions jsonrpc/endpoints_zkevm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,7 @@ func TestGetBatchByNumber(t *testing.T) {
Once()
m.State.
On("GetL2TxHashByTxHash", context.Background(), tx.Hash(), m.DbTx).
Return(tx.Hash(), nil).
Return(state.Ptr(tx.Hash()), nil).
Once()
}
m.State.
Expand Down Expand Up @@ -1063,7 +1063,7 @@ func TestGetBatchByNumber(t *testing.T) {

m.State.
On("GetL2TxHashByTxHash", context.Background(), tx.Hash(), m.DbTx).
Return(tx.Hash(), nil).
Return(state.Ptr(tx.Hash()), nil).
Once()
}

Expand Down Expand Up @@ -1980,7 +1980,7 @@ func TestGetTransactionByL2Hash(t *testing.T) {

m.State.
On("GetL2TxHashByTxHash", context.Background(), signedTx.Hash(), m.DbTx).
Return(l2Hash, nil).
Return(&l2Hash, nil).
Once()
},
},
Expand Down Expand Up @@ -2296,7 +2296,7 @@ func TestGetTransactionReceiptByL2Hash(t *testing.T) {

m.State.
On("GetL2TxHashByTxHash", context.Background(), signedTx.Hash(), m.DbTx).
Return(l2Hash, nil).
Return(&l2Hash, nil).
Once()
},
},
Expand Down Expand Up @@ -2426,7 +2426,7 @@ func TestGetTransactionReceiptByL2Hash(t *testing.T) {

m.State.
On("GetL2TxHashByTxHash", context.Background(), tx.Hash(), m.DbTx).
Return(l2Hash, nil).
Return(&l2Hash, nil).
Once()
},
},
Expand Down
10 changes: 5 additions & 5 deletions jsonrpc/mocks/mock_state.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion jsonrpc/types/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ type StateInterface interface {
GetLastVerifiedBatchNumberUntilL1Block(ctx context.Context, l1BlockNumber uint64, dbTx pgx.Tx) (uint64, error)
GetBatchTimestamp(ctx context.Context, batchNumber uint64, forcedForkId *uint64, dbTx pgx.Tx) (*time.Time, error)
GetLatestBatchGlobalExitRoot(ctx context.Context, dbTx pgx.Tx) (common.Hash, error)
GetL2TxHashByTxHash(ctx context.Context, hash common.Hash, dbTx pgx.Tx) (common.Hash, error)
GetL2TxHashByTxHash(ctx context.Context, hash common.Hash, dbTx pgx.Tx) (*common.Hash, error)
}

// EthermanInterface provides integration with L1
Expand Down
4 changes: 2 additions & 2 deletions jsonrpc/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ func NewBlock(ctx context.Context, st StateInterface, hash *common.Hash, b *stat
if err != nil {
return nil, err
}
l2Hash = &l2h
l2Hash = l2h
}

rpcTx, err := NewTransaction(*tx, receiptPtr, includeReceipts, l2Hash)
Expand Down Expand Up @@ -422,7 +422,7 @@ func NewBatch(ctx context.Context, st StateInterface, batch *state.Batch, virtua
if err != nil {
return nil, err
}
rpcTx, err := NewTransaction(tx, receiptPtr, includeReceipts, &l2Hash)
rpcTx, err := NewTransaction(tx, receiptPtr, includeReceipts, l2Hash)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion state/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ type storage interface {
GetVirtualBatchParentHash(ctx context.Context, batchNumber uint64, dbTx pgx.Tx) (common.Hash, error)
GetForcedBatchParentHash(ctx context.Context, forcedBatchNumber uint64, dbTx pgx.Tx) (common.Hash, error)
GetLatestBatchGlobalExitRoot(ctx context.Context, dbTx pgx.Tx) (common.Hash, error)
GetL2TxHashByTxHash(ctx context.Context, hash common.Hash, dbTx pgx.Tx) (common.Hash, error)
GetL2TxHashByTxHash(ctx context.Context, hash common.Hash, dbTx pgx.Tx) (*common.Hash, error)
GetSyncInfoData(ctx context.Context, dbTx pgx.Tx) (SyncInfoDataOnStorage, error)
GetFirstL2BlockNumberForBatchNumber(ctx context.Context, batchNumber uint64, dbTx pgx.Tx) (uint64, error)
GetForkIDInMemory(forkId uint64) *ForkIDInterval
Expand Down
14 changes: 7 additions & 7 deletions state/mocks/mock_storage.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 10 additions & 6 deletions state/pgstatestorage/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -562,19 +562,23 @@ func (p *PostgresStorage) GetTransactionEGPLogByHash(ctx context.Context, transa
}

// GetL2TxHashByTxHash gets the L2 Hash from the tx found by the provided tx hash
func (p *PostgresStorage) GetL2TxHashByTxHash(ctx context.Context, hash common.Hash, dbTx pgx.Tx) (common.Hash, error) {
func (p *PostgresStorage) GetL2TxHashByTxHash(ctx context.Context, hash common.Hash, dbTx pgx.Tx) (*common.Hash, error) {
const getTransactionByHashSQL = "SELECT transaction.l2_hash FROM state.transaction WHERE hash = $1"

var l2HashHex string
var l2HashHex *string
q := p.getExecQuerier(dbTx)
err := q.QueryRow(ctx, getTransactionByHashSQL, hash.String()).Scan(&l2HashHex)

if errors.Is(err, pgx.ErrNoRows) {
return common.Hash{}, state.ErrNotFound
return nil, state.ErrNotFound
} else if err != nil {
return common.Hash{}, err
return nil, err
}

if l2HashHex == nil {
return nil, nil
}

l2Hash := common.HexToHash(l2HashHex)
return l2Hash, nil
l2Hash := common.HexToHash(*l2HashHex)
return &l2Hash, nil
}
Loading