Skip to content

Commit cd31965

Browse files
committed
fix sector events and datacap diffing
1 parent 31260cd commit cd31965

File tree

3 files changed

+56
-8
lines changed

3 files changed

+56
-8
lines changed

chain/actors/builtin/datacap/diff.go

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ import (
77
"github.com/filecoin-project/go-address"
88
"github.com/filecoin-project/go-hamt-ipld/v3"
99
"github.com/filecoin-project/go-state-types/abi"
10+
"github.com/multiformats/go-varint"
1011
cbg "github.com/whyrusleeping/cbor-gen"
1112
"go.opentelemetry.io/otel"
1213
"go.opentelemetry.io/otel/attribute"
14+
"golang.org/x/xerrors"
1315

1416
"github.com/filecoin-project/lily/chain/actors/adt"
1517
"github.com/filecoin-project/lily/chain/actors/adt/diff"
@@ -122,7 +124,14 @@ func (m *balanceDiffContainer) AsKey(key string) (abi.Keyer, error) {
122124
}
123125

124126
func (m *balanceDiffContainer) Add(key string, val *cbg.Deferred) error {
125-
addr, err := address.NewFromBytes([]byte(key))
127+
id, n, err := varint.FromUvarint([]byte(key))
128+
if n != len([]byte(key)) {
129+
return xerrors.Errorf("could not get varint from address string")
130+
}
131+
if err != nil {
132+
return err
133+
}
134+
addr, err := address.NewIDAddress(id)
126135
if err != nil {
127136
return err
128137
}
@@ -138,7 +147,14 @@ func (m *balanceDiffContainer) Add(key string, val *cbg.Deferred) error {
138147
}
139148

140149
func (m *balanceDiffContainer) Modify(key string, before, after *cbg.Deferred) error {
141-
addr, err := address.NewFromBytes([]byte(key))
150+
id, n, err := varint.FromUvarint([]byte(key))
151+
if n != len([]byte(key)) {
152+
return xerrors.Errorf("could not get varint from address string")
153+
}
154+
if err != nil {
155+
return err
156+
}
157+
addr, err := address.NewIDAddress(id)
142158
if err != nil {
143159
return err
144160
}
@@ -164,7 +180,14 @@ func (m *balanceDiffContainer) Modify(key string, before, after *cbg.Deferred) e
164180
}
165181

166182
func (m *balanceDiffContainer) Remove(key string, val *cbg.Deferred) error {
167-
addr, err := address.NewFromBytes([]byte(key))
183+
id, n, err := varint.FromUvarint([]byte(key))
184+
if n != len([]byte(key)) {
185+
return xerrors.Errorf("could not get varint from address string")
186+
}
187+
if err != nil {
188+
return err
189+
}
190+
addr, err := address.NewIDAddress(id)
168191
if err != nil {
169192
return err
170193
}

tasks/actorstate/datacap/balance.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ func (BalanceExtractor) Extract(ctx context.Context, a actorstate.ActorInfo, nod
4343
Height: int64(ec.CurrTs.Height()),
4444
StateRoot: ec.CurrTs.ParentState().String(),
4545
Address: a.Address.String(),
46-
Event: dcap.String(),
47-
DataCap: datacapmodel.Added,
46+
Event: datacapmodel.Added,
47+
DataCap: dcap.String(),
4848
})
4949
return nil
5050
}); err != nil {

tasks/actorstate/miner/sector_events.go

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"go.uber.org/zap"
1212
"golang.org/x/sync/errgroup"
1313

14+
"github.com/filecoin-project/lily/chain/actors"
1415
"github.com/filecoin-project/lily/chain/actors/builtin/miner"
1516
"github.com/filecoin-project/lily/model"
1617
minermodel "github.com/filecoin-project/lily/model/actors/miner"
@@ -67,10 +68,34 @@ func (SectorEventsExtractor) Extract(ctx context.Context, a actorstate.ActorInfo
6768
grp.Go(func() error {
6869
start := time.Now()
6970
// collect changes made to miner precommit map (HAMT)
70-
preCommitChanges, err = node.DiffPreCommits(grpCtx, a.Address, a.Current, a.Executed, extState.ParentState(), extState.CurrentState())
71-
if err != nil {
72-
return fmt.Errorf("diffing precommits %w", err)
71+
if extState.CurrentState().ActorVersion() > actors.Version8 {
72+
preCommitChanges, err = node.DiffPreCommits(grpCtx, a.Address, a.Current, a.Executed, extState.ParentState(), extState.CurrentState())
73+
if err != nil {
74+
return fmt.Errorf("diffing precommits %w", err)
75+
}
76+
} else {
77+
var v8PreCommitChanges *miner.PreCommitChangesV8
78+
v8PreCommitChanges, err = node.DiffPreCommitsV8(grpCtx, a.Address, a.Current, a.Executed, extState.ParentState(), extState.CurrentState())
79+
if err != nil {
80+
return fmt.Errorf("diffing precommits: %w", err)
81+
}
82+
for _, c := range v8PreCommitChanges.Added {
83+
preCommitChanges.Added = append(preCommitChanges.Added, minertypes.SectorPreCommitOnChainInfo{
84+
Info: minertypes.SectorPreCommitInfo{
85+
SealProof: c.Info.SealProof,
86+
SectorNumber: c.Info.SectorNumber,
87+
SealedCID: c.Info.SealedCID,
88+
SealRandEpoch: c.Info.SealRandEpoch,
89+
DealIDs: nil,
90+
Expiration: c.Info.Expiration,
91+
UnsealedCid: nil,
92+
},
93+
PreCommitDeposit: c.PreCommitDeposit,
94+
PreCommitEpoch: c.PreCommitEpoch,
95+
})
96+
}
7397
}
98+
7499
log.Debugw("diff precommits", "miner", a.Address, "duration", time.Since(start))
75100
return nil
76101
})

0 commit comments

Comments
 (0)