erigon-pulse/core/state/intermediate_trie_cache.go
Alex Sharov ff23980dc6
Intermediate hash phase 2 (#341)
* add env INTERMEDIATE_TRIE_CACHE
* try to use assert.New() pattern
* Fix "maligned" linter warnings to reduce space consumption of structs:

core/types/accounts/account.go:18:14: struct of size 136 bytes could be of size 128 bytes (maligned)
type Account struct {
--
trie/node.go:44:10: struct of size 80 bytes could be of size 72 bytes (maligned)
	duoNode struct {
--
trie/resolve_set.go:28:17: struct of size 56 bytes could be of size 48 bytes (maligned)
type ResolveSet struct {
--
trie/resolver.go:34:15: struct of size 88 bytes could be of size 72 bytes (maligned)
type Resolver struct {
--
trie/visual.go:32:17: struct of size 104 bytes could be of size 96 bytes (maligned)
type VisualOpts struct {
2020-01-31 14:31:50 +07:00

48 lines
1.1 KiB
Go

package state
import (
"fmt"
"github.com/ledgerwatch/turbo-geth/common/dbutils"
"github.com/ledgerwatch/turbo-geth/common/pool"
"github.com/ledgerwatch/turbo-geth/ethdb"
"github.com/ledgerwatch/turbo-geth/trie"
)
func putIntermediateCache(db ethdb.Putter, prefix []byte, subtrieHash []byte) error {
v := make([]byte, len(subtrieHash))
copy(v, subtrieHash)
buf := pool.GetBuffer(64)
buf.Reset()
defer pool.PutBuffer(buf)
if err := trie.CompressNibbles(prefix, &buf.B); err != nil {
return err
}
k := make([]byte, buf.Len())
copy(k, buf.Bytes())
if err := db.Put(dbutils.IntermediateTrieCacheBucket, k, v); err != nil {
return fmt.Errorf("could not put IntermediateTrieCacheBucket, %w", err)
}
return nil
}
func delIntermediateCache(db ethdb.Deleter, prefix []byte) error {
buf := pool.GetBuffer(64)
buf.Reset()
defer pool.PutBuffer(buf)
if err := trie.CompressNibbles(prefix, &buf.B); err != nil {
return err
}
if err := db.Delete(dbutils.IntermediateTrieCacheBucket, buf.Bytes()); err != nil {
return fmt.Errorf("could not put IntermediateTrieCacheBucket, %w", err)
}
return nil
}