-
Notifications
You must be signed in to change notification settings - Fork 240
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Problem: state streamers are not integrated (#702)
* Problem: state streaming is integrated Solution: - integration the basic file streamer * add integration test * changelog * fix build * fix lint * fix deliver tx event in cosmos-sdk * fix integration test * Update integration_tests/test_streamer.py Signed-off-by: yihuang <huang@crypto.com> * update ethermint and fix build * add a small cli utility into test_streamer.py * fix integration test * update sdk to upstream Signed-off-by: yihuang <huang@crypto.com>
- Loading branch information
Showing
10 changed files
with
150 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package client | ||
|
||
const FlagStreamers = "streamers" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
from cprotobuf import Field, ProtoEntity, decode_primitive | ||
from hexbytes import HexBytes | ||
|
||
from .utils import ADDRS | ||
|
||
|
||
class StoreKVPairs(ProtoEntity): | ||
# the store key for the KVStore this pair originates from | ||
store_key = Field("string", 1) | ||
# true indicates a delete operation | ||
delete = Field("bool", 2) | ||
key = Field("bytes", 3) | ||
value = Field("bytes", 4) | ||
|
||
|
||
def decode_stream_file(data, body_cls=StoreKVPairs, header_cls=None, footer_cls=None): | ||
""" | ||
header, body*, footer | ||
""" | ||
header = footer = None | ||
body = [] | ||
offset = 0 | ||
size, n = decode_primitive(data, "uint64") | ||
offset += n | ||
|
||
# header | ||
if header_cls is not None: | ||
header = header_cls() | ||
header.ParseFromString(data[offset : offset + size]) | ||
offset += size | ||
|
||
while True: | ||
size, n = decode_primitive(data[offset:], "uint64") | ||
offset += n | ||
if offset + size == len(data): | ||
# footer | ||
if footer_cls is not None: | ||
footer = footer_cls() | ||
footer.ParseFromString(data[offset : offset + size]) | ||
offset += size | ||
break | ||
else: | ||
# body | ||
if body_cls is not None: | ||
item = body_cls() | ||
item.ParseFromString(data[offset : offset + size]) | ||
body.append(item) | ||
offset += size | ||
return header, body, footer | ||
|
||
|
||
def test_streamers(cronos): | ||
""" | ||
- check the streaming files are created | ||
- try to parse the state change sets | ||
""" | ||
# inspect the first state change of the first tx in genesis | ||
path = cronos.node_home(0) / "data/file_streamer/block-0-tx-0" | ||
_, body, _ = decode_stream_file(open(path, "rb").read()) | ||
# creation of the validator account | ||
assert body[0].store_key == "acc" | ||
# the order in gen_txs is undeterministic, could be either one. | ||
assert body[0].key in ( | ||
b"\x01" + HexBytes(ADDRS["validator"]), | ||
b"\x01" + HexBytes(ADDRS["validator2"]), | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
import binascii | ||
import sys | ||
|
||
_, body, _ = decode_stream_file(open(sys.argv[1], "rb").read()) | ||
for item in body: | ||
print( | ||
item.store_key, | ||
item.delete, | ||
binascii.hexlify(item.key).decode(), | ||
binascii.hexlify(item.value).decode(), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters