Skip to content

Commit

Permalink
chore!: rename "payload" CID to "root" CID
Browse files Browse the repository at this point in the history
except in the case of data-transfer requests where this is the lingo for
retrievals.

BREAKING only in that consumers of the internal event system will have trouble
with this; otherwise we use "root" CID externally everywhere else already.

Closes: #334
  • Loading branch information
rvagg committed Oct 2, 2023
1 parent bc241ce commit c730309
Show file tree
Hide file tree
Showing 23 changed files with 37 additions and 37 deletions.
2 changes: 1 addition & 1 deletion cmd/lassie/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ type progressPrinter struct {
func (pp *progressPrinter) subscriber(event types.RetrievalEvent) {
switch ret := event.(type) {
case events.StartedFindingCandidatesEvent:
fmt.Fprintf(pp.writer, "\rQuerying indexer for %s...\n", ret.PayloadCid())
fmt.Fprintf(pp.writer, "\rQuerying indexer for %s...\n", ret.RootCid())
case events.StartedRetrievalEvent:
fmt.Fprintf(pp.writer, "\rRetrieving from [%s] (%s)...\n", events.Identifier(ret), ret.Code())
case events.ConnectedToProviderEvent:
Expand Down
2 changes: 1 addition & 1 deletion pkg/aggregateeventrecorder/aggregateeventrecorder.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func (a *aggregateEventRecorder) ingestEvents() {
candidatesFiltered: 0,
firstByteTime: time.Time{},
spId: "",
rootCid: startedEvent.PayloadCid().String(),
rootCid: startedEvent.RootCid().String(),
urlPath: startedEvent.UrlPath(),
success: false,
bandwidth: 0,
Expand Down
4 changes: 2 additions & 2 deletions pkg/events/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import (
type retrievalEvent struct {
eventTime time.Time
retrievalId types.RetrievalID
payloadCid cid.Cid
rootCid cid.Cid
}

func (r retrievalEvent) Time() time.Time { return r.eventTime }
func (r retrievalEvent) RetrievalId() types.RetrievalID { return r.retrievalId }
func (r retrievalEvent) PayloadCid() cid.Cid { return r.payloadCid }
func (r retrievalEvent) RootCid() cid.Cid { return r.rootCid }

type providerRetrievalEvent struct {
retrievalEvent
Expand Down
2 changes: 1 addition & 1 deletion pkg/events/blockreceived.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func (e BlockReceivedEvent) Code() types.EventCode { return types.BlockRecei
func (e BlockReceivedEvent) ByteCount() uint64 { return e.byteCount }
func (e BlockReceivedEvent) Protocol() multicodec.Code { return e.protocol }
func (e BlockReceivedEvent) String() string {
return fmt.Sprintf("BlockReceivedEvent<%s, %s, %s, %s, %s, %d>", e.eventTime, e.retrievalId, e.payloadCid, e.providerId, e.protocol, e.byteCount)
return fmt.Sprintf("BlockReceivedEvent<%s, %s, %s, %s, %s, %d>", e.eventTime, e.retrievalId, e.rootCid, e.providerId, e.protocol, e.byteCount)
}

func BlockReceived(at time.Time, retrievalId types.RetrievalID, candidate types.RetrievalCandidate, protocol multicodec.Code, byteCount uint64) BlockReceivedEvent {
Expand Down
6 changes: 3 additions & 3 deletions pkg/events/candidatesfiltered.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ func (e CandidatesFilteredEvent) Code() types.EventCode { retur
func (e CandidatesFilteredEvent) Candidates() []types.RetrievalCandidate { return e.candidates }
func (e CandidatesFilteredEvent) Protocols() []multicodec.Code { return e.protocols }
func (e CandidatesFilteredEvent) String() string {
return fmt.Sprintf("CandidatesFilteredEvent<%s, %s, %s, %d>", e.eventTime, e.retrievalId, e.payloadCid, len(e.candidates))
return fmt.Sprintf("CandidatesFilteredEvent<%s, %s, %s, %d>", e.eventTime, e.retrievalId, e.rootCid, len(e.candidates))
}

func CandidatesFiltered(at time.Time, retrievalId types.RetrievalID, payloadCid cid.Cid, candidates []types.RetrievalCandidate) CandidatesFilteredEvent {
func CandidatesFiltered(at time.Time, retrievalId types.RetrievalID, rootCid cid.Cid, candidates []types.RetrievalCandidate) CandidatesFilteredEvent {
c := make([]types.RetrievalCandidate, len(candidates))
copy(c, candidates)
return CandidatesFilteredEvent{retrievalEvent{at, retrievalId, payloadCid}, c, collectProtocols(c)}
return CandidatesFilteredEvent{retrievalEvent{at, retrievalId, rootCid}, c, collectProtocols(c)}
}
6 changes: 3 additions & 3 deletions pkg/events/candidatesfound.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ type CandidatesFoundEvent struct {
func (e CandidatesFoundEvent) Code() types.EventCode { return types.CandidatesFoundCode }
func (e CandidatesFoundEvent) Candidates() []types.RetrievalCandidate { return e.candidates }
func (e CandidatesFoundEvent) String() string {
return fmt.Sprintf("CandidatesFoundEvent<%s, %s, %s, %d>", e.eventTime, e.retrievalId, e.payloadCid, len(e.candidates))
return fmt.Sprintf("CandidatesFoundEvent<%s, %s, %s, %d>", e.eventTime, e.retrievalId, e.rootCid, len(e.candidates))
}

func CandidatesFound(at time.Time, retrievalId types.RetrievalID, payloadCid cid.Cid, candidates []types.RetrievalCandidate) CandidatesFoundEvent {
func CandidatesFound(at time.Time, retrievalId types.RetrievalID, rootCid cid.Cid, candidates []types.RetrievalCandidate) CandidatesFoundEvent {
c := make([]types.RetrievalCandidate, len(candidates))
copy(c, candidates)
return CandidatesFoundEvent{retrievalEvent{at, retrievalId, payloadCid}, c}
return CandidatesFoundEvent{retrievalEvent{at, retrievalId, rootCid}, c}
}
2 changes: 1 addition & 1 deletion pkg/events/connectedtoprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type ConnectedToProviderEvent struct {
func (e ConnectedToProviderEvent) Code() types.EventCode { return types.ConnectedToProviderCode }
func (e ConnectedToProviderEvent) Protocol() multicodec.Code { return e.protocol }
func (e ConnectedToProviderEvent) String() string {
return fmt.Sprintf("ConnectedToProviderEvent<%s, %s, %s, %s>", e.eventTime, e.retrievalId, e.payloadCid, e.providerId)
return fmt.Sprintf("ConnectedToProviderEvent<%s, %s, %s, %s>", e.eventTime, e.retrievalId, e.rootCid, e.providerId)
}

func ConnectedToProvider(at time.Time, retrievalId types.RetrievalID, candidate types.RetrievalCandidate, protocol multicodec.Code) ConnectedToProviderEvent {
Expand Down
2 changes: 1 addition & 1 deletion pkg/events/failed.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type FailedEvent struct {
func (e FailedEvent) Code() types.EventCode { return types.FailedCode }
func (e FailedEvent) ErrorMessage() string { return e.errorMessage }
func (e FailedEvent) String() string {
return fmt.Sprintf("FailedEvent<%s, %s, %s, %v>", e.eventTime, e.retrievalId, e.payloadCid, e.errorMessage)
return fmt.Sprintf("FailedEvent<%s, %s, %s, %v>", e.eventTime, e.retrievalId, e.rootCid, e.errorMessage)
}

func Failed(at time.Time, retrievalId types.RetrievalID, candidate types.RetrievalCandidate, errorMessage string) FailedEvent {
Expand Down
2 changes: 1 addition & 1 deletion pkg/events/failedretrieval.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func (e FailedRetrievalEvent) Code() types.EventCode { return types.FailedRe
func (e FailedRetrievalEvent) ErrorMessage() string { return e.errorMessage }
func (e FailedRetrievalEvent) Protocol() multicodec.Code { return e.protocol }
func (e FailedRetrievalEvent) String() string {
return fmt.Sprintf("FailedRetrievalEvent<%s, %s, %s, %v>", e.eventTime, e.retrievalId, e.payloadCid, e.errorMessage)
return fmt.Sprintf("FailedRetrievalEvent<%s, %s, %s, %v>", e.eventTime, e.retrievalId, e.rootCid, e.errorMessage)
}

func FailedRetrieval(at time.Time, retrievalId types.RetrievalID, candidate types.RetrievalCandidate, protocol multicodec.Code, errorMessage string) FailedRetrievalEvent {
Expand Down
2 changes: 1 addition & 1 deletion pkg/events/finished.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type FinishedEvent struct {

func (e FinishedEvent) Code() types.EventCode { return types.FinishedCode }
func (e FinishedEvent) String() string {
return fmt.Sprintf("FinishedEvent<%s, %s, %s, %s>", e.eventTime, e.retrievalId, e.payloadCid, e.providerId)
return fmt.Sprintf("FinishedEvent<%s, %s, %s, %s>", e.eventTime, e.retrievalId, e.rootCid, e.providerId)
}

func Finished(at time.Time, retrievalId types.RetrievalID, candidate types.RetrievalCandidate) FinishedEvent {
Expand Down
2 changes: 1 addition & 1 deletion pkg/events/firstbyte.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func (e FirstByteEvent) Code() types.EventCode { return types.FirstByteCode
func (e FirstByteEvent) Duration() time.Duration { return e.duration }
func (e FirstByteEvent) Protocol() multicodec.Code { return e.protocol }
func (e FirstByteEvent) String() string {
return fmt.Sprintf("FirstByteEvent<%s, %s, %s, %s, %s, %s>", e.eventTime, e.retrievalId, e.payloadCid, e.providerId, e.duration.String(), e.protocol.String())
return fmt.Sprintf("FirstByteEvent<%s, %s, %s, %s, %s, %s>", e.eventTime, e.retrievalId, e.rootCid, e.providerId, e.duration.String(), e.protocol.String())
}

func FirstByte(at time.Time, retrievalId types.RetrievalID, candidate types.RetrievalCandidate, duration time.Duration, protocol multicodec.Code) FirstByteEvent {
Expand Down
2 changes: 1 addition & 1 deletion pkg/events/graphsyncaccepted.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func (e GraphsyncAcceptedEvent) Protocol() multicodec.Code {
return multicodec.TransportGraphsyncFilecoinv1
}
func (e GraphsyncAcceptedEvent) String() string {
return fmt.Sprintf("GraphsyncAcceptedEvent<%s, %s, %s, %s>", e.eventTime, e.retrievalId, e.payloadCid, e.providerId)
return fmt.Sprintf("GraphsyncAcceptedEvent<%s, %s, %s, %s>", e.eventTime, e.retrievalId, e.rootCid, e.providerId)
}

func Accepted(at time.Time, retrievalId types.RetrievalID, candidate types.RetrievalCandidate) GraphsyncAcceptedEvent {
Expand Down
2 changes: 1 addition & 1 deletion pkg/events/graphsyncproposed.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func (e GraphsyncProposedEvent) Protocol() multicodec.Code {
return multicodec.TransportGraphsyncFilecoinv1
}
func (e GraphsyncProposedEvent) String() string {
return fmt.Sprintf("GraphsyncProposedEvent<%s, %s, %s, %s>", e.eventTime, e.retrievalId, e.payloadCid, e.providerId)
return fmt.Sprintf("GraphsyncProposedEvent<%s, %s, %s, %s>", e.eventTime, e.retrievalId, e.rootCid, e.providerId)
}

func Proposed(at time.Time, retrievalId types.RetrievalID, candidate types.RetrievalCandidate) GraphsyncProposedEvent {
Expand Down
12 changes: 6 additions & 6 deletions pkg/events/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func TestEventManager(t *testing.T) {
verifyIndexerStarted := func(event types.RetrievalEvent) {
require.IsType(t, events.StartedFindingCandidatesEvent{}, event)
require.Equal(t, id, event.RetrievalId())
require.Equal(t, cid, event.PayloadCid())
require.Equal(t, cid, event.RootCid())
require.Equal(t, types.StartedFindingCandidatesCode, event.Code())
}
verifyEvent(gotEvents1, types.StartedFindingCandidatesCode, verifyIndexerStarted)
Expand All @@ -90,7 +90,7 @@ func TestEventManager(t *testing.T) {
verifyIndexerCandidatesFound := func(event types.RetrievalEvent) {
require.IsType(t, events.CandidatesFoundEvent{}, event)
require.Equal(t, id, event.RetrievalId())
require.Equal(t, cid, event.PayloadCid())
require.Equal(t, cid, event.RootCid())
require.Equal(t, types.CandidatesFoundCode, event.Code())
storageProviderIds := event.(events.CandidatesFoundEvent).Candidates()
require.Len(t, storageProviderIds, 3)
Expand All @@ -104,7 +104,7 @@ func TestEventManager(t *testing.T) {
verifyIndexerCandidatesFiltered := func(event types.RetrievalEvent) {
require.IsType(t, events.CandidatesFilteredEvent{}, event)
require.Equal(t, id, event.RetrievalId())
require.Equal(t, cid, event.PayloadCid())
require.Equal(t, cid, event.RootCid())
require.Equal(t, types.CandidatesFilteredCode, event.Code())
storageProviderIds := event.(events.CandidatesFilteredEvent).Candidates()
require.Len(t, storageProviderIds, 3)
Expand All @@ -118,7 +118,7 @@ func TestEventManager(t *testing.T) {
verifyRetrievalStarted := func(event types.RetrievalEvent) {
require.IsType(t, events.StartedRetrievalEvent{}, event)
require.Equal(t, id, event.RetrievalId())
require.Equal(t, cid, event.PayloadCid())
require.Equal(t, cid, event.RootCid())
require.Equal(t, types.StartedRetrievalCode, event.Code())
require.Equal(t, peerB, event.(events.StartedRetrievalEvent).ProviderId())
}
Expand All @@ -128,7 +128,7 @@ func TestEventManager(t *testing.T) {
verifyRetrievalSuccess := func(event types.RetrievalEvent) {
require.IsType(t, events.SucceededEvent{}, event)
require.Equal(t, id, event.RetrievalId())
require.Equal(t, cid, event.PayloadCid())
require.Equal(t, cid, event.RootCid())

successEvent := event.(events.SucceededEvent)
require.Equal(t, peerB, successEvent.ProviderId())
Expand All @@ -141,7 +141,7 @@ func TestEventManager(t *testing.T) {
verifyRetrievalFailure := func(event types.RetrievalEvent) {
require.IsType(t, events.FailedRetrievalEvent{}, event)
require.Equal(t, id, event.RetrievalId())
require.Equal(t, cid, event.PayloadCid())
require.Equal(t, cid, event.RootCid())

failedEvent := event.(events.FailedRetrievalEvent)
require.Equal(t, peerB, failedEvent.ProviderId())
Expand Down
2 changes: 1 addition & 1 deletion pkg/events/startedfetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func (e StartedFetchEvent) Code() types.EventCode { return types.StartedF
func (e StartedFetchEvent) UrlPath() string { return e.urlPath }
func (e StartedFetchEvent) Protocols() []multicodec.Code { return e.supportedProtocols }
func (e StartedFetchEvent) String() string {
return fmt.Sprintf("StartedFetchEvent<%s, %s, %s>", e.eventTime, e.retrievalId, e.payloadCid)
return fmt.Sprintf("StartedFetchEvent<%s, %s, %s>", e.eventTime, e.retrievalId, e.rootCid)
}

func StartedFetch(at time.Time, retrievalId types.RetrievalID, rootCid cid.Cid, urlPath string, supportedProtocols ...multicodec.Code) StartedFetchEvent {
Expand Down
6 changes: 3 additions & 3 deletions pkg/events/startedfindingcandidates.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ func (e StartedFindingCandidatesEvent) Code() types.EventCode {
return types.StartedFindingCandidatesCode
}
func (e StartedFindingCandidatesEvent) String() string {
return fmt.Sprintf("StartedFindingCandidatesEvent<%s, %s, %s>", e.eventTime, e.retrievalId, e.payloadCid)
return fmt.Sprintf("StartedFindingCandidatesEvent<%s, %s, %s>", e.eventTime, e.retrievalId, e.rootCid)
}

func StartedFindingCandidates(at time.Time, retrievalId types.RetrievalID, payloadCid cid.Cid) StartedFindingCandidatesEvent {
return StartedFindingCandidatesEvent{retrievalEvent{at, retrievalId, payloadCid}}
func StartedFindingCandidates(at time.Time, retrievalId types.RetrievalID, rootCid cid.Cid) StartedFindingCandidatesEvent {
return StartedFindingCandidatesEvent{retrievalEvent{at, retrievalId, rootCid}}
}
2 changes: 1 addition & 1 deletion pkg/events/startedretrieval.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type StartedRetrievalEvent struct {
func (e StartedRetrievalEvent) Code() types.EventCode { return types.StartedRetrievalCode }
func (e StartedRetrievalEvent) Protocol() multicodec.Code { return e.protocol }
func (e StartedRetrievalEvent) String() string {
return fmt.Sprintf("StartedRetrievalEvent<%s, %s, %s, %s, %s>", e.eventTime, e.retrievalId, e.payloadCid, e.providerId, e.protocol)
return fmt.Sprintf("StartedRetrievalEvent<%s, %s, %s, %s, %s>", e.eventTime, e.retrievalId, e.rootCid, e.providerId, e.protocol)
}

func StartedRetrieval(at time.Time, retrievalId types.RetrievalID, candidate types.RetrievalCandidate, protocol multicodec.Code) StartedRetrievalEvent {
Expand Down
2 changes: 1 addition & 1 deletion pkg/events/succeeded.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (e SucceededEvent) ReceivedCidsCount() uint64 { return e.receivedCidsCount
func (e SucceededEvent) Duration() time.Duration { return e.duration }
func (e SucceededEvent) Protocol() multicodec.Code { return e.protocol }
func (e SucceededEvent) String() string {
return fmt.Sprintf("SucceededEvent<%s, %s, %s, %s, { %d, %d, %s, %s }>", e.eventTime, e.retrievalId, e.payloadCid, e.providerId, e.receivedBytesSize, e.receivedCidsCount, e.protocol, e.duration)
return fmt.Sprintf("SucceededEvent<%s, %s, %s, %s, { %d, %d, %s, %s }>", e.eventTime, e.retrievalId, e.rootCid, e.providerId, e.receivedBytesSize, e.receivedCidsCount, e.protocol, e.duration)
}

func Success(at time.Time, retrievalId types.RetrievalID, candidate types.RetrievalCandidate, receivedBytesSize uint64, receivedCidsCount uint64, duration time.Duration, protocol multicodec.Code) SucceededEvent {
Expand Down
2 changes: 1 addition & 1 deletion pkg/internal/testutil/collectingeventlsubscriber.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func VerifyContainsCollectedEvent(t *testing.T, afterStart time.Duration, expect
func VerifyCollectedEvent(t *testing.T, actual types.RetrievalEvent, expected types.RetrievalEvent) {
require.Equal(t, expected.Code(), actual.Code(), "event code")
require.Equal(t, expected.RetrievalId(), actual.RetrievalId(), fmt.Sprintf("retrieval id for %s", expected.Code()))
require.Equal(t, expected.PayloadCid(), actual.PayloadCid(), fmt.Sprintf("cid for %s", expected.Code()))
require.Equal(t, expected.RootCid(), actual.RootCid(), fmt.Sprintf("cid for %s", expected.Code()))
require.Equal(t, expected.Time(), actual.Time(), fmt.Sprintf("time for %s", expected.Code()))

if asp, ok := actual.(events.EventWithProviderID); ok {
Expand Down
2 changes: 1 addition & 1 deletion pkg/retriever/assignablecandidatefinder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func TestAssignableCandidateFinder(t *testing.T) {
}
receivedEvents := make(map[cid.Cid][]types.RetrievalEvent)
retrievalCollector := func(evt types.RetrievalEvent) {
receivedEvents[evt.PayloadCid()] = append(receivedEvents[evt.PayloadCid()], evt)
receivedEvents[evt.RootCid()] = append(receivedEvents[evt.RootCid()], evt)
}
retrievalCandidateFinder := retriever.NewAssignableCandidateFinder(candidateFinder, isAcceptableStorageProvider)
rid1, err := types.NewRetrievalID()
Expand Down
2 changes: 1 addition & 1 deletion pkg/retriever/bitswapretriever_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ func TestBitswapRetriever(t *testing.T) {
bsr := retriever.NewBitswapRetrieverFromDeps(ctx, bsrv, mir, mipc, mbs, testCase.cfg, clock, awaitReceivedCandidates)
receivedEvents := make(map[cid.Cid][]types.RetrievalEvent)
retrievalCollector := func(evt types.RetrievalEvent) {
receivedEvents[evt.PayloadCid()] = append(receivedEvents[evt.PayloadCid()], evt)
receivedEvents[evt.RootCid()] = append(receivedEvents[evt.RootCid()], evt)
}

// retrieve
Expand Down
4 changes: 2 additions & 2 deletions pkg/retriever/retriever.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ func handleFailureEvent(
logger.Warnf(
"Failed to retrieve from miner %s for %s: %s",
event.ProviderId(),
event.PayloadCid(),
event.RootCid(),
event.ErrorMessage(),
)
}
Expand Down Expand Up @@ -274,7 +274,7 @@ func logEvent(event types.RetrievalEvent) {
}
}
logadd("code", event.Code(),
"payloadCid", event.PayloadCid(),
"rootCid", event.RootCid(),
"storageProviderId", events.Identifier(event))
switch tevent := event.(type) {
case events.EventWithCandidates:
Expand Down
4 changes: 2 additions & 2 deletions pkg/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,8 @@ type RetrievalEvent interface {
RetrievalId() RetrievalID
// Code returns the type of event this is
Code() EventCode
// PayloadCid returns the CID being requested
PayloadCid() cid.Cid
// RootCid returns the CID being requested
RootCid() cid.Cid
}

const BitswapIndentifier = "Bitswap"
Expand Down

0 comments on commit c730309

Please sign in to comment.