Skip to content
This repository has been archived by the owner on Mar 28, 2023. It is now read-only.

Blockchain Module imports not working? #35

Closed
brianlenz opened this issue Jan 27, 2018 · 4 comments
Closed

Blockchain Module imports not working? #35

brianlenz opened this issue Jan 27, 2018 · 4 comments

Comments

@brianlenz
Copy link

brianlenz commented Jan 27, 2018

We've found our smart contract stopped compiling on the latest neo-boa (both master and development branches). It looks like this commit is the culprit:

2c6e01a

The compile works fine on the prior commit:

aad18d8

(venv) neo-boa $ git checkout 2c6e01ad89b398092610cff89a23f11484b3bfb1
Previous HEAD position was aad18d8... Merge branch 'development' of github.com:CityOfZion/neo-boa into development
HEAD is now at 2c6e01a... Blockchain no longer imports other modules
(venv) neo-boa $ python compile.py 
Traceback (most recent call last):
  File "compile.py", line 3, in <module>
    Compiler.load_and_save('../tokensale-neo-smartcontract/ico_template.py')
  File ".../neo-boa/boa/compiler.py", line 105, in load_and_save
    data = compiler.write()
  File ".../neo-boa/boa/compiler.py", line 81, in write
    out_bytes = bytes(module.write())
  File ".../neo-boa/boa/code/module.py", line 403, in write
    self.link_methods()
  File ".../neo-boa/boa/code/module.py", line 462, in link_methods
    raise Exception("Target method %s not found" % vmtoken.target_method)
Exception: Target method GetTimestamp not found
(venv) neo-boa $ git checkout aad18d8c47a9b3f99ec15bfdb7653c673f4691c3
Previous HEAD position was 2c6e01a... Blockchain no longer imports other modules
HEAD is now at aad18d8... Merge branch 'development' of github.com:CityOfZion/neo-boa into development
(venv) neo-boa $ python compile.py 
(venv) neo-boa $

Note that "GetTimestamp" compile error is the same on the latest master, as well.

Our project is https://github.com/NarrativeNetwork/tokensale-neo-smartcontract if you want to test against the same source.

If we remove the Header.Timestamp property reference, the GetTimestamp error goes away and turns into:

(venv) neo-boa brian$ python compile.py 
Traceback (most recent call last):
  File "compile.py", line 3, in <module>
    Compiler.load_and_save('../tokensale-neo-smartcontract/ico_template.py')
  File ".../neo-boa/boa/compiler.py", line 105, in load_and_save
    data = compiler.write()
  File ".../neo-boa/boa/compiler.py", line 81, in write
    out_bytes = bytes(module.write())
  File ".../neo-boa/boa/code/module.py", line 403, in write
    self.link_methods()
  File ".../neo-boa/boa/code/module.py", line 462, in link_methods
    raise Exception("Target method %s not found" % vmtoken.target_method)
Exception: Target method GetUnspentCoins not found
(venv) neo-boa brian$ 

I tried to isolate a more limited use case, but it seems to be challenging, as there appear to be non-deterministic properties of this issue. Here's one example, but this doesn't seem to be affected by the specific changeset I mentioned above:

from boa.blockchain.vm.Neo.Transaction import Transaction

class Test():
    def Main(self):
        return 0

That results in what appears to be the same GetUnspentCoins error as above:

(venv) neo-boa brian$ python compile.test.py 
Traceback (most recent call last):
  File "compile.test.py", line 3, in <module>
    Compiler.load_and_save('../tokensale-neo-smartcontract/test.py')
  File ".../neo-boa/boa/compiler.py", line 105, in load_and_save
    data = compiler.write()
  File ".../neo-boa/boa/compiler.py", line 81, in write
    out_bytes = bytes(module.write())
  File ".../neo-boa/boa/code/module.py", line 403, in write
    self.link_methods()
  File ".../neo-boa/boa/code/module.py", line 462, in link_methods
    raise Exception("Target method %s not found" % vmtoken.target_method)
Exception: Target method GetUnspentCoins not found
(venv) neo-boa brian$ 

For now, to work around the issue, we are using neo-boa 0.2.1, as the issue is present in 0.2.2.

@brianlenz
Copy link
Author

It's worth pointing out that the GetTimestamp error is triggered by a static now() method in the crowdsale.py. If we use that method in a simplified contract, it does not give the same GetTimestamp error:

from boa.blockchain.vm.Neo.Blockchain import GetHeight,GetHeader
from boa.blockchain.vm.Neo.Transaction import Transaction, GetReferences, GetOutputs

class Test():
    def Main(self):
        return 0


    @staticmethod
    def now():
        height = GetHeight()
        current_block = GetHeader(height)
        return current_block.Timestamp

This results in the GetUnspentCoins error from above. This code does compile successfully on the aad18d8 changeset, so it seems to be pretty clear that those module import optimizations are the culprit.

Note: I realize that the Transaction import isn't actually used in the code, but it's what reproduces the issue.

(venv) neo-boa brian$ git checkout 2c6e01ad89b398092610cff89a23f11484b3bfb1
Previous HEAD position was aad18d8... Merge branch 'development' of github.com:CityOfZion/neo-boa into development
HEAD is now at 2c6e01a... Blockchain no longer imports other modules
(venv) neo-boa brian$ python compile.test.py 
Traceback (most recent call last):
  File "compile.test.py", line 3, in <module>
    Compiler.load_and_save('../tokensale-neo-smartcontract/test.py')
  File ".../neo-boa/boa/compiler.py", line 105, in load_and_save
    data = compiler.write()
  File ".../neo-boa/boa/compiler.py", line 81, in write
    out_bytes = bytes(module.write())
  File ".../neo-boa/boa/code/module.py", line 403, in write
    self.link_methods()
  File ".../neo-boa/boa/code/module.py", line 462, in link_methods
    raise Exception("Target method %s not found" % vmtoken.target_method)
Exception: Target method GetUnspentCoins not found
(venv) neo-boa brian$ git checkout aad18d8c47a9b3f99ec15bfdb7653c673f4691c3
Previous HEAD position was 2c6e01a... Blockchain no longer imports other modules
HEAD is now at aad18d8... Merge branch 'development' of github.com:CityOfZion/neo-boa into development
(venv) neo-boa brian$ python compile.test.py 
(venv) neo-boa brian$

@ixje
Copy link
Member

ixje commented Jan 29, 2018

was facing the same, reverted back to 0.2.1 for the time being.

@localhuman
Copy link
Collaborator

This should be fixed in the new version of the compiler, v0.3.3

@adarshaJha
Copy link

when i try to compile neo-ico-template , using command :-
sc build_run /home/adarsh.jha/Documents/neoproject/neo-ico-template/compile
.py True False False '' 02 ''
i get this error : -
from boa.compiler import Compiler
^
IndentationError: unexpected indent

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

No branches or pull requests

4 participants