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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
e7320d0
moves distributor logic into score registry
yhassanzadeh13 Feb 8, 2024
a5c7b8d
wip
yhassanzadeh13 Feb 8, 2024
9cad443
cleans up distributor and inspector suit
yhassanzadeh13 Feb 9, 2024
bb8ac36
renames a method on builder
yhassanzadeh13 Feb 9, 2024
308b780
removes inspector suite factory func
yhassanzadeh13 Feb 9, 2024
f1571b4
removes distributor and inspector suite interfaces
yhassanzadeh13 Feb 9, 2024
5e344ca
adds notification consumer to score option
yhassanzadeh13 Feb 9, 2024
4a63d82
moves worker pool to score registry
yhassanzadeh13 Feb 9, 2024
e7acb98
refactors gossipsub builder to use the inspector than suite
yhassanzadeh13 Feb 9, 2024
e5e86d6
adds invalid control message notification consumer as a base dependency
yhassanzadeh13 Feb 9, 2024
90c2bcd
removes overriding inspector suite func
yhassanzadeh13 Feb 9, 2024
7cde571
renames a method
yhassanzadeh13 Feb 9, 2024
77589bd
generates mocks
yhassanzadeh13 Feb 9, 2024
006768c
Revert "removes overriding inspector suite func"
yhassanzadeh13 Feb 12, 2024
7fde32d
Revert "removes inspector suite factory func"
yhassanzadeh13 Feb 12, 2024
5ee4b87
fixes rpc inspector tests
yhassanzadeh13 Feb 13, 2024
aea636a
add invalid topic ID threshold configuration and flags
kc1116 Feb 13, 2024
1d572c5
add invalid topic unit tests above/below threshold for each control m…
kc1116 Feb 13, 2024
85527b8
Add ability to read or extract payloads from state
fxamacker Feb 13, 2024
9b1fc05
Add t.Parallel() to test
fxamacker Feb 13, 2024
5d5eb09
Remove t.Parallel() to clean output dir correctly
fxamacker Feb 13, 2024
34d325c
Merge branch 'master' into fxamacker/extract-payloads-from-state-extr…
fxamacker Feb 13, 2024
392b842
Refactor & add flags for payloads in state extraction
fxamacker Feb 13, 2024
7477666
Optimize payload filtering in state extraction
fxamacker Feb 13, 2024
67ec2e2
Add tests for payload file related functionality
fxamacker Feb 13, 2024
48edc60
Add utility to extract payloads by addresses
fxamacker Feb 13, 2024
75e1099
Refactor to use named magic number for CBOR data
fxamacker Feb 14, 2024
46c1c7a
update tests and add metrics
kc1116 Feb 14, 2024
0e9356d
fixes inspector validation test
yhassanzadeh13 Feb 15, 2024
dfb2c9b
Merge branch 'master' into yahya/simplify-rpc-inspection
yhassanzadeh13 Feb 15, 2024
6eaa46d
fixes tests
yhassanzadeh13 Feb 15, 2024
e10006b
Merge branch 'yahya/simplify-rpc-inspection' of github.com:onflow/flo…
yhassanzadeh13 Feb 15, 2024
86a9ba4
re-generates mocks
yhassanzadeh13 Feb 15, 2024
27e9dc0
Merge pull request #5389 from onflow/fxamacker/extract-payloads-by-ad…
fxamacker Feb 15, 2024
b2934fb
Merge branch 'master' into fxamacker/extract-payloads-from-state-extr…
fxamacker Feb 15, 2024
2a21a44
fixing tests
yhassanzadeh13 Feb 16, 2024
3275b22
fixes TestScoreRegistry_SpamRecordWithoutDuplicateMessagesPenalty
yhassanzadeh13 Feb 16, 2024
d72ccac
fixes testScoreRegistryPeerWithSpamRecord
yhassanzadeh13 Feb 16, 2024
832d285
fixes TestScoreRegistry_SpamRecordWithUnknownIdentity
yhassanzadeh13 Feb 16, 2024
29302d6
fixes TestScoreRegistry_SpamRecordWithSubscriptionPenalty
yhassanzadeh13 Feb 16, 2024
27bbd0f
fixes all scoring tests
yhassanzadeh13 Feb 16, 2024
ee2ca4c
Add suggested comments from feedback
fxamacker Feb 16, 2024
182bcf6
adds documentations to the gossipsub builder
yhassanzadeh13 Feb 16, 2024
5267830
adds documentation and renames a method
yhassanzadeh13 Feb 16, 2024
03fb255
adds a godoc
yhassanzadeh13 Feb 16, 2024
f7d5549
removes an unused function
yhassanzadeh13 Feb 16, 2024
149f309
adds config for size of hero store for notification queue
yhassanzadeh13 Feb 16, 2024
e2e837a
Merge branch 'master' into yahya/simplify-rpc-inspection
yhassanzadeh13 Feb 18, 2024
a5a05e9
Merge branch 'master' into yahya/simplify-rpc-inspection
yhassanzadeh13 Feb 20, 2024
e1edb3d
Merge branch 'master' into yahya/simplify-rpc-inspection
yhassanzadeh13 Feb 21, 2024
c03eb77
Update config/default-config.yml
kc1116 Feb 21, 2024
cc41ebc
Update config/default-config.yml
kc1116 Feb 21, 2024
d1564ab
Update config/default-config.yml
kc1116 Feb 21, 2024
0ada021
Update config/default-config.yml
kc1116 Feb 21, 2024
21da688
Merge branch 'master' into yahya/simplify-rpc-inspection
yhassanzadeh13 Feb 21, 2024
a6cd7ba
add *ThresholdExceeded errors for invalid topic ID and duplicate topi…
kc1116 Feb 21, 2024
0bc3fff
Merge branch 'master' into khalil/6934-invalid-topicid-threshold
kc1116 Feb 21, 2024
fd268a3
update mocks
kc1116 Feb 21, 2024
bb9a107
Merge branch 'khalil/6934-invalid-topicid-threshold' of github.com:on…
kc1116 Feb 21, 2024
0e6358b
Merge branch 'master' into yahya/simplify-rpc-inspection
yhassanzadeh13 Feb 21, 2024
23beb88
Merge branch 'master' into fxamacker/extract-payloads-from-state-extr…
fxamacker Feb 21, 2024
3c2d313
Use latest NewCompactor API
fxamacker Feb 21, 2024
cb9a2f3
Merge pull request #5386 from onflow/fxamacker/extract-payloads-from-…
fxamacker Feb 22, 2024
30d0231
comments out flakey test
yhassanzadeh13 Feb 22, 2024
625fa72
Merge remote-tracking branch 'origin/master' into yahya/simplify-rpc-…
yhassanzadeh13 Feb 22, 2024
514461a
Merge pull request #5398 from onflow/yahya/simplify-rpc-inspection
yhassanzadeh13 Feb 22, 2024
4bc4eba
Merge branch 'master' into khalil/6934-invalid-topicid-threshold
kc1116 Feb 23, 2024
3e393bb
merge master
kc1116 Feb 23, 2024
8f4ecc4
Merge pull request #5391 from onflow/khalil/6934-invalid-topicid-thre…
kc1116 Feb 23, 2024
f4dd026
Fix return type
turbolent Feb 23, 2024
85cc479
Merge pull request #5450 from onflow/bastian/fix-load-types-evm-test
turbolent Feb 23, 2024
13deb4e
Merge branch 'master' into bastian/update-stable-cadence-12
turbolent Feb 23, 2024
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
176 changes: 153 additions & 23 deletions cmd/util/cmd/execution-state-extract/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@ package extract

