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

Remove store getHeaderByNumber #900

Merged
merged 2 commits into from
Nov 11, 2022
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
9 changes: 0 additions & 9 deletions jsonrpc/eth_blockchain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -450,15 +450,6 @@ func (m *mockBlockStore) GetReceiptsByHash(hash types.Hash) ([]*types.Receipt, e
return receipts, nil
}

func (m *mockBlockStore) GetHeaderByNumber(blockNumber uint64) (*types.Header, bool) {
b, ok := m.GetBlockByNumber(blockNumber, false)
if !ok {
return nil, false
}

return b.Header, true
}

func (m *mockBlockStore) GetBlockByNumber(blockNumber uint64, full bool) (*types.Block, bool) {
for _, b := range m.blocks {
if b.Number() == blockNumber {
Expand Down
11 changes: 4 additions & 7 deletions jsonrpc/eth_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@ type ethBlockchainStore interface {
// Header returns the current header of the chain (genesis if empty)
Header() *types.Header

// GetHeaderByNumber returns the header by number
GetHeaderByNumber(block uint64) (*types.Header, bool)

// GetBlockByHash gets a block using the provided hash
GetBlockByHash(hash types.Hash, full bool) (*types.Block, bool)

Expand Down Expand Up @@ -779,24 +776,24 @@ func (e *Eth) getBlockHeader(number BlockNumber) (*types.Header, error) {
return e.store.Header(), nil

case EarliestBlockNumber:
header, ok := e.store.GetHeaderByNumber(uint64(0))
block, ok := e.store.GetBlockByNumber(uint64(0), false)
if !ok {
return nil, fmt.Errorf("error fetching genesis block header")
}

return header, nil
return block.Header, nil

case PendingBlockNumber:
return nil, fmt.Errorf("fetching the pending header is not supported")

default:
// Convert the block number from hex to uint64
header, ok := e.store.GetHeaderByNumber(uint64(number))
block, ok := e.store.GetBlockByNumber(uint64(number), false)
if !ok {
return nil, fmt.Errorf("error fetching block number %d header", uint64(number))
}

return header, nil
return block.Header, nil
}
}

Expand Down
4 changes: 2 additions & 2 deletions jsonrpc/eth_state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -792,12 +792,12 @@ func (m *mockSpecialStore) GetAccount(root types.Hash, addr types.Address) (*sta
return m.account.account, nil
}

func (m *mockSpecialStore) GetHeaderByNumber(blockNumber uint64) (*types.Header, bool) {
func (m *mockSpecialStore) GetBlockByNumber(blockNumber uint64, full bool) (*types.Block, bool) {
if m.block.Number() != blockNumber {
return nil, false
}

return m.block.Header, true
return m.block, true
}

func (m *mockSpecialStore) Header() *types.Header {
Expand Down
8 changes: 0 additions & 8 deletions jsonrpc/mocks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,6 @@ func (m *mockStore) SubscribeEvents() blockchain.Subscription {
return m.subscription
}

func (m *mockStore) GetHeaderByNumber(number uint64) (*types.Header, bool) {
header := m.headerLoop(func(header *types.Header) bool {
return header.Number == number
})

return header, header != nil
}

func (m *mockStore) GetBlockByHash(hash types.Hash, full bool) (*types.Block, bool) {
header := m.headerLoop(func(header *types.Header) bool {
return header.Hash == hash
Expand Down