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

SyncProgress() fails unmarshalling in Geth v1.10.14 #24180

Closed
jclapis opened this issue Jan 3, 2022 · 0 comments · Fixed by #24199
Closed

SyncProgress() fails unmarshalling in Geth v1.10.14 #24180

jclapis opened this issue Jan 3, 2022 · 0 comments · Fixed by #24199
Assignees
Labels

Comments

@jclapis
Copy link

jclapis commented Jan 3, 2022

System information

Geth version:

  • Client: v1.10.14
  • Library: works in v1.10.13, fails in v1.10.14
    OS & Version: Linux x64 and ARM64

Expected behaviour

ethclient.Client.SyncProgress(context.Background()) should return a pointer to a populated ethereum.SyncProgress object.

Actual behaviour

The function returns the following error:
json: cannot unmarshal string into Go struct field SyncProgress.CurrentBlock of type uint64

This may be the same problem as #24176, though this report is for the current release (v1.10.14) and is part of the library itself regardless of mobile / desktop platform.

This was likely caused by the changes to ethclient/ethclient.go's unmarshaling code in #23576:
https://github.com/ethereum/go-ethereum/pull/23576/files#diff-1053ae80885a491cefa0ab360c605e7abbcec41fbb620c070a132c58a3bd6cac

Steps to reproduce the behaviour

Sample code:

package main

import (
	"context"
	"fmt"
	"os"

	"github.com/ethereum/go-ethereum/ethclient"
)

func main() {

    eth1Address := "http://localhost:8545"

    // Connect to ETH1
    ethClient, err := ethclient.Dial(eth1Address)
    if err != nil {
        fmt.Printf("Error connecting to ETH1 client on %s: %s\n", eth1Address, err.Error())
        os.Exit(1)
    }

    progress, err := ethClient.SyncProgress(context.Background())
    if err != nil {
        fmt.Printf("Error getting sync: %s\n", err.Error())
        os.Exit(1)
    }

    fmt.Println(progress)
    p := float64(progress.CurrentBlock - progress.StartingBlock) / float64(progress.HighestBlock - progress.StartingBlock)
    if p > 1 {
        p = 1
    } 
    
    fmt.Printf("Progress: %.2f\n", p)

}

Output when importing github.com/ethereum/[email protected]:

&{0 2199239 6133456 0 0}
Progress: 0.36

Output when importing github.com/ethereum/[email protected]:

Error getting sync: json: cannot unmarshal string into Go struct field SyncProgress.CurrentBlock of type uint64
@fjl fjl self-assigned this Jan 3, 2022
@fjl fjl closed this as completed in #24199 Jan 5, 2022
fjl added a commit that referenced this issue Jan 5, 2022
SyncProgress was modified in PR #23576 to add the fields reported for
snap sync. The PR also changed ethclient to use the SyncProgress struct
directly instead of wrapping it for hex-decoding. This broke the
SyncProgress method.

Fix it by putting back the custom wrapper. While here, also put back the
fast sync related fields because SyncProgress is stable API and thus
removing fields is not allowed.

Fixes #24180
Fixes #24176
sidhujag pushed a commit to syscoin/go-ethereum that referenced this issue Jan 6, 2022
SyncProgress was modified in PR ethereum#23576 to add the fields reported for
snap sync. The PR also changed ethclient to use the SyncProgress struct
directly instead of wrapping it for hex-decoding. This broke the
SyncProgress method.

Fix it by putting back the custom wrapper. While here, also put back the
fast sync related fields because SyncProgress is stable API and thus
removing fields is not allowed.

Fixes ethereum#24180
Fixes ethereum#24176
JacekGlen pushed a commit to JacekGlen/go-ethereum that referenced this issue May 26, 2022
SyncProgress was modified in PR ethereum#23576 to add the fields reported for
snap sync. The PR also changed ethclient to use the SyncProgress struct
directly instead of wrapping it for hex-decoding. This broke the
SyncProgress method.

Fix it by putting back the custom wrapper. While here, also put back the
fast sync related fields because SyncProgress is stable API and thus
removing fields is not allowed.

Fixes ethereum#24180
Fixes ethereum#24176
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants
@fjl @jclapis and others