Skip to content

Commit

Permalink
Merge pull request #34 from persistenceOne/avkr003/v0.5.0
Browse files Browse the repository at this point in the history
For v0.5.0
  • Loading branch information
Deepanshu Tripathi authored Sep 20, 2021
2 parents 9800582 + c7ae38e commit 20dc70e
Show file tree
Hide file tree
Showing 48 changed files with 897 additions and 1,085 deletions.
13 changes: 13 additions & 0 deletions .run/first start.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="first start" type="GoApplicationRunConfiguration" factoryName="Go Application">
<module name="persistenceBridge" />
<working_directory value="$PROJECT_DIR$" />
<parameters value="start --ethStart 1 --tmStart 1" />
<kind value="DIRECTORY" />
<package value="github.com/persistenceOne/persistenceBridge/" />
<directory value="$PROJECT_DIR$/orchestrator" />
<filePath value="$PROJECT_DIR$/../persistenceBridge|$PROJECT_DIR$/orchestrator/main.go|$PROJECT_DIR$/orchestrator/main.go" />
<option name="build_on_remote_target" value="true" />
<method v="2" />
</configuration>
</component>
13 changes: 13 additions & 0 deletions .run/init.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="init" type="GoApplicationRunConfiguration" factoryName="Go Application">
<module name="persistenceBridge" />
<working_directory value="$PROJECT_DIR$" />
<parameters value="init" />
<kind value="DIRECTORY" />
<package value="github.com/persistenceOne/persistenceBridge/" />
<directory value="$PROJECT_DIR$/orchestrator" />
<filePath value="$PROJECT_DIR$/../persistenceBridge|$PROJECT_DIR$/orchestrator/main.go|$PROJECT_DIR$/orchestrator/main.go" />
<option name="build_on_remote_target" value="true" />
<method v="2" />
</configuration>
</component>
13 changes: 13 additions & 0 deletions .run/start.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="start" type="GoApplicationRunConfiguration" factoryName="Go Application">
<module name="persistenceBridge" />
<working_directory value="$PROJECT_DIR$" />
<parameters value="start" />
<kind value="DIRECTORY" />
<package value="github.com/persistenceOne/persistenceBridge/" />
<directory value="$PROJECT_DIR$/orchestrator" />
<filePath value="$PROJECT_DIR$/../persistenceBridge|$PROJECT_DIR$/orchestrator/main.go|$PROJECT_DIR$/orchestrator/main.go" />
<option name="build_on_remote_target" value="true" />
<method v="2" />
</configuration>
</component>
2 changes: 1 addition & 1 deletion .script/compileSC.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ solc --abi --bin contracts/LiquidStaking.sol -o build
abigen --bin ./build/LiquidStaking.bin --abi ./build/LiquidStaking.abi --pkg=liquidStaking --out=liquidStaking.go

solc --abi --bin contracts/TokenWrapper.sol -o build --overwrite
abigen --bin ./build/TokenWrapper.bin --abi ./build/TokenWrapper.abi --pkg=tokenWrapper --out=tokenWrapper.go
abigen --bin ./build/TokenWrapper.bin --abi ./build/TokenWrapper.abi --pkg=tokenWrapper --out=TokenWrapper.go
80 changes: 1 addition & 79 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,9 @@ export GO111MODULE=on
VERSION := $(shell echo $(shell git describe --tags) | sed 's/^v//')
TM_VERSION := $(shell go list -m github.com/tendermint/tendermint | sed 's:.* ::')
COMMIT := $(shell git rev-parse --short HEAD)
LEDGER_ENABLED ?= true
include sims.mk

build_tags = netgo

