Commit e10286b5 authored by George Hotz's avatar George Hotz

add fake ethash

parent 5be4ecb4
package ethash
import (
"math/big"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/consensus"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/types"
)
type Ethash struct {
/*Author
Finalize*/
}
func (ethash *Ethash) Author(header *types.Header) (common.Address, error) {
return header.Coinbase, nil
}
func (ethash *Ethash) CalcDifficulty(chain consensus.ChainHeaderReader, time uint64, parent *types.Header) *big.Int {
return nil
}
func (ethash *Ethash) Close() error {
return nil
}
func (ethash *Ethash) Finalize(chain consensus.ChainHeaderReader, header *types.Header, state *state.StateDB, txs []*types.Transaction, uncles []*types.Header) {
}
func (ethash *Ethash) FinalizeAndAssemble(chain consensus.ChainHeaderReader, header *types.Header, state *state.StateDB, txs []*types.Transaction, uncles []*types.Header, receipts []*types.Receipt) (*types.Block, error) {
return nil, nil
}
func (ethash *Ethash) Prepare(chain consensus.ChainHeaderReader, header *types.Header) error {
return nil
}
func (ethash *Ethash) Seal(chain consensus.ChainHeaderReader, block *types.Block, results chan<- *types.Block, stop <-chan struct{}) error {
return nil
}
func (ethash *Ethash) SealHash(header *types.Header) (hash common.Hash) {
return common.Hash{}
}
func (ethash *Ethash) VerifyHeader(chain consensus.ChainHeaderReader, header *types.Header, seal bool) error {
return nil
}
func (ethash *Ethash) VerifyHeaders(chain consensus.ChainHeaderReader, headers []*types.Header, seals []bool) (chan<- struct{}, <-chan error) {
return nil, nil
}
func (ethash *Ethash) VerifyUncles(chain consensus.ChainReader, block *types.Block) error {
return nil
}
...@@ -3,6 +3,7 @@ package core ...@@ -3,6 +3,7 @@ package core
import ( import (
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/consensus" "github.com/ethereum/go-ethereum/consensus"
"github.com/ethereum/go-ethereum/consensus/ethash"
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/params"
) )
...@@ -13,6 +14,10 @@ type BlockChain struct { ...@@ -13,6 +14,10 @@ type BlockChain struct {
engine consensus.Engine engine consensus.Engine
} }
func NewBlockChain() *BlockChain {
return &BlockChain{engine: &ethash.Ethash{}}
}
// Config retrieves the chain's fork configuration. // Config retrieves the chain's fork configuration.
func (bc *BlockChain) Config() *params.ChainConfig { return bc.chainConfig } func (bc *BlockChain) Config() *params.ChainConfig { return bc.chainConfig }
......
...@@ -48,6 +48,7 @@ func NewEVMBlockContext(header *types.Header, chain ChainContext, author *common ...@@ -48,6 +48,7 @@ func NewEVMBlockContext(header *types.Header, chain ChainContext, author *common
} else { } else {
beneficiary = *author beneficiary = *author
} }
if header.BaseFee != nil { if header.BaseFee != nil {
baseFee = new(big.Int).Set(header.BaseFee) baseFee = new(big.Int).Set(header.BaseFee)
} }
......
...@@ -4,6 +4,7 @@ import ( ...@@ -4,6 +4,7 @@ import (
"fmt" "fmt"
"os" "os"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/state" "github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
...@@ -12,20 +13,29 @@ import ( ...@@ -12,20 +13,29 @@ import (
"github.com/ethereum/go-ethereum/rlp" "github.com/ethereum/go-ethereum/rlp"
) )
type DumbEngine struct {
/*Author
Finalize*/
}
func (ethash *DumbEngine) Author(header *types.Header) (common.Address, error) {
return header.Coinbase, nil
}
func main() { func main() {
bc := &core.BlockChain{} bc := core.NewBlockChain()
//engine := ethash.NewFullFaker()
statedb := &state.StateDB{} statedb := &state.StateDB{}
vmconfig := vm.Config{} vmconfig := vm.Config{}
processor := core.NewStateProcessor(params.MainnetChainConfig, bc, nil) processor := core.NewStateProcessor(params.MainnetChainConfig, bc, nil)
fmt.Println("made state processor") fmt.Println("made state processor")
f, _ := os.Open("../data/block_block_13247502") f, _ := os.Open("../data/block_13247502")
defer f.Close() defer f.Close()
var header types.Header
block := &types.Block{} rlpheader := rlp.NewStream(f, 0)
block.DecodeRLP(rlp.NewStream(f, 0)) rlpheader.Decode(&header)
fmt.Println("read block RLP") block := types.NewBlockWithHeader(&header)
fmt.Println("made block, parent:", header.ParentHash)
processor.Process(block, statedb, vmconfig) processor.Process(block, statedb, vmconfig)
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment