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: verfier and server #1

Merged
merged 45 commits into from
Jul 29, 2024
Merged

feat: verfier and server #1

merged 45 commits into from
Jul 29, 2024

Conversation

BarryTong65
Copy link
Collaborator

@BarryTong65 BarryTong65 commented Jul 11, 2024

Description

image

Rationale

The purpose of the Greenfield BSC Archiver is to store the headers and bodies of BSC historical blocks, and to upload the block information to Greenfield via the bundle service.

The Syncer is responsible for retrieving block information through Ethereum calls, storing it in a database, and uploading it to Greenfield through the bundle service. The range of block heights uploaded can be customized; currently, it is set to 100 blocks.

The Verifier periodically verifies the correctness of the objects uploaded to Greenfield. If an error is detected, it updates and uploads the correct version of the object to the bundle service, and also updates the bundle name of the corresponding block in the local block database.

The Server provides RPC interfaces, with parameters currently adapted to Ethereum calls. Variables are customized and generated using a Swagger.yaml file.

  1. eth_getBlockByNumber
  2. eth_getBundledBlockByNumber
  3. eth_blockNumber
  4. eth_getBlockByHash
  5. /bsc/v1/blocks/{block_id}/bundle/name

Further Improvement
Currently, the process of retrieving block heights and storing them in the database is sequential, raising concerns that the high concurrency might overwhelm the bundle service. If the current version’s block tracking speed is slow, an update will be made to employ multiple workers to request and retrieve block heights into memory, and then collectively store them in both the bundle service and the database.

Example

Method: POST
URL: https://gnfd-bsc-archiver-testnet.bnbchain.org/
eth_getBlockByNumber
request

{
    "method": "eth_getBlockByNumber",
    "params": [
        "0x2625A00"
    ],
    "id": 100,
    "jsonrpc": "2.0"
}

response

