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

Fix SeedHash API #1033

Merged
merged 2 commits into from
Aug 2, 2023
Merged
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
6 changes: 6 additions & 0 deletions consensus/progpow/algorithm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 0 additions & 5 deletions core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
5 changes: 0 additions & 5 deletions eth/api_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
11 changes: 2 additions & 9 deletions eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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)
}
Expand Down
8 changes: 2 additions & 6 deletions internal/quaiapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1518,11 +1519,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
Expand Down
1 change: 0 additions & 1 deletion internal/quaiapi/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading