V1.10.2 statediff 0.0.20 #68
@ -23,6 +23,8 @@ import (
|
|||||||
"math/big"
|
"math/big"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/lib/pq"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/core/state"
|
"github.com/ethereum/go-ethereum/core/state"
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
@ -163,7 +165,8 @@ func (sdi *StateDiffIndexer) PushBlock(block *types.Block, receipts types.Receip
|
|||||||
t = time.Now()
|
t = time.Now()
|
||||||
|
|
||||||
// Publish and index header, collect headerID
|
// Publish and index header, collect headerID
|
||||||
headerID, err := sdi.processHeader(tx, block.Header(), headerNode, reward, totalDifficulty)
|
var headerID int64
|
||||||
|
headerID, err = sdi.processHeader(tx, block.Header(), headerNode, reward, totalDifficulty)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -321,11 +324,36 @@ func (sdi *StateDiffIndexer) processReceiptsAndTxs(tx *sqlx.Tx, args processArgs
|
|||||||
Data: trx.Data(),
|
Data: trx.Data(),
|
||||||
CID: txNode.Cid().String(),
|
CID: txNode.Cid().String(),
|
||||||
MhKey: shared.MultihashKeyFromCID(txNode.Cid()),
|
MhKey: shared.MultihashKeyFromCID(txNode.Cid()),
|
||||||
|
Type: trx.Type(),
|
||||||
}
|
}
|
||||||
txID, err := sdi.dbWriter.upsertTransactionCID(tx, txModel, args.headerID)
|
txID, err := sdi.dbWriter.upsertTransactionCID(tx, txModel, args.headerID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AccessListEntryModel is the db model for eth.access_list_entry
|
||||||
|
type AccessListElementModel struct {
|
||||||
|
ID int64 `db:"id"`
|
||||||
|
Index int64 `db:"index"`
|
||||||
|
TxID int64 `db:"tx_id"`
|
||||||
|
Address string `db:"address"`
|
||||||
|
StorageKeys pq.StringArray `db:"storage_keys"`
|
||||||
|
}
|
||||||
|
// index access list if this is one
|
||||||
|
for j, accessListElement := range trx.AccessList() {
|
||||||
|
storageKeys := make([]string, len(accessListElement.StorageKeys))
|
||||||
|
for k, storageKey := range accessListElement.StorageKeys {
|
||||||
|
storageKeys[k] = storageKey.Hex()
|
||||||
|
}
|
||||||
|
accessListElementModel := models.AccessListElementModel{
|
||||||
|
Index: int64(j),
|
||||||
|
Address: accessListElement.Address.Hex(),
|
||||||
|
StorageKeys: storageKeys,
|
||||||
|
}
|
||||||
|
if err := sdi.dbWriter.upsertAccessListElement(tx, accessListElementModel, txID); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
// index the receipt
|
// index the receipt
|
||||||
rctModel := models.ReceiptModel{
|
rctModel := models.ReceiptModel{
|
||||||
Topic0s: topicSets[0],
|
Topic0s: topicSets[0],
|
||||||
|
@ -80,6 +80,17 @@ func (in *PostgresCIDWriter) upsertTransactionCID(tx *sqlx.Tx, transaction model
|
|||||||
return txID, nil
|
return txID, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (in *PostgresCIDWriter) upsertAccessListElement(tx *sqlx.Tx, accessListElement models.AccessListElementModel, txID int64) error {
|
||||||
|
_, err := tx.Exec(`INSERT INTO eth.access_list_element (tx_id, index, address, storage_keys) VALUES ($1, $2, $3, $4)
|
||||||
|
ON CONFLICT (tx_id, index) DO UPDATE SET (address, storage_keys) = ($3, $4)`,
|
||||||
|
txID, accessListElement.Index, accessListElement.Address, accessListElement.StorageKeys)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("error upserting access_list_element entry: %v", err)
|
||||||
|
}
|
||||||
|
indexerMetrics.accessListEntries.Inc(1)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (in *PostgresCIDWriter) upsertReceiptCID(tx *sqlx.Tx, rct models.ReceiptModel, txID int64) error {
|
func (in *PostgresCIDWriter) upsertReceiptCID(tx *sqlx.Tx, rct models.ReceiptModel, txID int64) error {
|
||||||
_, err := tx.Exec(`INSERT INTO eth.receipt_cids (tx_id, cid, contract, contract_hash, topic0s, topic1s, topic2s, topic3s, log_contracts, mh_key, post_state, post_status) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12)
|
_, err := tx.Exec(`INSERT INTO eth.receipt_cids (tx_id, cid, contract, contract_hash, topic0s, topic1s, topic2s, topic3s, log_contracts, mh_key, post_state, post_status) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12)
|
||||||
ON CONFLICT (tx_id) DO UPDATE SET (cid, contract, contract_hash, topic0s, topic1s, topic2s, topic3s, log_contracts, mh_key, post_state, post_status) = ($2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12)`,
|
ON CONFLICT (tx_id) DO UPDATE SET (cid, contract, contract_hash, topic0s, topic1s, topic2s, topic3s, log_contracts, mh_key, post_state, post_status) = ($2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12)`,
|
||||||
|
Loading…
Reference in New Issue
Block a user