aeternity / ae_mdw

Aeternity Middleware in Elixir
26 stars 11 forks source link

Can't setup middleware for local development on a private chain #518

Closed davidyuk closed 1 year ago

davidyuk commented 2 years ago

I've clonned both ae_mdw (067f2c4, 1.5.0 tag) and aeternity (39941357, v6.4.0) to the same folder. Opened ae_mdw.

Adjusted configuration a bit:

diff --git a/docker-compose.yml b/docker-compose.yml
index f98ee4c..258c199 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -15,6 +15,7 @@ services:
       - ${PWD}/mnesia:/home/aeternity/node/local/rel/aeternity/data/mnesia
       - ${PWD}/docker/aeternity.yaml:/home/aeternity/aeternity.yaml
       - ${PWD}:/app
+      - ${PWD}/docker/accounts_test.json:/home/aeternity/node/data/aecore/.genesis/accounts_test.json
     expose: [3013, 3014, 3113, 4001, 4000]
     environment:
       - AETERNITY_CONFIG=/home/aeternity/aeternity.yaml
diff --git a/docker/aeternity.yaml b/docker/aeternity.yaml
index 80c8cfd..d5af2ae 100644
--- a/docker/aeternity.yaml
+++ b/docker/aeternity.yaml
@@ -1,3 +1,7 @@
+---
+peers: []
+include_default_peers: false
+
 sync:
     port: 3015
     log_peer_connection_count_interval: 6000000
@@ -17,8 +21,8 @@ websocket:
         port: 3014

 mining:
-    autostart: false
-    beneficiary: "ak_2Dri7n9Bm2FgdN5ZFXzDn1ZAXUMox6roEWTfU1rCQ842pTdWiK"
+    autostart: true
+    beneficiary: "ak_2swhLkgBPeeADxVTAVCJnZLY5NZtCFiM93JxsEaMuC59euuFRQ"

 chain:
     persist: true
@@ -28,4 +32,4 @@ chain:
         history: 500

 fork_management:
-    network_id: ae_mainnet
\ No newline at end of file
+    network_id: ae_uat

Executed docker-compose build and docker-compose up.

