Giter Site home page Giter Site logo

icon-service's People

Contributors

boyeon555 avatar cow-hs avatar endlessgate avatar eunsoo-icon avatar goldworm avatar goldworm-icon avatar inwonkim avatar light-src avatar sink772 avatar sojinkim-icon avatar soobokjin avatar whylee259 avatar yakkle avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

icon-service's Issues

Cannot unit test len(ArrayDB)

I always get

AttributeError: 'NoneType' object has no attribute 'revision'

when doing a unit test with such setup:

In Init

def __init__(self, db: IconScoreDatabase) -> None:
    super().__init__(db)
    self._lolo = ArrayDB("lolo", db, value_type=int)

In a function

@external
def lolo(self):
    if len(self._lolo) > 0:
        revert("Alert!")

In the unit test

def test_lolo(self):
    self.score.lolo()

This len() call throws me the error in the unit tests.

This is because in (venv/lib/python3.6/site-packages/iconservice/iconscore/icon_container_db.py:326):

@classmethod
def __is_defective_revision(cls):
    context = ContextContainer._get_context()
    revision = context.revision
    return context.type == IconScoreContextType.INVOKE and revision < Revision.THREE.value

the function context = ContextContainer._get_context() returns None, because no context is set.

I have no knowledge of the inner workings of icon-service.
But I'd really like to unit test my SCORE.

What is the correct value of STEP_TYPE_DEFAULT in T-Bears?

100_000 is correct
step_price is 10 ** 10
1 icx == 10 ** 18 loop

Fee of a default icx transfer transaction == 10 ** 5 * 10 ** 10 == 10 ** 15 loop == 0.001 icx

Originally posted by @goldworm-icon in #109 (comment)

@goldworm-icon Thanks.

What about t-bears ?
I send transaction with 100_000 stepLimit, it returns "Step limit too low".
And i find some code (iconservice/builtin_scores/governance/governance.py):

def _set_initial_step_costs(self):
        initial_costs = {
            STEP_TYPE_DEFAULT: 1_000_000,
...

Improve input data calculating rule

  • basic rule
    • Calculating strings
      : Counts UTF-8 encoded byte length
    • Calculating binaries (0x prefixed lowercase hex-string)
      : Counts real byte length
    • 0x prefixed hex-string which included uppercases is not a binary
  • when pre-validating
    • Counts key and value as a string
    • Reject non-binary data on message type transaction
  • when STEP counting
    • Counts key and value
    • Counts key as a string
    • If the value is 0x prefixed lowercase hex-string, counts as a binary
    • If the value is a negative integer(e.g. -0x1a2b3c), counts as a binary with removing a sign.
    • Otherwise, counts as a string

Context rollback without revert in SCORE ?

Hello ICON Team,

For context, here's my use case : I'm doing a multisig wallet that can process multiple sub-transaction in a single transaction.
If a sub-transaction fails, I'd like to cancel already executed sub-transactions.

For doing so, I'm looking for a way to rollback an IconScoreContext to a previous state when writing a SCORE contract.

I could do that with the revert method, but the issue with that API is that it also throws and stop the SCORE method.
I'd like to call a rollback method that does the same than revert but also keeps executing further operations, so I can cancel all previous operations and keep executing the transaction. As I call external SCOREs before the rollback, I cannot reset the variables manually.

Is there a way to do what I want in the current version ?

The current IconScoreContext doesn't seem accessible from the SCORE environnent. It's available in self._context but as it isn't documented, I don't think we're supposed to access it.

Thank you!

OutOfBalanceException Out of balance

Mainnet error just occurred

2021-03-12 20:02:48,192 780 140314064668416 ERROR icon_service_engine.py(1442) ISE Out of balance
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/iconservice/icon_service_engine.py", line 1436, in _charge_transaction_fee
    context, from_, to, step_price, step_used, context.block.height)
  File "/usr/local/lib/python3.7/site-packages/iconservice/fee/engine.py", line 405, in charge_transaction_fee
    context.engine.icx.charge_fee(context, sender, sender_step * step_price)
  File "/usr/local/lib/python3.7/site-packages/iconservice/icx/engine.py", line 66, in charge_fee
    self._transfer(context, from_, context.storage.icx.fee_treasury, fee)
  File "/usr/local/lib/python3.7/site-packages/iconservice/icx/engine.py", line 96, in _transfer
    from_account.withdraw(amount)
  File "/usr/local/lib/python3.7/site-packages/iconservice/icx/icx_account.py", line 139, in withdraw
    self.coin_part.withdraw(value)
  File "/usr/local/lib/python3.7/site-packages/iconservice/icx/coin_part.py", line 166, in withdraw
    raise OutOfBalanceException('Out of balance')