{
    "id": 100,
    "jsonrpc": "2.0",
    "result": {
        "difficulty": "0x2",
        "extraData": "0xd883010002846765746888676f312e31332e34856c696e757800000000000000924cd67a1565fdd24dd59327a298f1d702d6b7a721440c063713cecb7229f4e162ae38be78f6f71aa5badeaaef35cea25061ee2100622a4a1631a07e862b517401",
        "gasLimit": "0x25ff7a7",
        "gasUsed": "0x300b37",
        "hash": "0x04055304e432294a65ff31069c4d3092ff8b58f009cdb50eba5351e0332ad0f6",
        "logsBloom": "0x08000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000",
        "miner": "0x2a7cdd959bFe8D9487B2a43B33565295a698F7e2",
        "mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
        "nonce": "0x0000000000000000",
        "number": "0x1",
        "parentHash": "0x0d21840abff46b96c84b2ac9e10e4f5cdaeb5693cb665db62a2f3b02d2d57b5b",
        "receiptsRoot": "0xfc7c0fda97e67ed8ae06e7a160218b3df995560dfcb209a3b0dddde969ec6b00",
        "sha3Uncles": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
        "size": "0x558",
        "stateRoot": "0x1db428ea79cb2e8cc233ae7f4db7c3567adfcb699af668a9f583fdae98e95588",
        "timestamp": "0x5f49ca59",
        "totalDifficulty": "0x3",
        "transactions": [
            {
                "accessList": null,
                "blockHash": "0x04055304e432294a65ff31069c4d3092ff8b58f009cdb50eba5351e0332ad0f6",
                "blockNumber": "0x1",
                "chainId": "0x38",
                "from": "0x2a7cdd959bFe8D9487B2a43B33565295a698F7e2",
                "gas": "0x7fffffffffffffff",
                "gasPrice": "0x0",
                "hash": "0xbaf8ffa0b475a67cfeac3992d24422804452f0982e4e21a8816db2e0c9e5f224",
                "input": "0xe1c7392a",
                "nonce": "0x0",
                "r": "0xba64c6614028e6f7fa4cf2b218719160b9850c591279218def6894586ab73157",
                "s": "0x69cd1b3041eaa9b282a522c49b294e3c51801a1347bb8999015a0bd29bed3bbf",
                "to": "0x0000000000000000000000000000000000001000",
                "transactionIndex": "0x0",
                "type": "0x0",
                "v": "0x93",
                "value": "0x0"
            },
            {
                "accessList": null,
                "blockHash": "0x04055304e432294a65ff31069c4d3092ff8b58f009cdb50eba5351e0332ad0f6",
                "blockNumber": "0x1",
                "chainId": "0x38",
                "from": "0x2a7cdd959bFe8D9487B2a43B33565295a698F7e2",
                "gas": "0x7fffffffffffffff",
                "gasPrice": "0x0",
                "hash": "0x8ea486df4eafaf713fbbe3b4b0b4196e50fbd1ea93daf66675accf3bf3f59d00",
                "input": "0xe1c7392a",
                "nonce": "0x1",
                "r": "0xd6541593c8d1bce8024f2bccfa6f73fc3a107f08e02b39a4571a027863558b3b",
                "s": "0x3448e68c416c115137e9cd1b04a9a09e10a53eadd958d9606962b4170ffffbe7",
                "to": "0x0000000000000000000000000000000000001001",
                "transactionIndex": "0x1",
                "type": "0x0",
                "v": "0x93",
                "value": "0x0"
            },
            {
                "accessList": null,
                "blockHash": "0x04055304e432294a65ff31069c4d3092ff8b58f009cdb50eba5351e0332ad0f6",
                "blockNumber": "0x1",
                "chainId": "0x38",
                "from": "0x2a7cdd959bFe8D9487B2a43B33565295a698F7e2",
                "gas": "0x7fffffffffffffff",
                "gasPrice": "0x0",
                "hash": "0x9ebc5237eabb339a103a34daf280db3d9498142b49fa47f1af71f64a605acffa",
                "input": "0xe1c7392a",
                "nonce": "0x2",
                "r": "0x151f5a54ed865ed852eafe84be6557c13c6d23535ff0ec212e043f48ba5c275d",
                "s": "0x17fa5ca73322133191df498ecb7a9b7fa57a81c403312704314716d81666f848",
                "to": "0x0000000000000000000000000000000000001003",
                "transactionIndex": "0x2",
                "type": "0x0",
                "v": "0x93",
                "value": "0x0"
            },
            {
                "accessList": null,
                "blockHash": "0x04055304e432294a65ff31069c4d3092ff8b58f009cdb50eba5351e0332ad0f6",
                "blockNumber": "0x1",
                "chainId": "0x38",
                "from": "0x2a7cdd959bFe8D9487B2a43B33565295a698F7e2",
                "gas": "0x7fffffffffffffff",
                "gasPrice": "0x0",
                "hash": "0xc043c5d33f8c3a6d6c0853ff8cbe88ebdf746f8092cb763b18de65db45246a6e",
                "input": "0xe1c7392a",
                "nonce": "0x3",
                "r": "0xf1d2414ecd63f567980be648645197d8a0d940921e6e8cde82f9da0ba7259be",
                "s": "0x5add78f836ad168f37cf8fe38432ca01c7827ffbccb8b1981b151f4463651b90",
                "to": "0x0000000000000000000000000000000000001006",
                "transactionIndex": "0x3",
                "type": "0x0",
                "v": "0x94",
                "value": "0x0"
            },
            {
                "accessList": null,
                "blockHash": "0x04055304e432294a65ff31069c4d3092ff8b58f009cdb50eba5351e0332ad0f6",
                "blockNumber": "0x1",
                "chainId": "0x38",
                "from": "0x2a7cdd959bFe8D9487B2a43B33565295a698F7e2",
                "gas": "0x7fffffffffffffff",
                "gasPrice": "0x0",
                "hash": "0x2f64d7e926e6fb62f906e18258097af179c213f0c87a717476cce1b334049797",
                "input": "0xe1c7392a",
                "nonce": "0x4",
                "r": "0x51c8f79cbe3eabe7b8c90fff02b6186c26a31681acea887557450916eaf7b67b",
                "s": "0x63d36286391f2976842e9f541a0ab07aa7e662b79b420f78e59a1e9a487658c9",
                "to": "0x0000000000000000000000000000000000001004",
                "transactionIndex": "0x4",
                "type": "0x0",
                "v": "0x93",
                "value": "0x0"
            },
            {
                "accessList": null,
                "blockHash": "0x04055304e432294a65ff31069c4d3092ff8b58f009cdb50eba5351e0332ad0f6",
                "blockNumber": "0x1",
                "chainId": "0x38",
                "from": "0x2a7cdd959bFe8D9487B2a43B33565295a698F7e2",
                "gas": "0x7fffffffffffffff",
                "gasPrice": "0x0",
                "hash": "0x463f0a179a89f47b055df14897dd7c55a2d819351568045dcb0496f2875c71ee",
                "input": "0xe1c7392a",
                "nonce": "0x5",
                "r": "0x36ffe2a7b51ea50b94dc75e02171e494e1e876902371586f24708a8c8ddb1b1b",
                "s": "0x3164d01a18795962b3a317dfec2ed4393dc0a6c34a2dc2bbb0a986d348f134df",
                "to": "0x0000000000000000000000000000000000001005",
                "transactionIndex": "0x5",
                "type": "0x0",
                "v": "0x93",
                "value": "0x0"
            },
            {
                "accessList": null,
                "blockHash": "0x04055304e432294a65ff31069c4d3092ff8b58f009cdb50eba5351e0332ad0f6",
                "blockNumber": "0x1",
                "chainId": "0x38",
                "from": "0x2a7cdd959bFe8D9487B2a43B33565295a698F7e2",
                "gas": "0x7fffffffffffffff",
                "gasPrice": "0x0",
                "hash": "0xc02fd5fc71fe8bdc4fec3f97a019a4dc9961eb95e5251c55fcb3da76f5cb5bca",
                "input": "0xe1c7392a",
                "nonce": "0x6",
                "r": "0x410b03142901b97ff5c61ed962de42f2aa052799eb1d196a7c1a2aca839e012a",
                "s": "0x599d8118ea6c2bbfe6a2338d21b46667b6ebd7d698221c8c3c580b59f3d49a06",
                "to": "0x0000000000000000000000000000000000002000",
                "transactionIndex": "0x6",
                "type": "0x0",
                "v": "0x94",
                "value": "0x0"
            }
        ],
        "transactionsRoot": "0x53a8743b873570daa630948b1858eaf5dc9bb0bca2093a197e507b2466c110a0",
        "uncles": [],
        "withdrawals": null
    }
}

