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

Update Stable Cadence feature branch #5451

Merged
merged 72 commits into from
Feb 23, 2024

Conversation

turbolent
Copy link
Member

Conflict resolution:
commit 13deb4efa6b3173b0eecf969b044ce9239f68d26
Merge: 9bcc86275a 85cc479264
Author: Bastian Müller <bastian@turbolent.com>
Date:   Fri Feb 23 10:51:27 2024 -0800

    Merge branch 'master' into bastian/update-stable-cadence-12

diff --git a/cmd/util/cmd/execution-state-extract/cmd.go b/cmd/util/cmd/execution-state-extract/cmd.go
remerge CONFLICT (content): Merge conflict in cmd/util/cmd/execution-state-extract/cmd.go
index 638b424d64..db04319c0e 100644
--- a/cmd/util/cmd/execution-state-extract/cmd.go
+++ b/cmd/util/cmd/execution-state-extract/cmd.go
@@ -32,13 +32,10 @@ var (
 	flagNoReport                  bool
 	flagValidateMigration         bool
 	flagLogVerboseValidationError bool
-<<<<<<< 9bcc86275a (Merge pull request #5405 from onflow/supun/contract-update-validator)
 	flagStagedContractsFile       string
-=======
 	flagInputPayloadFileName      string
 	flagOutputPayloadFileName     string
 	flagOutputPayloadByAddresses  string
->>>>>>> 85cc479264 (Merge pull request #5450 from onflow/bastian/fix-load-types-evm-test)
 )
 
 var Cmd = &cobra.Command{
@@ -82,10 +79,9 @@ func init() {
 	Cmd.Flags().BoolVar(&flagLogVerboseValidationError, "log-verbose-validation-error", false,
 		"log entire Cadence values on validation error (atree migration)")
 
-<<<<<<< 9bcc86275a (Merge pull request #5405 from onflow/supun/contract-update-validator)
 	Cmd.Flags().StringVar(&flagStagedContractsFile, "staged-contracts", "",
 		"Staged contracts CSV file")
-=======
+
 	// If specified, the state will consist of payloads from the given input payload file.
 	// If not specified, then the state will be extracted from the latest checkpoint file.
 	// This flag can be used to reduce total duration of migrations when state extraction involves
@@ -115,7 +111,6 @@ func init() {
 		"",
 		"extract payloads of addresses (comma separated hex-encoded addresses) to file specified by output-payload-filename",
 	)
->>>>>>> 85cc479264 (Merge pull request #5450 from onflow/bastian/fix-load-types-evm-test)
 }
 
 func run(*cobra.Command, []string) {
@@ -225,20 +220,6 @@ func run(*cobra.Command, []string) {
 		log.Warn().Msgf("atree migration has verbose validation error logging enabled which may increase size of log")
 	}
 
-<<<<<<< 9bcc86275a (Merge pull request #5405 from onflow/supun/contract-update-validator)
-	err := extractExecutionState(
-		log.Logger,
-		flagExecutionStateDir,
-		stateCommitment,
-		flagOutputDir,
-		flagNWorker,
-		!flagNoMigration,
-		chain.ChainID(),
-		// TODO:
-		migrations.EVMContractChangeNone,
-		flagStagedContractsFile,
-	)
-=======
 	var inputMsg string
 	if len(flagInputPayloadFileName) > 0 {
 		// Input is payloads
@@ -274,7 +255,15 @@ func run(*cobra.Command, []string) {
 
 	log.Info().Msgf("state extraction plan: %s, %s", inputMsg, outputMsg)
 
-	var err error
+	chainID := chain.ChainID()
+	// TODO:
+	evmContractChange := migrations.EVMContractChangeNone
+
+	stagedContracts, err := migrations.StagedContractsFromCSV(flagStagedContractsFile)
+	if err != nil {
+		log.Fatal().Err(err).Msgf("error loading staged contracts: %s", err.Error())
+	}
+
 	if len(flagInputPayloadFileName) > 0 {
 		err = extractExecutionStateFromPayloads(
 			log.Logger,
@@ -282,6 +271,9 @@ func run(*cobra.Command, []string) {
 			flagOutputDir,
 			flagNWorker,
 			!flagNoMigration,
+			chainID,
+			evmContractChange,
+			stagedContracts,
 			flagInputPayloadFileName,
 			flagOutputPayloadFileName,
 			exportedAddresses,
@@ -294,11 +286,13 @@ func run(*cobra.Command, []string) {
 			flagOutputDir,
 			flagNWorker,
 			!flagNoMigration,
+			chainID,
+			evmContractChange,
+			stagedContracts,
 			flagOutputPayloadFileName,
 			exportedAddresses,
 		)
 	}
->>>>>>> 85cc479264 (Merge pull request #5450 from onflow/bastian/fix-load-types-evm-test)
 
 	if err != nil {
 		log.Fatal().Err(err).Msgf("error extracting the execution state: %s", err.Error())
diff --git a/cmd/util/cmd/execution-state-extract/execution_state_extract.go b/cmd/util/cmd/execution-state-extract/execution_state_extract.go
remerge CONFLICT (content): Merge conflict in cmd/util/cmd/execution-state-extract/execution_state_extract.go
index 6c71286363..4cfe396b2d 100644
--- a/cmd/util/cmd/execution-state-extract/execution_state_extract.go
+++ b/cmd/util/cmd/execution-state-extract/execution_state_extract.go
@@ -37,14 +37,11 @@ func extractExecutionState(
 	outputDir string,
 	nWorker int, // number of concurrent worker to migration payloads
 	runMigrations bool,
-<<<<<<< 9bcc86275a (Merge pull request #5405 from onflow/supun/contract-update-validator)
 	chainID flow.ChainID,
 	evmContractChange migrators.EVMContractChange,
-	stagedContractsFile string,
-=======
+	stagedContracts []migrators.StagedContract,
 	outputPayloadFile string,
 	exportPayloadsByAddresses []common.Address,
->>>>>>> 85cc479264 (Merge pull request #5450 from onflow/bastian/fix-load-types-evm-test)
 ) error {
 
 	log.Info().Msg("init WAL")
@@ -95,29 +92,15 @@ func extractExecutionState(
 		<-compactor.Done()
 	}()
 
-<<<<<<< 9bcc86275a (Merge pull request #5405 from onflow/supun/contract-update-validator)
-	var migrations []ledger.Migration
-
-	stagedContracts, err := migrators.StagedContractsFromCSV(stagedContractsFile)
-	if err != nil {
-		return err
-	}
-
-	if runMigrations {
-		rwf := reporters.NewReportFileWriterFactory(dir, log)
-
-		migrations = migrators.NewCadence1Migrations(
+	migrations := newMigrations(
 		log,
-			rwf,
+		dir,
 		nWorker,
+		runMigrations,
 		chainID,
 		evmContractChange,
 		stagedContracts,
 	)
-	}
-=======
-	migrations := newMigrations(log, dir, nWorker, runMigrations)
->>>>>>> 85cc479264 (Merge pull request #5450 from onflow/bastian/fix-load-types-evm-test)
 
 	newState := ledger.State(targetHash)
 
@@ -227,6 +210,9 @@ func extractExecutionStateFromPayloads(
 	outputDir string,
 	nWorker int, // number of concurrent worker to migation payloads
 	runMigrations bool,
+	chainID flow.ChainID,
+	evmContractChange migrators.EVMContractChange,
+	stagedContracts []migrators.StagedContract,
 	inputPayloadFile string,
 	outputPayloadFile string,
 	exportPayloadsByAddresses []common.Address,
@@ -239,7 +225,15 @@ func extractExecutionStateFromPayloads(
 
 	log.Info().Msgf("read %d payloads", len(payloads))
 
-	migrations := newMigrations(log, dir, nWorker, runMigrations)
+	migrations := newMigrations(
+		log,
+		dir,
+		nWorker,
+		runMigrations,
+		chainID,
+		evmContractChange,
+		stagedContracts,
+	)
 
 	payloads, err = migratePayloads(log, payloads, migrations)
 	if err != nil {
@@ -354,33 +348,24 @@ func createTrieFromPayloads(logger zerolog.Logger, payloads []*ledger.Payload) (
 func newMigrations(
 	log zerolog.Logger,
 	dir string,
-	nWorker int, // number of concurrent worker to migation payloads
+	nWorker int,
 	runMigrations bool,
+	chainID flow.ChainID,
+	evmContractChange migrators.EVMContractChange,
+	stagedContracts []migrators.StagedContract,
 ) []ledger.Migration {
-	if runMigrations {
+	if !runMigrations {
+		return nil
+	}
+
 	rwf := reporters.NewReportFileWriterFactory(dir, log)
 
-		migrations := []ledger.Migration{
-			migrators.CreateAccountBasedMigration(
+	return migrators.NewCadence1Migrations(
 		log,
-				nWorker,
-				[]migrators.AccountBasedMigration{
-					migrators.NewAtreeRegisterMigrator(
 		rwf,
-						flagValidateMigration,
-						flagLogVerboseValidationError,
-					),
-
-					&migrators.DeduplicateContractNamesMigration{},
-
-					// This will fix storage used discrepancies caused by the
-					// DeduplicateContractNamesMigration.
-					&migrators.AccountUsageMigrator{},
-				}),
-		}
-
-		return migrations
-	}
-
-	return nil
+		nWorker,
+		chainID,
+		evmContractChange,
+		stagedContracts,
+	)
 }
diff --git a/cmd/util/cmd/execution-state-extract/execution_state_extract_test.go b/cmd/util/cmd/execution-state-extract/execution_state_extract_test.go
remerge CONFLICT (content): Merge conflict in cmd/util/cmd/execution-state-extract/execution_state_extract_test.go
index 694543ca14..f936733480 100644
--- a/cmd/util/cmd/execution-state-extract/execution_state_extract_test.go
+++ b/cmd/util/cmd/execution-state-extract/execution_state_extract_test.go
@@ -15,11 +15,8 @@ import (
 	runtimeCommon "github.com/onflow/cadence/runtime/common"
 
 	"github.com/onflow/flow-go/cmd/util/cmd/common"
-<<<<<<< 9bcc86275a (Merge pull request #5405 from onflow/supun/contract-update-validator)
 	"github.com/onflow/flow-go/cmd/util/ledger/migrations"
-=======
 	"github.com/onflow/flow-go/cmd/util/ledger/util"
->>>>>>> 85cc479264 (Merge pull request #5450 from onflow/bastian/fix-load-types-evm-test)
 	"github.com/onflow/flow-go/ledger"
 	"github.com/onflow/flow-go/ledger/common/pathfinder"
 	"github.com/onflow/flow-go/ledger/complete"
@@ -76,15 +73,12 @@ func TestExtractExecutionState(t *testing.T) {
 				outdir,
 				10,
 				false,
-<<<<<<< 9bcc86275a (Merge pull request #5405 from onflow/supun/contract-update-validator)
 				flow.Emulator,
 				// TODO:
 				migrations.EVMContractChangeNone,
-				"",
-=======
+				nil,
 				"",
 				nil,
->>>>>>> 85cc479264 (Merge pull request #5450 from onflow/bastian/fix-load-types-evm-test)
 			)
 			require.Error(t, err)
 		})

@fxamacker Can you please have a look at the conflict resolution and double check I resolved the conflicts between our changes correctly?

yhassanzadeh13 and others added 30 commits February 8, 2024 10:03
Added two flags to execution state extraction program:

--extract-payloads-by-address produces a file of payloads for
specified accounts or for all accounts instead of checkpoint files

--use-payload-as-input uses payload file as input instead of
checkpoint files

The two new flags don't affect migration and other existing
functionaly of state extraction program.  These two options
only affect input and output of state extraction program.

In other words, this can be used to extract migrated payloads
or extract as-is payloads for specified accounts.
Co-authored-by: Bastian Müller <bastian@turbolent.com>
Refactored payload file related functionality to be more reusable.

Added flags:
--input-payload-filename
--output-payload-filename
This utility can be used to create a subset of execution state
which can save time during development, testing, and
support/troubleshooting.
kc1116 and others added 21 commits February 21, 2024 09:36
Co-authored-by: Yahya Hassanzadeh, Ph.D. <yhassanzadeh@ieee.org>
Co-authored-by: Yahya Hassanzadeh, Ph.D. <yhassanzadeh@ieee.org>
Co-authored-by: Yahya Hassanzadeh, Ph.D. <yhassanzadeh@ieee.org>
…flow/flow-go into khalil/6934-invalid-topicid-threshold
…state-extraction

Optimize migration by adding ability to read or extract payloads from state
[Networking] Simplifies RPC inspection misbehavior notification handling
…shold

[Networking] Enhance Gossipsub Resilience: Configurable Threshold for Invalid Topic IDs in Control Messages
@turbolent turbolent requested review from a team February 23, 2024 18:54
@codecov-commenter
Copy link

codecov-commenter commented Feb 23, 2024

Codecov Report

Attention: Patch coverage is 59.46276% with 332 lines in your changes are missing coverage. Please review.

Project coverage is 56.35%. Comparing base (9bcc862) to head (13deb4e).

Files Patch % Lines
cmd/util/cmd/extract-payloads-by-address/cmd.go 59.01% 50 Missing and 25 partials ⚠️
...execution-state-extract/execution_state_extract.go 58.50% 53 Missing and 8 partials ⚠️
...dule/metrics/gossipsub_rpc_validation_inspector.go 0.00% 57 Missing ⚠️
cmd/util/ledger/util/payload_file.go 64.49% 33 Missing and 16 partials ⚠️
network/netconf/flags.go 35.84% 34 Missing ⚠️
cmd/util/cmd/execution-state-extract/cmd.go 81.81% 16 Missing and 8 partials ⚠️
module/metrics/noop.go 0.00% 19 Missing ⚠️
network/p2p/test/fixtures.go 0.00% 4 Missing and 1 partial ⚠️
network/p2p/scoring/noopConsumer.go 0.00% 4 Missing ⚠️
network/p2p/builder/libp2pNodeBuilder.go 0.00% 3 Missing ⚠️
... and 1 more
Additional details and impacted files
@@                    Coverage Diff                     @@
##           feature/stable-cadence    #5451      +/-   ##
==========================================================
+ Coverage                   56.33%   56.35%   +0.01%     
==========================================================
  Files                        1030     1032       +2     
  Lines                      100025   100620     +595     
==========================================================
+ Hits                        56354    56702     +348     
- Misses                      39410    39608     +198     
- Partials                     4261     4310      +49     
Flag Coverage Δ
unittests 56.35% <59.46%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@turbolent turbolent merged commit b295bd5 into feature/stable-cadence Feb 23, 2024
50 of 51 checks passed
@turbolent turbolent deleted the bastian/update-stable-cadence-12 branch February 23, 2024 19:48
@fxamacker
Copy link
Member

@fxamacker Can you please have a look at the conflict resolution and double check I resolved the conflicts between our changes correctly?

@turbolent LGTM!

@turbolent
Copy link
Member Author

Thanks @fxamacker!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants