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

[ALSP] Implements disallowlisting logic #4441

Merged
merged 168 commits into from
Jun 19, 2023
Merged
Show file tree
Hide file tree
Changes from 142 commits
Commits
Show all changes
168 commits
Select commit Hold shift + click to select a range
8b8dd46
fixes a godoc
yhassanzadeh13 May 17, 2023
9ef7ed5
adds heartbeat
yhassanzadeh13 May 17, 2023
ec18867
wires in alsp parameters in code
yhassanzadeh13 May 17, 2023
734785b
wires in alsp parameters for testing
yhassanzadeh13 May 17, 2023
ea31c5f
adds test for a single heartbeat
yhassanzadeh13 May 18, 2023
e503468
decouples misbehavior fixture functions
yhassanzadeh13 May 18, 2023
388fbfe
reduces sleep time of the test
yhassanzadeh13 May 18, 2023
32e8aec
adds decay to zero test
yhassanzadeh13 May 18, 2023
567d34f
Merge remote-tracking branch 'origin/master' into yahya/6470-alsp-par…
yhassanzadeh13 May 24, 2023
eff453d
Merge branch 'master' into yahya/6470-alsp-part-5-decay
yhassanzadeh13 May 24, 2023
71684fc
lint fix
yhassanzadeh13 May 24, 2023
c59b9d4
test fix
yhassanzadeh13 May 24, 2023
3efe364
Merge remote-tracking branch 'origin/yahya/6470-alsp-part-5-decay' in…
yhassanzadeh13 May 24, 2023
4e7117a
lint fix
yhassanzadeh13 May 24, 2023
b10397a
Merge branch 'master' into yahya/6470-alsp-part-5-decay
yhassanzadeh13 May 24, 2023
141bc1d
dissolves start method of middleware
yhassanzadeh13 May 24, 2023
780c594
chore: renames topology method and middleware option
yhassanzadeh13 May 24, 2023
0d21785
chore: renames middleware option
yhassanzadeh13 May 24, 2023
4fb9a8f
chores middleware
yhassanzadeh13 May 24, 2023
0e05b59
adds disallow list cache interface
yhassanzadeh13 May 24, 2023
ddcf7d8
changes signature of a single method
yhassanzadeh13 May 25, 2023
a7b9335
adds cache entity
yhassanzadeh13 May 25, 2023
b63cb9e
revises the interface of cache
yhassanzadeh13 May 25, 2023
ac7739b
changes cause type to map
yhassanzadeh13 May 25, 2023
f28ff45
adds adjust function
yhassanzadeh13 May 25, 2023
14a616d
adds disallow for
yhassanzadeh13 May 25, 2023
6a6c9d6
refactors interface and adds missing methods
yhassanzadeh13 May 25, 2023
e08e7cb
adds TestNewDisallowListCache
yhassanzadeh13 May 25, 2023
aab01c6
adds TestDisallowFor_SinglePeer
yhassanzadeh13 May 25, 2023
53a75e8
adds TestDisallowFor_MultiplePeers
yhassanzadeh13 May 26, 2023
b57e0ad
refactors interface of the cache
yhassanzadeh13 May 26, 2023
0eda3d0
refactors implementation of the cache
yhassanzadeh13 May 26, 2023
4d52d74
implements test AllowFor Single peer
yhassanzadeh13 May 26, 2023
c850faf
updates godocs
yhassanzadeh13 May 26, 2023
c015531
adds test for multiple peers concurrently
yhassanzadeh13 May 26, 2023
c64ddfc
adds a comment
yhassanzadeh13 May 26, 2023
0456c66
removes unused methods
yhassanzadeh13 May 26, 2023
b3147f4
adds disallow list cache config
yhassanzadeh13 May 26, 2023
c2f0fa6
replaces middleware parameters with config
yhassanzadeh13 May 29, 2023
56ba9be
adds networking disallow list cache metrics factory
yhassanzadeh13 May 29, 2023
746e565
adds default middleware size
yhassanzadeh13 May 29, 2023
66af1fc
adds default middleware size to cache
yhassanzadeh13 May 29, 2023
8e4062b
refactors middleware for access node builder
yhassanzadeh13 May 29, 2023
b2e4e3e
adds validate to nuddkeware config
yhassanzadeh13 May 29, 2023
31a3e19
refactors middleware initialization for observer
yhassanzadeh13 May 29, 2023
643ea52
refactors middleware initialization in scaffold
yhassanzadeh13 May 29, 2023
e960230
refactors middleware initialization in follower
yhassanzadeh13 May 29, 2023
fdfebb4
Merge remote-tracking branch 'origin/master' into yahya/6470-alsp-par…
yhassanzadeh13 May 29, 2023
ab9cce5
adds interface for disallow list oracle
yhassanzadeh13 May 29, 2023
99d3daa
moves all disallow listing components to network root package
yhassanzadeh13 May 29, 2023
69e8de1
replaces disallow listing distributor with middleware
yhassanzadeh13 May 29, 2023
be1ae68
revises middleware interface
yhassanzadeh13 May 29, 2023
6c51a00
adds string method to disallow list wrapper
yhassanzadeh13 May 29, 2023
d955a31
removes disallow list consumer and distributor interfaces
yhassanzadeh13 May 29, 2023
f31b5b3
adds disallow listing event handlers to middleware
yhassanzadeh13 May 29, 2023
e8794d6
refactors node blocklist wrappers
yhassanzadeh13 May 29, 2023
3b8864a
lint fix
yhassanzadeh13 May 29, 2023
02edadd
lint fix
yhassanzadeh13 May 29, 2023
9894b9f
generates mocks
yhassanzadeh13 May 29, 2023
2eababa
lint fix
yhassanzadeh13 May 29, 2023
a01d718
fixes tests
yhassanzadeh13 May 30, 2023
acab9d3
fixes tests
yhassanzadeh13 May 30, 2023
72da2d9
Merge remote-tracking branch 'origin/master' into yahya/6470-alsp-par…
yhassanzadeh13 Jun 5, 2023
d0067c4
fix lint
yhassanzadeh13 Jun 5, 2023
3e3f07a
libp2p implements disallow list consumer
yhassanzadeh13 Jun 5, 2023
7884cfe
removes disallow list oracle
yhassanzadeh13 Jun 5, 2023
2d289b4
moves disallow list logic to libp2p node
yhassanzadeh13 Jun 5, 2023
38dc082
moves disallow list cache to libp2p node
yhassanzadeh13 Jun 5, 2023
cc468c8
fixes import cycle
yhassanzadeh13 Jun 5, 2023
97b6683
moves disallowlist cache to p2p package
yhassanzadeh13 Jun 5, 2023
b87c449
lint fix
yhassanzadeh13 Jun 5, 2023
0f1eb95
wires disallow lists to peer manager
yhassanzadeh13 Jun 5, 2023
5c80d74
adds disallow list oracle
yhassanzadeh13 Jun 5, 2023
8d1bcd6
adds disallow list oracle to connection gater interface and implement…
yhassanzadeh13 Jun 5, 2023
03f36b2
wires disallow listing oracle to connection gater
yhassanzadeh13 Jun 5, 2023
7d9242f
wires disallow list consumer to alsp manager
yhassanzadeh13 Jun 5, 2023
5b51471
implements disallow listing below threshold
yhassanzadeh13 Jun 5, 2023
5bc0be9
generates mocks
yhassanzadeh13 Jun 5, 2023
b76ab40
lint fix
yhassanzadeh13 Jun 5, 2023
a32e12f
lint fix
yhassanzadeh13 Jun 5, 2023
3c25286
lint fix
yhassanzadeh13 Jun 5, 2023
aa36d19
fix lint
yhassanzadeh13 Jun 5, 2023
7d02c90
adds test for disallow list notification
yhassanzadeh13 Jun 5, 2023
1fd72a8
renames a test fixture and add more
yhassanzadeh13 Jun 6, 2023
2983198
decreases min backoff
yhassanzadeh13 Jun 6, 2023
9f28a3b
adds a new method to connector host
yhassanzadeh13 Jun 6, 2023
e2e0146
adds disallow listing logic to libp2p node
yhassanzadeh13 Jun 6, 2023
c9ed446
adds disallow listing test
yhassanzadeh13 Jun 6, 2023
6098a7f
decreases time interval of peer manager
yhassanzadeh13 Jun 6, 2023
938a36e
skips connecting to already connected peers
yhassanzadeh13 Jun 6, 2023
f77621c
adds is connected method
yhassanzadeh13 Jun 6, 2023
4fbe8af
Merge remote-tracking branch 'origin/master' into yahya/6470-alsp-par…
yhassanzadeh13 Jun 6, 2023
0342aee
reduces backup
yhassanzadeh13 Jun 7, 2023
5bb3fc4
fixes closure of authorized peers
yhassanzadeh13 Jun 7, 2023
d5cf92a
adds disallow listing test
yhassanzadeh13 Jun 7, 2023
a1cd316
adds godoc
yhassanzadeh13 Jun 7, 2023
f3dd70d
separate the connection gater for each node in test util
yhassanzadeh13 Jun 7, 2023
2a033db
extends a documentation
yhassanzadeh13 Jun 7, 2023
e8b7178
adds misbehavior and disallowlisting test
yhassanzadeh13 Jun 7, 2023
a1a1f00
Merge branch 'master' into yahya/6470-alsp-part-6-pruning
yhassanzadeh13 Jun 7, 2023
afde747
updates mocks
yhassanzadeh13 Jun 7, 2023
38539e6
Merge remote-tracking branch 'origin/yahya/6470-alsp-part-6-pruning' …
yhassanzadeh13 Jun 7, 2023
276d352
fixes build issues
yhassanzadeh13 Jun 7, 2023
dd43a63
lint fix
yhassanzadeh13 Jun 7, 2023
14fe8db
renames block list to disallow list
yhassanzadeh13 Jun 7, 2023
a2fd745
renames block list to disallow list
yhassanzadeh13 Jun 7, 2023
8af9228
Merge branch 'master' into yahya/6470-alsp-part-6-pruning
yhassanzadeh13 Jun 7, 2023
f5c8bd3
fuxes herocache metrics issue
yhassanzadeh13 Jun 7, 2023
7c2b1d7
Merge remote-tracking branch 'origin/yahya/6470-alsp-part-6-pruning' …
yhassanzadeh13 Jun 7, 2023
1da07ed
fixes nil dependecy issue
yhassanzadeh13 Jun 7, 2023
1445fbd
lint fix
yhassanzadeh13 Jun 8, 2023
c1ac0a4
fixes nil pointer exception
yhassanzadeh13 Jun 8, 2023
20ed7a3
Merge branch 'master' into yahya/6470-alsp-part-6-pruning
yhassanzadeh13 Jun 8, 2023
3a9df70
Merge branch 'master' into yahya/6470-alsp-part-6-pruning
yhassanzadeh13 Jun 9, 2023
16d09f3
Merge branch 'master' into yahya/6470-alsp-part-6-pruning
yhassanzadeh13 Jun 12, 2023
6435656
adds a comment
yhassanzadeh13 Jun 12, 2023
1f77da8
Update network/disallow.go
yhassanzadeh13 Jun 12, 2023
ae12a36
Update network/p2p/p2pnode/internal/cache.go
yhassanzadeh13 Jun 12, 2023
0a996e5
Update network/alsp/manager/manager.go
yhassanzadeh13 Jun 12, 2023
c3c81e7
Update network/p2p/p2pnode/internal/cache.go
yhassanzadeh13 Jun 12, 2023
3b43e0b
Update network/p2p/p2pnode/internal/cache.go
yhassanzadeh13 Jun 12, 2023
8e5d412
Update network/p2p/p2pnode/internal/cache.go
yhassanzadeh13 Jun 12, 2023
c5b48af
Update module/metrics/labels.go
yhassanzadeh13 Jun 12, 2023
8c1cd97
Update network/alsp/manager/manager_test.go
yhassanzadeh13 Jun 12, 2023
5cd8855
Update network/alsp/manager/manager_test.go
yhassanzadeh13 Jun 12, 2023
282ef12
Update network/alsp/manager/manager_test.go
yhassanzadeh13 Jun 12, 2023
aa6228a
Update network/p2p/p2pnode/internal/cache.go
yhassanzadeh13 Jun 12, 2023
088dbb3
Update network/p2p/p2pnode/internal/cache.go
yhassanzadeh13 Jun 12, 2023
58f4090
Update network/p2p/p2pnode/internal/cache.go
yhassanzadeh13 Jun 12, 2023
f1d581f
Update network/disallow.go
yhassanzadeh13 Jun 12, 2023
14f7d60
adds documentation for integration testing
yhassanzadeh13 Jun 12, 2023
bb9c358
Merge remote-tracking branch 'origin/yahya/6470-alsp-part-6-pruning' …
yhassanzadeh13 Jun 12, 2023
850310e
Update network/alsp/manager/manager_test.go
yhassanzadeh13 Jun 12, 2023
37bedd3
resolves shadow variables
yhassanzadeh13 Jun 12, 2023
06a1fbe
Merge remote-tracking branch 'origin/yahya/6470-alsp-part-6-pruning' …
yhassanzadeh13 Jun 12, 2023
eefca22
Update network/alsp/manager/manager.go
yhassanzadeh13 Jun 12, 2023
3e3cd10
Update network/alsp/manager/manager.go
yhassanzadeh13 Jun 12, 2023
9264afb
Update network/p2p/connection/peerManager.go
yhassanzadeh13 Jun 12, 2023
554c7d5
renames and refactors a cache and libp2p method
yhassanzadeh13 Jun 12, 2023
e42d58c
Merge remote-tracking branch 'origin/yahya/6470-alsp-part-6-pruning' …
yhassanzadeh13 Jun 12, 2023
0c60366
lint fix
yhassanzadeh13 Jun 12, 2023
5e98a72
Merge branch 'master' into yahya/6470-alsp-part-6-pruning
yhassanzadeh13 Jun 12, 2023
473153b
adds readme
yhassanzadeh13 Jun 12, 2023
0ee0a2a
Merge remote-tracking branch 'origin/yahya/6470-alsp-part-6-pruning' …
yhassanzadeh13 Jun 12, 2023
cb7744e
Merge branch 'master' into yahya/6470-alsp-part-6-pruning
yhassanzadeh13 Jun 13, 2023
e6a2f38
Update network/alsp/manager/manager_test.go
yhassanzadeh13 Jun 13, 2023
0d54873
Merge branch 'master' into yahya/6470-alsp-part-6-pruning
yhassanzadeh13 Jun 13, 2023
9f07e0f
Merge branch 'master' into yahya/6470-alsp-part-6-pruning
yhassanzadeh13 Jun 13, 2023
121987e
Merge branch 'master' into yahya/6470-alsp-part-6-pruning
yhassanzadeh13 Jun 14, 2023
520c2ef
Update network/alsp/manager/README.md
yhassanzadeh13 Jun 14, 2023
c9e5140
Update network/alsp/manager/README.md
yhassanzadeh13 Jun 14, 2023
da1d5c4
Update network/alsp/manager/README.md
yhassanzadeh13 Jun 14, 2023
f5c7d2d
Update network/p2p/p2pnode/libp2pNode.go
yhassanzadeh13 Jun 14, 2023
c8ff213
Update network/alsp/manager/README.md
yhassanzadeh13 Jun 14, 2023
b483f08
Update network/alsp/manager/README.md
yhassanzadeh13 Jun 14, 2023
3d3f69f
Update network/alsp/manager/README.md
yhassanzadeh13 Jun 14, 2023
a9233f7
Update network/alsp/manager/manager_test.go
yhassanzadeh13 Jun 14, 2023
430b369
adds disallow-listed status to cache
yhassanzadeh13 Jun 14, 2023
722fc29
Merge remote-tracking branch 'origin/yahya/6470-alsp-part-6-pruning' …
yhassanzadeh13 Jun 14, 2023
be550f2
Merge branch 'master' into yahya/6470-alsp-part-6-pruning
yhassanzadeh13 Jun 14, 2023
a3c613c
switches a log level
yhassanzadeh13 Jun 14, 2023
95535ab
fixes duplicate metrics panic
yhassanzadeh13 Jun 14, 2023
60059c5
Merge branch 'master' into yahya/6470-alsp-part-6-pruning
yhassanzadeh13 Jun 15, 2023
13da346
Merge branch 'master' into yahya/6470-alsp-part-6-pruning
yhassanzadeh13 Jun 15, 2023
65011f5
Merge branch 'master' into yahya/6470-alsp-part-6-pruning
yhassanzadeh13 Jun 15, 2023
0737d56
Merge branch 'master' into yahya/6470-alsp-part-6-pruning
yhassanzadeh13 Jun 16, 2023
88ef201
Merge branch 'master' into yahya/6470-alsp-part-6-pruning
yhassanzadeh13 Jun 17, 2023
e628587
Merge branch 'master' into yahya/6470-alsp-part-6-pruning
yhassanzadeh13 Jun 19, 2023
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
44 changes: 21 additions & 23 deletions cmd/access/node_builder/access_node_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -811,21 +811,21 @@ func (builder *FlowAccessNodeBuilder) InitIDProviders() {
}
builder.IDTranslator = translator.NewHierarchicalIDTranslator(idCache, translator.NewPublicNetworkIDTranslator())

