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

Simplify serialization #472

Merged
merged 29 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
1aed560
Adjust retainer models to use stream package instead of marshalutil
jonastheis Oct 26, 2023
72c83bf
Adjust utxoledger to use stream package instead marshalutil
jonastheis Oct 27, 2023
d4668c2
Merge remote-tracking branch 'origin/develop' into feat/simplify-seri…
jonastheis Oct 27, 2023
5558829
Replace usage of marshalutil with stream package in network
jonastheis Oct 27, 2023
45e7996
Adjust settings to new stream package
jonastheis Oct 27, 2023
b8ff52b
Adjust to changes of ads.Map and ads.Set
jonastheis Oct 27, 2023
5383f66
Adjust new stream package
jonastheis Oct 27, 2023
bb8d582
Adjust accounts to new stream package and remove marshalutil usage
jonastheis Oct 27, 2023
59e7583
Adjust debug API to changes of ads.Map and ads.Set
jonastheis Oct 27, 2023
6a5e28b
Adjust to renaming changes in https://github.com/iotaledger/hive.go/c…
jonastheis Oct 31, 2023
e242934
Improve serialization of accounts: get rid of PositionedWriter and bi…
jonastheis Oct 31, 2023
a1867df
Merge remote-tracking branch 'origin/develop' into feat/simplify-seri…
jonastheis Oct 31, 2023
cd0292b
Remove PositionedWriter
jonastheis Nov 1, 2023
96763c3
Adjust ValidatorPerformance to use stream package instead of manual b…
jonastheis Nov 1, 2023
0c643cf
Make (de)serialization of BlockIssuerKeys consistent using new method…
jonastheis Nov 2, 2023
3865cc4
Simplify typedKVstore usage
jonastheis Nov 3, 2023
6cdd097
Remove ioutils
jonastheis Nov 3, 2023
d406b7b
Adjust utxo ledger to use stream package instead of ioutils
jonastheis Nov 3, 2023
49a0be6
Remove dependency to github.com/orcaman/writerseeker
jonastheis Nov 6, 2023
7f5bd3d
Adjust utxo ledger to use stream package instead of manual binary.Read
jonastheis Nov 6, 2023
9e59adb
Merge remote-tracking branch 'origin/develop' into feat/simplify-seri…
jonastheis Nov 6, 2023
9cfc673
Update go.mod to latest hive.go
jonastheis Nov 6, 2023
82f433e
Fix bug with wrong serializer.SeriLengthPrefixType
jonastheis Nov 6, 2023
31e1aed
Fix deserialization of attestations in onAttestations
jonastheis Nov 6, 2023
a5a2cd2
Update to latest hive.go
jonastheis Nov 8, 2023
c868f92
Change utxo ledger snapshot diff to uint32
jonastheis Nov 8, 2023
50aba28
Change performance snapshot to uint32 where possible
jonastheis Nov 8, 2023
68a36c7
Change commitments snapshot to uint32
jonastheis Nov 8, 2023
d8aaf2f
Address review comments
jonastheis Nov 8, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion components/debugapi/blocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@ func getSlotBlockIDs(index iotago.SlotIndex) (*BlockChangesResponse, error) {
}

includedBlocks := make([]string, 0)
tangleTree := ads.NewSet[iotago.Identifier](mapdb.NewMapDB(), iotago.BlockID.Bytes, iotago.BlockIDFromBytes)
tangleTree := ads.NewSet[iotago.Identifier](
mapdb.NewMapDB(),
iotago.Identifier.Bytes,
iotago.IdentifierFromBytes,
iotago.BlockID.Bytes,
iotago.BlockIDFromBytes,
)