The logs looks fine ``` docker-compose up [+] Running 1/0 ⠿ Container ae_mdw-ae_mdw-1 Created 0.0s Attaching to ae_mdw-ae_mdw-1 ae_mdw-ae_mdw-1 | warning: variable "deps" does not exist and is being expanded to "deps()", please use parentheses to remove the ambiguity or change the variable name ae_mdw-ae_mdw-1 | /home/aeternity/node/ae_mdw/deps/dbg/mix.exs:19: Dbg.Mixfile.project/0 ae_mdw-ae_mdw-1 | ae_mdw-ae_mdw-1 | Loading aecore and deps ae_mdw-ae_mdw-1 | Loading sext ae_mdw-ae_mdw-1 | Loading parse_trans ae_mdw-ae_mdw-1 | Loading syntax_tools ae_mdw-ae_mdw-1 | Loading goldrush ae_mdw-ae_mdw-1 | Loading gproc ae_mdw-ae_mdw-1 | Loading jobs ae_mdw-ae_mdw-1 | Loading exometer_core ae_mdw-ae_mdw-1 | Loading redbug ae_mdw-ae_mdw-1 | Loading yamerl ae_mdw-ae_mdw-1 | Loading lager ae_mdw-ae_mdw-1 | Loading aeutils ae_mdw-ae_mdw-1 | Loading base58 ae_mdw-ae_mdw-1 | Loading sha3 ae_mdw-ae_mdw-1 | Loading enacl ae_mdw-ae_mdw-1 | Loading enoise ae_mdw-ae_mdw-1 | Loading jsx ae_mdw-ae_mdw-1 | Loading unicode_util_compat ae_mdw-ae_mdw-1 | Loading idna ae_mdw-ae_mdw-1 | Loading nat ae_mdw-ae_mdw-1 | Loading aeminer ae_mdw-ae_mdw-1 | Loading aetx ae_mdw-ae_mdw-1 | Loading aevm ae_mdw-ae_mdw-1 | Loading aeprimop ae_mdw-ae_mdw-1 | Loading aeoracle ae_mdw-ae_mdw-1 | Loading aecontract ae_mdw-ae_mdw-1 | Loading aebytecode ae_mdw-ae_mdw-1 | Loading aens ae_mdw-ae_mdw-1 | Loading aega ae_mdw-ae_mdw-1 | Loading aefate ae_mdw-ae_mdw-1 | Loading aeserialization ae_mdw-ae_mdw-1 | Loading ranch ae_mdw-ae_mdw-1 | Setting up data paths ae_mdw-ae_mdw-1 | Running setup hooks ae_mdw-ae_mdw-1 | setenv A=aecore: K=persist, V=true ae_mdw-ae_mdw-1 | 14:28:36.531 [info] Application lager started on node aeternity@localhost ae_mdw-ae_mdw-1 | 14:28:36.652 [info] Database persist mode true ae_mdw-ae_mdw-1 | 14:28:36.652 [info] Database backend mnesia_rocksdb ae_mdw-ae_mdw-1 | 14:28:36.653 [info] Database directory /home/aeternity/node/local/rel/aeternity/data/mnesia ae_mdw-ae_mdw-1 | 14:28:36.893 [info] Application mnesia started on node aeternity@localhost ae_mdw-ae_mdw-1 | 14:28:43.067 [info] aec_db:check_db()-> ok ae_mdw-ae_mdw-1 | 14:28:43.067 [info] Setup phase 210 ae_mdw-ae_mdw-1 | 14:28:43.199 [info] Loaded empty persisted chain ae_mdw-ae_mdw-1 | 14:28:43.202 [info] aec_db:start_db()-> ok ae_mdw-ae_mdw-1 | 14:28:43.202 [info] Setup phase 1000 ae_mdw-ae_mdw-1 | 14:28:43.203 [info] Set app_ctrl mode: normal ae_mdw-ae_mdw-1 | Starting aecore ae_mdw-ae_mdw-1 | 14:28:43.216 [info] aecore_app:set_app_ctrl_mode()-> ok ae_mdw-ae_mdw-1 | 14:28:43.216 [info] Setup finished processing hooks (Mode=normal)... ae_mdw-ae_mdw-1 | 14:28:43.221 [info] Application sext started on node aeternity@localhost ae_mdw-ae_mdw-1 | 14:28:43.221 [info] Application parse_trans started on node aeternity@localhost ae_mdw-ae_mdw-1 | 14:28:43.262 [info] Application jobs started on node aeternity@localhost ae_mdw-ae_mdw-1 | 14:28:43.276 [info] Application hut started on node aeternity@localhost ae_mdw-ae_mdw-1 | 14:28:43.299 [info] Application bear started on node aeternity@localhost ae_mdw-ae_mdw-1 | 14:28:43.404 [info] Application folsom started on node aeternity@localhost ae_mdw-ae_mdw-1 | 14:28:43.560 [info] Application exometer_core started on node aeternity@localhost ae_mdw-ae_mdw-1 | 14:28:43.562 [info] Application redbug started on node aeternity@localhost ae_mdw-ae_mdw-1 | 14:28:43.584 [info] Application yamerl started on node aeternity@localhost ae_mdw-ae_mdw-1 | 14:28:43.602 [info] Application argparse started on node aeternity@localhost ae_mdw-ae_mdw-1 | 14:28:43.627 [info] Application aeutils started on node aeternity@localhost ae_mdw-ae_mdw-1 | 14:28:43.628 [info] Application base58 started on node aeternity@localhost ae_mdw-ae_mdw-1 | 14:28:43.642 [info] Application hex2bin started on node aeternity@localhost ae_mdw-ae_mdw-1 | 14:28:43.642 [info] Application sha3 started on node aeternity@localhost ae_mdw-ae_mdw-1 | 14:28:43.642 [info] Application enacl started on node aeternity@localhost ae_mdw-ae_mdw-1 | 14:28:43.642 [info] Application enoise started on node aeternity@localhost ae_mdw-ae_mdw-1 | 14:28:43.643 [info] Application jsx started on node aeternity@localhost ae_mdw-ae_mdw-1 | 14:28:43.643 [info] Application unicode_util_compat started on node aeternity@localhost ae_mdw-ae_mdw-1 | 14:28:43.643 [info] Application idna started on node aeternity@localhost ae_mdw-ae_mdw-1 | 14:28:43.661 [info] Application inet_cidr started on node aeternity@localhost ae_mdw-ae_mdw-1 | 14:28:43.673 [info] Application inet_ext started on node aeternity@localhost ae_mdw-ae_mdw-1 | 14:28:43.682 [info] Application xmerl started on node aeternity@localhost ae_mdw-ae_mdw-1 | 14:28:43.696 [info] Application rand_compat started on node aeternity@localhost ae_mdw-ae_mdw-1 | 14:28:43.733 [info] Application lhttpc started on node aeternity@localhost ae_mdw-ae_mdw-1 | 14:28:43.734 [info] Application nat started on node aeternity@localhost ae_mdw-ae_mdw-1 | 14:28:43.743 [info] Application aecuckoo started on node aeternity@localhost ae_mdw-ae_mdw-1 | 14:28:43.753 [info] Application aecuckooprebuilt started on node aeternity@localhost ae_mdw-ae_mdw-1 | 14:28:43.753 [info] Application aeminer started on node aeternity@localhost ae_mdw-ae_mdw-1 | 14:28:43.753 [info] Application aetx started on node aeternity@localhost ae_mdw-ae_mdw-1 | 14:28:43.767 [info] Application eblake2 started on node aeternity@localhost ae_mdw-ae_mdw-1 | 14:28:43.767 [info] Application aeserialization started on node aeternity@localhost ae_mdw-ae_mdw-1 | 14:28:43.783 [info] Application getopt started on node aeternity@localhost ae_mdw-ae_mdw-1 | 14:28:43.783 [info] Application aebytecode started on node aeternity@localhost ae_mdw-ae_mdw-1 | 14:28:43.783 [info] Application aevm started on node aeternity@localhost ae_mdw-ae_mdw-1 | 14:28:43.783 [info] Application aecontract started on node aeternity@localhost ae_mdw-ae_mdw-1 | 14:28:43.783 [info] Application aens started on node aeternity@localhost ae_mdw-ae_mdw-1 | 14:28:43.783 [info] Application aeoracle started on node aeternity@localhost ae_mdw-ae_mdw-1 | 14:28:43.783 [info] Application aeprimop started on node aeternity@localhost ae_mdw-ae_mdw-1 | 14:28:43.784 [info] Application aega started on node aeternity@localhost ae_mdw-ae_mdw-1 | 14:28:43.811 [info] Application ecrecoverprebuilt started on node aeternity@localhost ae_mdw-ae_mdw-1 | 14:28:43.811 [info] Application ecrecover started on node aeternity@localhost ae_mdw-ae_mdw-1 | 14:28:43.824 [info] Application emcl started on node aeternity@localhost ae_mdw-ae_mdw-1 | 14:28:43.824 [info] Application aefate started on node aeternity@localhost ae_mdw-ae_mdw-1 | 14:28:43.838 [info] Application ranch started on node aeternity@localhost ae_mdw-ae_mdw-1 | 14:28:43.839 [info] Starting aecore node ae_mdw-ae_mdw-1 | 14:28:43.899 [info] Initializing keys manager ae_mdw-ae_mdw-1 | 14:28:43.912 [info] Detailed peer statistics are disabled ae_mdw-ae_mdw-1 | 14:28:43.969 [info] aec_monitor_metrics_probe:probe_init([ae,epoch,aecore,eper], probe, [{module,aec_monitor_metrics_probe},{type,probe}]) ae_mdw-ae_mdw-1 | 14:28:44.042 [info] Application aecore started on node aeternity@localhost ae_mdw-ae_mdw-1 | 14:28:44.058 [info] Application ae_plugin started on node aeternity@localhost ae_mdw-ae_mdw-1 | 14:28:44.088 [info] Application deep_merge started on node aeternity@localhost ae_mdw-ae_mdw-1 | 14:28:44.090 [info] Application benchee started on node aeternity@localhost ae_mdw-ae_mdw-1 | 14:28:44.100 [info] Application smart_global started on node aeternity@localhost ae_mdw-ae_mdw-1 | 14:28:44.107 [info] Application jason started on node aeternity@localhost ae_mdw-ae_mdw-1 | 14:28:44.113 [info] Application smart_record started on node aeternity@localhost ae_mdw-ae_mdw-1 | 14:28:44.119 [info] Application ex_json_schema started on node aeternity@localhost ae_mdw-ae_mdw-1 | 14:28:44.127 [info] Application tesla started on node aeternity@localhost ae_mdw-ae_mdw-1 | 14:28:44.149 [info] Application websockex started on node aeternity@localhost ae_mdw-ae_mdw-1 | 14:28:44.156 [info] Application cors_plug started on node aeternity@localhost ae_mdw-ae_mdw-1 | 14:28:44.165 [info] Application cowlib started on node aeternity@localhost ae_mdw-ae_mdw-1 | 14:28:44.182 [info] Application cowboy started on node aeternity@localhost ae_mdw-ae_mdw-1 | 14:28:44.188 [info] Application cowboy_telemetry started on node aeternity@localhost ae_mdw-ae_mdw-1 | 14:28:44.197 [info] Application plug_cowboy started on node aeternity@localhost ae_mdw-ae_mdw-1 | 14:28:44.201 [info] Application phoenix_swagger started on node aeternity@localhost ae_mdw-ae_mdw-1 | 14:28:44.204 [info] Application phoenix_html started on node aeternity@localhost ae_mdw-ae_mdw-1 | 14:28:44.208 [info] Application msgpax started on node aeternity@localhost ae_mdw-ae_mdw-1 | 14:28:44.215 [info] Application poison started on node aeternity@localhost ae_mdw-ae_mdw-1 | 14:28:51.383 [warning] PID <0.50.0> triggered monitor long_schedule with [{timeout,514},{in,{erl_prim_loader,request,1}},{out,undefined}] ae_mdw-ae_mdw-1 | 14:28:55.343 [warning] PID <0.927.0> triggered monitor long_schedule with [{timeout,671},{in,{gen,do_call,4}},{out,{gen,do_call,4}}] ae_mdw-ae_mdw-1 | 14:28:58.634 [warning] PID <0.50.0> triggered monitor long_schedule with [{timeout,540},{in,{erl_prim_loader,request,1}},{out,undefined}] ae_mdw-ae_mdw-1 | 14:29:01.294 [warning] PID <0.50.0> triggered monitor long_schedule with [{timeout,671},{in,undefined},{out,{code_server,loop,1}}] ae_mdw-ae_mdw-1 | 14:29:10.704 [info] Application prometheus started on node aeternity@localhost ae_mdw-ae_mdw-1 | 14:29:10.711 [info] Application prometheus_ex started on node aeternity@localhost ae_mdw-ae_mdw-1 | 14:29:10.726 [info] Application accept started on node aeternity@localhost ae_mdw-ae_mdw-1 | 14:29:10.727 [info] Application prometheus_plugs started on node aeternity@localhost ae_mdw-ae_mdw-1 | 14:29:10.734 [info] Application secure_random started on node aeternity@localhost ae_mdw-ae_mdw-1 | 14:29:10.746 [info] Application elixir_uuid started on node aeternity@localhost ae_mdw-ae_mdw-1 | 14:29:10.753 [info] Application socket started on node aeternity@localhost ae_mdw-ae_mdw-1 | 14:29:10.761 [info] Application the_end started on node aeternity@localhost ae_mdw-ae_mdw-1 | 14:29:10.761 [info] Application riverside started on node aeternity@localhost ```

