Commit 8f3a0989 authored by George Hotz's avatar George Hotz

fix transaction order

parent 1495f490
...@@ -20,6 +20,12 @@ import ( ...@@ -20,6 +20,12 @@ import (
"github.com/ethereum/go-ethereum/trie" "github.com/ethereum/go-ethereum/trie"
) )
func check(err error) {
if err != nil {
log.Fatal(err)
}
}
func main() { func main() {
// init secp256k1BytePoints // init secp256k1BytePoints
crypto.S256() crypto.S256()
...@@ -38,10 +44,7 @@ func main() { ...@@ -38,10 +44,7 @@ func main() {
// read start block header // read start block header
var parent types.Header var parent types.Header
rlperr := rlp.DecodeBytes(oracle.Preimage(oracle.Input(0)), &parent) check(rlp.DecodeBytes(oracle.Preimage(oracle.Input(0)), &parent))
if rlperr != nil {
log.Fatal(rlperr)
}
// read header // read header
var newheader types.Header var newheader types.Header
...@@ -74,14 +77,17 @@ func main() { ...@@ -74,14 +77,17 @@ func main() {
tt, _ := trie.New(newheader.TxHash, &triedb) tt, _ := trie.New(newheader.TxHash, &triedb)
tni := tt.NodeIterator([]byte{}) tni := tt.NodeIterator([]byte{})
for tni.Next(true) { for tni.Next(true) {
fmt.Println(tni.Hash(), tni.Leaf(), tni.Path(), tni.Error()) //fmt.Println(tni.Hash(), tni.Leaf(), tni.Path(), tni.Error())
if tni.Leaf() { if tni.Leaf() {
tx := types.Transaction{} tx := types.Transaction{}
lerr := tx.UnmarshalBinary(tni.LeafBlob()) var rlpKey uint64
if lerr != nil { check(rlp.DecodeBytes(tni.LeafKey(), &rlpKey))
log.Fatal(lerr) check(tx.UnmarshalBinary(tni.LeafBlob()))
// TODO: resize an array in go?
for uint64(len(txs)) <= rlpKey {
txs = append(txs, nil)
} }
txs = append(txs, &tx) txs[rlpKey] = &tx
} }
} }
fmt.Println("read", len(txs), "transactions") fmt.Println("read", len(txs), "transactions")
......
...@@ -247,7 +247,7 @@ func PrefetchBlock(blockNumber *big.Int, startBlock bool, hasher types.TrieHashe ...@@ -247,7 +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()) //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 {
......
...@@ -41,9 +41,7 @@ func (kw PreimageKeyValueWriter) Put(key []byte, value []byte) error { ...@@ -41,9 +41,7 @@ func (kw PreimageKeyValueWriter) Put(key []byte, value []byte) error {
if hash != common.BytesToHash(key) { if hash != common.BytesToHash(key) {
panic("bad preimage value write") panic("bad preimage value write")
} }
nval := make([]byte, len(value)) preimages[hash] = common.CopyBytes(value)
copy(nval, value)
preimages[hash] = nval
//fmt.Println("tx preimage", hash, common.Bytes2Hex(value)) //fmt.Println("tx preimage", hash, common.Bytes2Hex(value))
return nil return nil
} }
......
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