Merge branch 'master' into asr/shed-balances
This commit is contained in:
commit
63d7ca328f
@ -895,6 +895,11 @@ workflows:
|
||||
suite: itest-sector_terminate
|
||||
target: "./itests/sector_terminate_test.go"
|
||||
|
||||
- test:
|
||||
name: test-itest-self_sent_txn
|
||||
suite: itest-self_sent_txn
|
||||
target: "./itests/self_sent_txn_test.go"
|
||||
|
||||
- test:
|
||||
name: test-itest-tape
|
||||
suite: itest-tape
|
||||
|
21
.github/pull_request_template.md
vendored
Normal file
21
.github/pull_request_template.md
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
## Related Issues
|
||||
<!-- link all issues that this PR might resolve/fix. If an issue doesn't exist, include a brief motivation for the change being made.-->
|
||||
|
||||
## Proposed Changes
|
||||
<!-- provide a clear list of the changes being made-->
|
||||
|
||||
|
||||
## Additional Info
|
||||
<!-- callouts, links to documentation, and etc-->
|
||||
|
||||
## Checklist
|
||||
|
||||
Before you mark the PR ready for review, please make sure that:
|
||||
- [ ] All commits have a clear commit message.
|
||||
- [ ] The PR title is in the form of of `<PR type>: <#issue number> <area>: <change being made>`
|
||||
- example: ` fix: #1234 mempool: Introduce a cache for valid signatures`
|
||||
- `PR type`: _fix_, _feat_, _INTERFACE BREAKING CHANGE_, _CONSENSUS BREAKING_, _build_, _chore_, _ci_, _docs_, _misc_,_perf_, _refactor_, _revert_, _style_, _test_
|
||||
- `area`: _api_, _chain_, _state_, _vm_, _data transfer_, _market_, _mempool_, _message_, _block production_, _multisig_, _networking_, _paychan_, _proving_, _sealing_, _wallet_
|
||||
- [ ] This PR has tests for new functionality or change in behaviour
|
||||
- [ ] If new user-facing features are introduced, clear usage guidelines and / or documentation updates should be included in https://lotus.filecoin.io or [Discussion Tutorials.](https://github.com/filecoin-project/lotus/discussions/categories/tutorials)
|
||||
- [ ] CI is green
|
@ -900,6 +900,7 @@ type QueryOffer struct {
|
||||
Size uint64
|
||||
MinPrice types.BigInt
|
||||
UnsealPrice types.BigInt
|
||||
PricePerByte abi.TokenAmount
|
||||
PaymentInterval uint64
|
||||
PaymentIntervalIncrease uint64
|
||||
Miner address.Address
|
||||
|
@ -118,17 +118,21 @@ type StorageMiner interface {
|
||||
WorkerJobs(context.Context) (map[uuid.UUID][]storiface.WorkerJob, error) //perm:admin
|
||||
|
||||
//storiface.WorkerReturn
|
||||
ReturnAddPiece(ctx context.Context, callID storiface.CallID, pi abi.PieceInfo, err *storiface.CallError) error //perm:admin retry:true
|
||||
ReturnSealPreCommit1(ctx context.Context, callID storiface.CallID, p1o storage.PreCommit1Out, err *storiface.CallError) error //perm:admin retry:true
|
||||
ReturnSealPreCommit2(ctx context.Context, callID storiface.CallID, sealed storage.SectorCids, err *storiface.CallError) error //perm:admin retry:true
|
||||
ReturnSealCommit1(ctx context.Context, callID storiface.CallID, out storage.Commit1Out, err *storiface.CallError) error //perm:admin retry:true
|
||||
ReturnSealCommit2(ctx context.Context, callID storiface.CallID, proof storage.Proof, err *storiface.CallError) error //perm:admin retry:true
|
||||
ReturnFinalizeSector(ctx context.Context, callID storiface.CallID, err *storiface.CallError) error //perm:admin retry:true
|
||||
ReturnReleaseUnsealed(ctx context.Context, callID storiface.CallID, err *storiface.CallError) error //perm:admin retry:true
|
||||
ReturnMoveStorage(ctx context.Context, callID storiface.CallID, err *storiface.CallError) error //perm:admin retry:true
|
||||
ReturnUnsealPiece(ctx context.Context, callID storiface.CallID, err *storiface.CallError) error //perm:admin retry:true
|
||||
ReturnReadPiece(ctx context.Context, callID storiface.CallID, ok bool, err *storiface.CallError) error //perm:admin retry:true
|
||||
ReturnFetch(ctx context.Context, callID storiface.CallID, err *storiface.CallError) error //perm:admin retry:true
|
||||
ReturnAddPiece(ctx context.Context, callID storiface.CallID, pi abi.PieceInfo, err *storiface.CallError) error //perm:admin retry:true
|
||||
ReturnSealPreCommit1(ctx context.Context, callID storiface.CallID, p1o storage.PreCommit1Out, err *storiface.CallError) error //perm:admin retry:true
|
||||
ReturnSealPreCommit2(ctx context.Context, callID storiface.CallID, sealed storage.SectorCids, err *storiface.CallError) error //perm:admin retry:true
|
||||
ReturnSealCommit1(ctx context.Context, callID storiface.CallID, out storage.Commit1Out, err *storiface.CallError) error //perm:admin retry:true
|
||||
ReturnSealCommit2(ctx context.Context, callID storiface.CallID, proof storage.Proof, err *storiface.CallError) error //perm:admin retry:true
|
||||
ReturnFinalizeSector(ctx context.Context, callID storiface.CallID, err *storiface.CallError) error //perm:admin retry:true
|
||||
ReturnReplicaUpdate(ctx context.Context, callID storiface.CallID, out storage.ReplicaUpdateOut, err *storiface.CallError) error //perm:admin retry:true
|
||||
ReturnProveReplicaUpdate1(ctx context.Context, callID storiface.CallID, vanillaProofs storage.ReplicaVanillaProofs, err *storiface.CallError) error //perm:admin retry:true
|
||||
ReturnProveReplicaUpdate2(ctx context.Context, callID storiface.CallID, proof storage.ReplicaUpdateProof, err *storiface.CallError) error //perm:admin retry:true
|
||||
ReturnGenerateSectorKeyFromData(ctx context.Context, callID storiface.CallID, err *storiface.CallError) error //perm:admin retry:true
|
||||
ReturnReleaseUnsealed(ctx context.Context, callID storiface.CallID, err *storiface.CallError) error //perm:admin retry:true
|
||||
ReturnMoveStorage(ctx context.Context, callID storiface.CallID, err *storiface.CallError) error //perm:admin retry:true
|
||||
ReturnUnsealPiece(ctx context.Context, callID storiface.CallID, err *storiface.CallError) error //perm:admin retry:true
|
||||
ReturnReadPiece(ctx context.Context, callID storiface.CallID, ok bool, err *storiface.CallError) error //perm:admin retry:true
|
||||
ReturnFetch(ctx context.Context, callID storiface.CallID, err *storiface.CallError) error //perm:admin retry:true
|
||||
|
||||
// SealingSchedDiag dumps internal sealing scheduler state
|
||||
SealingSchedDiag(ctx context.Context, doSched bool) (interface{}, error) //perm:admin
|
||||
@ -145,6 +149,7 @@ type StorageMiner interface {
|
||||
StorageLock(ctx context.Context, sector abi.SectorID, read storiface.SectorFileType, write storiface.SectorFileType) error //perm:admin
|
||||
StorageTryLock(ctx context.Context, sector abi.SectorID, read storiface.SectorFileType, write storiface.SectorFileType) (bool, error) //perm:admin
|
||||
StorageList(ctx context.Context) (map[stores.ID][]stores.Decl, error) //perm:admin
|
||||
StorageGetLocks(ctx context.Context) (storiface.SectorLocks, error) //perm:admin
|
||||
|
||||
StorageLocal(ctx context.Context) (map[stores.ID]string, error) //perm:admin
|
||||
StorageStat(ctx context.Context, id stores.ID) (fsutil.FsStat, error) //perm:admin
|
||||
@ -160,6 +165,8 @@ type StorageMiner interface {
|
||||
MarketGetRetrievalAsk(ctx context.Context) (*retrievalmarket.Ask, error) //perm:read
|
||||
MarketListDataTransfers(ctx context.Context) ([]DataTransferChannel, error) //perm:write
|
||||
MarketDataTransferUpdates(ctx context.Context) (<-chan DataTransferChannel, error) //perm:write
|
||||
// MarketDataTransferDiagnostics generates debugging information about current data transfers over graphsync
|
||||
MarketDataTransferDiagnostics(ctx context.Context, p peer.ID) (*TransferDiagnostics, error) //perm:write
|
||||
// MarketRestartDataTransfer attempts to restart a data transfer with the given transfer ID and other peer
|
||||
MarketRestartDataTransfer(ctx context.Context, transferID datatransfer.TransferID, otherPeer peer.ID, isInitiator bool) error //perm:write
|
||||
// MarketCancelDataTransfer cancels a data transfer with the given transfer ID and other peer
|
||||
|
@ -39,6 +39,10 @@ type Worker interface {
|
||||
SealCommit1(ctx context.Context, sector storage.SectorRef, ticket abi.SealRandomness, seed abi.InteractiveSealRandomness, pieces []abi.PieceInfo, cids storage.SectorCids) (storiface.CallID, error) //perm:admin
|
||||
SealCommit2(ctx context.Context, sector storage.SectorRef, c1o storage.Commit1Out) (storiface.CallID, error) //perm:admin
|
||||
FinalizeSector(ctx context.Context, sector storage.SectorRef, keepUnsealed []storage.Range) (storiface.CallID, error) //perm:admin
|
||||
ReplicaUpdate(ctx context.Context, sector storage.SectorRef, pieces []abi.PieceInfo) (storiface.CallID, error) //perm:admin
|
||||
ProveReplicaUpdate1(ctx context.Context, sector storage.SectorRef, sectorKey, newSealed, newUnsealed cid.Cid) (storiface.CallID, error) //perm:admin
|
||||
ProveReplicaUpdate2(ctx context.Context, sector storage.SectorRef, sectorKey, newSealed, newUnsealed cid.Cid, vanillaProofs storage.ReplicaVanillaProofs) (storiface.CallID, error) //perm:admin
|
||||
GenerateSectorKeyFromData(ctx context.Context, sector storage.SectorRef, commD cid.Cid) (storiface.CallID, error) //perm:admin
|
||||
ReleaseUnsealed(ctx context.Context, sector storage.SectorRef, safeToFree []storage.Range) (storiface.CallID, error) //perm:admin
|
||||
MoveStorage(ctx context.Context, sector storage.SectorRef, types storiface.SectorFileType) (storiface.CallID, error) //perm:admin
|
||||
UnsealPiece(context.Context, storage.SectorRef, storiface.UnpaddedByteIndex, abi.UnpaddedPieceSize, abi.SealRandomness, cid.Cid) (storiface.CallID, error) //perm:admin
|
||||
|
@ -1,6 +1,7 @@
|
||||
package docgen
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"go/ast"
|
||||
"go/parser"
|
||||
@ -15,6 +16,7 @@ import (
|
||||
"github.com/filecoin-project/go-bitfield"
|
||||
"github.com/google/uuid"
|
||||
"github.com/ipfs/go-cid"
|
||||
"github.com/ipfs/go-graphsync"
|
||||
"github.com/libp2p/go-libp2p-core/metrics"
|
||||
"github.com/libp2p/go-libp2p-core/network"
|
||||
"github.com/libp2p/go-libp2p-core/peer"
|
||||
@ -120,6 +122,7 @@ func init() {
|
||||
addExample(api.FullAPIVersion1)
|
||||
addExample(api.PCHInbound)
|
||||
addExample(time.Minute)
|
||||
addExample(graphsync.RequestID(4))
|
||||
addExample(datatransfer.TransferID(3))
|
||||
addExample(datatransfer.Ongoing)
|
||||
addExample(storeIDExample)
|
||||
@ -250,10 +253,18 @@ func init() {
|
||||
addExample(map[abi.SectorNumber]string{
|
||||
123: "can't acquire read lock",
|
||||
})
|
||||
addExample(json.RawMessage(`"json raw message"`))
|
||||
addExample(map[api.SectorState]int{
|
||||
api.SectorState(sealing.Proving): 120,
|
||||
})
|
||||
addExample([]abi.SectorNumber{123, 124})
|
||||
addExample([]storiface.SectorLock{
|
||||
{
|
||||
Sector: abi.SectorID{Number: 123, Miner: 1000},
|
||||
Write: [storiface.FileTypes]uint{0, 0, 1},
|
||||
Read: [storiface.FileTypes]uint{2, 3, 0},
|
||||
},
|
||||
})
|
||||
|
||||
// worker specific
|
||||
addExample(storiface.AcquireMove)
|
||||
@ -339,7 +350,7 @@ func ExampleValue(method string, t, parent reflect.Type) interface{} {
|
||||
switch t.Kind() {
|
||||
case reflect.Slice:
|
||||
out := reflect.New(t).Elem()
|
||||
reflect.Append(out, reflect.ValueOf(ExampleValue(method, t.Elem(), t)))
|
||||
out = reflect.Append(out, reflect.ValueOf(ExampleValue(method, t.Elem(), t)))
|
||||
return out.Interface()
|
||||
case reflect.Chan:
|
||||
return ExampleValue(method, t.Elem(), nil)
|
||||
|
130
api/proxy_gen.go
130
api/proxy_gen.go
@ -668,6 +668,8 @@ type StorageMinerStruct struct {
|
||||
|
||||
MarketCancelDataTransfer func(p0 context.Context, p1 datatransfer.TransferID, p2 peer.ID, p3 bool) error `perm:"write"`
|
||||
|
||||
MarketDataTransferDiagnostics func(p0 context.Context, p1 peer.ID) (*TransferDiagnostics, error) `perm:"write"`
|
||||
|
||||
MarketDataTransferUpdates func(p0 context.Context) (<-chan DataTransferChannel, error) `perm:"write"`
|
||||
|
||||
MarketGetAsk func(p0 context.Context) (*storagemarket.SignedStorageAsk, error) `perm:"read"`
|
||||
@ -716,12 +718,20 @@ type StorageMinerStruct struct {
|
||||
|
||||
ReturnFinalizeSector func(p0 context.Context, p1 storiface.CallID, p2 *storiface.CallError) error `perm:"admin"`
|
||||
|
||||
ReturnGenerateSectorKeyFromData func(p0 context.Context, p1 storiface.CallID, p2 *storiface.CallError) error `perm:"admin"`
|
||||
|
||||
ReturnMoveStorage func(p0 context.Context, p1 storiface.CallID, p2 *storiface.CallError) error `perm:"admin"`
|
||||
|
||||
ReturnProveReplicaUpdate1 func(p0 context.Context, p1 storiface.CallID, p2 storage.ReplicaVanillaProofs, p3 *storiface.CallError) error `perm:"admin"`
|
||||
|
||||
ReturnProveReplicaUpdate2 func(p0 context.Context, p1 storiface.CallID, p2 storage.ReplicaUpdateProof, p3 *storiface.CallError) error `perm:"admin"`
|
||||
|
||||
ReturnReadPiece func(p0 context.Context, p1 storiface.CallID, p2 bool, p3 *storiface.CallError) error `perm:"admin"`
|
||||
|
||||
ReturnReleaseUnsealed func(p0 context.Context, p1 storiface.CallID, p2 *storiface.CallError) error `perm:"admin"`
|
||||
|
||||
ReturnReplicaUpdate func(p0 context.Context, p1 storiface.CallID, p2 storage.ReplicaUpdateOut, p3 *storiface.CallError) error `perm:"admin"`
|
||||
|
||||
ReturnSealCommit1 func(p0 context.Context, p1 storiface.CallID, p2 storage.Commit1Out, p3 *storiface.CallError) error `perm:"admin"`
|
||||
|
||||
ReturnSealCommit2 func(p0 context.Context, p1 storiface.CallID, p2 storage.Proof, p3 *storiface.CallError) error `perm:"admin"`
|
||||
@ -794,6 +804,8 @@ type StorageMinerStruct struct {
|
||||
|
||||
StorageFindSector func(p0 context.Context, p1 abi.SectorID, p2 storiface.SectorFileType, p3 abi.SectorSize, p4 bool) ([]stores.SectorStorageInfo, error) `perm:"admin"`
|
||||
|
||||
StorageGetLocks func(p0 context.Context) (storiface.SectorLocks, error) `perm:"admin"`
|
||||
|
||||
StorageInfo func(p0 context.Context, p1 stores.ID) (stores.StorageInfo, error) `perm:"admin"`
|
||||
|
||||
StorageList func(p0 context.Context) (map[stores.ID][]stores.Decl, error) `perm:"admin"`
|
||||
@ -853,6 +865,8 @@ type WorkerStruct struct {
|
||||
|
||||
FinalizeSector func(p0 context.Context, p1 storage.SectorRef, p2 []storage.Range) (storiface.CallID, error) `perm:"admin"`
|
||||
|
||||
GenerateSectorKeyFromData func(p0 context.Context, p1 storage.SectorRef, p2 cid.Cid) (storiface.CallID, error) `perm:"admin"`
|
||||
|
||||
Info func(p0 context.Context) (storiface.WorkerInfo, error) `perm:"admin"`
|
||||
|
||||
MoveStorage func(p0 context.Context, p1 storage.SectorRef, p2 storiface.SectorFileType) (storiface.CallID, error) `perm:"admin"`
|
||||
@ -861,10 +875,16 @@ type WorkerStruct struct {
|
||||
|
||||
ProcessSession func(p0 context.Context) (uuid.UUID, error) `perm:"admin"`
|
||||
|
||||
ProveReplicaUpdate1 func(p0 context.Context, p1 storage.SectorRef, p2 cid.Cid, p3 cid.Cid, p4 cid.Cid) (storiface.CallID, error) `perm:"admin"`
|
||||
|
||||
ProveReplicaUpdate2 func(p0 context.Context, p1 storage.SectorRef, p2 cid.Cid, p3 cid.Cid, p4 cid.Cid, p5 storage.ReplicaVanillaProofs) (storiface.CallID, error) `perm:"admin"`
|
||||
|
||||
ReleaseUnsealed func(p0 context.Context, p1 storage.SectorRef, p2 []storage.Range) (storiface.CallID, error) `perm:"admin"`
|
||||
|
||||
Remove func(p0 context.Context, p1 abi.SectorID) error `perm:"admin"`
|
||||
|
||||
ReplicaUpdate func(p0 context.Context, p1 storage.SectorRef, p2 []abi.PieceInfo) (storiface.CallID, error) `perm:"admin"`
|
||||
|
||||
SealCommit1 func(p0 context.Context, p1 storage.SectorRef, p2 abi.SealRandomness, p3 abi.InteractiveSealRandomness, p4 []abi.PieceInfo, p5 storage.SectorCids) (storiface.CallID, error) `perm:"admin"`
|
||||
|
||||
SealCommit2 func(p0 context.Context, p1 storage.SectorRef, p2 storage.Commit1Out) (storiface.CallID, error) `perm:"admin"`
|
||||
@ -3954,6 +3974,17 @@ func (s *StorageMinerStub) MarketCancelDataTransfer(p0 context.Context, p1 datat
|
||||
return ErrNotSupported
|
||||
}
|
||||
|
||||
func (s *StorageMinerStruct) MarketDataTransferDiagnostics(p0 context.Context, p1 peer.ID) (*TransferDiagnostics, error) {
|
||||
if s.Internal.MarketDataTransferDiagnostics == nil {
|
||||
return nil, ErrNotSupported
|
||||
}
|
||||
return s.Internal.MarketDataTransferDiagnostics(p0, p1)
|
||||
}
|
||||
|
||||
func (s *StorageMinerStub) MarketDataTransferDiagnostics(p0 context.Context, p1 peer.ID) (*TransferDiagnostics, error) {
|
||||
return nil, ErrNotSupported
|
||||
}
|
||||
|
||||
func (s *StorageMinerStruct) MarketDataTransferUpdates(p0 context.Context) (<-chan DataTransferChannel, error) {
|
||||
if s.Internal.MarketDataTransferUpdates == nil {
|
||||
return nil, ErrNotSupported
|
||||
@ -4218,6 +4249,17 @@ func (s *StorageMinerStub) ReturnFinalizeSector(p0 context.Context, p1 storiface
|
||||
return ErrNotSupported
|
||||
}
|
||||
|
||||
func (s *StorageMinerStruct) ReturnGenerateSectorKeyFromData(p0 context.Context, p1 storiface.CallID, p2 *storiface.CallError) error {
|
||||
if s.Internal.ReturnGenerateSectorKeyFromData == nil {
|
||||
return ErrNotSupported
|
||||
}
|
||||
return s.Internal.ReturnGenerateSectorKeyFromData(p0, p1, p2)
|
||||
}
|
||||
|
||||
func (s *StorageMinerStub) ReturnGenerateSectorKeyFromData(p0 context.Context, p1 storiface.CallID, p2 *storiface.CallError) error {
|
||||
return ErrNotSupported
|
||||
}
|
||||
|
||||
func (s *StorageMinerStruct) ReturnMoveStorage(p0 context.Context, p1 storiface.CallID, p2 *storiface.CallError) error {
|
||||
if s.Internal.ReturnMoveStorage == nil {
|
||||
return ErrNotSupported
|
||||
@ -4229,6 +4271,28 @@ func (s *StorageMinerStub) ReturnMoveStorage(p0 context.Context, p1 storiface.Ca
|
||||
return ErrNotSupported
|
||||
}
|
||||
|
||||
func (s *StorageMinerStruct) ReturnProveReplicaUpdate1(p0 context.Context, p1 storiface.CallID, p2 storage.ReplicaVanillaProofs, p3 *storiface.CallError) error {
|
||||
if s.Internal.ReturnProveReplicaUpdate1 == nil {
|
||||
return ErrNotSupported
|
||||
}
|
||||
return s.Internal.ReturnProveReplicaUpdate1(p0, p1, p2, p3)
|
||||
}
|
||||
|
||||
func (s *StorageMinerStub) ReturnProveReplicaUpdate1(p0 context.Context, p1 storiface.CallID, p2 storage.ReplicaVanillaProofs, p3 *storiface.CallError) error {
|
||||
return ErrNotSupported
|
||||
}
|
||||
|
||||
func (s *StorageMinerStruct) ReturnProveReplicaUpdate2(p0 context.Context, p1 storiface.CallID, p2 storage.ReplicaUpdateProof, p3 *storiface.CallError) error {
|
||||
if s.Internal.ReturnProveReplicaUpdate2 == nil {
|
||||
return ErrNotSupported
|
||||
}
|
||||
return s.Internal.ReturnProveReplicaUpdate2(p0, p1, p2, p3)
|
||||
}
|
||||
|
||||
func (s *StorageMinerStub) ReturnProveReplicaUpdate2(p0 context.Context, p1 storiface.CallID, p2 storage.ReplicaUpdateProof, p3 *storiface.CallError) error {
|
||||
return ErrNotSupported
|
||||
}
|
||||
|
||||
func (s *StorageMinerStruct) ReturnReadPiece(p0 context.Context, p1 storiface.CallID, p2 bool, p3 *storiface.CallError) error {
|
||||
if s.Internal.ReturnReadPiece == nil {
|
||||
return ErrNotSupported
|
||||
@ -4251,6 +4315,17 @@ func (s *StorageMinerStub) ReturnReleaseUnsealed(p0 context.Context, p1 storifac
|
||||
return ErrNotSupported
|
||||
}
|
||||
|
||||
func (s *StorageMinerStruct) ReturnReplicaUpdate(p0 context.Context, p1 storiface.CallID, p2 storage.ReplicaUpdateOut, p3 *storiface.CallError) error {
|
||||
if s.Internal.ReturnReplicaUpdate == nil {
|
||||
return ErrNotSupported
|
||||
}
|
||||
return s.Internal.ReturnReplicaUpdate(p0, p1, p2, p3)
|
||||
}
|
||||
|
||||
func (s *StorageMinerStub) ReturnReplicaUpdate(p0 context.Context, p1 storiface.CallID, p2 storage.ReplicaUpdateOut, p3 *storiface.CallError) error {
|
||||
return ErrNotSupported
|
||||
}
|
||||
|
||||
func (s *StorageMinerStruct) ReturnSealCommit1(p0 context.Context, p1 storiface.CallID, p2 storage.Commit1Out, p3 *storiface.CallError) error {
|
||||
if s.Internal.ReturnSealCommit1 == nil {
|
||||
return ErrNotSupported
|
||||
@ -4647,6 +4722,17 @@ func (s *StorageMinerStub) StorageFindSector(p0 context.Context, p1 abi.SectorID
|
||||
return *new([]stores.SectorStorageInfo), ErrNotSupported
|
||||
}
|
||||
|
||||
func (s *StorageMinerStruct) StorageGetLocks(p0 context.Context) (storiface.SectorLocks, error) {
|
||||
if s.Internal.StorageGetLocks == nil {
|
||||
return *new(storiface.SectorLocks), ErrNotSupported
|
||||
}
|
||||
return s.Internal.StorageGetLocks(p0)
|
||||
}
|
||||
|
||||
func (s *StorageMinerStub) StorageGetLocks(p0 context.Context) (storiface.SectorLocks, error) {
|
||||
return *new(storiface.SectorLocks), ErrNotSupported
|
||||
}
|
||||
|
||||
func (s *StorageMinerStruct) StorageInfo(p0 context.Context, p1 stores.ID) (stores.StorageInfo, error) {
|
||||
if s.Internal.StorageInfo == nil {
|
||||
return *new(stores.StorageInfo), ErrNotSupported
|
||||
@ -4878,6 +4964,17 @@ func (s *WorkerStub) FinalizeSector(p0 context.Context, p1 storage.SectorRef, p2
|
||||
return *new(storiface.CallID), ErrNotSupported
|
||||
}
|
||||
|
||||
func (s *WorkerStruct) GenerateSectorKeyFromData(p0 context.Context, p1 storage.SectorRef, p2 cid.Cid) (storiface.CallID, error) {
|
||||
if s.Internal.GenerateSectorKeyFromData == nil {
|
||||
return *new(storiface.CallID), ErrNotSupported
|
||||
}
|
||||
return s.Internal.GenerateSectorKeyFromData(p0, p1, p2)
|
||||
}
|
||||
|
||||
func (s *WorkerStub) GenerateSectorKeyFromData(p0 context.Context, p1 storage.SectorRef, p2 cid.Cid) (storiface.CallID, error) {
|
||||
return *new(storiface.CallID), ErrNotSupported
|
||||
}
|
||||
|
||||
func (s *WorkerStruct) Info(p0 context.Context) (storiface.WorkerInfo, error) {
|
||||
if s.Internal.Info == nil {
|
||||
return *new(storiface.WorkerInfo), ErrNotSupported
|
||||
@ -4922,6 +5019,28 @@ func (s *WorkerStub) ProcessSession(p0 context.Context) (uuid.UUID, error) {
|
||||
return *new(uuid.UUID), ErrNotSupported
|
||||
}
|
||||
|
||||
func (s *WorkerStruct) ProveReplicaUpdate1(p0 context.Context, p1 storage.SectorRef, p2 cid.Cid, p3 cid.Cid, p4 cid.Cid) (storiface.CallID, error) {
|
||||
if s.Internal.ProveReplicaUpdate1 == nil {
|
||||
return *new(storiface.CallID), ErrNotSupported
|
||||
}
|
||||
return s.Internal.ProveReplicaUpdate1(p0, p1, p2, p3, p4)
|
||||
}
|
||||
|
||||
func (s *WorkerStub) ProveReplicaUpdate1(p0 context.Context, p1 storage.SectorRef, p2 cid.Cid, p3 cid.Cid, p4 cid.Cid) (storiface.CallID, error) {
|
||||
return *new(storiface.CallID), ErrNotSupported
|
||||
}
|
||||
|
||||
func (s *WorkerStruct) ProveReplicaUpdate2(p0 context.Context, p1 storage.SectorRef, p2 cid.Cid, p3 cid.Cid, p4 cid.Cid, p5 storage.ReplicaVanillaProofs) (storiface.CallID, error) {
|
||||
if s.Internal.ProveReplicaUpdate2 == nil {
|
||||
return *new(storiface.CallID), ErrNotSupported
|
||||
}
|
||||
return s.Internal.ProveReplicaUpdate2(p0, p1, p2, p3, p4, p5)
|
||||
}
|
||||
|
||||
func (s *WorkerStub) ProveReplicaUpdate2(p0 context.Context, p1 storage.SectorRef, p2 cid.Cid, p3 cid.Cid, p4 cid.Cid, p5 storage.ReplicaVanillaProofs) (storiface.CallID, error) {
|
||||
return *new(storiface.CallID), ErrNotSupported
|
||||
}
|
||||
|
||||
func (s *WorkerStruct) ReleaseUnsealed(p0 context.Context, p1 storage.SectorRef, p2 []storage.Range) (storiface.CallID, error) {
|
||||
if s.Internal.ReleaseUnsealed == nil {
|
||||
return *new(storiface.CallID), ErrNotSupported
|
||||
@ -4944,6 +5063,17 @@ func (s *WorkerStub) Remove(p0 context.Context, p1 abi.SectorID) error {
|
||||
return ErrNotSupported
|
||||
}
|
||||
|
||||
func (s *WorkerStruct) ReplicaUpdate(p0 context.Context, p1 storage.SectorRef, p2 []abi.PieceInfo) (storiface.CallID, error) {
|
||||
if s.Internal.ReplicaUpdate == nil {
|
||||
return *new(storiface.CallID), ErrNotSupported
|
||||
}
|
||||
return s.Internal.ReplicaUpdate(p0, p1, p2)
|
||||
}
|
||||
|
||||
func (s *WorkerStub) ReplicaUpdate(p0 context.Context, p1 storage.SectorRef, p2 []abi.PieceInfo) (storiface.CallID, error) {
|
||||
return *new(storiface.CallID), ErrNotSupported
|
||||
}
|
||||
|
||||
func (s *WorkerStruct) SealCommit1(p0 context.Context, p1 storage.SectorRef, p2 abi.SealRandomness, p3 abi.InteractiveSealRandomness, p4 []abi.PieceInfo, p5 storage.SectorCids) (storiface.CallID, error) {
|
||||
if s.Internal.SealCommit1 == nil {
|
||||
return *new(storiface.CallID), ErrNotSupported
|
||||
|
25
api/types.go
25
api/types.go
@ -10,6 +10,7 @@ import (
|
||||
"github.com/filecoin-project/go-state-types/abi"
|
||||
"github.com/filecoin-project/lotus/chain/types"
|
||||
"github.com/ipfs/go-cid"
|
||||
"github.com/ipfs/go-graphsync"
|
||||
|
||||
"github.com/libp2p/go-libp2p-core/peer"
|
||||
pubsub "github.com/libp2p/go-libp2p-pubsub"
|
||||
@ -53,6 +54,30 @@ type MessageSendSpec struct {
|
||||
MaxFee abi.TokenAmount
|
||||
}
|
||||
|
||||
// GraphSyncDataTransfer provides diagnostics on a data transfer happening over graphsync
|
||||
type GraphSyncDataTransfer struct {
|
||||
// GraphSync request id for this transfer
|
||||
RequestID graphsync.RequestID
|
||||
// Graphsync state for this transfer
|
||||
RequestState string
|
||||
// If a channel ID is present, indicates whether this is the current graphsync request for this channel
|
||||
// (could have changed in a restart)
|
||||
IsCurrentChannelRequest bool
|
||||
// Data transfer channel ID for this transfer
|
||||
ChannelID *datatransfer.ChannelID
|
||||
// Data transfer state for this transfer
|
||||
ChannelState *DataTransferChannel
|
||||
// Diagnostic information about this request -- and unexpected inconsistencies in
|
||||
// request state
|
||||
Diagnostics []string
|
||||
}
|
||||
|
||||
// TransferDiagnostics give current information about transfers going over graphsync that may be helpful for debugging
|
||||
type TransferDiagnostics struct {
|
||||
ReceivingTransfers []*GraphSyncDataTransfer
|
||||
SendingTransfers []*GraphSyncDataTransfer
|
||||
}
|
||||
|
||||
type DataTransferChannel struct {
|
||||
TransferID datatransfer.TransferID
|
||||
Status datatransfer.Status
|
||||
|
@ -25,35 +25,35 @@ func NewAPIBlockstore(cio ChainIO) Blockstore {
|
||||
return Adapt(bs) // return an adapted blockstore.
|
||||
}
|
||||
|
||||
func (a *apiBlockstore) DeleteBlock(cid.Cid) error {
|
||||
func (a *apiBlockstore) DeleteBlock(context.Context, cid.Cid) error {
|
||||
return xerrors.New("not supported")
|
||||
}
|
||||
|
||||
func (a *apiBlockstore) Has(c cid.Cid) (bool, error) {
|
||||
return a.api.ChainHasObj(context.TODO(), c)
|
||||
func (a *apiBlockstore) Has(ctx context.Context, c cid.Cid) (bool, error) {
|
||||
return a.api.ChainHasObj(ctx, c)
|
||||
}
|
||||
|
||||
func (a *apiBlockstore) Get(c cid.Cid) (blocks.Block, error) {
|
||||
bb, err := a.api.ChainReadObj(context.TODO(), c)
|
||||
func (a *apiBlockstore) Get(ctx context.Context, c cid.Cid) (blocks.Block, error) {
|
||||
bb, err := a.api.ChainReadObj(ctx, c)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return blocks.NewBlockWithCid(bb, c)
|
||||
}
|
||||
|
||||
func (a *apiBlockstore) GetSize(c cid.Cid) (int, error) {
|
||||
bb, err := a.api.ChainReadObj(context.TODO(), c)
|
||||
func (a *apiBlockstore) GetSize(ctx context.Context, c cid.Cid) (int, error) {
|
||||
bb, err := a.api.ChainReadObj(ctx, c)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return len(bb), nil
|
||||
}
|
||||
|
||||
func (a *apiBlockstore) Put(blocks.Block) error {
|
||||
func (a *apiBlockstore) Put(context.Context, blocks.Block) error {
|
||||
return xerrors.New("not supported")
|
||||
}
|
||||
|
||||
func (a *apiBlockstore) PutMany([]blocks.Block) error {
|
||||
func (a *apiBlockstore) PutMany(context.Context, []blocks.Block) error {
|
||||
return xerrors.New("not supported")
|
||||
}
|
||||
|
||||
|
@ -525,7 +525,7 @@ func (b *Blockstore) Size() (int64, error) {
|
||||
|
||||
// View implements blockstore.Viewer, which leverages zero-copy read-only
|
||||
// access to values.
|
||||
func (b *Blockstore) View(cid cid.Cid, fn func([]byte) error) error {
|
||||
func (b *Blockstore) View(ctx context.Context, cid cid.Cid, fn func([]byte) error) error {
|
||||
if err := b.access(); err != nil {
|
||||
return err
|
||||
}
|
||||
@ -552,7 +552,7 @@ func (b *Blockstore) View(cid cid.Cid, fn func([]byte) error) error {
|
||||
}
|
||||
|
||||
// Has implements Blockstore.Has.
|
||||
func (b *Blockstore) Has(cid cid.Cid) (bool, error) {
|
||||
func (b *Blockstore) Has(ctx context.Context, cid cid.Cid) (bool, error) {
|
||||
if err := b.access(); err != nil {
|
||||
return false, err
|
||||
}
|
||||
@ -582,7 +582,7 @@ func (b *Blockstore) Has(cid cid.Cid) (bool, error) {
|
||||
}
|
||||
|
||||
// Get implements Blockstore.Get.
|
||||
func (b *Blockstore) Get(cid cid.Cid) (blocks.Block, error) {
|
||||
func (b *Blockstore) Get(ctx context.Context, cid cid.Cid) (blocks.Block, error) {
|
||||
if !cid.Defined() {
|
||||
return nil, blockstore.ErrNotFound
|
||||
}
|
||||
@ -619,7 +619,7 @@ func (b *Blockstore) Get(cid cid.Cid) (blocks.Block, error) {
|
||||
}
|
||||
|
||||
// GetSize implements Blockstore.GetSize.
|
||||
func (b *Blockstore) GetSize(cid cid.Cid) (int, error) {
|
||||
func (b *Blockstore) GetSize(ctx context.Context, cid cid.Cid) (int, error) {
|
||||
if err := b.access(); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
@ -652,7 +652,7 @@ func (b *Blockstore) GetSize(cid cid.Cid) (int, error) {
|
||||
}
|
||||
|
||||
// Put implements Blockstore.Put.
|
||||
func (b *Blockstore) Put(block blocks.Block) error {
|
||||
func (b *Blockstore) Put(ctx context.Context, block blocks.Block) error {
|
||||
if err := b.access(); err != nil {
|
||||
return err
|
||||
}
|
||||
@ -691,7 +691,7 @@ func (b *Blockstore) Put(block blocks.Block) error {
|
||||
}
|
||||
|
||||
// PutMany implements Blockstore.PutMany.
|
||||
func (b *Blockstore) PutMany(blocks []blocks.Block) error {
|
||||
func (b *Blockstore) PutMany(ctx context.Context, blocks []blocks.Block) error {
|
||||
if err := b.access(); err != nil {
|
||||
return err
|
||||
}
|
||||
@ -755,7 +755,7 @@ func (b *Blockstore) PutMany(blocks []blocks.Block) error {
|
||||
}
|
||||
|
||||
// DeleteBlock implements Blockstore.DeleteBlock.
|
||||
func (b *Blockstore) DeleteBlock(cid cid.Cid) error {
|
||||
func (b *Blockstore) DeleteBlock(ctx context.Context, cid cid.Cid) error {
|
||||
if err := b.access(); err != nil {
|
||||
return err
|
||||
}
|
||||
@ -774,7 +774,7 @@ func (b *Blockstore) DeleteBlock(cid cid.Cid) error {
|
||||
})
|
||||
}
|
||||
|
||||
func (b *Blockstore) DeleteMany(cids []cid.Cid) error {
|
||||
func (b *Blockstore) DeleteMany(ctx context.Context, cids []cid.Cid) error {
|
||||
if err := b.access(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package badgerbs
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
@ -98,6 +99,7 @@ func openBlockstore(optsSupplier func(path string) Options) func(tb testing.TB,
|
||||
}
|
||||
|
||||
func testMove(t *testing.T, optsF func(string) Options) {
|
||||
ctx := context.Background()
|
||||
basePath, err := ioutil.TempDir("", "")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@ -122,7 +124,7 @@ func testMove(t *testing.T, optsF func(string) Options) {
|
||||
// add some blocks
|
||||
for i := 0; i < 10; i++ {
|
||||
blk := blocks.NewBlock([]byte(fmt.Sprintf("some data %d", i)))
|
||||
err := db.Put(blk)
|
||||
err := db.Put(ctx, blk)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -132,7 +134,7 @@ func testMove(t *testing.T, optsF func(string) Options) {
|
||||
// delete some of them
|
||||
for i := 5; i < 10; i++ {
|
||||
c := have[i].Cid()
|
||||
err := db.DeleteBlock(c)
|
||||
err := db.DeleteBlock(ctx, c)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -145,7 +147,7 @@ func testMove(t *testing.T, optsF func(string) Options) {
|
||||
g.Go(func() error {
|
||||
for i := 10; i < 1000; i++ {
|
||||
blk := blocks.NewBlock([]byte(fmt.Sprintf("some data %d", i)))
|
||||
err := db.Put(blk)
|
||||
err := db.Put(ctx, blk)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -165,7 +167,7 @@ func testMove(t *testing.T, optsF func(string) Options) {
|
||||
// now check that we have all the blocks in have and none in the deleted lists
|
||||
checkBlocks := func() {
|
||||
for _, blk := range have {
|
||||
has, err := db.Has(blk.Cid())
|
||||
has, err := db.Has(ctx, blk.Cid())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -174,7 +176,7 @@ func testMove(t *testing.T, optsF func(string) Options) {
|
||||
t.Fatal("missing block")
|
||||
}
|
||||
|
||||
blk2, err := db.Get(blk.Cid())
|
||||
blk2, err := db.Get(ctx, blk.Cid())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -185,7 +187,7 @@ func testMove(t *testing.T, optsF func(string) Options) {
|
||||
}
|
||||
|
||||
for _, c := range deleted {
|
||||
has, err := db.Has(c)
|
||||
has, err := db.Has(ctx, c)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -44,28 +44,31 @@ func (s *Suite) RunTests(t *testing.T, prefix string) {
|
||||
}
|
||||
|
||||
func (s *Suite) TestGetWhenKeyNotPresent(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
bs, _ := s.NewBlockstore(t)
|
||||
if c, ok := bs.(io.Closer); ok {
|
||||
defer func() { require.NoError(t, c.Close()) }()
|
||||
}
|
||||
|
||||
c := cid.NewCidV0(u.Hash([]byte("stuff")))
|
||||
bl, err := bs.Get(c)
|
||||
bl, err := bs.Get(ctx, c)
|
||||
require.Nil(t, bl)
|
||||
require.Equal(t, blockstore.ErrNotFound, err)
|
||||
}
|
||||
|
||||
func (s *Suite) TestGetWhenKeyIsNil(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
bs, _ := s.NewBlockstore(t)
|
||||
if c, ok := bs.(io.Closer); ok {
|
||||
defer func() { require.NoError(t, c.Close()) }()
|
||||
}
|
||||
|
||||
_, err := bs.Get(cid.Undef)
|
||||
_, err := bs.Get(ctx, cid.Undef)
|
||||
require.Equal(t, blockstore.ErrNotFound, err)
|
||||
}
|
||||
|
||||
func (s *Suite) TestPutThenGetBlock(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
bs, _ := s.NewBlockstore(t)
|
||||
if c, ok := bs.(io.Closer); ok {
|
||||
defer func() { require.NoError(t, c.Close()) }()
|
||||
@ -73,15 +76,16 @@ func (s *Suite) TestPutThenGetBlock(t *testing.T) {
|
||||
|
||||
orig := blocks.NewBlock([]byte("some data"))
|
||||
|
||||
err := bs.Put(orig)
|
||||
err := bs.Put(ctx, orig)
|
||||
require.NoError(t, err)
|
||||
|
||||
fetched, err := bs.Get(orig.Cid())
|
||||
fetched, err := bs.Get(ctx, orig.Cid())
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, orig.RawData(), fetched.RawData())
|
||||
}
|
||||
|
||||
func (s *Suite) TestHas(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
bs, _ := s.NewBlockstore(t)
|
||||
if c, ok := bs.(io.Closer); ok {
|
||||
defer func() { require.NoError(t, c.Close()) }()
|
||||
@ -89,19 +93,20 @@ func (s *Suite) TestHas(t *testing.T) {
|
||||
|
||||
orig := blocks.NewBlock([]byte("some data"))
|
||||
|
||||
err := bs.Put(orig)
|
||||
err := bs.Put(ctx, orig)
|
||||
require.NoError(t, err)
|
||||
|
||||
ok, err := bs.Has(orig.Cid())
|
||||
ok, err := bs.Has(ctx, orig.Cid())
|
||||
require.NoError(t, err)
|
||||
require.True(t, ok)
|
||||
|
||||
ok, err = bs.Has(blocks.NewBlock([]byte("another thing")).Cid())
|
||||
ok, err = bs.Has(ctx, blocks.NewBlock([]byte("another thing")).Cid())
|
||||
require.NoError(t, err)
|
||||
require.False(t, ok)
|
||||
}
|
||||
|
||||
func (s *Suite) TestCidv0v1(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
bs, _ := s.NewBlockstore(t)
|
||||
if c, ok := bs.(io.Closer); ok {
|
||||
defer func() { require.NoError(t, c.Close()) }()
|
||||
@ -109,15 +114,17 @@ func (s *Suite) TestCidv0v1(t *testing.T) {
|
||||
|
||||
orig := blocks.NewBlock([]byte("some data"))
|
||||
|
||||
err := bs.Put(orig)
|
||||
err := bs.Put(ctx, orig)
|
||||
require.NoError(t, err)
|
||||
|
||||
fetched, err := bs.Get(cid.NewCidV1(cid.DagProtobuf, orig.Cid().Hash()))
|
||||
fetched, err := bs.Get(ctx, cid.NewCidV1(cid.DagProtobuf, orig.Cid().Hash()))
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, orig.RawData(), fetched.RawData())
|
||||
}
|
||||
|
||||
func (s *Suite) TestPutThenGetSizeBlock(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
bs, _ := s.NewBlockstore(t)
|
||||
if c, ok := bs.(io.Closer); ok {
|
||||
defer func() { require.NoError(t, c.Close()) }()
|
||||
@ -127,21 +134,21 @@ func (s *Suite) TestPutThenGetSizeBlock(t *testing.T) {
|
||||
missingBlock := blocks.NewBlock([]byte("missingBlock"))
|
||||
emptyBlock := blocks.NewBlock([]byte{})
|
||||
|
||||
err := bs.Put(block)
|
||||
err := bs.Put(ctx, block)
|
||||
require.NoError(t, err)
|
||||
|
||||
blockSize, err := bs.GetSize(block.Cid())
|
||||
blockSize, err := bs.GetSize(ctx, block.Cid())
|
||||
require.NoError(t, err)
|
||||
require.Len(t, block.RawData(), blockSize)
|
||||
|
||||
err = bs.Put(emptyBlock)
|
||||
err = bs.Put(ctx, emptyBlock)
|
||||
require.NoError(t, err)
|
||||
|
||||
emptySize, err := bs.GetSize(emptyBlock.Cid())
|
||||
emptySize, err := bs.GetSize(ctx, emptyBlock.Cid())
|
||||
require.NoError(t, err)
|
||||
require.Zero(t, emptySize)
|
||||
|
||||
missingSize, err := bs.GetSize(missingBlock.Cid())
|
||||
missingSize, err := bs.GetSize(ctx, missingBlock.Cid())
|
||||
require.Equal(t, blockstore.ErrNotFound, err)
|
||||
require.Equal(t, -1, missingSize)
|
||||
}
|
||||
@ -203,6 +210,7 @@ func (s *Suite) TestDoubleClose(t *testing.T) {
|
||||
}
|
||||
|
||||
func (s *Suite) TestReopenPutGet(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
bs, path := s.NewBlockstore(t)
|
||||
c, ok := bs.(io.Closer)
|
||||
if !ok {
|
||||
@ -210,7 +218,7 @@ func (s *Suite) TestReopenPutGet(t *testing.T) {
|
||||
}
|
||||
|
||||
orig := blocks.NewBlock([]byte("some data"))
|
||||
err := bs.Put(orig)
|
||||
err := bs.Put(ctx, orig)
|
||||
require.NoError(t, err)
|
||||
|
||||
err = c.Close()
|
||||
@ -219,7 +227,7 @@ func (s *Suite) TestReopenPutGet(t *testing.T) {
|
||||
bs, err = s.OpenBlockstore(t, path)
|
||||
require.NoError(t, err)
|
||||
|
||||
fetched, err := bs.Get(orig.Cid())
|
||||
fetched, err := bs.Get(ctx, orig.Cid())
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, orig.RawData(), fetched.RawData())
|
||||
|
||||
@ -228,6 +236,7 @@ func (s *Suite) TestReopenPutGet(t *testing.T) {
|
||||
}
|
||||
|
||||
func (s *Suite) TestPutMany(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
bs, _ := s.NewBlockstore(t)
|
||||
if c, ok := bs.(io.Closer); ok {
|
||||
defer func() { require.NoError(t, c.Close()) }()
|
||||
@ -238,15 +247,15 @@ func (s *Suite) TestPutMany(t *testing.T) {
|
||||
blocks.NewBlock([]byte("foo2")),
|
||||
blocks.NewBlock([]byte("foo3")),
|
||||
}
|
||||
err := bs.PutMany(blks)
|
||||
err := bs.PutMany(ctx, blks)
|
||||
require.NoError(t, err)
|
||||
|
||||
for _, blk := range blks {
|
||||
fetched, err := bs.Get(blk.Cid())
|
||||
fetched, err := bs.Get(ctx, blk.Cid())
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, blk.RawData(), fetched.RawData())
|
||||
|
||||
ok, err := bs.Has(blk.Cid())
|
||||
ok, err := bs.Has(ctx, blk.Cid())
|
||||
require.NoError(t, err)
|
||||
require.True(t, ok)
|
||||
}
|
||||
@ -259,6 +268,7 @@ func (s *Suite) TestPutMany(t *testing.T) {
|
||||
}
|
||||
|
||||
func (s *Suite) TestDelete(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
bs, _ := s.NewBlockstore(t)
|
||||
if c, ok := bs.(io.Closer); ok {
|
||||
defer func() { require.NoError(t, c.Close()) }()
|
||||
@ -269,10 +279,10 @@ func (s *Suite) TestDelete(t *testing.T) {
|
||||
blocks.NewBlock([]byte("foo2")),
|
||||
blocks.NewBlock([]byte("foo3")),
|
||||
}
|
||||
err := bs.PutMany(blks)
|
||||
err := bs.PutMany(ctx, blks)
|
||||
require.NoError(t, err)
|
||||
|
||||
err = bs.DeleteBlock(blks[1].Cid())
|
||||
err = bs.DeleteBlock(ctx, blks[1].Cid())
|
||||
require.NoError(t, err)
|
||||
|
||||
ch, err := bs.AllKeysChan(context.Background())
|
||||
@ -285,17 +295,17 @@ func (s *Suite) TestDelete(t *testing.T) {
|
||||
cid.NewCidV1(cid.Raw, blks[2].Cid().Hash()),
|
||||
})
|
||||
|
||||
has, err := bs.Has(blks[1].Cid())
|
||||
has, err := bs.Has(ctx, blks[1].Cid())
|
||||
require.NoError(t, err)
|
||||
require.False(t, has)
|
||||
|
||||
}
|
||||
|
||||
func insertBlocks(t *testing.T, bs blockstore.BasicBlockstore, count int) []cid.Cid {
|
||||
ctx := context.Background()
|
||||
keys := make([]cid.Cid, count)
|
||||
for i := 0; i < count; i++ {
|
||||
block := blocks.NewBlock([]byte(fmt.Sprintf("some data %d", i)))
|
||||
err := bs.Put(block)
|
||||
err := bs.Put(ctx, block)
|
||||
require.NoError(t, err)
|
||||
// NewBlock assigns a CIDv0; we convert it to CIDv1 because that's what
|
||||
// the store returns.
|
||||
|
@ -1,6 +1,8 @@
|
||||
package blockstore
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
cid "github.com/ipfs/go-cid"
|
||||
ds "github.com/ipfs/go-datastore"
|
||||
logging "github.com/ipfs/go-log/v2"
|
||||
@ -27,7 +29,7 @@ type BasicBlockstore = blockstore.Blockstore
|
||||
type Viewer = blockstore.Viewer
|
||||
|
||||
type BatchDeleter interface {
|
||||
DeleteMany(cids []cid.Cid) error
|
||||
DeleteMany(ctx context.Context, cids []cid.Cid) error
|
||||
}
|
||||
|
||||
// BlockstoreIterator is a trait for efficient iteration
|
||||
@ -93,17 +95,17 @@ type adaptedBlockstore struct {
|
||||
|
||||
var _ Blockstore = (*adaptedBlockstore)(nil)
|
||||
|
||||
func (a *adaptedBlockstore) View(cid cid.Cid, callback func([]byte) error) error {
|
||||
blk, err := a.Get(cid)
|
||||
func (a *adaptedBlockstore) View(ctx context.Context, cid cid.Cid, callback func([]byte) error) error {
|
||||
blk, err := a.Get(ctx, cid)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return callback(blk.RawData())
|
||||
}
|
||||
|
||||
func (a *adaptedBlockstore) DeleteMany(cids []cid.Cid) error {
|
||||
func (a *adaptedBlockstore) DeleteMany(ctx context.Context, cids []cid.Cid) error {
|
||||
for _, cid := range cids {
|
||||
err := a.DeleteBlock(cid)
|
||||
err := a.DeleteBlock(ctx, cid)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -88,34 +88,34 @@ func (bs *BufferedBlockstore) AllKeysChan(ctx context.Context) (<-chan cid.Cid,
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (bs *BufferedBlockstore) DeleteBlock(c cid.Cid) error {
|
||||
if err := bs.read.DeleteBlock(c); err != nil {
|
||||
func (bs *BufferedBlockstore) DeleteBlock(ctx context.Context, c cid.Cid) error {
|
||||
if err := bs.read.DeleteBlock(ctx, c); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return bs.write.DeleteBlock(c)
|
||||
return bs.write.DeleteBlock(ctx, c)
|
||||
}
|
||||
|
||||
func (bs *BufferedBlockstore) DeleteMany(cids []cid.Cid) error {
|
||||
if err := bs.read.DeleteMany(cids); err != nil {
|
||||
func (bs *BufferedBlockstore) DeleteMany(ctx context.Context, cids []cid.Cid) error {
|
||||
if err := bs.read.DeleteMany(ctx, cids); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return bs.write.DeleteMany(cids)
|
||||
return bs.write.DeleteMany(ctx, cids)
|
||||
}
|
||||
|
||||
func (bs *BufferedBlockstore) View(c cid.Cid, callback func([]byte) error) error {
|
||||
func (bs *BufferedBlockstore) View(ctx context.Context, c cid.Cid, callback func([]byte) error) error {
|
||||
// both stores are viewable.
|
||||
if err := bs.write.View(c, callback); err == ErrNotFound {
|
||||
if err := bs.write.View(ctx, c, callback); err == ErrNotFound {
|
||||
// not found in write blockstore; fall through.
|
||||
} else {
|
||||
return err // propagate errors, or nil, i.e. found.
|
||||
}
|
||||
return bs.read.View(c, callback)
|
||||
return bs.read.View(ctx, c, callback)
|
||||
}
|
||||
|
||||
func (bs *BufferedBlockstore) Get(c cid.Cid) (block.Block, error) {
|
||||
if out, err := bs.write.Get(c); err != nil {
|
||||
func (bs *BufferedBlockstore) Get(ctx context.Context, c cid.Cid) (block.Block, error) {
|
||||
if out, err := bs.write.Get(ctx, c); err != nil {
|
||||
if err != ErrNotFound {
|
||||
return nil, err
|
||||
}
|
||||
@ -123,20 +123,20 @@ func (bs *BufferedBlockstore) Get(c cid.Cid) (block.Block, error) {
|
||||
return out, nil
|
||||
}
|
||||
|
||||
return bs.read.Get(c)
|
||||
return bs.read.Get(ctx, c)
|
||||
}
|
||||
|
||||
func (bs *BufferedBlockstore) GetSize(c cid.Cid) (int, error) {
|
||||
s, err := bs.read.GetSize(c)
|
||||
func (bs *BufferedBlockstore) GetSize(ctx context.Context, c cid.Cid) (int, error) {
|
||||
s, err := bs.read.GetSize(ctx, c)
|
||||
if err == ErrNotFound || s == 0 {
|
||||
return bs.write.GetSize(c)
|
||||
return bs.write.GetSize(ctx, c)
|
||||
}
|
||||
|
||||
return s, err
|
||||
}
|
||||
|
||||
func (bs *BufferedBlockstore) Put(blk block.Block) error {
|
||||
has, err := bs.read.Has(blk.Cid()) // TODO: consider dropping this check
|
||||
func (bs *BufferedBlockstore) Put(ctx context.Context, blk block.Block) error {
|
||||
has, err := bs.read.Has(ctx, blk.Cid()) // TODO: consider dropping this check
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -145,11 +145,11 @@ func (bs *BufferedBlockstore) Put(blk block.Block) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
return bs.write.Put(blk)
|
||||
return bs.write.Put(ctx, blk)
|
||||
}
|
||||
|
||||
func (bs *BufferedBlockstore) Has(c cid.Cid) (bool, error) {
|
||||
has, err := bs.write.Has(c)
|
||||
func (bs *BufferedBlockstore) Has(ctx context.Context, c cid.Cid) (bool, error) {
|
||||
has, err := bs.write.Has(ctx, c)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
@ -157,7 +157,7 @@ func (bs *BufferedBlockstore) Has(c cid.Cid) (bool, error) {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
return bs.read.Has(c)
|
||||
return bs.read.Has(ctx, c)
|
||||
}
|
||||
|
||||
func (bs *BufferedBlockstore) HashOnRead(hor bool) {
|
||||
@ -165,8 +165,8 @@ func (bs *BufferedBlockstore) HashOnRead(hor bool) {
|
||||
bs.write.HashOnRead(hor)
|
||||
}
|
||||
|
||||
func (bs *BufferedBlockstore) PutMany(blks []block.Block) error {
|
||||
return bs.write.PutMany(blks)
|
||||
func (bs *BufferedBlockstore) PutMany(ctx context.Context, blks []block.Block) error {
|
||||
return bs.write.PutMany(ctx, blks)
|
||||
}
|
||||
|
||||
func (bs *BufferedBlockstore) Read() Blockstore {
|
||||
|
@ -18,39 +18,39 @@ func NewDiscardStore(bs Blockstore) Blockstore {
|
||||
return &discardstore{bs: bs}
|
||||
}
|
||||
|
||||
func (b *discardstore) Has(cid cid.Cid) (bool, error) {
|
||||
return b.bs.Has(cid)
|
||||
func (b *discardstore) Has(ctx context.Context, cid cid.Cid) (bool, error) {
|
||||
return b.bs.Has(ctx, cid)
|
||||
}
|
||||
|
||||
func (b *discardstore) HashOnRead(hor bool) {
|
||||
b.bs.HashOnRead(hor)
|
||||
}
|
||||
|
||||
func (b *discardstore) Get(cid cid.Cid) (blocks.Block, error) {
|
||||
return b.bs.Get(cid)
|
||||
func (b *discardstore) Get(ctx context.Context, cid cid.Cid) (blocks.Block, error) {
|
||||
return b.bs.Get(ctx, cid)
|
||||
}
|
||||
|
||||
func (b *discardstore) GetSize(cid cid.Cid) (int, error) {
|
||||
return b.bs.GetSize(cid)
|
||||
func (b *discardstore) GetSize(ctx context.Context, cid cid.Cid) (int, error) {
|
||||
return b.bs.GetSize(ctx, cid)
|
||||
}
|
||||
|
||||
func (b *discardstore) View(cid cid.Cid, f func([]byte) error) error {
|
||||
return b.bs.View(cid, f)
|
||||
func (b *discardstore) View(ctx context.Context, cid cid.Cid, f func([]byte) error) error {
|
||||
return b.bs.View(ctx, cid, f)
|
||||
}
|
||||
|
||||
func (b *discardstore) Put(blk blocks.Block) error {
|
||||
func (b *discardstore) Put(ctx context.Context, blk blocks.Block) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b *discardstore) PutMany(blks []blocks.Block) error {
|
||||
func (b *discardstore) PutMany(ctx context.Context, blks []blocks.Block) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b *discardstore) DeleteBlock(cid cid.Cid) error {
|
||||
func (b *discardstore) DeleteBlock(ctx context.Context, cid cid.Cid) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b *discardstore) DeleteMany(cids []cid.Cid) error {
|
||||
func (b *discardstore) DeleteMany(ctx context.Context, cids []cid.Cid) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -71,14 +71,14 @@ func (fbs *FallbackStore) getFallback(c cid.Cid) (blocks.Block, error) {
|
||||
// chain bitswap puts blocks in temp blockstore which is cleaned up
|
||||
// every few min (to drop any messages we fetched but don't want)
|
||||
// in this case we want to keep this block around
|
||||
if err := fbs.Put(b); err != nil {
|
||||
if err := fbs.Put(ctx, b); err != nil {
|
||||
return nil, xerrors.Errorf("persisting fallback-fetched block: %w", err)
|
||||
}
|
||||
return b, nil
|
||||
}
|
||||
|
||||
func (fbs *FallbackStore) Get(c cid.Cid) (blocks.Block, error) {
|
||||
b, err := fbs.Blockstore.Get(c)
|
||||
func (fbs *FallbackStore) Get(ctx context.Context, c cid.Cid) (blocks.Block, error) {
|
||||
b, err := fbs.Blockstore.Get(ctx, c)
|
||||
switch err {
|
||||
case nil:
|
||||
return b, nil
|
||||
@ -89,8 +89,8 @@ func (fbs *FallbackStore) Get(c cid.Cid) (blocks.Block, error) {
|
||||
}
|
||||
}
|
||||
|
||||
func (fbs *FallbackStore) GetSize(c cid.Cid) (int, error) {
|
||||
sz, err := fbs.Blockstore.GetSize(c)
|
||||
func (fbs *FallbackStore) GetSize(ctx context.Context, c cid.Cid) (int, error) {
|
||||
sz, err := fbs.Blockstore.GetSize(ctx, c)
|
||||
switch err {
|
||||
case nil:
|
||||
return sz, nil
|
||||
|
@ -38,7 +38,7 @@ func decodeCid(cid cid.Cid) (inline bool, data []byte, err error) {
|
||||
return false, nil, err
|
||||
}
|
||||
|
||||
func (b *idstore) Has(cid cid.Cid) (bool, error) {
|
||||
func (b *idstore) Has(ctx context.Context, cid cid.Cid) (bool, error) {
|
||||
inline, _, err := decodeCid(cid)
|
||||
if err != nil {
|
||||
return false, xerrors.Errorf("error decoding Cid: %w", err)
|
||||
@ -48,10 +48,10 @@ func (b *idstore) Has(cid cid.Cid) (bool, error) {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
return b.bs.Has(cid)
|
||||
return b.bs.Has(ctx, cid)
|
||||
}
|
||||
|
||||
func (b *idstore) Get(cid cid.Cid) (blocks.Block, error) {
|
||||
func (b *idstore) Get(ctx context.Context, cid cid.Cid) (blocks.Block, error) {
|
||||
inline, data, err := decodeCid(cid)
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("error decoding Cid: %w", err)
|
||||
@ -61,10 +61,10 @@ func (b *idstore) Get(cid cid.Cid) (blocks.Block, error) {
|
||||
return blocks.NewBlockWithCid(data, cid)
|
||||
}
|
||||
|
||||
return b.bs.Get(cid)
|
||||
return b.bs.Get(ctx, cid)
|
||||
}
|
||||
|
||||
func (b *idstore) GetSize(cid cid.Cid) (int, error) {
|
||||
func (b *idstore) GetSize(ctx context.Context, cid cid.Cid) (int, error) {
|
||||
inline, data, err := decodeCid(cid)
|
||||
if err != nil {
|
||||
return 0, xerrors.Errorf("error decoding Cid: %w", err)
|
||||
@ -74,10 +74,10 @@ func (b *idstore) GetSize(cid cid.Cid) (int, error) {
|
||||
return len(data), err
|
||||
}
|
||||
|
||||
return b.bs.GetSize(cid)
|
||||
return b.bs.GetSize(ctx, cid)
|
||||
}
|
||||
|
||||
func (b *idstore) View(cid cid.Cid, cb func([]byte) error) error {
|
||||
func (b *idstore) View(ctx context.Context, cid cid.Cid, cb func([]byte) error) error {
|
||||
inline, data, err := decodeCid(cid)
|
||||
if err != nil {
|
||||
return xerrors.Errorf("error decoding Cid: %w", err)
|
||||
@ -87,10 +87,10 @@ func (b *idstore) View(cid cid.Cid, cb func([]byte) error) error {
|
||||
return cb(data)
|
||||
}
|
||||
|
||||
return b.bs.View(cid, cb)
|
||||
return b.bs.View(ctx, cid, cb)
|
||||
}
|
||||
|
||||
func (b *idstore) Put(blk blocks.Block) error {
|
||||
func (b *idstore) Put(ctx context.Context, blk blocks.Block) error {
|
||||
inline, _, err := decodeCid(blk.Cid())
|
||||
if err != nil {
|
||||
return xerrors.Errorf("error decoding Cid: %w", err)
|
||||
@ -100,10 +100,10 @@ func (b *idstore) Put(blk blocks.Block) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
return b.bs.Put(blk)
|
||||
return b.bs.Put(ctx, blk)
|
||||
}
|
||||
|
||||
func (b *idstore) PutMany(blks []blocks.Block) error {
|
||||
func (b *idstore) PutMany(ctx context.Context, blks []blocks.Block) error {
|
||||
toPut := make([]blocks.Block, 0, len(blks))
|
||||
for _, blk := range blks {
|
||||
inline, _, err := decodeCid(blk.Cid())
|
||||
@ -118,13 +118,13 @@ func (b *idstore) PutMany(blks []blocks.Block) error {
|
||||
}
|
||||
|
||||
if len(toPut) > 0 {
|
||||
return b.bs.PutMany(toPut)
|
||||
return b.bs.PutMany(ctx, toPut)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b *idstore) DeleteBlock(cid cid.Cid) error {
|
||||
func (b *idstore) DeleteBlock(ctx context.Context, cid cid.Cid) error {
|
||||
inline, _, err := decodeCid(cid)
|
||||
if err != nil {
|
||||
return xerrors.Errorf("error decoding Cid: %w", err)
|
||||
@ -134,10 +134,10 @@ func (b *idstore) DeleteBlock(cid cid.Cid) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
return b.bs.DeleteBlock(cid)
|
||||
return b.bs.DeleteBlock(ctx, cid)
|
||||
}
|
||||
|
||||
func (b *idstore) DeleteMany(cids []cid.Cid) error {
|
||||
func (b *idstore) DeleteMany(ctx context.Context, cids []cid.Cid) error {
|
||||
toDelete := make([]cid.Cid, 0, len(cids))
|
||||
for _, cid := range cids {
|
||||
inline, _, err := decodeCid(cid)
|
||||
@ -152,7 +152,7 @@ func (b *idstore) DeleteMany(cids []cid.Cid) error {
|
||||
}
|
||||
|
||||
if len(toDelete) > 0 {
|
||||
return b.bs.DeleteMany(toDelete)
|
||||
return b.bs.DeleteMany(ctx, toDelete)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -79,12 +79,12 @@ func NewRemoteIPFSBlockstore(ctx context.Context, maddr multiaddr.Multiaddr, onl
|
||||
return Adapt(bs), nil
|
||||
}
|
||||
|
||||
func (i *IPFSBlockstore) DeleteBlock(cid cid.Cid) error {
|
||||
func (i *IPFSBlockstore) DeleteBlock(ctx context.Context, cid cid.Cid) error {
|
||||
return xerrors.Errorf("not supported")
|
||||
}
|
||||
|
||||
func (i *IPFSBlockstore) Has(cid cid.Cid) (bool, error) {
|
||||
_, err := i.offlineAPI.Block().Stat(i.ctx, path.IpldPath(cid))
|
||||
func (i *IPFSBlockstore) Has(ctx context.Context, cid cid.Cid) (bool, error) {
|
||||
_, err := i.offlineAPI.Block().Stat(ctx, path.IpldPath(cid))
|
||||
if err != nil {
|
||||
// The underlying client is running in Offline mode.
|
||||
// Stat() will fail with an err if the block isn't in the
|
||||
@ -99,8 +99,8 @@ func (i *IPFSBlockstore) Has(cid cid.Cid) (bool, error) {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func (i *IPFSBlockstore) Get(cid cid.Cid) (blocks.Block, error) {
|
||||
rd, err := i.api.Block().Get(i.ctx, path.IpldPath(cid))
|
||||
func (i *IPFSBlockstore) Get(ctx context.Context, cid cid.Cid) (blocks.Block, error) {
|
||||
rd, err := i.api.Block().Get(ctx, path.IpldPath(cid))
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("getting ipfs block: %w", err)
|
||||
}
|
||||
@ -113,8 +113,8 @@ func (i *IPFSBlockstore) Get(cid cid.Cid) (blocks.Block, error) {
|
||||
return blocks.NewBlockWithCid(data, cid)
|
||||
}
|
||||
|
||||
func (i *IPFSBlockstore) GetSize(cid cid.Cid) (int, error) {
|
||||
st, err := i.api.Block().Stat(i.ctx, path.IpldPath(cid))
|
||||
func (i *IPFSBlockstore) GetSize(ctx context.Context, cid cid.Cid) (int, error) {
|
||||
st, err := i.api.Block().Stat(ctx, path.IpldPath(cid))
|
||||
if err != nil {
|
||||
return 0, xerrors.Errorf("getting ipfs block: %w", err)
|
||||
}
|
||||
@ -122,23 +122,23 @@ func (i *IPFSBlockstore) GetSize(cid cid.Cid) (int, error) {
|
||||
return st.Size(), nil
|
||||
}
|
||||
|
||||
func (i *IPFSBlockstore) Put(block blocks.Block) error {
|
||||
func (i *IPFSBlockstore) Put(ctx context.Context, block blocks.Block) error {
|
||||
mhd, err := multihash.Decode(block.Cid().Hash())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = i.api.Block().Put(i.ctx, bytes.NewReader(block.RawData()),
|
||||
_, err = i.api.Block().Put(ctx, bytes.NewReader(block.RawData()),
|
||||
options.Block.Hash(mhd.Code, mhd.Length),
|
||||
options.Block.Format(cid.CodecToStr[block.Cid().Type()]))
|
||||
return err
|
||||
}
|
||||
|
||||
func (i *IPFSBlockstore) PutMany(blocks []blocks.Block) error {
|
||||
func (i *IPFSBlockstore) PutMany(ctx context.Context, blocks []blocks.Block) error {
|
||||
// TODO: could be done in parallel
|
||||
|
||||
for _, block := range blocks {
|
||||
if err := i.Put(block); err != nil {
|
||||
if err := i.Put(ctx, block); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
@ -15,24 +15,24 @@ func NewMemory() MemBlockstore {
|
||||
// MemBlockstore is a terminal blockstore that keeps blocks in memory.
|
||||
type MemBlockstore map[cid.Cid]blocks.Block
|
||||
|
||||
func (m MemBlockstore) DeleteBlock(k cid.Cid) error {
|
||||
func (m MemBlockstore) DeleteBlock(ctx context.Context, k cid.Cid) error {
|
||||
delete(m, k)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m MemBlockstore) DeleteMany(ks []cid.Cid) error {
|
||||
func (m MemBlockstore) DeleteMany(ctx context.Context, ks []cid.Cid) error {
|
||||
for _, k := range ks {
|
||||
delete(m, k)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m MemBlockstore) Has(k cid.Cid) (bool, error) {
|
||||
func (m MemBlockstore) Has(ctx context.Context, k cid.Cid) (bool, error) {
|
||||
_, ok := m[k]
|
||||
return ok, nil
|
||||
}
|
||||
|
||||
func (m MemBlockstore) View(k cid.Cid, callback func([]byte) error) error {
|
||||
func (m MemBlockstore) View(ctx context.Context, k cid.Cid, callback func([]byte) error) error {
|
||||
b, ok := m[k]
|
||||
if !ok {
|
||||
return ErrNotFound
|
||||
@ -40,7 +40,7 @@ func (m MemBlockstore) View(k cid.Cid, callback func([]byte) error) error {
|
||||
return callback(b.RawData())
|
||||
}
|
||||
|
||||
func (m MemBlockstore) Get(k cid.Cid) (blocks.Block, error) {
|
||||
func (m MemBlockstore) Get(ctx context.Context, k cid.Cid) (blocks.Block, error) {
|
||||
b, ok := m[k]
|
||||
if !ok {
|
||||
return nil, ErrNotFound
|
||||
@ -49,7 +49,7 @@ func (m MemBlockstore) Get(k cid.Cid) (blocks.Block, error) {
|
||||
}
|
||||
|
||||
// GetSize returns the CIDs mapped BlockSize
|
||||
func (m MemBlockstore) GetSize(k cid.Cid) (int, error) {
|
||||
func (m MemBlockstore) GetSize(ctx context.Context, k cid.Cid) (int, error) {
|
||||
b, ok := m[k]
|
||||
if !ok {
|
||||
return 0, ErrNotFound
|
||||
@ -58,7 +58,7 @@ func (m MemBlockstore) GetSize(k cid.Cid) (int, error) {
|
||||
}
|
||||
|
||||
// Put puts a given block to the underlying datastore
|
||||
func (m MemBlockstore) Put(b blocks.Block) error {
|
||||
func (m MemBlockstore) Put(ctx context.Context, b blocks.Block) error {
|
||||
// Convert to a basic block for safety, but try to reuse the existing
|
||||
// block if it's already a basic block.
|
||||
k := b.Cid()
|
||||
@ -76,9 +76,9 @@ func (m MemBlockstore) Put(b blocks.Block) error {
|
||||
|
||||
// PutMany puts a slice of blocks at the same time using batching
|
||||
// capabilities of the underlying datastore whenever possible.
|
||||
func (m MemBlockstore) PutMany(bs []blocks.Block) error {
|
||||
func (m MemBlockstore) PutMany(ctx context.Context, bs []blocks.Block) error {
|
||||
for _, b := range bs {
|
||||
_ = m.Put(b) // can't fail
|
||||
_ = m.Put(ctx, b) // can't fail
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -216,17 +216,17 @@ func Open(path string, ds dstore.Datastore, hot, cold bstore.Blockstore, cfg *Co
|
||||
}
|
||||
|
||||
// Blockstore interface
|
||||
func (s *SplitStore) DeleteBlock(_ cid.Cid) error {
|
||||
func (s *SplitStore) DeleteBlock(_ context.Context, _ cid.Cid) error {
|
||||
// afaict we don't seem to be using this method, so it's not implemented
|
||||
return errors.New("DeleteBlock not implemented on SplitStore; don't do this Luke!") //nolint
|
||||
}
|
||||
|
||||
func (s *SplitStore) DeleteMany(_ []cid.Cid) error {
|
||||
func (s *SplitStore) DeleteMany(_ context.Context, _ []cid.Cid) error {
|
||||
// afaict we don't seem to be using this method, so it's not implemented
|
||||
return errors.New("DeleteMany not implemented on SplitStore; don't do this Luke!") //nolint
|
||||
}
|
||||
|
||||
func (s *SplitStore) Has(cid cid.Cid) (bool, error) {
|
||||
func (s *SplitStore) Has(ctx context.Context, cid cid.Cid) (bool, error) {
|
||||
if isIdentiyCid(cid) {
|
||||
return true, nil
|
||||
}
|
||||
@ -234,7 +234,7 @@ func (s *SplitStore) Has(cid cid.Cid) (bool, error) {
|
||||
s.txnLk.RLock()
|
||||
defer s.txnLk.RUnlock()
|
||||
|
||||
has, err := s.hot.Has(cid)
|
||||
has, err := s.hot.Has(ctx, cid)
|
||||
|
||||
if err != nil {
|
||||
return has, err
|
||||
@ -245,10 +245,10 @@ func (s *SplitStore) Has(cid cid.Cid) (bool, error) {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
return s.cold.Has(cid)
|
||||
return s.cold.Has(ctx, cid)
|
||||
}
|
||||
|
||||
func (s *SplitStore) Get(cid cid.Cid) (blocks.Block, error) {
|
||||
func (s *SplitStore) Get(ctx context.Context, cid cid.Cid) (blocks.Block, error) {
|
||||
if isIdentiyCid(cid) {
|
||||
data, err := decodeIdentityCid(cid)
|
||||
if err != nil {
|
||||
@ -261,7 +261,7 @@ func (s *SplitStore) Get(cid cid.Cid) (blocks.Block, error) {
|
||||
s.txnLk.RLock()
|
||||
defer s.txnLk.RUnlock()
|
||||
|
||||
blk, err := s.hot.Get(cid)
|
||||
blk, err := s.hot.Get(ctx, cid)
|
||||
|
||||
switch err {
|
||||
case nil:
|
||||
@ -273,7 +273,7 @@ func (s *SplitStore) Get(cid cid.Cid) (blocks.Block, error) {
|
||||
s.debug.LogReadMiss(cid)
|
||||
}
|
||||
|
||||
blk, err = s.cold.Get(cid)
|
||||
blk, err = s.cold.Get(ctx, cid)
|
||||
if err == nil {
|
||||
stats.Record(s.ctx, metrics.SplitstoreMiss.M(1))
|
||||
|
||||
@ -285,7 +285,7 @@ func (s *SplitStore) Get(cid cid.Cid) (blocks.Block, error) {
|
||||
}
|
||||
}
|
||||
|
||||
func (s *SplitStore) GetSize(cid cid.Cid) (int, error) {
|
||||
func (s *SplitStore) GetSize(ctx context.Context, cid cid.Cid) (int, error) {
|
||||
if isIdentiyCid(cid) {
|
||||
data, err := decodeIdentityCid(cid)
|
||||
if err != nil {
|
||||
@ -298,7 +298,7 @@ func (s *SplitStore) GetSize(cid cid.Cid) (int, error) {
|
||||
s.txnLk.RLock()
|
||||
defer s.txnLk.RUnlock()
|
||||
|
||||
size, err := s.hot.GetSize(cid)
|
||||
size, err := s.hot.GetSize(ctx, cid)
|
||||
|
||||
switch err {
|
||||
case nil:
|
||||
@ -310,7 +310,7 @@ func (s *SplitStore) GetSize(cid cid.Cid) (int, error) {
|
||||
s.debug.LogReadMiss(cid)
|
||||
}
|
||||
|
||||
size, err = s.cold.GetSize(cid)
|
||||
size, err = s.cold.GetSize(ctx, cid)
|
||||
if err == nil {
|
||||
stats.Record(s.ctx, metrics.SplitstoreMiss.M(1))
|
||||
}
|
||||
@ -321,7 +321,7 @@ func (s *SplitStore) GetSize(cid cid.Cid) (int, error) {
|
||||
}
|
||||
}
|
||||
|
||||
func (s *SplitStore) Put(blk blocks.Block) error {
|
||||
func (s *SplitStore) Put(ctx context.Context, blk blocks.Block) error {
|
||||
if isIdentiyCid(blk.Cid()) {
|
||||
return nil
|
||||
}
|
||||
@ -329,7 +329,7 @@ func (s *SplitStore) Put(blk blocks.Block) error {
|
||||
s.txnLk.RLock()
|
||||
defer s.txnLk.RUnlock()
|
||||
|
||||
err := s.hot.Put(blk)
|
||||
err := s.hot.Put(ctx, blk)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -340,7 +340,7 @@ func (s *SplitStore) Put(blk blocks.Block) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *SplitStore) PutMany(blks []blocks.Block) error {
|
||||
func (s *SplitStore) PutMany(ctx context.Context, blks []blocks.Block) error {
|
||||
// filter identites
|
||||
idcids := 0
|
||||
for _, blk := range blks {
|
||||
@ -374,7 +374,7 @@ func (s *SplitStore) PutMany(blks []blocks.Block) error {
|
||||
s.txnLk.RLock()
|
||||
defer s.txnLk.RUnlock()
|
||||
|
||||
err := s.hot.PutMany(blks)
|
||||
err := s.hot.PutMany(ctx, blks)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -430,7 +430,7 @@ func (s *SplitStore) HashOnRead(enabled bool) {
|
||||
s.cold.HashOnRead(enabled)
|
||||
}
|
||||
|
||||
func (s *SplitStore) View(cid cid.Cid, cb func([]byte) error) error {
|
||||
func (s *SplitStore) View(ctx context.Context, cid cid.Cid, cb func([]byte) error) error {
|
||||
if isIdentiyCid(cid) {
|
||||
data, err := decodeIdentityCid(cid)
|
||||
if err != nil {
|
||||
@ -451,14 +451,14 @@ func (s *SplitStore) View(cid cid.Cid, cb func([]byte) error) error {
|
||||
s.protectView(cid)
|
||||
defer s.viewDone()
|
||||
|
||||
err := s.hot.View(cid, cb)
|
||||
err := s.hot.View(ctx, cid, cb)
|
||||
switch err {
|
||||
case bstore.ErrNotFound:
|
||||
if s.isWarm() {
|
||||
s.debug.LogReadMiss(cid)
|
||||
}
|
||||
|
||||
err = s.cold.View(cid, cb)
|
||||
err = s.cold.View(ctx, cid, cb)
|
||||
if err == nil {
|
||||
stats.Record(s.ctx, metrics.SplitstoreMiss.M(1))
|
||||
}
|
||||
@ -502,7 +502,7 @@ func (s *SplitStore) Start(chain ChainAccessor, us stmgr.UpgradeSchedule) error
|
||||
|
||||
// load base epoch from metadata ds
|
||||
// if none, then use current epoch because it's a fresh start
|
||||
bs, err := s.ds.Get(baseEpochKey)
|
||||
bs, err := s.ds.Get(s.ctx, baseEpochKey)
|
||||
switch err {
|
||||
case nil:
|
||||
s.baseEpoch = bytesToEpoch(bs)
|
||||
@ -523,7 +523,7 @@ func (s *SplitStore) Start(chain ChainAccessor, us stmgr.UpgradeSchedule) error
|
||||
}
|
||||
|
||||
// load warmup epoch from metadata ds
|
||||
bs, err = s.ds.Get(warmupEpochKey)
|
||||
bs, err = s.ds.Get(s.ctx, warmupEpochKey)
|
||||
switch err {
|
||||
case nil:
|
||||
s.warmupEpoch = bytesToEpoch(bs)
|
||||
@ -536,7 +536,7 @@ func (s *SplitStore) Start(chain ChainAccessor, us stmgr.UpgradeSchedule) error
|
||||
}
|
||||
|
||||
// load markSetSize from metadata ds to provide a size hint for marksets
|
||||
bs, err = s.ds.Get(markSetSizeKey)
|
||||
bs, err = s.ds.Get(s.ctx, markSetSizeKey)
|
||||
switch err {
|
||||
case nil:
|
||||
s.markSetSize = bytesToInt64(bs)
|
||||
@ -547,7 +547,7 @@ func (s *SplitStore) Start(chain ChainAccessor, us stmgr.UpgradeSchedule) error
|
||||
}
|
||||
|
||||
// load compactionIndex from metadata ds to provide a hint as to when to perform moving gc
|
||||
bs, err = s.ds.Get(compactionIndexKey)
|
||||
bs, err = s.ds.Get(s.ctx, compactionIndexKey)
|
||||
switch err {
|
||||
case nil:
|
||||
s.compactionIndex = bytesToInt64(bs)
|
||||
@ -609,5 +609,5 @@ func (s *SplitStore) checkClosing() error {
|
||||
|
||||
func (s *SplitStore) setBaseEpoch(epoch abi.ChainEpoch) error {
|
||||
s.baseEpoch = epoch
|
||||
return s.ds.Put(baseEpochKey, epochToBytes(epoch))
|
||||
return s.ds.Put(s.ctx, baseEpochKey, epochToBytes(epoch))
|
||||
}
|
||||
|
@ -96,7 +96,7 @@ func (s *SplitStore) doCheck(curTs *types.TipSet) error {
|
||||
return errStopWalk
|
||||
}
|
||||
|
||||
has, err := s.hot.Has(c)
|
||||
has, err := s.hot.Has(s.ctx, c)
|
||||
if err != nil {
|
||||
return xerrors.Errorf("error checking hotstore: %w", err)
|
||||
}
|
||||
@ -105,7 +105,7 @@ func (s *SplitStore) doCheck(curTs *types.TipSet) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
has, err = s.cold.Has(c)
|
||||
has, err = s.cold.Has(s.ctx, c)
|
||||
if err != nil {
|
||||
return xerrors.Errorf("error checking coldstore: %w", err)
|
||||
}
|
||||
|
@ -577,13 +577,13 @@ func (s *SplitStore) doCompact(curTs *types.TipSet) error {
|
||||
return xerrors.Errorf("error saving base epoch: %w", err)
|
||||
}
|
||||
|
||||
err = s.ds.Put(markSetSizeKey, int64ToBytes(s.markSetSize))
|
||||
err = s.ds.Put(s.ctx, markSetSizeKey, int64ToBytes(s.markSetSize))
|
||||
if err != nil {
|
||||
return xerrors.Errorf("error saving mark set size: %w", err)
|
||||
}
|
||||
|
||||
s.compactionIndex++
|
||||
err = s.ds.Put(compactionIndexKey, int64ToBytes(s.compactionIndex))
|
||||
err = s.ds.Put(s.ctx, compactionIndexKey, int64ToBytes(s.compactionIndex))
|
||||
if err != nil {
|
||||
return xerrors.Errorf("error saving compaction index: %w", err)
|
||||
}
|
||||
@ -835,10 +835,10 @@ func (s *SplitStore) view(c cid.Cid, cb func([]byte) error) error {
|
||||
return cb(data)
|
||||
}
|
||||
|
||||
err := s.hot.View(c, cb)
|
||||
err := s.hot.View(s.ctx, c, cb)
|
||||
switch err {
|
||||
case bstore.ErrNotFound:
|
||||
return s.cold.View(c, cb)
|
||||
return s.cold.View(s.ctx, c, cb)
|
||||
|
||||
default:
|
||||
return err
|
||||
@ -850,13 +850,13 @@ func (s *SplitStore) has(c cid.Cid) (bool, error) {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
has, err := s.hot.Has(c)
|
||||
has, err := s.hot.Has(s.ctx, c)
|
||||
|
||||
if has || err != nil {
|
||||
return has, err
|
||||
}
|
||||
|
||||
return s.cold.Has(c)
|
||||
return s.cold.Has(s.ctx, c)
|
||||
}
|
||||
|
||||
func (s *SplitStore) moveColdBlocks(cold []cid.Cid) error {
|
||||
@ -867,7 +867,7 @@ func (s *SplitStore) moveColdBlocks(cold []cid.Cid) error {
|
||||
return err
|
||||
}
|
||||
|
||||
blk, err := s.hot.Get(c)
|
||||
blk, err := s.hot.Get(s.ctx, c)
|
||||
if err != nil {
|
||||
if err == bstore.ErrNotFound {
|
||||
log.Warnf("hotstore missing block %s", c)
|
||||
@ -879,7 +879,7 @@ func (s *SplitStore) moveColdBlocks(cold []cid.Cid) error {
|
||||
|
||||
batch = append(batch, blk)
|
||||
if len(batch) == batchSize {
|
||||
err = s.cold.PutMany(batch)
|
||||
err = s.cold.PutMany(s.ctx, batch)
|
||||
if err != nil {
|
||||
return xerrors.Errorf("error putting batch to coldstore: %w", err)
|
||||
}
|
||||
@ -888,7 +888,7 @@ func (s *SplitStore) moveColdBlocks(cold []cid.Cid) error {
|
||||
}
|
||||
|
||||
if len(batch) > 0 {
|
||||
err := s.cold.PutMany(batch)
|
||||
err := s.cold.PutMany(s.ctx, batch)
|
||||
if err != nil {
|
||||
return xerrors.Errorf("error putting batch to coldstore: %w", err)
|
||||
}
|
||||
@ -1058,7 +1058,7 @@ func (s *SplitStore) purge(cids []cid.Cid, markSet MarkSetVisitor) error {
|
||||
deadCids = append(deadCids, c)
|
||||
}
|
||||
|
||||
err := s.hot.DeleteMany(deadCids)
|
||||
err := s.hot.DeleteMany(s.ctx, deadCids)
|
||||
if err != nil {
|
||||
return xerrors.Errorf("error purging cold objects: %w", err)
|
||||
}
|
||||
|
@ -20,28 +20,28 @@ func (s *SplitStore) Expose() bstore.Blockstore {
|
||||
return &exposedSplitStore{s: s}
|
||||
}
|
||||
|
||||
func (es *exposedSplitStore) DeleteBlock(_ cid.Cid) error {
|
||||
func (es *exposedSplitStore) DeleteBlock(_ context.Context, _ cid.Cid) error {
|
||||
return errors.New("DeleteBlock: operation not supported")
|
||||
}
|
||||
|
||||
func (es *exposedSplitStore) DeleteMany(_ []cid.Cid) error {
|
||||
func (es *exposedSplitStore) DeleteMany(_ context.Context, _ []cid.Cid) error {
|
||||
return errors.New("DeleteMany: operation not supported")
|
||||
}
|
||||
|
||||
func (es *exposedSplitStore) Has(c cid.Cid) (bool, error) {
|
||||
func (es *exposedSplitStore) Has(ctx context.Context, c cid.Cid) (bool, error) {
|
||||
if isIdentiyCid(c) {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
has, err := es.s.hot.Has(c)
|
||||
has, err := es.s.hot.Has(ctx, c)
|
||||
if has || err != nil {
|
||||
return has, err
|
||||
}
|
||||
|
||||
return es.s.cold.Has(c)
|
||||
return es.s.cold.Has(ctx, c)
|
||||
}
|
||||
|
||||
func (es *exposedSplitStore) Get(c cid.Cid) (blocks.Block, error) {
|
||||
func (es *exposedSplitStore) Get(ctx context.Context, c cid.Cid) (blocks.Block, error) {
|
||||
if isIdentiyCid(c) {
|
||||
data, err := decodeIdentityCid(c)
|
||||
if err != nil {
|
||||
@ -51,16 +51,16 @@ func (es *exposedSplitStore) Get(c cid.Cid) (blocks.Block, error) {
|
||||
return blocks.NewBlockWithCid(data, c)
|
||||
}
|
||||
|
||||
blk, err := es.s.hot.Get(c)
|
||||
blk, err := es.s.hot.Get(ctx, c)
|
||||
switch err {
|
||||
case bstore.ErrNotFound:
|
||||
return es.s.cold.Get(c)
|
||||
return es.s.cold.Get(ctx, c)
|
||||
default:
|
||||
return blk, err
|
||||
}
|
||||
}
|
||||
|
||||
func (es *exposedSplitStore) GetSize(c cid.Cid) (int, error) {
|
||||
func (es *exposedSplitStore) GetSize(ctx context.Context, c cid.Cid) (int, error) {
|
||||
if isIdentiyCid(c) {
|
||||
data, err := decodeIdentityCid(c)
|
||||
if err != nil {
|
||||
@ -70,21 +70,21 @@ func (es *exposedSplitStore) GetSize(c cid.Cid) (int, error) {
|
||||
return len(data), nil
|
||||
}
|
||||
|
||||
size, err := es.s.hot.GetSize(c)
|
||||
size, err := es.s.hot.GetSize(ctx, c)
|
||||
switch err {
|
||||
case bstore.ErrNotFound:
|
||||
return es.s.cold.GetSize(c)
|
||||
return es.s.cold.GetSize(ctx, c)
|
||||
default:
|
||||
return size, err
|
||||
}
|
||||
}
|
||||
|
||||
func (es *exposedSplitStore) Put(blk blocks.Block) error {
|
||||
return es.s.Put(blk)
|
||||
func (es *exposedSplitStore) Put(ctx context.Context, blk blocks.Block) error {
|
||||
return es.s.Put(ctx, blk)
|
||||
}
|
||||
|
||||
func (es *exposedSplitStore) PutMany(blks []blocks.Block) error {
|
||||
return es.s.PutMany(blks)
|
||||
func (es *exposedSplitStore) PutMany(ctx context.Context, blks []blocks.Block) error {
|
||||
return es.s.PutMany(ctx, blks)
|
||||
}
|
||||
|
||||
func (es *exposedSplitStore) AllKeysChan(ctx context.Context) (<-chan cid.Cid, error) {
|
||||
@ -93,7 +93,7 @@ func (es *exposedSplitStore) AllKeysChan(ctx context.Context) (<-chan cid.Cid, e
|
||||
|
||||
func (es *exposedSplitStore) HashOnRead(enabled bool) {}
|
||||
|
||||
func (es *exposedSplitStore) View(c cid.Cid, f func([]byte) error) error {
|
||||
func (es *exposedSplitStore) View(ctx context.Context, c cid.Cid, f func([]byte) error) error {
|
||||
if isIdentiyCid(c) {
|
||||
data, err := decodeIdentityCid(c)
|
||||
if err != nil {
|
||||
@ -103,10 +103,10 @@ func (es *exposedSplitStore) View(c cid.Cid, f func([]byte) error) error {
|
||||
return f(data)
|
||||
}
|
||||
|
||||
err := es.s.hot.View(c, f)
|
||||
err := es.s.hot.View(ctx, c, f)
|
||||
switch err {
|
||||
case bstore.ErrNotFound:
|
||||
return es.s.cold.View(c, f)
|
||||
return es.s.cold.View(ctx, c, f)
|
||||
|
||||
default:
|
||||
return err
|
||||
|
@ -30,6 +30,7 @@ func init() {
|
||||
}
|
||||
|
||||
func testSplitStore(t *testing.T, cfg *Config) {
|
||||
ctx := context.Background()
|
||||
chain := &mockChain{t: t}
|
||||
|
||||
// the myriads of stores
|
||||
@ -39,7 +40,7 @@ func testSplitStore(t *testing.T, cfg *Config) {
|
||||
|
||||
// this is necessary to avoid the garbage mock puts in the blocks
|
||||
garbage := blocks.NewBlock([]byte{1, 2, 3})
|
||||
err := cold.Put(garbage)
|
||||
err := cold.Put(ctx, garbage)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -60,21 +61,21 @@ func testSplitStore(t *testing.T, cfg *Config) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
err = cold.Put(blk)
|
||||
err = cold.Put(ctx, blk)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// create a garbage block that is protected with a rgistered protector
|
||||
protected := blocks.NewBlock([]byte("protected!"))
|
||||
err = hot.Put(protected)
|
||||
err = hot.Put(ctx, protected)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// and another one that is not protected
|
||||
unprotected := blocks.NewBlock([]byte("unprotected!"))
|
||||
err = hot.Put(unprotected)
|
||||
err = hot.Put(ctx, unprotected)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -109,11 +110,11 @@ func testSplitStore(t *testing.T, cfg *Config) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err = ss.Put(stateRoot)
|
||||
err = ss.Put(ctx, stateRoot)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err = ss.Put(sblk)
|
||||
err = ss.Put(ctx, sblk)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -176,7 +177,7 @@ func testSplitStore(t *testing.T, cfg *Config) {
|
||||
}
|
||||
|
||||
// ensure our protected block is still there
|
||||
has, err := hot.Has(protected.Cid())
|
||||
has, err := hot.Has(ctx, protected.Cid())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -186,7 +187,7 @@ func testSplitStore(t *testing.T, cfg *Config) {
|
||||
}
|
||||
|
||||
// ensure our unprotected block is in the coldstore now
|
||||
has, err = hot.Has(unprotected.Cid())
|
||||
has, err = hot.Has(ctx, unprotected.Cid())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -195,7 +196,7 @@ func testSplitStore(t *testing.T, cfg *Config) {
|
||||
t.Fatal("unprotected block is still in hotstore")
|
||||
}
|
||||
|
||||
has, err = cold.Has(unprotected.Cid())
|
||||
has, err = cold.Has(ctx, unprotected.Cid())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -222,6 +223,7 @@ func TestSplitStoreCompactionWithBadger(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestSplitStoreSuppressCompactionNearUpgrade(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
chain := &mockChain{t: t}
|
||||
|
||||
// the myriads of stores
|
||||
@ -231,7 +233,7 @@ func TestSplitStoreSuppressCompactionNearUpgrade(t *testing.T) {
|
||||
|
||||
// this is necessary to avoid the garbage mock puts in the blocks
|
||||
garbage := blocks.NewBlock([]byte{1, 2, 3})
|
||||
err := cold.Put(garbage)
|
||||
err := cold.Put(ctx, garbage)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -252,7 +254,7 @@ func TestSplitStoreSuppressCompactionNearUpgrade(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
err = cold.Put(blk)
|
||||
err = cold.Put(ctx, blk)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -288,11 +290,11 @@ func TestSplitStoreSuppressCompactionNearUpgrade(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err = ss.Put(stateRoot)
|
||||
err = ss.Put(ctx, stateRoot)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err = ss.Put(sblk)
|
||||
err = ss.Put(ctx, sblk)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -431,7 +433,7 @@ func newMockStore() *mockStore {
|
||||
return &mockStore{set: make(map[cid.Cid]blocks.Block)}
|
||||
}
|
||||
|
||||
func (b *mockStore) Has(cid cid.Cid) (bool, error) {
|
||||
func (b *mockStore) Has(_ context.Context, cid cid.Cid) (bool, error) {
|
||||
b.mx.Lock()
|
||||
defer b.mx.Unlock()
|
||||
_, ok := b.set[cid]
|
||||
@ -440,7 +442,7 @@ func (b *mockStore) Has(cid cid.Cid) (bool, error) {
|
||||
|
||||
func (b *mockStore) HashOnRead(hor bool) {}
|
||||
|
||||
func (b *mockStore) Get(cid cid.Cid) (blocks.Block, error) {
|
||||
func (b *mockStore) Get(_ context.Context, cid cid.Cid) (blocks.Block, error) {
|
||||
b.mx.Lock()
|
||||
defer b.mx.Unlock()
|
||||
|
||||
@ -451,8 +453,8 @@ func (b *mockStore) Get(cid cid.Cid) (blocks.Block, error) {
|
||||
return blk, nil
|
||||
}
|
||||
|
||||
func (b *mockStore) GetSize(cid cid.Cid) (int, error) {
|
||||
blk, err := b.Get(cid)
|
||||
func (b *mockStore) GetSize(ctx context.Context, cid cid.Cid) (int, error) {
|
||||
blk, err := b.Get(ctx, cid)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
@ -460,15 +462,15 @@ func (b *mockStore) GetSize(cid cid.Cid) (int, error) {
|
||||
return len(blk.RawData()), nil
|
||||
}
|
||||
|
||||
func (b *mockStore) View(cid cid.Cid, f func([]byte) error) error {
|
||||
blk, err := b.Get(cid)
|
||||
func (b *mockStore) View(ctx context.Context, cid cid.Cid, f func([]byte) error) error {
|
||||
blk, err := b.Get(ctx, cid)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return f(blk.RawData())
|
||||
}
|
||||
|
||||
func (b *mockStore) Put(blk blocks.Block) error {
|
||||
func (b *mockStore) Put(_ context.Context, blk blocks.Block) error {
|
||||
b.mx.Lock()
|
||||
defer b.mx.Unlock()
|
||||
|
||||
@ -476,7 +478,7 @@ func (b *mockStore) Put(blk blocks.Block) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b *mockStore) PutMany(blks []blocks.Block) error {
|
||||
func (b *mockStore) PutMany(_ context.Context, blks []blocks.Block) error {
|
||||
b.mx.Lock()
|
||||
defer b.mx.Unlock()
|
||||
|
||||
@ -486,7 +488,7 @@ func (b *mockStore) PutMany(blks []blocks.Block) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b *mockStore) DeleteBlock(cid cid.Cid) error {
|
||||
func (b *mockStore) DeleteBlock(_ context.Context, cid cid.Cid) error {
|
||||
b.mx.Lock()
|
||||
defer b.mx.Unlock()
|
||||
|
||||
@ -494,7 +496,7 @@ func (b *mockStore) DeleteBlock(cid cid.Cid) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b *mockStore) DeleteMany(cids []cid.Cid) error {
|
||||
func (b *mockStore) DeleteMany(_ context.Context, cids []cid.Cid) error {
|
||||
b.mx.Lock()
|
||||
defer b.mx.Unlock()
|
||||
|
||||
|
@ -75,7 +75,7 @@ func (s *SplitStore) doWarmup(curTs *types.TipSet) error {
|
||||
|
||||
count++
|
||||
|
||||
has, err := s.hot.Has(c)
|
||||
has, err := s.hot.Has(s.ctx, c)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -84,7 +84,7 @@ func (s *SplitStore) doWarmup(curTs *types.TipSet) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
blk, err := s.cold.Get(c)
|
||||
blk, err := s.cold.Get(s.ctx, c)
|
||||
if err != nil {
|
||||
if err == bstore.ErrNotFound {
|
||||
missing++
|
||||
@ -97,7 +97,7 @@ func (s *SplitStore) doWarmup(curTs *types.TipSet) error {
|
||||
|
||||
batchHot = append(batchHot, blk)
|
||||
if len(batchHot) == batchSize {
|
||||
err = s.hot.PutMany(batchHot)
|
||||
err = s.hot.PutMany(s.ctx, batchHot)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -112,7 +112,7 @@ func (s *SplitStore) doWarmup(curTs *types.TipSet) error {
|
||||
}
|
||||
|
||||
if len(batchHot) > 0 {
|
||||
err = s.hot.PutMany(batchHot)
|
||||
err = s.hot.PutMany(s.ctx, batchHot)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -121,13 +121,13 @@ func (s *SplitStore) doWarmup(curTs *types.TipSet) error {
|
||||
log.Infow("warmup stats", "visited", count, "warm", xcount, "missing", missing)
|
||||
|
||||
s.markSetSize = count + count>>2 // overestimate a bit
|
||||
err = s.ds.Put(markSetSizeKey, int64ToBytes(s.markSetSize))
|
||||
err = s.ds.Put(s.ctx, markSetSizeKey, int64ToBytes(s.markSetSize))
|
||||
if err != nil {
|
||||
log.Warnf("error saving mark set size: %s", err)
|
||||
}
|
||||
|
||||
// save the warmup epoch
|
||||
err = s.ds.Put(warmupEpochKey, epochToBytes(epoch))
|
||||
err = s.ds.Put(s.ctx, warmupEpochKey, epochToBytes(epoch))
|
||||
if err != nil {
|
||||
return xerrors.Errorf("error saving warm up epoch: %w", err)
|
||||
}
|
||||
@ -136,7 +136,7 @@ func (s *SplitStore) doWarmup(curTs *types.TipSet) error {
|
||||
s.mx.Unlock()
|
||||
|
||||
// also save the compactionIndex, as this is used as an indicator of warmup for upgraded nodes
|
||||
err = s.ds.Put(compactionIndexKey, int64ToBytes(s.compactionIndex))
|
||||
err = s.ds.Put(s.ctx, compactionIndexKey, int64ToBytes(s.compactionIndex))
|
||||
if err != nil {
|
||||
return xerrors.Errorf("error saving compaction index: %w", err)
|
||||
}
|
||||
|
@ -20,53 +20,53 @@ type SyncBlockstore struct {
|
||||
bs MemBlockstore // specifically use a memStore to save indirection overhead.
|
||||
}
|
||||
|
||||
func (m *SyncBlockstore) DeleteBlock(k cid.Cid) error {
|
||||
func (m *SyncBlockstore) DeleteBlock(ctx context.Context, k cid.Cid) error {
|
||||
m.mu.Lock()
|
||||
defer m.mu.Unlock()
|
||||
return m.bs.DeleteBlock(k)
|
||||
return m.bs.DeleteBlock(ctx, k)
|
||||
}
|
||||
|
||||
func (m *SyncBlockstore) DeleteMany(ks []cid.Cid) error {
|
||||
func (m *SyncBlockstore) DeleteMany(ctx context.Context, ks []cid.Cid) error {
|
||||
m.mu.Lock()
|
||||
defer m.mu.Unlock()
|
||||
return m.bs.DeleteMany(ks)
|
||||
return m.bs.DeleteMany(ctx, ks)
|
||||
}
|
||||
|
||||
func (m *SyncBlockstore) Has(k cid.Cid) (bool, error) {
|
||||
func (m *SyncBlockstore) Has(ctx context.Context, k cid.Cid) (bool, error) {
|
||||
m.mu.RLock()
|
||||
defer m.mu.RUnlock()
|
||||
return m.bs.Has(k)
|
||||
return m.bs.Has(ctx, k)
|
||||
}
|
||||
|
||||
func (m *SyncBlockstore) View(k cid.Cid, callback func([]byte) error) error {
|
||||
func (m *SyncBlockstore) View(ctx context.Context, k cid.Cid, callback func([]byte) error) error {
|
||||
m.mu.RLock()
|
||||
defer m.mu.RUnlock()
|
||||
|
||||
return m.bs.View(k, callback)
|
||||
return m.bs.View(ctx, k, callback)
|
||||
}
|
||||
|
||||
func (m *SyncBlockstore) Get(k cid.Cid) (blocks.Block, error) {
|
||||
func (m *SyncBlockstore) Get(ctx context.Context, k cid.Cid) (blocks.Block, error) {
|
||||
m.mu.RLock()
|
||||
defer m.mu.RUnlock()
|
||||
return m.bs.Get(k)
|
||||
return m.bs.Get(ctx, k)
|
||||
}
|
||||
|
||||
func (m *SyncBlockstore) GetSize(k cid.Cid) (int, error) {
|
||||
func (m *SyncBlockstore) GetSize(ctx context.Context, k cid.Cid) (int, error) {
|
||||
m.mu.RLock()
|
||||
defer m.mu.RUnlock()
|
||||
return m.bs.GetSize(k)
|
||||
return m.bs.GetSize(ctx, k)
|
||||
}
|
||||
|
||||
func (m *SyncBlockstore) Put(b blocks.Block) error {
|
||||
func (m *SyncBlockstore) Put(ctx context.Context, b blocks.Block) error {
|
||||
m.mu.Lock()
|
||||
defer m.mu.Unlock()
|
||||
return m.bs.Put(b)
|
||||
return m.bs.Put(ctx, b)
|
||||
}
|
||||
|
||||
func (m *SyncBlockstore) PutMany(bs []blocks.Block) error {
|
||||
func (m *SyncBlockstore) PutMany(ctx context.Context, bs []blocks.Block) error {
|
||||
m.mu.Lock()
|
||||
defer m.mu.Unlock()
|
||||
return m.bs.PutMany(bs)
|
||||
return m.bs.PutMany(ctx, bs)
|
||||
}
|
||||
|
||||
func (m *SyncBlockstore) AllKeysChan(ctx context.Context) (<-chan cid.Cid, error) {
|
||||
|
@ -92,28 +92,28 @@ func (t *TimedCacheBlockstore) rotate() {
|
||||
t.mu.Unlock()
|
||||
}
|
||||
|
||||
func (t *TimedCacheBlockstore) Put(b blocks.Block) error {
|
||||
func (t *TimedCacheBlockstore) Put(ctx context.Context, b blocks.Block) error {
|
||||
// Don't check the inactive set here. We want to keep this block for at
|
||||
// least one interval.
|
||||
t.mu.Lock()
|
||||
defer t.mu.Unlock()
|
||||
return t.active.Put(b)
|
||||
return t.active.Put(ctx, b)
|
||||
}
|
||||
|
||||
func (t *TimedCacheBlockstore) PutMany(bs []blocks.Block) error {
|
||||
func (t *TimedCacheBlockstore) PutMany(ctx context.Context, bs []blocks.Block) error {
|
||||
t.mu.Lock()
|
||||
defer t.mu.Unlock()
|
||||
return t.active.PutMany(bs)
|
||||
return t.active.PutMany(ctx, bs)
|
||||
}
|
||||
|
||||
func (t *TimedCacheBlockstore) View(k cid.Cid, callback func([]byte) error) error {
|
||||
func (t *TimedCacheBlockstore) View(ctx context.Context, k cid.Cid, callback func([]byte) error) error {
|
||||
// The underlying blockstore is always a "mem" blockstore so there's no difference,
|
||||
// from a performance perspective, between view & get. So we call Get to avoid
|
||||
// calling an arbitrary callback while holding a lock.
|
||||
t.mu.RLock()
|
||||
block, err := t.active.Get(k)
|
||||
block, err := t.active.Get(ctx, k)
|
||||
if err == ErrNotFound {
|
||||
block, err = t.inactive.Get(k)
|
||||
block, err = t.inactive.Get(ctx, k)
|
||||
}
|
||||
t.mu.RUnlock()
|
||||
|
||||
@ -123,51 +123,51 @@ func (t *TimedCacheBlockstore) View(k cid.Cid, callback func([]byte) error) erro
|
||||
return callback(block.RawData())
|
||||
}
|
||||
|
||||
func (t *TimedCacheBlockstore) Get(k cid.Cid) (blocks.Block, error) {
|
||||
func (t *TimedCacheBlockstore) Get(ctx context.Context, k cid.Cid) (blocks.Block, error) {
|
||||
t.mu.RLock()
|
||||
defer t.mu.RUnlock()
|
||||
b, err := t.active.Get(k)
|
||||
b, err := t.active.Get(ctx, k)
|
||||
if err == ErrNotFound {
|
||||
b, err = t.inactive.Get(k)
|
||||
b, err = t.inactive.Get(ctx, k)
|
||||
}
|
||||
return b, err
|
||||
}
|
||||
|
||||
func (t *TimedCacheBlockstore) GetSize(k cid.Cid) (int, error) {
|
||||
func (t *TimedCacheBlockstore) GetSize(ctx context.Context, k cid.Cid) (int, error) {
|
||||
t.mu.RLock()
|
||||
defer t.mu.RUnlock()
|
||||
size, err := t.active.GetSize(k)
|
||||
size, err := t.active.GetSize(ctx, k)
|
||||
if err == ErrNotFound {
|
||||
size, err = t.inactive.GetSize(k)
|
||||
size, err = t.inactive.GetSize(ctx, k)
|
||||
}
|
||||
return size, err
|
||||
}
|
||||
|
||||
func (t *TimedCacheBlockstore) Has(k cid.Cid) (bool, error) {
|
||||
func (t *TimedCacheBlockstore) Has(ctx context.Context, k cid.Cid) (bool, error) {
|
||||
t.mu.RLock()
|
||||
defer t.mu.RUnlock()
|
||||
if has, err := t.active.Has(k); err != nil {
|
||||
if has, err := t.active.Has(ctx, k); err != nil {
|
||||
return false, err
|
||||
} else if has {
|
||||
return true, nil
|
||||
}
|
||||
return t.inactive.Has(k)
|
||||
return t.inactive.Has(ctx, k)
|
||||
}
|
||||
|
||||
func (t *TimedCacheBlockstore) HashOnRead(_ bool) {
|
||||
// no-op
|
||||
}
|
||||
|
||||
func (t *TimedCacheBlockstore) DeleteBlock(k cid.Cid) error {
|
||||
func (t *TimedCacheBlockstore) DeleteBlock(ctx context.Context, k cid.Cid) error {
|
||||
t.mu.Lock()
|
||||
defer t.mu.Unlock()
|
||||
return multierr.Combine(t.active.DeleteBlock(k), t.inactive.DeleteBlock(k))
|
||||
return multierr.Combine(t.active.DeleteBlock(ctx, k), t.inactive.DeleteBlock(ctx, k))
|
||||
}
|
||||
|
||||
func (t *TimedCacheBlockstore) DeleteMany(ks []cid.Cid) error {
|
||||
func (t *TimedCacheBlockstore) DeleteMany(ctx context.Context, ks []cid.Cid) error {
|
||||
t.mu.Lock()
|
||||
defer t.mu.Unlock()
|
||||
return multierr.Combine(t.active.DeleteMany(ks), t.inactive.DeleteMany(ks))
|
||||
return multierr.Combine(t.active.DeleteMany(ctx, ks), t.inactive.DeleteMany(ctx, ks))
|
||||
}
|
||||
|
||||
func (t *TimedCacheBlockstore) AllKeysChan(_ context.Context) (<-chan cid.Cid, error) {
|
||||
|
@ -19,6 +19,8 @@ func TestTimedCacheBlockstoreSimple(t *testing.T) {
|
||||
tc.clock = mClock
|
||||
tc.doneRotatingCh = make(chan struct{})
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
_ = tc.Start(context.Background())
|
||||
mClock.Add(1) // IDK why it is needed but it makes it work
|
||||
|
||||
@ -27,18 +29,18 @@ func TestTimedCacheBlockstoreSimple(t *testing.T) {
|
||||
}()
|
||||
|
||||
b1 := blocks.NewBlock([]byte("foo"))
|
||||
require.NoError(t, tc.Put(b1))
|
||||
require.NoError(t, tc.Put(ctx, b1))
|
||||
|
||||
b2 := blocks.NewBlock([]byte("bar"))
|
||||
require.NoError(t, tc.Put(b2))
|
||||
require.NoError(t, tc.Put(ctx, b2))
|
||||
|
||||
b3 := blocks.NewBlock([]byte("baz"))
|
||||
|
||||
b1out, err := tc.Get(b1.Cid())
|
||||
b1out, err := tc.Get(ctx, b1.Cid())
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, b1.RawData(), b1out.RawData())
|
||||
|
||||
has, err := tc.Has(b1.Cid())
|
||||
has, err := tc.Has(ctx, b1.Cid())
|
||||
require.NoError(t, err)
|
||||
require.True(t, has)
|
||||
|
||||
@ -46,17 +48,17 @@ func TestTimedCacheBlockstoreSimple(t *testing.T) {
|
||||
<-tc.doneRotatingCh
|
||||
|
||||
// We should still have everything.
|
||||
has, err = tc.Has(b1.Cid())
|
||||
has, err = tc.Has(ctx, b1.Cid())
|
||||
require.NoError(t, err)
|
||||
require.True(t, has)
|
||||
|
||||
has, err = tc.Has(b2.Cid())
|
||||
has, err = tc.Has(ctx, b2.Cid())
|
||||
require.NoError(t, err)
|
||||
require.True(t, has)
|
||||
|
||||
// extend b2, add b3.
|
||||
require.NoError(t, tc.Put(b2))
|
||||
require.NoError(t, tc.Put(b3))
|
||||
require.NoError(t, tc.Put(ctx, b2))
|
||||
require.NoError(t, tc.Put(ctx, b3))
|
||||
|
||||
// all keys once.
|
||||
allKeys, err := tc.AllKeysChan(context.Background())
|
||||
@ -71,15 +73,15 @@ func TestTimedCacheBlockstoreSimple(t *testing.T) {
|
||||
<-tc.doneRotatingCh
|
||||
// should still have b2, and b3, but not b1
|
||||
|
||||
has, err = tc.Has(b1.Cid())
|
||||
has, err = tc.Has(ctx, b1.Cid())
|
||||
require.NoError(t, err)
|
||||
require.False(t, has)
|
||||
|
||||
has, err = tc.Has(b2.Cid())
|
||||
has, err = tc.Has(ctx, b2.Cid())
|
||||
require.NoError(t, err)
|
||||
require.True(t, has)
|
||||
|
||||
has, err = tc.Has(b3.Cid())
|
||||
has, err = tc.Has(ctx, b3.Cid())
|
||||
require.NoError(t, err)
|
||||
require.True(t, has)
|
||||
}
|
||||
|
@ -19,72 +19,72 @@ func Union(stores ...Blockstore) Blockstore {
|
||||
return unionBlockstore(stores)
|
||||
}
|
||||
|
||||
func (m unionBlockstore) Has(cid cid.Cid) (has bool, err error) {
|
||||
func (m unionBlockstore) Has(ctx context.Context, cid cid.Cid) (has bool, err error) {
|
||||
for _, bs := range m {
|
||||
if has, err = bs.Has(cid); has || err != nil {
|
||||
if has, err = bs.Has(ctx, cid); has || err != nil {
|
||||
break
|
||||
}
|
||||
}
|
||||
return has, err
|
||||
}
|
||||
|
||||
func (m unionBlockstore) Get(cid cid.Cid) (blk blocks.Block, err error) {
|
||||
func (m unionBlockstore) Get(ctx context.Context, cid cid.Cid) (blk blocks.Block, err error) {
|
||||
for _, bs := range m {
|
||||
if blk, err = bs.Get(cid); err == nil || err != ErrNotFound {
|
||||
if blk, err = bs.Get(ctx, cid); err == nil || err != ErrNotFound {
|
||||
break
|
||||
}
|
||||
}
|
||||
return blk, err
|
||||
}
|
||||
|
||||
func (m unionBlockstore) View(cid cid.Cid, callback func([]byte) error) (err error) {
|
||||
func (m unionBlockstore) View(ctx context.Context, cid cid.Cid, callback func([]byte) error) (err error) {
|
||||
for _, bs := range m {
|
||||
if err = bs.View(cid, callback); err == nil || err != ErrNotFound {
|
||||
if err = bs.View(ctx, cid, callback); err == nil || err != ErrNotFound {
|
||||
break
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (m unionBlockstore) GetSize(cid cid.Cid) (size int, err error) {
|
||||
func (m unionBlockstore) GetSize(ctx context.Context, cid cid.Cid) (size int, err error) {
|
||||
for _, bs := range m {
|
||||
if size, err = bs.GetSize(cid); err == nil || err != ErrNotFound {
|
||||
if size, err = bs.GetSize(ctx, cid); err == nil || err != ErrNotFound {
|
||||
break
|
||||
}
|
||||
}
|
||||
return size, err
|
||||
}
|
||||
|
||||
func (m unionBlockstore) Put(block blocks.Block) (err error) {
|
||||
func (m unionBlockstore) Put(ctx context.Context, block blocks.Block) (err error) {
|
||||
for _, bs := range m {
|
||||
if err = bs.Put(block); err != nil {
|
||||
if err = bs.Put(ctx, block); err != nil {
|
||||
break
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (m unionBlockstore) PutMany(blks []blocks.Block) (err error) {
|
||||
func (m unionBlockstore) PutMany(ctx context.Context, blks []blocks.Block) (err error) {
|
||||
for _, bs := range m {
|
||||
if err = bs.PutMany(blks); err != nil {
|
||||
if err = bs.PutMany(ctx, blks); err != nil {
|
||||
break
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (m unionBlockstore) DeleteBlock(cid cid.Cid) (err error) {
|
||||
func (m unionBlockstore) DeleteBlock(ctx context.Context, cid cid.Cid) (err error) {
|
||||
for _, bs := range m {
|
||||
if err = bs.DeleteBlock(cid); err != nil {
|
||||
if err = bs.DeleteBlock(ctx, cid); err != nil {
|
||||
break
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (m unionBlockstore) DeleteMany(cids []cid.Cid) (err error) {
|
||||
func (m unionBlockstore) DeleteMany(ctx context.Context, cids []cid.Cid) (err error) {
|
||||
for _, bs := range m {
|
||||
if err = bs.DeleteMany(cids); err != nil {
|
||||
if err = bs.DeleteMany(ctx, cids); err != nil {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
@ -15,79 +15,81 @@ var (
|
||||
)
|
||||
|
||||
func TestUnionBlockstore_Get(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
m1 := NewMemory()
|
||||
m2 := NewMemory()
|
||||
|
||||
_ = m1.Put(b1)
|
||||
_ = m2.Put(b2)
|
||||
_ = m1.Put(ctx, b1)
|
||||
_ = m2.Put(ctx, b2)
|
||||
|
||||
u := Union(m1, m2)
|
||||
|
||||
v1, err := u.Get(b1.Cid())
|
||||
v1, err := u.Get(ctx, b1.Cid())
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, b1.RawData(), v1.RawData())
|
||||
|
||||
v2, err := u.Get(b2.Cid())
|
||||
v2, err := u.Get(ctx, b2.Cid())
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, b2.RawData(), v2.RawData())
|
||||
}
|
||||
|
||||
func TestUnionBlockstore_Put_PutMany_Delete_AllKeysChan(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
m1 := NewMemory()
|
||||
m2 := NewMemory()
|
||||
|
||||
u := Union(m1, m2)
|
||||
|
||||
err := u.Put(b0)
|
||||
err := u.Put(ctx, b0)
|
||||
require.NoError(t, err)
|
||||
|
||||
var has bool
|
||||
|
||||
// write was broadcasted to all stores.
|
||||
has, _ = m1.Has(b0.Cid())
|
||||
has, _ = m1.Has(ctx, b0.Cid())
|
||||
require.True(t, has)
|
||||
|
||||
has, _ = m2.Has(b0.Cid())
|
||||
has, _ = m2.Has(ctx, b0.Cid())
|
||||
require.True(t, has)
|
||||
|
||||
has, _ = u.Has(b0.Cid())
|
||||
has, _ = u.Has(ctx, b0.Cid())
|
||||
require.True(t, has)
|
||||
|
||||
// put many.
|
||||
err = u.PutMany([]blocks.Block{b1, b2})
|
||||
err = u.PutMany(ctx, []blocks.Block{b1, b2})
|
||||
require.NoError(t, err)
|
||||
|
||||
// write was broadcasted to all stores.
|
||||
has, _ = m1.Has(b1.Cid())
|
||||
has, _ = m1.Has(ctx, b1.Cid())
|
||||
require.True(t, has)
|
||||
|
||||
has, _ = m1.Has(b2.Cid())
|
||||
has, _ = m1.Has(ctx, b2.Cid())
|
||||
require.True(t, has)
|
||||
|
||||
has, _ = m2.Has(b1.Cid())
|
||||
has, _ = m2.Has(ctx, b1.Cid())
|
||||
require.True(t, has)
|
||||
|
||||
has, _ = m2.Has(b2.Cid())
|
||||
has, _ = m2.Has(ctx, b2.Cid())
|
||||
require.True(t, has)
|
||||
|
||||
// also in the union store.
|
||||
has, _ = u.Has(b1.Cid())
|
||||
has, _ = u.Has(ctx, b1.Cid())
|
||||
require.True(t, has)
|
||||
|
||||
has, _ = u.Has(b2.Cid())
|
||||
has, _ = u.Has(ctx, b2.Cid())
|
||||
require.True(t, has)
|
||||
|
||||
// deleted from all stores.
|
||||
err = u.DeleteBlock(b1.Cid())
|
||||
err = u.DeleteBlock(ctx, b1.Cid())
|
||||
require.NoError(t, err)
|
||||
|
||||
has, _ = u.Has(b1.Cid())
|
||||
has, _ = u.Has(ctx, b1.Cid())
|
||||
require.False(t, has)
|
||||
|
||||
has, _ = m1.Has(b1.Cid())
|
||||
has, _ = m1.Has(ctx, b1.Cid())
|
||||
require.False(t, has)
|
||||
|
||||
has, _ = m2.Has(b1.Cid())
|
||||
has, _ = m2.Has(ctx, b1.Cid())
|
||||
require.False(t, has)
|
||||
|
||||
// check that AllKeysChan returns b0 and b2, twice (once per backing store)
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -47,6 +47,8 @@ var UpgradeHyperdriveHeight = abi.ChainEpoch(-16)
|
||||
|
||||
var UpgradeChocolateHeight = abi.ChainEpoch(-17)
|
||||
|
||||
var UpgradeSnapDealsHeight = abi.ChainEpoch(-18)
|
||||
|
||||
var DrandSchedule = map[abi.ChainEpoch]DrandEnum{
|
||||
0: DrandMainnet,
|
||||
}
|
||||
|
@ -41,6 +41,7 @@ const UpgradeNorwegianHeight = -14
|
||||
const UpgradeTurboHeight = -15
|
||||
const UpgradeHyperdriveHeight = -16
|
||||
const UpgradeChocolateHeight = 6360
|
||||
const UpgradeSnapDealsHeight = 99999999
|
||||
|
||||
func init() {
|
||||
policy.SetConsensusMinerMinPower(abi.NewStoragePower(2 << 30))
|
||||
|
@ -54,6 +54,8 @@ const UpgradeHyperdriveHeight = 420
|
||||
|
||||
const UpgradeChocolateHeight = 312746
|
||||
|
||||
const UpgradeSnapDealsHeight = 99999999
|
||||
|
||||
func init() {
|
||||
policy.SetConsensusMinerMinPower(abi.NewStoragePower(32 << 30))
|
||||
policy.SetSupportedProofTypes(
|
||||
|
@ -47,6 +47,7 @@ var UpgradeTurboHeight = abi.ChainEpoch(-15)
|
||||
|
||||
var UpgradeHyperdriveHeight = abi.ChainEpoch(-16)
|
||||
var UpgradeChocolateHeight = abi.ChainEpoch(-17)
|
||||
var UpgradeSnapDealsHeight = abi.ChainEpoch(-18)
|
||||
|
||||
var DrandSchedule = map[abi.ChainEpoch]DrandEnum{
|
||||
0: DrandMainnet,
|
||||
|
@ -62,18 +62,20 @@ const UpgradeNorwegianHeight = 665280
|
||||
const UpgradeTurboHeight = 712320
|
||||
|
||||
// 2021-06-30T22:00:00Z
|
||||
var UpgradeHyperdriveHeight = abi.ChainEpoch(892800)
|
||||
const UpgradeHyperdriveHeight = 892800
|
||||
|
||||
// 2021-10-26T13:30:00Z
|
||||
var UpgradeChocolateHeight = abi.ChainEpoch(1231620)
|
||||
const UpgradeChocolateHeight = 1231620
|
||||
|
||||
var UpgradeSnapDealsHeight = abi.ChainEpoch(999999999999)
|
||||
|
||||
func init() {
|
||||
if os.Getenv("LOTUS_USE_TEST_ADDRESSES") != "1" {
|
||||
SetAddressNetwork(address.Mainnet)
|
||||
}
|
||||
|
||||
if os.Getenv("LOTUS_DISABLE_CHOCOLATE") == "1" {
|
||||
UpgradeChocolateHeight = math.MaxInt64
|
||||
if os.Getenv("LOTUS_DISABLE_SNAPDEALS") == "1" {
|
||||
UpgradeSnapDealsHeight = math.MaxInt64
|
||||
}
|
||||
|
||||
Devnet = false
|
||||
|
@ -34,7 +34,7 @@ const NewestNetworkVersion = network.Version{{.latestNetworkVersion}}
|
||||
|
||||
/* inline-gen start */
|
||||
|
||||
const NewestNetworkVersion = network.Version14
|
||||
const NewestNetworkVersion = network.Version15
|
||||
|
||||
/* inline-gen end */
|
||||
|
||||
|
@ -99,6 +99,7 @@ var (
|
||||
UpgradeTurboHeight abi.ChainEpoch = -14
|
||||
UpgradeHyperdriveHeight abi.ChainEpoch = -15
|
||||
UpgradeChocolateHeight abi.ChainEpoch = -16
|
||||
UpgradeSnapDealsHeight abi.ChainEpoch = -17
|
||||
|
||||
DrandSchedule = map[abi.ChainEpoch]DrandEnum{
|
||||
0: DrandMainnet,
|
||||
|
@ -23,6 +23,8 @@ import (
|
||||
builtin5 "github.com/filecoin-project/specs-actors/v5/actors/builtin"
|
||||
|
||||
builtin6 "github.com/filecoin-project/specs-actors/v6/actors/builtin"
|
||||
|
||||
builtin7 "github.com/filecoin-project/specs-actors/v7/actors/builtin"
|
||||
)
|
||||
|
||||
func init() {
|
||||
@ -50,6 +52,10 @@ func init() {
|
||||
builtin.RegisterActorState(builtin6.AccountActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
|
||||
return load6(store, root)
|
||||
})
|
||||
|
||||
builtin.RegisterActorState(builtin7.AccountActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
|
||||
return load7(store, root)
|
||||
})
|
||||
}
|
||||
|
||||
var Methods = builtin4.MethodsAccount
|
||||
@ -75,6 +81,9 @@ func Load(store adt.Store, act *types.Actor) (State, error) {
|
||||
case builtin6.AccountActorCodeID:
|
||||
return load6(store, act.Head)
|
||||
|
||||
case builtin7.AccountActorCodeID:
|
||||
return load7(store, act.Head)
|
||||
|
||||
}
|
||||
return nil, xerrors.Errorf("unknown actor code %s", act.Code)
|
||||
}
|
||||
@ -100,6 +109,9 @@ func MakeState(store adt.Store, av actors.Version, addr address.Address) (State,
|
||||
case actors.Version6:
|
||||
return make6(store, addr)
|
||||
|
||||
case actors.Version7:
|
||||
return make7(store, addr)
|
||||
|
||||
}
|
||||
return nil, xerrors.Errorf("unknown actor version %d", av)
|
||||
}
|
||||
@ -125,6 +137,9 @@ func GetActorCodeID(av actors.Version) (cid.Cid, error) {
|
||||
case actors.Version6:
|
||||
return builtin6.AccountActorCodeID, nil
|
||||
|
||||
case actors.Version7:
|
||||
return builtin7.AccountActorCodeID, nil
|
||||
|
||||
}
|
||||
|
||||
return cid.Undef, xerrors.Errorf("unknown actor version %d", av)
|
||||
|
40
chain/actors/builtin/account/v7.go
Normal file
40
chain/actors/builtin/account/v7.go
Normal file
@ -0,0 +1,40 @@
|
||||
package account
|
||||
|
||||
import (
|
||||
"github.com/filecoin-project/go-address"
|
||||
"github.com/ipfs/go-cid"
|
||||
|
||||
"github.com/filecoin-project/lotus/chain/actors/adt"
|
||||
|
||||
account7 "github.com/filecoin-project/specs-actors/v7/actors/builtin/account"
|
||||
)
|
||||
|
||||
var _ State = (*state7)(nil)
|
||||
|
||||
func load7(store adt.Store, root cid.Cid) (State, error) {
|
||||
out := state7{store: store}
|
||||
err := store.Get(store.Context(), root, &out)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &out, nil
|
||||
}
|
||||
|
||||
func make7(store adt.Store, addr address.Address) (State, error) {
|
||||
out := state7{store: store}
|
||||
out.State = account7.State{Address: addr}
|
||||
return &out, nil
|
||||
}
|
||||
|
||||
type state7 struct {
|
||||
account7.State
|
||||
store adt.Store
|
||||
}
|
||||
|
||||
func (s *state7) PubkeyAddress() (address.Address, error) {
|
||||
return s.Address, nil
|
||||
}
|
||||
|
||||
func (s *state7) GetState() interface{} {
|
||||
return &s.State
|
||||
}
|
@ -23,46 +23,49 @@ import (
|
||||
builtin6 "github.com/filecoin-project/specs-actors/v6/actors/builtin"
|
||||
smoothing6 "github.com/filecoin-project/specs-actors/v6/actors/util/smoothing"
|
||||
|
||||
builtin7 "github.com/filecoin-project/specs-actors/v7/actors/builtin"
|
||||
smoothing7 "github.com/filecoin-project/specs-actors/v7/actors/util/smoothing"
|
||||
|
||||
"github.com/filecoin-project/go-state-types/abi"
|
||||
"github.com/filecoin-project/go-state-types/cbor"
|
||||
|
||||
"github.com/filecoin-project/lotus/chain/actors/adt"
|
||||
"github.com/filecoin-project/lotus/chain/types"
|
||||
|
||||
miner6 "github.com/filecoin-project/specs-actors/v6/actors/builtin/miner"
|
||||
proof6 "github.com/filecoin-project/specs-actors/v6/actors/runtime/proof"
|
||||
miner7 "github.com/filecoin-project/specs-actors/v7/actors/builtin/miner"
|
||||
proof7 "github.com/filecoin-project/specs-actors/v7/actors/runtime/proof"
|
||||
)
|
||||
|
||||
var SystemActorAddr = builtin6.SystemActorAddr
|
||||
var BurntFundsActorAddr = builtin6.BurntFundsActorAddr
|
||||
var CronActorAddr = builtin6.CronActorAddr
|
||||
var SystemActorAddr = builtin7.SystemActorAddr
|
||||
var BurntFundsActorAddr = builtin7.BurntFundsActorAddr
|
||||
var CronActorAddr = builtin7.CronActorAddr
|
||||
var SaftAddress = makeAddress("t0122")
|
||||
var ReserveAddress = makeAddress("t090")
|
||||
var RootVerifierAddress = makeAddress("t080")
|
||||
|
||||
var (
|
||||
ExpectedLeadersPerEpoch = builtin6.ExpectedLeadersPerEpoch
|
||||
ExpectedLeadersPerEpoch = builtin7.ExpectedLeadersPerEpoch
|
||||
)
|
||||
|
||||
const (
|
||||
EpochDurationSeconds = builtin6.EpochDurationSeconds
|
||||
EpochsInDay = builtin6.EpochsInDay
|
||||
SecondsInDay = builtin6.SecondsInDay
|
||||
EpochDurationSeconds = builtin7.EpochDurationSeconds
|
||||
EpochsInDay = builtin7.EpochsInDay
|
||||
SecondsInDay = builtin7.SecondsInDay
|
||||
)
|
||||
|
||||
const (
|
||||
MethodSend = builtin6.MethodSend
|
||||
MethodConstructor = builtin6.MethodConstructor
|
||||
MethodSend = builtin7.MethodSend
|
||||
MethodConstructor = builtin7.MethodConstructor
|
||||
)
|
||||
|
||||
// These are all just type aliases across actor versions. In the future, that might change
|
||||
// and we might need to do something fancier.
|
||||
type SectorInfo = proof6.SectorInfo
|
||||
type PoStProof = proof6.PoStProof
|
||||
type SectorInfo = proof7.SectorInfo
|
||||
type PoStProof = proof7.PoStProof
|
||||
type FilterEstimate = smoothing0.FilterEstimate
|
||||
|
||||
func QAPowerForWeight(size abi.SectorSize, duration abi.ChainEpoch, dealWeight, verifiedWeight abi.DealWeight) abi.StoragePower {
|
||||
return miner6.QAPowerForWeight(size, duration, dealWeight, verifiedWeight)
|
||||
return miner7.QAPowerForWeight(size, duration, dealWeight, verifiedWeight)
|
||||
}
|
||||
|
||||
func FromV0FilterEstimate(v0 smoothing0.FilterEstimate) FilterEstimate {
|
||||
@ -101,6 +104,12 @@ func FromV6FilterEstimate(v6 smoothing6.FilterEstimate) FilterEstimate {
|
||||
|
||||
}
|
||||
|
||||
func FromV7FilterEstimate(v7 smoothing7.FilterEstimate) FilterEstimate {
|
||||
|
||||
return (FilterEstimate)(v7)
|
||||
|
||||
}
|
||||
|
||||
type ActorStateLoader func(store adt.Store, root cid.Cid) (cbor.Marshaler, error)
|
||||
|
||||
var ActorStateLoaders = make(map[cid.Cid]ActorStateLoader)
|
||||
@ -138,6 +147,9 @@ func ActorNameByCode(c cid.Cid) string {
|
||||
case builtin6.IsBuiltinActor(c):
|
||||
return builtin6.ActorNameByCode(c)
|
||||
|
||||
case builtin7.IsBuiltinActor(c):
|
||||
return builtin7.ActorNameByCode(c)
|
||||
|
||||
default:
|
||||
return "<unknown>"
|
||||
}
|
||||
@ -169,6 +181,10 @@ func IsBuiltinActor(c cid.Cid) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
if builtin7.IsBuiltinActor(c) {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
@ -198,6 +214,10 @@ func IsAccountActor(c cid.Cid) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
if c == builtin7.AccountActorCodeID {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
@ -227,6 +247,10 @@ func IsStorageMinerActor(c cid.Cid) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
if c == builtin7.StorageMinerActorCodeID {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
@ -256,6 +280,10 @@ func IsMultisigActor(c cid.Cid) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
if c == builtin7.MultisigActorCodeID {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
@ -285,6 +313,10 @@ func IsPaymentChannelActor(c cid.Cid) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
if c == builtin7.PaymentChannelActorCodeID {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
|
@ -17,6 +17,8 @@ import (
|
||||
builtin5 "github.com/filecoin-project/specs-actors/v5/actors/builtin"
|
||||
|
||||
builtin6 "github.com/filecoin-project/specs-actors/v6/actors/builtin"
|
||||
|
||||
builtin7 "github.com/filecoin-project/specs-actors/v7/actors/builtin"
|
||||
)
|
||||
|
||||
func MakeState(store adt.Store, av actors.Version) (State, error) {
|
||||
@ -40,6 +42,9 @@ func MakeState(store adt.Store, av actors.Version) (State, error) {
|
||||
case actors.Version6:
|
||||
return make6(store)
|
||||
|
||||
case actors.Version7:
|
||||
return make7(store)
|
||||
|
||||
}
|
||||
return nil, xerrors.Errorf("unknown actor version %d", av)
|
||||
}
|
||||
@ -65,14 +70,17 @@ func GetActorCodeID(av actors.Version) (cid.Cid, error) {
|
||||
case actors.Version6:
|
||||
return builtin6.CronActorCodeID, nil
|
||||
|
||||
case actors.Version7:
|
||||
return builtin7.CronActorCodeID, nil
|
||||
|
||||
}
|
||||
|
||||
return cid.Undef, xerrors.Errorf("unknown actor version %d", av)
|
||||
}
|
||||
|
||||
var (
|
||||
Address = builtin6.CronActorAddr
|
||||
Methods = builtin6.MethodsCron
|
||||
Address = builtin7.CronActorAddr
|
||||
Methods = builtin7.MethodsCron
|
||||
)
|
||||
|
||||
type State interface {
|
||||
|
35
chain/actors/builtin/cron/v7.go
Normal file
35
chain/actors/builtin/cron/v7.go
Normal file
@ -0,0 +1,35 @@
|
||||
package cron
|
||||
|
||||
import (
|
||||
"github.com/ipfs/go-cid"
|
||||
|
||||
"github.com/filecoin-project/lotus/chain/actors/adt"
|
||||
|
||||
cron7 "github.com/filecoin-project/specs-actors/v7/actors/builtin/cron"
|
||||
)
|
||||
|
||||
var _ State = (*state7)(nil)
|
||||
|
||||
func load7(store adt.Store, root cid.Cid) (State, error) {
|
||||
out := state7{store: store}
|
||||
err := store.Get(store.Context(), root, &out)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &out, nil
|
||||
}
|
||||
|
||||
func make7(store adt.Store) (State, error) {
|
||||
out := state7{store: store}
|
||||
out.State = *cron7.ConstructState(cron7.BuiltInEntries())
|
||||
return &out, nil
|
||||
}
|
||||
|
||||
type state7 struct {
|
||||
cron7.State
|
||||
store adt.Store
|
||||
}
|
||||
|
||||
func (s *state7) GetState() interface{} {
|
||||
return &s.State
|
||||
}
|
@ -25,6 +25,8 @@ import (
|
||||
builtin5 "github.com/filecoin-project/specs-actors/v5/actors/builtin"
|
||||
|
||||
builtin6 "github.com/filecoin-project/specs-actors/v6/actors/builtin"
|
||||
|
||||
builtin7 "github.com/filecoin-project/specs-actors/v7/actors/builtin"
|
||||
)
|
||||
|
||||
func init() {
|
||||
@ -52,11 +54,15 @@ func init() {
|
||||
builtin.RegisterActorState(builtin6.InitActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
|
||||
return load6(store, root)
|
||||
})
|
||||
|
||||
builtin.RegisterActorState(builtin7.InitActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
|
||||
return load7(store, root)
|
||||
})
|
||||
}
|
||||
|
||||
var (
|
||||
Address = builtin6.InitActorAddr
|
||||
Methods = builtin6.MethodsInit
|
||||
Address = builtin7.InitActorAddr
|
||||
Methods = builtin7.MethodsInit
|
||||
)
|
||||
|
||||
func Load(store adt.Store, act *types.Actor) (State, error) {
|
||||
@ -80,6 +86,9 @@ func Load(store adt.Store, act *types.Actor) (State, error) {
|
||||
case builtin6.InitActorCodeID:
|
||||
return load6(store, act.Head)
|
||||
|
||||
case builtin7.InitActorCodeID:
|
||||
return load7(store, act.Head)
|
||||
|
||||
}
|
||||
return nil, xerrors.Errorf("unknown actor code %s", act.Code)
|
||||
}
|
||||
@ -105,6 +114,9 @@ func MakeState(store adt.Store, av actors.Version, networkName string) (State, e
|
||||
case actors.Version6:
|
||||
return make6(store, networkName)
|
||||
|
||||
case actors.Version7:
|
||||
return make7(store, networkName)
|
||||
|
||||
}
|
||||
return nil, xerrors.Errorf("unknown actor version %d", av)
|
||||
}
|
||||
@ -130,6 +142,9 @@ func GetActorCodeID(av actors.Version) (cid.Cid, error) {
|
||||
case actors.Version6:
|
||||
return builtin6.InitActorCodeID, nil
|
||||
|
||||
case actors.Version7:
|
||||
return builtin7.InitActorCodeID, nil
|
||||
|
||||
}
|
||||
|
||||
return cid.Undef, xerrors.Errorf("unknown actor version %d", av)
|
||||
|
114
chain/actors/builtin/init/v7.go
Normal file
114
chain/actors/builtin/init/v7.go
Normal file
@ -0,0 +1,114 @@
|
||||
package init
|
||||
|
||||
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"
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
"github.com/filecoin-project/lotus/chain/actors/adt"
|
||||
"github.com/filecoin-project/lotus/node/modules/dtypes"
|
||||
|
||||
builtin7 "github.com/filecoin-project/specs-actors/v7/actors/builtin"
|
||||
|
||||
init7 "github.com/filecoin-project/specs-actors/v7/actors/builtin/init"
|
||||
adt7 "github.com/filecoin-project/specs-actors/v7/actors/util/adt"
|
||||
)
|
||||
|
||||
var _ State = (*state7)(nil)
|
||||
|
||||
func load7(store adt.Store, root cid.Cid) (State, error) {
|
||||
out := state7{store: store}
|
||||
err := store.Get(store.Context(), root, &out)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &out, nil
|
||||
}
|
||||
|
||||
func make7(store adt.Store, networkName string) (State, error) {
|
||||
out := state7{store: store}
|
||||
|
||||
s, err := init7.ConstructState(store, networkName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
out.State = *s
|
||||
|
||||
return &out, nil
|
||||
}
|
||||
|
||||
type state7 struct {
|
||||
init7.State
|
||||
store adt.Store
|
||||
}
|
||||
|
||||
func (s *state7) ResolveAddress(address address.Address) (address.Address, bool, error) {
|
||||
return s.State.ResolveAddress(s.store, address)
|
||||
}
|
||||
|
||||
func (s *state7) MapAddressToNewID(address address.Address) (address.Address, error) {
|
||||
return s.State.MapAddressToNewID(s.store, address)
|
||||
}
|
||||
|
||||
func (s *state7) ForEachActor(cb func(id abi.ActorID, address address.Address) error) error {
|
||||
addrs, err := adt7.AsMap(s.store, s.State.AddressMap, builtin7.DefaultHamtBitwidth)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var actorID cbg.CborInt
|
||||
return addrs.ForEach(&actorID, func(key string) error {
|
||||
addr, err := address.NewFromBytes([]byte(key))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return cb(abi.ActorID(actorID), addr)
|
||||
})
|
||||
}
|
||||
|
||||
func (s *state7) NetworkName() (dtypes.NetworkName, error) {
|
||||
return dtypes.NetworkName(s.State.NetworkName), nil
|
||||
}
|
||||
|
||||
func (s *state7) SetNetworkName(name string) error {
|
||||
s.State.NetworkName = name
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *state7) SetNextID(id abi.ActorID) error {
|
||||
s.State.NextID = id
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *state7) Remove(addrs ...address.Address) (err error) {
|
||||
m, err := adt7.AsMap(s.store, s.State.AddressMap, builtin7.DefaultHamtBitwidth)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, addr := range addrs {
|
||||
if err = m.Delete(abi.AddrKey(addr)); err != nil {
|
||||
return xerrors.Errorf("failed to delete entry for address: %s; err: %w", addr, err)
|
||||
}
|
||||
}
|
||||
amr, err := m.Root()
|
||||
if err != nil {
|
||||
return xerrors.Errorf("failed to get address map root: %w", err)
|
||||
}
|
||||
s.State.AddressMap = amr
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *state7) SetAddressMap(mcid cid.Cid) error {
|
||||
s.State.AddressMap = mcid
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *state7) AddressMap() (adt.Map, error) {
|
||||
return adt7.AsMap(s.store, s.State.AddressMap, builtin7.DefaultHamtBitwidth)
|
||||
}
|
||||
|
||||
func (s *state7) GetState() interface{} {
|
||||
return &s.State
|
||||
}
|
@ -25,6 +25,8 @@ import (
|
||||
|
||||
builtin6 "github.com/filecoin-project/specs-actors/v6/actors/builtin"
|
||||
|
||||
builtin7 "github.com/filecoin-project/specs-actors/v7/actors/builtin"
|
||||
|
||||
"github.com/filecoin-project/lotus/chain/actors"
|
||||
"github.com/filecoin-project/lotus/chain/actors/adt"
|
||||
"github.com/filecoin-project/lotus/chain/actors/builtin"
|
||||
@ -56,11 +58,15 @@ func init() {
|
||||
builtin.RegisterActorState(builtin6.StorageMarketActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
|
||||
return load6(store, root)
|
||||
})
|
||||
|
||||
builtin.RegisterActorState(builtin7.StorageMarketActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
|
||||
return load7(store, root)
|
||||
})
|
||||
}
|
||||
|
||||
var (
|
||||
Address = builtin6.StorageMarketActorAddr
|
||||
Methods = builtin6.MethodsMarket
|
||||
Address = builtin7.StorageMarketActorAddr
|
||||
Methods = builtin7.MethodsMarket
|
||||
)
|
||||
|
||||
func Load(store adt.Store, act *types.Actor) (State, error) {
|
||||
@ -84,6 +90,9 @@ func Load(store adt.Store, act *types.Actor) (State, error) {
|
||||
case builtin6.StorageMarketActorCodeID:
|
||||
return load6(store, act.Head)
|
||||
|
||||
case builtin7.StorageMarketActorCodeID:
|
||||
return load7(store, act.Head)
|
||||
|
||||
}
|
||||
return nil, xerrors.Errorf("unknown actor code %s", act.Code)
|
||||
}
|
||||
@ -109,6 +118,9 @@ func MakeState(store adt.Store, av actors.Version) (State, error) {
|
||||
case actors.Version6:
|
||||
return make6(store)
|
||||
|
||||
case actors.Version7:
|
||||
return make7(store)
|
||||
|
||||
}
|
||||
return nil, xerrors.Errorf("unknown actor version %d", av)
|
||||
}
|
||||
@ -134,6 +146,9 @@ func GetActorCodeID(av actors.Version) (cid.Cid, error) {
|
||||
case actors.Version6:
|
||||
return builtin6.StorageMarketActorCodeID, nil
|
||||
|
||||
case actors.Version7:
|
||||
return builtin7.StorageMarketActorCodeID, nil
|
||||
|
||||
}
|
||||
|
||||
return cid.Undef, xerrors.Errorf("unknown actor version %d", av)
|
||||
@ -211,6 +226,9 @@ func DecodePublishStorageDealsReturn(b []byte, nv network.Version) (PublishStora
|
||||
case actors.Version6:
|
||||
return decodePublishStorageDealsReturn6(b)
|
||||
|
||||
case actors.Version7:
|
||||
return decodePublishStorageDealsReturn7(b)
|
||||
|
||||
}
|
||||
return nil, xerrors.Errorf("unknown actor version %d", av)
|
||||
}
|
||||
|
252
chain/actors/builtin/market/v7.go
Normal file
252
chain/actors/builtin/market/v7.go
Normal file
@ -0,0 +1,252 @@
|
||||
package market
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
|
||||
"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"
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
"github.com/filecoin-project/lotus/chain/actors/adt"
|
||||
"github.com/filecoin-project/lotus/chain/types"
|
||||
|
||||
market7 "github.com/filecoin-project/specs-actors/v7/actors/builtin/market"
|
||||
adt7 "github.com/filecoin-project/specs-actors/v7/actors/util/adt"
|
||||
)
|
||||
|
||||
var _ State = (*state7)(nil)
|
||||
|
||||
func load7(store adt.Store, root cid.Cid) (State, error) {
|
||||
out := state7{store: store}
|
||||
err := store.Get(store.Context(), root, &out)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &out, nil
|
||||
}
|
||||
|
||||
func make7(store adt.Store) (State, error) {
|
||||
out := state7{store: store}
|
||||
|
||||
s, err := market7.ConstructState(store)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
out.State = *s
|
||||
|
||||
return &out, nil
|
||||
}
|
||||
|
||||
type state7 struct {
|
||||
market7.State
|
||||
store adt.Store
|
||||
}
|
||||
|
||||
func (s *state7) TotalLocked() (abi.TokenAmount, error) {
|
||||
fml := types.BigAdd(s.TotalClientLockedCollateral, s.TotalProviderLockedCollateral)
|
||||
fml = types.BigAdd(fml, s.TotalClientStorageFee)
|
||||
return fml, nil
|
||||
}
|
||||
|
||||
func (s *state7) BalancesChanged(otherState State) (bool, error) {
|
||||
otherState7, ok := otherState.(*state7)
|
||||
if !ok {
|
||||
// there's no way to compare different versions of the state, so let's
|
||||
// just say that means the state of balances has changed
|
||||
return true, nil
|
||||
}
|
||||
return !s.State.EscrowTable.Equals(otherState7.State.EscrowTable) || !s.State.LockedTable.Equals(otherState7.State.LockedTable), nil
|
||||
}
|
||||
|
||||
func (s *state7) StatesChanged(otherState State) (bool, error) {
|
||||
otherState7, ok := otherState.(*state7)
|
||||
if !ok {
|
||||
// there's no way to compare different versions of the state, so let's
|
||||
// just say that means the state of balances has changed
|
||||
return true, nil
|
||||
}
|
||||
return !s.State.States.Equals(otherState7.State.States), nil
|
||||
}
|
||||
|
||||
func (s *state7) States() (DealStates, error) {
|
||||
stateArray, err := adt7.AsArray(s.store, s.State.States, market7.StatesAmtBitwidth)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &dealStates7{stateArray}, nil
|
||||
}
|
||||
|
||||
func (s *state7) ProposalsChanged(otherState State) (bool, error) {
|
||||
otherState7, ok := otherState.(*state7)
|
||||
if !ok {
|
||||
// there's no way to compare different versions of the state, so let's
|
||||
// just say that means the state of balances has changed
|
||||
return true, nil
|
||||
}
|
||||
return !s.State.Proposals.Equals(otherState7.State.Proposals), nil
|
||||
}
|
||||
|
||||
func (s *state7) Proposals() (DealProposals, error) {
|
||||
proposalArray, err := adt7.AsArray(s.store, s.State.Proposals, market7.ProposalsAmtBitwidth)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &dealProposals7{proposalArray}, nil
|
||||
}
|
||||
|
||||
func (s *state7) EscrowTable() (BalanceTable, error) {
|
||||
bt, err := adt7.AsBalanceTable(s.store, s.State.EscrowTable)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &balanceTable7{bt}, nil
|
||||
}
|
||||
|
||||
func (s *state7) LockedTable() (BalanceTable, error) {
|
||||
bt, err := adt7.AsBalanceTable(s.store, s.State.LockedTable)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &balanceTable7{bt}, nil
|
||||
}
|
||||
|
||||
func (s *state7) VerifyDealsForActivation(
|
||||
minerAddr address.Address, deals []abi.DealID, currEpoch, sectorExpiry abi.ChainEpoch,
|
||||
) (weight, verifiedWeight abi.DealWeight, err error) {
|
||||
w, vw, _, err := market7.ValidateDealsForActivation(&s.State, s.store, deals, minerAddr, sectorExpiry, currEpoch)
|
||||
return w, vw, err
|
||||
}
|
||||
|
||||
func (s *state7) NextID() (abi.DealID, error) {
|
||||
return s.State.NextID, nil
|
||||
}
|
||||
|
||||
type balanceTable7 struct {
|
||||
*adt7.BalanceTable
|
||||
}
|
||||
|
||||
func (bt *balanceTable7) ForEach(cb func(address.Address, abi.TokenAmount) error) error {
|
||||
asMap := (*adt7.Map)(bt.BalanceTable)
|
||||
var ta abi.TokenAmount
|
||||
return asMap.ForEach(&ta, func(key string) error {
|
||||
a, err := address.NewFromBytes([]byte(key))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return cb(a, ta)
|
||||
})
|
||||
}
|
||||
|
||||
type dealStates7 struct {
|
||||
adt.Array
|
||||
}
|
||||
|
||||
func (s *dealStates7) Get(dealID abi.DealID) (*DealState, bool, error) {
|
||||
var deal7 market7.DealState
|
||||
found, err := s.Array.Get(uint64(dealID), &deal7)
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
if !found {
|
||||
return nil, false, nil
|
||||
}
|
||||
deal := fromV7DealState(deal7)
|
||||
return &deal, true, nil
|
||||
}
|
||||
|
||||
func (s *dealStates7) ForEach(cb func(dealID abi.DealID, ds DealState) error) error {
|
||||
var ds7 market7.DealState
|
||||
return s.Array.ForEach(&ds7, func(idx int64) error {
|
||||
return cb(abi.DealID(idx), fromV7DealState(ds7))
|
||||
})
|
||||
}
|
||||
|
||||
func (s *dealStates7) decode(val *cbg.Deferred) (*DealState, error) {
|
||||
var ds7 market7.DealState
|
||||
if err := ds7.UnmarshalCBOR(bytes.NewReader(val.Raw)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ds := fromV7DealState(ds7)
|
||||
return &ds, nil
|
||||
}
|
||||
|
||||
func (s *dealStates7) array() adt.Array {
|
||||
return s.Array
|
||||
}
|
||||
|
||||
func fromV7DealState(v7 market7.DealState) DealState {
|
||||
return (DealState)(v7)
|
||||
}
|
||||
|
||||
type dealProposals7 struct {
|
||||
adt.Array
|
||||
}
|
||||
|
||||
func (s *dealProposals7) Get(dealID abi.DealID) (*DealProposal, bool, error) {
|
||||
var proposal7 market7.DealProposal
|
||||
found, err := s.Array.Get(uint64(dealID), &proposal7)
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
if !found {
|
||||
return nil, false, nil
|
||||
}
|
||||
proposal := fromV7DealProposal(proposal7)
|
||||
return &proposal, true, nil
|
||||
}
|
||||
|
||||
func (s *dealProposals7) ForEach(cb func(dealID abi.DealID, dp DealProposal) error) error {
|
||||
var dp7 market7.DealProposal
|
||||
return s.Array.ForEach(&dp7, func(idx int64) error {
|
||||
return cb(abi.DealID(idx), fromV7DealProposal(dp7))
|
||||
})
|
||||
}
|
||||
|
||||
func (s *dealProposals7) decode(val *cbg.Deferred) (*DealProposal, error) {
|
||||
var dp7 market7.DealProposal
|
||||
if err := dp7.UnmarshalCBOR(bytes.NewReader(val.Raw)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
dp := fromV7DealProposal(dp7)
|
||||
return &dp, nil
|
||||
}
|
||||
|
||||
func (s *dealProposals7) array() adt.Array {
|
||||
return s.Array
|
||||
}
|
||||
|
||||
func fromV7DealProposal(v7 market7.DealProposal) DealProposal {
|
||||
return (DealProposal)(v7)
|
||||
}
|
||||
|
||||
func (s *state7) GetState() interface{} {
|
||||
return &s.State
|
||||
}
|
||||
|
||||
var _ PublishStorageDealsReturn = (*publishStorageDealsReturn7)(nil)
|
||||
|
||||
func decodePublishStorageDealsReturn7(b []byte) (PublishStorageDealsReturn, error) {
|
||||
var retval market7.PublishStorageDealsReturn
|
||||
if err := retval.UnmarshalCBOR(bytes.NewReader(b)); err != nil {
|
||||
return nil, xerrors.Errorf("failed to unmarshal PublishStorageDealsReturn: %w", err)
|
||||
}
|
||||
|
||||
return &publishStorageDealsReturn7{retval}, nil
|
||||
}
|
||||
|
||||
type publishStorageDealsReturn7 struct {
|
||||
market7.PublishStorageDealsReturn
|
||||
}
|
||||
|
||||
func (r *publishStorageDealsReturn7) IsDealValid(index uint64) (bool, error) {
|
||||
|
||||
return r.ValidDeals.IsSet(index)
|
||||
|
||||
}
|
||||
|
||||
func (r *publishStorageDealsReturn7) DealIDs() ([]abi.DealID, error) {
|
||||
return r.IDs, nil
|
||||
}
|
@ -177,6 +177,7 @@ type SectorOnChainInfo struct {
|
||||
InitialPledge abi.TokenAmount
|
||||
ExpectedDayReward abi.TokenAmount
|
||||
ExpectedStoragePledge abi.TokenAmount
|
||||
SectorKeyCID *cid.Cid
|
||||
}
|
||||
|
||||
type SectorPreCommitInfo = miner0.SectorPreCommitInfo
|
||||
|
@ -35,6 +35,8 @@ import (
|
||||
builtin5 "github.com/filecoin-project/specs-actors/v5/actors/builtin"
|
||||
|
||||
builtin6 "github.com/filecoin-project/specs-actors/v6/actors/builtin"
|
||||
|
||||
builtin7 "github.com/filecoin-project/specs-actors/v7/actors/builtin"
|
||||
)
|
||||
|
||||
func init() {
|
||||
@ -63,9 +65,13 @@ func init() {
|
||||
return load6(store, root)
|
||||
})
|
||||
|
||||
builtin.RegisterActorState(builtin7.StorageMinerActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
|
||||
return load7(store, root)
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
var Methods = builtin6.MethodsMiner
|
||||
var Methods = builtin7.MethodsMiner
|
||||
|
||||
// Unchanged between v0, v2, v3, v4, and v5 actors
|
||||
var WPoStProvingPeriod = miner0.WPoStProvingPeriod
|
||||
@ -102,6 +108,9 @@ func Load(store adt.Store, act *types.Actor) (State, error) {
|
||||
case builtin6.StorageMinerActorCodeID:
|
||||
return load6(store, act.Head)
|
||||
|
||||
case builtin7.StorageMinerActorCodeID:
|
||||
return load7(store, act.Head)
|
||||
|
||||
}
|
||||
return nil, xerrors.Errorf("unknown actor code %s", act.Code)
|
||||
}
|
||||
@ -127,6 +136,9 @@ func MakeState(store adt.Store, av actors.Version) (State, error) {
|
||||
case actors.Version6:
|
||||
return make6(store)
|
||||
|
||||
case actors.Version7:
|
||||
return make7(store)
|
||||
|
||||
}
|
||||
return nil, xerrors.Errorf("unknown actor version %d", av)
|
||||
}
|
||||
@ -152,6 +164,9 @@ func GetActorCodeID(av actors.Version) (cid.Cid, error) {
|
||||
case actors.Version6:
|
||||
return builtin6.StorageMinerActorCodeID, nil
|
||||
|
||||
case actors.Version7:
|
||||
return builtin7.StorageMinerActorCodeID, nil
|
||||
|
||||
}
|
||||
|
||||
return cid.Undef, xerrors.Errorf("unknown actor version %d", av)
|
||||
@ -251,6 +266,7 @@ type SectorOnChainInfo struct {
|
||||
InitialPledge abi.TokenAmount
|
||||
ExpectedDayReward abi.TokenAmount
|
||||
ExpectedStoragePledge abi.TokenAmount
|
||||
SectorKeyCID *cid.Cid
|
||||
}
|
||||
|
||||
type SectorPreCommitInfo = miner0.SectorPreCommitInfo
|
||||
|
@ -138,11 +138,22 @@ func (s *state{{.v}}) GetSectorExpiration(num abi.SectorNumber) (*SectorExpirati
|
||||
return nil, err
|
||||
}
|
||||
// NOTE: this can be optimized significantly.
|
||||
// 1. If the sector is non-faulty, it will either expire on-time (can be
|
||||
{{if (ge .v 7) -}}
|
||||
// 1. If the sector is non-faulty, it will expire on-time (can be
|
||||
// learned from the sector info).
|
||||
{{- else -}}
|
||||
// 1. If the sector is non-faulty, it will either expire on-time (can be
|
||||
// learned from the sector info), or in the next quantized expiration
|
||||
// epoch (i.e., the first element in the partition's expiration queue.
|
||||
{{- end}}
|
||||
{{if (ge .v 6) -}}
|
||||
// 2. If it's faulty, it will expire early within the first 42 entries
|
||||
// of the expiration queue.
|
||||
{{- else -}}
|
||||
// 2. If it's faulty, it will expire early within the first 14 entries
|
||||
// of the expiration queue.
|
||||
{{- end}}
|
||||
|
||||
stopErr := errors.New("stop")
|
||||
out := SectorExpiration{}
|
||||
err = dls.ForEach(s.store, func(dlIdx uint64, dl *miner{{.v}}.Deadline) error {
|
||||
@ -554,8 +565,7 @@ func (p *partition{{.v}}) UnprovenSectors() (bitfield.BitField, error) {
|
||||
}
|
||||
|
||||
func fromV{{.v}}SectorOnChainInfo(v{{.v}} miner{{.v}}.SectorOnChainInfo) SectorOnChainInfo {
|
||||
{{if (ge .v 2)}}
|
||||
return SectorOnChainInfo{
|
||||
info := SectorOnChainInfo{
|
||||
SectorNumber: v{{.v}}.SectorNumber,
|
||||
SealProof: v{{.v}}.SealProof,
|
||||
SealedCID: v{{.v}}.SealedCID,
|
||||
@ -567,10 +577,11 @@ func fromV{{.v}}SectorOnChainInfo(v{{.v}} miner{{.v}}.SectorOnChainInfo) SectorO
|
||||
InitialPledge: v{{.v}}.InitialPledge,
|
||||
ExpectedDayReward: v{{.v}}.ExpectedDayReward,
|
||||
ExpectedStoragePledge: v{{.v}}.ExpectedStoragePledge,
|
||||
{{if (ge .v 7)}}
|
||||
SectorKeyCID: v{{.v}}.SectorKeyCID,
|
||||
{{end}}
|
||||
}
|
||||
{{else}}
|
||||
return (SectorOnChainInfo)(v0)
|
||||
{{end}}
|
||||
return info
|
||||
}
|
||||
|
||||
func fromV{{.v}}SectorPreCommitOnChainInfo(v{{.v}} miner{{.v}}.SectorPreCommitOnChainInfo) SectorPreCommitOnChainInfo {
|
||||
|
@ -140,6 +140,7 @@ func (s *state0) GetSectorExpiration(num abi.SectorNumber) (*SectorExpiration, e
|
||||
// epoch (i.e., the first element in the partition's expiration queue.
|
||||
// 2. If it's faulty, it will expire early within the first 14 entries
|
||||
// of the expiration queue.
|
||||
|
||||
stopErr := errors.New("stop")
|
||||
out := SectorExpiration{}
|
||||
err = dls.ForEach(s.store, func(dlIdx uint64, dl *miner0.Deadline) error {
|
||||
@ -505,9 +506,20 @@ func (p *partition0) UnprovenSectors() (bitfield.BitField, error) {
|
||||
}
|
||||
|
||||
func fromV0SectorOnChainInfo(v0 miner0.SectorOnChainInfo) SectorOnChainInfo {
|
||||
|
||||
return (SectorOnChainInfo)(v0)
|
||||
|
||||
info := SectorOnChainInfo{
|
||||
SectorNumber: v0.SectorNumber,
|
||||
SealProof: v0.SealProof,
|
||||
SealedCID: v0.SealedCID,
|
||||
DealIDs: v0.DealIDs,
|
||||
Activation: v0.Activation,
|
||||
Expiration: v0.Expiration,
|
||||
DealWeight: v0.DealWeight,
|
||||
VerifiedDealWeight: v0.VerifiedDealWeight,
|
||||
InitialPledge: v0.InitialPledge,
|
||||
ExpectedDayReward: v0.ExpectedDayReward,
|
||||
ExpectedStoragePledge: v0.ExpectedStoragePledge,
|
||||
}
|
||||
return info
|
||||
}
|
||||
|
||||
func fromV0SectorPreCommitOnChainInfo(v0 miner0.SectorPreCommitOnChainInfo) SectorPreCommitOnChainInfo {
|
||||
|
@ -138,6 +138,7 @@ func (s *state2) GetSectorExpiration(num abi.SectorNumber) (*SectorExpiration, e
|
||||
// epoch (i.e., the first element in the partition's expiration queue.
|
||||
// 2. If it's faulty, it will expire early within the first 14 entries
|
||||
// of the expiration queue.
|
||||
|
||||
stopErr := errors.New("stop")
|
||||
out := SectorExpiration{}
|
||||
err = dls.ForEach(s.store, func(dlIdx uint64, dl *miner2.Deadline) error {
|
||||
@ -535,8 +536,7 @@ func (p *partition2) UnprovenSectors() (bitfield.BitField, error) {
|
||||
}
|
||||
|
||||
func fromV2SectorOnChainInfo(v2 miner2.SectorOnChainInfo) SectorOnChainInfo {
|
||||
|
||||
return SectorOnChainInfo{
|
||||
info := SectorOnChainInfo{
|
||||
SectorNumber: v2.SectorNumber,
|
||||
SealProof: v2.SealProof,
|
||||
SealedCID: v2.SealedCID,
|
||||
@ -549,7 +549,7 @@ func fromV2SectorOnChainInfo(v2 miner2.SectorOnChainInfo) SectorOnChainInfo {
|
||||
ExpectedDayReward: v2.ExpectedDayReward,
|
||||
ExpectedStoragePledge: v2.ExpectedStoragePledge,
|
||||
}
|
||||
|
||||
return info
|
||||
}
|
||||
|
||||
func fromV2SectorPreCommitOnChainInfo(v2 miner2.SectorPreCommitOnChainInfo) SectorPreCommitOnChainInfo {
|
||||
|
@ -140,6 +140,7 @@ func (s *state3) GetSectorExpiration(num abi.SectorNumber) (*SectorExpiration, e
|
||||
// epoch (i.e., the first element in the partition's expiration queue.
|
||||
// 2. If it's faulty, it will expire early within the first 14 entries
|
||||
// of the expiration queue.
|
||||
|
||||
stopErr := errors.New("stop")
|
||||
out := SectorExpiration{}
|
||||
err = dls.ForEach(s.store, func(dlIdx uint64, dl *miner3.Deadline) error {
|
||||
@ -536,8 +537,7 @@ func (p *partition3) UnprovenSectors() (bitfield.BitField, error) {
|
||||
}
|
||||
|
||||
func fromV3SectorOnChainInfo(v3 miner3.SectorOnChainInfo) SectorOnChainInfo {
|
||||
|
||||
return SectorOnChainInfo{
|
||||
info := SectorOnChainInfo{
|
||||
SectorNumber: v3.SectorNumber,
|
||||
SealProof: v3.SealProof,
|
||||
SealedCID: v3.SealedCID,
|
||||
@ -550,7 +550,7 @@ func fromV3SectorOnChainInfo(v3 miner3.SectorOnChainInfo) SectorOnChainInfo {
|
||||
ExpectedDayReward: v3.ExpectedDayReward,
|
||||
ExpectedStoragePledge: v3.ExpectedStoragePledge,
|
||||
}
|
||||
|
||||
return info
|
||||
}
|
||||
|
||||
func fromV3SectorPreCommitOnChainInfo(v3 miner3.SectorPreCommitOnChainInfo) SectorPreCommitOnChainInfo {
|
||||
|
@ -140,6 +140,7 @@ func (s *state4) GetSectorExpiration(num abi.SectorNumber) (*SectorExpiration, e
|
||||
// epoch (i.e., the first element in the partition's expiration queue.
|
||||
// 2. If it's faulty, it will expire early within the first 14 entries
|
||||
// of the expiration queue.
|
||||
|
||||
stopErr := errors.New("stop")
|
||||
out := SectorExpiration{}
|
||||
err = dls.ForEach(s.store, func(dlIdx uint64, dl *miner4.Deadline) error {
|
||||
@ -536,8 +537,7 @@ func (p *partition4) UnprovenSectors() (bitfield.BitField, error) {
|
||||
}
|
||||
|
||||
func fromV4SectorOnChainInfo(v4 miner4.SectorOnChainInfo) SectorOnChainInfo {
|
||||
|
||||
return SectorOnChainInfo{
|
||||
info := SectorOnChainInfo{
|
||||
SectorNumber: v4.SectorNumber,
|
||||
SealProof: v4.SealProof,
|
||||
SealedCID: v4.SealedCID,
|
||||
@ -550,7 +550,7 @@ func fromV4SectorOnChainInfo(v4 miner4.SectorOnChainInfo) SectorOnChainInfo {
|
||||
ExpectedDayReward: v4.ExpectedDayReward,
|
||||
ExpectedStoragePledge: v4.ExpectedStoragePledge,
|
||||
}
|
||||
|
||||
return info
|
||||
}
|
||||
|
||||
func fromV4SectorPreCommitOnChainInfo(v4 miner4.SectorPreCommitOnChainInfo) SectorPreCommitOnChainInfo {
|
||||
|
@ -140,6 +140,7 @@ func (s *state5) GetSectorExpiration(num abi.SectorNumber) (*SectorExpiration, e
|
||||
// epoch (i.e., the first element in the partition's expiration queue.
|
||||
// 2. If it's faulty, it will expire early within the first 14 entries
|
||||
// of the expiration queue.
|
||||
|
||||
stopErr := errors.New("stop")
|
||||
out := SectorExpiration{}
|
||||
err = dls.ForEach(s.store, func(dlIdx uint64, dl *miner5.Deadline) error {
|
||||
@ -536,8 +537,7 @@ func (p *partition5) UnprovenSectors() (bitfield.BitField, error) {
|
||||
}
|
||||
|
||||
func fromV5SectorOnChainInfo(v5 miner5.SectorOnChainInfo) SectorOnChainInfo {
|
||||
|
||||
return SectorOnChainInfo{
|
||||
info := SectorOnChainInfo{
|
||||
SectorNumber: v5.SectorNumber,
|
||||
SealProof: v5.SealProof,
|
||||
SealedCID: v5.SealedCID,
|
||||
@ -550,7 +550,7 @@ func fromV5SectorOnChainInfo(v5 miner5.SectorOnChainInfo) SectorOnChainInfo {
|
||||
ExpectedDayReward: v5.ExpectedDayReward,
|
||||
ExpectedStoragePledge: v5.ExpectedStoragePledge,
|
||||
}
|
||||
|
||||
return info
|
||||
}
|
||||
|
||||
func fromV5SectorPreCommitOnChainInfo(v5 miner5.SectorPreCommitOnChainInfo) SectorPreCommitOnChainInfo {
|
||||
|
@ -138,8 +138,9 @@ func (s *state6) GetSectorExpiration(num abi.SectorNumber) (*SectorExpiration, e
|
||||
// 1. If the sector is non-faulty, it will either expire on-time (can be
|
||||
// learned from the sector info), or in the next quantized expiration
|
||||
// epoch (i.e., the first element in the partition's expiration queue.
|
||||
// 2. If it's faulty, it will expire early within the first 14 entries
|
||||
// 2. If it's faulty, it will expire early within the first 42 entries
|
||||
// of the expiration queue.
|
||||
|
||||
stopErr := errors.New("stop")
|
||||
out := SectorExpiration{}
|
||||
err = dls.ForEach(s.store, func(dlIdx uint64, dl *miner6.Deadline) error {
|
||||
@ -536,8 +537,7 @@ func (p *partition6) UnprovenSectors() (bitfield.BitField, error) {
|
||||
}
|
||||
|
||||
func fromV6SectorOnChainInfo(v6 miner6.SectorOnChainInfo) SectorOnChainInfo {
|
||||
|
||||
return SectorOnChainInfo{
|
||||
info := SectorOnChainInfo{
|
||||
SectorNumber: v6.SectorNumber,
|
||||
SealProof: v6.SealProof,
|
||||
SealedCID: v6.SealedCID,
|
||||
@ -550,7 +550,7 @@ func fromV6SectorOnChainInfo(v6 miner6.SectorOnChainInfo) SectorOnChainInfo {
|
||||
ExpectedDayReward: v6.ExpectedDayReward,
|
||||
ExpectedStoragePledge: v6.ExpectedStoragePledge,
|
||||
}
|
||||
|
||||
return info
|
||||
}
|
||||
|
||||
func fromV6SectorPreCommitOnChainInfo(v6 miner6.SectorPreCommitOnChainInfo) SectorPreCommitOnChainInfo {
|
||||
|
571
chain/actors/builtin/miner/v7.go
Normal file
571
chain/actors/builtin/miner/v7.go
Normal file
@ -0,0 +1,571 @@
|
||||
package miner
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
|
||||
"github.com/filecoin-project/go-address"
|
||||
"github.com/filecoin-project/go-bitfield"
|
||||
rle "github.com/filecoin-project/go-bitfield/rle"
|
||||
"github.com/filecoin-project/go-state-types/abi"
|
||||
"github.com/filecoin-project/go-state-types/dline"
|
||||
"github.com/ipfs/go-cid"
|
||||
"github.com/libp2p/go-libp2p-core/peer"
|
||||
cbg "github.com/whyrusleeping/cbor-gen"
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
"github.com/filecoin-project/lotus/chain/actors/adt"
|
||||
|
||||
builtin7 "github.com/filecoin-project/specs-actors/v7/actors/builtin"
|
||||
|
||||
miner7 "github.com/filecoin-project/specs-actors/v7/actors/builtin/miner"
|
||||
adt7 "github.com/filecoin-project/specs-actors/v7/actors/util/adt"
|
||||
)
|
||||
|
||||
var _ State = (*state7)(nil)
|
||||
|
||||
func load7(store adt.Store, root cid.Cid) (State, error) {
|
||||
out := state7{store: store}
|
||||
err := store.Get(store.Context(), root, &out)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &out, nil
|
||||
}
|
||||
|
||||
func make7(store adt.Store) (State, error) {
|
||||
out := state7{store: store}
|
||||
out.State = miner7.State{}
|
||||
return &out, nil
|
||||
}
|
||||
|
||||
type state7 struct {
|
||||
miner7.State
|
||||
store adt.Store
|
||||
}
|
||||
|
||||
type deadline7 struct {
|
||||
miner7.Deadline
|
||||
store adt.Store
|
||||
}
|
||||
|
||||
type partition7 struct {
|
||||
miner7.Partition
|
||||
store adt.Store
|
||||
}
|
||||
|
||||
func (s *state7) AvailableBalance(bal abi.TokenAmount) (available abi.TokenAmount, err error) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
err = xerrors.Errorf("failed to get available balance: %w", r)
|
||||
available = abi.NewTokenAmount(0)
|
||||
}
|
||||
}()
|
||||
// this panics if the miner doesnt have enough funds to cover their locked pledge
|
||||
available, err = s.GetAvailableBalance(bal)
|
||||
return available, err
|
||||
}
|
||||
|
||||
func (s *state7) VestedFunds(epoch abi.ChainEpoch) (abi.TokenAmount, error) {
|
||||
return s.CheckVestedFunds(s.store, epoch)
|
||||
}
|
||||
|
||||
func (s *state7) LockedFunds() (LockedFunds, error) {
|
||||
return LockedFunds{
|
||||
VestingFunds: s.State.LockedFunds,
|
||||
InitialPledgeRequirement: s.State.InitialPledge,
|
||||
PreCommitDeposits: s.State.PreCommitDeposits,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *state7) FeeDebt() (abi.TokenAmount, error) {
|
||||
return s.State.FeeDebt, nil
|
||||
}
|
||||
|
||||
func (s *state7) InitialPledge() (abi.TokenAmount, error) {
|
||||
return s.State.InitialPledge, nil
|
||||
}
|
||||
|
||||
func (s *state7) PreCommitDeposits() (abi.TokenAmount, error) {
|
||||
return s.State.PreCommitDeposits, nil
|
||||
}
|
||||
|
||||
func (s *state7) GetSector(num abi.SectorNumber) (*SectorOnChainInfo, error) {
|
||||
info, ok, err := s.State.GetSector(s.store, num)
|
||||
if !ok || err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ret := fromV7SectorOnChainInfo(*info)
|
||||
return &ret, nil
|
||||
}
|
||||
|
||||
func (s *state7) FindSector(num abi.SectorNumber) (*SectorLocation, error) {
|
||||
dlIdx, partIdx, err := s.State.FindSector(s.store, num)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &SectorLocation{
|
||||
Deadline: dlIdx,
|
||||
Partition: partIdx,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *state7) NumLiveSectors() (uint64, error) {
|
||||
dls, err := s.State.LoadDeadlines(s.store)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
var total uint64
|
||||
if err := dls.ForEach(s.store, func(dlIdx uint64, dl *miner7.Deadline) error {
|
||||
total += dl.LiveSectors
|
||||
return nil
|
||||
}); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return total, nil
|
||||
}
|
||||
|
||||
// GetSectorExpiration returns the effective expiration of the given sector.
|
||||
//
|
||||
// If the sector does not expire early, the Early expiration field is 0.
|
||||
func (s *state7) GetSectorExpiration(num abi.SectorNumber) (*SectorExpiration, error) {
|
||||
dls, err := s.State.LoadDeadlines(s.store)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// NOTE: this can be optimized significantly.
|
||||
// 1. If the sector is non-faulty, it will expire on-time (can be
|
||||
// learned from the sector info).
|
||||
// 2. If it's faulty, it will expire early within the first 42 entries
|
||||
// of the expiration queue.
|
||||
|
||||
stopErr := errors.New("stop")
|
||||
out := SectorExpiration{}
|
||||
err = dls.ForEach(s.store, func(dlIdx uint64, dl *miner7.Deadline) error {
|
||||
partitions, err := dl.PartitionsArray(s.store)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
quant := s.State.QuantSpecForDeadline(dlIdx)
|
||||
var part miner7.Partition
|
||||
return partitions.ForEach(&part, func(partIdx int64) error {
|
||||
if found, err := part.Sectors.IsSet(uint64(num)); err != nil {
|
||||
return err
|
||||
} else if !found {
|
||||
return nil
|
||||
}
|
||||
if found, err := part.Terminated.IsSet(uint64(num)); err != nil {
|
||||
return err
|
||||
} else if found {
|
||||
// already terminated
|
||||
return stopErr
|
||||
}
|
||||
|
||||
q, err := miner7.LoadExpirationQueue(s.store, part.ExpirationsEpochs, quant, miner7.PartitionExpirationAmtBitwidth)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var exp miner7.ExpirationSet
|
||||
return q.ForEach(&exp, func(epoch int64) error {
|
||||
if early, err := exp.EarlySectors.IsSet(uint64(num)); err != nil {
|
||||
return err
|
||||
} else if early {
|
||||
out.Early = abi.ChainEpoch(epoch)
|
||||
return nil
|
||||
}
|
||||
if onTime, err := exp.OnTimeSectors.IsSet(uint64(num)); err != nil {
|
||||
return err
|
||||
} else if onTime {
|
||||
out.OnTime = abi.ChainEpoch(epoch)
|
||||
return stopErr
|
||||
}
|
||||
return nil
|
||||
})
|
||||
})
|
||||
})
|
||||
if err == stopErr {
|
||||
err = nil
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if out.Early == 0 && out.OnTime == 0 {
|
||||
return nil, xerrors.Errorf("failed to find sector %d", num)
|
||||
}
|
||||
return &out, nil
|
||||
}
|
||||
|
||||
func (s *state7) GetPrecommittedSector(num abi.SectorNumber) (*SectorPreCommitOnChainInfo, error) {
|
||||
info, ok, err := s.State.GetPrecommittedSector(s.store, num)
|
||||
if !ok || err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ret := fromV7SectorPreCommitOnChainInfo(*info)
|
||||
|
||||
return &ret, nil
|
||||
}
|
||||
|
||||
func (s *state7) ForEachPrecommittedSector(cb func(SectorPreCommitOnChainInfo) error) error {
|
||||
precommitted, err := adt7.AsMap(s.store, s.State.PreCommittedSectors, builtin7.DefaultHamtBitwidth)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var info miner7.SectorPreCommitOnChainInfo
|
||||
if err := precommitted.ForEach(&info, func(_ string) error {
|
||||
return cb(fromV7SectorPreCommitOnChainInfo(info))
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *state7) LoadSectors(snos *bitfield.BitField) ([]*SectorOnChainInfo, error) {
|
||||
sectors, err := miner7.LoadSectors(s.store, s.State.Sectors)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// If no sector numbers are specified, load all.
|
||||
if snos == nil {
|
||||
infos := make([]*SectorOnChainInfo, 0, sectors.Length())
|
||||
var info7 miner7.SectorOnChainInfo
|
||||
if err := sectors.ForEach(&info7, func(_ int64) error {
|
||||
info := fromV7SectorOnChainInfo(info7)
|
||||
infos = append(infos, &info)
|
||||
return nil
|
||||
}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return infos, nil
|
||||
}
|
||||
|
||||
// Otherwise, load selected.
|
||||
infos7, err := sectors.Load(*snos)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
infos := make([]*SectorOnChainInfo, len(infos7))
|
||||
for i, info7 := range infos7 {
|
||||
info := fromV7SectorOnChainInfo(*info7)
|
||||
infos[i] = &info
|
||||
}
|
||||
return infos, nil
|
||||
}
|
||||
|
||||
func (s *state7) loadAllocatedSectorNumbers() (bitfield.BitField, error) {
|
||||
var allocatedSectors bitfield.BitField
|
||||
err := s.store.Get(s.store.Context(), s.State.AllocatedSectors, &allocatedSectors)
|
||||
return allocatedSectors, err
|
||||
}
|
||||
|
||||
func (s *state7) IsAllocated(num abi.SectorNumber) (bool, error) {
|
||||
allocatedSectors, err := s.loadAllocatedSectorNumbers()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return allocatedSectors.IsSet(uint64(num))
|
||||
}
|
||||
|
||||
func (s *state7) GetProvingPeriodStart() (abi.ChainEpoch, error) {
|
||||
return s.State.ProvingPeriodStart, nil
|
||||
}
|
||||
|
||||
func (s *state7) UnallocatedSectorNumbers(count int) ([]abi.SectorNumber, error) {
|
||||
allocatedSectors, err := s.loadAllocatedSectorNumbers()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
allocatedRuns, err := allocatedSectors.RunIterator()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
unallocatedRuns, err := rle.Subtract(
|
||||
&rle.RunSliceIterator{Runs: []rle.Run{{Val: true, Len: abi.MaxSectorNumber}}},
|
||||
allocatedRuns,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
iter, err := rle.BitsFromRuns(unallocatedRuns)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
sectors := make([]abi.SectorNumber, 0, count)
|
||||
for iter.HasNext() && len(sectors) < count {
|
||||
nextNo, err := iter.Next()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
sectors = append(sectors, abi.SectorNumber(nextNo))
|
||||
}
|
||||
|
||||
return sectors, nil
|
||||
}
|
||||
|
||||
func (s *state7) GetAllocatedSectors() (*bitfield.BitField, error) {
|
||||
var allocatedSectors bitfield.BitField
|
||||
if err := s.store.Get(s.store.Context(), s.State.AllocatedSectors, &allocatedSectors); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &allocatedSectors, nil
|
||||
}
|
||||
|
||||
func (s *state7) LoadDeadline(idx uint64) (Deadline, error) {
|
||||
dls, err := s.State.LoadDeadlines(s.store)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
dl, err := dls.LoadDeadline(s.store, idx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &deadline7{*dl, s.store}, nil
|
||||
}
|
||||
|
||||
func (s *state7) ForEachDeadline(cb func(uint64, Deadline) error) error {
|
||||
dls, err := s.State.LoadDeadlines(s.store)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return dls.ForEach(s.store, func(i uint64, dl *miner7.Deadline) error {
|
||||
return cb(i, &deadline7{*dl, s.store})
|
||||
})
|
||||
}
|
||||
|
||||
func (s *state7) NumDeadlines() (uint64, error) {
|
||||
return miner7.WPoStPeriodDeadlines, nil
|
||||
}
|
||||
|
||||
func (s *state7) DeadlinesChanged(other State) (bool, error) {
|
||||
other7, ok := other.(*state7)
|
||||
if !ok {
|
||||
// treat an upgrade as a change, always
|
||||
return true, nil
|
||||
}
|
||||
|
||||
return !s.State.Deadlines.Equals(other7.Deadlines), nil
|
||||
}
|
||||
|
||||
func (s *state7) MinerInfoChanged(other State) (bool, error) {
|
||||
other0, ok := other.(*state7)
|
||||
if !ok {
|
||||
// treat an upgrade as a change, always
|
||||
return true, nil
|
||||
}
|
||||
return !s.State.Info.Equals(other0.State.Info), nil
|
||||
}
|
||||
|
||||
func (s *state7) Info() (MinerInfo, error) {
|
||||
info, err := s.State.GetInfo(s.store)
|
||||
if err != nil {
|
||||
return MinerInfo{}, err
|
||||
}
|
||||
|
||||
var pid *peer.ID
|
||||
if peerID, err := peer.IDFromBytes(info.PeerId); err == nil {
|
||||
pid = &peerID
|
||||
}
|
||||
|
||||
mi := MinerInfo{
|
||||
Owner: info.Owner,
|
||||
Worker: info.Worker,
|
||||
ControlAddresses: info.ControlAddresses,
|
||||
|
||||
NewWorker: address.Undef,
|
||||
WorkerChangeEpoch: -1,
|
||||
|
||||
PeerId: pid,
|
||||
Multiaddrs: info.Multiaddrs,
|
||||
WindowPoStProofType: info.WindowPoStProofType,
|
||||
SectorSize: info.SectorSize,
|
||||
WindowPoStPartitionSectors: info.WindowPoStPartitionSectors,
|
||||
ConsensusFaultElapsed: info.ConsensusFaultElapsed,
|
||||
}
|
||||
|
||||
if info.PendingWorkerKey != nil {
|
||||
mi.NewWorker = info.PendingWorkerKey.NewWorker
|
||||
mi.WorkerChangeEpoch = info.PendingWorkerKey.EffectiveAt
|
||||
}
|
||||
|
||||
return mi, nil
|
||||
}
|
||||
|
||||
func (s *state7) DeadlineInfo(epoch abi.ChainEpoch) (*dline.Info, error) {
|
||||
return s.State.RecordedDeadlineInfo(epoch), nil
|
||||
}
|
||||
|
||||
func (s *state7) DeadlineCronActive() (bool, error) {
|
||||
return s.State.DeadlineCronActive, nil
|
||||
}
|
||||
|
||||
func (s *state7) sectors() (adt.Array, error) {
|
||||
return adt7.AsArray(s.store, s.Sectors, miner7.SectorsAmtBitwidth)
|
||||
}
|
||||
|
||||
func (s *state7) decodeSectorOnChainInfo(val *cbg.Deferred) (SectorOnChainInfo, error) {
|
||||
var si miner7.SectorOnChainInfo
|
||||
err := si.UnmarshalCBOR(bytes.NewReader(val.Raw))
|
||||
if err != nil {
|
||||
return SectorOnChainInfo{}, err
|
||||
}
|
||||
|
||||
return fromV7SectorOnChainInfo(si), nil
|
||||
}
|
||||
|
||||
func (s *state7) precommits() (adt.Map, error) {
|
||||
return adt7.AsMap(s.store, s.PreCommittedSectors, builtin7.DefaultHamtBitwidth)
|
||||
}
|
||||
|
||||
func (s *state7) decodeSectorPreCommitOnChainInfo(val *cbg.Deferred) (SectorPreCommitOnChainInfo, error) {
|
||||
var sp miner7.SectorPreCommitOnChainInfo
|
||||
err := sp.UnmarshalCBOR(bytes.NewReader(val.Raw))
|
||||
if err != nil {
|
||||
return SectorPreCommitOnChainInfo{}, err
|
||||
}
|
||||
|
||||
return fromV7SectorPreCommitOnChainInfo(sp), nil
|
||||
}
|
||||
|
||||
func (s *state7) EraseAllUnproven() error {
|
||||
|
||||
dls, err := s.State.LoadDeadlines(s.store)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = dls.ForEach(s.store, func(dindx uint64, dl *miner7.Deadline) error {
|
||||
ps, err := dl.PartitionsArray(s.store)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var part miner7.Partition
|
||||
err = ps.ForEach(&part, func(pindx int64) error {
|
||||
_ = part.ActivateUnproven()
|
||||
err = ps.Set(uint64(pindx), &part)
|
||||
return nil
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
dl.Partitions, err = ps.Root()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return dls.UpdateDeadline(s.store, dindx, dl)
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return s.State.SaveDeadlines(s.store, dls)
|
||||
|
||||
}
|
||||
|
||||
func (d *deadline7) LoadPartition(idx uint64) (Partition, error) {
|
||||
p, err := d.Deadline.LoadPartition(d.store, idx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &partition7{*p, d.store}, nil
|
||||
}
|
||||
|
||||
func (d *deadline7) ForEachPartition(cb func(uint64, Partition) error) error {
|
||||
ps, err := d.Deadline.PartitionsArray(d.store)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var part miner7.Partition
|
||||
return ps.ForEach(&part, func(i int64) error {
|
||||
return cb(uint64(i), &partition7{part, d.store})
|
||||
})
|
||||
}
|
||||
|
||||
func (d *deadline7) PartitionsChanged(other Deadline) (bool, error) {
|
||||
other7, ok := other.(*deadline7)
|
||||
if !ok {
|
||||
// treat an upgrade as a change, always
|
||||
return true, nil
|
||||
}
|
||||
|
||||
return !d.Deadline.Partitions.Equals(other7.Deadline.Partitions), nil
|
||||
}
|
||||
|
||||
func (d *deadline7) PartitionsPoSted() (bitfield.BitField, error) {
|
||||
return d.Deadline.PartitionsPoSted, nil
|
||||
}
|
||||
|
||||
func (d *deadline7) DisputableProofCount() (uint64, error) {
|
||||
|
||||
ops, err := d.OptimisticProofsSnapshotArray(d.store)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return ops.Length(), nil
|
||||
|
||||
}
|
||||
|
||||
func (p *partition7) AllSectors() (bitfield.BitField, error) {
|
||||
return p.Partition.Sectors, nil
|
||||
}
|
||||
|
||||
func (p *partition7) FaultySectors() (bitfield.BitField, error) {
|
||||
return p.Partition.Faults, nil
|
||||
}
|
||||
|
||||
func (p *partition7) RecoveringSectors() (bitfield.BitField, error) {
|
||||
return p.Partition.Recoveries, nil
|
||||
}
|
||||
|
||||
func (p *partition7) UnprovenSectors() (bitfield.BitField, error) {
|
||||
return p.Partition.Unproven, nil
|
||||
}
|
||||
|
||||
func fromV7SectorOnChainInfo(v7 miner7.SectorOnChainInfo) SectorOnChainInfo {
|
||||
info := SectorOnChainInfo{
|
||||
SectorNumber: v7.SectorNumber,
|
||||
SealProof: v7.SealProof,
|
||||
SealedCID: v7.SealedCID,
|
||||
DealIDs: v7.DealIDs,
|
||||
Activation: v7.Activation,
|
||||
Expiration: v7.Expiration,
|
||||
DealWeight: v7.DealWeight,
|
||||
VerifiedDealWeight: v7.VerifiedDealWeight,
|
||||
InitialPledge: v7.InitialPledge,
|
||||
ExpectedDayReward: v7.ExpectedDayReward,
|
||||
ExpectedStoragePledge: v7.ExpectedStoragePledge,
|
||||
|
||||
SectorKeyCID: v7.SectorKeyCID,
|
||||
}
|
||||
return info
|
||||
}
|
||||
|
||||
func fromV7SectorPreCommitOnChainInfo(v7 miner7.SectorPreCommitOnChainInfo) SectorPreCommitOnChainInfo {
|
||||
|
||||
return SectorPreCommitOnChainInfo{
|
||||
Info: (SectorPreCommitInfo)(v7.Info),
|
||||
PreCommitDeposit: v7.PreCommitDeposit,
|
||||
PreCommitEpoch: v7.PreCommitEpoch,
|
||||
DealWeight: v7.DealWeight,
|
||||
VerifiedDealWeight: v7.VerifiedDealWeight,
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (s *state7) GetState() interface{} {
|
||||
return &s.State
|
||||
}
|
71
chain/actors/builtin/multisig/message7.go
Normal file
71
chain/actors/builtin/multisig/message7.go
Normal file
@ -0,0 +1,71 @@
|
||||
package multisig
|
||||
|
||||
import (
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
"github.com/filecoin-project/go-address"
|
||||
"github.com/filecoin-project/go-state-types/abi"
|
||||
|
||||
builtin7 "github.com/filecoin-project/specs-actors/v7/actors/builtin"
|
||||
init7 "github.com/filecoin-project/specs-actors/v7/actors/builtin/init"
|
||||
multisig7 "github.com/filecoin-project/specs-actors/v7/actors/builtin/multisig"
|
||||
|
||||
"github.com/filecoin-project/lotus/chain/actors"
|
||||
init_ "github.com/filecoin-project/lotus/chain/actors/builtin/init"
|
||||
"github.com/filecoin-project/lotus/chain/types"
|
||||
)
|
||||
|
||||
type message7 struct{ message0 }
|
||||
|
||||
func (m message7) Create(
|
||||
signers []address.Address, threshold uint64,
|
||||
unlockStart, unlockDuration abi.ChainEpoch,
|
||||
initialAmount abi.TokenAmount,
|
||||
) (*types.Message, error) {
|
||||
|
||||
lenAddrs := uint64(len(signers))
|
||||
|
||||
if lenAddrs < threshold {
|
||||
return nil, xerrors.Errorf("cannot require signing of more addresses than provided for multisig")
|
||||
}
|
||||
|
||||
if threshold == 0 {
|
||||
threshold = lenAddrs
|
||||
}
|
||||
|
||||
if m.from == address.Undef {
|
||||
return nil, xerrors.Errorf("must provide source address")
|
||||
}
|
||||
|
||||
// Set up constructor parameters for multisig
|
||||
msigParams := &multisig7.ConstructorParams{
|
||||
Signers: signers,
|
||||
NumApprovalsThreshold: threshold,
|
||||
UnlockDuration: unlockDuration,
|
||||
StartEpoch: unlockStart,
|
||||
}
|
||||
|
||||
enc, actErr := actors.SerializeParams(msigParams)
|
||||
if actErr != nil {
|
||||
return nil, actErr
|
||||
}
|
||||
|
||||
// new actors are created by invoking 'exec' on the init actor with the constructor params
|
||||
execParams := &init7.ExecParams{
|
||||
CodeCID: builtin7.MultisigActorCodeID,
|
||||
ConstructorParams: enc,
|
||||
}
|
||||
|
||||
enc, actErr = actors.SerializeParams(execParams)
|
||||
if actErr != nil {
|
||||
return nil, actErr
|
||||
}
|
||||
|
||||
return &types.Message{
|
||||
To: init_.Address,
|
||||
From: m.from,
|
||||
Method: builtin7.MethodsInit.Exec,
|
||||
Params: enc,
|
||||
Value: initialAmount,
|
||||
}, nil
|
||||
}
|
@ -13,7 +13,7 @@ import (
|
||||
"github.com/ipfs/go-cid"
|
||||
|
||||
msig0 "github.com/filecoin-project/specs-actors/actors/builtin/multisig"
|
||||
msig6 "github.com/filecoin-project/specs-actors/v6/actors/builtin/multisig"
|
||||
msig7 "github.com/filecoin-project/specs-actors/v7/actors/builtin/multisig"
|
||||
|
||||
builtin0 "github.com/filecoin-project/specs-actors/actors/builtin"
|
||||
|
||||
@ -27,6 +27,8 @@ import (
|
||||
|
||||
builtin6 "github.com/filecoin-project/specs-actors/v6/actors/builtin"
|
||||
|
||||
builtin7 "github.com/filecoin-project/specs-actors/v7/actors/builtin"
|
||||
|
||||
"github.com/filecoin-project/lotus/chain/actors"
|
||||
"github.com/filecoin-project/lotus/chain/actors/adt"
|
||||
"github.com/filecoin-project/lotus/chain/actors/builtin"
|
||||
@ -58,6 +60,10 @@ func init() {
|
||||
builtin.RegisterActorState(builtin6.MultisigActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
|
||||
return load6(store, root)
|
||||
})
|
||||
|
||||
builtin.RegisterActorState(builtin7.MultisigActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
|
||||
return load7(store, root)
|
||||
})
|
||||
}
|
||||
|
||||
func Load(store adt.Store, act *types.Actor) (State, error) {
|
||||
@ -81,6 +87,9 @@ func Load(store adt.Store, act *types.Actor) (State, error) {
|
||||
case builtin6.MultisigActorCodeID:
|
||||
return load6(store, act.Head)
|
||||
|
||||
case builtin7.MultisigActorCodeID:
|
||||
return load7(store, act.Head)
|
||||
|
||||
}
|
||||
return nil, xerrors.Errorf("unknown actor code %s", act.Code)
|
||||
}
|
||||
@ -106,6 +115,9 @@ func MakeState(store adt.Store, av actors.Version, signers []address.Address, th
|
||||
case actors.Version6:
|
||||
return make6(store, signers, threshold, startEpoch, unlockDuration, initialBalance)
|
||||
|
||||
case actors.Version7:
|
||||
return make7(store, signers, threshold, startEpoch, unlockDuration, initialBalance)
|
||||
|
||||
}
|
||||
return nil, xerrors.Errorf("unknown actor version %d", av)
|
||||
}
|
||||
@ -131,6 +143,9 @@ func GetActorCodeID(av actors.Version) (cid.Cid, error) {
|
||||
case actors.Version6:
|
||||
return builtin6.MultisigActorCodeID, nil
|
||||
|
||||
case actors.Version7:
|
||||
return builtin7.MultisigActorCodeID, nil
|
||||
|
||||
}
|
||||
|
||||
return cid.Undef, xerrors.Errorf("unknown actor version %d", av)
|
||||
@ -156,7 +171,7 @@ type State interface {
|
||||
|
||||
type Transaction = msig0.Transaction
|
||||
|
||||
var Methods = builtin6.MethodsMultisig
|
||||
var Methods = builtin7.MethodsMultisig
|
||||
|
||||
func Message(version actors.Version, from address.Address) MessageBuilder {
|
||||
switch version {
|
||||
@ -178,6 +193,9 @@ func Message(version actors.Version, from address.Address) MessageBuilder {
|
||||
|
||||
case actors.Version6:
|
||||
return message6{message0{from}}
|
||||
|
||||
case actors.Version7:
|
||||
return message7{message0{from}}
|
||||
default:
|
||||
panic(fmt.Sprintf("unsupported actors version: %d", version))
|
||||
}
|
||||
@ -201,13 +219,13 @@ type MessageBuilder interface {
|
||||
}
|
||||
|
||||
// this type is the same between v0 and v2
|
||||
type ProposalHashData = msig6.ProposalHashData
|
||||
type ProposeReturn = msig6.ProposeReturn
|
||||
type ProposeParams = msig6.ProposeParams
|
||||
type ApproveReturn = msig6.ApproveReturn
|
||||
type ProposalHashData = msig7.ProposalHashData
|
||||
type ProposeReturn = msig7.ProposeReturn
|
||||
type ProposeParams = msig7.ProposeParams
|
||||
type ApproveReturn = msig7.ApproveReturn
|
||||
|
||||
func txnParams(id uint64, data *ProposalHashData) ([]byte, error) {
|
||||
params := msig6.TxnIDParams{ID: msig6.TxnID(id)}
|
||||
params := msig7.TxnIDParams{ID: msig7.TxnID(id)}
|
||||
if data != nil {
|
||||
if data.Requester.Protocol() != address.ID {
|
||||
return nil, xerrors.Errorf("proposer address must be an ID address, was %s", data.Requester)
|
||||
|
119
chain/actors/builtin/multisig/v7.go
Normal file
119
chain/actors/builtin/multisig/v7.go
Normal file
@ -0,0 +1,119 @@
|
||||
package multisig
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
|
||||
adt7 "github.com/filecoin-project/specs-actors/v7/actors/util/adt"
|
||||
|
||||
"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"
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
"github.com/filecoin-project/lotus/chain/actors/adt"
|
||||
|
||||
builtin7 "github.com/filecoin-project/specs-actors/v7/actors/builtin"
|
||||
|
||||
msig7 "github.com/filecoin-project/specs-actors/v7/actors/builtin/multisig"
|
||||
)
|
||||
|
||||
var _ State = (*state7)(nil)
|
||||
|
||||
func load7(store adt.Store, root cid.Cid) (State, error) {
|
||||
out := state7{store: store}
|
||||
err := store.Get(store.Context(), root, &out)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &out, nil
|
||||
}
|
||||
|
||||
func make7(store adt.Store, signers []address.Address, threshold uint64, startEpoch abi.ChainEpoch, unlockDuration abi.ChainEpoch, initialBalance abi.TokenAmount) (State, error) {
|
||||
out := state7{store: store}
|
||||
out.State = msig7.State{}
|
||||
out.State.Signers = signers
|
||||
out.State.NumApprovalsThreshold = threshold
|
||||
out.State.StartEpoch = startEpoch
|
||||
out.State.UnlockDuration = unlockDuration
|
||||
out.State.InitialBalance = initialBalance
|
||||
|
||||
em, err := adt7.StoreEmptyMap(store, builtin7.DefaultHamtBitwidth)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
out.State.PendingTxns = em
|
||||
|
||||
return &out, nil
|
||||
}
|
||||
|
||||
type state7 struct {
|
||||
msig7.State
|
||||
store adt.Store
|
||||
}
|
||||
|
||||
func (s *state7) LockedBalance(currEpoch abi.ChainEpoch) (abi.TokenAmount, error) {
|
||||
return s.State.AmountLocked(currEpoch - s.State.StartEpoch), nil
|
||||
}
|
||||
|
||||
func (s *state7) StartEpoch() (abi.ChainEpoch, error) {
|
||||
return s.State.StartEpoch, nil
|
||||
}
|
||||
|
||||
func (s *state7) UnlockDuration() (abi.ChainEpoch, error) {
|
||||
return s.State.UnlockDuration, nil
|
||||
}
|
||||
|
||||
func (s *state7) InitialBalance() (abi.TokenAmount, error) {
|
||||
return s.State.InitialBalance, nil
|
||||
}
|
||||
|
||||
func (s *state7) Threshold() (uint64, error) {
|
||||
return s.State.NumApprovalsThreshold, nil
|
||||
}
|
||||
|
||||
func (s *state7) Signers() ([]address.Address, error) {
|
||||
return s.State.Signers, nil
|
||||
}
|
||||
|
||||
func (s *state7) ForEachPendingTxn(cb func(id int64, txn Transaction) error) error {
|
||||
arr, err := adt7.AsMap(s.store, s.State.PendingTxns, builtin7.DefaultHamtBitwidth)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var out msig7.Transaction
|
||||
return arr.ForEach(&out, func(key string) error {
|
||||
txid, n := binary.Varint([]byte(key))
|
||||
if n <= 0 {
|
||||
return xerrors.Errorf("invalid pending transaction key: %v", key)
|
||||
}
|
||||
return cb(txid, (Transaction)(out)) //nolint:unconvert
|
||||
})
|
||||
}
|
||||
|
||||
func (s *state7) PendingTxnChanged(other State) (bool, error) {
|
||||
other7, ok := other.(*state7)
|
||||
if !ok {
|
||||
// treat an upgrade as a change, always
|
||||
return true, nil
|
||||
}
|
||||
return !s.State.PendingTxns.Equals(other7.PendingTxns), nil
|
||||
}
|
||||
|
||||
func (s *state7) transactions() (adt.Map, error) {
|
||||
return adt7.AsMap(s.store, s.PendingTxns, builtin7.DefaultHamtBitwidth)
|
||||
}
|
||||
|
||||
func (s *state7) decodeTransaction(val *cbg.Deferred) (Transaction, error) {
|
||||
var tx msig7.Transaction
|
||||
if err := tx.UnmarshalCBOR(bytes.NewReader(val.Raw)); err != nil {
|
||||
return Transaction{}, err
|
||||
}
|
||||
return tx, nil
|
||||
}
|
||||
|
||||
func (s *state7) GetState() interface{} {
|
||||
return &s.State
|
||||
}
|
74
chain/actors/builtin/paych/message7.go
Normal file
74
chain/actors/builtin/paych/message7.go
Normal file
@ -0,0 +1,74 @@
|
||||
package paych
|
||||
|
||||
import (
|
||||
"github.com/filecoin-project/go-address"
|
||||
"github.com/filecoin-project/go-state-types/abi"
|
||||
|
||||
builtin7 "github.com/filecoin-project/specs-actors/v7/actors/builtin"
|
||||
init7 "github.com/filecoin-project/specs-actors/v7/actors/builtin/init"
|
||||
paych7 "github.com/filecoin-project/specs-actors/v7/actors/builtin/paych"
|
||||
|
||||
"github.com/filecoin-project/lotus/chain/actors"
|
||||
init_ "github.com/filecoin-project/lotus/chain/actors/builtin/init"
|
||||
"github.com/filecoin-project/lotus/chain/types"
|
||||
)
|
||||
|
||||
type message7 struct{ from address.Address }
|
||||
|
||||
func (m message7) Create(to address.Address, initialAmount abi.TokenAmount) (*types.Message, error) {
|
||||
params, aerr := actors.SerializeParams(&paych7.ConstructorParams{From: m.from, To: to})
|
||||
if aerr != nil {
|
||||
return nil, aerr
|
||||
}
|
||||
enc, aerr := actors.SerializeParams(&init7.ExecParams{
|
||||
CodeCID: builtin7.PaymentChannelActorCodeID,
|
||||
ConstructorParams: params,
|
||||
})
|
||||
if aerr != nil {
|
||||
return nil, aerr
|
||||
}
|
||||
|
||||
return &types.Message{
|
||||
To: init_.Address,
|
||||
From: m.from,
|
||||
Value: initialAmount,
|
||||
Method: builtin7.MethodsInit.Exec,
|
||||
Params: enc,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (m message7) Update(paych address.Address, sv *SignedVoucher, secret []byte) (*types.Message, error) {
|
||||
params, aerr := actors.SerializeParams(&paych7.UpdateChannelStateParams{
|
||||
Sv: *sv,
|
||||
Secret: secret,
|
||||
})
|
||||
if aerr != nil {
|
||||
return nil, aerr
|
||||
}
|
||||
|
||||
return &types.Message{
|
||||
To: paych,
|
||||
From: m.from,
|
||||
Value: abi.NewTokenAmount(0),
|
||||
Method: builtin7.MethodsPaych.UpdateChannelState,
|
||||
Params: params,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (m message7) Settle(paych address.Address) (*types.Message, error) {
|
||||
return &types.Message{
|
||||
To: paych,
|
||||
From: m.from,
|
||||
Value: abi.NewTokenAmount(0),
|
||||
Method: builtin7.MethodsPaych.Settle,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (m message7) Collect(paych address.Address) (*types.Message, error) {
|
||||
return &types.Message{
|
||||
To: paych,
|
||||
From: m.from,
|
||||
Value: abi.NewTokenAmount(0),
|
||||
Method: builtin7.MethodsPaych.Collect,
|
||||
}, nil
|
||||
}
|
@ -27,6 +27,8 @@ import (
|
||||
|
||||
builtin6 "github.com/filecoin-project/specs-actors/v6/actors/builtin"
|
||||
|
||||
builtin7 "github.com/filecoin-project/specs-actors/v7/actors/builtin"
|
||||
|
||||
"github.com/filecoin-project/lotus/chain/actors"
|
||||
"github.com/filecoin-project/lotus/chain/actors/adt"
|
||||
"github.com/filecoin-project/lotus/chain/actors/builtin"
|
||||
@ -58,6 +60,10 @@ func init() {
|
||||
builtin.RegisterActorState(builtin6.PaymentChannelActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
|
||||
return load6(store, root)
|
||||
})
|
||||
|
||||
builtin.RegisterActorState(builtin7.PaymentChannelActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
|
||||
return load7(store, root)
|
||||
})
|
||||
}
|
||||
|
||||
// Load returns an abstract copy of payment channel state, irregardless of actor version
|
||||
@ -82,6 +88,9 @@ func Load(store adt.Store, act *types.Actor) (State, error) {
|
||||
case builtin6.PaymentChannelActorCodeID:
|
||||
return load6(store, act.Head)
|
||||
|
||||
case builtin7.PaymentChannelActorCodeID:
|
||||
return load7(store, act.Head)
|
||||
|
||||
}
|
||||
return nil, xerrors.Errorf("unknown actor code %s", act.Code)
|
||||
}
|
||||
@ -107,6 +116,9 @@ func MakeState(store adt.Store, av actors.Version) (State, error) {
|
||||
case actors.Version6:
|
||||
return make6(store)
|
||||
|
||||
case actors.Version7:
|
||||
return make7(store)
|
||||
|
||||
}
|
||||
return nil, xerrors.Errorf("unknown actor version %d", av)
|
||||
}
|
||||
@ -132,6 +144,9 @@ func GetActorCodeID(av actors.Version) (cid.Cid, error) {
|
||||
case actors.Version6:
|
||||
return builtin6.PaymentChannelActorCodeID, nil
|
||||
|
||||
case actors.Version7:
|
||||
return builtin7.PaymentChannelActorCodeID, nil
|
||||
|
||||
}
|
||||
|
||||
return cid.Undef, xerrors.Errorf("unknown actor version %d", av)
|
||||
@ -185,7 +200,7 @@ func DecodeSignedVoucher(s string) (*SignedVoucher, error) {
|
||||
return &sv, nil
|
||||
}
|
||||
|
||||
var Methods = builtin6.MethodsPaych
|
||||
var Methods = builtin7.MethodsPaych
|
||||
|
||||
func Message(version actors.Version, from address.Address) MessageBuilder {
|
||||
switch version {
|
||||
@ -208,6 +223,9 @@ func Message(version actors.Version, from address.Address) MessageBuilder {
|
||||
case actors.Version6:
|
||||
return message6{from}
|
||||
|
||||
case actors.Version7:
|
||||
return message7{from}
|
||||
|
||||
default:
|
||||
panic(fmt.Sprintf("unsupported actors version: %d", version))
|
||||
}
|
||||
|
114
chain/actors/builtin/paych/v7.go
Normal file
114
chain/actors/builtin/paych/v7.go
Normal file
@ -0,0 +1,114 @@
|
||||
package paych
|
||||
|
||||
import (
|
||||
"github.com/ipfs/go-cid"
|
||||
|
||||
"github.com/filecoin-project/go-address"
|
||||
"github.com/filecoin-project/go-state-types/abi"
|
||||
"github.com/filecoin-project/go-state-types/big"
|
||||
|
||||
"github.com/filecoin-project/lotus/chain/actors/adt"
|
||||
|
||||
paych7 "github.com/filecoin-project/specs-actors/v7/actors/builtin/paych"
|
||||
adt7 "github.com/filecoin-project/specs-actors/v7/actors/util/adt"
|
||||
)
|
||||
|
||||
var _ State = (*state7)(nil)
|
||||
|
||||
func load7(store adt.Store, root cid.Cid) (State, error) {
|
||||
out := state7{store: store}
|
||||
err := store.Get(store.Context(), root, &out)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &out, nil
|
||||
}
|
||||
|
||||
func make7(store adt.Store) (State, error) {
|
||||
out := state7{store: store}
|
||||
out.State = paych7.State{}
|
||||
return &out, nil
|
||||
}
|
||||
|
||||
type state7 struct {
|
||||
paych7.State
|
||||
store adt.Store
|
||||
lsAmt *adt7.Array
|
||||
}
|
||||
|
||||
// Channel owner, who has funded the actor
|
||||
func (s *state7) From() (address.Address, error) {
|
||||
return s.State.From, nil
|
||||
}
|
||||
|
||||
// Recipient of payouts from channel
|
||||
func (s *state7) To() (address.Address, error) {
|
||||
return s.State.To, nil
|
||||
}
|
||||
|
||||
// Height at which the channel can be `Collected`
|
||||
func (s *state7) SettlingAt() (abi.ChainEpoch, error) {
|
||||
return s.State.SettlingAt, nil
|
||||
}
|
||||
|
||||
// Amount successfully redeemed through the payment channel, paid out on `Collect()`
|
||||
func (s *state7) ToSend() (abi.TokenAmount, error) {
|
||||
return s.State.ToSend, nil
|
||||
}
|
||||
|
||||
func (s *state7) getOrLoadLsAmt() (*adt7.Array, error) {
|
||||
if s.lsAmt != nil {
|
||||
return s.lsAmt, nil
|
||||
}
|
||||
|
||||
// Get the lane state from the chain
|
||||
lsamt, err := adt7.AsArray(s.store, s.State.LaneStates, paych7.LaneStatesAmtBitwidth)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
s.lsAmt = lsamt
|
||||
return lsamt, nil
|
||||
}
|
||||
|
||||
// Get total number of lanes
|
||||
func (s *state7) LaneCount() (uint64, error) {
|
||||
lsamt, err := s.getOrLoadLsAmt()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return lsamt.Length(), nil
|
||||
}
|
||||
|
||||
func (s *state7) GetState() interface{} {
|
||||
return &s.State
|
||||
}
|
||||
|
||||
// Iterate lane states
|
||||
func (s *state7) ForEachLaneState(cb func(idx uint64, dl LaneState) error) error {
|
||||
// Get the lane state from the chain
|
||||
lsamt, err := s.getOrLoadLsAmt()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Note: we use a map instead of an array to store laneStates because the
|
||||
// client sets the lane ID (the index) and potentially they could use a
|
||||
// very large index.
|
||||
var ls paych7.LaneState
|
||||
return lsamt.ForEach(&ls, func(i int64) error {
|
||||
return cb(uint64(i), &laneState7{ls})
|
||||
})
|
||||
}
|
||||
|
||||
type laneState7 struct {
|
||||
paych7.LaneState
|
||||
}
|
||||
|
||||
func (ls *laneState7) Redeemed() (big.Int, error) {
|
||||
return ls.LaneState.Redeemed, nil
|
||||
}
|
||||
|
||||
func (ls *laneState7) Nonce() (uint64, error) {
|
||||
return ls.LaneState.Nonce, nil
|
||||
}
|
@ -26,6 +26,8 @@ import (
|
||||
builtin5 "github.com/filecoin-project/specs-actors/v5/actors/builtin"
|
||||
|
||||
builtin6 "github.com/filecoin-project/specs-actors/v6/actors/builtin"
|
||||
|
||||
builtin7 "github.com/filecoin-project/specs-actors/v7/actors/builtin"
|
||||
)
|
||||
|
||||
func init() {
|
||||
@ -53,11 +55,15 @@ func init() {
|
||||
builtin.RegisterActorState(builtin6.StoragePowerActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
|
||||
return load6(store, root)
|
||||
})
|
||||
|
||||
builtin.RegisterActorState(builtin7.StoragePowerActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
|
||||
return load7(store, root)
|
||||
})
|
||||
}
|
||||
|
||||
var (
|
||||
Address = builtin6.StoragePowerActorAddr
|
||||
Methods = builtin6.MethodsPower
|
||||
Address = builtin7.StoragePowerActorAddr
|
||||
Methods = builtin7.MethodsPower
|
||||
)
|
||||
|
||||
func Load(store adt.Store, act *types.Actor) (State, error) {
|
||||
@ -81,6 +87,9 @@ func Load(store adt.Store, act *types.Actor) (State, error) {
|
||||
case builtin6.StoragePowerActorCodeID:
|
||||
return load6(store, act.Head)
|
||||
|
||||
case builtin7.StoragePowerActorCodeID:
|
||||
return load7(store, act.Head)
|
||||
|
||||
}
|
||||
return nil, xerrors.Errorf("unknown actor code %s", act.Code)
|
||||
}
|
||||
@ -106,6 +115,9 @@ func MakeState(store adt.Store, av actors.Version) (State, error) {
|
||||
case actors.Version6:
|
||||
return make6(store)
|
||||
|
||||
case actors.Version7:
|
||||
return make7(store)
|
||||
|
||||
}
|
||||
return nil, xerrors.Errorf("unknown actor version %d", av)
|
||||
}
|
||||
@ -131,6 +143,9 @@ func GetActorCodeID(av actors.Version) (cid.Cid, error) {
|
||||
case actors.Version6:
|
||||
return builtin6.StoragePowerActorCodeID, nil
|
||||
|
||||
case actors.Version7:
|
||||
return builtin7.StoragePowerActorCodeID, nil
|
||||
|
||||
}
|
||||
|
||||
return cid.Undef, xerrors.Errorf("unknown actor version %d", av)
|
||||
|
187
chain/actors/builtin/power/v7.go
Normal file
187
chain/actors/builtin/power/v7.go
Normal file
@ -0,0 +1,187 @@
|
||||
package power
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
|
||||
"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/lotus/chain/actors/adt"
|
||||
"github.com/filecoin-project/lotus/chain/actors/builtin"
|
||||
|
||||
builtin7 "github.com/filecoin-project/specs-actors/v7/actors/builtin"
|
||||
|
||||
power7 "github.com/filecoin-project/specs-actors/v7/actors/builtin/power"
|
||||
adt7 "github.com/filecoin-project/specs-actors/v7/actors/util/adt"
|
||||
)
|
||||
|
||||
var _ State = (*state7)(nil)
|
||||
|
||||
func load7(store adt.Store, root cid.Cid) (State, error) {
|
||||
out := state7{store: store}
|
||||
err := store.Get(store.Context(), root, &out)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &out, nil
|
||||
}
|
||||
|
||||
func make7(store adt.Store) (State, error) {
|
||||
out := state7{store: store}
|
||||
|
||||
s, err := power7.ConstructState(store)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
out.State = *s
|
||||
|
||||
return &out, nil
|
||||
}
|
||||
|
||||
type state7 struct {
|
||||
power7.State
|
||||
store adt.Store
|
||||
}
|
||||
|
||||
func (s *state7) TotalLocked() (abi.TokenAmount, error) {
|
||||
return s.TotalPledgeCollateral, nil
|
||||
}
|
||||
|
||||
func (s *state7) TotalPower() (Claim, error) {
|
||||
return Claim{
|
||||
RawBytePower: s.TotalRawBytePower,
|
||||
QualityAdjPower: s.TotalQualityAdjPower,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Committed power to the network. Includes miners below the minimum threshold.
|
||||
func (s *state7) TotalCommitted() (Claim, error) {
|
||||
return Claim{
|
||||
RawBytePower: s.TotalBytesCommitted,
|
||||
QualityAdjPower: s.TotalQABytesCommitted,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *state7) MinerPower(addr address.Address) (Claim, bool, error) {
|
||||
claims, err := s.claims()
|
||||
if err != nil {
|
||||
return Claim{}, false, err
|
||||
}
|
||||
var claim power7.Claim
|
||||
ok, err := claims.Get(abi.AddrKey(addr), &claim)
|
||||
if err != nil {
|
||||
return Claim{}, false, err
|
||||
}
|
||||
return Claim{
|
||||
RawBytePower: claim.RawBytePower,
|
||||
QualityAdjPower: claim.QualityAdjPower,
|
||||
}, ok, nil
|
||||
}
|
||||
|
||||
func (s *state7) MinerNominalPowerMeetsConsensusMinimum(a address.Address) (bool, error) {
|
||||
return s.State.MinerNominalPowerMeetsConsensusMinimum(s.store, a)
|
||||
}
|
||||
|
||||
func (s *state7) TotalPowerSmoothed() (builtin.FilterEstimate, error) {
|
||||
return builtin.FromV7FilterEstimate(s.State.ThisEpochQAPowerSmoothed), nil
|
||||
}
|
||||
|
||||
func (s *state7) MinerCounts() (uint64, uint64, error) {
|
||||
return uint64(s.State.MinerAboveMinPowerCount), uint64(s.State.MinerCount), nil
|
||||
}
|
||||
|
||||
func (s *state7) ListAllMiners() ([]address.Address, error) {
|
||||
claims, err := s.claims()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var miners []address.Address
|
||||
err = claims.ForEach(nil, func(k string) error {
|
||||
a, err := address.NewFromBytes([]byte(k))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
miners = append(miners, a)
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return miners, nil
|
||||
}
|
||||
|
||||
func (s *state7) ForEachClaim(cb func(miner address.Address, claim Claim) error) error {
|
||||
claims, err := s.claims()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var claim power7.Claim
|
||||
return claims.ForEach(&claim, func(k string) error {
|
||||
a, err := address.NewFromBytes([]byte(k))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return cb(a, Claim{
|
||||
RawBytePower: claim.RawBytePower,
|
||||
QualityAdjPower: claim.QualityAdjPower,
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func (s *state7) ClaimsChanged(other State) (bool, error) {
|
||||
other7, ok := other.(*state7)
|
||||
if !ok {
|
||||
// treat an upgrade as a change, always
|
||||
return true, nil
|
||||
}
|
||||
return !s.State.Claims.Equals(other7.State.Claims), nil
|
||||
}
|
||||
|
||||
func (s *state7) SetTotalQualityAdjPower(p abi.StoragePower) error {
|
||||
s.State.TotalQualityAdjPower = p
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *state7) SetTotalRawBytePower(p abi.StoragePower) error {
|
||||
s.State.TotalRawBytePower = p
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *state7) SetThisEpochQualityAdjPower(p abi.StoragePower) error {
|
||||
s.State.ThisEpochQualityAdjPower = p
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *state7) SetThisEpochRawBytePower(p abi.StoragePower) error {
|
||||
s.State.ThisEpochRawBytePower = p
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *state7) GetState() interface{} {
|
||||
return &s.State
|
||||
}
|
||||
|
||||
func (s *state7) claims() (adt.Map, error) {
|
||||
return adt7.AsMap(s.store, s.Claims, builtin7.DefaultHamtBitwidth)
|
||||
}
|
||||
|
||||
func (s *state7) decodeClaim(val *cbg.Deferred) (Claim, error) {
|
||||
var ci power7.Claim
|
||||
if err := ci.UnmarshalCBOR(bytes.NewReader(val.Raw)); err != nil {
|
||||
return Claim{}, err
|
||||
}
|
||||
return fromV7Claim(ci), nil
|
||||
}
|
||||
|
||||
func fromV7Claim(v7 power7.Claim) Claim {
|
||||
return Claim{
|
||||
RawBytePower: v7.RawBytePower,
|
||||
QualityAdjPower: v7.QualityAdjPower,
|
||||
}
|
||||
}
|
@ -21,6 +21,8 @@ import (
|
||||
|
||||
builtin6 "github.com/filecoin-project/specs-actors/v6/actors/builtin"
|
||||
|
||||
builtin7 "github.com/filecoin-project/specs-actors/v7/actors/builtin"
|
||||
|
||||
"github.com/filecoin-project/lotus/chain/actors/adt"
|
||||
"github.com/filecoin-project/lotus/chain/actors/builtin"
|
||||
"github.com/filecoin-project/lotus/chain/types"
|
||||
@ -51,11 +53,15 @@ func init() {
|
||||
builtin.RegisterActorState(builtin6.RewardActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
|
||||
return load6(store, root)
|
||||
})
|
||||
|
||||
builtin.RegisterActorState(builtin7.RewardActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
|
||||
return load7(store, root)
|
||||
})
|
||||
}
|
||||
|
||||
var (
|
||||
Address = builtin6.RewardActorAddr
|
||||
Methods = builtin6.MethodsReward
|
||||
Address = builtin7.RewardActorAddr
|
||||
Methods = builtin7.MethodsReward
|
||||
)
|
||||
|
||||
func Load(store adt.Store, act *types.Actor) (State, error) {
|
||||
@ -79,6 +85,9 @@ func Load(store adt.Store, act *types.Actor) (State, error) {
|
||||
case builtin6.RewardActorCodeID:
|
||||
return load6(store, act.Head)
|
||||
|
||||
case builtin7.RewardActorCodeID:
|
||||
return load7(store, act.Head)
|
||||
|
||||
}
|
||||
return nil, xerrors.Errorf("unknown actor code %s", act.Code)
|
||||
}
|
||||
@ -104,6 +113,9 @@ func MakeState(store adt.Store, av actors.Version, currRealizedPower abi.Storage
|
||||
case actors.Version6:
|
||||
return make6(store, currRealizedPower)
|
||||
|
||||
case actors.Version7:
|
||||
return make7(store, currRealizedPower)
|
||||
|
||||
}
|
||||
return nil, xerrors.Errorf("unknown actor version %d", av)
|
||||
}
|
||||
@ -129,6 +141,9 @@ func GetActorCodeID(av actors.Version) (cid.Cid, error) {
|
||||
case actors.Version6:
|
||||
return builtin6.RewardActorCodeID, nil
|
||||
|
||||
case actors.Version7:
|
||||
return builtin7.RewardActorCodeID, nil
|
||||
|
||||
}
|
||||
|
||||
return cid.Undef, xerrors.Errorf("unknown actor version %d", av)
|
||||
|
98
chain/actors/builtin/reward/v7.go
Normal file
98
chain/actors/builtin/reward/v7.go
Normal file
@ -0,0 +1,98 @@
|
||||
package reward
|
||||
|
||||
import (
|
||||
"github.com/filecoin-project/go-state-types/abi"
|
||||
"github.com/ipfs/go-cid"
|
||||
|
||||
"github.com/filecoin-project/lotus/chain/actors/adt"
|
||||
"github.com/filecoin-project/lotus/chain/actors/builtin"
|
||||
|
||||
miner7 "github.com/filecoin-project/specs-actors/v7/actors/builtin/miner"
|
||||
reward7 "github.com/filecoin-project/specs-actors/v7/actors/builtin/reward"
|
||||
smoothing7 "github.com/filecoin-project/specs-actors/v7/actors/util/smoothing"
|
||||
)
|
||||
|
||||
var _ State = (*state7)(nil)
|
||||
|
||||
func load7(store adt.Store, root cid.Cid) (State, error) {
|
||||
out := state7{store: store}
|
||||
err := store.Get(store.Context(), root, &out)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &out, nil
|
||||
}
|
||||
|
||||
func make7(store adt.Store, currRealizedPower abi.StoragePower) (State, error) {
|
||||
out := state7{store: store}
|
||||
out.State = *reward7.ConstructState(currRealizedPower)
|
||||
return &out, nil
|
||||
}
|
||||
|
||||
type state7 struct {
|
||||
reward7.State
|
||||
store adt.Store
|
||||
}
|
||||
|
||||
func (s *state7) ThisEpochReward() (abi.TokenAmount, error) {
|
||||
return s.State.ThisEpochReward, nil
|
||||
}
|
||||
|
||||
func (s *state7) ThisEpochRewardSmoothed() (builtin.FilterEstimate, error) {
|
||||
|
||||
return builtin.FilterEstimate{
|
||||
PositionEstimate: s.State.ThisEpochRewardSmoothed.PositionEstimate,
|
||||
VelocityEstimate: s.State.ThisEpochRewardSmoothed.VelocityEstimate,
|
||||
}, nil
|
||||
|
||||
}
|
||||
|
||||
func (s *state7) ThisEpochBaselinePower() (abi.StoragePower, error) {
|
||||
return s.State.ThisEpochBaselinePower, nil
|
||||
}
|
||||
|
||||
func (s *state7) TotalStoragePowerReward() (abi.TokenAmount, error) {
|
||||
return s.State.TotalStoragePowerReward, nil
|
||||
}
|
||||
|
||||
func (s *state7) EffectiveBaselinePower() (abi.StoragePower, error) {
|
||||
return s.State.EffectiveBaselinePower, nil
|
||||
}
|
||||
|
||||
func (s *state7) EffectiveNetworkTime() (abi.ChainEpoch, error) {
|
||||
return s.State.EffectiveNetworkTime, nil
|
||||
}
|
||||
|
||||
func (s *state7) CumsumBaseline() (reward7.Spacetime, error) {
|
||||
return s.State.CumsumBaseline, nil
|
||||
}
|
||||
|
||||
func (s *state7) CumsumRealized() (reward7.Spacetime, error) {
|
||||
return s.State.CumsumRealized, nil
|
||||
}
|
||||
|
||||
func (s *state7) InitialPledgeForPower(qaPower abi.StoragePower, networkTotalPledge abi.TokenAmount, networkQAPower *builtin.FilterEstimate, circSupply abi.TokenAmount) (abi.TokenAmount, error) {
|
||||
return miner7.InitialPledgeForPower(
|
||||
qaPower,
|
||||
s.State.ThisEpochBaselinePower,
|
||||
s.State.ThisEpochRewardSmoothed,
|
||||
smoothing7.FilterEstimate{
|
||||
PositionEstimate: networkQAPower.PositionEstimate,
|
||||
VelocityEstimate: networkQAPower.VelocityEstimate,
|
||||
},
|
||||
circSupply,
|
||||
), nil
|
||||
}
|
||||
|
||||
func (s *state7) PreCommitDepositForPower(networkQAPower builtin.FilterEstimate, sectorWeight abi.StoragePower) (abi.TokenAmount, error) {
|
||||
return miner7.PreCommitDepositForPower(s.State.ThisEpochRewardSmoothed,
|
||||
smoothing7.FilterEstimate{
|
||||
PositionEstimate: networkQAPower.PositionEstimate,
|
||||
VelocityEstimate: networkQAPower.VelocityEstimate,
|
||||
},
|
||||
sectorWeight), nil
|
||||
}
|
||||
|
||||
func (s *state7) GetState() interface{} {
|
||||
return &s.State
|
||||
}
|
@ -17,10 +17,12 @@ import (
|
||||
builtin5 "github.com/filecoin-project/specs-actors/v5/actors/builtin"
|
||||
|
||||
builtin6 "github.com/filecoin-project/specs-actors/v6/actors/builtin"
|
||||
|
||||
builtin7 "github.com/filecoin-project/specs-actors/v7/actors/builtin"
|
||||
)
|
||||
|
||||
var (
|
||||
Address = builtin6.SystemActorAddr
|
||||
Address = builtin7.SystemActorAddr
|
||||
)
|
||||
|
||||
func MakeState(store adt.Store, av actors.Version) (State, error) {
|
||||
@ -44,6 +46,9 @@ func MakeState(store adt.Store, av actors.Version) (State, error) {
|
||||
case actors.Version6:
|
||||
return make6(store)
|
||||
|
||||
case actors.Version7:
|
||||
return make7(store)
|
||||
|
||||
}
|
||||
return nil, xerrors.Errorf("unknown actor version %d", av)
|
||||
}
|
||||
@ -69,6 +74,9 @@ func GetActorCodeID(av actors.Version) (cid.Cid, error) {
|
||||
case actors.Version6:
|
||||
return builtin6.SystemActorCodeID, nil
|
||||
|
||||
case actors.Version7:
|
||||
return builtin7.SystemActorCodeID, nil
|
||||
|
||||
}
|
||||
|
||||
return cid.Undef, xerrors.Errorf("unknown actor version %d", av)
|
||||
|
35
chain/actors/builtin/system/v7.go
Normal file
35
chain/actors/builtin/system/v7.go
Normal file
@ -0,0 +1,35 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"github.com/ipfs/go-cid"
|
||||
|
||||
"github.com/filecoin-project/lotus/chain/actors/adt"
|
||||
|
||||
system7 "github.com/filecoin-project/specs-actors/v7/actors/builtin/system"
|
||||
)
|
||||
|
||||
var _ State = (*state7)(nil)
|
||||
|
||||
func load7(store adt.Store, root cid.Cid) (State, error) {
|
||||
out := state7{store: store}
|
||||
err := store.Get(store.Context(), root, &out)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &out, nil
|
||||
}
|
||||
|
||||
func make7(store adt.Store) (State, error) {
|
||||
out := state7{store: store}
|
||||
out.State = system7.State{}
|
||||
return &out, nil
|
||||
}
|
||||
|
||||
type state7 struct {
|
||||
system7.State
|
||||
store adt.Store
|
||||
}
|
||||
|
||||
func (s *state7) GetState() interface{} {
|
||||
return &s.State
|
||||
}
|
75
chain/actors/builtin/verifreg/v7.go
Normal file
75
chain/actors/builtin/verifreg/v7.go
Normal file
@ -0,0 +1,75 @@
|
||||
package verifreg
|
||||
|
||||
import (
|
||||
"github.com/filecoin-project/go-address"
|
||||
"github.com/filecoin-project/go-state-types/abi"
|
||||
"github.com/ipfs/go-cid"
|
||||
|
||||
"github.com/filecoin-project/lotus/chain/actors"
|
||||
"github.com/filecoin-project/lotus/chain/actors/adt"
|
||||
|
||||
builtin7 "github.com/filecoin-project/specs-actors/v7/actors/builtin"
|
||||
verifreg7 "github.com/filecoin-project/specs-actors/v7/actors/builtin/verifreg"
|
||||
adt7 "github.com/filecoin-project/specs-actors/v7/actors/util/adt"
|
||||
)
|
||||
|
||||
var _ State = (*state7)(nil)
|
||||
|
||||
func load7(store adt.Store, root cid.Cid) (State, error) {
|
||||
out := state7{store: store}
|
||||
err := store.Get(store.Context(), root, &out)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &out, nil
|
||||
}
|
||||
|
||||
func make7(store adt.Store, rootKeyAddress address.Address) (State, error) {
|
||||
out := state7{store: store}
|
||||
|
||||
s, err := verifreg7.ConstructState(store, rootKeyAddress)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
out.State = *s
|
||||
|
||||
return &out, nil
|
||||
}
|
||||
|
||||
type state7 struct {
|
||||
verifreg7.State
|
||||
store adt.Store
|
||||
}
|
||||
|
||||
func (s *state7) RootKey() (address.Address, error) {
|
||||
return s.State.RootKey, nil
|
||||
}
|
||||
|
||||
func (s *state7) VerifiedClientDataCap(addr address.Address) (bool, abi.StoragePower, error) {
|
||||
return getDataCap(s.store, actors.Version7, s.verifiedClients, addr)
|
||||
}
|
||||
|
||||
func (s *state7) VerifierDataCap(addr address.Address) (bool, abi.StoragePower, error) {
|
||||
return getDataCap(s.store, actors.Version7, s.verifiers, addr)
|
||||
}
|
||||
|
||||
func (s *state7) ForEachVerifier(cb func(addr address.Address, dcap abi.StoragePower) error) error {
|
||||
return forEachCap(s.store, actors.Version7, s.verifiers, cb)
|
||||
}
|
||||
|
||||
func (s *state7) ForEachClient(cb func(addr address.Address, dcap abi.StoragePower) error) error {
|
||||
return forEachCap(s.store, actors.Version7, s.verifiedClients, cb)
|
||||
}
|
||||
|
||||
func (s *state7) verifiedClients() (adt.Map, error) {
|
||||
return adt7.AsMap(s.store, s.VerifiedClients, builtin7.DefaultHamtBitwidth)
|
||||
}
|
||||
|
||||
func (s *state7) verifiers() (adt.Map, error) {
|
||||
return adt7.AsMap(s.store, s.Verifiers, builtin7.DefaultHamtBitwidth)
|
||||
}
|
||||
|
||||
func (s *state7) GetState() interface{} {
|
||||
return &s.State
|
||||
}
|
@ -21,6 +21,8 @@ import (
|
||||
|
||||
builtin6 "github.com/filecoin-project/specs-actors/v6/actors/builtin"
|
||||
|
||||
builtin7 "github.com/filecoin-project/specs-actors/v7/actors/builtin"
|
||||
|
||||
"github.com/filecoin-project/lotus/chain/actors"
|
||||
"github.com/filecoin-project/lotus/chain/actors/adt"
|
||||
"github.com/filecoin-project/lotus/chain/actors/builtin"
|
||||
@ -53,11 +55,15 @@ func init() {
|
||||
return load6(store, root)
|
||||
})
|
||||
|
||||
builtin.RegisterActorState(builtin7.VerifiedRegistryActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
|
||||
return load7(store, root)
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
var (
|
||||
Address = builtin6.VerifiedRegistryActorAddr
|
||||
Methods = builtin6.MethodsVerifiedRegistry
|
||||
Address = builtin7.VerifiedRegistryActorAddr
|
||||
Methods = builtin7.MethodsVerifiedRegistry
|
||||
)
|
||||
|
||||
func Load(store adt.Store, act *types.Actor) (State, error) {
|
||||
@ -81,6 +87,9 @@ func Load(store adt.Store, act *types.Actor) (State, error) {
|
||||
case builtin6.VerifiedRegistryActorCodeID:
|
||||
return load6(store, act.Head)
|
||||
|
||||
case builtin7.VerifiedRegistryActorCodeID:
|
||||
return load7(store, act.Head)
|
||||
|
||||
}
|
||||
return nil, xerrors.Errorf("unknown actor code %s", act.Code)
|
||||
}
|
||||
@ -106,6 +115,9 @@ func MakeState(store adt.Store, av actors.Version, rootKeyAddress address.Addres
|
||||
case actors.Version6:
|
||||
return make6(store, rootKeyAddress)
|
||||
|
||||
case actors.Version7:
|
||||
return make7(store, rootKeyAddress)
|
||||
|
||||
}
|
||||
return nil, xerrors.Errorf("unknown actor version %d", av)
|
||||
}
|
||||
@ -131,6 +143,9 @@ func GetActorCodeID(av actors.Version) (cid.Cid, error) {
|
||||
case actors.Version6:
|
||||
return builtin6.VerifiedRegistryActorCodeID, nil
|
||||
|
||||
case actors.Version7:
|
||||
return builtin7.VerifiedRegistryActorCodeID, nil
|
||||
|
||||
}
|
||||
|
||||
return cid.Undef, xerrors.Errorf("unknown actor version %d", av)
|
||||
|
@ -40,14 +40,19 @@ import (
|
||||
miner6 "github.com/filecoin-project/specs-actors/v6/actors/builtin/miner"
|
||||
verifreg6 "github.com/filecoin-project/specs-actors/v6/actors/builtin/verifreg"
|
||||
|
||||
paych6 "github.com/filecoin-project/specs-actors/v6/actors/builtin/paych"
|
||||
builtin7 "github.com/filecoin-project/specs-actors/v7/actors/builtin"
|
||||
market7 "github.com/filecoin-project/specs-actors/v7/actors/builtin/market"
|
||||
miner7 "github.com/filecoin-project/specs-actors/v7/actors/builtin/miner"
|
||||
verifreg7 "github.com/filecoin-project/specs-actors/v7/actors/builtin/verifreg"
|
||||
|
||||
paych7 "github.com/filecoin-project/specs-actors/v7/actors/builtin/paych"
|
||||
)
|
||||
|
||||
const (
|
||||
ChainFinality = miner6.ChainFinality
|
||||
ChainFinality = miner7.ChainFinality
|
||||
SealRandomnessLookback = ChainFinality
|
||||
PaychSettleDelay = paych6.SettleDelay
|
||||
MaxPreCommitRandomnessLookback = builtin6.EpochsInDay + SealRandomnessLookback
|
||||
PaychSettleDelay = paych7.SettleDelay
|
||||
MaxPreCommitRandomnessLookback = builtin7.EpochsInDay + SealRandomnessLookback
|
||||
)
|
||||
|
||||
// SetSupportedProofTypes sets supported proof types, across all actor versions.
|
||||
@ -72,6 +77,8 @@ func SetSupportedProofTypes(types ...abi.RegisteredSealProof) {
|
||||
|
||||
miner6.PreCommitSealProofTypesV8 = make(map[abi.RegisteredSealProof]struct{}, len(types))
|
||||
|
||||
miner7.PreCommitSealProofTypesV8 = make(map[abi.RegisteredSealProof]struct{}, len(types))
|
||||
|
||||
AddSupportedProofTypes(types...)
|
||||
}
|
||||
|
||||
@ -119,6 +126,15 @@ func AddSupportedProofTypes(types ...abi.RegisteredSealProof) {
|
||||
|
||||
miner6.WindowPoStProofTypes[wpp] = struct{}{}
|
||||
|
||||
miner7.PreCommitSealProofTypesV8[t+abi.RegisteredSealProof_StackedDrg2KiBV1_1] = struct{}{}
|
||||
wpp, err = t.RegisteredWindowPoStProof()
|
||||
if err != nil {
|
||||
// Fine to panic, this is a test-only method
|
||||
panic(err)
|
||||
}
|
||||
|
||||
miner7.WindowPoStProofTypes[wpp] = struct{}{}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -139,11 +155,13 @@ func SetPreCommitChallengeDelay(delay abi.ChainEpoch) {
|
||||
|
||||
miner6.PreCommitChallengeDelay = delay
|
||||
|
||||
miner7.PreCommitChallengeDelay = delay
|
||||
|
||||
}
|
||||
|
||||
// TODO: this function shouldn't really exist. Instead, the API should expose the precommit delay.
|
||||
func GetPreCommitChallengeDelay() abi.ChainEpoch {
|
||||
return miner6.PreCommitChallengeDelay
|
||||
return miner7.PreCommitChallengeDelay
|
||||
}
|
||||
|
||||
// SetConsensusMinerMinPower sets the minimum power of an individual miner must
|
||||
@ -173,6 +191,10 @@ func SetConsensusMinerMinPower(p abi.StoragePower) {
|
||||
policy.ConsensusMinerMinPower = p
|
||||
}
|
||||
|
||||
for _, policy := range builtin7.PoStProofPolicies {
|
||||
policy.ConsensusMinerMinPower = p
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// SetMinVerifiedDealSize sets the minimum size of a verified deal. This should
|
||||
@ -191,6 +213,8 @@ func SetMinVerifiedDealSize(size abi.StoragePower) {
|
||||
|
||||
verifreg6.MinVerifiedDealSize = size
|
||||
|
||||
verifreg7.MinVerifiedDealSize = size
|
||||
|
||||
}
|
||||
|
||||
func GetMaxProveCommitDuration(ver actors.Version, t abi.RegisteredSealProof) (abi.ChainEpoch, error) {
|
||||
@ -220,6 +244,10 @@ func GetMaxProveCommitDuration(ver actors.Version, t abi.RegisteredSealProof) (a
|
||||
|
||||
return miner6.MaxProveCommitDuration[t], nil
|
||||
|
||||
case actors.Version7:
|
||||
|
||||
return miner7.MaxProveCommitDuration[t], nil
|
||||
|
||||
default:
|
||||
return 0, xerrors.Errorf("unsupported actors version")
|
||||
}
|
||||
@ -255,6 +283,11 @@ func SetProviderCollateralSupplyTarget(num, denom big.Int) {
|
||||
Denominator: denom,
|
||||
}
|
||||
|
||||
market7.ProviderCollateralSupplyTarget = builtin7.BigFrac{
|
||||
Numerator: num,
|
||||
Denominator: denom,
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func DealProviderCollateralBounds(
|
||||
@ -298,13 +331,18 @@ func DealProviderCollateralBounds(
|
||||
min, max := market6.DealProviderCollateralBounds(size, verified, rawBytePower, qaPower, baselinePower, circulatingFil)
|
||||
return min, max, nil
|
||||
|
||||
case actors.Version7:
|
||||
|
||||
min, max := market7.DealProviderCollateralBounds(size, verified, rawBytePower, qaPower, baselinePower, circulatingFil)
|
||||
return min, max, nil
|
||||
|
||||
default:
|
||||
return big.Zero(), big.Zero(), xerrors.Errorf("unsupported actors version")
|
||||
}
|
||||
}
|
||||
|
||||
func DealDurationBounds(pieceSize abi.PaddedPieceSize) (min, max abi.ChainEpoch) {
|
||||
return market6.DealDurationBounds(pieceSize)
|
||||
return market7.DealDurationBounds(pieceSize)
|
||||
}
|
||||
|
||||
// Sets the challenge window and scales the proving period to match (such that
|
||||
@ -345,6 +383,13 @@ func SetWPoStChallengeWindow(period abi.ChainEpoch) {
|
||||
// scale it if we're scaling the challenge period.
|
||||
miner6.WPoStDisputeWindow = period * 30
|
||||
|
||||
miner7.WPoStChallengeWindow = period
|
||||
miner7.WPoStProvingPeriod = period * abi.ChainEpoch(miner7.WPoStPeriodDeadlines)
|
||||
|
||||
// by default, this is 2x finality which is 30 periods.
|
||||
// scale it if we're scaling the challenge period.
|
||||
miner7.WPoStDisputeWindow = period * 30
|
||||
|
||||
}
|
||||
|
||||
func GetWinningPoStSectorSetLookback(nwVer network.Version) abi.ChainEpoch {
|
||||
@ -357,15 +402,15 @@ func GetWinningPoStSectorSetLookback(nwVer network.Version) abi.ChainEpoch {
|
||||
}
|
||||
|
||||
func GetMaxSectorExpirationExtension() abi.ChainEpoch {
|
||||
return miner6.MaxSectorExpirationExtension
|
||||
return miner7.MaxSectorExpirationExtension
|
||||
}
|
||||
|
||||
func GetMinSectorExpiration() abi.ChainEpoch {
|
||||
return miner6.MinSectorExpiration
|
||||
return miner7.MinSectorExpiration
|
||||
}
|
||||
|
||||
func GetMaxPoStPartitions(nv network.Version, p abi.RegisteredPoStProof) (int, error) {
|
||||
sectorsPerPart, err := builtin6.PoStProofWindowPoStPartitionSectors(p)
|
||||
sectorsPerPart, err := builtin7.PoStProofWindowPoStPartitionSectors(p)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
@ -378,8 +423,8 @@ func GetMaxPoStPartitions(nv network.Version, p abi.RegisteredPoStProof) (int, e
|
||||
|
||||
func GetDefaultSectorSize() abi.SectorSize {
|
||||
// supported sector sizes are the same across versions.
|
||||
szs := make([]abi.SectorSize, 0, len(miner6.PreCommitSealProofTypesV8))
|
||||
for spt := range miner6.PreCommitSealProofTypesV8 {
|
||||
szs := make([]abi.SectorSize, 0, len(miner7.PreCommitSealProofTypesV8))
|
||||
for spt := range miner7.PreCommitSealProofTypesV8 {
|
||||
ss, err := spt.SectorSize()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
@ -404,7 +449,7 @@ func GetSectorMaxLifetime(proof abi.RegisteredSealProof, nwVer network.Version)
|
||||
return builtin4.SealProofPoliciesV0[proof].SectorMaxLifetime
|
||||
}
|
||||
|
||||
return builtin6.SealProofPoliciesV11[proof].SectorMaxLifetime
|
||||
return builtin7.SealProofPoliciesV11[proof].SectorMaxLifetime
|
||||
}
|
||||
|
||||
func GetAddressedSectorsMax(nwVer network.Version) (int, error) {
|
||||
@ -432,6 +477,9 @@ func GetAddressedSectorsMax(nwVer network.Version) (int, error) {
|
||||
case actors.Version6:
|
||||
return miner6.AddressedSectorsMax, nil
|
||||
|
||||
case actors.Version7:
|
||||
return miner7.AddressedSectorsMax, nil
|
||||
|
||||
default:
|
||||
return 0, xerrors.Errorf("unsupported network version")
|
||||
}
|
||||
@ -469,6 +517,10 @@ func GetDeclarationsMax(nwVer network.Version) (int, error) {
|
||||
|
||||
return miner6.DeclarationsMax, nil
|
||||
|
||||
case actors.Version7:
|
||||
|
||||
return miner7.DeclarationsMax, nil
|
||||
|
||||
default:
|
||||
return 0, xerrors.Errorf("unsupported network version")
|
||||
}
|
||||
@ -505,6 +557,10 @@ func AggregateProveCommitNetworkFee(nwVer network.Version, aggregateSize int, ba
|
||||
|
||||
return miner6.AggregateProveCommitNetworkFee(aggregateSize, baseFee), nil
|
||||
|
||||
case actors.Version7:
|
||||
|
||||
return miner7.AggregateProveCommitNetworkFee(aggregateSize, baseFee), nil
|
||||
|
||||
default:
|
||||
return big.Zero(), xerrors.Errorf("unsupported network version")
|
||||
}
|
||||
@ -541,6 +597,10 @@ func AggregatePreCommitNetworkFee(nwVer network.Version, aggregateSize int, base
|
||||
|
||||
return miner6.AggregatePreCommitNetworkFee(aggregateSize, baseFee), nil
|
||||
|
||||
case actors.Version7:
|
||||
|
||||
return miner7.AggregatePreCommitNetworkFee(aggregateSize, baseFee), nil
|
||||
|
||||
default:
|
||||
return big.Zero(), xerrors.Errorf("unsupported network version")
|
||||
}
|
||||
|
@ -20,9 +20,9 @@ const ({{range .actorVersions}}
|
||||
|
||||
/* inline-gen start */
|
||||
|
||||
var LatestVersion = 6
|
||||
var LatestVersion = 7
|
||||
|
||||
var Versions = []int{0, 2, 3, 4, 5, 6}
|
||||
var Versions = []int{0, 2, 3, 4, 5, 6, 7}
|
||||
|
||||
const (
|
||||
Version0 Version = 0
|
||||
@ -31,6 +31,7 @@ const (
|
||||
Version4 Version = 4
|
||||
Version5 Version = 5
|
||||
Version6 Version = 6
|
||||
Version7 Version = 7
|
||||
)
|
||||
|
||||
/* inline-gen end */
|
||||
@ -50,6 +51,8 @@ func VersionForNetwork(version network.Version) (Version, error) {
|
||||
return Version5, nil
|
||||
case network.Version14:
|
||||
return Version6, nil
|
||||
case network.Version15:
|
||||
return Version7, nil
|
||||
default:
|
||||
return -1, fmt.Errorf("unsupported network version %d", version)
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ func (syncer *Syncer) SyncCheckpoint(ctx context.Context, tsk types.TipSetKey) e
|
||||
return xerrors.Errorf("called with empty tsk")
|
||||
}
|
||||
|
||||
ts, err := syncer.ChainStore().LoadTipSet(tsk)
|
||||
ts, err := syncer.ChainStore().LoadTipSet(ctx, tsk)
|
||||
if err != nil {
|
||||
tss, err := syncer.Exchange.GetBlocks(ctx, tsk, 1)
|
||||
if err != nil {
|
||||
@ -28,7 +28,7 @@ func (syncer *Syncer) SyncCheckpoint(ctx context.Context, tsk types.TipSetKey) e
|
||||
return xerrors.Errorf("failed to switch chain when syncing checkpoint: %w", err)
|
||||
}
|
||||
|
||||
if err := syncer.ChainStore().SetCheckpoint(ts); err != nil {
|
||||
if err := syncer.ChainStore().SetCheckpoint(ctx, ts); err != nil {
|
||||
return xerrors.Errorf("failed to set the chain checkpoint: %w", err)
|
||||
}
|
||||
|
||||
@ -41,7 +41,7 @@ func (syncer *Syncer) switchChain(ctx context.Context, ts *types.TipSet) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
if anc, err := syncer.store.IsAncestorOf(ts, hts); err == nil && anc {
|
||||
if anc, err := syncer.store.IsAncestorOf(ctx, ts, hts); err == nil && anc {
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -50,7 +50,7 @@ func (syncer *Syncer) switchChain(ctx context.Context, ts *types.TipSet) error {
|
||||
return xerrors.Errorf("failed to collect chain for checkpoint: %w", err)
|
||||
}
|
||||
|
||||
if err := syncer.ChainStore().SetHead(ts); err != nil {
|
||||
if err := syncer.ChainStore().SetHead(ctx, ts); err != nil {
|
||||
return xerrors.Errorf("failed to set the chain head: %w", err)
|
||||
}
|
||||
return nil
|
||||
|
@ -28,6 +28,7 @@ import (
|
||||
exported4 "github.com/filecoin-project/specs-actors/v4/actors/builtin/exported"
|
||||
exported5 "github.com/filecoin-project/specs-actors/v5/actors/builtin/exported"
|
||||
exported6 "github.com/filecoin-project/specs-actors/v6/actors/builtin/exported"
|
||||
exported7 "github.com/filecoin-project/specs-actors/v7/actors/builtin/exported"
|
||||
|
||||
/* inline-gen end */
|
||||
|
||||
@ -59,6 +60,7 @@ func NewActorRegistry() *vm.ActorRegistry {
|
||||
inv.Register(vm.ActorsVersionPredicate(actors.Version4), exported4.BuiltinActors()...)
|
||||
inv.Register(vm.ActorsVersionPredicate(actors.Version5), exported5.BuiltinActors()...)
|
||||
inv.Register(vm.ActorsVersionPredicate(actors.Version6), exported6.BuiltinActors()...)
|
||||
inv.Register(vm.ActorsVersionPredicate(actors.Version7), exported7.BuiltinActors()...)
|
||||
|
||||
/* inline-gen end */
|
||||
|
||||
@ -99,7 +101,7 @@ func (t *TipSetExecutor) ApplyBlocks(ctx context.Context, sm *stmgr.StateManager
|
||||
Actors: NewActorRegistry(),
|
||||
Syscalls: sm.Syscalls,
|
||||
CircSupplyCalc: sm.GetVMCirculatingSupply,
|
||||
NtwkVersion: sm.GetNtwkVersion,
|
||||
NetworkVersion: sm.GetNetworkVersion(ctx, epoch),
|
||||
BaseFee: baseFee,
|
||||
LookbackState: stmgr.LookbackStateGetterForTipset(sm, ts),
|
||||
}
|
||||
@ -289,7 +291,7 @@ func (t *TipSetExecutor) ExecuteTipSet(ctx context.Context, sm *stmgr.StateManag
|
||||
var parentEpoch abi.ChainEpoch
|
||||
pstate := blks[0].ParentStateRoot
|
||||
if blks[0].Height > 0 {
|
||||
parent, err := sm.ChainStore().GetBlock(blks[0].Parents[0])
|
||||
parent, err := sm.ChainStore().GetBlock(ctx, blks[0].Parents[0])
|
||||
if err != nil {
|
||||
return cid.Undef, cid.Undef, xerrors.Errorf("getting parent block: %w", err)
|
||||
}
|
||||
@ -297,9 +299,9 @@ func (t *TipSetExecutor) ExecuteTipSet(ctx context.Context, sm *stmgr.StateManag
|
||||
parentEpoch = parent.Height
|
||||
}
|
||||
|
||||
r := rand.NewStateRand(sm.ChainStore(), ts.Cids(), sm.Beacon())
|
||||
r := rand.NewStateRand(sm.ChainStore(), ts.Cids(), sm.Beacon(), sm.GetNetworkVersion)
|
||||
|
||||
blkmsgs, err := sm.ChainStore().BlockMsgsForTipset(ts)
|
||||
blkmsgs, err := sm.ChainStore().BlockMsgsForTipset(ctx, ts)
|
||||
if err != nil {
|
||||
return cid.Undef, cid.Undef, xerrors.Errorf("getting block messages for tipset: %w", err)
|
||||
}
|
||||
|
@ -90,19 +90,19 @@ func (filec *FilecoinEC) ValidateBlock(ctx context.Context, b *types.FullBlock)
|
||||
|
||||
h := b.Header
|
||||
|
||||
baseTs, err := filec.store.LoadTipSet(types.NewTipSetKey(h.Parents...))
|
||||
baseTs, err := filec.store.LoadTipSet(ctx, types.NewTipSetKey(h.Parents...))
|
||||
if err != nil {
|
||||
return xerrors.Errorf("load parent tipset failed (%s): %w", h.Parents, err)
|
||||
}
|
||||
|
||||
winPoStNv := filec.sm.GetNtwkVersion(ctx, baseTs.Height())
|
||||
winPoStNv := filec.sm.GetNetworkVersion(ctx, baseTs.Height())
|
||||
|
||||
lbts, lbst, err := stmgr.GetLookbackTipSetForRound(ctx, filec.sm, baseTs, h.Height)
|
||||
if err != nil {
|
||||
return xerrors.Errorf("failed to get lookback tipset for block: %w", err)
|
||||
}
|
||||
|
||||
prevBeacon, err := filec.store.GetLatestBeaconEntry(baseTs)
|
||||
prevBeacon, err := filec.store.GetLatestBeaconEntry(ctx, baseTs)
|
||||
if err != nil {
|
||||
return xerrors.Errorf("failed to get latest beacon entry: %w", err)
|
||||
}
|
||||
@ -171,7 +171,7 @@ func (filec *FilecoinEC) ValidateBlock(ctx context.Context, b *types.FullBlock)
|
||||
}
|
||||
|
||||
if stateroot != h.ParentStateRoot {
|
||||
msgs, err := filec.store.MessagesForTipset(baseTs)
|
||||
msgs, err := filec.store.MessagesForTipset(ctx, baseTs)
|
||||
if err != nil {
|
||||
log.Error("failed to load messages for tipset during tipset state mismatch error: ", err)
|
||||
} else {
|
||||
@ -457,7 +457,7 @@ func (filec *FilecoinEC) checkBlockMessages(ctx context.Context, b *types.FullBl
|
||||
return xerrors.Errorf("failed to load base state tree: %w", err)
|
||||
}
|
||||
|
||||
nv := filec.sm.GetNtwkVersion(ctx, b.Header.Height)
|
||||
nv := filec.sm.GetNetworkVersion(ctx, b.Header.Height)
|
||||
pl := vm.PricelistByEpoch(baseTs.Height())
|
||||
var sumGasLimit int64
|
||||
checkMsg := func(msg types.ChainMsg) error {
|
||||
@ -479,7 +479,7 @@ func (filec *FilecoinEC) checkBlockMessages(ctx context.Context, b *types.FullBl
|
||||
// Phase 2: (Partial) semantic validation:
|
||||
// the sender exists and is an account actor, and the nonces make sense
|
||||
var sender address.Address
|
||||
if filec.sm.GetNtwkVersion(ctx, b.Header.Height) >= network.Version13 {
|
||||
if filec.sm.GetNetworkVersion(ctx, b.Header.Height) >= network.Version13 {
|
||||
sender, err = st.LookupID(m.From)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -519,7 +519,7 @@ func (filec *FilecoinEC) checkBlockMessages(ctx context.Context, b *types.FullBl
|
||||
return xerrors.Errorf("block had invalid bls message at index %d: %w", i, err)
|
||||
}
|
||||
|
||||
c, err := store.PutMessage(tmpbs, m)
|
||||
c, err := store.PutMessage(ctx, tmpbs, m)
|
||||
if err != nil {
|
||||
return xerrors.Errorf("failed to store message %s: %w", m.Cid(), err)
|
||||
}
|
||||
@ -532,7 +532,7 @@ func (filec *FilecoinEC) checkBlockMessages(ctx context.Context, b *types.FullBl
|
||||
|
||||
smArr := blockadt.MakeEmptyArray(tmpstore)
|
||||
for i, m := range b.SecpkMessages {
|
||||
if filec.sm.GetNtwkVersion(ctx, b.Header.Height) >= network.Version14 {
|
||||
if filec.sm.GetNetworkVersion(ctx, b.Header.Height) >= network.Version14 {
|
||||
if m.Signature.Type != crypto.SigTypeSecp256k1 {
|
||||
return xerrors.Errorf("block had invalid secpk message at index %d: %w", i, err)
|
||||
}
|
||||
@ -553,7 +553,7 @@ func (filec *FilecoinEC) checkBlockMessages(ctx context.Context, b *types.FullBl
|
||||
return xerrors.Errorf("secpk message %s has invalid signature: %w", m.Cid(), err)
|
||||
}
|
||||
|
||||
c, err := store.PutMessage(tmpbs, m)
|
||||
c, err := store.PutMessage(ctx, tmpbs, m)
|
||||
if err != nil {
|
||||
return xerrors.Errorf("failed to store message %s: %w", m.Cid(), err)
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ import (
|
||||
)
|
||||
|
||||
func (filec *FilecoinEC) CreateBlock(ctx context.Context, w api.Wallet, bt *api.BlockTemplate) (*types.FullBlock, error) {
|
||||
pts, err := filec.sm.ChainStore().LoadTipSet(bt.Parents)
|
||||
pts, err := filec.sm.ChainStore().LoadTipSet(ctx, bt.Parents)
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("failed to load parent tipset: %w", err)
|
||||
}
|
||||
@ -59,14 +59,14 @@ func (filec *FilecoinEC) CreateBlock(ctx context.Context, w api.Wallet, bt *api.
|
||||
blsSigs = append(blsSigs, msg.Signature)
|
||||
blsMessages = append(blsMessages, &msg.Message)
|
||||
|
||||
c, err := filec.sm.ChainStore().PutMessage(&msg.Message)
|
||||
c, err := filec.sm.ChainStore().PutMessage(ctx, &msg.Message)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
blsMsgCids = append(blsMsgCids, c)
|
||||
} else {
|
||||
c, err := filec.sm.ChainStore().PutMessage(msg)
|
||||
} else if msg.Signature.Type == crypto.SigTypeSecp256k1 {
|
||||
c, err := filec.sm.ChainStore().PutMessage(ctx, msg)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -74,6 +74,8 @@ func (filec *FilecoinEC) CreateBlock(ctx context.Context, w api.Wallet, bt *api.
|
||||
secpkMsgCids = append(secpkMsgCids, c)
|
||||
secpkMessages = append(secpkMessages, msg)
|
||||
|
||||
} else {
|
||||
return nil, xerrors.Errorf("unknown sig type: %d", msg.Signature.Type)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/filecoin-project/specs-actors/v6/actors/migration/nv14"
|
||||
"github.com/filecoin-project/specs-actors/v7/actors/migration/nv15"
|
||||
|
||||
"github.com/ipfs/go-cid"
|
||||
cbor "github.com/ipfs/go-ipld-cbor"
|
||||
@ -156,6 +157,22 @@ func DefaultUpgradeSchedule() stmgr.UpgradeSchedule {
|
||||
StopWithin: 5,
|
||||
}},
|
||||
Expensive: true,
|
||||
}, {
|
||||
Height: build.UpgradeSnapDealsHeight,
|
||||
Network: network.Version15,
|
||||
Migration: UpgradeActorsV7,
|
||||
PreMigrations: []stmgr.PreMigration{{
|
||||
PreMigration: PreUpgradeActorsV7,
|
||||
StartWithin: 120,
|
||||
DontStartWithin: 60,
|
||||
StopWithin: 35,
|
||||
}, {
|
||||
PreMigration: PreUpgradeActorsV7,
|
||||
StartWithin: 30,
|
||||
DontStartWithin: 15,
|
||||
StopWithin: 5,
|
||||
}},
|
||||
Expensive: true,
|
||||
},
|
||||
}
|
||||
|
||||
@ -625,7 +642,7 @@ func splitGenesisMultisig0(ctx context.Context, em stmgr.ExecMonitor, addr addre
|
||||
|
||||
// TODO: After the Liftoff epoch, refactor this to use resetMultisigVesting
|
||||
func resetGenesisMsigs0(ctx context.Context, sm *stmgr.StateManager, store adt0.Store, tree *state.StateTree, startEpoch abi.ChainEpoch) error {
|
||||
gb, err := sm.ChainStore().GetGenesis()
|
||||
gb, err := sm.ChainStore().GetGenesis(ctx)
|
||||
if err != nil {
|
||||
return xerrors.Errorf("getting genesis block: %w", err)
|
||||
}
|
||||
@ -1170,7 +1187,94 @@ func upgradeActorsV6Common(
|
||||
// Perform the migration
|
||||
newHamtRoot, err := nv14.MigrateStateTree(ctx, store, stateRoot.Actors, epoch, config, migrationLogger{}, cache)
|
||||
if err != nil {
|
||||
return cid.Undef, xerrors.Errorf("upgrading to actors v5: %w", err)
|
||||
return cid.Undef, xerrors.Errorf("upgrading to actors v6: %w", err)
|
||||
}
|
||||
|
||||
// Persist the result.
|
||||
newRoot, err := store.Put(ctx, &types.StateRoot{
|
||||
Version: types.StateTreeVersion4,
|
||||
Actors: newHamtRoot,
|
||||
Info: stateRoot.Info,
|
||||
})
|
||||
if err != nil {
|
||||
return cid.Undef, xerrors.Errorf("failed to persist new state root: %w", err)
|
||||
}
|
||||
|
||||
// Persist the new tree.
|
||||
|
||||
{
|
||||
from := buf
|
||||
to := buf.Read()
|
||||
|
||||
if err := vm.Copy(ctx, from, to, newRoot); err != nil {
|
||||
return cid.Undef, xerrors.Errorf("copying migrated tree: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
return newRoot, nil
|
||||
}
|
||||
|
||||
func UpgradeActorsV7(ctx context.Context, sm *stmgr.StateManager, cache stmgr.MigrationCache, cb stmgr.ExecMonitor, root cid.Cid, epoch abi.ChainEpoch, ts *types.TipSet) (cid.Cid, error) {
|
||||
// Use all the CPUs except 3.
|
||||
workerCount := runtime.NumCPU() - 3
|
||||
if workerCount <= 0 {
|
||||
workerCount = 1
|
||||
}
|
||||
|
||||
config := nv15.Config{
|
||||
MaxWorkers: uint(workerCount),
|
||||
JobQueueSize: 1000,
|
||||
ResultQueueSize: 100,
|
||||
ProgressLogPeriod: 10 * time.Second,
|
||||
}
|
||||
|
||||
newRoot, err := upgradeActorsV7Common(ctx, sm, cache, root, epoch, ts, config)
|
||||
if err != nil {
|
||||
return cid.Undef, xerrors.Errorf("migrating actors v6 state: %w", err)
|
||||
}
|
||||
|
||||
return newRoot, nil
|
||||
}
|
||||
|
||||
func PreUpgradeActorsV7(ctx context.Context, sm *stmgr.StateManager, cache stmgr.MigrationCache, root cid.Cid, epoch abi.ChainEpoch, ts *types.TipSet) error {
|
||||
// Use half the CPUs for pre-migration, but leave at least 3.
|
||||
workerCount := runtime.NumCPU()
|
||||
if workerCount <= 4 {
|
||||
workerCount = 1
|
||||
} else {
|
||||
workerCount /= 2
|
||||
}
|
||||
|
||||
config := nv15.Config{MaxWorkers: uint(workerCount)}
|
||||
_, err := upgradeActorsV7Common(ctx, sm, cache, root, epoch, ts, config)
|
||||
return err
|
||||
}
|
||||
|
||||
func upgradeActorsV7Common(
|
||||
ctx context.Context, sm *stmgr.StateManager, cache stmgr.MigrationCache,
|
||||
root cid.Cid, epoch abi.ChainEpoch, ts *types.TipSet,
|
||||
config nv15.Config,
|
||||
) (cid.Cid, error) {
|
||||
buf := blockstore.NewTieredBstore(sm.ChainStore().StateBlockstore(), blockstore.NewMemorySync())
|
||||
store := store.ActorStore(ctx, buf)
|
||||
|
||||
// Load the state root.
|
||||
var stateRoot types.StateRoot
|
||||
if err := store.Get(ctx, root, &stateRoot); err != nil {
|
||||
return cid.Undef, xerrors.Errorf("failed to decode state root: %w", err)
|
||||
}
|
||||
|
||||
if stateRoot.Version != types.StateTreeVersion4 {
|
||||
return cid.Undef, xerrors.Errorf(
|
||||
"expected state root version 4 for actors v7 upgrade, got %d",
|
||||
stateRoot.Version,
|
||||
)
|
||||
}
|
||||
|
||||
// Perform the migration
|
||||
newHamtRoot, err := nv15.MigrateStateTree(ctx, store, stateRoot.Actors, epoch, config, migrationLogger{}, cache)
|
||||
if err != nil {
|
||||
return cid.Undef, xerrors.Errorf("upgrading to actors v7: %w", err)
|
||||
}
|
||||
|
||||
// Persist the result.
|
||||
|
@ -87,7 +87,7 @@ func (fcs *fakeCS) ChainGetPath(ctx context.Context, from, to types.TipSetKey) (
|
||||
}
|
||||
|
||||
// copied from the chainstore
|
||||
revert, apply, err := store.ReorgOps(func(tsk types.TipSetKey) (*types.TipSet, error) {
|
||||
revert, apply, err := store.ReorgOps(ctx, func(ctx context.Context, tsk types.TipSetKey) (*types.TipSet, error) {
|
||||
return fcs.ChainGetTipSet(ctx, tsk)
|
||||
}, fromTs, toTs)
|
||||
if err != nil {
|
||||
|
@ -27,11 +27,11 @@ func NewMockAPI(bs blockstore.Blockstore) *MockAPI {
|
||||
}
|
||||
|
||||
func (m *MockAPI) ChainHasObj(ctx context.Context, c cid.Cid) (bool, error) {
|
||||
return m.bs.Has(c)
|
||||
return m.bs.Has(ctx, c)
|
||||
}
|
||||
|
||||
func (m *MockAPI) ChainReadObj(ctx context.Context, c cid.Cid) ([]byte, error) {
|
||||
blk, err := m.bs.Get(c)
|
||||
blk, err := m.bs.Get(ctx, c)
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("blockstore get: %w", err)
|
||||
}
|
||||
|
@ -136,7 +136,7 @@ func (s *server) serviceRequest(ctx context.Context, req *validatedRequest) (*Re
|
||||
_, span := trace.StartSpan(ctx, "chainxchg.ServiceRequest")
|
||||
defer span.End()
|
||||
|
||||
chain, err := collectChainSegment(s.cs, req)
|
||||
chain, err := collectChainSegment(ctx, s.cs, req)
|
||||
if err != nil {
|
||||
log.Warn("block sync request: collectChainSegment failed: ", err)
|
||||
return &Response{
|
||||
@ -156,13 +156,13 @@ func (s *server) serviceRequest(ctx context.Context, req *validatedRequest) (*Re
|
||||
}, nil
|
||||
}
|
||||
|
||||
func collectChainSegment(cs *store.ChainStore, req *validatedRequest) ([]*BSTipSet, error) {
|
||||
func collectChainSegment(ctx context.Context, cs *store.ChainStore, req *validatedRequest) ([]*BSTipSet, error) {
|
||||
var bstips []*BSTipSet
|
||||
|
||||
cur := req.head
|
||||
for {
|
||||
var bst BSTipSet
|
||||
ts, err := cs.LoadTipSet(cur)
|
||||
ts, err := cs.LoadTipSet(ctx, cur)
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("failed loading tipset %s: %w", cur, err)
|
||||
}
|
||||
@ -172,7 +172,7 @@ func collectChainSegment(cs *store.ChainStore, req *validatedRequest) ([]*BSTipS
|
||||
}
|
||||
|
||||
if req.options.IncludeMessages {
|
||||
bmsgs, bmincl, smsgs, smincl, err := gatherMessages(cs, ts)
|
||||
bmsgs, bmincl, smsgs, smincl, err := gatherMessages(ctx, cs, ts)
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("gather messages failed: %w", err)
|
||||
}
|
||||
@ -197,14 +197,14 @@ func collectChainSegment(cs *store.ChainStore, req *validatedRequest) ([]*BSTipS
|
||||
}
|
||||
}
|
||||
|
||||
func gatherMessages(cs *store.ChainStore, ts *types.TipSet) ([]*types.Message, [][]uint64, []*types.SignedMessage, [][]uint64, error) {
|
||||
func gatherMessages(ctx context.Context, cs *store.ChainStore, ts *types.TipSet) ([]*types.Message, [][]uint64, []*types.SignedMessage, [][]uint64, error) {
|
||||
blsmsgmap := make(map[cid.Cid]uint64)
|
||||
secpkmsgmap := make(map[cid.Cid]uint64)
|
||||
var secpkincl, blsincl [][]uint64
|
||||
|
||||
var blscids, secpkcids []cid.Cid
|
||||
for _, block := range ts.Blocks() {
|
||||
bc, sc, err := cs.ReadMsgMetaCids(block.Messages)
|
||||
bc, sc, err := cs.ReadMsgMetaCids(ctx, block.Messages)
|
||||
if err != nil {
|
||||
return nil, nil, nil, nil, err
|
||||
}
|
||||
@ -237,12 +237,12 @@ func gatherMessages(cs *store.ChainStore, ts *types.TipSet) ([]*types.Message, [
|
||||
secpkincl = append(secpkincl, smi)
|
||||
}
|
||||
|
||||
blsmsgs, err := cs.LoadMessagesFromCids(blscids)
|
||||
blsmsgs, err := cs.LoadMessagesFromCids(ctx, blscids)
|
||||
if err != nil {
|
||||
return nil, nil, nil, nil, err
|
||||
}
|
||||
|
||||
secpkmsgs, err := cs.LoadSignedMessagesFromCids(secpkcids)
|
||||
secpkmsgs, err := cs.LoadSignedMessagesFromCids(ctx, secpkcids)
|
||||
if err != nil {
|
||||
return nil, nil, nil, nil, err
|
||||
}
|
||||
|
@ -9,6 +9,8 @@ import (
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
proof7 "github.com/filecoin-project/specs-actors/v7/actors/runtime/proof"
|
||||
|
||||
"github.com/filecoin-project/lotus/chain/rand"
|
||||
|
||||
"github.com/filecoin-project/go-state-types/network"
|
||||
@ -239,7 +241,7 @@ func NewGeneratorWithSectorsAndUpgradeSchedule(numSectors int, us stmgr.UpgradeS
|
||||
genfb := &types.FullBlock{Header: genb.Genesis}
|
||||
gents := store.NewFullTipSet([]*types.FullBlock{genfb})
|
||||
|
||||
if err := cs.SetGenesis(genb.Genesis); err != nil {
|
||||
if err := cs.SetGenesis(context.TODO(), genb.Genesis); err != nil {
|
||||
return nil, xerrors.Errorf("set genesis failed: %w", err)
|
||||
}
|
||||
|
||||
@ -469,7 +471,7 @@ func (cg *ChainGen) NextTipSetFromMinersWithMessagesAndNulls(base *types.TipSet,
|
||||
return nil, xerrors.Errorf("making a block for next tipset failed: %w", err)
|
||||
}
|
||||
|
||||
if err := cg.cs.PersistBlockHeaders(fblk.Header); err != nil {
|
||||
if err := cg.cs.PersistBlockHeaders(context.TODO(), fblk.Header); err != nil {
|
||||
return nil, xerrors.Errorf("chainstore AddBlock: %w", err)
|
||||
}
|
||||
|
||||
@ -686,6 +688,10 @@ func (m genFakeVerifier) VerifyAggregateSeals(aggregate proof5.AggregateSealVeri
|
||||
panic("not supported")
|
||||
}
|
||||
|
||||
func (m genFakeVerifier) VerifyReplicaUpdate(update proof7.ReplicaUpdateInfo) (bool, error) {
|
||||
panic("not supported")
|
||||
}
|
||||
|
||||
func (m genFakeVerifier) VerifyWinningPoSt(ctx context.Context, info proof5.WinningPoStVerifyInfo) (bool, error) {
|
||||
panic("not supported")
|
||||
}
|
||||
|
@ -479,6 +479,10 @@ func VerifyPreSealedData(ctx context.Context, cs *store.ChainStore, sys vm.Sysca
|
||||
verifNeeds := make(map[address.Address]abi.PaddedPieceSize)
|
||||
var sum abi.PaddedPieceSize
|
||||
|
||||
csc := func(context.Context, abi.ChainEpoch, *state.StateTree) (abi.TokenAmount, error) {
|
||||
return big.Zero(), nil
|
||||
}
|
||||
|
||||
vmopt := vm.VMOpts{
|
||||
StateBase: stateroot,
|
||||
Epoch: 0,
|
||||
@ -486,11 +490,9 @@ func VerifyPreSealedData(ctx context.Context, cs *store.ChainStore, sys vm.Sysca
|
||||
Bstore: cs.StateBlockstore(),
|
||||
Actors: filcns.NewActorRegistry(),
|
||||
Syscalls: mkFakedSigSyscalls(sys),
|
||||
CircSupplyCalc: nil,
|
||||
NtwkVersion: func(_ context.Context, _ abi.ChainEpoch) network.Version {
|
||||
return nv
|
||||
},
|
||||
BaseFee: types.NewInt(0),
|
||||
CircSupplyCalc: csc,
|
||||
NetworkVersion: nv,
|
||||
BaseFee: types.NewInt(0),
|
||||
}
|
||||
vm, err := vm.NewVM(ctx, &vmopt)
|
||||
if err != nil {
|
||||
@ -591,7 +593,7 @@ func MakeGenesisBlock(ctx context.Context, j journal.Journal, bs bstore.Blocksto
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("serializing msgmeta failed: %w", err)
|
||||
}
|
||||
if err := bs.Put(mmb); err != nil {
|
||||
if err := bs.Put(ctx, mmb); err != nil {
|
||||
return nil, xerrors.Errorf("putting msgmeta block to blockstore: %w", err)
|
||||
}
|
||||
|
||||
@ -621,7 +623,7 @@ func MakeGenesisBlock(ctx context.Context, j journal.Journal, bs bstore.Blocksto
|
||||
return nil, xerrors.Errorf("filecoinGenesisCid != gblk.Cid")
|
||||
}
|
||||
|
||||
if err := bs.Put(gblk); err != nil {
|
||||
if err := bs.Put(ctx, gblk); err != nil {
|
||||
return nil, xerrors.Errorf("failed writing filecoin genesis block to blockstore: %w", err)
|
||||
}
|
||||
|
||||
@ -652,7 +654,7 @@ func MakeGenesisBlock(ctx context.Context, j journal.Journal, bs bstore.Blocksto
|
||||
return nil, xerrors.Errorf("serializing block header failed: %w", err)
|
||||
}
|
||||
|
||||
if err := bs.Put(sb); err != nil {
|
||||
if err := bs.Put(ctx, sb); err != nil {
|
||||
return nil, xerrors.Errorf("putting header to blockstore: %w", err)
|
||||
}
|
||||
|
||||
|
@ -6,6 +6,8 @@ import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
|
||||
runtime7 "github.com/filecoin-project/specs-actors/v7/actors/runtime"
|
||||
|
||||
builtin6 "github.com/filecoin-project/specs-actors/v6/actors/builtin"
|
||||
|
||||
"github.com/ipfs/go-cid"
|
||||
@ -29,7 +31,6 @@ import (
|
||||
market4 "github.com/filecoin-project/specs-actors/v4/actors/builtin/market"
|
||||
power4 "github.com/filecoin-project/specs-actors/v4/actors/builtin/power"
|
||||
reward4 "github.com/filecoin-project/specs-actors/v4/actors/builtin/reward"
|
||||
runtime5 "github.com/filecoin-project/specs-actors/v5/actors/runtime"
|
||||
|
||||
"github.com/filecoin-project/lotus/chain/actors"
|
||||
"github.com/filecoin-project/lotus/chain/actors/adt"
|
||||
@ -57,7 +58,7 @@ func MinerAddress(genesisIndex uint64) address.Address {
|
||||
}
|
||||
|
||||
type fakedSigSyscalls struct {
|
||||
runtime5.Syscalls
|
||||
runtime7.Syscalls
|
||||
}
|
||||
|
||||
func (fss *fakedSigSyscalls) VerifySignature(signature crypto.Signature, signer address.Address, plaintext []byte) error {
|
||||
@ -65,7 +66,7 @@ func (fss *fakedSigSyscalls) VerifySignature(signature crypto.Signature, signer
|
||||
}
|
||||
|
||||
func mkFakedSigSyscalls(base vm.SyscallBuilder) vm.SyscallBuilder {
|
||||
return func(ctx context.Context, rt *vm.Runtime) runtime5.Syscalls {
|
||||
return func(ctx context.Context, rt *vm.Runtime) runtime7.Syscalls {
|
||||
return &fakedSigSyscalls{
|
||||
base(ctx, rt),
|
||||
}
|
||||
@ -93,10 +94,8 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sys vm.Syscal
|
||||
Actors: filcns.NewActorRegistry(),
|
||||
Syscalls: mkFakedSigSyscalls(sys),
|
||||
CircSupplyCalc: csc,
|
||||
NtwkVersion: func(_ context.Context, _ abi.ChainEpoch) network.Version {
|
||||
return nv
|
||||
},
|
||||
BaseFee: types.NewInt(0),
|
||||
NetworkVersion: nv,
|
||||
BaseFee: types.NewInt(0),
|
||||
}
|
||||
|
||||
vm, err := vm.NewVM(ctx, vmopt)
|
||||
@ -509,31 +508,13 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sys vm.Syscal
|
||||
// TODO: copied from actors test harness, deduplicate or remove from here
|
||||
type fakeRand struct{}
|
||||
|
||||
func (fr *fakeRand) GetChainRandomnessV2(ctx context.Context, personalization crypto.DomainSeparationTag, randEpoch abi.ChainEpoch, entropy []byte) ([]byte, error) {
|
||||
func (fr *fakeRand) GetChainRandomness(ctx context.Context, personalization crypto.DomainSeparationTag, randEpoch abi.ChainEpoch, entropy []byte) ([]byte, error) {
|
||||
out := make([]byte, 32)
|
||||
_, _ = rand.New(rand.NewSource(int64(randEpoch * 1000))).Read(out) //nolint
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (fr *fakeRand) GetChainRandomnessV1(ctx context.Context, personalization crypto.DomainSeparationTag, randEpoch abi.ChainEpoch, entropy []byte) ([]byte, error) {
|
||||
out := make([]byte, 32)
|
||||
_, _ = rand.New(rand.NewSource(int64(randEpoch * 1000))).Read(out) //nolint
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (fr *fakeRand) GetBeaconRandomnessV3(ctx context.Context, personalization crypto.DomainSeparationTag, randEpoch abi.ChainEpoch, entropy []byte) ([]byte, error) {
|
||||
out := make([]byte, 32)
|
||||
_, _ = rand.New(rand.NewSource(int64(randEpoch))).Read(out) //nolint
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (fr *fakeRand) GetBeaconRandomnessV2(ctx context.Context, personalization crypto.DomainSeparationTag, randEpoch abi.ChainEpoch, entropy []byte) ([]byte, error) {
|
||||
out := make([]byte, 32)
|
||||
_, _ = rand.New(rand.NewSource(int64(randEpoch))).Read(out) //nolint
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (fr *fakeRand) GetBeaconRandomnessV1(ctx context.Context, personalization crypto.DomainSeparationTag, randEpoch abi.ChainEpoch, entropy []byte) ([]byte, error) {
|
||||
func (fr *fakeRand) GetBeaconRandomness(ctx context.Context, personalization crypto.DomainSeparationTag, randEpoch abi.ChainEpoch, entropy []byte) ([]byte, error) {
|
||||
out := make([]byte, 32)
|
||||
_, _ = rand.New(rand.NewSource(int64(randEpoch))).Read(out) //nolint
|
||||
return out, nil
|
||||
|
@ -1,6 +1,7 @@
|
||||
package slashfilter
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/filecoin-project/lotus/build"
|
||||
@ -27,7 +28,7 @@ func New(dstore ds.Batching) *SlashFilter {
|
||||
}
|
||||
}
|
||||
|
||||
func (f *SlashFilter) MinedBlock(bh *types.BlockHeader, parentEpoch abi.ChainEpoch) error {
|
||||
func (f *SlashFilter) MinedBlock(ctx context.Context, bh *types.BlockHeader, parentEpoch abi.ChainEpoch) error {
|
||||
if build.IsNearUpgrade(bh.Height, build.UpgradeOrangeHeight) {
|
||||
return nil
|
||||
}
|
||||
@ -35,7 +36,7 @@ func (f *SlashFilter) MinedBlock(bh *types.BlockHeader, parentEpoch abi.ChainEpo
|
||||
epochKey := ds.NewKey(fmt.Sprintf("/%s/%d", bh.Miner, bh.Height))
|
||||
{
|
||||
// double-fork mining (2 blocks at one epoch)
|
||||
if err := checkFault(f.byEpoch, epochKey, bh, "double-fork mining faults"); err != nil {
|
||||
if err := checkFault(ctx, f.byEpoch, epochKey, bh, "double-fork mining faults"); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@ -43,7 +44,7 @@ func (f *SlashFilter) MinedBlock(bh *types.BlockHeader, parentEpoch abi.ChainEpo
|
||||
parentsKey := ds.NewKey(fmt.Sprintf("/%s/%x", bh.Miner, types.NewTipSetKey(bh.Parents...).Bytes()))
|
||||
{
|
||||
// time-offset mining faults (2 blocks with the same parents)
|
||||
if err := checkFault(f.byParents, parentsKey, bh, "time-offset mining faults"); err != nil {
|
||||
if err := checkFault(ctx, f.byParents, parentsKey, bh, "time-offset mining faults"); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@ -53,14 +54,14 @@ func (f *SlashFilter) MinedBlock(bh *types.BlockHeader, parentEpoch abi.ChainEpo
|
||||
|
||||
// First check if we have mined a block on the parent epoch
|
||||
parentEpochKey := ds.NewKey(fmt.Sprintf("/%s/%d", bh.Miner, parentEpoch))
|
||||
have, err := f.byEpoch.Has(parentEpochKey)
|
||||
have, err := f.byEpoch.Has(ctx, parentEpochKey)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if have {
|
||||
// If we had, make sure it's in our parent tipset
|
||||
cidb, err := f.byEpoch.Get(parentEpochKey)
|
||||
cidb, err := f.byEpoch.Get(ctx, parentEpochKey)
|
||||
if err != nil {
|
||||
return xerrors.Errorf("getting other block cid: %w", err)
|
||||
}
|
||||
@ -83,25 +84,25 @@ func (f *SlashFilter) MinedBlock(bh *types.BlockHeader, parentEpoch abi.ChainEpo
|
||||
}
|
||||
}
|
||||
|
||||
if err := f.byParents.Put(parentsKey, bh.Cid().Bytes()); err != nil {
|
||||
if err := f.byParents.Put(ctx, parentsKey, bh.Cid().Bytes()); err != nil {
|
||||
return xerrors.Errorf("putting byEpoch entry: %w", err)
|
||||
}
|
||||
|
||||
if err := f.byEpoch.Put(epochKey, bh.Cid().Bytes()); err != nil {
|
||||
if err := f.byEpoch.Put(ctx, epochKey, bh.Cid().Bytes()); err != nil {
|
||||
return xerrors.Errorf("putting byEpoch entry: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func checkFault(t ds.Datastore, key ds.Key, bh *types.BlockHeader, faultType string) error {
|
||||
fault, err := t.Has(key)
|
||||
func checkFault(ctx context.Context, t ds.Datastore, key ds.Key, bh *types.BlockHeader, faultType string) error {
|
||||
fault, err := t.Has(ctx, key)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if fault {
|
||||
cidb, err := t.Get(key)
|
||||
cidb, err := t.Get(ctx, key)
|
||||
if err != nil {
|
||||
return xerrors.Errorf("getting other block cid: %w", err)
|
||||
}
|
||||
|
@ -89,7 +89,7 @@ func (fm *FundManager) Start() error {
|
||||
// - in State() only load addresses with in-progress messages
|
||||
// - load the others just-in-time from getFundedAddress
|
||||
// - delete(fm.fundedAddrs, addr) when the queue has been processed
|
||||
return fm.str.forEach(func(state *FundedAddressState) {
|
||||
return fm.str.forEach(fm.ctx, func(state *FundedAddressState) {
|
||||
fa := newFundedAddress(fm, state.Addr)
|
||||
fa.state = state
|
||||
fm.fundedAddrs[fa.state.Addr] = fa
|
||||
@ -322,7 +322,7 @@ func (a *fundedAddress) clearWaitState() {
|
||||
// Save state to datastore
|
||||
func (a *fundedAddress) saveState() {
|
||||
// Not much we can do if saving to the datastore fails, just log
|
||||
err := a.str.save(a.state)
|
||||
err := a.str.save(a.ctx, a.state)
|
||||
if err != nil {
|
||||
log.Errorf("saving state to store for addr %s: %v", a.state.Addr, err)
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package market
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
|
||||
cborrpc "github.com/filecoin-project/go-cbor-util"
|
||||
"github.com/ipfs/go-datastore"
|
||||
@ -27,7 +28,7 @@ func newStore(ds dtypes.MetadataDS) *Store {
|
||||
}
|
||||
|
||||
// save the state to the datastore
|
||||
func (ps *Store) save(state *FundedAddressState) error {
|
||||
func (ps *Store) save(ctx context.Context, state *FundedAddressState) error {
|
||||
k := dskeyForAddr(state.Addr)
|
||||
|
||||
b, err := cborrpc.Dump(state)
|
||||
@ -35,14 +36,14 @@ func (ps *Store) save(state *FundedAddressState) error {
|
||||
return err
|
||||
}
|
||||
|
||||
return ps.ds.Put(k, b)
|
||||
return ps.ds.Put(ctx, k, b)
|
||||
}
|
||||
|
||||
// get the state for the given address
|
||||
func (ps *Store) get(addr address.Address) (*FundedAddressState, error) {
|
||||
func (ps *Store) get(ctx context.Context, addr address.Address) (*FundedAddressState, error) {
|
||||
k := dskeyForAddr(addr)
|
||||
|
||||
data, err := ps.ds.Get(k)
|
||||
data, err := ps.ds.Get(ctx, k)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -56,8 +57,8 @@ func (ps *Store) get(addr address.Address) (*FundedAddressState, error) {
|
||||
}
|
||||
|
||||
// forEach calls iter with each address in the datastore
|
||||
func (ps *Store) forEach(iter func(*FundedAddressState)) error {
|
||||
res, err := ps.ds.Query(dsq.Query{Prefix: dsKeyAddr})
|
||||
func (ps *Store) forEach(ctx context.Context, iter func(*FundedAddressState)) error {
|
||||
res, err := ps.ds.Query(ctx, dsq.Query{Prefix: dsKeyAddr})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package messagepool
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"time"
|
||||
@ -20,8 +21,8 @@ var (
|
||||
ConfigKey = datastore.NewKey("/mpool/config")
|
||||
)
|
||||
|
||||
func loadConfig(ds dtypes.MetadataDS) (*types.MpoolConfig, error) {
|
||||
haveCfg, err := ds.Has(ConfigKey)
|
||||
func loadConfig(ctx context.Context, ds dtypes.MetadataDS) (*types.MpoolConfig, error) {
|
||||
haveCfg, err := ds.Has(ctx, ConfigKey)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -30,7 +31,7 @@ func loadConfig(ds dtypes.MetadataDS) (*types.MpoolConfig, error) {
|
||||
return DefaultConfig(), nil
|
||||
}
|
||||
|
||||
cfgBytes, err := ds.Get(ConfigKey)
|
||||
cfgBytes, err := ds.Get(ctx, ConfigKey)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -39,12 +40,12 @@ func loadConfig(ds dtypes.MetadataDS) (*types.MpoolConfig, error) {
|
||||
return cfg, err
|
||||
}
|
||||
|
||||
func saveConfig(cfg *types.MpoolConfig, ds dtypes.MetadataDS) error {
|
||||
func saveConfig(ctx context.Context, cfg *types.MpoolConfig, ds dtypes.MetadataDS) error {
|
||||
cfgBytes, err := json.Marshal(cfg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return ds.Put(ConfigKey, cfgBytes)
|
||||
return ds.Put(ctx, ConfigKey, cfgBytes)
|
||||
}
|
||||
|
||||
func (mp *MessagePool) GetConfig() *types.MpoolConfig {
|
||||
@ -68,7 +69,7 @@ func validateConfg(cfg *types.MpoolConfig) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (mp *MessagePool) SetConfig(cfg *types.MpoolConfig) error {
|
||||
func (mp *MessagePool) SetConfig(ctx context.Context, cfg *types.MpoolConfig) error {
|
||||
if err := validateConfg(cfg); err != nil {
|
||||
return err
|
||||
}
|
||||
@ -76,7 +77,7 @@ func (mp *MessagePool) SetConfig(cfg *types.MpoolConfig) error {
|
||||
|
||||
mp.cfgLk.Lock()
|
||||
mp.cfg = cfg
|
||||
err := saveConfig(cfg, mp.ds)
|
||||
err := saveConfig(ctx, cfg, mp.ds)
|
||||
if err != nil {
|
||||
log.Warnf("error persisting mpool config: %s", err)
|
||||
}
|
||||
|
@ -358,11 +358,11 @@ func (ms *msgSet) toSlice() []*types.SignedMessage {
|
||||
return set
|
||||
}
|
||||
|
||||
func New(api Provider, ds dtypes.MetadataDS, us stmgr.UpgradeSchedule, netName dtypes.NetworkName, j journal.Journal) (*MessagePool, error) {
|
||||
func New(ctx context.Context, api Provider, ds dtypes.MetadataDS, us stmgr.UpgradeSchedule, netName dtypes.NetworkName, j journal.Journal) (*MessagePool, error) {
|
||||
cache, _ := lru.New2Q(build.BlsSignatureCacheSize)
|
||||
verifcache, _ := lru.New2Q(build.VerifSigCacheSize)
|
||||
|
||||
cfg, err := loadConfig(ds)
|
||||
cfg, err := loadConfig(ctx, ds)
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("error loading mpool config: %w", err)
|
||||
}
|
||||
@ -601,7 +601,7 @@ func (mp *MessagePool) addLocal(ctx context.Context, m *types.SignedMessage) err
|
||||
return xerrors.Errorf("error serializing message: %w", err)
|
||||
}
|
||||
|
||||
if err := mp.localMsgs.Put(datastore.NewKey(string(m.Cid().Bytes())), msgb); err != nil {
|
||||
if err := mp.localMsgs.Put(ctx, datastore.NewKey(string(m.Cid().Bytes())), msgb); err != nil {
|
||||
return xerrors.Errorf("persisting local message: %w", err)
|
||||
}
|
||||
|
||||
@ -909,12 +909,12 @@ func (mp *MessagePool) addLocked(ctx context.Context, m *types.SignedMessage, st
|
||||
mp.blsSigCache.Add(m.Cid(), m.Signature)
|
||||
}
|
||||
|
||||
if _, err := mp.api.PutMessage(m); err != nil {
|
||||
if _, err := mp.api.PutMessage(ctx, m); err != nil {
|
||||
log.Warnf("mpooladd cs.PutMessage failed: %s", err)
|
||||
return err
|
||||
}
|
||||
|
||||
if _, err := mp.api.PutMessage(&m.Message); err != nil {
|
||||
if _, err := mp.api.PutMessage(ctx, &m.Message); err != nil {
|
||||
log.Warnf("mpooladd cs.PutMessage failed: %s", err)
|
||||
return err
|
||||
}
|
||||
@ -1207,7 +1207,7 @@ func (mp *MessagePool) HeadChange(ctx context.Context, revert []*types.TipSet, a
|
||||
var merr error
|
||||
|
||||
for _, ts := range revert {
|
||||
pts, err := mp.api.LoadTipSet(ts.Parents())
|
||||
pts, err := mp.api.LoadTipSet(ctx, ts.Parents())
|
||||
if err != nil {
|
||||
log.Errorf("error loading reverted tipset parent: %s", err)
|
||||
merr = multierror.Append(merr, err)
|
||||
@ -1216,7 +1216,7 @@ func (mp *MessagePool) HeadChange(ctx context.Context, revert []*types.TipSet, a
|
||||
|
||||
mp.curTs = pts
|
||||
|
||||
msgs, err := mp.MessagesForBlocks(ts.Blocks())
|
||||
msgs, err := mp.MessagesForBlocks(ctx, ts.Blocks())
|
||||
if err != nil {
|
||||
log.Errorf("error retrieving messages for reverted block: %s", err)
|
||||
merr = multierror.Append(merr, err)
|
||||
@ -1232,7 +1232,7 @@ func (mp *MessagePool) HeadChange(ctx context.Context, revert []*types.TipSet, a
|
||||
mp.curTs = ts
|
||||
|
||||
for _, b := range ts.Blocks() {
|
||||
bmsgs, smsgs, err := mp.api.MessagesForBlock(b)
|
||||
bmsgs, smsgs, err := mp.api.MessagesForBlock(ctx, b)
|
||||
if err != nil {
|
||||
xerr := xerrors.Errorf("failed to get messages for apply block %s(height %d) (msgroot = %s): %w", b.Cid(), b.Height, b.Messages, err)
|
||||
log.Errorf("error retrieving messages for block: %s", xerr)
|
||||
@ -1338,7 +1338,7 @@ func (mp *MessagePool) HeadChange(ctx context.Context, revert []*types.TipSet, a
|
||||
return merr
|
||||
}
|
||||
|
||||
func (mp *MessagePool) runHeadChange(from *types.TipSet, to *types.TipSet, rmsgs map[address.Address]map[uint64]*types.SignedMessage) error {
|
||||
func (mp *MessagePool) runHeadChange(ctx context.Context, from *types.TipSet, to *types.TipSet, rmsgs map[address.Address]map[uint64]*types.SignedMessage) error {
|
||||
add := func(m *types.SignedMessage) {
|
||||
s, ok := rmsgs[m.Message.From]
|
||||
if !ok {
|
||||
@ -1360,7 +1360,7 @@ func (mp *MessagePool) runHeadChange(from *types.TipSet, to *types.TipSet, rmsgs
|
||||
|
||||
}
|
||||
|
||||
revert, apply, err := store.ReorgOps(mp.api.LoadTipSet, from, to)
|
||||
revert, apply, err := store.ReorgOps(ctx, mp.api.LoadTipSet, from, to)
|
||||
if err != nil {
|
||||
return xerrors.Errorf("failed to compute reorg ops for mpool pending messages: %w", err)
|
||||
}
|
||||
@ -1368,7 +1368,7 @@ func (mp *MessagePool) runHeadChange(from *types.TipSet, to *types.TipSet, rmsgs
|
||||
var merr error
|
||||
|
||||
for _, ts := range revert {
|
||||
msgs, err := mp.MessagesForBlocks(ts.Blocks())
|
||||
msgs, err := mp.MessagesForBlocks(ctx, ts.Blocks())
|
||||
if err != nil {
|
||||
log.Errorf("error retrieving messages for reverted block: %s", err)
|
||||
merr = multierror.Append(merr, err)
|
||||
@ -1382,7 +1382,7 @@ func (mp *MessagePool) runHeadChange(from *types.TipSet, to *types.TipSet, rmsgs
|
||||
|
||||
for _, ts := range apply {
|
||||
for _, b := range ts.Blocks() {
|
||||
bmsgs, smsgs, err := mp.api.MessagesForBlock(b)
|
||||
bmsgs, smsgs, err := mp.api.MessagesForBlock(ctx, b)
|
||||
if err != nil {
|
||||
xerr := xerrors.Errorf("failed to get messages for apply block %s(height %d) (msgroot = %s): %w", b.Cid(), b.Height, b.Messages, err)
|
||||
log.Errorf("error retrieving messages for block: %s", xerr)
|
||||
@ -1407,11 +1407,11 @@ type statBucket struct {
|
||||
msgs map[uint64]*types.SignedMessage
|
||||
}
|
||||
|
||||
func (mp *MessagePool) MessagesForBlocks(blks []*types.BlockHeader) ([]*types.SignedMessage, error) {
|
||||
func (mp *MessagePool) MessagesForBlocks(ctx context.Context, blks []*types.BlockHeader) ([]*types.SignedMessage, error) {
|
||||
out := make([]*types.SignedMessage, 0)
|
||||
|
||||
for _, b := range blks {
|
||||
bmsgs, smsgs, err := mp.api.MessagesForBlock(b)
|
||||
bmsgs, smsgs, err := mp.api.MessagesForBlock(ctx, b)
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("failed to get messages for apply block %s(height %d) (msgroot = %s): %w", b.Cid(), b.Height, b.Messages, err)
|
||||
}
|
||||
@ -1477,7 +1477,7 @@ func (mp *MessagePool) Updates(ctx context.Context) (<-chan api.MpoolUpdate, err
|
||||
}
|
||||
|
||||
func (mp *MessagePool) loadLocal(ctx context.Context) error {
|
||||
res, err := mp.localMsgs.Query(query.Query{})
|
||||
res, err := mp.localMsgs.Query(ctx, query.Query{})
|
||||
if err != nil {
|
||||
return xerrors.Errorf("query local messages: %w", err)
|
||||
}
|
||||
@ -1525,7 +1525,7 @@ func (mp *MessagePool) Clear(ctx context.Context, local bool) {
|
||||
|
||||
if ok {
|
||||
for _, m := range mset.msgs {
|
||||
err := mp.localMsgs.Delete(datastore.NewKey(string(m.Cid().Bytes())))
|
||||
err := mp.localMsgs.Delete(ctx, datastore.NewKey(string(m.Cid().Bytes())))
|
||||
if err != nil {
|
||||
log.Warnf("error deleting local message: %s", err)
|
||||
}
|
||||
|
@ -103,7 +103,7 @@ func (tma *testMpoolAPI) SubscribeHeadChanges(cb func(rev, app []*types.TipSet)
|
||||
return tma.tipsets[0]
|
||||
}
|
||||
|
||||
func (tma *testMpoolAPI) PutMessage(m types.ChainMsg) (cid.Cid, error) {
|
||||
func (tma *testMpoolAPI) PutMessage(ctx context.Context, m types.ChainMsg) (cid.Cid, error) {
|
||||
return cid.Undef, nil
|
||||
}
|
||||
|
||||
@ -164,16 +164,16 @@ func (tma *testMpoolAPI) StateAccountKeyAtFinality(ctx context.Context, addr add
|
||||
return addr, nil
|
||||
}
|
||||
|
||||
func (tma *testMpoolAPI) MessagesForBlock(h *types.BlockHeader) ([]*types.Message, []*types.SignedMessage, error) {
|
||||
func (tma *testMpoolAPI) MessagesForBlock(ctx context.Context, h *types.BlockHeader) ([]*types.Message, []*types.SignedMessage, error) {
|
||||
return nil, tma.bmsgs[h.Cid()], nil
|
||||
}
|
||||
|
||||
func (tma *testMpoolAPI) MessagesForTipset(ts *types.TipSet) ([]types.ChainMsg, error) {
|
||||
func (tma *testMpoolAPI) MessagesForTipset(ctx context.Context, ts *types.TipSet) ([]types.ChainMsg, error) {
|
||||
if len(ts.Blocks()) != 1 {
|
||||
panic("cant deal with multiblock tipsets in this test")
|
||||
}
|
||||
|
||||
bm, sm, err := tma.MessagesForBlock(ts.Blocks()[0])
|
||||
bm, sm, err := tma.MessagesForBlock(ctx, ts.Blocks()[0])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -190,7 +190,7 @@ func (tma *testMpoolAPI) MessagesForTipset(ts *types.TipSet) ([]types.ChainMsg,
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (tma *testMpoolAPI) LoadTipSet(tsk types.TipSetKey) (*types.TipSet, error) {
|
||||
func (tma *testMpoolAPI) LoadTipSet(ctx context.Context, tsk types.TipSetKey) (*types.TipSet, error) {
|
||||
for _, ts := range tma.tipsets {
|
||||
if types.CidArrsEqual(tsk.Cids(), ts.Cids()) {
|
||||
return ts, nil
|
||||
@ -233,7 +233,7 @@ func TestMessagePool(t *testing.T) {
|
||||
|
||||
ds := datastore.NewMapDatastore()
|
||||
|
||||
mp, err := New(tma, ds, filcns.DefaultUpgradeSchedule(), "mptest", nil)
|
||||
mp, err := New(context.Background(), tma, ds, filcns.DefaultUpgradeSchedule(), "mptest", nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -277,7 +277,7 @@ func TestCheckMessageBig(t *testing.T) {
|
||||
|
||||
ds := datastore.NewMapDatastore()
|
||||
|
||||
mp, err := New(tma, ds, filcns.DefaultUpgradeSchedule(), "mptest", nil)
|
||||
mp, err := New(context.Background(), tma, ds, filcns.DefaultUpgradeSchedule(), "mptest", nil)
|
||||
assert.NoError(t, err)
|
||||
|
||||
to := mock.Address(1001)
|
||||
@ -340,7 +340,7 @@ func TestMessagePoolMessagesInEachBlock(t *testing.T) {
|
||||
|
||||
ds := datastore.NewMapDatastore()
|
||||
|
||||
mp, err := New(tma, ds, filcns.DefaultUpgradeSchedule(), "mptest", nil)
|
||||
mp, err := New(context.Background(), tma, ds, filcns.DefaultUpgradeSchedule(), "mptest", nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -389,7 +389,7 @@ func TestRevertMessages(t *testing.T) {
|
||||
|
||||
ds := datastore.NewMapDatastore()
|
||||
|
||||
mp, err := New(tma, ds, filcns.DefaultUpgradeSchedule(), "mptest", nil)
|
||||
mp, err := New(context.Background(), tma, ds, filcns.DefaultUpgradeSchedule(), "mptest", nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -452,7 +452,7 @@ func TestPruningSimple(t *testing.T) {
|
||||
|
||||
ds := datastore.NewMapDatastore()
|
||||
|
||||
mp, err := New(tma, ds, filcns.DefaultUpgradeSchedule(), "mptest", nil)
|
||||
mp, err := New(context.Background(), tma, ds, filcns.DefaultUpgradeSchedule(), "mptest", nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -496,7 +496,7 @@ func TestLoadLocal(t *testing.T) {
|
||||
tma := newTestMpoolAPI()
|
||||
ds := datastore.NewMapDatastore()
|
||||
|
||||
mp, err := New(tma, ds, filcns.DefaultUpgradeSchedule(), "mptest", nil)
|
||||
mp, err := New(context.Background(), tma, ds, filcns.DefaultUpgradeSchedule(), "mptest", nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -539,7 +539,7 @@ func TestLoadLocal(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
mp, err = New(tma, ds, filcns.DefaultUpgradeSchedule(), "mptest", nil)
|
||||
mp, err = New(context.Background(), tma, ds, filcns.DefaultUpgradeSchedule(), "mptest", nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -568,7 +568,7 @@ func TestClearAll(t *testing.T) {
|
||||
tma := newTestMpoolAPI()
|
||||
ds := datastore.NewMapDatastore()
|
||||
|
||||
mp, err := New(tma, ds, filcns.DefaultUpgradeSchedule(), "mptest", nil)
|
||||
mp, err := New(context.Background(), tma, ds, filcns.DefaultUpgradeSchedule(), "mptest", nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -622,7 +622,7 @@ func TestClearNonLocal(t *testing.T) {
|
||||
tma := newTestMpoolAPI()
|
||||
ds := datastore.NewMapDatastore()
|
||||
|
||||
mp, err := New(tma, ds, filcns.DefaultUpgradeSchedule(), "mptest", nil)
|
||||
mp, err := New(context.Background(), tma, ds, filcns.DefaultUpgradeSchedule(), "mptest", nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -683,7 +683,7 @@ func TestUpdates(t *testing.T) {
|
||||
tma := newTestMpoolAPI()
|
||||
ds := datastore.NewMapDatastore()
|
||||
|
||||
mp, err := New(tma, ds, filcns.DefaultUpgradeSchedule(), "mptest", nil)
|
||||
mp, err := New(context.Background(), tma, ds, filcns.DefaultUpgradeSchedule(), "mptest", nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -23,13 +23,13 @@ var (
|
||||
|
||||
type Provider interface {
|
||||
SubscribeHeadChanges(func(rev, app []*types.TipSet) error) *types.TipSet
|
||||
PutMessage(m types.ChainMsg) (cid.Cid, error)
|
||||
PutMessage(ctx context.Context, m types.ChainMsg) (cid.Cid, error)
|
||||
PubSubPublish(string, []byte) error
|
||||
GetActorAfter(address.Address, *types.TipSet) (*types.Actor, error)
|
||||
StateAccountKeyAtFinality(context.Context, address.Address, *types.TipSet) (address.Address, error)
|
||||
MessagesForBlock(*types.BlockHeader) ([]*types.Message, []*types.SignedMessage, error)
|
||||
MessagesForTipset(*types.TipSet) ([]types.ChainMsg, error)
|
||||
LoadTipSet(tsk types.TipSetKey) (*types.TipSet, error)
|
||||
MessagesForBlock(context.Context, *types.BlockHeader) ([]*types.Message, []*types.SignedMessage, error)
|
||||
MessagesForTipset(context.Context, *types.TipSet) ([]types.ChainMsg, error)
|
||||
LoadTipSet(ctx context.Context, tsk types.TipSetKey) (*types.TipSet, error)
|
||||
ChainComputeBaseFee(ctx context.Context, ts *types.TipSet) (types.BigInt, error)
|
||||
IsLite() bool
|
||||
}
|
||||
@ -66,8 +66,8 @@ func (mpp *mpoolProvider) SubscribeHeadChanges(cb func(rev, app []*types.TipSet)
|
||||
return mpp.sm.ChainStore().GetHeaviestTipSet()
|
||||
}
|
||||
|
||||
func (mpp *mpoolProvider) PutMessage(m types.ChainMsg) (cid.Cid, error) {
|
||||
return mpp.sm.ChainStore().PutMessage(m)
|
||||
func (mpp *mpoolProvider) PutMessage(ctx context.Context, m types.ChainMsg) (cid.Cid, error) {
|
||||
return mpp.sm.ChainStore().PutMessage(ctx, m)
|
||||
}
|
||||
|
||||
func (mpp *mpoolProvider) PubSubPublish(k string, v []byte) error {
|
||||
@ -103,16 +103,16 @@ func (mpp *mpoolProvider) StateAccountKeyAtFinality(ctx context.Context, addr ad
|
||||
return mpp.sm.ResolveToKeyAddressAtFinality(ctx, addr, ts)
|
||||
}
|
||||
|
||||
func (mpp *mpoolProvider) MessagesForBlock(h *types.BlockHeader) ([]*types.Message, []*types.SignedMessage, error) {
|
||||
return mpp.sm.ChainStore().MessagesForBlock(h)
|
||||
func (mpp *mpoolProvider) MessagesForBlock(ctx context.Context, h *types.BlockHeader) ([]*types.Message, []*types.SignedMessage, error) {
|
||||
return mpp.sm.ChainStore().MessagesForBlock(ctx, h)
|
||||
}
|
||||
|
||||
func (mpp *mpoolProvider) MessagesForTipset(ts *types.TipSet) ([]types.ChainMsg, error) {
|
||||
return mpp.sm.ChainStore().MessagesForTipset(ts)
|
||||
func (mpp *mpoolProvider) MessagesForTipset(ctx context.Context, ts *types.TipSet) ([]types.ChainMsg, error) {
|
||||
return mpp.sm.ChainStore().MessagesForTipset(ctx, ts)
|
||||
}
|
||||
|
||||
func (mpp *mpoolProvider) LoadTipSet(tsk types.TipSetKey) (*types.TipSet, error) {
|
||||
return mpp.sm.ChainStore().LoadTipSet(tsk)
|
||||
func (mpp *mpoolProvider) LoadTipSet(ctx context.Context, tsk types.TipSetKey) (*types.TipSet, error) {
|
||||
return mpp.sm.ChainStore().LoadTipSet(ctx, tsk)
|
||||
}
|
||||
|
||||
func (mpp *mpoolProvider) ChainComputeBaseFee(ctx context.Context, ts *types.TipSet) (types.BigInt, error) {
|
||||
|
@ -49,7 +49,7 @@ func (mp *MessagePool) pruneMessages(ctx context.Context, ts *types.TipSet) erro
|
||||
}
|
||||
baseFeeLowerBound := getBaseFeeLowerBound(baseFee, baseFeeLowerBoundFactor)
|
||||
|
||||
pending, _ := mp.getPendingMessages(ts, ts)
|
||||
pending, _ := mp.getPendingMessages(ctx, ts, ts)
|
||||
|
||||
// protected actors -- not pruned
|
||||
protected := make(map[address.Address]struct{})
|
||||
|
@ -121,7 +121,7 @@ loop:
|
||||
|
||||
// we can't fit the current chain but there is gas to spare
|
||||
// trim it and push it down
|
||||
chain.Trim(gasLimit, mp, baseFee)
|
||||
chain.Trim(gasLimit, repubMsgLimit, mp, baseFee)
|
||||
for j := i; j < len(chains)-1; j++ {
|
||||
if chains[j].Before(chains[j+1]) {
|
||||
break
|
||||
@ -131,6 +131,10 @@ loop:
|
||||
}
|
||||
|
||||
count := 0
|
||||
if len(msgs) > repubMsgLimit {
|
||||
msgs = msgs[:repubMsgLimit]
|
||||
}
|
||||
|
||||
log.Infof("republishing %d messages", len(msgs))
|
||||
for _, m := range msgs {
|
||||
mb, err := m.Serialize()
|
||||
|
@ -25,7 +25,7 @@ func TestRepubMessages(t *testing.T) {
|
||||
tma := newTestMpoolAPI()
|
||||
ds := datastore.NewMapDatastore()
|
||||
|
||||
mp, err := New(tma, ds, filcns.DefaultUpgradeSchedule(), "mptest", nil)
|
||||
mp, err := New(context.Background(), tma, ds, filcns.DefaultUpgradeSchedule(), "mptest", nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -7,6 +7,10 @@ import (
|
||||
"sort"
|
||||
"time"
|
||||
|
||||
cbg "github.com/whyrusleeping/cbor-gen"
|
||||
|
||||
"github.com/filecoin-project/go-state-types/crypto"
|
||||
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
"github.com/filecoin-project/go-address"
|
||||
@ -34,9 +38,10 @@ type msgChain struct {
|
||||
merged bool
|
||||
next *msgChain
|
||||
prev *msgChain
|
||||
sigType crypto.SigType
|
||||
}
|
||||
|
||||
func (mp *MessagePool) SelectMessages(ctx context.Context, ts *types.TipSet, tq float64) (msgs []*types.SignedMessage, err error) {
|
||||
func (mp *MessagePool) SelectMessages(ctx context.Context, ts *types.TipSet, tq float64) ([]*types.SignedMessage, error) {
|
||||
mp.curTsLk.Lock()
|
||||
defer mp.curTsLk.Unlock()
|
||||
|
||||
@ -46,24 +51,156 @@ func (mp *MessagePool) SelectMessages(ctx context.Context, ts *types.TipSet, tq
|
||||
// if the ticket quality is high enough that the first block has higher probability
|
||||
// than any other block, then we don't bother with optimal selection because the
|
||||
// first block will always have higher effective performance
|
||||
var sm *selectedMessages
|
||||
var err error
|
||||
if tq > 0.84 {
|
||||
msgs, err = mp.selectMessagesGreedy(ctx, mp.curTs, ts)
|
||||
sm, err = mp.selectMessagesGreedy(ctx, mp.curTs, ts)
|
||||
} else {
|
||||
msgs, err = mp.selectMessagesOptimal(ctx, mp.curTs, ts, tq)
|
||||
sm, err = mp.selectMessagesOptimal(ctx, mp.curTs, ts, tq)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(msgs) > build.BlockMessageLimit {
|
||||
msgs = msgs[:build.BlockMessageLimit]
|
||||
if sm == nil {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
return msgs, nil
|
||||
// one last sanity check
|
||||
if len(sm.msgs) > build.BlockMessageLimit {
|
||||
log.Errorf("message selection chose too many messages %d > %d", len(sm.msgs), build.BlockMessageLimit)
|
||||
sm.msgs = sm.msgs[:build.BlockMessageLimit]
|
||||
}
|
||||
|
||||
return sm.msgs, nil
|
||||
}
|
||||
|
||||
func (mp *MessagePool) selectMessagesOptimal(ctx context.Context, curTs, ts *types.TipSet, tq float64) ([]*types.SignedMessage, error) {
|
||||
type selectedMessages struct {
|
||||
msgs []*types.SignedMessage
|
||||
gasLimit int64
|
||||
secpLimit int
|
||||
blsLimit int
|
||||
}
|
||||
|
||||
// returns false if chain can't be added due to block constraints
|
||||
func (sm *selectedMessages) tryToAdd(mc *msgChain) bool {
|
||||
l := len(mc.msgs)
|
||||
|
||||
if build.BlockMessageLimit < l+len(sm.msgs) || sm.gasLimit < mc.gasLimit {
|
||||
return false
|
||||
}
|
||||
|
||||
if mc.sigType == crypto.SigTypeBLS {
|
||||
if sm.blsLimit < l {
|
||||
return false
|
||||
}
|
||||
|
||||
sm.msgs = append(sm.msgs, mc.msgs...)
|
||||
sm.blsLimit -= l
|
||||
sm.gasLimit -= mc.gasLimit
|
||||
} else if mc.sigType == crypto.SigTypeSecp256k1 {
|
||||
if sm.secpLimit < l {
|
||||
return false
|
||||
}
|
||||
|
||||
sm.msgs = append(sm.msgs, mc.msgs...)
|
||||
sm.secpLimit -= l
|
||||
sm.gasLimit -= mc.gasLimit
|
||||
}
|
||||
|
||||
// don't add the weird sigType msg, but otherwise proceed
|
||||
return true
|
||||
}
|
||||
|
||||
// returns false if messages can't be added due to block constraints
|
||||
// will trim / invalidate chain as appropriate
|
||||
func (sm *selectedMessages) tryToAddWithDeps(mc *msgChain, mp *MessagePool, baseFee types.BigInt) bool {
|
||||
// compute the dependencies that must be merged and the gas limit including deps
|
||||
chainGasLimit := mc.gasLimit
|
||||
chainMsgLimit := len(mc.msgs)
|
||||
depGasLimit := int64(0)
|
||||
depMsgLimit := 0
|
||||
smMsgLimit := 0
|
||||
|
||||
if mc.sigType == crypto.SigTypeBLS {
|
||||
smMsgLimit = sm.blsLimit
|
||||
} else if mc.sigType == crypto.SigTypeSecp256k1 {
|
||||
smMsgLimit = sm.secpLimit
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
|
||||
if smMsgLimit > build.BlockMessageLimit-len(sm.msgs) {
|
||||
smMsgLimit = build.BlockMessageLimit - len(sm.msgs)
|
||||
}
|
||||
|
||||
var chainDeps []*msgChain
|
||||
for curChain := mc.prev; curChain != nil && !curChain.merged; curChain = curChain.prev {
|
||||
chainDeps = append(chainDeps, curChain)
|
||||
chainGasLimit += curChain.gasLimit
|
||||
chainMsgLimit += len(curChain.msgs)
|
||||
depGasLimit += curChain.gasLimit
|
||||
depMsgLimit += len(curChain.msgs)
|
||||
}
|
||||
|
||||
// the chain doesn't fit as-is, so trim / invalidate it and return false
|
||||
if chainGasLimit > sm.gasLimit || chainMsgLimit > smMsgLimit {
|
||||
|
||||
// it doesn't all fit; now we have to take into account the dependent chains before
|
||||
// making a decision about trimming or invalidating.
|
||||
// if the dependencies exceed the block limits, then we must invalidate the chain
|
||||
// as it can never be included.
|
||||
// Otherwise we can just trim and continue
|
||||
if depGasLimit > sm.gasLimit || depMsgLimit >= smMsgLimit {
|
||||
mc.Invalidate()
|
||||
} else {
|
||||
// dependencies fit, just trim it
|
||||
mc.Trim(sm.gasLimit-depGasLimit, smMsgLimit-depMsgLimit, mp, baseFee)
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// the chain fits! include it together with all dependencies
|
||||
for i := len(chainDeps) - 1; i >= 0; i-- {
|
||||
curChain := chainDeps[i]
|
||||
curChain.merged = true
|
||||
sm.msgs = append(sm.msgs, curChain.msgs...)
|
||||
}
|
||||
|
||||
mc.merged = true
|
||||
|
||||
sm.msgs = append(sm.msgs, mc.msgs...)
|
||||
sm.gasLimit -= chainGasLimit
|
||||
|
||||
if mc.sigType == crypto.SigTypeBLS {
|
||||
sm.blsLimit -= chainMsgLimit
|
||||
} else if mc.sigType == crypto.SigTypeSecp256k1 {
|
||||
sm.secpLimit -= chainMsgLimit
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func (sm *selectedMessages) trimChain(mc *msgChain, mp *MessagePool, baseFee types.BigInt) {
|
||||
msgLimit := build.BlockMessageLimit - len(sm.msgs)
|
||||
if mc.sigType == crypto.SigTypeBLS {
|
||||
if msgLimit > sm.blsLimit {
|
||||
msgLimit = sm.blsLimit
|
||||
}
|
||||
} else if mc.sigType == crypto.SigTypeSecp256k1 {
|
||||
if msgLimit > sm.secpLimit {
|
||||
msgLimit = sm.secpLimit
|
||||
}
|
||||
}
|
||||
|
||||
if mc.gasLimit > sm.gasLimit || len(mc.msgs) > msgLimit {
|
||||
mc.Trim(sm.gasLimit, msgLimit, mp, baseFee)
|
||||
}
|
||||
}
|
||||
|
||||
func (mp *MessagePool) selectMessagesOptimal(ctx context.Context, curTs, ts *types.TipSet, tq float64) (*selectedMessages, error) {
|
||||
start := time.Now()
|
||||
|
||||
baseFee, err := mp.api.ChainComputeBaseFee(context.TODO(), ts)
|
||||
@ -73,7 +210,7 @@ func (mp *MessagePool) selectMessagesOptimal(ctx context.Context, curTs, ts *typ
|
||||
|
||||
// 0. Load messages from the target tipset; if it is the same as the current tipset in
|
||||
// the mpool, then this is just the pending messages
|
||||
pending, err := mp.getPendingMessages(curTs, ts)
|
||||
pending, err := mp.getPendingMessages(ctx, curTs, ts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -89,10 +226,10 @@ func (mp *MessagePool) selectMessagesOptimal(ctx context.Context, curTs, ts *typ
|
||||
|
||||
// 0b. Select all priority messages that fit in the block
|
||||
minGas := int64(gasguess.MinGas)
|
||||
result, gasLimit := mp.selectPriorityMessages(ctx, pending, baseFee, ts)
|
||||
result := mp.selectPriorityMessages(ctx, pending, baseFee, ts)
|
||||
|
||||
// have we filled the block?
|
||||
if gasLimit < minGas {
|
||||
if result.gasLimit < minGas || len(result.msgs) >= build.BlockMessageLimit {
|
||||
return result, nil
|
||||
}
|
||||
|
||||
@ -117,19 +254,21 @@ func (mp *MessagePool) selectMessagesOptimal(ctx context.Context, curTs, ts *typ
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// 3. Parition chains into blocks (without trimming)
|
||||
// 3. Partition chains into blocks (without trimming)
|
||||
// we use the full blockGasLimit (as opposed to the residual gas limit from the
|
||||
// priority message selection) as we have to account for what other miners are doing
|
||||
// priority message selection) as we have to account for what other block providers are doing
|
||||
nextChain := 0
|
||||
partitions := make([][]*msgChain, MaxBlocks)
|
||||
for i := 0; i < MaxBlocks && nextChain < len(chains); i++ {
|
||||
gasLimit := int64(build.BlockGasLimit)
|
||||
msgLimit := build.BlockMessageLimit
|
||||
for nextChain < len(chains) {
|
||||
chain := chains[nextChain]
|
||||
nextChain++
|
||||
partitions[i] = append(partitions[i], chain)
|
||||
gasLimit -= chain.gasLimit
|
||||
if gasLimit < minGas {
|
||||
msgLimit -= len(chain.msgs)
|
||||
if gasLimit < minGas || msgLimit <= 0 {
|
||||
break
|
||||
}
|
||||
}
|
||||
@ -158,7 +297,7 @@ func (mp *MessagePool) selectMessagesOptimal(ctx context.Context, curTs, ts *typ
|
||||
})
|
||||
|
||||
// 6. Merge the head chains to produce the list of messages selected for inclusion
|
||||
// subject to the residual gas limit
|
||||
// subject to the residual block limits
|
||||
// When a chain is merged in, all its previous dependent chains *must* also be
|
||||
// merged in or we'll have a broken block
|
||||
startMerge := time.Now()
|
||||
@ -174,35 +313,16 @@ func (mp *MessagePool) selectMessagesOptimal(ctx context.Context, curTs, ts *typ
|
||||
continue
|
||||
}
|
||||
|
||||
// compute the dependencies that must be merged and the gas limit including deps
|
||||
chainGasLimit := chain.gasLimit
|
||||
var chainDeps []*msgChain
|
||||
for curChain := chain.prev; curChain != nil && !curChain.merged; curChain = curChain.prev {
|
||||
chainDeps = append(chainDeps, curChain)
|
||||
chainGasLimit += curChain.gasLimit
|
||||
}
|
||||
|
||||
// does it all fit in the block?
|
||||
if chainGasLimit <= gasLimit {
|
||||
// include it together with all dependencies
|
||||
for i := len(chainDeps) - 1; i >= 0; i-- {
|
||||
curChain := chainDeps[i]
|
||||
curChain.merged = true
|
||||
result = append(result, curChain.msgs...)
|
||||
}
|
||||
|
||||
chain.merged = true
|
||||
// adjust the effective pefromance for all subsequent chains
|
||||
if result.tryToAddWithDeps(chain, mp, baseFee) {
|
||||
// adjust the effective performance for all subsequent chains
|
||||
if next := chain.next; next != nil && next.effPerf > 0 {
|
||||
next.effPerf += next.parentOffset
|
||||
for next = next.next; next != nil && next.effPerf > 0; next = next.next {
|
||||
next.setEffPerf()
|
||||
}
|
||||
}
|
||||
result = append(result, chain.msgs...)
|
||||
gasLimit -= chainGasLimit
|
||||
|
||||
// resort to account for already merged chains and effective performance adjustments
|
||||
// re-sort to account for already merged chains and effective performance adjustments
|
||||
// the sort *must* be stable or we end up getting negative gasPerfs pushed up.
|
||||
sort.SliceStable(chains[i+1:], func(i, j int) bool {
|
||||
return chains[i].BeforeEffective(chains[j])
|
||||
@ -211,7 +331,7 @@ func (mp *MessagePool) selectMessagesOptimal(ctx context.Context, curTs, ts *typ
|
||||
continue
|
||||
}
|
||||
|
||||
// we can't fit this chain and its dependencies because of block gasLimit -- we are
|
||||
// we can't fit this chain and its dependencies because of block limits -- we are
|
||||
// at the edge
|
||||
last = i
|
||||
break
|
||||
@ -222,18 +342,22 @@ func (mp *MessagePool) selectMessagesOptimal(ctx context.Context, curTs, ts *typ
|
||||
|
||||
// 7. We have reached the edge of what can fit wholesale; if we still hae available
|
||||
// gasLimit to pack some more chains, then trim the last chain and push it down.
|
||||
// Trimming invalidaates subsequent dependent chains so that they can't be selected
|
||||
// Trimming invalidates subsequent dependent chains so that they can't be selected
|
||||
// as their dependency cannot be (fully) included.
|
||||
// We do this in a loop because the blocker might have been inordinately large and
|
||||
// we might have to do it multiple times to satisfy tail packing
|
||||
startTail := time.Now()
|
||||
tailLoop:
|
||||
for gasLimit >= minGas && last < len(chains) {
|
||||
// trim if necessary
|
||||
if chains[last].gasLimit > gasLimit {
|
||||
chains[last].Trim(gasLimit, mp, baseFee)
|
||||
for result.gasLimit >= minGas && last < len(chains) {
|
||||
|
||||
if !chains[last].valid {
|
||||
last++
|
||||
continue tailLoop
|
||||
}
|
||||
|
||||
// trim if necessary
|
||||
result.trimChain(chains[last], mp, baseFee)
|
||||
|
||||
// push down if it hasn't been invalidated
|
||||
if chains[last].valid {
|
||||
for i := last; i < len(chains)-1; i++ {
|
||||
@ -245,7 +369,7 @@ tailLoop:
|
||||
}
|
||||
|
||||
// select the next (valid and fitting) chain and its dependencies for inclusion
|
||||
for i, chain := range chains[last:] {
|
||||
for _, chain := range chains[last:] {
|
||||
// has the chain been invalidated?
|
||||
if !chain.valid {
|
||||
continue
|
||||
@ -261,45 +385,10 @@ tailLoop:
|
||||
break tailLoop
|
||||
}
|
||||
|
||||
// compute the dependencies that must be merged and the gas limit including deps
|
||||
chainGasLimit := chain.gasLimit
|
||||
depGasLimit := int64(0)
|
||||
var chainDeps []*msgChain
|
||||
for curChain := chain.prev; curChain != nil && !curChain.merged; curChain = curChain.prev {
|
||||
chainDeps = append(chainDeps, curChain)
|
||||
chainGasLimit += curChain.gasLimit
|
||||
depGasLimit += curChain.gasLimit
|
||||
}
|
||||
|
||||
// does it all fit in the bock
|
||||
if chainGasLimit <= gasLimit {
|
||||
// include it together with all dependencies
|
||||
for i := len(chainDeps) - 1; i >= 0; i-- {
|
||||
curChain := chainDeps[i]
|
||||
curChain.merged = true
|
||||
result = append(result, curChain.msgs...)
|
||||
}
|
||||
|
||||
chain.merged = true
|
||||
result = append(result, chain.msgs...)
|
||||
gasLimit -= chainGasLimit
|
||||
if result.tryToAddWithDeps(chain, mp, baseFee) {
|
||||
continue
|
||||
}
|
||||
|
||||
// it doesn't all fit; now we have to take into account the dependent chains before
|
||||
// making a decision about trimming or invalidating.
|
||||
// if the dependencies exceed the gas limit, then we must invalidate the chain
|
||||
// as it can never be included.
|
||||
// Otherwise we can just trim and continue
|
||||
if depGasLimit > gasLimit {
|
||||
chain.Invalidate()
|
||||
last += i + 1
|
||||
continue tailLoop
|
||||
}
|
||||
|
||||
// dependencies fit, just trim it
|
||||
chain.Trim(gasLimit-depGasLimit, mp, baseFee)
|
||||
last += i
|
||||
continue tailLoop
|
||||
}
|
||||
|
||||
@ -311,17 +400,17 @@ tailLoop:
|
||||
log.Infow("pack tail chains done", "took", dt)
|
||||
}
|
||||
|
||||
// if we have gasLimit to spare, pick some random (non-negative) chains to fill the block
|
||||
// we pick randomly so that we minimize the probability of duplication among all miners
|
||||
if gasLimit >= minGas {
|
||||
randomCount := 0
|
||||
// if we have room to spare, pick some random (non-negative) chains to fill the block
|
||||
// we pick randomly so that we minimize the probability of duplication among all block producers
|
||||
if result.gasLimit >= minGas && len(result.msgs) <= build.BlockMessageLimit {
|
||||
preRandomLength := len(result.msgs)
|
||||
|
||||
startRandom := time.Now()
|
||||
shuffleChains(chains)
|
||||
|
||||
for _, chain := range chains {
|
||||
// have we filled the block
|
||||
if gasLimit < minGas {
|
||||
if result.gasLimit < minGas || len(result.msgs) >= build.BlockMessageLimit {
|
||||
break
|
||||
}
|
||||
|
||||
@ -335,59 +424,31 @@ tailLoop:
|
||||
continue
|
||||
}
|
||||
|
||||
// compute the dependencies that must be merged and the gas limit including deps
|
||||
chainGasLimit := chain.gasLimit
|
||||
depGasLimit := int64(0)
|
||||
var chainDeps []*msgChain
|
||||
for curChain := chain.prev; curChain != nil && !curChain.merged; curChain = curChain.prev {
|
||||
chainDeps = append(chainDeps, curChain)
|
||||
chainGasLimit += curChain.gasLimit
|
||||
depGasLimit += curChain.gasLimit
|
||||
}
|
||||
|
||||
// do the deps fit? if the deps won't fit, invalidate the chain
|
||||
if depGasLimit > gasLimit {
|
||||
chain.Invalidate()
|
||||
if result.tryToAddWithDeps(chain, mp, baseFee) {
|
||||
continue
|
||||
}
|
||||
|
||||
// do they fit as is? if it doesn't, trim to make it fit if possible
|
||||
if chainGasLimit > gasLimit {
|
||||
chain.Trim(gasLimit-depGasLimit, mp, baseFee)
|
||||
|
||||
if !chain.valid {
|
||||
continue
|
||||
}
|
||||
if chain.valid {
|
||||
// chain got trimmed on the previous call to tryToAddWithDeps, can now be included
|
||||
result.tryToAddWithDeps(chain, mp, baseFee)
|
||||
continue
|
||||
}
|
||||
|
||||
// include it together with all dependencies
|
||||
for i := len(chainDeps) - 1; i >= 0; i-- {
|
||||
curChain := chainDeps[i]
|
||||
curChain.merged = true
|
||||
result = append(result, curChain.msgs...)
|
||||
randomCount += len(curChain.msgs)
|
||||
}
|
||||
|
||||
chain.merged = true
|
||||
result = append(result, chain.msgs...)
|
||||
randomCount += len(chain.msgs)
|
||||
gasLimit -= chainGasLimit
|
||||
}
|
||||
|
||||
if dt := time.Since(startRandom); dt > time.Millisecond {
|
||||
log.Infow("pack random tail chains done", "took", dt)
|
||||
}
|
||||
|
||||
if randomCount > 0 {
|
||||
if len(result.msgs) != preRandomLength {
|
||||
log.Warnf("optimal selection failed to pack a block; picked %d messages with random selection",
|
||||
randomCount)
|
||||
len(result.msgs)-preRandomLength)
|
||||
}
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (mp *MessagePool) selectMessagesGreedy(ctx context.Context, curTs, ts *types.TipSet) ([]*types.SignedMessage, error) {
|
||||
func (mp *MessagePool) selectMessagesGreedy(ctx context.Context, curTs, ts *types.TipSet) (*selectedMessages, error) {
|
||||
start := time.Now()
|
||||
|
||||
baseFee, err := mp.api.ChainComputeBaseFee(context.TODO(), ts)
|
||||
@ -397,7 +458,7 @@ func (mp *MessagePool) selectMessagesGreedy(ctx context.Context, curTs, ts *type
|
||||
|
||||
// 0. Load messages for the target tipset; if it is the same as the current tipset in the mpool
|
||||
// then this is just the pending messages
|
||||
pending, err := mp.getPendingMessages(curTs, ts)
|
||||
pending, err := mp.getPendingMessages(ctx, curTs, ts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -413,10 +474,10 @@ func (mp *MessagePool) selectMessagesGreedy(ctx context.Context, curTs, ts *type
|
||||
|
||||
// 0b. Select all priority messages that fit in the block
|
||||
minGas := int64(gasguess.MinGas)
|
||||
result, gasLimit := mp.selectPriorityMessages(ctx, pending, baseFee, ts)
|
||||
result := mp.selectPriorityMessages(ctx, pending, baseFee, ts)
|
||||
|
||||
// have we filled the block?
|
||||
if gasLimit < minGas {
|
||||
if result.gasLimit < minGas || len(result.msgs) > build.BlockMessageLimit {
|
||||
return result, nil
|
||||
}
|
||||
|
||||
@ -442,7 +503,7 @@ func (mp *MessagePool) selectMessagesGreedy(ctx context.Context, curTs, ts *type
|
||||
}
|
||||
|
||||
// 3. Merge the head chains to produce the list of messages selected for inclusion, subject to
|
||||
// the block gas limit.
|
||||
// the block gas and message limits.
|
||||
startMerge := time.Now()
|
||||
last := len(chains)
|
||||
for i, chain := range chains {
|
||||
@ -452,13 +513,12 @@ func (mp *MessagePool) selectMessagesGreedy(ctx context.Context, curTs, ts *type
|
||||
}
|
||||
|
||||
// does it fit in the block?
|
||||
if chain.gasLimit <= gasLimit {
|
||||
gasLimit -= chain.gasLimit
|
||||
result = append(result, chain.msgs...)
|
||||
if result.tryToAdd(chain) {
|
||||
// there was room, we added the chain, keep going
|
||||
continue
|
||||
}
|
||||
|
||||
// we can't fit this chain because of block gasLimit -- we are at the edge
|
||||
// we can't fit this chain because of block limits -- we are at the edge
|
||||
last = i
|
||||
break
|
||||
}
|
||||
@ -474,9 +534,9 @@ func (mp *MessagePool) selectMessagesGreedy(ctx context.Context, curTs, ts *type
|
||||
// have to do it multiple times to satisfy tail packing.
|
||||
startTail := time.Now()
|
||||
tailLoop:
|
||||
for gasLimit >= minGas && last < len(chains) {
|
||||
for result.gasLimit >= minGas && last < len(chains) {
|
||||
// trim
|
||||
chains[last].Trim(gasLimit, mp, baseFee)
|
||||
result.trimChain(chains[last], mp, baseFee)
|
||||
|
||||
// push down if it hasn't been invalidated
|
||||
if chains[last].valid {
|
||||
@ -501,9 +561,8 @@ tailLoop:
|
||||
}
|
||||
|
||||
// does it fit in the bock?
|
||||
if chain.gasLimit <= gasLimit {
|
||||
gasLimit -= chain.gasLimit
|
||||
result = append(result, chain.msgs...)
|
||||
if result.tryToAdd(chain) {
|
||||
// there was room, we added the chain, keep going
|
||||
continue
|
||||
}
|
||||
|
||||
@ -523,7 +582,7 @@ tailLoop:
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (mp *MessagePool) selectPriorityMessages(ctx context.Context, pending map[address.Address]map[uint64]*types.SignedMessage, baseFee types.BigInt, ts *types.TipSet) ([]*types.SignedMessage, int64) {
|
||||
func (mp *MessagePool) selectPriorityMessages(ctx context.Context, pending map[address.Address]map[uint64]*types.SignedMessage, baseFee types.BigInt, ts *types.TipSet) *selectedMessages {
|
||||
start := time.Now()
|
||||
defer func() {
|
||||
if dt := time.Since(start); dt > time.Millisecond {
|
||||
@ -531,8 +590,12 @@ func (mp *MessagePool) selectPriorityMessages(ctx context.Context, pending map[a
|
||||
}
|
||||
}()
|
||||
mpCfg := mp.getConfig()
|
||||
result := make([]*types.SignedMessage, 0, mpCfg.SizeLimitLow)
|
||||
gasLimit := int64(build.BlockGasLimit)
|
||||
result := &selectedMessages{
|
||||
msgs: make([]*types.SignedMessage, 0, mpCfg.SizeLimitLow),
|
||||
gasLimit: int64(build.BlockGasLimit),
|
||||
blsLimit: cbg.MaxLength,
|
||||
secpLimit: cbg.MaxLength,
|
||||
}
|
||||
minGas := int64(gasguess.MinGas)
|
||||
|
||||
// 1. Get priority actor chains
|
||||
@ -542,7 +605,7 @@ func (mp *MessagePool) selectPriorityMessages(ctx context.Context, pending map[a
|
||||
pk, err := mp.resolveToKey(ctx, actor)
|
||||
if err != nil {
|
||||
log.Debugf("mpooladdlocal failed to resolve sender: %s", err)
|
||||
return nil, gasLimit
|
||||
return result
|
||||
}
|
||||
|
||||
mset, ok := pending[pk]
|
||||
@ -554,9 +617,8 @@ func (mp *MessagePool) selectPriorityMessages(ctx context.Context, pending map[a
|
||||
chains = append(chains, next...)
|
||||
}
|
||||
}
|
||||
|
||||
if len(chains) == 0 {
|
||||
return nil, gasLimit
|
||||
return result
|
||||
}
|
||||
|
||||
// 2. Sort the chains
|
||||
@ -566,7 +628,7 @@ func (mp *MessagePool) selectPriorityMessages(ctx context.Context, pending map[a
|
||||
|
||||
if len(chains) != 0 && chains[0].gasPerf < 0 {
|
||||
log.Warnw("all priority messages in mpool have negative gas performance", "bestGasPerf", chains[0].gasPerf)
|
||||
return nil, gasLimit
|
||||
return result
|
||||
}
|
||||
|
||||
// 3. Merge chains until the block limit, as long as they have non-negative gas performance
|
||||
@ -576,9 +638,8 @@ func (mp *MessagePool) selectPriorityMessages(ctx context.Context, pending map[a
|
||||
break
|
||||
}
|
||||
|
||||
if chain.gasLimit <= gasLimit {
|
||||
gasLimit -= chain.gasLimit
|
||||
result = append(result, chain.msgs...)
|
||||
if result.tryToAdd(chain) {
|
||||
// there was room, we added the chain, keep going
|
||||
continue
|
||||
}
|
||||
|
||||
@ -588,9 +649,10 @@ func (mp *MessagePool) selectPriorityMessages(ctx context.Context, pending map[a
|
||||
}
|
||||
|
||||
tailLoop:
|
||||
for gasLimit >= minGas && last < len(chains) {
|
||||
for result.gasLimit >= minGas && last < len(chains) {
|
||||
// trim, discarding negative performing messages
|
||||
chains[last].Trim(gasLimit, mp, baseFee)
|
||||
|
||||
result.trimChain(chains[last], mp, baseFee)
|
||||
|
||||
// push down if it hasn't been invalidated
|
||||
if chains[last].valid {
|
||||
@ -615,9 +677,8 @@ tailLoop:
|
||||
}
|
||||
|
||||
// does it fit in the bock?
|
||||
if chain.gasLimit <= gasLimit {
|
||||
gasLimit -= chain.gasLimit
|
||||
result = append(result, chain.msgs...)
|
||||
if result.tryToAdd(chain) {
|
||||
// there was room, we added the chain, keep going
|
||||
continue
|
||||
}
|
||||
|
||||
@ -631,10 +692,10 @@ tailLoop:
|
||||
break
|
||||
}
|
||||
|
||||
return result, gasLimit
|
||||
return result
|
||||
}
|
||||
|
||||
func (mp *MessagePool) getPendingMessages(curTs, ts *types.TipSet) (map[address.Address]map[uint64]*types.SignedMessage, error) {
|
||||
func (mp *MessagePool) getPendingMessages(ctx context.Context, curTs, ts *types.TipSet) (map[address.Address]map[uint64]*types.SignedMessage, error) {
|
||||
start := time.Now()
|
||||
|
||||
result := make(map[address.Address]map[uint64]*types.SignedMessage)
|
||||
@ -670,7 +731,7 @@ func (mp *MessagePool) getPendingMessages(curTs, ts *types.TipSet) (map[address.
|
||||
return result, nil
|
||||
}
|
||||
|
||||
if err := mp.runHeadChange(curTs, ts, result); err != nil {
|
||||
if err := mp.runHeadChange(ctx, curTs, ts, result); err != nil {
|
||||
return nil, xerrors.Errorf("failed to process difference between mpool head and given head: %w", err)
|
||||
}
|
||||
|
||||
@ -778,11 +839,16 @@ func (mp *MessagePool) createMessageChains(actor address.Address, mset map[uint6
|
||||
return nil
|
||||
}
|
||||
|
||||
// if we have more messages from this sender than can fit in a block, drop the extra ones
|
||||
if len(msgs) > build.BlockMessageLimit {
|
||||
msgs = msgs[:build.BlockMessageLimit]
|
||||
}
|
||||
|
||||
// ok, now we can construct the chains using the messages we have
|
||||
// invariant: each chain has a bigger gasPerf than the next -- otherwise they can be merged
|
||||
// and increase the gasPerf of the first chain
|
||||
// We do this in two passes:
|
||||
// - in the first pass we create chains that aggreagate messages with non-decreasing gasPerf
|
||||
// - in the first pass we create chains that aggregate messages with non-decreasing gasPerf
|
||||
// - in the second pass we merge chains to maintain the invariant.
|
||||
var chains []*msgChain
|
||||
var curChain *msgChain
|
||||
@ -794,6 +860,7 @@ func (mp *MessagePool) createMessageChains(actor address.Address, mset map[uint6
|
||||
chain.gasLimit = m.Message.GasLimit
|
||||
chain.gasPerf = mp.getGasPerf(chain.gasReward, chain.gasLimit)
|
||||
chain.valid = true
|
||||
chain.sigType = m.Signature.Type
|
||||
return chain
|
||||
}
|
||||
|
||||
@ -808,7 +875,7 @@ func (mp *MessagePool) createMessageChains(actor address.Address, mset map[uint6
|
||||
gasLimit := curChain.gasLimit + m.Message.GasLimit
|
||||
gasPerf := mp.getGasPerf(gasReward, gasLimit)
|
||||
|
||||
// try to add the message to the current chain -- if it decreases the gasPerf, then make a
|
||||
// try to add the message to the current chain -- if it decreases the gasPerf, or then make a
|
||||
// new chain
|
||||
if gasPerf < curChain.gasPerf {
|
||||
chains = append(chains, curChain)
|
||||
@ -868,9 +935,9 @@ func (mc *msgChain) Before(other *msgChain) bool {
|
||||
(mc.gasPerf == other.gasPerf && mc.gasReward.Cmp(other.gasReward) > 0)
|
||||
}
|
||||
|
||||
func (mc *msgChain) Trim(gasLimit int64, mp *MessagePool, baseFee types.BigInt) {
|
||||
func (mc *msgChain) Trim(gasLimit int64, msgLimit int, mp *MessagePool, baseFee types.BigInt) {
|
||||
i := len(mc.msgs) - 1
|
||||
for i >= 0 && (mc.gasLimit > gasLimit || mc.gasPerf < 0) {
|
||||
for i >= 0 && (mc.gasLimit > gasLimit || mc.gasPerf < 0 || i >= msgLimit) {
|
||||
gasReward := mp.getGasReward(mc.msgs[i], baseFee)
|
||||
mc.gasReward = new(big.Int).Sub(mc.gasReward, gasReward)
|
||||
mc.gasLimit -= mc.msgs[i].Message.GasLimit
|
||||
@ -893,6 +960,7 @@ func (mc *msgChain) Trim(gasLimit int64, mp *MessagePool, baseFee types.BigInt)
|
||||
mc.msgs = mc.msgs[:i+1]
|
||||
}
|
||||
|
||||
// TODO: if the trim above is a no-op, this (may) needlessly invalidates the next chain
|
||||
if mc.next != nil {
|
||||
mc.next.Invalidate()
|
||||
mc.next = nil
|
||||
|
@ -13,6 +13,10 @@ import (
|
||||
"sort"
|
||||
"testing"
|
||||
|
||||
"github.com/filecoin-project/go-state-types/crypto"
|
||||
|
||||
cbg "github.com/whyrusleeping/cbor-gen"
|
||||
|
||||
"github.com/filecoin-project/go-address"
|
||||
"github.com/ipfs/go-cid"
|
||||
"github.com/ipfs/go-datastore"
|
||||
@ -61,7 +65,7 @@ func makeTestMessage(w *wallet.LocalWallet, from, to address.Address, nonce uint
|
||||
func makeTestMpool() (*MessagePool, *testMpoolAPI) {
|
||||
tma := newTestMpoolAPI()
|
||||
ds := datastore.NewMapDatastore()
|
||||
mp, err := New(tma, ds, filcns.DefaultUpgradeSchedule(), "test", nil)
|
||||
mp, err := New(context.Background(), tma, ds, filcns.DefaultUpgradeSchedule(), "test", nil)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@ -527,7 +531,7 @@ func TestBasicMessageSelection(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestMessageSelectionTrimming(t *testing.T) {
|
||||
func TestMessageSelectionTrimmingGas(t *testing.T) {
|
||||
mp, tma := makeTestMpool()
|
||||
|
||||
// the actors
|
||||
@ -577,7 +581,7 @@ func TestMessageSelectionTrimming(t *testing.T) {
|
||||
|
||||
expected := int(build.BlockGasLimit / gasLimit)
|
||||
if len(msgs) != expected {
|
||||
t.Fatalf("expected %d messages, bug got %d", expected, len(msgs))
|
||||
t.Fatalf("expected %d messages, but got %d", expected, len(msgs))
|
||||
}
|
||||
|
||||
mGasLimit := int64(0)
|
||||
@ -590,6 +594,199 @@ func TestMessageSelectionTrimming(t *testing.T) {
|
||||
|
||||
}
|
||||
|
||||
func TestMessageSelectionTrimmingMsgsBasic(t *testing.T) {
|
||||
mp, tma := makeTestMpool()
|
||||
|
||||
// the actors
|
||||
w1, err := wallet.NewWallet(wallet.NewMemKeyStore())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
a1, err := w1.WalletNew(context.Background(), types.KTSecp256k1)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
block := tma.nextBlock()
|
||||
ts := mock.TipSet(block)
|
||||
tma.applyBlock(t, block)
|
||||
|
||||
tma.setBalance(a1, 1) // in FIL
|
||||
|
||||
// create a larger than selectable chain
|
||||
for i := 0; i < build.BlockMessageLimit; i++ {
|
||||
m := makeTestMessage(w1, a1, a1, uint64(i), 300000, 100)
|
||||
mustAdd(t, mp, m)
|
||||
}
|
||||
|
||||
msgs, err := mp.SelectMessages(context.Background(), ts, 1.0)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
expected := cbg.MaxLength
|
||||
if len(msgs) != expected {
|
||||
t.Fatalf("expected %d messages, but got %d", expected, len(msgs))
|
||||
}
|
||||
|
||||
mGasLimit := int64(0)
|
||||
for _, m := range msgs {
|
||||
mGasLimit += m.Message.GasLimit
|
||||
}
|
||||
if mGasLimit > build.BlockGasLimit {
|
||||
t.Fatal("selected messages gas limit exceeds block gas limit!")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestMessageSelectionTrimmingMsgsTwoSendersBasic(t *testing.T) {
|
||||
mp, tma := makeTestMpool()
|
||||
|
||||
// the actors
|
||||
w1, err := wallet.NewWallet(wallet.NewMemKeyStore())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
a1, err := w1.WalletNew(context.Background(), types.KTSecp256k1)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
w2, err := wallet.NewWallet(wallet.NewMemKeyStore())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
a2, err := w2.WalletNew(context.Background(), types.KTBLS)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
block := tma.nextBlock()
|
||||
ts := mock.TipSet(block)
|
||||
tma.applyBlock(t, block)
|
||||
|
||||
tma.setBalance(a1, 1) // in FIL
|
||||
tma.setBalance(a2, 1) // in FIL
|
||||
|
||||
// create 2 larger than selectable chains
|
||||
for i := 0; i < build.BlockMessageLimit; i++ {
|
||||
m := makeTestMessage(w1, a1, a2, uint64(i), 300000, 100)
|
||||
mustAdd(t, mp, m)
|
||||
// a2's messages are preferred
|
||||
m = makeTestMessage(w2, a2, a1, uint64(i), 300000, 1000)
|
||||
mustAdd(t, mp, m)
|
||||
}
|
||||
|
||||
msgs, err := mp.SelectMessages(context.Background(), ts, 1.0)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
mGasLimit := int64(0)
|
||||
counts := make(map[crypto.SigType]uint)
|
||||
for _, m := range msgs {
|
||||
mGasLimit += m.Message.GasLimit
|
||||
counts[m.Signature.Type]++
|
||||
}
|
||||
|
||||
if mGasLimit > build.BlockGasLimit {
|
||||
t.Fatal("selected messages gas limit exceeds block gas limit!")
|
||||
}
|
||||
|
||||
expected := build.BlockMessageLimit
|
||||
if len(msgs) != expected {
|
||||
t.Fatalf("expected %d messages, but got %d", expected, len(msgs))
|
||||
}
|
||||
|
||||
if counts[crypto.SigTypeBLS] != cbg.MaxLength {
|
||||
t.Fatalf("expected %d bls messages, but got %d", cbg.MaxLength, len(msgs))
|
||||
}
|
||||
}
|
||||
|
||||
func TestMessageSelectionTrimmingMsgsTwoSendersAdvanced(t *testing.T) {
|
||||
mp, tma := makeTestMpool()
|
||||
|
||||
// the actors
|
||||
w1, err := wallet.NewWallet(wallet.NewMemKeyStore())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
a1, err := w1.WalletNew(context.Background(), types.KTSecp256k1)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
w2, err := wallet.NewWallet(wallet.NewMemKeyStore())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
a2, err := w2.WalletNew(context.Background(), types.KTBLS)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
block := tma.nextBlock()
|
||||
ts := mock.TipSet(block)
|
||||
tma.applyBlock(t, block)
|
||||
|
||||
tma.setBalance(a1, 1) // in FIL
|
||||
tma.setBalance(a2, 1) // in FIL
|
||||
|
||||
// create 2 almost max-length chains of equal value
|
||||
i := 0
|
||||
for i = 0; i < cbg.MaxLength-1; i++ {
|
||||
m := makeTestMessage(w1, a1, a2, uint64(i), 300000, 100)
|
||||
mustAdd(t, mp, m)
|
||||
// a2's messages are preferred
|
||||
m = makeTestMessage(w2, a2, a1, uint64(i), 300000, 100)
|
||||
mustAdd(t, mp, m)
|
||||
}
|
||||
|
||||
// a1's 8192th message is worth more than a2's
|
||||
m := makeTestMessage(w1, a1, a2, uint64(i), 300000, 1000)
|
||||
mustAdd(t, mp, m)
|
||||
|
||||
m = makeTestMessage(w2, a2, a1, uint64(i), 300000, 100)
|
||||
mustAdd(t, mp, m)
|
||||
|
||||
i++
|
||||
|
||||
// a2's (unselectable) 8193rd message is worth SO MUCH
|
||||
m = makeTestMessage(w2, a2, a1, uint64(i), 300000, 1000000)
|
||||
mustAdd(t, mp, m)
|
||||
|
||||
msgs, err := mp.SelectMessages(context.Background(), ts, 1.0)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
mGasLimit := int64(0)
|
||||
counts := make(map[crypto.SigType]uint)
|
||||
for _, m := range msgs {
|
||||
mGasLimit += m.Message.GasLimit
|
||||
counts[m.Signature.Type]++
|
||||
}
|
||||
|
||||
if mGasLimit > build.BlockGasLimit {
|
||||
t.Fatal("selected messages gas limit exceeds block gas limit!")
|
||||
}
|
||||
|
||||
expected := build.BlockMessageLimit
|
||||
if len(msgs) != expected {
|
||||
t.Fatalf("expected %d messages, but got %d", expected, len(msgs))
|
||||
}
|
||||
|
||||
// we should have taken the secp chain
|
||||
if counts[crypto.SigTypeSecp256k1] != cbg.MaxLength {
|
||||
t.Fatalf("expected %d bls messages, but got %d", cbg.MaxLength, len(msgs))
|
||||
}
|
||||
}
|
||||
|
||||
func TestPriorityMessageSelection(t *testing.T) {
|
||||
mp, tma := makeTestMpool()
|
||||
|
||||
@ -978,7 +1175,7 @@ func TestOptimalMessageSelection2(t *testing.T) {
|
||||
func TestOptimalMessageSelection3(t *testing.T) {
|
||||
// this test uses 10 actors sending a block of messages to each other, with the the first
|
||||
// actors paying higher gas premium than the subsequent actors.
|
||||
// We select with a low ticket quality; the chain depenent merging algorithm should pick
|
||||
// We select with a low ticket quality; the chain dependent merging algorithm should pick
|
||||
// messages from the median actor from the start
|
||||
mp, tma := makeTestMpool()
|
||||
|
||||
@ -1109,11 +1306,13 @@ func testCompetitiveMessageSelection(t *testing.T, rng *rand.Rand, getPremium fu
|
||||
logging.SetLogLevel("messagepool", "error")
|
||||
|
||||
// 1. greedy selection
|
||||
greedyMsgs, err := mp.selectMessagesGreedy(context.Background(), ts, ts)
|
||||
gm, err := mp.selectMessagesGreedy(context.Background(), ts, ts)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
greedyMsgs := gm.msgs
|
||||
|
||||
totalGreedyCapacity := 0.0
|
||||
totalGreedyReward := 0.0
|
||||
totalOptimalCapacity := 0.0
|
||||
|
@ -84,7 +84,7 @@ func (ms *MessageSigner) SignMessage(ctx context.Context, msg *types.Message, cb
|
||||
}
|
||||
|
||||
// If the callback executed successfully, write the nonce to the datastore
|
||||
if err := ms.saveNonce(msg.From, nonce); err != nil {
|
||||
if err := ms.saveNonce(ctx, msg.From, nonce); err != nil {
|
||||
return nil, xerrors.Errorf("failed to save nonce: %w", err)
|
||||
}
|
||||
|
||||
@ -105,7 +105,7 @@ func (ms *MessageSigner) nextNonce(ctx context.Context, addr address.Address) (u
|
||||
|
||||
// Get the next nonce for this address from the datastore
|
||||
addrNonceKey := ms.dstoreKey(addr)
|
||||
dsNonceBytes, err := ms.ds.Get(addrNonceKey)
|
||||
dsNonceBytes, err := ms.ds.Get(ctx, addrNonceKey)
|
||||
|
||||
switch {
|
||||
case xerrors.Is(err, datastore.ErrNotFound):
|
||||
@ -139,7 +139,7 @@ func (ms *MessageSigner) nextNonce(ctx context.Context, addr address.Address) (u
|
||||
|
||||
// saveNonce increments the nonce for this address and writes it to the
|
||||
// datastore
|
||||
func (ms *MessageSigner) saveNonce(addr address.Address, nonce uint64) error {
|
||||
func (ms *MessageSigner) saveNonce(ctx context.Context, addr address.Address, nonce uint64) error {
|
||||
// Increment the nonce
|
||||
nonce++
|
||||
|
||||
@ -150,7 +150,7 @@ func (ms *MessageSigner) saveNonce(addr address.Address, nonce uint64) error {
|
||||
if err != nil {
|
||||
return xerrors.Errorf("failed to marshall nonce: %w", err)
|
||||
}
|
||||
err = ms.ds.Put(addrNonceKey, buf.Bytes())
|
||||
err = ms.ds.Put(ctx, addrNonceKey, buf.Bytes())
|
||||
if err != nil {
|
||||
return xerrors.Errorf("failed to write nonce to datastore: %w", err)
|
||||
}
|
||||
|
@ -4,6 +4,8 @@ import (
|
||||
"context"
|
||||
"encoding/binary"
|
||||
|
||||
"github.com/filecoin-project/go-state-types/network"
|
||||
|
||||
logging "github.com/ipfs/go-log/v2"
|
||||
|
||||
"github.com/filecoin-project/lotus/chain/beacon"
|
||||
@ -48,7 +50,7 @@ func (sr *stateRand) GetBeaconRandomnessTipset(ctx context.Context, round abi.Ch
|
||||
defer span.End()
|
||||
span.AddAttributes(trace.Int64Attribute("round", int64(round)))
|
||||
|
||||
ts, err := sr.cs.LoadTipSet(types.NewTipSetKey(sr.blks...))
|
||||
ts, err := sr.cs.LoadTipSet(ctx, types.NewTipSetKey(sr.blks...))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -70,12 +72,12 @@ func (sr *stateRand) GetBeaconRandomnessTipset(ctx context.Context, round abi.Ch
|
||||
return randTs, nil
|
||||
}
|
||||
|
||||
func (sr *stateRand) GetChainRandomness(ctx context.Context, pers crypto.DomainSeparationTag, round abi.ChainEpoch, entropy []byte, lookback bool) ([]byte, error) {
|
||||
func (sr *stateRand) getChainRandomness(ctx context.Context, pers crypto.DomainSeparationTag, round abi.ChainEpoch, entropy []byte, lookback bool) ([]byte, error) {
|
||||
_, span := trace.StartSpan(ctx, "store.GetChainRandomness")
|
||||
defer span.End()
|
||||
span.AddAttributes(trace.Int64Attribute("round", int64(round)))
|
||||
|
||||
ts, err := sr.cs.LoadTipSet(types.NewTipSetKey(sr.blks...))
|
||||
ts, err := sr.cs.LoadTipSet(ctx, types.NewTipSetKey(sr.blks...))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -101,38 +103,32 @@ func (sr *stateRand) GetChainRandomness(ctx context.Context, pers crypto.DomainS
|
||||
return DrawRandomness(mtb.Ticket.VRFProof, pers, round, entropy)
|
||||
}
|
||||
|
||||
type NetworkVersionGetter func(context.Context, abi.ChainEpoch) network.Version
|
||||
|
||||
type stateRand struct {
|
||||
cs *store.ChainStore
|
||||
blks []cid.Cid
|
||||
beacon beacon.Schedule
|
||||
cs *store.ChainStore
|
||||
blks []cid.Cid
|
||||
beacon beacon.Schedule
|
||||
networkVersionGetter NetworkVersionGetter
|
||||
}
|
||||
|
||||
func NewStateRand(cs *store.ChainStore, blks []cid.Cid, b beacon.Schedule) vm.Rand {
|
||||
func NewStateRand(cs *store.ChainStore, blks []cid.Cid, b beacon.Schedule, networkVersionGetter NetworkVersionGetter) vm.Rand {
|
||||
return &stateRand{
|
||||
cs: cs,
|
||||
blks: blks,
|
||||
beacon: b,
|
||||
cs: cs,
|
||||
blks: blks,
|
||||
beacon: b,
|
||||
networkVersionGetter: networkVersionGetter,
|
||||
}
|
||||
}
|
||||
|
||||
// network v0-12
|
||||
func (sr *stateRand) GetChainRandomnessV1(ctx context.Context, pers crypto.DomainSeparationTag, round abi.ChainEpoch, entropy []byte) ([]byte, error) {
|
||||
return sr.GetChainRandomness(ctx, pers, round, entropy, true)
|
||||
}
|
||||
|
||||
// network v13 and on
|
||||
func (sr *stateRand) GetChainRandomnessV2(ctx context.Context, pers crypto.DomainSeparationTag, round abi.ChainEpoch, entropy []byte) ([]byte, error) {
|
||||
return sr.GetChainRandomness(ctx, pers, round, entropy, false)
|
||||
}
|
||||
|
||||
// network v0-12
|
||||
func (sr *stateRand) GetBeaconRandomnessV1(ctx context.Context, pers crypto.DomainSeparationTag, round abi.ChainEpoch, entropy []byte) ([]byte, error) {
|
||||
func (sr *stateRand) getBeaconRandomnessV1(ctx context.Context, pers crypto.DomainSeparationTag, round abi.ChainEpoch, entropy []byte) ([]byte, error) {
|
||||
randTs, err := sr.GetBeaconRandomnessTipset(ctx, round, true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
be, err := sr.cs.GetLatestBeaconEntry(randTs)
|
||||
be, err := sr.cs.GetLatestBeaconEntry(ctx, randTs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -143,13 +139,13 @@ func (sr *stateRand) GetBeaconRandomnessV1(ctx context.Context, pers crypto.Doma
|
||||
}
|
||||
|
||||
// network v13
|
||||
func (sr *stateRand) GetBeaconRandomnessV2(ctx context.Context, pers crypto.DomainSeparationTag, round abi.ChainEpoch, entropy []byte) ([]byte, error) {
|
||||
func (sr *stateRand) getBeaconRandomnessV2(ctx context.Context, pers crypto.DomainSeparationTag, round abi.ChainEpoch, entropy []byte) ([]byte, error) {
|
||||
randTs, err := sr.GetBeaconRandomnessTipset(ctx, round, false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
be, err := sr.cs.GetLatestBeaconEntry(randTs)
|
||||
be, err := sr.cs.GetLatestBeaconEntry(ctx, randTs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -160,9 +156,9 @@ func (sr *stateRand) GetBeaconRandomnessV2(ctx context.Context, pers crypto.Doma
|
||||
}
|
||||
|
||||
// network v14 and on
|
||||
func (sr *stateRand) GetBeaconRandomnessV3(ctx context.Context, pers crypto.DomainSeparationTag, filecoinEpoch abi.ChainEpoch, entropy []byte) ([]byte, error) {
|
||||
func (sr *stateRand) getBeaconRandomnessV3(ctx context.Context, pers crypto.DomainSeparationTag, filecoinEpoch abi.ChainEpoch, entropy []byte) ([]byte, error) {
|
||||
if filecoinEpoch < 0 {
|
||||
return sr.GetBeaconRandomnessV2(ctx, pers, filecoinEpoch, entropy)
|
||||
return sr.getBeaconRandomnessV2(ctx, pers, filecoinEpoch, entropy)
|
||||
}
|
||||
|
||||
be, err := sr.extractBeaconEntryForEpoch(ctx, filecoinEpoch)
|
||||
@ -174,6 +170,28 @@ func (sr *stateRand) GetBeaconRandomnessV3(ctx context.Context, pers crypto.Doma
|
||||
return DrawRandomness(be.Data, pers, filecoinEpoch, entropy)
|
||||
}
|
||||
|
||||
func (sr *stateRand) GetChainRandomness(ctx context.Context, pers crypto.DomainSeparationTag, filecoinEpoch abi.ChainEpoch, entropy []byte) ([]byte, error) {
|
||||
nv := sr.networkVersionGetter(ctx, filecoinEpoch)
|
||||
|
||||
if nv >= network.Version13 {
|
||||
return sr.getChainRandomness(ctx, pers, filecoinEpoch, entropy, false)
|
||||
}
|
||||
|
||||
return sr.getChainRandomness(ctx, pers, filecoinEpoch, entropy, true)
|
||||
}
|
||||
|
||||
func (sr *stateRand) GetBeaconRandomness(ctx context.Context, pers crypto.DomainSeparationTag, filecoinEpoch abi.ChainEpoch, entropy []byte) ([]byte, error) {
|
||||
nv := sr.networkVersionGetter(ctx, filecoinEpoch)
|
||||
|
||||
if nv >= network.Version14 {
|
||||
return sr.getBeaconRandomnessV3(ctx, pers, filecoinEpoch, entropy)
|
||||
} else if nv == network.Version13 {
|
||||
return sr.getBeaconRandomnessV2(ctx, pers, filecoinEpoch, entropy)
|
||||
} else {
|
||||
return sr.getBeaconRandomnessV1(ctx, pers, filecoinEpoch, entropy)
|
||||
}
|
||||
}
|
||||
|
||||
func (sr *stateRand) extractBeaconEntryForEpoch(ctx context.Context, filecoinEpoch abi.ChainEpoch) (*types.BeaconEntry, error) {
|
||||
randTs, err := sr.GetBeaconRandomnessTipset(ctx, filecoinEpoch, false)
|
||||
if err != nil {
|
||||
@ -190,7 +208,7 @@ func (sr *stateRand) extractBeaconEntryForEpoch(ctx context.Context, filecoinEpo
|
||||
}
|
||||
}
|
||||
|
||||
next, err := sr.cs.LoadTipSet(randTs.Parents())
|
||||
next, err := sr.cs.LoadTipSet(ctx, randTs.Parents())
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("failed to load parents when searching back for beacon entry: %w", err)
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user