Commit e7e3af9f authored by George Hotz's avatar George Hotz

fix 13284494

parent d04bfcc2
package core package core
import ( import (
"log"
"math/big"
"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/consensus/ethash"
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/oracle"
"github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rlp"
) )
type BlockChain struct { type BlockChain struct {
// TODO: write stub BlockChain // TODO: write stub BlockChain
chainConfig *params.ChainConfig // Chain & network configuration chainConfig *params.ChainConfig // Chain & network configuration
engine consensus.Engine engine consensus.Engine
lastBlock *types.Header
} }
func NewBlockChain() *BlockChain { func NewBlockChain(parent *types.Header) *BlockChain {
return &BlockChain{ return &BlockChain{
chainConfig: params.MainnetChainConfig, chainConfig: params.MainnetChainConfig,
engine: &ethash.Ethash{}, engine: &ethash.Ethash{},
lastBlock: parent,
} }
} }
...@@ -30,21 +37,36 @@ func (bc *BlockChain) Engine() consensus.Engine { return bc.engine } ...@@ -30,21 +37,36 @@ func (bc *BlockChain) Engine() consensus.Engine { return bc.engine }
// GetHeader retrieves a block header from the database by hash and number, // GetHeader retrieves a block header from the database by hash and number,
// caching it if found. // caching it if found.
func (bc *BlockChain) GetHeader(hash common.Hash, number uint64) *types.Header { func (bc *BlockChain) GetHeader(hash common.Hash, number uint64) *types.Header {
return nil if hash == bc.lastBlock.Hash() {
return bc.lastBlock
}
oracle.PrefetchBlock(big.NewInt(int64(number)), true, nil)
var ret types.Header
err := rlp.DecodeBytes(oracle.Preimage(hash), &ret)
if err != nil {
log.Fatal(err)
}
return &ret
} }
func (bc *BlockChain) CurrentHeader() *types.Header { func (bc *BlockChain) CurrentHeader() *types.Header {
return nil log.Fatal("CurrentHeader")
// this right?
return bc.lastBlock
} }
// GetHeaderByHash retrieves a block header from the database by hash, caching it if // GetHeaderByHash retrieves a block header from the database by hash, caching it if
// found. // found.
func (bc *BlockChain) GetHeaderByHash(hash common.Hash) *types.Header { func (bc *BlockChain) GetHeaderByHash(hash common.Hash) *types.Header {
log.Fatal("GetHeaderByHash", hash)
return nil return nil
} }
// GetHeaderByNumber retrieves a block header from the database by number, // GetHeaderByNumber retrieves a block header from the database by number,
// caching it (associated with its hash) if found. // caching it (associated with its hash) if found.
func (bc *BlockChain) GetHeaderByNumber(number uint64) *types.Header { func (bc *BlockChain) GetHeaderByNumber(number uint64) *types.Header {
log.Fatal("GetHeaderByNumber", number)
return nil return nil
} }
...@@ -61,7 +61,7 @@ func main() { ...@@ -61,7 +61,7 @@ func main() {
newheader.GasLimit = oracle.Input(4).Big().Uint64() newheader.GasLimit = oracle.Input(4).Big().Uint64()
newheader.Time = oracle.Input(5).Big().Uint64() newheader.Time = oracle.Input(5).Big().Uint64()
bc := core.NewBlockChain() bc := core.NewBlockChain(&parent)
database := state.NewDatabase(parent) database := state.NewDatabase(parent)
statedb, _ := state.New(parent.Root, database, nil) statedb, _ := state.New(parent.Root, database, nil)
vmconfig := vm.Config{} vmconfig := vm.Config{}
......
...@@ -269,7 +269,10 @@ func PrefetchBlock(blockNumber *big.Int, startBlock bool, hasher types.TrieHashe ...@@ -269,7 +269,10 @@ func PrefetchBlock(blockNumber *big.Int, startBlock bool, hasher types.TrieHashe
blockHeaderRlp, _ := rlp.EncodeToBytes(blockHeader) blockHeaderRlp, _ := rlp.EncodeToBytes(blockHeader)
hash := crypto.Keccak256Hash(blockHeaderRlp) hash := crypto.Keccak256Hash(blockHeaderRlp)
preimages[hash] = blockHeaderRlp preimages[hash] = blockHeaderRlp
emptyHash := common.Hash{}
if inputs[0] == emptyHash {
inputs[0] = hash inputs[0] = hash
}
return return
} }
......
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