From 04241e89c9d2346a46c238f37107d0efddd06cd7 Mon Sep 17 00:00:00 2001 From: Alexander Sporn Date: Wed, 27 Sep 2023 13:07:59 +0200 Subject: [PATCH] Use the adapted merklehasher with serix support --- go.mod | 2 +- go.sum | 4 ++-- pkg/network/protocols/core/protocol.go | 7 +++---- pkg/network/protocols/core/warp_sync.go | 8 +++----- pkg/testsuite/mock/node.go | 3 +-- tools/evil-spammer/go.mod | 2 +- tools/evil-spammer/go.sum | 4 ++-- tools/gendoc/go.mod | 2 +- tools/gendoc/go.sum | 4 ++-- tools/genesis-snapshot/go.mod | 2 +- tools/genesis-snapshot/go.sum | 4 ++-- 11 files changed, 19 insertions(+), 23 deletions(-) diff --git a/go.mod b/go.mod index d0a2cb1cc..0b81ce6b8 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index 9415582e0..dc5d2bf54 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/pkg/network/protocols/core/protocol.go b/pkg/network/protocols/core/protocol.go index cb98d6d4f..5652c001f 100644 --- a/pkg/network/protocols/core/protocol.go +++ b/pkg/network/protocols/core/protocol.go @@ -2,7 +2,6 @@ package core import ( "encoding/binary" - "encoding/json" "github.com/libp2p/go-libp2p/core/peer" "google.golang.org/protobuf/proto" @@ -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...) } @@ -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 diff --git a/pkg/network/protocols/core/warp_sync.go b/pkg/network/protocols/core/warp_sync.go index b1b617b33..90cc94302 100644 --- a/pkg/network/protocols/core/warp_sync.go +++ b/pkg/network/protocols/core/warp_sync.go @@ -1,8 +1,6 @@ package core import ( - "encoding/json" - "github.com/libp2p/go-libp2p/core/peer" "github.com/iotaledger/hive.go/ierrors" @@ -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...) } @@ -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 diff --git a/pkg/testsuite/mock/node.go b/pkg/testsuite/mock/node.go index 096406949..69d560375 100644 --- a/pkg/testsuite/mock/node.go +++ b/pkg/testsuite/mock/node.go @@ -3,7 +3,6 @@ package mock import ( "context" "crypto/ed25519" - "encoding/json" "fmt" "sync" "sync/atomic" @@ -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()) })) }) diff --git a/tools/evil-spammer/go.mod b/tools/evil-spammer/go.mod index bab246f37..bf95e2459 100644 --- a/tools/evil-spammer/go.mod +++ b/tools/evil-spammer/go.mod @@ -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 ) diff --git a/tools/evil-spammer/go.sum b/tools/evil-spammer/go.sum index b4710506f..1e45bac47 100644 --- a/tools/evil-spammer/go.sum +++ b/tools/evil-spammer/go.sum @@ -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= diff --git a/tools/gendoc/go.mod b/tools/gendoc/go.mod index 59620c7df..8e6677a89 100644 --- a/tools/gendoc/go.mod +++ b/tools/gendoc/go.mod @@ -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 diff --git a/tools/gendoc/go.sum b/tools/gendoc/go.sum index 00dac6753..e8eae9a30 100644 --- a/tools/gendoc/go.sum +++ b/tools/gendoc/go.sum @@ -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= diff --git a/tools/genesis-snapshot/go.mod b/tools/genesis-snapshot/go.mod index eea632b7c..15ccfb9ad 100644 --- a/tools/genesis-snapshot/go.mod +++ b/tools/genesis-snapshot/go.mod @@ -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 diff --git a/tools/genesis-snapshot/go.sum b/tools/genesis-snapshot/go.sum index 4fe32e3fb..96060b9a3 100644 --- a/tools/genesis-snapshot/go.sum +++ b/tools/genesis-snapshot/go.sum @@ -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=