planetarium / planet-node

A simple node implementation using Libplanet
GNU Affero General Public License v3.0
7 stars 13 forks source link

Write docs on how to communicate between multiple nodes #36

Closed sensecodevalue closed 1 year ago

sensecodevalue commented 1 year ago

communicate between multiple nodes

Check before you begin

Please check the store address of root and peer before starting. PN_StorePath is the address of the store.

root node store path(PN_StorePath) : /tmp/planet-node-chain
peer node store path(PN_StorePath) : /tmp/planet-node-chain-a

1. Excute root peer node

$ PN_StorePath=/tmp/planet-node-chain dotnet run --project PlanetNode

2. Copy root chain for using same genesis block & Setting peer node chain

$ cp -r /tmp/planet-node-chain /tmp/planet-node-chain-a

If you want to know if they want to have the same hash, see the code below.


// /planet-node/Libplanet.Headless/Hosting/SwarmService.cs
protected override async Task ExecuteAsync(CancellationToken stoppingToken)

{

_ = swarm.WaitForRunningAsync().ContinueWith( =>

{

var peer = _swarm.AsPeer; var result = getPeerString(peer); Console.WriteLine("Genesis hash: {0}", _swarm.BlockChain.Genesis.Hash); // use Console.WriteLine });

await _swarm.AddPeersAsync(_peers, default, cancellationToken: stoppingToken).ConfigureAwait(false); await _swarm.PreloadAsync(cancellationToken: stoppingToken).ConfigureAwait(false); await _swarm.StartAsync(cancellationToken: stoppingToken).ConfigureAwait(false); }

### 2. Copy `peerString` of root peer node & Paste to `PeerStrings` of `appsettings.peer.json`

**Requesting a query through root node of you can see peerstring**  
>rootNode GraphQL query | http://localhost:308080/ui/playground
```graphql
query{
  application {
    peerString
  }
}
//ex) query result
{
  "data": {
    "application": {
      "peerString": "034f11693177d1a3d7a20c10cf064fd89f82592cd8fd2b25bc8af2855878e831b9,localhost,31234."
    }
  }
}

When copying, exclude the last (.)
X - 034f11693177d1a3d7a20c10cf064fd89f82592cd8fd2b25bc8af2855878e831b9,localhost,31234.
O - 034f11693177d1a3d7a20c10cf064fd89f82592cd8fd2b25bc8af2855878e831b9,localhost,31234

// appsettings.peer.json
{
 ...
 "PeerStrings": ["034f11693177d1a3d7a20c10cf064fd89f82592cd8fd2b25bc8af2855878e831b9,localhost,31234"],
}

3. Excute peer node

$ PN_StorePath=/tmp/planet-node-chain-a PN_CONFIG_FILE=appsettings.peer.json  dotnet run --project PlanetNode

4. Create transaction in peer node & Check at root node

$ dotnet run --project PlanetNode -- key

#Key ID                               Address                                   
#------------------------------------ ------------------------------------------
#b53ba868-4749-49d3-b2aa-2433a507370b 0x50129015Fa9F02AE2db055d4C675E42f5Ec82066
#62ca49b2-999b-4459-a9a9-6fb64317864c 0xBc35F4797514e6f13736e6C6777BAea4764B0526
#9f5a70fd-b9b2-415f-8ff2-eb64cc7629f7 0x917955C717b82801479e43732BD9b3c6710e5000
#66aa63b4-048a-43f7-a747-e769bf861f36 0xBd04842e6Bee1b6399F143D2CeB65EAE8f7ee453

$ dotnet run --project PlanetNode -- key export 62ca49b2-999b-4459-a9a9-6fb64317864c

#Passphrase (of 62ca49b2-999b-4459-a9a9-6fb64317864c): 
#543140f03e7294eea41c67efbcca6f20c2f557e0a6101f8a6935ffc0aec9bcae

peerNode GraphQL Mutation | http://localhost:308081/ui/playground

mutation
{
transferAsset(
recipient: "917955C717b82801479e43732BD9b3c6710e5000"
amount: "50"
privateKeyHex: "543140f03e7294eea41c67efbcca6f20c2f557e0a6101f8a6935ffc0aec9bcae"
)
{
id
}
}
// ex) mutation result
{
"data": {
"transferAsset": {
"id": "d9a5d7638350f3b38cde81772f7bf147ac67a73b20893922ae89ddaeb52c246f"
}
}
}

rootNode GraphQL Query | http://localhost:308080/ui/playground

query
{
explorer
{
transactionQuery
{
transactionResult (txId:"d9a5d7638350f3b38cde81772f7bf147ac67a73b20893922ae89ddaeb52c246f")
{
txStatus
blockIndex
blockHash
}
}
}
}
// ex) query result
{
"data": {
"explorer": {
"transactionQuery": {
"transactionResult": {
"txStatus": "SUCCESS",
"blockIndex": 1554,
"blockHash": "4ecdb169992d8c15522845fd08368d32273042726ad83f8de70050d24404fbfe"
}
}
}
}
}

closed #8

pull-request-quantifier-deprecated[bot] commented 1 year ago

This PR has 103 quantified lines of changes. In general, a change size of upto 200 lines is ideal for the best PR experience!


Quantification details

``` Label : Medium Size : +103 -0 Percentile : 40.6% Total files changed: 1 Change summary by file extension: .md : +103 -0 ``` > Change counts above are quantified counts, based on the [PullRequestQuantifier customizations](https://github.com/microsoft/PullRequestQuantifier/blob/main/docs/prquantifier-yaml.md).

Why proper sizing of changes matters

Optimal pull request sizes drive a better predictable PR flow as they strike a balance between between PR complexity and PR review overhead. PRs within the optimal size (typical small, or medium sized PRs) mean: - Fast and predictable releases to production: - Optimal size changes are more likely to be reviewed faster with fewer iterations. - Similarity in low PR complexity drives similar review times. - Review quality is likely higher as complexity is lower: - Bugs are more likely to be detected. - Code inconsistencies are more likely to be detected. - Knowledge sharing is improved within the participants: - Small portions can be assimilated better. - Better engineering practices are exercised: - Solving big problems by dividing them in well contained, smaller problems. - Exercising separation of concerns within the code changes. #### What can I do to optimize my changes - Use the PullRequestQuantifier to quantify your PR accurately - Create a context profile for your repo using the [context generator](https://github.com/microsoft/PullRequestQuantifier/releases) - Exclude files that are not necessary to be reviewed or do not increase the review complexity. Example: Autogenerated code, docs, project IDE setting files, binaries, etc. Check out the `Excluded` section from your `prquantifier.yaml` context profile. - Understand your typical change complexity, drive towards the desired complexity by adjusting the label mapping in your `prquantifier.yaml` context profile. - Only use the labels that matter to you, [see context specification](./docs/prquantifier-yaml.md) to customize your `prquantifier.yaml` context profile. - Change your engineering behaviors - For PRs that fall outside of the desired spectrum, review the details and check if: - Your PR could be split in smaller, self-contained PRs instead - Your PR only solves one particular issue. (For example, don't refactor and code new features in the same PR). #### How to interpret the change counts in git diff output - One line was added: `+1 -0` - One line was deleted: `+0 -1` - One line was modified: `+1 -1` (git diff doesn't know about modified, it will interpret that line like one addition plus one deletion) - Change percentiles: Change characteristics (addition, deletion, modification) of this PR in relation to all other PRs within the repository.


Was this comment helpful? :thumbsup:  :ok_hand:  :thumbsdown: (Email) Customize PullRequestQuantifier for this repository.

dahlia commented 1 year ago

Good job!