2019-05-27 13:51:49 +00:00
|
|
|
// Copyright 2019 The go-ethereum Authors
|
2017-06-27 13:57:06 +00: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 05:00:31 +00:00
|
|
|
//nolint:scopelint
|
2017-06-27 13:57:06 +00:00
|
|
|
package state
|
|
|
|
|
|
|
|
import (
|
2020-05-25 11:12:25 +00:00
|
|
|
"github.com/holiman/uint256"
|
2021-05-20 18:25:53 +00:00
|
|
|
"github.com/ledgerwatch/erigon/common"
|
|
|
|
"github.com/ledgerwatch/erigon/core/types/accounts"
|
2017-06-27 13:57:06 +00:00
|
|
|
)
|
|
|
|
|
2020-01-08 09:55:56 +00: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 13:51:49 +00:00
|
|
|
|
|
|
|
type StateReader interface {
|
|
|
|
ReadAccountData(address common.Address) (*accounts.Account, error)
|
|
|
|
ReadAccountStorage(address common.Address, incarnation uint64, key *common.Hash) ([]byte, error)
|
2020-12-08 09:44:29 +00:00
|
|
|
ReadAccountCode(address common.Address, incarnation uint64, codeHash common.Hash) ([]byte, error)
|
|
|
|
ReadAccountCodeSize(address common.Address, incarnation uint64, codeHash common.Hash) (int, error)
|
2020-05-02 18:00:42 +00:00
|
|
|
ReadAccountIncarnation(address common.Address) (uint64, error)
|
2019-05-27 13:51:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type StateWriter interface {
|
2021-07-05 08:42:44 +00:00
|
|
|
UpdateAccountData(address common.Address, original, account *accounts.Account) error
|
2020-05-15 07:52:45 +00:00
|
|
|
UpdateAccountCode(address common.Address, incarnation uint64, codeHash common.Hash, code []byte) error
|
2021-07-05 08:42:44 +00:00
|
|
|
DeleteAccount(address common.Address, original *accounts.Account) error
|
|
|
|
WriteAccountStorage(address common.Address, incarnation uint64, key *common.Hash, original, value *uint256.Int) error
|
2020-05-02 18:00:42 +00:00
|
|
|
CreateContract(address common.Address) error
|
2019-05-27 13:51:49 +00:00
|
|
|
}
|
|
|
|
|
2020-05-15 07:52:45 +00:00
|
|
|
type WriterWithChangeSets interface {
|
|
|
|
StateWriter
|
|
|
|
WriteChangeSets() error
|
2020-05-31 06:57:47 +00:00
|
|
|
WriteHistory() error
|
2020-05-15 07:52:45 +00:00
|
|
|
}
|
|
|
|
|
2019-05-27 13:51:49 +00:00
|
|
|
type NoopWriter struct {
|
|
|
|
}
|
|
|
|
|
2021-06-21 05:56:56 +00:00
|
|
|
var noopWriter = &NoopWriter{}
|
|
|
|
|
2019-05-27 13:51:49 +00:00
|
|
|
func NewNoopWriter() *NoopWriter {
|
2021-06-21 05:56:56 +00:00
|
|
|
return noopWriter
|
2019-05-27 13:51:49 +00:00
|
|
|
}
|
|
|
|
|
2021-07-05 08:42:44 +00:00
|
|
|
func (nw *NoopWriter) UpdateAccountData(address common.Address, original, account *accounts.Account) error {
|
2019-05-27 13:51:49 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-07-05 08:42:44 +00:00
|
|
|
func (nw *NoopWriter) DeleteAccount(address common.Address, original *accounts.Account) error {
|
2019-05-27 13:51:49 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-05-15 07:52:45 +00:00
|
|
|
func (nw *NoopWriter) UpdateAccountCode(address common.Address, incarnation uint64, codeHash common.Hash, code []byte) error {
|
2019-05-27 13:51:49 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-07-05 08:42:44 +00:00
|
|
|
func (nw *NoopWriter) WriteAccountStorage(address common.Address, incarnation uint64, key *common.Hash, original, value *uint256.Int) error {
|
2019-05-27 13:51:49 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-05-02 18:00:42 +00:00
|
|
|
func (nw *NoopWriter) CreateContract(address common.Address) error {
|
|
|
|
return nil
|
2019-05-27 13:51:49 +00:00
|
|
|
}
|
|
|
|
|
2020-10-12 08:39:04 +00:00
|
|
|
func (nw *NoopWriter) WriteChangeSets() error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (nw *NoopWriter) WriteHistory() error {
|
|
|
|
return nil
|
|
|
|
}
|