lotus/chain/gen/genesis/util.go

78 lines
2.0 KiB
Go
Raw Normal View History

2020-02-11 20:48:03 +00:00
package genesis
import (
"context"
2020-09-14 12:17:45 +00:00
"github.com/filecoin-project/go-state-types/network"
2020-09-14 13:17:00 +00:00
"github.com/filecoin-project/lotus/build"
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"
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"
"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
}
func doExecValue(ctx context.Context, vm *vm.VM, to, from address.Address, value types.BigInt, method abi.MethodNum, params []byte) ([]byte, error) {
act, err := vm.StateTree().GetActor(from)
if err != nil {
return nil, xerrors.Errorf("doExec failed to get from actor (%s): %w", from, err)
2020-02-11 20:48:03 +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,
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
}
2020-09-14 12:17:45 +00:00
// TODO: Get from build
// TODO: make a list/schedule of these.
var GenesisNetworkVersion = func() network.Version {
// returns the version _before_ the first upgrade.
if build.UpgradeBreezeHeight >= 0 {
return network.Version0
}
if build.UpgradeSmokeHeight >= 0 {
return network.Version1
}
if build.UpgradeIgnitionHeight >= 0 {
return network.Version2
}
if build.UpgradeActorsV2Height >= 0 {
return network.Version3
}
if build.UpgradeLiftoffHeight >= 0 {
return network.Version3
}
return build.ActorUpgradeNetworkVersion - 1 // genesis requires actors v0.
}()
2020-09-15 13:29:39 +00:00
func genesisNetworkVersion(context.Context, abi.ChainEpoch) network.Version { // TODO: Get from build/
2020-09-14 12:17:45 +00:00
return GenesisNetworkVersion // TODO: Get from build/
2020-09-15 13:29:39 +00:00
} // TODO: Get from build/