Skip to content

Commit

Permalink
Register custom hasher from plugin code instead of in go-multihash fork
Browse files Browse the repository at this point in the history
 - use hasher from nmt instead of redefining the logic in multihash or here
   (see celestiaorg/nmt#19)
 - remove multihash fork and use updated go-verifcid
 - minor renaming and refactoring
  • Loading branch information
liamsi committed Feb 13, 2021
1 parent fc79d47 commit b8a6eb8
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 53 deletions.
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ require (
github.com/ipfs/go-ipfs-config v0.9.0
github.com/ipfs/interface-go-ipfs-core v0.4.0
github.com/lazyledger/lazyledger-core/p2p/ipld/plugin v0.0.0-00010101000000-000000000000
github.com/lazyledger/nmt v0.1.0
// TODO(ismail): update to tagged version after
// https://github.com/lazyledger/nmt/pull/19 gets merged
github.com/lazyledger/nmt v0.1.1-0.20210212160145-d6f4312f0a8d
github.com/lazyledger/rsmt2d v0.0.0-20201215203123-e5ec7910ddd4
github.com/libp2p/go-buffer-pool v0.0.2
github.com/minio/highwayhash v1.0.1
Expand Down Expand Up @@ -48,5 +50,4 @@ replace (
github.com/ipfs/go-ipfs v0.7.0 => github.com/lazyledger/go-ipfs v0.7.1-0.20210205233505-656642674e11
github.com/ipfs/go-verifcid => github.com/lazyledger/go-verifcid v0.0.2-0.20210205232850-c3e21cfe4064
github.com/lazyledger/lazyledger-core/p2p/ipld/plugin => ./p2p/ipld/plugin
github.com/multiformats/go-multihash => github.com/lazyledger/go-multihash v0.0.15-0.20210205224750-88bad1265973
)
18 changes: 14 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -616,14 +616,12 @@ github.com/lazyledger/go-ipfs v0.7.1-0.20210205233505-656642674e11 h1:4NH5iOp5WQ
github.com/lazyledger/go-ipfs v0.7.1-0.20210205233505-656642674e11/go.mod h1:2Bj1K5NX/KTpCziiP9RNDfgdwHnaytIlr4fCi0ZwJQo=
github.com/lazyledger/go-leopard v0.0.0-20200604113236-298f93361181 h1:mUeCGuCgjZVadW4CzA2dMBq7p2BqaoCfpnKjxMmSaSE=
github.com/lazyledger/go-leopard v0.0.0-20200604113236-298f93361181/go.mod h1:v1o1CRihQ9i7hizx23KK4aR79lxA6VDUIzUCfDva0XQ=
github.com/lazyledger/go-multihash v0.0.15-0.20210205224750-88bad1265973 h1:qERqAEXJ28G9Hhk9GBiGRwXynqZ5hbDqMhyvP5XOJS4=
github.com/lazyledger/go-multihash v0.0.15-0.20210205224750-88bad1265973/go.mod h1:VdAWLKTwram9oKAatUcLxBNUjdtcVwxObEQBtRfuyjc=
github.com/lazyledger/go-verifcid v0.0.2-0.20210205232850-c3e21cfe4064 h1:qFcXjQi5GY8UFQH1li/aGFJ/PIXNADoNek9i57ha3gg=
github.com/lazyledger/go-verifcid v0.0.2-0.20210205232850-c3e21cfe4064/go.mod h1:i0oimuqPNkw9y4DWtt1G+aPznQkyaYPvr9SRXEOZtb0=
github.com/lazyledger/merkletree v0.0.0-20201214195110-6901c4c3c75f h1:jbyPAH6o6hGte4RtZBaqWs2n4Fl6hS7qJGXX3qnjiy4=
github.com/lazyledger/merkletree v0.0.0-20201214195110-6901c4c3c75f/go.mod h1:10PA0NlnYtB8HrtwIDQAyTKWp8TEZ0zBZCGlYC/7+QE=
github.com/lazyledger/nmt v0.1.0 h1:GSpAmBc3B7cwJSYTjh/v+vPQCsNCqKzSklu8LzYxwaU=
github.com/lazyledger/nmt v0.1.0/go.mod h1:tY7ypPX26Sbkt6F8EbPl3AT33B5N0BJe4OVPbq849YI=
github.com/lazyledger/nmt v0.1.1-0.20210212160145-d6f4312f0a8d h1:Q45qTAaYay8r+1kndwjo1EDvpxbqgE7D6xKlaPNeVXk=
github.com/lazyledger/nmt v0.1.1-0.20210212160145-d6f4312f0a8d/go.mod h1:tY7ypPX26Sbkt6F8EbPl3AT33B5N0BJe4OVPbq849YI=
github.com/lazyledger/rsmt2d v0.0.0-20201215203123-e5ec7910ddd4 h1:r2mI8AnDTOSwL9GWGjgHC4rwzaR56jRCo1GLpG2lwIw=
github.com/lazyledger/rsmt2d v0.0.0-20201215203123-e5ec7910ddd4/go.mod h1:ORR2U7THCNr1fpUhwYqZN7QCFJ20iR2uiIWfXKz3KJ4=
github.com/libp2p/go-addr-util v0.0.1/go.mod h1:4ac6O7n9rIAKB1dnd+s8IbbMXkt+oBpzX4/+RACcnlQ=
Expand Down Expand Up @@ -1007,6 +1005,15 @@ github.com/multiformats/go-multibase v0.0.1/go.mod h1:bja2MqRZ3ggyXtZSEDKpl0uO/g
github.com/multiformats/go-multibase v0.0.2/go.mod h1:bja2MqRZ3ggyXtZSEDKpl0uO/gviWFaSteVbWT51qgs=
github.com/multiformats/go-multibase v0.0.3 h1:l/B6bJDQjvQ5G52jw4QGSYeOTZoAwIO77RblWplfIqk=
github.com/multiformats/go-multibase v0.0.3/go.mod h1:5+1R4eQrT3PkYZ24C3W2Ue2tPwIdYQD509ZjSb5y9Oc=
github.com/multiformats/go-multihash v0.0.1/go.mod h1:w/5tugSrLEbWqlcgJabL3oHFKTwfvkofsjW2Qa1ct4U=
github.com/multiformats/go-multihash v0.0.5/go.mod h1:lt/HCbqlQwlPBz7lv0sQCdtfcMtlJvakRUn/0Ual8po=
github.com/multiformats/go-multihash v0.0.7/go.mod h1:XuKXPp8VHcTygube3OWZC+aZrA+H1IhmjoCDtJc7PXM=
github.com/multiformats/go-multihash v0.0.8/go.mod h1:YSLudS+Pi8NHE7o6tb3D8vrpKa63epEDmG8nTduyAew=
github.com/multiformats/go-multihash v0.0.9/go.mod h1:YSLudS+Pi8NHE7o6tb3D8vrpKa63epEDmG8nTduyAew=
github.com/multiformats/go-multihash v0.0.10/go.mod h1:YSLudS+Pi8NHE7o6tb3D8vrpKa63epEDmG8nTduyAew=
github.com/multiformats/go-multihash v0.0.13/go.mod h1:VdAWLKTwram9oKAatUcLxBNUjdtcVwxObEQBtRfuyjc=
github.com/multiformats/go-multihash v0.0.14 h1:QoBceQYQQtNUuf6s7wHxnE2c8bhbMqhfGzNI032se/I=
github.com/multiformats/go-multihash v0.0.14/go.mod h1:VdAWLKTwram9oKAatUcLxBNUjdtcVwxObEQBtRfuyjc=
github.com/multiformats/go-multistream v0.0.1/go.mod h1:fJTiDfXJVmItycydCnNx4+wSzZ5NwG2FEVAI30fiovg=
github.com/multiformats/go-multistream v0.0.4/go.mod h1:fJTiDfXJVmItycydCnNx4+wSzZ5NwG2FEVAI30fiovg=
github.com/multiformats/go-multistream v0.1.0/go.mod h1:fJTiDfXJVmItycydCnNx4+wSzZ5NwG2FEVAI30fiovg=
Expand Down Expand Up @@ -1336,10 +1343,12 @@ golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnf
golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20181030102418-4d3f4d9ffa16/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190211182817-74369b46fc67/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190225124518-7f87c0fbb88b/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190228161510-8dd112bcdc25/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190313024323-a1f597ede03a/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190426145343-a29dc8fdc734/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20190513172903-22d7a77e9e5f/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20190530122614-20be4c3c3ed5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
Expand Down Expand Up @@ -1466,6 +1475,7 @@ golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b/go.mod h1:STP8DvDyc/dI5b8T5h
golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190130150945-aca44879d564/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190219092855-153ac476189d/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190228124157-a34e9553db1e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190302025703-b6889370fb10/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
Expand Down
9 changes: 5 additions & 4 deletions p2p/ipld/plugin/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ require (
github.com/ipfs/go-ipfs v0.7.0
github.com/ipfs/go-ipfs-api v0.2.0
github.com/ipfs/go-ipld-format v0.2.0
github.com/lazyledger/nmt v0.1.0
// TODO(ismail): change this to a tagged version after
// https://github.com/lazyledger/nmt/pull/19 gets merged
github.com/lazyledger/nmt v0.1.1-0.20210212160145-d6f4312f0a8d
// rsmt2d is only used in tests:
github.com/lazyledger/rsmt2d v0.0.0-20201215203123-e5ec7910ddd4
github.com/multiformats/go-multihash v0.0.14
)

replace (
github.com/ipfs/go-ipfs v0.7.0 => github.com/lazyledger/go-ipfs v0.7.1-0.20210205233505-656642674e11
github.com/ipfs/go-verifcid => github.com/lazyledger/go-verifcid v0.0.2-0.20210205232850-c3e21cfe4064
github.com/multiformats/go-multihash => github.com/lazyledger/go-multihash v0.0.15-0.20210205224750-88bad1265973
github.com/ipfs/go-ipfs v0.7.0 => github.com/lazyledger/go-ipfs v0.7.1-0.20210213193504-c65604ccb2ed
github.com/ipfs/go-verifcid => github.com/lazyledger/go-verifcid v0.0.2-0.20210213182512-19890b0d114d
)
26 changes: 18 additions & 8 deletions p2p/ipld/plugin/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -458,18 +458,16 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/pty v1.1.3/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/lazyledger/go-ipfs v0.7.1-0.20210205233505-656642674e11 h1:4NH5iOp5WQKbvH39l5lv3z3McXbdLIEpQc8CC3G8INs=
github.com/lazyledger/go-ipfs v0.7.1-0.20210205233505-656642674e11/go.mod h1:2Bj1K5NX/KTpCziiP9RNDfgdwHnaytIlr4fCi0ZwJQo=
github.com/lazyledger/go-ipfs v0.7.1-0.20210213193504-c65604ccb2ed h1:/0LMtgKop0LGb8/gX8O3rALeYasqSkbotbHNk47Mdyc=
github.com/lazyledger/go-ipfs v0.7.1-0.20210213193504-c65604ccb2ed/go.mod h1:AXxQDfXMEZtkNCWaI+okNaK1D47EGGooDkyeFMcoTiA=
github.com/lazyledger/go-leopard v0.0.0-20200604113236-298f93361181 h1:mUeCGuCgjZVadW4CzA2dMBq7p2BqaoCfpnKjxMmSaSE=
github.com/lazyledger/go-leopard v0.0.0-20200604113236-298f93361181/go.mod h1:v1o1CRihQ9i7hizx23KK4aR79lxA6VDUIzUCfDva0XQ=
github.com/lazyledger/go-multihash v0.0.15-0.20210205224750-88bad1265973 h1:qERqAEXJ28G9Hhk9GBiGRwXynqZ5hbDqMhyvP5XOJS4=
github.com/lazyledger/go-multihash v0.0.15-0.20210205224750-88bad1265973/go.mod h1:VdAWLKTwram9oKAatUcLxBNUjdtcVwxObEQBtRfuyjc=
github.com/lazyledger/go-verifcid v0.0.2-0.20210205232850-c3e21cfe4064 h1:qFcXjQi5GY8UFQH1li/aGFJ/PIXNADoNek9i57ha3gg=
github.com/lazyledger/go-verifcid v0.0.2-0.20210205232850-c3e21cfe4064/go.mod h1:i0oimuqPNkw9y4DWtt1G+aPznQkyaYPvr9SRXEOZtb0=
github.com/lazyledger/go-verifcid v0.0.2-0.20210213182512-19890b0d114d h1:zvUbSnIsdnBIc1fDOKXubVcTKqw64cvaSoIwOAD1wcU=
github.com/lazyledger/go-verifcid v0.0.2-0.20210213182512-19890b0d114d/go.mod h1:kXPYu0XqTNUKWA1h3M95UHjUqBzDwXVVt/RXZDjKJmQ=
github.com/lazyledger/merkletree v0.0.0-20201214195110-6901c4c3c75f h1:jbyPAH6o6hGte4RtZBaqWs2n4Fl6hS7qJGXX3qnjiy4=
github.com/lazyledger/merkletree v0.0.0-20201214195110-6901c4c3c75f/go.mod h1:10PA0NlnYtB8HrtwIDQAyTKWp8TEZ0zBZCGlYC/7+QE=
github.com/lazyledger/nmt v0.1.0 h1:GSpAmBc3B7cwJSYTjh/v+vPQCsNCqKzSklu8LzYxwaU=
github.com/lazyledger/nmt v0.1.0/go.mod h1:tY7ypPX26Sbkt6F8EbPl3AT33B5N0BJe4OVPbq849YI=
github.com/lazyledger/nmt v0.1.1-0.20210212160145-d6f4312f0a8d h1:Q45qTAaYay8r+1kndwjo1EDvpxbqgE7D6xKlaPNeVXk=
github.com/lazyledger/nmt v0.1.1-0.20210212160145-d6f4312f0a8d/go.mod h1:tY7ypPX26Sbkt6F8EbPl3AT33B5N0BJe4OVPbq849YI=
github.com/lazyledger/rsmt2d v0.0.0-20201215203123-e5ec7910ddd4 h1:r2mI8AnDTOSwL9GWGjgHC4rwzaR56jRCo1GLpG2lwIw=
github.com/lazyledger/rsmt2d v0.0.0-20201215203123-e5ec7910ddd4/go.mod h1:ORR2U7THCNr1fpUhwYqZN7QCFJ20iR2uiIWfXKz3KJ4=
github.com/libp2p/go-addr-util v0.0.1/go.mod h1:4ac6O7n9rIAKB1dnd+s8IbbMXkt+oBpzX4/+RACcnlQ=
Expand Down Expand Up @@ -833,6 +831,15 @@ github.com/multiformats/go-multibase v0.0.1/go.mod h1:bja2MqRZ3ggyXtZSEDKpl0uO/g
github.com/multiformats/go-multibase v0.0.2/go.mod h1:bja2MqRZ3ggyXtZSEDKpl0uO/gviWFaSteVbWT51qgs=
github.com/multiformats/go-multibase v0.0.3 h1:l/B6bJDQjvQ5G52jw4QGSYeOTZoAwIO77RblWplfIqk=
github.com/multiformats/go-multibase v0.0.3/go.mod h1:5+1R4eQrT3PkYZ24C3W2Ue2tPwIdYQD509ZjSb5y9Oc=
github.com/multiformats/go-multihash v0.0.1/go.mod h1:w/5tugSrLEbWqlcgJabL3oHFKTwfvkofsjW2Qa1ct4U=
github.com/multiformats/go-multihash v0.0.5/go.mod h1:lt/HCbqlQwlPBz7lv0sQCdtfcMtlJvakRUn/0Ual8po=
github.com/multiformats/go-multihash v0.0.7/go.mod h1:XuKXPp8VHcTygube3OWZC+aZrA+H1IhmjoCDtJc7PXM=
github.com/multiformats/go-multihash v0.0.8/go.mod h1:YSLudS+Pi8NHE7o6tb3D8vrpKa63epEDmG8nTduyAew=
github.com/multiformats/go-multihash v0.0.9/go.mod h1:YSLudS+Pi8NHE7o6tb3D8vrpKa63epEDmG8nTduyAew=
github.com/multiformats/go-multihash v0.0.10/go.mod h1:YSLudS+Pi8NHE7o6tb3D8vrpKa63epEDmG8nTduyAew=
github.com/multiformats/go-multihash v0.0.13/go.mod h1:VdAWLKTwram9oKAatUcLxBNUjdtcVwxObEQBtRfuyjc=
github.com/multiformats/go-multihash v0.0.14 h1:QoBceQYQQtNUuf6s7wHxnE2c8bhbMqhfGzNI032se/I=
github.com/multiformats/go-multihash v0.0.14/go.mod h1:VdAWLKTwram9oKAatUcLxBNUjdtcVwxObEQBtRfuyjc=
github.com/multiformats/go-multistream v0.0.1/go.mod h1:fJTiDfXJVmItycydCnNx4+wSzZ5NwG2FEVAI30fiovg=
github.com/multiformats/go-multistream v0.0.4/go.mod h1:fJTiDfXJVmItycydCnNx4+wSzZ5NwG2FEVAI30fiovg=
github.com/multiformats/go-multistream v0.1.0/go.mod h1:fJTiDfXJVmItycydCnNx4+wSzZ5NwG2FEVAI30fiovg=
Expand Down Expand Up @@ -1047,10 +1054,12 @@ golang.org/x/crypto v0.0.0-20170930174604-9419663f5a44/go.mod h1:6SG95UA2DQfeDnf
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20181030102418-4d3f4d9ffa16/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190211182817-74369b46fc67/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190225124518-7f87c0fbb88b/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190228161510-8dd112bcdc25/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190313024323-a1f597ede03a/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190426145343-a29dc8fdc734/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20190513172903-22d7a77e9e5f/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20190530122614-20be4c3c3ed5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
Expand Down Expand Up @@ -1155,6 +1164,7 @@ golang.org/x/sys v0.0.0-20181029174526-d69651ed3497/go.mod h1:STP8DvDyc/dI5b8T5h
golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190219092855-153ac476189d/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190228124157-a34e9553db1e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190302025703-b6889370fb10/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
Expand Down
86 changes: 67 additions & 19 deletions p2p/ipld/plugin/nodes/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,15 @@ import (
)

const (
// NMT is the codec used for this plugin.
// 0x77 seems to be free:
// Below used multiformats (one codec, one multihash) seem free:
// https://github.com/multiformats/multicodec/blob/master/table.csv
NMT = 0x7700
NamespaceTaggedSha256 = 0x7701

// Nmt is the codec used for leaf and inner nodes of an Namespaced Merkle Tree.
Nmt = 0x7700
// Sha256Namespace8Flagged is the multihash code used to hash blocks
// that contain an NMT node (inner and leaf nodes).
Sha256Namespace8Flagged = 0x7701

// DagParserFormatName can be used when putting into the IPLD Dag
DagParserFormatName = "extended-square-row-or-col"

Expand All @@ -35,12 +39,50 @@ const (
shareSize = 256
)

func init() {
registerNamespacedCodecOrPanic(
Sha256Namespace8Flagged,
"sha2-256-namespace8-flagged",
2*namespaceSize+sha256.Size,
sumSha256Namespace8Flagged,
)
}

func registerNamespacedCodecOrPanic(
codec uint64,
name string,
defaulLength int,
hashFunc mh.HashFunc,
) {
if _, ok := mh.Codes[codec]; !ok {
// add to mh.Codes map first, otherwise mh.RegisterHashFunc would err:
mh.Codes[codec] = name
mh.Names[name] = codec
mh.DefaultLengths[codec] = defaulLength

if err := mh.RegisterHashFunc(codec, hashFunc); err != nil {
panic(fmt.Sprintf("could not register hash function: %v", mh.Codes[codec]))
}
}
}

// sumSha256Namespace8Flagged is the mh.HashFunc used to hash leaf and inner nodes.
// It is registered as a mh.HashFunc in the go-multihash module.
func sumSha256Namespace8Flagged(data []byte, _length int) ([]byte, error) {
isLeafData := data[0] == nmt.LeafPrefix
if isLeafData {
return nmt.Sha256Namespace8FlaggedLeaf(data[1:]), nil
} else {
return nmt.Sha256Namespace8FlaggedInner(data[1:]), nil
}
}

var _ plugin.PluginIPLD = &LazyLedgerPlugin{}

type LazyLedgerPlugin struct{}

func (l LazyLedgerPlugin) RegisterBlockDecoders(dec format.BlockDecoder) error {
dec.Register(NMT, NmtNodeParser)
dec.Register(Nmt, NmtNodeParser)
return nil
}

Expand Down Expand Up @@ -73,10 +115,7 @@ func DataSquareRowOrColumnRawInputParser(r io.Reader, _mhType uint64, _mhLen int
br := bufio.NewReader(r)
nodes := make([]node.Node, 0, extendedSquareSize)
nodeCollector := func(hash []byte, children ...[]byte) {
cid, err := cidFromNamespacedSha256(hash)
if err != nil {
panic(fmt.Sprintf("nmt lib created a malformed hash: %s", err))
}
cid := mustCidFromNamespacedSha256(hash)
switch len(children) {
case 1:
prependNode(nmtLeafNode{
Expand Down Expand Up @@ -240,14 +279,9 @@ func (n nmtNode) Copy() node.Node {
}

func (n nmtNode) Links() []*node.Link {
leftCid, err := cidFromNamespacedSha256(n.l)
if err != nil {
panic(fmt.Errorf("malformed nmtNode, cidFromNamespacedSha256(): %w", err))
}
rightCid, err := cidFromNamespacedSha256(n.r)
if err != nil {
panic(fmt.Errorf("malformed nmtNode, cidFromNamespacedSha256(): %w", err))
}
leftCid := mustCidFromNamespacedSha256(n.l)
rightCid := mustCidFromNamespacedSha256(n.r)

return []*node.Link{{Cid: leftCid}, {Cid: rightCid}}
}

Expand Down Expand Up @@ -338,9 +372,23 @@ func cidFromNamespacedSha256(namespacedHash []byte) (cid.Cid, error) {
if got, want := len(namespacedHash), 2*namespaceSize+sha256.Size; got != want {
return cid.Cid{}, fmt.Errorf("invalid namespaced hash lenght, got: %v, want: %v", got, want)
}
buf, err := mh.Encode(namespacedHash, mh.SHA2_256_NAMESPACE_TAGGED)
buf, err := mh.Encode(namespacedHash, Sha256Namespace8Flagged)
if err != nil {
return cid.Undef, err
}
return cid.NewCidV1(NMT, mh.Multihash(buf)), nil
return cid.NewCidV1(Nmt, mh.Multihash(buf)), nil
}

// mustCidFromNamespacedSha256 is a wrapper around cidFromNamespacedSha256 that panics
// in case of an error. Use with care and only in places where no error should occur.
func mustCidFromNamespacedSha256(hash []byte) cid.Cid {
cid, err := cidFromNamespacedSha256(hash)
if err != nil {
panic(
fmt.Sprintf("malformed hash: %s, codec: %v",
err,
mh.Codes[Sha256Namespace8Flagged]),
)
}
return cid
}
Loading

0 comments on commit b8a6eb8

Please sign in to comment.