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

add __ether_view_enabled option to Docker #124

Merged
merged 1 commit into from
Feb 15, 2023
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
6 changes: 6 additions & 0 deletions client/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,9 @@ services:
- /var/run/docker.sock:/var/run/docker.sock
ports:
- 8080:8080

networks:
- my-network
networks:
my-network:
driver: bridge
2 changes: 1 addition & 1 deletion examples/C04-ethereum-pos/blockchain-pos.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@

emu.render()

docker = Docker(internetMapEnabled=True)
docker = Docker(internetMapEnabled=True, etherViewEnabled=True)
# Use the "handsonsecurity/seed-ubuntu:small" custom image from dockerhub

# Add the 'rafaelawon/seedemu-lighthouse-base' custom image from dockerhub.
Expand Down
54 changes: 42 additions & 12 deletions seedemu/compiler/Docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
from shutil import copyfile
import json

SEEDEMU_CLIENT_IMAGE='handsonsecurity/seedemu-map'
SEEDEMU_INTERNET_MAP_IMAGE='handsonsecurity/seedemu-map'
SEEDEMU_ETHER_VIEW_IMAGE='rafaelawon/seedemu-etherview:1.0'

DockerCompilerFileTemplates: Dict[str, str] = {}

Expand Down Expand Up @@ -174,16 +175,26 @@
{labelList}
"""

DockerCompilerFileTemplates['seedemu_client'] = """\
DockerCompilerFileTemplates['seedemu_internet_map'] = """\
seedemu-client:
image: {clientImage}
container_name: seedemu_client
container_name: seedemu_internet_map
volumes:
- /var/run/docker.sock:/var/run/docker.sock
ports:
- {clientPort}:8080/tcp
"""

DockerCompilerFileTemplates['seedemu_ether_view'] = """\
seedemu-client:
image: {clientImage}
container_name: seedemu_ether_view
volumes:
- /var/run/docker.sock:/var/run/docker.sock
ports:
- {clientPort}:5000/tcp
"""

