diff --git a/.github/workflows/orchestrator_builder.yml b/.github/workflows/orchestrator_builder.yml new file mode 100644 index 0000000..7514fc6 --- /dev/null +++ b/.github/workflows/orchestrator_builder.yml @@ -0,0 +1,64 @@ +name: Build and release orchestrator + +on: + push: + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +jobs: + xgo: + permissions: write-all + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Install zip utility + run: | + sudo apt update + sudo apt install -y zip + - name: Make version + run: make version + - name: Build orchestrator + uses: crazy-max/ghaction-xgo@v2.4.0 + with: + xgo_version: latest + go_version: 1.20.0 + dest: build + prefix: orchestrator + pkg: ./main.go + targets: linux/amd64,linux/arm64 + v: true + x: true + ldflags: '-extldflags "-Wl,--allow-multiple-definition"' + buildvcs: false + buildmode: default + trimpath: true + - name: Add execute flag + run: | + chmod +x build/* + - name: Archive files + run: | + cd build + zip orchestrator-linux-amd64.zip orchestrator-linux-amd64 + zip orchestrator-linux-arm64.zip orchestrator-linux-arm64 + rm orchestrator-linux-amd64 + rm orchestrator-linux-arm64 + - name: Generate checksums + run: | + cd build + echo $(sha256sum *) + echo $(sha256sum *) >> SHA256CHECKSUMS.txt + - name: Set version + run: | + ORCHESTRATOR=$(cat metadata/version.go | grep Version | awk -F '"' '{print $2}') + echo "ORCHESTRATOR_VERSION=$ORCHESTRATOR" >> $GITHUB_ENV + - name: Upload files to a GitHub release + uses: svenstaro/upload-release-action@2.5.0 + with: + repo_token: ${{ secrets.GITHUB_TOKEN }} + file: build/* + release_name: ${{ env.ORCHESTRATOR_VERSION }} + tag: ${{ env.ORCHESTRATOR_VERSION }}-alphanet + file_glob: true + overwrite: true + body: "" diff --git a/Makefile b/Makefile index 8cd7ab2..5e911fe 100644 --- a/Makefile +++ b/Makefile @@ -1,11 +1,24 @@ +.PHONY: all clean version + +GO ?= latest + BINARY_NAME=orchestrator +BUILDDIR = $(shell pwd)/build +GIT_COMMIT=$(shell git rev-parse HEAD) +GIT_COMMIT_FILE=$(shell pwd)/metadata/git_commit.go build: - go build --ldflags '-extldflags "-Wl,--allow-multiple-definition"' -o ${BINARY_NAME} main.go + go build --ldflags '-extldflags "-Wl,--allow-multiple-definition"' -o $(BUILDDIR)/${BINARY_NAME} main.go run: ./${BINARY_NAME} +version: + @echo "package metadata\n" > $(GIT_COMMIT_FILE) + @echo "const (" >> $(GIT_COMMIT_FILE) + @echo "\tGitCommit = \"${GIT_COMMIT}\"" >> $(GIT_COMMIT_FILE) + @echo ")" >> $(GIT_COMMIT_FILE) + clean: go clean - rm orchestrator + rm $(BINARY_NAME) diff --git a/app/action_version.go b/app/action_version.go new file mode 100644 index 0000000..08d25af --- /dev/null +++ b/app/action_version.go @@ -0,0 +1,34 @@ +package app + +import ( + "fmt" + "os" + "runtime" + + "orchestrator/metadata" + + "gopkg.in/urfave/cli.v1" +) + +var ( + versionCommand = cli.Command{ + Action: versionAction, + Name: "version", + Usage: "Print version numbers", + ArgsUsage: " ", + Category: "MISCELLANEOUS COMMANDS", + } +) + +func versionAction(*cli.Context) error { + fmt.Printf(`orchestrator +Version:%v +Architecture:%v +Go Version:%v +Operating System:%v +GOPATH:%v +GOROOT:%v +Commit hash:%v +`, metadata.Version, runtime.GOARCH, runtime.Version(), runtime.GOOS, os.Getenv("GOPATH"), runtime.GOROOT(), metadata.GitCommit) + return nil +} diff --git a/app/cli.go b/app/cli.go index 28359d4..5639859 100644 --- a/app/cli.go +++ b/app/cli.go @@ -2,9 +2,16 @@ package app import ( "fmt" - "gopkg.in/urfave/cli.v1" + "net/http" "os" + "path/filepath" "runtime" + "sort" + "time" + + "orchestrator/metadata" + + "gopkg.in/urfave/cli.v1" ) var ( @@ -28,20 +35,49 @@ func Stop() { } func init() { + app.Name = filepath.Base(os.Args[0]) + app.HideVersion = false + app.Version = metadata.Version + app.Compiled = time.Now() + app.Usage = "orchestrator Node" + app.Commands = []cli.Command{ + versionCommand, + } + sort.Sort(cli.CommandsByName(app.Commands)) + + app.Flags = AllFlags app.Before = beforeAction app.Action = action app.After = afterAction } func beforeAction(ctx *cli.Context) error { - if len(ctx.Args()) == 0 { - max := runtime.NumCPU() - fmt.Printf("Starting orchestrator.\n") - runtime.GOMAXPROCS(max) + + max := runtime.NumCPU() + fmt.Printf("Starting orchestrator.\n") + fmt.Printf("current time is %v\n", time.Now().Format("2009-01-03 18:15:05")) + fmt.Printf("version: %v\n", metadata.Version) + fmt.Printf("git-commit-hash: %v\n", metadata.GitCommit) + fmt.Printf("orchestrator will use at most %v cpu-cores\n", max) + runtime.GOMAXPROCS(max) + + // pprof server + if ctx.GlobalIsSet(PprofFlag.Name) { + listenHost := ctx.String(PprofAddrFlag.Name) + + port := ctx.Int(PprofPortFlag.Name) + + address := fmt.Sprintf("%s:%d", listenHost, port) + + go func() { + if err := http.ListenAndServe(address, nil); err != nil { + nodeManager.logger.Error(err.Error()) + } + }() } + return nil } func action(ctx *cli.Context) error { - //Make sure No subCommands were entered,Only the flags if args := ctx.Args(); len(args) > 0 { return fmt.Errorf("invalid command: %q", args[0]) } diff --git a/app/flags.go b/app/flags.go new file mode 100644 index 0000000..97683f6 --- /dev/null +++ b/app/flags.go @@ -0,0 +1,34 @@ +package app + +import ( + "gopkg.in/urfave/cli.v1" +) + +var ( + + // pprof + + PprofFlag = cli.BoolFlag{ + Name: "pprof", + Usage: "Enable the pprof HTTP server", + } + PprofPortFlag = cli.Uint64Flag{ + Name: "pprof.port", + Usage: "pprof HTTP server listening port", + Value: 6060, + } + + PprofAddrFlag = cli.StringFlag{ + Name: "pprof.addr", + Usage: "pprof HTTP server listening interface", + Value: "127.0.0.1", + } + + AllFlags = []cli.Flag{ + + // pprof + PprofFlag, + PprofPortFlag, + PprofAddrFlag, + } +) diff --git a/examples/tss/main.go b/examples/tss/main.go index a013c7a..d342d60 100644 --- a/examples/tss/main.go +++ b/examples/tss/main.go @@ -119,7 +119,7 @@ func main() { // Start keygen fmt.Println("Start keygen") - if err := z.Send(z.Client.BridgeApi.AllowKeygen()); err != nil { + if err := z.Send(z.Client.BridgeApi.SetAllowKeygen(true)); err != nil { fmt.Println(err) } fmt.Println("Done") @@ -154,7 +154,7 @@ func main() { // Keygen is done, setting TSS Public Key fmt.Println("Keygen is done, setting TSS Public Key", tssPubKey) - if err := z.Send(z.Client.BridgeApi.ChangeTssECDSAPubKey(tssPubKey, "", "", uint32(numPillars))); err != nil { + if err := z.Send(z.Client.BridgeApi.ChangeTssECDSAPubKey(tssPubKey, "", "")); err != nil { fmt.Println("ChangeTssECDSAPubKey err:") fmt.Println(err) } @@ -232,7 +232,7 @@ func main() { fmt.Println("EstimatedMomentumTime: ", orchestratorInfo.EstimatedMomentumTime) fmt.Println("ConfirmationsToFinality: ", orchestratorInfo.ConfirmationsToFinality) fmt.Println("AllowKeyGenHeight: ", orchestratorInfo.AllowKeyGenHeight) - fmt.Println("KeySignThreshold: ", orchestratorInfo.KeySignThreshold) + fmt.Println("KeyGenThreshold: ", orchestratorInfo.KeyGenThreshold) } fmt.Println("--------------------------------\nSecurity Info") diff --git a/examples/wrap/main.go b/examples/wrap/main.go index bf86f6f..0b1b4cc 100644 --- a/examples/wrap/main.go +++ b/examples/wrap/main.go @@ -48,7 +48,6 @@ func main() { } else { fmt.Println("CompressedTssECDSAPubKey: ", bridgeInfo.CompressedTssECDSAPubKey) fmt.Println("DecompressedTssECDSAPubKey: ", bridgeInfo.DecompressedTssECDSAPubKey) - fmt.Println("AdministratorEDDSAPubKey: ", bridgeInfo.AdministratorEDDSAPubKey) fmt.Println("AllowKeygen: ", bridgeInfo.AllowKeyGen) fmt.Println("HaltActivated: ", bridgeInfo.Halted) fmt.Println("UnhaltHeight: ", bridgeInfo.UnhaltedAt) @@ -66,7 +65,6 @@ func main() { fmt.Println("EstimatedMomentumTime: ", orchestratorInfo.EstimatedMomentumTime) fmt.Println("ConfirmationsToFinality: ", orchestratorInfo.ConfirmationsToFinality) fmt.Println("AllowKeyGenHeight: ", orchestratorInfo.AllowKeyGenHeight) - fmt.Println("KeySignThreshold: ", orchestratorInfo.KeySignThreshold) } fmt.Println("--------------------------------\nSecurity Info") diff --git a/metadata/git_commit.go b/metadata/git_commit.go new file mode 100644 index 0000000..f14adf2 --- /dev/null +++ b/metadata/git_commit.go @@ -0,0 +1,5 @@ +package metadata + +const ( + GitCommit = "" +) diff --git a/metadata/version.go b/metadata/version.go new file mode 100644 index 0000000..2d6e764 --- /dev/null +++ b/metadata/version.go @@ -0,0 +1,5 @@ +package metadata + +const ( + Version = "v0.0.1" +)