Giter Club home page Giter Club logo

eth-payment-processor's Introduction

eth-payment-processor

  • provides evm payment gateway to enable service providers to collect payment for services in various tokens based off USD fixed price of service

eth-payment-processor's People

Contributors

atcsecure avatar conanmishler avatar francobenner avatar magic53 avatar pom11 avatar shrnkld avatar walkjivefly avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

eth-payment-processor's Issues

consistent format for discount env vars

  File "/app/manager/main.py", line 12, in <module>
    from util.eth_payments import Web3Helper
  File "/app/manager/util/__init__.py", line 11, in <module>
    discount_ablock = float((100 - os.environ.get('DISCOUNT_ABLOCK', 20))/100)
TypeError: unsupported operand type(s) for -: 'int' and 'str'```

[Bug] eth-payment-processor:latest container keeps restarting

After the latest updates to eth-payment-processor the container keeps restarting.

The only possible errors I can see in the logs are as follows:

column "min_amount_usd" of relation "payment" already exists

ADD payment min_amount_ablock_usd float8
column "min_amount_ablock_usd" of relation "payment" already exists

ADD payment min_amount_aablock_usd float8
column "min_amount_aablock_usd" of relation "payment" already exists

ADD payment min_amount_sysblock_usd float8
column "min_amount_sysblock_usd" of relation "payment" already exists

and:

Traceback (most recent call last):
  File "/app/manager/payment_processor.py", line 22, in <module>
    web3_helper = Web3Helper()
  File "/app/manager/util/eth_payments.py", line 63, in __init__
    self.w3[evm].middleware_onion.inject(geth_poa_middleware, layer=0)
AttributeError: 'NoneType' object has no attribute 'middleware_onion'
RENAME payment address eth_address
column "address" does not exist

docker ps shows: blocknetdx/eth-payment-processor:latest "/bin/sh -c 'python3…" 16 hours ago Restarting (1) 32 seconds ago

Changes to the `request_project` method

To do:

  • add a parameter to request_project to enable selecting the project type:
    1. xquery
    2. hydra
  • modify request_hydra_project method to accept one of the following optional parameters:
    1. archival
    2. non-archival
    • set the default option to: non-archival
  • set a lower limit for api calls, where minimum purchase possible==1000 queries
  • display all pricing info as cost_per_1000_queries eg $0.001/1000 query - TBD
  • #43
  • remove all usage-limiting features eg time constraints, max calls, etc - TBD
  • #42
  • #41

Method `request_project` takes over a minute to respond

Scenario:

Trying to request a new XQuery project via curl, and using the method request_project is resulting in a delay of over a minute before any response.

Steps to reproduce

  1. From a terminal/cli:
    -X POST \
    -H "Content-Type: application/json" \
    -d '{"jsonrpc":"2.0","method":"request_project","params": [],"id":1}'
  1. Wait...
  2. Response takes >1 min

To do:

  • Investigate the cause of the delay, which may be linked to this: #26
  • fix to be discussed once the cause is confirmed

check nodes status

wait for nodes to sync and after that connect to them to fetch prices and check payments.

Payments - feature changes

——
Some suggested changes to the payment system...TBD
——
PAYMENT NOTES:

  • projects can be underpaid and the snode waits unlimited time for them to be paid fully
    the time limit for any requested project to be paid for should be 24hrs (inactive projects that are not paid for in 24hrs will then be cancelled and cleared from the UI)
  • if a project is paid in over 12h, the user only gets access to the most recent 128 blocks of ETH (nonarchival access) and half of default api count
    we should change this imho; not paid in 24hrs > cancel project > inform user to request new project
  • if a project is paid in time in under 12h change to 24hrs the api call count is relative to the amount paid and activate archival (i.e. access to all ETH blocks) if greater than tier2

geth host

use local/external host for eth or aBlock payment.
spin node if necessary

payment processor using 100% CPU

@Tryou is reporting the payment processor (which runs /app/manager/main.py in the exrproxy-env-payment-1 container) is using 100% of one CPU, even when no payment blockchains are attached to EXR ENV. It should be sitting idle, waiting for payment blockchains to be attached. @Tryou's comments:

flat 100% cpu usage with no connected chain and even 'between' the connect attempts  =
problem with multithreading, main loop refresh timers, conflict between 2 py modules, etc

and

looking on GH, the big bag of changes made on Jan 11, 2022,
seems it went offroad from here,
maybe something with flask, async, threading, no idea

Memory Leak?

Memory usage by the exrproxy-env-payment-1 container grows over time. I've seen it grow up to 3.5 GB on one of my SNodes, which is much more than this simple container should require. Maybe it's just the memory occupied by the growing log file, or maybe it's a memory leak. It should be investigated.

Suggestion to replace WSYS with SYS (NEVM token) in eth-payment-processor

Scenario:

There are two distinct tokens on the SYS NEVM: SYS and WSYS.
Wrapped SYS is required to swap on the Pegasys AMM.
SYS is the token that is received by users who bridge from SYS UTXO to SYS NEVM and therefore the primary token of the SYS NEVM network.

Accepting only WSYS for XQuery and Hydra requires an extra step for users (swap from SYS > WSYS on Pegasys DEX) and therefore I would suggest we change WSYS to SYS.

Contract address for WSYS: 0xd3e822f3ef011Ca5f17D82C956D952D8d7C3A1BB
Contract address for SYS:

TBD before making any changes

add HOST_TYPE

check for HOST_TYPE env var to check if a http or a ws is required.

  • ETH_HOST_TYPE
  • AVAX_HOST_TYPE

Add AVAX as a payment option

Scenario:

eth-payment-processor for EXR projects currently allows payment in aBLOCK, aaBLOCK and ETH but not AVAX.

An AVAX address is generated but AVAX doesn't show in the list of accepted tokens. eg:

        'result': {
            'project_id': project_name,
            'api_key': api_key,
            'payment_eth_address': eth_address,
            'payment_avax_address': avax_address,
            'payment_amount_tier1_eth': tier1_expected_amount,
            'payment_amount_tier2_eth': tier2_expected_amount,
            'payment_amount_tier1_ablock': tier1_expected_amount_ablock,
            'payment_amount_tier2_ablock': tier2_expected_amount_ablock,
            'payment_amount_tier1_aablock': tier1_expected_amount_aablock,
            'payment_amount_tier2_aablock': tier2_expected_amount_aablock,
            'expiry_time': payment_expires.strftime("%Y-%m-%d %H:%M:%S EST")
        }

To do:

  • add AVAX as an accepted payment currency for exr projects
  • add required options for AVAX fee values to the auto-builder

QA:

  • snode op can set the AVAX payment values for tier 1
  • the relevant project fee is shown in AVAX
  • the user is able to pay for a project with AVAX

Migration script

Create a migration script that converts older versions of db models to new ones

Activate project w/ aBLOCK payment failed

I don't know that we've tested whether it works to activate a new project with an aBLOCK payment, so I decided to test it (even though it cost me $10 in eth gas fees to send the aBLOCK!)

Here's what I did:

  1. I adjusted my DISCOUNT_ABLOCK value to 95%, then restarted the payment processor.
  2. I requested a new project and got this reply:
{
    "result": {
        "api_key": "P2kLB9PpK2Be_PzG6u97pTnVkjaVVGFChDNv2e9vm2A",
        "expiry_time": "2022-02-14 04:00:26 EST",
        "payment_amount_tier1_aablock": 64.7457,
        "payment_amount_tier1_ablock": 1.367188,
        "payment_amount_tier1_eth": 0.012199,
        "payment_amount_tier2_aablock": 369.975426,
        "payment_amount_tier2_ablock": 7.8125,
        "payment_amount_tier2_eth": 0.069709,
        "payment_avax_address": "0x56f9F4a48c4D614b51C6036BE53d7dd89Aa90a1e",
        "payment_eth_address": "0xb847f6734975D99EB90E819DfEDfE666b4A15CD0",
        "project_id": "8ff20bd2-3505-4ff2-826a-dbd6a36fa481"
    }
}
  1. I sent 1.367188 aBLOCK to 0xb847f6734975D99EB90E819DfEDfE666b4A15CD0
  2. I invoked the list_projects call to see if my new project had become active. It had not become active.
  3. I checked logs of exrproxy-env_eth_payment_api_1 container and found error messages like this:
[2022-02-14:00:39:29] CRITICAL - error handling eth back event
Traceback (most recent call last):
  File "/app/manager/util/eth_payments.py", line 164, in eth_start_back
    self.handle_eth_events(events)
  File "<string>", line 2, in handle_eth_events
  File "/usr/local/lib/python3.8/site-packages/pony/orm/core.py", line 533, in new_func
    result = func(*args, **kwargs)
  File "/app/manager/util/eth_payments.py", line 246, in handle_eth_events
    self.handle_eth_event(event)
  File "/app/manager/util/eth_payments.py", line 283, in handle_eth_event
    ablock_accounts = self.check_ablock_balance()
  File "/app/manager/util/eth_payments.py", line 266, in check_ablock_balance
    balance_contract = self.contract_ablock.functions.balanceOf(contract_address).call()
  File "/usr/local/lib/python3.8/site-packages/web3/contract.py", line 878, in __call__
    clone._set_function_info()
  File "/usr/local/lib/python3.8/site-packages/web3/contract.py", line 883, in _set_function_info
    self.abi = find_matching_fn_abi(
  File "/usr/local/lib/python3.8/site-packages/web3/_utils/contracts.py", line 163, in find_matching_fn_abi
    raise ValidationError(message)
web3.exceptions.ValidationError: 
Could not identify the intended function with name `balanceOf`, positional argument(s) of type `(<class 'str'>,)` and keyword argument(s) of type `{}`.
Found 1 function(s) with the name `balanceOf`: ['balanceOf(address)']
Function invocation failed due to no matching argument types.

This was on my VPS4 if you want to login and poke around.

Failed to activate project w/ ETH payment

Inspired by the successful activation of a project through aBLOCK payment, I went on to request a new project and activate it via ETH payment. The project_request call yielded this (after rates were intentionally lowered on the server):

{
    "result": {
        "api_key": "yjUZiB-XFzARsgc2t11XuMkEtIJsHh1oAPA0LsbbhA0",
        "expiry_time": "2022-02-15 06:10:01 EST",
        "payment_amount_tier1_aablock": 1.752046,
        "payment_amount_tier1_ablock": 0.390625,
        "payment_amount_tier1_eth": 0.000332,
        "payment_amount_tier2_aablock": 350.409251,
        "payment_amount_tier2_ablock": 78.125,
        "payment_amount_tier2_eth": 0.06631,
        "payment_avax_address": "0xe59C639DA8278599c04503CF511b1adF972c61F3",
        "payment_eth_address": "0xAD0ae3AB7E2Eae865dc1DeE3Fa195Ce13da32650",
        "project_id": "ed7a4642-41f7-4593-86a8-be592ccc9272"
    }
}

Then I sent 0.000332 ETH to the payment_eth_address: https://etherscan.io/tx/0xb8b1c68b18a1b7aac843cfdcac4978a8bd6003c255a4d03d4033dd83b2790653

Then I checked the status of "project_id": "ed7a4642-41f7-4593-86a8-be592ccc9272", only to find it has not become active. ☹️

I'm seeing this in the payment processor logs:

[2022-02-15:02:51:12] CRITICAL - error handling eth back event
Traceback (most recent call last):
  File "/app/manager/util/eth_payments.py", line 164, in eth_start_back
    self.handle_eth_events(events)
  File "<string>", line 2, in handle_eth_events
  File "/usr/local/lib/python3.8/site-packages/pony/orm/core.py", line 533, in new_func
    result = func(*args, **kwargs)
  File "/app/manager/util/eth_payments.py", line 246, in handle_eth_events
    self.handle_eth_event(event)
  File "/app/manager/util/eth_payments.py", line 385, in handle_eth_event
    payment_obj.project.api_token_count += calc_api_calls(value, 'ablock',
  File "/usr/local/lib/python3.8/site-packages/pony/orm/core.py", line 2310, in __set__
    new_val = attr.validate(new_val, obj, from_db=False)
  File "/usr/local/lib/python3.8/site-packages/pony/orm/core.py", line 2544, in validate
    val = Attribute.validate(attr, val, obj, entity, from_db)
  File "/usr/local/lib/python3.8/site-packages/pony/orm/core.py", line 2215, in validate
    val = converter.validate(val, obj)
  File "/usr/local/lib/python3.8/site-packages/pony/orm/dbapiprovider.py", line 546, in validate
    throw(ValueError, 'Value %r of attr %s is greater than the maximum allowed value %r'
  File "/usr/local/lib/python3.8/site-packages/pony/utils/utils.py", line 106, in throw
    raise exc
ValueError: Value 2168400007 of attr Project.api_token_count is greater than the maximum allowed value 2147483647

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.