But, the beneficiary account contains no tokens:

curl http://localhost:3013/v3/accounts/ak_2swhLkgBPeeADxVTAVCJnZLY5NZtCFiM93JxsEaMuC59euuFRQ
{"reason":"Account not found"}

Node is not mining blocks:

$ curl http://localhost:4000/status | jq .
{
  "mdw_async_tasks": {
    "long_tasks": 0,
    "producer_buffer": 0,
    "total_pending": 0
  },
  "mdw_height": 0,
  "mdw_revision": "067f2c4",
  "mdw_synced": false,
  "mdw_syncing": true,
  "mdw_tx_index": 0,
  "mdw_version": "1.5.0",
  "node_height": 0,
  "node_progress": 100,
  "node_revision": "39941357ac8491d890155c2ccbcd0571fbf3f5a0",
  "node_syncing": false,
  "node_version": "6.4.0"
}
$ curl http://localhost:3013/v3/headers/top | jq .
{
  "beneficiary": "ak_11111111111111111111111111111111273Yts",
  "hash": "kh_wUCideEB8aDtUaiHCtKcfywU6oHZW6gnyci8Mw6S1RSTCnCRu",
  "height": 0,
  "info": "cb_Xfbg4g==",
  "miner": "ak_11111111111111111111111111111111273Yts",
  "prev_hash": "kh_2CipHmrBcC5LrmnggBrAGuxAf2fPDrAt79asKnadME4nyPRzBL",
  "prev_key_hash": "kh_11111111111111111111111111111111273Yts",
  "state_hash": "bs_2aBz1QS23piMnSmZGwQk8iNCHLBdHSycPBbA5SHuScuYfHATit",
  "target": 553713663,
  "time": 0,
  "version": 1
}
$ curl http://localhost:3013/v3/status | jq .
{
  "difficulty": 16777216,
  "genesis_key_block_hash": "kh_wUCideEB8aDtUaiHCtKcfywU6oHZW6gnyci8Mw6S1RSTCnCRu",
  "listening": true,
  "network_id": "ae_uat",
  "node_revision": "39941357ac8491d890155c2ccbcd0571fbf3f5a0",
  "node_version": "6.4.0",
  "peer_connections": {
    "inbound": 0,
    "outbound": 0
  },
  "peer_count": 0,
  "peer_pubkey": "pp_QDLDtQRbq9aWfobooZQx8bSsYRuykqMjcrU1JXzfNPQTD4JAn",
  "pending_transactions_count": 0,
  "protocols": [
    {
      "effective_at_height": 425900,
      "version": 5
    },
    {
      "effective_at_height": 154300,
      "version": 4
    },
    {
      "effective_at_height": 82900,
      "version": 3
    },
    {
      "effective_at_height": 40900,
      "version": 2
    },
    {
      "effective_at_height": 0,
      "version": 1
    }
  ],
  "solutions": 0,
  "sync_progress": 100,
  "syncing": false,
  "top_block_height": 0,
  "top_key_block_hash": "kh_wUCideEB8aDtUaiHCtKcfywU6oHZW6gnyci8Mw6S1RSTCnCRu"
}
marc0olo commented 2 years ago

