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

temp fix eth_syncing #580

Merged
merged 1 commit into from
Dec 21, 2024
Merged
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
54 changes: 44 additions & 10 deletions turbo/jsonrpc/eth_system.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package jsonrpc

import (
"context"
"github.com/erigontech/erigon/eth/stagedsync/stages"
"math/big"

"github.com/erigontech/erigon-lib/chain"
Expand Down Expand Up @@ -49,27 +50,60 @@ func (api *APIImpl) BlockNumber(ctx context.Context) (hexutil.Uint64, error) {

// Syncing implements eth_syncing. Returns a data object detailing the status of the sync process or false if not syncing.
func (api *APIImpl) Syncing(ctx context.Context) (interface{}, error) {
reply, err := api.ethBackend.Syncing(ctx)
tx, err := api.db.BeginRo(ctx)
if err != nil {
return nil, err
}
defer tx.Rollback()
highestBlock, err := stages.GetStageProgress(tx, stages.Headers)
if err != nil {
return false, err
}
if !reply.Syncing {
return false, nil

currentBlock, err := stages.GetStageProgress(tx, stages.Finish)
if err != nil {
return false, err
}

// Still sync-ing, gather the block sync stats
highestBlock := reply.LastNewBlockSeen
currentBlock := reply.CurrentBlock
if currentBlock > 0 && currentBlock >= highestBlock {
return false, nil
} // Return not syncing if the synchronisation already completed

type S struct {
StageName string `json:"stage_name"`
BlockNumber hexutil.Uint64 `json:"block_number"`
}
stagesMap := make([]S, len(reply.Stages))
for i, stage := range reply.Stages {
stagesMap[i].StageName = stage.StageName
stagesMap[i].BlockNumber = hexutil.Uint64(stage.BlockNumber)
stagesMap := make([]S, len(stages.AllStages))
for i, stage := range stages.AllStages {
progress, err := stages.GetStageProgress(tx, stage)
if err != nil {
return nil, err
}
stagesMap[i].StageName = string(stage)
stagesMap[i].BlockNumber = hexutil.Uint64(progress)
}

//reply, err := api.ethBackend.Syncing(ctx)
//if err != nil {
// return false, err
//}
//if !reply.Syncing {
// return false, nil
//}
//
//// Still sync-ing, gather the block sync stats
//highestBlock := reply.LastNewBlockSeen
//currentBlock := reply.CurrentBlock
//type S struct {
// StageName string `json:"stage_name"`
// BlockNumber hexutil.Uint64 `json:"block_number"`
//}
//stagesMap := make([]S, len(reply.Stages))
//for i, stage := range reply.Stages {
// stagesMap[i].StageName = stage.StageName
// stagesMap[i].BlockNumber = hexutil.Uint64(stage.BlockNumber)
//}

return map[string]interface{}{
"startingBlock": "0x0", // 0x0 is a placeholder, I do not think it matters what we return here
"currentBlock": hexutil.Uint64(currentBlock),
Expand Down