Skip to content

Commit 4ce667d

Browse files
authored
Merge pull request #6969 from onflow/janez/migration-mainnet-add-keys-to-core-contracts-master
Migration to add keys to service accounts for testing
2 parents 10f1894 + 65c285c commit 4ce667d

File tree

4 files changed

+465
-1
lines changed

4 files changed

+465
-1
lines changed

cmd/util/cmd/execution-state-extract/cmd.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ func run(*cobra.Command, []string) {
307307
}
308308

309309
// Validate chain ID
310-
_ = flow.ChainID(flagChain).Chain()
310+
chain := flow.ChainID(flagChain).Chain()
311311

312312
if flagNoReport {
313313
log.Warn().Msgf("--no-report flag is deprecated")
@@ -404,6 +404,8 @@ func run(*cobra.Command, []string) {
404404
var migs []migrations.NamedMigration
405405

406406
switch flagMigration {
407+
case "add-migrationmainnet-keys":
408+
migs = append(migs, addMigrationMainnetKeysMigration(log.Logger, flagOutputDir, flagNWorker, chain.ChainID())...)
407409
default:
408410
log.Fatal().Msgf("unknown migration: %s", flagMigration)
409411
}

cmd/util/cmd/execution-state-extract/execution_state_extract.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ import (
1010
"github.com/rs/zerolog/log"
1111
"golang.org/x/sync/errgroup"
1212

13+
"github.com/onflow/flow-go-sdk/crypto"
14+
1315
migrators "github.com/onflow/flow-go/cmd/util/ledger/migrations"
16+
"github.com/onflow/flow-go/cmd/util/ledger/reporters"
1417
"github.com/onflow/flow-go/cmd/util/ledger/util"
1518
"github.com/onflow/flow-go/ledger"
1619
"github.com/onflow/flow-go/ledger/common/hash"
@@ -356,3 +359,37 @@ func createTrieFromPayloads(logger zerolog.Logger, payloads []*ledger.Payload) (
356359

357360
return newTrie, nil
358361
}
362+
363+
func addMigrationMainnetKeysMigration(
364+
log zerolog.Logger,
365+
outputDir string,
366+
workerCount int,
367+
chainID flow.ChainID,
368+
) []migrators.NamedMigration {
369+
370+
log.Info().Msg("initializing add-migrationmainnet-keys migrations ...")
371+
372+
rwf := reporters.NewReportFileWriterFactory(outputDir, log)
373+
374+
key, err := crypto.DecodePublicKeyHex(crypto.ECDSA_P256, "711d4cd9930d695ef5c79b668d321f92ba00ed8280fded52c0fa2b15501411d026fe6fb4be3ec894facd3a00f04e32e2db5f5696d3b2b3419e4fba89fb95dca8")
375+
if err != nil {
376+
panic("failed to decode key")
377+
}
378+
379+
namedMigrations := []migrators.NamedMigration{
380+
{
381+
Name: "add-migrationmainnet-keys",
382+
Migrate: migrators.NewAccountBasedMigration(
383+
log,
384+
workerCount,
385+
[]migrators.AccountBasedMigration{
386+
migrators.NewAddKeyMigration(chainID, key, rwf),
387+
},
388+
),
389+
},
390+
}
391+
392+
log.Info().Msg("initialized migrations")
393+
394+
return namedMigrations
395+
}

0 commit comments

Comments
 (0)