DockerCompilerFileTemplates['zshrc_pre'] = """\
export NOPRECMD=1
alias st=set_title
Expand Down Expand Up @@ -281,8 +292,11 @@ class Docker(Compiler):
__self_managed_network: bool
__dummy_network_pool: Generator[IPv4Network, None, None]

__map_client_enabled: bool
__map_client_port: int
__internet_map_enabled: bool
__internet_map_port: int

__ether_view_enabled: bool
__ether_view_port: int

__client_hide_svcnet: bool

Expand All @@ -300,6 +314,8 @@ def __init__(
dummyNetworksMask: int = 24,
internetMapEnabled: bool = False,
internetMapPort: int = 8080,
etherViewEnabled: bool = False,
etherViewPort: int = 5000,
clientHideServiceNet: bool = True
):
"""!
Expand Down Expand Up @@ -328,6 +344,9 @@ def __init__(
access to all nodes, which can potentially allow root access to the
emulator host. Only enable seedemu in a trusted network.
@param internetMapPort (optional) set seedemu internetMap port. Default to 8080.
@param etherViewEnabled (optional) set if seedemu EtherView should be enabled.
Default to False.
@param etherViewPort (optional) set seedemu EtherView port. Default to 5000.
@param clientHideServiceNet (optional) hide service network for the
client map by not adding metadata on the net. Default to True.
"""
Expand All @@ -337,8 +356,11 @@ def __init__(
self.__self_managed_network = selfManagedNetwork
self.__dummy_network_pool = IPv4Network(dummyNetworksPool).subnets(new_prefix = dummyNetworksMask)

self.__map_client_enabled = internetMapEnabled
self.__map_client_port = internetMapPort
self.__internet_map_enabled = internetMapEnabled
self.__internet_map_port = internetMapPort

self.__ether_view_enabled = etherViewEnabled
self.__ether_view_port = etherViewPort

self.__client_hide_svcnet = clientHideServiceNet

Expand Down Expand Up @@ -984,12 +1006,20 @@ def _doCompile(self, emulator: Emulator):
self._log('compiling service node {}...'.format(name))
self.__services += self._compileNode(obj)

if self.__map_client_enabled:
self._log('enabling seedemu-client...')
if self.__internet_map_enabled:
self._log('enabling seedemu-internet-map...')

self.__services += DockerCompilerFileTemplates['seedemu_internet_map'].format(
clientImage = SEEDEMU_INTERNET_MAP_IMAGE,
clientPort = self.__internet_map_port
)

if self.__ether_view_enabled:
self._log('enabling seedemu-ether-view...')

self.__services += DockerCompilerFileTemplates['seedemu_client'].format(
clientImage = SEEDEMU_CLIENT_IMAGE,
clientPort = self.__map_client_port
self.__services += DockerCompilerFileTemplates['seedemu_ether_view'].format(
clientImage = SEEDEMU_ETHER_VIEW_IMAGE,
clientPort = self.__ether_view_port
)

local_images = ''
Expand Down
3 changes: 3 additions & 0 deletions tools/Blockchain/EtherView/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
keystore/
emulator_info/
emulator_data/
8 changes: 8 additions & 0 deletions tools/Blockchain/EtherView/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM handsonsecurity/seed-ubuntu:large

RUN apt-get update && apt-get install -y python3 pip
RUN pip3 install flask web3 docker
COPY start.sh /start.sh
RUN chmod +x /start.sh
COPY . .
ENTRYPOINT ["sh", "/start.sh"]
21 changes: 21 additions & 0 deletions tools/Blockchain/EtherView/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# EtherView

EtherView is a collection of tools that can be used to
interact with the Ethereum emulator. It has the following
features:

- Viewing the balances for all the accounts

- Viewing blocks and transactions (like EtherScan)

- Viewing (or visualizing) interesting blockchain properties, such as
- base fee
- transaction pools on each node

- Viewing POA/POS related information, especially POS.

- Sample dApps. We should host some open-source dApps. Each dApp
is built into a container. They can be included when the emulator
is built. When EtherView detects it, the corresponding menu
will appear, leading us to the dApp. More thinking is needed
for this feature.
4 changes: 0 additions & 4 deletions tools/Blockchain/EtherView/REAMD.md

This file was deleted.

44 changes: 44 additions & 0 deletions tools/Blockchain/EtherView/TODO.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Todo List

## Should do it soon

- We need another view to display all the transactions inside
a block (not finished yet).

- Several items in the `config.py` needs to be set
automatically from the emulator, including
`CONSENSUS` and `DEFAULT_URL`.

- Right now, we are using the `ETH_NODE_NAME_PATTERN`
to identify which container is an Ethereum node.
We should use the container meta data to replace this.

- Use the time stamp from the 1st block to decide whether
we should recreate the json files in the `emulator_data`
folder.


## Will take a while

- The style used in the program does not looks good.
We need to fine tune it or find a better one.


- Transaction view: use tabs for choosing transaction content and
transaction receipts.

- On each view, we should display the following information:
- chain id selection, provider selection
- consensus, number of nodes
- When clicking on the number of nodes, we should switch to the InternetMap
app (should we call it InternetView? to be consistent with EtherView).


- POA and POS related features. Whether to display these menus depend
on the context: they should not appear when the blockchain is not
their type.





10 changes: 10 additions & 0 deletions tools/Blockchain/EtherView/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: "3"

services:
seedemu-eth-client:
build: .
container_name: seedemu_eth_client
volumes:
- /var/run/docker.sock:/var/run/docker.sock
ports:
- 5000:5000
1 change: 1 addition & 0 deletions tools/Blockchain/EtherView/emulator
4 changes: 4 additions & 0 deletions tools/Blockchain/EtherView/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

FLASK_APP=server flask run

Loading