# Substrate and Gossamer nodes
## Tasks
1. Modify gossamer genesis with 3 grandpa and babe authorities and run 2 nodes (Alice and Bob).
2. Run substrate and gossamer node with modified gssmr genesis. Run libp2p logs to see what is happening.
-------
1. On running 2 gossamer nodes (Alice and Bob node)
#### Alice Node command
```bash=
./bin/gossamer --chain gssmr init --config ~/go/src/github.com/ChainSafe/gossamer/tests/utils/config_default.toml --basepath /tmp/TestSync_ManyProducers/alice --genesis ~/go/src/github.com/ChainSafe/gossamer/chain/gssmr/genesis.json --force
./bin/gossamer --chain gssmr --port 7000 --log debug --config ~/go/src/github.com/ChainSafe/gossamer/tests/utils/config_default.toml --basepath /tmp/TestSync_ManyProducers/alice --rpchost localhost --rpcport 8540 --rpcmods system,author,chain,state,dev,rpc --rpc --log info --roles 4 --key alice --wsport 9591 --ws
```
#### Bob Node command
```bash=
./bin/gossamer --chain gssmr init --config ~/go/src/github.com/ChainSafe/gossamer/tests/utils/config_default.toml --basepath /tmp/TestSync_ManyProducers/bob --genesis ~/go/src/github.com/ChainSafe/gossamer/chain/gssmr/genesis.json --force
./bin/gossamer --chain gssmr --port 7001 --config ~/go/src/github.com/ChainSafe/gossamer/tests/utils/config_default.toml --basepath /tmp/TestSync_ManyProducers/bob --rpchost localhost --rpcport 8541 --rpcmods system,author,chain,state,dev,rpc --rpc --log info --roles 4 --key bob --wsport 9541 --ws
```
On running Alice node it is building blocks but not finalising. After running Bob node, Bob node synced created blocks by Alice and finalising the blocks.

2. Running 2 substrate nodes (Alice and Bob).
On Running Alice node alone, it is not producing blocks. On adding Bob node block production and syncing are working fine. But block finalise is not happening.
#### Alice Node command
```bash=
./target/release/substrate --base-path /tmp/alice --chain ./customSpecRaw.json --port 30333 --ws-port 9945 --rpc-port 9933 --validator --rpc-methods Unsafe --alice
```
#### Bob Node command
```bash=
./target/release/substrate --base-path /tmp/bob --chain ./customSpecRaw.json --port 30334 --ws-port 9946 --rpc-port 9934 --validator --rpc-methods Unsafe --bob
```
#### Charlie Node command
```bash=
./target/release/substrate --base-path /tmp/charlie --chain ./customSpecRaw.json --port 30335 --ws-port 9947 --rpc-port 9935 --validator --rpc-methods Unsafe --charlie -llibp2p=trace --log=debug --bootnodes /ip4/127.0.0.1/tcp/7000/p2p/12D3KooWB6VqqsnMohudX1EwyZiLhFNuwp4uh9r9c6o7LyuYMimR
```

3. On running 2 nodes, 1 for substarte and 1 for gossamer.
a. Without bootnodes, Gossamer is able to build blocks but substrate is neither creating nor syncing.

b. With boothnodes provided to the substrate it is erroring out in substrate node. This is triggering communication between node. But somehow substrate node is getting panicked. Below links are the logs with trace for network in gossamer and libp2p trace logs in substrate.
#### Alice Gossamer logs
https://drive.google.com/file/d/1lekkvHQgT4Phqv1B-KjQJorKoD4bMmFQ/view?usp=sharing
#### Bob Substrate logs
https://drive.google.com/file/d/1kC7saaUkDFfsFNUdSXO39sjZLQWzLBS2/view?usp=sharing
4. On running 3 nodes
a. With 3 nodes (2 substrate nodes and 1 gossamer node) without boot nodes provided, both substrate nodes are producing and syncing blocks between substrate nodes only. Gossamer node creating blocks but substrate and gossamer are unable to sync.

