Skip to content

Commit

Permalink
Merge pull request #580 from blxdyx/fix_eth_syncing
Browse files Browse the repository at this point in the history
temp fix eth_syncing
  • Loading branch information
blxdyx authored Dec 21, 2024
2 parents 84d8422 + 4dc33bf commit 9c19e6b
Showing 1 changed file with 44 additions and 10 deletions.
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

0 comments on commit 9c19e6b

Please sign in to comment.