improve upgrade schedule configurable
Unfortunately, it looks like functional ops cannot be passed in via lotus's di system.
This commit is contained in:
parent
1cc0f74744
commit
e865ba0c64
@ -115,8 +115,9 @@ func TestForkHeightTriggers(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
sm := NewStateManager(cg.ChainStore(),
|
sm := NewStateManagerWithUpgradeSchedule(
|
||||||
WithUpgradeSchedule(UpgradeSchedule{
|
cg.ChainStore(),
|
||||||
|
UpgradeSchedule{
|
||||||
1: {Height: testForkHeight, Migration: func(ctx context.Context, sm *StateManager, cb ExecCallback,
|
1: {Height: testForkHeight, Migration: func(ctx context.Context, sm *StateManager, cb ExecCallback,
|
||||||
root cid.Cid, ts *types.TipSet) (cid.Cid, error) {
|
root cid.Cid, ts *types.TipSet) (cid.Cid, error) {
|
||||||
cst := ipldcbor.NewCborStore(sm.ChainStore().Blockstore())
|
cst := ipldcbor.NewCborStore(sm.ChainStore().Blockstore())
|
||||||
@ -151,8 +152,7 @@ func TestForkHeightTriggers(t *testing.T) {
|
|||||||
|
|
||||||
return st.Flush(ctx)
|
return st.Flush(ctx)
|
||||||
}},
|
}},
|
||||||
}),
|
})
|
||||||
)
|
|
||||||
|
|
||||||
inv := vm.NewActorRegistry()
|
inv := vm.NewActorRegistry()
|
||||||
inv.Register(nil, testActor{})
|
inv.Register(nil, testActor{})
|
||||||
|
@ -1,23 +0,0 @@
|
|||||||
package stmgr
|
|
||||||
|
|
||||||
type Option func(*config)
|
|
||||||
|
|
||||||
type config struct {
|
|
||||||
upgradeSchedule UpgradeSchedule
|
|
||||||
}
|
|
||||||
|
|
||||||
func parseOptions(opts ...Option) *config {
|
|
||||||
cfg := &config{
|
|
||||||
upgradeSchedule: DefaultUpgradeSchedule,
|
|
||||||
}
|
|
||||||
for _, opt := range opts {
|
|
||||||
opt(cfg)
|
|
||||||
}
|
|
||||||
return cfg
|
|
||||||
}
|
|
||||||
|
|
||||||
func WithUpgradeSchedule(schedule UpgradeSchedule) Option {
|
|
||||||
return func(cfg *config) {
|
|
||||||
cfg.upgradeSchedule = schedule
|
|
||||||
}
|
|
||||||
}
|
|
@ -57,15 +57,18 @@ type StateManager struct {
|
|||||||
postIgnitionGenInfos *genesisInfo
|
postIgnitionGenInfos *genesisInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewStateManager(cs *store.ChainStore, options ...Option) *StateManager {
|
func NewStateManager(cs *store.ChainStore) *StateManager {
|
||||||
cfg := parseOptions(options...)
|
return NewStateManagerWithUpgradeSchedule(cs, DefaultUpgradeSchedule)
|
||||||
stateMigrations := make(map[abi.ChainEpoch]UpgradeFunc, len(cfg.upgradeSchedule))
|
}
|
||||||
|
|
||||||
|
func NewStateManagerWithUpgradeSchedule(cs *store.ChainStore, us UpgradeSchedule) *StateManager {
|
||||||
|
stateMigrations := make(map[abi.ChainEpoch]UpgradeFunc, len(us))
|
||||||
networkVersions := make([]abi.ChainEpoch, 0, len(stateMigrations))
|
networkVersions := make([]abi.ChainEpoch, 0, len(stateMigrations))
|
||||||
|
|
||||||
// Iterate version by version, to make sure we handle skipped version numbers.
|
// Iterate version by version, to make sure we handle skipped version numbers.
|
||||||
// Always skip version 0.
|
// Always skip version 0.
|
||||||
for i, version := 0, network.Version(1); i < len(cfg.upgradeSchedule); version++ {
|
for i, version := 0, network.Version(1); i < len(us); version++ {
|
||||||
upgrade, ok := cfg.upgradeSchedule[version]
|
upgrade, ok := us[version]
|
||||||
if ok {
|
if ok {
|
||||||
// We've processed an upgrade.
|
// We've processed an upgrade.
|
||||||
i++
|
i++
|
||||||
|
@ -259,7 +259,8 @@ func Online() Option {
|
|||||||
Override(new(ffiwrapper.Verifier), ffiwrapper.ProofVerifier),
|
Override(new(ffiwrapper.Verifier), ffiwrapper.ProofVerifier),
|
||||||
Override(new(vm.SyscallBuilder), vm.Syscalls),
|
Override(new(vm.SyscallBuilder), vm.Syscalls),
|
||||||
Override(new(*store.ChainStore), modules.ChainStore),
|
Override(new(*store.ChainStore), modules.ChainStore),
|
||||||
Override(new(*stmgr.StateManager), stmgr.NewStateManager),
|
Override(new(stmgr.UpgradeSchedule), stmgr.DefaultUpgradeSchedule),
|
||||||
|
Override(new(*stmgr.StateManager), stmgr.NewStateManagerWithUpgradeSchedule),
|
||||||
Override(new(*wallet.Wallet), wallet.NewWallet),
|
Override(new(*wallet.Wallet), wallet.NewWallet),
|
||||||
Override(new(*messagesigner.MessageSigner), messagesigner.NewMessageSigner),
|
Override(new(*messagesigner.MessageSigner), messagesigner.NewMessageSigner),
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user