Skip to content

Custom RemoveExpiredAllocationsReturn #396

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

Merged
merged 3 commits into from
May 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
85 changes: 85 additions & 0 deletions actors/v2/verifiedRegistry/types/removeExpiredAllocations.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package types

import (
"fmt"
"io"

"github.com/filecoin-project/go-state-types/batch"
"github.com/filecoin-project/go-state-types/big"
cbg "github.com/whyrusleeping/cbor-gen"
)

type RemoveExpiredAllocationsReturn struct {
Considered []uint64
Results batch.BatchReturn
DataCapRecovered big.Int
}

func (t *RemoveExpiredAllocationsReturn) UnmarshalCBOR(r io.Reader) (err error) {
*t = RemoveExpiredAllocationsReturn{}

cr := cbg.NewCborReader(r)

maj, extra, err := cr.ReadHeader()
if err != nil {
return err
}
defer func() {
if err == io.EOF {
err = io.ErrUnexpectedEOF
}
}()

if maj != cbg.MajArray {
return fmt.Errorf("cbor input should be of type array")
}

if extra != 3 {
return fmt.Errorf("cbor input had wrong number of fields")
}

// t.Considered ([]verifreg.AllocationId) (slice)

maj, extra, err = cr.ReadHeader()
if err != nil {
return err
}

// allow a larger []Considered
// if extra > 8192 {
// return fmt.Errorf("t.Considered: array too large (%d)", extra)
// }

if maj != cbg.MajArray {
return fmt.Errorf("expected cbor array")
}

if extra > 0 {
t.Considered = make([]uint64, extra)
}

for i := 0; i < int(extra); i++ {
maj, extra, err := cr.ReadHeader()
if err != nil {
return err
}
if maj != cbg.MajUnsignedInt {
return fmt.Errorf("wrong type for uint64 field")
}
t.Considered[i] = extra
}

// t.Results (batch.BatchReturn) (struct)

if err := t.Results.UnmarshalCBOR(cr); err != nil {
return fmt.Errorf("unmarshaling t.Results: %w", err)
}

// t.DataCapRecovered (big.Int) (struct)

if err := t.DataCapRecovered.UnmarshalCBOR(cr); err != nil {
return fmt.Errorf("unmarshaling t.DataCapRecovered: %w", err)
}

return nil
}
10 changes: 9 additions & 1 deletion actors/v2/verifiedRegistry/verifiedRegistry.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (
verifregv9 "github.com/filecoin-project/go-state-types/builtin/v9/verifreg"

"github.com/zondax/fil-parser/actors"
"github.com/zondax/fil-parser/actors/v2/verifiedRegistry/types"
"github.com/zondax/fil-parser/parser"
"github.com/zondax/fil-parser/tools"
)

Expand Down Expand Up @@ -150,7 +152,13 @@ func (*VerifiedRegistry) RemoveExpiredAllocationsExported(network string, height
return nil, fmt.Errorf("%w: %d", actors.ErrUnsupportedHeight, height)
}

return parse(raw, rawReturn, true, params(), returnValue())
metadata, err := parse(raw, rawReturn, true, params(), returnValue())
if err != nil || metadata[parser.ReturnKey] == nil {
// if Considered is larger than 8192 the go-state-types parser will return an error
// try with a larger allowed slice for the return
metadata, err = parse(raw, rawReturn, true, params(), &types.RemoveExpiredAllocationsReturn{})
}
return metadata, err
}

func (*VerifiedRegistry) Deprecated1(network string, height int64, raw []byte) (map[string]interface{}, error) {
Expand Down
Loading