this is regarding base aepp testing now?

in the java sdk we are using mdw locally:

it's a custom build of us with node v6.3.0 right now. do you need latest features of v6.4.0 ? I can trigger a build to use latest version of node and mdw if you need it

thepiwo commented 2 years ago

the docs currently say only ae_mainnet and ae_uat are supported, but I don't know the technical reason. @jyeshe @sborrazas

jyeshe commented 2 years ago

Since node v6.3.0 this is needed in config.exs: config :aecore, network_id: "ae_uat" @thepiwo @davidyuk @marc0olo

sborrazas commented 2 years ago

There's also the devnet configuration that can be used to set up a dev chain (where transactions are processed instantly).

This closed PR contains a sample on how you can additionally set up a devnet with the JS SDK to be able to create transactions locally

thepiwo commented 2 years ago

@davidyuk can you use something else then ae_uat for this? Anyways I think its a node issue, not a mdw issue

jyeshe commented 2 years ago

Since node v6.3.0 this is needed in config.exs: config :aecore, network_id: "ae_uat" @thepiwo @davidyuk @marc0olo

At least when running ad-hoc images/containers with make docker-shell

davidyuk commented 2 years ago

do you need latest features of v6.4.0?

I just wasn't aware of what with what is compatible. Can we define it somehow explicitly in readme/release notes/#517?

the docs currently say only ae_mainnet and ae_uat are supported

I used ae_uat but with peers disabled to get the needed behavior.

This closed PR contains a sample on how you can additionally set up a devnet

I don't need to setup a local mdw anymore, but would be nice to have it documented.

sborrazas commented 2 years ago

@davidyuk looking at the docs I believe setting peers to an empty array won't connect to any node from any network, which means it will remain without any new blocks, but we might have to ask the core team to be sure on this.

What kind of setup are you trying to have locally and for what use would it be?

marc0olo commented 2 years ago

@davidyuk looking at the docs I believe setting peers to an empty array won't connect to any node from any network, which means it will remain without any new blocks, but we might have to ask the core team to be sure on this.

as long the node is mining that should work as far as I know

sborrazas commented 2 years ago

@marc0olo once I removed the include_default_peers: False config the node started syncing

thepiwo commented 2 years ago

@davidyuk have you verified the node without mdw would be syncing with that configuration? Genesis block is > 4 years old and I don't know how fast the difficulty adjustment happens. I'd think you are mining already, just not finding a block.

davidyuk commented 2 years ago

What kind of setup are you trying to have locally and for what use would it be?

Ideally, it shouldn't sync with anything, should mine blocks by interval, middleware endpoints should be in sync with mined blocks, I should be able to provide a genesis account with some coins.

