Skip to content

Commit

Permalink
supported cosmos, compile time flags for two execs
Browse files Browse the repository at this point in the history
  • Loading branch information
root committed Dec 21, 2020
1 parent 4c85636 commit 60a68e6
Show file tree
Hide file tree
Showing 23 changed files with 247 additions and 103 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ PROTOLOC=protocols/tmDataTransferProtocolv1
GO=go
GOBUILD=$(GO) build
BINDIR=build
BINCLI=tendermint_connector
BIN=$(BINDIR)/$(BINCLI)
BINCLI=TendermintConnector
INSTALLLOC=/usr/local/bin/$(BINCLI)

all:
$(PROTOC) --go_out=. $(PROTOLOC)/*.proto
$(GOBUILD) -o $(BIN)
$(GOBUILD) -ldflags="-X github.com/supragya/TendermintConnector/cmd.compilationChain=iris -linkmode=external" -o $(BINDIR)/iris_connector
$(GOBUILD) -ldflags="-X github.com/supragya/TendermintConnector/cmd.compilationChain=cosmos -linkmode=external" -o $(BINDIR)/cosmos_connector

clean:
rm $(PROTOLOC)/*.go
Expand Down
40 changes: 20 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
Tendermint Connector is a bridging application required for Tendermint based blockchains to interface with Marlin Protocol. Tendermint Connector connects as a peer to already running TM based blockchain and retrieves / pushes selective messages that the peer needs from / to Marlin Relays. Tendermint Connector also doubles up as a spam checker machanism for marlin relay.

## Serviced Blockchains
Currently, the following blockchains are serviced by **tendermint_connector**:
Currently, the following blockchains are serviced by **TendermintConnector**:
1. Irisnet Mainnet 0.16.3
2. Cosmos-3 Mainnet (WIP)

Expand Down Expand Up @@ -35,7 +35,7 @@ Tendermint Connector runs in two different modes:
2. **SpamFilter mode**: Tendermint Connector acts as a spamfilter servicing application at marlin relay nodes and interacts with `tm_abci`. Relay operators would like to use this mode.

### marlinTo and marlinFrom
**marlinTo** and **marlinFrom** are two channels which act as a connecting buffer between the marlin side connector and peer side connector. Both of these are capable of holding upto 1000 messages in each direction and are supposed to make both sides (marlin side / peer side) be agnostic of wire protocols each of them use. In case of overflow, oldest messages are dropped and shown as warning by tendermint_connector.
**marlinTo** and **marlinFrom** are two channels which act as a connecting buffer between the marlin side connector and peer side connector. Both of these are capable of holding upto 1000 messages in each direction and are supposed to make both sides (marlin side / peer side) be agnostic of wire protocols each of them use. In case of overflow, oldest messages are dropped and shown as warning by TendermintConnector.

### Selecting a Peer Side Connector
Tendermint Connector aims to provide support for many tendermint based blockchains. Consequently, there needs to be quite similar however different peer side connectors that are engineered to support a specific blockchain.
Expand All @@ -60,45 +60,45 @@ Tendermint Connector's marlin side connectivity is not always TCP. While in "dat


## Running the application
The tendermint_connector application provides the following features:
The TendermintConnector application provides the following features:
1. Full CLI interface (POSIX style flags)
2. Automatic Blockchain detection based on Node Info of peer (RPC access to real TMCore required)
3. Secured On the fly ED25519 key pair generation and handshake for every session in peerdial

For finding version info of the application, supported chains and supported encodings for marlin relay, run:
```
tendermint_connector --version
TendermintConnector --version
```

This should return you information such as this:
```
tendermint_connector version 0.1-rc-1
TendermintConnector version 0.1-rc-1
+ [Tendermint Chain] IRISNet Mainnet 0.16.3 (Consensus State transfers) v0.1
+ [Marlin TM Protocol] Marlin Tendermint Data Transfer Protocol v1
```

### tendermint_connector as a dataconnector between TMCore and Marlin Relay
### TendermintConnector as a dataconnector between TMCore and Marlin Relay
```
tendermint_connector dataconnect --dial
TendermintConnector dataconnect --dial
```
Tendermint connector will automatically try to connect using the default parameters.

You can learn more about the *tendermint_connector connect* command using `tendermint_connector connect -h`.
You can learn more about the *TendermintConnector connect* command using `TendermintConnector connect -h`.

For configuring any of this for runtime, the following can be used for changed params:
```
tendermint_connector --server_address 127.0.0.2 --rpc_port 21222
TendermintConnector --server_address 127.0.0.2 --rpc_port 21222
```

### tendermint_connector keyfiles for persistent peer connection between TMCore and tendermint_connector
### TendermintConnector keyfiles for persistent peer connection between TMCore and TendermintConnector
```
tendermint_connector keyfile
TendermintConnector keyfile
```
Tendermint connector can act as a tendermint peer who listens for connections instead of dialing TMCore itself. For this, you may need a persistent node ID to put in `config.toml` file for your real tendermint node. This is of format: *ae239af43..9bd7@127.0.0.1:266657*. This is essentially **nodeID@IP:PORT**. A keyfile for tendermint_connector is a file which describes the nodeID for tendermint_connector to use across process runs; it provides tendermint_connector with keys for fulfilling it's job as the given nodeID.
Tendermint connector can act as a tendermint peer who listens for connections instead of dialing TMCore itself. For this, you may need a persistent node ID to put in `config.toml` file for your real tendermint node. This is of format: *ae239af43..9bd7@127.0.0.1:266657*. This is essentially **nodeID@IP:PORT**. A keyfile for TendermintConnector is a file which describes the nodeID for TendermintConnector to use across process runs; it provides TendermintConnector with keys for fulfilling it's job as the given nodeID.

For example, you can generate a keyfile for irisnet chain using the following command:
```
tendermint_connector keyfile --chain irisnet --filelocation irisnetkeys.json --generate
TendermintConnector keyfile --chain irisnet --filelocation irisnetkeys.json --generate
```

This would return logs similar to below:
Expand All @@ -110,25 +110,25 @@ This would return logs similar to below:

This would create a new file `irisnetkeys.json` which contains keys relevant to peer nodeID `376378adce3c6e3fde8201a4926b4adae6cb72e0`. You can now put `376378adce3c6e3fde8201a4926b4adae6cb72e0@127.0.0.1:59001` (for localhost) as a persistent peer of your real tendermint node by editing your *config.toml* or passing peer as a command line argument.

Subsequent runs of `tendermint_connector connect` would require this keyfile to be provided to the program using command such as follows:
Subsequent runs of `TendermintConnector connect` would require this keyfile to be provided to the program using command such as follows:
```
tendermint_connector connect --keyfile irisnetkeys.json
TendermintConnector connect --keyfile irisnetkeys.json
```

You may wish to verify the integrity of generated keyfiles. This can be done by simply (no `--generate` flag):
```
tendermint_connector keyfile --keyfile irisnetkeys.json --chain irisnet
TendermintConnector keyfile --keyfile irisnetkeys.json --chain irisnet
```

### tendermint_connector as a spamfilter for Marlin Relay
### TendermintConnector as a spamfilter for Marlin Relay
```
tendermint_connector spamfilter
TendermintConnector spamfilter
```
Tendermint connector will run as a spam filter endpoint for verifying messages recieved at any relay endpoint. The expected format of message in spamfilter mode is proto3 encoded Marlin Tendermint Data Transfer Protocol messages. Spamfilter replies with a single byte (0 or 1) for whether message is spam (0), hence to be blocked or not (1), hence to be allowed.

You can learn more about the *tendermint_connector spamfilter* command using `tendermint_connector spamfilter -h`.
You can learn more about the *TendermintConnector spamfilter* command using `TendermintConnector spamfilter -h`.

For configuring any of this for runtime, the following can be used for changed params:
```
tendermint_connector spamfilter --peerip 127.0.0.2 --rpcport 26667
TendermintConnector spamfilter --peerip 127.0.0.2 --rpcport 26667
```
4 changes: 2 additions & 2 deletions chains/cosmos/conn/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
"sync/atomic"
"time"

cmn "github.com/supragya/tendermint_connector/chains/irisnet/libs/common"
flow "github.com/supragya/tendermint_connector/chains/irisnet/libs/flowrate"
cmn "github.com/supragya/TendermintConnector/chains/irisnet/libs/common"
flow "github.com/supragya/TendermintConnector/chains/irisnet/libs/flowrate"
amino "github.com/tendermint/go-amino"
"github.com/tendermint/tendermint/libs/log"
)
Expand Down
2 changes: 1 addition & 1 deletion chains/cosmos/conn/secret_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"golang.org/x/crypto/nacl/box"

pool "github.com/libp2p/go-buffer-pool"
cmn "github.com/supragya/tendermint_connector/chains/irisnet/libs/common"
cmn "github.com/supragya/TendermintConnector/chains/irisnet/libs/common"
"github.com/tendermint/tendermint/crypto"
"golang.org/x/crypto/hkdf"
)
Expand Down
14 changes: 7 additions & 7 deletions chains/cosmos/handlerCosmos.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ import (

log "github.com/sirupsen/logrus"
"github.com/hashicorp/golang-lru"
"github.com/supragya/tendermint_connector/chains"
"github.com/supragya/tendermint_connector/chains/cosmos/conn"
cmn "github.com/supragya/tendermint_connector/chains/cosmos/libs/common"
flow "github.com/supragya/tendermint_connector/chains/cosmos/libs/flowrate"
marlinTypes "github.com/supragya/tendermint_connector/types"
"github.com/supragya/TendermintConnector/chains"
"github.com/supragya/TendermintConnector/chains/cosmos/conn"
cmn "github.com/supragya/TendermintConnector/chains/cosmos/libs/common"
flow "github.com/supragya/TendermintConnector/chains/cosmos/libs/flowrate"
marlinTypes "github.com/supragya/TendermintConnector/types"
amino "github.com/tendermint/go-amino"
"github.com/tendermint/tendermint/crypto/ed25519"

// Protocols
"github.com/supragya/tendermint_connector/marlin"
"github.com/supragya/TendermintConnector/marlin"
)

// ServicedTMCore is a string associated with each TM core handler
Expand Down Expand Up @@ -924,7 +924,7 @@ func VerifyKeyFile(fileLocation string) (bool, error) {
json.Unmarshal(byteValue, &key)

// TODO Check these conditions, add more checks - v0.2 prerelease
if string(hex.EncodeToString(key.PrivateKey[:])) == key.PrivateKeyString {
if key.Chain == "cosmos-3-mainnet" && string(hex.EncodeToString(key.PrivateKey[:])) == key.PrivateKeyString {
log.Info("Integrity for KeyFile: ", fileLocation, " checked. Integrity OK.")
return true, nil
} else {
Expand Down
4 changes: 2 additions & 2 deletions chains/cosmos/structsMarlin.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
amino "github.com/tendermint/go-amino"
lru "github.com/hashicorp/golang-lru"
"github.com/tendermint/tendermint/crypto/ed25519"
"github.com/supragya/tendermint_connector/chains/cosmos/conn"
marlinTypes "github.com/supragya/tendermint_connector/types"
"github.com/supragya/TendermintConnector/chains/cosmos/conn"
marlinTypes "github.com/supragya/TendermintConnector/types"
)

type TendermintHandler struct {
Expand Down
4 changes: 2 additions & 2 deletions chains/cosmos/structsTendermint.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"errors"

amino "github.com/tendermint/go-amino"
cmn "github.com/supragya/tendermint_connector/chains/cosmos/libs/common"
flow "github.com/supragya/tendermint_connector/chains/cosmos/libs/flowrate"
cmn "github.com/supragya/TendermintConnector/chains/cosmos/libs/common"
flow "github.com/supragya/TendermintConnector/chains/cosmos/libs/flowrate"
"github.com/tendermint/tendermint/crypto/merkle"
)

Expand Down
4 changes: 2 additions & 2 deletions chains/irisnet/conn/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
"sync/atomic"
"time"

cmn "github.com/supragya/tendermint_connector/chains/irisnet/libs/common"
flow "github.com/supragya/tendermint_connector/chains/irisnet/libs/flowrate"
cmn "github.com/supragya/TendermintConnector/chains/irisnet/libs/common"
flow "github.com/supragya/TendermintConnector/chains/irisnet/libs/flowrate"
amino "github.com/tendermint/go-amino"
"github.com/tendermint/tendermint/libs/log"
)
Expand Down
2 changes: 1 addition & 1 deletion chains/irisnet/conn/secret_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"golang.org/x/crypto/nacl/box"

pool "github.com/libp2p/go-buffer-pool"
cmn "github.com/supragya/tendermint_connector/chains/irisnet/libs/common"
cmn "github.com/supragya/TendermintConnector/chains/irisnet/libs/common"
"github.com/tendermint/tendermint/crypto"
"golang.org/x/crypto/hkdf"
)
Expand Down
14 changes: 7 additions & 7 deletions chains/irisnet/handlerIrisnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ import (

log "github.com/sirupsen/logrus"
"github.com/hashicorp/golang-lru"
"github.com/supragya/tendermint_connector/chains"
"github.com/supragya/tendermint_connector/chains/irisnet/conn"
cmn "github.com/supragya/tendermint_connector/chains/irisnet/libs/common"
flow "github.com/supragya/tendermint_connector/chains/irisnet/libs/flowrate"
marlinTypes "github.com/supragya/tendermint_connector/types"
"github.com/supragya/TendermintConnector/chains"
"github.com/supragya/TendermintConnector/chains/irisnet/conn"
cmn "github.com/supragya/TendermintConnector/chains/irisnet/libs/common"
flow "github.com/supragya/TendermintConnector/chains/irisnet/libs/flowrate"
marlinTypes "github.com/supragya/TendermintConnector/types"
amino "github.com/tendermint/go-amino"
"github.com/tendermint/tendermint/crypto/ed25519"

// Protocols
"github.com/supragya/tendermint_connector/marlin"
"github.com/supragya/TendermintConnector/marlin"
)

// ServicedTMCore is a string associated with each TM core handler
Expand Down Expand Up @@ -924,7 +924,7 @@ func VerifyKeyFile(fileLocation string) (bool, error) {
json.Unmarshal(byteValue, &key)

// TODO Check these conditions, add more checks - v0.2 prerelease
if string(hex.EncodeToString(key.PrivateKey[:])) == key.PrivateKeyString {
if key.Chain == "irisnet-0.16.3-mainnet" && string(hex.EncodeToString(key.PrivateKey[:])) == key.PrivateKeyString {
log.Info("Integrity for KeyFile: ", fileLocation, " checked. Integrity OK.")
return true, nil
} else {
Expand Down
4 changes: 2 additions & 2 deletions chains/irisnet/structsMarlin.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
amino "github.com/tendermint/go-amino"
lru "github.com/hashicorp/golang-lru"
"github.com/tendermint/tendermint/crypto/ed25519"
"github.com/supragya/tendermint_connector/chains/irisnet/conn"
marlinTypes "github.com/supragya/tendermint_connector/types"
"github.com/supragya/TendermintConnector/chains/irisnet/conn"
marlinTypes "github.com/supragya/TendermintConnector/types"
)

type TendermintHandler struct {
Expand Down
4 changes: 2 additions & 2 deletions chains/irisnet/structsTendermint.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"errors"

amino "github.com/tendermint/go-amino"
cmn "github.com/supragya/tendermint_connector/chains/irisnet/libs/common"
flow "github.com/supragya/tendermint_connector/chains/irisnet/libs/flowrate"
cmn "github.com/supragya/TendermintConnector/chains/irisnet/libs/common"
flow "github.com/supragya/TendermintConnector/chains/irisnet/libs/flowrate"
"github.com/tendermint/tendermint/crypto/merkle"
)

Expand Down
10 changes: 5 additions & 5 deletions cmd/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ import (
"net/http"

log "github.com/sirupsen/logrus"
marlinTypes "github.com/supragya/tendermint_connector/types"
marlinTypes "github.com/supragya/TendermintConnector/types"

// Tendermint Core Chains
"github.com/supragya/tendermint_connector/chains"
"github.com/supragya/tendermint_connector/chains/irisnet"
"github.com/supragya/tendermint_connector/chains/cosmos"
"github.com/supragya/TendermintConnector/chains"
"github.com/supragya/TendermintConnector/chains/irisnet"
"github.com/supragya/TendermintConnector/chains/cosmos"
)

var peerPort, rpcPort, marlinPort, listenPortPeer int
var peerIP, marlinIP, keyFile, chain, fileLocation, marlinUdsFile string
var isConnectionOutgoing, isGenerate, isMarlinconnectionOutgoing bool
var isConnectionOutgoing, isGenerate, isMarlinconnectionOutgoing, doRpcSanity bool

func getRPCNodeStatus(rpcAddr string) (map[string]interface{}, error) {
log.Info("Retrieving Information from RPC server")
Expand Down
Loading

0 comments on commit 60a68e6

Please sign in to comment.