diff --git a/chain/actors/forks.go b/chain/actors/forks.go index 9580fb498..609b2557e 100644 --- a/chain/actors/forks.go +++ b/chain/actors/forks.go @@ -9,7 +9,7 @@ import ( ) type update struct { - start uint64 + start uint64 method interface{} } @@ -31,7 +31,7 @@ func withUpdates(updates ...update) interface{} { } } - return reflect.ValueOf(notFound(vmctx)).Call([]reflect.Value{}) + return reflect.ValueOf(notFound(vmctx)).Call([]reflect.Value{args[1]}) }) return out.Interface() @@ -43,4 +43,4 @@ func notFound(vmctx types.VMContext) func() ([]byte, ActorError) { return func() ([]byte, ActorError) { return nil, aerrors.Fatal("no code for method %d at height %d", vmctx.Message().Method, vmctx.BlockHeight()) } -} \ No newline at end of file +} diff --git a/chain/stmgr/forks.go b/chain/stmgr/forks.go index 90fcf974b..844687b8c 100644 --- a/chain/stmgr/forks.go +++ b/chain/stmgr/forks.go @@ -3,15 +3,21 @@ package stmgr import ( "context" "github.com/ipfs/go-cid" + "golang.org/x/xerrors" "github.com/filecoin-project/lotus/build" ) -func (sm *StateManager) handleStateForks(ctx context.Context, pstate cid.Cid, height uint64) (cid.Cid, error) { - switch height { - case build.ForkNoPowerEPSUpdates: // TODO: +1? - return sm.forkNoPowerEPS(ctx, pstate) - default: - return pstate, nil +func (sm *StateManager) handleStateForks(ctx context.Context, pstate cid.Cid, height, parentH uint64) (_ cid.Cid, err error) { + for i := parentH; i < height; i++ { + switch i { + case build.ForkNoPowerEPSUpdates: + pstate, err = sm.forkNoPowerEPS(ctx, pstate) + if err != nil { + return cid.Undef, xerrors.Errorf("executing state fork in epoch %d: %w", i, err) + } + } } + + return pstate, nil } diff --git a/chain/stmgr/stmgr.go b/chain/stmgr/stmgr.go index 782e7decf..6f8e7ece9 100644 --- a/chain/stmgr/stmgr.go +++ b/chain/stmgr/stmgr.go @@ -119,9 +119,17 @@ func (sm *StateManager) computeTipSetState(ctx context.Context, blks []*types.Bl } } - pstate, err := sm.handleStateForks(ctx, blks[0].ParentStateRoot, blks[0].Height) - if err != nil { - return cid.Undef, cid.Undef, xerrors.Errorf("error handling state forks: %w", err) + pstate := blks[0].ParentStateRoot + if len(blks[0].Parents) > 0 { // don't support forks on genesis + parent, err := sm.cs.GetBlock(blks[0].Parents[0]) + if err != nil { + return cid.Undef, cid.Undef, xerrors.Errorf("getting parent block: %w", err) + } + + pstate, err = sm.handleStateForks(ctx, blks[0].ParentStateRoot, blks[0].Height, parent.Height) + if err != nil { + return cid.Undef, cid.Undef, xerrors.Errorf("error handling state forks: %w", err) + } } cids := make([]cid.Cid, len(blks))