ifeq ($(LEDGER_ENABLED),true)
ifeq ($(OS),Windows_NT)
GCCEXE = $(shell where gcc.exe 2> NUL)
ifeq ($(GCCEXE),)
$(error gcc.exe not installed for ledger support, please install or set LEDGER_ENABLED=false)
else
build_tags += ledger
endif
else
UNAME_S = $(shell uname -s)
ifeq ($(UNAME_S),OpenBSD)
$(warning OpenBSD detected, disabling ledger support (https://github.com/cosmos/cosmos-sdk/issues/1988))
else
GCC = $(shell command -v gcc 2> /dev/null)
ifeq ($(GCC),)
$(error gcc not installed for ledger support, please install or set LEDGER_ENABLED=false)
else
build_tags += ledger
endif
endif
endif
endif

build_tags += $(BUILD_TAGS)
build_tags := $(strip $(build_tags))

Expand Down Expand Up @@ -61,17 +36,9 @@ GOBIN = $(shell go env GOPATH)/bin
GOARCH = $(shell go env GOARCH)
GOOS = $(shell go env GOOS)

# Docker variables
DOCKER := $(shell which docker)

DOCKER_IMAGE_NAME = persistenceone/persistenceBridge
DOCKER_TAG_NAME = latest
DOCKER_CONTAINER_NAME = persistence-core-container
DOCKER_CMD ?= "/bin/sh"

.PHONY: all install build verify

all: verify build
all: verify install

install:
ifeq (${OS},Windows_NT)
Expand Down Expand Up @@ -104,48 +71,3 @@ else
endif


clean:
rm -rf build release

proto-gen:
@echo "Generating Protobuf files"
$(DOCKER) run --rm -v $(shell go list -f "{{ .Dir }}" \
-m github.com/cosmos/cosmos-sdk):/workspace/cosmos_sdk_dir\
--env COSMOS_SDK_DIR=/workspace/cosmos_sdk_dir \
-v $(CURDIR):/workspace --workdir /workspace \
tendermintdev/sdk-proto-gen sh ./.script/protocgen.sh


# Commands for running docker
#
# Run persistenceBridge on docker
# Example Usage:
# make docker-build ## Builds persistenceBridge binary in 2 stages, 1st builder 2nd Runner
# Final image only has the compiled persistenceBridge binary
# make docker-interactive ## Will start an shell session into the docker container
# Access to persistenceBridge binary here
# NOTE: To be used for testing only, since the container will be removed after stopping
# make docker-run DOCKER_CMD=sleep 10000000 DOCKER_OPTS=-d ## Will run the container in the background
# NOTE: Recommeded to use docker commands directly for long running processes
# make docker-clean # Will clean up the running container, as well as delete the image
# after one is done testing
docker-build:
${DOCKER} build -t ${DOCKER_IMAGE_NAME}:${DOCKER_TAG_NAME} .

docker-build-push: docker-build
${DOCKER} push ${DOCKER_IMAGE_NAME}:${DOCKER_TAG_NAME}

docker-run:
${DOCKER} run ${DOCKER_OPTS} --name=${DOCKER_CONTAINER_NAME} ${DOCKER_IMAGE_NAME}:${DOCKER_TAG_NAME} ${DOCKER_CMD}

docker-interactive:
${MAKE} docker-run DOCKER_CMD=/bin/sh DOCKER_OPTS=--rm --it

docker-clean-container:
-${DOCKER} stop ${DOCKER_CONTAINER_NAME}
-${DOCKER} rm ${DOCKER_CONTAINER_NAME}

docker-clean-image:
-${DOCKER} rmi ${DOCKER_IMAGE_NAME}:${DOCKER_TAG_NAME}

docker-clean: docker-clean-container docker-clean-image
57 changes: 34 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
# persistenceBridge

This project implements an application for the Persistence Bridge Orchestrator that listens to, verifies, transforms and relays transactions between a Cosmos-SDK chain and ethereum.
This project implements an application for the Persistence Bridge Orchestrator that listens to, verifies, transforms and
relays transactions between a Cosmos-SDK chain and ethereum.

## Talk to us!
* [Twitter](https://twitter.com/PersistenceOne)
* [Telegram](https://t.me/PersistenceOneChat)
* [Discord](https://discord.com/channels/796174129077813248)

## Hardware Requirements
* [Twitter](https://twitter.com/PersistenceOne)
* [Telegram](https://t.me/PersistenceOneChat)
* [Discord](https://discord.com/channels/796174129077813248)

## Hardware Requirements

* **Minimal**
* 1 GB RAM
* 25 GB HDD
Expand All @@ -20,49 +23,57 @@ This project implements an application for the Persistence Bridge Orchestrator t
> NOTE: SSDs have limited TBW before non-catastrophic data errors. Running a full node requires a TB+ writes per day, causing rapid deterioration of SSDs over HDDs of comparable quality.
## Operating System

* Linux/Windows/MacOS(x86)
* **Recommended**
* Linux(x86_64)

## Installation Steps
>Prerequisite: go1.15+ required. [ref](https://golang.org/doc/install)

>Prerequisite: git. [ref](https://github.com/git/git)
> Prerequisite: go1.15+ required. [ref](https://golang.org/doc/install)
>Optional requirement: GNU make. [ref](https://www.gnu.org/software/make/manual/html_node/index.html)
> Prerequisite: git. [ref](https://github.com/git/git)
> Optional requirement: GNU make. [ref](https://www.gnu.org/software/make/manual/html_node/index.html)
* Clone git repository

```shell
git clone https://github.com/persistenceOne/persistenceBridge.git
```

> Note: If running go the latest version (tested on `1.16.3`), do `export CGO_ENABLED="0"` before make install
* Make the binary
Might require you to run `export CGO_ENABLED="0"` before make.
Might require you to run `export CGO_ENABLED="0"` before make.

```shell
make all
```

* Start the bridge
```shell
./build/..../persistenceBridge start {arguments}
```
When starting for first time `--tmStart` `--ethStart ` needs to be always given, after that not adding it will start
checking from last checked height + 1

When starting for first time `--tmStart` `--ethStart ` needs to be always given,
after that not adding it will start checking from last checked height + 1
* Starting the bridge

`path_to_chain_json` json file for tendermint chain, same as the relayer format -
`{"key":"acc_0","chain-id":"test","rpc-addr":"http://192.168.1.4:26657","account-prefix":"cosmos","gas-adjustment":1.5,"gas-prices":"0.025stake","trusting-period":"336h"`
```shell
persistenceBridge init
```

* First time start
`persistenceBridge init`
This generates a `config.toml` file in `$HOME/.persistenceBridge/` with empty and default values. Update this file as per configuration (Telegram configuration is not compulsory).

`persistenceBridge add [validator_address] [validator_name]`
Add participating validators:
```shell
persistenceBridge add [validator_address] [validator_name]
```

Update the config file generated (CASP server, vault and public keys) (Telegram configuration is not compulsory).
Now when starting for the first time:

`persistenceBridge start chain.json --tmStart 1 --ethStart 4772131`
```shell
persistenceBridge start --tmStart 1 --ethStart 4772131
```

>IMPORTANT NOTE: Remove `--tmStart --ethStart` when starting next time
When starting next time
```shell
persistenceBridge start
```
12 changes: 6 additions & 6 deletions application/casp/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ func GetEthAddress() (common.Address, error) {
if err != nil {
return common.Address{}, err
}
if len(uncompressedPublicKeys.PublicKeys) == 0 {
return common.Address{}, fmt.Errorf("no public keys got from casp")
if len(uncompressedPublicKeys.Items) == 0 {
return common.Address{}, fmt.Errorf("no eth public keys got from casp")
}
publicKey := GetEthPubKey(uncompressedPublicKeys.PublicKeys[0])
publicKey := GetEthPubKey(uncompressedPublicKeys.Items[0])
return crypto.PubkeyToAddress(publicKey), nil
}

Expand All @@ -25,9 +25,9 @@ func GetTendermintAddress() (sdk.AccAddress, error) {
if err != nil {
return nil, err
}
if len(uncompressedPublicKeys.PublicKeys) == 0 {
return nil, err
if len(uncompressedPublicKeys.Items) == 0 {
return nil, fmt.Errorf("no tendermint public keys got from casp")
}
tmPublicKey := GetTMPubKey(uncompressedPublicKeys.PublicKeys[0])
tmPublicKey := GetTMPubKey(uncompressedPublicKeys.Items[0])
return sdk.AccAddress(tmPublicKey.Address()), nil
}
1 change: 1 addition & 0 deletions application/commands/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func InitCommand() *cobra.Command {
cmd.Flags().String(constants2.FlagDenom, constants2.DefaultDenom, "denom name")
cmd.Flags().String(constants2.FlagAccountPrefix, constants2.DefaultAccountPrefix, "account prefix on tendermint chains")
cmd.Flags().String(constants2.FlagTendermintNode, constants2.DefaultTendermintNode, "tendermint rpc node url")
cmd.Flags().Uint32(constants2.FlagTendermintCoinType, constants2.DefaultTendermintCoinType, "tendermint address coin type")
cmd.Flags().String(constants2.FlagTendermintChainID, constants2.DefaultTendermintChainId, "chain id of tendermint node")
cmd.Flags().Uint64(constants2.FlagEthGasLimit, constants2.DefaultEthGasLimit, "Gas limit for eth txs")
cmd.Flags().String(constants2.FlagBroadcastMode, constants2.DefaultBroadcastMode, "broadcast mode for tendermint")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package commands

import (
"github.com/BurntSushi/toml"
"github.com/persistenceOne/persistenceBridge/application/casp"
"github.com/persistenceOne/persistenceBridge/application/configuration"
constants2 "github.com/persistenceOne/persistenceBridge/application/constants"
"github.com/persistenceOne/persistenceBridge/application/db"
Expand All @@ -15,7 +16,7 @@ import (
func ShowCommand() *cobra.Command {
showCommand := &cobra.Command{
Use: "show",
Short: "show validators address to signing group",
Short: "show wrap address, eth bridge admin and validators",
RunE: func(cmd *cobra.Command, args []string) error {
homePath, err := cmd.Flags().GetString(constants2.FlagPBridgeHome)
if err != nil {
Expand All @@ -33,6 +34,17 @@ func ShowCommand() *cobra.Command {
}
configuration.ValidateAndSeal()

tmAddress, err := casp.GetTendermintAddress()
if err != nil {
log.Fatalln(err)
}
ethAddress, err := casp.GetEthAddress()
if err != nil {
log.Fatalln(err)
}
log.Println("Tendermint Address:", tmAddress.String())
log.Println("Ethereum Address:", ethAddress.String())

rpcEndpoint, err := cmd.Flags().GetString(constants2.FlagRPCEndpoint)
if err != nil {
log.Fatalln(err)
Expand Down
File renamed without changes.
32 changes: 4 additions & 28 deletions application/commands/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ func StartCommand() *cobra.Command {
if err != nil {
log.Fatalf("Error decoding pStakeConfig file: %v\n", err.Error())
}
pStakeConfig = configuration.SetConfig(cmd)

ethAddress, err := casp.GetEthAddress()
if err != nil {
log.Fatalln(err)
Expand Down Expand Up @@ -137,7 +135,7 @@ func StartCommand() *cobra.Command {
}

encodingConfig := application.MakeEncodingConfig()
initClientCtx := client.Context{}.
clientContext := client.Context{}.
WithJSONMarshaler(encodingConfig.Marshaler).
WithInterfaceRegistry(encodingConfig.InterfaceRegistry).
WithTxConfig(encodingConfig.TransactionConfig).
Expand All @@ -147,7 +145,7 @@ func StartCommand() *cobra.Command {
WithBroadcastMode(configuration.GetAppConfig().Tendermint.BroadcastMode).
WithHomeDir(homePath)

protoCodec := codec.NewProtoCodec(initClientCtx.InterfaceRegistry)
protoCodec := codec.NewProtoCodec(clientContext.InterfaceRegistry)
kafkaState := utils.NewKafkaState(pStakeConfig.Kafka.Brokers, homePath, pStakeConfig.Kafka.TopicDetail)
end := make(chan bool)
ended := make(chan bool)
Expand All @@ -159,12 +157,12 @@ func StartCommand() *cobra.Command {
go ethereum2.StartListening(ethereumClient, time.Duration(ethSleepTime)*time.Millisecond, pStakeConfig.Kafka.Brokers, protoCodec)

logging.Info("Starting to listen tendermint....")
go tendermint2.StartListening(initClientCtx, chain, pStakeConfig.Kafka.Brokers, protoCodec, time.Duration(tmSleepTime)*time.Millisecond)
go tendermint2.StartListening(clientContext, chain, pStakeConfig.Kafka.Brokers, protoCodec, time.Duration(tmSleepTime)*time.Millisecond)

signalChan := make(chan os.Signal, 1)
signal.Notify(signalChan, syscall.SIGINT, syscall.SIGTERM)
for sig := range signalChan {
logging.Info("STOP SIGNAL RECEIVED: " + sig.String())
logging.Info("STOP SIGNAL RECEIVED:", sig.String(), "(Might take around a minute to stop)")
shutdown.SetBridgeStopSignal(true)
for {
if !shutdown.GetKafkaConsumerClosed() {
Expand All @@ -182,35 +180,13 @@ func StartCommand() *cobra.Command {
return nil
},
}
//This will always be used from flag
pBridgeCommand.Flags().String(constants2.FlagTimeOut, constants2.DefaultTimeout, "timeout time for connecting to rpc")
pBridgeCommand.Flags().String(constants2.FlagPBridgeHome, constants2.DefaultPBridgeHome, "home for pBridge")
pBridgeCommand.Flags().Bool(constants2.FlagShowDebugLog, false, "show debug logs")

pBridgeCommand.Flags().String(constants2.FlagEthereumEndPoint, "", "ethereum orchestrator to connect")
pBridgeCommand.Flags().String(constants2.FlagKafkaPorts, "", "ports kafka brokers are running on, --ports 192.100.10.10:443,192.100.10.11:443")
pBridgeCommand.Flags().Int(constants2.FlagTendermintSleepTime, constants2.DefaultTendermintSleepTime, "sleep time between block checking for tendermint in ms")
pBridgeCommand.Flags().Int(constants2.FlagEthereumSleepTime, constants2.DefaultEthereumSleepTime, "sleep time between block checking for ethereum in ms")
pBridgeCommand.Flags().Int64(constants2.FlagTendermintStartHeight, constants2.DefaultTendermintStartHeight, fmt.Sprintf("Start checking height on tendermint chain from this height (default %d - starts from where last left)", constants2.DefaultTendermintStartHeight))
pBridgeCommand.Flags().Int64(constants2.FlagEthereumStartHeight, constants2.DefaultEthereumStartHeight, fmt.Sprintf("Start checking height on ethereum chain from this height (default %d - starts from where last left)", constants2.DefaultEthereumStartHeight))
pBridgeCommand.Flags().String(constants2.FlagDenom, "", "denom name")
pBridgeCommand.Flags().String(constants2.FlagAccountPrefix, "", "account prefix on tendermint chains")
pBridgeCommand.Flags().String(constants2.FlagTendermintNode, constants2.DefaultTendermintNode, "tendermint rpc node url")
pBridgeCommand.Flags().String(constants2.FlagTendermintChainID, constants2.DefaultTendermintChainId, "chain identifier")
pBridgeCommand.Flags().Uint64(constants2.FlagEthGasLimit, 0, "Gas limit for eth txs")
pBridgeCommand.Flags().String(constants2.FlagBroadcastMode, "", "broadcast mode for tendermint")
pBridgeCommand.Flags().String(constants2.FlagCASPURL, "", "casp api url (with http)")
pBridgeCommand.Flags().String(constants2.FlagCASPVaultID, "", "casp vault id")
pBridgeCommand.Flags().String(constants2.FlagCASPApiToken, "", "casp api token (in format: Bearer ...)")
pBridgeCommand.Flags().String(constants2.FlagCASPTMPublicKey, "", "casp tendermint public key")
pBridgeCommand.Flags().String(constants2.FlagCASPEthPublicKey, "", "casp ethereum public key")
pBridgeCommand.Flags().Int(constants2.FlagCASPSignatureWaitTime, -1, "csap siganture wait time")
pBridgeCommand.Flags().Int(constants2.FlagCASPMaxGetSignatureAttempts, 0, "casp max attempts to fetch operation id")
pBridgeCommand.Flags().String(constants2.FlagRPCEndpoint, "", "rpc Endpoint for server")
pBridgeCommand.Flags().Int64(constants2.FlagMinimumWrapAmount, -1, "minimum amount in send coin tx to wrap onto eth")
pBridgeCommand.Flags().String(constants2.FlagTelegramBotToken, "", "telegram bot token")
pBridgeCommand.Flags().Int64(constants2.FlagTelegramChatID, 0, "telegram chat id")
pBridgeCommand.Flags().Bool(constants2.FlagCASPConcurrentKey, true, "allows starting multiple sign operations that specify the same key")

return pBridgeCommand
}
Loading

0 comments on commit 20dc70e

Please sign in to comment.