Other error

2021-03-12 20:12:15,388 780 140314064668416 INFO icon_service_engine.py(516) ISE TX_END: BH=31700340 txIndex=50 to=hx542550181ea328195d3b02850692b2988fcb5447 method=NOT_CALL_DATA_TYPE duration=0.0010838769376277924
2021-03-12 20:12:15,388 780 140314064668416 ERROR icon_service_engine.py(1516) ISE Out of balance: from=hx542550181ea328195d3b02850692b2988fcb5447 balance=100000000000000 value=998750000000000000 fee=1250000000000000
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/iconservice/icon_service_engine.py", line 1271, in _handle_icx_send_transaction
    self._process_transaction(context, params, tx_result)
  File "/usr/local/lib/python3.7/site-packages/iconservice/icon_service_engine.py", line 1340, in _process_transaction
    step_price=context.step_counter.step_price)
  File "/usr/local/lib/python3.7/site-packages/iconservice/iconscore/icon_pre_validator.py", line 187, in execute_to_check_out_of_balance
    self._check_from_can_charge_fee_v3(context, params, step_price)
  File "/usr/local/lib/python3.7/site-packages/iconservice/iconscore/icon_pre_validator.py", line 320, in _check_from_can_charge_fee_v3
    self._check_balance(context, from_, value, fee)
  File "/usr/local/lib/python3.7/site-packages/iconservice/iconscore/icon_pre_validator.py", line 455, in _check_balance
    raise OutOfBalanceException(msg)
iconservice.base.exception.OutOfBalanceException: Out of balance: from=hx542550181ea328195d3b02850692b2988fcb5447 balance=100000000000000 value=998750000000000000 fee=1250000000000000 (11)
2021-03-12 20:12:15,389 780 140314064668416 ERROR icon_service_engine.py(1442) ISE Out of balance
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/iconservice/icon_service_engine.py", line 1436, in _charge_transaction_fee
    context, from_, to, step_price, step_used, context.block.height)
  File "/usr/local/lib/python3.7/site-packages/iconservice/fee/engine.py", line 405, in charge_transaction_fee
    context.engine.icx.charge_fee(context, sender, sender_step * step_price)
  File "/usr/local/lib/python3.7/site-packages/iconservice/icx/engine.py", line 66, in charge_fee
    self._transfer(context, from_, context.storage.icx.fee_treasury, fee)
  File "/usr/local/lib/python3.7/site-packages/iconservice/icx/engine.py", line 96, in _transfer
    from_account.withdraw(amount)
  File "/usr/local/lib/python3.7/site-packages/iconservice/icx/icx_account.py", line 139, in withdraw
    self.coin_part.withdraw(value)
  File "/usr/local/lib/python3.7/site-packages/iconservice/icx/coin_part.py", line 166, in withdraw
    raise OutOfBalanceException('Out of balance')
iconservice.base.exception.OutOfBalanceException: Out of balance (11)

This also resulted in some

If SCORE contains package.json with a file path, icon-service throws an error when deploying SCORE.

package.json

{
    "version": "0.0.1",
    "main_file": "src/proj_test",
    "main_score": "ScoreTest"
}

console output

$ tbears deploy proj_test
If you want to check SCORE deployed successfully, execute txresult command
transaction hash: 0xcb4e47b0c6856a005e71437a134c358f9616a0d1ec76ed119307b5bc72e2a9bb
$ tbears txresult 0xcb4e47b0c6856a005e71437a134c358f9616a0d1ec76ed119307b5bc72e2a9bb
Transaction result: {
    "jsonrpc": "2.0",
    "result": {
        "txHash": "0xcb4e47b0c6856a005e71437a134c358f9616a0d1ec76ed119307b5bc72e2a9bb",
        "blockHeight": "0x503",
        "blockHash": "0x18840132e5c8c6ad938b4969d3f38516885cef8850b3b5f205c42686f74bde29",
        "txIndex": "0x0",
        "to": "cx0000000000000000000000000000000000000000",
        "stepUsed": "0x185c608",
        "stepPrice": "0x0",
        "cumulativeStepUsed": "0x185c608",
        "eventLogs": [],
        "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
        "status": "0x0",
        "failure": {
            "code": "0x7d00",
            "message": "No module named '01f8ff4a3ec5e6b7094e1c6eaba6e1984c0603b835.0xcb4e47b0c6856a005e71437a134c358f9616a0d1ec76ed119307b5bc72e2a9bb.src/proj_test'"
        }
    },
    "id": 1
}

