Geth 1.13 (Deneb/Cancun) update #5
@ -48,7 +48,19 @@ func ReadLegacyTrieNode(db ethdb.KeyValueReader, hash common.Hash, codec uint64)
|
|||||||
return enc, nil
|
return enc, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func WriteLegacyTrieNode(db ethdb.KeyValueWriter, hash common.Hash, codec uint64, data []byte) error {
|
// HasLegacyTrieNode checks if the trie node with the provided hash is present in db.
|
||||||
|
func HasLegacyTrieNode(db ethdb.KeyValueReader, hash common.Hash, codec uint64) bool {
|
||||||
|
cid, err := Keccak256ToCid(codec, hash[:])
|
||||||
|
if err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
ok, _ := db.Has(cid.Bytes())
|
||||||
|
return ok
|
||||||
|
}
|
||||||
|
|
||||||
|
func WriteLegacyTrieNode(db ethdb.KeyValueWriter, hash common.Hash, data []byte, codec uint64) error {
|
||||||
|
//
|
||||||
|
panic("Writing to the DB is disabled")
|
||||||
cid, err := Keccak256ToCid(codec, hash[:])
|
cid, err := Keccak256ToCid(codec, hash[:])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -61,5 +73,5 @@ func ReadCode(db ethdb.KeyValueReader, hash common.Hash) ([]byte, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func WriteCode(db ethdb.KeyValueWriter, hash common.Hash, code []byte) error {
|
func WriteCode(db ethdb.KeyValueWriter, hash common.Hash, code []byte) error {
|
||||||
return WriteLegacyTrieNode(db, hash, ipld.RawBinary, code)
|
return WriteLegacyTrieNode(db, hash, code, ipld.RawBinary)
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,15 @@
|
|||||||
// This package is a near complete copy of go-ethereum/trie and go-ethereum/core/state, modified to use
|
// This package is a near complete copy of go-ethereum/trie and go-ethereum/core/state, modified to use
|
||||||
// a v0 IPFS blockstore as the backing DB, i.e. DB values are indexed by CID rather than hash.
|
// a v0 IPFS blockstore as the backing DB, i.e. DB values are indexed by CID rather than hash.
|
||||||
package trie_by_cid
|
package trie_by_cid
|
||||||
|
|
||||||
|
// Note: This is written so as to minimize the difference from the geth packages to allow easier
|
||||||
|
// patching during upgrades.
|
||||||
|
//
|
||||||
|
// Changes to the original functionality should be marked with (ipld-eth-statedb change)
|
||||||
|
// The main changes are within the triedb/hashdb package.
|
||||||
|
//
|
||||||
|
// Writes are currently disabled and will panic, but they may be useful for testing if possible.
|
||||||
|
//
|
||||||
|
// Tests from the original source are preserved as much as reasonably possible. Memory DBs are
|
||||||
|
// replaced with Postgres connections within the state package, but not the trie packages, since
|
||||||
|
// they mostly check the structural consistency of the trie.
|
||||||
|
@ -32,6 +32,7 @@ import (
|
|||||||
"github.com/ethereum/go-ethereum/params"
|
"github.com/ethereum/go-ethereum/params"
|
||||||
"github.com/holiman/uint256"
|
"github.com/holiman/uint256"
|
||||||
|
|
||||||
|
"github.com/cerc-io/ipld-eth-statedb/internal"
|
||||||
"github.com/cerc-io/ipld-eth-statedb/trie_by_cid/trie"
|
"github.com/cerc-io/ipld-eth-statedb/trie_by_cid/trie"
|
||||||
"github.com/cerc-io/ipld-eth-statedb/trie_by_cid/trie/trienode"
|
"github.com/cerc-io/ipld-eth-statedb/trie_by_cid/trie/trienode"
|
||||||
"github.com/cerc-io/ipld-eth-statedb/trie_by_cid/trie/triestate"
|
"github.com/cerc-io/ipld-eth-statedb/trie_by_cid/trie/triestate"
|
||||||
@ -1192,7 +1193,8 @@ func (s *StateDB) Commit(block uint64, deleteEmptyObjects bool) (common.Hash, er
|
|||||||
}
|
}
|
||||||
// Write any contract code associated with the state object
|
// Write any contract code associated with the state object
|
||||||
if obj.code != nil && obj.dirtyCode {
|
if obj.code != nil && obj.dirtyCode {
|
||||||
rawdb.WriteCode(codeWriter, common.BytesToHash(obj.CodeHash()), obj.code)
|
// Writes are currently disabled and this will panic (ipld-eth-statedb change)
|
||||||
|
internal.WriteCode(codeWriter, common.BytesToHash(obj.CodeHash()), obj.code)
|
||||||
obj.dirtyCode = false
|
obj.dirtyCode = false
|
||||||
}
|
}
|
||||||
// Write any storage changes in the state object to its storage trie
|
// Write any storage changes in the state object to its storage trie
|
||||||
|
@ -109,7 +109,8 @@ func NewDatabase(diskdb ethdb.Database, config *Config) *Database {
|
|||||||
log.Crit("Both 'hash' and 'path' mode are configured")
|
log.Crit("Both 'hash' and 'path' mode are configured")
|
||||||
}
|
}
|
||||||
if config.PathDB != nil {
|
if config.PathDB != nil {
|
||||||
db.backend = pathdb.New(diskdb, config.PathDB)
|
// Disable PathDB (ipld-eth-statedb change). TODO: look into implementing it
|
||||||
|
panic("PathDB is not compatible with ipld-eth-statedb")
|
||||||
} else {
|
} else {
|
||||||
var resolver hashdb.ChildResolver
|
var resolver hashdb.ChildResolver
|
||||||
if config.IsVerkle {
|
if config.IsVerkle {
|
||||||
|
@ -359,7 +359,7 @@ func (db *Database) Cap(limit common.StorageSize) error {
|
|||||||
for size > limit && oldest != (common.Hash{}) {
|
for size > limit && oldest != (common.Hash{}) {
|
||||||
// Fetch the oldest referenced node and push into the batch
|
// Fetch the oldest referenced node and push into the batch
|
||||||
node := db.dirties[oldest]
|
node := db.dirties[oldest]
|
||||||
rawdb.WriteLegacyTrieNode(batch, oldest, node.node)
|
internal.WriteLegacyTrieNode(batch, oldest, node.node, 0)
|
||||||
|
|
||||||
// If we exceeded the ideal batch size, commit and reset
|
// If we exceeded the ideal batch size, commit and reset
|
||||||
if batch.ValueSize() >= ethdb.IdealBatchSize {
|
if batch.ValueSize() >= ethdb.IdealBatchSize {
|
||||||
@ -482,7 +482,9 @@ func (db *Database) commit(hash common.Hash, batch ethdb.Batch, uncacher *cleane
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// If we've reached an optimal batch size, commit and start over
|
// If we've reached an optimal batch size, commit and start over
|
||||||
rawdb.WriteLegacyTrieNode(batch, hash, node.node)
|
// FIXME: placeholder - this won't work unless we know the codec we need here,
|
||||||
|
// so writes are currently disabled and this will panic (ipld-eth-statedb change)
|
||||||
|
internal.WriteLegacyTrieNode(batch, hash, node.node, 0)
|
||||||
if batch.ValueSize() >= ethdb.IdealBatchSize {
|
if batch.ValueSize() >= ethdb.IdealBatchSize {
|
||||||
if err := batch.Write(); err != nil {
|
if err := batch.Write(); err != nil {
|
||||||
return err
|
return err
|
||||||
@ -552,7 +554,7 @@ func (c *cleaner) Delete(key []byte) error {
|
|||||||
// Initialized returns an indicator if state data is already initialized
|
// Initialized returns an indicator if state data is already initialized
|
||||||
// in hash-based scheme by checking the presence of genesis state.
|
// in hash-based scheme by checking the presence of genesis state.
|
||||||
func (db *Database) Initialized(genesisRoot common.Hash) bool {
|
func (db *Database) Initialized(genesisRoot common.Hash) bool {
|
||||||
return rawdb.HasLegacyTrieNode(db.diskdb, genesisRoot)
|
return internal.HasLegacyTrieNode(db.diskdb, genesisRoot, internal.StateTrieCodec)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update inserts the dirty nodes in provided nodeset into database and link the
|
// Update inserts the dirty nodes in provided nodeset into database and link the
|
||||||
|
Loading…
Reference in New Issue
Block a user