Skip to content

Commit

Permalink
genesis: instantiate EAM at id 10.
Browse files Browse the repository at this point in the history
  • Loading branch information
raulk committed Oct 20, 2022
1 parent 866e1a2 commit aaaa2ba
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 21 deletions.
4 changes: 4 additions & 0 deletions chain/actors/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ const (
SystemKey = "system"
VerifregKey = "verifiedregistry"
EvmKey = "evm"
EamKey = "eam"
EmbrioKey = "embryo"
)

func GetBuiltinActorsKeys() []string {
Expand All @@ -47,6 +49,8 @@ func GetBuiltinActorsKeys() []string {
SystemKey,
VerifregKey,
EvmKey,
EamKey,
EmbrioKey,
}
}

Expand Down
1 change: 0 additions & 1 deletion chain/actors/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ const (

// Converts a network version into an actors adt version.
func VersionForNetwork(version network.Version) (Version, error) {
fmt.Println(version)
switch version {
case network.Version0, network.Version1, network.Version2, network.Version3:
return Version0, nil
Expand Down
29 changes: 21 additions & 8 deletions chain/gen/genesis/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"encoding/json"
"fmt"

builtintypes "github.com/filecoin-project/go-state-types/builtin"
"github.com/ipfs/go-cid"
"github.com/ipfs/go-datastore"
cbor "github.com/ipfs/go-ipld-cbor"
Expand Down Expand Up @@ -512,8 +513,6 @@ func VerifyPreSealedData(ctx context.Context, cs *store.ChainStore, sys vm.Sysca
return cid.Undef, err
}

fmt.Println("****aaaa")

// Note: This is brittle, if the methodNum / param changes, it could break things
_, err = doExecValue(ctx, vm, verifreg.Address, verifregRoot, types.NewInt(0), builtin0.MethodsVerifiedRegistry.AddVerifier, mustEnc(&verifreg0.AddVerifierParams{

Expand All @@ -536,8 +535,6 @@ func VerifyPreSealedData(ctx context.Context, cs *store.ChainStore, sys vm.Sysca
}
}

fmt.Println("****bbb")

st, err := vm.Flush(ctx)
if err != nil {
return cid.Cid{}, xerrors.Errorf("vm flush: %w", err)
Expand All @@ -555,6 +552,11 @@ func MakeGenesisBlock(ctx context.Context, j journal.Journal, bs bstore.Blocksto
return nil, xerrors.Errorf("make initial state tree failed: %w", err)
}

// Set up the Ethereum Address Manager.
if err = SetupEAM(ctx, st); err != nil {
return nil, xerrors.Errorf("failed to setup EAM: %w", err)
}

stateroot, err := st.Flush(ctx)
if err != nil {
return nil, xerrors.Errorf("flush state tree failed: %w", err)
Expand All @@ -569,8 +571,6 @@ func MakeGenesisBlock(ctx context.Context, j journal.Journal, bs bstore.Blocksto
return nil, xerrors.Errorf("failed to verify presealed data: %w", err)
}

fmt.Println("****1")

stateroot, err = SetupStorageMiners(ctx, cs, sys, stateroot, template.Miners, template.NetworkVersion)
if err != nil {
return nil, xerrors.Errorf("setup miners failed: %w", err)
Expand Down Expand Up @@ -611,8 +611,6 @@ func MakeGenesisBlock(ctx context.Context, j journal.Journal, bs bstore.Blocksto
return nil, xerrors.Errorf("expectedCid != filecoinGenesisCid")
}

fmt.Println("****2")

gblk, err := getGenesisBlock()
if err != nil {
return nil, xerrors.Errorf("failed to construct filecoin genesis block: %w", err)
Expand Down Expand Up @@ -661,3 +659,18 @@ func MakeGenesisBlock(ctx context.Context, j journal.Journal, bs bstore.Blocksto
Genesis: b,
}, nil
}

func SetupEAM(_ context.Context, nst *state.StateTree) error {
// TODO Version10
codecid, ok := actors.GetActorCodeID(actors.Version8, actors.EamKey)
if !ok {
return fmt.Errorf("failed to get CodeCID for EAM during genesis")
}

header := &types.Actor{
Code: codecid,
Head: vm.EmptyObjectCid,
Balance: big.Zero(),
}
return nst.SetActor(builtintypes.EthereumAddressManagerActorAddr, header)
}
12 changes: 0 additions & 12 deletions chain/gen/genesis/miners.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,6 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sys vm.Syscal
return vm.NewVM(ctx, vmopt)
}

fmt.Println("*******nnnn")

genesisVm, err := newVM(sroot)
if err != nil {
return cid.Undef, fmt.Errorf("creating vm: %w", err)
Expand Down Expand Up @@ -146,7 +144,6 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sys vm.Syscal
}

params := mustEnc(constructorParams)
fmt.Println("*******p")
rval, err := doExecValue(ctx, genesisVm, power.Address, m.Owner, m.PowerBalance, power.Methods.CreateMiner, params)
if err != nil {
return cid.Undef, xerrors.Errorf("failed to create genesis miner: %w", err)
Expand Down Expand Up @@ -207,8 +204,6 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sys vm.Syscal
publish := func(params *markettypes.PublishStorageDealsParams) error {
fmt.Printf("publishing %d storage deals on miner %s with worker %s\n", len(params.Deals), params.Deals[0].Proposal.Provider, m.Worker)

fmt.Println("*******ooooo")

ret, err := doExecValue(ctx, genesisVm, market.Address, m.Worker, big.Zero(), builtin0.MethodsMarket.PublishStorageDeals, mustEnc(params))
if err != nil {
return xerrors.Errorf("failed to create genesis miner (publish deals): %w", err)
Expand Down Expand Up @@ -384,8 +379,6 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sys vm.Syscal

// we've added fake power for this sector above, remove it now

fmt.Println("*******dddddd")

nh, err := genesisVm.Flush(ctx)
if err != nil {
return cid.Undef, xerrors.Errorf("flushing vm: %w", err)
Expand Down Expand Up @@ -465,7 +458,6 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sys vm.Syscal

fmt.Println(types.FIL(pledge))

fmt.Println("*******__________")
_, err = doExecValue(ctx, genesisVm, minerInfos[i].maddr, m.Worker, pledge, builtintypes.MethodsMiner.PreCommitSector, mustEnc(params))
if err != nil {
return cid.Undef, xerrors.Errorf("failed to confirm presealed sectors: %w", err)
Expand All @@ -488,8 +480,6 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sys vm.Syscal

paramBytes = mustEnc(confirmParams)
}

fmt.Println("*******/////")
_, err = doExecValue(ctx, genesisVm, minerInfos[i].maddr, power.Address, big.Zero(), builtintypes.MethodsMiner.ConfirmSectorProofsValid, paramBytes)
if err != nil {
return cid.Undef, xerrors.Errorf("failed to confirm presealed sectors: %w", err)
Expand All @@ -501,8 +491,6 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sys vm.Syscal
RawByteDelta: types.NewInt(uint64(m.SectorSize)),
QualityAdjustedDelta: sectorWeight,
}

fmt.Println("*******yyyyy")
_, err = doExecValue(ctx, genesisVm, power.Address, minerInfos[i].maddr, big.Zero(), power.Methods.UpdateClaimedPower, mustEnc(claimParams))
if err != nil {
return cid.Undef, xerrors.Errorf("failed to confirm presealed sectors: %w", err)
Expand Down

0 comments on commit aaaa2ba

Please sign in to comment.