Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(nanomsg): remove nano message in server #1665

Merged
merged 2 commits into from
Jan 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/semantic-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ jobs:
proto
http
jsonrpc
nanomsg
zeromq
windows
linux
Expand Down
12 changes: 0 additions & 12 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"github.com/pactus-project/pactus/www/grpc"
"github.com/pactus-project/pactus/www/http"
"github.com/pactus-project/pactus/www/jsonrpc"
"github.com/pactus-project/pactus/www/nanomsg"
"github.com/pactus-project/pactus/www/zmq"
"github.com/pelletier/go-toml/v2"
)
Expand Down Expand Up @@ -47,7 +46,6 @@ type Config struct {
JSONRPC *jsonrpc.Config `toml:"jsonrpc"`
HTTP *http.Config `toml:"http"`
WalletManager *wallet.Config `toml:"-"`
Nanomsg *nanomsg.Config `toml:"nanomsg"`
ZeroMq *zmq.Config `toml:"zeromq"`
}

Expand Down Expand Up @@ -100,7 +98,6 @@ func defaultConfig() *Config {
GRPC: grpc.DefaultConfig(),
JSONRPC: jsonrpc.DefaultConfig(),
HTTP: http.DefaultConfig(),
Nanomsg: nanomsg.DefaultConfig(),
ZeroMq: zmq.DefaultConfig(),
WalletManager: wallet.DefaultConfig(),
}
Expand Down Expand Up @@ -156,8 +153,6 @@ func DefaultConfigMainnet() *Config {
conf.HTTP.Enable = false
conf.HTTP.Listen = "127.0.0.1:80"
conf.HTTP.EnablePprof = false
conf.Nanomsg.Enable = false
conf.Nanomsg.Listen = "tcp://127.0.0.1:40899"

return conf
}
Expand Down Expand Up @@ -192,8 +187,6 @@ func DefaultConfigTestnet() *Config {
conf.HTTP.Enable = false
conf.HTTP.Listen = "[::]:80"
conf.HTTP.EnablePprof = false
conf.Nanomsg.Enable = false
conf.Nanomsg.Listen = "tcp://[::]:40799"

return conf
}
Expand All @@ -220,8 +213,6 @@ func DefaultConfigLocalnet() *Config {
conf.HTTP.Enable = true
conf.HTTP.Listen = "[::]:0"
conf.HTTP.EnablePprof = true
conf.Nanomsg.Enable = true
conf.Nanomsg.Listen = "tcp://[::]:40799"
conf.ZeroMq.ZmqPubBlockInfo = "tcp://127.0.0.1:28332"
conf.ZeroMq.ZmqPubTxInfo = "tcp://127.0.0.1:28333"
conf.ZeroMq.ZmqPubRawBlock = "tcp://127.0.0.1:28334"
Expand Down Expand Up @@ -295,9 +286,6 @@ func (conf *Config) BasicCheck() error {
if err := conf.Sync.BasicCheck(); err != nil {
return err
}
if err := conf.Nanomsg.BasicCheck(); err != nil {
return err
}
if err := conf.JSONRPC.BasicCheck(); err != nil {
return err
}
Expand Down
8 changes: 0 additions & 8 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,10 @@ func TestDefaultConfig(t *testing.T) {
assert.False(t, conf.GRPC.Enable)
assert.False(t, conf.GRPC.Gateway.Enable)
assert.False(t, conf.HTTP.Enable)
assert.False(t, conf.Nanomsg.Enable)

assert.Zero(t, conf.GRPC.Listen)
assert.Zero(t, conf.GRPC.Gateway.Listen)
assert.Zero(t, conf.HTTP.Listen)
assert.Zero(t, conf.Nanomsg.Listen)
}

func TestMainnetConfig(t *testing.T) {
Expand All @@ -67,12 +65,10 @@ func TestMainnetConfig(t *testing.T) {
assert.True(t, conf.GRPC.Enable)
assert.False(t, conf.GRPC.Gateway.Enable)
assert.False(t, conf.HTTP.Enable)
assert.False(t, conf.Nanomsg.Enable)

assert.Equal(t, "127.0.0.1:50051", conf.GRPC.Listen)
assert.Equal(t, "127.0.0.1:8080", conf.GRPC.Gateway.Listen)
assert.Equal(t, "127.0.0.1:80", conf.HTTP.Listen)
assert.Equal(t, "tcp://127.0.0.1:40899", conf.Nanomsg.Listen)
}

func TestTestnetConfig(t *testing.T) {
Expand All @@ -86,12 +82,10 @@ func TestTestnetConfig(t *testing.T) {
assert.True(t, conf.GRPC.Enable)
assert.True(t, conf.GRPC.Gateway.Enable)
assert.False(t, conf.HTTP.Enable)
assert.False(t, conf.Nanomsg.Enable)

assert.Equal(t, "[::]:50052", conf.GRPC.Listen)
assert.Equal(t, "[::]:8080", conf.GRPC.Gateway.Listen)
assert.Equal(t, "[::]:80", conf.HTTP.Listen)
assert.Equal(t, "tcp://[::]:40799", conf.Nanomsg.Listen)
}

func TestLocalnetConfig(t *testing.T) {
Expand All @@ -105,12 +99,10 @@ func TestLocalnetConfig(t *testing.T) {
assert.True(t, conf.GRPC.Enable)
assert.True(t, conf.GRPC.Gateway.Enable)
assert.True(t, conf.HTTP.Enable)
assert.True(t, conf.Nanomsg.Enable)

assert.Equal(t, "[::]:50052", conf.GRPC.Listen)
assert.Equal(t, "[::]:8080", conf.GRPC.Gateway.Listen)
assert.Equal(t, "[::]:0", conf.HTTP.Listen)
assert.Equal(t, "tcp://[::]:40799", conf.Nanomsg.Listen)
}

func TestLoadFromFile(t *testing.T) {
Expand Down
10 changes: 0 additions & 10 deletions config/example_config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -238,16 +238,6 @@
# data, so enable only in secure environments with restricted access.
enable_pprof = false

# Nanomsg configuration.
[nanomsg]

# `enable` indicates whether nanomsg service should be enabled or not.
# Default is `false`.
enable = false

# `listen` is the address for incoming connections to the nanomsg server.
listen = 'tcp://127.0.0.1:40899'

# ZeroMQ configuration.
[zeromq]

Expand Down
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ require (
github.com/stretchr/testify v1.10.0
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7
github.com/tyler-smith/go-bip39 v1.1.0
go.nanomsg.org/mangos/v3 v3.4.2
golang.org/x/crypto v0.31.0
golang.org/x/exp v0.0.0-20241217172543-b2144cdd0a67
golang.org/x/term v0.27.0
Expand All @@ -47,7 +46,6 @@ require (
)

require (
github.com/Microsoft/go-winio v0.6.2 // indirect
github.com/benbjohnson/clock v1.3.5 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bits-and-blooms/bitset v1.20.0 // indirect
Expand Down
7 changes: 0 additions & 7 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ dmitri.shuralyov.com/service/change v0.0.0-20181023043359-a85b471d5412/go.mod h1
dmitri.shuralyov.com/state v0.0.0-20180228185332-28bcc343414c/go.mod h1:0PRwlb0D6DFvNNtx+9ybjezNCa8XF0xaYcETyp6rHWU=
git.apache.org/thrift.git v0.0.0-20180902110319-2566ecd5d999/go.mod h1:fPE2ZNJGynbRyZ4dJvy6G277gSllfV2HJqblrnkyeyg=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/Microsoft/go-winio v0.5.2/go.mod h1:WpS1mjBmmwHBEWmogvA2mj8546UReBk4v8QkMxJ6pZY=
github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY=
github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU=
github.com/NathanBaulch/protoc-gen-cobra v1.2.1 h1:BOqX9glwicbqDJDGndMnhHhx8psGTSjGdZzRDY1a7A8=
github.com/NathanBaulch/protoc-gen-cobra v1.2.1/go.mod h1:ZLPLEPQgV3jP3a7IEp+xxYPk8tF4lhY9ViV0hn6K3iA=
github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYUyUczH0OGQWaF5ceTx0UBShxjsH6f8oGKYe2c=
Expand Down Expand Up @@ -101,7 +98,6 @@ github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4
github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw=
github.com/fxamacker/cbor/v2 v2.7.0 h1:iM5WgngdRBanHcxugY4JySA0nk1wZorNOpTgCMedv5E=
github.com/fxamacker/cbor/v2 v2.7.0/go.mod h1:pxXPTn3joSm21Gbwsv0w9OSA2y1HFR9qXEeXQVeNoDQ=
github.com/gdamore/optopia v0.2.0/go.mod h1:YKYEwo5C1Pa617H7NlPcmQXl+vG6YnSSNB44n8dNL0Q=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/gliderlabs/ssh v0.1.1/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0=
github.com/go-errors/errors v1.0.1/go.mod h1:f4zRHt4oKfwPJE5k8C9vpYG+aDHdBFUsgrm6/TyX73Q=
Expand Down Expand Up @@ -186,7 +182,6 @@ github.com/gorilla/handlers v1.5.2 h1:cLTUSsNkgcwhgRqvCNmdbRWG0A3N4F+M2nWKdScwyE
github.com/gorilla/handlers v1.5.2/go.mod h1:dX+xVpaxdSw+q0Qek8SSsl3dfMk3jNddUkMzo0GtH0w=
github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY=
github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ=
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg=
github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/gotk3/gotk3 v0.6.2 h1:sx/PjaKfKULJPTPq8p2kn2ZbcNFxpOJqi4VLzMbEOO8=
Expand Down Expand Up @@ -573,8 +568,6 @@ github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9de
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
go.nanomsg.org/mangos/v3 v3.4.2 h1:gHlopxjWvJcVCcUilQIsRQk9jdj6/HB7wrTiUN8Ki7Q=
go.nanomsg.org/mangos/v3 v3.4.2/go.mod h1:8+hjBMQub6HvXmuGvIq6hf19uxGQIjCofmc62lbedLA=
go.opencensus.io v0.18.0/go.mod h1:vKdFvxhtzZ9onBp9VKHK8z/sRpBMnKAsufL7wlDrCOA=
go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0=
go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo=
Expand Down
30 changes: 15 additions & 15 deletions node/node.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package node

import (
"context"
"time"

"github.com/pactus-project/pactus/config"
Expand All @@ -21,8 +22,7 @@
"github.com/pactus-project/pactus/www/grpc"
"github.com/pactus-project/pactus/www/http"
"github.com/pactus-project/pactus/www/jsonrpc"
"github.com/pactus-project/pactus/www/nanomsg"
"github.com/pactus-project/pactus/www/nanomsg/event"
"github.com/pactus-project/pactus/www/zmq"
"github.com/pkg/errors"
)

Expand All @@ -38,7 +38,8 @@
http *http.Server
grpc *grpc.Server
jsonrpc *jsonrpc.Server
nanomsg *nanomsg.Server
zeromq *zmq.Server
eventCh chan any
}

func NewNode(genDoc *genesis.Genesis, conf *config.Config,
Expand All @@ -54,10 +55,7 @@
"network", chainType)

messageCh := make(chan message.Message, 500)
eventCh := make(chan event.Event, 500)
if !conf.Nanomsg.Enable {
eventCh = nil
}
eventCh := make(chan any)

store, err := store.NewStore(conf.Store)
if err != nil {
Expand Down Expand Up @@ -91,10 +89,15 @@
if conf.GRPC.BasicAuth != "" {
enableHTTPAuth = true
}

zeromqServer, err := zmq.New(context.TODO(), conf.ZeroMq, eventCh)
if err != nil {
return nil, err
}

Check warning on line 96 in node/node.go

View check run for this annotation

Codecov / codecov/patch

node/node.go#L95-L96

Added lines #L95 - L96 were not covered by tests

grpcServer := grpc.NewServer(conf.GRPC, state, syn, net, consMgr, walletMgr)
httpServer := http.NewServer(conf.HTTP, enableHTTPAuth)
jsonrpcServer := jsonrpc.NewServer(conf.JSONRPC)
nanomsgServer := nanomsg.NewServer(conf.Nanomsg, eventCh)

node := &Node{
config: conf,
Expand All @@ -108,7 +111,8 @@
http: httpServer,
grpc: grpcServer,
jsonrpc: jsonrpcServer,
nanomsg: nanomsgServer,
zeromq: zeromqServer,
eventCh: eventCh,
}

return node, nil
Expand Down Expand Up @@ -152,11 +156,6 @@
return errors.Wrap(err, "could not start JSON-RPC server")
}

err = n.nanomsg.StartServer()
if err != nil {
return errors.Wrap(err, "could not start Nanomsg server")
}

return nil
}

Expand All @@ -168,14 +167,15 @@
// Wait for network to stop
time.Sleep(1 * time.Second)

close(n.eventCh)
n.consMgr.Stop()
n.sync.Stop()
n.state.Close()
n.store.Close()
n.grpc.StopServer()
n.http.StopServer()
n.jsonrpc.StopServer()
n.nanomsg.StopServer()
n.zeromq.Close()
}

// these methods are using by GUI.
Expand Down
2 changes: 0 additions & 2 deletions node/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ func TestRunningNode(t *testing.T) {
conf.HTTP.Listen = "0.0.0.0:0"
conf.JSONRPC.Enable = true
conf.JSONRPC.Listen = "0.0.0.0:0"
conf.Nanomsg.Enable = true
conf.Nanomsg.Listen = "tcp://0.0.0.0:0"
conf.Store.Path = util.TempDirPath()
conf.Network.EnableRelay = false
conf.Network.NetworkKey = util.TempFilePath()
Expand Down
42 changes: 12 additions & 30 deletions state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
"github.com/pactus-project/pactus/util/logger"
"github.com/pactus-project/pactus/util/persistentmerkle"
"github.com/pactus-project/pactus/util/simplemerkle"
"github.com/pactus-project/pactus/www/nanomsg/event"
)

type state struct {
Expand All @@ -49,14 +48,14 @@
validatorMerkle *persistentmerkle.Tree
scoreMgr *score.Manager
logger *logger.SubLogger
eventCh chan event.Event
eventCh chan<- any
}

func LoadOrNewState(
genDoc *genesis.Genesis,
valKeys []*bls.ValidatorKey,
store store.Store,
txPool txpool.TxPool, eventCh chan event.Event,
txPool txpool.TxPool, eventCh chan<- any,
) (Facade, error) {
state := &state{
valKeys: valKeys,
Expand Down Expand Up @@ -459,9 +458,8 @@
}
}

// -----------------------------------
// Publishing the events to the nano message.
st.publishEvents(height, blk)
// publish committed block to event channel zeromq
st.publishEvent(blk)

return nil
}
Expand Down Expand Up @@ -716,30 +714,6 @@
return st.params
}

// publishEvents publishes block related events.
func (st *state) publishEvents(height uint32, blk *block.Block) {
if st.eventCh == nil {
return
}
blockEvent := event.CreateBlockEvent(blk.Hash(), height)
st.eventCh <- blockEvent

for i := 1; i < blk.Transactions().Len(); i++ {
transaction := blk.Transactions().Get(i)

senderChangeEvent := event.CreateAccountChangeEvent(transaction.Payload().Signer(), height)
st.eventCh <- senderChangeEvent

if transaction.Payload().Receiver() != nil {
receiverChangeEvent := event.CreateAccountChangeEvent(*transaction.Payload().Receiver(), height)
st.eventCh <- receiverChangeEvent
}

txEvent := event.CreateTransactionEvent(transaction.ID(), height)
st.eventCh <- txEvent
}
}

func (st *state) CalculateFee(amt amount.Amount, payloadType payload.Type) amount.Amount {
return st.txPool.EstimatedFee(amt, payloadType)
}
Expand Down Expand Up @@ -772,3 +746,11 @@
func (st *state) PruningHeight() uint32 {
return st.store.PruningHeight()
}

func (st *state) publishEvent(msg any) {
if st.eventCh == nil {
return
}

st.eventCh <- msg

Check warning on line 755 in state/state.go

View check run for this annotation

Codecov / codecov/patch

state/state.go#L755

Added line #L755 was not covered by tests
}
18 changes: 0 additions & 18 deletions www/nanomsg/config.go

This file was deleted.

Loading
Loading