From 4f2baa8953b01429e60fd3a8e50fb3827b9070a0 Mon Sep 17 00:00:00 2001 From: lanzafame Date: Wed, 19 Feb 2020 10:15:45 -0800 Subject: [PATCH 1/3] conform protocol ids to spec Signed-off-by: lanzafame --- chain/messagepool/messagepool.go | 2 +- node/modules/lp2p/host.go | 4 +++- node/modules/services.go | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/chain/messagepool/messagepool.go b/chain/messagepool/messagepool.go index 7cd1aaa26..125a83e52 100644 --- a/chain/messagepool/messagepool.go +++ b/chain/messagepool/messagepool.go @@ -45,7 +45,7 @@ var ( ) const ( - msgTopic = "/fil/messages" + msgTopic = "/fil/msgs" localMsgsDs = "/mpool/local" diff --git a/node/modules/lp2p/host.go b/node/modules/lp2p/host.go index af02fdba1..b399618e0 100644 --- a/node/modules/lp2p/host.go +++ b/node/modules/lp2p/host.go @@ -21,6 +21,8 @@ import ( "github.com/filecoin-project/lotus/node/modules/helpers" ) +const KadProtocolID = "/fil/kad/1.0.0" + type P2PHostIn struct { fx.In @@ -80,7 +82,7 @@ func DHTRouting(client bool) interface{} { dhtopts.Client(client), dhtopts.Datastore(dstore), dhtopts.Validator(validator), - dhtopts.Protocols("/lotus/kad/1.0.0"), + dhtopts.Protocols(KadProtocolID), ) if err != nil { diff --git a/node/modules/services.go b/node/modules/services.go index d87058b5d..2969cac37 100644 --- a/node/modules/services.go +++ b/node/modules/services.go @@ -24,7 +24,7 @@ import ( ) const BlocksTopic = "/fil/blocks" -const MessagesTopic = "/fil/messages" +const MessagesTopic = "/fil/msgs" func RunHello(mctx helpers.MetricsCtx, lc fx.Lifecycle, h host.Host, svc *hello.Service) { h.SetStreamHandler(hello.ProtocolID, svc.HandleStream) From d6723935b9887d0959a6442c9d0747fac08ad43e Mon Sep 17 00:00:00 2001 From: whyrusleeping Date: Tue, 3 Mar 2020 15:44:08 -0800 Subject: [PATCH 2/3] fixup to match spec, move constants to common location --- build/params_shared.go | 5 +++++ chain/messagepool/messagepool.go | 8 +++----- node/impl/full/sync.go | 3 ++- node/modules/lp2p/host.go | 4 +--- node/modules/services.go | 12 +++++------- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/build/params_shared.go b/build/params_shared.go index b202c5925..a4c986e1b 100644 --- a/build/params_shared.go +++ b/build/params_shared.go @@ -8,6 +8,11 @@ import ( // Core network constants +const NetworkName = "interop" +const BlocksTopic = "/fil/blocks/" + NetworkName +const MessagesTopic = "/fil/msgs/" + NetworkName +const DhtProtocolName = "/fil/kad/" + NetworkName + // ///// // Storage diff --git a/chain/messagepool/messagepool.go b/chain/messagepool/messagepool.go index 125a83e52..f63dfa2cb 100644 --- a/chain/messagepool/messagepool.go +++ b/chain/messagepool/messagepool.go @@ -45,8 +45,6 @@ var ( ) const ( - msgTopic = "/fil/msgs" - localMsgsDs = "/mpool/local" localUpdates = "update" @@ -237,7 +235,7 @@ func (mp *MessagePool) repubLocal() { continue } - err = mp.api.PubSubPublish(msgTopic, msgb) + err = mp.api.PubSubPublish(build.MessagesTopic, msgb) if err != nil { errout = multierr.Append(errout, xerrors.Errorf("could not publish: %w", err)) continue @@ -282,7 +280,7 @@ func (mp *MessagePool) Push(m *types.SignedMessage) (cid.Cid, error) { } mp.lk.Unlock() - return m.Cid(), mp.api.PubSubPublish(msgTopic, msgb) + return m.Cid(), mp.api.PubSubPublish(build.MessagesTopic, msgb) } func (mp *MessagePool) Add(m *types.SignedMessage) error { @@ -480,7 +478,7 @@ func (mp *MessagePool) PushWithNonce(addr address.Address, cb func(uint64) (*typ log.Errorf("addLocal failed: %+v", err) } - return msg, mp.api.PubSubPublish(msgTopic, msgb) + return msg, mp.api.PubSubPublish(build.MessagesTopic, msgb) } func (mp *MessagePool) Remove(from address.Address, nonce uint64) { diff --git a/node/impl/full/sync.go b/node/impl/full/sync.go index 4a769502b..48ae34d84 100644 --- a/node/impl/full/sync.go +++ b/node/impl/full/sync.go @@ -4,6 +4,7 @@ import ( "context" "github.com/filecoin-project/lotus/api" + "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/chain" "github.com/filecoin-project/lotus/chain/types" cid "github.com/ipfs/go-cid" @@ -76,7 +77,7 @@ func (a *SyncAPI) SyncSubmitBlock(ctx context.Context, blk *types.BlockMsg) erro } // TODO: anything else to do here? - return a.PubSub.Publish("/fil/blocks", b) + return a.PubSub.Publish(build.MessagesTopic, b) } func (a *SyncAPI) SyncIncomingBlocks(ctx context.Context) (<-chan *types.BlockHeader, error) { diff --git a/node/modules/lp2p/host.go b/node/modules/lp2p/host.go index b399618e0..be2379bb9 100644 --- a/node/modules/lp2p/host.go +++ b/node/modules/lp2p/host.go @@ -21,8 +21,6 @@ import ( "github.com/filecoin-project/lotus/node/modules/helpers" ) -const KadProtocolID = "/fil/kad/1.0.0" - type P2PHostIn struct { fx.In @@ -82,7 +80,7 @@ func DHTRouting(client bool) interface{} { dhtopts.Client(client), dhtopts.Datastore(dstore), dhtopts.Validator(validator), - dhtopts.Protocols(KadProtocolID), + dhtopts.Protocols(build.DhtProtocolName), ) if err != nil { diff --git a/node/modules/services.go b/node/modules/services.go index 2969cac37..cac24391b 100644 --- a/node/modules/services.go +++ b/node/modules/services.go @@ -12,6 +12,7 @@ import ( "github.com/filecoin-project/go-fil-markets/retrievalmarket" "github.com/filecoin-project/go-fil-markets/retrievalmarket/discovery" "github.com/filecoin-project/go-fil-markets/storagemarket" + "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/chain" "github.com/filecoin-project/lotus/chain/blocksync" "github.com/filecoin-project/lotus/chain/messagepool" @@ -23,9 +24,6 @@ import ( "github.com/filecoin-project/lotus/node/modules/helpers" ) -const BlocksTopic = "/fil/blocks" -const MessagesTopic = "/fil/msgs" - func RunHello(mctx helpers.MetricsCtx, lc fx.Lifecycle, h host.Host, svc *hello.Service) { h.SetStreamHandler(hello.ProtocolID, svc.HandleStream) @@ -53,7 +51,7 @@ func RunBlockSync(h host.Host, svc *blocksync.BlockSyncService) { func HandleIncomingBlocks(mctx helpers.MetricsCtx, lc fx.Lifecycle, ps *pubsub.PubSub, s *chain.Syncer, h host.Host) { ctx := helpers.LifecycleCtx(mctx, lc) - blocksub, err := ps.Subscribe(BlocksTopic) + blocksub, err := ps.Subscribe(build.BlocksTopic) if err != nil { panic(err) } @@ -63,7 +61,7 @@ func HandleIncomingBlocks(mctx helpers.MetricsCtx, lc fx.Lifecycle, ps *pubsub.P h.ConnManager().TagPeer(p, "badblock", -1000) }) - if err := ps.RegisterTopicValidator(BlocksTopic, v.Validate); err != nil { + if err := ps.RegisterTopicValidator(build.BlocksTopic, v.Validate); err != nil { panic(err) } @@ -73,7 +71,7 @@ func HandleIncomingBlocks(mctx helpers.MetricsCtx, lc fx.Lifecycle, ps *pubsub.P func HandleIncomingMessages(mctx helpers.MetricsCtx, lc fx.Lifecycle, ps *pubsub.PubSub, mpool *messagepool.MessagePool) { ctx := helpers.LifecycleCtx(mctx, lc) - msgsub, err := ps.Subscribe(MessagesTopic) + msgsub, err := ps.Subscribe(build.MessagesTopic) if err != nil { panic(err) } @@ -89,7 +87,7 @@ func HandleIncomingMessages(mctx helpers.MetricsCtx, lc fx.Lifecycle, ps *pubsub return true } - if err := ps.RegisterTopicValidator(MessagesTopic, v); err != nil { + if err := ps.RegisterTopicValidator(build.MessagesTopic, v); err != nil { panic(err) } From 33ca9dabef9a538c9725e0eecc1dc9a445bfa982 Mon Sep 17 00:00:00 2001 From: whyrusleeping Date: Tue, 3 Mar 2020 15:50:45 -0800 Subject: [PATCH 3/3] mod tidy --- go.sum | 2 -- 1 file changed, 2 deletions(-) diff --git a/go.sum b/go.sum index 1777e10be..a9d85bee6 100644 --- a/go.sum +++ b/go.sum @@ -128,8 +128,6 @@ github.com/filecoin-project/go-statestore v0.1.0 h1:t56reH59843TwXHkMcwyuayStBIi github.com/filecoin-project/go-statestore v0.1.0/go.mod h1:LFc9hD+fRxPqiHiaqUEZOinUJB4WARkRfNl10O7kTnI= github.com/filecoin-project/specs-actors v0.0.0-20200210130641-2d1fbd8672cf/go.mod h1:xtDZUB6pe4Pksa/bAJbJ693OilaC5Wbot9jMhLm3cZA= github.com/filecoin-project/specs-actors v0.0.0-20200226200336-94c9b92b2775/go.mod h1:0HAWYrvajFHDgRaKbF0rl+IybVLZL5z4gQ8koCMPhoU= -github.com/filecoin-project/specs-actors v0.0.0-20200229011003-1d726e3afd04 h1:O343OeQLkLWLj5ZqQ5nhevAGBTeB5LioiA53ddScqdY= -github.com/filecoin-project/specs-actors v0.0.0-20200229011003-1d726e3afd04/go.mod h1:0HAWYrvajFHDgRaKbF0rl+IybVLZL5z4gQ8koCMPhoU= github.com/filecoin-project/specs-actors v0.0.0-20200302011114-7d19171ad051 h1:DX/fGDuARZwasW9ka9k1eK510bjHm/pfxY6JDjAxP1I= github.com/filecoin-project/specs-actors v0.0.0-20200302011114-7d19171ad051/go.mod h1:0HAWYrvajFHDgRaKbF0rl+IybVLZL5z4gQ8koCMPhoU= github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=