-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4623 from filecoin-project/feat/cache-deal-state-…
…matcher Cache deal states for most recent old/new tipset
- Loading branch information
Showing
8 changed files
with
402 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package test | ||
|
||
import ( | ||
"context" | ||
"sync" | ||
|
||
"github.com/filecoin-project/go-address" | ||
"github.com/filecoin-project/lotus/chain/types" | ||
"github.com/filecoin-project/lotus/lib/blockstore" | ||
"github.com/ipfs/go-cid" | ||
"golang.org/x/xerrors" | ||
) | ||
|
||
type MockAPI struct { | ||
bs blockstore.Blockstore | ||
|
||
lk sync.Mutex | ||
ts map[types.TipSetKey]*types.Actor | ||
stateGetActorCalled int | ||
} | ||
|
||
func NewMockAPI(bs blockstore.Blockstore) *MockAPI { | ||
return &MockAPI{ | ||
bs: bs, | ||
ts: make(map[types.TipSetKey]*types.Actor), | ||
} | ||
} | ||
|
||
func (m *MockAPI) ChainHasObj(ctx context.Context, c cid.Cid) (bool, error) { | ||
return m.bs.Has(c) | ||
} | ||
|
||
func (m *MockAPI) ChainReadObj(ctx context.Context, c cid.Cid) ([]byte, error) { | ||
blk, err := m.bs.Get(c) | ||
if err != nil { | ||
return nil, xerrors.Errorf("blockstore get: %w", err) | ||
} | ||
|
||
return blk.RawData(), nil | ||
} | ||
|
||
func (m *MockAPI) StateGetActor(ctx context.Context, actor address.Address, tsk types.TipSetKey) (*types.Actor, error) { | ||
m.lk.Lock() | ||
defer m.lk.Unlock() | ||
|
||
m.stateGetActorCalled++ | ||
return m.ts[tsk], nil | ||
} | ||
|
||
func (m *MockAPI) StateGetActorCallCount() int { | ||
m.lk.Lock() | ||
defer m.lk.Unlock() | ||
|
||
return m.stateGetActorCalled | ||
} | ||
|
||
func (m *MockAPI) ResetCallCounts() { | ||
m.lk.Lock() | ||
defer m.lk.Unlock() | ||
|
||
m.stateGetActorCalled = 0 | ||
} | ||
|
||
func (m *MockAPI) SetActor(tsk types.TipSetKey, act *types.Actor) { | ||
m.lk.Lock() | ||
defer m.lk.Unlock() | ||
|
||
m.ts[tsk] = act | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package test | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/filecoin-project/go-state-types/abi" | ||
"github.com/ipfs/go-cid" | ||
|
||
"github.com/filecoin-project/specs-actors/v2/actors/builtin/market" | ||
"github.com/filecoin-project/specs-actors/v2/actors/util/adt" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func CreateEmptyMarketState(t *testing.T, store adt.Store) *market.State { | ||
emptyArrayCid, err := adt.MakeEmptyArray(store).Root() | ||
require.NoError(t, err) | ||
emptyMap, err := adt.MakeEmptyMap(store).Root() | ||
require.NoError(t, err) | ||
return market.ConstructState(emptyArrayCid, emptyMap, emptyMap) | ||
} | ||
|
||
func CreateDealAMT(ctx context.Context, t *testing.T, store adt.Store, deals map[abi.DealID]*market.DealState) cid.Cid { | ||
root := adt.MakeEmptyArray(store) | ||
for dealID, dealState := range deals { | ||
err := root.Set(uint64(dealID), dealState) | ||
require.NoError(t, err) | ||
} | ||
rootCid, err := root.Root() | ||
require.NoError(t, err) | ||
return rootCid | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package test | ||
|
||
import ( | ||
"github.com/filecoin-project/go-address" | ||
"github.com/filecoin-project/go-state-types/crypto" | ||
"github.com/filecoin-project/lotus/chain/types" | ||
"github.com/ipfs/go-cid" | ||
) | ||
|
||
var dummyCid cid.Cid | ||
|
||
func init() { | ||
dummyCid, _ = cid.Parse("bafkqaaa") | ||
} | ||
|
||
func MockTipset(minerAddr address.Address, timestamp uint64) (*types.TipSet, error) { | ||
return types.NewTipSet([]*types.BlockHeader{{ | ||
Miner: minerAddr, | ||
Height: 5, | ||
ParentStateRoot: dummyCid, | ||
Messages: dummyCid, | ||
ParentMessageReceipts: dummyCid, | ||
BlockSig: &crypto.Signature{Type: crypto.SigTypeBLS}, | ||
BLSAggregate: &crypto.Signature{Type: crypto.SigTypeBLS}, | ||
Timestamp: timestamp, | ||
}}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.