I was planning to connect some aepp to it (to both middleware and node endpoints) to do some testing.

have you verified the node without mdw would be syncing with that configuration?

Actually, I didn't. I wouldn't use include_default_peers if I am able to change the network id.

thepiwo commented 2 years ago

confirmed this is still an issue with this config

sync:
    port: 3015
    log_peer_connection_count_interval: 6000000

keys:
    dir: keys
    peer_password: "secret"

http:
    external:
        port: 3013
    internal:
        port: 3113

websocket:
    channel:
        port: 3014

mining:
    autostart: true
    beneficiary: "ak_2Dri7n9Bm2FgdN5ZFXzDn1ZAXUMox6roEWTfU1rCQ842pTdWiK"
    expected_mine_rate: 5000
    cuckoo:
        miner:
            executable: mean15-generic
            extra_args: ""
            edge_bits: 15

fork_management:
    network_id: ae_devnet

running docker-compose up --build

thepiwo commented 1 year ago

@jyeshe is this resolved with the latest changes for HC?

jyeshe commented 1 year ago

@jyeshe is this resolved with the latest changes for HC?

It was a fix for another issue but solved this one too. Testing with your aeternity.yaml it syncs and the beneficary is found:

$ curl http://localhost:3013/v3/accounts/ak_2Dri7n9Bm2FgdN5ZFXzDn1ZAXUMox6roEWTfU1rCQ842pTdWiK 
{"balance":1680535000000000000000,"id":"ak_2Dri7n9Bm2FgdN5ZFXzDn1ZAXUMox6roEWTfU1rCQ842pTdWiK","kind":"basic","nonce":0,"payable":true}