ton-blockchain / ton

Main TON monorepo
Other
2.95k stars 891 forks source link

Running a single node network #172

Closed leedioxin closed 2 years ago

leedioxin commented 4 years ago

I've been trying to run a test network from a single node, using a zero-state that I create using create-state.

I'm getting error logs complaining that there are no nodes from which to download state.

I did change the global-config to only contain 1 node (with my own address). I was wondering if there's anything obvious I'm doing incorrectly.

I wrote out the list of steps that I tried -- I'll paste them below. If I ever get this working, I'd be happy to share the final document. Also, sorry about any formatting ... I copied it from a Word Doc

=== Starting up a single node network:

Goal: Create a private test network consisting of only a single node.

This was all done on an Ubuntu 18.04 VM in AWS.

0 - Pre-work. Clone and build a validator engine. Use https://test.ton.org/FullNode-HOWTO.txt for guidance.

After this is done, stop the validator engine.

For the purposes of this exercise, I have used the recommended directory name of /var/ton-work to hold the database.

I used the directory /home/tonton/source to clone the ton repo.

Clean Slate:

When you have completed this prework, you have probably started up your validator-engine at least twice. Since you have already gotten a donor global config (wget https://test.ton.org/ton-global.config.json) that means the node has already at least tried to communicate with the set of static validators listed in the static_nodes list. As such, the database directory will already have some artifacts written.

example:

tonton@ip-10-5-1-13:/var/ton-work/db$ ls

adnl archive blockdb celldb config.json dht-kJQwsFgjfqx6KWUwz_R3KpcIsu647Pu9_yOdOg7zehY error files keyring ltdb overlays state

1- Keep some/drop many

We will get rid of the directories {adnl, archive, blockdb, celldb, error, files, ltdb, overlays, state}

We will retain files/directories {config.json, dht-kJQwsFgjfqx6KWUwz_R3KpcIsu647Pu9_yOdOg7zehY, keyring} -- note: the generated dht-* file will have a different identifier than the example

What did we keep?

Mostly, we retained the address and keys that we get at startup. They are the 2 keys that live in keyring:

tonton@ip-10-5-1-13:/var/ton-work/db$ ls keyring/

909430B058237EAC7A296530CFF4772A9708B2EEB8ECFBBDFF239D3A0EF37A16 EF5908705E23A075FCBF3CFB99ACCE38BAFD50BB48888D2C89D9B70E3BB131E5

These contain private keys (the filename is the corresponding public key) that correspond to 2 addresses in our newly created validator. You can see them inside the config.json that we kept.

Excerpt:

...

"adnl" : [

  { 

     "@type" : "engine.adnl", 

     "id" : "kJQwsFgjfqx6KWUwz/R3KpcIsu647Pu9/yOdOg7zehY=", 

     "category" : 0 

  }, 

  { 

     "@type" : "engine.adnl", 

     "id" : "71kIcF4joHX8vzz7mazOOLr9ULtIiI0sidm3DjuxMeU=", 

     "category" : 1 

  } 

],

If we base64 decode these ids, we end up with the keyring file names:

tonton@ip-10-5-1-13:/var/ton-work/db$ echo "kJQwsFgjfqx6KWUwz/R3KpcIsu647Pu9/yOdOg7zehY=" | base64 --decode | hexdump

0000000 9490 b030 2358 ac7e 297a 3065 f4cf 2a77

0000010 0897 eeb2 ecb8 bdfb 23ff 3a9d f30e 167a

0000020

Associated to 909430B058237EAC7A296530CFF4772A9708B2EEB8ECFBBDFF239D3A0EF37A16

and:

tonton@ip-10-5-1-13:/var/ton-work/db$ echo "71kIcF4joHX8vzz7mazOOLr9ULtIiI0sidm3DjuxMeU=" | base64 --decode | hexdump

0000000 59ef 7008 235e 75a0 bffc fb3c ac99 38ce

0000010 fdba bb50 8848 2c8d d989 0eb7 b13b e531

Is associated with EF5908705E23A075FCBF3CFB99ACCE38BAFD50BB48888D2C89D9B70E3BB131E5

*Note: You can use hexdump -C for this display if the endianness bothers you

2 - Make a zero state:

Generate a single member list of public validator keys using the public key from our config.

From config.json, use the public key listed as our full node:

"fullnode" : "71kIcF4joHX8vzz7mazOOLr9ULtIiI0sidm3DjuxMeU=",

To generate the file validator-keys.pub

cd /home/tonton/source/crypto

2.1 echo "71kIcF4joHX8vzz7mazOOLr9ULtIiI0sidm3DjuxMeU=" | base64 --decode > validator-keys.pub

2.2 We will also want to adjust some of the configuration items in the zero-state config file /home/tonton/source/ton/crypto/smartcont/gen-zerostate.fif

I made a copy and editted it (insert your own favourite editor):

vi /home/tonton/source/ton/crypto/smartcont/gen-zerostate.fif

The only change I made at this point was to let the config have only 1 validator.

tonton@ip-10-5-1-13:~/source/ton/crypto/smartcont$ sdiff -s gen-zerostate.fif gen-zerostate-singlevalidator.fif

// 9 4 1 config.validator_num! | 9 4 1 config.validator_num!

1000 100 5 config.validator_num! | // LEEBUG -- reduce size: 1000 100 5 config.validator_num!

2.3 Run create-state

tonton@ip-10-5-1-13:~/source/crypto$ ./create-state ../ton/crypto/smartcont/gen-zerostate-singlevalidator.fif

initial basechain state is:

x{9023AFE2FFFFFFEF0000000000800000000000000000000000000000005DB1B6910000000000000000FFFFFFFF2_}

x{00000000000000001_}

x{001_}

x{00000000000000000000000000000000000}

B5EE9C72E1010401005600667C84AC035B9023AFE2FFFFFFEF0000000000800000000000000000000000000000005DB1B6910000000000000000FFFFFFFF2001020300110000000000000000100003001000230000000000000000000000000000000000082D851E8E

(Initial basechain state saved to file basestate0.boc)

8< --------- lots of stuff ---------- >8

(Initial masterchain state saved to file zerostate.boc)

file hash= 9129E1F3206F1F8155E231116A65D8764F2EA9B9C832D37007D9952E0CBD82B5 kSnh8yBvH4FV4jERamXYdk8uqbnIMtNwB9mVLgy9grU=

root hash= 6B6C120D226E270A1102E056CEE871630F1FFD43E9D55B34216C771D0D9C8BC2 a2wSDSJuJwoRAuBWzuhxYw8f_UPp1Vs0IWx3HQ2ci8I=

Basestate0 root hash= E8F8D65BAB9DEE8D1F178CC0676BF7C5CFFB5D6652510BA8DEFAC76631003F88 6PjWW6ud7o0fF4zAZ2v3xc_7XWZSUQuo3vrHZjEAP4g=

Basestate0 file hash= CA2E690D917479CF8126751ED442D6927CC798D71352EAF30C404532BE1E06EF yi5pDZF0ec-BJnUe1ELWknzHmNcTUurzDEBFMr4eBu8=

Zerostate root hash= 6B6C120D226E270A1102E056CEE871630F1FFD43E9D55B34216C771D0D9C8BC2 a2wSDSJuJwoRAuBWzuhxYw8f_UPp1Vs0IWx3HQ2ci8I=

Zerostate file hash= 9129E1F3206F1F8155E231116A65D8764F2EA9B9C832D37007D9952E0CBD82B5 kSnh8yBvH4FV4jERamXYdk8uqbnIMtNwB9mVLgy9grU=

Move the artifacts to /var/ton-work/db/static (might have to create the static dir first)

mv basestate0.boc zerostate.boc /var/ton-work/db/static/

2.4 Rename zero-state artifacts

Inside the static directory, rename the new files to be the same as the sha256 of the file contents.

tonton@ip-10-5-1-13:/var/ton

basestate0.boc zerostate.boc

tonton@ip-10-5-1-13:/var/ton-work/db/static$ sha256sum basestate0.boc

ca2e690d917479cf8126751ed442d6927cc798d71352eaf30c404532be1e06ef basestate0.boc

tonton@ip-10-5-1-13:/var/ton-work/db/static$ mv basestate0.boc ca2e690d917479cf8126751ed442d6927cc798d71352eaf30c404532be1e06ef

tonton@ip-10-5-1-13:/var/ton-work/db/static$ sha256sum zerostate.boc

9129e1f3206f1f8155e231116a65d8764f2ea9b9c832d37007d9952e0cbd82b5 zerostate.boc

tonton@ip-10-5-1-13:/var/ton-work/db/static$ mv zerostate.boc 9129e1f3206f1f8155e231116a65d8764f2ea9b9c832d37007d9952e0cbd82b5

3 – Adjust global config

Make a copy of /var/ton-work/etc/ton-global.config.json

Edit the new one. This should reflect our newer, stripped down configuration.

3.1 - Adjust k, a (writer’s note -- I have no idea what these values are. I’m guessing that they have something to do with the required number of nodes for running??)

"@type": "dht.config.global", 

"k": 2, 

"a": 1, 

As you can see I dropped them to 2 and 1

3.2 - Adjust the static dht entries

The regular global config has about 111 entries; we’ll take all but one out.

End up with:

{

"@type": "config.global",

"dht": {

"@type": "dht.config.global", 

"k": 2, 

"a": 1, 

"static_nodes": { 

  "@type": "dht.nodes", 

  "nodes": [ 

    { 

      "@type": "dht.node", 

      "id": { 

        "@type": "pub.ed25519", 

        "key": "kJQwsFgjfqx6KWUwz/R3KpcIsu647Pu9/yOdOg7zehY=" 

      }, 

      "addr_list": { 

        "@type": "adnl.addressList", 

        "addrs": [ 

          { 

            "@type": "adnl.address.udp", 

            "ip": 55716249, 

            "port": 4444 

          } 

        ], 

        "version": 0, 

        "reinit_date": 0, 

        "priority": 0, 

        "expire_at": 0 

      }, 

      "version": -1, 

      "signature": "9M8RgXWm//yQGfYc2fqTx+Vs5Jk12FtGrnqY27fLp3HM1Bscnt8Qxpdm7UpLfwC9DEbeh2kDnUA5gGKhbvClDA==" 

    } 

  ] 

} 

},

In here, I changed the ip to the decimal representation of my external IP.

I also changed the key to be the same as the public key entry in config.json.

leedioxin commented 4 years ago

I should probably point out too -- I didn't change the signature of the dht node in the global config. I wasn't sure what exactly to sign.

ton-blockchain commented 4 years ago

If you want to run only a single node for smart contract testing, test-ton-collator may be a better option.

leedioxin commented 4 years ago

I was hoping to be able to test the validator workflow, but I don't have enough test grams to do it in testnet.

I'll probably try the collator as an exercise, but I really was hoping for a validator node.

I'm guessing there are no guidelines for this kind of thing yet? I really was guessing that changing the global config would be the way to start off.

sorokinvld commented 4 years ago

@leedioxin could you share entire the doc of your steps, we're are trying to solve the same issue @ton-blockchain will you share any guide about this issue? test-givers are offline and we don't have idea how to test our ton-based solutions

leedioxin commented 4 years ago

@leedioxin could you share entire the doc of your steps, we're are trying to solve the same issue @ton-blockchain will you share any guide about this issue? test-givers are offline and we don't have idea how to test our ton-based solutions

Hey @sorokinvld -- in my initial question, I had listed out the steps that I had tried. In the meantime, I did learn of the existence of the script test/generate-test-node-config.py. I think we can scavenge some of that code to create the signatures needed to start up.

Also, there's a chance that my firewall rules are blocking some of the messaging needed between nodes. I haven't had a chance to verify this, but I did also notice some interesting issues when I was testing tonlib-cli that makes me think I'm blocking a port that may be needed.

sorokinvld commented 4 years ago

step /create-state ../../crypto/smartcont/gen-zerostate.fif returned

[ 1][t 0][1574337088.913357496][words.cpp:2916] gen-zerostate.fif:222: newdict: -? Error interpreting file../../crypto/smartcont/gen-zerostate.fif: [Error : 0 : error interpreting included filegen-zerostate.fif: gen-zerostate.fif:222: newdict: -?]

I ponted: export FIFTPATH=/root/ton/crypto/fift/lib/:/root/ton/crypto/smartcont/

@ton-blockchain even with orig gen-zerostate.fif error occurs

@leedioxin have you started your network?

akme commented 4 years ago

Getting the same error

step /create-state ../../crypto/smartcont/gen-zerostate.fif returned

[ 1][t 0][1574337088.913357496][words.cpp:2916] gen-zerostate.fif:222: newdict: -? Error interpreting file../../crypto/smartcont/gen-zerostate.fif: [Error : 0 : error interpreting included filegen-zerostate.fif: gen-zerostate.fif:222: newdict: -?]

leedioxin commented 4 years ago

step /create-state ../../crypto/smartcont/gen-zerostate.fif returned

[ 1][t 0][1574337088.913357496][words.cpp:2916] gen-zerostate.fif:222: newdict: -? Error interpreting file../../crypto/smartcont/gen-zerostate.fif: [Error : 0 : error interpreting included filegen-zerostate.fif: gen-zerostate.fif:222: newdict: -?]

I ponted: export FIFTPATH=/root/ton/crypto/fift/lib/:/root/ton/crypto/smartcont/

@ton-blockchain even with orig gen-zerostate.fif error occurs

@leedioxin have you started your network?

I've actually been redirected onto another activity. I haven't made any further progress on starting up the network.

akme commented 4 years ago

This should help https://github.com/ton-blockchain/ton/pull/191

akme commented 4 years ago

To get signature you need to use generate-random-id like this:

$ utils/generate-random-id -m dht -n dht -a '{
>             "@type": "adnl.addressList",
>             "addrs": [
>               {
>                 "@type": "adnl.address.udp",
>                 "ip": -1057912003,
>                 "port": 6302
>               }
>             ],
>             "version": 0,
>             "reinit_date": 0,
>             "priority": 0,
>             "expire_at": 0
>           }'
{"@type":"dht.node","id":{"@type":"pub.ed25519","key":"kUeAmGCk6hBpumRj5BITGDFUTvu6FVCXwi0ZMZ2Lroo="},"addr_list":{"@type":"adnl.addressList","addrs":[{"@type":"adnl.address.udp","ip":-1057912003,"port":6302}],"version":0,"reinit_date":0,"priority":0,"expire_at":0},"version":-1,"signature":"Q64uQUyQ28fzPvuJCBq6ql97Qg563vdpJhLOcu+hP/OlyeQvkD5P+a0kk7sNXajrAJTsX6sSbKknuF/C78NaBA=="}
sorokinvld commented 4 years ago

@akme thanks, it works! do you have further steps of starting own network? how should I generate keys for initial wallets as in zerostate:

// pubkey amountcreate-wallet1or pubkey amountcreate-wallet2 PK'PuZPPXK5Rff9SvtoS7Y9lUuEixvy-J6aishYFj3Qn6P0pJMb GR$100 create-wallet1 PK'PuYiB1zAWzr4p8j6I681+sGUrRGcn6Ylf7vXl0xaUl/w6Xfg GR$170 create-wallet0

I've done: crypto/fift -I <source-dir>/crypto/fift/lib:<source-dir>/crypto/smartcont -s new-wallet.fif -1 my_wallet_id

but It returned: [ 1][t 0][1574406945.983657360][words.cpp:2916] gen-zerostate.fif:239: PK': invalid tag in public key Error interpreting file../../crypto/smartcont/gen-zerostate.fif: [Error : 0 : error interpreting included filegen-zerostate.fif: gen-zerostate.fif:239: PK': invalid tag in public key]

what values a,k for?

akme commented 4 years ago

I still can't get it running, because of errors in ton-global.config that I made...

akme commented 4 years ago

[ 1][t 1][1574412880.317345381][validator-engine.cpp:2777][!validator-engine] failed to load global config'ton-global.config.json': [Error : 0 : json does not fit TL scheme: Wrong character in the string] I think it says about root_hash and file_hash, but I don't know how to fix this yet

EmelyanenkoK commented 2 years ago

MyLocalTON devoted solves this task.