Skip to content

Commit

Permalink
Fix bootstrapping order
Browse files Browse the repository at this point in the history
  • Loading branch information
janezpodhostnik committed Mar 1, 2024
1 parent a09cf00 commit 3bbd0cc
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 10 deletions.
3 changes: 2 additions & 1 deletion cmd/bootstrap/utils/key_generation.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"crypto/rand"
"crypto/sha256"
"fmt"
"github.com/onflow/flow-go/fvm/systemcontracts"

Check failure on line 7 in cmd/bootstrap/utils/key_generation.go

View workflow job for this annotation

GitHub Actions / Lint (./)

File is not `goimports`-ed with -local github.com/onflow/flow-go (goimports)
gohash "hash"
"io"

Expand Down Expand Up @@ -173,7 +174,7 @@ func WriteMachineAccountFiles(chainID flow.ChainID, nodeInfos []bootstrap.NodeIn
//
// for the machine account key, we keep track of the address index to map
// the Flow address of the machine account to the key.
addressIndex := uint64(4)
addressIndex := uint64(systemcontracts.LastSystemAccountIndex)
for _, nodeInfo := range nodeInfos {

// retrieve private representation of the node
Expand Down
3 changes: 2 additions & 1 deletion cmd/bootstrap/utils/key_generation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package utils

import (
"fmt"
"github.com/onflow/flow-go/fvm/systemcontracts"

Check failure on line 5 in cmd/bootstrap/utils/key_generation_test.go

View workflow job for this annotation

GitHub Actions / Lint (./)

File is not `goimports`-ed with -local github.com/onflow/flow-go (goimports)
"testing"

"github.com/onflow/crypto"
Expand Down Expand Up @@ -62,7 +63,7 @@ func TestWriteMachineAccountFiles(t *testing.T) {
expected := make(map[string]bootstrap.NodeMachineAccountInfo)
for i, node := range nodes {
// See comments in WriteMachineAccountFiles for why addresses take this form
addr, err := chain.AddressAtIndex(uint64(6 + i*2))
addr, err := chain.AddressAtIndex(uint64(systemcontracts.LastSystemAccountIndex + (i+1)*2))
require.NoError(t, err)
private, err := node.Private()
require.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion engine/execution/state/bootstrap/bootstrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func TestBootstrapLedger(t *testing.T) {
}

func TestBootstrapLedger_ZeroTokenSupply(t *testing.T) {
expectedStateCommitmentBytes, _ := hex.DecodeString("8f73796f4a6107fcddcfb6e780198e219dc0133a8fd724e6b016c2a55092d8fc")
expectedStateCommitmentBytes, _ := hex.DecodeString("a76ef8608e869025232141334d4559900709b9ef59bfaee3393cc33b69f5483e")
expectedStateCommitment, err := flow.ToStateCommitment(expectedStateCommitmentBytes)
require.NoError(t, err)

Expand Down
55 changes: 51 additions & 4 deletions fvm/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package fvm

import (
"fmt"
"github.com/onflow/flow-go/fvm/systemcontracts"

Check failure on line 5 in fvm/bootstrap.go

View workflow job for this annotation

GitHub Actions / Lint (./)

File is not `goimports`-ed with -local github.com/onflow/flow-go (goimports)
"math"

"github.com/onflow/cadence"
Expand Down Expand Up @@ -341,24 +342,58 @@ func (b *bootstrapExecutor) Execute() error {
b.ctx.Chain,
environment.NewAccounts(b.txnState))

expectAccounts := func(n uint64) error {
ag := environment.NewAddressGenerator(b.txnState, b.ctx.Chain)
currentAddresses := ag.AddressCount()
if currentAddresses != n {
return fmt.Errorf("expected %d accounts, got %d", n, currentAddresses)
}
return nil
}

service := b.createServiceAccount()

err := expectAccounts(1)
if err != nil {
return err
}

env := templates.Environment{
ServiceAccountAddress: service.String(),
}

b.deployViewResolver(service, &env)
b.deployBurner(service, &env)

err = expectAccounts(1)
if err != nil {
return err
}

fungibleToken := b.deployFungibleToken(&env)

err = expectAccounts(systemcontracts.FungibleTokenAccountIndex)
if err != nil {
return err
}

nonFungibleToken := b.deployNonFungibleToken(service, &env)

b.deployMetadataViews(fungibleToken, nonFungibleToken, &env)
b.deployFungibleTokenSwitchboard(fungibleToken, &env)

flowToken := b.deployFlowToken(service, &env)
err = expectAccounts(systemcontracts.FlowTokenAccountIndex)
if err != nil {
return err
}

b.deployStorageFees(service, &env)
feeContract := b.deployFlowFees(service, &env)
err = expectAccounts(systemcontracts.FlowFeesAccountIndex)
if err != nil {
return err
}

if b.initialTokenSupply > 0 {
b.mintInitialTokens(service, fungibleToken, flowToken, b.initialTokenSupply)
Expand Down Expand Up @@ -411,13 +446,23 @@ func (b *bootstrapExecutor) Execute() error {
// deploy staking collection contract to the service account
b.deployStakingCollection(service, &env)

// sets up the EVM environment
b.setupEVM(service, fungibleToken, flowToken)

err = expectAccounts(systemcontracts.EVMStorageAccountIndex)
if err != nil {
return err
}

b.registerNodes(service, fungibleToken, flowToken)

// set the list of nodes which are allowed to stake in this network
b.setStakingAllowlist(service, b.identities.NodeIDs())

// sets up the EVM environment
b.setupEVM(service, fungibleToken, flowToken)
err = expectAccounts(uint64(systemcontracts.LastSystemAccountIndex + len(b.identities)))
if err != nil {
return err
}

return nil
}
Expand Down Expand Up @@ -912,7 +957,8 @@ func (b *bootstrapExecutor) registerNodes(service, fungibleToken, flowToken flow
// fund the staking account
txError, err = b.invokeMetaTransaction(
b.ctx,
Transaction(blueprints.FundAccountTransaction(service,
Transaction(blueprints.FundAccountTransaction(
service,
fungibleToken,
flowToken,
nodeAddress),
Expand All @@ -925,7 +971,8 @@ func (b *bootstrapExecutor) registerNodes(service, fungibleToken, flowToken flow
// and set it up with the QC/DKG participant resource
txError, err = b.invokeMetaTransaction(
b.ctx,
Transaction(blueprints.RegisterNodeTransaction(service,
Transaction(blueprints.RegisterNodeTransaction(
service,
flowToken,
fungibleToken,
nodeAddress,
Expand Down
6 changes: 3 additions & 3 deletions utils/unittest/execution_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const ServiceAccountPrivateKeySignAlgo = crypto.ECDSAP256
const ServiceAccountPrivateKeyHashAlgo = hash.SHA2_256

// Pre-calculated state commitment with root account with the above private key
const GenesisStateCommitmentHex = "9f7ab548cdbf23cf4080b95f6bd1c2ff1fa68cb1cd6c0364d98d7510da2fb947"
const GenesisStateCommitmentHex = "950eead8a731067405a0b56858e70af4b318d8154a2923e0001b4e239fbd0e56"

var GenesisStateCommitment flow.StateCommitment

Expand Down Expand Up @@ -87,10 +87,10 @@ func genesisCommitHexByChainID(chainID flow.ChainID) string {
return GenesisStateCommitmentHex
}
if chainID == flow.Testnet {
return "a6225d58e21db8a769b64120f8273b02b707fe51ddf36b0df316cfb102a26889"
return "74c54a0d99a9cbdbb835778be1d1aff419664639cf4b3667c7584840a2ea351b"
}
if chainID == flow.Sandboxnet {
return "e1c08b17f9e5896f03fe28dd37ca396c19b26628161506924fbf785834646ea1"
}
return "283d0f20e0ad2ae03dc1bdc1112e05fd05e77d61d8b34c64a8af60efd2dae678"
return "abd550ebb99650c66d7a27c0a7ca08ab49fbdd5c618666f2bc026223030a12af"
}

0 comments on commit 3bbd0cc

Please sign in to comment.