erigon-pulse/turbo/trie/hack.go

129 lines
287 KiB
Go
Raw Normal View History

package trie
import (
"fmt"
"github.com/ledgerwatch/erigon/common"
"github.com/ledgerwatch/erigon/rlp"
)
func FullNode1() {
f := &fullNode{}
b, err := rlp.EncodeToBytes(f)
if err != nil {
panic(err)
}
fmt.Printf("FullNode1 %x\n", b)
}
func FullNode2() {
f := &fullNode{}
f.Children[0] = valueNode(nil)
b, err := rlp.EncodeToBytes(f)
if err != nil {
panic(err)
}
fmt.Printf("FullNode2 %x\n", b)
}
func FullNode3() {
f := &fullNode{}
f.Children[0] = valueNode(nil)
h := common.Hash{}
f.Children[1] = hashNode{hash: h[:]}
b, err := rlp.EncodeToBytes(f)
if err != nil {
panic(err)
}
fmt.Printf("FullNode3 %x\n", b)
}
func FullNode4() {
f := &fullNode{}
h := common.Hash{}
for i := 0; i < 17; i++ {
f.Children[i] = hashNode{hash: h[:]}
}
b, err := rlp.EncodeToBytes(f)
if err != nil {
panic(err)
}
fmt.Printf("FullNode4 %x\n", b)
}
func ShortNode1() {
s := NewShortNode([]byte("1"), valueNode([]byte("2")))
b, err := rlp.EncodeToBytes(s)
if err != nil {
panic(err)
}
fmt.Printf("ShortNode1 %x\n", b)
}
func ShortNode2() {
s := NewShortNode([]byte("1"), valueNode([]byte("123456789012345678901234567890123456789012345678901234567890")))
b, err := rlp.EncodeToBytes(s)
if err != nil {
panic(err)
}
fmt.Printf("ShortNode2 %x\n", b)
}
func hashRoot(n node, title string) {
h := newHasher(false)
h1 := newHasher(true)
defer returnHasherToPool(h)
defer returnHasherToPool(h1)
var hash common.Hash
hLen, _ := h.hash(n, true, hash[:])
if hLen < 32 {
panic("expected hashNode")
}
fmt.Printf("%s noencode: %x\n", title, hash[:])
hLen, _ = h1.hash(n, true, hash[:])
if hLen < 32 {
panic("expected hashNode")
}
fmt.Printf("%s encode: %x\n", title, hash[:])
}
func Hash1() {
f := &fullNode{}
hashRoot(f, "Hash1")
}
func Hash2() {
f := &fullNode{}
f.Children[0] = &fullNode{}
hashRoot(f, "Hash2")
}
func Hash3() {
s := NewShortNode([]byte("12"), valueNode([]byte("1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012")))
hashRoot(s, "Hash3")
}
func Hash4() {
s := NewShortNode([]byte("12345678901234567890123456789012"), valueNode([]byte("12345678901234567890")))
hashRoot(s, "Hash4")
}
func Hash5() {
s := NewShortNode([]byte("1234567890123456789012345678901"), valueNode([]byte("1")))
hashRoot(s, "Hash5")
}
func Hash6() {
s := NewShortNode(common.FromHex("080010"), valueNode(common.FromHex("f90129a0bc7bbe9ce39e604900ca736606290650c4c630501a97745a3f21fae5261623df830362c0b9010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c0")))
hashRoot(s, "Hash6")
}
func Hash7() {
d := &duoNode{}
d.child1 = NewShortNode(common.FromHex("0110"), valueNode(common.FromHex("f871820ba5850ba43b7400830186a0942eb08efb9e10d9f56e46938f28c13ecb33f67b158a085c1bad4187cfe90000801ba0a7e45cf38e44d2c39a4b94bae2e14fccde41e3280c57b611d9cb6494fde12fc7a00858adac2ba2381c591978b8404c22981f7141f0aef9c3cab8f93a55efc40acc")))
d.child2 = NewShortNode(common.FromHex("0010"), valueNode(common.FromHex("fa02368e820276850ba43b7400830f4240947fd85d1fc04087b3d9d1e610410989191c09b97380ba023624847b07e7000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000011af74000000000000000000000000000000000000000000000000000000000000006c0000000000000000000000000000000000000000000000000000000000000073000000000000000000000000000000000000000000000000000000000000006e000000000000000000000000000000000000000000000000000000000000006f00000000000000000000000000000000000000000000000000000000000000740000000000000000000000000000000000000000000000000000000000000061000000000000000000000000000000000000000000000000000000000000007200000000000000000000000000000000000000000000000000000000000000790000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000006e000000000000000000000000000000000000000000000000000000000000006f0000000000000000000000000000000000000000000000000000000000000074000000000000000000000000000000000000000000000000000000000000006100000000000000000000000000000000000000000000000000000000000000720000000000000000000000000000000000000000000000000000000000000069000000000000000000000000000000000000000000000000000000000000007a000000000000000000000000000000000000000000000000000000000000006100000000000000000000000000000000000000000000000000000000000000740000000000000000000000000000000000000000000000000000000000000069000000000000000000000000000000000000000000000000000000000000006f000000000000000000000000000000000000000000000000000000000000006e000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000660000000000000000000000000000000000000000000000000000000000000069000000000000000000000000000000000000000000000000000000000000006c0000000000000000000000000000000000000000000000000000000000000065000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000350000000000000000000000000000000000000000000000000000000000000056000000000000000000000000000000000000000000000000000000000000002e000000000000000000000000000000000000000000000000000000000000005a0000000000000000000000000000000000000000000000000000000000000044000000000000000000000000000000000000000000000000000000000000009c00000000000000000000000000000000000000000000000000000000000000eb00000000000000000000000000000000000000000000000000000000000000a100000000000000000000000000000000000000000000000000000000000000c1000000000000000000000000000000000000000000000000000000000000000d000000000000000000000000000000000000000000000000000000000000005d0000000000000000000000000000000000000000000000000000000000000085000000000000000000000000000000000000000000000000000000000000005400000000000000000000000000000000000000000000000000000000000000ce000000000000000000000000000000000000000000000000000000000000009c000000000000000000000000000000000000000000000000000000000000002600000000000000000000000000000000000000000000000000000000000000cc00000000000000000000000000000000000000000000000000000000000000c3000000000000000000000000000000000000000000000000000000000000004900000000000000000000000000000000000000000000000000000000000000f300000000000000000000000000000000000000000000000000000000000000fe000000000000000000000000000000000000000000000000000000000000005f0000000000000000000000000000000000000000000000000000000000000067000000000000000000000000000000000000000000000000000000000000008300000000000000000000000000000000000000000000000000000000000000af00000000000000000000000000000000000000000000000000000000000000490000000000000000000000000000000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000000004500000000000000000000
d.mask |= uint32(1) << 0
d.mask |= uint32(1) << 8
hashRoot(d, "Hash7")
}