Commit 0975f738 authored by Mark Tyneway's avatar Mark Tyneway

l2geth: remove diffdb

This PR removes the diffdb as it is not currently being used.
Removing the diffdb is meant to help with resource usage of the node.
parent 1574f946
---
'@eth-optimism/l2geth': patch
---
Remove diffdb
......@@ -162,7 +162,6 @@ var (
utils.RollupTimstampRefreshFlag,
utils.RollupPollIntervalFlag,
utils.RollupStateDumpPathFlag,
utils.RollupDiffDbFlag,
utils.RollupMaxCalldataSizeFlag,
utils.RollupBackendFlag,
utils.RollupEnforceFeesFlag,
......
......@@ -77,7 +77,6 @@ var AppHelpFlagGroups = []flagGroup{
utils.RollupTimstampRefreshFlag,
utils.RollupPollIntervalFlag,
utils.RollupStateDumpPathFlag,
utils.RollupDiffDbFlag,
utils.RollupMaxCalldataSizeFlag,
utils.RollupBackendFlag,
utils.RollupEnforceFeesFlag,
......
......@@ -881,12 +881,6 @@ var (
Value: eth.DefaultConfig.Rollup.StateDumpPath,
EnvVar: "ROLLUP_STATE_DUMP_PATH",
}
RollupDiffDbFlag = cli.Uint64Flag{
Name: "rollup.diffdbcache",
Usage: "Number of diffdb batch updates",
Value: eth.DefaultConfig.DiffDbCache,
EnvVar: "ROLLUP_DIFFDB_CACHE",
}
RollupMaxCalldataSizeFlag = cli.IntFlag{
Name: "rollup.maxcalldatasize",
Usage: "Maximum allowed calldata size for Queue Origin Sequencer Txs",
......@@ -1676,9 +1670,6 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *eth.Config) {
setEth1(ctx, &cfg.Rollup)
setRollup(ctx, &cfg.Rollup)
if ctx.GlobalIsSet(RollupDiffDbFlag.Name) {
cfg.DiffDbCache = ctx.GlobalUint64(RollupDiffDbFlag.Name)
}
if ctx.GlobalIsSet(SyncModeFlag.Name) {
cfg.SyncMode = *GlobalTextMarshaler(ctx, SyncModeFlag.Name).(*downloader.SyncMode)
}
......
......@@ -36,7 +36,6 @@ import (
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/diffdb"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/log"
......@@ -165,8 +164,6 @@ type BlockChain struct {
txLookupCache *lru.Cache // Cache for the most recent transaction lookup data.
futureBlocks *lru.Cache // future blocks are blocks added for later processing
diffdb state.DiffDB // Diff
quit chan struct{} // blockchain quit channel
running int32 // running must be called atomically
// procInterrupt must be atomically called
......@@ -184,20 +181,6 @@ type BlockChain struct {
terminateInsert func(common.Hash, uint64) bool // Testing hook used to terminate ancient receipt chain insertion.
}
func NewBlockChainWithDiffDb(db ethdb.Database, cacheConfig *CacheConfig, chainConfig *params.ChainConfig, engine consensus.Engine, vmConfig vm.Config, shouldPreserve func(block *types.Block) bool, path string, cache uint64) (*BlockChain, error) {
diff, err := diffdb.NewDiffDb(path, cache)
if err != nil {
return nil, err
}
bc, err := NewBlockChain(db, cacheConfig, chainConfig, engine, vmConfig, shouldPreserve)
if err != nil {
return nil, err
}
bc.diffdb = diff
return bc, nil
}
// NewBlockChain returns a fully initialised block chain using information
// available in the database. It initialises the default Ethereum Validator and
// Processor.
......@@ -365,7 +348,7 @@ func (bc *BlockChain) loadLastState() error {
return bc.Reset()
}
// Make sure the state associated with the block is available
if _, err := state.NewWithDiffDb(currentBlock.Root(), bc.stateCache, bc.diffdb); err != nil {
if _, err := state.New(currentBlock.Root(), bc.stateCache); err != nil {
// Dangling block without a state associated, init from scratch
log.Warn("Head state missing, repairing chain", "number", currentBlock.Number(), "hash", currentBlock.Hash())
if err := bc.repair(&currentBlock); err != nil {
......@@ -427,7 +410,7 @@ func (bc *BlockChain) SetHead(head uint64) error {
if newHeadBlock == nil {
newHeadBlock = bc.genesisBlock
} else {
if _, err := state.NewWithDiffDb(newHeadBlock.Root(), bc.stateCache, bc.diffdb); err != nil {
if _, err := state.New(newHeadBlock.Root(), bc.stateCache); err != nil {
// Rewound state missing, rolled back to before pivot, reset to genesis
newHeadBlock = bc.genesisBlock
}
......@@ -543,11 +526,6 @@ func (bc *BlockChain) SetCurrentBlock(block *types.Block) {
bc.currentBlock.Store(block)
}
// GetDiff retrieves the diffdb's state diff keys for a block
func (bc *BlockChain) GetDiff(block *big.Int) (diffdb.Diff, error) {
return bc.diffdb.GetDiff(block)
}
// CurrentFastBlock retrieves the current fast-sync head block of the canonical
// chain. The block is retrieved from the blockchain's internal cache.
func (bc *BlockChain) CurrentFastBlock() *types.Block {
......@@ -571,7 +549,7 @@ func (bc *BlockChain) State() (*state.StateDB, error) {
// StateAt returns a new mutable state based on a particular point in time.
func (bc *BlockChain) StateAt(root common.Hash) (*state.StateDB, error) {
return state.NewWithDiffDb(root, bc.stateCache, bc.diffdb)
return state.New(root, bc.stateCache)
}
// StateCache returns the caching database underpinning the blockchain instance.
......@@ -623,7 +601,7 @@ func (bc *BlockChain) ResetWithGenesisBlock(genesis *types.Block) error {
func (bc *BlockChain) repair(head **types.Block) error {
for {
// Abort if we've rewound to a head block that does have associated state
if _, err := state.NewWithDiffDb((*head).Root(), bc.stateCache, bc.diffdb); err == nil {
if _, err := state.New((*head).Root(), bc.stateCache); err == nil {
log.Info("Rewound blockchain to past state", "number", (*head).Number(), "hash", (*head).Hash())
return nil
}
......@@ -912,14 +890,6 @@ func (bc *BlockChain) Stop() {
}
}
if bc.diffdb != nil {
if err := bc.diffdb.ForceCommit(); err != nil {
log.Error("Failed to commit recent state diffs", "err", err)
}
if err := bc.diffdb.Close(); err != nil {
log.Error("Failed to commit state diffs handler", "err", err)
}
}
log.Info("Blockchain manager stopped")
}
......@@ -1709,7 +1679,7 @@ func (bc *BlockChain) insertChain(chain types.Blocks, verifySeals bool) (int, er
if parent == nil {
parent = bc.GetHeader(block.ParentHash(), block.NumberU64()-1)
}
statedb, err := state.NewWithDiffDb(parent.Root, bc.stateCache, bc.diffdb)
statedb, err := state.New(parent.Root, bc.stateCache)
if err != nil {
return it.index, err
}
......
......@@ -27,7 +27,6 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/diffdb"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/metrics"
"github.com/ethereum/go-ethereum/rlp"
......@@ -59,15 +58,6 @@ func (n *proofList) Delete(key []byte) error {
panic("not supported")
}
// DiffDb is a database for storing state diffs per block
type DiffDB interface {
SetDiffKey(*big.Int, common.Address, common.Hash, bool) error
SetDiffAccount(*big.Int, common.Address) error
GetDiff(*big.Int) (diffdb.Diff, error)
Close() error
ForceCommit() error
}
// StateDBs within the ethereum protocol are used to store anything
// within the merkle trie. StateDBs take care of caching and storing
// nested states. It's the general query interface to retrieve:
......@@ -77,8 +67,6 @@ type StateDB struct {
db Database
trie Trie
diffdb DiffDB
// This map holds 'live' objects, which will get modified while processing a state transition.
stateObjects map[common.Address]*stateObject
stateObjectsPending map[common.Address]struct{} // State objects finalized but not yet written to the trie
......@@ -136,15 +124,6 @@ func New(root common.Hash, db Database) (*StateDB, error) {
}, nil
}
func NewWithDiffDb(root common.Hash, db Database, diffdb DiffDB) (*StateDB, error) {
res, err := New(root, db)
if err != nil {
return nil, err
}
res.diffdb = diffdb
return res, nil
}
// setError remembers the first non-nil error it is called with.
func (s *StateDB) setError(err error) {
if s.dbErr == nil {
......@@ -152,20 +131,6 @@ func (s *StateDB) setError(err error) {
}
}
func (s *StateDB) SetDiffKey(block *big.Int, address common.Address, key common.Hash, mutated bool) error {
if s.diffdb == nil {
return errors.New("DiffDB not set")
}
return s.diffdb.SetDiffKey(block, address, key, mutated)
}
func (s *StateDB) SetDiffAccount(block *big.Int, address common.Address) error {
if s.diffdb == nil {
return errors.New("DiffDB not set")
}
return s.diffdb.SetDiffAccount(block, address)
}
func (s *StateDB) Error() error {
return s.dbErr
}
......
......@@ -64,8 +64,6 @@ type StateDB interface {
AddPreimage(common.Hash, []byte)
ForEachStorage(common.Address, func(common.Hash, common.Hash) bool) error
SetDiffKey(block *big.Int, address common.Address, key common.Hash, mutated bool) error
SetDiffAccount(block *big.Int, address common.Address) error
}
// CallContext provides a basic interface for the EVM calling conventions. The EVM
......
......@@ -133,46 +133,14 @@ func putContractStorage(evm *EVM, contract *Contract, args map[string]interface{
return nil, errors.New("Could not parse value arg in putContractStorage")
}
val := toHash(_value)
// save the block number and address with modified key if it's not an eth_call
if evm.Context.EthCallSender == nil {
// save the value before
before := evm.StateDB.GetState(address, key)
evm.StateDB.SetState(address, key, val)
err := evm.StateDB.SetDiffKey(
evm.Context.BlockNumber,
address,
key,
before != val,
)
if err != nil {
log.Error("Cannot set diff key", "err", err)
}
log.Debug("Put contract storage", "address", address.Hex(), "key", key.Hex(), "val", val.Hex())
} else {
// otherwise just do the db update
evm.StateDB.SetState(address, key, val)
}
evm.StateDB.SetState(address, key, val)
return []interface{}{}, nil
}
func testAndSetAccount(evm *EVM, contract *Contract, args map[string]interface{}) ([]interface{}, error) {
address, ok := args["_address"].(common.Address)
if !ok {
return nil, errors.New("Could not parse address arg in putContractStorage")
}
if evm.Context.EthCallSender == nil {
err := evm.StateDB.SetDiffAccount(
evm.Context.BlockNumber,
address,
)
if err != nil {
log.Error("Cannot set account diff", "err", err)
}
}
return []interface{}{true}, nil
}
......@@ -196,15 +164,6 @@ func testAndSetContractStorage(evm *EVM, contract *Contract, args map[string]int
key := toHash(_key)
if evm.Context.EthCallSender == nil {
err := evm.StateDB.SetDiffKey(
evm.Context.BlockNumber,
address,
key,
changed,
)
if err != nil {
log.Error("Cannot set diff key", "err", err)
}
log.Debug("Test and Set Contract Storage", "address", address.Hex(), "key", key.Hex(), "changed", changed)
}
......
package vm
import (
"crypto/rand"
"math/big"
"os"
"sort"
"testing"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/diffdb"
"github.com/ethereum/go-ethereum/params"
)
type TestData map[*big.Int]BlockData
// per-block test data are an address + a bunch of k/v pairs
type BlockData map[common.Address][]ContractData
// keys and values are bytes32 in solidity
type ContractData struct {
key [32]uint8
value [32]uint8
mutated bool
}
// Test contract addrs
var (
contract1 = common.HexToAddress("0x000000000000000000000000000000000001")
contract2 = common.HexToAddress("0x000000000000000000000000000000000002")
)
func makeEnv(dbname string) (*diffdb.DiffDb, *EVM, TestData, *Contract) {
db, _ := diffdb.NewDiffDb(dbname, 1)
mock := &mockDb{db: *db}
env := NewEVM(Context{}, mock, params.TestChainConfig, Config{})
// re-use `dummyContractRef` from `logger_test.go`
contract := NewContract(&dummyContractRef{}, &dummyContractRef{}, new(big.Int), 0)
testData := make(TestData)
return db, env, testData, contract
}
func TestEthCallNoop(t *testing.T) {
db, env, _, contract := makeEnv("test1")
defer os.Remove("test1")
env.Context.EthCallSender = &common.Address{0}
env.Context.BlockNumber = big.NewInt(1)
args := map[string]interface{}{
"_contract": contract1,
"_key": [32]uint8{1},
"_value": [32]uint8{2},
}
putContractStorage(env, contract, args)
diff, err := db.GetDiff(env.Context.BlockNumber)
if err != nil {
t.Fatal("Db call error", err)
}
if len(diff) > 0 {
t.Fatalf("map must be empty since it was an eth call")
}
}
func TestSetDiffs(t *testing.T) {
db, env, testData, contract := makeEnv("test2")
defer os.Remove("test2")
// not an eth-call
env.Context.EthCallSender = nil
// in block 1 both contracts get touched
blockNumber := big.NewInt(5)
testData.addRandomData(blockNumber, contract1, 5)
testData.addRandomData(blockNumber, contract2, 10)
// in another block, only 1 contract gets touched
blockNumber2 := big.NewInt(6)
testData.addRandomData(blockNumber2, contract2, 10)
// insert the data in the diffdb via `putContractStorage` calls
putTestData(t, env, contract, blockNumber, testData)
// diffs match
diff, _ := db.GetDiff(blockNumber)
expected := getExpected(testData[blockNumber])
if !DiffsEqual(diff, expected) {
t.Fatalf("Diff did not match.")
}
// empty diff for the next block
diff2, err := db.GetDiff(blockNumber2)
if err != nil {
t.Fatal("Db call error", err)
}
if len(diff2) != 0 {
t.Fatalf("Diff2 should be empty since data about the next block is not added yet")
}
// insert the data and get the diff again
putTestData(t, env, contract, blockNumber2, testData)
expected2 := getExpected(testData[blockNumber2])
diff2, err = db.GetDiff(blockNumber2)
if err != nil {
t.Fatal("Db call error", err)
}
if !DiffsEqual(diff2, expected2) {
t.Fatalf("Diff did not match.")
}
}
/// Sorted equality between 2 diffs
func DiffsEqual(d1 diffdb.Diff, d2 diffdb.Diff) bool {
for k, v := range d1 {
sort.SliceStable(v, func(i, j int) bool {
return v[i].Key.Big().Cmp(v[j].Key.Big()) < 0
})
sort.SliceStable(d2[k], func(i, j int) bool {
return d2[k][i].Key.Big().Cmp(d2[k][j].Key.Big()) < 0
})
exp := d2[k]
for i, v2 := range v {
if exp[i] != v2 {
return false
}
}
}
return true
}
// inserts a bunch of data for the provided `blockNumber` for all contracts touched in that block
func putTestData(t *testing.T, env *EVM, contract *Contract, blockNumber *big.Int, testData TestData) {
blockData := testData[blockNumber]
env.Context.BlockNumber = blockNumber
for address, data := range blockData {
for _, contractData := range data {
args := map[string]interface{}{
"_contract": address,
"_key": contractData.key,
"_value": contractData.value,
}
_, err := putContractStorage(env, contract, args)
if err != nil {
t.Fatalf("Expected nil error, got %s", err)
}
}
}
}
// creates `num` random k/v entries for `contract`'s address at `blockNumber`
func (data TestData) addRandomData(blockNumber *big.Int, contract common.Address, num int) {
for i := 0; i < num; i++ {
val := ContractData{
key: randBytes(),
value: randBytes(),
mutated: true,
}
// alloc empty blockdata
if data[blockNumber] == nil {
data[blockNumber] = make(BlockData)
}
data[blockNumber][contract] = append(data[blockNumber][contract], val)
}
}
// the expected diff for the GetDiff call contains the data's keys only, the values & proofs
// are fetched via GetProof
func getExpected(testData BlockData) diffdb.Diff {
res := make(diffdb.Diff)
for address, data := range testData {
for _, contractData := range data {
key := diffdb.Key{
Key: contractData.key,
Mutated: contractData.mutated,
}
res[address] = append(res[address], key)
}
}
return res
}
// creates a random 32 byte array
func randBytes() [32]uint8 {
bytes := make([]uint8, 32)
rand.Read(bytes)
var res [32]uint8
copy(res[:], bytes)
return res
}
// Mock everything else
type mockDb struct {
db diffdb.DiffDb
}
func (mock *mockDb) SetDiffKey(block *big.Int, address common.Address, key common.Hash, mutated bool) error {
mock.db.SetDiffKey(block, address, key, mutated)
return nil
}
func (mock *mockDb) SetDiffAccount(block *big.Int, address common.Address) error {
// mock.db.SetDiffAccount(block, address)
return nil
}
func (mock *mockDb) CreateAccount(common.Address) {}
func (mock *mockDb) SubBalance(common.Address, *big.Int) {}
func (mock *mockDb) AddBalance(common.Address, *big.Int) {}
func (mock *mockDb) GetBalance(common.Address) *big.Int { return big.NewInt(0) }
func (mock *mockDb) GetNonce(common.Address) uint64 { return 0 }
func (mock *mockDb) SetNonce(common.Address, uint64) {}
func (mock *mockDb) GetCodeHash(common.Address) common.Hash { return common.Hash{} }
func (mock *mockDb) GetCode(common.Address) []byte { return []byte{} }
func (mock *mockDb) SetCode(common.Address, []byte) {}
func (mock *mockDb) GetCodeSize(common.Address) int { return 0 }
func (mock *mockDb) AddRefund(uint64) {}
func (mock *mockDb) SubRefund(uint64) {}
func (mock *mockDb) GetRefund() uint64 { return 0 }
func (mock *mockDb) GetCommittedState(common.Address, common.Hash) common.Hash { return common.Hash{} }
func (mock *mockDb) GetState(common.Address, common.Hash) common.Hash { return common.Hash{} }
func (mock *mockDb) SetState(common.Address, common.Hash, common.Hash) {}
func (mock *mockDb) Suicide(common.Address) bool { return true }
func (mock *mockDb) HasSuicided(common.Address) bool { return true }
func (mock *mockDb) Exist(common.Address) bool { return true }
func (mock *mockDb) Empty(common.Address) bool { return true }
func (mock *mockDb) RevertToSnapshot(int) {}
func (mock *mockDb) Snapshot() int { return 0 }
func (mock *mockDb) AddLog(*types.Log) {}
func (mock *mockDb) AddPreimage(common.Hash, []byte) {}
func (mock *mockDb) ForEachStorage(common.Address, func(common.Hash, common.Hash) bool) error {
return nil
}
package diffdb
import (
"github.com/ethereum/go-ethereum/common"
_ "github.com/mattn/go-sqlite3"
"database/sql"
"math/big"
)
type Key struct {
Key common.Hash
Mutated bool
}
type Diff map[common.Address][]Key
/// A DiffDb is a thin wrapper around an Sqlite3 connection.
///
/// Its purpose is to store and fetch the storage keys corresponding to an address that was
/// touched in a block.
type DiffDb struct {
db *sql.DB
tx *sql.Tx
stmt *sql.Stmt
cache uint64
// We have a db-wide counter for the number of db calls made which we reset
// whenever it hits `cache`.
numCalls uint64
}
/// This key is used to mark that an account's state has been modified (e.g. nonce or balance)
/// and that an account proof is required.
var accountKey = common.HexToHash("0xDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEF")
var insertStatement = `
INSERT INTO diffs
(block, address, key, mutated)
VALUES
($1, $2, $3, $4)
ON CONFLICT DO NOTHING
`
var createStmt = `
CREATE TABLE IF NOT EXISTS diffs (
block INTEGER,
address STRING,
key STRING,
mutated BOOL,
PRIMARY KEY (block, address, key)
)
`
var selectStmt = `
SELECT * from diffs WHERE block = $1
`
/// Inserts a new row to the sqlite with the provided diff data.
func (diff *DiffDb) SetDiffKey(block *big.Int, address common.Address, key common.Hash, mutated bool) error {
// add 1 more insertion to the transaction
_, err := diff.stmt.Exec(block.Uint64(), address, key, mutated)
if err != nil {
return err
}
// increment number of calls
diff.numCalls += 1
// if we had enough calls, commit it
if diff.numCalls >= diff.cache {
if err := diff.ForceCommit(); err != nil {
return err
}
}
return nil
}
/// Inserts a new row to the sqlite indicating that the account was modified in that block
/// at a pre-set key
func (diff *DiffDb) SetDiffAccount(block *big.Int, address common.Address) error {
return diff.SetDiffKey(block, address, accountKey, true)
}
/// Commits a pending diffdb transaction
func (diff *DiffDb) ForceCommit() error {
if err := diff.tx.Commit(); err != nil {
return err
}
return diff.resetTx()
}
/// Gets all the rows for the matching block and converts them to a Diff map.
func (diff *DiffDb) GetDiff(blockNum *big.Int) (Diff, error) {
// make the query
rows, err := diff.db.Query(selectStmt, blockNum.Uint64())
if err != nil {
return nil, err
}
// initialize our data
res := make(Diff)
var block uint64
var address common.Address
var key common.Hash
var mutated bool
for rows.Next() {
// deserialize the line
err = rows.Scan(&block, &address, &key, &mutated)
if err != nil {
return nil, err
}
// add the data to the map
res[address] = append(res[address], Key{key, mutated})
}
return res, rows.Err()
}
// Initializes the transaction which we will be using to commit data to the db
func (diff *DiffDb) resetTx() error {
// reset the number of calls made
diff.numCalls = 0
// start a new tx
tx, err := diff.db.Begin()
if err != nil {
return err
}
diff.tx = tx
// the tx is about inserts
stmt, err := diff.tx.Prepare(insertStatement)
if err != nil {
return err
}
diff.stmt = stmt
return nil
}
func (diff *DiffDb) Close() error {
return diff.db.Close()
}
/// Instantiates a new DiffDb using sqlite at `path`, with `cache` insertions
/// done in a transaction before it gets committed to the database.
func NewDiffDb(path string, cache uint64) (*DiffDb, error) {
// get a handle
db, err := sql.Open("sqlite3", path)
if err != nil {
return nil, err
}
// create the table if it does not exist
_, err = db.Exec(createStmt)
if err != nil {
return nil, err
}
diffdb := &DiffDb{db: db, cache: cache}
// initialize the transaction
if err := diffdb.resetTx(); err != nil {
return nil, err
}
return diffdb, nil
}
package diffdb
import (
"math/big"
"os"
"testing"
"github.com/ethereum/go-ethereum/common"
)
func TestDiffDb(t *testing.T) {
db, err := NewDiffDb("./test_diff.db", 3)
// cleanup (sqlite will create the file if it doesn't exist)
defer os.Remove("./test_diff.db")
if err != nil {
t.Fatal(err)
}
hashes := []common.Hash{
common.Hash{0x0},
common.Hash{0x1},
common.Hash{0x2},
}
addr := common.Address{0x1}
db.SetDiffKey(big.NewInt(1), common.Address{0x1, 0x2}, common.Hash{0x12, 0x13}, false)
db.SetDiffKey(big.NewInt(1), addr, hashes[0], false)
db.SetDiffKey(big.NewInt(1), addr, hashes[1], false)
db.SetDiffKey(big.NewInt(1), addr, hashes[2], false)
db.SetDiffKey(big.NewInt(1), common.Address{0x2}, common.Hash{0x99}, false)
db.SetDiffKey(big.NewInt(2), common.Address{0x2}, common.Hash{0x98}, true)
// try overwriting, ON CONFLICT clause gets hit
err = db.SetDiffKey(big.NewInt(2), common.Address{0x2}, common.Hash{0x98}, false)
if err != nil {
t.Fatal("should be able to resolve conflict without error at the sql level")
}
diff, err := db.GetDiff(big.NewInt(1))
if err != nil {
t.Fatal("Did not expect error")
}
for i := range hashes {
if hashes[i] != diff[addr][i].Key {
t.Fatal("Did not match", hashes[i], "got", diff[addr][i].Key)
}
}
diff, _ = db.GetDiff(big.NewInt(2))
if diff[common.Address{0x2}][0].Mutated != true {
t.Fatalf("Did not match mutated")
}
}
......@@ -31,7 +31,6 @@ import (
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/diffdb"
"github.com/ethereum/go-ethereum/eth/downloader"
"github.com/ethereum/go-ethereum/eth/gasprice"
"github.com/ethereum/go-ethereum/ethdb"
......@@ -97,10 +96,6 @@ func (b *EthAPIBackend) CurrentBlock() *types.Block {
return b.eth.blockchain.CurrentBlock()
}
func (b *EthAPIBackend) GetDiff(block *big.Int) (diffdb.Diff, error) {
return b.eth.blockchain.GetDiff(block)
}
func (b *EthAPIBackend) SetHead(number uint64) {
if number == 0 {
log.Info("Cannot reset to genesis")
......
......@@ -22,7 +22,6 @@ import (
"errors"
"fmt"
"math/big"
"path/filepath"
"runtime"
"sync"
"sync/atomic"
......@@ -190,9 +189,7 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
}
)
// Save the diffdb under chaindata/diffdb
diffdbPath := filepath.Join(ctx.ResolvePath("chaindata"), "diffdb")
eth.blockchain, err = core.NewBlockChainWithDiffDb(chainDb, cacheConfig, chainConfig, eth.engine, vmConfig, eth.shouldPreserve, diffdbPath, config.DiffDbCache)
eth.blockchain, err = core.NewBlockChain(chainDb, cacheConfig, chainConfig, eth.engine, vmConfig, eth.shouldPreserve)
if err != nil {
return nil, err
}
......
......@@ -82,7 +82,6 @@ var DefaultConfig = Config{
// safety.
MaxCallDataSize: 127000,
},
DiffDbCache: 256,
}
func init() {
......@@ -139,7 +138,6 @@ type Config struct {
DatabaseHandles int `toml:"-"`
DatabaseCache int
DatabaseFreezer string
DiffDbCache uint64
TrieCleanCache int
TrieDirtyCache int
......
......@@ -40,7 +40,6 @@ import (
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/diffdb"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/p2p"
"github.com/ethereum/go-ethereum/params"
......@@ -571,61 +570,6 @@ type HeaderMeta struct {
Timestamp uint64 `json:"timestamp"`
}
func (s *PublicBlockChainAPI) GetStateDiff(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) (diffdb.Diff, error) {
_, header, err := s.b.StateAndHeaderByNumberOrHash(ctx, blockNrOrHash)
if err != nil {
return nil, err
}
return s.b.GetDiff(new(big.Int).Add(header.Number, big.NewInt(1)))
}
// GetStateDiffProof returns the Merkle-proofs corresponding to all the accounts and
// storage slots which were touched for a given block number or hash.
func (s *PublicBlockChainAPI) GetStateDiffProof(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) (*StateDiffProof, error) {
state, header, err := s.b.StateAndHeaderByNumberOrHash(ctx, blockNrOrHash)
if state == nil || header == nil || err != nil {
return nil, err
}
// get the changed accounts for this block
diffs, err := s.GetStateDiff(ctx, blockNrOrHash)
if err != nil {
return nil, err
}
// for each changed account, get their proof
var accounts []AccountResult
for address, keys := range diffs {
// need to convert the hashes to strings, we could maybe refactor getProof
// alternatively
keyStrings := make([]string, len(keys))
for i, key := range keys {
keyStrings[i] = key.Key.String()
}
// get the proofs
res, err := s.GetProof(ctx, address, keyStrings, blockNrOrHash)
if err != nil {
return nil, err
}
accounts = append(accounts, *res)
}
// add some metadata
stateDiffProof := &StateDiffProof{
Header: &HeaderMeta{
Number: header.Number,
Hash: header.Hash(),
StateRoot: header.Root,
Timestamp: header.Time,
},
Accounts: accounts,
}
return stateDiffProof, state.Error()
}
// GetProof returns the Merkle-proof for a given account and optionally some storage keys.
func (s *PublicBlockChainAPI) GetProof(ctx context.Context, address common.Address, storageKeys []string, blockNrOrHash rpc.BlockNumberOrHash) (*AccountResult, error) {
state, _, err := s.b.StateAndHeaderByNumberOrHash(ctx, blockNrOrHash)
......
......@@ -28,7 +28,6 @@ import (
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/diffdb"
"github.com/ethereum/go-ethereum/eth/downloader"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/event"
......@@ -93,7 +92,6 @@ type Backend interface {
GetEthContext() (uint64, uint64)
GetRollupContext() (uint64, uint64, uint64)
GasLimit() uint64
GetDiff(*big.Int) (diffdb.Diff, error)
SuggestL1GasPrice(ctx context.Context) (*big.Int, error)
SetL1GasPrice(context.Context, *big.Int) error
SuggestL2GasPrice(context.Context) (*big.Int, error)
......
......@@ -30,7 +30,6 @@ import (
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/diffdb"
"github.com/ethereum/go-ethereum/eth/downloader"
"github.com/ethereum/go-ethereum/eth/gasprice"
"github.com/ethereum/go-ethereum/ethdb"
......@@ -78,10 +77,6 @@ func (b *LesApiBackend) CurrentBlock() *types.Block {
return types.NewBlockWithHeader(b.eth.BlockChain().CurrentHeader())
}
func (b *LesApiBackend) GetDiff(*big.Int) (diffdb.Diff, error) {
return nil, errors.New("Diffs not supported in light client mode")
}
func (b *LesApiBackend) SetHead(number uint64) {
b.eth.handler.downloader.Cancel()
b.eth.blockchain.SetHead(number)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment