Commit 25d67c04 authored by George Hotz's avatar George Hotz

fix uncle support

parent add9a4ee
...@@ -17,9 +17,11 @@ jobs: ...@@ -17,9 +17,11 @@ jobs:
run: | run: |
(cd minigeth/ && go build) (cd minigeth/ && go build)
mkdir -p /tmp/eth mkdir -p /tmp/eth
- name: Test block 13284491 - name: Test block 13284491 (0 tx)
run: minigeth/go-ethereum 13284491 run: minigeth/go-ethereum 13284491
- name: Test block 13284469 - name: Test block 13284469 (few tx)
run: minigeth/go-ethereum 13284469 run: minigeth/go-ethereum 13284469
- name: Test block 13284053 - name: Test block 13284053 (deletion)
run: minigeth/go-ethereum 13284053 run: minigeth/go-ethereum 13284053
\ No newline at end of file - name: Test block 13303075 (uncles)
run: minigeth/go-ethereum 13303075
\ No newline at end of file
...@@ -27,15 +27,7 @@ import ( ...@@ -27,15 +27,7 @@ import (
"github.com/ethereum/go-ethereum/core/vm" "github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/params"
/*"fmt" )
"math/big"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/consensus"
"github.com/ethereum/go-ethereum/consensus/misc"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/params"*/)
// StateProcessor is a basic Processor, which takes care of transitioning // StateProcessor is a basic Processor, which takes care of transitioning
// state from one point to another. // state from one point to another.
......
...@@ -96,6 +96,8 @@ func main() { ...@@ -96,6 +96,8 @@ func main() {
// TODO: OMG the transaction ordering isn't fixed // TODO: OMG the transaction ordering isn't fixed
var uncles []*types.Header var uncles []*types.Header
check(rlp.DecodeBytes(oracle.Preimage(newheader.UncleHash), &uncles))
var receipts []*types.Receipt var receipts []*types.Receipt
block := types.NewBlock(&newheader, txs, uncles, receipts, trie.NewStackTrie(nil)) block := types.NewBlock(&newheader, txs, uncles, receipts, trie.NewStackTrie(nil))
fmt.Println("made block, parent:", newheader.ParentHash) fmt.Println("made block, parent:", newheader.ParentHash)
...@@ -106,7 +108,7 @@ func main() { ...@@ -106,7 +108,7 @@ func main() {
panic("wrong transactions for block") panic("wrong transactions for block")
} }
if newheader.UncleHash != block.Header().UncleHash { if newheader.UncleHash != block.Header().UncleHash {
panic("wrong uncles for block") panic("wrong uncles for block " + newheader.UncleHash.String() + " " + block.Header().UncleHash.String())
} }
_, _, _, err := processor.Process(block, statedb, vmconfig) _, _, _, err := processor.Process(block, statedb, vmconfig)
......
...@@ -41,6 +41,12 @@ type jsonresps struct { ...@@ -41,6 +41,12 @@ type jsonresps struct {
Result string `json:"result"` Result string `json:"result"`
} }
type jsonrespi struct {
Jsonrpc string `json:"jsonrpc"`
Id uint64 `json:"id"`
Result hexutil.Uint64 `json:"result"`
}
type jsonrespt struct { type jsonrespt struct {
Jsonrpc string `json:"jsonrpc"` Jsonrpc string `json:"jsonrpc"`
Id uint64 `json:"id"` Id uint64 `json:"id"`
...@@ -196,6 +202,53 @@ func Output(output common.Hash) { ...@@ -196,6 +202,53 @@ func Output(output common.Hash) {
} }
} }
func check(err error) {
if err != nil {
log.Fatal(err)
}
}
func prefetchUncles(blockHash common.Hash, uncleHash common.Hash, hasher types.TrieHasher) {
jr := jsonrespi{}
{
r := jsonreq{Jsonrpc: "2.0", Method: "eth_getUncleCountByBlockHash", Id: 1}
r.Params = make([]interface{}, 1)
r.Params[0] = blockHash.Hex()
jsonData, _ := json.Marshal(r)
check(json.NewDecoder(getAPI(jsonData)).Decode(&jr))
}
var uncles []*types.Header
for u := 0; u < int(jr.Result); u++ {
jr2 := jsonrespt{}
{
r := jsonreq{Jsonrpc: "2.0", Method: "eth_getUncleByBlockHashAndIndex", Id: 1}
r.Params = make([]interface{}, 2)
r.Params[0] = blockHash.Hex()
r.Params[1] = fmt.Sprintf("0x%x", u)
jsonData, _ := json.Marshal(r)
/*a, _ := ioutil.ReadAll(getAPI(jsonData))
fmt.Println(string(a))*/
check(json.NewDecoder(getAPI(jsonData)).Decode(&jr2))
}
uncleHeader := jr2.Result.ToHeader()
uncles = append(uncles, &uncleHeader)
//fmt.Println(uncleHeader)
//fmt.Println(jr2.Result)
}
unclesRlp, _ := rlp.EncodeToBytes(uncles)
hash := crypto.Keccak256Hash(unclesRlp)
if hash != uncleHash {
panic("wrong uncle hash")
}
preimages[hash] = unclesRlp
}
func PrefetchBlock(blockNumber *big.Int, startBlock bool, hasher types.TrieHasher) { func PrefetchBlock(blockNumber *big.Int, startBlock bool, hasher types.TrieHasher) {
r := jsonreq{Jsonrpc: "2.0", Method: "eth_getBlockByNumber", Id: 1} r := jsonreq{Jsonrpc: "2.0", Method: "eth_getBlockByNumber", Id: 1}
r.Params = make([]interface{}, 2) r.Params = make([]interface{}, 2)
...@@ -207,10 +260,7 @@ func PrefetchBlock(blockNumber *big.Int, startBlock bool, hasher types.TrieHashe ...@@ -207,10 +260,7 @@ func PrefetchBlock(blockNumber *big.Int, startBlock bool, hasher types.TrieHashe
fmt.Println(string(dat))*/ fmt.Println(string(dat))*/
jr := jsonrespt{} jr := jsonrespt{}
err := json.NewDecoder(getAPI(jsonData)).Decode(&jr) check(json.NewDecoder(getAPI(jsonData)).Decode(&jr))
if err != nil {
log.Fatal(err)
}
//fmt.Println(jr.Result) //fmt.Println(jr.Result)
blockHeader := jr.Result.ToHeader() blockHeader := jr.Result.ToHeader()
...@@ -245,10 +295,10 @@ func PrefetchBlock(blockNumber *big.Int, startBlock bool, hasher types.TrieHashe ...@@ -245,10 +295,10 @@ func PrefetchBlock(blockNumber *big.Int, startBlock bool, hasher types.TrieHashe
key := fmt.Sprintf("/tmp/eth/%d", blockNumber.Uint64()-1) key := fmt.Sprintf("/tmp/eth/%d", blockNumber.Uint64()-1)
ioutil.WriteFile(key, saveinput, 0644) ioutil.WriteFile(key, saveinput, 0644)
// save the txs
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 {
...@@ -256,14 +306,8 @@ func PrefetchBlock(blockNumber *big.Int, startBlock bool, hasher types.TrieHashe ...@@ -256,14 +306,8 @@ func PrefetchBlock(blockNumber *big.Int, startBlock bool, hasher types.TrieHashe
panic("tx hash derived wrong") panic("tx hash derived wrong")
} }
// put in transaction trie // save the uncles
prefetchUncles(blockHeader.Hash(), blockHeader.UncleHash, hasher)
//return blockHeader, txs
/*var uncles []*types.Header
var receipts []*types.Receipt
block := types.NewBlock(&blockHeader, txs, uncles, receipts, trie.NewStackTrie(nil))*/
} }
func getProofAccount(blockNumber *big.Int, addr common.Address, skey common.Hash, storage bool) []string { func getProofAccount(blockNumber *big.Int, addr common.Address, skey common.Hash, storage bool) []string {
......
...@@ -5,5 +5,11 @@ mkdir -p /tmp/eth ...@@ -5,5 +5,11 @@ mkdir -p /tmp/eth
# 0 tx: 13284491 # 0 tx: 13284491
# low tx: 13284469 # low tx: 13284469
# delete issue: 13284053 # delete issue: 13284053
minigeth/go-ethereum 13284469 if [ $# -eq 0 ]; then
BLOCK=13284469
else
BLOCK=$1
fi
minigeth/go-ethereum $BLOCK
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