Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: lotus-shed tooling for chain indexer #12474

Conversation

akaladarshi
Copy link
Contributor

@akaladarshi akaladarshi commented Sep 17, 2024

This PR is a part of: #12450

PR changes:

  • Adds lotus-shed indexes validate-chainindex to inspect and backfill the chain indexer through ChainValidateIndex API.

@akaladarshi
Copy link
Contributor Author

akaladarshi commented Sep 17, 2024

@aarshkshah1992

inspect-chainindex cmd uses chainValidateIndex API and also fetches manually from the chain indexer to inspect the data by comparing with chain store data.

Should I keep it that way or remove it because ChainIndexValidate API is already verifying the indexed data ?.

@aarshkshah1992
Copy link
Contributor

@akaladarshi Let's remove it because ChainIndexValidate is already validating the indexed data.

@akaladarshi
Copy link
Contributor Author

akaladarshi commented Sep 17, 2024

@akaladarshi Let's remove it because ChainIndexValidate is already validating the indexed data.

Ok sure.

@aarshkshah1992
Also right now, in inspect we are just doing counts mostly, should we check the data as well?

@aarshkshah1992
Copy link
Contributor

@akaladarshi Yeah we can add data validation as well in a follow-up PR. That would be great 👍
Can you raise a PR to validate the data in addition to the counts against #12450 ?

However, please note that that should be done in the API, not in the lotus-shed command here.

@aarshkshah1992
Copy link
Contributor

@akaladarshi But let's do that once we have this lotus-shed command implementation in place.

@akaladarshi akaladarshi force-pushed the akaladarshi/lotus-shed-chainindexer-tooling branch from fa127ed to 0dc4dba Compare September 17, 2024 18:09
@@ -34,6 +35,15 @@ const (
insertEntry = `INSERT OR IGNORE INTO event_entry(event_id, indexed, flags, key, codec, value) VALUES(?, ?, ?, ?, ?, ?)`
upsertEventsSeen = `INSERT INTO events_seen(height, tipset_key_cid, reverted) VALUES(?, ?, false) ON CONFLICT(height, tipset_key_cid) DO UPDATE SET reverted=false`
tipsetSeen = `SELECT height,reverted FROM events_seen WHERE tipset_key_cid=?`

getEthTxHashCountForTipset = `SELECT COUNT(*) FROM eth_tx_hash WHERE message_cid IN (SELECT message_cid FROM tipset_message WHERE tipset_key_cid = ? AND reverted = 0)`
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aarshkshah1992

should we return data related to eth_tx_hash from ChainValidateIndex API in IndexValidation as well ?.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@akaladarshi After thinking this through, I think we should return data for ETH TX hashes, however for now, let's just continue validating counts like we are currently doing. We can validate the actual contents as well as part of a future work stream but I think what we have is good for now..

@akaladarshi akaladarshi marked this pull request as ready for review September 17, 2024 18:14
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@akaladarshi akaladarshi changed the title feat(lotus-shed): lotus-shed tooling for chain indexer feat: lotus-shed tooling for chain indexer Sep 18, 2024
@github-actions github-actions bot dismissed their stale review September 18, 2024 10:14

PR title now matches the required format.

},
&cli.BoolFlag{
Name: "backfill",
Usage: "Backfill missing index entries while validating the chain index. When enabled, the command will perform backfilling for any missing indexes (default: true)",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"will perform backfilling for any missing epochs in the index"

if fromEpoch == 0 {
curTs, err := api.ChainHead(ctx)
if err != nil {
return err
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need an informative error message

}
fromEpoch = int(curTs.Height()) - 1
} else {
fromEpoch = fromEpoch - 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need this ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only do this is fromEpoch >= head.Height()

Copy link
Contributor Author

@akaladarshi akaladarshi Sep 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was done because ChainValidateIndex fetches event of ts from ts+1, So in case of fromEpoch == head.height(), we can't get ts.Height() + 1.

So due to nature of ChainValidateIndex by default fromEpoch will not be included in backfilling, and to maintain consistency I did fromEpoch -1.


toEpoch := cctx.Int("to")
if toEpoch > fromEpoch {
return fmt.Errorf("to epoch must be less than from epoch")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

errors.New()

fromEpoch, toEpoch)

// starting from the FromEpoch-1 and going down to the ToEpoch
// this is because `ChainValidateIndex` fetches the tipset.height()+1, which might not be available in case of chain head
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this comment is not clear. Wdym by "ChainValidateIndex fetches the tipset.height()+1" ?

if failfast {
return fmt.Errorf("failed to validate index for epoch %d: %w", epoch, err)
}
log.Warnf("Error validating index for epoch %d: %v", epoch, err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use %w for errors.

continue
}

if !indexValidateResp.TipSetKey.IsEmpty() || indexValidateResp.Height != uint64(epoch) && indexValidateResp.Backfilled == backfill {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont think we need this validation block here at all. The ChainIndexValidationAPI guruantees that it will return a valid indexValidateResp if error is nil.

@aarshkshah1992
Copy link
Contributor

@akaladarshi This looks mostly correct. Thanks for all the great work here 👍

Let me merge this, fill in the missing gaps and test it out e2e on a calibnet node. I will tag you for review on the changes I make.

@aarshkshah1992 aarshkshah1992 merged commit e7506cc into filecoin-project:feat/implement-index-validation-api Sep 18, 2024
77 of 79 checks passed
@akaladarshi akaladarshi deleted the akaladarshi/lotus-shed-chainindexer-tooling branch September 19, 2024 05:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 🎉 Done
Development

Successfully merging this pull request may close these issues.

2 participants