Merge pull request #51 from vulcanize/v1.9.25-statediff-0.0.14
add poststate and status to receipt ipld indexes
This commit is contained in:
commit
aa4339fefc
@ -299,16 +299,8 @@ func (sdi *StateDiffIndexer) processReceiptsAndTxs(tx *sqlx.Tx, args processArgs
|
|||||||
// this is the contract address if this receipt is for a contract creation tx
|
// this is the contract address if this receipt is for a contract creation tx
|
||||||
contract := shared.HandleZeroAddr(receipt.ContractAddress)
|
contract := shared.HandleZeroAddr(receipt.ContractAddress)
|
||||||
var contractHash string
|
var contractHash string
|
||||||
isDeployment := contract != ""
|
if contract != "" {
|
||||||
if isDeployment {
|
|
||||||
contractHash = crypto.Keccak256Hash(common.HexToAddress(contract).Bytes()).String()
|
contractHash = crypto.Keccak256Hash(common.HexToAddress(contract).Bytes()).String()
|
||||||
// if tx is a contract deployment, publish the data (code)
|
|
||||||
// codec doesn't matter in this case sine we are not interested in the cid and the db key is multihash-derived
|
|
||||||
// TODO: THE DATA IS NOT DIRECTLY THE CONTRACT CODE; THERE IS A MISSING PROCESSING STEP HERE
|
|
||||||
// the contractHash => contract code is not currently correct
|
|
||||||
if _, err := shared.PublishRaw(tx, ipld.MEthStorageTrie, multihash.KECCAK_256, trx.Data()); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// index tx first so that the receipt can reference it by FK
|
// index tx first so that the receipt can reference it by FK
|
||||||
txModel := models.TxModel{
|
txModel := models.TxModel{
|
||||||
@ -317,7 +309,6 @@ func (sdi *StateDiffIndexer) processReceiptsAndTxs(tx *sqlx.Tx, args processArgs
|
|||||||
TxHash: trx.Hash().String(),
|
TxHash: trx.Hash().String(),
|
||||||
Index: int64(i),
|
Index: int64(i),
|
||||||
Data: trx.Data(),
|
Data: trx.Data(),
|
||||||
Deployment: isDeployment,
|
|
||||||
CID: txNode.Cid().String(),
|
CID: txNode.Cid().String(),
|
||||||
MhKey: shared.MultihashKeyFromCID(txNode.Cid()),
|
MhKey: shared.MultihashKeyFromCID(txNode.Cid()),
|
||||||
}
|
}
|
||||||
@ -337,6 +328,11 @@ func (sdi *StateDiffIndexer) processReceiptsAndTxs(tx *sqlx.Tx, args processArgs
|
|||||||
CID: rctNode.Cid().String(),
|
CID: rctNode.Cid().String(),
|
||||||
MhKey: shared.MultihashKeyFromCID(rctNode.Cid()),
|
MhKey: shared.MultihashKeyFromCID(rctNode.Cid()),
|
||||||
}
|
}
|
||||||
|
if len(receipt.PostState) == 0 {
|
||||||
|
rctModel.PostStatus = receipt.Status
|
||||||
|
} else {
|
||||||
|
rctModel.PostState = common.Bytes2Hex(receipt.PostState)
|
||||||
|
}
|
||||||
if err := sdi.dbWriter.upsertReceiptCID(tx, rctModel, txID); err != nil {
|
if err := sdi.dbWriter.upsertReceiptCID(tx, rctModel, txID); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -183,10 +183,31 @@ func TestPublishAndIndexer(t *testing.T) {
|
|||||||
switch c {
|
switch c {
|
||||||
case mocks.Rct1CID.String():
|
case mocks.Rct1CID.String():
|
||||||
shared.ExpectEqual(t, data, mocks.MockReceipts.GetRlp(0))
|
shared.ExpectEqual(t, data, mocks.MockReceipts.GetRlp(0))
|
||||||
|
var postStatus uint64
|
||||||
|
pgStr = `SELECT post_status FROM eth.receipt_cids WHERE cid = $1`
|
||||||
|
err = db.Get(&postStatus, pgStr, c)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
shared.ExpectEqual(t, postStatus, mocks.ExpectedPostStatus)
|
||||||
case mocks.Rct2CID.String():
|
case mocks.Rct2CID.String():
|
||||||
shared.ExpectEqual(t, data, mocks.MockReceipts.GetRlp(1))
|
shared.ExpectEqual(t, data, mocks.MockReceipts.GetRlp(1))
|
||||||
|
var postState string
|
||||||
|
pgStr = `SELECT post_state FROM eth.receipt_cids WHERE cid = $1`
|
||||||
|
err = db.Get(&postState, pgStr, c)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
shared.ExpectEqual(t, postState, mocks.ExpectedPostState1)
|
||||||
case mocks.Rct3CID.String():
|
case mocks.Rct3CID.String():
|
||||||
shared.ExpectEqual(t, data, mocks.MockReceipts.GetRlp(2))
|
shared.ExpectEqual(t, data, mocks.MockReceipts.GetRlp(2))
|
||||||
|
var postState string
|
||||||
|
pgStr = `SELECT post_state FROM eth.receipt_cids WHERE cid = $1`
|
||||||
|
err = db.Get(&postState, pgStr, c)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
shared.ExpectEqual(t, postState, mocks.ExpectedPostState2)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -64,6 +64,9 @@ var (
|
|||||||
mockTopic12 = common.HexToHash("0x06")
|
mockTopic12 = common.HexToHash("0x06")
|
||||||
mockTopic21 = common.HexToHash("0x05")
|
mockTopic21 = common.HexToHash("0x05")
|
||||||
mockTopic22 = common.HexToHash("0x07")
|
mockTopic22 = common.HexToHash("0x07")
|
||||||
|
ExpectedPostStatus uint64 = 1
|
||||||
|
ExpectedPostState1 = common.Bytes2Hex(common.HexToHash("0x1").Bytes())
|
||||||
|
ExpectedPostState2 = common.Bytes2Hex(common.HexToHash("0x2").Bytes())
|
||||||
MockLog1 = &types.Log{
|
MockLog1 = &types.Log{
|
||||||
Address: Address,
|
Address: Address,
|
||||||
Topics: []common.Hash{mockTopic11, mockTopic12},
|
Topics: []common.Hash{mockTopic11, mockTopic12},
|
||||||
@ -181,7 +184,7 @@ func createTransactionsAndReceipts() (types.Transactions, types.Receipts, common
|
|||||||
log.Crit(err.Error())
|
log.Crit(err.Error())
|
||||||
}
|
}
|
||||||
// make receipts
|
// make receipts
|
||||||
mockReceipt1 := types.NewReceipt(common.HexToHash("0x0").Bytes(), false, 50)
|
mockReceipt1 := types.NewReceipt(nil, false, 50)
|
||||||
mockReceipt1.Logs = []*types.Log{MockLog1}
|
mockReceipt1.Logs = []*types.Log{MockLog1}
|
||||||
mockReceipt1.TxHash = signedTrx1.Hash()
|
mockReceipt1.TxHash = signedTrx1.Hash()
|
||||||
mockReceipt2 := types.NewReceipt(common.HexToHash("0x1").Bytes(), false, 100)
|
mockReceipt2 := types.NewReceipt(common.HexToHash("0x1").Bytes(), false, 100)
|
||||||
|
@ -60,7 +60,6 @@ type TxModel struct {
|
|||||||
Dst string `db:"dst"`
|
Dst string `db:"dst"`
|
||||||
Src string `db:"src"`
|
Src string `db:"src"`
|
||||||
Data []byte `db:"tx_data"`
|
Data []byte `db:"tx_data"`
|
||||||
Deployment bool `db:"deployment"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReceiptModel is the db model for eth.receipt_cids
|
// ReceiptModel is the db model for eth.receipt_cids
|
||||||
@ -69,6 +68,8 @@ type ReceiptModel struct {
|
|||||||
TxID int64 `db:"tx_id"`
|
TxID int64 `db:"tx_id"`
|
||||||
CID string `db:"cid"`
|
CID string `db:"cid"`
|
||||||
MhKey string `db:"mh_key"`
|
MhKey string `db:"mh_key"`
|
||||||
|
PostStatus uint64 `db:"post_status"`
|
||||||
|
PostState string `db:"post_state"`
|
||||||
Contract string `db:"contract"`
|
Contract string `db:"contract"`
|
||||||
ContractHash string `db:"contract_hash"`
|
ContractHash string `db:"contract_hash"`
|
||||||
LogContracts pq.StringArray `db:"log_contracts"`
|
LogContracts pq.StringArray `db:"log_contracts"`
|
||||||
|
@ -96,9 +96,9 @@ func (in *PostgresCIDWriter) upsertTransactionCID(tx *sqlx.Tx, transaction model
|
|||||||
}
|
}
|
||||||
|
|
||||||
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) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)
|
_, 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) = ($2, $3, $4, $5, $6, $7, $8, $9, $10)`,
|
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)`,
|
||||||
txID, rct.CID, rct.Contract, rct.ContractHash, rct.Topic0s, rct.Topic1s, rct.Topic2s, rct.Topic3s, rct.LogContracts, rct.MhKey)
|
txID, rct.CID, rct.Contract, rct.ContractHash, rct.Topic0s, rct.Topic1s, rct.Topic2s, rct.Topic3s, rct.LogContracts, rct.MhKey, rct.PostState, rct.PostStatus)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
indexerMetrics.receipts.Inc(1)
|
indexerMetrics.receipts.Inc(1)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user