Commit e7e3af9f authored by George Hotz's avatar George Hotz

fix 13284494

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