builder.NodeDisallowListDistributor = cmd.BuildDisallowListNotificationDisseminator(builder.DisallowListNotificationCacheSize, builder.MetricsRegisterer, builder.Logger, builder.MetricsEnabled)

// The following wrapper allows to disallow-list byzantine nodes via an admin command:
// the wrapper overrides the 'Ejected' flag of disallow-listed nodes to true
disallowListWrapper, err := cache.NewNodeBlocklistWrapper(idCache, node.DB, builder.NodeDisallowListDistributor)
disallowListWrapper, err := cache.NewNodeDisallowListWrapper(idCache, node.DB, func() network.DisallowListNotificationConsumer {
return builder.Middleware
})
if err != nil {
return fmt.Errorf("could not initialize NodeBlockListWrapper: %w", err)
}
builder.IdentityProvider = disallowListWrapper

// register the wrapper for dynamic configuration via admin command
err = node.ConfigManager.RegisterIdentifierListConfig("network-id-provider-blocklist",
disallowListWrapper.GetBlocklist, disallowListWrapper.Update)
disallowListWrapper.GetDisallowList, disallowListWrapper.Update)
if err != nil {
return fmt.Errorf("failed to register blocklist with config manager: %w", err)
return fmt.Errorf("failed to register disallow-list wrapper with config manager: %w", err)
}