import (
"encoding/hex"
"fmt"
"os"
"path"
"strings"

"github.com/rs/zerolog/log"
"github.com/spf13/cobra"

runtimeCommon "github.com/onflow/cadence/runtime/common"

"github.com/onflow/flow-go/cmd/util/cmd/common"
"github.com/onflow/flow-go/cmd/util/ledger/migrations"
"github.com/onflow/flow-go/model/bootstrap"
Expand All @@ -28,6 +33,9 @@ var (
flagValidateMigration bool
flagLogVerboseValidationError bool
flagStagedContractsFile string
flagInputPayloadFileName string
flagOutputPayloadFileName string
flagOutputPayloadByAddresses string
)

var Cmd = &cobra.Command{
Expand Down Expand Up @@ -73,6 +81,36 @@ func init() {

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
// multiple migrations because it helps avoid repeatedly reading from checkpoint file to rebuild trie.
// The input payload file must be created by state extraction running with either
// flagOutputPayloadFileName or flagOutputPayloadByAddresses.
Cmd.Flags().StringVar(
&flagInputPayloadFileName,
"input-payload-filename",
"",
"input payload file",
)

Cmd.Flags().StringVar(
&flagOutputPayloadFileName,
"output-payload-filename",
"",
"output payload file",
)

Cmd.Flags().StringVar(
// Extract payloads of specified addresses (comma separated list of hex-encoded addresses)
// to file specified by --output-payload-filename.
// If no address is specified (empty string) then this flag is ignored.
&flagOutputPayloadByAddresses,
"extract-payloads-by-address",
"",
"extract payloads of addresses (comma separated hex-encoded addresses) to file specified by output-payload-filename",
)
}

func run(*cobra.Command, []string) {
Expand All @@ -83,6 +121,19 @@ func run(*cobra.Command, []string) {
return
}

if len(flagBlockHash) == 0 && len(flagStateCommitment) == 0 && len(flagInputPayloadFileName) == 0 {
log.Fatal().Msg("--block-hash or --state-commitment or --input-payload-filename must be specified")
}

if len(flagInputPayloadFileName) > 0 && (len(flagBlockHash) > 0 || len(flagStateCommitment) > 0) {
log.Fatal().Msg("--input-payload-filename cannot be used with --block-hash or --state-commitment")
}

// When flagOutputPayloadByAddresses is specified, flagOutputPayloadFileName is required.
if len(flagOutputPayloadFileName) == 0 && len(flagOutputPayloadByAddresses) > 0 {
log.Fatal().Msg("--extract-payloads-by-address requires --output-payload-filename to be specified")
}

if len(flagBlockHash) > 0 {
blockID, err := flow.HexStringToIdentifier(flagBlockHash)
if err != nil {
Expand Down Expand Up @@ -117,20 +168,38 @@ func run(*cobra.Command, []string) {
log.Info().Msgf("extracting state by state commitment: %x", stateCommitment)
}

if len(flagBlockHash) == 0 && len(flagStateCommitment) == 0 {
log.Fatal().Msg("no --block-hash or --state-commitment was specified")
if len(flagInputPayloadFileName) > 0 {
if _, err := os.Stat(flagInputPayloadFileName); os.IsNotExist(err) {
log.Fatal().Msgf("payload input file %s doesn't exist", flagInputPayloadFileName)
}
}

log.Info().Msgf("Extracting state from %s, exporting root checkpoint to %s, version: %v",
flagExecutionStateDir,
path.Join(flagOutputDir, bootstrap.FilenameWALRootCheckpoint),
6,
)
if len(flagOutputPayloadFileName) > 0 {
if _, err := os.Stat(flagOutputPayloadFileName); os.IsExist(err) {
log.Fatal().Msgf("payload output file %s exists", flagOutputPayloadFileName)
}
}

var exportedAddresses []runtimeCommon.Address

log.Info().Msgf("Block state commitment: %s from %v, output dir: %s",
hex.EncodeToString(stateCommitment[:]),
flagExecutionStateDir,
flagOutputDir)
if len(flagOutputPayloadByAddresses) > 0 {

addresses := strings.Split(flagOutputPayloadByAddresses, ",")

for _, hexAddr := range addresses {
b, err := hex.DecodeString(strings.TrimSpace(hexAddr))
if err != nil {
log.Fatal().Err(err).Msgf("cannot hex decode address %s for payload export", strings.TrimSpace(hexAddr))
}

addr, err := runtimeCommon.BytesToAddress(b)
if err != nil {
log.Fatal().Err(err).Msgf("cannot decode address %x for payload export", b)
}

exportedAddresses = append(exportedAddresses, addr)
}
}

// err := ensureCheckpointFileExist(flagExecutionStateDir)
// if err != nil {
Expand All @@ -151,18 +220,79 @@ func run(*cobra.Command, []string) {
log.Warn().Msgf("atree migration has verbose validation error logging enabled which may increase size of log")
}

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
inputMsg = fmt.Sprintf("reading payloads from %s", flagInputPayloadFileName)
} else {
// Input is execution state
inputMsg = fmt.Sprintf("reading block state commitment %s from %s",
hex.EncodeToString(stateCommitment[:]),
flagExecutionStateDir,
)
}

var outputMsg string
if len(flagOutputPayloadFileName) > 0 {
// Output is payload file
if len(exportedAddresses) == 0 {
outputMsg = fmt.Sprintf("exporting all payloads to %s", flagOutputPayloadFileName)
} else {
outputMsg = fmt.Sprintf(
"exporting payloads by addresses %v to %s",
flagOutputPayloadByAddresses,
flagOutputPayloadFileName,
)
}
} else {
// Output is checkpoint files
outputMsg = fmt.Sprintf(
"exporting root checkpoint to %s, version: %d",
path.Join(flagOutputDir, bootstrap.FilenameWALRootCheckpoint),
6,
)
}

log.Info().Msgf("state extraction plan: %s, %s", inputMsg, outputMsg)

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,
flagExecutionStateDir,
flagOutputDir,
flagNWorker,
!flagNoMigration,
chainID,
evmContractChange,
stagedContracts,
flagInputPayloadFileName,
flagOutputPayloadFileName,
exportedAddresses,
)
} else {
err = extractExecutionState(
log.Logger,
flagExecutionStateDir,
stateCommitment,
flagOutputDir,
flagNWorker,
!flagNoMigration,
chainID,
evmContractChange,
stagedContracts,
flagOutputPayloadFileName,
exportedAddresses,
)
}

if err != nil {
log.Fatal().Err(err).Msgf("error extracting the execution state: %s", err.Error())
Expand Down
Loading
Loading