Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Work in Progress] Decouple extract and transform #1103

Draft
wants to merge 48 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
43c66d8
refactor: add InfoCid to miner interface
frrist Dec 6, 2022
1dca7c7
chore: fix code comment
frrist Dec 6, 2022
877e3cd
feat: add deferred miner precommit & sector diff
frrist Dec 6, 2022
6894636
fixup! refactor: add InfoCid to miner interface
frrist Dec 6, 2022
df8b54e
MVP: complete miner extraction MVP
frrist Dec 7, 2022
a5464c4
feat: persist miner state as IPLD
frrist Dec 7, 2022
49241a6
generic actor map and array diffing :)
frrist Dec 8, 2022
75fe340
verifireg extraction
frrist Dec 9, 2022
a1d5510
things work
frrist Dec 14, 2022
13d76f3
write that fancy state decode method you always wanted
frrist Dec 14, 2022
5250617
can convert car file of cbor into timescale models
frrist Dec 15, 2022
45ee51f
add ipld index command
frrist Dec 15, 2022
eee4ae8
add command to index car file into timescale
frrist Dec 15, 2022
6480285
fix miner infor handler
frrist Dec 15, 2022
b523d7e
large refactor, can still produce car files and persist them to database
frrist Dec 16, 2022
39e755a
add init extract
frrist Jan 10, 2023
11bc7c5
add power diff
frrist Jan 11, 2023
bd16e3f
add market diff
frrist Jan 11, 2023
cfa9ae5
WIP
frrist Jan 12, 2023
1575b14
can still produce car files
frrist Jan 12, 2023
8da1603
working
frrist Jan 13, 2023
fd5ae8e
fix cbor gen for ipld container and actor statee to json
frrist Jan 13, 2023
9f95002
checking
frrist Jan 14, 2023
bd75f43
add message extraction to car file
frrist Jan 14, 2023
6745112
checking
frrist Jan 18, 2023
0bd8b34
need to fix cborgen
frrist Jan 18, 2023
f5952f6
compiles, need to cborgen
frrist Jan 19, 2023
443cfd2
can encode and decode car file, produces miner models
frrist Jan 19, 2023
b57eb41
works
frrist Jan 20, 2023
b2f33ef
wire up allocation for verifreg
frrist Jan 23, 2023
588752b
remove unused actor seralize handlers
frrist Jan 23, 2023
af68777
wip
frrist Jan 24, 2023
ad9ac03
checkpoint, all works
frrist Jan 25, 2023
0e7235e
clean up actor extraction
frrist Jan 25, 2023
b10d395
checkin
frrist Jan 26, 2023
5c7ca7b
refactor timescale transformer
frrist Jan 26, 2023
8205fe3
tmp: add database tracking of seralized state
frrist Jan 26, 2023
34739c0
version extractors and add a simple binary to show example of extract
frrist Jan 26, 2023
0cddcde
extractio logic clean up
frrist Jan 27, 2023
6d13e5b
start new schema add lambda example for parsed messages
frrist Jan 27, 2023
0655c3e
simplify actor state diffing into single method
frrist Feb 8, 2023
b97fcd5
paralle message extraction
frrist Feb 9, 2023
a986e96
can at least exit when there is an error
frrist Feb 9, 2023
827b2aa
worker pool works
frrist Feb 9, 2023
4814a89
okay worker pool works for reals this time
frrist Feb 10, 2023
15b9107
polish actor workers
frrist Feb 10, 2023
70815f8
fix race in worker pool
frrist Feb 10, 2023
e952206
testing: wire up walker
frrist Feb 11, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions chain/actors/adt/diff/generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type ArrayDiffer interface {
// - All values that exist in curArr nnd not in prevArr are passed to ArrayDiffer.Add()
// - All values that exist in preArr and in curArr are passed to ArrayDiffer.Modify()
// - It is the responsibility of ArrayDiffer.Modify() to determine if the values it was passed have been modified.
//
// If `preArr` and `curArr` are both backed by /v3/AMTs with the same bitwidth use the more efficient Amt method.
func CompareArray(preArr, curArr adt.Array, out ArrayDiffer) error {
notNew := make(map[int64]struct{}, curArr.Length())
Expand Down Expand Up @@ -84,6 +85,7 @@ type MapDiffer interface {
// - All values that exist in curMap nnd not in prevArr are passed to MapDiffer.Add()
// - All values that exist in preMap and in curMap are passed to MapDiffer.Modify()
// - It is the responsibility of ArrayDiffer.Modify() to determine if the values it was passed have been modified.
//
// If `preMap` and `curMap` are both backed by /v3/HAMTs with the same bitwidth and hash function use the more efficient Hamt method.
func CompareMap(preMap, curMap adt.Map, out MapDiffer) error {
notNew := make(map[string]struct{})
Expand Down
5 changes: 5 additions & 0 deletions chain/actors/builtin/datacap/actor.go.template
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ type State interface {
VerifiedClients() (adt.Map, error)
VerifiedClientsMapBitWidth() int
VerifiedClientsMapHashFunction() func(input []byte) []byte

AllowanceMap() (adt.Map, error)
AllowanceMapBitWidth() int
AllowanceMapHashFunction() func(input []byte) []byte
AllowanceMapForOwner(owner address.Address) (adt.Map, error)
}

func AllCodes() []cid.Cid {
Expand Down
8 changes: 7 additions & 1 deletion chain/actors/builtin/datacap/datacap.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ import (
"github.com/filecoin-project/go-state-types/cbor"
"github.com/ipfs/go-cid"

"github.com/filecoin-project/lily/chain/actors"
lotusactors "github.com/filecoin-project/lotus/chain/actors"
"github.com/filecoin-project/lotus/chain/actors/adt"
"github.com/filecoin-project/lotus/chain/types"

"github.com/filecoin-project/lily/chain/actors"
)

var (
Expand Down Expand Up @@ -65,6 +66,11 @@ type State interface {
VerifiedClients() (adt.Map, error)
VerifiedClientsMapBitWidth() int
VerifiedClientsMapHashFunction() func(input []byte) []byte

AllowanceMap() (adt.Map, error)
AllowanceMapBitWidth() int
AllowanceMapHashFunction() func(input []byte) []byte
AllowanceMapForOwner(owner address.Address) (adt.Map, error)
}

func AllCodes() []cid.Cid {
Expand Down
40 changes: 40 additions & 0 deletions chain/actors/builtin/datacap/state.go.template
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,30 @@ func (s *state{{.v}}) VerifiedClientsMapHashFunction() func(input []byte) []byte
}
}

func (s *state{{.v}}) AllowanceMap() (adt.Map, error) {
return adt{{.v}}.AsMap(s.store, s.Token.Allowances, int(s.Token.HamtBitWidth))
}

func (s *state{{.v}}) AllowanceMapBitWidth() int {
return int(s.Token.HamtBitWidth)
}

func (s *state{{.v}}) AllowanceMapHashFunction() func(input []byte) []byte {
return func(input []byte) []byte {
res := sha256.Sum256(input)
return res[:]
}
}

func (s *state{{.v}}) AllowanceMapForOwner(owner address.Address) (adt.Map, error) {
innerHamtCid, err := s.getInnerHamtCid(s.store, abi.IdAddrKey(owner), s.Token.Allowances, int(s.Token.HamtBitWidth))
if err != nil {
return nil, err
}
return adt{{.v}}.AsMap(s.store, innerHamtCid, int(s.Token.HamtBitWidth))
}


func (s *state{{.v}}) ActorKey() string {
return actors.DatacapKey
}
Expand All @@ -90,3 +114,19 @@ func (s *state{{.v}}) Code() cid.Cid {

return code
}

func (s *state{{.v}}) getInnerHamtCid(store adt.Store, key abi.Keyer, mapCid cid.Cid, bitwidth int) (cid.Cid, error) {
actorToHamtMap, err := adt{{.v}}.AsMap(store, mapCid, bitwidth)
if err != nil {
return cid.Undef, fmt.Errorf("couldn't get outer map: %x", err)
}

var innerHamtCid cbg.CborCid
if found, err := actorToHamtMap.Get(key, &innerHamtCid); err != nil {
return cid.Undef, fmt.Errorf("looking up key: %s: %w", key, err)
} else if !found {
return cid.Undef, fmt.Errorf("did not find key: %s", key)
}

return cid.Cid(innerHamtCid), nil
}
43 changes: 42 additions & 1 deletion chain/actors/builtin/datacap/v9.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ import (
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/abi"
"github.com/ipfs/go-cid"
cbg "github.com/whyrusleeping/cbor-gen"

"github.com/filecoin-project/lily/chain/actors"
"github.com/filecoin-project/lotus/chain/actors/adt"

"github.com/filecoin-project/lily/chain/actors"

datacap9 "github.com/filecoin-project/go-state-types/builtin/v9/datacap"
adt9 "github.com/filecoin-project/go-state-types/builtin/v9/util/adt"
)
Expand Down Expand Up @@ -74,6 +76,29 @@ func (s *state9) VerifiedClientsMapHashFunction() func(input []byte) []byte {
}
}

func (s *state9) AllowanceMap() (adt.Map, error) {
return adt9.AsMap(s.store, s.Token.Allowances, int(s.Token.HamtBitWidth))
}

func (s *state9) AllowanceMapBitWidth() int {
return int(s.Token.HamtBitWidth)
}

func (s *state9) AllowanceMapHashFunction() func(input []byte) []byte {
return func(input []byte) []byte {
res := sha256.Sum256(input)
return res[:]
}
}

func (s *state9) AllowanceMapForOwner(owner address.Address) (adt.Map, error) {
innerHamtCid, err := s.getInnerHamtCid(s.store, abi.IdAddrKey(owner), s.Token.Allowances, int(s.Token.HamtBitWidth))
if err != nil {
return nil, err
}
return adt9.AsMap(s.store, innerHamtCid, int(s.Token.HamtBitWidth))
}

func (s *state9) ActorKey() string {
return actors.DatacapKey
}
Expand All @@ -90,3 +115,19 @@ func (s *state9) Code() cid.Cid {

return code
}

func (s *state9) getInnerHamtCid(store adt.Store, key abi.Keyer, mapCid cid.Cid, bitwidth int) (cid.Cid, error) {
actorToHamtMap, err := adt9.AsMap(store, mapCid, bitwidth)
if err != nil {
return cid.Undef, fmt.Errorf("couldn't get outer map: %x", err)
}

var innerHamtCid cbg.CborCid
if found, err := actorToHamtMap.Get(key, &innerHamtCid); err != nil {
return cid.Undef, fmt.Errorf("looking up key: %s: %w", key, err)
} else if !found {
return cid.Undef, fmt.Errorf("did not find key: %s", key)
}

return cid.Cid(innerHamtCid), nil
}
4 changes: 2 additions & 2 deletions chain/actors/builtin/market/actor.go.template
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,15 @@ type DealStates interface {
ForEach(cb func(id abi.DealID, ds DealState) error) error
Get(id abi.DealID) (*DealState, bool, error)

array() adt.Array
AsArray() adt.Array
decode(*cbg.Deferred) (*DealState, error)
}

type DealProposals interface {
ForEach(cb func(id abi.DealID, dp markettypes.DealProposal) error) error
Get(id abi.DealID) (*markettypes.DealProposal, bool, error)

array() adt.Array
AsArray() adt.Array
decode(*cbg.Deferred) (*markettypes.DealProposal, error)
}

Expand Down
8 changes: 4 additions & 4 deletions chain/actors/builtin/market/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ func DiffDealProposals(ctx context.Context, store adt.Store, pre, cur State) (*D
diffContainer := NewMarketProposalsDiffContainer(preP, curP)
if requiresLegacyDiffing(pre, cur, preOpts, curOpts) {
log.Warn("actor AMT opts differ, running slower generic array diff", "preCID", pre.Code(), "curCID", cur.Code())
if err := diff.CompareArray(preP.array(), curP.array(), diffContainer); err != nil {
if err := diff.CompareArray(preP.AsArray(), curP.AsArray(), diffContainer); err != nil {
return nil, fmt.Errorf("diffing deal states: %w", err)
}
return diffContainer.Results, nil
}

changes, err := diff.Amt(ctx, preP.array(), curP.array(), store, store, amt.UseTreeBitWidth(uint(preOpts)))
changes, err := diff.Amt(ctx, preP.AsArray(), curP.AsArray(), store, store, amt.UseTreeBitWidth(uint(preOpts)))
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -116,13 +116,13 @@ func DiffDealStates(ctx context.Context, store adt.Store, pre, cur State) (*Deal
diffContainer := NewMarketStatesDiffContainer(preS, curS)
if requiresLegacyDiffing(pre, cur, preOpts, curOpts) {
log.Warn("actor AMT opts differ, running slower generic array diff", "preCID", pre.Code(), "curCID", cur.Code())
if err := diff.CompareArray(preS.array(), curS.array(), diffContainer); err != nil {
if err := diff.CompareArray(preS.AsArray(), curS.AsArray(), diffContainer); err != nil {
return nil, fmt.Errorf("diffing deal states: %w", err)
}
return diffContainer.Results, nil
}

changes, err := diff.Amt(ctx, preS.array(), curS.array(), store, store, amt.UseTreeBitWidth(uint(preOpts)))
changes, err := diff.Amt(ctx, preS.AsArray(), curS.AsArray(), store, store, amt.UseTreeBitWidth(uint(preOpts)))
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions chain/actors/builtin/market/market.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions chain/actors/builtin/market/state.go.template
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func (s *dealStates{{.v}}) decode(val *cbg.Deferred) (*DealState, error) {
return &ds, nil
}

func (s *dealStates{{.v}}) array() adt.Array {
func (s *dealStates{{.v}}) AsArray() adt.Array {
return s.Array
}

Expand Down Expand Up @@ -199,7 +199,7 @@ func (s *dealProposals{{.v}}) decode(val *cbg.Deferred) (*DealProposal, error) {
return &dp, nil
}

func (s *dealProposals{{.v}}) array() adt.Array {
func (s *dealProposals{{.v}}) AsArray() adt.Array {
return s.Array
}

Expand Down
4 changes: 2 additions & 2 deletions chain/actors/builtin/market/v0.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions chain/actors/builtin/market/v2.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions chain/actors/builtin/market/v3.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions chain/actors/builtin/market/v4.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions chain/actors/builtin/market/v5.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions chain/actors/builtin/market/v6.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions chain/actors/builtin/market/v7.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions chain/actors/builtin/market/v8.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading