From 502847775253eea829c4adcd43b22982910d226a Mon Sep 17 00:00:00 2001 From: paul-ahn-wm Date: Thu, 23 May 2024 10:30:26 +0900 Subject: [PATCH 01/16] Fix: replace deprecated syscall pkg to golang.org/x/sys/unix pkg --- cmd/geth/dbcmd.go | 6 +++--- cmd/geth/main.go | 6 +++--- cmd/geth/wemixcmd.go | 10 +++++----- cmd/utils/cmd.go | 10 +++++----- common/fdlimit/fdlimit_bsd.go | 18 +++++++++--------- common/fdlimit/fdlimit_darwin.go | 18 +++++++++--------- common/fdlimit/fdlimit_unix.go | 18 +++++++++--------- console/console.go | 4 ++-- internal/cmdtest/test_cmd.go | 4 ++-- metrics/cputime_unix.go | 7 +++---- node/errors.go | 5 +++-- p2p/netutil/toobig_windows.go | 5 +++-- p2p/simulations/adapters/exec.go | 6 +++--- 13 files changed, 59 insertions(+), 58 deletions(-) diff --git a/cmd/geth/dbcmd.go b/cmd/geth/dbcmd.go index ace2849c9f06..871b8002fe18 100644 --- a/cmd/geth/dbcmd.go +++ b/cmd/geth/dbcmd.go @@ -25,7 +25,6 @@ import ( "sort" "strconv" "strings" - "syscall" "time" "github.com/ethereum/go-ethereum/cmd/utils" @@ -40,6 +39,7 @@ import ( "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/trie" "github.com/olekukonko/tablewriter" + "golang.org/x/sys/unix" "gopkg.in/urfave/cli.v1" ) @@ -597,7 +597,7 @@ func importLDBdata(ctx *cli.Context) error { stop = make(chan struct{}) ) defer stack.Close() - signal.Notify(interrupt, syscall.SIGINT, syscall.SIGTERM) + signal.Notify(interrupt, unix.SIGINT, unix.SIGTERM) defer signal.Stop(interrupt) defer close(interrupt) go func() { @@ -693,7 +693,7 @@ func exportChaindata(ctx *cli.Context) error { stop = make(chan struct{}) ) defer stack.Close() - signal.Notify(interrupt, syscall.SIGINT, syscall.SIGTERM) + signal.Notify(interrupt, unix.SIGINT, unix.SIGTERM) defer signal.Stop(interrupt) defer close(interrupt) go func() { diff --git a/cmd/geth/main.go b/cmd/geth/main.go index 1cdbfe866863..cdbff4d8ff1a 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -26,7 +26,6 @@ import ( "sort" "strconv" "strings" - "syscall" "time" "github.com/elastic/gosigar" @@ -45,6 +44,7 @@ import ( "github.com/ethereum/go-ethereum/metrics" "github.com/ethereum/go-ethereum/node" "github.com/ethereum/go-ethereum/wemix" + "golang.org/x/sys/unix" // Force-load the tracer engines to trigger registration _ "github.com/ethereum/go-ethereum/eth/tracers/js" @@ -514,8 +514,8 @@ func limitMaxRss(max int64) { timer := time.NewTimer(interval) for { <-timer.C - rusage := syscall.Rusage{} - err := syscall.Getrusage(syscall.RUSAGE_SELF, &rusage) + rusage := unix.Rusage{} + err := unix.Getrusage(unix.RUSAGE_SELF, &rusage) if err != nil { log.Error("Getrusage() failed:", "reason", err) } else { diff --git a/cmd/geth/wemixcmd.go b/cmd/geth/wemixcmd.go index 632ac93f51b3..d301dd9c6a9e 100644 --- a/cmd/geth/wemixcmd.go +++ b/cmd/geth/wemixcmd.go @@ -17,7 +17,6 @@ import ( "path/filepath" "strconv" "strings" - "syscall" "github.com/charlanxcc/logrot" "github.com/ethereum/go-ethereum/accounts/keystore" @@ -29,6 +28,7 @@ import ( "github.com/ethereum/go-ethereum/ethclient" "github.com/ethereum/go-ethereum/p2p/enode" "github.com/ethereum/go-ethereum/wemix/metclient" + "golang.org/x/sys/unix" "gopkg.in/urfave/cli.v1" ) @@ -667,10 +667,10 @@ func logrota(ctx *cli.Context) error { if err != nil { return err } - syscall.Close(syscall.Stdout) - syscall.Close(syscall.Stdout) - syscall.Dup2(int(w.Fd()), syscall.Stdout) - syscall.Dup2(int(w.Fd()), syscall.Stderr) + unix.Close(unix.Stdout) + unix.Close(unix.Stdout) + unix.Dup2(int(w.Fd()), unix.Stdout) + unix.Dup2(int(w.Fd()), unix.Stderr) go logrot.LogRotate(r, logFile, logSize, logCount) diff --git a/cmd/utils/cmd.go b/cmd/utils/cmd.go index 47ad3b22c8dd..d9d8e605b15f 100644 --- a/cmd/utils/cmd.go +++ b/cmd/utils/cmd.go @@ -27,7 +27,6 @@ import ( "os/signal" "runtime" "strings" - "syscall" "time" "github.com/ethereum/go-ethereum/common" @@ -41,6 +40,7 @@ import ( "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/node" "github.com/ethereum/go-ethereum/rlp" + "golang.org/x/sys/unix" "gopkg.in/urfave/cli.v1" ) @@ -74,7 +74,7 @@ func StartNode(ctx *cli.Context, stack *node.Node, isConsole bool) { } go func() { sigc := make(chan os.Signal, 1) - signal.Notify(sigc, syscall.SIGINT, syscall.SIGTERM) + signal.Notify(sigc, unix.SIGINT, unix.SIGTERM) defer signal.Stop(sigc) minFreeDiskSpace := 2 * ethconfig.Defaults.TrieDirtyCache // Default 2 * 256Mb @@ -105,7 +105,7 @@ func StartNode(ctx *cli.Context, stack *node.Node, isConsole bool) { // However, SIGTERM still shuts down the node. for { sig := <-sigc - if sig == syscall.SIGTERM { + if sig == unix.SIGTERM { shutdown() return } @@ -126,7 +126,7 @@ func monitorFreeDiskSpace(sigc chan os.Signal, path string, freeDiskSpaceCritica } if freeSpace < freeDiskSpaceCritical { log.Error("Low disk space. Gracefully shutting down Geth to prevent database corruption.", "available", common.StorageSize(freeSpace)) - sigc <- syscall.SIGTERM + sigc <- unix.SIGTERM break } else if freeSpace < 2*freeDiskSpaceCritical { log.Warn("Disk space is running low. Geth will shutdown if disk space runs below critical level.", "available", common.StorageSize(freeSpace), "critical_level", common.StorageSize(freeDiskSpaceCritical)) @@ -140,7 +140,7 @@ func ImportChain(chain *core.BlockChain, fn string) error { // If a signal is received, the import will stop at the next batch. interrupt := make(chan os.Signal, 1) stop := make(chan struct{}) - signal.Notify(interrupt, syscall.SIGINT, syscall.SIGTERM) + signal.Notify(interrupt, unix.SIGINT, unix.SIGTERM) defer signal.Stop(interrupt) defer close(interrupt) go func() { diff --git a/common/fdlimit/fdlimit_bsd.go b/common/fdlimit/fdlimit_bsd.go index a3a6902c0925..abe73b96197a 100644 --- a/common/fdlimit/fdlimit_bsd.go +++ b/common/fdlimit/fdlimit_bsd.go @@ -19,7 +19,7 @@ package fdlimit -import "syscall" +import "golang.org/x/sys/unix" // This file is largely identical to fdlimit_unix.go, // but Rlimit fields have type int64 on *BSD so it needs @@ -29,8 +29,8 @@ import "syscall" // to the maximum hard-limit allowed by the OS. func Raise(max uint64) (uint64, error) { // Get the current limit - var limit syscall.Rlimit - if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &limit); err != nil { + var limit unix.Rlimit + if err := unix.Getrlimit(unix.RLIMIT_NOFILE, &limit); err != nil { return 0, err } // Try to update the limit to the max allowance @@ -38,10 +38,10 @@ func Raise(max uint64) (uint64, error) { if limit.Cur > int64(max) { limit.Cur = int64(max) } - if err := syscall.Setrlimit(syscall.RLIMIT_NOFILE, &limit); err != nil { + if err := unix.Setrlimit(unix.RLIMIT_NOFILE, &limit); err != nil { return 0, err } - if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &limit); err != nil { + if err := unix.Getrlimit(unix.RLIMIT_NOFILE, &limit); err != nil { return 0, err } return uint64(limit.Cur), nil @@ -50,8 +50,8 @@ func Raise(max uint64) (uint64, error) { // Current retrieves the number of file descriptors allowed to be opened by this // process. func Current() (int, error) { - var limit syscall.Rlimit - if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &limit); err != nil { + var limit unix.Rlimit + if err := unix.Getrlimit(unix.RLIMIT_NOFILE, &limit); err != nil { return 0, err } return int(limit.Cur), nil @@ -60,8 +60,8 @@ func Current() (int, error) { // Maximum retrieves the maximum number of file descriptors this process is // allowed to request for itself. func Maximum() (int, error) { - var limit syscall.Rlimit - if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &limit); err != nil { + var limit unix.Rlimit + if err := unix.Getrlimit(unix.RLIMIT_NOFILE, &limit); err != nil { return 0, err } return int(limit.Max), nil diff --git a/common/fdlimit/fdlimit_darwin.go b/common/fdlimit/fdlimit_darwin.go index 6b26fa00f12c..dc932238eae7 100644 --- a/common/fdlimit/fdlimit_darwin.go +++ b/common/fdlimit/fdlimit_darwin.go @@ -16,7 +16,7 @@ package fdlimit -import "syscall" +import "golang.org/x/sys/unix" // hardlimit is the number of file descriptors allowed at max by the kernel. const hardlimit = 10240 @@ -26,8 +26,8 @@ const hardlimit = 10240 // Returns the size it was set to (may differ from the desired 'max') func Raise(max uint64) (uint64, error) { // Get the current limit - var limit syscall.Rlimit - if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &limit); err != nil { + var limit unix.Rlimit + if err := unix.Getrlimit(unix.RLIMIT_NOFILE, &limit); err != nil { return 0, err } // Try to update the limit to the max allowance @@ -35,11 +35,11 @@ func Raise(max uint64) (uint64, error) { if limit.Cur > max { limit.Cur = max } - if err := syscall.Setrlimit(syscall.RLIMIT_NOFILE, &limit); err != nil { + if err := unix.Setrlimit(unix.RLIMIT_NOFILE, &limit); err != nil { return 0, err } // MacOS can silently apply further caps, so retrieve the actually set limit - if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &limit); err != nil { + if err := unix.Getrlimit(unix.RLIMIT_NOFILE, &limit); err != nil { return 0, err } return limit.Cur, nil @@ -48,8 +48,8 @@ func Raise(max uint64) (uint64, error) { // Current retrieves the number of file descriptors allowed to be opened by this // process. func Current() (int, error) { - var limit syscall.Rlimit - if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &limit); err != nil { + var limit unix.Rlimit + if err := unix.Getrlimit(unix.RLIMIT_NOFILE, &limit); err != nil { return 0, err } return int(limit.Cur), nil @@ -59,8 +59,8 @@ func Current() (int, error) { // allowed to request for itself. func Maximum() (int, error) { // Retrieve the maximum allowed by dynamic OS limits - var limit syscall.Rlimit - if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &limit); err != nil { + var limit unix.Rlimit + if err := unix.Getrlimit(unix.RLIMIT_NOFILE, &limit); err != nil { return 0, err } // Cap it to OPEN_MAX (10240) because macos is a special snowflake diff --git a/common/fdlimit/fdlimit_unix.go b/common/fdlimit/fdlimit_unix.go index a1f388ebb78d..ce6bd41bceb2 100644 --- a/common/fdlimit/fdlimit_unix.go +++ b/common/fdlimit/fdlimit_unix.go @@ -19,15 +19,15 @@ package fdlimit -import "syscall" +import "golang.org/x/sys/unix" // Raise tries to maximize the file descriptor allowance of this process // to the maximum hard-limit allowed by the OS. // Returns the size it was set to (may differ from the desired 'max') func Raise(max uint64) (uint64, error) { // Get the current limit - var limit syscall.Rlimit - if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &limit); err != nil { + var limit unix.Rlimit + if err := unix.Getrlimit(unix.RLIMIT_NOFILE, &limit); err != nil { return 0, err } // Try to update the limit to the max allowance @@ -35,11 +35,11 @@ func Raise(max uint64) (uint64, error) { if limit.Cur > max { limit.Cur = max } - if err := syscall.Setrlimit(syscall.RLIMIT_NOFILE, &limit); err != nil { + if err := unix.Setrlimit(unix.RLIMIT_NOFILE, &limit); err != nil { return 0, err } // MacOS can silently apply further caps, so retrieve the actually set limit - if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &limit); err != nil { + if err := unix.Getrlimit(unix.RLIMIT_NOFILE, &limit); err != nil { return 0, err } return limit.Cur, nil @@ -48,8 +48,8 @@ func Raise(max uint64) (uint64, error) { // Current retrieves the number of file descriptors allowed to be opened by this // process. func Current() (int, error) { - var limit syscall.Rlimit - if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &limit); err != nil { + var limit unix.Rlimit + if err := unix.Getrlimit(unix.RLIMIT_NOFILE, &limit); err != nil { return 0, err } return int(limit.Cur), nil @@ -58,8 +58,8 @@ func Current() (int, error) { // Maximum retrieves the maximum number of file descriptors this process is // allowed to request for itself. func Maximum() (int, error) { - var limit syscall.Rlimit - if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &limit); err != nil { + var limit unix.Rlimit + if err := unix.Getrlimit(unix.RLIMIT_NOFILE, &limit); err != nil { return 0, err } return int(limit.Max), nil diff --git a/console/console.go b/console/console.go index 78706860e0cb..0b1b21165183 100644 --- a/console/console.go +++ b/console/console.go @@ -27,7 +27,6 @@ import ( "sort" "strings" "sync" - "syscall" "github.com/dop251/goja" "github.com/ethereum/go-ethereum/console/prompt" @@ -37,6 +36,7 @@ import ( "github.com/ethereum/go-ethereum/rpc" "github.com/mattn/go-colorable" "github.com/peterh/liner" + "golang.org/x/sys/unix" ) var ( @@ -371,7 +371,7 @@ func (c *Console) interruptHandler() { // Unfortunately, it is not possible to abort the prompt in this case and // the c.readLines goroutine leaks. sig := make(chan os.Signal, 1) - signal.Notify(sig, syscall.SIGINT) + signal.Notify(sig, unix.SIGINT) defer signal.Stop(sig) for { diff --git a/internal/cmdtest/test_cmd.go b/internal/cmdtest/test_cmd.go index fd7a4a8b7f4c..3abdb1fe8b5d 100644 --- a/internal/cmdtest/test_cmd.go +++ b/internal/cmdtest/test_cmd.go @@ -27,12 +27,12 @@ import ( "strings" "sync" "sync/atomic" - "syscall" "testing" "text/template" "time" "github.com/docker/docker/pkg/reexec" + "golang.org/x/sys/unix" ) func NewTestCmd(t *testing.T, data interface{}) *TestCmd { @@ -208,7 +208,7 @@ func (tt *TestCmd) ExitStatus() int { if tt.Err != nil { exitErr := tt.Err.(*exec.ExitError) if exitErr != nil { - if status, ok := exitErr.Sys().(syscall.WaitStatus); ok { + if status, ok := exitErr.Sys().(unix.WaitStatus); ok { return status.ExitStatus() } } diff --git a/metrics/cputime_unix.go b/metrics/cputime_unix.go index 3c56a75d0077..3948ef6f8882 100644 --- a/metrics/cputime_unix.go +++ b/metrics/cputime_unix.go @@ -20,15 +20,14 @@ package metrics import ( - syscall "golang.org/x/sys/unix" - "github.com/ethereum/go-ethereum/log" + "golang.org/x/sys/unix" ) // getProcessCPUTime retrieves the process' CPU time since program startup. func getProcessCPUTime() int64 { - var usage syscall.Rusage - if err := syscall.Getrusage(syscall.RUSAGE_SELF, &usage); err != nil { + var usage unix.Rusage + if err := unix.Getrusage(unix.RUSAGE_SELF, &usage); err != nil { log.Warn("Failed to retrieve CPU time", "err", err) return 0 } diff --git a/node/errors.go b/node/errors.go index 67547bf691f1..6855c8ad6103 100644 --- a/node/errors.go +++ b/node/errors.go @@ -20,7 +20,8 @@ import ( "errors" "fmt" "reflect" - "syscall" + + "golang.org/x/sys/unix" ) var ( @@ -33,7 +34,7 @@ var ( ) func convertFileLockError(err error) error { - if errno, ok := err.(syscall.Errno); ok && datadirInUseErrnos[uint(errno)] { + if errno, ok := err.(unix.Errno); ok && datadirInUseErrnos[uint(errno)] { return ErrDatadirUsed } return err diff --git a/p2p/netutil/toobig_windows.go b/p2p/netutil/toobig_windows.go index 652903e83c30..128150f7bd1f 100644 --- a/p2p/netutil/toobig_windows.go +++ b/p2p/netutil/toobig_windows.go @@ -22,10 +22,11 @@ package netutil import ( "net" "os" - "syscall" + + "golang.org/x/sys/unix" ) -const _WSAEMSGSIZE = syscall.Errno(10040) +const _WSAEMSGSIZE = unix.Errno(10040) // isPacketTooBig reports whether err indicates that a UDP packet didn't // fit the receive buffer. On Windows, WSARecvFrom returns diff --git a/p2p/simulations/adapters/exec.go b/p2p/simulations/adapters/exec.go index 35ccdfb06882..d6d8de89fc69 100644 --- a/p2p/simulations/adapters/exec.go +++ b/p2p/simulations/adapters/exec.go @@ -31,7 +31,6 @@ import ( "path/filepath" "strings" "sync" - "syscall" "time" "github.com/docker/docker/pkg/reexec" @@ -41,6 +40,7 @@ import ( "github.com/ethereum/go-ethereum/p2p/enode" "github.com/ethereum/go-ethereum/rpc" "github.com/gorilla/websocket" + "golang.org/x/sys/unix" ) func init() { @@ -295,7 +295,7 @@ func (n *ExecNode) Stop() error { n.Info = nil } - if err := n.Cmd.Process.Signal(syscall.SIGTERM); err != nil { + if err := n.Cmd.Process.Signal(unix.SIGTERM); err != nil { return n.Cmd.Process.Kill() } waitErr := make(chan error, 1) @@ -438,7 +438,7 @@ func execP2PNode() { // Stop the stack if we get a SIGTERM signal. go func() { sigc := make(chan os.Signal, 1) - signal.Notify(sigc, syscall.SIGTERM) + signal.Notify(sigc, unix.SIGTERM) defer signal.Stop(sigc) <-sigc log.Info("Received SIGTERM, shutting down...") From 18c3921865cbc6b77caa3af5b4dc10ee7fb854d5 Mon Sep 17 00:00:00 2001 From: paul-ahn-wm Date: Thu, 23 May 2024 14:36:01 +0900 Subject: [PATCH 02/16] Fix: fix DockerFiles --- Dockerfile.wemix | 102 +++++++++++++++++++++++----- containers/docker/wemix/Dockerfile | 105 ++++++++++++++++++++++++----- 2 files changed, 172 insertions(+), 35 deletions(-) diff --git a/Dockerfile.wemix b/Dockerfile.wemix index 632e6ce193e0..c130bd9529b8 100644 --- a/Dockerfile.wemix +++ b/Dockerfile.wemix @@ -1,24 +1,92 @@ -# builder image +# Stage 1: Build stage +FROM golang:1.19 as builder -FROM ubuntu:focal as base +# Set environment variables +ENV PATH=/usr/local/go/bin:$PATH -SHELL ["/bin/bash", "-c"] +# Update and upgrade the package list +RUN apt-get update && \ + apt-get upgrade -q -y -RUN apt-get update -q -y && apt-get upgrade -q -y -RUN DEBIAN_FRONTEND=noninteractive apt-get install -y tzdata -RUN DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends build-essential ca-certificates curl libjemalloc-dev liblz4-dev libsnappy-dev libzstd-dev libudev-dev git +# Install required packages +RUN apt-get install -y --no-install-recommends \ + git \ + ca-certificates \ + openssl \ + make && \ + rm -rf /var/lib/apt/lists/* -# golang -RUN curl -sL -o /tmp/go.tar.gz https://dl.google.com/go/$(curl -sL https://golang.org/VERSION?m=text | head -1).linux-amd64.tar.gz && \ - pushd /usr/local/ && \ - tar xfz /tmp/go.tar.gz && \ - cd /usr/local/bin/ && \ - ln -sf ../go/bin/* . && \ - popd && \ - rm /tmp/go.tar.gz +# Define the location for custom certificates +ARG cert_location=/usr/local/share/ca-certificates -RUN apt autoremove && apt autoclean +# Fetch and install certificates for github.com and proxy.golang.org +RUN openssl s_client -showcerts -connect github.com:443 /dev/null | \ + openssl x509 -outform PEM > ${cert_location}/github.crt && \ + openssl s_client -showcerts -connect proxy.golang.org:443 /dev/null | \ + openssl x509 -outform PEM > ${cert_location}/proxy.golang.crt && \ + update-ca-certificates -ENTRYPOINT ["/bin/bash", "-c"] +# Clone the repository, install dependencies, and build the project +RUN git clone https://github.com/wemixarchive/go-wemix.git /go-wemix && \ + cd /go-wemix && \ + go mod download && \ + make -# EOF +# Clean up unnecessary packages and files after building +RUN apt-get remove -y \ + git \ + ca-certificates \ + openssl \ + make && \ + apt autoremove -y && \ + apt-get clean + +# Stage 2: Runtime stage +FROM ubuntu:22.04 + +# Set environment variables +ENV SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt + +# Update and upgrade the package list +RUN apt-get update && \ + apt-get upgrade -q -y + +# Install required runtime packages +RUN apt-get install -y --no-install-recommends \ + g++ \ + libc-dev \ + ca-certificates \ + bash \ + wget && \ + update-ca-certificates && \ + rm -rf /var/lib/apt/lists/* + +# Create directories for wemix +RUN mkdir -p /usr/local/wemix /usr/local/wemix/keystore + +# Copy the built binaries and configuration files from the builder stage +COPY --from=builder /go-wemix/build /usr/local/wemix/ + +# Download and install solc +RUN wget -nv -O /usr/local/bin/solc https://github.com/ethereum/solidity/releases/download/v0.4.24/solc-static-linux && \ + chmod a+x /usr/local/bin/solc + +# Create new accounts for wemix +RUN bash -c 'for i in 1 2 3 4; do \ + /usr/local/wemix/bin/gwemix wemix new-account --password <(echo demo) --out /usr/local/wemix/keystore/account-$i; \ +done' + +# Clean up unnecessary packages +RUN apt-get remove -y \ + g++ \ + libc-dev \ + wget && \ + apt autoremove -y && \ + apt-get clean + +# Expose necessary ports +EXPOSE 10009 +EXPOSE 10010 + +# Set the entrypoint +ENTRYPOINT ["/usr/local/wemix/bin/gwemix"] \ No newline at end of file diff --git a/containers/docker/wemix/Dockerfile b/containers/docker/wemix/Dockerfile index 662ec9c997ab..c130bd9529b8 100644 --- a/containers/docker/wemix/Dockerfile +++ b/containers/docker/wemix/Dockerfile @@ -1,23 +1,92 @@ -FROM ubuntu:xenial - -ENV PATH=/usr/lib/go-1.9/bin:$PATH - -RUN /bin/bash -c '\ - apt-get update && apt-get upgrade -q -y && \ - apt-get install -y --no-install-recommends golang-1.9 git make gcc libc-dev ca-certificates wget && \ - git clone https://github.com/wemix3/go-wemix && \ - (cd go-wemix && make) && \ - mkdir -p /usr/local/wemix /usr/local/wemix/keystore && \ - cp -r go-wemix/build/bin go-wemix/build/conf /usr/local/wemix/ && \ - /usr/bin/wget -nv -O /usr/local/bin/solc https://github.com/ethereum/solidity/releases/download/v0.4.24/solc-static-linux && \ - chmod a+x /usr/local/bin/solc && \ - for i in 1 2 3 4; do \ +# Stage 1: Build stage +FROM golang:1.19 as builder + +# Set environment variables +ENV PATH=/usr/local/go/bin:$PATH + +# Update and upgrade the package list +RUN apt-get update && \ + apt-get upgrade -q -y + +# Install required packages +RUN apt-get install -y --no-install-recommends \ + git \ + ca-certificates \ + openssl \ + make && \ + rm -rf /var/lib/apt/lists/* + +# Define the location for custom certificates +ARG cert_location=/usr/local/share/ca-certificates + +# Fetch and install certificates for github.com and proxy.golang.org +RUN openssl s_client -showcerts -connect github.com:443 /dev/null | \ + openssl x509 -outform PEM > ${cert_location}/github.crt && \ + openssl s_client -showcerts -connect proxy.golang.org:443 /dev/null | \ + openssl x509 -outform PEM > ${cert_location}/proxy.golang.crt && \ + update-ca-certificates + +# Clone the repository, install dependencies, and build the project +RUN git clone https://github.com/wemixarchive/go-wemix.git /go-wemix && \ + cd /go-wemix && \ + go mod download && \ + make + +# Clean up unnecessary packages and files after building +RUN apt-get remove -y \ + git \ + ca-certificates \ + openssl \ + make && \ + apt autoremove -y && \ + apt-get clean + +# Stage 2: Runtime stage +FROM ubuntu:22.04 + +# Set environment variables +ENV SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt + +# Update and upgrade the package list +RUN apt-get update && \ + apt-get upgrade -q -y + +# Install required runtime packages +RUN apt-get install -y --no-install-recommends \ + g++ \ + libc-dev \ + ca-certificates \ + bash \ + wget && \ + update-ca-certificates && \ + rm -rf /var/lib/apt/lists/* + +# Create directories for wemix +RUN mkdir -p /usr/local/wemix /usr/local/wemix/keystore + +# Copy the built binaries and configuration files from the builder stage +COPY --from=builder /go-wemix/build /usr/local/wemix/ + +# Download and install solc +RUN wget -nv -O /usr/local/bin/solc https://github.com/ethereum/solidity/releases/download/v0.4.24/solc-static-linux && \ + chmod a+x /usr/local/bin/solc + +# Create new accounts for wemix +RUN bash -c 'for i in 1 2 3 4; do \ /usr/local/wemix/bin/gwemix wemix new-account --password <(echo demo) --out /usr/local/wemix/keystore/account-$i; \ - done && \ - apt-get remove -y golang-1.9 git make gcc libc-dev wget && apt autoremove -y && apt-get clean && \ - rm -rf /go-wemix' +done' + +# Clean up unnecessary packages +RUN apt-get remove -y \ + g++ \ + libc-dev \ + wget && \ + apt autoremove -y && \ + apt-get clean +# Expose necessary ports EXPOSE 10009 EXPOSE 10010 -ENTRYPOINT ["/bin/bash"] +# Set the entrypoint +ENTRYPOINT ["/usr/local/wemix/bin/gwemix"] \ No newline at end of file From 1067c615a9cc99b62f7f195b28409f11fd613daa Mon Sep 17 00:00:00 2001 From: paul-ahn-wm Date: Thu, 23 May 2024 16:03:21 +0900 Subject: [PATCH 03/16] Fix: fix exitstatus fn --- internal/cmdtest/test_cmd.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/internal/cmdtest/test_cmd.go b/internal/cmdtest/test_cmd.go index 3abdb1fe8b5d..b9942e2e5a26 100644 --- a/internal/cmdtest/test_cmd.go +++ b/internal/cmdtest/test_cmd.go @@ -32,7 +32,6 @@ import ( "time" "github.com/docker/docker/pkg/reexec" - "golang.org/x/sys/unix" ) func NewTestCmd(t *testing.T, data interface{}) *TestCmd { @@ -208,9 +207,7 @@ func (tt *TestCmd) ExitStatus() int { if tt.Err != nil { exitErr := tt.Err.(*exec.ExitError) if exitErr != nil { - if status, ok := exitErr.Sys().(unix.WaitStatus); ok { - return status.ExitStatus() - } + return exitErr.ProcessState.ExitCode() } } return 0 From 3e13bd8aeda50c6d94d12731272f159cc899d0e4 Mon Sep 17 00:00:00 2001 From: kai-yu-wm Date: Thu, 23 May 2024 16:52:15 +0900 Subject: [PATCH 04/16] Fix: fix docker-compose.yml --- Dockerfile.wemix | 6 +- containers/docker/wemix/Dockerfile | 6 +- containers/docker/wemix/docker-compose.yml | 81 +++- containers/docker/wemix/testdata/.rc | 2 + containers/docker/wemix/testdata/bootnode.sh | 25 ++ containers/docker/wemix/testdata/config.json | 69 +++ .../wemix/testdata/deploy-governance.js | 420 ++++++++++++++++++ containers/docker/wemix/testdata/genesis.json | 42 ++ containers/docker/wemix/testdata/gwemix.sh | 349 +++++++++++++++ .../docker/wemix/testdata/keystore/account1 | 1 + .../docker/wemix/testdata/keystore/account2 | 1 + .../docker/wemix/testdata/keystore/account3 | 1 + .../wemix/testdata/keystore/maintenance | 1 + .../docker/wemix/testdata/nodekey/nodekey1 | 1 + .../docker/wemix/testdata/nodekey/nodekey2 | 1 + .../docker/wemix/testdata/nodekey/nodekey3 | 1 + 16 files changed, 984 insertions(+), 23 deletions(-) create mode 100644 containers/docker/wemix/testdata/.rc create mode 100755 containers/docker/wemix/testdata/bootnode.sh create mode 100644 containers/docker/wemix/testdata/config.json create mode 100644 containers/docker/wemix/testdata/deploy-governance.js create mode 100644 containers/docker/wemix/testdata/genesis.json create mode 100755 containers/docker/wemix/testdata/gwemix.sh create mode 100644 containers/docker/wemix/testdata/keystore/account1 create mode 100644 containers/docker/wemix/testdata/keystore/account2 create mode 100644 containers/docker/wemix/testdata/keystore/account3 create mode 100644 containers/docker/wemix/testdata/keystore/maintenance create mode 100644 containers/docker/wemix/testdata/nodekey/nodekey1 create mode 100644 containers/docker/wemix/testdata/nodekey/nodekey2 create mode 100644 containers/docker/wemix/testdata/nodekey/nodekey3 diff --git a/Dockerfile.wemix b/Dockerfile.wemix index c130bd9529b8..3001685fc0f5 100644 --- a/Dockerfile.wemix +++ b/Dockerfile.wemix @@ -64,6 +64,9 @@ RUN apt-get install -y --no-install-recommends \ # Create directories for wemix RUN mkdir -p /usr/local/wemix /usr/local/wemix/keystore +# Set environment variables +ENV PATH=/usr/local/wemix/bin:$PATH + # Copy the built binaries and configuration files from the builder stage COPY --from=builder /go-wemix/build /usr/local/wemix/ @@ -85,8 +88,7 @@ RUN apt-get remove -y \ apt-get clean # Expose necessary ports -EXPOSE 10009 -EXPOSE 10010 +EXPOSE 8588 8589 8598 # Set the entrypoint ENTRYPOINT ["/usr/local/wemix/bin/gwemix"] \ No newline at end of file diff --git a/containers/docker/wemix/Dockerfile b/containers/docker/wemix/Dockerfile index c130bd9529b8..3001685fc0f5 100644 --- a/containers/docker/wemix/Dockerfile +++ b/containers/docker/wemix/Dockerfile @@ -64,6 +64,9 @@ RUN apt-get install -y --no-install-recommends \ # Create directories for wemix RUN mkdir -p /usr/local/wemix /usr/local/wemix/keystore +# Set environment variables +ENV PATH=/usr/local/wemix/bin:$PATH + # Copy the built binaries and configuration files from the builder stage COPY --from=builder /go-wemix/build /usr/local/wemix/ @@ -85,8 +88,7 @@ RUN apt-get remove -y \ apt-get clean # Expose necessary ports -EXPOSE 10009 -EXPOSE 10010 +EXPOSE 8588 8589 8598 # Set the entrypoint ENTRYPOINT ["/usr/local/wemix/bin/gwemix"] \ No newline at end of file diff --git a/containers/docker/wemix/docker-compose.yml b/containers/docker/wemix/docker-compose.yml index 1773a3e8b5e7..b180cc458fc3 100644 --- a/containers/docker/wemix/docker-compose.yml +++ b/containers/docker/wemix/docker-compose.yml @@ -1,34 +1,77 @@ -version: "3" services: wemix1: - container_name: wemix1 + build: + context: . + dockerfile: Dockerfile + image: wemix/node-demo:latest hostname: wemix1 - stdin_open: true + networks: + wemix_bridge: + ipv4_address: 172.16.237.11 + restart: unless-stopped tty: true - build: . - image: wemix/multinode-demo:latest volumes: - - ".:/opt" - entrypoint: ["/usr/local/wemix/bin/gwemix-demo.sh", "start-leader", "wemix1", "wemix2", "wemix3"] + - /etc/localtime:/etc/localtime:ro + - ./testdata/bootnode.sh:/usr/local/wemix/bin/bootnode.sh:ro + - ./testdata/gwemix.sh:/usr/local/wemix/bin/gwemix.sh:ro + - ./testdata/config.json:/usr/local/wemix/conf/config.json:ro + - ./testdata/deploy-governance.js:/usr/local/wemix/conf/deploy-governance.js:ro + - ./testdata/genesis.json:/usr/local/wemix/genesis.json:ro + - ./testdata/.rc:/usr/local/wemix/.rc:ro + - ./testdata/keystore:/usr/local/wemix/keystore + - ./testdata/nodekey/nodekey1:/usr/local/wemix/geth/nodekey:ro + ports: + - 8588:8588 + - 8589:8589 + - 8598:8598 + container_name: wemix1 + entrypoint: ["sh", "-c", "bootnode.sh && sleep 5 && tail -f /usr/local/wemix/logs/log"] wemix2: - container_name: wemix2 + image: wemix/node-demo:latest hostname: wemix2 - stdin_open: true + networks: + wemix_bridge: + ipv4_address: 172.16.237.12 + restart: unless-stopped tty: true - image: wemix/multinode-demo:latest depends_on: - - wemix1 + wemix1: + condition: service_started volumes: - - ".:/opt" - entrypoint: ["/usr/local/wemix/bin/gwemix-demo.sh", "start"] + - /etc/localtime:/etc/localtime:ro + - ./testdata/gwemix.sh:/usr/local/wemix/bin/gwemix.sh:ro + - ./testdata/genesis.json:/usr/local/wemix/genesis.json:ro + - ./testdata/.rc:/usr/local/wemix/.rc:ro + - ./testdata/keystore/account2:/usr/local/wemix/keystore/account2 + - ./testdata/nodekey/nodekey2:/usr/local/wemix/geth/nodekey:ro + container_name: wemix2 + entrypoint: ["sh", "-c", "gwemix.sh start && sleep 5 && tail -f /usr/local/wemix/logs/log"] wemix3: - container_name: wemix3 + image: wemix/node-demo:latest hostname: wemix3 - stdin_open: true + networks: + wemix_bridge: + ipv4_address: 172.16.237.13 + restart: unless-stopped tty: true - image: wemix/multinode-demo:latest depends_on: - - wemix1 + wemix1: + condition: service_started volumes: - - ".:/opt" - entrypoint: ["/usr/local/wemix/bin/gwemix-demo.sh", "start"] + - /etc/localtime:/etc/localtime:ro + - ./testdata/gwemix.sh:/usr/local/wemix/bin/gwemix.sh:ro + - ./testdata/genesis.json:/usr/local/wemix/genesis.json:ro + - ./testdata/.rc:/usr/local/wemix/.rc:ro + - ./testdata/keystore/account3:/usr/local/wemix/keystore/account3 + - ./testdata/nodekey/nodekey3:/usr/local/wemix/geth/nodekey:ro + container_name: wemix3 + entrypoint: ["sh", "-c", "gwemix.sh start && sleep 5 && tail -f /usr/local/wemix/logs/log"] + +networks: + wemix_bridge: + name: wemix_bridge + driver: bridge + ipam: + driver: default + config: + - subnet: 172.16.237.0/24 diff --git a/containers/docker/wemix/testdata/.rc b/containers/docker/wemix/testdata/.rc new file mode 100644 index 000000000000..792df1fb93df --- /dev/null +++ b/containers/docker/wemix/testdata/.rc @@ -0,0 +1,2 @@ +PORT=8588 +DISCOVER=0 \ No newline at end of file diff --git a/containers/docker/wemix/testdata/bootnode.sh b/containers/docker/wemix/testdata/bootnode.sh new file mode 100755 index 000000000000..cba2bcf17303 --- /dev/null +++ b/containers/docker/wemix/testdata/bootnode.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +cd $(dirname ${BASH_SOURCE[0]})/.. + +gwemix.sh start +sleep 5 + +RESULT=$(gwemix --exec "admin.wemixInfo.etcd" attach gwemix.ipc) + +if [[ "$RESULT" == "Fatal:"* ]]; then + echo "Failed to start gwemix!" + exit 1 +elif [[ "$RESULT" == "{}" ]]; then + echo "Initailize governance" + + gwemix.sh init-gov wemix conf/config.json + sleep 5 + + gwemix --exec "admin.wemixInfo" attach gwemix.ipc + gwemix --exec "admin.etcdInit()" attach gwemix.ipc # Initialize etcd + sleep 5 + gwemix --exec "admin.wemixInfo.etcd" attach gwemix.ipc +fi + +echo "Started gwemix!" \ No newline at end of file diff --git a/containers/docker/wemix/testdata/config.json b/containers/docker/wemix/testdata/config.json new file mode 100644 index 000000000000..74b5e54acb81 --- /dev/null +++ b/containers/docker/wemix/testdata/config.json @@ -0,0 +1,69 @@ +{ + "extraData": "The beginning of Wemix3.0 localnet", + "staker": "0xf00d9928ed1dada205aec56ab85e0e2ab5670ad5", + "ecosystem": "0x92875d5ba8b104c375a471d58a6de4f75ccb431f", + "maintenance": "0x2c77f2c8997182e31a19ec48e321f4d09f36819e", + "feecollector": "0x2c77f2c8997182e31a19ec48e321f4d09f36819e", + "env": { + "ballotDurationMin": 86400, + "ballotDurationMax": 604800, + "stakingMin": 1500000000000000000000000, + "stakingMax": 1500000000000000000000000, + "MaxIdleBlockInterval": 100, + "blockCreationTime": 5000, + "blockRewardAmount": 1000000000000000000, + "maxPriorityFeePerGas": 100000000000, + "rewardDistributionMethod": [ 4000, 1000, 2500, 2500 ], + "maxBaseFee": 50000000000000, + "blockGasLimit": 105000000, + "baseFeeMaxChangeRate": 55, + "gasTargetPercentage": 30 + }, + "members": [ + { + "addr": "0x92875d5ba8b104c375a471d58a6de4f75ccb431f", + "stake": 1500000000000000000000000, + "name": "node1", + "id": "0xe4dfe854223c1b85ea7962cd724d98eec1863a49847eb749bc5caa519104713c78a972ebf263b13329ceb8a7b5959125ab6e9a3c73c15f659cc1291d0a7aae1e", + "ip": "172.16.237.11", + "port": 8589, + "bootnode": true + }, + { + "addr": "0xb61544371ef73161496009a77989da30f8f91867", + "stake": 1500000000000000000000000, + "name": "node2", + "id": "0x4b8b229f97bbe68fa7cfc43e357fe74503733d0cc236b8d176d896f33547d8fcfd59daa0b4f9e1a4e83157adf1a386ea314dfb9a3e6efe747948fa5e10d5fff5", + "ip": "172.16.237.12", + "port": 8589, + "bootnode": false + }, + { + "addr": "0x708ebe75a5dbc5f56176db6e84ce5740897e8a17", + "stake": 1500000000000000000000000, + "name": "node3", + "id": "0xa6f08d187a8da5d76f072b0f0d114e1469e77a53713b710177bd6206b16331b8ead7d41bdeec1df3bb0bb56de8f102e86ecaf44bb6affb4383151c603ff5ac10", + "ip": "172.16.237.13", + "port": 8589, + "bootnode": false + } + ], + "accounts": [ + { + "addr": "0x92875d5ba8b104c375a471d58a6de4f75ccb431f", + "balance": 2000000000000000000000000 + }, + { + "addr": "0xb61544371ef73161496009a77989da30f8f91867", + "balance": 2000000000000000000000000 + }, + { + "addr": "0x708ebe75a5dbc5f56176db6e84ce5740897e8a17", + "balance": 2000000000000000000000000 + }, + { + "addr": "0x2c77f2c8997182e31a19ec48e321f4d09f36819e", + "balance": 2000000000000000000000000 + } + ] +} \ No newline at end of file diff --git a/containers/docker/wemix/testdata/deploy-governance.js b/containers/docker/wemix/testdata/deploy-governance.js new file mode 100644 index 000000000000..5add63dd15b2 --- /dev/null +++ b/containers/docker/wemix/testdata/deploy-governance.js @@ -0,0 +1,420 @@ +// deploy-governance.js + +// uses offline wallet +var GovernanceDeployer = new function() { + this.wallet = ["keystore/account1", "keystore/account2", "keystore/account3"] + this.account = [] + this.from = null + this.gas = 21000 * 1400 + this.gasPrice = eth.gasPrice + this._nonce = [] + this.receiptCheckParams = { "interval": 100, "count": 300 } + + // bool log(var args...) + this.log = function() { + var msg = "" + for (var i in arguments) { + if (msg.length > 0) + msg += " " + msg += arguments[i] + } + console.log(msg) + return true + } + + // void verifyCfg(json data) + // verifies config data, and normalize addresses + // throws exception on failure + this.verifyCfg = function(data) { + if (data.accounts.length == 0 || data.members.length == 0) + throw "At least one account and node are required" + var bootnodeExists = false + for (var i in data.members) { + var m = data.members[i] + if (!web3.isAddress(m.addr)) + throw "Invalid address 1 " + m.addr + data.members[i].addr = web3.toChecksumAddress(m.addr) + if (m.bootnode) + bootnodeExists = true + } + if (!bootnodeExists) + throw "Bootnode is not designated" + for (var i in data.accounts) { + var a = data.accounts[i] + if (!web3.isAddress(a.addr)) + throw "Invalid address " + a.addr + data.accounts[i].addr = web3.toChecksumAddress(a.addr) + } + if (data.staker) { + if (!web3.isAddress(data.staker)) + throw "Invalid staker address " + data.staker + data.staker = web3.toChecksumAddress(data.staker) + } + if (data.ecosystem) { + if (!web3.isAddress(data.ecosystem)) + throw "Invalid ecosystem address " + data.ecosystem + data.ecosystem = web3.toChecksumAddress(data.ecosystem) + } + if (data.maintenance) { + if (!web3.isAddress(data.maintenance)) + throw "Invalid maintenance address " + data.maintenance + data.maintenance = web3.toChecksumAddress(data.maintenance) + } + if (data.feecollector) { + if (!web3.isAddress(data.feecollector)) + throw "Invalid feecollector address " + data.feecollector + data.feecollector = web3.toChecksumAddress(data.feecollector) + } + } + + // bytes packNum(int num) + // pack a number into 256 bit bytes + this.packNum = function(num) { + return web3.padLeft(web3.toHex(num).substr(2), 64, "0") + } + + // { "nodes": string, "stakes": string, "staker": address, + // "ecosystem": address, "maintenance": address, "feecollector": address, + // "env": { env variables } } + // getInitialGovernanceMembersAndNodes(json data) + this.getInitialGovernanceMembersAndNodes = function(data) { + var nodes = "0x", stakes = "0x" + + for (var i = 0, l = data.members.length; i < l; i++) { + var m = data.members[i], id + if (m.id.length != 128 && m.id.length != 130) + throw "Invalid enode id " + m.id + id = m.id.length == 128 ? m.id : m.id.substr(2) + if (m.addr) { + if (m.addr.indexOf("0x") == 0) + m.addr = m.addr.substr(2) + if (!m.staker) + m.staker = m.addr + if (!m.voter) + m.voter = m.addr + if (!m.reward) + m.reward = m.addr + } + if (m.staker) { + if (m.staker.indexOf("0x") == 0) + m.staker = m.staker.substr(2) + if (!m.addr) + m.addr = m.staker + if (!m.voter) + m.voter = m.staker + if (!m.reward) + m.reward = m.staker + } + if (!m.addr && !m.staker) + throw "Address & staker are missing" + nodes += web3.padLeft(m.staker, 64, "0") + + web3.padLeft(m.voter, 64, "0") + + web3.padLeft(m.reward, 64, "0") + + this.packNum(m.name.length) + web3.fromAscii(m.name).substr(2) + + this.packNum(id.length/2) + id + + this.packNum(m.ip.length) + web3.fromAscii(m.ip).substr(2) + + this.packNum(m.port) + + stakes += web3.padLeft(m.staker, 64, "0") + + this.packNum(m.stake) + } + return { + "nodes": nodes, + "stakes": stakes, + "staker": data.staker, + "ecosystem": data.ecosystem, + "maintenance": data.maintenance, + "feecollector": data.feecollector, + "env": data.env + } + } + + this.nonce = function(index) { + return this._nonce[index]++ + } + + // returns transaction hash, or throws error + this.deployContract = function(data) { + var tx = { + from: this.from, + data: data, + gas: this.gas, + gasPrice: this.gasPrice, + nonce: this.nonce(0) + } + var stx = offlineWalletSignTx(this.account[0].id, tx, eth.chainId()) + return eth.sendRawTransaction(stx) + } + + // wait for transaction receipt for contract address, then + // load a contract + // Contract resolveContract(ABI abi, hash txh) + this.resolveContract = function(abi, txh) { + for (var i = 0; i < this.receiptCheckParams.count; i++ ) { + var r = eth.getTransactionReceipt(txh) + if (r != null && r.contractAddress != null) { + var ctr = web3.eth.contract(abi).at(r.contractAddress) + ctr.transactionHash = txh + return ctr + } + msleep(this.receiptCheckParams.interval) + } + throw "Cannot get contract address for " + txh + } + + // sends a simple or method transaction, returns transaction hash + this.sendTx = function(to, value, data) { + var tx = {from:this.from, to:to, gas:this.gas, + gasPrice:this.gasPrice, nonce:this.nonce(0)} + if (value) + tx.value = value + if (data) + tx.data = data + var stx = offlineWalletSignTx(this.account[0].id, tx, eth.chainId()) + return eth.sendRawTransaction(stx) + } + + this.checkReceipt = function(tx) { + for (var i = 0; i < this.receiptCheckParams.count; i++ ) { + var r = eth.getTransactionReceipt(tx) + if (r != null) + return web3.toBigNumber(r.status) == 1 + msleep(this.receiptCheckParams.interval) + } + return false + //throw "Cannot get a transaction receipt for " + tx + } + + this.sendStakingDeposit = function (from, nonce, to, data, stake) { + this.log("staker addr = " + from.address) + var tx = { from: from.address, to: to, gas: this.gas, gasPrice: this.gasPrice, nonce: nonce, value: "0" } + tx.value = stake + if (data) tx.data = data + var stx = offlineWalletSignTx(from.id, tx, eth.chainId()) + + return eth.sendRawTransaction(stx) + } + + // bool deploy(string walletUrl, string password, string cfg) + this.deploy = function(cfg, doInitOnce) { + for (var i = 0; i < this.wallet.length; i++) { + w = offlineWalletOpen(this.wallet[i], "1") + if (!w || !w.id || !w.address) { + throw "Offline wallet is not loaded" + } + this.account[i] = w + this._nonce[i] = eth.getTransactionCount(this.account[i].address, 'pending') + } + this.from = this.account[0].address + + var data + if (!(data = loadFile(cfg))) + throw "cannot load governance contract .js or config .json file" + + // check if contracts exist + var contractNames = [ "Registry", "EnvStorageImp", "Staking", "StakingImp", + "BallotStorage", "EnvStorage", "GovImp", "Gov" ] + for (var i in contractNames) { + var cn = contractNames[i] + if (eval("typeof " + cn + "_data") == "undefined" || + eval("typeof " + cn + "_contract") == "undefined") + throw cn + " not found" + } + + // check config.js + eval("var data = " + data) + this.verifyCfg(data) + + // initial members and nodes data + var initData = this.getInitialGovernanceMembersAndNodes(data) + + // bootnode + var bootNode = { + "name": web3.fromAscii(data.members[0].name), + "id": data.members[0].id, + "ip": web3.fromAscii(data.members[0].ip), + "port": data.members[0].port, + "stake": data.members[0].stake + } + + // contacts, transactions to be deployed + var registry, envStorageImp, staking, stakingImp, ballotStorage, envStorage, govImp, gov + var txs = new Array() + + // 1. deploy Registry and EnvStorageImp contracts + this.log("Deploying Registry and EnvStorageImp...") + registry = this.deployContract(Registry_data) + envStorageImp = this.deployContract(EnvStorageImp_data) + stakingImp = this.deployContract(StakingImp_data) + + this.log("Waiting for receipts...") + envStorageImp = this.resolveContract(EnvStorageImp_contract.abi, envStorageImp) + registry = this.resolveContract(Registry_contract.abi, registry) + stakingImp = this.resolveContract(StakingImp_contract.abi, stakingImp); + + // 2. deploy Staking, BallotStorage, EnvStorage, GovImp, Gov + this.log("Deploying Staking, BallotStorage, EnvStorage, GovImp & Gov...") + var code = Staking_contract.getData(stakingImp.address, {data: Staking_data}) + staking = this.deployContract(code) + var code = BallotStorage_contract.getData(registry.address, {data: BallotStorage_data}) + ballotStorage = this.deployContract(code) + code = EnvStorage_contract.getData(envStorageImp.address, {data: EnvStorage_data}) + envStorage = this.deployContract(code) + govImp = this.deployContract(GovImp_data) + + this.log("Waiting for receipts...") + govImp = this.resolveContract(GovImp_contract.abi, govImp) + code = Gov_contract.getData(govImp.address, { data: Gov_data }) + gov = this.deployContract(code) + + this.log("Waiting for gov contract...") + gov = this.resolveContract(Gov_contract.abi, gov) + envStorage = this.resolveContract(EnvStorage_contract.abi, envStorage) + ballotStorage = this.resolveContract(BallotStorage_contract.abi, ballotStorage) + staking = this.resolveContract(Staking_contract.abi, staking) + + // 3. setup registry + this.log("Setting registry...") + txs.length = 0 + txs[txs.length] = this.sendTx(registry.address, null, + registry.setContractDomain.getData( + "Staking", staking.address)) + txs[txs.length] = this.sendTx(registry.address, null, + registry.setContractDomain.getData( + "BallotStorage", ballotStorage.address)) + txs[txs.length] = this.sendTx(registry.address, null, + registry.setContractDomain.getData( + "EnvStorage", envStorage.address)) + txs[txs.length] = this.sendTx(registry.address, null, + registry.setContractDomain.getData( + "GovernanceContract", gov.address)) + if (initData.staker) + txs[txs.length] = this.sendTx(registry.address, null, + registry.setContractDomain.getData( + "StakingReward", initData.staker)) + if (initData.ecosystem) + txs[txs.length] = this.sendTx(registry.address, null, + registry.setContractDomain.getData( + "Ecosystem", initData.ecosystem)) + if (initData.maintenance) + txs[txs.length] = this.sendTx(registry.address, null, + registry.setContractDomain.getData( + "Maintenance", initData.maintenance)) + if (initData.feecollector) + txs[txs.length] = this.sendTx(registry.address, null, + registry.setContractDomain.getData( + "FeeCollector", initData.feecollector)) + + // no need to wait for the receipts for the above + + // 4. initialize environment storage data: + this.log("Initializing environment storage...") + data.env = data.env || {} + // Just changing address doesn't work here. Address is embedded in + // the methods. Have to re-construct temporary EnvStorageImp here. + var tmpEnvStorageImp = web3.eth.contract(envStorageImp.abi).at(envStorage.address) + var envNames = [ + web3.sha3("blocksPer"), + web3.sha3("ballotDurationMin"), web3.sha3("ballotDurationMax"), + web3.sha3("stakingMin"), web3.sha3("stakingMax"), + web3.sha3("MaxIdleBlockInterval"), + web3.sha3("blockCreationTime"), + web3.sha3("blockRewardAmount"), + web3.sha3("maxPriorityFeePerGas"), + web3.sha3("blockRewardDistributionBlockProducer"), + web3.sha3("blockRewardDistributionStakingReward"), + web3.sha3("blockRewardDistributionEcosystem"), + web3.sha3("blockRewardDistributionMaintenance"), + web3.sha3("maxBaseFee"), + web3.sha3("blockGasLimit"), + web3.sha3("baseFeeMaxChangeRate"), + web3.sha3("gasTargetPercentage") ] + var rewardDistributionMethod = data.env.rewardDistributionMethod || [ 4000, 1000, 2500, 2500 ] + var envValues = [ + 1, + data.env.ballotDurationMin || 86400, + data.env.ballotDurationMax || 604800, + data.env.stakingMin || 1500000000000000000000000, + data.env.stakingMax || 1500000000000000000000000, + data.env.MaxIdleBlockInterval || 5, + data.env.blockCreationTime || 1000, + // mint amount: 1 wemix + data.env.blockRewardAmount || web3.toWei(1, 'ether'), + // tip: 100 gwei + data.env.maxPriorityFeePerGas || web3.toWei(100, 'gwei'), + // NCPs, WEMIX Staker, Eco System, Maintenance + rewardDistributionMethod[0], + rewardDistributionMethod[1], + rewardDistributionMethod[2], + rewardDistributionMethod[3], + // maxBaseFee * 21000 -> 1.05 wemix + data.env.maxBaseFee || web3.toWei(50000, 'gwei'), + data.env.blockGasLimit || 5000 * 21000, + data.env.baseFeeMaxChangeRate || 55, + data.env.gasTargetPercentage || 30 ] + txs[txs.length] = this.sendTx(envStorage.address, null, + tmpEnvStorageImp.initialize.getData(registry.address, envNames, envValues)) + + // 5. deposit staking + var tmpStakingImp = web3.eth.contract(stakingImp.abi).at(staking.address) + code = tmpStakingImp.init.getData(registry.address, + doInitOnce ? initData.stakes : "", {data: Staking_data}) + //"", {data: Staking_data}) + txs[txs.length] = this.sendTx(staking.address, null, code); + + for (var i = 1; i < this.account.length; i++) { + var d = tmpStakingImp.balanceOf.getData(this.account[i].address) + txs[txs.length] = this.sendStakingDeposit(this.account[i], this.nonce(i), staking.address, tmpStakingImp.deposit.getData(), web3.toBigNumber(bootNode.stake).toString(10)); + } + + this.log("txs.length = " + txs.length) + for(i=0;i /dev/null && pwd) + cd "$OPWD" +} + +function get_data_dir () +{ + if [ ! "$1" = "" ]; then + if [ -x "$1/bin/gwemix" ]; then + echo $1 + else + d=${WEMIX_DIR}/$1 + if [ -x "$d/bin/gwemix" ]; then + echo $d + fi + fi + else + echo $(dirname $(get_script_dir)) + fi +} + +# void init(String node, String config_json) +function init () +{ + NODE="$1" + CONFIG="$2" + + if [ ! -f "$CONFIG" ]; then + echo "Cannot find config file: $2" + return 1 + fi + + d=$(get_data_dir "${NODE}") + if [ -x "$d/bin/gwemix" ]; then + GWEMIX="$d/bin/gwemix" + else + echo "Cannot find gwemix" + return 1 + fi + + if [ ! -f "${d}/conf/genesis-template.json" ]; then + echo "Cannot find template files." + return 1 + fi + + echo "wiping out data..." + wipe $NODE + + [ -d "$d/geth" ] || mkdir -p "$d/geth" + [ -d "$d/logs" ] || mkdir -p "$d/logs" + + ${GWEMIX} wemix genesis --data "$CONFIG" --genesis "$d/conf/genesis-template.json" --out "$d/genesis.json" + [ $? = 0 ] || return $? + + echo "PORT=8588 +DISCOVER=0" > $d/.rc + ${GWEMIX} --datadir $d init $d/genesis.json + # echo "Generating dags for epoch 0 and 1..." + # ${GWEMIX} makedag 0 $d/.ethash & + # ${GWEMIX} makedag 30000 $d/.ethash & + wait +} + +# void init_gov(String node, String config_json, String account_file, bool doInitOnce) +# account_file can be +# 1. keystore file: "" +# 2. nano ledger: "ledger:" +# 3. trezor: "trezor:" +function init_gov () +{ + NODE="$1" + CONFIG="$2" + INIT_ONCE=true + + if [ ! -f "$CONFIG" ]; then + echo "Cannot find config file: $2" + return 1 + fi + + d=$(get_data_dir "${NODE}") + if [ -x "$d/bin/gwemix" ]; then + GWEMIX="$d/bin/gwemix" + else + echo "Cannot find gwemix" + return 1 + fi + + if [ ! -f "${d}/conf/WemixGovernance.js" ]; then + echo "Cannot find ${d}/conf/WemixGovernance.js" + return 1 + fi + + PORT=$(grep PORT ${d}/.rc | sed -e 's/PORT=//') + [ "$PORT" = "" ] && PORT=8588 + + exec ${GWEMIX} attach http://localhost:${PORT} --preload "$d/conf/WemixGovernance.js,$d/conf/deploy-governance.js" --exec 'GovernanceDeployer.deploy("'${CONFIG}'", '${INIT_ONCE}')' +} + +function wipe () +{ + d=$(get_data_dir "$1") + if [ ! -x "$d/bin/gwemix" ]; then + echo "Is '$1' wemix data directory?" + return + fi + + cd $d + /bin/rm -rf geth/LOCK geth/chaindata geth/ethash geth/lightchaindata \ + geth/transactions.rlp geth/nodes geth/triecache gwemix.ipc logs/* etcd +} + +function clean () +{ + d=$(get_data_dir "$1") + if [ -x "$d/bin/gwemix" ]; then + GWEMIX="$d/bin/gwemix" + else + echo "Cannot find gwemix" + return + fi + + cd $d + $GWEMIX --datadir ${PWD} removedb +} + +function start () +{ + d=$(get_data_dir "$1") + if [ -x "$d/bin/gwemix" ]; then + GWEMIX="$d/bin/gwemix" + else + echo "Cannot find gwemix" + return + fi + + [ -f "$d/.rc" ] && source "$d/.rc" + [ "$COINBASE" = "" ] && COINBASE="" || COINBASE="--miner.etherbase $COINBASE" + + RPCOPT="--http --http.addr 0.0.0.0 --mine" + [ "$PORT" = "" ] || RPCOPT="${RPCOPT} --http.port ${PORT}" + RPCOPT="${RPCOPT} --ws --ws.addr 0.0.0.0" + [ "$PORT" = "" ] || RPCOPT="${RPCOPT} --ws.port $((${PORT}+10))" + [ "$NONCE_LIMIT" = "" ] || NONCE_LIMIT="--noncelimit $NONCE_LIMIT" + [ "$BOOT_NODES" = "" ] || BOOT_NODES="--bootnodes $BOOT_NODES" + [ "$TESTNET" = "1" ] && TESTNET=--wemix-testnet + if [ "$DISCOVER" = "0" ]; then + DISCOVER=--nodiscover + else + DISCOVER= + fi + case $SYNC_MODE in + "full") + SYNC_MODE="--syncmode full";; + "fast") + SYNC_MODE="--syncmode fast";; + "snap") + SYNC_MODE="--syncmode snap";; + *) + SYNC_MODE="--syncmode full --gcmode archive";; + esac + + OPTS="$COINBASE $DISCOVER $RPCOPT $BOOT_NODES $NONCE_LIMIT $TESTNET $SYNC_MODE ${GWEMIX_OPTS}" + [ "$PORT" = "" ] || OPTS="${OPTS} --port $(($PORT + 1))" + [ "$HUB" = "" ] || OPTS="${OPTS} --hub ${HUB}" + [ "$MAX_TXS_PER_BLOCK" = "" ] || OPTS="${OPTS} --maxtxsperblock ${MAX_TXS_PER_BLOCK}" + + [ -d "$d/logs" ] || mkdir -p $d/logs + [ "$LOG_FILESIZE" = "" ] && LOG_FILESIZE="10M" + [ "$LOG_FILECOUNT" = "" ] && LOG_FILECOUNT="5" + + cd $d + if [ ! "$2" = "inner" ]; then + $GWEMIX --datadir ${PWD} --metrics $OPTS 2>&1 | \ + ${d}/bin/logrot ${d}/logs/log ${LOG_FILESIZE} ${LOG_FILECOUNT} & + else + if [ -x "$d/bin/logrot" ]; then + exec > >($d/bin/logrot $d/logs/log ${LOG_FILESIZE} ${LOG_FILECOUNT}) + exec 2>&1 + fi + exec $GWEMIX --datadir ${PWD} --metrics $OPTS + fi +} + +function get_gwemix_pids () +{ + ps axww | grep -v grep | grep "gwemix.*datadir.*${1}" | awk '{print $1}' +} + +function do_nodes () +{ + LHN=$(hostname) + CMD=${1/-nodes/} + shift + while [ ! "$1" = "" -a ! "$2" = "" ]; do + if [ "$1" = "$LHN" -o "$1" = "${LHN/.*/}" ]; then + $0 ${CMD} $2 + else + ssh -f $1 ${WEMIX_DIR}/$2/bin/gwemix.sh ${CMD} $2 + fi + shift + shift + done +} + +function usage () +{ + echo "Usage: `basename $0` [init | + init-gov | + clean [] | wipe [] | console [] | + [re]start [] | stop [] | [re]start-nodes | stop-nodes] + +*-nodes uses NODES environment variable: [ ]+ +" +} + +case "$1" in +"init") + if [ $# -lt 3 ]; then + usage; + else + init "$2" "$3" + fi + ;; + +"init-gov") + if [ $# -lt 3 ]; then + usage; + else + init_gov "$2" "$3" "$4" + fi + ;; + +"wipe") + wipe $2 + ;; + +"clean") + clean $2 + ;; + +"stop") + echo -n "stopping..." + dir=$(get_data_dir $2) + PIDS=$(get_gwemix_pids ${dir}) + if [ ! "$PIDS" = "" ]; then + # check if we're the miner or leader + CMD=' +function check_if_mining() { + for (var i = 0; i < 15; i++) { + try { + var token = debug.etcdGet("token") + eval("token = " + token) + // console.log("miner -> " + token.miner) + if (token.miner != admin.wemixInfo.self.name) { + break + } else { + console.log("we are the miner, sleeping...") + admin.sleep(0.25) + } + } catch { + admin.sleep(0.25) + } + } +} +if (admin.wemixInfo != null && admin.wemixInfo.self != null) { + check_if_mining() + if (admin.wemixInfo.etcd.leader.name == admin.wemixInfo.self.name) { + var nodes = admin.wemixNodes("", 0) + for (var n of nodes) { + if (admin.wemixInfo.etcd.leader.name != admin.wemixInfo.self.name) { + break + } + if (n.status == "up" && n.name != admin.wemixInfo.self.name) { + console.log("moving leader to " + n.name) + admin.etcdMoveLeader(n.name) + } + } + } + check_if_mining() +}' + ${dir}/bin/gwemix attach ipc:${dir}/gwemix.ipc --exec "$CMD" | grep -v "undefined" + echo $PIDS | xargs -L1 kill + fi + for i in {1..200}; do + PIDS=$(get_gwemix_pids ${dir}) + [ "$PIDS" = "" ] && break + echo -n "." + sleep 1 + done + PIDS=$(get_gwemix_pids ${dir}) + if [ ! "$PIDS" = "" ]; then + echo $PIDS | xargs -L1 kill -9 + fi + # wait until geth/chaindata is free + for i in {1..200}; do + lsof ${dir}/geth/chaindata/LOG 2>&1 | grep -q gwemix > /dev/null 2>&1 || break + sleep 1 + done + echo "done." + ;; + +"start") + start $2 + ;; + +"start-inner") + if [ "$2" = "" ]; then + usage; + else + start $2 inner + fi + ;; + +"restart") + $0 stop $2 + start $2 + ;; + +"start-nodes"|"restart-nodes"|"stop-nodes") + if [ "${NODES}" = "" ]; then + echo "NODES is not defined" + fi + do_nodes $1 ${NODES} + ;; + +"console") + d=$(get_data_dir "$2") + if [ ! -d $d ]; then + usage; exit; + fi + RCJS= + if [ -f "$d/rc.js" ]; then + RCJS="--preload $d/rc.js" + fi + exec ${d}/bin/gwemix ${RCJS} attach ipc:${d}/gwemix.ipc + ;; + +*) + usage; + ;; +esac + +# EOF diff --git a/containers/docker/wemix/testdata/keystore/account1 b/containers/docker/wemix/testdata/keystore/account1 new file mode 100644 index 000000000000..239d507bec25 --- /dev/null +++ b/containers/docker/wemix/testdata/keystore/account1 @@ -0,0 +1 @@ +{"address":"92875d5ba8b104c375a471d58a6de4f75ccb431f","crypto":{"cipher":"aes-128-ctr","ciphertext":"a07c46d69f5e35b76214af74004686a5c0abf54687dce4e3358318a6d7e3cf23","cipherparams":{"iv":"68f1ee7bd8e3c64ca00e5696b60a7846"},"kdf":"scrypt","kdfparams":{"dklen":32,"n":262144,"p":1,"r":8,"salt":"4166f64bc5dfa526cf1a1da89b26cf1ffb60784827dda85a1ccca6193f818deb"},"mac":"6a2e60f7b74f42802d741503dececef073eaff56374bcfdf2a009c6424d96176"},"id":"caa93028-d6fc-4daf-8c48-152d2bd802bd","version":3} \ No newline at end of file diff --git a/containers/docker/wemix/testdata/keystore/account2 b/containers/docker/wemix/testdata/keystore/account2 new file mode 100644 index 000000000000..55e020da3d94 --- /dev/null +++ b/containers/docker/wemix/testdata/keystore/account2 @@ -0,0 +1 @@ +{"address":"b61544371ef73161496009a77989da30f8f91867","crypto":{"cipher":"aes-128-ctr","ciphertext":"cfc35242ce14823f04188ec46b3591cd17dd112d0cd8b90b4e9ef5600fd9c488","cipherparams":{"iv":"58dbb26dc76dddf7fcfc4ad9bdb18f58"},"kdf":"scrypt","kdfparams":{"dklen":32,"n":262144,"p":1,"r":8,"salt":"17c027b25228ac748c2999dabc4047ac72af698c3260f5deadd025c97027d436"},"mac":"469b428c69e9ed23c509c63211205b354632a018c5798bb02a0456a890018a4b"},"id":"572324e3-fd42-4ef9-a877-843a9d6ea231","version":3} \ No newline at end of file diff --git a/containers/docker/wemix/testdata/keystore/account3 b/containers/docker/wemix/testdata/keystore/account3 new file mode 100644 index 000000000000..f4e8cd39989d --- /dev/null +++ b/containers/docker/wemix/testdata/keystore/account3 @@ -0,0 +1 @@ +{"address":"708ebe75a5dbc5f56176db6e84ce5740897e8a17","crypto":{"cipher":"aes-128-ctr","ciphertext":"5cc062f0bd18808a0708877b79fe85f608ba05a43256f17426c1991e97c7b75b","cipherparams":{"iv":"a84efff4ec48f5ad9ca269a06e893f32"},"kdf":"scrypt","kdfparams":{"dklen":32,"n":262144,"p":1,"r":8,"salt":"b994ab1c05a7da29b2f29b5dfc3dcd39acd1fc07bd19b5c6184ac4c4bc2a3f89"},"mac":"13536b9717e35d2665d6f86b96d3f4c80d8921853cc5ca9be0c13ca9f83a7cbd"},"id":"4aed4e3a-9545-4c6f-a832-db9061962ace","version":3} \ No newline at end of file diff --git a/containers/docker/wemix/testdata/keystore/maintenance b/containers/docker/wemix/testdata/keystore/maintenance new file mode 100644 index 000000000000..853b48f908aa --- /dev/null +++ b/containers/docker/wemix/testdata/keystore/maintenance @@ -0,0 +1 @@ +{"address":"2c77f2c8997182e31a19ec48e321f4d09f36819e","crypto":{"cipher":"aes-128-ctr","ciphertext":"92fdc92f09b59c20ff2a39d5cacc8953006679f797a446371d20caaa9b44201b","cipherparams":{"iv":"560b9a6fe1bba58cfaf4a5a4f95cb7d3"},"kdf":"scrypt","kdfparams":{"dklen":32,"n":262144,"p":1,"r":8,"salt":"cfd2974920c10638af987464ed23ccfad5a787b067bffb346c6f6adbc44e0141"},"mac":"a3fbe185cfad466d73addcc814d0c91771707e95d0cf04431e2276dee04f1bdb"},"id":"aa594e16-1669-4d7c-bd5f-ada55400427c","version":3} \ No newline at end of file diff --git a/containers/docker/wemix/testdata/nodekey/nodekey1 b/containers/docker/wemix/testdata/nodekey/nodekey1 new file mode 100644 index 000000000000..54bde66ceb64 --- /dev/null +++ b/containers/docker/wemix/testdata/nodekey/nodekey1 @@ -0,0 +1 @@ +6af367dc76aaf0dd08464c2af10df669343601e458172c8822d7baebf72dd58b \ No newline at end of file diff --git a/containers/docker/wemix/testdata/nodekey/nodekey2 b/containers/docker/wemix/testdata/nodekey/nodekey2 new file mode 100644 index 000000000000..3c2f344d5931 --- /dev/null +++ b/containers/docker/wemix/testdata/nodekey/nodekey2 @@ -0,0 +1 @@ +9d5e6380dbcd2e202f699867f31302059918c5b90fcbd02207214f8ca89fa62d \ No newline at end of file diff --git a/containers/docker/wemix/testdata/nodekey/nodekey3 b/containers/docker/wemix/testdata/nodekey/nodekey3 new file mode 100644 index 000000000000..582ffe51f88c --- /dev/null +++ b/containers/docker/wemix/testdata/nodekey/nodekey3 @@ -0,0 +1 @@ +9f011066ffb5ec558d1bc6efaf1efac620e79fd44a3a3fcf30fbb1015f0a5b1d \ No newline at end of file From c01beea5adc25095c9a7ab410dd96c4a96914546 Mon Sep 17 00:00:00 2001 From: kai-yu-wm Date: Tue, 28 May 2024 15:45:28 +0900 Subject: [PATCH 05/16] docs: Add container.md and move feedelegation.md --- README.md | 4 ++++ FEEDELEGATION.md => docs/FEEDELEGATION.md | 0 docs/container.md | 9 +++++++++ 3 files changed, 13 insertions(+) rename FEEDELEGATION.md => docs/FEEDELEGATION.md (100%) create mode 100644 docs/container.md diff --git a/README.md b/README.md index 3d4dd711fd35..d844c72fb4a5 100644 --- a/README.md +++ b/README.md @@ -166,6 +166,10 @@ After getting enodes of mining nodes, run gwemix as follows. bin/gwemix --syncmode full --datadir --bootnodes --http --http.addr 0.0.0.0 +### Starting Nodes With Docker + +See documentation [here](docs/container.md) + ### The original go-ethereum README follows... ## Go Ethereum diff --git a/FEEDELEGATION.md b/docs/FEEDELEGATION.md similarity index 100% rename from FEEDELEGATION.md rename to docs/FEEDELEGATION.md diff --git a/docs/container.md b/docs/container.md new file mode 100644 index 000000000000..4464b14da648 --- /dev/null +++ b/docs/container.md @@ -0,0 +1,9 @@ +### Starting Nodes With Docker + +Before starting node, an image build is required. Runs from the `containers/docker/wemix` directory. + + docker compose build + +After, run gwemix as follows. + + docker compose up -d \ No newline at end of file From 0f9ad8ec947b1996f85d28323bff782f23418787 Mon Sep 17 00:00:00 2001 From: egonspace Date: Wed, 29 May 2024 11:13:32 +0900 Subject: [PATCH 06/16] fix: version up to v0.10.8 --- params/version.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/params/version.go b/params/version.go index 65bce5efb03b..daf0ba2ca895 100644 --- a/params/version.go +++ b/params/version.go @@ -23,7 +23,7 @@ import ( const ( VersionMajor = 0 // Major version component of the current release VersionMinor = 10 // Minor version component of the current release - VersionPatch = 7 // Patch version component of the current release + VersionPatch = 8 // Patch version component of the current release VersionMeta = "stable" // Version metadata to append to the version string ) From 536e59652fff6feb2ce9590d328095a643a24132 Mon Sep 17 00:00:00 2001 From: egonspace Date: Thu, 30 May 2024 10:25:59 +0900 Subject: [PATCH 07/16] ci: add ci for devnet --- .github/workflows/devnet-ci.yml | 60 +++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 .github/workflows/devnet-ci.yml diff --git a/.github/workflows/devnet-ci.yml b/.github/workflows/devnet-ci.yml new file mode 100644 index 000000000000..f3dd4d0ded78 --- /dev/null +++ b/.github/workflows/devnet-ci.yml @@ -0,0 +1,60 @@ +name: devnet-ci + +on: + pull_request: + branches: + - devnet + +jobs: + build_test: + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v3 + with: + ref: ${{ github.event.pull_request.head.sha }} + + - name: Set up Go + uses: actions/setup-go@v3 + with: + go-version: 1.19 + + - name: Build Go-WEMIX + run: make gwemix.tar.gz + - name: Check Build + run: ls -al build/gwemix.tar.gz + + lint_test: + strategy: + fail-fast: false + matrix: + version: [1.17, 1.18, 1.19] + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v3 + with: + ref: ${{ github.event.pull_request.head.sha }} + + - name: Set up Go + uses: actions/setup-go@v3 + with: + go-version: ${{ matrix.version }} + + - name: Check Lint + run: make lint + + unit_test: + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v3 + with: + ref: ${{ github.event.pull_request.head.sha }} + + - name: Set up Go + uses: actions/setup-go@v3 + with: + go-version: 1.19 + + - name: Check golang Test Cases + run: | + unset ANDROID_HOME + make test From eb5a9657f567a60fe930a99d9947c2b329768529 Mon Sep 17 00:00:00 2001 From: eomti-wm Date: Thu, 30 May 2024 13:58:11 +0900 Subject: [PATCH 08/16] fix: modify big.Int to hexutil.Big --- eth/api.go | 42 ++++++++++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/eth/api.go b/eth/api.go index 776e7125883a..23e27d61702d 100644 --- a/eth/api.go +++ b/eth/api.go @@ -683,12 +683,13 @@ type PublicWemixAPI struct { e *Ethereum } -func NewPublicWemixAPI(e *Ethereum) *PublicWemixAPI { - return &PublicWemixAPI{e} -} - -func (api *PublicWemixAPI) BriocheConfig() *params.BriocheConfig { - return api.e.BlockChain().Config().Brioche +type BriocheConfigResult struct { + BlockReward *hexutil.Big `json:"blockReward,omitempty"` + FirstHalvingBlock *hexutil.Big `json:"firstHalvingBlock,omitempty"` + HalvingPeriod *hexutil.Big `json:"halvingPeriod,omitempty"` + FinishRewardBlock *hexutil.Big `json:"finishRewardBlock,omitempty"` + HalvingTimes hexutil.Uint64 `json:"halvingTimes,omitempty"` + HalvingRate hexutil.Uint64 `json:"halvingRate,omitempty"` } type HalvingInfo struct { @@ -698,8 +699,24 @@ type HalvingInfo struct { BlockReward *hexutil.Big `json:"blockReward"` } +func NewPublicWemixAPI(e *Ethereum) *PublicWemixAPI { + return &PublicWemixAPI{e} +} + +func (api *PublicWemixAPI) BriocheConfig() BriocheConfigResult { + bc := api.e.BlockChain().Config().Brioche + return BriocheConfigResult{ + BlockReward: (*hexutil.Big)(bc.BlockReward), + FirstHalvingBlock: (*hexutil.Big)(bc.FirstHalvingBlock), + HalvingPeriod: (*hexutil.Big)(bc.HalvingPeriod), + FinishRewardBlock: (*hexutil.Big)(bc.FinishRewardBlock), + HalvingTimes: hexutil.Uint64(bc.HalvingTimes), + HalvingRate: hexutil.Uint64(bc.HalvingRate), + } +} + func (api *PublicWemixAPI) HalvingSchedule() []*HalvingInfo { - bc := api.BriocheConfig() + bc := api.e.BlockChain().Config().Brioche if bc.FirstHalvingBlock == nil || bc.HalvingPeriod == nil || bc.HalvingTimes == 0 { return nil } @@ -712,7 +729,7 @@ func (api *PublicWemixAPI) HalvingSchedule() []*HalvingInfo { result := make([]*HalvingInfo, 0) for i := uint64(0); i < bc.HalvingTimes; i++ { startBlock := new(big.Int).Add(bc.FirstHalvingBlock, new(big.Int).Mul(bc.HalvingPeriod, new(big.Int).SetUint64(i))) - if lastRewardBlock != nil && startBlock.Cmp(lastRewardBlock) == 1 { + if lastRewardBlock != nil && startBlock.Cmp(lastRewardBlock) > 0 { break } result = append(result, &HalvingInfo{ @@ -730,13 +747,14 @@ func (api *PublicWemixAPI) HalvingSchedule() []*HalvingInfo { func (api *PublicWemixAPI) GetBriocheBlockReward(blockNumber rpc.BlockNumber) *hexutil.Big { height := new(big.Int) - if blockNumber == rpc.LatestBlockNumber { + switch blockNumber { + case rpc.LatestBlockNumber: height.Set(api.e.BlockChain().CurrentHeader().Number) - } else if blockNumber == rpc.FinalizedBlockNumber { + case rpc.FinalizedBlockNumber: height.Set(api.e.BlockChain().CurrentHeader().Number) - } else if blockNumber == rpc.PendingBlockNumber { + case rpc.PendingBlockNumber: height.Set(api.e.miner.PendingBlock().Header().Number) - } else { + default: height.SetInt64(blockNumber.Int64()) } From d439b023eca93ff73a4ce760e3d4d071f24f6710 Mon Sep 17 00:00:00 2001 From: egon-wm Date: Fri, 31 May 2024 10:13:24 +0900 Subject: [PATCH 09/16] fix: remove 6 PNs for testnet (#94) fix: remote 6 PNs for testnet --- params/wemix_config.go | 6 ------ 1 file changed, 6 deletions(-) diff --git a/params/wemix_config.go b/params/wemix_config.go index 772976c16345..455782306915 100644 --- a/params/wemix_config.go +++ b/params/wemix_config.go @@ -16,13 +16,7 @@ var ( WemixTestnetBootnodes = []string{ "enode://6137facc7a938d245d3a9b8a8ab2bed33b4d4dbc6f75058e176d54f3f9689ac5b7fad00efbda3eec8a292412d3616e84507adecc12c175eaa5dd7c1374a46fb2@20.41.113.133:8589", - "enode://a7274dcc5653edf72db753208ce21fce4ed23f967f94eaa720d1296ef4ceb99ed429aec2daedf01864e07c38d48407e8c02b768698b4f34aac845829045b6705@20.41.113.165:8589", "enode://7b53a01356fd4b227dc354f1f725705257c96b504f2da4bb6e0f1beb6bbd4e9203608711e13035f278dbfd144a904bddb3fe526719d878e15b3e9f759afbef85@20.89.67.116:8589", - "enode://f8b4979b8e8afd5031ced4ebb9c8e7ce0ad8d914be3186bc8a67346fbd1c9cae1447d2c006d986e910820956b755ce32e40f5af953e3e68812bb5f3f62ce8cd3@20.222.40.143:8589", - "enode://64e4cb4b0702f1fb33ca8f5beb62f19c928ecc0acf925c53312e44ea53ccf381616178bcc77f70eec68770158b8d8be994b4bde317bea33c13185bdc689a018e@20.24.30.174:8589", - "enode://0778431754005b5a0332ffbb61d54983668cbfdbfcd5d830364c0b7fb0355f81306ef761762eb38f0800f37b1aebbd4f680fde33cfc9c683bb3c8283d12dc64a@20.212.107.1:8589", - "enode://0b8f4bc0ada2695f5d064953cf9f2486c4fc3560dc662363d01a1908df9d273118009755413a3eb6e651f1cdc62ec5425e03ecf6e511c3a2fddae690e91f2b5c@20.245.249.106:8589", - "enode://1a66550c2e7ec3e07aa39efc615331539aadca109377575a4c86bf84d24e66317dd1939f99016699f217285c2a82e4f1e225796666f6af59ab2b29b3c8243fc8@20.245.249.99:8589", } WemixGenesisFile string From 9f8f87012ace91dcdd883859fae5b37c11f45a6b Mon Sep 17 00:00:00 2001 From: jed-wemade <127728629+jed-wemade@users.noreply.github.com> Date: Mon, 3 Jun 2024 10:25:42 +0900 Subject: [PATCH 10/16] feat: make artifact for dev-ci --- .github/workflows/dev-ci.yml | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/.github/workflows/dev-ci.yml b/.github/workflows/dev-ci.yml index df9f049e80aa..a38ed5030d9d 100644 --- a/.github/workflows/dev-ci.yml +++ b/.github/workflows/dev-ci.yml @@ -19,9 +19,21 @@ jobs: go-version: 1.19 - name: Build Go-WEMIX - run: make gwemix.tar.gz - - name: Check Build - run: ls -al build/gwemix.tar.gz + run: USE_ROCKSDB=YES make gwemix.tar.gz + + - name: Stat Go-WEMIX + run: | + ls -l build/gwemix.tar.gz + tar tf build/gwemix.tar.gz + - name: Move results to artifact + run: mv build/gwemix.tar.gz gwemix-${{ github.event.pull_request.head.sha }}-linux-amd64-rocksdb.tar.gz + + - name: Upload Go-WEMIX + uses: actions/upload-artifact@v4 + with: + name: artifact-${{ github.event.pull_request.head.sha }} + path: gwemix-${{ github.event.pull_request.head.sha }}-linux-amd64-rocksdb.tar.gz + retention-days: 7 lint_test: strategy: From cb117c3f6a6d4ecd8fbcc07309ac52c41de95576 Mon Sep 17 00:00:00 2001 From: jed-wemade <127728629+jed-wemade@users.noreply.github.com> Date: Mon, 3 Jun 2024 10:26:31 +0900 Subject: [PATCH 11/16] feat: make artifact for master-ci --- .github/workflows/master-ci.yml | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/.github/workflows/master-ci.yml b/.github/workflows/master-ci.yml index 46736e268895..043664d41fdb 100644 --- a/.github/workflows/master-ci.yml +++ b/.github/workflows/master-ci.yml @@ -19,9 +19,21 @@ jobs: go-version: 1.19 - name: Build Go-WEMIX - run: make gwemix.tar.gz - - name: Check Build - run: ls -al build/gwemix.tar.gz + run: USE_ROCKSDB=YES make gwemix.tar.gz + + - name: Stat Go-WEMIX + run: | + ls -l build/gwemix.tar.gz + tar tf build/gwemix.tar.gz + - name: Move results to artifact + run: mv build/gwemix.tar.gz gwemix-${{ github.event.pull_request.head.sha }}-linux-amd64-rocksdb.tar.gz + + - name: Upload Go-WEMIX + uses: actions/upload-artifact@v4 + with: + name: artifact-${{ github.event.pull_request.head.sha }} + path: gwemix-${{ github.event.pull_request.head.sha }}-linux-amd64-rocksdb.tar.gz + retention-days: 7 lint_test: strategy: From 376fc608b849f396ec061b75140b7b282a3d1e1c Mon Sep 17 00:00:00 2001 From: jed-wemade <127728629+jed-wemade@users.noreply.github.com> Date: Mon, 3 Jun 2024 13:56:08 +0900 Subject: [PATCH 12/16] feat: make artifact during ci --- .github/workflows/artifacts.yml | 38 +++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 .github/workflows/artifacts.yml diff --git a/.github/workflows/artifacts.yml b/.github/workflows/artifacts.yml new file mode 100644 index 000000000000..86aea2b69c79 --- /dev/null +++ b/.github/workflows/artifacts.yml @@ -0,0 +1,38 @@ +name: artifacts + +on: + push: + branches: + - devnet + - dev + - master + +jobs: + + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: '1.19' + + - name: Build Go-WEMIX tarball + run: USE_ROCKSDB=YES make gwemix.tar.gz + + - name: Stat Go-WEMIX tarball + run: | + ls -l build/gwemix.tar.gz + tar tf build/gwemix.tar.gz + + - name: Move results to artifact + run: mv build/gwemix.tar.gz gwemix-${{ github.ref_name }}-${{ github.sha }}-linux-amd64-rocksdb.tar.gz + + - name: Upload Go-WEMIX + uses: actions/upload-artifact@v4 + with: + name: artifact-${{ github.ref_name }}-${{ github.sha }} + path: gwemix-${{ github.ref_name }}-${{ github.sha }}-linux-amd64-rocksdb.tar.gz + retention-days: 7 From 782779ff6f150988ef763896122d16e7b1cbf038 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A0=95=EC=84=9D=EC=9A=A9=28WM=29?= Date: Mon, 3 Jun 2024 14:00:25 +0900 Subject: [PATCH 13/16] Revert "feat: make artifact for dev-ci" This reverts commit 9f8f87012ace91dcdd883859fae5b37c11f45a6b. --- .github/workflows/dev-ci.yml | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/.github/workflows/dev-ci.yml b/.github/workflows/dev-ci.yml index a38ed5030d9d..df9f049e80aa 100644 --- a/.github/workflows/dev-ci.yml +++ b/.github/workflows/dev-ci.yml @@ -19,21 +19,9 @@ jobs: go-version: 1.19 - name: Build Go-WEMIX - run: USE_ROCKSDB=YES make gwemix.tar.gz - - - name: Stat Go-WEMIX - run: | - ls -l build/gwemix.tar.gz - tar tf build/gwemix.tar.gz - - name: Move results to artifact - run: mv build/gwemix.tar.gz gwemix-${{ github.event.pull_request.head.sha }}-linux-amd64-rocksdb.tar.gz - - - name: Upload Go-WEMIX - uses: actions/upload-artifact@v4 - with: - name: artifact-${{ github.event.pull_request.head.sha }} - path: gwemix-${{ github.event.pull_request.head.sha }}-linux-amd64-rocksdb.tar.gz - retention-days: 7 + run: make gwemix.tar.gz + - name: Check Build + run: ls -al build/gwemix.tar.gz lint_test: strategy: From 8f0d9e1cd1f043afe694467b46f924fbe89ed61b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A0=95=EC=84=9D=EC=9A=A9=28WM=29?= Date: Mon, 3 Jun 2024 14:00:34 +0900 Subject: [PATCH 14/16] Revert "feat: make artifact for master-ci" This reverts commit cb117c3f6a6d4ecd8fbcc07309ac52c41de95576. --- .github/workflows/master-ci.yml | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/.github/workflows/master-ci.yml b/.github/workflows/master-ci.yml index 043664d41fdb..46736e268895 100644 --- a/.github/workflows/master-ci.yml +++ b/.github/workflows/master-ci.yml @@ -19,21 +19,9 @@ jobs: go-version: 1.19 - name: Build Go-WEMIX - run: USE_ROCKSDB=YES make gwemix.tar.gz - - - name: Stat Go-WEMIX - run: | - ls -l build/gwemix.tar.gz - tar tf build/gwemix.tar.gz - - name: Move results to artifact - run: mv build/gwemix.tar.gz gwemix-${{ github.event.pull_request.head.sha }}-linux-amd64-rocksdb.tar.gz - - - name: Upload Go-WEMIX - uses: actions/upload-artifact@v4 - with: - name: artifact-${{ github.event.pull_request.head.sha }} - path: gwemix-${{ github.event.pull_request.head.sha }}-linux-amd64-rocksdb.tar.gz - retention-days: 7 + run: make gwemix.tar.gz + - name: Check Build + run: ls -al build/gwemix.tar.gz lint_test: strategy: From cec95f56fa39bc538dd2ff0facb96a28d7afd4e8 Mon Sep 17 00:00:00 2001 From: jed-wemade <127728629+jed-wemade@users.noreply.github.com> Date: Mon, 3 Jun 2024 15:09:03 +0900 Subject: [PATCH 15/16] fix: use default retention-days and ignore dev branch --- .github/workflows/artifacts.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/artifacts.yml b/.github/workflows/artifacts.yml index 86aea2b69c79..527a85885a3e 100644 --- a/.github/workflows/artifacts.yml +++ b/.github/workflows/artifacts.yml @@ -4,7 +4,6 @@ on: push: branches: - devnet - - dev - master jobs: @@ -35,4 +34,3 @@ jobs: with: name: artifact-${{ github.ref_name }}-${{ github.sha }} path: gwemix-${{ github.ref_name }}-${{ github.sha }}-linux-amd64-rocksdb.tar.gz - retention-days: 7 From 9d160117bbec4d8cb48e339785e5435f14195c3c Mon Sep 17 00:00:00 2001 From: egon-wm Date: Tue, 4 Jun 2024 09:54:50 +0900 Subject: [PATCH 16/16] fix: adjust boot node count (hotfix to dev) (#100) fix: adjust boot node count --- cmd/utils/flags.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 96e8cd654c53..6786ac702d82 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -1041,6 +1041,9 @@ func setRandomBootstrapNodes(ctx *cli.Context, bootnodes []string) []string { } // select random bootnodes selectcount := params.BootnodeCount + if selectcount > bootnodeslen { + selectcount = bootnodeslen + } urls := make([]string, selectcount) tempnode := make([]string, bootnodeslen) copy(tempnode, bootnodes)