Commit 1495f490 authored by George Hotz's avatar George Hotz

ugh, transactions are in the wrong order

parent 2d12be53
...@@ -40,8 +40,6 @@ func (db *Database) ContractCodeSize(addrHash common.Hash, codeHash common.Hash) ...@@ -40,8 +40,6 @@ func (db *Database) ContractCodeSize(addrHash common.Hash, codeHash common.Hash)
} }
func (db *Database) CopyTrie(trie Trie) Trie { func (db *Database) CopyTrie(trie Trie) Trie {
// TODO: this is wrong
//return trie
panic("don't copy tries") panic("don't copy tries")
} }
......
...@@ -26,9 +26,14 @@ func main() { ...@@ -26,9 +26,14 @@ func main() {
// non mips // non mips
if len(os.Args) > 1 { if len(os.Args) > 1 {
pkw := oracle.PreimageKeyValueWriter{}
pkwtrie := trie.NewStackTrie(pkw)
blockNumber, _ := strconv.Atoi(os.Args[1]) blockNumber, _ := strconv.Atoi(os.Args[1])
oracle.PrefetchBlock(big.NewInt(int64(blockNumber)), true, trie.NewStackTrie(nil)) oracle.PrefetchBlock(big.NewInt(int64(blockNumber)), true, nil)
oracle.PrefetchBlock(big.NewInt(int64(blockNumber)+1), false, trie.NewStackTrie(nil)) oracle.PrefetchBlock(big.NewInt(int64(blockNumber)+1), false, pkwtrie)
hash, err := pkwtrie.Commit()
fmt.Println("commited transactions", hash, err)
} }
// read start block header // read start block header
...@@ -59,14 +64,28 @@ func main() { ...@@ -59,14 +64,28 @@ func main() {
fmt.Println("made state processor") fmt.Println("made state processor")
// read txs // read txs
//traverseStackTrie(newheader.TxHash)
//fmt.Println(fn)
//fmt.Println(txTrieRoot)
var txs []*types.Transaction var txs []*types.Transaction
{
f, _ := os.Open(fmt.Sprintf("data/txs_%d", newheader.Number)) triedb := trie.NewDatabase(parent)
rlpheader := rlp.NewStream(f, 0) tt, _ := trie.New(newheader.TxHash, &triedb)
rlpheader.Decode(&txs) tni := tt.NodeIterator([]byte{})
f.Close() for tni.Next(true) {
fmt.Println(tni.Hash(), tni.Leaf(), tni.Path(), tni.Error())
if tni.Leaf() {
tx := types.Transaction{}
lerr := tx.UnmarshalBinary(tni.LeafBlob())
if lerr != nil {
log.Fatal(lerr)
}
txs = append(txs, &tx)
}
} }
fmt.Println("read", len(txs), "transactions") fmt.Println("read", len(txs), "transactions")
// TODO: OMG the transaction ordering isn't fixed
var uncles []*types.Header var uncles []*types.Header
var receipts []*types.Receipt var receipts []*types.Receipt
......
...@@ -80,5 +80,11 @@ func Preimage(hash common.Hash) []byte { ...@@ -80,5 +80,11 @@ func Preimage(hash common.Hash) []byte {
// these are stubs in embedded world // these are stubs in embedded world
func PrefetchStorage(*big.Int, common.Address, common.Hash, func(map[common.Hash][]byte)) {} func PrefetchStorage(*big.Int, common.Address, common.Hash, func(map[common.Hash][]byte)) {}
func PrefetchAccount(*big.Int, common.Address, func(map[common.Hash][]byte)) {} func PrefetchAccount(*big.Int, common.Address, func(map[common.Hash][]byte)) {}
func PrefetchCode(blockNumber *big.Int, addrHash common.Hash) {} func PrefetchCode(blockNumber *big.Int, addrHash common.Hash) {}
func PrefetchBlock(blockNumber *big.Int, startBlock bool, hasher types.TrieHasher) {} func PrefetchBlock(blockNumber *big.Int, startBlock bool, hasher types.TrieHasher) {}
// KeyValueWriter wraps the Put method of a backing data store.
type PreimageKeyValueWriter struct{}
func (kw PreimageKeyValueWriter) Put(key []byte, value []byte) error { return nil }
func (kw PreimageKeyValueWriter) Delete(key []byte) error { return nil }
...@@ -247,6 +247,7 @@ func PrefetchBlock(blockNumber *big.Int, startBlock bool, hasher types.TrieHashe ...@@ -247,6 +247,7 @@ func PrefetchBlock(blockNumber *big.Int, startBlock bool, hasher types.TrieHashe
txs := make([]*types.Transaction, len(jr.Result.Transactions)) txs := make([]*types.Transaction, len(jr.Result.Transactions))
for i := 0; i < len(jr.Result.Transactions); i++ { for i := 0; i < len(jr.Result.Transactions); i++ {
txs[i] = jr.Result.Transactions[i].ToTransaction() txs[i] = jr.Result.Transactions[i].ToTransaction()
fmt.Println("tx", i, "hash", txs[i].Hash())
} }
testTxHash := types.DeriveSha(types.Transactions(txs), hasher) testTxHash := types.DeriveSha(types.Transactions(txs), hasher)
if testTxHash != blockHeader.TxHash { if testTxHash != blockHeader.TxHash {
......
...@@ -8,6 +8,7 @@ import ( ...@@ -8,6 +8,7 @@ import (
"io/ioutil" "io/ioutil"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
) )
var preimages = make(map[common.Hash][]byte) var preimages = make(map[common.Hash][]byte)
...@@ -19,6 +20,10 @@ func Preimage(hash common.Hash) []byte { ...@@ -19,6 +20,10 @@ func Preimage(hash common.Hash) []byte {
if !ok { if !ok {
fmt.Println("can't find preimage", hash) fmt.Println("can't find preimage", hash)
} }
comphash := crypto.Keccak256Hash(val)
if hash != comphash {
panic("corruption in hash " + hash.String())
}
return val return val
} }
...@@ -26,3 +31,24 @@ func Preimage(hash common.Hash) []byte { ...@@ -26,3 +31,24 @@ func Preimage(hash common.Hash) []byte {
func Preimages() map[common.Hash][]byte { func Preimages() map[common.Hash][]byte {
return preimages return preimages
} }
// KeyValueWriter wraps the Put method of a backing data store.
type PreimageKeyValueWriter struct{}
// Put inserts the given value into the key-value data store.
func (kw PreimageKeyValueWriter) Put(key []byte, value []byte) error {
hash := crypto.Keccak256Hash(value)
if hash != common.BytesToHash(key) {
panic("bad preimage value write")
}
nval := make([]byte, len(value))
copy(nval, value)
preimages[hash] = nval
//fmt.Println("tx preimage", hash, common.Bytes2Hex(value))
return nil
}
// Delete removes the key from the key-value data store.
func (kw PreimageKeyValueWriter) Delete(key []byte) error {
return nil
}
...@@ -21,11 +21,13 @@ import ( ...@@ -21,11 +21,13 @@ import (
"bytes" "bytes"
"encoding/gob" "encoding/gob"
"errors" "errors"
"fmt"
"io" "io"
"sync" "sync"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/log"
//"github.com/ethereum/go-ethereum/log" //"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/rlp" "github.com/ethereum/go-ethereum/rlp"
...@@ -199,12 +201,12 @@ func (st *StackTrie) TryUpdate(key, value []byte) error { ...@@ -199,12 +201,12 @@ func (st *StackTrie) TryUpdate(key, value []byte) error {
func (st *StackTrie) Update(key, value []byte) { func (st *StackTrie) Update(key, value []byte) {
if err := st.TryUpdate(key, value); err != nil { if err := st.TryUpdate(key, value); err != nil {
//log.Error(fmt.Sprintf("Unhandled trie error: %v", err)) log.Error(fmt.Sprintf("Unhandled trie error: %v", err))
} }
} }
func (st *StackTrie) Reset() { func (st *StackTrie) Reset() {
st.db = nil //st.db = nil
st.key = st.key[:0] st.key = st.key[:0]
st.val = nil st.val = nil
for i := range st.children { for i := range st.children {
......
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