builder.SyncEngineParticipantsProviderFactory = func() module.IdentifierProvider {
Expand All @@ -840,11 +840,6 @@ func (builder *FlowAccessNodeBuilder) InitIDProviders() {
}
return nil
})

builder.Component("disallow list notification distributor", func(node *cmd.NodeConfig) (module.ReadyDoneAware, error) {
// distributor is returned as a component to be started and stopped.
return builder.NodeDisallowListDistributor, nil
})
}

func (builder *FlowAccessNodeBuilder) Initialize() error {
Expand Down Expand Up @@ -1220,7 +1215,11 @@ func (builder *FlowAccessNodeBuilder) initPublicLibp2pNode(networkKey crypto.Pri
bindAddress,
networkKey,
builder.SporkID,
builder.LibP2PResourceManagerConfig).
builder.LibP2PResourceManagerConfig,
&p2p.DisallowListCacheConfig{
MaxSize: builder.BaseConfig.NetworkConfig.DisallowListCacheSize,
Metrics: metrics.DisallowListCacheMetricsFactory(builder.HeroCacheMetricsFactory(), network.PrivateNetwork),
}).
SetBasicResolver(builder.Resolver).
SetSubscriptionFilter(
subscription.NewRoleBasedFilter(
Expand Down Expand Up @@ -1261,20 +1260,19 @@ func (builder *FlowAccessNodeBuilder) initMiddleware(nodeID flow.Identifier,
validators ...network.MessageValidator,
) network.Middleware {
logger := builder.Logger.With().Bool("staked", false).Logger()
slashingViolationsConsumer := slashing.NewSlashingViolationsConsumer(logger, networkMetrics)
mw := middleware.NewMiddleware(
logger,
libp2pNode,
nodeID,
builder.Metrics.Bitswap,
builder.SporkID,
middleware.DefaultUnicastTimeout,
builder.IDTranslator,
builder.CodecFactory(),
slashingViolationsConsumer,
mw := middleware.NewMiddleware(&middleware.Config{
Logger: logger,
Libp2pNode: libp2pNode,
FlowId: nodeID,
BitSwapMetrics: builder.Metrics.Bitswap,
RootBlockID: builder.SporkID,
UnicastMessageTimeout: middleware.DefaultUnicastTimeout,
IdTranslator: builder.IDTranslator,
Codec: builder.CodecFactory(),
SlashingViolationsConsumer: slashing.NewSlashingViolationsConsumer(logger, networkMetrics),
},
middleware.WithMessageValidators(validators...), // use default identifier provider
)
builder.NodeDisallowListDistributor.AddConsumer(mw)
builder.Middleware = mw
return builder.Middleware
}
22 changes: 11 additions & 11 deletions cmd/node_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
"github.com/onflow/flow-go/network/codec/cbor"
"github.com/onflow/flow-go/network/p2p"
"github.com/onflow/flow-go/network/p2p/connection"
"github.com/onflow/flow-go/network/p2p/distributor"
"github.com/onflow/flow-go/network/p2p/dns"
"github.com/onflow/flow-go/network/p2p/middleware"
"github.com/onflow/flow-go/network/p2p/p2pbuilder"
Expand Down Expand Up @@ -197,8 +196,11 @@ type NetworkConfig struct {
ConnectionManagerConfig *connection.ManagerConfig
// UnicastCreateStreamRetryDelay initial delay used in the exponential backoff for create stream retries
UnicastCreateStreamRetryDelay time.Duration
// size of the queue for notifications about new peers in the disallow list.
DisallowListNotificationCacheSize uint32
// size of the cache keeping the status of disallow-listed peers. Recommended to be 100 * number of authorized nodes.
// Note: this cache is meant to only keep the authorized (i.e., staked) but disallow-listed peers. There is no sybil
// vulnerability for this cache. However, the cache must be large enough to ensure it never runs out of space even if
// the node has not been re-configured for a long time.
DisallowListCacheSize uint32
// UnicastRateLimitersConfig configuration for all unicast rate limiters.
UnicastRateLimitersConfig *UnicastRateLimitersConfig
AlspConfig *AlspConfig
Expand Down Expand Up @@ -291,8 +293,6 @@ type NodeConfig struct {

// UnicastRateLimiterDistributor notifies consumers when a peer's unicast message is rate limited.
UnicastRateLimiterDistributor p2p.UnicastRateLimiterDistributor
// NodeDisallowListDistributor notifies consumers of updates to disallow listing of nodes.
NodeDisallowListDistributor p2p.DisallowListNotificationDistributor
}

// StateExcerptAtBoot stores information about the root snapshot and latest finalized block for use in bootstrapping.
Expand Down Expand Up @@ -333,12 +333,12 @@ func DefaultBaseConfig() *BaseConfig {
BandwidthRateLimit: 0,
BandwidthBurstLimit: middleware.LargeMsgMaxUnicastMsgSize,
},
GossipSubConfig: p2pbuilder.DefaultGossipSubConfig(),
DNSCacheTTL: dns.DefaultTimeToLive,
LibP2PResourceManagerConfig: p2pbuilder.DefaultResourceManagerConfig(),
ConnectionManagerConfig: connection.DefaultConnManagerConfig(),
NetworkConnectionPruning: connection.PruningEnabled,
DisallowListNotificationCacheSize: distributor.DefaultDisallowListNotificationQueueCacheSize,
GossipSubConfig: p2pbuilder.DefaultGossipSubConfig(),
DNSCacheTTL: dns.DefaultTimeToLive,
LibP2PResourceManagerConfig: p2pbuilder.DefaultResourceManagerConfig(),
ConnectionManagerConfig: connection.DefaultConnManagerConfig(),
NetworkConnectionPruning: connection.PruningEnabled,
DisallowListCacheSize: middleware.DisallowListCacheSize,
AlspConfig: &AlspConfig{
SpamRecordCacheSize: alsp.DefaultSpamRecordCacheSize,
SpamReportQueueSize: alsp.DefaultSpamReportQueueSize,
Expand Down
38 changes: 19 additions & 19 deletions cmd/observer/node_builder/observer_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -580,11 +580,11 @@ func (builder *ObserverServiceBuilder) InitIDProviders() {
}
builder.IDTranslator = translator.NewHierarchicalIDTranslator(idCache, translator.NewPublicNetworkIDTranslator())

builder.NodeDisallowListDistributor = cmd.BuildDisallowListNotificationDisseminator(builder.DisallowListNotificationCacheSize, builder.MetricsRegisterer, builder.Logger, builder.MetricsEnabled)

// The following wrapper allows to black-list byzantine nodes via an admin command:
// the wrapper overrides the 'Ejected' flag of disallow-listed nodes to true
builder.IdentityProvider, err = cache.NewNodeBlocklistWrapper(idCache, node.DB, builder.NodeDisallowListDistributor)
builder.IdentityProvider, err = cache.NewNodeDisallowListWrapper(idCache, node.DB, func() network.DisallowListNotificationConsumer {
return builder.Middleware
})
if err != nil {
return fmt.Errorf("could not initialize NodeBlockListWrapper: %w", err)
}
Expand Down Expand Up @@ -615,11 +615,6 @@ func (builder *ObserverServiceBuilder) InitIDProviders() {

return nil
})

builder.Component("disallow list notification distributor", func(node *cmd.NodeConfig) (module.ReadyDoneAware, error) {
// distributor is returned as a component to be started and stopped.
return builder.NodeDisallowListDistributor, nil
})
}

func (builder *ObserverServiceBuilder) Initialize() error {
Expand Down Expand Up @@ -730,7 +725,11 @@ func (builder *ObserverServiceBuilder) initPublicLibp2pNode(networkKey crypto.Pr
builder.BaseConfig.BindAddr,
networkKey,
builder.SporkID,
builder.LibP2PResourceManagerConfig).
builder.LibP2PResourceManagerConfig,
&p2p.DisallowListCacheConfig{
MaxSize: builder.BaseConfig.NetworkConfig.DisallowListCacheSize,
Metrics: metrics.DisallowListCacheMetricsFactory(builder.HeroCacheMetricsFactory(), network.PublicNetwork),
}).
SetSubscriptionFilter(
subscription.NewRoleBasedFilter(
subscription.UnstakedRole, builder.IdentityProvider,
Expand Down Expand Up @@ -911,18 +910,19 @@ func (builder *ObserverServiceBuilder) initMiddleware(nodeID flow.Identifier,
validators ...network.MessageValidator,
) network.Middleware {
slashingViolationsConsumer := slashing.NewSlashingViolationsConsumer(builder.Logger, builder.Metrics.Network)
mw := middleware.NewMiddleware(
builder.Logger,
libp2pNode, nodeID,
builder.Metrics.Bitswap,
builder.SporkID,
middleware.DefaultUnicastTimeout,
builder.IDTranslator,
builder.CodecFactory(),
slashingViolationsConsumer,
mw := middleware.NewMiddleware(&middleware.Config{
Logger: builder.Logger,
Libp2pNode: libp2pNode,
FlowId: nodeID,
BitSwapMetrics: builder.Metrics.Bitswap,
RootBlockID: builder.SporkID,
UnicastMessageTimeout: middleware.DefaultUnicastTimeout,
IdTranslator: builder.IDTranslator,
Codec: builder.CodecFactory(),
SlashingViolationsConsumer: slashingViolationsConsumer,
},
middleware.WithMessageValidators(validators...), // use default identifier provider
)
builder.NodeDisallowListDistributor.AddConsumer(mw)
builder.Middleware = mw
return builder.Middleware
}
Expand Down
59 changes: 30 additions & 29 deletions cmd/scaffold.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,6 @@ func (fnb *FlowNodeBuilder) BaseFlags() {

// networking event notifications
fnb.flags.Uint32Var(&fnb.BaseConfig.GossipSubConfig.RpcInspector.GossipSubRPCInspectorNotificationCacheSize, "gossipsub-rpc-inspector-notification-cache-size", defaultConfig.GossipSubConfig.RpcInspector.GossipSubRPCInspectorNotificationCacheSize, "cache size for notification events from gossipsub rpc inspector")
fnb.flags.Uint32Var(&fnb.BaseConfig.DisallowListNotificationCacheSize, "disallow-list-notification-cache-size", defaultConfig.DisallowListNotificationCacheSize, "cache size for notification events from disallow list")

// unicast manager options
fnb.flags.DurationVar(&fnb.BaseConfig.UnicastCreateStreamRetryDelay, "unicast-manager-create-stream-retry-delay", defaultConfig.NetworkConfig.UnicastCreateStreamRetryDelay, "Initial delay between failing to establish a connection with another node and retrying. This delay increases exponentially (exponential backoff) with the number of subsequent failures to establish a connection.")
Expand Down Expand Up @@ -413,7 +412,12 @@ func (fnb *FlowNodeBuilder) EnqueueNetworkInit() {
fnb.GossipSubConfig,
fnb.GossipSubRpcInspectorSuite,
fnb.LibP2PResourceManagerConfig,
uniCfg)
uniCfg,
&p2p.DisallowListCacheConfig{
MaxSize: fnb.BaseConfig.NetworkConfig.DisallowListCacheSize,
Metrics: metrics.DisallowListCacheMetricsFactory(fnb.HeroCacheMetricsFactory(), network.PrivateNetwork),
},
)

if err != nil {
return nil, fmt.Errorf("could not create libp2p node builder: %w", err)
Expand Down Expand Up @@ -458,8 +462,13 @@ func (fnb *FlowNodeBuilder) HeroCacheMetricsFactory() metrics.HeroCacheMetricsFa
return metrics.NewNoopHeroCacheMetricsFactory()
}

func (fnb *FlowNodeBuilder) InitFlowNetworkWithConduitFactory(node *NodeConfig, cf network.ConduitFactory, unicastRateLimiters *ratelimit.RateLimiters, peerManagerFilters []p2p.PeerFilter) (network.Network, error) {
var mwOpts []middleware.MiddlewareOption
func (fnb *FlowNodeBuilder) InitFlowNetworkWithConduitFactory(
node *NodeConfig,
cf network.ConduitFactory,
unicastRateLimiters *ratelimit.RateLimiters,
peerManagerFilters []p2p.PeerFilter) (network.Network, error) {

var mwOpts []middleware.OptionFn
if len(fnb.MsgValidators) > 0 {
mwOpts = append(mwOpts, middleware.WithMessageValidators(fnb.MsgValidators...))
}
Expand All @@ -476,20 +485,19 @@ func (fnb *FlowNodeBuilder) InitFlowNetworkWithConduitFactory(node *NodeConfig,
if len(peerManagerFilters) > 0 {
mwOpts = append(mwOpts, middleware.WithPeerManagerFilters(peerManagerFilters))
}

slashingViolationsConsumer := slashing.NewSlashingViolationsConsumer(fnb.Logger, fnb.Metrics.Network)
mw := middleware.NewMiddleware(
fnb.Logger,
fnb.LibP2PNode,
fnb.Me.NodeID(),
fnb.Metrics.Bitswap,
fnb.SporkID,
fnb.BaseConfig.UnicastMessageTimeout,
fnb.IDTranslator,
fnb.CodecFactory(),
slashingViolationsConsumer,
mw := middleware.NewMiddleware(&middleware.Config{
Logger: fnb.Logger,
Libp2pNode: fnb.LibP2PNode,
FlowId: fnb.Me.NodeID(),
BitSwapMetrics: fnb.Metrics.Bitswap,
RootBlockID: fnb.SporkID,
UnicastMessageTimeout: fnb.BaseConfig.UnicastMessageTimeout,
IdTranslator: fnb.IDTranslator,
Codec: fnb.CodecFactory(),
SlashingViolationsConsumer: slashing.NewSlashingViolationsConsumer(fnb.Logger, fnb.Metrics.Network),
},
mwOpts...)
fnb.NodeDisallowListDistributor.AddConsumer(mw)

fnb.Middleware = mw

subscriptionManager := subscription.NewChannelSubscriptionManager(fnb.Middleware)
Expand Down Expand Up @@ -1037,35 +1045,28 @@ func (fnb *FlowNodeBuilder) initStorage() error {
}

func (fnb *FlowNodeBuilder) InitIDProviders() {
fnb.Component("disallow list notification distributor", func(node *NodeConfig) (module.ReadyDoneAware, error) {
// distributor is returned as a component to be started and stopped.
if fnb.NodeDisallowListDistributor == nil {
return nil, fmt.Errorf("disallow list notification distributor has not been set")
}
return fnb.NodeDisallowListDistributor, nil
})
fnb.Module("id providers", func(node *NodeConfig) error {
idCache, err := cache.NewProtocolStateIDCache(node.Logger, node.State, node.ProtocolEvents)
if err != nil {
return fmt.Errorf("could not initialize ProtocolStateIDCache: %w", err)
}
node.IDTranslator = idCache

fnb.NodeDisallowListDistributor = BuildDisallowListNotificationDisseminator(fnb.DisallowListNotificationCacheSize, fnb.MetricsRegisterer, fnb.Logger, fnb.MetricsEnabled)

// The following wrapper allows to disallow-list byzantine nodes via an admin command:
// the wrapper overrides the 'Ejected' flag of disallow-listed nodes to true
disallowListWrapper, err := cache.NewNodeBlocklistWrapper(idCache, node.DB, fnb.NodeDisallowListDistributor)
disallowListWrapper, err := cache.NewNodeDisallowListWrapper(idCache, node.DB, func() network.DisallowListNotificationConsumer {
return fnb.Middleware
})
if err != nil {
return fmt.Errorf("could not initialize NodeBlockListWrapper: %w", err)
}
node.IdentityProvider = disallowListWrapper

// register the disallow list wrapper for dynamic configuration via admin command
err = node.ConfigManager.RegisterIdentifierListConfig("network-id-provider-blocklist",
disallowListWrapper.GetBlocklist, disallowListWrapper.Update)
disallowListWrapper.GetDisallowList, disallowListWrapper.Update)
if err != nil {
return fmt.Errorf("failed to register blocklist with config manager: %w", err)
return fmt.Errorf("failed to register disallow-list wrapper with config manager: %w", err)
}

node.SyncEngineIdentifierProvider = id.NewIdentityFilterIdentifierProvider(
Expand Down
15 changes: 0 additions & 15 deletions cmd/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,10 @@ import (
"path/filepath"

"github.com/libp2p/go-libp2p/core/peer"
"github.com/prometheus/client_golang/prometheus"
"github.com/rs/zerolog"

"github.com/onflow/flow-go/model/bootstrap"
"github.com/onflow/flow-go/model/flow"
"github.com/onflow/flow-go/module/mempool/queue"
"github.com/onflow/flow-go/module/metrics"
"github.com/onflow/flow-go/network/p2p"
"github.com/onflow/flow-go/network/p2p/distributor"
"github.com/onflow/flow-go/state/protocol/inmem"
"github.com/onflow/flow-go/utils/io"
)
Expand Down Expand Up @@ -68,13 +63,3 @@ func rateLimiterPeerFilter(rateLimiter p2p.RateLimiter) p2p.PeerFilter {
return nil
}
}

// BuildDisallowListNotificationDisseminator builds the disallow list notification distributor.
func BuildDisallowListNotificationDisseminator(size uint32, metricsRegistry prometheus.Registerer, logger zerolog.Logger, metricsEnabled bool) p2p.DisallowListNotificationDistributor {
heroStoreOpts := []queue.HeroStoreConfigOption{queue.WithHeroStoreSizeLimit(size)}
if metricsEnabled {
collector := metrics.DisallowListNotificationQueueMetricFactory(metricsRegistry)
heroStoreOpts = append(heroStoreOpts, queue.WithHeroStoreCollector(collector))
}
return distributor.DefaultDisallowListNotificationDistributor(logger, heroStoreOpts...)
}
Loading