_ = blocksForSlot.StreamKeys(func(blockID iotago.BlockID) error {
includedBlocks = append(includedBlocks, blockID.String())
Expand Down
8 changes: 7 additions & 1 deletion components/debugapi/transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@ func storeTransactionsPerSlot(scd *notarization.SlotCommittedDetails) error {
if err != nil {
return ierrors.Wrapf(err, "failed to retrieve state diff for slot %d", slot)
}
mutationsTree := ads.NewSet[iotago.Identifier](mapdb.NewMapDB(), iotago.TransactionID.Bytes, iotago.TransactionIDFromBytes)
mutationsTree := ads.NewSet[iotago.Identifier](
mapdb.NewMapDB(),
iotago.Identifier.Bytes,
iotago.IdentifierFromBytes,
iotago.TransactionID.Bytes,
iotago.TransactionIDFromBytes,
)
tcs := &TransactionsChangesResponse{
Index: slot,
IncludedTransactions: make([]string, 0),
Expand Down
31 changes: 15 additions & 16 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,29 @@ require (
github.com/google/uuid v1.4.0
github.com/gorilla/websocket v1.5.0
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0
github.com/iotaledger/hive.go/ads v0.0.0-20231027195901-620bd7470e42
github.com/iotaledger/hive.go/app v0.0.0-20231027195901-620bd7470e42
github.com/iotaledger/hive.go/constraints v0.0.0-20231027195901-620bd7470e42
github.com/iotaledger/hive.go/core v1.0.0-rc.3.0.20231027195901-620bd7470e42
github.com/iotaledger/hive.go/crypto v0.0.0-20231027195901-620bd7470e42
github.com/iotaledger/hive.go/ds v0.0.0-20231027195901-620bd7470e42
github.com/iotaledger/hive.go/ierrors v0.0.0-20231027195901-620bd7470e42
github.com/iotaledger/hive.go/kvstore v0.0.0-20231027195901-620bd7470e42
github.com/iotaledger/hive.go/lo v0.0.0-20231027195901-620bd7470e42
github.com/iotaledger/hive.go/logger v0.0.0-20231027195901-620bd7470e42
github.com/iotaledger/hive.go/runtime v0.0.0-20231027195901-620bd7470e42
github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20231027195901-620bd7470e42
github.com/iotaledger/hive.go/stringify v0.0.0-20231027195901-620bd7470e42
github.com/iotaledger/hive.go/ads v0.0.0-20231106033111-7f3042d04fc4
github.com/iotaledger/hive.go/app v0.0.0-20231106033111-7f3042d04fc4
github.com/iotaledger/hive.go/constraints v0.0.0-20231106033111-7f3042d04fc4
github.com/iotaledger/hive.go/core v1.0.0-rc.3.0.20231106033111-7f3042d04fc4
github.com/iotaledger/hive.go/crypto v0.0.0-20231106033111-7f3042d04fc4
github.com/iotaledger/hive.go/ds v0.0.0-20231106033111-7f3042d04fc4
github.com/iotaledger/hive.go/ierrors v0.0.0-20231106033111-7f3042d04fc4
github.com/iotaledger/hive.go/kvstore v0.0.0-20231106033111-7f3042d04fc4
github.com/iotaledger/hive.go/lo v0.0.0-20231106033111-7f3042d04fc4
github.com/iotaledger/hive.go/logger v0.0.0-20231106033111-7f3042d04fc4
github.com/iotaledger/hive.go/runtime v0.0.0-20231106033111-7f3042d04fc4
github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20231106033111-7f3042d04fc4
github.com/iotaledger/hive.go/stringify v0.0.0-20231106033111-7f3042d04fc4
github.com/iotaledger/inx-app v1.0.0-rc.3.0.20231031135002-4c79ea5193f5
github.com/iotaledger/inx/go v1.0.0-rc.2.0.20231031134131-b6ad918dc1ac
github.com/iotaledger/iota.go/v4 v4.0.0-20231102113728-20b8d01e826e
github.com/iotaledger/iota.go/v4 v4.0.0-20231106063525-564529bf7361
github.com/labstack/echo/v4 v4.11.2
github.com/labstack/gommon v0.4.0
github.com/libp2p/go-libp2p v0.32.0
github.com/libp2p/go-libp2p-kad-dht v0.25.1
github.com/mr-tron/base58 v1.2.0
github.com/multiformats/go-multiaddr v0.12.0
github.com/multiformats/go-varint v0.0.7
github.com/orcaman/writerseeker v0.0.0-20200621085525-1d3f536ff85e
github.com/otiai10/copy v1.14.0
github.com/prometheus/client_golang v1.17.0
github.com/spf13/pflag v1.0.5
Expand Down Expand Up @@ -89,7 +88,7 @@ require (
github.com/huin/goupnp v1.3.0 // indirect
github.com/iancoleman/orderedmap v0.3.0 // indirect
github.com/iotaledger/grocksdb v1.7.5-0.20230220105546-5162e18885c7 // indirect
github.com/iotaledger/hive.go/log v0.0.0-20231027195901-620bd7470e42 // indirect
github.com/iotaledger/hive.go/log v0.0.0-20231106033111-7f3042d04fc4 // indirect
github.com/ipfs/boxo v0.13.1 // indirect
github.com/ipfs/go-cid v0.4.1 // indirect
github.com/ipfs/go-datastore v0.6.0 // indirect
Expand Down
62 changes: 30 additions & 32 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -275,40 +275,40 @@ github.com/iancoleman/orderedmap v0.3.0/go.mod h1:XuLcCUkdL5owUCQeF2Ue9uuw1EptkJ
github.com/ianlancetaylor/demangle v0.0.0-20210905161508-09a460cdf81d/go.mod h1:aYm2/VgdVmcIU8iMfdMvDMsRAQjcfZSKFby6HOFvi/w=
github.com/iotaledger/grocksdb v1.7.5-0.20230220105546-5162e18885c7 h1:dTrD7X2PTNgli6EbS4tV9qu3QAm/kBU3XaYZV2xdzys=
github.com/iotaledger/grocksdb v1.7.5-0.20230220105546-5162e18885c7/go.mod h1:ZRdPu684P0fQ1z8sXz4dj9H5LWHhz4a9oCtvjunkSrw=
github.com/iotaledger/hive.go/ads v0.0.0-20231027195901-620bd7470e42 h1:EOfxTuAiBmED1VHuVh7/UIeB27cCRe13gdSzyioNMBw=
github.com/iotaledger/hive.go/ads v0.0.0-20231027195901-620bd7470e42/go.mod h1:IFh0gDfeMgZtfCo+5afK59IDR4xXh+cTR9YtLnZPcbY=
github.com/iotaledger/hive.go/app v0.0.0-20231027195901-620bd7470e42 h1:xAER9M9Uoz2EOWT43E9wmXRe+RmAk8OBSUoboH4Su8M=
github.com/iotaledger/hive.go/app v0.0.0-20231027195901-620bd7470e42/go.mod h1:8ZbIKR84oQd/3iQ5eeT7xpudO9/ytzXP7veIYnk7Orc=
github.com/iotaledger/hive.go/constraints v0.0.0-20231027195901-620bd7470e42 h1:drmpgLlJy7kZ09Dt1qKSnbILU+27Qu2jp4VdPDNwbFk=
github.com/iotaledger/hive.go/constraints v0.0.0-20231027195901-620bd7470e42/go.mod h1:dOBOM2s4se3HcWefPe8sQLUalGXJ8yVXw58oK8jke3s=
github.com/iotaledger/hive.go/core v1.0.0-rc.3.0.20231027195901-620bd7470e42 h1:BC5GkIHyXdoJGdw6Tu5ds2kjw9grFLtwQiuMaKfdLU8=
github.com/iotaledger/hive.go/core v1.0.0-rc.3.0.20231027195901-620bd7470e42/go.mod h1:Mc+ACqBGPxrPMIPUBOm6/HL0J6m0iVMwjtIEKW3uow8=
github.com/iotaledger/hive.go/crypto v0.0.0-20231027195901-620bd7470e42 h1:r8TkdQJB7/bJd8cF8z5GQ+rX/7JpbPdPoN7wMoV1OCM=
github.com/iotaledger/hive.go/crypto v0.0.0-20231027195901-620bd7470e42/go.mod h1:h3o6okvMSEK3KOX6pOp3yq1h9ohTkTfo6X8MzEadeb0=
github.com/iotaledger/hive.go/ds v0.0.0-20231027195901-620bd7470e42 h1:ytzZZPtclAzLfjxv26frbinCGx3Z6ouUENbx5U7lFGg=
github.com/iotaledger/hive.go/ds v0.0.0-20231027195901-620bd7470e42/go.mod h1:3XkUSKfHaVxGbT0XAvjNlVYqPzhfLTGhDtdNA5UBPco=
github.com/iotaledger/hive.go/ierrors v0.0.0-20231027195901-620bd7470e42 h1:QMxd32Y/veVhTDPCiOFgetjUbG7sr9MryF29/rSPkMA=
github.com/iotaledger/hive.go/ierrors v0.0.0-20231027195901-620bd7470e42/go.mod h1:HcE8B5lP96enc/OALTb2/rIIi+yOLouRoHOKRclKmC8=
github.com/iotaledger/hive.go/kvstore v0.0.0-20231027195901-620bd7470e42 h1:/xPwStUckZ2V0XPoY496cXU+c5elpHyvYoT6JAmuvRY=
github.com/iotaledger/hive.go/kvstore v0.0.0-20231027195901-620bd7470e42/go.mod h1:O/U3jtiUDeqqM0MZQFu2UPqS9fUm0C5hNISxlmg/thE=
github.com/iotaledger/hive.go/lo v0.0.0-20231027195901-620bd7470e42 h1:AvNLzONVMspwx7nD/NyYUgb5Hi7/zgzIOegr1uRD/M8=
github.com/iotaledger/hive.go/lo v0.0.0-20231027195901-620bd7470e42/go.mod h1:s4kzx9QY1MVWHJralj+3q5kI0eARtrJhphYD/iBbPfo=
github.com/iotaledger/hive.go/log v0.0.0-20231027195901-620bd7470e42 h1:e1uJAlXE3zeXpa+c4uFOG+/AMFbUlLt2mcrSK5NMxVs=
github.com/iotaledger/hive.go/log v0.0.0-20231027195901-620bd7470e42/go.mod h1:JvokzmpmFZPDskMlUqqjgHtD8usVJU4nAY/TNMGge8M=
github.com/iotaledger/hive.go/logger v0.0.0-20231027195901-620bd7470e42 h1:7wjs4t1snBDJ8LOTl+tZhr2ORywSOTgJMppxiIAMA0A=
github.com/iotaledger/hive.go/logger v0.0.0-20231027195901-620bd7470e42/go.mod h1:aBfAfIB2GO/IblhYt5ipCbyeL9bXSNeAwtYVA3hZaHg=
github.com/iotaledger/hive.go/runtime v0.0.0-20231027195901-620bd7470e42 h1:1QMJ39qXIx/IZVzus3+97IV7Pa++e+d340TvbMjhiBU=
github.com/iotaledger/hive.go/runtime v0.0.0-20231027195901-620bd7470e42/go.mod h1:jRw8yFipiPaqmTPHh7hTcxAP9u6pjRGpByS3REJKkbY=
github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20231027195901-620bd7470e42 h1:hZli4E9kJUAEQ7gzZR1XbPcpgqvqMPYq8YBPMbrBuos=
github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20231027195901-620bd7470e42/go.mod h1:SdK26z8/VhWtxaqCuQrufm80SELgowQPmu9T/8eUQ8g=
github.com/iotaledger/hive.go/stringify v0.0.0-20231027195901-620bd7470e42 h1:OlDhgvJ48bZxcvTeebJ1b96xtNnJAddejd2Q4rlH1mU=
github.com/iotaledger/hive.go/stringify v0.0.0-20231027195901-620bd7470e42/go.mod h1:FTo/UWzNYgnQ082GI9QVM9HFDERqf9rw9RivNpqrnTs=
github.com/iotaledger/hive.go/ads v0.0.0-20231106033111-7f3042d04fc4 h1:3F60Hx0Oi+4p7V5e+Ap8/aagbk0eSZ8jci4GxGXVLmc=
github.com/iotaledger/hive.go/ads v0.0.0-20231106033111-7f3042d04fc4/go.mod h1:b8w/1e7wk7ZQgTm/2dZPH2pWl7CTlTmgkgaIleaZgFw=
github.com/iotaledger/hive.go/app v0.0.0-20231106033111-7f3042d04fc4 h1:XhqawtbvRagBjd9MTMtzVAnWggXEQF3Mj9cMPhiTXYg=
github.com/iotaledger/hive.go/app v0.0.0-20231106033111-7f3042d04fc4/go.mod h1:iM05Js4OhYlTbQqwxbgMIuWq1TT+lfKntg0PeOE8zkU=
github.com/iotaledger/hive.go/constraints v0.0.0-20231106033111-7f3042d04fc4 h1:GS3d6xi8eiI9rIycajLs4z3vM/u0D9oJ2qEP8f/Mnmw=
github.com/iotaledger/hive.go/constraints v0.0.0-20231106033111-7f3042d04fc4/go.mod h1:dOBOM2s4se3HcWefPe8sQLUalGXJ8yVXw58oK8jke3s=
github.com/iotaledger/hive.go/core v1.0.0-rc.3.0.20231106033111-7f3042d04fc4 h1:xz1Vy5YujaXLL6Kx2gU7eueWGZPquimCGXBLimtCSak=
github.com/iotaledger/hive.go/core v1.0.0-rc.3.0.20231106033111-7f3042d04fc4/go.mod h1:oBpjupsGbCg4WlK9HfXaF5RWtZvA4LmtmuLsMEcz+Qg=
github.com/iotaledger/hive.go/crypto v0.0.0-20231106033111-7f3042d04fc4 h1:3FNxPWFuNEdEJ17PoNS5ILTcg2b7wHDkLZx2lL3PhIE=
github.com/iotaledger/hive.go/crypto v0.0.0-20231106033111-7f3042d04fc4/go.mod h1:ePC73xHcQdkbbHApVoF9XfLfjTtCuYJ8+WJepdRoUIw=
github.com/iotaledger/hive.go/ds v0.0.0-20231106033111-7f3042d04fc4 h1:eVNGVSEX/Z8CyTjUXD/QBSlevFSfu5rwdIJkjPULGeM=
github.com/iotaledger/hive.go/ds v0.0.0-20231106033111-7f3042d04fc4/go.mod h1:RnYZNMRIXKt/SXVsFA18uUBNDZMQm0h5BykMXjv8/8A=
github.com/iotaledger/hive.go/ierrors v0.0.0-20231106033111-7f3042d04fc4 h1:yr8sRMURAjVQhWX+HgDm2AwgY2jH1JrZjOf49aUM8CQ=
github.com/iotaledger/hive.go/ierrors v0.0.0-20231106033111-7f3042d04fc4/go.mod h1:HcE8B5lP96enc/OALTb2/rIIi+yOLouRoHOKRclKmC8=
github.com/iotaledger/hive.go/kvstore v0.0.0-20231106033111-7f3042d04fc4 h1:N21PVtaSvtG9Qq+3hLEj6Cca4Thx7YTa5ezKuqj3V0Y=
github.com/iotaledger/hive.go/kvstore v0.0.0-20231106033111-7f3042d04fc4/go.mod h1:gQWd99xA2Wl4DpCqHIeieNUAKbRJDZo1VNnswAbibyA=
github.com/iotaledger/hive.go/lo v0.0.0-20231106033111-7f3042d04fc4 h1:bK0+pb716B9rBuXDp1+xKh5iX5wp00FF47UjTD+KphM=
github.com/iotaledger/hive.go/lo v0.0.0-20231106033111-7f3042d04fc4/go.mod h1:lFKoK3stQVscy4k6+Cqd3Chq6u65JoTRhfhzJsmKyY8=
github.com/iotaledger/hive.go/log v0.0.0-20231106033111-7f3042d04fc4 h1:VJpxS4LePyDXJT1TRAVExm1ELmEH0t79NB08xEGyR/U=
github.com/iotaledger/hive.go/log v0.0.0-20231106033111-7f3042d04fc4/go.mod h1:61LNutuzo3UnIgC9E8fPCIZ1Xwlb6ApbyTZssMl2cvI=
github.com/iotaledger/hive.go/logger v0.0.0-20231106033111-7f3042d04fc4 h1:jEcVfw96tzB8yjcHBIfc0qUXZvYkn4wu9/bWscgdlNc=
github.com/iotaledger/hive.go/logger v0.0.0-20231106033111-7f3042d04fc4/go.mod h1:LOquQmtaz338r5ftNhYMpjcl0lpO6YtpXyVFbvNOrqs=
github.com/iotaledger/hive.go/runtime v0.0.0-20231106033111-7f3042d04fc4 h1:hOGlfCiQxIumcWMFxxAp13Ox//SQK0DGcXY3NJf7kGQ=
github.com/iotaledger/hive.go/runtime v0.0.0-20231106033111-7f3042d04fc4/go.mod h1:6WKyYAkvdY08iW4/w30goNq0GaBTljT0MXXilnQ33wk=
github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20231106033111-7f3042d04fc4 h1:CRNZkH8TuRIoCHDkfHGA09hpgT2cFFzj1Dys4ze61tI=
github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20231106033111-7f3042d04fc4/go.mod h1:fW/lA6n0C/jf9B9NMX46eJXsJTU8Nzs+9oBWMTNzPzE=
github.com/iotaledger/hive.go/stringify v0.0.0-20231106033111-7f3042d04fc4 h1:xY4tsqeuZq/V8S3vYpuHJT6EdRgMGoFJkyFfxWV0ZPY=
github.com/iotaledger/hive.go/stringify v0.0.0-20231106033111-7f3042d04fc4/go.mod h1:FTo/UWzNYgnQ082GI9QVM9HFDERqf9rw9RivNpqrnTs=
github.com/iotaledger/inx-app v1.0.0-rc.3.0.20231031135002-4c79ea5193f5 h1:17JDzMKTMXKF3xys6gPURRddkZhg1LY+xwfhbr/sVqg=
github.com/iotaledger/inx-app v1.0.0-rc.3.0.20231031135002-4c79ea5193f5/go.mod h1:LsJvoBUVVnY7tkwwByCVtAwmp5bFXdyJNGU/+KVQJVM=
github.com/iotaledger/inx/go v1.0.0-rc.2.0.20231031134131-b6ad918dc1ac h1:c7R33+TQGMYP6pvLUQQaqpdDFl+GZbhAcfGMI0285fo=
github.com/iotaledger/inx/go v1.0.0-rc.2.0.20231031134131-b6ad918dc1ac/go.mod h1:qPuMUvCTaghsnYRDnRoRuztTyEKFlmi2S7gb44rH7WM=
github.com/iotaledger/iota.go/v4 v4.0.0-20231102113728-20b8d01e826e h1:ZYRC1MHn/ghsqtjIpYGTxLQrh5n5eUmC0/YWnJiTRhk=
github.com/iotaledger/iota.go/v4 v4.0.0-20231102113728-20b8d01e826e/go.mod h1:jqbLYq4a/FwuiPBqFfkAwwxU8vs3+kReRq2/tyX5qRA=
github.com/iotaledger/iota.go/v4 v4.0.0-20231106063525-564529bf7361 h1:8uHWvSQpTa8FqakKkKwdppk46PUr/FJjFeupi9csa64=
github.com/iotaledger/iota.go/v4 v4.0.0-20231106063525-564529bf7361/go.mod h1:GXUQi5h4MAtPoBkJ/BRFakVbOiJeU76O0HcXl28mwK8=
github.com/ipfs/boxo v0.13.1 h1:nQ5oQzcMZR3oL41REJDcTbrvDvuZh3J9ckc9+ILeRQI=
github.com/ipfs/boxo v0.13.1/go.mod h1:btrtHy0lmO1ODMECbbEY1pxNtrLilvKSYLoGQt1yYCk=
github.com/ipfs/go-cid v0.4.1 h1:A/T3qGvxi4kpKWWcPC/PgbvDA2bjVLO7n4UeVwnbs/s=
Expand Down Expand Up @@ -507,8 +507,6 @@ github.com/opencontainers/runtime-spec v1.1.0/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/
github.com/opentracing/opentracing-go v1.2.0 h1:uEJPy/1a5RIPAJ0Ov+OIO8OxWu77jEv+1B0VhjKrZUs=
github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc=
github.com/openzipkin/zipkin-go v0.1.1/go.mod h1:NtoC/o8u3JlF1lSlyPNswIbeQH9bJTmOf0Erfk+hxe8=
github.com/orcaman/writerseeker v0.0.0-20200621085525-1d3f536ff85e h1:s2RNOM/IGdY0Y6qfTeUKhDawdHDpK9RGBdx80qN4Ttw=
github.com/orcaman/writerseeker v0.0.0-20200621085525-1d3f536ff85e/go.mod h1:nBdnFKj15wFbf94Rwfq4m30eAcyY9V/IyKAGQFtqkW0=
github.com/otiai10/copy v1.14.0 h1:dCI/t1iTdYGtkvCuBG2BgR6KZa83PTclw4U5n2wAllU=
github.com/otiai10/copy v1.14.0/go.mod h1:ECfuL02W+/FkTWZWgQqXPWZgW9oeKCSQ5qVfSc4qc4w=
github.com/otiai10/mint v1.5.1 h1:XaPLeE+9vGbuyEHem1JNk3bYc7KKqyI/na0/mLd/Kks=
Expand Down
123 changes: 53 additions & 70 deletions pkg/core/account/accounts.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package account

import (
"bytes"
"encoding/binary"
"io"
"sync/atomic"

"github.com/iotaledger/hive.go/core/safemath"
"github.com/iotaledger/hive.go/ds/shrinkingmap"
"github.com/iotaledger/hive.go/ierrors"
"github.com/iotaledger/hive.go/runtime/syncutils"
"github.com/iotaledger/hive.go/serializer/v2/marshalutil"
"github.com/iotaledger/hive.go/serializer/v2"
"github.com/iotaledger/hive.go/serializer/v2/stream"
iotago "github.com/iotaledger/iota.go/v4"
)

Expand All @@ -27,14 +26,9 @@ type Accounts struct {

// NewAccounts creates a new Weights instance.
func NewAccounts() *Accounts {
a := new(Accounts)
a.initialize()

return a
}

func (a *Accounts) initialize() {
a.accountPools = shrinkingmap.New[iotago.AccountID, *Pool]()
return &Accounts{
accountPools: shrinkingmap.New[iotago.AccountID, *Pool](),
}
}

func (a *Accounts) Has(id iotago.AccountID) bool {
Expand Down Expand Up @@ -137,91 +131,80 @@ func (a *Accounts) SelectCommittee(members ...iotago.AccountID) *SeatedAccounts
}

func AccountsFromBytes(b []byte) (*Accounts, int, error) {
return AccountsFromReader(bytes.NewReader(b))
}

func AccountsFromReader(readSeeker io.ReadSeeker) (*Accounts, int, error) {
a := new(Accounts)
n, err := a.readFromReadSeeker(readSeeker)
reader := stream.NewByteReader(b)

return a, n, err
}

func (a *Accounts) readFromReadSeeker(reader io.ReadSeeker) (n int, err error) {
a.mutex.Lock()
defer a.mutex.Unlock()

a.initialize()

var accountCount uint32
if err = binary.Read(reader, binary.LittleEndian, &accountCount); err != nil {
return n, ierrors.Wrap(err, "unable to read accounts count")
a, err := AccountsFromReader(reader)
if err != nil {
return nil, 0, ierrors.Wrap(err, "unable to read accounts from bytes")
}
n += 4

for i := uint32(0); i < accountCount; i++ {
var accountID iotago.AccountID

if _, err = io.ReadFull(reader, accountID[:]); err != nil {
return 0, ierrors.Wrap(err, "unable to read accountID")
}
n += iotago.AccountIDLength
return a, reader.BytesRead(), nil
}

poolBytes := make([]byte, poolBytesLength)
if _, err = io.ReadFull(reader, poolBytes); err != nil {
return 0, ierrors.Wrap(err, "unable to read pool bytes")
}
n += poolBytesLength
func AccountsFromReader(reader io.Reader) (*Accounts, error) {
a := NewAccounts()

pool, c, err := PoolFromBytes(poolBytes)
if err := stream.ReadCollection(reader, serializer.SeriLengthPrefixTypeAsUint32, func(i int) error {
accountID, err := stream.Read[iotago.AccountID](reader)
if err != nil {
return 0, ierrors.Wrap(err, "failed to parse pool")
return ierrors.Wrapf(err, "unable to read accountID at index %d", i)
}

if c != poolBytesLength {
return 0, ierrors.Wrap(err, "invalid pool bytes length")
pool, err := stream.ReadObject(reader, poolBytesLength, PoolFromBytes)
if err != nil {
return ierrors.Wrapf(err, "unable to read pool at index %d", i)
}

if err := a.setWithoutLocking(accountID, pool); err != nil {
return 0, ierrors.Wrapf(err, "failed to set pool for account %s", accountID.String())
return ierrors.Wrapf(err, "failed to set pool for account %s", accountID.String())
}

return nil
}); err != nil {
return nil, ierrors.Wrap(err, "failed to read account data")
}

var reused bool
if err = binary.Read(reader, binary.LittleEndian, &reused); err != nil {
return n, ierrors.Wrap(err, "unable to read reused flag")
reused, err := stream.Read[bool](reader)
if err != nil {
return nil, ierrors.Wrap(err, "failed to read reused flag")
}

a.reused.Store(reused)
n++

return n, nil
return a, nil
}

func (a *Accounts) Bytes() (bytes []byte, err error) {
func (a *Accounts) Bytes() ([]byte, error) {
a.mutex.RLock()
defer a.mutex.RUnlock()

m := marshalutil.New()
byteBuffer := stream.NewByteBuffer()

m.WriteUint32(uint32(a.accountPools.Size()))
var innerErr error
a.ForEach(func(id iotago.AccountID, pool *Pool) bool {
m.WriteBytes(id[:])
poolBytes, err := pool.Bytes()
if err != nil {
innerErr = err
return false
}
m.WriteBytes(poolBytes)
if err := stream.WriteCollection(byteBuffer, serializer.SeriLengthPrefixTypeAsUint32, func() (elementsCount int, err error) {
var innerErr error
a.ForEach(func(id iotago.AccountID, pool *Pool) bool {
if innerErr = stream.Write(byteBuffer, id); innerErr != nil {
return false
}

return true
})
if innerErr = stream.WriteObject(byteBuffer, pool, (*Pool).Bytes); innerErr != nil {
return false
}

m.WriteBool(a.reused.Load())
return true
})
if innerErr != nil {
return 0, innerErr
}

return a.accountPools.Size(), nil
}); err != nil {
return nil, ierrors.Wrap(err, "failed to write accounts")
}

if innerErr != nil {
return nil, innerErr
if err := stream.Write(byteBuffer, a.reused.Load()); err != nil {
return nil, ierrors.Wrap(err, "failed to write reused flag")
}

return m.Bytes(), nil
return byteBuffer.Bytes()
}
2 changes: 1 addition & 1 deletion pkg/core/account/accounts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func TestAccounts(t *testing.T) {
require.Equal(t, accounts, accounts2)

// check "AccountsFromReader"
accounts3, _, err := account.AccountsFromReader(bytes.NewReader(accountBytes))
accounts3, err := account.AccountsFromReader(bytes.NewReader(accountBytes))
require.NoError(t, err)

// check if the new account is the same
Expand Down
Loading
Loading