Skip to content

Commit 0b9353e

Browse files
authored
chore(nanomsg): remove nano message in server (#1665)
1 parent 5f05122 commit 0b9353e

File tree

13 files changed

+27
-302
lines changed

13 files changed

+27
-302
lines changed

.github/workflows/semantic-pr.yml

-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ jobs:
5959
proto
6060
http
6161
jsonrpc
62-
nanomsg
6362
zeromq
6463
windows
6564
linux

config/config.go

-12
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import (
1919
"github.com/pactus-project/pactus/www/grpc"
2020
"github.com/pactus-project/pactus/www/http"
2121
"github.com/pactus-project/pactus/www/jsonrpc"
22-
"github.com/pactus-project/pactus/www/nanomsg"
2322
"github.com/pactus-project/pactus/www/zmq"
2423
"github.com/pelletier/go-toml/v2"
2524
)
@@ -47,7 +46,6 @@ type Config struct {
4746
JSONRPC *jsonrpc.Config `toml:"jsonrpc"`
4847
HTTP *http.Config `toml:"http"`
4948
WalletManager *wallet.Config `toml:"-"`
50-
Nanomsg *nanomsg.Config `toml:"nanomsg"`
5149
ZeroMq *zmq.Config `toml:"zeromq"`
5250
}
5351

@@ -100,7 +98,6 @@ func defaultConfig() *Config {
10098
GRPC: grpc.DefaultConfig(),
10199
JSONRPC: jsonrpc.DefaultConfig(),
102100
HTTP: http.DefaultConfig(),
103-
Nanomsg: nanomsg.DefaultConfig(),
104101
ZeroMq: zmq.DefaultConfig(),
105102
WalletManager: wallet.DefaultConfig(),
106103
}
@@ -156,8 +153,6 @@ func DefaultConfigMainnet() *Config {
156153
conf.HTTP.Enable = false
157154
conf.HTTP.Listen = "127.0.0.1:80"
158155
conf.HTTP.EnablePprof = false
159-
conf.Nanomsg.Enable = false
160-
conf.Nanomsg.Listen = "tcp://127.0.0.1:40899"
161156

162157
return conf
163158
}
@@ -192,8 +187,6 @@ func DefaultConfigTestnet() *Config {
192187
conf.HTTP.Enable = false
193188
conf.HTTP.Listen = "[::]:80"
194189
conf.HTTP.EnablePprof = false
195-
conf.Nanomsg.Enable = false
196-
conf.Nanomsg.Listen = "tcp://[::]:40799"
197190

198191
return conf
199192
}
@@ -220,8 +213,6 @@ func DefaultConfigLocalnet() *Config {
220213
conf.HTTP.Enable = true
221214
conf.HTTP.Listen = "[::]:0"
222215
conf.HTTP.EnablePprof = true
223-
conf.Nanomsg.Enable = true
224-
conf.Nanomsg.Listen = "tcp://[::]:40799"
225216
conf.ZeroMq.ZmqPubBlockInfo = "tcp://127.0.0.1:28332"
226217
conf.ZeroMq.ZmqPubTxInfo = "tcp://127.0.0.1:28333"
227218
conf.ZeroMq.ZmqPubRawBlock = "tcp://127.0.0.1:28334"
@@ -295,9 +286,6 @@ func (conf *Config) BasicCheck() error {
295286
if err := conf.Sync.BasicCheck(); err != nil {
296287
return err
297288
}
298-
if err := conf.Nanomsg.BasicCheck(); err != nil {
299-
return err
300-
}
301289
if err := conf.JSONRPC.BasicCheck(); err != nil {
302290
return err
303291
}

config/config_test.go

-8
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,10 @@ func TestDefaultConfig(t *testing.T) {
4848
assert.False(t, conf.GRPC.Enable)
4949
assert.False(t, conf.GRPC.Gateway.Enable)
5050
assert.False(t, conf.HTTP.Enable)
51-
assert.False(t, conf.Nanomsg.Enable)
5251

5352
assert.Zero(t, conf.GRPC.Listen)
5453
assert.Zero(t, conf.GRPC.Gateway.Listen)
5554
assert.Zero(t, conf.HTTP.Listen)
56-
assert.Zero(t, conf.Nanomsg.Listen)
5755
}
5856

5957
func TestMainnetConfig(t *testing.T) {
@@ -67,12 +65,10 @@ func TestMainnetConfig(t *testing.T) {
6765
assert.True(t, conf.GRPC.Enable)
6866
assert.False(t, conf.GRPC.Gateway.Enable)
6967
assert.False(t, conf.HTTP.Enable)
70-
assert.False(t, conf.Nanomsg.Enable)
7168

7269
assert.Equal(t, "127.0.0.1:50051", conf.GRPC.Listen)
7370
assert.Equal(t, "127.0.0.1:8080", conf.GRPC.Gateway.Listen)
7471
assert.Equal(t, "127.0.0.1:80", conf.HTTP.Listen)
75-
assert.Equal(t, "tcp://127.0.0.1:40899", conf.Nanomsg.Listen)
7672
}
7773

7874
func TestTestnetConfig(t *testing.T) {
@@ -86,12 +82,10 @@ func TestTestnetConfig(t *testing.T) {
8682
assert.True(t, conf.GRPC.Enable)
8783
assert.True(t, conf.GRPC.Gateway.Enable)
8884
assert.False(t, conf.HTTP.Enable)
89-
assert.False(t, conf.Nanomsg.Enable)
9085

9186
assert.Equal(t, "[::]:50052", conf.GRPC.Listen)
9287
assert.Equal(t, "[::]:8080", conf.GRPC.Gateway.Listen)
9388
assert.Equal(t, "[::]:80", conf.HTTP.Listen)
94-
assert.Equal(t, "tcp://[::]:40799", conf.Nanomsg.Listen)
9589
}
9690

9791
func TestLocalnetConfig(t *testing.T) {
@@ -105,12 +99,10 @@ func TestLocalnetConfig(t *testing.T) {
10599
assert.True(t, conf.GRPC.Enable)
106100
assert.True(t, conf.GRPC.Gateway.Enable)
107101
assert.True(t, conf.HTTP.Enable)
108-
assert.True(t, conf.Nanomsg.Enable)
109102

110103
assert.Equal(t, "[::]:50052", conf.GRPC.Listen)
111104
assert.Equal(t, "[::]:8080", conf.GRPC.Gateway.Listen)
112105
assert.Equal(t, "[::]:0", conf.HTTP.Listen)
113-
assert.Equal(t, "tcp://[::]:40799", conf.Nanomsg.Listen)
114106
}
115107

116108
func TestLoadFromFile(t *testing.T) {

config/example_config.toml

-10
Original file line numberDiff line numberDiff line change
@@ -238,16 +238,6 @@
238238
# data, so enable only in secure environments with restricted access.
239239
enable_pprof = false
240240

241-
# Nanomsg configuration.
242-
[nanomsg]
243-
244-
# `enable` indicates whether nanomsg service should be enabled or not.
245-
# Default is `false`.
246-
enable = false
247-
248-
# `listen` is the address for incoming connections to the nanomsg server.
249-
listen = 'tcp://127.0.0.1:40899'
250-
251241
# ZeroMQ configuration.
252242
[zeromq]
253243

go.mod

-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ require (
3737
github.com/stretchr/testify v1.10.0
3838
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7
3939
github.com/tyler-smith/go-bip39 v1.1.0
40-
go.nanomsg.org/mangos/v3 v3.4.2
4140
golang.org/x/crypto v0.31.0
4241
golang.org/x/exp v0.0.0-20241217172543-b2144cdd0a67
4342
golang.org/x/term v0.27.0
@@ -47,7 +46,6 @@ require (
4746
)
4847

4948
require (
50-
github.com/Microsoft/go-winio v0.6.2 // indirect
5149
github.com/benbjohnson/clock v1.3.5 // indirect
5250
github.com/beorn7/perks v1.0.1 // indirect
5351
github.com/bits-and-blooms/bitset v1.20.0 // indirect

go.sum

-7
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ dmitri.shuralyov.com/service/change v0.0.0-20181023043359-a85b471d5412/go.mod h1
88
dmitri.shuralyov.com/state v0.0.0-20180228185332-28bcc343414c/go.mod h1:0PRwlb0D6DFvNNtx+9ybjezNCa8XF0xaYcETyp6rHWU=
99
git.apache.org/thrift.git v0.0.0-20180902110319-2566ecd5d999/go.mod h1:fPE2ZNJGynbRyZ4dJvy6G277gSllfV2HJqblrnkyeyg=
1010
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
11-
github.com/Microsoft/go-winio v0.5.2/go.mod h1:WpS1mjBmmwHBEWmogvA2mj8546UReBk4v8QkMxJ6pZY=
12-
github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY=
13-
github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU=
1411
github.com/NathanBaulch/protoc-gen-cobra v1.2.1 h1:BOqX9glwicbqDJDGndMnhHhx8psGTSjGdZzRDY1a7A8=
1512
github.com/NathanBaulch/protoc-gen-cobra v1.2.1/go.mod h1:ZLPLEPQgV3jP3a7IEp+xxYPk8tF4lhY9ViV0hn6K3iA=
1613
github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYUyUczH0OGQWaF5ceTx0UBShxjsH6f8oGKYe2c=
@@ -101,7 +98,6 @@ github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4
10198
github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw=
10299
github.com/fxamacker/cbor/v2 v2.7.0 h1:iM5WgngdRBanHcxugY4JySA0nk1wZorNOpTgCMedv5E=
103100
github.com/fxamacker/cbor/v2 v2.7.0/go.mod h1:pxXPTn3joSm21Gbwsv0w9OSA2y1HFR9qXEeXQVeNoDQ=
104-
github.com/gdamore/optopia v0.2.0/go.mod h1:YKYEwo5C1Pa617H7NlPcmQXl+vG6YnSSNB44n8dNL0Q=
105101
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
106102
github.com/gliderlabs/ssh v0.1.1/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0=
107103
github.com/go-errors/errors v1.0.1/go.mod h1:f4zRHt4oKfwPJE5k8C9vpYG+aDHdBFUsgrm6/TyX73Q=
@@ -186,7 +182,6 @@ github.com/gorilla/handlers v1.5.2 h1:cLTUSsNkgcwhgRqvCNmdbRWG0A3N4F+M2nWKdScwyE
186182
github.com/gorilla/handlers v1.5.2/go.mod h1:dX+xVpaxdSw+q0Qek8SSsl3dfMk3jNddUkMzo0GtH0w=
187183
github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY=
188184
github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ=
189-
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
190185
github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg=
191186
github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
192187
github.com/gotk3/gotk3 v0.6.2 h1:sx/PjaKfKULJPTPq8p2kn2ZbcNFxpOJqi4VLzMbEOO8=
@@ -573,8 +568,6 @@ github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9de
573568
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
574569
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
575570
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
576-
go.nanomsg.org/mangos/v3 v3.4.2 h1:gHlopxjWvJcVCcUilQIsRQk9jdj6/HB7wrTiUN8Ki7Q=
577-
go.nanomsg.org/mangos/v3 v3.4.2/go.mod h1:8+hjBMQub6HvXmuGvIq6hf19uxGQIjCofmc62lbedLA=
578571
go.opencensus.io v0.18.0/go.mod h1:vKdFvxhtzZ9onBp9VKHK8z/sRpBMnKAsufL7wlDrCOA=
579572
go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0=
580573
go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo=

node/node.go

+15-15
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package node
22

33
import (
4+
"context"
45
"time"
56

67
"github.com/pactus-project/pactus/config"
@@ -21,8 +22,7 @@ import (
2122
"github.com/pactus-project/pactus/www/grpc"
2223
"github.com/pactus-project/pactus/www/http"
2324
"github.com/pactus-project/pactus/www/jsonrpc"
24-
"github.com/pactus-project/pactus/www/nanomsg"
25-
"github.com/pactus-project/pactus/www/nanomsg/event"
25+
"github.com/pactus-project/pactus/www/zmq"
2626
"github.com/pkg/errors"
2727
)
2828

@@ -38,7 +38,8 @@ type Node struct {
3838
http *http.Server
3939
grpc *grpc.Server
4040
jsonrpc *jsonrpc.Server
41-
nanomsg *nanomsg.Server
41+
zeromq *zmq.Server
42+
eventCh chan any
4243
}
4344

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

5657
messageCh := make(chan message.Message, 500)
57-
eventCh := make(chan event.Event, 500)
58-
if !conf.Nanomsg.Enable {
59-
eventCh = nil
60-
}
58+
eventCh := make(chan any)
6159

6260
store, err := store.NewStore(conf.Store)
6361
if err != nil {
@@ -91,10 +89,15 @@ func NewNode(genDoc *genesis.Genesis, conf *config.Config,
9189
if conf.GRPC.BasicAuth != "" {
9290
enableHTTPAuth = true
9391
}
92+
93+
zeromqServer, err := zmq.New(context.TODO(), conf.ZeroMq, eventCh)
94+
if err != nil {
95+
return nil, err
96+
}
97+
9498
grpcServer := grpc.NewServer(conf.GRPC, state, syn, net, consMgr, walletMgr)
9599
httpServer := http.NewServer(conf.HTTP, enableHTTPAuth)
96100
jsonrpcServer := jsonrpc.NewServer(conf.JSONRPC)
97-
nanomsgServer := nanomsg.NewServer(conf.Nanomsg, eventCh)
98101

99102
node := &Node{
100103
config: conf,
@@ -108,7 +111,8 @@ func NewNode(genDoc *genesis.Genesis, conf *config.Config,
108111
http: httpServer,
109112
grpc: grpcServer,
110113
jsonrpc: jsonrpcServer,
111-
nanomsg: nanomsgServer,
114+
zeromq: zeromqServer,
115+
eventCh: eventCh,
112116
}
113117

114118
return node, nil
@@ -152,11 +156,6 @@ func (n *Node) Start() error {
152156
return errors.Wrap(err, "could not start JSON-RPC server")
153157
}
154158

155-
err = n.nanomsg.StartServer()
156-
if err != nil {
157-
return errors.Wrap(err, "could not start Nanomsg server")
158-
}
159-
160159
return nil
161160
}
162161

@@ -168,14 +167,15 @@ func (n *Node) Stop() {
168167
// Wait for network to stop
169168
time.Sleep(1 * time.Second)
170169

170+
close(n.eventCh)
171171
n.consMgr.Stop()
172172
n.sync.Stop()
173173
n.state.Close()
174174
n.store.Close()
175175
n.grpc.StopServer()
176176
n.http.StopServer()
177177
n.jsonrpc.StopServer()
178-
n.nanomsg.StopServer()
178+
n.zeromq.Close()
179179
}
180180

181181
// these methods are using by GUI.

node/node_test.go

-2
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ func TestRunningNode(t *testing.T) {
3939
conf.HTTP.Listen = "0.0.0.0:0"
4040
conf.JSONRPC.Enable = true
4141
conf.JSONRPC.Listen = "0.0.0.0:0"
42-
conf.Nanomsg.Enable = true
43-
conf.Nanomsg.Listen = "tcp://0.0.0.0:0"
4442
conf.Store.Path = util.TempDirPath()
4543
conf.Network.EnableRelay = false
4644
conf.Network.NetworkKey = util.TempFilePath()

state/state.go

+12-30
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import (
3131
"github.com/pactus-project/pactus/util/logger"
3232
"github.com/pactus-project/pactus/util/persistentmerkle"
3333
"github.com/pactus-project/pactus/util/simplemerkle"
34-
"github.com/pactus-project/pactus/www/nanomsg/event"
3534
)
3635

3736
type state struct {
@@ -49,14 +48,14 @@ type state struct {
4948
validatorMerkle *persistentmerkle.Tree
5049
scoreMgr *score.Manager
5150
logger *logger.SubLogger
52-
eventCh chan event.Event
51+
eventCh chan<- any
5352
}
5453

5554
func LoadOrNewState(
5655
genDoc *genesis.Genesis,
5756
valKeys []*bls.ValidatorKey,
5857
store store.Store,
59-
txPool txpool.TxPool, eventCh chan event.Event,
58+
txPool txpool.TxPool, eventCh chan<- any,
6059
) (Facade, error) {
6160
state := &state{
6261
valKeys: valKeys,
@@ -459,9 +458,8 @@ func (st *state) CommitBlock(blk *block.Block, cert *certificate.BlockCertificat
459458
}
460459
}
461460

462-
// -----------------------------------
463-
// Publishing the events to the nano message.
464-
st.publishEvents(height, blk)
461+
// publish committed block to event channel zeromq
462+
st.publishEvent(blk)
465463

466464
return nil
467465
}
@@ -716,30 +714,6 @@ func (st *state) Params() *param.Params {
716714
return st.params
717715
}
718716

719-
// publishEvents publishes block related events.
720-
func (st *state) publishEvents(height uint32, blk *block.Block) {
721-
if st.eventCh == nil {
722-
return
723-
}
724-
blockEvent := event.CreateBlockEvent(blk.Hash(), height)
725-
st.eventCh <- blockEvent
726-
727-
for i := 1; i < blk.Transactions().Len(); i++ {
728-
transaction := blk.Transactions().Get(i)
729-
730-
senderChangeEvent := event.CreateAccountChangeEvent(transaction.Payload().Signer(), height)
731-
st.eventCh <- senderChangeEvent
732-
733-
if transaction.Payload().Receiver() != nil {
734-
receiverChangeEvent := event.CreateAccountChangeEvent(*transaction.Payload().Receiver(), height)
735-
st.eventCh <- receiverChangeEvent
736-
}
737-
738-
txEvent := event.CreateTransactionEvent(transaction.ID(), height)
739-
st.eventCh <- txEvent
740-
}
741-
}
742-
743717
func (st *state) CalculateFee(amt amount.Amount, payloadType payload.Type) amount.Amount {
744718
return st.txPool.EstimatedFee(amt, payloadType)
745719
}
@@ -772,3 +746,11 @@ func (st *state) IsPruned() bool {
772746
func (st *state) PruningHeight() uint32 {
773747
return st.store.PruningHeight()
774748
}
749+
750+
func (st *state) publishEvent(msg any) {
751+
if st.eventCh == nil {
752+
return
753+
}
754+
755+
st.eventCh <- msg
756+
}

www/nanomsg/config.go

-18
This file was deleted.

0 commit comments

Comments
 (0)