-
Notifications
You must be signed in to change notification settings - Fork 3
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
[Design] List address balances per token on the Explorer #156
Comments
Hi Abadesso, my comments: High Level design
Hathor Explorer Service (Backend)
Hathor Explorer
|
Thanks for your review
Updated the diagram, adding the cronjob inside the Logstash instance
Added it on the tasks breakdown
Updated the design, just worth noticing that I'm not creating an index for the
Yes, I think we can do that on the Lambda, just like the tokens API, right?
Actually, we are currently only allowing the user to sort by value, so I updated the design to consider it
I've added this as a future possibility, I don't know how valuable this would be for now. I will talk with @trondbjoroy and @pedroferreira1 about this |
The diagram has no step 3. Additionally, I think you could add the name of each service below their image. These AWS images are not so straightforward.
Wouldn't it be useful for development to have this index? Unless it adds too much work to have it, but I think that's not the case.
What throttling parameters are we going to use?
Is there some reason why we are giving it a high timeout?
We will use this feature toggle just to turn on and off the feature, or will we do things like partial rollouts as well?
It seems to me that there is nothing to create on Terraform, since the Lambda and API Gateway will probably be just added to the explorer-service's serverless, and the other things already exist. |
Updated the diagram
I guess you're right, I didn't add it because we also don't have it on the tokens API. Updated the design removing this notice
I was thinking on setting the same defaults as we have on the wallet-service lambdas and tune it after we learn from usage on the explorer
Not really, I guess we can use the default 6s. Updated the design
For now, those are the features I've created, and they all have the same
You are right, removed the part about terraform and updated the |
This seems like a lot. Although we know the Lambda will be able to handle this, the same request rate would potentially hit our Elasticsearch, right? I'm slightly concerned that someone trying to run a DDoS could be successful in taking the Elasticsearch down. Did @lucas3003 do something about this in the Tokens API? Maybe we could apply similar policies. But at a mininum I would check if we can grab any info about which rate Elasticsearch is capable of hanlding, and decrease this throttle if necessary. We will hardly reach this level of usage under normal circumstances, at least not in the near future. What do you think? |
I applied rate limits on the Explorer Service lambda, but not on the ElasticSearch cluster itself. More info on this PR |
All requests to the Lambda API will hit our elastic search as it is also handling cache I guess we can set the same limits we have on the tokens API for our address balances Lambda and open an issue to check if our current ElasticSearch instance can handle it and tune it accordingly What do you guys think? |
I think that's good enough for now. So we would have 50 req/s as limit, right? For me this is ✔️ |
I also believe this is good enough. Approved for me. |
Problem and Opportunity
We should be able to display the total number of addresses created and list those addresses with the ability to sort them by holdings. It should be possible to see the richest addresses for both HTR and custom tokens.
This design has been heavily inspired by the Token API design
Solution
We will leverage the Wallet Service's already indexed database to populate the Explorer Service with address and token holdings information, ingesting it on ElasticSearch through LogStash
High-Level Design
Steps 1 through 3 describe the synchronization process. Every minute, Logstash will get changes from the Wallet Service
address_balance
table (by using theupdated_at
column) and send them to ElasticSearch.Steps 4 through 6 describe how the client (Explorer) will communicate and how this request will be passed to the ElasticSearch.
Wallet Service
On Wallet Service, two new columns will be added to the
address_balance
table:created_at
andupdated_at
. On migration file, all currentaddress_balance
rows will have the current datetime as initial values for both columns. This is necessary for Logstash to know which records to process.Task Breakdown
Costs
No cost will be added to the Wallet Service
Hathor Explorer Service (Backend)
Hathor Explorer Service will be the place of most of the backend changes. We will re-use the Logstash and ElasticSearch instances that were created for the Token API
GET /address_balance
Note: We will have three indexes on the same ElasticSearch cluster, one for
mainnet
, one fordev-testnet
and another one for thetestnet
API (Hathor Explorer Service - API Gateway):
GET /address_balance?from=:from&token_id=:token_id&sort=:sort
From = Start the records from the nth record.
TokenId = Filter by
token_id
Sort = Since we will only allow sorting by value for now (until we add the total supply percentage), only available parameters are
ASC
orDESC
.GET /tokens
The frontend will use this API to allow the user to search for the token he wants to see information about. It has been described on the Token API Design
Throttling
We should use the same defaults that were set for the Tokens API lambda:
Tasks breakdown
Costs
ElasticSearch
We are currently using only 776MB out of the 30GB available on the current ElasticSearch cluster created for the Token API, since we have monitoring set up for the storage, I suggest we keep the cluster as-is until the data gets large enough to require a cluster upgrade.
Lambda
Considering that the Lambda function will handle 100,000 requests, we will have a total cost of 0.11USD/month.
API Gateway
API Gateway charges $3.70 per million requests. Considering 100,00 requests/month, we will have an estimated total cost of 0.37 USD/month
Logstash
We will also use the same instance created for the Token API, so we should also have no additional costs as the instance is enough to handle both use cases
Hathor Explorer (Frontend)
On this screenshot, the token is already selected from the search auto-complete
On this screenshot, we display the options returned from ElasticSearch, highlighting the searched term
Disclaimer: This is just a mock-up. The final result might not be exactly like this.
Tasks
Costs
No additional cost will be added to the Explorer, as it already runs on an S3 as a static website.
Tasks Consolidation
Cost Consolidation
Infrastructure
The new infrastructure code will be done in the ops-tools project, on the same deploy structure that already exists for the Tokens API feature
Future Possibilities
Total Supply percentage
Some explorers show on the
address_balance
table the percentage of the total supply each address hasWe currently have a
total_supply
API on the wallet-service that is being used by the network-monitor, but it is a very expensive call as it will fetch this data from thetx_output
table on every request.We could start storing the updated total supply on a separate table on every transaction the wallet-service receives, so this data can be fetched by the explorer (or ingested through ElasticSearch) to be able to display the percentage of the total supply for a token each address has
Share-able search page
On the new Tokens list page, we allow the user to share his search on a specific page, we could also add this feature to the address list page
The text was updated successfully, but these errors were encountered: