Skip to content

Commit 7d086e0

Browse files
authored
Merge branch 'master' into tarak/randomness-part5-ledger
2 parents e961761 + 10204df commit 7d086e0

File tree

121 files changed

+3631
-2102
lines changed

Some content is hidden

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

121 files changed

+3631
-2102
lines changed

.github/workflows/bench.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ jobs:
2020
benchstat:
2121
name: Performance regression check
2222
runs-on: ubuntu-latest
23+
# Check if the event is not triggered by a fork
24+
# peter-evans/find-comment@v1 does not work on forks.
25+
# see https://github.com/peter-evans/create-pull-request/blob/main/docs/concepts-guidelines.md#restrictions-on-repository-forks for details.
26+
# Ideally we would like to still run the benchmark on forks, but we can't do that with the current setup.
27+
if: github.event.pull_request.head.repo.full_name == github.repository
2328
continue-on-error: true
2429
steps:
2530
- name: Set benchmark repetitions

access/validator.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ import (
55
"fmt"
66

77
"github.com/onflow/flow-go/crypto"
8+
"github.com/onflow/flow-go/state"
89

910
"github.com/onflow/cadence/runtime/parser"
1011

1112
"github.com/onflow/flow-go/model/flow"
1213
"github.com/onflow/flow-go/state/protocol"
13-
"github.com/onflow/flow-go/storage"
1414
)
1515

1616
type Blocks interface {
@@ -29,7 +29,7 @@ func NewProtocolStateBlocks(state protocol.State) *ProtocolStateBlocks {
2929
func (b *ProtocolStateBlocks) HeaderByID(id flow.Identifier) (*flow.Header, error) {
3030
header, err := b.state.AtBlockID(id).Head()
3131
if err != nil {
32-
if errors.Is(err, storage.ErrNotFound) {
32+
if errors.Is(err, state.ErrUnknownSnapshotReference) {
3333
return nil, nil
3434
}
3535

cmd/access/node_builder/access_node_builder.go

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ import (
6868
"github.com/onflow/flow-go/network/p2p/dht"
6969
"github.com/onflow/flow-go/network/p2p/middleware"
7070
"github.com/onflow/flow-go/network/p2p/p2pbuilder"
71+
"github.com/onflow/flow-go/network/p2p/p2pbuilder/inspector"
7172
"github.com/onflow/flow-go/network/p2p/subscription"
7273
"github.com/onflow/flow-go/network/p2p/tracer"
7374
"github.com/onflow/flow-go/network/p2p/translator"
@@ -170,7 +171,7 @@ func DefaultAccessNodeConfig() *AccessNodeConfig {
170171
BindAddress: cmd.NotSet,
171172
Metrics: metrics.NewNoopCollector(),
172173
},
173-
executionDataSyncEnabled: false,
174+
executionDataSyncEnabled: true,
174175
executionDataDir: filepath.Join(homedir, ".flow", "execution_data"),
175176
executionDataStartHeight: 0,
176177
executionDataConfig: edrequester.ExecutionDataConfig{
@@ -236,7 +237,15 @@ func (builder *FlowAccessNodeBuilder) buildFollowerState() *FlowAccessNodeBuilde
236237
return fmt.Errorf("only implementations of type badger.State are currently supported but read-only state has type %T", node.State)
237238
}
238239

239-
followerState, err := badgerState.NewFollowerState(state, node.Storage.Index, node.Storage.Payloads, node.Tracer, node.ProtocolEvents, blocktimer.DefaultBlockTimer)
240+
followerState, err := badgerState.NewFollowerState(
241+
node.Logger,
242+
node.Tracer,
243+
node.ProtocolEvents,
244+
state,
245+
node.Storage.Index,
246+
node.Storage.Payloads,
247+
blocktimer.DefaultBlockTimer,
248+
)
240249
builder.FollowerState = followerState
241250

242251
return err
@@ -333,7 +342,6 @@ func (builder *FlowAccessNodeBuilder) buildFollowerEngine() *FlowAccessNodeBuild
333342
builder.Validator,
334343
builder.SyncCore,
335344
node.Tracer,
336-
modulecompliance.WithSkipNewProposalsThreshold(node.ComplianceConfig.SkipNewProposalsThreshold),
337345
)
338346
if err != nil {
339347
return nil, fmt.Errorf("could not create follower core: %w", err)
@@ -347,6 +355,7 @@ func (builder *FlowAccessNodeBuilder) buildFollowerEngine() *FlowAccessNodeBuild
347355
node.Storage.Headers,
348356
builder.Finalized,
349357
core,
358+
followereng.WithComplianceConfigOpt(modulecompliance.WithSkipNewProposalsThreshold(node.ComplianceConfig.SkipNewProposalsThreshold)),
350359
)
351360
if err != nil {
352361
return nil, fmt.Errorf("could not create follower engine: %w", err)
@@ -1020,7 +1029,7 @@ func (builder *FlowAccessNodeBuilder) enqueuePublicNetworkInit() {
10201029
}).
10211030
Component("public libp2p node", func(node *cmd.NodeConfig) (module.ReadyDoneAware, error) {
10221031

1023-
libP2PFactory := builder.initLibP2PFactory(builder.NodeConfig.NetworkKey, builder.PublicNetworkConfig.BindAddress, builder.PublicNetworkConfig.Metrics)
1032+
libP2PFactory := builder.initPublicLibP2PFactory(builder.NodeConfig.NetworkKey, builder.PublicNetworkConfig.BindAddress, builder.PublicNetworkConfig.Metrics)
10241033

10251034
var err error
10261035
libp2pNode, err = libP2PFactory()
@@ -1066,15 +1075,15 @@ func (builder *FlowAccessNodeBuilder) enqueuePublicNetworkInit() {
10661075
})
10671076
}
10681077

1069-
// initLibP2PFactory creates the LibP2P factory function for the given node ID and network key.
1078+
// initPublicLibP2PFactory creates the LibP2P factory function for the given node ID and network key.
10701079
// The factory function is later passed into the initMiddleware function to eventually instantiate the p2p.LibP2PNode instance
10711080
// The LibP2P host is created with the following options:
10721081
// - DHT as server
10731082
// - The address from the node config or the specified bind address as the listen address
10741083
// - The passed in private key as the libp2p key
10751084
// - No connection gater
10761085
// - Default Flow libp2p pubsub options
1077-
func (builder *FlowAccessNodeBuilder) initLibP2PFactory(networkKey crypto.PrivateKey, bindAddress string, networkMetrics module.LibP2PMetrics) p2p.LibP2PFactoryFunc {
1086+
func (builder *FlowAccessNodeBuilder) initPublicLibP2PFactory(networkKey crypto.PrivateKey, bindAddress string, networkMetrics module.LibP2PMetrics) p2p.LibP2PFactoryFunc {
10781087
return func() (p2p.LibP2PNode, error) {
10791088
connManager, err := connection.NewConnManager(builder.Logger, networkMetrics, builder.ConnectionManagerConfig)
10801089
if err != nil {
@@ -1087,6 +1096,16 @@ func (builder *FlowAccessNodeBuilder) initLibP2PFactory(networkKey crypto.Privat
10871096
builder.IdentityProvider,
10881097
builder.GossipSubConfig.LocalMeshLogInterval)
10891098

1099+
// setup RPC inspectors
1100+
rpcInspectorBuilder := inspector.NewGossipSubInspectorBuilder(builder.Logger, builder.SporkID, builder.GossipSubRPCInspectorsConfig, builder.GossipSubInspectorNotifDistributor)
1101+
rpcInspectors, err := rpcInspectorBuilder.
1102+
SetPublicNetwork(p2p.PublicNetworkEnabled).
1103+
SetMetrics(builder.Metrics.Network, builder.MetricsRegisterer).
1104+
SetMetricsEnabled(builder.MetricsEnabled).Build()
1105+
if err != nil {
1106+
return nil, fmt.Errorf("failed to create gossipsub rpc inspectors: %w", err)
1107+
}
1108+
10901109
libp2pNode, err := p2pbuilder.NewNodeBuilder(
10911110
builder.Logger,
10921111
networkMetrics,
@@ -1116,6 +1135,7 @@ func (builder *FlowAccessNodeBuilder) initLibP2PFactory(networkKey crypto.Privat
11161135
SetStreamCreationRetryInterval(builder.UnicastCreateStreamRetryDelay).
11171136
SetGossipSubTracer(meshTracer).
11181137
SetGossipSubScoreTracerInterval(builder.GossipSubConfig.ScoreTracerInterval).
1138+
SetGossipSubRPCInspectors(rpcInspectors...).
11191139
Build()
11201140

11211141
if err != nil {

cmd/collection/main.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,15 @@ func main() {
183183
if !ok {
184184
return fmt.Errorf("only implementations of type badger.State are currently supported but read-only state has type %T", node.State)
185185
}
186-
followerState, err = badgerState.NewFollowerState(state, node.Storage.Index, node.Storage.Payloads, node.Tracer, node.ProtocolEvents, blocktimer.DefaultBlockTimer)
186+
followerState, err = badgerState.NewFollowerState(
187+
node.Logger,
188+
node.Tracer,
189+
node.ProtocolEvents,
190+
state,
191+
node.Storage.Index,
192+
node.Storage.Payloads,
193+
blocktimer.DefaultBlockTimer,
194+
)
187195
return err
188196
}).
189197
Module("transactions mempool", func(node *cmd.NodeConfig) error {
@@ -229,7 +237,7 @@ func main() {
229237
return nil
230238
}).
231239
Component("machine account config validator", func(node *cmd.NodeConfig) (module.ReadyDoneAware, error) {
232-
//@TODO use fallback logic for flowClient similar to DKG/QC contract clients
240+
// @TODO use fallback logic for flowClient similar to DKG/QC contract clients
233241
flowClient, err := common.FlowClient(flowClientConfigs[0])
234242
if err != nil {
235243
return nil, fmt.Errorf("failed to get flow client connection option for access node (0): %s %w", flowClientConfigs[0].AccessAddress, err)
@@ -317,7 +325,6 @@ func main() {
317325
validator,
318326
mainChainSyncCore,
319327
node.Tracer,
320-
modulecompliance.WithSkipNewProposalsThreshold(node.ComplianceConfig.SkipNewProposalsThreshold),
321328
)
322329
if err != nil {
323330
return nil, fmt.Errorf("could not create follower core: %w", err)
@@ -331,6 +338,7 @@ func main() {
331338
node.Storage.Headers,
332339
finalizedHeader.Get(),
333340
core,
341+
followereng.WithComplianceConfigOpt(modulecompliance.WithSkipNewProposalsThreshold(node.ComplianceConfig.SkipNewProposalsThreshold)),
334342
)
335343
if err != nil {
336344
return nil, fmt.Errorf("could not create follower engine: %w", err)

cmd/consensus/main.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,17 @@ func main() {
242242
return err
243243
}
244244

245-
mutableState, err = badgerState.NewFullConsensusState(state, node.Storage.Index, node.Storage.Payloads, node.Tracer, node.ProtocolEvents, blockTimer, receiptValidator, sealValidator)
245+
mutableState, err = badgerState.NewFullConsensusState(
246+
node.Logger,
247+
node.Tracer,
248+
node.ProtocolEvents,
249+
state,
250+
node.Storage.Index,
251+
node.Storage.Payloads,
252+
blockTimer,
253+
receiptValidator,
254+
sealValidator,
255+
)
246256
return err
247257
}).
248258
Module("random beacon key", func(node *cmd.NodeConfig) error {
@@ -377,7 +387,7 @@ func main() {
377387
return nil
378388
}).
379389
Component("machine account config validator", func(node *cmd.NodeConfig) (module.ReadyDoneAware, error) {
380-
//@TODO use fallback logic for flowClient similar to DKG/QC contract clients
390+
// @TODO use fallback logic for flowClient similar to DKG/QC contract clients
381391
flowClient, err := common.FlowClient(flowClientConfigs[0])
382392
if err != nil {
383393
return nil, fmt.Errorf("failed to get flow client connection option for access node (0): %s %w", flowClientConfigs[0].AccessAddress, err)

cmd/execution_builder.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,15 @@ func (exeNode *ExecutionNode) LoadMutableFollowerState(node *NodeConfig) error {
216216
return fmt.Errorf("only implementations of type badger.State are currently supported but read-only state has type %T", node.State)
217217
}
218218
var err error
219-
exeNode.followerState, err = badgerState.NewFollowerState(bState, node.Storage.Index, node.Storage.Payloads, node.Tracer, node.ProtocolEvents, blocktimer.DefaultBlockTimer)
219+
exeNode.followerState, err = badgerState.NewFollowerState(
220+
node.Logger,
221+
node.Tracer,
222+
node.ProtocolEvents,
223+
bState,
224+
node.Storage.Index,
225+
node.Storage.Payloads,
226+
blocktimer.DefaultBlockTimer,
227+
)
220228
return err
221229
}
222230

@@ -899,7 +907,6 @@ func (exeNode *ExecutionNode) LoadFollowerEngine(
899907
validator,
900908
exeNode.syncCore,
901909
node.Tracer,
902-
compliance.WithSkipNewProposalsThreshold(node.ComplianceConfig.SkipNewProposalsThreshold),
903910
)
904911
if err != nil {
905912
return nil, fmt.Errorf("could not create follower core: %w", err)
@@ -913,6 +920,7 @@ func (exeNode *ExecutionNode) LoadFollowerEngine(
913920
node.Storage.Headers,
914921
exeNode.finalizedHeader.Get(),
915922
core,
923+
followereng.WithComplianceConfigOpt(compliance.WithSkipNewProposalsThreshold(node.ComplianceConfig.SkipNewProposalsThreshold)),
916924
)
917925
if err != nil {
918926
return nil, fmt.Errorf("could not create follower engine: %w", err)

cmd/node_builder.go

Lines changed: 16 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ import (
66
"path/filepath"
77
"time"
88

9-
"github.com/onflow/flow-go/network/p2p/distributor"
10-
"github.com/onflow/flow-go/network/p2p/p2pbuilder"
11-
129
"github.com/dgraph-io/badger/v2"
1310
madns "github.com/multiformats/go-multiaddr-dns"
1411
"github.com/prometheus/client_golang/prometheus"
@@ -29,9 +26,11 @@ import (
2926
"github.com/onflow/flow-go/network/codec/cbor"
3027
"github.com/onflow/flow-go/network/p2p"
3128
"github.com/onflow/flow-go/network/p2p/connection"
29+
"github.com/onflow/flow-go/network/p2p/distributor"
3230
"github.com/onflow/flow-go/network/p2p/dns"
33-
"github.com/onflow/flow-go/network/p2p/inspector/validation"
3431
"github.com/onflow/flow-go/network/p2p/middleware"
32+
"github.com/onflow/flow-go/network/p2p/p2pbuilder"
33+
inspectorbuilder "github.com/onflow/flow-go/network/p2p/p2pbuilder/inspector"
3534
"github.com/onflow/flow-go/network/p2p/unicast"
3635
"github.com/onflow/flow-go/state/protocol"
3736
"github.com/onflow/flow-go/state/protocol/events"
@@ -185,7 +184,10 @@ type NetworkConfig struct {
185184
// that are not part of protocol state should be trimmed
186185
// TODO: solely a fallback mechanism, can be removed upon reliable behavior in production.
187186
NetworkConnectionPruning bool
188-
GossipSubConfig *p2pbuilder.GossipSubConfig
187+
// GossipSubConfig core gossipsub configuration.
188+
GossipSubConfig *p2pbuilder.GossipSubConfig
189+
// GossipSubRPCInspectorsConfig configuration for all gossipsub RPC control message inspectors.
190+
GossipSubRPCInspectorsConfig *inspectorbuilder.GossipSubRPCInspectorsConfig
189191
// PreferredUnicastProtocols list of unicast protocols in preferred order
190192
PreferredUnicastProtocols []string
191193
NetworkReceivedMessageCacheSize uint32
@@ -199,11 +201,8 @@ type NetworkConfig struct {
199201
UnicastCreateStreamRetryDelay time.Duration
200202
// size of the queue for notifications about new peers in the disallow list.
201203
DisallowListNotificationCacheSize uint32
202-
// size of the queue for notifications about gossipsub RPC inspections.
203-
GossipSubRPCInspectorNotificationCacheSize uint32
204-
GossipSubRPCInspectorCacheSize uint32
205-
UnicastRateLimitersConfig *UnicastRateLimitersConfig
206-
GossipSubRPCValidationConfigs *p2pbuilder.GossipSubRPCValidationConfigs
204+
// UnicastRateLimitersConfig configuration for all unicast rate limiters.
205+
UnicastRateLimitersConfig *UnicastRateLimitersConfig
207206
}
208207

209208
// UnicastRateLimitersConfig unicast rate limiter configuration for the message and bandwidth rate limiters.
@@ -301,27 +300,13 @@ func DefaultBaseConfig() *BaseConfig {
301300
BandwidthRateLimit: 0,
302301
BandwidthBurstLimit: middleware.LargeMsgMaxUnicastMsgSize,
303302
},
304-
GossipSubRPCValidationConfigs: &p2pbuilder.GossipSubRPCValidationConfigs{
305-
NumberOfWorkers: validation.DefaultNumberOfWorkers,
306-
GraftLimits: map[string]int{
307-
validation.DiscardThresholdMapKey: validation.DefaultGraftDiscardThreshold,
308-
validation.SafetyThresholdMapKey: validation.DefaultGraftSafetyThreshold,
309-
validation.RateLimitMapKey: validation.DefaultGraftRateLimit,
310-
},
311-
PruneLimits: map[string]int{
312-
validation.DiscardThresholdMapKey: validation.DefaultPruneDiscardThreshold,
313-
validation.SafetyThresholdMapKey: validation.DefaultPruneSafetyThreshold,
314-
validation.RateLimitMapKey: validation.DefaultPruneRateLimit,
315-
},
316-
},
317-
DNSCacheTTL: dns.DefaultTimeToLive,
318-
LibP2PResourceManagerConfig: p2pbuilder.DefaultResourceManagerConfig(),
319-
ConnectionManagerConfig: connection.DefaultConnManagerConfig(),
320-
NetworkConnectionPruning: connection.ConnectionPruningEnabled,
321-
GossipSubConfig: p2pbuilder.DefaultGossipSubConfig(),
322-
GossipSubRPCInspectorNotificationCacheSize: distributor.DefaultGossipSubInspectorNotificationQueueCacheSize,
323-
GossipSubRPCInspectorCacheSize: validation.DefaultControlMsgValidationInspectorQueueCacheSize,
324-
DisallowListNotificationCacheSize: distributor.DefaultDisallowListNotificationQueueCacheSize,
303+
GossipSubConfig: p2pbuilder.DefaultGossipSubConfig(),
304+
GossipSubRPCInspectorsConfig: inspectorbuilder.DefaultGossipSubRPCInspectorsConfig(),
305+
DNSCacheTTL: dns.DefaultTimeToLive,
306+
LibP2PResourceManagerConfig: p2pbuilder.DefaultResourceManagerConfig(),
307+
ConnectionManagerConfig: connection.DefaultConnManagerConfig(),
308+
NetworkConnectionPruning: connection.ConnectionPruningEnabled,
309+
DisallowListNotificationCacheSize: distributor.DefaultDisallowListNotificationQueueCacheSize,
325310
},
326311
nodeIDHex: NotSet,
327312
AdminAddr: NotSet,

0 commit comments

Comments
 (0)