Skip to content
This repository has been archived by the owner on Oct 4, 2019. It is now read-only.

[WIP] use python3 and add more instructions on README #4

Closed
wants to merge 7 commits into from

Conversation

whilei
Copy link
Contributor

@whilei whilei commented Sep 26, 2017

PR currently just for sharing/reference

(dfs)~/dev/etc/ecip1017test dev *% ⟠ ./bin/status.py
Nodes status
IDPEERSHEIGHTHASH
Traceback (most recent call last):
  File ./bin/status.py, line 70, in <module>
    list()
  File ./bin/status.py, line 64, in list
    height = api.get_height(pod_id)
  File /Users/ia/dev/etc/ecip1017test/bin/rpc_api.py, line 23, in get_height
    return self.rpc_call(node_id, eth_blockNumber, [])
  File /Users/ia/dev/etc/ecip1017test/bin/rpc_api.py, line 66, in rpc_call
    if not x.has_key(result):
AttributeError: 'dict' object has no attribute 'has_key'

----
solution: dont use method, just check for nil on dict key
(dfs)~/dev/etc/ecip1017test dev *% ⟠ ./bin/verify.py
Verify blockchain state....
-------------------------------------------
Download blockchain for local analysis.... (blocks 1..49, it may take 5+ minutes)
Traceback (most recent call last):
  File ./bin/verify.py, line 150, in <module>
    state.download()
  File ./bin/verify.py, line 67, in download
    self.state = reduce(reduce_state, blocks, defaultdict(lambda: 0))
NameError: name 'reduce' is not defined

----
solution: import from functools
(dfs)~/dev/etc/ecip1017test dev *% ⟠ ./bin/verify.py
Verify blockchain state....
-------------------------------------------
Download blockchain for local analysis.... (blocks 1..56, it may take 5+ minutes)
Traceback (most recent call last):
  File ./bin/verify.py, line 151, in <module>
    state.download()
  File ./bin/verify.py, line 68, in download
    self.state = reduce(reduce_state, blocks, defaultdict(lambda: 0))
  File ./bin/verify.py, line 110, in reduce_state
    base += era.get_block_reward()
  File ./bin/verify.py, line 39, in get_block_reward
    return toWei(coef(5.0, self.era))
  File ./bin/verify.py, line 23, in toWei
    val = long(ether * ETHER)
NameError: name 'long' is not defined

----
solution: use int instead
https://stackoverflow.com/questions/14904814/nameerror-global-name-long-is-not-defined
(dfs)~/dev/etc/ecip1017test dev *% ⟠ ./bin/verify.py
Verify blockchain state....
-------------------------------------------
Download blockchain for local analysis.... (blocks 1..93, it may take 5+ minutes)
Done
-------------------------------------------
-------------------------------------------
Mining stats:
-------------------------------------------
Expected state:
  Miner 0x479f3307a0e40a8cd8b772e17ec9f809e0dd03ad should have 25000000000000000000
  Miner 0x895b2a4a1beffc42f0eb28fb9be9d8d4478c011f should have 4.4015625e+20
-------------------------------------------
-------------------------------------------
Verifying...
Invalid balance for miner 0x479f3307a0e40a8cd8b772e17ec9f809e0dd03ad: 25.0 != 28.0 (exp != act)
                0x15af1d78b58c40000 wei != 0x18efc84ad0c7b0000 wei
Traceback (most recent call last):
  File ./bin/verify.py, line 153, in <module>
    state.verify()
  File ./bin/verify.py, line 97, in verify
    if abs(toEther(hex(balance)) - toEther(act)) > 0:
TypeError: 'float' object cannot be interpreted as an integer

----
solution: cast balance as int
@splix
Copy link
Contributor

splix commented Sep 26, 2017

I'm not actually sure about Python 3. AFAIK Python 2 is still standard for most systems. Do you think it will work with both version after this change?

@whilei
Copy link
Contributor Author

whilei commented Sep 26, 2017

I don't know -- I guess it might not. I switched to a virtualenv with 3.5 to fix #3 from my 2.7.13 OS default. What version are you at?

-- We might want to consider adding a docker container to run the scripts in order to avoid exactly these annoying issues.

@splix
Copy link
Contributor

splix commented Sep 26, 2017

