2019-05-27 14:51:49 +01:00
|
|
|
// Copyright 2019 The go-ethereum Authors
|
2017-06-27 15:57:06 +02:00
|
|
|
// This file is part of the go-ethereum library.
|
|
|
|
//
|
|
|
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2020-04-08 08:00:31 +03:00
|
|
|
//nolint:scopelint
|
2017-06-27 15:57:06 +02:00
|
|
|
package state
|
|
|
|
|
|
|
|
import (
|
2020-05-25 13:12:25 +02:00
|
|
|
"github.com/holiman/uint256"
|
2023-06-14 10:01:00 +07:00
|
|
|
"github.com/ledgerwatch/erigon-lib/common"
|
2023-01-13 18:12:18 +00:00
|
|
|
|
2021-05-21 01:25:53 +07:00
|
|
|
"github.com/ledgerwatch/erigon/core/types/accounts"
|
2017-06-27 15:57:06 +02:00
|
|
|
)
|
|
|
|
|
2020-01-08 12:55:56 +03:00
|
|
|
const (
|
|
|
|
//FirstContractIncarnation - first incarnation for contract accounts. After 1 it increases by 1.
|
|
|
|
FirstContractIncarnation = 1
|
|
|
|
//NonContractIncarnation incarnation for non contracts
|
|
|
|
NonContractIncarnation = 0
|
|
|
|
)
|
2019-05-27 14:51:49 +01:00
|
|
|
|
|
|
|
type StateReader interface {
|
2023-06-14 10:01:00 +07:00
|
|
|
ReadAccountData(address common.Address) (*accounts.Account, error)
|
|
|
|
ReadAccountStorage(address common.Address, incarnation uint64, key *common.Hash) ([]byte, error)
|
|
|
|
ReadAccountCode(address common.Address, incarnation uint64, codeHash common.Hash) ([]byte, error)
|
|
|
|
ReadAccountCodeSize(address common.Address, incarnation uint64, codeHash common.Hash) (int, error)
|
|
|
|
ReadAccountIncarnation(address common.Address) (uint64, error)
|
2019-05-27 14:51:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type StateWriter interface {
|
2023-06-14 10:01:00 +07:00
|
|
|
UpdateAccountData(address common.Address, original, account *accounts.Account) error
|
|
|
|
UpdateAccountCode(address common.Address, incarnation uint64, codeHash common.Hash, code []byte) error
|
|
|
|
DeleteAccount(address common.Address, original *accounts.Account) error
|
|
|
|
WriteAccountStorage(address common.Address, incarnation uint64, key *common.Hash, original, value *uint256.Int) error
|
|
|
|
CreateContract(address common.Address) error
|
2019-05-27 14:51:49 +01:00
|
|
|
}
|
|
|
|
|
2020-05-15 10:52:45 +03:00
|
|
|
type WriterWithChangeSets interface {
|
|
|
|
StateWriter
|
|
|
|
WriteChangeSets() error
|
2020-05-31 09:57:47 +03:00
|
|
|
WriteHistory() error
|
2020-05-15 10:52:45 +03:00
|
|
|
}
|
|
|
|
|
2019-05-27 14:51:49 +01:00
|
|
|
type NoopWriter struct {
|
|
|
|
}
|
|
|
|
|
2021-06-21 12:56:56 +07:00
|
|
|
var noopWriter = &NoopWriter{}
|
|
|
|
|
2019-05-27 14:51:49 +01:00
|
|
|
func NewNoopWriter() *NoopWriter {
|
2021-06-21 12:56:56 +07:00
|
|
|
return noopWriter
|
2019-05-27 14:51:49 +01:00
|
|
|
}
|
|
|
|
|
2023-06-14 10:01:00 +07:00
|
|
|
func (nw *NoopWriter) UpdateAccountData(address common.Address, original, account *accounts.Account) error {
|
2019-05-27 14:51:49 +01:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-06-14 10:01:00 +07:00
|
|
|
func (nw *NoopWriter) DeleteAccount(address common.Address, original *accounts.Account) error {
|
2019-05-27 14:51:49 +01:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-06-14 10:01:00 +07:00
|
|
|
func (nw *NoopWriter) UpdateAccountCode(address common.Address, incarnation uint64, codeHash common.Hash, code []byte) error {
|
2019-05-27 14:51:49 +01:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-06-14 10:01:00 +07:00
|
|
|
func (nw *NoopWriter) WriteAccountStorage(address common.Address, incarnation uint64, key *common.Hash, original, value *uint256.Int) error {
|
2019-05-27 14:51:49 +01:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-06-14 10:01:00 +07:00
|
|
|
func (nw *NoopWriter) CreateContract(address common.Address) error {
|
2020-05-02 20:00:42 +02:00
|
|
|
return nil
|
2019-05-27 14:51:49 +01:00
|
|
|
}
|
|
|
|
|
2020-10-12 09:39:04 +01:00
|
|
|
func (nw *NoopWriter) WriteChangeSets() error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (nw *NoopWriter) WriteHistory() error {
|
|
|
|
return nil
|
|
|
|
}
|