Install
The Indexer system
There are a couple players here. I'll use specific examples to make it clearer, but note that some of these can be generalized.
Filecoin Storage Provider – Hosts data for folks and proves it via the Filecoin Network Chain. Aka Storage Provider.
Indexer (aka storetheindex) – A service that can answer the question: "Given this CID, who has a copy?". This is little more than a lookup table.
Index Provider – A service that runs alongside a Storage Provider and tells the Indexer what content this storage provider has.
The Index Provider serves as the interface between the storage provider and the indexer. It can be used from within Lotus
so that the publishing of new data happens automatically. But it can also happen separately.
The Index Provider sends updates to the Indexer via a series of Advertisement messages. Each message references a previous advertisement so that as a whole it forms an advertisement chain. The state of the indexer is basically a function of consuming this chain from the initial Advertisement to the latest one.
HTTP Index Provider
An HTTP Index provider needs to provide two endpoints:
GET /head
This returns the latest Advertisement that the index provider knows about.
GET /<cid>
This returns the content for a block identified by the given cid.
And that’s it. With those two endpoints an indexer should be able to sync with the provider.
On Syncing
If an indexer has registered an index provider it will occasionally poll the provider to check if there is new content to index. If you want to let the indexer know you have new changes you may call the Announce
endpoint on the indexer.
libp2p Index Provider
While this should be possible in any language, Go has the best support here. If you’re trying to target another language I’d recommend building an HTTP Index provider.
In Go, it’s simplest to use go-legs. Legs provides a simpler interface to go-data-transfer and graphsync.
For an index-provider you’ll want to setup a go-legs Publisher:
And when you have a new Advertisement you’ll call:
That will automatically send a message on the gossipsub channel to let the indexer know there’s a new update for this provider.
The go-legs publisher will also handle the datatransfer requests from the indexer automatically.
Testing your index Provider
After you finish building your index provider, you probably want to test it. You can run the indexer locally and tell it about your index provider. That should cause the indexer to sync from your index provider. Then you can query the indexer to see if it has some content that your index provider provided.
Make sure your index provider has actual content it is providing. You can do this by checking the
/head
endpoint if implementing an HTTP provider or by using https://pkg.go.dev/github.com/filecoin-project/go-legs/dtsync#Syncer.GetHead with go-legs.HTTP:
Make sure you can also fetch that block. For an HTTP provider you should get the block back when hitting
/<cid>
. For a libp2p provider you should be able to call https://pkg.go.dev/github.com/filecoin-project/go-legs/dtsync#Syncer.Sync.HTTP: (using dagconv to convert the dagcbor into readable dagjson)
Now you can see if the indexer can fetch from the provider.
Run the indexer in the background with
Sync the provider with your local indexer using the indexer’s cli. Here’s an example, replace the peer id and addr with your provider’s value.
You can also follow the log from the indexer to see if any errors pop up.
Now query the indexer to see if it returns results for some multihash our indexer provided
If you aren’t sure which multihash to use, you can use the index-provider cli to list some multihashes that your provider is advertising.
If you can read the update on your local indexer, then your provider is ready to go. Reach out in the #storetheindex channel in the filecoin project slack to get added to the mainnet indexer.
Last updated