for my macos I have python 2.7 as default, and python 3 under python3 command

@whilei
Copy link
Contributor Author

whilei commented Sep 26, 2017

I can't get around #3 without using 3.5... here's my python context for reference

~/dev/etc/ecip1017test dev1 % ⟠ python --version
Python 2.7.13
~/dev/etc/ecip1017test dev1 % ⟠ pip freeze -r bin/requirements.txt
kubernetes==3.0.0
pprint==0.1
## The following requirements were added by pip freeze:
appnope==0.1.0
awscli==1.11.59
backports-abc==0.4
backports.ssl-match-hostname==3.4.0.2
beautifulsoup4==4.5.0
botocore==1.5.22
bs4==0.0.1
cachetools==2.0.1
certifi==2017.7.27.1
chardet==3.0.4
click==6.6
colorama==0.3.7
decorator==4.0.6
docutils==0.12
Flask==0.11.1
functools32==3.2.3.post2
future==0.15.2
futures==3.0.5
GDAL==1.11.3
Glances==2.6.2
gnureadline==6.3.3
google-auth==1.1.1
howmanypeoplearearound==0.3.5
httpie==0.9.9
httpie-oauth==1.0.2
idna==2.6
ImageScraper==2.0.7
ipaddress==1.0.18
ipykernel==4.2.1
ipython==4.0.1
ipython-genutils==0.1.0
ipywidgets==4.1.1
isitup==0.3.1
itsdangerous==0.24
Jinja2==2.8
jmespath==0.9.1
jsonschema==2.5.1
jupyter==1.0.0
jupyter-client==4.1.1
jupyter-console==4.0.3
jupyter-core==4.0.6
lxml==3.5.0
MarkupSafe==0.23
mercurial==3.7.1
mistune==0.7.1
nbconvert==4.1.0
nbformat==4.0.1
netifaces==0.10.6
nose==1.3.7
notebook==4.0.6
numpy==1.11.2
oauthlib==2.0.1
path.py==8.1.2
peewee==2.8.5
pexpect==4.0.1
pick==0.6.3
pickleshare==0.5
powerline-status==2.5
psutil==4.3.0
ptyprocess==0.5
pyasn1==0.3.6
pyasn1-modules==0.1.4
Pygments==2.1.3
python-dateutil==2.6.1
PyYAML==3.12
pyzmq==15.1.0
qtconsole==4.1.1
requests==2.18.4
requests-oauthlib==0.7.0
rsa==3.4.2
s3transfer==0.1.10
seashells==0.1.2
setproctitle==1.1.9
simplegeneric==0.8.1
SimplePool==0.1
singledispatch==3.4.0.3
six==1.11.0
statistics==1.0.3.5
stevedore==1.9.0
terminado==0.5
tornado==4.3
traitlets==4.0.0
tweepy==3.5.0
twitter==1.17.1
urllib3==1.22
virtualenv==13.1.2
virtualenvwrapper==4.7.1
websocket-client==0.40.0
Werkzeug==0.11.10

Similar to yours?

@splix
Copy link
Contributor

splix commented Sep 26, 2017

backports.ssl-match-hostname==3.5.0.1
cachetools==2.0.1
certifi==2017.7.27.1
chardet==3.0.4
ecdsa==0.13
gevent==1.0.2
google-auth==1.0.2
greenlet==0.4.9
idna==2.6
ipaddress==1.0.18
junit2html==3
kubernetes==3.0.0
mercurial==4.0
msgpack-python==0.4.7
nose==1.3.7
numpy==1.11.2
powerline-status==2.5
protobuf==3.1.0
pyasn1==0.3.2
pyasn1-modules==0.0.11
pydevd==0.0.5
pygobject==3.22.0
pysha3==1.0.2
python-dateutil==2.6.1
PyYAML==3.12
requests==2.18.4
rsa==3.4.2
six==1.10.0
urllib3==1.22
websocket-client==0.40.0
wget==2.0

@whilei
Copy link
Contributor Author

whilei commented Sep 26, 2017

backports.ssl-match-hostname==3.5.0.1 that did it ✅ , thanks -- I will close this and open a new PR

@whilei whilei closed this Sep 26, 2017
@splix
Copy link
Contributor

splix commented Sep 26, 2017

now we see why python got replaced by golang ;)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants