# IaViewer
`iaviewer` is a utility to inspect the contents of a persisted iavl tree, given (a copy of) the leveldb store.
This can be quite useful for debugging, especially when you find odd errors, or non-deterministic behavior.
Below is a brief introduction to the tool.
## Installation
Once this is merged into the offical repo, master, you should be able to do:
```shell
go get github.com/cosmos/iavl
cd ${GOPATH}/src/github.com/cosmos/iavl
make install
```
## Using the tool
First make sure it is properly installed and you have `${GOPATH}/bin` in your `PATH`.
Typing `iaviewer` should run and print out a usage message.
### Sample databases
Once you understand the tool, you will most likely want to run it on captures from your
own abci app (built on cosmos-sdk or weave), but as a tutorial, you can try to use some
captures from an actual bug I found in my code... Same data, different hash.
```shell
mkdir ./testdata
cd ./testdata
curl -L https://github.com/iov-one/iavl/files/2860877/bns-a.db.zip > bns-a.db.zip
unzip bns-a.db.zip
curl -L https://github.com/iov-one/iavl/files/2860878/bns-b.db.zip > bns-b.db.zip
unzip bns-b.db.zip
```
Now, if you run `ls -l`, you should see two directories... `bns-a.db` and `bns-b.db`
### Inspecting available versions
```shell
iaviewer versions ./bns-a.db ""
```
This should print out a list of 20 versions of the code. Note the the iavl tree will persist multiple
historical versions, which is a great aid in forensic queries (thanks Tendermint team!). For the rest
of the cases, we will consider only the last two versions, 190257 (last one where they match) and 190258
(where they are different).
### Checking keys and app hash
First run these two and take a quick a look at the output:
```shell
iaviewer data ./bns-a.db ""
iaviewer data ./bns-a.db "" 190257
```
Notice you see the different heights and there is a change in size and app hash.
That's what happens when we process a transaction. Let's go further and use
the handy tool `diff` to compare two states.
```shell
iaviewer data ./bns-a.db "" 190257 > a-last.data
iaviewer data ./bns-b.db "" 190257 > b-last.data
diff a-last.data b-last.data
```
Same, same :)
But if we take the current version...
```shell
iaviewer data ./bns-a.db "" 190258 > a-cur.data
iaviewer data ./bns-b.db "" 190258 > b-cur.data
diff a-cur.data b-cur.data
```
Hmmm... everything is the same, except the hash. Odd...
So odd that I [wrote an article about it](https://medium.com/@ethan.frey/tracking-down-a-tendermint-consensus-failure-77f6ff414406)
And finally, if we want to inspect which keys were modified in the last block:
```shell
diff a-cur.data a-last.data
```
You should see 6 writes.. the `_i.usernft_*` are the secondary indexes on the username nft.
`sigs.*` is setting the nonce (if this were an update, you would see a previous value).
And `usrnft:*` is creating the actual username nft.
### Checking the tree shape
So, remember above, when we found that the current state of a and b have the same data
but different hashes. This must be due to the shape of the iavl tree.
To confirm that, and possibly get more insights, there is another command.
```shell
iaviewer shape ./bns-a.db "" 190258 > a-cur.shape
iaviewer shape ./bns-b.db "" 190258 > b-cur.shape
diff a-cur.shape b-cur.shape
```
Yup, that is quite some difference. You can also look at the tree as a whole.
So, stretch your terminal nice and wide, and...
```shell
less a-cur.shape
```
It has `-5 ` for an inner node of depth 5, and `*6 ` for a leaf node (data) of depth 6.
Indentation also suggests the shape of the tree.
Note, if anyone wants to improve the visualization, that would be awesome.
I have no idea how to do this well, but at least text output makes some
sense and is diff-able.
没有合适的资源?快使用搜索试试~ 我知道了~
Go中的MerkleizedIAVL+Tree实现.zip
共104个文件
go:57个
md:18个
yml:9个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 53 浏览量
2023-03-28
13:22:03
上传
评论
收藏 206KB ZIP 举报
温馨提示
Go中的MerkleizedIAVL+Tree实现.zip
资源推荐
资源详情
资源评论
收起资源包目录
Go中的MerkleizedIAVL+Tree实现.zip (104个子文件)
CODEOWNERS 56B
CURRENT 16B
CURRENT 16B
.gitignore 151B
tree_test.go 48KB
mutable_tree_test.go 44KB
mutable_tree.go 29KB
nodedb.go 22KB
node.go 16KB
tree_random_test.go 14KB
db_mock.go 13KB
basic_test.go 12KB
bench_test.go 12KB
nodedb_test.go 11KB
iterator_test.go 11KB
immutable_tree.go 10KB
iterator.go 9KB
export_test.go 8KB
testutils_test.go 8KB
node_test.go 7KB
cache_test.go 6KB
proof_ics23_test.go 6KB
import_test.go 6KB
unsaved_fast_iterator.go 6KB
proof_ics23.go 6KB
proof.go 6KB
import.go 6KB
key_format.go 5KB
main.go 5KB
encoding.go 4KB
main.go 4KB
random.go 4KB
tree_dotgraph.go 4KB
diff.go 4KB
key_format_test.go 4KB
encoding_test.go 3KB
util.go 3KB
cache.go 3KB
proof_test.go 3KB
tree_fuzz_test.go 3KB
fast_iterator.go 3KB
export.go 3KB
diff_test.go 2KB
options.go 2KB
fast_node.go 2KB
random_test.go 2KB
doc.go 2KB
fast_node_test.go 1KB
bytes.go 1KB
bytes_test.go 1KB
proof_iavl_test.go 1KB
cache_bench_test.go 1KB
string_test.go 1KB
hash_test.go 1KB
proof_path.go 1KB
string.go 770B
version.go 753B
with_gcc_test.go 460B
tree_dotgraph_test.go 402B
tools.go 306B
logger.go 158B
settings.json 53B
LICENSE 11KB
LOCK 0B
LOCK 0B
000001.log 4KB
000001.log 4KB
LOG 361B
LOG 360B
Makefile 3KB
MANIFEST-000000 54B
MANIFEST-000000 54B
proof.md 12KB
mutable_tree.md 10KB
PERFORMANCE.md 7KB
adr-001-node-key-refactoring.md 6KB
node.md 5KB
nodedb.md 4KB
overview.md 4KB
README.md 4KB
export_import.md 4KB
CHANGELOG.md 3KB
immutable_tree.md 3KB
README.md 3KB
adr-template.md 2KB
README.md 2KB
README.md 1KB
README.md 985B
key_format.md 608B
CONTRIBUTING.md 334B
go.mod 10KB
POEM 633B
mockgen.sh 144B
go.sum 114KB
.mergify.yaml 1KB
stale.yml 2KB
.golangci.yml 1KB
ci.yml 1KB
codeql.yml 833B
lint.yml 592B
共 104 条
- 1
- 2
资源评论
快撑死的鱼
- 粉丝: 1w+
- 资源: 9154
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功