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

Context in SyncProgressBackend #421

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
14 changes: 7 additions & 7 deletions arbitrum/apibackend.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ func CreateFallbackClient(fallbackClientUrl string, fallbackClientTimeout time.D
}

type SyncProgressBackend interface {
SyncProgressMap() map[string]interface{}
BlockMetadataByNumber(blockNum uint64) (common.BlockMetadata, error)
SyncProgressMap(ctx context.Context) map[string]interface{}
BlockMetadataByNumber(ctx context.Context, blockNum uint64) (common.BlockMetadata, error)
}

func createRegisterAPIBackend(backend *Backend, filterConfig filters.Config, fallbackClientUrl string, fallbackClientTimeout time.Duration) (*filters.FilterSystem, error) {
Expand Down Expand Up @@ -205,17 +205,17 @@ func (a *APIBackend) GetBody(ctx context.Context, hash common.Hash, number rpc.B
}

// General Ethereum API
func (a *APIBackend) SyncProgressMap() map[string]interface{} {
func (a *APIBackend) SyncProgressMap(ctx context.Context) map[string]interface{} {
if a.sync == nil {
res := make(map[string]interface{})
res["error"] = "sync object not set in apibackend"
return res
}
return a.sync.SyncProgressMap()
return a.sync.SyncProgressMap(ctx)
}

func (a *APIBackend) SyncProgress() ethereum.SyncProgress {
progress := a.SyncProgressMap()
progress := a.SyncProgressMap(context.Background())

if len(progress) == 0 {
return ethereum.SyncProgress{}
Expand Down Expand Up @@ -496,8 +496,8 @@ func (a *APIBackend) BlockByNumberOrHash(ctx context.Context, blockNrOrHash rpc.
return nil, errors.New("invalid arguments; neither block nor hash specified")
}

func (a *APIBackend) BlockMetadataByNumber(blockNum uint64) (common.BlockMetadata, error) {
return a.sync.BlockMetadataByNumber(blockNum)
func (a *APIBackend) BlockMetadataByNumber(ctx context.Context, blockNum uint64) (common.BlockMetadata, error) {
return a.sync.BlockMetadataByNumber(ctx, blockNum)
}

func StateAndHeaderFromHeader(ctx context.Context, chainDb ethdb.Database, bc *core.BlockChain, maxRecreateStateDepth int64, header *types.Header, err error) (*state.StateDB, *types.Header, error) {
Expand Down
4 changes: 2 additions & 2 deletions eth/api_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ func (b *EthAPIBackend) BlockByNumberOrHash(ctx context.Context, blockNrOrHash r
return nil, errors.New("invalid arguments; neither block nor hash specified")
}

func (b *EthAPIBackend) BlockMetadataByNumber(blockNum uint64) (common.BlockMetadata, error) {
func (b *EthAPIBackend) BlockMetadataByNumber(ctx context.Context, blockNum uint64) (common.BlockMetadata, error) {
return nil, nil
}

Expand Down Expand Up @@ -353,7 +353,7 @@ func (b *EthAPIBackend) SubscribeNewTxsEvent(ch chan<- core.NewTxsEvent) event.S
return b.eth.txPool.SubscribeTransactions(ch, true)
}

func (b *EthAPIBackend) SyncProgressMap() map[string]interface{} {
func (b *EthAPIBackend) SyncProgressMap(ctx context.Context) map[string]interface{} {
progress := b.eth.Downloader().Progress()
return progress.ToMap()
}
Expand Down
6 changes: 3 additions & 3 deletions internal/ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ func (api *EthereumAPI) BlobBaseFee(ctx context.Context) *hexutil.Big {
// - highestBlock: block number of the highest block header this node has received from peers
// - pulledStates: number of state entries processed until now
// - knownStates: number of known state entries that still need to be pulled
func (api *EthereumAPI) Syncing() (interface{}, error) {
progress := api.b.SyncProgressMap()
func (api *EthereumAPI) Syncing(ctx context.Context) (interface{}, error) {
progress := api.b.SyncProgressMap(ctx)

if len(progress) == 0 {
return false, nil
Expand Down Expand Up @@ -2144,7 +2144,7 @@ func marshalReceipt(ctx context.Context, receipt *types.Receipt, blockHash commo

// If blockMetadata exists for the block containing this tx, then we will determine if it was timeboosted or not
// and add that info to the receipt object
blockMetadata, err := backend.BlockMetadataByNumber(blockNumber)
blockMetadata, err := backend.BlockMetadataByNumber(ctx, blockNumber)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions internal/ethapi/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ func (b testBackend) BlockByNumberOrHash(ctx context.Context, blockNrOrHash rpc.
}
panic("unknown type rpc.BlockNumberOrHash")
}
func (b testBackend) BlockMetadataByNumber(blockNum uint64) (common.BlockMetadata, error) {
func (b testBackend) BlockMetadataByNumber(ctx context.Context, blockNum uint64) (common.BlockMetadata, error) {
return nil, nil
}
func (b testBackend) GetBody(ctx context.Context, hash common.Hash, number rpc.BlockNumber) (*types.Body, error) {
Expand Down Expand Up @@ -636,7 +636,7 @@ func (b testBackend) FallbackClient() types.FallbackClient {
return nil
}

func (b testBackend) SyncProgressMap() map[string]interface{} {
func (b testBackend) SyncProgressMap(ctx context.Context) map[string]interface{} {
return map[string]interface{}{}
}

Expand Down
4 changes: 2 additions & 2 deletions internal/ethapi/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ type Backend interface {

// General Ethereum API
SyncProgress() ethereum.SyncProgress
SyncProgressMap() map[string]interface{}
SyncProgressMap(ctx context.Context) map[string]interface{}

SuggestGasTipCap(ctx context.Context) (*big.Int, error)
FeeHistory(ctx context.Context, blockCount uint64, lastBlock rpc.BlockNumber, rewardPercentiles []float64) (*big.Int, [][]*big.Int, []*big.Int, []float64, []*big.Int, []float64, error)
Expand All @@ -67,7 +67,7 @@ type Backend interface {
BlockByNumber(ctx context.Context, number rpc.BlockNumber) (*types.Block, error)
BlockByHash(ctx context.Context, hash common.Hash) (*types.Block, error)
BlockByNumberOrHash(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) (*types.Block, error)
BlockMetadataByNumber(blockNum uint64) (common.BlockMetadata, error) // This queries SyncProgressBackend (execution's syncMonitor) to fetch blockMetadata for a given block number
BlockMetadataByNumber(ctx context.Context, blockNum uint64) (common.BlockMetadata, error) // This queries SyncProgressBackend (execution's syncMonitor) to fetch blockMetadata for a given block number
StateAndHeaderByNumber(ctx context.Context, number rpc.BlockNumber) (*state.StateDB, *types.Header, error)
StateAndHeaderByNumberOrHash(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) (*state.StateDB, *types.Header, error)
Pending() (*types.Block, types.Receipts, *state.StateDB)
Expand Down
4 changes: 2 additions & 2 deletions internal/ethapi/transaction_args_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ func (b *backendMock) BlockByHash(ctx context.Context, hash common.Hash) (*types
func (b *backendMock) BlockByNumberOrHash(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) (*types.Block, error) {
return nil, nil
}
func (b *backendMock) BlockMetadataByNumber(blockNum uint64) (common.BlockMetadata, error) {
func (b *backendMock) BlockMetadataByNumber(ctx context.Context, blockNum uint64) (common.BlockMetadata, error) {
return nil, nil
}
func (b *backendMock) GetBody(ctx context.Context, hash common.Hash, number rpc.BlockNumber) (*types.Body, error) {
Expand Down Expand Up @@ -413,6 +413,6 @@ func (b *backendMock) FallbackClient() types.FallbackClient {
return nil
}

func (b *backendMock) SyncProgressMap() map[string]interface{} {
func (b *backendMock) SyncProgressMap(ctx context.Context) map[string]interface{} {
return nil
}
Loading