From 1df6211183ac5f2ec888c01f1bbd88ad11b3a24c Mon Sep 17 00:00:00 2001 From: Jonathan Downing Date: Wed, 2 Aug 2023 15:54:32 -0500 Subject: [PATCH 1/2] Remove SetHead from API and Core --- core/core.go | 5 ----- eth/api_backend.go | 5 ----- eth/backend.go | 11 ++--------- internal/quaiapi/api.go | 5 ----- internal/quaiapi/backend.go | 1 - 5 files changed, 2 insertions(+), 25 deletions(-) diff --git a/core/core.go b/core/core.go index ba014d3adf..9a8d863a71 100644 --- a/core/core.go +++ b/core/core.go @@ -567,11 +567,6 @@ func (c *Core) Snapshots() *snapshot.Tree { return nil } -// this needs to be implemented, it is being used by a lot of modules -func (c *Core) SetHead(number uint64) error { - return nil -} - func (c *Core) TxLookupLimit() uint64 { return 0 } diff --git a/eth/api_backend.go b/eth/api_backend.go index 383b5bca04..62651aef32 100644 --- a/eth/api_backend.go +++ b/eth/api_backend.go @@ -78,11 +78,6 @@ func (b *QuaiAPIBackend) CalcOrder(header *types.Header) (*big.Int, int, error) return b.eth.core.CalcOrder(header) } -func (b *QuaiAPIBackend) SetHead(number uint64) { - b.eth.handler.downloader.Cancel() - b.eth.core.SetHead(number) -} - func (b *QuaiAPIBackend) HeaderByNumber(ctx context.Context, number rpc.BlockNumber) (*types.Header, error) { // Pending block is only known by the miner if number == rpc.PendingBlockNumber { diff --git a/eth/backend.go b/eth/backend.go index 6e917ed410..2c7b3d1b41 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -114,8 +114,8 @@ func New(stack *node.Node, config *ethconfig.Config) (*Quai, error) { if err != nil { return nil, err } - chainConfig, genesisHash, genesisErr := core.SetupGenesisBlockWithOverride(chainDb, config.Genesis) - if _, ok := genesisErr.(*params.ConfigCompatError); genesisErr != nil && !ok { + chainConfig, _, genesisErr := core.SetupGenesisBlockWithOverride(chainDb, config.Genesis) + if genesisErr != nil { return nil, genesisErr } @@ -181,13 +181,6 @@ func New(stack *node.Node, config *ethconfig.Config) (*Quai, error) { } ) - // Rewind the chain in case of an incompatible config upgrade. - if compat, ok := genesisErr.(*params.ConfigCompatError); ok { - log.Warn("Rewinding chain to upgrade configuration", "err", compat) - eth.core.SetHead(compat.RewindTo) - rawdb.WriteChainConfig(chainDb, genesisHash, chainConfig) - } - if config.TxPool.Journal != "" { config.TxPool.Journal = stack.ResolvePath(config.TxPool.Journal) } diff --git a/internal/quaiapi/api.go b/internal/quaiapi/api.go index 5d1ae8ea59..a51710decc 100644 --- a/internal/quaiapi/api.go +++ b/internal/quaiapi/api.go @@ -1518,11 +1518,6 @@ func (api *PrivateDebugAPI) ChaindbCompact() error { return nil } -// SetHead rewinds the head of the blockchain to a previous block. -func (api *PrivateDebugAPI) SetHead(number hexutil.Uint64) { - api.b.SetHead(uint64(number)) -} - // PublicNetAPI offers network related RPC methods type PublicNetAPI struct { net *p2p.Server diff --git a/internal/quaiapi/backend.go b/internal/quaiapi/backend.go index 2f3ca75316..914aa57661 100644 --- a/internal/quaiapi/backend.go +++ b/internal/quaiapi/backend.go @@ -53,7 +53,6 @@ type Backend interface { RPCTxFeeCap() float64 // global tx fee cap for all transaction related APIs // Blockchain API - SetHead(number uint64) HeaderByNumber(ctx context.Context, number rpc.BlockNumber) (*types.Header, error) HeaderByHash(ctx context.Context, hash common.Hash) (*types.Header, error) HeaderByNumberOrHash(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) (*types.Header, error) From e47b5245caee9e80254f647c8df614651de77cad Mon Sep 17 00:00:00 2001 From: Jonathan Downing Date: Wed, 2 Aug 2023 16:27:55 -0500 Subject: [PATCH 2/2] SeedHash API now returns proper progpow seedhash --- consensus/progpow/algorithm.go | 6 ++++++ internal/quaiapi/api.go | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/consensus/progpow/algorithm.go b/consensus/progpow/algorithm.go index ba8ac6c21a..6048c0f6cb 100644 --- a/consensus/progpow/algorithm.go +++ b/consensus/progpow/algorithm.go @@ -130,6 +130,12 @@ func seedHash(block uint64) []byte { return seed } +// SeedHash is the seed to use for generating a verification cache and the mining +// dataset. +func SeedHash(block uint64) []byte { + return seedHash(block) +} + // generateCache creates a verification cache of a given size for an input seed. // The cache production process involves first sequentially filling up 32 MB of // memory, then performing two passes of Sergio Demian Lerner's RandMemoHash diff --git a/internal/quaiapi/api.go b/internal/quaiapi/api.go index a51710decc..439a854edb 100644 --- a/internal/quaiapi/api.go +++ b/internal/quaiapi/api.go @@ -29,6 +29,7 @@ import ( "github.com/dominant-strategies/go-quai/common/hexutil" "github.com/dominant-strategies/go-quai/common/math" "github.com/dominant-strategies/go-quai/consensus/misc" + "github.com/dominant-strategies/go-quai/consensus/progpow" "github.com/dominant-strategies/go-quai/core" "github.com/dominant-strategies/go-quai/core/state" "github.com/dominant-strategies/go-quai/core/types" @@ -1480,7 +1481,7 @@ func (api *PublicDebugAPI) SeedHash(ctx context.Context, number uint64) (string, if block == nil { return "", fmt.Errorf("block #%d not found", number) } - return "", fmt.Errorf("progpow does not have seedhash") + return fmt.Sprintf("0x%x", progpow.SeedHash(number)), nil } // PrivateDebugAPI is the collection of Quai APIs exposed over the private