-
Notifications
You must be signed in to change notification settings - Fork 75
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: Adds draft design doc for new endpoints #3342
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Konstantina Blazhukova <[email protected]>
7088d1c
to
b840444
Compare
Test Results 26 files + 2 382 suites +21 1h 15m 51s ⏱️ + 15m 31s For more details on these failures, see this check. Results for commit e6f883c. ± Comparison against base commit 90739e1. This pull request removes 18 and adds 4 tests. Note that renamed tests count towards both.
♻️ This comment has been updated with latest results. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good start.
I think we have to think through the way in which this would deploy and scale a bit more.
docs/design/additional-endpoints.md
Outdated
@@ -0,0 +1,160 @@ | |||
# Design Document: ERC20/ERC721/ERC1155 Token Transfer Events API, Tokens Owned by an Address |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would name it Block Explorer API Support
docs/design/additional-endpoints.md
Outdated
# Design Document: ERC20/ERC721/ERC1155 Token Transfer Events API, Tokens Owned by an Address | ||
|
||
## Overview | ||
- This document outlines the design for implementing new endpoints allowing exposure of more EVM centric data, similar to Etherscan's and BlockScout's APIs. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- This document outlines the design for implementing new endpoints allowing exposure of more EVM centric data, similar to Etherscan's and BlockScout's APIs. | |
- This document outlines the design for implementing new endpoints allowing exposure of more EVM centric data that support Block Explorer (e.g. Etherscan, BlockScout) API needs. |
docs/design/additional-endpoints.md
Outdated
|
||
## `getTokenTransfers` | ||
|
||
### Components |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be a new package not under relay.
We want it to be a separate deployable service so that it can be scaled separately from the relay and not impact the core APIs
If not the alternative is make endpoint support configureable so that a deployemnt can decide to support explorer APIs only or along with core APIs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reformed the design doc so we implement this as a new package
docs/design/additional-endpoints.md
Outdated
### Overview | ||
|
||
Introduce two new endpoints: | ||
- `getTokenTransfers` - to fetch token transfer events |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Q: what are the params?
You should move the params explanation lower to here.
Also note what's mandatory
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So i think in the overview its enough to state the format of the endpoint and the detailed explanation down where it is, do you think thats fine or should I move it all to this section?
Also I have chosen this classic REST format, which differentiates from the way etherscan and blockscout has implemented their endpoints, entirely with query parameters, not sure if thats gonna affect the user. Do they expect the exactly same format
In etherscan the ednpoints look like this:
GET /api
?module=account
&action=tokentx
&contractaddress=0x9f8f72aa9304c8b593d555f12ef6589cc3a579a2
&address=0x4e83362442b8d1bec281594cea3050c8eb01311c
&page=1
&offset=100
&startblock=0
&endblock=27025780
&sort=asc
&apikey=YourApiKeyToken
docs/design/additional-endpoints.md
Outdated
- Test address matching | ||
- Test token standard detection | ||
|
||
2. **Acceptance Tests** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Acceptance tests should be in teh form of E2E features a User would go through with a focus on the input and the outputs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Edited them : )
docs/design/additional-endpoints.md
Outdated
|
||
### Dependencies | ||
|
||
- ERC registry |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How so, please expand
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 on this. Please expand on how ERC Registry is involved.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good start waiting on a bit more structure
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great process! Many questions and suggestions
docs/design/additional-endpoints.md
Outdated
|
||
### Overview | ||
|
||
Introduce two new endpoints: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, this is a bit misleading. The two items below seem more like methods rather than endpoints don’t you think?
docs/design/additional-endpoints.md
Outdated
MirrorNodeClient->>CommonService: '' | ||
CommonService->>EthImpl: '' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps use a different placeholder instead of an empty string.
docs/design/additional-endpoints.md
Outdated
```mermaid | ||
sequenceDiagram | ||
Client->>EthImpl: getTokenTransfers() | ||
EthImpl->>CommonService: getLogs() | ||
CommonService->>CommonService: getLogsWithParams() | ||
CommonService->>MirrorNodeClient: getContractResultsLogs() | ||
MirrorNodeClient->>CommonService: '' | ||
CommonService->>EthImpl: '' | ||
EthImpl->>EthImpl: getErcRegistry() | ||
EthImpl->>EthImpl: checkContracts() | ||
EthImpl->>Client: Return Response | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice diagram, but perhaps the flow from Client to EthImpl should include RelayServer in between:
Client ->> RelayServer: endpoint_values
RelayServer ->> EthImpl: getTokenTransfers()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also didn’t see anything about getErcRegistry()
, checkContracts()
until inside the flow diagram, and I don’t believe they are methods implemented in the CommenService
or MirrorNodeClient
classes. I think it would be better to note down its purpose and clarify.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So in my opinion, since these endpoints are intended to be RESTful, which should not be conflated with the RPC functionality, should we consider creating a new implementation class other than EthImpl
dedicated specifically to the REST endpoints? In my view, EthImpl is primarily focused on the RPC functionality, so combining the two within a single implementation class could lead to unnecessary overlap. A separate implementation class for the REST endpoints could leverage shared components like CommonService or MirrorNodeClient while maintaining a clear separation of concerns. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this will be a standalone package i reformed the design doc and this is not relevant anymore
docs/design/additional-endpoints.md
Outdated
```typescript | ||
interface TokenTransferEvent { | ||
blockNumber: string; | ||
timeStamp: string; | ||
hash: string; | ||
nonce: number; | ||
blockHash: string; | ||
from: string; | ||
contractAddress: string; | ||
to: string; | ||
tokenId?: string; | ||
tokenName?: string; | ||
tokenSymbol?: string; | ||
tokenDecimal?: number; | ||
transactionIndex: number; | ||
gas: number; | ||
gasPrice: number; | ||
gasUsed: number; | ||
cumulativeGasUsed: number; | ||
input: string; | ||
confirmations: number; | ||
} | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we’re aiming to match Etherscan’s response interface, should we include a link here to clarify where and how this interface is constructed?
docs/design/additional-endpoints.md
Outdated
|
||
#### Key Implementation Details | ||
|
||
The `getTokenTransfers` endpoint will be calling the same method in the `EthImpl` class which will accept the following parameters: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: shouldn't it be method instead of endpoint here?
The `getTokenTransfers` endpoint will be calling the same method in the `EthImpl` class which will accept the following parameters: | |
The `getTokenTransfers` method will be calling the same method in the `EthImpl` class which will accept the following parameters: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed this section, since I reworked the design doc a little bit
docs/design/additional-endpoints.md
Outdated
|
||
1. Possibly restrict the number of logs returned by the MN to a maximum of 10000 | ||
2. Possibly restrict the block range to a maximum of 10000 blocks | ||
3. Consider the amount of resources required to check the ERC registry for each log |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you explain to me what this means?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
its not relevant I deleted it
docs/design/additional-endpoints.md
Outdated
|
||
### Dependencies | ||
|
||
- ERC registry |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 on this. Please expand on how ERC Registry is involved.
bc9bfcc
to
441d39b
Compare
Signed-off-by: Konstantina Blazhukova <[email protected]>
441d39b
to
f81f789
Compare
Signed-off-by: Konstantina Blazhukova <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great start, looking forward to discussing more
|
||
#### 4. CacheService | ||
Redis-based caching service: | ||
- Caches frequent queries |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we call out the cached objects. I'd like to ensure that we only cache what is needed e.g. in some cases the relay caches the full account or token object but we really only need a few fields from the mirror node response.
In this case do we need to cache a full log or can we cache only a subset of them?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, we dont need to cache the full object, so I changed and specified what we will need
|
||
#### 4. CacheService | ||
Redis-based caching service: | ||
- Caches frequent queries |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please suggest an TTL for these caches components.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
docs/design/additional-endpoints.md
Outdated
|
||
### Performance Considerations | ||
|
||
1. Possibly restrict the number of logs returned by the MN to a maximum of 10000 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We currently have a max on the logs endpoint we can likely match that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently, investigating this. Seems like its 100 so added this as a value @Nana-EC
docs/design/additional-endpoints.md
Outdated
packages/ | ||
rest-api/ | ||
└── src/ | ||
├── config/ # Configuration for REST API |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see a section for this, could you add one that calls out which config fields you plan to add and what their defaults might be?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added one :) Its a starting point tho, maybe something comes up later during implementation
docs/design/additional-endpoints.md
Outdated
### Package Structure | ||
``` | ||
packages/ | ||
rest-api/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, another approach would be rest-server
package with the controllers under there and the services under the relay
package or this new rest-api
package.
In this way the service implementation could be change in the future a transparent way or the underlying server logic - both packages decoupled from each other.
Let's chat about it, the above is food for thought and might hint towards the final form we want to get to in a tentative refactor of the repo
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will add it as a point to discuss in the meeting
docs/design/additional-endpoints.md
Outdated
|
||
### Dependencies | ||
|
||
* ERC registry - As explained in the _Flow_ section, the TokenService will need to fetch the ERC registry to get the token standard (ERC20/721/ 1155) contracts and filter the response by only those matching the standard, wanted in the request. E.g if the request is for ERC20, the TokenService will need to fetch the ERC registry to get the ERC20 contracts and filter the response from the MN by only those matching the standard. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should note that initially we'll use the static outputs from the smart contract repo. We should be able to import that package soon but int eh early stage we can copy over the files as needed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed
Signed-off-by: Konstantina Blazhukova <[email protected]>
…ents Signed-off-by: Konstantina Blazhukova <[email protected]>
Signed-off-by: Konstantina Blazhukova <[email protected]>
Quality Gate passedIssues Measures |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #3342 +/- ##
==========================================
- Coverage 85.30% 82.66% -2.64%
==========================================
Files 69 65 -4
Lines 4688 4541 -147
Branches 1050 1036 -14
==========================================
- Hits 3999 3754 -245
- Misses 374 421 +47
- Partials 315 366 +51
Flags with carried forward coverage won't be shown. Click here to find out more.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good suggestions @konstantinabl.
To confirm after some thought we should indeed position this from the get go as an independently deployable instance.
Should be something like http-explorer-server
containing the specific etherscan focused controllers and server logic.
Initially we can colocate the api logic including services in the relay
package then revisit when we pick up the repo refactor
|
||
| Endpoint | Description | | ||
|----------|-------------| | ||
| `GET /api?module=account&action=tokentx&address={address}&contractaddress={contractaddress}&startblock={startblock}&endblock={endblock}&page={page}&offset={offset}&sort={asc\|desc}` | Get ERC20 token transfer events | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we should make the etherscan nature explicit
Somethings like what snowtrace does https://testnet.snowtrace.io/documentation/api-swagger
| `GET /api?module=account&action=tokentx&address={address}&contractaddress={contractaddress}&startblock={startblock}&endblock={endblock}&page={page}&offset={offset}&sort={asc\|desc}` | Get ERC20 token transfer events | | |
| `GET /api/v1/etherscan?module=account&action=tokentx&address={address}&contractaddress={contractaddress}&startblock={startblock}&endblock={endblock}&page={page}&offset={offset}&sort={asc\|desc}` | Get ERC20 token transfer events | |
|
||
Currently MN doesn't support EVM centric queries, like token transfer events for specific standards like ERC20, ERC721, ERC1155 or balance of an address for a specific token. | ||
|
||
## Goals |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please take a look at
https://api-testnet.snowtrace.io/api?module=contract&action=getsourcecode&address=0x5425890298aed601595a70AB815c96711a31Bc65, a user may use this when looking for ABI
I think this might be another goal to capture. P2 in nature for this story though.
This is very interesting as it may require calling the verification service.
@acuarica do you see any other option to retrieve such information?
Description:
Creates a design document for the new block explorer REST API endpoints
Related issue(s):
Fixes #3340
Notes for reviewer: