store receipt contract hash instead of contract
This commit is contained in:
parent
00031e2b83
commit
649fd54a9f
@ -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;
|
19
db/migrations/00032_update_receipt_cids.sql
Normal file
19
db/migrations/00032_update_receipt_cids.sql
Normal 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;
|
@ -1,9 +1,9 @@
|
||||
-- +goose Up
|
||||
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
|
||||
ADD COLUMN times_validated INTEGER NOT NULL DEFAULT 0;
|
||||
ADD COLUMN times_validated INTEGER NOT NULL DEFAULT 1;
|
||||
|
||||
-- +goose Down
|
||||
ALTER TABLE btc.header_cids
|
||||
|
@ -16,6 +16,7 @@
|
||||
batchSize = 1 # $RESYNC_BATCH_SIZE
|
||||
batchNumber = 50 # $RESYNC_BATCH_NUMBER
|
||||
clearOldCache = false # $RESYNC_CLEAR_OLD_CACHE
|
||||
resetValidation = false # $RESYNC_RESET_VALIDATION
|
||||
|
||||
[superNode]
|
||||
chain = "bitcoin" # $SUPERNODE_CHAIN
|
||||
|
@ -16,6 +16,7 @@
|
||||
batchSize = 5 # $RESYNC_BATCH_SIZE
|
||||
batchNumber = 50 # $RESYNC_BATCH_NUMBER
|
||||
clearOldCache = true # $RESYNC_CLEAR_OLD_CACHE
|
||||
resetValidation = true # $RESYNC_RESET_VALIDATION
|
||||
|
||||
[superNode]
|
||||
chain = "ethereum" # $SUPERNODE_CHAIN
|
||||
|
@ -22,15 +22,14 @@ import (
|
||||
"fmt"
|
||||
"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/hexutil"
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/ethereum/go-ethereum/rlp"
|
||||
"github.com/ethereum/go-ethereum/rpc"
|
||||
"github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/vulcanize/vulcanizedb/pkg/ipfs"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/postgres"
|
||||
)
|
||||
|
||||
|
@ -89,12 +89,12 @@ var (
|
||||
rct2Contract = common.HexToAddress("0x010c")
|
||||
receiptModels1 = map[common.Hash]eth2.ReceiptModel{
|
||||
tx1Hash: {
|
||||
CID: rct1CID,
|
||||
Contract: rct1Contract.String(),
|
||||
CID: rct1CID,
|
||||
ContractHash: crypto.Keccak256Hash(rct1Contract.Bytes()).String(),
|
||||
},
|
||||
tx2Hash: {
|
||||
CID: rct2CID,
|
||||
Contract: rct2Contract.String(),
|
||||
CID: rct2CID,
|
||||
ContractHash: crypto.Keccak256Hash(rct2Contract.Bytes()).String(),
|
||||
},
|
||||
}
|
||||
|
||||
@ -170,8 +170,8 @@ var (
|
||||
rct3CID = "mockRct3CID"
|
||||
receiptModels2 = map[common.Hash]eth2.ReceiptModel{
|
||||
tx3Hash: {
|
||||
CID: rct3CID,
|
||||
Contract: rct1Contract.String(),
|
||||
CID: rct3CID,
|
||||
ContractHash: crypto.Keccak256Hash(rct1Contract.Bytes()).String(),
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -104,12 +104,17 @@ func (pc *PayloadConverter) Convert(payload shared.RawChainData) (shared.Convert
|
||||
for addr := range mappedContracts {
|
||||
logContracts = append(logContracts, addr)
|
||||
}
|
||||
contract := shared.HandleNullAddr(receipt.ContractAddress)
|
||||
var contractHash string
|
||||
if contract != "" {
|
||||
contractHash = crypto.Keccak256Hash(common.HexToAddress(contract).Bytes()).String()
|
||||
}
|
||||
rctMeta := ReceiptModel{
|
||||
Topic0s: topicSets[0],
|
||||
Topic1s: topicSets[1],
|
||||
Topic2s: topicSets[2],
|
||||
Topic3s: topicSets[3],
|
||||
Contract: shared.HandleNullAddr(receipt.ContractAddress),
|
||||
ContractHash: contractHash,
|
||||
LogContracts: logContracts,
|
||||
}
|
||||
// receipt and rctMeta will have same indexes
|
||||
|
@ -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 {
|
||||
_, 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)`,
|
||||
txID, cidMeta.CID, cidMeta.Contract, cidMeta.Topic0s, cidMeta.Topic1s, cidMeta.Topic2s, cidMeta.Topic3s, cidMeta.LogContracts)
|
||||
_, 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)
|
||||
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
|
||||
}
|
||||
|
||||
@ -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 {
|
||||
_, 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)
|
||||
return err
|
||||
}
|
||||
@ -177,7 +178,7 @@ func (in *CIDIndexer) indexStorageCID(tx *sqlx.Tx, storageCID StorageNodeModel,
|
||||
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)
|
||||
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)
|
||||
return err
|
||||
}
|
||||
|
@ -61,7 +61,7 @@ var (
|
||||
Address = common.HexToAddress("0xaE9BEa628c4Ce503DcFD7E305CaB4e29E7476592")
|
||||
AnotherAddress = common.HexToAddress("0xaE9BEa628c4Ce503DcFD7E305CaB4e29E7476593")
|
||||
ContractAddress = crypto.CreateAddress(SenderAddr, MockTransactions[2].Nonce())
|
||||
NullAddr = common.HexToAddress("0x0000000000000000000000000000000000000000")
|
||||
ContractHash = crypto.Keccak256Hash(ContractAddress.Bytes()).String()
|
||||
mockTopic11 = common.HexToHash("0x04")
|
||||
mockTopic12 = common.HexToHash("0x06")
|
||||
mockTopic21 = common.HexToHash("0x05")
|
||||
@ -141,7 +141,7 @@ var (
|
||||
Topic1s: []string{
|
||||
mockTopic12.String(),
|
||||
},
|
||||
Contract: "",
|
||||
ContractHash: "",
|
||||
LogContracts: []string{
|
||||
Address.String(),
|
||||
},
|
||||
@ -154,14 +154,14 @@ var (
|
||||
Topic1s: []string{
|
||||
mockTopic22.String(),
|
||||
},
|
||||
Contract: "",
|
||||
ContractHash: "",
|
||||
LogContracts: []string{
|
||||
AnotherAddress.String(),
|
||||
},
|
||||
},
|
||||
{
|
||||
CID: "",
|
||||
Contract: ContractAddress.String(),
|
||||
ContractHash: ContractHash,
|
||||
LogContracts: []string{},
|
||||
},
|
||||
}
|
||||
@ -174,7 +174,7 @@ var (
|
||||
Topic1s: []string{
|
||||
mockTopic12.String(),
|
||||
},
|
||||
Contract: "",
|
||||
ContractHash: "",
|
||||
LogContracts: []string{
|
||||
Address.String(),
|
||||
},
|
||||
@ -187,14 +187,14 @@ var (
|
||||
Topic1s: []string{
|
||||
mockTopic22.String(),
|
||||
},
|
||||
Contract: "",
|
||||
ContractHash: "",
|
||||
LogContracts: []string{
|
||||
AnotherAddress.String(),
|
||||
},
|
||||
},
|
||||
{
|
||||
CID: Rct3CID.String(),
|
||||
Contract: ContractAddress.String(),
|
||||
ContractHash: ContractHash,
|
||||
LogContracts: []string{},
|
||||
},
|
||||
}
|
||||
|
@ -63,7 +63,7 @@ type ReceiptModel struct {
|
||||
ID int64 `db:"id"`
|
||||
TxID int64 `db:"tx_id"`
|
||||
CID string `db:"cid"`
|
||||
Contract string `db:"contract"`
|
||||
ContractHash string `db:"contract_hash"`
|
||||
LogContracts pq.StringArray `db:"log_contracts"`
|
||||
Topic0s pq.StringArray `db:"topic0s"`
|
||||
Topic1s pq.StringArray `db:"topic1s"`
|
||||
|
@ -189,7 +189,7 @@ func (pub *IPLDPublisher) publishReceipts(receipts []*ipld.EthReceipt, receiptTr
|
||||
}
|
||||
rctCids[rct.TxHash] = ReceiptModel{
|
||||
CID: cid,
|
||||
Contract: receiptMeta[i].Contract,
|
||||
ContractHash: receiptMeta[i].ContractHash,
|
||||
Topic0s: receiptMeta[i].Topic0s,
|
||||
Topic1s: receiptMeta[i].Topic1s,
|
||||
Topic2s: receiptMeta[i].Topic2s,
|
||||
|
@ -215,7 +215,7 @@ func (ecr *CIDRetriever) RetrieveRctCIDsByHeaderID(tx *sqlx.Tx, rctFilter Receip
|
||||
log.Debug("retrieving receipt cids for header id ", headerID)
|
||||
args := make([]interface{}, 0, 4)
|
||||
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
|
||||
FROM eth.receipt_cids, eth.transaction_cids, eth.header_cids
|
||||
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)
|
||||
args := make([]interface{}, 0, 5)
|
||||
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
|
||||
FROM eth.receipt_cids, eth.transaction_cids, eth.header_cids
|
||||
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) {
|
||||
log.Debugf("retrieving receipt cids for tx ids %v", txIDs)
|
||||
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
|
||||
FROM eth.receipt_cids, eth.transaction_cids
|
||||
WHERE tx_id = ANY($1::INTEGER[])
|
||||
|
@ -18,6 +18,7 @@ package eth
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"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 {
|
||||
logContracts = append(logContracts, addr)
|
||||
}
|
||||
contract := shared.HandleNullAddr(receipt.ContractAddress)
|
||||
var contractHash string
|
||||
if contract != "" {
|
||||
contractHash = crypto.Keccak256Hash(common.Hex2Bytes(contract)).String()
|
||||
}
|
||||
// Rct data
|
||||
cids.ReceiptCIDs[matchedTx.Hash()] = eth.ReceiptModel{
|
||||
CID: ethIPLDs.Receipts[i].CID,
|
||||
@ -134,7 +140,7 @@ func (pc *WatcherConverter) Convert(ethIPLDs eth.IPLDs) (*eth.CIDPayload, error)
|
||||
Topic1s: topicSets[1],
|
||||
Topic2s: topicSets[2],
|
||||
Topic3s: topicSets[3],
|
||||
Contract: receipt.ContractAddress.Hex(),
|
||||
ContractHash: contractHash,
|
||||
LogContracts: logContracts,
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user