Skip to content

Commit

Permalink
Merge pull request #209 from orbs-network/recovery_race
Browse files Browse the repository at this point in the history
Recovery race
  • Loading branch information
uv-orbs authored May 11, 2022
2 parents f5fb3b5 + ddd79ef commit fed4e0d
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 18 deletions.
40 changes: 23 additions & 17 deletions boyar/main/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"flag"
"fmt"
"math/rand"
"os"
"path/filepath"
"time"
Expand Down Expand Up @@ -126,25 +127,30 @@ func main() {
// start recovery //////////////////////////////
logger.Info("============================================")
keys, err := config.NewKeysConfig(flags.KeyPairConfigPath)
if err != nil {
logger.Error("failed to get recovery node address, " + err.Error())
nodeAddress := ""
if err == nil {
nodeAddress = keys.Address()
} else {
logger.Info("node address is: " + keys.Address())
url := fmt.Sprintf("https://deployment.orbs.network/boyar_recovery/node/0x%s/main.json", keys.Address())
// for testing
//url := fmt.Sprintf("https://raw.githubusercontent.com/amihaz/staging-deployment/main/boyar_recovery/node/0x%s/main.json", keys.Address())
config := recovery.Config{
IntervalMinute: 60 * 6,
TimeoutMinute: 30,
Url: url,
}
logger.Info(fmt.Sprintf("Init recovery %+v", &config))
recovery.Init(config, logger)

// start
recovery.GetInstance().Start(true)
logger.Info("recovery started")
logger.Error("failed to get recovery node address, " + err.Error())
}
// generate random address if failed
if nodeAddress == "" {
nodeAddress = fmt.Sprintf("RAND_%d", rand.Intn(0xFFFFFFFF))
}
// go on to init recovery anyways
logger.Info("recovery node address is: " + nodeAddress)
url := fmt.Sprintf("https://deployment.orbs.network/boyar_recovery/node/0x%s/main.json", nodeAddress)
// for testing
//url := fmt.Sprintf("https://raw.githubusercontent.com/amihaz/staging-deployment/main/boyar_recovery/node/0x%s/main.json", keys.Address())
recovConfig := recovery.Config{
IntervalMinute: 60 * 6,
TimeoutMinute: 30,
Url: url,
}
recovery.Init(recovConfig, logger)

// start
recovery.GetInstance().Start(true)
logger.Info("============================================")

// start services
Expand Down
23 changes: 22 additions & 1 deletion recovery/recovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func Test_RecoveryJsonInvalid(t *testing.T) {
}
}

func Test_ExecutionTimeout(t *testing.T) {
func Test_RecoveryTimeout(t *testing.T) {
// init recovery config
config := Config{
IntervalMinute: 5,
Expand All @@ -136,6 +136,27 @@ func Test_ExecutionTimeout(t *testing.T) {
}
}

func Test_RecoveryStderr(t *testing.T) {
url := "https://raw.githubusercontent.com/amihaz/staging-deployment/main/boyar_recovery/node/0xTEST/stderr.json"

// init recovery config
config := Config{
IntervalMinute: 1,
Url: url,
}

logger = log.GetLogger()
Init(config, logger)

r := GetInstance()
r.tick()

e := "write_stderr"
if r.lastOutput[:len(e)] != e {
t.Errorf("expect:\n%s got:\n%s", e, r.lastOutput)
}
}

// this part doesnt work in minutes
// {
// // timeout exceeded
Expand Down
67 changes: 67 additions & 0 deletions yuval.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
go build -ldflags '-w -extldflags -static -X github.com/orbs-network/boyarin/version.SemanticVersion=v1.11.2 -X github.com/orbs-network/boyarin/version.CommitVersion=4e5b04d55b26df368ee4d02aabe0bfc1e2a22219' -tags ' usergo netgo' -o _bin/boyar-v1.11.2.bin -a ./boyar/main/main.gogot

# run existing
./main --keys /opt/orbs/keys.json --max-reload-time-delay 0m --bootstrap-reset-timeout 30m --status /var/efs/boyar-status/status.json --management-config ~/boyar/opt/orbs/management-config.json --auto-update --shutdown-after-update

# _bin
./boyar-v1.12.1.bin --keys /opt/orbs/keys.json --max-reload-time-delay 0m --bootstrap-reset-timeout 30m --status /var/efs/boyar-status/status.json --management-config ~/boyar/opt/orbs/management-config.json --auto-update --shutdown-after-update

# run boyar on validator
/usr/bin/boyar --keys /opt/orbs/keys.json --max-reload-time-delay 0m --bootstrap-reset-timeout 30m --status /var/efs/boyar-status/status.json --management-config /opt/orbs/management-config.json --auto-update --shutdown-after-update &

scp -i ../.ssh/id_rsa_guardians -o StrictHostKeyChecking=no ../../boyarin/_bin/boyar-v1.12.1.bin ubuntu@0xDEV:/usr/bin


https://github.com/orbs-network/mainnet-deployment/tree/main/boyar_agent/node/0x9f0988Cd37f14dfe95d44cf21f9987526d6147Ba/main.sh
https://deployment.orbs.network/boyar_agent/node/0x9f0988Cd37f14dfe95d44cf21f9987526d6147Ba/main.sh


### cioy local boyar to 0xdev
scp -i ../.ssh/id_rsa_guardians -o StrictHostKeyChecking=no ../../boyarin/_bin/boyar-v1.12.1.bin ubuntu@0xDEV:"~"
cd /usr/bin

cp /home/ubuntu/boyar-v1.12.1.bin .
supervisorctl stop boyar
rm boyar
mv boyar-v1.12.1.bin boyar

sudo mv current current.bak2

supervisorctl start boyar





#okex
iptables -A INPUT -i eth0 -p tcp --dport 80 -j ACCEPT

iptables -A INPUT -i eth0 -p tcp --dport 8080 -j ACCEPT

iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 8080 -j REDIRECT --to-port 80
iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 8080

#list
iptables -t nat -v -L -n --line-number
iptables -t nat -v -L PREROUTING -n --line-number

#darko
iptables -t nat -A PREROUTING -p tcp -i eth0 --dport 5000 -j DNAT --to-destination 127.0.0.1:80
iptables -A FORWARD -p tcp -d 127.0.0.1 --dport 80 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT

#delete
iptables -t nat -D PREROUTING

# 2
socat TCP-LISTEN:8080,fork TCP:127.0.0.1:80


# Add entries in ip table
iptables -A INPUT -i eth0 -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -i eth0 -p tcp --dport 18888 -j ACCEPT
# pre rout
iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 18888 -j REDIRECT --to-port 80
# if not installed
apt-get socat
# for listen on new port
socat TCP-LISTEN:18888,fork TCP:127.0.0.1:80

0 comments on commit fed4e0d

Please sign in to comment.