Skip to content

Commit

Permalink
DS Tool Doc (#3702)
Browse files Browse the repository at this point in the history
* DS Tool Doc
  • Loading branch information
ToniRamirezM authored Jun 7, 2024
1 parent 4c8e55a commit 63a0010
Show file tree
Hide file tree
Showing 2 changed files with 180 additions and 12 deletions.
23 changes: 11 additions & 12 deletions tools/datastreamer/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ decode-batch: check-go
decode-batch-offline: check-go
truncate: check-go
dump-batch: check-go
dump-batch-offline: check-go

arguments := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS))

Expand All @@ -33,6 +34,10 @@ decode-l2block: ## Runs the tool to decode a given L2 block
decode-batch: ## Runs the tool to decode a given batch
go run main.go decode-batch -cfg config/tool.config.toml -batch $(arguments)

.PHONY: dump-batch
dump-batch: ## Runs the tool to dump a given batch to file
go run main.go dump-batch -cfg config/tool.config.toml -d -batch $(arguments)

.PHONY: decode-entry-offline
decode-entry-offline: ## Runs the offline tool to decode a given entry number
go run main.go decode-entry-offline -cfg config/tool.config.toml -entry $(arguments)
Expand All @@ -45,17 +50,14 @@ decode-l2block-offline: ## Runs the offline tool to decode a given L2 block
decode-batch-offline: ## Runs the offline tool to decode a given batch
go run main.go decode-batch-offline -cfg config/tool.config.toml -batch $(arguments)

.PHONY: dump-batch-offline
dump-batch-offline: ## Runs the tool to dump a given batch to file offline
go run main.go dump-batch-offline -cfg config/tool.config.toml -d -batch $(arguments)

.PHONY: truncate
truncate: ## Runs the offline tool to truncate the stream file
go run main.go truncate -cfg config/tool.config.toml -entry $(arguments)

.PHONY: dump-batch
dump-batch: ## Runs the tool to dump a given batch to file
go run main.go dump-batch -cfg config/tool.config.toml -d -batch $(arguments)

.PHONY: dump-batch-offline
dump-batch-offline: ## Runs the tool to dump a given batch to file offline
go run main.go dump-batch-offline -cfg config/tool.config.toml -d -batch $(arguments)

## Help display.
## Pulls comments from beside commands and prints a nicely formatted
Expand All @@ -64,10 +66,7 @@ dump-batch-offline: ## Runs the tool to dump a given batch to file offline

.PHONY: help
help: ## Prints this help
@grep -h -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) \
| sort \
| awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
@grep -E '^[a-zA-Z0-9_-]+:.*## ' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' | sort

.DEFAULT:
.DEFAULT:
@echo ""

169 changes: 169 additions & 0 deletions tools/datastreamer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
# Datastream Tool

This tool was designed to be used internally with the legacy zkEVM node, but most of its options are compatible with the CDK-Erigon node, as they share the same data stream format. The only non-compatible option is the data stream generation (generate-file).

The DataStream format spec can be found [here](https://github.com/0xPolygonHermez/cdk-erigon/blob/zkevm/docs/datastream/datastream.md).

## Configuration

```
[Online]
URI = "localhost:6900"
StreamType = 1
[Offline]
Port = 6901
Filename = "datastream.bin"
Version = 3
ChainID = 1440
UpgradeEtrogBatchNumber = 0
[StateDB]
User = "state_user"
Password = "state_password"
Name = "state_db"
Host = "localhost"
Port = "5432"
EnableLog = false
MaxConns = 200
[MerkleTree]
URI = "localhost:50061"
MaxThreads = 20
CacheFile = "merkle_tree_cache.json"
[Log]
Environment = "development"
Level = "error"
Outputs = ["stdout"]
```

- **Online Section**:
- It is used to connect to a remote data stream server. Currently only StreamType 1 exists.
- **Offline Section**:
- It is used to work with local datastream files. This section is also used during local data stream file generation.
- Port: The data stream library requires a port, this must be a free port in the machine where the tool is running.
- Filename: Full path and file name of the datastream to generate or query.
- Version: It will be added to the data stream file header. Current version is 3. It is only for information, but it is recommended to properly set it to the correct value.
- ChainID: L2 Chain ID
- UpgradeEtrogBatchMNumber: Only useful for chains that started before Fork ID Etrog. This value must be the batch number of the firtst etrog batch. The reason for this is that the first batch for an upgrade to Etrog contains a transaction generated by the rollup smart contract that must be handled in a special way as it has not been sequenced by the sequencer, but synchronized from L1.
- **StateDB Section**:
- Database access to the StateDB of the zkEVM node where the trusted state is stored. The information to generate the datastream will be extracted from here.
- **MerkleTree Section**:
- HashDB Service offered by the Prover image. It is needed to retrieve the IM State Root for Fork ID <= Etrog. If the network is only > Etrog, set MaxThreads to 0 to disable this feature. The CacheFile is useful to speed up generations, but will only help once it has been generated on the first run.
- **Log Section**:
- It is recommended to leave `Level` to `error` once the tool is up and running, but during configuration and until it is working, setting it to `debug` can be very helpful.

## Options

To see avalible options type `make` once in the tool folder.

```
decode-batch Runs the tool to decode a given batch
decode-batch-offline Runs the offline tool to decode a given batch
decode-entry Runs the tool to decode a given entry number
decode-entry-offline Runs the offline tool to decode a given entry number
decode-l2block Runs the tool to decode a given L2 block
decode-l2block-offline Runs the offline tool to decode a given L2 block
dump-batch Runs the tool to dump a given batch to file
dump-batch-offline Runs the tool to dump a given batch to file offline
generate-file Runs the tool to populate the binary file
help Prints this help
truncate Runs the offline tool to truncate the stream file
```

All the decode options can work online, connecting to a node serving the stream, or offline, accessing the data stream files directly.

- **Decode Batch**: Decodes a Batch from a given number and shows all its data, l2blocks and transactions.
- **Decode Entry**: Decodes an entry and shows its content. Entry can be anything: bookmark, batch start, batch end, l2block, updateGER or transaction.
- **Decode L2Block**: Decodes a L2Block from a given number and shows all its data and transactions.
- **Truncate**: Truncates the file to a given entry number. Useful in case of unwinding the network.
- **Generate file**: Connects to StateDB and MerkleTree and generates the data stream files.
- **Dump batch**: Used to extract the binary data of a batch following the DS Spec. Useful during development of the integration with the Stateless Executor and Prover to generate test vectors.

## Examples


### Generate Data Stream files

`make generate-file`


### Get contents of Batch 1 from the local files

`make decode-batch-offline 1`

```
Entry Type......: Batch Start
Entry Number....: 6
Batch Number....: 1
Batch Type......: BATCH_TYPE_INJECTED
Fork ID.........: 9
Chain ID........: 6969
Entry Type......: BookMark
Entry Number....: 7
Type............: 2 (BOOKMARK_TYPE_L2_BLOCK)
Value...........: 1
Entry Type......: L2 Block
Entry Number....: 8
L2 Block Number.: 1
Batch Number....: 1
Timestamp.......: 1714380108 (2024-04-29 08:41:48 +0000 UTC)
Delta Timestamp.: 1714380108
Min. Timestamp..: 0
L1 Block Hash...: 0xdeaef97f8a5c6f056d08e162073d720c035a25adcaa2cd868124543ea54fb185
L1 InfoTree Idx.: 0
Block Hash......: 0xeeb2b1e810770dc1dcdd71a7ffa2a81ae77642d1e3c389919464100b3f70e366
State Root......: 0xada6af5a8bf491712d5ba14c67283a7b516245cd571151c5ade13f82532a398d
Global Exit Root: 0xad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5
Coinbase........: 0x5BD65BF6e084ECC10565EED59b838E82aBc28083
Block Gas Limit.: 0
Block Info Root.: 0x5dfdd92c4436374df99c4532ca7b8b1732faa10e9a6e31e0868bd4bfb6e8303d
Entry Type......: L2 Transaction
Entry Number....: 9
L2 Block Number.: 1
Index...........: 0
Is Valid........: true
Data............: 0xf9010f80808401c9c38094ca127484cda2b723c4c03558b94749184d3cfa9880b8e4f811bff7000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a40d5f56745a118d0906a34e69aec8c0db1cb8fa000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000001b8505ca1ab1e0845ca1ab1e
Effec. Gas Price: 255
IM State Root...: 0xeb6b784c61931c8d188ce19298799000615de174e17850ae53feb496b4a5a6ca
Sender..........: 0x2CfbeDbE634712c0Cec2Cd929DcB8c23B0038F2A
Nonce...........: 0
Entry Type......: Batch End
Entry Number....: 10
Batch Number....: 1
State Root......: 0xada6af5a8bf491712d5ba14c67283a7b516245cd571151c5ade13f82532a398d
Local Exit Root.: 0x0000000000000000000000000000000000000000000000000000000000000000
```

### Get content of L2Block 1 from an online Data Stream

`make decode-l2block 1`

```
Entry Type......: L2 Block
Entry Number....: 8
L2 Block Number.: 1
Batch Number....: 1
Timestamp.......: 1714380108 (2024-04-29 08:41:48 +0000 UTC)
Delta Timestamp.: 1714380108
Min. Timestamp..: 0
L1 Block Hash...: 0xdeaef97f8a5c6f056d08e162073d720c035a25adcaa2cd868124543ea54fb185
L1 InfoTree Idx.: 0
Block Hash......: 0xeeb2b1e810770dc1dcdd71a7ffa2a81ae77642d1e3c389919464100b3f70e366
State Root......: 0xada6af5a8bf491712d5ba14c67283a7b516245cd571151c5ade13f82532a398d
Global Exit Root: 0xad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5
Coinbase........: 0x5BD65BF6e084ECC10565EED59b838E82aBc28083
Block Gas Limit.: 0
Block Info Root.: 0x5dfdd92c4436374df99c4532ca7b8b1732faa10e9a6e31e0868bd4bfb6e8303d
Entry Type......: L2 Transaction
Entry Number....: 9
L2 Block Number.: 1
Index...........: 0
Is Valid........: true
Data............: 0xf9010f80808401c9c38094ca127484cda2b723c4c03558b94749184d3cfa9880b8e4f811bff7000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a40d5f56745a118d0906a34e69aec8c0db1cb8fa000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000001b8505ca1ab1e0845ca1ab1e
Effec. Gas Price: 255
IM State Root...: 0x0000000000000000000000000000000000000000000000000000000000000000
Sender..........: 0x2CfbeDbE634712c0Cec2Cd929DcB8c23B0038F2A
Nonce...........: 0
```

0 comments on commit 63a0010

Please sign in to comment.