{"id":14967009,"url":"https://github.com/golemfactory/concent","last_synced_at":"2025-06-11T10:09:18.976Z","repository":{"id":86423474,"uuid":"108836885","full_name":"golemfactory/concent","owner":"golemfactory","description":"Repository for Concent Service sources","archived":false,"fork":false,"pushed_at":"2020-04-10T18:15:22.000Z","size":5189,"stargazers_count":8,"open_issues_count":82,"forks_count":7,"subscribers_count":31,"default_branch":"master","last_synced_at":"2024-10-01T01:56:52.975Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/golemfactory.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-10-30T10:41:44.000Z","updated_at":"2022-10-27T06:03:04.000Z","dependencies_parsed_at":"2023-04-16T17:19:11.308Z","dependency_job_id":null,"html_url":"https://github.com/golemfactory/concent","commit_stats":{"total_commits":1591,"total_committers":14,"mean_commits":"113.64285714285714","dds":0.6926461345065996,"last_synced_commit":"23ffa9464c995a628aa570bc9a0a05d29f48b044"},"previous_names":[],"tags_count":34,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/golemfactory%2Fconcent","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/golemfactory%2Fconcent/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/golemfactory%2Fconcent/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/golemfactory%2Fconcent/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/golemfactory","download_url":"https://codeload.github.com/golemfactory/concent/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":219869245,"owners_count":16555571,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-09-24T13:37:17.359Z","updated_at":"2024-10-07T10:05:46.694Z","avatar_url":"https://github.com/golemfactory.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# concent\nRepository for Concent Service sources\n\n## Production setup\n\n### `local_settings.py`\n\nAll the configuration of the application is defined in `concent_api/concent_api/settings/`.\nWhen setting up a new instance you should create a `local_settings.py` file in that directory and import the default production settings:\n\n``` python\nfrom .production import *\n```\n\nNow you can add any settings you need or override defaults defined in `base.py` and `production.py`.\n\n### Generating public and private key pair for settings\n\nKeys should be generated using the `ECCx` class from `golem-messages`:\n\n``` python\nfrom golem_messages import ECCx\n\necc = ECCx(None)\n\nprint(\"CONCENT_PUBLIC_KEY  = {}\".format(ecc.raw_pubkey))\nprint(\"CONCENT_PRIVATE_KEY = {}\".format(ecc.raw_privkey))\n```\n\nYou can put the output of the script above directly in your `local_settings.py`\n\n## Development setup\n\n### Preparing your environment for development\n\n1. Install [Python](https://www.python.org/) \u003e= 3.6 using your package manager.\n\n2. Install [PostgreSQL](https://www.postgresql.org) \u003e= 10 using your package manager.\n\n    If you're using this machine only for development, configure PosgreSQL to be reachable only from `localhost`.\n\n    Make sure that PostgreSQL service is running (in many distros the service is started automatically right after installation).\n\n3. Clone this repository\n\n    ``` bash\n    git clone git@github.com:golemfactory/concent.git\n    ```\n\n4. Install dependencies in a virtualenv\n\n    ``` bash\n    virtualenv ~/.virtualenvs/concent --python python3\n    source ~/.virtualenvs/concent/bin/activate\n    pip install pip --upgrade\n\n    # Dependencies for running concent\n    pip install --requirement concent_api/requirements.lock\n\n    # Extra stuff for development that's not normally installed in production. Linter, debugger, etc.\n    pip install --requirement requirements-development.txt\n\n    # All dependencies needed for developers. Concent, Singing Service, Middleman Protocol and requirements placed in requirements-development.txt\n    ./install-development-requirements.sh\n    ```\n\n    **libsecp256k1**\n\n    If `pip` tries to build a Python package called [secp256k1](https://github.com/ludbb/secp256k1-py) and fails, you'll need to install a Linux package called [libsecp256k1](https://github.com/bitcoin-core/secp256k1) using your package manager and rerun the installation.\n    This should not be the case most of the time because there are binary .wheels available on PyPI and they have this library bundled with them.\n    They don't cover all possible configurations though.\n    If you're running a very recent version of Python, `pip` might not be able to find pre-built binaries matching your version of the interpreter and try to build the C extension on its own.\n    This will only succeed if you have `libsecp256k1` installed.\n    The package is available in the repositories of some Linux distributions.\n    If you can't find it in your distro, you can also build it manually from source by following the instructions listed on the page linked above.\n\n    **OpenSSL 1.1**\n\n    [golem-messages](https://github.com/golemfactory/golem-messages) depends on [pyelliptic](https://github.com/yann2192/pyelliptic) which is not compatible with OpenSSL 1.1.\n    For it to work you'll have to install OpenSSL 1.0.\n    Fortunately most distributions still provide both versions.\n    For example on Debian you can install `libssl1.0.2` and `libssl1.0-dev`.\n    On Arch Linux there's `openssl-1.0`.\n\n    You'll run into a problem if you have both OpenSSL 1.0 and OpenSSL 1.1 installed at the same time though.\n    `pyelliptic` calls `ctypes.util.find_library('crypto')` to load the library and if you have both versions it loads version 1.1.\n    To prevent this you can patch its source and hard-code the path to OpenSSL 1.0:\n\n    ``` bash\n    sed \\\n        \"s%ctypes.util.find_library('crypto')%'/usr/lib/openssl-1.0/libcrypto.so'%\" \\\n        -i ~/.virtualenvs/concent/lib/python3.*/site-packages/pyelliptic/openssl.py\n    ```\n\n    Note that the path to `libcrypto.so` can vary between distributions.\n    On Debian it's `/usr/lib/x86_64-linux-gnu/libcrypto.so.1.0`.\n    On Arch Linux you'll find it in `/usr/lib/openssl-1.0/libcrypto.so`.\n    You'll have to adjust the command above to match your system.\n\n5. Create your local configutation in `concent_api/concent_api/settings/local_settings.py`:\n\n    ``` python\n    from .development import *\n    ```\n\n    If your database configuration differs from the defaults, you may need to tweak the values below and add them to your `local_settings.py` too:\n\n    ``` python\n    DATABASES['NAME']     = 'concent_api'\n    DATABASES['USER']     = 'postgres'\n    DATABASES['PASSWORD'] = ''\n    DATABASES['HOST']     = '5432'\n    DATABASES['PORT']     = 'locslhost'\n    ```\n\n6. Create an empty database with the name you set in `DATABASES['NAME']` (`concent_api` if you did not set it explicitly):\n\n    ``` bash\n    createdb --username postgres concent_api\n    ```\n\n7. Run Django migrations for each database to initialize and create the tables:\n\n    ```\n    concent_api/manage.py migrate --database control\n    concent_api/manage.py migrate --database storage\n    ```\n\n8. Create a superuser account:\n\n    ```\n    concent_api/manage.py createsuperuser --database control\n    ```\n    \n9. Enable time synchronization:\n\n    Concent is highly time dependent service. Thus time synchronization should be enabled:\n    ```bash\n    timedatectl set-ntp true\n    ```\n\n### Running concent in development\n\nTo start a Concent server simply run\n\n``` bash\nconcent_api/manage.py runserver\n```\n\nThe server is now reachable at http://localhost:8000/.\n\nNote that Concent does not have a UI so you will only get HTTP 404 if you try to go to that address in the browser.\nYou can access the admin panel at http://localhost:8000/admin/ but this is only for maintenance and accessing statistics.\n\nThe primary way to interact with the service is via a Golem client.\nYou can simulate this interaction with a tool like [curl](https://curl.haxx.se/) or custom scripts that send HTTP requests.\nOne of such scripts, meant to test a working Concent server in a very rudimentary way is `api-test.py`:\n\n``` bash\nconcent_api/api-test.py http://localhost:8000\n```\n\n### Running tests\n\nYou can run automated tests, code analysis and Django configuration checks with:\n\n``` bash\n./full_check.sh\n```\n\nAlways run this command before submitting code in a pull request and make sure that there are no warnings or failed tests.\n\n\n### Running Middleman\n\nConcent signs Ethereum transactions by passing them to an external signing service provided by Golem.\nTo decrease the attack surface the service is not serving any requests.\nInstead, Concent runs a component that opens a TCP port, and allows the signing service to connect at will.\nThis component (internally called \"Middleman\") needs to be started separately from the main server:\n\n``` bash\nconcent_api/manage.py middleman\n```\n\nThe command should work fine without any extra arguments.\nYou can use `--help` option to see all the available options.\n\nNote that in development you need to run an instance of the Signing Service yourself.\nThe application is maintained by the Concent team as well and you can find it in this repository.\nSee [Signing Service README](signing_service/README.md)\n\n### Running Celery workers in development\n\nConcent uses Celery asynchronous task queue to perform additional verification for Golem clients.\nConcent works fine without them, they are required only if you want to perform additional verification use case.\nTo use workers you should have a message broker like RabbitMQ or Redis running locally.\n\nYou can run Celery workers for Concent with:\n\n``` bash\nconcent_api/celery worker --app concent_api --loglevel info --queues concent,conductor,verifier\n```\n\n### Deploying GNTDeposit contract\n\nTo be able to run end-to-end (E2E) tests locally without interfering with other Concent instances, you need a separate instance of the `GNTDeposit` contract on the blockchain and a separate Ethereum account Concent will use to issue transactions and transfer deposits.\nConcent assumes that it's the only entity with access to the deposits and you'll get false positives and random failures if that's not true.\n\n1. Get [GNTDeposit.sol](https://github.com/golemfactory/golem-contracts/blob/master/contracts/GNTDeposit.sol)\nfrom [golem-contracts](https://github.com/golemfactory/golem-contracts) repository.\n\n2. Fallow this tutorial to deploy GNTDeposit.sol on `rinkeby` ethereum testnet:\n[Deploy Smart Contracts on Ropsten Testnet through Ethereum Remix](https://medium.com/swlh/deploy-smart-contracts-on-ropsten-testnet-through-ethereum-remix-233cd1494b4b)\n\n    It involves installing `MetaMask` in your browser, importing ethereum account that you generate before using\n    hex-encoded value and getting some testnet ETH. Then copy `GNTDeposit.sol` with all dependencies to single file in\n    solidity IDE - `remix`. You can use [solidity-flattener](https://github.com/BlockCatIO/solidity-flattener) to do so.\n\n3. There are four variables needed to deploy new GNTDeposit contract:\n\n    - `_token` - GNTB contract address.\n    For all testnet environments, it should be hardcoded to `0x123438d379BAbD07134d1d4d7dFa0BCbd56ca3F3`.\n\n    - `_concent` - Concent ethereum address, compatible with keys pair generated before.\n\n    - `_coldwallet` - Another or the same concent ethereum address. It's used as an account to store communication and\n    verification fees.\n\n    - `_withdrawal_delay` - This is the time(in seconds) after which a Golem client is allowed to withdraw its deposit.\n    We used mainnet value so far, which is 48h (172800 seconds).\n\n4. After successfully deploying your own copy of `GNTDeposit` contract, you need to put the new values in your `local_settings.py`:\n\n    - `GNT_DEPOSIT_CONTRACT_ADDRESS`: the Ethereum address of the newly deployed contract\n    - `CONCENT_ETHEREUM_PRIVATE_KEY`: the private key matching contract's address (binary value as Python's `bytes`)\n    - `CONCENT_ETHEREUM_PUBLIC_KEY`: the public key matching contract's address (hex-encoded value as Python's `str`)\n    - `CONCENT_PRIVATE_KEY`: the same as `CONCENT_ETHEREUM_PRIVATE_KEY`\n    - `CONCENT_PUBLIC_KEY`: the same as `CONCENT_ETHEREUM_PUBLIC_KEY`, but in binary value\n\n5. For the tests to work there must be some test GNT on deposit accounts belonging to the provider and requestor that interact with Concent in E2E tests.\nYou need to manually request some GNT from the faucet and transfer it to the accounts.\nBefore doing this, remember to clear Concent's databases if there were any previous transaction being made with different `GNT_DEPOSIT_CONTRACT_ADDRESS`.\nThen adjust the code below to your need and type it in the Django shell (`manage.py shell`):\n\n    ``` python\n    from core.payments.payment_interface import PaymentInterface\n\n    p = PaymentInterface()  # eth address for \"p\" depends on `CONCENT_ETHEREUM_PRIVATE_KEY` and `CONCENT_ETHEREUM_PUBLIC_KEY`\n    p.request_gnt_from_faucet()\n    # check if You have GNT with `p.get_gnt_balance(p.get_eth_address())`\n\n    p.open_gate()\n    # check if the command above worked with `p.get_gate_address()` (should return eth address)\n\n    p.transfer_gnt(p.get_gate_address(), value)  # `value` is amount of GNT You want to convert to GNTB\n    p.transfer_from_gate()\n    # check if You have GNTB with `p.get_gntb_balance(p.get_eth_address())`\n\n    p.deposit_payment(value)  # value is amount of GNTB You want to use as deposit\n    # check if You have deposit with `p.get_deposit_value(p.get_eth_address())`\n    ```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgolemfactory%2Fconcent","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgolemfactory%2Fconcent","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgolemfactory%2Fconcent/lists"}