2020-02-11 20:48:03 +00:00
|
|
|
package genesis
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2020-09-16 05:00:00 +00:00
|
|
|
|
2020-02-11 20:48:03 +00:00
|
|
|
"github.com/filecoin-project/go-address"
|
2020-09-07 03:49:10 +00:00
|
|
|
"github.com/filecoin-project/go-state-types/abi"
|
2022-04-08 09:45:17 +00:00
|
|
|
"github.com/filecoin-project/go-state-types/network"
|
2020-02-11 20:48:03 +00:00
|
|
|
cbg "github.com/whyrusleeping/cbor-gen"
|
|
|
|
"golang.org/x/xerrors"
|
|
|
|
|
|
|
|
"github.com/filecoin-project/lotus/chain/actors"
|
2022-04-08 09:45:17 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/actors/builtin"
|
|
|
|
"github.com/filecoin-project/lotus/chain/state"
|
2020-02-11 20:48:03 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/types"
|
|
|
|
"github.com/filecoin-project/lotus/chain/vm"
|
|
|
|
)
|
|
|
|
|
|
|
|
func mustEnc(i cbg.CBORMarshaler) []byte {
|
|
|
|
enc, err := actors.SerializeParams(i)
|
|
|
|
if err != nil {
|
|
|
|
panic(err) // ok
|
|
|
|
}
|
|
|
|
return enc
|
|
|
|
}
|
|
|
|
|
2022-03-15 23:40:17 +00:00
|
|
|
func doExecValue(ctx context.Context, vm *vm.LegacyVM, to, from address.Address, value types.BigInt, method abi.MethodNum, params []byte) ([]byte, error) {
|
2020-02-11 20:48:03 +00:00
|
|
|
act, err := vm.StateTree().GetActor(from)
|
|
|
|
if err != nil {
|
2020-08-19 19:54:33 +00:00
|
|
|
return nil, xerrors.Errorf("doExec failed to get from actor (%s): %w", from, err)
|
2020-02-11 20:48:03 +00:00
|
|
|
}
|
|
|
|
|
2020-03-25 08:46:42 +00:00
|
|
|
ret, err := vm.ApplyImplicitMessage(ctx, &types.Message{
|
2020-02-11 20:48:03 +00:00
|
|
|
To: to,
|
|
|
|
From: from,
|
|
|
|
Method: method,
|
|
|
|
Params: params,
|
2020-04-15 20:09:33 +00:00
|
|
|
GasLimit: 1_000_000_000_000_000,
|
2020-02-11 20:48:03 +00:00
|
|
|
Value: value,
|
|
|
|
Nonce: act.Nonce,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return nil, xerrors.Errorf("doExec apply message failed: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if ret.ExitCode != 0 {
|
2020-02-17 07:59:53 +00:00
|
|
|
return nil, xerrors.Errorf("failed to call method: %w", ret.ActorErr)
|
2020-02-11 20:48:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret.Return, nil
|
|
|
|
}
|
2022-04-08 09:45:17 +00:00
|
|
|
|
|
|
|
func patchStateTree(st *state.StateTree, nv network.Version) error {
|
|
|
|
av, err := actors.VersionForNetwork(nv)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
var acts []address.Address
|
|
|
|
err = st.ForEach(func(a address.Address, _ *types.Actor) error {
|
|
|
|
acts = append(acts, a)
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return xerrors.Errorf("error collecting actors: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, a := range acts {
|
|
|
|
err = st.MutateActor(a, func(act *types.Actor) error {
|
|
|
|
name := actors.CanonicalName(builtin.ActorNameByCode(act.Code))
|
|
|
|
code, ok := actors.GetActorCodeID(av, name)
|
|
|
|
if ok {
|
|
|
|
act.Code = code
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return xerrors.Errorf("error mutating actor %s: %w", a, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|