erigon-pulse/cmd/verkle/accessories.go
Giulio rebuffo 52d76977ca
Correct Verkle trie generation (#5399)
* log msg

* refactor

* use of delete

* fixed verkle tree incremental

* ops

* ops

Co-authored-by: giuliorebuffo <giuliorebuffo@system76-pc.localdomain>
2022-09-16 15:11:13 +02:00

45 lines
1.0 KiB
Go

package main
import (
"encoding/binary"
"github.com/ledgerwatch/erigon-lib/kv"
"github.com/ledgerwatch/erigon/common"
"github.com/ledgerwatch/erigon/common/dbutils"
)
func ReadVerkleIncarnation(tx kv.Tx, address common.Address) (uint64, error) {
inc, err := tx.GetOne(VerkleIncarnation, address[:])
if err != nil {
return 0, err
}
if len(inc) == 0 {
return 0, nil
}
return binary.BigEndian.Uint64(inc), nil
}
func WriteVerkleRootLookup(tx kv.Tx, address common.Address) (uint64, error) {
inc, err := tx.GetOne(VerkleIncarnation, address[:])
if err != nil {
return 0, err
}
if len(inc) == 0 {
return 0, nil
}
return binary.BigEndian.Uint64(inc), nil
}
func ReadVerkleRoot(tx kv.Tx, blockNum uint64) (common.Hash, error) {
root, err := tx.GetOne(VerkleIncarnation, dbutils.EncodeBlockNumber(blockNum))
if err != nil {
return common.Hash{}, err
}
return common.BytesToHash(root), nil
}
func WriteVerkleRoot(tx kv.RwTx, blockNum uint64, root common.Hash) error {
return tx.Put(VerkleRoots, dbutils.EncodeBlockNumber(blockNum), root[:])
}