v1.4.18-patch-2 (#230)
* feat: IPC for wesolowski
* update self peer info
* remove digests and signatures
* add new binaries and digests
* Signatory #13 added
* Signatory #4 added (#231)
* added sig.6 files (#232)
* Signatory #9 added (#233)
* Added signatories #1, #2, #3, #5, #8, #12, #14, #15, #16, #17
* remove binaries, release ready
---------
Co-authored-by: 0xOzgur <29779769+0xOzgur@users.noreply.github.com>
Co-authored-by: Demipoet <161999657+demipoet@users.noreply.github.com>
Co-authored-by: Freekers <1370857+Freekers@users.noreply.github.com>
2024-05-29 17:51:47 +00:00
|
|
|
package rpc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"os"
|
|
|
|
"runtime"
|
|
|
|
"syscall"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"source.quilibrium.com/quilibrium/monorepo/node/crypto"
|
|
|
|
|
|
|
|
"github.com/multiformats/go-multiaddr"
|
|
|
|
mn "github.com/multiformats/go-multiaddr/net"
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
"go.uber.org/zap"
|
|
|
|
"google.golang.org/grpc"
|
|
|
|
"google.golang.org/grpc/reflection"
|
|
|
|
"source.quilibrium.com/quilibrium/monorepo/node/protobufs"
|
|
|
|
)
|
|
|
|
|
|
|
|
type DataWorkerIPCServer struct {
|
|
|
|
protobufs.UnimplementedDataIPCServiceServer
|
|
|
|
listenAddrGRPC string
|
|
|
|
logger *zap.Logger
|
|
|
|
coreId uint32
|
|
|
|
prover crypto.FrameProver
|
|
|
|
parentProcessId int
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetFrameInfo implements protobufs.NodeServiceServer.
|
|
|
|
func (r *DataWorkerIPCServer) CalculateChallengeProof(
|
|
|
|
ctx context.Context,
|
|
|
|
req *protobufs.ChallengeProofRequest,
|
|
|
|
) (*protobufs.ChallengeProofResponse, error) {
|
|
|
|
if r.coreId != req.Core {
|
|
|
|
return nil, errors.Wrap(
|
|
|
|
errors.New("invalid core id"),
|
|
|
|
"calculate challenge proof",
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2024-06-08 08:38:53 +00:00
|
|
|
proof, err := r.prover.CalculateChallengeProof(
|
v1.4.18-patch-2 (#230)
* feat: IPC for wesolowski
* update self peer info
* remove digests and signatures
* add new binaries and digests
* Signatory #13 added
* Signatory #4 added (#231)
* added sig.6 files (#232)
* Signatory #9 added (#233)
* Added signatories #1, #2, #3, #5, #8, #12, #14, #15, #16, #17
* remove binaries, release ready
---------
Co-authored-by: 0xOzgur <29779769+0xOzgur@users.noreply.github.com>
Co-authored-by: Demipoet <161999657+demipoet@users.noreply.github.com>
Co-authored-by: Freekers <1370857+Freekers@users.noreply.github.com>
2024-05-29 17:51:47 +00:00
|
|
|
req.Challenge,
|
|
|
|
uint32(r.coreId),
|
2024-06-08 08:38:53 +00:00
|
|
|
req.Increment,
|
v1.4.18-patch-2 (#230)
* feat: IPC for wesolowski
* update self peer info
* remove digests and signatures
* add new binaries and digests
* Signatory #13 added
* Signatory #4 added (#231)
* added sig.6 files (#232)
* Signatory #9 added (#233)
* Added signatories #1, #2, #3, #5, #8, #12, #14, #15, #16, #17
* remove binaries, release ready
---------
Co-authored-by: 0xOzgur <29779769+0xOzgur@users.noreply.github.com>
Co-authored-by: Demipoet <161999657+demipoet@users.noreply.github.com>
Co-authored-by: Freekers <1370857+Freekers@users.noreply.github.com>
2024-05-29 17:51:47 +00:00
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "calculate challenge proof")
|
|
|
|
}
|
|
|
|
|
|
|
|
return &protobufs.ChallengeProofResponse{
|
2024-06-08 08:38:53 +00:00
|
|
|
Output: proof,
|
v1.4.18-patch-2 (#230)
* feat: IPC for wesolowski
* update self peer info
* remove digests and signatures
* add new binaries and digests
* Signatory #13 added
* Signatory #4 added (#231)
* added sig.6 files (#232)
* Signatory #9 added (#233)
* Added signatories #1, #2, #3, #5, #8, #12, #14, #15, #16, #17
* remove binaries, release ready
---------
Co-authored-by: 0xOzgur <29779769+0xOzgur@users.noreply.github.com>
Co-authored-by: Demipoet <161999657+demipoet@users.noreply.github.com>
Co-authored-by: Freekers <1370857+Freekers@users.noreply.github.com>
2024-05-29 17:51:47 +00:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewDataWorkerIPCServer(
|
|
|
|
listenAddrGRPC string,
|
|
|
|
logger *zap.Logger,
|
|
|
|
coreId uint32,
|
|
|
|
prover crypto.FrameProver,
|
|
|
|
parentProcessId int,
|
|
|
|
) (*DataWorkerIPCServer, error) {
|
|
|
|
return &DataWorkerIPCServer{
|
|
|
|
listenAddrGRPC: listenAddrGRPC,
|
|
|
|
logger: logger,
|
|
|
|
coreId: coreId,
|
|
|
|
prover: prover,
|
|
|
|
parentProcessId: parentProcessId,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *DataWorkerIPCServer) Start() error {
|
|
|
|
s := grpc.NewServer(
|
|
|
|
grpc.MaxRecvMsgSize(10*1024*1024),
|
|
|
|
grpc.MaxSendMsgSize(10*1024*1024),
|
|
|
|
)
|
|
|
|
protobufs.RegisterDataIPCServiceServer(s, r)
|
|
|
|
reflection.Register(s)
|
|
|
|
|
|
|
|
mg, err := multiaddr.NewMultiaddr(r.listenAddrGRPC)
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, "start")
|
|
|
|
}
|
|
|
|
|
|
|
|
lis, err := mn.Listen(mg)
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, "start")
|
|
|
|
}
|
|
|
|
|
|
|
|
go r.monitorParent()
|
|
|
|
|
2024-06-07 08:24:22 +00:00
|
|
|
r.logger.Info(
|
|
|
|
"data worker listening",
|
|
|
|
zap.String("address", r.listenAddrGRPC),
|
|
|
|
)
|
v1.4.18-patch-2 (#230)
* feat: IPC for wesolowski
* update self peer info
* remove digests and signatures
* add new binaries and digests
* Signatory #13 added
* Signatory #4 added (#231)
* added sig.6 files (#232)
* Signatory #9 added (#233)
* Added signatories #1, #2, #3, #5, #8, #12, #14, #15, #16, #17
* remove binaries, release ready
---------
Co-authored-by: 0xOzgur <29779769+0xOzgur@users.noreply.github.com>
Co-authored-by: Demipoet <161999657+demipoet@users.noreply.github.com>
Co-authored-by: Freekers <1370857+Freekers@users.noreply.github.com>
2024-05-29 17:51:47 +00:00
|
|
|
if err := s.Serve(mn.NetListener(lis)); err != nil {
|
2024-06-08 08:38:53 +00:00
|
|
|
r.logger.Error("terminating server", zap.Error(err))
|
v1.4.18-patch-2 (#230)
* feat: IPC for wesolowski
* update self peer info
* remove digests and signatures
* add new binaries and digests
* Signatory #13 added
* Signatory #4 added (#231)
* added sig.6 files (#232)
* Signatory #9 added (#233)
* Added signatories #1, #2, #3, #5, #8, #12, #14, #15, #16, #17
* remove binaries, release ready
---------
Co-authored-by: 0xOzgur <29779769+0xOzgur@users.noreply.github.com>
Co-authored-by: Demipoet <161999657+demipoet@users.noreply.github.com>
Co-authored-by: Freekers <1370857+Freekers@users.noreply.github.com>
2024-05-29 17:51:47 +00:00
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *DataWorkerIPCServer) monitorParent() {
|
2024-06-07 08:24:22 +00:00
|
|
|
if r.parentProcessId == 0 {
|
|
|
|
r.logger.Info(
|
|
|
|
"no parent process id specified, running in detached worker mode",
|
|
|
|
zap.Uint32("core_id", r.coreId),
|
|
|
|
)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
v1.4.18-patch-2 (#230)
* feat: IPC for wesolowski
* update self peer info
* remove digests and signatures
* add new binaries and digests
* Signatory #13 added
* Signatory #4 added (#231)
* added sig.6 files (#232)
* Signatory #9 added (#233)
* Added signatories #1, #2, #3, #5, #8, #12, #14, #15, #16, #17
* remove binaries, release ready
---------
Co-authored-by: 0xOzgur <29779769+0xOzgur@users.noreply.github.com>
Co-authored-by: Demipoet <161999657+demipoet@users.noreply.github.com>
Co-authored-by: Freekers <1370857+Freekers@users.noreply.github.com>
2024-05-29 17:51:47 +00:00
|
|
|
for {
|
|
|
|
time.Sleep(1 * time.Second)
|
|
|
|
proc, err := os.FindProcess(r.parentProcessId)
|
|
|
|
if err != nil {
|
|
|
|
r.logger.Error("parent process not found, terminating")
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Windows returns an error if the process is dead, nobody else does
|
|
|
|
if runtime.GOOS != "windows" {
|
|
|
|
err := proc.Signal(syscall.Signal(0))
|
|
|
|
if err != nil {
|
|
|
|
r.logger.Error("parent process not found, terminating")
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|