erigon-pulse/trie/hack.go

141 lines
287 KiB
Go
Raw Normal View History

package trie
import (
"fmt"
"github.com/ledgerwatch/turbo-geth/common"
"github.com/ledgerwatch/turbo-geth/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(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(h[:])
}
b, err := rlp.EncodeToBytes(f)
if err != nil {
panic(err)
}
fmt.Printf("FullNode4 %x\n", b)
}
func ShortNode1() {
s := &shortNode{}
s.Key = []byte("1")
s.Val = valueNode([]byte("2"))
b, err := rlp.EncodeToBytes(s)
if err != nil {
panic(err)
}
fmt.Printf("ShortNode1 %x\n", b)
}
func ShortNode2() {
s := &shortNode{}
s.Key = []byte("1")
s.Val = 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 := &shortNode{}
s.Key = []byte("12")
s.Val = valueNode([]byte("1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012"))
hashRoot(s, "Hash3")
}
func Hash4() {
s := &shortNode{}
s.Key = []byte("12345678901234567890123456789012")
s.Val = valueNode([]byte("12345678901234567890"))
hashRoot(s, "Hash4")
}
func Hash5() {
s := &shortNode{}
s.Key = []byte("1234567890123456789012345678901")
s.Val = valueNode([]byte("1"))
hashRoot(s, "Hash5")
}
func Hash6() {
s := &shortNode{}
s.Key = common.FromHex("080010")
s.Val = valueNode(common.FromHex("f90129a0bc7bbe9ce39e604900ca736606290650c4c630501a97745a3f21fae5261623df830362c0b9010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c0"))
hashRoot(s, "Hash6")
}
func Hash7() {
d := &duoNode{}
d.child1 = &shortNode{Key: common.FromHex("0110"), Val: valueNode(common.FromHex("f871820ba5850ba43b7400830186a0942eb08efb9e10d9f56e46938f28c13ecb33f67b158a085c1bad4187cfe90000801ba0a7e45cf38e44d2c39a4b94bae2e14fccde41e3280c57b611d9cb6494fde12fc7a00858adac2ba2381c591978b8404c22981f7141f0aef9c3cab8f93a55efc40acc"))}
d.child2 = &shortNode{Key: common.FromHex("0010"), Val: valueNode(common.FromHex("fa02368e820276850ba43b7400830f4240947fd85d1fc04087b3d9d1e610410989191c09b97380ba023624847b07e7000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000011af74000000000000000000000000000000000000000000000000000000000000006c0000000000000000000000000000000000000000000000000000000000000073000000000000000000000000000000000000000000000000000000000000006e000000000000000000000000000000000000000000000000000000000000006f00000000000000000000000000000000000000000000000000000000000000740000000000000000000000000000000000000000000000000000000000000061000000000000000000000000000000000000000000000000000000000000007200000000000000000000000000000000000000000000000000000000000000790000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000006e000000000000000000000000000000000000000000000000000000000000006f0000000000000000000000000000000000000000000000000000000000000074000000000000000000000000000000000000000000000000000000000000006100000000000000000000000000000000000000000000000000000000000000720000000000000000000000000000000000000000000000000000000000000069000000000000000000000000000000000000000000000000000000000000007a000000000000000000000000000000000000000000000000000000000000006100000000000000000000000000000000000000000000000000000000000000740000000000000000000000000000000000000000000000000000000000000069000000000000000000000000000000000000000000000000000000000000006f000000000000000000000000000000000000000000000000000000000000006e000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000660000000000000000000000000000000000000000000000000000000000000069000000000000000000000000000000000000000000000000000000000000006c0000000000000000000000000000000000000000000000000000000000000065000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000350000000000000000000000000000000000000000000000000000000000000056000000000000000000000000000000000000000000000000000000000000002e000000000000000000000000000000000000000000000000000000000000005a0000000000000000000000000000000000000000000000000000000000000044000000000000000000000000000000000000000000000000000000000000009c00000000000000000000000000000000000000000000000000000000000000eb00000000000000000000000000000000000000000000000000000000000000a100000000000000000000000000000000000000000000000000000000000000c1000000000000000000000000000000000000000000000000000000000000000d000000000000000000000000000000000000000000000000000000000000005d0000000000000000000000000000000000000000000000000000000000000085000000000000000000000000000000000000000000000000000000000000005400000000000000000000000000000000000000000000000000000000000000ce000000000000000000000000000000000000000000000000000000000000009c000000000000000000000000000000000000000000000000000000000000002600000000000000000000000000000000000000000000000000000000000000cc00000000000000000000000000000000000000000000000000000000000000c3000000000000000000000000000000000000000000000000000000000000004900000000000000000000000000000000000000000000000000000000000000f300000000000000000000000000000000000000000000000000000000000000fe000000000000000000000000000000000000000000000000000000000000005f0000000000000000000000000000000000000000000000000000000000000067000000000000000000000000000000000000000000000000000000000000008300000000000000000000000000000000000000000000000000000000000000af000000000000000000000000000000000000000000000000000000000000004900000000000000000000000000000000000000000000000000000000000000140000000000000000000000000000000000000000000000000000000000000045000000000000
d.mask |= uint32(1) << 0
d.mask |= uint32(1) << 8
hashRoot(d, "Hash7")
}