2021-06-18 18:45:29 +00:00
|
|
|
package kit
|
2021-06-11 17:26:25 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/filecoin-project/go-state-types/abi"
|
2021-08-20 14:53:24 +00:00
|
|
|
|
2021-08-06 00:46:05 +00:00
|
|
|
"github.com/filecoin-project/lotus/build"
|
|
|
|
"github.com/filecoin-project/lotus/chain/stmgr"
|
2022-06-14 17:21:34 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/wallet/key"
|
2021-06-11 17:26:25 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type EnsembleOpt func(opts *ensembleOpts) error
|
|
|
|
|
2021-06-16 17:11:34 +00:00
|
|
|
type genesisAccount struct {
|
2022-06-14 17:21:34 +00:00
|
|
|
key *key.Key
|
2021-06-16 17:11:34 +00:00
|
|
|
initialBalance abi.TokenAmount
|
|
|
|
}
|
|
|
|
|
2021-06-11 17:26:25 +00:00
|
|
|
type ensembleOpts struct {
|
2021-06-16 17:11:34 +00:00
|
|
|
pastOffset time.Duration
|
|
|
|
verifiedRoot genesisAccount
|
|
|
|
accounts []genesisAccount
|
|
|
|
mockProofs bool
|
2021-08-06 00:46:05 +00:00
|
|
|
|
|
|
|
upgradeSchedule stmgr.UpgradeSchedule
|
2021-06-11 17:26:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var DefaultEnsembleOpts = ensembleOpts{
|
2021-06-21 12:24:25 +00:00
|
|
|
pastOffset: 10000000 * time.Second, // time sufficiently in the past to trigger catch-up mining.
|
2021-08-06 00:46:05 +00:00
|
|
|
upgradeSchedule: stmgr.UpgradeSchedule{{
|
|
|
|
Height: -1,
|
2022-09-21 15:55:59 +00:00
|
|
|
Network: build.TestNetworkVersion,
|
2021-08-06 00:46:05 +00:00
|
|
|
}},
|
2021-06-11 17:26:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// MockProofs activates mock proofs for the entire ensemble.
|
2024-03-12 16:05:04 +00:00
|
|
|
func MockProofs(e ...bool) EnsembleOpt {
|
|
|
|
if len(e) > 0 && !e[0] {
|
|
|
|
return func(opts *ensembleOpts) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-11 17:26:25 +00:00
|
|
|
return func(opts *ensembleOpts) error {
|
|
|
|
opts.mockProofs = true
|
2021-08-20 14:53:24 +00:00
|
|
|
// since we're using mock proofs, we don't need to download
|
|
|
|
// proof parameters
|
|
|
|
build.DisableBuiltinAssets = true
|
2021-06-11 17:26:25 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
2021-06-16 17:11:34 +00:00
|
|
|
|
2021-06-16 17:16:59 +00:00
|
|
|
// RootVerifier specifies the key to be enlisted as the verified registry root,
|
|
|
|
// as well as the initial balance to be attributed during genesis.
|
2022-06-14 17:21:34 +00:00
|
|
|
func RootVerifier(key *key.Key, balance abi.TokenAmount) EnsembleOpt {
|
2021-06-16 17:11:34 +00:00
|
|
|
return func(opts *ensembleOpts) error {
|
|
|
|
opts.verifiedRoot.key = key
|
|
|
|
opts.verifiedRoot.initialBalance = balance
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Account sets up an account at genesis with the specified key and balance.
|
2022-06-14 17:21:34 +00:00
|
|
|
func Account(key *key.Key, balance abi.TokenAmount) EnsembleOpt {
|
2021-06-16 17:11:34 +00:00
|
|
|
return func(opts *ensembleOpts) error {
|
|
|
|
opts.accounts = append(opts.accounts, genesisAccount{
|
|
|
|
key: key,
|
|
|
|
initialBalance: balance,
|
|
|
|
})
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|