mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-26 05:27:19 +00:00
eca0f233ec
* save state * walkAsOf by cs test passed * cs search for plain state * save state * fix accounts tests * refactor walkAsOf account tests * fix storage test * refactor walkAsOf storage tests * fix lint * fix test * save state * save state * add test with fixed bits * fmt * add stages check * fix lint * fix lint * remove obsoleted methods
97 lines
2.7 KiB
Go
97 lines
2.7 KiB
Go
package changeset
|
|
|
|
import (
|
|
"errors"
|
|
|
|
"github.com/ledgerwatch/turbo-geth/common"
|
|
)
|
|
|
|
const (
|
|
DefaultIncarnation = uint64(1)
|
|
)
|
|
|
|
var (
|
|
ErrNotFound = errors.New("not found")
|
|
errIncorrectData = errors.New("empty prepared data")
|
|
ErrFindValue = errors.New("find value error")
|
|
)
|
|
|
|
/* Hashed changesets (key is a hash of common.Address) */
|
|
|
|
func NewStorageChangeSet() *ChangeSet {
|
|
return &ChangeSet{
|
|
Changes: make([]Change, 0),
|
|
keyLen: 2*common.HashLength + common.IncarnationLength,
|
|
}
|
|
}
|
|
|
|
func EncodeStorage(s *ChangeSet) ([]byte, error) {
|
|
return encodeStorage(s, common.HashLength)
|
|
}
|
|
|
|
func DecodeStorage(b []byte) (*ChangeSet, error) {
|
|
cs := NewStorageChangeSet()
|
|
err := decodeStorage(b, common.HashLength, cs)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return cs, nil
|
|
}
|
|
|
|
type StorageChangeSetBytes []byte
|
|
|
|
func (b StorageChangeSetBytes) Walk(f func(k, v []byte) error) error {
|
|
return walkStorageChangeSet(b, common.HashLength, f)
|
|
}
|
|
|
|
func (b StorageChangeSetBytes) Find(k []byte) ([]byte, error) {
|
|
return findWithoutIncarnationInStorageChangeSet(b, common.HashLength, k[:common.HashLength], k[common.HashLength:])
|
|
}
|
|
func (b StorageChangeSetBytes) FindWithIncarnation(k []byte) ([]byte, error) {
|
|
return findInStorageChangeSet(b, common.HashLength, k)
|
|
}
|
|
|
|
func (b StorageChangeSetBytes) FindWithoutIncarnation(addrHashToFind []byte, keyHashToFind []byte) ([]byte, error) {
|
|
return findWithoutIncarnationInStorageChangeSet(b, common.HashLength, addrHashToFind, keyHashToFind)
|
|
}
|
|
|
|
/* Plain changesets (key is a common.Address) */
|
|
|
|
func NewStorageChangeSetPlain() *ChangeSet {
|
|
return &ChangeSet{
|
|
Changes: make([]Change, 0),
|
|
keyLen: common.AddressLength + common.HashLength + common.IncarnationLength,
|
|
}
|
|
}
|
|
|
|
func EncodeStoragePlain(s *ChangeSet) ([]byte, error) {
|
|
return encodeStorage(s, common.AddressLength)
|
|
}
|
|
|
|
func DecodeStoragePlain(b []byte) (*ChangeSet, error) {
|
|
cs := NewStorageChangeSetPlain()
|
|
err := decodeStorage(b, common.AddressLength, cs)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return cs, nil
|
|
}
|
|
|
|
type StorageChangeSetPlainBytes []byte
|
|
|
|
func (b StorageChangeSetPlainBytes) Walk(f func(k, v []byte) error) error {
|
|
return walkStorageChangeSet(b, common.AddressLength, f)
|
|
}
|
|
|
|
func (b StorageChangeSetPlainBytes) Find(k []byte) ([]byte, error) {
|
|
return findWithoutIncarnationInStorageChangeSet(b, common.AddressLength, k[:common.AddressLength], k[common.AddressLength:])
|
|
}
|
|
|
|
func (b StorageChangeSetPlainBytes) FindWithIncarnation(k []byte) ([]byte, error) {
|
|
return findInStorageChangeSet(b, common.AddressLength, k)
|
|
}
|
|
|
|
func (b StorageChangeSetPlainBytes) FindWithoutIncarnation(addressToFind []byte, keyToFind []byte) ([]byte, error) {
|
|
return findWithoutIncarnationInStorageChangeSet(b, common.AddressLength, addressToFind, keyToFind)
|
|
}
|