forked from filecoin-project/go-state-types
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjob.go
47 lines (41 loc) · 1.2 KB
/
job.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package migration
import (
"context"
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/builtin"
cbor "github.com/ipfs/go-ipld-cbor"
"golang.org/x/xerrors"
)
type migrationJob struct {
address.Address
// This assumes ActorV5, which is relatively stable.
builtin.ActorV5
ActorMigration
cache MigrationCache
}
type migrationJobResult struct {
address.Address
builtin.ActorV5
}
func (job *migrationJob) run(ctx context.Context, store cbor.IpldStore) (*migrationJobResult, error) {
result, err := job.MigrateState(ctx, store, ActorMigrationInput{
Address: job.Address,
Head: job.ActorV5.Head,
Cache: job.cache,
})
if err != nil {
return nil, xerrors.Errorf("state migration failed for actor code %s, addr %s: %w",
job.ActorV5.Code, job.Address, err)
}
// Set up new actor record with the migrated state.
return &migrationJobResult{
job.Address, // Unchanged
builtin.ActorV5{
Code: result.NewCodeCID,
Head: result.NewHead,
CallSeqNum: job.ActorV5.CallSeqNum, // Unchanged
Balance: job.ActorV5.Balance, // Unchanged
DelegatedAddress: job.ActorV5.DelegatedAddress, // Unchanged
},
}, nil
}