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

release first version #4

Merged
merged 29 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
b2-committer
test-docker/mysql1
test-docker/mysql2
test-docker/postgres1
wallet
batchFile
114 changes: 45 additions & 69 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,79 +1,55 @@
# b2-committer

## Introduction

![img.png](img.png)
## Details
https://github.com/b2network/b2-node/issues/93

## Description

Step1:Rollup Aggregator invoke method verifyBatchesTrustedAggregator in PolygonZkEVM.sol
Step2: b2-committer listen for events (verifyBatchesTrustedAggregator) and store data in Mysql
Step3: b2-committer submit proposal to b2-node (send a transaction)
```
transaction {
"proposalId": getLastProposalId() from b2-node api,
"stateRoot": rootHash from a merkle tree which contains all the stateRoots of the batch, which are range of startBatchNum and endBatchNum,
"rootHash" from a merkle tree which contains all the proofs of the batch, which are range of startBatchNum and endBatchNum,
"startBatchNum": getFinalBatch() from b2-node rpc or rest interface,
"endBatchNum": startBatchNum + 10 (defined a constant)
```

Generate a proposal in b2-node depends on this transaction.
```
proposal {
"transaction": transaction from above describe,
"currentBlockNum": the current b2-node block number,
"voteMax": how many b2-committer node need to vote,
"txVoteNum": voteNums Step3,
"resultVoteNum": voteNums Step8,
"winAddress": which address has the entitlement to execute submitter to submit data(stateRoot and proof) to btc network
"btcTxId": btc tx id which contains the stateRoot and proof
"voteAdressList": already vote address list,
"state": (PENDING, SUCCESS, TIMEOUT),
}
```
simple algorithm about winAddressIndex
```
winAddressIndex = tx_id% voteAdressList
winAddress = voteAdressList[winAddressIndex]
```
you can get winAddress using api of b2-node.

after generated a proposal, put proposalId to channel[proposalId]

Step4: get proposalId from channel[proposalId]] and search proposal state from b2-node api.
if state is PENDING, and check winAddress equal local b2-committer address, then execute submitter to submit data(stateRoot and proof) to btc network
Step5: get the btcTxId from Step4, and put it in channel[btcTxId], and then update finalBatchNum in b2-node
Step6: go service loop channel[btcTxId] and get the btcTxId, and query the blockNum of btc network by btcTxId. If blockNum is confirmed, then execute Step7.
Step7: the b2-committer which execute btc transaction and get the btcTxId update the proposal btcTxId.
Step8: every b2-committer node loop their channel[proposalId] to check btcTxId is null or not. If not, then check the btcTxId blockHeight and submit a transaction to b2-node to vote.
resultVoteNum++. if resultVoteNum > 50%, then update state to SUCCESS.
Step9: loop check proposal by proposalId from channel[proposalId]. if the state of proposal is still PENDING and (currentBlockNum - proposal.currentBlockNum)> 10000, than update state to TIMEOUT and go to Step 3 again.

# Introduce

Submit op txs to decentralized store(e.g arweave)
![img_1.png](img_1.png)

Submit op l2 state roots to decentralized store(e.g arweave)
![img_2.png](img_2.png)

## environment Variables

| env | value | description | remarks |
|------------|----------------------------------------------------------------------------------------------------------|------------------------|--------------------|
| LOG_LEVEL | info | | warn、error、panic、fatal |
| LOG_FORMAT | text | | options: text、json |
| MYSQL_DATA_SOURCE | root:root@tcp(127.0.0.1:3306)/b2_committer?charset=utf8mb4&parseTime=True&loc=Local&multiStatements=true | | |
| MYSQL_MAX_IDLE_CONNS | 10 | | |
| MYSQL_MAX_OPEN_CONNS | 20 | | |
| MYSQL_CONN_MAX_LIFETIME | 3600 | | |
| RPC_URL | https://b2-nodes.bsquared.network | B2NODE-RPC | |
| BLOCKCHAIN | B2-NODE | | |
| INIT_BLOCK_NUMBER | 0 | block-height | |
| INIT_BLOCK_HASH | 0xfbecff3c9ca93f097d243d01d027d28f9bdcdebfb3208977246504ef4dddfc08 | block-hash | | |
| POLYGON_ZKEVM_ADDRESS | 0x67d269191c92Caf3cD7723F116c85e6E9bf55933 | | |
| NETWORK_NAME | testnet3 | btc-network type | |
| BITCOIN_PRIVATE_KEY | | privateKey | |
| COMMITTER_DESTINATION_ADDRESS | 0xB50109D57ae713388dc404eb2e8311bd9A8125a9 | btc commit destination | | |

