Skip to content

Commit

Permalink
Merge branch 'main' of github.com:gattaca-com/based-op
Browse files Browse the repository at this point in the history
  • Loading branch information
louisponet committed Feb 11, 2025
2 parents 2968a1a + 5eb19f2 commit 16909d9
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 15 deletions.
4 changes: 4 additions & 0 deletions op-geth/eth/api_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -477,3 +477,7 @@ func (b *EthAPIBackend) HistoricalRPCService() *rpc.Client {
func (b *EthAPIBackend) Genesis() *types.Block {
return b.eth.blockchain.Genesis()
}

func (b *EthAPIBackend) GetUnsealedBlock() *types.UnsealedBlock {
return b.eth.blockchain.CurrentUnsealedBlock()
}
37 changes: 22 additions & 15 deletions op-geth/internal/ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,10 @@ func (api *BlockChainAPI) ChainId() *hexutil.Big {

// BlockNumber returns the block number of the chain head.
func (api *BlockChainAPI) BlockNumber() hexutil.Uint64 {
if unsealed := api.b.GetUnsealedBlock(); unsealed != nil {
return hexutil.Uint64(unsealed.Env.Number)
}

header, _ := api.b.HeaderByNumber(context.Background(), rpc.LatestBlockNumber) // latest header should always be available
return hexutil.Uint64(header.Number.Uint64())
}
Expand Down Expand Up @@ -1934,29 +1938,32 @@ func (api *TransactionAPI) GetRawTransactionByBlockHashAndIndex(ctx context.Cont
// GetTransactionCount returns the number of transactions the given address has sent for the given block number
func (api *TransactionAPI) GetTransactionCount(ctx context.Context, address common.Address, blockNrOrHash rpc.BlockNumberOrHash) (*hexutil.Uint64, error) {
// Ask transaction pool for the nonce which includes pending transactions
if blockNr, ok := blockNrOrHash.Number(); ok && blockNr == rpc.PendingBlockNumber {
blockNr, ok := blockNrOrHash.Number()
if ok && blockNr == rpc.PendingBlockNumber {
nonce, err := api.b.GetPoolNonce(ctx, address)
if err != nil {
return nil, err
}
return (*hexutil.Uint64)(&nonce), nil
}
// Resolve block number and use its state to ask for the nonce
header, err := headerByNumberOrHash(ctx, api.b, blockNrOrHash)
if err != nil {
return nil, err
}
if !ok || blockNr != rpc.LatestBlockNumber {
// Resolve block number and use its state to ask for the nonce
header, err := headerByNumberOrHash(ctx, api.b, blockNrOrHash)
if err != nil {
return nil, err
}

if api.b.ChainConfig().IsOptimismPreBedrock(header.Number) {
if api.b.HistoricalRPCService() != nil {
var res hexutil.Uint64
err := api.b.HistoricalRPCService().CallContext(ctx, &res, "eth_getTransactionCount", address, blockNrOrHash)
if err != nil {
return nil, fmt.Errorf("historical backend error: %w", err)
if api.b.ChainConfig().IsOptimismPreBedrock(header.Number) {
if api.b.HistoricalRPCService() != nil {
var res hexutil.Uint64
err := api.b.HistoricalRPCService().CallContext(ctx, &res, "eth_getTransactionCount", address, blockNrOrHash)
if err != nil {
return nil, fmt.Errorf("historical backend error: %w", err)
}
return &res, nil
} else {
return nil, rpc.ErrNoHistoricalFallback
}
return &res, nil
} else {
return nil, rpc.ErrNoHistoricalFallback
}
}

Expand Down
4 changes: 4 additions & 0 deletions op-geth/internal/ethapi/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -792,6 +792,10 @@ func (b testBackend) Genesis() *types.Block {
panic("implement me")
}

func (b testBackend) GetUnsealedBlock() *types.UnsealedBlock {
panic("implement me")
}

func TestEstimateGas(t *testing.T) {
t.Parallel()
// Initialize test accounts
Expand Down
3 changes: 3 additions & 0 deletions op-geth/internal/ethapi/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ type Backend interface {
SubscribeLogsEvent(ch chan<- []*types.Log) event.Subscription
BloomStatus() (uint64, uint64)
ServiceFilter(ctx context.Context, session *bloombits.MatcherSession)

// Frags
GetUnsealedBlock() *types.UnsealedBlock
}

func GetAPIs(apiBackend Backend) []rpc.API {
Expand Down
2 changes: 2 additions & 0 deletions op-geth/internal/ethapi/transaction_args_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,3 +407,5 @@ func (b *backendMock) SubscribeRemovedLogsEvent(ch chan<- core.RemovedLogsEvent)
func (b *backendMock) Engine() consensus.Engine { return nil }
func (b *backendMock) HistoricalRPCService() *rpc.Client { return nil }
func (b *backendMock) Genesis() *types.Block { return nil }

func (b *backendMock) GetUnsealedBlock() *types.UnsealedBlock { return nil }

0 comments on commit 16909d9

Please sign in to comment.