github.com/koko1123/flow-go-1@v0.29.6/cmd/bootstrap/run/execution_state.go (about) 1 package run 2 3 import ( 4 "math" 5 6 "github.com/rs/zerolog" 7 "go.uber.org/atomic" 8 9 "github.com/onflow/flow-go/crypto" 10 "github.com/onflow/flow-go/crypto/hash" 11 "github.com/koko1123/flow-go-1/engine/execution/state/bootstrap" 12 "github.com/koko1123/flow-go-1/fvm" 13 "github.com/koko1123/flow-go-1/ledger/common/pathfinder" 14 "github.com/koko1123/flow-go-1/ledger/complete" 15 ledger "github.com/koko1123/flow-go-1/ledger/complete" 16 "github.com/koko1123/flow-go-1/ledger/complete/wal" 17 "github.com/koko1123/flow-go-1/model/flow" 18 "github.com/koko1123/flow-go-1/module/metrics" 19 ) 20 21 // NOTE: this is now unused and should become part of another tool. 22 func GenerateServiceAccountPrivateKey(seed []byte) (flow.AccountPrivateKey, error) { 23 priv, err := crypto.GeneratePrivateKey(crypto.ECDSASecp256k1, seed) 24 if err != nil { 25 return flow.AccountPrivateKey{}, err 26 } 27 28 return flow.AccountPrivateKey{ 29 PrivateKey: priv, 30 SignAlgo: crypto.ECDSASecp256k1, 31 HashAlgo: hash.SHA2_256, 32 }, nil 33 } 34 35 // NOTE: this is now unused and should become part of another tool. 36 func GenerateExecutionState( 37 dbDir string, 38 accountKey flow.AccountPublicKey, 39 chain flow.Chain, 40 bootstrapOptions ...fvm.BootstrapProcedureOption, 41 ) (flow.StateCommitment, error) { 42 const ( 43 capacity = 100 44 checkpointDistance = math.MaxInt // A large number to prevent checkpoint creation. 45 checkpointsToKeep = 1 46 ) 47 48 metricsCollector := &metrics.NoopCollector{} 49 50 diskWal, err := wal.NewDiskWAL(zerolog.Nop(), nil, metricsCollector, dbDir, capacity, pathfinder.PathByteSize, wal.SegmentSize) 51 if err != nil { 52 return flow.DummyStateCommitment, err 53 } 54 55 ledgerStorage, err := ledger.NewLedger(diskWal, capacity, metricsCollector, zerolog.Nop(), ledger.DefaultPathFinderVersion) 56 if err != nil { 57 return flow.DummyStateCommitment, err 58 } 59 60 compactor, err := complete.NewCompactor(ledgerStorage, diskWal, zerolog.Nop(), capacity, checkpointDistance, checkpointsToKeep, atomic.NewBool(false)) 61 if err != nil { 62 return flow.DummyStateCommitment, err 63 } 64 <-compactor.Ready() 65 66 defer func() { 67 <-ledgerStorage.Done() 68 <-compactor.Done() 69 }() 70 71 return bootstrap.NewBootstrapper( 72 zerolog.Nop()).BootstrapLedger( 73 ledgerStorage, 74 accountKey, 75 chain, 76 bootstrapOptions..., 77 ) 78 }