Choose a reason for hiding this comment

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

shall we remove this Intellij IDE related file, as intelij is not a must for this project?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

removed

@@ -280,7 +280,7 @@ func (c *BundleClient) UploadObject(fileName, bucketName, bundleName, contentTyp
return nil

Choose a reason for hiding this comment

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

When will be the method "func (c *BundleClient) UploadObject" used? Seemingly it is not being used now.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Currently, I use the function UploadAndFinalizeBundle(bundleName, bucketName, bundleDir, bundlePath string) to upload to Greenfield via the bundle service. This function is now obsolete and has been removed.

config/example/config-syncer.json Outdated Show resolved Hide resolved
config/example/config-syncer.json Outdated Show resolved Hide resolved
config/example/config-syncer.json Outdated Show resolved Hide resolved
db/dao.go Show resolved Hide resolved
syncer/syncer.go Outdated Show resolved Hide resolved
syncer/syncer.go Outdated Show resolved Hide resolved
service/block.go Outdated Show resolved Hide resolved
service/block.go Show resolved Hide resolved
"stateRoot": "0x1db428ea79cb2e8cc233ae7f4db7c3567adfcb699af668a9f583fdae98e95588",
"timestamp": "0x5f49ca59",
"totalDifficulty": "0x3",
"transactions": [
Copy link
Collaborator

Choose a reason for hiding this comment

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

The example is too long, we dont have to show all of them. It can improve the readability of the readme.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed

2. eth_getBundledBlockByNumber
3. eth_blockNumber
4. eth_getBlockByHash
5. /bsc/v1/blocks/{block_id}/bundle/name
Copy link
Collaborator

Choose a reason for hiding this comment

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

TODO: put the public endpoint of the service after deploy

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

add the endpoint https://gnfd-bsc-archiver-testnet.bnbchain.org/ to the readme

@@ -1,14 +1,14 @@
{
"chain": "BSC",
"bucket_name": "yourbucketname",
"bucket_name": "bsc-historical-blocks-testnet-concurrency",
Copy link
Collaborator

Choose a reason for hiding this comment

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

name concurrency is unnecessary, user dont have to aware of this

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

change to yourbucketname

README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
db/dao.go Show resolved Hide resolved
external/cmn/sp_client.go Outdated Show resolved Hide resolved
restapi/handlers/block.go Outdated Show resolved Hide resolved
syncer/syncer.go Outdated Show resolved Hide resolved
syncer/syncer.go Outdated Show resolved Hide resolved
syncer/syncer.go Show resolved Hide resolved
syncer/syncer.go Show resolved Hide resolved
Copy link
Collaborator

@alexgao001 alexgao001 left a comment

Choose a reason for hiding this comment

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

the .idea folder should be added to gitignore

@BarryTong65
Copy link
Collaborator Author

BarryTong65 commented Jul 25, 2024

the .idea folder should be added to gitignore

removed the .idea file and add it to the gitignore
image

@BarryTong65 BarryTong65 merged commit 38eabae into main Jul 29, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants