Skip to content

Commit

Permalink
Create & use Blake3pow consensus engine instead of Ethash
Browse files Browse the repository at this point in the history
  • Loading branch information
wizeguyy committed Jan 25, 2023
1 parent e6dcf1e commit db0454c
Show file tree
Hide file tree
Showing 94 changed files with 2,492 additions and 643 deletions.
12 changes: 6 additions & 6 deletions accounts/abi/bind/backends/simulated.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
"github.com/spruce-solutions/go-quai/common"
"github.com/spruce-solutions/go-quai/common/hexutil"
"github.com/spruce-solutions/go-quai/common/math"
"github.com/spruce-solutions/go-quai/consensus/ethash"
"github.com/spruce-solutions/go-quai/consensus/blake3pow"
"github.com/spruce-solutions/go-quai/core"
"github.com/spruce-solutions/go-quai/core/bloombits"
"github.com/spruce-solutions/go-quai/core/rawdb"
Expand Down Expand Up @@ -76,9 +76,9 @@ type SimulatedBackend struct {
// and uses a simulated blockchain for testing purposes.
// A simulated backend always uses chainID 1337.
func NewSimulatedBackendWithDatabase(database ethdb.Database, alloc core.GenesisAlloc, gasLimit uint64) *SimulatedBackend {
genesis := core.Genesis{Config: params.AllEthashProtocolChanges, GasLimit: []uint64{gasLimit, gasLimit, gasLimit}, Alloc: alloc}
genesis := core.Genesis{Config: params.AllBlake3powProtocolChanges, GasLimit: []uint64{gasLimit, gasLimit, gasLimit}, Alloc: alloc}
genesis.MustCommit(database)
blockchain, _ := core.NewBlockChain(database, nil, genesis.Config, ethash.NewFaker(), vm.Config{}, nil, nil)
blockchain, _ := core.NewBlockChain(database, nil, genesis.Config, blake3pow.NewFaker(), vm.Config{}, nil, nil)

backend := &SimulatedBackend{
database: database,
Expand Down Expand Up @@ -126,7 +126,7 @@ func (b *SimulatedBackend) Rollback() {
}

func (b *SimulatedBackend) rollback(parent *types.Block) {
blocks, _ := core.GenerateChain(b.config, parent, ethash.NewFaker(), b.database, 1, func(int, *core.BlockGen) {})
blocks, _ := core.GenerateChain(b.config, parent, blake3pow.NewFaker(), b.database, 1, func(int, *core.BlockGen) {})

b.pendingBlock = blocks[0]
b.pendingState, _ = state.New(b.pendingBlock.Root(), b.blockchain.StateCache(), nil)
Expand Down Expand Up @@ -654,7 +654,7 @@ func (b *SimulatedBackend) SendTransaction(ctx context.Context, tx *types.Transa
panic(fmt.Errorf("invalid transaction nonce: got %d, want %d", tx.Nonce(), nonce))
}
// Include tx in chain
blocks, _ := core.GenerateChain(b.config, block, ethash.NewFaker(), b.database, 1, func(number int, block *core.BlockGen) {
blocks, _ := core.GenerateChain(b.config, block, blake3pow.NewFaker(), b.database, 1, func(number int, block *core.BlockGen) {
for _, tx := range b.pendingBlock.Transactions() {
block.AddTxWithChain(b.blockchain, tx)
}
Expand Down Expand Up @@ -772,7 +772,7 @@ func (b *SimulatedBackend) AdjustTime(adjustment time.Duration) error {
return errors.New("Could not adjust time on non-empty block")
}

blocks, _ := core.GenerateChain(b.config, b.blockchain.CurrentBlock(), ethash.NewFaker(), b.database, 1, func(number int, block *core.BlockGen) {
blocks, _ := core.GenerateChain(b.config, b.blockchain.CurrentBlock(), blake3pow.NewFaker(), b.database, 1, func(number int, block *core.BlockGen) {
block.OffsetTime(int64(adjustment.Seconds()))
})
stateDB, _ := b.blockchain.State()
Expand Down
8 changes: 4 additions & 4 deletions accounts/abi/bind/backends/simulated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,12 @@ func TestNewSimulatedBackend(t *testing.T) {
sim := simTestBackend(testAddr)
defer sim.Close()

if sim.config != params.AllEthashProtocolChanges {
t.Errorf("expected sim config to equal params.AllEthashProtocolChanges, got %v", sim.config)
if sim.config != params.AllBlake3powProtocolChanges {
t.Errorf("expected sim config to equal params.AllBlake3powProtocolChanges, got %v", sim.config)
}

if sim.blockchain.Config() != params.AllEthashProtocolChanges {
t.Errorf("expected sim blockchain config to equal params.AllEthashProtocolChanges, got %v", sim.config)
if sim.blockchain.Config() != params.AllBlake3powProtocolChanges {
t.Errorf("expected sim blockchain config to equal params.AllBlake3powProtocolChanges, got %v", sim.config)
}

stateDB, _ := sim.blockchain.State()
Expand Down
2 changes: 1 addition & 1 deletion build/update-license.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ var (
"cmd/internal/browser",
"common/bitutil/bitutil",
"common/prque/",
"consensus/ethash/xor.go",
"consensus/blake3pow/xor.go",
"crypto/bn256/",
"crypto/ecies/",
"graphql/graphiql.go",
Expand Down
5 changes: 2 additions & 3 deletions cmd/clef/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ import (
"strings"
"time"

"github.com/mattn/go-colorable"
"github.com/mattn/go-isatty"
"github.com/spruce-solutions/go-quai/accounts"
"github.com/spruce-solutions/go-quai/accounts/keystore"
"github.com/spruce-solutions/go-quai/cmd/utils"
Expand All @@ -54,8 +56,6 @@ import (
"github.com/spruce-solutions/go-quai/signer/fourbyte"
"github.com/spruce-solutions/go-quai/signer/rules"
"github.com/spruce-solutions/go-quai/signer/storage"
"github.com/mattn/go-colorable"
"github.com/mattn/go-isatty"
"gopkg.in/urfave/cli.v1"
)

Expand Down Expand Up @@ -882,7 +882,6 @@ func testExternalUI(api *core.SignerAPI) {
GasUsed: 1338,
Time: 1338,
Extra: []byte("Extra data Extra data Extra data Extra data Extra data Extra data Extra data Extra data"),
MixDigest: common.HexToHash("0x0000H45H"),
}
cliqueRlp, err := rlp.EncodeToBytes(cliqueHeader)
if err != nil {
Expand Down
1 change: 0 additions & 1 deletion cmd/devp2p/internal/ethtest/large.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ func randHash() common.Hash {

func largeHeader() *types.Header {
return &types.Header{
MixDigest: randHash(),
ReceiptHash: randHash(),
TxHash: randHash(),
Nonce: types.BlockNonce{},
Expand Down
2 changes: 1 addition & 1 deletion cmd/evm/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ func runCmd(ctx *cli.Context) error {
if chainConfig != nil {
runtimeConfig.ChainConfig = chainConfig
} else {
runtimeConfig.ChainConfig = params.AllEthashProtocolChanges
runtimeConfig.ChainConfig = params.AllBlake3powProtocolChanges
}

var hexInput []byte
Expand Down
2 changes: 1 addition & 1 deletion cmd/go-quai/consolecmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
)

const (
ipcAPIs = "admin:1.0 debug:1.0 eth:1.0 ethash:1.0 miner:1.0 net:1.0 personal:1.0 rpc:1.0 txpool:1.0 web3:1.0"
ipcAPIs = "admin:1.0 debug:1.0 eth:1.0 blake3pow:1.0 miner:1.0 net:1.0 personal:1.0 rpc:1.0 txpool:1.0 web3:1.0"
httpAPIs = "eth:1.0 net:1.0 rpc:1.0 web3:1.0"
)

Expand Down
10 changes: 0 additions & 10 deletions cmd/go-quai/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,6 @@ var (
utils.USBFlag,
utils.SmartCardDaemonPathFlag,
utils.OverrideLondonFlag,
utils.EthashCacheDirFlag,
utils.EthashCachesInMemoryFlag,
utils.EthashCachesOnDiskFlag,
utils.EthashCachesLockMmapFlag,
utils.EthashDatasetDirFlag,
utils.EthashDatasetsInMemoryFlag,
utils.EthashDatasetsOnDiskFlag,
utils.EthashDatasetsLockMmapFlag,
utils.TxPoolLocalsFlag,
utils.TxPoolNoLocalsFlag,
utils.TxPoolJournalFlag,
Expand Down Expand Up @@ -223,8 +215,6 @@ func init() {
attachCommand,
javascriptCommand,
// See misccmd.go:
makecacheCommand,
makedagCommand,
versionCommand,
versionCheckCommand,
licenseCommand,
Expand Down
58 changes: 0 additions & 58 deletions cmd/go-quai/misccmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@ import (
"fmt"
"os"
"runtime"
"strconv"
"strings"

"github.com/spruce-solutions/go-quai/cmd/utils"
"github.com/spruce-solutions/go-quai/consensus/ethash"
"github.com/spruce-solutions/go-quai/params"
"gopkg.in/urfave/cli.v1"
)
Expand All @@ -42,32 +40,6 @@ var (
params.VersionWithCommit(gitCommit, gitDate),
runtime.GOOS, runtime.GOARCH, runtime.Version()),
}
makecacheCommand = cli.Command{
Action: utils.MigrateFlags(makecache),
Name: "makecache",
Usage: "Generate ethash verification cache (for testing)",
ArgsUsage: "<blockNum> <outputDir>",
Category: "MISCELLANEOUS COMMANDS",
Description: `
The makecache command generates an ethash cache in <outputDir>.
This command exists to support the system testing project.
Regular users do not need to execute it.
`,
}
makedagCommand = cli.Command{
Action: utils.MigrateFlags(makedag),
Name: "makedag",
Usage: "Generate ethash mining DAG (for testing)",
ArgsUsage: "<blockNum> <outputDir>",
Category: "MISCELLANEOUS COMMANDS",
Description: `
The makedag command generates an ethash DAG in <outputDir>.
This command exists to support the system testing project.
Regular users do not need to execute it.
`,
}
versionCommand = cli.Command{
Action: utils.MigrateFlags(version),
Name: "version",
Expand Down Expand Up @@ -102,36 +74,6 @@ and displays information about any security vulnerabilities that affect the curr
}
)

// makecache generates an ethash verification cache into the provided folder.
func makecache(ctx *cli.Context) error {
args := ctx.Args()
if len(args) != 2 {
utils.Fatalf(`Usage: quai makecache <block number> <outputdir>`)
}
block, err := strconv.ParseUint(args[0], 0, 64)
if err != nil {
utils.Fatalf("Invalid block number: %v", err)
}
ethash.MakeCache(block, args[1])

return nil
}

// makedag generates an ethash mining DAG into the provided folder.
func makedag(ctx *cli.Context) error {
args := ctx.Args()
if len(args) != 2 {
utils.Fatalf(`Usage: quai makedag <block number> <outputdir>`)
}
block, err := strconv.ParseUint(args[0], 0, 64)
if err != nil {
utils.Fatalf("Invalid block number: %v", err)
}
ethash.MakeDataset(block, args[1])

return nil
}

func version(ctx *cli.Context) error {
fmt.Println(strings.Title(clientIdentifier))
fmt.Println("Version:", params.VersionWithMeta)
Expand Down
13 changes: 0 additions & 13 deletions cmd/go-quai/usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,19 +77,6 @@ var AppHelpFlagGroups = []flags.FlagGroup{
utils.DeveloperPeriodFlag,
},
},
{
Name: "ETHASH",
Flags: []cli.Flag{
utils.EthashCacheDirFlag,
utils.EthashCachesInMemoryFlag,
utils.EthashCachesOnDiskFlag,
utils.EthashCachesLockMmapFlag,
utils.EthashDatasetDirFlag,
utils.EthashDatasetsInMemoryFlag,
utils.EthashDatasetsOnDiskFlag,
utils.EthashDatasetsLockMmapFlag,
},
},
{
Name: "TRANSACTION POOL",
Flags: []cli.Flag{
Expand Down
46 changes: 23 additions & 23 deletions cmd/puppeth/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"github.com/spruce-solutions/go-quai/common"
"github.com/spruce-solutions/go-quai/common/hexutil"
math2 "github.com/spruce-solutions/go-quai/common/math"
"github.com/spruce-solutions/go-quai/consensus/ethash"
"github.com/spruce-solutions/go-quai/consensus/blake3pow"
"github.com/spruce-solutions/go-quai/core"
"github.com/spruce-solutions/go-quai/core/types"
"github.com/spruce-solutions/go-quai/params"
Expand Down Expand Up @@ -96,13 +96,13 @@ type alethGenesisSpecLinearPricing struct {
// newAlethGenesisSpec converts a go-ethereum genesis block into a Aleth-specific
// chain specification format.
func newAlethGenesisSpec(network string, genesis *core.Genesis) (*alethGenesisSpec, error) {
// Only ethash is currently supported between go-ethereum and aleth
if genesis.Config.Ethash == nil {
// Only blake3pow is currently supported between go-ethereum and aleth
if genesis.Config.Blake3pow == nil {
return nil, errors.New("unsupported consensus engine")
}
// Reconstruct the chain spec in Aleth format
spec := &alethGenesisSpec{
SealEngine: "Ethash",
SealEngine: "Blake3pow",
}
// Some defaults
spec.Params.AccountStartNonce = 0
Expand Down Expand Up @@ -144,7 +144,7 @@ func newAlethGenesisSpec(network string, genesis *core.Genesis) (*alethGenesisSp
spec.Params.DifficultyBoundDivisor = (*math2.HexOrDecimal256)(params.DifficultyBoundDivisor)
spec.Params.GasLimitBoundDivisor = (math2.HexOrDecimal64)(params.GasLimitBoundDivisor)
spec.Params.DurationLimit = (*math2.HexOrDecimal256)(params.DurationLimit)
spec.Params.BlockReward = (*hexutil.Big)(ethash.FrontierBlockReward)
spec.Params.BlockReward = (*hexutil.Big)(blake3pow.FrontierBlockReward)

spec.Genesis.Nonce() = types.EncodeNonce(genesis.Nonce())
spec.Genesis.MixHash = genesis.Mixhash
Expand Down Expand Up @@ -230,7 +230,7 @@ type parityChainSpec struct {
Name string `json:"name"`
Datadir string `json:"dataDir"`
Engine struct {
Ethash struct {
Blake3pow struct {
Params struct {
MinimumDifficulty *hexutil.Big `json:"minimumDifficulty"`
DifficultyBoundDivisor *hexutil.Big `json:"difficultyBoundDivisor"`
Expand All @@ -240,7 +240,7 @@ type parityChainSpec struct {
HomesteadTransition hexutil.Uint64 `json:"homesteadTransition"`
EIP100bTransition hexutil.Uint64 `json:"eip100bTransition"`
} `json:"params"`
} `json:"Ethash"`
} `json:"Blake3pow"`
} `json:"engine"`

Params struct {
Expand Down Expand Up @@ -364,8 +364,8 @@ type parityChainSpecVersionedPricing struct {
// newParityChainSpec converts a go-ethereum genesis block into a Parity specific
// chain specification format.
func newParityChainSpec(network string, genesis *core.Genesis, bootnodes []string) (*parityChainSpec, error) {
// Only ethash is currently supported between go-ethereum and Parity
if genesis.Config.Ethash == nil {
// Only blake3pow is currently supported between go-ethereum and Parity
if genesis.Config.Blake3pow == nil {
return nil, errors.New("unsupported consensus engine")
}
// Reconstruct the chain spec in Parity's format
Expand All @@ -374,16 +374,16 @@ func newParityChainSpec(network string, genesis *core.Genesis, bootnodes []strin
Nodes: bootnodes,
Datadir: strings.ToLower(network),
}
spec.Engine.Ethash.Params.BlockReward = make(map[string]string)
spec.Engine.Ethash.Params.DifficultyBombDelays = make(map[string]string)
spec.Engine.Blake3pow.Params.BlockReward = make(map[string]string)
spec.Engine.Blake3pow.Params.DifficultyBombDelays = make(map[string]string)
// Frontier
spec.Engine.Ethash.Params.MinimumDifficulty = (*hexutil.Big)(params.MinimumDifficulty)
spec.Engine.Ethash.Params.DifficultyBoundDivisor = (*hexutil.Big)(params.DifficultyBoundDivisor)
spec.Engine.Ethash.Params.DurationLimit = (*hexutil.Big)(params.DurationLimit)
spec.Engine.Ethash.Params.BlockReward["0x0"] = hexutil.EncodeBig(ethash.FrontierBlockReward)
spec.Engine.Blake3pow.Params.MinimumDifficulty = (*hexutil.Big)(params.MinimumDifficulty)
spec.Engine.Blake3pow.Params.DifficultyBoundDivisor = (*hexutil.Big)(params.DifficultyBoundDivisor)
spec.Engine.Blake3pow.Params.DurationLimit = (*hexutil.Big)(params.DurationLimit)
spec.Engine.Blake3pow.Params.BlockReward["0x0"] = hexutil.EncodeBig(blake3pow.FrontierBlockReward)

// Homestead
spec.Engine.Ethash.Params.HomesteadTransition = hexutil.Uint64(genesis.Config.HomesteadBlock.Uint64())
spec.Engine.Blake3pow.Params.HomesteadTransition = hexutil.Uint64(genesis.Config.HomesteadBlock.Uint64())

// Tangerine Whistle : 150
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-608.md
Expand Down Expand Up @@ -559,19 +559,19 @@ func (spec *parityChainSpec) setPrecompile(address byte, data *parityChainSpecBu
}

func (spec *parityChainSpec) setByzantium(num *big.Int) {
spec.Engine.Ethash.Params.BlockReward[hexutil.EncodeBig(num)] = hexutil.EncodeBig(ethash.ByzantiumBlockReward)
spec.Engine.Ethash.Params.DifficultyBombDelays[hexutil.EncodeBig(num)] = hexutil.EncodeUint64(3000000)
spec.Engine.Blake3pow.Params.BlockReward[hexutil.EncodeBig(num)] = hexutil.EncodeBig(blake3pow.ByzantiumBlockReward)
spec.Engine.Blake3pow.Params.DifficultyBombDelays[hexutil.EncodeBig(num)] = hexutil.EncodeUint64(3000000)
n := hexutil.Uint64(num.Uint64())
spec.Engine.Ethash.Params.EIP100bTransition = n
spec.Engine.Blake3pow.Params.EIP100bTransition = n
spec.Params.EIP140Transition = n
spec.Params.EIP211Transition = n
spec.Params.EIP214Transition = n
spec.Params.EIP658Transition = n
}

func (spec *parityChainSpec) setConstantinople(num *big.Int) {
spec.Engine.Ethash.Params.BlockReward[hexutil.EncodeBig(num)] = hexutil.EncodeBig(ethash.ConstantinopleBlockReward)
spec.Engine.Ethash.Params.DifficultyBombDelays[hexutil.EncodeBig(num)] = hexutil.EncodeUint64(2000000)
spec.Engine.Blake3pow.Params.BlockReward[hexutil.EncodeBig(num)] = hexutil.EncodeBig(blake3pow.ConstantinopleBlockReward)
spec.Engine.Blake3pow.Params.DifficultyBombDelays[hexutil.EncodeBig(num)] = hexutil.EncodeUint64(2000000)
n := hexutil.Uint64(num.Uint64())
spec.Params.EIP145Transition = n
spec.Params.EIP1014Transition = n
Expand Down Expand Up @@ -607,8 +607,8 @@ type pyEthereumGenesisSpec struct {
// newPyEthereumGenesisSpec converts a go-ethereum genesis block into a Parity specific
// chain specification format.
func newPyEthereumGenesisSpec(network string, genesis *core.Genesis) (*pyEthereumGenesisSpec, error) {
// Only ethash is currently supported between go-ethereum and pyethereum
if genesis.Config.Ethash == nil {
// Only blake3pow is currently supported between go-ethereum and pyethereum
if genesis.Config.Blake3pow == nil {
return nil, errors.New("unsupported consensus engine")
}
spec := &pyEthereumGenesisSpec{
Expand Down
Loading

0 comments on commit db0454c

Please sign in to comment.