Skip to content

Commit

Permalink
commit
Browse files Browse the repository at this point in the history
  • Loading branch information
JkLondon committed Mar 5, 2025
1 parent 81148fa commit 200ddf7
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 62 deletions.
14 changes: 5 additions & 9 deletions turbo/jsonrpc/debug_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -512,23 +512,19 @@ func (api *PrivateDebugAPIImpl) GetRawTransaction(ctx context.Context, txnHash c
txNumsReader := rawdbv3.TxNums.WithCustomReadTxNumFunc(freezeblocks.ReadTxNumFuncFromBlockReader(ctx, api._blockReader))

// Private API returns 0 if transaction is not found.
isBorStateSyncTx := false
if blockNum == 0 && chainConfig.Bor != nil {
if api.useBridgeReader {
blockNum, ok, err = api.bridgeReader.EventTxnLookup(ctx, txnHash)
if ok {
txNumNextBlock, err := txNumsReader.Min(tx, blockNum+1)
if err != nil {
return nil, err
}
txNum = txNumNextBlock
}
} else {
blockNum, ok, err = api._blockReader.EventLookup(ctx, tx, txnHash)
}

if err != nil {
return nil, err
}

isBorStateSyncTx = true
}

if !ok {
Expand All @@ -540,11 +536,11 @@ func (api *PrivateDebugAPIImpl) GetRawTransaction(ctx context.Context, txnHash c
return nil, err
}

if txNumMin+2 > txNum {
if txNumMin+2 > txNum && !isBorStateSyncTx {
return nil, fmt.Errorf("uint underflow txnums error txNum: %d, txNumMin: %d, blockNum: %d", txNum, txNumMin, blockNum)
}

var txnIndex uint64 = txNum - txNumMin - 2
var txnIndex = txNum - txNumMin - 2

txn, err := api._txnReader.TxnByIdxInBlock(ctx, tx, blockNum, int(txnIndex))
if err != nil {
Expand Down
29 changes: 12 additions & 17 deletions turbo/jsonrpc/eth_receipts.go
Original file line number Diff line number Diff line change
Expand Up @@ -470,19 +470,14 @@ func (api *APIImpl) GetTransactionReceipt(ctx context.Context, txnHash common.Ha
}

// Private API returns 0 if transaction is not found.
if blockNum == 0 && chainConfig.Bor != nil {
isStateSync := blockNum == 0 && chainConfig.Bor != nil

if isStateSync {
if api.useBridgeReader {
blockNum, ok, err = api.bridgeReader.EventTxnLookup(ctx, txnHash)
if err != nil {
return nil, err
}
if ok {
txNumNextBlock, err := txNumsReader.Min(tx, blockNum+1)
if err != nil {
return nil, err
}
txNum = txNumNextBlock
}
} else {
blockNum, ok, err = api._blockReader.EventLookup(ctx, tx, txnHash)
}
Expand All @@ -495,7 +490,7 @@ func (api *APIImpl) GetTransactionReceipt(ctx context.Context, txnHash common.Ha
return nil, nil
}

if txNumMin+2 > txNum { //TODO: what a magic is this "2" and how to avoid it
if txNumMin+2 > txNum && !isStateSync { //TODO: what a magic is this "2" and how to avoid it
return nil, fmt.Errorf("uint underflow txnums error txNum: %d, txNumMin: %d, blockNum: %d", txNum, txNumMin, blockNum)
}

Expand All @@ -504,14 +499,7 @@ func (api *APIImpl) GetTransactionReceipt(ctx context.Context, txnHash common.Ha
return nil, err
}

var txnIndex = int(txNum - txNumMin - 2)

txn, err := api._blockReader.TxnByIdxInBlock(ctx, tx, header.Number.Uint64(), txnIndex)
if err != nil {
return nil, err
}

if txn == nil && chainConfig.Bor != nil {
if isStateSync {
block, err := api.blockByNumberWithSenders(ctx, tx, blockNum)
if err != nil {
return nil, err
Expand All @@ -537,6 +525,13 @@ func (api *APIImpl) GetTransactionReceipt(ctx context.Context, txnHash common.Ha
return ethutils.MarshalReceipt(borReceipt, bortypes.NewBorTransaction(), chainConfig, block.HeaderNoCopy(), txnHash, false), nil
}

var txnIndex = int(txNum - txNumMin - 2)

txn, err := api._blockReader.TxnByIdxInBlock(ctx, tx, header.Number.Uint64(), txnIndex)
if err != nil {
return nil, err
}

receipt, err := api.getReceipt(ctx, chainConfig, tx, header, txn, txnIndex, txNum)
if err != nil {
return nil, fmt.Errorf("getReceipt error: %w", err)
Expand Down
31 changes: 11 additions & 20 deletions turbo/jsonrpc/eth_txs.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,10 @@ func (api *APIImpl) GetTransactionByHash(ctx context.Context, txnHash common.Has
txNumsReader := rawdbv3.TxNums.WithCustomReadTxNumFunc(freezeblocks.ReadTxNumFuncFromBlockReader(ctx, api._blockReader))

// Private API returns 0 if transaction is not found.
if blockNum == 0 && chainConfig.Bor != nil {
isStateSyncTx := blockNum == 0 && chainConfig.Bor != nil
if isStateSyncTx {
if api.useBridgeReader {
blockNum, ok, err = api.bridgeReader.EventTxnLookup(ctx, txnHash)
if ok {
txNumNextBlock, err := txNumsReader.Min(tx, blockNum+1)
if err != nil {
return nil, err
}
txNum = txNumNextBlock
}
} else {
blockNum, ok, err = api._blockReader.EventLookup(ctx, tx, txnHash)
}
Expand All @@ -82,17 +76,10 @@ func (api *APIImpl) GetTransactionByHash(ctx context.Context, txnHash common.Has
return nil, err
}

if txNumMin+2 > txNum { //TODO: what a magic is this "2" and how to avoid it
if txNumMin+2 > txNum && !isStateSyncTx { //TODO: what a magic is this "2" and how to avoid it
return nil, fmt.Errorf("uint underflow txnums error txNum: %d, txNumMin: %d, blockNum: %d", txNum, txNumMin, blockNum)
}

var txnIndex uint64 = txNum - txNumMin - 2

txn, err := api._txnReader.TxnByIdxInBlock(ctx, tx, blockNum, int(txnIndex))
if err != nil {
return nil, err
}

header, err := api._blockReader.HeaderByNumber(ctx, tx, blockNum)
if err != nil {
return nil, err
Expand All @@ -110,10 +97,7 @@ func (api *APIImpl) GetTransactionByHash(ctx context.Context, txnHash common.Has
}

// if no transaction was found then we return nil
if txn == nil {
if chainConfig.Bor == nil {
return nil, nil
}
if isStateSyncTx {
borTx := bortypes.NewBorTransaction()
_, txCount, err := api._blockReader.Body(ctx, tx, blockHash, blockNum)
if err != nil {
Expand All @@ -122,6 +106,13 @@ func (api *APIImpl) GetTransactionByHash(ctx context.Context, txnHash common.Has
return ethapi.NewRPCBorTransaction(borTx, txnHash, blockHash, blockNum, uint64(txCount), chainConfig.ChainID), nil
}

var txnIndex = txNum - txNumMin - 2

txn, err := api._txnReader.TxnByIdxInBlock(ctx, tx, blockNum, int(txnIndex))
if err != nil {
return nil, err
}

return ethapi.NewRPCTransaction(txn, blockHash, blockNum, txnIndex, baseFee), nil
}

Expand Down
9 changes: 1 addition & 8 deletions turbo/jsonrpc/trace_adhoc.go
Original file line number Diff line number Diff line change
Expand Up @@ -833,13 +833,6 @@ func (api *TraceAPIImpl) ReplayTransaction(ctx context.Context, txHash libcommon
// otherwise this may be a bor state sync transaction - check
if api.useBridgeReader {
blockNum, ok, err = api.bridgeReader.EventTxnLookup(ctx, txHash)
if ok {
txNumNextBlock, err := txNumsReader.Min(tx, blockNum+1)
if err != nil {
return nil, err
}
txNum = txNumNextBlock
}
} else {
blockNum, ok, err = api._blockReader.EventLookup(ctx, tx, txHash)
}
Expand All @@ -864,7 +857,7 @@ func (api *TraceAPIImpl) ReplayTransaction(ctx context.Context, txHash libcommon
return nil, err
}

if txNumMin+2 > txNum {
if txNumMin+2 > txNum && !isBorStateSyncTxn {
return nil, fmt.Errorf("uint underflow txnums error txNum: %d, txNumMin: %d, blockNum: %d", txNum, txNumMin, blockNum)
}

Expand Down
9 changes: 1 addition & 8 deletions turbo/jsonrpc/trace_filtering.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,6 @@ func (api *TraceAPIImpl) Transaction(ctx context.Context, txHash common.Hash, ga
// otherwise this may be a bor state sync transaction - check
if api.useBridgeReader {
blockNumber, ok, err = api.bridgeReader.EventTxnLookup(ctx, txHash)
if ok {
txNumNextBlock, err := txNumsReader.Min(tx, blockNumber+1)
if err != nil {
return nil, err
}
txNum = txNumNextBlock
}
} else {
blockNumber, ok, err = api._blockReader.EventLookup(ctx, tx, txHash)
}
Expand All @@ -115,7 +108,7 @@ func (api *TraceAPIImpl) Transaction(ctx context.Context, txHash common.Hash, ga
return nil, err
}

if txNumMin+2 > txNum {
if txNumMin+2 > txNum && !isBorStateSyncTxn {
return nil, fmt.Errorf("uint underflow txnums error txNum: %d, txNumMin: %d, blockNum: %d", txNum, txNumMin, blockNumber)
}

Expand Down

0 comments on commit 200ddf7

Please sign in to comment.