Commit 69b6305f authored by George Hotz's avatar George Hotz

simpler block, wrong root hash

parent 4da9923c
...@@ -99,8 +99,10 @@ async function getBlock(blockNumber: Number) { ...@@ -99,8 +99,10 @@ async function getBlock(blockNumber: Number) {
async function main() { async function main() {
await getBlock(13247501) /*await getBlock(13247501)
await getBlock(13247502) await getBlock(13247502)*/
await getBlock(13284053)
await getBlock(13284054)
} }
main().then(() => process.exit(0)) main().then(() => process.exit(0))
...@@ -354,8 +354,9 @@ func (s *stateObject) updateTrie(db Database) Trie { ...@@ -354,8 +354,9 @@ func (s *stateObject) updateTrie(db Database) Trie {
s.originStorage[key] = value s.originStorage[key] = value
var v []byte var v []byte
oracle.PrefetchAddress(db.BlockNumber, s.address, key)
if (value == common.Hash{}) { if (value == common.Hash{}) {
s.setError(tr.TryDelete(key[:])) //s.setError(tr.TryDelete(key[:]))
} else { } else {
// Encoding []byte cannot fail, ok to ignore the error. // Encoding []byte cannot fail, ok to ignore the error.
v, _ = rlp.EncodeToBytes(common.TrimLeftZeroes(value[:])) v, _ = rlp.EncodeToBytes(common.TrimLeftZeroes(value[:]))
......
...@@ -17,12 +17,21 @@ func main() { ...@@ -17,12 +17,21 @@ func main() {
// read header // read header
var header types.Header var header types.Header
{ {
f, _ := os.Open("data/block_13247501") f, _ := os.Open("data/block_13284053")
defer f.Close() defer f.Close()
rlpheader := rlp.NewStream(f, 0) rlpheader := rlp.NewStream(f, 0)
rlpheader.Decode(&header) rlpheader.Decode(&header)
} }
// read header
var newheader types.Header
{
f, _ := os.Open("data/block_13284054")
defer f.Close()
rlpheader := rlp.NewStream(f, 0)
rlpheader.Decode(&newheader)
}
bc := core.NewBlockChain() bc := core.NewBlockChain()
database := state.NewDatabase(header) database := state.NewDatabase(header)
statedb, _ := state.New(header.Root, database, nil) statedb, _ := state.New(header.Root, database, nil)
...@@ -33,7 +42,7 @@ func main() { ...@@ -33,7 +42,7 @@ func main() {
// read txs // read txs
var txs []*types.Transaction var txs []*types.Transaction
{ {
f, _ := os.Open("data/txs_13247502") f, _ := os.Open("data/txs_13284054")
defer f.Close() defer f.Close()
rlpheader := rlp.NewStream(f, 0) rlpheader := rlp.NewStream(f, 0)
rlpheader.Decode(&txs) rlpheader.Decode(&txs)
...@@ -53,8 +62,8 @@ func main() { ...@@ -53,8 +62,8 @@ func main() {
_, _, _, err := processor.Process(block, statedb, vmconfig) _, _, _, err := processor.Process(block, statedb, vmconfig)
fmt.Println(err) fmt.Println(err)
/*outHash, err := statedb.Commit(false) outHash, err := statedb.Commit(true)
fmt.Println(err) fmt.Println(err)
fmt.Println("process done with hash", outHash, header.Root)*/ fmt.Println("process done with hash", header.Root, "->", outHash, newheader.Root)
} }
...@@ -97,6 +97,7 @@ var preimages = make(map[common.Hash][]byte) ...@@ -97,6 +97,7 @@ var preimages = make(map[common.Hash][]byte)
func Preimage(hash common.Hash) []byte { func Preimage(hash common.Hash) []byte {
val, ok := preimages[hash] val, ok := preimages[hash]
if !ok { if !ok {
fmt.Println("can't find preimage", hash)
panic("preimage missing") panic("preimage missing")
} }
return val return val
...@@ -104,6 +105,7 @@ func Preimage(hash common.Hash) []byte { ...@@ -104,6 +105,7 @@ func Preimage(hash common.Hash) []byte {
func PrefetchAddress(blockNumber *big.Int, addr common.Address, skey common.Hash) { func PrefetchAddress(blockNumber *big.Int, addr common.Address, skey common.Hash) {
key := fmt.Sprintf("proof_%d_%s_%s", blockNumber, addr, skey) key := fmt.Sprintf("proof_%d_%s_%s", blockNumber, addr, skey)
fmt.Println("prefetch", key)
if cached[key] { if cached[key] {
//fmt.Println("hit", key) //fmt.Println("hit", key)
return return
......
...@@ -82,6 +82,7 @@ func (db *Database) Node(hash common.Hash) ([]byte, error) { ...@@ -82,6 +82,7 @@ func (db *Database) Node(hash common.Hash) ([]byte, error) {
// node retrieves a cached trie node from memory, or returns nil if none can be // node retrieves a cached trie node from memory, or returns nil if none can be
// found in the memory cache. // found in the memory cache.
func (db *Database) node(hash common.Hash) node { func (db *Database) node(hash common.Hash) node {
fmt.Println("node", hash)
return mustDecodeNode(hash[:], oracle.Preimage(hash)) return mustDecodeNode(hash[:], oracle.Preimage(hash))
} }
...@@ -90,4 +91,6 @@ func (db *Database) node(hash common.Hash) node { ...@@ -90,4 +91,6 @@ func (db *Database) node(hash common.Hash) node {
// All nodes inserted by this function will be reference tracked // All nodes inserted by this function will be reference tracked
// and in theory should only used for **trie nodes** insertion. // and in theory should only used for **trie nodes** insertion.
func (db *Database) insert(hash common.Hash, size int, node node) { func (db *Database) insert(hash common.Hash, size int, node node) {
//panic("insert")
//fmt.Println("insert", hash, size)
} }
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