Address comments.
This commit is contained in:
parent
e4de336833
commit
112cdc9670
@ -22,12 +22,12 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ancientDBPath = "ANCIENT_DB_PATH"
|
ANCIENT_DB_PATH = "ANCIENT_DB_PATH"
|
||||||
ethClientName = "ETH_CLIENT_NAME"
|
ETH_CLIENT_NAME = "ETH_CLIENT_NAME"
|
||||||
ethGenesisBlock = "ETH_GENESIS_BLOCK"
|
ETH_GENESIS_BLOCK = "ETH_GENESIS_BLOCK"
|
||||||
ethNetworkID = "ETH_NETWORK_ID"
|
ETH_NETWORK_ID = "ETH_NETWORK_ID"
|
||||||
ethNodeID = "ETH_NODE_ID"
|
ETH_NODE_ID = "ETH_NODE_ID"
|
||||||
lvlDBPath = "LVL_DB_PATH"
|
LVL_DB_PATH = "LVL_DB_PATH"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Config is config parameters for DB.
|
// Config is config parameters for DB.
|
||||||
@ -42,12 +42,12 @@ type Config struct {
|
|||||||
// Init Initialises config
|
// Init Initialises config
|
||||||
func (c *Config) Init() {
|
func (c *Config) Init() {
|
||||||
c.dbInit()
|
c.dbInit()
|
||||||
viper.BindEnv("leveldb.path", lvlDBPath)
|
viper.BindEnv("leveldb.path", LVL_DB_PATH)
|
||||||
viper.BindEnv("ethereum.nodeID", ethNodeID)
|
viper.BindEnv("ethereum.nodeID", ETH_NODE_ID)
|
||||||
viper.BindEnv("ethereum.clientName", ethClientName)
|
viper.BindEnv("ethereum.clientName", ETH_CLIENT_NAME)
|
||||||
viper.BindEnv("ethereum.genesisBlock", ethGenesisBlock)
|
viper.BindEnv("ethereum.genesisBlock", ETH_GENESIS_BLOCK)
|
||||||
viper.BindEnv("ethereum.networkID", ethNetworkID)
|
viper.BindEnv("ethereum.networkID", ETH_NETWORK_ID)
|
||||||
viper.BindEnv("leveldb.ancient", ancientDBPath)
|
viper.BindEnv("leveldb.ancient", ANCIENT_DB_PATH)
|
||||||
|
|
||||||
c.Node = ethNode.Info{
|
c.Node = ethNode.Info{
|
||||||
ID: viper.GetString("ethereum.nodeID"),
|
ID: viper.GetString("ethereum.nodeID"),
|
||||||
|
@ -17,10 +17,10 @@ package snapshot
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
blockstore "github.com/ipfs/go-ipfs-blockstore"
|
|
||||||
dshelp "github.com/ipfs/go-ipfs-ds-help"
|
|
||||||
"github.com/jmoiron/sqlx"
|
"github.com/jmoiron/sqlx"
|
||||||
"github.com/multiformats/go-multihash"
|
"github.com/multiformats/go-multihash"
|
||||||
|
|
||||||
@ -90,13 +90,6 @@ func (p *Publisher) PublishStateNode(node *node, headerID int64, tx *sqlx.Tx) (i
|
|||||||
stateKey = node.key.Hex()
|
stateKey = node.key.Hex()
|
||||||
}
|
}
|
||||||
|
|
||||||
defer func() {
|
|
||||||
if rec := recover(); rec != nil {
|
|
||||||
shared.Rollback(tx)
|
|
||||||
panic(rec)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
stateCIDStr, mhKey, err := shared.PublishRaw(tx, ipld.MEthStateTrie, multihash.KECCAK_256, node.value)
|
stateCIDStr, mhKey, err := shared.PublishRaw(tx, ipld.MEthStateTrie, multihash.KECCAK_256, node.value)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
@ -118,13 +111,6 @@ func (p *Publisher) PublishStorageNode(node *node, stateID int64, tx *sqlx.Tx) e
|
|||||||
storageKey = node.key.Hex()
|
storageKey = node.key.Hex()
|
||||||
}
|
}
|
||||||
|
|
||||||
defer func() {
|
|
||||||
if rec := recover(); rec != nil {
|
|
||||||
shared.Rollback(tx)
|
|
||||||
panic(rec)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
storageCIDStr, mhKey, err := shared.PublishRaw(tx, ipld.MEthStorageTrie, multihash.KECCAK_256, node.value)
|
storageCIDStr, mhKey, err := shared.PublishRaw(tx, ipld.MEthStorageTrie, multihash.KECCAK_256, node.value)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -142,22 +128,15 @@ func (p *Publisher) PublishStorageNode(node *node, stateID int64, tx *sqlx.Tx) e
|
|||||||
}
|
}
|
||||||
|
|
||||||
// PublishCode writes code to the ipfs backing pg datastore
|
// PublishCode writes code to the ipfs backing pg datastore
|
||||||
func (p *Publisher) PublishCode(code []byte, tx *sqlx.Tx) error {
|
func (p *Publisher) PublishCode(codeHash common.Hash, codeBytes []byte, tx *sqlx.Tx) error {
|
||||||
// no codec for code, doesn't matter though since blockstore key is multihash-derived
|
// no codec for code, doesn't matter though since blockstore key is multihash-derived
|
||||||
return p.publishRaw(ipld.MEthStorageTrie, multihash.KECCAK_256, code, tx)
|
mhKey, err := shared.MultihashKeyFromKeccak256(codeHash)
|
||||||
}
|
|
||||||
|
|
||||||
func (p *Publisher) publishRaw(codec, mh uint64, raw []byte, tx *sqlx.Tx) error {
|
|
||||||
c, err := ipld.RawdataToCid(codec, raw, mh)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return fmt.Errorf("error deriving multihash key from codehash: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
dbKey := dshelp.MultihashToDsKey(c.Hash())
|
if err = shared.PublishDirect(tx, mhKey, codeBytes); err != nil {
|
||||||
prefixedKey := blockstore.BlockPrefix.String() + dbKey.String()
|
return fmt.Errorf("error publishing code IPLD: %v", err)
|
||||||
_, err = tx.Exec(`INSERT INTO public.blocks (key, data) VALUES ($1, $2) ON CONFLICT (key) DO NOTHING`, prefixedKey, raw)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
p.currBatchSize++
|
p.currBatchSize++
|
||||||
|
@ -28,6 +28,7 @@ import (
|
|||||||
"github.com/ethereum/go-ethereum/ethdb"
|
"github.com/ethereum/go-ethereum/ethdb"
|
||||||
"github.com/ethereum/go-ethereum/rlp"
|
"github.com/ethereum/go-ethereum/rlp"
|
||||||
"github.com/ethereum/go-ethereum/statediff/indexer/postgres"
|
"github.com/ethereum/go-ethereum/statediff/indexer/postgres"
|
||||||
|
"github.com/ethereum/go-ethereum/statediff/indexer/shared"
|
||||||
"github.com/ethereum/go-ethereum/trie"
|
"github.com/ethereum/go-ethereum/trie"
|
||||||
"github.com/jmoiron/sqlx"
|
"github.com/jmoiron/sqlx"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
@ -136,7 +137,14 @@ func (s *Service) createSnapshot(it trie.NodeIterator, trieDB *trie.Database, he
|
|||||||
}
|
}
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
err = tx.Commit()
|
if rec := recover(); rec != nil {
|
||||||
|
shared.Rollback(tx)
|
||||||
|
panic(rec)
|
||||||
|
} else if err != nil {
|
||||||
|
shared.Rollback(tx)
|
||||||
|
} else {
|
||||||
|
err = tx.Commit()
|
||||||
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
for it.Next(true) {
|
for it.Next(true) {
|
||||||
@ -203,13 +211,14 @@ func (s *Service) createSnapshot(it trie.NodeIterator, trieDB *trie.Database, he
|
|||||||
|
|
||||||
// publish any non-nil code referenced by codehash
|
// publish any non-nil code referenced by codehash
|
||||||
if !bytes.Equal(account.CodeHash, emptyCodeHash) {
|
if !bytes.Equal(account.CodeHash, emptyCodeHash) {
|
||||||
codeBytes := rawdb.ReadCode(s.ethDB, common.BytesToHash(account.CodeHash))
|
codeHash := common.BytesToHash(account.CodeHash)
|
||||||
|
codeBytes := rawdb.ReadCode(s.ethDB, codeHash)
|
||||||
if len(codeBytes) == 0 {
|
if len(codeBytes) == 0 {
|
||||||
logrus.Error("Code is missing", "account", common.BytesToHash(it.LeafKey()))
|
logrus.Error("Code is missing", "account", common.BytesToHash(it.LeafKey()))
|
||||||
return errors.New("missing code")
|
return errors.New("missing code")
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = s.ipfsPublisher.PublishCode(codeBytes, tx); err != nil {
|
if err = s.ipfsPublisher.PublishCode(codeHash, codeBytes, tx); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user