b. With 3 nodes (2 substrate nodes and 1 gossamer node) with boot nodes provided to substrate nodes for gossamer node, On running both substrate nodes first both are producing and syncing blocks between substrate nodes only. On adding the Gossamer node it is creating blocks but substrate and gossamer are unable to sync. After some time both substrate nodes are getting panicked.

#### Issues shows in substrate logs with these protocols.
1. /gossamer/gssmr/0/sync/2
2. /libp2p/simultaneous-connect (not present in above mentioned logs)
Substrate is getting panicked for /gossamer/gssmr/0/sync/2
tokio-runtime-worker multistream_select::listener_select: Listener: rejecting protocol: /gossamer/gssmr/0/sync/2
syncAtHead is responsible for triggering /gossamer/gssmr/0/sync/2 protocol.
syncAtHead pushing request for head, this will trigger processBlockRequests() -> trySync() -> syncwithpeers(), syncwithpeers() is making use of the protocol /gossamer/gssmr/0/sync/2
#### To print logs in substrate
flags: -llibp2p=trace --log=debug
```bash=
./target/release/substrate --base-path /tmp/bob --chain ./customSpecRaw.json --port 30334 --ws-port 9946 --rpc-port 9934 --validator --rpc-methods Unsafe --bob -llibp2p=trace --log=debug --bootnodes /ip4/127.0.0.1/tcp/7000/p2p/12D3KooWB6VqqsnMohudX1EwyZiLhFNuwp4uh9r9c6o7LyuYMimR
```
### Issue detected
Substrate itself adding '/' as prefix and substrate was expecting "//gossamer/gssmr/0" protocol id for sync. thats why it was failing.
`"protocolId": "/gossamer/gssmr/0"`
After updating genesis for substrate to ``"protocolId": "gossamer/gssmr/0"``, its working fine now. In gossamer genesis use `"protocolId": "/gossamer/gssmr/0"`
Observation
1. 2 nodes 2 substrate done
2. 2 nodes 2 gossamer nodes
3. 1 gossamer 1 substrate node (block build, sync and finalisation)
a. without bootnodes provided
b. with bootnode provided
4. 3 nodes, 1 substrate, 2 gossamer
a. making substrate non authority node and gossamers authority nodes
Block production in gossamer and finalisation are working. on adding substrate node with bootnodes peers are getting connected but substrate node is not syncing gossamer nodes blocks.
### Commands for alice, bob and chearlie nodes.
```bash=
./bin/gossamer --chain gssmr --port 7000 --log debug --config /Users/arijitdas/go/src/github.com/ChainSafe/gossamer/tests/utils/config_default.toml --basepath /tmp/TestSync_ManyProducers/alice --rpchost localhost --rpcport 8540 --rpcmods system,author,chain,state,dev,rpc --rpc --log info --roles 4 --key alice --wsport 9591 --ws
./bin/gossamer --chain gssmr --port 7001 --config /Users/arijitdas/go/src/github.com/ChainSafe/gossamer/tests/utils/config_default.toml --basepath /tmp/TestSync_ManyProducers/bob --rpchost localhost --rpcport 8541 --rpcmods system,author,chain,state,dev,rpc --rpc --log info --roles 4 --key bob --wsport 9541 --ws
./target/release/substrate --base-path /tmp/charlie --chain ./customSpecRaw.json --port 30335 --ws-port 9947 --rpc-port 9935 --rpc-methods Unsafe --name Charlie --bootnodes /ip4/127.0.0.1/tcp/7000/p2p/12D3KooWB6VqqsnMohudX1EwyZiLhFNuwp4uh9r9c6o7LyuYMimR
```

On running Alice gossamer node and Bob substrate node, both nodes creating and syncing blocks. On starting charlie gossamer node after block no. 20. The block finalisation started on both gossamer nodes and finalised the block till 20. But substrate node didn't synced finalisation no and showing 0 finalised blocks. The Alice gossamer node and bob substrate node was in sync till block no. 50 and had same block hash. Both nodes stopped here building blocks and syncing blocks. But charlie gossamer node still creating blocks finalisation of block stopped at 20.

6. 3 nodes, 2 substrate, 1 gossamer
