Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PDS does not correctly track rev for SyncGetLatestCommit #1841

Open
strideynet opened this issue Nov 9, 2023 · 1 comment
Open

PDS does not correctly track rev for SyncGetLatestCommit #1841

strideynet opened this issue Nov 9, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@strideynet
Copy link

strideynet commented Nov 9, 2023

Describe the bug

It does not appear that the PDS implementation of SyncGetLatestCommit is returning the repo's correct rev.

The rev returned by PDS implementation of SyncGetLatestCommit disagrees with the BGS implementation of SyncGetLatestCommit and with the rev contained within the repo returned by the PDS implementation of SyncGetRepo.

It feels like applyCommit/updateRoot in https://github.com/bluesky-social/atproto/blob/main/packages/pds/src/sql-repo-storage.ts is missing an update to the rev field on the repo_root table

To Reproduce

package main

import (
	"bytes"
	"context"
	"fmt"
	"github.com/bluesky-social/indigo/api/atproto"
	"github.com/bluesky-social/indigo/repo"
	"github.com/bluesky-social/indigo/xrpc"
	"github.com/ipfs/go-datastore"
	blockstore "github.com/ipfs/go-ipfs-blockstore"
)

func main() {
	run("https://bsky.network")
	run("https://bsky.social")
}

func run(host string) {
	ctx := context.Background()
	x := &xrpc.Client{
		Host: host,
	}
	myDID := "did:plc:dllwm3fafh66ktjofzxhylwk"
	out, err := atproto.SyncGetLatestCommit(ctx, x, myDID)
	if err != nil {
		panic(err)
	}

	rootCommitFromGetRecord := ""
	revFromGetRecord := ""
	{
		data, err := atproto.SyncGetRecord(ctx, x, "app.bsky.actor.profile", "", myDID, "self")
		if err != nil {
			panic(err)
		}
		bs := blockstore.NewBlockstore(datastore.NewMapDatastore())
		root, err := repo.IngestRepo(ctx, bs, bytes.NewReader(data))
		if err != nil {
			panic(err)
		}
		rr, err := repo.OpenRepo(ctx, bs, root, false)
		if err != nil {
			panic(err)
		}
		revFromGetRecord = rr.SignedCommit().Rev
		rootCommitFromGetRecord = root.String()
	}

	rootCommitFromGetRepo := ""
	revFromGetRepo := ""
	{
		data, err := atproto.SyncGetRepo(ctx, x, myDID, "")
		if err != nil {
			panic(err)
		}
		bs := blockstore.NewBlockstore(datastore.NewMapDatastore())
		root, err := repo.IngestRepo(ctx, bs, bytes.NewReader(data))
		if err != nil {
			panic(err)
		}
		rr, err := repo.OpenRepo(ctx, bs, root, false)
		if err != nil {
			panic(err)
		}
		revFromGetRepo = rr.SignedCommit().Rev
		rootCommitFromGetRepo = root.String()
	}

	fmt.Println("-- " + host + " --")
	fmt.Println("SyncGetLatestCommit root commit: " + out.Cid)
	fmt.Println("SyncGetRecord root commit:       " + rootCommitFromGetRecord)
	fmt.Println("SyncGetRepo root commit:         " + rootCommitFromGetRepo)
	fmt.Println("SyncGetLatestCommit rev: " + out.Rev)
	fmt.Println("SyncGetRecord rev:       " + revFromGetRecord)
	fmt.Println("SyncGetRepo rev:         " + revFromGetRepo)
}
-- https://bsky.network --
SyncGetLatestCommit root commit: bafyreibb2gfpu4szqbdqu7thfgmdk3mkmolhqyhyrmy6fkbj562to3fhqq
SyncGetRecord root commit:       bafyreibb2gfpu4szqbdqu7thfgmdk3mkmolhqyhyrmy6fkbj562to3fhqq
SyncGetRepo root commit:         bafyreibb2gfpu4szqbdqu7thfgmdk3mkmolhqyhyrmy6fkbj562to3fhqq
SyncGetLatestCommit rev: 3kds2mpvq7g25
SyncGetRecord rev:       3kds2mpvq7g25
SyncGetRepo rev:         3kds2mpvq7g25
-- https://bsky.social --
SyncGetLatestCommit root commit: bafyreibb2gfpu4szqbdqu7thfgmdk3mkmolhqyhyrmy6fkbj562to3fhqq
SyncGetRecord root commit:       bafyreibb2gfpu4szqbdqu7thfgmdk3mkmolhqyhyrmy6fkbj562to3fhqq
SyncGetRepo root commit:         bafyreibb2gfpu4szqbdqu7thfgmdk3mkmolhqyhyrmy6fkbj562to3fhqq
SyncGetLatestCommit rev: 3k6gswiedac24
SyncGetRecord rev:       3kds2mpvq7g25
SyncGetRepo rev:         3kds2mpvq7g25

Apologies for the ugly ass Go - it's just a quick demo to show how root commit / rev are agreed on by most things, but the rev returned by SyncGetLatestCommit for the PDS is in disagreement.

Expected behavior

SyncGetLatestCommit to return the correct rev for the repository.

Details

  • Operating system: MacOS
  • Node version: Not installed

Additional context

@strideynet strideynet added the bug Something isn't working label Nov 9, 2023
@bnewbold
Copy link
Collaborator

cc: @dholms @devinivy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants