store receipt contract hash instead of contract

This commit is contained in:
Ian Norden 2020-04-03 15:15:06 -05:00
parent 00031e2b83
commit 649fd54a9f
14 changed files with 61 additions and 36 deletions

View File

@ -1,7 +0,0 @@
-- +goose Up
ALTER TABLE eth.receipt_cids
ADD COLUMN log_contracts VARCHAR(66)[];
-- +goose Down
ALTER TABLE eth.receipt_cids
DROP COLUMN log_contracts;

View File

@ -0,0 +1,19 @@
-- +goose Up
ALTER TABLE eth.receipt_cids
ADD COLUMN log_contracts VARCHAR(66)[];
ALTER TABLE eth.receipt_cids
RENAME COLUMN contract TO contract_hash;
ALTER TABLE eth.receipt_cids
ADD CONSTRAINT receipt_cids_tx_id_key UNIQUE (tx_id);
-- +goose Down
ALTER TABLE eth.receipt_cids
DROP CONSTRAINT receipt_cids_tx_id_key;
ALTER TABLE eth.receipt_cids
RENAME COLUMN contract_hash TO contract;
ALTER TABLE eth.receipt_cids
DROP COLUMN log_contracts;

View File

@ -1,9 +1,9 @@
-- +goose Up -- +goose Up
ALTER TABLE eth.header_cids ALTER TABLE eth.header_cids
ADD COLUMN times_validated INTEGER NOT NULL DEFAULT 0; ADD COLUMN times_validated INTEGER NOT NULL DEFAULT 1;
ALTER TABLE btc.header_cids ALTER TABLE btc.header_cids
ADD COLUMN times_validated INTEGER NOT NULL DEFAULT 0; ADD COLUMN times_validated INTEGER NOT NULL DEFAULT 1;
-- +goose Down -- +goose Down
ALTER TABLE btc.header_cids ALTER TABLE btc.header_cids

View File

@ -16,6 +16,7 @@
batchSize = 1 # $RESYNC_BATCH_SIZE batchSize = 1 # $RESYNC_BATCH_SIZE
batchNumber = 50 # $RESYNC_BATCH_NUMBER batchNumber = 50 # $RESYNC_BATCH_NUMBER
clearOldCache = false # $RESYNC_CLEAR_OLD_CACHE clearOldCache = false # $RESYNC_CLEAR_OLD_CACHE
resetValidation = false # $RESYNC_RESET_VALIDATION
[superNode] [superNode]
chain = "bitcoin" # $SUPERNODE_CHAIN chain = "bitcoin" # $SUPERNODE_CHAIN

View File

@ -16,6 +16,7 @@
batchSize = 5 # $RESYNC_BATCH_SIZE batchSize = 5 # $RESYNC_BATCH_SIZE
batchNumber = 50 # $RESYNC_BATCH_NUMBER batchNumber = 50 # $RESYNC_BATCH_NUMBER
clearOldCache = true # $RESYNC_CLEAR_OLD_CACHE clearOldCache = true # $RESYNC_CLEAR_OLD_CACHE
resetValidation = true # $RESYNC_RESET_VALIDATION
[superNode] [superNode]
chain = "ethereum" # $SUPERNODE_CHAIN chain = "ethereum" # $SUPERNODE_CHAIN

View File

@ -22,15 +22,14 @@ import (
"fmt" "fmt"
"math/big" "math/big"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/vulcanize/vulcanizedb/pkg/ipfs"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/rlp" "github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/rpc" "github.com/ethereum/go-ethereum/rpc"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"github.com/vulcanize/vulcanizedb/pkg/ipfs"
"github.com/vulcanize/vulcanizedb/pkg/postgres" "github.com/vulcanize/vulcanizedb/pkg/postgres"
) )

View File

@ -89,12 +89,12 @@ var (
rct2Contract = common.HexToAddress("0x010c") rct2Contract = common.HexToAddress("0x010c")
receiptModels1 = map[common.Hash]eth2.ReceiptModel{ receiptModels1 = map[common.Hash]eth2.ReceiptModel{
tx1Hash: { tx1Hash: {
CID: rct1CID, CID: rct1CID,
Contract: rct1Contract.String(), ContractHash: crypto.Keccak256Hash(rct1Contract.Bytes()).String(),
}, },
tx2Hash: { tx2Hash: {
CID: rct2CID, CID: rct2CID,
Contract: rct2Contract.String(), ContractHash: crypto.Keccak256Hash(rct2Contract.Bytes()).String(),
}, },
} }
@ -170,8 +170,8 @@ var (
rct3CID = "mockRct3CID" rct3CID = "mockRct3CID"
receiptModels2 = map[common.Hash]eth2.ReceiptModel{ receiptModels2 = map[common.Hash]eth2.ReceiptModel{
tx3Hash: { tx3Hash: {
CID: rct3CID, CID: rct3CID,
Contract: rct1Contract.String(), ContractHash: crypto.Keccak256Hash(rct1Contract.Bytes()).String(),
}, },
} }

View File

@ -104,12 +104,17 @@ func (pc *PayloadConverter) Convert(payload shared.RawChainData) (shared.Convert
for addr := range mappedContracts { for addr := range mappedContracts {
logContracts = append(logContracts, addr) logContracts = append(logContracts, addr)
} }
contract := shared.HandleNullAddr(receipt.ContractAddress)
var contractHash string
if contract != "" {
contractHash = crypto.Keccak256Hash(common.HexToAddress(contract).Bytes()).String()
}
rctMeta := ReceiptModel{ rctMeta := ReceiptModel{
Topic0s: topicSets[0], Topic0s: topicSets[0],
Topic1s: topicSets[1], Topic1s: topicSets[1],
Topic2s: topicSets[2], Topic2s: topicSets[2],
Topic3s: topicSets[3], Topic3s: topicSets[3],
Contract: shared.HandleNullAddr(receipt.ContractAddress), ContractHash: contractHash,
LogContracts: logContracts, LogContracts: logContracts,
} }
// receipt and rctMeta will have same indexes // receipt and rctMeta will have same indexes

View File

@ -127,8 +127,9 @@ func (in *CIDIndexer) indexTransactionAndReceiptCIDs(tx *sqlx.Tx, payload *CIDPa
} }
func (in *CIDIndexer) indexReceiptCID(tx *sqlx.Tx, cidMeta ReceiptModel, txID int64) error { func (in *CIDIndexer) indexReceiptCID(tx *sqlx.Tx, cidMeta ReceiptModel, txID int64) error {
_, err := tx.Exec(`INSERT INTO eth.receipt_cids (tx_id, cid, contract, topic0s, topic1s, topic2s, topic3s, log_contracts) VALUES ($1, $2, $3, $4, $5, $6, $7, $8)`, _, err := tx.Exec(`INSERT INTO eth.receipt_cids (tx_id, cid, contract_hash, topic0s, topic1s, topic2s, topic3s, log_contracts) VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
txID, cidMeta.CID, cidMeta.Contract, cidMeta.Topic0s, cidMeta.Topic1s, cidMeta.Topic2s, cidMeta.Topic3s, cidMeta.LogContracts) ON CONFLICT (tx_id) DO UPDATE SET (cid, contract_hash, topic0s, topic1s, topic2s, topic3s, log_contracts) = ($2, $3, $4, $5, $6, $7, $8)`,
txID, cidMeta.CID, cidMeta.ContractHash, cidMeta.Topic0s, cidMeta.Topic1s, cidMeta.Topic2s, cidMeta.Topic3s, cidMeta.LogContracts)
return err return err
} }
@ -166,7 +167,7 @@ func (in *CIDIndexer) indexStateAndStorageCIDs(tx *sqlx.Tx, payload *CIDPayload,
func (in *CIDIndexer) indexStateAccount(tx *sqlx.Tx, stateAccount StateAccountModel, stateID int64) error { func (in *CIDIndexer) indexStateAccount(tx *sqlx.Tx, stateAccount StateAccountModel, stateID int64) error {
_, err := tx.Exec(`INSERT INTO eth.state_accounts (state_id, balance, nonce, code_hash, storage_root) VALUES ($1, $2, $3, $4, $5) _, err := tx.Exec(`INSERT INTO eth.state_accounts (state_id, balance, nonce, code_hash, storage_root) VALUES ($1, $2, $3, $4, $5)
ON CONFLICT (state_id) DO UPDATE SET (balance, nonce, code_hash, storage_root) = ($2, $3, $4, $5)`, ON CONFLICT (state_id) DO UPDATE SET (balance, nonce, code_hash, storage_root) = ($2, $3, $4, $5)`,
stateID, stateAccount.Balance, stateAccount.Nonce, stateAccount.CodeHash, stateAccount.StorageRoot) stateID, stateAccount.Balance, stateAccount.Nonce, stateAccount.CodeHash, stateAccount.StorageRoot)
return err return err
} }
@ -177,7 +178,7 @@ func (in *CIDIndexer) indexStorageCID(tx *sqlx.Tx, storageCID StorageNodeModel,
storageKey = storageCID.StorageKey storageKey = storageCID.StorageKey
} }
_, err := tx.Exec(`INSERT INTO eth.storage_cids (state_id, storage_leaf_key, cid, storage_path, node_type) VALUES ($1, $2, $3, $4, $5) _, err := tx.Exec(`INSERT INTO eth.storage_cids (state_id, storage_leaf_key, cid, storage_path, node_type) VALUES ($1, $2, $3, $4, $5)
ON CONFLICT (state_id, storage_path) DO UPDATE SET (storage_leaf_key, cid, node_type) = ($2, $3, $5)`, ON CONFLICT (state_id, storage_path) DO UPDATE SET (storage_leaf_key, cid, node_type) = ($2, $3, $5)`,
stateID, storageKey, storageCID.CID, storageCID.Path, storageCID.NodeType) stateID, storageKey, storageCID.CID, storageCID.Path, storageCID.NodeType)
return err return err
} }

View File

@ -61,7 +61,7 @@ var (
Address = common.HexToAddress("0xaE9BEa628c4Ce503DcFD7E305CaB4e29E7476592") Address = common.HexToAddress("0xaE9BEa628c4Ce503DcFD7E305CaB4e29E7476592")
AnotherAddress = common.HexToAddress("0xaE9BEa628c4Ce503DcFD7E305CaB4e29E7476593") AnotherAddress = common.HexToAddress("0xaE9BEa628c4Ce503DcFD7E305CaB4e29E7476593")
ContractAddress = crypto.CreateAddress(SenderAddr, MockTransactions[2].Nonce()) ContractAddress = crypto.CreateAddress(SenderAddr, MockTransactions[2].Nonce())
NullAddr = common.HexToAddress("0x0000000000000000000000000000000000000000") ContractHash = crypto.Keccak256Hash(ContractAddress.Bytes()).String()
mockTopic11 = common.HexToHash("0x04") mockTopic11 = common.HexToHash("0x04")
mockTopic12 = common.HexToHash("0x06") mockTopic12 = common.HexToHash("0x06")
mockTopic21 = common.HexToHash("0x05") mockTopic21 = common.HexToHash("0x05")
@ -141,7 +141,7 @@ var (
Topic1s: []string{ Topic1s: []string{
mockTopic12.String(), mockTopic12.String(),
}, },
Contract: "", ContractHash: "",
LogContracts: []string{ LogContracts: []string{
Address.String(), Address.String(),
}, },
@ -154,14 +154,14 @@ var (
Topic1s: []string{ Topic1s: []string{
mockTopic22.String(), mockTopic22.String(),
}, },
Contract: "", ContractHash: "",
LogContracts: []string{ LogContracts: []string{
AnotherAddress.String(), AnotherAddress.String(),
}, },
}, },
{ {
CID: "", CID: "",
Contract: ContractAddress.String(), ContractHash: ContractHash,
LogContracts: []string{}, LogContracts: []string{},
}, },
} }
@ -174,7 +174,7 @@ var (
Topic1s: []string{ Topic1s: []string{
mockTopic12.String(), mockTopic12.String(),
}, },
Contract: "", ContractHash: "",
LogContracts: []string{ LogContracts: []string{
Address.String(), Address.String(),
}, },
@ -187,14 +187,14 @@ var (
Topic1s: []string{ Topic1s: []string{
mockTopic22.String(), mockTopic22.String(),
}, },
Contract: "", ContractHash: "",
LogContracts: []string{ LogContracts: []string{
AnotherAddress.String(), AnotherAddress.String(),
}, },
}, },
{ {
CID: Rct3CID.String(), CID: Rct3CID.String(),
Contract: ContractAddress.String(), ContractHash: ContractHash,
LogContracts: []string{}, LogContracts: []string{},
}, },
} }

View File

@ -63,7 +63,7 @@ type ReceiptModel struct {
ID int64 `db:"id"` ID int64 `db:"id"`
TxID int64 `db:"tx_id"` TxID int64 `db:"tx_id"`
CID string `db:"cid"` CID string `db:"cid"`
Contract string `db:"contract"` ContractHash string `db:"contract_hash"`
LogContracts pq.StringArray `db:"log_contracts"` LogContracts pq.StringArray `db:"log_contracts"`
Topic0s pq.StringArray `db:"topic0s"` Topic0s pq.StringArray `db:"topic0s"`
Topic1s pq.StringArray `db:"topic1s"` Topic1s pq.StringArray `db:"topic1s"`

View File

@ -189,7 +189,7 @@ func (pub *IPLDPublisher) publishReceipts(receipts []*ipld.EthReceipt, receiptTr
} }
rctCids[rct.TxHash] = ReceiptModel{ rctCids[rct.TxHash] = ReceiptModel{
CID: cid, CID: cid,
Contract: receiptMeta[i].Contract, ContractHash: receiptMeta[i].ContractHash,
Topic0s: receiptMeta[i].Topic0s, Topic0s: receiptMeta[i].Topic0s,
Topic1s: receiptMeta[i].Topic1s, Topic1s: receiptMeta[i].Topic1s,
Topic2s: receiptMeta[i].Topic2s, Topic2s: receiptMeta[i].Topic2s,

View File

@ -215,7 +215,7 @@ func (ecr *CIDRetriever) RetrieveRctCIDsByHeaderID(tx *sqlx.Tx, rctFilter Receip
log.Debug("retrieving receipt cids for header id ", headerID) log.Debug("retrieving receipt cids for header id ", headerID)
args := make([]interface{}, 0, 4) args := make([]interface{}, 0, 4)
pgStr := `SELECT receipt_cids.id, receipt_cids.tx_id, receipt_cids.cid, pgStr := `SELECT receipt_cids.id, receipt_cids.tx_id, receipt_cids.cid,
receipt_cids.contract, receipt_cids.topic0s, receipt_cids.topic1s, receipt_cids.contract_hash, receipt_cids.topic0s, receipt_cids.topic1s,
receipt_cids.topic2s, receipt_cids.topic3s, receipt_cids.log_contracts receipt_cids.topic2s, receipt_cids.topic3s, receipt_cids.log_contracts
FROM eth.receipt_cids, eth.transaction_cids, eth.header_cids FROM eth.receipt_cids, eth.transaction_cids, eth.header_cids
WHERE receipt_cids.tx_id = transaction_cids.id WHERE receipt_cids.tx_id = transaction_cids.id
@ -295,7 +295,7 @@ func (ecr *CIDRetriever) RetrieveRctCIDs(tx *sqlx.Tx, rctFilter ReceiptFilter, b
log.Debug("retrieving receipt cids for block ", blockNumber) log.Debug("retrieving receipt cids for block ", blockNumber)
args := make([]interface{}, 0, 5) args := make([]interface{}, 0, 5)
pgStr := `SELECT receipt_cids.id, receipt_cids.tx_id, receipt_cids.cid, pgStr := `SELECT receipt_cids.id, receipt_cids.tx_id, receipt_cids.cid,
receipt_cids.contract, receipt_cids.topic0s, receipt_cids.topic1s, receipt_cids.contract_hash, receipt_cids.topic0s, receipt_cids.topic1s,
receipt_cids.topic2s, receipt_cids.topic3s, receipt_cids.log_contracts receipt_cids.topic2s, receipt_cids.topic3s, receipt_cids.log_contracts
FROM eth.receipt_cids, eth.transaction_cids, eth.header_cids FROM eth.receipt_cids, eth.transaction_cids, eth.header_cids
WHERE receipt_cids.tx_id = transaction_cids.id WHERE receipt_cids.tx_id = transaction_cids.id
@ -587,7 +587,7 @@ func (ecr *CIDRetriever) RetrieveTxCIDsByHeaderID(tx *sqlx.Tx, headerID int64) (
func (ecr *CIDRetriever) RetrieveReceiptCIDsByTxIDs(tx *sqlx.Tx, txIDs []int64) ([]ReceiptModel, error) { func (ecr *CIDRetriever) RetrieveReceiptCIDsByTxIDs(tx *sqlx.Tx, txIDs []int64) ([]ReceiptModel, error) {
log.Debugf("retrieving receipt cids for tx ids %v", txIDs) log.Debugf("retrieving receipt cids for tx ids %v", txIDs)
pgStr := `SELECT receipt_cids.id, receipt_cids.tx_id, receipt_cids.cid, pgStr := `SELECT receipt_cids.id, receipt_cids.tx_id, receipt_cids.cid,
receipt_cids.contract, receipt_cids.topic0s, receipt_cids.topic1s, receipt_cids.contract_hash, receipt_cids.topic0s, receipt_cids.topic1s,
receipt_cids.topic2s, receipt_cids.topic3s, receipt_cids.log_contracts receipt_cids.topic2s, receipt_cids.topic3s, receipt_cids.log_contracts
FROM eth.receipt_cids, eth.transaction_cids FROM eth.receipt_cids, eth.transaction_cids
WHERE tx_id = ANY($1::INTEGER[]) WHERE tx_id = ANY($1::INTEGER[])

View File

@ -18,6 +18,7 @@ package eth
import ( import (
"fmt" "fmt"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
@ -127,6 +128,11 @@ func (pc *WatcherConverter) Convert(ethIPLDs eth.IPLDs) (*eth.CIDPayload, error)
for addr := range mappedContracts { for addr := range mappedContracts {
logContracts = append(logContracts, addr) logContracts = append(logContracts, addr)
} }
contract := shared.HandleNullAddr(receipt.ContractAddress)
var contractHash string
if contract != "" {
contractHash = crypto.Keccak256Hash(common.Hex2Bytes(contract)).String()
}
// Rct data // Rct data
cids.ReceiptCIDs[matchedTx.Hash()] = eth.ReceiptModel{ cids.ReceiptCIDs[matchedTx.Hash()] = eth.ReceiptModel{
CID: ethIPLDs.Receipts[i].CID, CID: ethIPLDs.Receipts[i].CID,
@ -134,7 +140,7 @@ func (pc *WatcherConverter) Convert(ethIPLDs eth.IPLDs) (*eth.CIDPayload, error)
Topic1s: topicSets[1], Topic1s: topicSets[1],
Topic2s: topicSets[2], Topic2s: topicSets[2],
Topic3s: topicSets[3], Topic3s: topicSets[3],
Contract: receipt.ContractAddress.Hex(), ContractHash: contractHash,
LogContracts: logContracts, LogContracts: logContracts,
} }
} }