Skip to content

Commit

Permalink
Merge pull request #372 from iotaledger/feat/serix-merklehasher
Browse files Browse the repository at this point in the history
Use the adapted merklehasher with serix support
  • Loading branch information
piotrm50 authored Sep 27, 2023
2 parents 6f07e17 + 04241e8 commit 26f46d5
Show file tree
Hide file tree
Showing 11 changed files with 19 additions and 23 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ require (
github.com/iotaledger/hive.go/stringify v0.0.0-20230926122307-d671b36a4a65
github.com/iotaledger/inx-app v1.0.0-rc.3.0.20230925153303-c7fbe63a0ab4
github.com/iotaledger/inx/go v1.0.0-rc.2.0.20230925152824-4bfa09b8c132
github.com/iotaledger/iota.go/v4 v4.0.0-20230926171759-340cfc7c2478
github.com/iotaledger/iota.go/v4 v4.0.0-20230927081440-4c25f83b8c40
github.com/labstack/echo/v4 v4.11.1
github.com/labstack/gommon v0.4.0
github.com/libp2p/go-libp2p v0.30.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,8 @@ github.com/iotaledger/inx-app v1.0.0-rc.3.0.20230925153303-c7fbe63a0ab4 h1:pbw/e
github.com/iotaledger/inx-app v1.0.0-rc.3.0.20230925153303-c7fbe63a0ab4/go.mod h1:KbmEuxbhax3fyVrxF4RjBD1/MWLFxHLNDFBnDYUzok4=
github.com/iotaledger/inx/go v1.0.0-rc.2.0.20230925152824-4bfa09b8c132 h1:YHvgNY3/TRx84UxqizkFe7vVUxAMQB2DOuEL8wjHxpg=
github.com/iotaledger/inx/go v1.0.0-rc.2.0.20230925152824-4bfa09b8c132/go.mod h1:DIFr5lt73HLIyn/Lg2jtzfakwhIT0mMZjMFFji3GXeI=
github.com/iotaledger/iota.go/v4 v4.0.0-20230926171759-340cfc7c2478 h1:sAjTMFvLwABCiYSh4JJehpwY5Tz20BgzGtgVbkwpyf4=
github.com/iotaledger/iota.go/v4 v4.0.0-20230926171759-340cfc7c2478/go.mod h1:wR9xBbsofns9hFyRHFZ2bDYIb861qsfmQPVMBKcPvDo=
github.com/iotaledger/iota.go/v4 v4.0.0-20230927081440-4c25f83b8c40 h1:NwmJf+JBVNZX/EUqRbdzIvfY2taGYJVRqvv7jzsuB3Y=
github.com/iotaledger/iota.go/v4 v4.0.0-20230927081440-4c25f83b8c40/go.mod h1:wR9xBbsofns9hFyRHFZ2bDYIb861qsfmQPVMBKcPvDo=
github.com/ipfs/boxo v0.10.0 h1:tdDAxq8jrsbRkYoF+5Rcqyeb91hgWe2hp7iLu7ORZLY=
github.com/ipfs/boxo v0.10.0/go.mod h1:Fg+BnfxZ0RPzR0nOodzdIq3A7KgoWAOWsEIImrIQdBM=
github.com/ipfs/go-cid v0.4.1 h1:A/T3qGvxi4kpKWWcPC/PgbvDA2bjVLO7n4UeVwnbs/s=
Expand Down
7 changes: 3 additions & 4 deletions pkg/network/protocols/core/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package core

import (
"encoding/binary"
"encoding/json"

"github.com/libp2p/go-libp2p/core/peer"
"google.golang.org/protobuf/proto"
Expand Down Expand Up @@ -84,7 +83,7 @@ func (p *Protocol) SendAttestations(cm *model.Commitment, attestations []*iotago
p.network.Send(&nwmodels.Packet{Body: &nwmodels.Packet_Attestations{Attestations: &nwmodels.Attestations{
Commitment: cm.Data(),
Attestations: encodedAttestations.Bytes(),
MerkleProof: lo.PanicOnErr(json.Marshal(merkleProof)),
MerkleProof: lo.PanicOnErr(merkleProof.Bytes()),
}}}, to...)
}

Expand Down Expand Up @@ -227,8 +226,8 @@ func (p *Protocol) onAttestations(commitmentBytes []byte, attestationsBytes []by
return
}

proof := new(merklehasher.Proof[iotago.Identifier])
if err := json.Unmarshal(merkleProof, proof); err != nil {
proof, _, err := merklehasher.ProofFromBytes[iotago.Identifier](merkleProof)
if err != nil {
p.Events.Error.Trigger(ierrors.Wrapf(err, "failed to deserialize merkle proof when receiving attestations for commitment %s", cm.ID()), id)

return
Expand Down
8 changes: 3 additions & 5 deletions pkg/network/protocols/core/warp_sync.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package core

import (
"encoding/json"

"github.com/libp2p/go-libp2p/core/peer"

"github.com/iotaledger/hive.go/ierrors"
Expand All @@ -28,7 +26,7 @@ func (p *Protocol) SendWarpSyncResponse(id iotago.CommitmentID, blockIDs iotago.
WarpSyncResponse: &nwmodels.WarpSyncResponse{
CommitmentId: lo.PanicOnErr(id.Bytes()),
BlockIds: lo.PanicOnErr(serializer.Encode(blockIDs)),
MerkleProof: lo.PanicOnErr(json.Marshal(merkleProof)),
MerkleProof: lo.PanicOnErr(merkleProof.Bytes()),
},
}}, to...)
}
Expand Down Expand Up @@ -62,8 +60,8 @@ func (p *Protocol) handleWarpSyncResponse(commitmentIDBytes []byte, blockIDsByte
return
}

merkleProof := new(merklehasher.Proof[iotago.Identifier])
if err = json.Unmarshal(merkleProofBytes, merkleProof); err != nil {
merkleProof, _, err := merklehasher.ProofFromBytes[iotago.Identifier](merkleProofBytes)
if err != nil {
p.Events.Error.Trigger(ierrors.Wrapf(err, "failed to deserialize merkle proof when receiving waprsync response for commitment %s", commitmentID), id)

return
Expand Down
3 changes: 1 addition & 2 deletions pkg/testsuite/mock/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package mock
import (
"context"
"crypto/ed25519"
"encoding/json"
"fmt"
"sync"
"sync/atomic"
Expand Down Expand Up @@ -172,7 +171,7 @@ func (n *Node) hookLogging(failOnBlockFiltered bool) {
})

events.Network.AttestationsReceived.Hook(func(commitment *model.Commitment, attestations []*iotago.Attestation, merkleProof *merklehasher.Proof[iotago.Identifier], source peer.ID) {
fmt.Printf("%s > Network.AttestationsReceived: from %s %s number of attestations: %d with merkleProof: %s - %s\n", n.Name, source, commitment.ID(), len(attestations), lo.PanicOnErr(json.Marshal(merkleProof)), lo.Map(attestations, func(a *iotago.Attestation) iotago.BlockID {
fmt.Printf("%s > Network.AttestationsReceived: from %s %s number of attestations: %d with merkleProof: %s - %s\n", n.Name, source, commitment.ID(), len(attestations), lo.PanicOnErr(merkleProof.JSONEncode()), lo.Map(attestations, func(a *iotago.Attestation) iotago.BlockID {
return lo.PanicOnErr(a.BlockID())
}))
})
Expand Down
2 changes: 1 addition & 1 deletion tools/evil-spammer/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ require (
github.com/iotaledger/hive.go/runtime v0.0.0-20230926122307-d671b36a4a65
github.com/iotaledger/iota-core v0.0.0-00010101000000-000000000000
github.com/iotaledger/iota-core/tools/genesis-snapshot v0.0.0-00010101000000-000000000000
github.com/iotaledger/iota.go/v4 v4.0.0-20230926171759-340cfc7c2478
github.com/iotaledger/iota.go/v4 v4.0.0-20230927081440-4c25f83b8c40
github.com/mr-tron/base58 v1.2.0
go.uber.org/atomic v1.11.0
)
Expand Down
4 changes: 2 additions & 2 deletions tools/evil-spammer/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,8 @@ github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20230926122307-d671b36
github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20230926122307-d671b36a4a65/go.mod h1:IJgaaxbgKCsNat18jlJJEAxCY2oVYR3F30B+M4vJ89I=
github.com/iotaledger/hive.go/stringify v0.0.0-20230926122307-d671b36a4a65 h1:3OmUR8yYlCENhbosY99eM3bIJQJCiLijtebt+Q6sQEs=
github.com/iotaledger/hive.go/stringify v0.0.0-20230926122307-d671b36a4a65/go.mod h1:FTo/UWzNYgnQ082GI9QVM9HFDERqf9rw9RivNpqrnTs=
github.com/iotaledger/iota.go/v4 v4.0.0-20230926171759-340cfc7c2478 h1:sAjTMFvLwABCiYSh4JJehpwY5Tz20BgzGtgVbkwpyf4=
github.com/iotaledger/iota.go/v4 v4.0.0-20230926171759-340cfc7c2478/go.mod h1:wR9xBbsofns9hFyRHFZ2bDYIb861qsfmQPVMBKcPvDo=
github.com/iotaledger/iota.go/v4 v4.0.0-20230927081440-4c25f83b8c40 h1:NwmJf+JBVNZX/EUqRbdzIvfY2taGYJVRqvv7jzsuB3Y=
github.com/iotaledger/iota.go/v4 v4.0.0-20230927081440-4c25f83b8c40/go.mod h1:wR9xBbsofns9hFyRHFZ2bDYIb861qsfmQPVMBKcPvDo=
github.com/ipfs/go-cid v0.4.1 h1:A/T3qGvxi4kpKWWcPC/PgbvDA2bjVLO7n4UeVwnbs/s=
github.com/ipfs/go-cid v0.4.1/go.mod h1:uQHwDeX4c6CtyrFwdqyhpNcxVewur1M7l7fNU7LKwZk=
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
Expand Down
2 changes: 1 addition & 1 deletion tools/gendoc/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ require (
github.com/iotaledger/hive.go/stringify v0.0.0-20230926122307-d671b36a4a65 // indirect
github.com/iotaledger/inx-app v1.0.0-rc.3.0.20230925153303-c7fbe63a0ab4 // indirect
github.com/iotaledger/inx/go v1.0.0-rc.2.0.20230925152824-4bfa09b8c132 // indirect
github.com/iotaledger/iota.go/v4 v4.0.0-20230926171759-340cfc7c2478 // indirect
github.com/iotaledger/iota.go/v4 v4.0.0-20230927081440-4c25f83b8c40 // indirect
github.com/ipfs/boxo v0.10.0 // indirect
github.com/ipfs/go-cid v0.4.1 // indirect
github.com/ipfs/go-datastore v0.6.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions tools/gendoc/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,8 @@ github.com/iotaledger/inx-app v1.0.0-rc.3.0.20230925153303-c7fbe63a0ab4 h1:pbw/e
github.com/iotaledger/inx-app v1.0.0-rc.3.0.20230925153303-c7fbe63a0ab4/go.mod h1:KbmEuxbhax3fyVrxF4RjBD1/MWLFxHLNDFBnDYUzok4=
github.com/iotaledger/inx/go v1.0.0-rc.2.0.20230925152824-4bfa09b8c132 h1:YHvgNY3/TRx84UxqizkFe7vVUxAMQB2DOuEL8wjHxpg=
github.com/iotaledger/inx/go v1.0.0-rc.2.0.20230925152824-4bfa09b8c132/go.mod h1:DIFr5lt73HLIyn/Lg2jtzfakwhIT0mMZjMFFji3GXeI=
github.com/iotaledger/iota.go/v4 v4.0.0-20230926171759-340cfc7c2478 h1:sAjTMFvLwABCiYSh4JJehpwY5Tz20BgzGtgVbkwpyf4=
github.com/iotaledger/iota.go/v4 v4.0.0-20230926171759-340cfc7c2478/go.mod h1:wR9xBbsofns9hFyRHFZ2bDYIb861qsfmQPVMBKcPvDo=
github.com/iotaledger/iota.go/v4 v4.0.0-20230927081440-4c25f83b8c40 h1:NwmJf+JBVNZX/EUqRbdzIvfY2taGYJVRqvv7jzsuB3Y=
github.com/iotaledger/iota.go/v4 v4.0.0-20230927081440-4c25f83b8c40/go.mod h1:wR9xBbsofns9hFyRHFZ2bDYIb861qsfmQPVMBKcPvDo=
github.com/ipfs/boxo v0.10.0 h1:tdDAxq8jrsbRkYoF+5Rcqyeb91hgWe2hp7iLu7ORZLY=
github.com/ipfs/boxo v0.10.0/go.mod h1:Fg+BnfxZ0RPzR0nOodzdIq3A7KgoWAOWsEIImrIQdBM=
github.com/ipfs/go-cid v0.4.1 h1:A/T3qGvxi4kpKWWcPC/PgbvDA2bjVLO7n4UeVwnbs/s=
Expand Down
2 changes: 1 addition & 1 deletion tools/genesis-snapshot/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/iotaledger/hive.go/lo v0.0.0-20230926122307-d671b36a4a65
github.com/iotaledger/hive.go/runtime v0.0.0-20230926122307-d671b36a4a65
github.com/iotaledger/iota-core v0.0.0-00010101000000-000000000000
github.com/iotaledger/iota.go/v4 v4.0.0-20230926171759-340cfc7c2478
github.com/iotaledger/iota.go/v4 v4.0.0-20230927081440-4c25f83b8c40
github.com/mr-tron/base58 v1.2.0
github.com/spf13/pflag v1.0.5
golang.org/x/crypto v0.13.0
Expand Down
4 changes: 2 additions & 2 deletions tools/genesis-snapshot/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20230926122307-d671b36
github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20230926122307-d671b36a4a65/go.mod h1:IJgaaxbgKCsNat18jlJJEAxCY2oVYR3F30B+M4vJ89I=
github.com/iotaledger/hive.go/stringify v0.0.0-20230926122307-d671b36a4a65 h1:3OmUR8yYlCENhbosY99eM3bIJQJCiLijtebt+Q6sQEs=
github.com/iotaledger/hive.go/stringify v0.0.0-20230926122307-d671b36a4a65/go.mod h1:FTo/UWzNYgnQ082GI9QVM9HFDERqf9rw9RivNpqrnTs=
github.com/iotaledger/iota.go/v4 v4.0.0-20230926171759-340cfc7c2478 h1:sAjTMFvLwABCiYSh4JJehpwY5Tz20BgzGtgVbkwpyf4=
github.com/iotaledger/iota.go/v4 v4.0.0-20230926171759-340cfc7c2478/go.mod h1:wR9xBbsofns9hFyRHFZ2bDYIb861qsfmQPVMBKcPvDo=
github.com/iotaledger/iota.go/v4 v4.0.0-20230927081440-4c25f83b8c40 h1:NwmJf+JBVNZX/EUqRbdzIvfY2taGYJVRqvv7jzsuB3Y=
github.com/iotaledger/iota.go/v4 v4.0.0-20230927081440-4c25f83b8c40/go.mod h1:wR9xBbsofns9hFyRHFZ2bDYIb861qsfmQPVMBKcPvDo=
github.com/ipfs/go-cid v0.4.1 h1:A/T3qGvxi4kpKWWcPC/PgbvDA2bjVLO7n4UeVwnbs/s=
github.com/ipfs/go-cid v0.4.1/go.mod h1:uQHwDeX4c6CtyrFwdqyhpNcxVewur1M7l7fNU7LKwZk=
github.com/klauspost/cpuid/v2 v2.2.5 h1:0E5MSMDEoAulmXNFquVs//DdoomxaoTY1kUhbc/qbZg=
Expand Down

0 comments on commit 26f46d5

Please sign in to comment.