Skip to content

Commit

Permalink
PROPOSAL - Use v1 Cids throughout the codebase
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewSisley committed Nov 24, 2021
1 parent 45230f9 commit 44e0dd9
Show file tree
Hide file tree
Showing 12 changed files with 34 additions and 25 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,24 +163,24 @@ This will return a structure similar to the following, which contains the update
{
"data": [
{
"cid": "QmPqCtcCPNHoWkHLFvG4aKqDkLLzhVDAVEDSzEs38GHxoo",
"cid": "bafkreibbbtps3cki27zs5w24djizgjfuydqsdgtrz773sfpqechiih5ose",
"delta": "pGNhZ2UYH2RuYW1lY0JvYmZwb2ludHMYWmh2ZXJpZmllZPU=",
"height": 1,
"links": [
{
"cid": "QmSom35RYVzYTE7nGsudvomv1pi9ffjEfSFsPZgQRM92v1",
"cid": "bafybeiccmckwnoe3ib3ebybcb6fdyawrji4z4wg2trwswjbfmkeyhdkd4y",
"name": "age"
},
{
"cid": "QmYJrCcfMmfFp4JcbChLfMLCv8TSHjGwRVHUBgPazWxPga",
"cid": "bafybeieud2zx7evz47vtujk4pyhexcaankozyfhkd4tyjoyp73eeq2xak4",
"name": "name"
},
{
"cid": "QmXLuVB5CCGqWcdQitingkfRxoVRLKh2jNcnX4UbYnW6Mk",
"cid": "bafybeiefzhsaukwg6dazgyztulstewns2f6a6c6hku4egso2cyowxrxcd4",
"name": "points"
},
{
"cid": "QmNRQwWjTBTDfAFUHkG8yuKmtbprYQtGs4jYxGJ5fCfXtn",
"cid": "bafybeiabhbk6omcebl52bwxjxbcabpe2ajc22yxrav7mq5f26v7ds76j2m",
"name": "verified"
}
]
Expand Down
2 changes: 1 addition & 1 deletion api/http/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func (s *Server) getBlock(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusBadRequest)
return
}
c = cid.NewCidV0(hash)
c = cid.NewCidV1(cid.Raw, hash)
}

block, err := s.db.GetBlock(ctx, c)
Expand Down
2 changes: 1 addition & 1 deletion db/fetcher/dag.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func (hf *HeadFetcher) processKV(kv *core.KeyValue) error {
if err != nil {
return err
}
headCid := cid.NewCidV0(hash)
headCid := cid.NewCidV1(cid.Raw, hash)
hf.cid = &headCid
return nil
}
Expand Down
10 changes: 5 additions & 5 deletions db/tests/query/all_commits/simple_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ func TestQueryAllCommitsSingleDAG(t *testing.T) {
},
Results: []map[string]interface{}{
{
"cid": "QmaXdKKsc5GRWXtMytZj4PEf5hFgFxjZaKToQpDY8cAocV",
"cid": "bafkreiercmxn6e3qryxvuped5pplg733c5fj6gjypj5wykk63ouvcfb25m",
"links": []map[string]interface{}{
{
"cid": "QmPaY2DNmd7LtRDpReswc5UTGoU5Q32Py1aEVG7Shq6Np1",
"cid": "bafybeiasnjaz6bohhhqopk77ksivqed5wgbog7575wunleaq57nar6otui",
"name": "Age",
},
{
"cid": "Qmag2zKKGGQwVSss9pQn3hjTu9opdF5mkJXUR9rt2A651h",
"cid": "bafybeifxin4fbdnc4hrn5tyimnzy53jj6oxtu5kpgohzv5y5wsrpjoih6a",
"name": "Name",
},
},
Expand Down Expand Up @@ -78,11 +78,11 @@ func TestQueryAllCommitsMultipleDAG(t *testing.T) {
},
Results: []map[string]interface{}{
{
"cid": "QmQQgYgC3PLFCTwsSgMHHFvFbPEeWDKkbsnvYJwuLP3R8t",
"cid": "bafkreicewiwopwgdrnrdnbh4qnv45yk6vhlmdvdmeri6rue34zpbouyxsq",
"height": int64(2),
},
{
"cid": "QmaXdKKsc5GRWXtMytZj4PEf5hFgFxjZaKToQpDY8cAocV",
"cid": "bafkreiercmxn6e3qryxvuped5pplg733c5fj6gjypj5wykk63ouvcfb25m",
"height": int64(1),
},
},
Expand Down
4 changes: 2 additions & 2 deletions db/tests/query/commit/simple_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func TestQueryOneCommit(t *testing.T) {
test := testUtils.QueryTestCase{
Description: "query for a single block by CID",
Query: `query {
commit(cid: "QmaXdKKsc5GRWXtMytZj4PEf5hFgFxjZaKToQpDY8cAocV") {
commit(cid: "bafkreiercmxn6e3qryxvuped5pplg733c5fj6gjypj5wykk63ouvcfb25m") {
cid
height
delta
Expand All @@ -34,7 +34,7 @@ func TestQueryOneCommit(t *testing.T) {
},
Results: []map[string]interface{}{
{
"cid": "QmaXdKKsc5GRWXtMytZj4PEf5hFgFxjZaKToQpDY8cAocV",
"cid": "bafkreiercmxn6e3qryxvuped5pplg733c5fj6gjypj5wykk63ouvcfb25m",
"height": int64(1),
// cbor encoded delta
"delta": []uint8{0xa2, 0x63, 0x41, 0x67, 0x65, 0x15, 0x64, 0x4e, 0x61, 0x6d, 0x65, 0x64, 0x4a, 0x6f, 0x68, 0x6e},
Expand Down
6 changes: 3 additions & 3 deletions db/tests/query/latest_commits/simple_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ func TestQueryLatestCommits(t *testing.T) {
},
Results: []map[string]interface{}{
{
"cid": "QmaXdKKsc5GRWXtMytZj4PEf5hFgFxjZaKToQpDY8cAocV",
"cid": "bafkreiercmxn6e3qryxvuped5pplg733c5fj6gjypj5wykk63ouvcfb25m",
"links": []map[string]interface{}{
{
"cid": "QmPaY2DNmd7LtRDpReswc5UTGoU5Q32Py1aEVG7Shq6Np1",
"cid": "bafybeiasnjaz6bohhhqopk77ksivqed5wgbog7575wunleaq57nar6otui",
"name": "Age",
},
{
"cid": "Qmag2zKKGGQwVSss9pQn3hjTu9opdF5mkJXUR9rt2A651h",
"cid": "bafybeifxin4fbdnc4hrn5tyimnzy53jj6oxtu5kpgohzv5y5wsrpjoih6a",
"name": "Name",
},
},
Expand Down
6 changes: 3 additions & 3 deletions db/tests/query/simple/with_version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ func TestQuerySimpleWithEmbeddedLatestCommit(t *testing.T) {
"Age": uint64(21),
"_version": []map[string]interface{}{
{
"cid": "QmaXdKKsc5GRWXtMytZj4PEf5hFgFxjZaKToQpDY8cAocV",
"cid": "bafkreiercmxn6e3qryxvuped5pplg733c5fj6gjypj5wykk63ouvcfb25m",
"links": []map[string]interface{}{
{
"cid": "QmPaY2DNmd7LtRDpReswc5UTGoU5Q32Py1aEVG7Shq6Np1",
"cid": "bafybeiasnjaz6bohhhqopk77ksivqed5wgbog7575wunleaq57nar6otui",
"name": "Age",
},
{
"cid": "Qmag2zKKGGQwVSss9pQn3hjTu9opdF5mkJXUR9rt2A651h",
"cid": "bafybeifxin4fbdnc4hrn5tyimnzy53jj6oxtu5kpgohzv5y5wsrpjoih6a",
"name": "Name",
},
},
Expand Down
2 changes: 1 addition & 1 deletion merkle/clock/heads.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func (hh *heads) List(ctx context.Context) ([]cid.Cid, uint64, error) {
if err != nil {
return nil, 0, fmt.Errorf("Failed to get CID from key : %w", err)
}
headCid := cid.NewCidV0(hash)
headCid := cid.NewCidV1(cid.Raw, hash)
height, n := binary.Uvarint(r.Value)
if n <= 0 {
return nil, 0, errors.New("error decocding height")
Expand Down
2 changes: 1 addition & 1 deletion merkle/clock/heads_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (

func newRandomCID() cid.Cid {
pref := cid.Prefix{
Version: 0,
Version: 1,
Codec: cid.Raw,
MhType: mh.SHA2_256,
MhLength: -1, // default length
Expand Down
9 changes: 9 additions & 0 deletions merkle/clock/ipld.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

"github.com/sourcenetwork/defradb/core"

mh "github.com/multiformats/go-multihash"
// pb "github.com/ipfs/go-ds-crdt/pb"
cid "github.com/ipfs/go-cid"
ipld "github.com/ipfs/go-ipld-format"
Expand Down Expand Up @@ -120,6 +121,14 @@ func makeNode(delta core.Delta, heads []cid.Cid) (ipld.Node, error) {
}

nd := dag.NodeWithData(data)
// The cid builder defaults to v0, we want to be using v1 Cids
nd.SetCidBuilder(
cid.V1Builder{
Codec: cid.Raw,
MhType: mh.SHA2_256,
MhLength: -1,
})

// add heads
for _, h := range heads {
if err = nd.AddRawLink("_head", &ipld.Link{Cid: h}); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions query/graphql/parser/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func TestQueryParse_Limit_Offset(t *testing.T) {
func TestQueryParse_Commit_Latest(t *testing.T) {
var query = (`
query {
latestCommits(dockey: "Qm123") {
latestCommits(dockey: "baf123") {
cid
}
}`)
Expand All @@ -128,6 +128,6 @@ func TestQueryParse_Commit_Latest(t *testing.T) {
assert.NoError(t, err)

commit := q.Queries[0].Selections[0].(*CommitSelect)
assert.Equal(t, commit.DocKey, "Qm123")
assert.Equal(t, commit.DocKey, "baf123")
assert.Len(t, commit.Fields, 1)
}
2 changes: 1 addition & 1 deletion store/blockstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func (bs *bstore) AllKeysChan(ctx context.Context) (<-chan cid.Cid, error) {
log.Warningf("error parsing key from binary: %s", err)
continue
}
k := cid.NewCidV0(hash)
k := cid.NewCidV1(cid.Raw, hash)
select {
case <-ctx.Done():
return
Expand Down

0 comments on commit 44e0dd9

Please sign in to comment.