Skip to content

Commit 29a959e

Browse files
authored
Merge branch 'master' into haroldsphinx/1152-Update-Benchnet2-automation-and-helmchart
2 parents 5cf41b5 + e69cffa commit 29a959e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+3205
-313
lines changed

cmd/access/node_builder/access_node_builder.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1072,7 +1072,7 @@ func (builder *FlowAccessNodeBuilder) enqueuePublicNetworkInit() {
10721072
// - The passed in private key as the libp2p key
10731073
// - No connection gater
10741074
// - Default Flow libp2p pubsub options
1075-
func (builder *FlowAccessNodeBuilder) initLibP2PFactory(networkKey crypto.PrivateKey, bindAddress string, networkMetrics module.LibP2PMetrics) p2pbuilder.LibP2PFactoryFunc {
1075+
func (builder *FlowAccessNodeBuilder) initLibP2PFactory(networkKey crypto.PrivateKey, bindAddress string, networkMetrics module.LibP2PMetrics) p2p.LibP2PFactoryFunc {
10761076
return func() (p2p.LibP2PNode, error) {
10771077
connManager, err := connection.NewConnManager(builder.Logger, networkMetrics, builder.ConnectionManagerConfig)
10781078
if err != nil {
@@ -1113,6 +1113,7 @@ func (builder *FlowAccessNodeBuilder) initLibP2PFactory(networkKey crypto.Privat
11131113
SetPeerManagerOptions(connection.ConnectionPruningDisabled, builder.PeerUpdateInterval).
11141114
SetStreamCreationRetryInterval(builder.UnicastCreateStreamRetryDelay).
11151115
SetGossipSubTracer(meshTracer).
1116+
SetGossipSubScoreTracerInterval(builder.GossipSubConfig.ScoreTracerInterval).
11161117
Build()
11171118

11181119
if err != nil {

cmd/observer/node_builder/observer_builder.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -846,7 +846,7 @@ func (builder *ObserverServiceBuilder) validateParams() error {
846846
// * No connection manager
847847
// * No peer manager
848848
// * Default libp2p pubsub options
849-
func (builder *ObserverServiceBuilder) initLibP2PFactory(networkKey crypto.PrivateKey) p2pbuilder.LibP2PFactoryFunc {
849+
func (builder *ObserverServiceBuilder) initLibP2PFactory(networkKey crypto.PrivateKey) p2p.LibP2PFactoryFunc {
850850
return func() (p2p.LibP2PNode, error) {
851851
var pis []peer.AddrInfo
852852

@@ -888,6 +888,7 @@ func (builder *ObserverServiceBuilder) initLibP2PFactory(networkKey crypto.Priva
888888
}).
889889
SetStreamCreationRetryInterval(builder.UnicastCreateStreamRetryDelay).
890890
SetGossipSubTracer(meshTracer).
891+
SetGossipSubScoreTracerInterval(builder.GossipSubConfig.ScoreTracerInterval).
891892
Build()
892893

893894
if err != nil {

cmd/scaffold.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ func (fnb *FlowNodeBuilder) BaseFlags() {
185185
fnb.flags.BoolVar(&fnb.BaseConfig.NetworkConnectionPruning, "networking-connection-pruning", defaultConfig.NetworkConnectionPruning, "enabling connection trimming")
186186
fnb.flags.BoolVar(&fnb.BaseConfig.GossipSubConfig.PeerScoring, "peer-scoring-enabled", defaultConfig.GossipSubConfig.PeerScoring, "enabling peer scoring on pubsub network")
187187
fnb.flags.DurationVar(&fnb.BaseConfig.GossipSubConfig.LocalMeshLogInterval, "gossipsub-local-mesh-logging-interval", defaultConfig.GossipSubConfig.LocalMeshLogInterval, "logging interval for local mesh in gossipsub")
188+
fnb.flags.DurationVar(&fnb.BaseConfig.GossipSubConfig.ScoreTracerInterval, "gossipsub-score-tracer-interval", defaultConfig.GossipSubConfig.ScoreTracerInterval, "logging interval for peer score tracer in gossipsub, set to 0 to disable")
188189
fnb.flags.UintVar(&fnb.BaseConfig.guaranteesCacheSize, "guarantees-cache-size", bstorage.DefaultCacheSize, "collection guarantees cache size")
189190
fnb.flags.UintVar(&fnb.BaseConfig.receiptsCacheSize, "receipts-cache-size", bstorage.DefaultCacheSize, "receipts cache size")
190191

engine/execution/state/state.go

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"errors"
66
"fmt"
7+
"sync"
78

89
"github.com/dgraph-io/badger/v2"
910

@@ -148,7 +149,8 @@ type LedgerStorageSnapshot struct {
148149
ledger ledger.Ledger
149150
commitment flow.StateCommitment
150151

151-
readCache map[flow.RegisterID]flow.RegisterValue
152+
mutex sync.RWMutex
153+
readCache map[flow.RegisterID]flow.RegisterValue // Guarded by mutex.
152154
}
153155

154156
func NewLedgerStorageSnapshot(
@@ -162,16 +164,25 @@ func NewLedgerStorageSnapshot(
162164
}
163165
}
164166

165-
func (storage *LedgerStorageSnapshot) Get(
167+
func (storage *LedgerStorageSnapshot) getFromCache(
166168
id flow.RegisterID,
167169
) (
168170
flow.RegisterValue,
169-
error,
171+
bool,
170172
) {
171-
if value, ok := storage.readCache[id]; ok {
172-
return value, nil
173-
}
173+
storage.mutex.RLock()
174+
defer storage.mutex.RUnlock()
174175

176+
value, ok := storage.readCache[id]
177+
return value, ok
178+
}
179+
180+
func (storage *LedgerStorageSnapshot) getFromLedger(
181+
id flow.RegisterID,
182+
) (
183+
flow.RegisterValue,
184+
error,
185+
) {
175186
query, err := makeSingleValueQuery(storage.commitment, id)
176187
if err != nil {
177188
return nil, fmt.Errorf("cannot create ledger query: %w", err)
@@ -186,14 +197,29 @@ func (storage *LedgerStorageSnapshot) Get(
186197
err)
187198
}
188199

189-
// Prevent caching of value with len zero
190-
if len(value) == 0 {
191-
return nil, nil
200+
return value, nil
201+
}
202+
203+
func (storage *LedgerStorageSnapshot) Get(
204+
id flow.RegisterID,
205+
) (
206+
flow.RegisterValue,
207+
error,
208+
) {
209+
value, ok := storage.getFromCache(id)
210+
if ok {
211+
return value, nil
212+
}
213+
214+
value, err := storage.getFromLedger(id)
215+
if err != nil {
216+
return nil, err
192217
}
193218

194-
// don't cache value with len zero
195-
storage.readCache[id] = value
219+
storage.mutex.Lock()
220+
defer storage.mutex.Unlock()
196221

222+
storage.readCache[id] = value
197223
return value, nil
198224
}
199225

follower/follower_builder.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ func (builder *FollowerServiceBuilder) validateParams() error {
576576
// - No connection manager
577577
// - No peer manager
578578
// - Default libp2p pubsub options
579-
func (builder *FollowerServiceBuilder) initLibP2PFactory(networkKey crypto.PrivateKey) p2pbuilder.LibP2PFactoryFunc {
579+
func (builder *FollowerServiceBuilder) initLibP2PFactory(networkKey crypto.PrivateKey) p2p.LibP2PFactoryFunc {
580580
return func() (p2p.LibP2PNode, error) {
581581
var pis []peer.AddrInfo
582582

@@ -618,6 +618,7 @@ func (builder *FollowerServiceBuilder) initLibP2PFactory(networkKey crypto.Priva
618618
}).
619619
SetStreamCreationRetryInterval(builder.UnicastCreateStreamRetryDelay).
620620
SetGossipSubTracer(meshTracer).
621+
SetGossipSubScoreTracerInterval(builder.GossipSubConfig.ScoreTracerInterval).
621622
Build()
622623

623624
if err != nil {

insecure/corruptlibp2p/libp2p_node_factory.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func NewCorruptLibP2PNodeFactory(
3535
topicValidatorDisabled,
3636
withMessageSigning,
3737
withStrictSignatureVerification bool,
38-
) p2pbuilder.LibP2PFactoryFunc {
38+
) p2p.LibP2PFactoryFunc {
3939
return func() (p2p.LibP2PNode, error) {
4040
if chainID != flow.BftTestnet {
4141
panic("illegal chain id for using corrupt libp2p node")
@@ -70,7 +70,7 @@ func NewCorruptLibP2PNodeFactory(
7070

7171
// CorruptGossipSubFactory returns a factory function that creates a new instance of the forked gossipsub module from
7272
// github.com/yhassanzadeh13/go-libp2p-pubsub for the purpose of BFT testing and attack vector implementation.
73-
func CorruptGossipSubFactory(routerOpts ...func(*corrupt.GossipSubRouter)) p2pbuilder.GossipSubFactoryFunc {
73+
func CorruptGossipSubFactory(routerOpts ...func(*corrupt.GossipSubRouter)) p2p.GossipSubFactoryFunc {
7474
factory := func(ctx context.Context, logger zerolog.Logger, host host.Host, cfg p2p.PubSubAdapterConfig) (p2p.PubSubAdapter, error) {
7575
adapter, router, err := NewCorruptGossipSubAdapter(ctx, logger, host, cfg)
7676
for _, opt := range routerOpts {
@@ -83,21 +83,21 @@ func CorruptGossipSubFactory(routerOpts ...func(*corrupt.GossipSubRouter)) p2pbu
8383

8484
// CorruptGossipSubConfigFactory returns a factory function that creates a new instance of the forked gossipsub config
8585
// from github.com/yhassanzadeh13/go-libp2p-pubsub for the purpose of BFT testing and attack vector implementation.
86-
func CorruptGossipSubConfigFactory(opts ...CorruptPubSubAdapterConfigOption) p2pbuilder.GossipSubAdapterConfigFunc {
86+
func CorruptGossipSubConfigFactory(opts ...CorruptPubSubAdapterConfigOption) p2p.GossipSubAdapterConfigFunc {
8787
return func(base *p2p.BasePubSubAdapterConfig) p2p.PubSubAdapterConfig {
8888
return NewCorruptPubSubAdapterConfig(base, opts...)
8989
}
9090
}
9191

9292
// CorruptGossipSubConfigFactoryWithInspector returns a factory function that creates a new instance of the forked gossipsub config
9393
// from github.com/yhassanzadeh13/go-libp2p-pubsub for the purpose of BFT testing and attack vector implementation.
94-
func CorruptGossipSubConfigFactoryWithInspector(inspector func(peer.ID, *corrupt.RPC) error) p2pbuilder.GossipSubAdapterConfigFunc {
94+
func CorruptGossipSubConfigFactoryWithInspector(inspector func(peer.ID, *corrupt.RPC) error) p2p.GossipSubAdapterConfigFunc {
9595
return func(base *p2p.BasePubSubAdapterConfig) p2p.PubSubAdapterConfig {
9696
return NewCorruptPubSubAdapterConfig(base, WithInspector(inspector))
9797
}
9898
}
9999

100-
func overrideWithCorruptGossipSub(builder p2pbuilder.NodeBuilder, opts ...CorruptPubSubAdapterConfigOption) {
100+
func overrideWithCorruptGossipSub(builder p2p.NodeBuilder, opts ...CorruptPubSubAdapterConfigOption) {
101101
factory := CorruptGossipSubFactory()
102102
builder.SetGossipSubFactory(factory, CorruptGossipSubConfigFactory(opts...))
103103
}

insecure/corruptlibp2p/p2p_node.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
"github.com/onflow/flow-go/network/codec/cbor"
1414
"github.com/onflow/flow-go/network/message"
1515
"github.com/onflow/flow-go/network/p2p"
16-
"github.com/onflow/flow-go/network/p2p/connection"
1716
"github.com/onflow/flow-go/network/p2p/p2pnode"
1817
validator "github.com/onflow/flow-go/network/validator/pubsub"
1918
)
@@ -52,7 +51,7 @@ func (n *CorruptP2PNode) Subscribe(topic channels.Topic, _ p2p.TopicValidatorFun
5251
}
5352

5453
// NewCorruptLibP2PNode returns corrupted libP2PNode that will subscribe to topics using the AcceptAllTopicValidator.
55-
func NewCorruptLibP2PNode(logger zerolog.Logger, host host.Host, pCache *p2pnode.ProtocolPeerCache, peerManager *connection.PeerManager) p2p.LibP2PNode {
54+
func NewCorruptLibP2PNode(logger zerolog.Logger, host host.Host, pCache p2p.ProtocolPeerCache, peerManager p2p.PeerManager) p2p.LibP2PNode {
5655
node := p2pnode.NewNode(logger, host, pCache, peerManager)
5756
return &CorruptP2PNode{Node: node, logger: logger, codec: cbor.NewCodec()}
5857
}

insecure/corruptlibp2p/pubsub_adapter.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import (
1111
corrupt "github.com/yhassanzadeh13/go-libp2p-pubsub"
1212

1313
"github.com/onflow/flow-go/insecure/internal"
14+
"github.com/onflow/flow-go/module/component"
15+
"github.com/onflow/flow-go/module/irrecoverable"
1416
"github.com/onflow/flow-go/network/p2p"
1517
"github.com/onflow/flow-go/utils/logging"
1618
)
@@ -25,6 +27,7 @@ import (
2527
// implementation, it is designed to be completely isolated in the "insecure" package, and
2628
// totally separated from the rest of the codebase.
2729
type CorruptGossipSubAdapter struct {
30+
component.Component
2831
gossipSub *corrupt.PubSub
2932
router *corrupt.GossipSubRouter
3033
logger zerolog.Logger
@@ -116,7 +119,14 @@ func NewCorruptGossipSubAdapter(ctx context.Context, logger zerolog.Logger, h ho
116119
return nil, nil, fmt.Errorf("failed to create corrupt gossipsub: %w", err)
117120
}
118121

122+
builder := component.NewComponentManagerBuilder().
123+
AddWorker(func(ctx irrecoverable.SignalerContext, ready component.ReadyFunc) {
124+
ready()
125+
<-ctx.Done()
126+
}).Build()
127+
119128
adapter := &CorruptGossipSubAdapter{
129+
Component: builder,
120130
gossipSub: gossipSub,
121131
router: router,
122132
logger: logger,

insecure/corruptlibp2p/pubsub_adapter_config.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ func (c *CorruptPubSubAdapterConfig) WithMessageIdFunction(f func([]byte) string
9797
return f(pmsg.Data)
9898
}))
9999
}
100+
func (c *CorruptPubSubAdapterConfig) WithScoreTracer(_ p2p.PeerScoreTracer) {
101+
// CorruptPubSub does not support score tracer. This is a no-op.
102+
}
100103

101104
func (c *CorruptPubSubAdapterConfig) Build() []corrupt.Option {
102105
return c.options

insecure/internal/factory.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package internal
22

33
import (
4-
"github.com/onflow/flow-go/network/p2p/p2pbuilder"
4+
"github.com/onflow/flow-go/network/p2p"
55
p2ptest "github.com/onflow/flow-go/network/p2p/test"
66
)
77

8-
func WithCorruptGossipSub(factory p2pbuilder.GossipSubFactoryFunc, config p2pbuilder.GossipSubAdapterConfigFunc) p2ptest.NodeFixtureParameterOption {
8+
func WithCorruptGossipSub(factory p2p.GossipSubFactoryFunc, config p2p.GossipSubAdapterConfigFunc) p2ptest.NodeFixtureParameterOption {
99
return func(p *p2ptest.NodeFixtureParameters) {
1010
p.GossipSubFactory = factory
1111
p.GossipSubConfig = config

0 commit comments

Comments
 (0)