| env | value | description | remarks |
| ---------------------------------- | ------------------------------------------------------------ | ---------------------------------------- | ------------------------- |
| LOG_LEVEL | info | | warn、error、panic、fatal |
| LOG_FORMAT | text | | options: text、json |
| MYSQL_DATA_SOURCE | root:root@tcp(127.0.0.1:3306)/b2_committer?charset=utf8mb4&parseTime=True&loc=Local&multiStatements=true | | |
| MYSQL_MAX_IDLE_CONNS | 10 | | |
| MYSQL_MAX_OPEN_CONNS | 20 | | |
| MYSQL_CONN_MAX_LIFETIME | 3600 | | |
| RPC_URL | https://b2-nodes.bsquared.network | B2NODE-RPC | |
| BEACON_CHAIN_ID | 11155111 | | |
| BEACON_CHAIN_RPC_URL | 3600 | | |
| BLOCKCHAIN | B2-NODE | | |
| INIT_BLOCK_NUMBER | 0 | for begainning to sync block to local db | |
| INIT_BLOCK_HASH | 0x9612534dc810c9c51211c77def2db781d7cc7979b0cb076a47c9fc6fb6dc475c | Init block hash | |
| INIT_BLOB_BLOCK_NUMBER | 5687501 | | |
| INIT_BLOB_BLOCK_HASH | 0x6218666b40fce4153e8f5349ab2f9d2590a601e5a178e4b6d4580094d5c0c2ee | | |
| BLOB_INTERVAL_TIME | 3600 | btc-network type | |
| OUTPUT_INTERVAL_TIME | 3600 | btc-network type | |
| L2_OUTPUT_ORACLE_PROXY_CONTRACT | 0x90E9c4f8a994a250F6aEfd61CAFb4F2e895D458F | btc-network type | |
| BATCHER_INBOX | 0xff00000000000000000000000000000011155420 (op batcher inbox) | btc-network type | |
| BATCHER_SENDER | 0x8F23BB38F531600e5d8FDDaAEC41F13FaB46E98c (op batcher inbox) | btc-network type | |
| DSTYPE | arweave (DecentralizedStore type) | btc-network type | |
| B2NODE_ARWEAVE_WALLET | /tmp/wallet/account.json | btc-network type | |
| B2NODE_ARWEAVE_RPC | https://arweave.net | btc-network type | |
| UNISAT_URL | https://open-api-testnet.unisat.io/ | privateKey | |
| UNISAT_PRIVATE_KEY | | btc commit destination | |
| B2NODE_CHAIN_ID | 11155111 | btc commit destination | |
| B2NODE_RPC_URL | 11155111 | btc commit destination | |
| B2NODE_OP_COMMITTER_ADDRESS | 0x270794Fc3ca753CDE033D2AeF9D00EAf71EbC386 | btc commit destination | |
| B2NODE_OP_PROPOSERS_ADDRESS | 0x837596C1Aa783E3B06C7Efb10a51Fe6699208D1D | btc commit destination | |
| B2NODE_OP_PROPOSAL_MANAGER_ADDRESS | 0x837596C1Aa783E3B06C7Efb10a51Fe6699208D1D | btc commit destination | |
| B2NODE_CREATOR_ADDRESS | 0xb634434CA448c39b05b460dEC51f458EaC1e2759 | btc commit destination | |
| B2NODE_CREATOR_PRIVATE_KEY | 0a81baab0ca0b65d406d68c79945054b092cbe77499ca55c57b3ecfd33f1d551 | btc commit destination | |
| BITCOIN_NETWORK_NAME | testnet3 | btc commit destination | |
| BITCOIN_PRIVATE_KEY | | btc commit destination | |
| COMMITTER_DESTINATION_ADDRESS | tb1q6t5py7fqml8patll2jzfc26q7987xqthslyvj4 | btc commit destination | |

Reference environment params

`B2NODE_CHAIN_ID=11155111;B2NODE_OP_COMMITTER_ADDRESS=0xE3DA42426AdEABC1c8d1ac28e79ef0bccbb6311e;B2NODE_OP_PROPOSAL_MANAGER_ADDRESS=0x16Bb9b79187B8d6C6Ad3ADe6dfA650070AA831c7;B2NODE_OP_PROPOSERS_ADDRESS=0x53bf2212Df41130F68Dfdf3f985105534C37e3E2;B2NODE_RPC_URL=https://quaint-white-season.ethereum-sepolia.quiknode.pro/b5c30cbb548d8743f08dd175fe50e3e923259d30;BATCHER_INBOX=0xfF000000000000000000000000000000000000FF;BATCHER_SENDER=0x4D0ca19b3c317DdB3c67FCC2C033ff0c25787BEe;BEACON_CHAIN_ID=213;BEACON_CHAIN_RPC_URL=https://hub-cl-rpc.bsquared.network;INIT_BLOB_BLOCK_HASH=0x35db0d9c50e33120690f50d2a50001be60c8c6b6871e03c2b8a1d39235b52d2d;INIT_BLOB_BLOCK_NUMBER=124543;INIT_BLOCK_HASH=0x0ade6a25acf1c5fa0f2b683584a2ea12a4913751b306549f5a740a39e2e38ec1;INIT_BLOCK_NUMBER=0;L2_OUTPUT_ORACLE_PROXY_CONTRACT=0x7893392346c2D73730733002718F278b4301dF83;RPC_URL=https://hub-rpc.bsquared.network`

### Run

Expand Down
Loading
Loading