tvx: trace puts to blockstore for inclusion in CAR.

This commit is contained in:
Raúl Kripalani 2020-10-09 22:20:15 +01:00
parent 91c10c2df5
commit e0dcb0ec49

View File

@ -87,7 +87,7 @@ type proxyingBlockstore struct {
ctx context.Context ctx context.Context
api api.FullNode api api.FullNode
lk sync.RWMutex lk sync.Mutex
tracing bool tracing bool
traced map[cid.Cid]struct{} traced map[cid.Cid]struct{}
@ -113,11 +113,11 @@ func (pb *proxyingBlockstore) FinishTracing() map[cid.Cid]struct{} {
} }
func (pb *proxyingBlockstore) Get(cid cid.Cid) (blocks.Block, error) { func (pb *proxyingBlockstore) Get(cid cid.Cid) (blocks.Block, error) {
pb.lk.RLock() pb.lk.Lock()
if pb.tracing { if pb.tracing {
pb.traced[cid] = struct{}{} pb.traced[cid] = struct{}{}
} }
pb.lk.RUnlock() pb.lk.Unlock()
if block, err := pb.Blockstore.Get(cid); err == nil { if block, err := pb.Blockstore.Get(cid); err == nil {
return block, err return block, err
@ -140,3 +140,12 @@ func (pb *proxyingBlockstore) Get(cid cid.Cid) (blocks.Block, error) {
return block, nil return block, nil
} }
func (pb *proxyingBlockstore) Put(block blocks.Block) error {
pb.lk.Lock()
if pb.tracing {
pb.traced[block.Cid()] = struct{}{}
}
pb.lk.Unlock()
return pb.Blockstore.Put(block)
}