z

z

Devide IconScoreContext class

currently IconScoreContext class is constituted data_struct and link system SCORE API
so someone who develop SCORE can accept API function which can't use
therefore I try to refactoring code about IconScoreContext Class

TODO. Divide that class to data class and API class

ISE Expecting value: line 1 column 1 (char 0)

Occurred on mainnet

2021-03-13 07:30:41,487 783 139965051762432 INFO regulator.py(114) IISS Regulate BH: 31718844 Covered by fee: 0 Covered by remain: 0 Corrected issue amount 3075118259590025435Regulator variable: Current calc period issued ICX: 38016724309111047851574 Prev calc period issued ICX: 132342850473422400858580 Remain over issued I-SCORE: -731
2021-03-13 07:30:41,488 783 139965051762432 INFO engine.py(84) ICX Issue icx. amount: 3075118259590025435 Total supply: 880299204205458544335591389 Treasury: 3345566070148711725148393
2021-03-13 07:30:41,488 783 139965051762432 INFO icon_service_engine.py(516) ISE TX_END: BH=31718844 txIndex=0 to=hx1000000000000000000000000000000000000000 method=NOT_CALL_DATA_TYPE duration=0.0008843950927257538
2021-03-13 07:30:41,514 783 139965051762432 INFO icon_service_engine.py(516) ISE TX_END: BH=31718844 txIndex=1 to=cx299d88908ab371d586c8dfe0ed42899a899e6e5b method=action duration=0.025901902001351118
2021-03-13 07:30:41,515 783 139965051762432 ERROR icon_service_engine.py(1521) ISE Expecting value: line 1 column 1 (char 0)
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/iconservice/icon_service_engine.py", line 1271, in _handle_icx_send_transaction
    self._process_transaction(context, params, tx_result)
  File "/usr/local/lib/python3.7/site-packages/iconservice/icon_service_engine.py", line 1357, in _process_transaction
    tx_result.score_address = self._handle_score_invoke(context, to, params)
  File "/usr/local/lib/python3.7/site-packages/iconservice/icon_service_engine.py", line 1470, in _handle_score_invoke
    IconScoreEngine.invoke(context, to, data_type, data)
  File "/usr/local/lib/python3.7/site-packages/iconservice/iconscore/icon_score_engine.py", line 57, in invoke
    IconScoreEngine._call(context, icon_score_address, data)
  File "/usr/local/lib/python3.7/site-packages/iconservice/iconscore/icon_score_engine.py", line 118, in _call
    ret = score_func(func_name=func_name, kw_params=converted_params)
  File "/usr/local/lib/python3.7/site-packages/iconservice/iconscore/icon_score_base.py", line 454, in __call
    ret = score_func(*arg_params, **kw_params)
  File "/usr/local/lib/python3.7/site-packages/iconservice/iconscore/icon_score_base.py", line 320, in __wrapper
    res = func(calling_obj, *args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/iconservice/iconscore/icon_score_base.py", line 286, in __wrapper
    res = func(calling_obj, *args, **kwargs)
  File "/data/mainnet/.score_data/score/01299d88908ab371d586c8dfe0ed42899a899e6e5b/0xb89051cbc02c2c46598636dcce73981170080420b47270bba041ac1543ac7671/main.py", line 623, in action
    self._process_cash_out(player_address, active_game_num)
  File "/data/mainnet/.score_data/score/01299d88908ab371d586c8dfe0ed42899a899e6e5b/0xb89051cbc02c2c46598636dcce73981170080420b47270bba041ac1543ac7671/main.py", line 373, in _process_cash_out
    game = json_loads(game_repository.get(player_address, active_game_num))
  File "/usr/local/lib/python3.7/site-packages/iconservice/iconscore/icon_score_base2.py", line 257, in json_loads
    return json.loads(src)
  File "/usr/local/lib/python3.7/json/__init__.py", line 348, in loads
    return _default_decoder.decode(s)
  File "/usr/local/lib/python3.7/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/local/lib/python3.7/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
2021-03-13 07:30:41,519 783 139965051762432 ERROR icon_service_engine.py(1522) ISE Expecting value: line 1 column 1 (char 0)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.