From 466d3ebfb5e1446c94d7edcd9bbe46ee05d850f0 Mon Sep 17 00:00:00 2001 From: vgonkivs Date: Wed, 25 Sep 2024 18:58:56 +0300 Subject: [PATCH 01/21] migrating to go-square v2 --- api/docgen/examples.go | 9 +- api/gateway/availability.go | 4 +- api/gateway/share.go | 23 +- api/gateway/share_test.go | 23 +- blob/blob.go | 111 ++++---- blob/blob_test.go | 23 +- blob/blobtest/testing.go | 29 ++- blob/commitment_proof.go | 9 +- blob/helper.go | 48 +--- blob/helper_test.go | 43 +-- blob/parser.go | 51 ++-- blob/repro_test.go | 2 +- blob/service.go | 51 ++-- blob/service_test.go | 132 +++++----- cmd/cel-key/main.go | 4 +- cmd/cel-shed/shwap.go | 2 +- cmd/start.go | 4 +- cmd/util.go | 7 +- cmd/util_test.go | 22 +- core/eds.go | 19 +- core/eds_test.go | 14 +- core/exchange_test.go | 14 +- core/header_test.go | 6 +- core/listener.go | 2 +- core/listener_no_race_test.go | 4 +- core/listener_test.go | 2 +- core/testing.go | 4 +- das/coordinator.go | 2 +- das/coordinator_test.go | 6 +- das/daser.go | 10 +- das/daser_test.go | 12 +- das/worker.go | 2 +- docs/adr/adr-011-blocksync-overhaul-part-1.md | 2 +- go.mod | 35 +-- go.sum | 68 ++--- header/header.go | 4 +- header/headertest/fraud/testing.go | 6 +- header/headertest/testing.go | 14 +- header/headertest/validate_test.go | 8 +- header/pb/extended_header.pb.go | 2 +- header/pb/extended_header.proto | 4 +- header/serde.go | 2 +- libs/edssser/edssser.go | 10 +- libs/keystore/map_keystore.go | 4 +- nodebuilder/blob/blob.go | 3 +- nodebuilder/blob/cmd/blob.go | 11 +- nodebuilder/blob/mocks/api.go | 2 +- nodebuilder/blob/module.go | 2 +- nodebuilder/core/module.go | 2 +- nodebuilder/da/service.go | 45 +++- nodebuilder/das/constructors.go | 8 +- nodebuilder/fraud/unmarshaler.go | 2 +- nodebuilder/header/constructors.go | 2 +- nodebuilder/init.go | 4 +- nodebuilder/init_test.go | 4 +- nodebuilder/node_test.go | 4 +- nodebuilder/p2p/module.go | 2 +- nodebuilder/p2p/routing.go | 2 +- nodebuilder/share/bitswap.go | 2 +- nodebuilder/share/cmd/share.go | 7 +- nodebuilder/share/config.go | 10 +- nodebuilder/share/constructors.go | 12 +- nodebuilder/share/mocks/api.go | 2 +- nodebuilder/share/module.go | 22 +- nodebuilder/share/opts.go | 10 +- nodebuilder/share/p2p_constructors.go | 6 +- nodebuilder/share/share.go | 18 +- nodebuilder/state/core.go | 2 +- nodebuilder/store.go | 5 +- nodebuilder/tests/api_test.go | 7 +- nodebuilder/tests/blob_test.go | 7 +- nodebuilder/tests/da_test.go | 28 +- nodebuilder/tests/fraud_test.go | 2 +- nodebuilder/tests/nd_test.go | 26 +- nodebuilder/tests/prune_test.go | 21 +- nodebuilder/tests/reconstruct_test.go | 4 +- nodebuilder/tests/swamp/config.go | 2 +- nodebuilder/tests/swamp/swamp.go | 2 +- nodebuilder/tests/swamp/swamp_tx.go | 2 +- pruner/light/pruner.go | 8 +- share/namespace_test.go | 218 ---------------- share/sharetest/testing.go | 87 ------- share/shwap/row_namespace_data_test.go | 99 ------- {share => square}/availability.go | 2 +- .../availability/full/availability.go | 14 +- .../availability/full/availability_test.go | 16 +- .../availability/full/reconstruction_test.go | 10 +- .../availability/full/testing.go | 25 +- .../availability/light/availability.go | 14 +- .../availability/light/availability_test.go | 34 ++- .../availability/light/options.go | 0 .../availability/light/sample.go | 0 .../availability/light/sample_test.go | 0 .../availability/light/testing.go | 12 +- .../availability/mocks/availability.go | 0 .../availability/test/testing.go | 19 +- {share => square}/doc.go | 4 +- {share => square}/eds/accessor.go | 13 +- {share => square}/eds/axis_half.go | 22 +- {share => square}/eds/axis_half_test.go | 4 +- .../eds/byzantine/bad_encoding.go | 16 +- .../eds/byzantine/bad_encoding_test.go | 34 +-- {share => square}/eds/byzantine/byzantine.go | 18 +- .../eds/byzantine/pb/share.pb.go | 58 ++--- .../eds/byzantine/pb/share.proto | 0 .../eds/byzantine/share_proof.go | 42 +-- {share => square}/eds/close_once.go | 9 +- {share => square}/eds/close_once_test.go | 13 +- {share => square}/eds/edstest/testing.go | 84 +++--- {share => square}/eds/nd.go | 8 +- {share => square}/eds/nd_test.go | 7 +- {share => square}/eds/proof.go | 8 +- {share => square}/eds/proofs_cache.go | 23 +- {share => square}/eds/proofs_cache_test.go | 0 {share => square}/eds/read.go | 19 +- {share => square}/eds/retriever.go | 21 +- .../eds/retriever_no_race_test.go | 15 +- {share => square}/eds/retriever_quadrant.go | 6 +- {share => square}/eds/retriever_test.go | 20 +- {share => square}/eds/rsmt2d.go | 55 ++-- {share => square}/eds/rsmt2d_test.go | 18 +- {share => square}/eds/share_reader.go | 0 {share => square}/eds/share_reader_test.go | 7 +- {share => square}/eds/testing.go | 57 ++-- {share => square}/eds/validation.go | 4 +- {share => square}/eds/validation_test.go | 8 +- {share => square}/empty.go | 22 +- {share => square}/ipld/add.go | 11 +- {share => square}/ipld/blockserv.go | 0 {share => square}/ipld/delete.go | 0 {share => square}/ipld/delete_test.go | 6 +- {share => square}/ipld/get.go | 4 +- {share => square}/ipld/get_shares.go | 28 +- {share => square}/ipld/get_shares_test.go | 90 ++++--- {share => square}/ipld/namespace_data.go | 6 +- {share => square}/ipld/nmt.go | 10 +- {share => square}/ipld/nmt_adder.go | 0 {share => square}/ipld/nmt_test.go | 6 +- {share => square}/ipld/proof_collector.go | 0 {share => square}/ipld/proofs.go | 0 {share => square}/ipld/proofs_test.go | 14 +- {share => square}/ipld/test_helpers.go | 0 {share => square}/ipld/utils.go | 8 +- {share => square}/namespace.go | 11 +- {share => square}/root.go | 7 +- square/share.go | 40 +++ {share => square}/shwap/eds.go | 0 {share => square}/shwap/eds_id.go | 0 {share => square}/shwap/eds_id_test.go | 0 {share => square}/shwap/getter.go | 2 +- {share => square}/shwap/getters/cascade.go | 8 +- .../shwap/getters/cascade_test.go | 4 +- .../shwap/getters/mock/getter.go | 8 +- {share => square}/shwap/getters/testing.go | 22 +- {share => square}/shwap/namespace_data.go | 8 +- {share => square}/shwap/namespace_data_id.go | 13 +- .../shwap/namespace_data_id_test.go | 6 +- .../shwap/p2p/bitswap/bitswap.go | 0 {share => square}/shwap/p2p/bitswap/block.go | 6 +- .../shwap/p2p/bitswap/block_fetch.go | 6 +- .../shwap/p2p/bitswap/block_fetch_test.go | 2 +- .../shwap/p2p/bitswap/block_proto.go | 2 +- .../shwap/p2p/bitswap/block_registry.go | 0 .../shwap/p2p/bitswap/block_store.go | 2 +- .../shwap/p2p/bitswap/block_test.go | 6 +- {share => square}/shwap/p2p/bitswap/cid.go | 0 {share => square}/shwap/p2p/bitswap/getter.go | 21 +- .../shwap/p2p/bitswap/getter_test.go | 13 +- .../shwap/p2p/bitswap/pb/bitswap.pb.go | 32 +-- .../shwap/p2p/bitswap/pb/bitswap.proto | 2 +- .../shwap/p2p/bitswap/row_block.go | 18 +- .../shwap/p2p/bitswap/row_block_test.go | 6 +- .../p2p/bitswap/row_namespace_data_block.go | 17 +- .../bitswap/row_namespace_data_block_test.go | 11 +- .../shwap/p2p/bitswap/sample_block.go | 18 +- .../shwap/p2p/bitswap/sample_block_test.go | 6 +- .../shwap/p2p/discovery/backoff.go | 0 .../shwap/p2p/discovery/backoff_test.go | 0 {share => square}/shwap/p2p/discovery/dht.go | 0 .../shwap/p2p/discovery/discovery.go | 0 .../shwap/p2p/discovery/discovery_test.go | 0 .../shwap/p2p/discovery/metrics.go | 0 .../shwap/p2p/discovery/options.go | 0 {share => square}/shwap/p2p/discovery/set.go | 0 .../shwap/p2p/discovery/set_test.go | 0 {share => square}/shwap/p2p/shrex/doc.go | 0 {share => square}/shwap/p2p/shrex/error.go | 0 .../shwap/p2p/shrex/error_test.go | 0 {share => square}/shwap/p2p/shrex/errors.go | 0 {share => square}/shwap/p2p/shrex/metrics.go | 0 .../shwap/p2p/shrex/middleware.go | 0 {share => square}/shwap/p2p/shrex/params.go | 0 .../shwap/p2p/shrex/pb/shrex.pb.go | 38 +-- .../shwap/p2p/shrex/pb/shrex.proto | 2 +- .../shwap/p2p/shrex/peers/doc.go | 0 .../shwap/p2p/shrex/peers/manager.go | 12 +- .../shwap/p2p/shrex/peers/manager_test.go | 16 +- .../shwap/p2p/shrex/peers/metrics.go | 2 +- .../shwap/p2p/shrex/peers/options.go | 2 +- .../shwap/p2p/shrex/peers/pool.go | 0 .../shwap/p2p/shrex/peers/pool_test.go | 0 .../shwap/p2p/shrex/peers/timedqueue.go | 0 .../shwap/p2p/shrex/peers/timedqueue_test.go | 0 {share => square}/shwap/p2p/shrex/recovery.go | 0 .../shwap/p2p/shrex/shrex_getter/shrex.go | 23 +- .../p2p/shrex/shrex_getter/shrex_test.go | 108 ++------ .../shwap/p2p/shrex/shrexeds/client.go | 14 +- .../shwap/p2p/shrex/shrexeds/doc.go | 0 .../shwap/p2p/shrex/shrexeds/exchange_test.go | 18 +- .../shwap/p2p/shrex/shrexeds/params.go | 4 +- .../shwap/p2p/shrex/shrexeds/server.go | 8 +- .../shwap/p2p/shrex/shrexnd/client.go | 10 +- .../shwap/p2p/shrex/shrexnd/doc.go | 0 .../shwap/p2p/shrex/shrexnd/exchange_test.go | 19 +- .../shwap/p2p/shrex/shrexnd/params.go | 4 +- .../shwap/p2p/shrex/shrexnd/server.go | 8 +- .../shwap/p2p/shrex/shrexsub/doc.go | 0 .../p2p/shrex/shrexsub/pb/notification.pb.go | 34 +-- .../p2p/shrex/shrexsub/pb/notification.proto | 0 .../shwap/p2p/shrex/shrexsub/pubsub.go | 6 +- .../shwap/p2p/shrex/shrexsub/pubsub_test.go | 2 +- .../shwap/p2p/shrex/shrexsub/subscription.go | 2 +- {share => square}/shwap/pb/shwap.pb.go | 68 ++--- {share => square}/shwap/pb/shwap.proto | 2 +- {share => square}/shwap/row.go | 33 ++- {share => square}/shwap/row_id.go | 0 {share => square}/shwap/row_id_test.go | 0 {share => square}/shwap/row_namespace_data.go | 48 ++-- .../shwap/row_namespace_data_id.go | 9 +- .../shwap/row_namespace_data_id_test.go | 6 +- square/shwap/row_namespace_data_test.go | 107 ++++++++ {share => square}/shwap/row_test.go | 41 ++- {share => square}/shwap/sample.go | 40 +-- {share => square}/shwap/sample_id.go | 0 {share => square}/shwap/sample_id_test.go | 0 {share => square}/shwap/sample_test.go | 23 +- {share => square}/shwap/share.go | 35 ++- state/core_access.go | 10 +- state/core_access_test.go | 29 ++- state/integration_test.go | 6 +- state/state.go | 4 +- state/tx_config.go | 4 +- store/cache/accessor_cache.go | 2 +- store/cache/accessor_cache_test.go | 11 +- store/cache/cache.go | 2 +- store/cache/doublecache.go | 2 +- store/cache/noop.go | 15 +- store/file/codec_test.go | 8 +- store/file/header.go | 6 +- store/file/ods.go | 54 ++-- store/file/ods_q4.go | 13 +- store/file/ods_q4_test.go | 11 +- store/file/ods_test.go | 17 +- store/file/q4.go | 2 +- store/file/square.go | 32 ++- store/getter.go | 12 +- store/getter_test.go | 13 +- store/store.go | 54 ++-- store/store_cache.go | 2 +- store/store_test.go | 245 +++++++++--------- store/striplock.go | 6 +- 261 files changed, 1974 insertions(+), 2126 deletions(-) delete mode 100644 share/namespace_test.go delete mode 100644 share/sharetest/testing.go delete mode 100644 share/shwap/row_namespace_data_test.go rename {share => square}/availability.go (97%) rename {share => square}/availability/full/availability.go (86%) rename {share => square}/availability/full/availability_test.go (86%) rename {share => square}/availability/full/reconstruction_test.go (96%) rename {share => square}/availability/full/testing.go (62%) rename {share => square}/availability/light/availability.go (91%) rename {share => square}/availability/light/availability_test.go (84%) rename {share => square}/availability/light/options.go (100%) rename {share => square}/availability/light/sample.go (100%) rename {share => square}/availability/light/sample_test.go (100%) rename {share => square}/availability/light/testing.go (89%) rename {share => square}/availability/mocks/availability.go (100%) rename {share => square}/availability/test/testing.go (92%) rename {share => square}/doc.go (88%) rename {share => square}/eds/accessor.go (80%) rename {share => square}/eds/axis_half.go (75%) rename {share => square}/eds/axis_half_test.go (83%) rename {share => square}/eds/byzantine/bad_encoding.go (95%) rename {share => square}/eds/byzantine/bad_encoding_test.go (89%) rename {share => square}/eds/byzantine/byzantine.go (75%) rename {share => square}/eds/byzantine/pb/share.pb.go (87%) rename {share => square}/eds/byzantine/pb/share.proto (100%) rename {share => square}/eds/byzantine/share_proof.go (77%) rename {share => square}/eds/close_once.go (85%) rename {share => square}/eds/close_once_test.go (83%) rename {share => square}/eds/edstest/testing.go (69%) rename {share => square}/eds/nd.go (79%) rename {share => square}/eds/nd_test.go (81%) rename {share => square}/eds/proof.go (92%) rename {share => square}/eds/proofs_cache.go (93%) rename {share => square}/eds/proofs_cache_test.go (100%) rename {share => square}/eds/read.go (80%) rename {share => square}/eds/retriever.go (93%) rename {share => square}/eds/retriever_no_race_test.go (74%) rename {share => square}/eds/retriever_quadrant.go (94%) rename {share => square}/eds/retriever_test.go (92%) rename {share => square}/eds/rsmt2d.go (68%) rename {share => square}/eds/rsmt2d_test.go (78%) rename {share => square}/eds/share_reader.go (100%) rename {share => square}/eds/share_reader_test.go (87%) rename {share => square}/eds/testing.go (89%) rename {share => square}/eds/validation.go (94%) rename {share => square}/eds/validation_test.go (92%) rename {share => square}/empty.go (76%) rename {share => square}/ipld/add.go (90%) rename {share => square}/ipld/blockserv.go (100%) rename {share => square}/ipld/delete.go (100%) rename {share => square}/ipld/delete_test.go (94%) rename {share => square}/ipld/get.go (97%) rename {share => square}/ipld/get_shares.go (79%) rename {share => square}/ipld/get_shares_test.go (85%) rename {share => square}/ipld/namespace_data.go (97%) rename {share => square}/ipld/nmt.go (93%) rename {share => square}/ipld/nmt_adder.go (100%) rename {share => square}/ipld/nmt_test.go (85%) rename {share => square}/ipld/proof_collector.go (100%) rename {share => square}/ipld/proofs.go (100%) rename {share => square}/ipld/proofs_test.go (79%) rename {share => square}/ipld/test_helpers.go (100%) rename {share => square}/ipld/utils.go (51%) rename {share => square}/namespace.go (96%) rename {share => square}/root.go (92%) create mode 100644 square/share.go rename {share => square}/shwap/eds.go (100%) rename {share => square}/shwap/eds_id.go (100%) rename {share => square}/shwap/eds_id_test.go (100%) rename {share => square}/shwap/getter.go (97%) rename {share => square}/shwap/getters/cascade.go (96%) rename {share => square}/shwap/getters/cascade_test.go (97%) rename {share => square}/shwap/getters/mock/getter.go (93%) rename {share => square}/shwap/getters/testing.go (77%) rename {share => square}/shwap/namespace_data.go (89%) rename {share => square}/shwap/namespace_data_id.go (91%) rename {share => square}/shwap/namespace_data_id_test.go (87%) rename {share => square}/shwap/p2p/bitswap/bitswap.go (100%) rename {share => square}/shwap/p2p/bitswap/block.go (89%) rename {share => square}/shwap/p2p/bitswap/block_fetch.go (98%) rename {share => square}/shwap/p2p/bitswap/block_fetch_test.go (98%) rename {share => square}/shwap/p2p/bitswap/block_proto.go (92%) rename {share => square}/shwap/p2p/bitswap/block_registry.go (100%) rename {share => square}/shwap/p2p/bitswap/block_store.go (98%) rename {share => square}/shwap/p2p/bitswap/block_test.go (92%) rename {share => square}/shwap/p2p/bitswap/cid.go (100%) rename {share => square}/shwap/p2p/bitswap/getter.go (92%) rename {share => square}/shwap/p2p/bitswap/getter_test.go (54%) rename {share => square}/shwap/p2p/bitswap/pb/bitswap.pb.go (85%) rename {share => square}/shwap/p2p/bitswap/pb/bitswap.proto (70%) rename {share => square}/shwap/p2p/bitswap/row_block.go (84%) rename {share => square}/shwap/p2p/bitswap/row_block_test.go (82%) rename {share => square}/shwap/p2p/bitswap/row_namespace_data_block.go (86%) rename {share => square}/shwap/p2p/bitswap/row_namespace_data_block_test.go (75%) rename {share => square}/shwap/p2p/bitswap/sample_block.go (84%) rename {share => square}/shwap/p2p/bitswap/sample_block_test.go (85%) rename {share => square}/shwap/p2p/discovery/backoff.go (100%) rename {share => square}/shwap/p2p/discovery/backoff_test.go (100%) rename {share => square}/shwap/p2p/discovery/dht.go (100%) rename {share => square}/shwap/p2p/discovery/discovery.go (100%) rename {share => square}/shwap/p2p/discovery/discovery_test.go (100%) rename {share => square}/shwap/p2p/discovery/metrics.go (100%) rename {share => square}/shwap/p2p/discovery/options.go (100%) rename {share => square}/shwap/p2p/discovery/set.go (100%) rename {share => square}/shwap/p2p/discovery/set_test.go (100%) rename {share => square}/shwap/p2p/shrex/doc.go (100%) rename {share => square}/shwap/p2p/shrex/error.go (100%) rename {share => square}/shwap/p2p/shrex/error_test.go (100%) rename {share => square}/shwap/p2p/shrex/errors.go (100%) rename {share => square}/shwap/p2p/shrex/metrics.go (100%) rename {share => square}/shwap/p2p/shrex/middleware.go (100%) rename {share => square}/shwap/p2p/shrex/params.go (100%) rename {share => square}/shwap/p2p/shrex/pb/shrex.pb.go (81%) rename {share => square}/shwap/p2p/shrex/pb/shrex.proto (69%) rename {share => square}/shwap/p2p/shrex/peers/doc.go (100%) rename {share => square}/shwap/p2p/shrex/peers/manager.go (97%) rename {share => square}/shwap/p2p/shrex/peers/manager_test.go (97%) rename {share => square}/shwap/p2p/shrex/peers/metrics.go (99%) rename {share => square}/shwap/p2p/shrex/peers/options.go (97%) rename {share => square}/shwap/p2p/shrex/peers/pool.go (100%) rename {share => square}/shwap/p2p/shrex/peers/pool_test.go (100%) rename {share => square}/shwap/p2p/shrex/peers/timedqueue.go (100%) rename {share => square}/shwap/p2p/shrex/peers/timedqueue_test.go (100%) rename {share => square}/shwap/p2p/shrex/recovery.go (100%) rename {share => square}/shwap/p2p/shrex/shrex_getter/shrex.go (92%) rename {share => square}/shwap/p2p/shrex/shrex_getter/shrex_test.go (77%) rename {share => square}/shwap/p2p/shrex/shrexeds/client.go (93%) rename {share => square}/shwap/p2p/shrex/shrexeds/doc.go (100%) rename {share => square}/shwap/p2p/shrex/shrexeds/exchange_test.go (90%) rename {share => square}/shwap/p2p/shrex/shrexeds/params.go (90%) rename {share => square}/shwap/p2p/shrex/shrexeds/server.go (95%) rename {share => square}/shwap/p2p/shrex/shrexnd/client.go (94%) rename {share => square}/shwap/p2p/shrex/shrexnd/doc.go (100%) rename {share => square}/shwap/p2p/shrex/shrexnd/exchange_test.go (85%) rename {share => square}/shwap/p2p/shrex/shrexnd/params.go (87%) rename {share => square}/shwap/p2p/shrex/shrexnd/server.go (96%) rename {share => square}/shwap/p2p/shrex/shrexsub/doc.go (100%) rename {share => square}/shwap/p2p/shrex/shrexsub/pb/notification.pb.go (84%) rename {share => square}/shwap/p2p/shrex/shrexsub/pb/notification.proto (100%) rename {share => square}/shwap/p2p/shrex/shrexsub/pubsub.go (96%) rename {share => square}/shwap/p2p/shrex/shrexsub/pubsub_test.go (97%) rename {share => square}/shwap/p2p/shrex/shrexsub/subscription.go (94%) rename {share => square}/shwap/pb/shwap.pb.go (89%) rename {share => square}/shwap/pb/shwap.proto (89%) rename {share => square}/shwap/row.go (84%) rename {share => square}/shwap/row_id.go (100%) rename {share => square}/shwap/row_id_test.go (100%) rename {share => square}/shwap/row_namespace_data.go (84%) rename {share => square}/shwap/row_namespace_data_id.go (94%) rename {share => square}/shwap/row_namespace_data_id_test.go (88%) create mode 100644 square/shwap/row_namespace_data_test.go rename {share => square}/shwap/row_test.go (74%) rename {share => square}/shwap/sample.go (82%) rename {share => square}/shwap/sample_id.go (100%) rename {share => square}/shwap/sample_id_test.go (100%) rename {share => square}/shwap/sample_test.go (83%) rename {share => square}/shwap/share.go (59%) diff --git a/api/docgen/examples.go b/api/docgen/examples.go index 9b12994be9..acb5fdb08a 100644 --- a/api/docgen/examples.go +++ b/api/docgen/examples.go @@ -22,14 +22,15 @@ import ( "github.com/celestiaorg/go-fraud" libhead "github.com/celestiaorg/go-header" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" "github.com/celestiaorg/celestia-node/blob" "github.com/celestiaorg/celestia-node/das" "github.com/celestiaorg/celestia-node/header" "github.com/celestiaorg/celestia-node/nodebuilder/node" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/eds/byzantine" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/eds/byzantine" "github.com/celestiaorg/celestia-node/state" ) @@ -79,7 +80,7 @@ var ExampleValues = map[reflect.Type]interface{}{ } func init() { - addToExampleValues(share.EmptyEDS()) + addToExampleValues(square.EmptyEDS()) addr, err := sdk.AccAddressFromBech32("celestia1377k5an3f94v6wyaceu0cf4nq6gk2jtpc46g7h") if err != nil { panic(err) @@ -165,7 +166,7 @@ func init() { // randomly generated namespace that's used in the blob example above // (AAAAAAAAAAAAAAAAAAAAAAAAAAAAAMJ/xGlNMdE=) - namespace, err := share.NewBlobNamespaceV0([]byte{0xc2, 0x7f, 0xc4, 0x69, 0x4d, 0x31, 0xd1}) + namespace, err := share.NewV0Namespace([]byte{0xc2, 0x7f, 0xc4, 0x69, 0x4d, 0x31, 0xd1}) if err != nil { panic(err) } diff --git a/api/gateway/availability.go b/api/gateway/availability.go index e8e96083d5..f9372018af 100644 --- a/api/gateway/availability.go +++ b/api/gateway/availability.go @@ -8,7 +8,7 @@ import ( "github.com/gorilla/mux" - "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/square" ) const heightAvailabilityEndpoint = "/data_available" @@ -45,7 +45,7 @@ func (h *Handler) handleHeightAvailabilityRequest(w http.ResponseWriter, r *http if werr != nil { log.Errorw("serving request", "endpoint", heightAvailabilityEndpoint, "err", err) } - case errors.Is(err, share.ErrNotAvailable): + case errors.Is(err, square.ErrNotAvailable): resp, err := json.Marshal(&AvailabilityResponse{Available: false}) if err != nil { writeError(w, http.StatusInternalServerError, heightAvailabilityEndpoint, err) diff --git a/api/gateway/share.go b/api/gateway/share.go index cdd40e1d2b..f6b5156ab4 100644 --- a/api/gateway/share.go +++ b/api/gateway/share.go @@ -9,9 +9,7 @@ import ( "github.com/gorilla/mux" - "github.com/celestiaorg/go-square/shares" - - "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/go-square/v2/share" ) const ( @@ -105,11 +103,7 @@ func (h *Handler) getShares(ctx context.Context, height uint64, namespace share. } func dataFromShares(input []share.Share) (data [][]byte, err error) { - appShares, err := shares.FromBytes(input) - if err != nil { - return nil, err - } - sequences, err := shares.ParseShares(appShares, false) + sequences, err := share.ParseShares(input, false) if err != nil { return nil, err } @@ -129,13 +123,18 @@ func parseGetByNamespaceArgs(r *http.Request) (height uint64, namespace share.Na if strHeight, ok := vars[heightKey]; ok { height, err = strconv.ParseUint(strHeight, 10, 64) if err != nil { - return 0, nil, err + return 0, share.Namespace{}, err } } hexNamespace := vars[namespaceKey] - namespace, err = hex.DecodeString(hexNamespace) + nsString, err := hex.DecodeString(hexNamespace) + if err != nil { + return 0, share.Namespace{}, err + } + ns, err := share.NewNamespaceFromBytes(nsString) if err != nil { - return 0, nil, err + return 0, share.Namespace{}, err } - return height, namespace, namespace.ValidateForData() + namespace = ns + return height, namespace, share.ValidateForData(namespace) } diff --git a/api/gateway/share_test.go b/api/gateway/share_test.go index 1928c721ec..b51d043f73 100644 --- a/api/gateway/share_test.go +++ b/api/gateway/share_test.go @@ -6,11 +6,7 @@ import ( "github.com/stretchr/testify/require" - "github.com/celestiaorg/celestia-app/v2/pkg/appconsts" - "github.com/celestiaorg/go-square/blob" - "github.com/celestiaorg/go-square/shares" - - "github.com/celestiaorg/celestia-node/share/sharetest" + "github.com/celestiaorg/go-square/v2/share" ) func Test_dataFromShares(t *testing.T) { @@ -20,17 +16,12 @@ func Test_dataFromShares(t *testing.T) { []byte("BEEEEAHP"), } - ns := sharetest.RandV0Namespace() - sss := shares.NewSparseShareSplitter() + ns := share.RandomNamespace() + sss := share.NewSparseShareSplitter() for _, data := range testData { - b := blob.Blob{ - Data: data, - NamespaceId: ns.ID(), - NamespaceVersion: uint32(ns.Version()), - ShareVersion: uint32(appconsts.ShareVersionZero), - } - err := sss.Write(&b) + b, err := share.NewBlob(ns, data, share.ShareVersionZero, nil) require.NoError(t, err) + require.NoError(t, sss.Write(b)) } sssShares := sss.Export() @@ -41,7 +32,9 @@ func Test_dataFromShares(t *testing.T) { rawSSSShares[i] = d } - parsedSSSShares, err := dataFromShares(rawSSSShares) + shrs, err := share.FromBytes(rawSSSShares) + require.NoError(t, err) + parsedSSSShares, err := dataFromShares(shrs) require.NoError(t, err) require.Equal(t, testData, parsedSSSShares) diff --git a/blob/blob.go b/blob/blob.go index 3b26e5f198..6f4029c0b4 100644 --- a/blob/blob.go +++ b/blob/blob.go @@ -6,23 +6,21 @@ import ( "errors" "fmt" - "github.com/tendermint/tendermint/crypto/merkle" - - "github.com/celestiaorg/celestia-app/v2/pkg/appconsts" - v2 "github.com/celestiaorg/celestia-app/v2/pkg/appconsts/v2" - "github.com/celestiaorg/go-square/blob" - "github.com/celestiaorg/go-square/inclusion" - "github.com/celestiaorg/go-square/shares" + "github.com/celestiaorg/celestia-app/v3/pkg/appconsts" + app "github.com/celestiaorg/celestia-app/v3/pkg/appconsts/v2" + "github.com/celestiaorg/go-square/merkle" + "github.com/celestiaorg/go-square/v2/inclusion" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt" - - "github.com/celestiaorg/celestia-node/share" ) // appVersion is the current application version of celestia-app. -const appVersion = v2.Version +const appVersion = app.Version var errEmptyShares = errors.New("empty shares") +var subtreeRootThreshold = appconsts.SubtreeRootThreshold(appVersion) + // The Proof is a set of nmt proofs that can be verified only through // the included method (due to limitation of the nmt https://github.com/celestiaorg/nmt/issues/218). // Proof proves the WHOLE namespaced data to the row roots. @@ -61,14 +59,10 @@ func (p Proof) equal(input Proof) error { // Blob represents any application-specific binary data that anyone can submit to Celestia. type Blob struct { - *blob.Blob `json:"blob"` + *share.Blob `json:"blob"` Commitment Commitment `json:"commitment"` - // the celestia-node's namespace type - // this is to avoid converting to and from app's type - namespace share.Namespace - // index represents the index of the blob's first share in the EDS. // Only retrieved, on-chain blobs will have the index set. Default is -1. index int @@ -77,35 +71,43 @@ type Blob struct { // NewBlobV0 constructs a new blob from the provided Namespace and data. // The blob will be formatted as v0 shares. func NewBlobV0(namespace share.Namespace, data []byte) (*Blob, error) { - return NewBlob(appconsts.ShareVersionZero, namespace, data) + return NewBlob(share.ShareVersionZero, namespace, data, nil) +} + +// NewBlobV1 constructs a new blob from the provided Namespace and data. +// The blob will be formatted as v0 shares. +func NewBlobV1(namespace share.Namespace, data, signer []byte) (*Blob, error) { + return NewBlob(share.ShareVersionOne, namespace, data, signer) } // NewBlob constructs a new blob from the provided Namespace, data and share version. -func NewBlob(shareVersion uint8, namespace share.Namespace, data []byte) (*Blob, error) { +func NewBlob(shareVersion uint8, namespace share.Namespace, data, signer []byte) (*Blob, error) { if len(data) == 0 || len(data) > appconsts.DefaultMaxBytes { return nil, fmt.Errorf("blob data must be > 0 && <= %d, but it was %d bytes", appconsts.DefaultMaxBytes, len(data)) } - if err := namespace.ValidateForBlob(); err != nil { - return nil, err + + if err := share.ValidateUserNamespace(namespace.Version(), namespace.ID()); err != nil { + return nil, fmt.Errorf("invalid user namespace: %w", err) + } + if !namespace.IsUsableNamespace() { + return nil, fmt.Errorf("namespace %s is not usable", namespace.ID()) // rename } - blob := blob.Blob{ - NamespaceId: namespace.ID(), - Data: data, - ShareVersion: uint32(shareVersion), - NamespaceVersion: uint32(namespace.Version()), + squareBlob, err := share.NewBlob(namespace, data, shareVersion, signer) + if err != nil { + return nil, err } - com, err := inclusion.CreateCommitment(&blob, merkle.HashFromByteSlices, appconsts.SubtreeRootThreshold(appVersion)) + com, err := inclusion.CreateCommitment(squareBlob, merkle.HashFromByteSlices, subtreeRootThreshold) if err != nil { return nil, err } - return &Blob{Blob: &blob, Commitment: com, namespace: namespace, index: -1}, nil + return &Blob{Blob: squareBlob, Commitment: com, index: -1}, nil } // Namespace returns blob's namespace. func (b *Blob) Namespace() share.Namespace { - return b.namespace + return b.Blob.Namespace() } // Index returns the blob's first share index in the EDS. @@ -124,18 +126,12 @@ func (b *Blob) Length() (int, error) { if len(s) == 0 { return 0, errors.New("blob with zero shares received") } + return share.SparseSharesNeeded(s[0].SequenceLen()), nil +} - appShare, err := shares.NewShare(s[0]) - if err != nil { - return 0, err - } - - seqLength, err := appShare.SequenceLen() - if err != nil { - return 0, err - } - - return shares.SparseSharesNeeded(seqLength), nil +// Signer returns blob's author. +func (b *Blob) Signer() []byte { + return b.Blob.Signer() } func (b *Blob) compareCommitments(com Commitment) bool { @@ -143,19 +139,21 @@ func (b *Blob) compareCommitments(com Commitment) bool { } type jsonBlob struct { - Namespace share.Namespace `json:"namespace"` - Data []byte `json:"data"` - ShareVersion uint32 `json:"share_version"` - Commitment Commitment `json:"commitment"` - Index int `json:"index"` + Namespace []byte `json:"namespace"` + Data []byte `json:"data"` + ShareVersion uint32 `json:"share_version"` + Commitment Commitment `json:"commitment"` + Signer []byte `json:"signer,omitempty"` + Index int `json:"index"` } func (b *Blob) MarshalJSON() ([]byte, error) { blob := &jsonBlob{ - Namespace: b.Namespace(), - Data: b.Data, - ShareVersion: b.ShareVersion, + Namespace: b.Namespace().Bytes(), + Data: b.Data(), + ShareVersion: uint32(b.ShareVersion()), Commitment: b.Commitment, + Signer: b.Signer(), Index: b.index, } return json.Marshal(blob) @@ -168,17 +166,18 @@ func (b *Blob) UnmarshalJSON(data []byte) error { return err } - if len(jsonBlob.Namespace) == 0 { - return errors.New("expected a non-empty namespace") + ns, err := share.NewNamespaceFromBytes(jsonBlob.Namespace) + if err != nil { + return err + } + + blob, err := NewBlob(uint8(jsonBlob.ShareVersion), ns, jsonBlob.Data, jsonBlob.Signer) + if err != nil { + return err } - b.Blob = &blob.Blob{} - b.Blob.NamespaceVersion = uint32(jsonBlob.Namespace.Version()) - b.Blob.NamespaceId = jsonBlob.Namespace.ID() - b.Blob.Data = jsonBlob.Data - b.Blob.ShareVersion = jsonBlob.ShareVersion - b.Commitment = jsonBlob.Commitment - b.namespace = jsonBlob.Namespace - b.index = jsonBlob.Index + blob.Commitment = jsonBlob.Commitment + blob.index = jsonBlob.Index + *b = *blob return nil } diff --git a/blob/blob_test.go b/blob/blob_test.go index d747090758..20871706d5 100644 --- a/blob/blob_test.go +++ b/blob/blob_test.go @@ -7,11 +7,9 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/celestiaorg/celestia-app/v2/pkg/appconsts" - apptypes "github.com/celestiaorg/celestia-app/v2/x/blob/types" - "github.com/celestiaorg/go-square/blob" - "github.com/celestiaorg/go-square/inclusion" "github.com/celestiaorg/go-square/merkle" + "github.com/celestiaorg/go-square/v2/inclusion" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/celestia-node/blob/blobtest" ) @@ -42,7 +40,7 @@ func TestBlob(t *testing.T) { comm, err := inclusion.CreateCommitment( blob[0].Blob, merkle.HashFromByteSlices, - appconsts.SubtreeRootThreshold(appVersion), + subtreeRootThreshold, ) require.NoError(t, err) assert.Equal(t, blob[0].Commitment, Commitment(comm)) @@ -51,9 +49,8 @@ func TestBlob(t *testing.T) { { name: "verify namespace", expectedRes: func(t *testing.T) { - ns := blob[0].Namespace().ToAppNamespace() - require.NoError(t, err) - require.NoError(t, apptypes.ValidateBlobNamespace(ns)) + ns := blob[0].Namespace() + require.NoError(t, share.ValidateUserNamespace(ns.Version(), ns.ID())) }, }, { @@ -67,9 +64,7 @@ func TestBlob(t *testing.T) { { name: "shares to blobs", expectedRes: func(t *testing.T) { - sh, err := BlobsToShares(blob...) - require.NoError(t, err) - shares, err := toAppShares(sh...) + shares, err := BlobsToShares(blob...) require.NoError(t, err) p := &parser{length: len(shares), shares: shares} b, err := p.parse() @@ -85,7 +80,7 @@ func TestBlob(t *testing.T) { newBlob := &Blob{} require.NoError(t, newBlob.UnmarshalJSON(data)) - require.True(t, bytes.Equal(blob[0].Blob.GetData(), newBlob.Data)) + require.True(t, bytes.Equal(blob[0].Blob.Data(), newBlob.Data())) require.True(t, bytes.Equal(blob[0].Commitment, newBlob.Commitment)) }, }, @@ -96,10 +91,10 @@ func TestBlob(t *testing.T) { } } -func convertBlobs(appBlobs ...*blob.Blob) ([]*Blob, error) { +func convertBlobs(appBlobs ...*share.Blob) ([]*Blob, error) { blobs := make([]*Blob, 0, len(appBlobs)) for _, appBlob := range appBlobs { - blob, err := NewBlob(uint8(appBlob.GetShareVersion()), appBlob.Namespace().Bytes(), appBlob.GetData()) + blob, err := NewBlob(appBlob.ShareVersion(), appBlob.Namespace(), appBlob.Data(), appBlob.Signer()) if err != nil { return nil, err } diff --git a/blob/blobtest/testing.go b/blob/blobtest/testing.go index eb85bead27..e509e36af3 100644 --- a/blob/blobtest/testing.go +++ b/blob/blobtest/testing.go @@ -1,31 +1,34 @@ package blobtest import ( + "fmt" + tmrand "github.com/tendermint/tendermint/libs/rand" - "github.com/celestiaorg/celestia-app/v2/pkg/appconsts" - "github.com/celestiaorg/celestia-app/v2/test/util/testfactory" - "github.com/celestiaorg/go-square/blob" + "github.com/celestiaorg/celestia-app/v3/test/util/testfactory" "github.com/celestiaorg/go-square/shares" - - "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/go-square/v2/share" ) // GenerateV0Blobs is a test utility producing v0 share formatted blobs with the // requested size and random namespaces. -func GenerateV0Blobs(sizes []int, sameNamespace bool) ([]*blob.Blob, error) { - blobs := make([]*blob.Blob, 0, len(sizes)) - +func GenerateV0Blobs(sizes []int, sameNamespace bool) ([]*share.Blob, error) { + blobs := make([]*share.Blob, 0, len(sizes)) for _, size := range sizes { - size := rawBlobSize(appconsts.FirstSparseShareContentSize * size) + size := RawBlobSize(share.FirstSparseShareContentSize * size) appBlob := testfactory.GenerateRandomBlob(size) if !sameNamespace { - namespace, err := share.NewBlobNamespaceV0(tmrand.Bytes(7)) + namespace, err := share.NewV0Namespace(tmrand.Bytes(7)) + if err != nil { + return nil, err + } + if namespace.IsReserved() { + return nil, fmt.Errorf("reserved namespace") + } + appBlob, err = share.NewV0Blob(namespace, appBlob.Data()) if err != nil { return nil, err } - appBlob.NamespaceVersion = uint32(namespace[0]) - appBlob.NamespaceId = namespace[1:] } blobs = append(blobs, appBlob) @@ -33,6 +36,6 @@ func GenerateV0Blobs(sizes []int, sameNamespace bool) ([]*blob.Blob, error) { return blobs, nil } -func rawBlobSize(totalSize int) int { +func RawBlobSize(totalSize int) int { return totalSize - shares.DelimLen(uint64(totalSize)) } diff --git a/blob/commitment_proof.go b/blob/commitment_proof.go index 82fed368dc..d59614a693 100644 --- a/blob/commitment_proof.go +++ b/blob/commitment_proof.go @@ -5,13 +5,12 @@ import ( "errors" "fmt" - "github.com/celestiaorg/celestia-app/v2/pkg/appconsts" - "github.com/celestiaorg/celestia-app/v2/pkg/proof" - "github.com/celestiaorg/go-square/inclusion" + "github.com/celestiaorg/celestia-app/v3/pkg/appconsts" + "github.com/celestiaorg/celestia-app/v3/pkg/proof" + "github.com/celestiaorg/go-square/v2/inclusion" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt" "github.com/celestiaorg/nmt/namespace" - - "github.com/celestiaorg/celestia-node/share" ) // Commitment is a Merkle Root of the subtree built from shares of the Blob. diff --git a/blob/helper.go b/blob/helper.go index 17f0068c9e..3b81fce5be 100644 --- a/blob/helper.go +++ b/blob/helper.go @@ -1,60 +1,38 @@ package blob import ( + "fmt" "sort" - squareblob "github.com/celestiaorg/go-square/blob" - "github.com/celestiaorg/go-square/shares" - - "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/go-square/v2/share" ) // BlobsToShares accepts blobs and convert them to the Shares. func BlobsToShares(nodeBlobs ...*Blob) ([]share.Share, error) { - b := make([]*squareblob.Blob, len(nodeBlobs)) + sort.Slice(nodeBlobs, func(i, j int) bool { + return nodeBlobs[i].Blob.Namespace().Compare(nodeBlobs[j].Blob.Namespace()) < 0 + }) + + splitter := share.NewSparseShareSplitter() for i, nodeBlob := range nodeBlobs { - namespace := nodeBlob.Namespace() - b[i] = &squareblob.Blob{ - NamespaceVersion: uint32(namespace[0]), - NamespaceId: namespace[1:], - Data: nodeBlob.Data, - ShareVersion: nodeBlob.ShareVersion, + err := splitter.Write(nodeBlob.Blob) + if err != nil { + return nil, fmt.Errorf("failed to split blob at index: %d: %w", i, err) } - } - - sort.Slice(b, func(i, j int) bool { - return b[i].Namespace().Compare(b[j].Namespace()) < 0 - }) - rawShares, err := shares.SplitBlobs(b...) - if err != nil { - return nil, err } - return shares.ToBytes(rawShares), nil + return splitter.Export(), nil } // ToAppBlobs converts node's blob type to the blob type from go-square. -func ToAppBlobs(blobs ...*Blob) []*squareblob.Blob { - appBlobs := make([]*squareblob.Blob, len(blobs)) +func ToAppBlobs(blobs ...*Blob) []*share.Blob { + appBlobs := make([]*share.Blob, len(blobs)) for i := range blobs { appBlobs[i] = blobs[i].Blob } return appBlobs } -// toAppShares converts node's raw shares to the app shares, skipping padding -func toAppShares(shrs ...share.Share) ([]shares.Share, error) { - appShrs := make([]shares.Share, 0, len(shrs)) - for _, shr := range shrs { - bShare, err := shares.NewShare(shr) - if err != nil { - return nil, err - } - appShrs = append(appShrs, *bShare) - } - return appShrs, nil -} - func calculateIndex(rowLength, blobIndex int) (row, col int) { row = blobIndex / rowLength col = blobIndex - (row * rowLength) diff --git a/blob/helper_test.go b/blob/helper_test.go index 39f0ba7c3f..f4ac403b97 100644 --- a/blob/helper_test.go +++ b/blob/helper_test.go @@ -7,52 +7,37 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/celestiaorg/celestia-app/v2/pkg/appconsts" - squareblob "github.com/celestiaorg/go-square/blob" - "github.com/celestiaorg/go-square/namespace" + "github.com/celestiaorg/go-square/v2/share" ) func TestBlobsToShares(t *testing.T) { t.Run("should sort blobs by namespace in ascending order", func(t *testing.T) { - namespaceA := namespace.MustNewV0(bytes.Repeat([]byte{0xa}, 10)).Bytes() - namespaceB := namespace.MustNewV0(bytes.Repeat([]byte{0xb}, 10)).Bytes() + namespaceA := share.MustNewV0Namespace(bytes.Repeat([]byte{0xa}, 10)) + namespaceB := share.MustNewV0Namespace(bytes.Repeat([]byte{0xb}, 10)) - blobA, err := NewBlob(appconsts.ShareVersionZero, namespaceA, []byte("dataA")) + blobA, err := NewBlob(share.ShareVersionZero, namespaceA, []byte("dataA"), nil) require.NoError(t, err) - blobB, err := NewBlob(appconsts.ShareVersionZero, namespaceB, []byte("dataB")) + blobB, err := NewBlob(share.ShareVersionZero, namespaceB, []byte("dataB"), nil) require.NoError(t, err) got, err := BlobsToShares(blobB, blobA) require.NoError(t, err) - assert.Equal(t, got[0][:appconsts.NamespaceSize], namespaceA) - assert.Equal(t, got[1][:appconsts.NamespaceSize], namespaceB) - assert.IsIncreasing(t, got) + assert.Equal(t, got[0].Namespace(), namespaceA) + assert.Equal(t, got[1].Namespace(), namespaceB) + assert.True(t, got[0].Namespace().IsLessThan(got[1].Namespace())) }) } func TestToAppBlobs(t *testing.T) { - namespaceA := namespace.MustNewV0(bytes.Repeat([]byte{0xa}, 10)) - namespaceB := namespace.MustNewV0(bytes.Repeat([]byte{0xb}, 10)) + namespaceA := share.MustNewV0Namespace(bytes.Repeat([]byte{0xa}, 10)) + namespaceB := share.MustNewV0Namespace(bytes.Repeat([]byte{0xb}, 10)) - blobA, err := NewBlob(appconsts.ShareVersionZero, namespaceA.Bytes(), []byte("dataA")) + blobA, err := NewBlob(share.ShareVersionZero, namespaceA, []byte("dataA"), nil) require.NoError(t, err) - blobB, err := NewBlob(appconsts.ShareVersionZero, namespaceB.Bytes(), []byte("dataB")) + blobB, err := NewBlob(share.ShareVersionZero, namespaceB, []byte("dataB"), nil) require.NoError(t, err) got := ToAppBlobs(blobA, blobB) - want := []*squareblob.Blob{ - { - NamespaceId: blobA.NamespaceId, - NamespaceVersion: blobA.NamespaceVersion, - Data: blobA.Data, - ShareVersion: blobA.ShareVersion, - }, - { - NamespaceId: blobB.NamespaceId, - NamespaceVersion: blobB.NamespaceVersion, - Data: blobB.Data, - ShareVersion: blobB.ShareVersion, - }, - } - assert.Equal(t, want, got) + + assert.Equal(t, []*share.Blob{blobA.Blob, blobB.Blob}, got) } diff --git a/blob/parser.go b/blob/parser.go index 0033d29ebf..d693b3a8c3 100644 --- a/blob/parser.go +++ b/blob/parser.go @@ -4,7 +4,9 @@ import ( "errors" "fmt" - "github.com/celestiaorg/go-square/shares" + "github.com/celestiaorg/go-square/merkle" + "github.com/celestiaorg/go-square/v2/inclusion" + "github.com/celestiaorg/go-square/v2/share" ) // parser helps to collect shares and transform them into a blob. @@ -15,13 +17,13 @@ type parser struct { // length is an amount of the shares needed to build the blob. length int // shares is a set of shares to build the blob. - shares []shares.Share + shares []share.Share verifyFn func(blob *Blob) bool } // set tries to find the first blob's share by skipping padding shares and // sets the metadata of the blob(index and length) -func (p *parser) set(index int, shrs []shares.Share) ([]shares.Share, error) { +func (p *parser) set(index int, shrs []share.Share) ([]share.Share, error) { if len(shrs) == 0 { return nil, errEmptyShares } @@ -37,19 +39,15 @@ func (p *parser) set(index int, shrs []shares.Share) ([]shares.Share, error) { // `+=` as index could be updated in `skipPadding` p.index += index - length, err := shrs[0].SequenceLen() - if err != nil { - return nil, err - } - - p.length = shares.SparseSharesNeeded(length) + length := shrs[0].SequenceLen() + p.length = share.SparseSharesNeeded(length) return shrs, nil } // addShares sets shares until the blob is completed and extra remaining shares back. // It assumes that the remaining shares required for blob completeness are correct and // do not include padding shares. -func (p *parser) addShares(shares []shares.Share) (shrs []shares.Share, isComplete bool) { +func (p *parser) addShares(shares []share.Share) (shrs []share.Share, isComplete bool) { index := -1 for i, sh := range shares { p.shares = append(p.shares, sh) @@ -77,54 +75,37 @@ func (p *parser) parse() (*Blob, error) { return nil, fmt.Errorf("invalid shares amount. want:%d, have:%d", p.length, len(p.shares)) } - sequence, err := shares.ParseShares(p.shares, true) + blobs, err := share.ParseBlobs(p.shares) if err != nil { return nil, err } - // ensure that sequence length is not 0 - if len(sequence) == 0 { + if len(blobs) == 0 { return nil, ErrBlobNotFound } - if len(sequence) > 1 { - return nil, errors.New("unexpected amount of sequences") - } - - data, err := sequence[0].RawData() - if err != nil { - return nil, err - } - if len(data) == 0 { - return nil, ErrBlobNotFound + if len(blobs) > 1 { + return nil, errors.New("unexpected amount of blobs") } - shareVersion, err := sequence[0].Shares[0].Version() + com, err := inclusion.CreateCommitment(blobs[0], merkle.HashFromByteSlices, subtreeRootThreshold) if err != nil { return nil, err } - blob, err := NewBlob(shareVersion, sequence[0].Namespace.Bytes(), data) - if err != nil { - return nil, err - } - blob.index = p.index + blob := &Blob{Blob: blobs[0], Commitment: com, index: p.index} return blob, nil } // skipPadding iterates through the shares until non-padding share will be found. It guarantees that // the returned set of shares will start with non-padding share(or empty set of shares). -func (p *parser) skipPadding(shares []shares.Share) ([]shares.Share, error) { +func (p *parser) skipPadding(shares []share.Share) ([]share.Share, error) { if len(shares) == 0 { return nil, errEmptyShares } offset := 0 for _, sh := range shares { - isPadding, err := sh.IsPadding() - if err != nil { - return nil, err - } - if !isPadding { + if !sh.IsPadding() { break } offset++ diff --git a/blob/repro_test.go b/blob/repro_test.go index 27070d1f28..6cb39948ac 100644 --- a/blob/repro_test.go +++ b/blob/repro_test.go @@ -3,7 +3,7 @@ package blob import ( "testing" - "github.com/celestiaorg/celestia-app/v2/pkg/proof" + "github.com/celestiaorg/celestia-app/v3/pkg/proof" "github.com/celestiaorg/nmt" "github.com/celestiaorg/nmt/pb" ) diff --git a/blob/service.go b/blob/service.go index 22a238ec97..f40114b8c8 100644 --- a/blob/service.go +++ b/blob/service.go @@ -1,7 +1,7 @@ package blob import ( - bytes2 "bytes" + "bytes" "context" "encoding/hex" "errors" @@ -16,18 +16,16 @@ import ( "go.opentelemetry.io/otel/codes" "go.opentelemetry.io/otel/trace" - "github.com/celestiaorg/celestia-app/v2/pkg/appconsts" - pkgproof "github.com/celestiaorg/celestia-app/v2/pkg/proof" - "github.com/celestiaorg/go-square/inclusion" - appns "github.com/celestiaorg/go-square/namespace" - "github.com/celestiaorg/go-square/shares" + "github.com/celestiaorg/celestia-app/v3/pkg/appconsts" + pkgproof "github.com/celestiaorg/celestia-app/v3/pkg/proof" + "github.com/celestiaorg/go-square/v2/inclusion" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt" "github.com/celestiaorg/rsmt2d" "github.com/celestiaorg/celestia-node/header" "github.com/celestiaorg/celestia-node/libs/utils" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/shwap" + "github.com/celestiaorg/celestia-node/square/shwap" "github.com/celestiaorg/celestia-node/state" ) @@ -171,9 +169,9 @@ func (s *Service) Subscribe(ctx context.Context, ns share.Namespace) (<-chan *Su func (s *Service) Submit(ctx context.Context, blobs []*Blob, txConfig *SubmitOptions) (uint64, error) { log.Debugw("submitting blobs", "amount", len(blobs)) - squareBlobs := make([]*state.Blob, len(blobs)) + squareBlobs := make([]*share.Blob, len(blobs)) for i := range blobs { - if err := blobs[i].Namespace().ValidateForBlob(); err != nil { + if err := share.ValidateForData(blobs[i].Namespace()); err != nil { return 0, err } squareBlobs[i] = blobs[i].Blob @@ -276,7 +274,7 @@ func (s *Service) getAll( blobs, err := s.getBlobs(ctx, namespace, header) if err != nil && !errors.Is(err, ErrBlobNotFound) { - log.Errorf("getting blobs for namespaceID(%s): %v", namespace.ID().String(), err) + log.Errorf("getting blobs for namespaceID(%s): %v", hex.EncodeToString(namespace.ID()), err) resultErr[i] = err } if len(blobs) > 0 { @@ -378,7 +376,7 @@ func (s *Service) retrieve( attribute.Int64("eds-size", int64(len(header.DAH.RowRoots))))) var ( - appShares = make([]shares.Share, 0) + appShares = make([]share.Share, 0) proofs = make(Proof, 0) ) @@ -390,18 +388,14 @@ func (s *Service) retrieve( return nil, nil, ErrBlobNotFound } - appShares, err = toAppShares(row.Shares...) - if err != nil { - return nil, nil, err - } - + appShares = row.Shares proofs = append(proofs, row.Proof) index := row.Proof.Start() for { var ( isComplete bool - shrs []shares.Share + shrs []share.Share wasEmpty = sharesParser.isEmpty() ) @@ -459,11 +453,7 @@ func (s *Service) retrieve( err = ErrBlobNotFound for _, sh := range appShares { - ok, err := sh.IsPadding() - if err != nil { - return nil, nil, err - } - if !ok { + if !sh.IsPadding() { err = fmt.Errorf("incomplete blob with the "+ "namespace: %s detected at %d: %w", namespace.String(), height, err) log.Error(err) @@ -570,7 +560,7 @@ func ProveCommitment( // find the blob shares in the EDS blobSharesStartIndex := -1 for index, share := range eds.FlattenedODS() { - if bytes2.Equal(share, blobShares[0]) { + if bytes.Equal(share, blobShares[0].ToBytes()) { blobSharesStartIndex = index } } @@ -578,11 +568,6 @@ func ProveCommitment( return nil, fmt.Errorf("couldn't find the blob shares in the ODS") } - nID, err := appns.From(namespace) - if err != nil { - return nil, err - } - log.Debugw( "generating the blob share proof for commitment", "start_share", @@ -592,8 +577,8 @@ func ProveCommitment( ) sharesProof, err := pkgproof.NewShareInclusionProofFromEDS( eds, - nID, - shares.NewRange(blobSharesStartIndex, blobSharesStartIndex+len(blobShares)), + namespace, + share.NewRange(blobSharesStartIndex, blobSharesStartIndex+len(blobShares)), ) if err != nil { return nil, err @@ -624,7 +609,7 @@ func ProveCommitment( ranges, err := nmt.ToLeafRanges( proof.Start(), proof.End(), - inclusion.SubTreeWidth(len(blobShares), appconsts.DefaultSubtreeRootThreshold), + inclusion.SubTreeWidth(len(blobShares), subtreeRootThreshold), ) if err != nil { return nil, err @@ -673,7 +658,7 @@ func computeSubtreeRoots(shares []share.Share, ranges []nmt.LeafRange, offset in ) for _, sh := range shares { leafData := make([]byte, 0) - leafData = append(append(leafData, share.GetNamespace(sh)...), sh...) + leafData = append(append(leafData, sh.Namespace().Bytes()...), sh.ToBytes()...) err := tree.Push(leafData) if err != nil { return nil, err diff --git a/blob/service_test.go b/blob/service_test.go index 621419dbd9..1114b84a97 100644 --- a/blob/service_test.go +++ b/blob/service_test.go @@ -16,17 +16,17 @@ import ( ds_sync "github.com/ipfs/go-datastore/sync" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/tendermint/tendermint/crypto/merkle" tmrand "github.com/tendermint/tendermint/libs/rand" - "github.com/celestiaorg/celestia-app/v2/pkg/appconsts" - pkgproof "github.com/celestiaorg/celestia-app/v2/pkg/proof" - "github.com/celestiaorg/celestia-app/v2/pkg/wrapper" + "github.com/celestiaorg/celestia-app/v3/pkg/appconsts" + pkgproof "github.com/celestiaorg/celestia-app/v3/pkg/proof" + "github.com/celestiaorg/celestia-app/v3/pkg/wrapper" "github.com/celestiaorg/go-header/store" - "github.com/celestiaorg/go-square/blob" - "github.com/celestiaorg/go-square/inclusion" + "github.com/celestiaorg/go-square/merkle" squarens "github.com/celestiaorg/go-square/namespace" appshares "github.com/celestiaorg/go-square/shares" + "github.com/celestiaorg/go-square/v2/inclusion" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt" "github.com/celestiaorg/rsmt2d" @@ -34,12 +34,12 @@ import ( "github.com/celestiaorg/celestia-node/header" "github.com/celestiaorg/celestia-node/header/headertest" "github.com/celestiaorg/celestia-node/libs/utils" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/eds" - "github.com/celestiaorg/celestia-node/share/eds/edstest" - "github.com/celestiaorg/celestia-node/share/ipld" - "github.com/celestiaorg/celestia-node/share/shwap" - "github.com/celestiaorg/celestia-node/share/shwap/getters/mock" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/eds" + "github.com/celestiaorg/celestia-node/square/eds/edstest" + "github.com/celestiaorg/celestia-node/square/ipld" + "github.com/celestiaorg/celestia-node/square/shwap" + "github.com/celestiaorg/celestia-node/square/shwap/getters/mock" ) func TestBlobService_Get(t *testing.T) { @@ -135,7 +135,7 @@ func TestBlobService_Get(t *testing.T) { assert.Len(t, blobs, 4) sort.Slice(blobs, func(i, j int) bool { - val := bytes.Compare(blobs[i].NamespaceId, blobs[j].NamespaceId) + val := bytes.Compare(blobs[i].Namespace().ID(), blobs[j].Namespace().ID()) return val < 0 }) @@ -149,17 +149,17 @@ func TestBlobService_Get(t *testing.T) { row, col := calculateIndex(len(h.DAH.RowRoots), blobs[i].index) sh, err := service.shareGetter.GetShare(ctx, h, row, col) require.NoError(t, err) - require.True(t, bytes.Equal(sh, resultShares[shareOffset]), + require.True(t, bytes.Equal(sh.ToBytes(), resultShares[shareOffset].ToBytes()), fmt.Sprintf("issue on %d attempt. ROW:%d, COL: %d, blobIndex:%d", i, row, col, blobs[i].index), ) - shareOffset += appshares.SparseSharesNeeded(uint32(len(blobs[i].Data))) + shareOffset += appshares.SparseSharesNeeded(uint32(len(blobs[i].Data()))) } }, }, { name: "get all with different namespaces", doFn: func() (interface{}, error) { - nid, err := share.NewBlobNamespaceV0(tmrand.Bytes(7)) + nid, err := share.NewV0Namespace(tmrand.Bytes(7)) require.NoError(t, err) b, err := service.GetAll(ctx, 1, []share.Namespace{ @@ -177,8 +177,9 @@ func TestBlobService_Get(t *testing.T) { assert.NotEmpty(t, blobs) assert.Len(t, blobs, 2) // check the order - require.True(t, bytes.Equal(blobs[0].Namespace(), blobsWithDiffNamespaces[0].Namespace())) - require.True(t, bytes.Equal(blobs[1].Namespace(), blobsWithDiffNamespaces[1].Namespace())) + + require.True(t, blobs[0].Namespace().Equals(blobsWithDiffNamespaces[0].Namespace())) + require.True(t, blobs[1].Namespace().Equals(blobsWithDiffNamespaces[1].Namespace())) }, }, { @@ -241,7 +242,7 @@ func TestBlobService_Get(t *testing.T) { for _, p := range *proof { from := to to = p.End() - p.Start() + from - eq := p.VerifyInclusion(share.NewSHA256Hasher(), namespace.ToNMT(), rawShares[from:to], row) + eq := p.VerifyInclusion(square.NewSHA256Hasher(), namespace.Bytes(), rawShares[from:to], row) if eq == true { return } @@ -252,7 +253,7 @@ func TestBlobService_Get(t *testing.T) { rawShares, err := BlobsToShares(blobsWithDiffNamespaces[1]) require.NoError(t, err) - verifyFn(t, rawShares, proof, blobsWithDiffNamespaces[1].Namespace()) + verifyFn(t, share.ToBytes(rawShares), proof, blobsWithDiffNamespaces[1].Namespace()) }, }, { @@ -357,7 +358,7 @@ func TestBlobService_Get(t *testing.T) { { name: "empty result and err when blobs were not found ", doFn: func() (interface{}, error) { - nid, err := share.NewBlobNamespaceV0(tmrand.Bytes(squarens.NamespaceVersionZeroIDSize)) + nid, err := share.NewV0Namespace(tmrand.Bytes(squarens.NamespaceVersionZeroIDSize)) require.NoError(t, err) return service.GetAll(ctx, 1, []share.Namespace{nid}) }, @@ -456,7 +457,7 @@ func TestBlobService_Get(t *testing.T) { // But to satisfy the rule of eds creating, padding namespace share is placed between // blobs. Test ensures that blob service will skip padding share and return the correct blob. func TestService_GetSingleBlobWithoutPadding(t *testing.T) { - ctx, cancel := context.WithTimeout(context.Background(), time.Minute*5) + ctx, cancel := context.WithTimeout(context.Background(), time.Second*5) t.Cleanup(cancel) appBlob, err := blobtest.GenerateV0Blobs([]int{9, 5}, true) @@ -464,20 +465,18 @@ func TestService_GetSingleBlobWithoutPadding(t *testing.T) { blobs, err := convertBlobs(appBlob...) require.NoError(t, err) - ns1, ns2 := blobs[0].Namespace().ToAppNamespace(), blobs[1].Namespace().ToAppNamespace() - - padding0, err := appshares.NamespacePaddingShare(ns1, appconsts.ShareVersionZero) + padding0, err := share.NamespacePaddingShare(blobs[0].Namespace(), share.ShareVersionZero) require.NoError(t, err) - padding1, err := appshares.NamespacePaddingShare(ns2, appconsts.ShareVersionZero) + padding1, err := share.NamespacePaddingShare(blobs[1].Namespace(), share.ShareVersionZero) require.NoError(t, err) rawShares0, err := BlobsToShares(blobs[0]) require.NoError(t, err) rawShares1, err := BlobsToShares(blobs[1]) require.NoError(t, err) - rawShares := make([][]byte, 0) - rawShares = append(rawShares, append(rawShares0, padding0.ToBytes())...) - rawShares = append(rawShares, append(rawShares1, padding1.ToBytes())...) + rawShares := make([]share.Share, 0) + rawShares = append(rawShares, append(rawShares0, padding0)...) + rawShares = append(rawShares, append(rawShares1, padding1)...) service := createService(ctx, t, rawShares) newBlob, err := service.Get(ctx, 1, blobs[1].Namespace(), blobs[1].Commitment) @@ -528,7 +527,7 @@ func TestService_Get(t *testing.T) { require.NoError(t, err) assert.Equal(t, sh, resultShares[shareOffset], fmt.Sprintf("issue on %d attempt", i)) - shareOffset += appshares.SparseSharesNeeded(uint32(len(blob.Data))) + shareOffset += appshares.SparseSharesNeeded(uint32(len(blob.Data()))) } } @@ -544,30 +543,27 @@ func TestService_GetAllWithoutPadding(t *testing.T) { blobs, err := convertBlobs(appBlob...) require.NoError(t, err) - var ( - ns = blobs[0].Namespace().ToAppNamespace() - rawShares = make([][]byte, 0) - ) + rawShares := make([]share.Share, 0) - padding, err := appshares.NamespacePaddingShare(ns, appconsts.ShareVersionZero) + require.NoError(t, err) + padding, err := share.NamespacePaddingShare(blobs[0].Namespace(), share.ShareVersionZero) require.NoError(t, err) for i := 0; i < 2; i++ { sh, err := BlobsToShares(blobs[i]) require.NoError(t, err) - rawShares = append(rawShares, append(sh, padding.ToBytes())...) + rawShares = append(rawShares, append(sh, padding)...) } sh, err := BlobsToShares(blobs[2]) require.NoError(t, err) - rawShares = append(rawShares, append(sh, padding.ToBytes(), padding.ToBytes())...) + rawShares = append(rawShares, append(sh, padding, padding)...) sh, err = BlobsToShares(blobs[3]) require.NoError(t, err) - rawShares = append(rawShares, append(sh, padding.ToBytes(), padding.ToBytes(), padding.ToBytes())...) + rawShares = append(rawShares, append(sh, padding, padding, padding)...) sh, err = BlobsToShares(blobs[4]) - require.NoError(t, err) rawShares = append(rawShares, sh...) service := createService(ctx, t, rawShares) @@ -589,19 +585,20 @@ func TestService_GetAllWithoutPadding(t *testing.T) { require.NoError(t, err) assert.Equal(t, sh, resultShares[shareOffset]) - shareOffset += appshares.SparseSharesNeeded(uint32(len(blob.Data))) + shareOffset += appshares.SparseSharesNeeded(uint32(len(blob.Data()))) } } func TestAllPaddingSharesInEDS(t *testing.T) { - nid, err := share.NewBlobNamespaceV0(tmrand.Bytes(7)) + nid, err := share.NewV0Namespace(tmrand.Bytes(7)) require.NoError(t, err) - padding, err := appshares.NamespacePaddingShare(nid.ToAppNamespace(), appconsts.ShareVersionZero) + + padding, err := share.NamespacePaddingShare(nid, share.ShareVersionZero) require.NoError(t, err) rawShares := make([]share.Share, 16) for i := 0; i < 16; i++ { - rawShares[i] = padding.ToBytes() + rawShares[i] = padding } ctx, cancel := context.WithTimeout(context.Background(), time.Second*5) @@ -614,22 +611,23 @@ func TestAllPaddingSharesInEDS(t *testing.T) { } func TestSkipPaddingsAndRetrieveBlob(t *testing.T) { - nid, err := share.NewBlobNamespaceV0(tmrand.Bytes(7)) - require.NoError(t, err) - padding, err := appshares.NamespacePaddingShare(nid.ToAppNamespace(), appconsts.ShareVersionZero) + nid := share.RandomBlobNamespace() + padding, err := share.NamespacePaddingShare(nid, share.ShareVersionZero) require.NoError(t, err) rawShares := make([]share.Share, 0, 64) for i := 0; i < 58; i++ { - rawShares = append(rawShares, padding.ToBytes()) + rawShares = append(rawShares, padding) } - appBlob, err := blobtest.GenerateV0Blobs([]int{6}, true) + size := blobtest.RawBlobSize(share.FirstSparseShareContentSize * 6) + ns, err := share.NewNamespace(nid.Version(), nid.ID()) + require.NoError(t, err) + data := tmrand.Bytes(size) + appBlob, err := share.NewBlob(ns, data, share.ShareVersionZero, nil) require.NoError(t, err) - appBlob[0].NamespaceVersion = uint32(nid[0]) - appBlob[0].NamespaceId = nid[1:] - blobs, err := convertBlobs(appBlob...) + blobs, err := convertBlobs(appBlob) require.NoError(t, err) sh, err := BlobsToShares(blobs[0]) require.NoError(t, err) @@ -668,7 +666,7 @@ func TestService_Subscribe(t *testing.T) { select { case resp := <-subCh: assert.Equal(t, i+1, resp.Height) - assert.Equal(t, blobs[i].Data, resp.Blobs[0].Data) + assert.Equal(t, blobs[i].Data(), resp.Blobs[0].Data()) case <-time.After(time.Second * 2): t.Fatalf("timeout waiting for subscription response %d", i) } @@ -676,7 +674,7 @@ func TestService_Subscribe(t *testing.T) { }) t.Run("subscription with no matching blobs", func(t *testing.T) { - ns, err := share.NewBlobNamespaceV0([]byte("nonexist")) + ns, err := share.NewV0Namespace([]byte("nonexist")) require.NoError(t, err) subCh, err := service.Subscribe(ctx, ns) @@ -760,7 +758,7 @@ func TestService_Subscribe_MultipleNamespaces(t *testing.T) { appBlobs2, err := blobtest.GenerateV0Blobs([]int{100, 100}, true) for i := range appBlobs2 { // if we don't do this, appBlobs1 and appBlobs2 will share a NS - appBlobs2[i].GetNamespaceId()[len(appBlobs2[i].GetNamespaceId())-1] = 0xDE + appBlobs2[i].Namespace().ID()[len(appBlobs2[i].Namespace().ID())-1] = 0xDE } require.NoError(t, err) @@ -892,8 +890,8 @@ func createServiceWithSub(ctx context.Context, t testing.TB, blobs []*Blob) *Ser func createService(ctx context.Context, t testing.TB, shares []share.Share) *Service { odsSize := int(utils.SquareSize(len(shares))) square, err := rsmt2d.ComputeExtendedDataSquare( - shares, - share.DefaultRSMT2DCodec(), + share.ToBytes(shares), + square.DefaultRSMT2DCodec(), wrapper.NewConstructor(uint64(odsSize))) require.NoError(t, err) @@ -955,12 +953,12 @@ func proveAndVerifyShareCommitments(t *testing.T, blobSize int) { msgs, blobs, nss, eds, _, _, dataRoot := edstest.GenerateTestBlock(t, blobSize, 10) for msgIndex, msg := range msgs { t.Run(fmt.Sprintf("msgIndex=%d", msgIndex), func(t *testing.T) { - blb, err := NewBlob(uint8(blobs[msgIndex].GetShareVersion()), nss[msgIndex].Bytes(), blobs[msgIndex].GetData()) + blb, err := NewBlob(uint8(blobs[msgIndex].ShareVersion()), nss[msgIndex], blobs[msgIndex].Data(), nil) require.NoError(t, err) blobShares, err := BlobsToShares(blb) require.NoError(t, err) // compute the commitment - actualCommitmentProof, err := ProveCommitment(eds, nss[msgIndex].Bytes(), blobShares) + actualCommitmentProof, err := ProveCommitment(eds, nss[msgIndex], blobShares) require.NoError(t, err) // make sure the actual commitment attests to the data @@ -973,7 +971,7 @@ func proveAndVerifyShareCommitments(t *testing.T, blobSize int) { require.True(t, valid) // generate an expected proof and verify it's valid - expectedCommitmentProof := generateCommitmentProofFromBlock(t, eds, nss[msgIndex].Bytes(), blobs[msgIndex], dataRoot) + expectedCommitmentProof := generateCommitmentProofFromBlock(t, eds, nss[msgIndex], blobs[msgIndex], dataRoot) require.NoError(t, expectedCommitmentProof.Validate()) valid, err = expectedCommitmentProof.Verify( dataRoot, @@ -998,14 +996,14 @@ func generateCommitmentProofFromBlock( t *testing.T, eds *rsmt2d.ExtendedDataSquare, ns share.Namespace, - blob *blob.Blob, + blob *share.Blob, dataRoot []byte, ) CommitmentProof { // create the blob from the data - blb, err := NewBlob( - uint8(blob.GetShareVersion()), + blb, err := NewBlob(blob.ShareVersion(), ns, - blob.GetData(), + blob.Data(), + nil, ) require.NoError(t, err) @@ -1016,7 +1014,7 @@ func generateCommitmentProofFromBlock( // find the first share of the blob in the ODS startShareIndex := -1 for i, sh := range eds.FlattenedODS() { - if bytes.Equal(sh, blobShares[0]) { + if bytes.Equal(sh, blobShares[0].ToBytes()) { startShareIndex = i break } @@ -1026,8 +1024,8 @@ func generateCommitmentProofFromBlock( // create an inclusion proof of the blob using the share range instead of the commitment sharesProof, err := pkgproof.NewShareInclusionProofFromEDS( eds, - ns.ToAppNamespace(), - appshares.NewRange(startShareIndex, startShareIndex+len(blobShares)), + ns, + share.NewRange(startShareIndex, startShareIndex+len(blobShares)), ) require.NoError(t, err) require.NoError(t, sharesProof.Validate(dataRoot)) @@ -1039,7 +1037,7 @@ func generateCommitmentProofFromBlock( ranges, err := nmt.ToLeafRanges( int(proof.Start), int(proof.End), - inclusion.SubTreeWidth(len(blobShares), appconsts.DefaultSubtreeRootThreshold), + inclusion.SubTreeWidth(len(blobShares), subtreeRootThreshold), ) require.NoError(t, err) roots, err := computeSubtreeRoots( diff --git a/cmd/cel-key/main.go b/cmd/cel-key/main.go index 5db3f4bc7c..33d3f1487a 100644 --- a/cmd/cel-key/main.go +++ b/cmd/cel-key/main.go @@ -12,8 +12,8 @@ import ( "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/spf13/cobra" - "github.com/celestiaorg/celestia-app/v2/app" - "github.com/celestiaorg/celestia-app/v2/app/encoding" + "github.com/celestiaorg/celestia-app/v3/app" + "github.com/celestiaorg/celestia-app/v3/app/encoding" ) var encodingConfig = encoding.MakeConfig(app.ModuleEncodingRegisters...) diff --git a/cmd/cel-shed/shwap.go b/cmd/cel-shed/shwap.go index 2d88e59ca9..60a6d237ac 100644 --- a/cmd/cel-shed/shwap.go +++ b/cmd/cel-shed/shwap.go @@ -7,7 +7,7 @@ import ( "github.com/ipfs/go-cid" "github.com/spf13/cobra" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/bitswap" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/bitswap" ) func init() { diff --git a/cmd/start.go b/cmd/start.go index 85970cbd6e..3a71c5a6db 100644 --- a/cmd/start.go +++ b/cmd/start.go @@ -10,8 +10,8 @@ import ( "github.com/cosmos/cosmos-sdk/crypto/keyring" "github.com/spf13/cobra" - "github.com/celestiaorg/celestia-app/v2/app" - "github.com/celestiaorg/celestia-app/v2/app/encoding" + "github.com/celestiaorg/celestia-app/v3/app" + "github.com/celestiaorg/celestia-app/v3/app/encoding" "github.com/celestiaorg/celestia-node/nodebuilder" ) diff --git a/cmd/util.go b/cmd/util.go index 750b9d9ae5..16ff39d5d7 100644 --- a/cmd/util.go +++ b/cmd/util.go @@ -11,6 +11,8 @@ import ( "github.com/spf13/cobra" flag "github.com/spf13/pflag" + "github.com/celestiaorg/go-square/v2/share" + "github.com/celestiaorg/celestia-node/nodebuilder/core" "github.com/celestiaorg/celestia-node/nodebuilder/gateway" "github.com/celestiaorg/celestia-node/nodebuilder/header" @@ -19,7 +21,6 @@ import ( "github.com/celestiaorg/celestia-node/nodebuilder/pruner" rpc_cfg "github.com/celestiaorg/celestia-node/nodebuilder/rpc" "github.com/celestiaorg/celestia-node/nodebuilder/state" - "github.com/celestiaorg/celestia-node/share" ) func PrintOutput(data interface{}, err error, formatData func(interface{}) interface{}) error { @@ -50,11 +51,11 @@ func PrintOutput(data interface{}, err error, formatData func(interface{}) inter func ParseV0Namespace(param string) (share.Namespace, error) { userBytes, err := DecodeToBytes(param) if err != nil { - return nil, err + return share.Namespace{}, err } // if the namespace ID is <= 10 bytes, left pad it with 0s - return share.NewBlobNamespaceV0(userBytes) + return share.NewV0Namespace(userBytes) } // DecodeToBytes decodes a Base64 or hex input string into a byte slice. diff --git a/cmd/util_test.go b/cmd/util_test.go index b6e245f3e2..97dc7cc83c 100644 --- a/cmd/util_test.go +++ b/cmd/util_test.go @@ -4,22 +4,23 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" - "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/go-square/v2/share" ) func Test_parseNamespaceID(t *testing.T) { type testCase struct { name string param string - want share.Namespace + want []byte wantErr bool } testCases := []testCase{ { param: "0x0c204d39600fddd3", name: "8 byte hex encoded namespace ID gets left padded", - want: share.Namespace{ + want: []byte{ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xc, 0x20, 0x4d, 0x39, 0x60, 0xf, 0xdd, 0xd3, }, @@ -28,7 +29,7 @@ func Test_parseNamespaceID(t *testing.T) { { name: "10 byte hex encoded namespace ID", param: "0x42690c204d39600fddd3", - want: share.Namespace{ + want: []byte{ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x42, 0x69, 0xc, 0x20, 0x4d, 0x39, 0x60, 0xf, 0xdd, 0xd3, }, @@ -37,7 +38,7 @@ func Test_parseNamespaceID(t *testing.T) { { name: "29 byte hex encoded namespace ID", param: "0x0000000000000000000000000000000000000001010101010101010101", - want: share.Namespace{ + want: []byte{ 0x0, // namespace version 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, // v0 ID prefix 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, // namespace ID @@ -47,13 +48,13 @@ func Test_parseNamespaceID(t *testing.T) { { name: "11 byte hex encoded namespace ID returns error", param: "0x42690c204d39600fddd3a3", - want: share.Namespace{}, + want: nil, wantErr: true, }, { name: "10 byte base64 encoded namespace ID", param: "QmkMIE05YA/d0w==", - want: share.Namespace{ + want: []byte{ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x42, 0x69, 0xc, 0x20, 0x4d, 0x39, 0x60, 0xf, 0xdd, 0xd3, }, @@ -62,7 +63,7 @@ func Test_parseNamespaceID(t *testing.T) { { name: "not base64 or hex encoded namespace ID returns error", param: "5748493939429", - want: share.Namespace{}, + want: nil, wantErr: true, }, } @@ -74,8 +75,11 @@ func Test_parseNamespaceID(t *testing.T) { assert.Error(t, err) return } + assert.NoError(t, err) - assert.Equal(t, tc.want, got) + ns, err := share.NewNamespaceFromBytes(tc.want) + require.NoError(t, err) + assert.Equal(t, ns, got) }) } } diff --git a/core/eds.go b/core/eds.go index a069ca7cec..b4d4fdfbcb 100644 --- a/core/eds.go +++ b/core/eds.go @@ -6,18 +6,19 @@ import ( "github.com/tendermint/tendermint/types" - "github.com/celestiaorg/celestia-app/v2/app" - "github.com/celestiaorg/celestia-app/v2/pkg/appconsts" - "github.com/celestiaorg/celestia-app/v2/pkg/wrapper" + "github.com/celestiaorg/celestia-app/v3/app" + "github.com/celestiaorg/celestia-app/v3/pkg/appconsts" + "github.com/celestiaorg/celestia-app/v3/pkg/wrapper" "github.com/celestiaorg/go-square/shares" - "github.com/celestiaorg/go-square/square" + libSquare "github.com/celestiaorg/go-square/v2" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt" "github.com/celestiaorg/rsmt2d" "github.com/celestiaorg/celestia-node/header" "github.com/celestiaorg/celestia-node/pruner" "github.com/celestiaorg/celestia-node/pruner/full" - "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/square" "github.com/celestiaorg/celestia-node/store" ) @@ -26,11 +27,11 @@ import ( // nil is returned in place of the eds. func extendBlock(data types.Data, appVersion uint64, options ...nmt.Option) (*rsmt2d.ExtendedDataSquare, error) { if app.IsEmptyBlock(data, appVersion) { - return share.EmptyEDS(), nil + return square.EmptyEDS(), nil } // Construct the data square from the block's transactions - dataSquare, err := square.Construct( + dataSquare, err := libSquare.Construct( data.Txs.ToSliceOfBytes(), appconsts.SquareSizeUpperBound(appVersion), appconsts.SubtreeRootThreshold(appVersion), @@ -38,7 +39,7 @@ func extendBlock(data types.Data, appVersion uint64, options ...nmt.Option) (*rs if err != nil { return nil, err } - return extendShares(shares.ToBytes(dataSquare), options...) + return extendShares(share.ToBytes(dataSquare), options...) } func extendShares(s [][]byte, options ...nmt.Option) (*rsmt2d.ExtendedDataSquare, error) { @@ -48,7 +49,7 @@ func extendShares(s [][]byte, options ...nmt.Option) (*rsmt2d.ExtendedDataSquare } // here we construct a tree // Note: uses the nmt wrapper to construct the tree. - squareSize := square.Size(len(s)) + squareSize := libSquare.Size(len(s)) return rsmt2d.ComputeExtendedDataSquare(s, appconsts.DefaultCodec(), wrapper.NewConstructor(uint64(squareSize), diff --git a/core/eds_test.go b/core/eds_test.go index 462561852a..ff4f6be808 100644 --- a/core/eds_test.go +++ b/core/eds_test.go @@ -7,10 +7,10 @@ import ( "github.com/stretchr/testify/require" "github.com/tendermint/tendermint/types" - "github.com/celestiaorg/celestia-app/v2/app" - "github.com/celestiaorg/celestia-app/v2/pkg/appconsts" + "github.com/celestiaorg/celestia-app/v3/app" + "github.com/celestiaorg/celestia-app/v3/pkg/appconsts" - "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/square" ) // TestTrulyEmptySquare ensures that a truly empty square (square size 1 and no @@ -24,7 +24,7 @@ func TestTrulyEmptySquare(t *testing.T) { eds, err := extendBlock(data, appconsts.LatestVersion) require.NoError(t, err) - require.True(t, eds.Equals(share.EmptyEDS())) + require.True(t, eds.Equals(square.EmptyEDS())) } // TestEmptySquareWithZeroTxs tests that the datahash of a block with no transactions @@ -40,13 +40,13 @@ func TestEmptySquareWithZeroTxs(t *testing.T) { eds, err := extendBlock(data, appconsts.LatestVersion) require.NoError(t, err) - require.True(t, eds.Equals(share.EmptyEDS())) + require.True(t, eds.Equals(square.EmptyEDS())) // force extend the square using an empty block and compare with the min DAH eds, err = app.ExtendBlock(data, appconsts.LatestVersion) require.NoError(t, err) - roots, err := share.NewAxisRoots(eds) + roots, err := square.NewAxisRoots(eds) require.NoError(t, err) - assert.Equal(t, share.EmptyEDSRoots().Hash(), roots.Hash()) + assert.Equal(t, square.EmptyEDSRoots().Hash(), roots.Hash()) } diff --git a/core/exchange_test.go b/core/exchange_test.go index fb3795d380..c7c1b6e3ab 100644 --- a/core/exchange_test.go +++ b/core/exchange_test.go @@ -10,11 +10,11 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/celestiaorg/celestia-app/v2/test/util/testnode" + "github.com/celestiaorg/celestia-app/v3/test/util/testnode" "github.com/celestiaorg/celestia-node/header" "github.com/celestiaorg/celestia-node/pruner" - "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/square" "github.com/celestiaorg/celestia-node/store" ) @@ -103,7 +103,7 @@ func TestExchange_DoNotStoreHistoric(t *testing.T) { assert.False(t, has) // empty EDSs are expected to exist in the store, so we skip them - if h.DAH.Equals(share.EmptyEDSRoots()) { + if h.DAH.Equals(square.EmptyEDSRoots()) { continue } has, err = store.HasByHash(ctx, h.DAH.Hash()) @@ -147,7 +147,7 @@ func generateNonEmptyBlocks( fetcher *BlockFetcher, cfg *testnode.Config, cctx testnode.Context, -) []share.DataHash { +) []square.DataHash { // generate several non-empty blocks generateCtx, generateCtxCancel := context.WithCancel(context.Background()) @@ -160,7 +160,7 @@ func generateNonEmptyBlocks( go fillBlocks(t, generateCtx, cfg, cctx) - hashes := make([]share.DataHash, 0, 20) + hashes := make([]square.DataHash, 0, 20) i := 0 for i < 20 { @@ -168,10 +168,10 @@ func generateNonEmptyBlocks( case b, ok := <-sub: require.True(t, ok) - if bytes.Equal(share.EmptyEDSDataHash(), b.Data.Hash()) { + if bytes.Equal(square.EmptyEDSDataHash(), b.Data.Hash()) { continue } - hashes = append(hashes, share.DataHash(b.Data.Hash())) + hashes = append(hashes, square.DataHash(b.Data.Hash())) i++ case <-ctx.Done(): t.Fatal("failed to fill blocks within timeout") diff --git a/core/header_test.go b/core/header_test.go index bcf3f177c9..87c4378bb4 100644 --- a/core/header_test.go +++ b/core/header_test.go @@ -9,11 +9,11 @@ import ( "github.com/stretchr/testify/require" "github.com/tendermint/tendermint/libs/rand" - "github.com/celestiaorg/celestia-app/v2/pkg/appconsts" + "github.com/celestiaorg/celestia-app/v3/pkg/appconsts" "github.com/celestiaorg/celestia-node/header" "github.com/celestiaorg/celestia-node/header/headertest" - "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/square" ) func TestMakeExtendedHeaderForEmptyBlock(t *testing.T) { @@ -40,7 +40,7 @@ func TestMakeExtendedHeaderForEmptyBlock(t *testing.T) { headerExt, err := header.MakeExtendedHeader(&b.Header, comm, val, eds) require.NoError(t, err) - assert.Equal(t, share.EmptyEDSRoots(), headerExt.DAH) + assert.Equal(t, square.EmptyEDSRoots(), headerExt.DAH) } func TestMismatchedDataHash_ComputedRoot(t *testing.T) { diff --git a/core/listener.go b/core/listener.go index 67e532d970..694675d420 100644 --- a/core/listener.go +++ b/core/listener.go @@ -15,7 +15,7 @@ import ( "github.com/celestiaorg/celestia-node/header" "github.com/celestiaorg/celestia-node/pruner" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrexsub" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrexsub" "github.com/celestiaorg/celestia-node/store" ) diff --git a/core/listener_no_race_test.go b/core/listener_no_race_test.go index b7d26fba36..3c67932104 100644 --- a/core/listener_no_race_test.go +++ b/core/listener_no_race_test.go @@ -11,7 +11,7 @@ import ( "github.com/cosmos/cosmos-sdk/client/flags" "github.com/stretchr/testify/require" - "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/square" "github.com/celestiaorg/celestia-node/store" ) @@ -43,7 +43,7 @@ func TestListenerWithNonEmptyBlocks(t *testing.T) { require.NoError(t, err) t.Cleanup(sub.Cancel) - empty := share.EmptyEDSRoots() + empty := square.EmptyEDSRoots() // TODO extract 16 for i := 0; i < 16; i++ { accounts := cfg.Genesis.Accounts() diff --git a/core/listener_test.go b/core/listener_test.go index 252c6e88c1..54a52864cf 100644 --- a/core/listener_test.go +++ b/core/listener_test.go @@ -16,7 +16,7 @@ import ( "github.com/celestiaorg/celestia-node/header" nodep2p "github.com/celestiaorg/celestia-node/nodebuilder/p2p" "github.com/celestiaorg/celestia-node/pruner" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrexsub" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrexsub" "github.com/celestiaorg/celestia-node/store" ) diff --git a/core/testing.go b/core/testing.go index dafeaed756..6d2aa8cc36 100644 --- a/core/testing.go +++ b/core/testing.go @@ -10,8 +10,8 @@ import ( tmconfig "github.com/tendermint/tendermint/config" tmrand "github.com/tendermint/tendermint/libs/rand" - "github.com/celestiaorg/celestia-app/v2/test/util/genesis" - "github.com/celestiaorg/celestia-app/v2/test/util/testnode" + "github.com/celestiaorg/celestia-app/v3/test/util/genesis" + "github.com/celestiaorg/celestia-app/v3/test/util/testnode" ) const chainID = "private" diff --git a/das/coordinator.go b/das/coordinator.go index aff41bac8c..c5ad1a668c 100644 --- a/das/coordinator.go +++ b/das/coordinator.go @@ -8,7 +8,7 @@ import ( libhead "github.com/celestiaorg/go-header" "github.com/celestiaorg/celestia-node/header" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrexsub" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrexsub" ) // samplingCoordinator runs and coordinates sampling workers and updates current sampling state diff --git a/das/coordinator_test.go b/das/coordinator_test.go index a94a9a4e6f..3b5b7f793a 100644 --- a/das/coordinator_test.go +++ b/das/coordinator_test.go @@ -13,8 +13,8 @@ import ( "github.com/tendermint/tendermint/types" "github.com/celestiaorg/celestia-node/header" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrexsub" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrexsub" ) func TestCoordinator(t *testing.T) { @@ -432,7 +432,7 @@ func (m *mockSampler) discover(ctx context.Context, newHeight uint64, emit liste emit(ctx, &header.ExtendedHeader{ Commit: &types.Commit{}, RawHeader: header.RawHeader{Height: int64(newHeight)}, - DAH: &share.AxisRoots{RowRoots: make([][]byte, 0)}, + DAH: &square.AxisRoots{RowRoots: make([][]byte, 0)}, }) } diff --git a/das/daser.go b/das/daser.go index 2b0b84ba29..cf8056ff95 100644 --- a/das/daser.go +++ b/das/daser.go @@ -14,9 +14,9 @@ import ( "github.com/celestiaorg/celestia-node/header" "github.com/celestiaorg/celestia-node/pruner" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/eds/byzantine" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrexsub" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/eds/byzantine" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrexsub" ) var log = logging.Logger("das") @@ -30,7 +30,7 @@ var errOutsideSamplingWindow = fmt.Errorf("skipping header outside of sampling w type DASer struct { params Parameters - da share.Availability + da square.Availability bcast fraud.Broadcaster[*header.ExtendedHeader] hsub libhead.Subscriber[*header.ExtendedHeader] // listens for new headers in the network getter libhead.Getter[*header.ExtendedHeader] // retrieves past headers @@ -51,7 +51,7 @@ type ( // NewDASer creates a new DASer. func NewDASer( - da share.Availability, + da square.Availability, hsub libhead.Subscriber[*header.ExtendedHeader], getter libhead.Getter[*header.ExtendedHeader], dstore datastore.Datastore, diff --git a/das/daser_test.go b/das/daser_test.go index c67e5c06e2..bf4516f40f 100644 --- a/das/daser_test.go +++ b/das/daser_test.go @@ -20,9 +20,9 @@ import ( "github.com/celestiaorg/celestia-node/header" "github.com/celestiaorg/celestia-node/header/headertest" "github.com/celestiaorg/celestia-node/pruner" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/availability/mocks" - "github.com/celestiaorg/celestia-node/share/eds/edstest" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/availability/mocks" + "github.com/celestiaorg/celestia-node/square/eds/edstest" ) var timeout = time.Second * 15 @@ -285,7 +285,7 @@ func TestDASer_SamplingWindow(t *testing.T) { // createDASerSubcomponents takes numGetter (number of headers // to store in mockGetter) and numSub (number of headers to store // in the mock header.Subscriber), returning a newly instantiated -// mockGetter, share.Availability, and mock header.Subscriber. +// mockGetter, square.Availability, and mock header.Subscriber. func createDASerSubcomponents( t *testing.T, numGetter, @@ -399,7 +399,7 @@ type benchGetterStub struct { func newBenchGetter() benchGetterStub { return benchGetterStub{header: &header.ExtendedHeader{ - DAH: &share.AxisRoots{RowRoots: make([][]byte, 0)}, + DAH: &square.AxisRoots{RowRoots: make([][]byte, 0)}, }} } @@ -420,7 +420,7 @@ func (m getterStub) GetByHeight(_ context.Context, height uint64) (*header.Exten return &header.ExtendedHeader{ Commit: &types.Commit{}, RawHeader: header.RawHeader{Height: int64(height)}, - DAH: &share.AxisRoots{RowRoots: make([][]byte, 0)}, + DAH: &square.AxisRoots{RowRoots: make([][]byte, 0)}, }, nil } diff --git a/das/worker.go b/das/worker.go index 88ca387211..4da0acd89e 100644 --- a/das/worker.go +++ b/das/worker.go @@ -10,7 +10,7 @@ import ( libhead "github.com/celestiaorg/go-header" "github.com/celestiaorg/celestia-node/header" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrexsub" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrexsub" ) type jobType string diff --git a/docs/adr/adr-011-blocksync-overhaul-part-1.md b/docs/adr/adr-011-blocksync-overhaul-part-1.md index 0173e78efb..50318efa09 100644 --- a/docs/adr/adr-011-blocksync-overhaul-part-1.md +++ b/docs/adr/adr-011-blocksync-overhaul-part-1.md @@ -301,7 +301,7 @@ The `GetDAH` method returns the DAH (`share.Root`) of the EDS identified by `Dat ```go // GetDAH returns the DataAvailabilityHeader for the EDS identified by DataHash. -func (s *Store) GetDAH(context.Context, share.DataHash) (*share.Root, error) +func (s *Store) GetDAH(context.Context, square.DataHash) (*share.Root, error) ``` ##### `eds.Store.Get` diff --git a/go.mod b/go.mod index ab489b180c..5e54b7f402 100644 --- a/go.mod +++ b/go.mod @@ -7,14 +7,15 @@ require ( github.com/BurntSushi/toml v1.4.1-0.20240526193622-a339e1f7089c github.com/alecthomas/jsonschema v0.0.0-20220216202328-9eeeec9d044b github.com/benbjohnson/clock v1.3.5 - github.com/celestiaorg/celestia-app/v2 v2.3.0 + github.com/celestiaorg/celestia-app/v3 v3.0.0 github.com/celestiaorg/go-fraud v0.2.1 github.com/celestiaorg/go-header v0.6.2 github.com/celestiaorg/go-libp2p-messenger v0.2.0 github.com/celestiaorg/go-square v1.1.0 github.com/celestiaorg/go-square/merkle v0.0.0-20240117232118-fd78256df076 - github.com/celestiaorg/nmt v0.22.1 - github.com/celestiaorg/rsmt2d v0.13.1 + github.com/celestiaorg/go-square/v2 v2.0.0 + github.com/celestiaorg/nmt v0.22.2 + github.com/celestiaorg/rsmt2d v0.14.0 github.com/cosmos/cosmos-sdk v0.46.16 github.com/cristalhq/jwt/v5 v5.4.0 github.com/dgraph-io/badger/v4 v4.2.1-0.20240106094458-1c417aa3799c @@ -74,13 +75,13 @@ require ( golang.org/x/exp v0.0.0-20240904232852-e7e105dedf7e golang.org/x/sync v0.8.0 golang.org/x/text v0.18.0 - google.golang.org/grpc v1.66.2 - google.golang.org/protobuf v1.34.2 + google.golang.org/grpc v1.67.0 + google.golang.org/protobuf v1.35.1 ) require ( cloud.google.com/go v0.112.1 // indirect - cloud.google.com/go/compute/metadata v0.3.0 // indirect + cloud.google.com/go/compute/metadata v0.5.0 // indirect cloud.google.com/go/iam v1.1.6 // indirect cloud.google.com/go/storage v1.38.0 // indirect cosmossdk.io/errors v1.0.1 // indirect @@ -99,6 +100,7 @@ require ( github.com/bgentry/speakeasy v0.1.0 // indirect github.com/bits-and-blooms/bitset v1.13.0 // indirect github.com/btcsuite/btcd/btcec/v2 v2.3.4 // indirect + github.com/bufbuild/protocompile v0.14.1 // indirect github.com/celestiaorg/blobstream-contracts/v3 v3.1.0 // indirect github.com/celestiaorg/merkletree v0.0.0-20230308153949-c33506a7aa26 // indirect github.com/cenkalti/backoff/v4 v4.3.0 // indirect @@ -122,7 +124,6 @@ require ( github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v6 v6.1.2 // indirect github.com/cosmos/ibc-go/v6 v6.3.0 // indirect github.com/cosmos/ledger-cosmos-go v0.13.2 // indirect - github.com/crate-crypto/go-ipa v0.0.0-20240223125850-b1e8a79f509c // indirect github.com/crate-crypto/go-kzg-4844 v1.0.0 // indirect github.com/creachadair/taskgroup v0.3.2 // indirect github.com/cskr/pubsub v1.0.2 // indirect @@ -135,14 +136,14 @@ require ( github.com/dgraph-io/badger/v2 v2.2007.4 // indirect github.com/dgraph-io/ristretto v0.1.1 // indirect github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13 // indirect + github.com/docker/go-connections v0.4.1-0.20210727194412-58542c764a11 // indirect github.com/docker/go-units v0.5.0 // indirect github.com/dustin/go-humanize v1.0.1 // indirect github.com/dvsekhvalnov/jose2go v1.6.0 // indirect github.com/elastic/gosigar v0.14.3 // indirect github.com/etclabscore/go-jsonschema-walk v0.0.6 // indirect github.com/ethereum/c-kzg-4844 v1.0.0 // indirect - github.com/ethereum/go-ethereum v1.14.11 // indirect - github.com/ethereum/go-verkle v0.1.1-0.20240829091221-dffa7562dbe9 // indirect + github.com/ethereum/go-ethereum v1.14.7 // indirect github.com/felixge/httpsnoop v1.0.4 // indirect github.com/flynn/noise v1.1.0 // indirect github.com/francoispqt/gojay v1.2.13 // indirect @@ -157,12 +158,12 @@ require ( github.com/go-openapi/jsonpointer v0.19.6 // indirect github.com/go-openapi/jsonreference v0.20.2 // indirect github.com/go-openapi/spec v0.19.11 // indirect - github.com/go-openapi/swag v0.22.3 // indirect + github.com/go-openapi/swag v0.22.4 // indirect github.com/go-task/slim-sprig/v3 v3.0.0 // indirect github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 // indirect github.com/godbus/dbus/v5 v5.1.0 // indirect github.com/gogo/gateway v1.1.0 // indirect - github.com/golang/glog v1.2.1 // indirect + github.com/golang/glog v1.2.2 // indirect github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect github.com/golang/protobuf v1.5.4 // indirect github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb // indirect @@ -196,7 +197,7 @@ require ( github.com/hashicorp/golang-lru/arc/v2 v2.0.7 // indirect github.com/hashicorp/hcl v1.0.0 // indirect github.com/hdevalence/ed25519consensus v0.0.0-20220222234857-c00d1f31bab3 // indirect - github.com/holiman/uint256 v1.3.1 // indirect + github.com/holiman/uint256 v1.3.0 // indirect github.com/huin/goupnp v1.3.0 // indirect github.com/iancoleman/orderedmap v0.2.0 // indirect github.com/improbable-eng/grpc-web v0.15.0 // indirect @@ -311,7 +312,7 @@ require ( github.com/wlynxg/anet v0.0.4 // indirect github.com/zondax/hid v0.9.2 // indirect github.com/zondax/ledger-go v0.14.3 // indirect - go.etcd.io/bbolt v1.3.6 // indirect + go.etcd.io/bbolt v1.3.10 // indirect go.opencensus.io v0.24.0 // indirect go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.49.0 // indirect go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.52.0 // indirect @@ -321,7 +322,7 @@ require ( go.uber.org/multierr v1.11.0 // indirect golang.org/x/mod v0.21.0 // indirect golang.org/x/net v0.28.0 // indirect - golang.org/x/oauth2 v0.21.0 // indirect + golang.org/x/oauth2 v0.22.0 // indirect golang.org/x/sys v0.25.0 // indirect golang.org/x/term v0.24.0 // indirect golang.org/x/time v0.5.0 // indirect @@ -330,7 +331,7 @@ require ( gonum.org/v1/gonum v0.15.0 // indirect google.golang.org/api v0.169.0 // indirect google.golang.org/genproto v0.0.0-20240227224415-6ceb2ff114de // indirect - google.golang.org/genproto/googleapis/api v0.0.0-20240617180043-68d350f18fd4 // indirect + google.golang.org/genproto/googleapis/api v0.0.0-20240814211410-ddb44dafa142 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1 // indirect gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect @@ -342,7 +343,9 @@ require ( ) replace ( - github.com/cosmos/cosmos-sdk => github.com/celestiaorg/cosmos-sdk v1.25.0-sdk-v0.46.16 + github.com/celestiaorg/celestia-app/v3 v3.0.0 => ../celestia-app + github.com/celestiaorg/go-square/v2 v2.0.0 => ../go-square + github.com/cosmos/cosmos-sdk => github.com/celestiaorg/cosmos-sdk v1.24.1-sdk-v0.46.16 github.com/filecoin-project/dagstore => github.com/celestiaorg/dagstore v0.0.0-20230824094345-537c012aa403 github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1 // broken goleveldb needs to be replaced for the cosmos-sdk and celestia-app diff --git a/go.sum b/go.sum index 199cd2a61f..2639195177 100644 --- a/go.sum +++ b/go.sum @@ -73,8 +73,8 @@ cloud.google.com/go/compute v1.6.0/go.mod h1:T29tfhtVbq1wvAPo0E3+7vhgmkOYeXjhFvz cloud.google.com/go/compute v1.6.1/go.mod h1:g85FgpzFvNULZ+S8AYq87axRKuf2Kh7deLqV/jJ3thU= cloud.google.com/go/compute v1.7.0/go.mod h1:435lt8av5oL9P3fv1OEzSbSUe+ybHXGMPQHHZWZxy9U= cloud.google.com/go/compute v1.10.0/go.mod h1:ER5CLbMxl90o2jtNbGSbtfOpQKR0t15FOtRsugnLrlU= -cloud.google.com/go/compute/metadata v0.3.0 h1:Tz+eQXMEqDIKRsmY3cHTL6FVaynIjX2QxYC4trgAKZc= -cloud.google.com/go/compute/metadata v0.3.0/go.mod h1:zFmK7XCadkQkj6TtorcaGlCW1hT1fIilQDwofLpJ20k= +cloud.google.com/go/compute/metadata v0.5.0 h1:Zr0eK8JbFv6+Wi4ilXAR8FJ3wyNdpxHKJNPos6LTZOY= +cloud.google.com/go/compute/metadata v0.5.0/go.mod h1:aHnloV2TPI38yx4s9+wAZhHykWvVCfu7hQbF+9CWoiY= cloud.google.com/go/containeranalysis v0.5.1/go.mod h1:1D92jd8gRR/c0fGMlymRgxWD3Qw9C1ff6/T7mLgVL8I= cloud.google.com/go/containeranalysis v0.6.0/go.mod h1:HEJoiEIu+lEXM+k7+qLCci0h33lX3ZqoYFdmPcoO7s4= cloud.google.com/go/datacatalog v1.3.0/go.mod h1:g9svFY6tuR+j+hrTw3J2dNcmI0dzmSiyOzm8kpLq0a0= @@ -229,6 +229,7 @@ github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible/go github.com/Masterminds/glide v0.13.2/go.mod h1:STyF5vcenH/rUqTEv+/hBXlSTo7KYwg2oc2f4tzPWic= github.com/Masterminds/semver v1.4.2/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y= github.com/Masterminds/vcs v1.13.0/go.mod h1:N09YCmOQr6RLxC6UNHzuVwAdodYbbnycGHSmwVJjcKA= +github.com/Microsoft/go-winio v0.4.14/go.mod h1:qXqCSQ3Xa7+6tgxaGTIe4Kpcdsi+P8jBhyzoq1bpyYA= github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY= github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU= github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5 h1:TngWCqHvy9oXAN6lEVMRuU21PR1EtLVZJmdB18Gu3Rw= @@ -344,12 +345,10 @@ github.com/c-bata/go-prompt v0.2.2/go.mod h1:VzqtzE2ksDBcdln8G7mk2RX9QyGjH+OVqOC github.com/casbin/casbin/v2 v2.1.2/go.mod h1:YcPU1XXisHhLzuxH9coDNf2FbKpjGlbCg3n9yuLkIJQ= github.com/celestiaorg/blobstream-contracts/v3 v3.1.0 h1:h1Y4V3EMQ2mFmNtWt2sIhZIuyASInj1a9ExI8xOsTOw= github.com/celestiaorg/blobstream-contracts/v3 v3.1.0/go.mod h1:x4DKyfKOSv1ZJM9NwV+Pw01kH2CD7N5zTFclXIVJ6GQ= -github.com/celestiaorg/celestia-app/v2 v2.3.0 h1:RHMw4z8ouTZV/p8f9G/zosKYI7aSm11AW9hsMAWcY1o= -github.com/celestiaorg/celestia-app/v2 v2.3.0/go.mod h1:jw08cXskzDYpOCH8uy5tdidgBdUwgXu/PLOt9AIigow= github.com/celestiaorg/celestia-core v1.42.0-tm-v0.34.35 h1:bWy5XOgeuuSLe0Lc/htL9/QLEURBjA1JTvEko6bEBhg= github.com/celestiaorg/celestia-core v1.42.0-tm-v0.34.35/go.mod h1:/fK0n3ps09t5uErBQe1QZbrE81L81MNUzWpFyWQLDT0= -github.com/celestiaorg/cosmos-sdk v1.25.0-sdk-v0.46.16 h1:f+fTe7GGk0/qgdzyqB8kk8EcDf9d6MC22khBTQiDXsU= -github.com/celestiaorg/cosmos-sdk v1.25.0-sdk-v0.46.16/go.mod h1:07Z8HJqS8Rw4XlZ+ok3D3NM/X/in8mvcGLvl0Zb5wrA= +github.com/celestiaorg/cosmos-sdk v1.24.1-sdk-v0.46.16 h1:SeQ7Y/CyOcUMKo7mQiexaj/pZ/xIgyuZFIwYZwpSkWE= +github.com/celestiaorg/cosmos-sdk v1.24.1-sdk-v0.46.16/go.mod h1:Bpl1LSWiDpQumgOhhMTZBMopqa0j7fRasIhvTZB44P0= github.com/celestiaorg/go-fraud v0.2.1 h1:oYhxI0gM/EpGRgbVQdRI/LSlqyT65g/WhQGSVGfx09w= github.com/celestiaorg/go-fraud v0.2.1/go.mod h1:lNY1i4K6kUeeE60Z2VK8WXd+qXb8KRzfBhvwPkK6aUc= github.com/celestiaorg/go-header v0.6.2 h1:qgWyJQg+/x6k4QAfN1rPt2HXHZjQOmCqD0ct4dFBIZY= @@ -364,8 +363,9 @@ github.com/celestiaorg/merkletree v0.0.0-20230308153949-c33506a7aa26 h1:P2RI1xJ4 github.com/celestiaorg/merkletree v0.0.0-20230308153949-c33506a7aa26/go.mod h1:2m8ukndOegwB0PU0AfJCwDUQHqd7QQRlSXvQL5VToVY= github.com/celestiaorg/nmt v0.22.1 h1:t7fqoP5MJ8mBns5DB2XjfcPxQpS3CKMkY+v+BEkDxYc= github.com/celestiaorg/nmt v0.22.1/go.mod h1:ia/EpCk0enD5yO5frcxoNoFToz2Ghtk2i+blmCRjIY8= -github.com/celestiaorg/rsmt2d v0.13.1 h1:eRhp79DKTkDojwInKVs1lRK6f6zJc1BVlmZfUfI19yQ= -github.com/celestiaorg/rsmt2d v0.13.1/go.mod h1:P7t92OATXbBmc/P5uR+GCOBv+PV8wLb0vU32ucrb148= +github.com/celestiaorg/nmt v0.22.2/go.mod h1:/7huDiSRL/d2EGhoiKctgSzmLOJoWG8yEfbFtY1+Mow= +github.com/celestiaorg/rsmt2d v0.14.0 h1:L7XJ3tRJDY8sQcvCjzHq0L7JmsmaSD+VItymIYFLqYc= +github.com/celestiaorg/rsmt2d v0.14.0/go.mod h1:4kxqiTdFev49sGiKXTDjohbWYOG5GlcIfftTgaBJnpc= github.com/cenkalti/backoff v2.2.1+incompatible h1:tNowT99t7UNflLxfYYSlKYsBpXdEet03Pg2g16Swow4= github.com/cenkalti/backoff v2.2.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM= github.com/cenkalti/backoff/v4 v4.1.1/go.mod h1:scbssz8iZGpm3xbr14ovlUdkxfGXNInqkPWOWmG2CLw= @@ -416,8 +416,8 @@ github.com/cockroachdb/fifo v0.0.0-20240606204812-0bbfbd93a7ce h1:giXvy4KSc/6g/e github.com/cockroachdb/fifo v0.0.0-20240606204812-0bbfbd93a7ce/go.mod h1:9/y3cnZ5GKakj/H4y9r9GTjCvAFta7KLgSHPJJYc52M= github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b h1:r6VH0faHjZeQy818SGhaone5OnYfxFR/+AzdY3sf5aE= github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b/go.mod h1:Vz9DsVWQQhf3vs21MhPMZpMGSht7O/2vFW2xusFUVOs= -github.com/cockroachdb/pebble v1.1.2 h1:CUh2IPtR4swHlEj48Rhfzw6l/d0qA31fItcIszQVIsA= -github.com/cockroachdb/pebble v1.1.2/go.mod h1:4exszw1r40423ZsmkG/09AFEG83I0uDgfujJdbL6kYU= +github.com/cockroachdb/pebble v1.1.1 h1:XnKU22oiCLy2Xn8vp1re67cXg4SAasg/WDt1NtcRFaw= +github.com/cockroachdb/pebble v1.1.1/go.mod h1:4exszw1r40423ZsmkG/09AFEG83I0uDgfujJdbL6kYU= github.com/cockroachdb/redact v1.1.5 h1:u1PMllDkdFfPWaNGMyLD1+so+aq3uUItthCFqzwPJ30= github.com/cockroachdb/redact v1.1.5/go.mod h1:BVNblN9mBWFyMyqK1k3AAiSxhvhfK2oOZZ2lK+dpvRg= github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 h1:zuQyyAKVxetITBuuhv3BI9cMrmStnpT18zmgmTxunpo= @@ -443,8 +443,8 @@ github.com/containerd/cgroups v0.0.0-20201119153540-4cbc285b3327/go.mod h1:ZJeTF github.com/containerd/cgroups v1.0.3/go.mod h1:/ofk34relqNjSGyqPrmEULrO4Sc8LJhvJmWbUCUKqj8= github.com/containerd/cgroups v1.1.0 h1:v8rEWFl6EoqHB+swVNjVoCJE8o3jX7e8nqBGPLaDFBM= github.com/containerd/cgroups v1.1.0/go.mod h1:6ppBcbh/NOOUU+dMKrykgaBnK9lCIBxHqJDGwsa1mIw= -github.com/containerd/continuity v0.3.0 h1:nisirsYROK15TAMVukJOUyGJjz4BNQJBVsNvAXZJ/eg= -github.com/containerd/continuity v0.3.0/go.mod h1:wJEAIwKOm/pBZuBd0JmeTvnLquTB1Ag8espWhkykbPM= +github.com/containerd/continuity v0.4.2 h1:v3y/4Yz5jwnvqPKJJ+7Wf93fyWoCB3F5EclWG023MDM= +github.com/containerd/continuity v0.4.2/go.mod h1:F6PTNCKepoxEaXLQp3wDAjygEnImnZ/7o4JzpodfroQ= github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk= github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= @@ -581,10 +581,10 @@ github.com/etclabscore/go-openrpc-reflect v0.0.37/go.mod h1:0404Ky3igAasAOpyj1eE github.com/ethereum/c-kzg-4844 v1.0.0 h1:0X1LBXxaEtYD9xsyj9B9ctQEZIpnvVDeoBx8aHEwTNA= github.com/ethereum/c-kzg-4844 v1.0.0/go.mod h1:VewdlzQmpT5QSrVhbBuGoCdFJkpaJlO1aQputP83wc0= github.com/ethereum/go-ethereum v1.10.17/go.mod h1:Lt5WzjM07XlXc95YzrhosmR4J9Ahd6X2wyEV2SvGhk0= -github.com/ethereum/go-ethereum v1.14.11 h1:8nFDCUUE67rPc6AKxFj7JKaOa2W/W1Rse3oS6LvvxEY= -github.com/ethereum/go-ethereum v1.14.11/go.mod h1:+l/fr42Mma+xBnhefL/+z11/hcmJ2egl+ScIVPjhc7E= -github.com/ethereum/go-verkle v0.1.1-0.20240829091221-dffa7562dbe9 h1:8NfxH2iXvJ60YRB8ChToFTUzl8awsc3cJ8CbLjGIl/A= -github.com/ethereum/go-verkle v0.1.1-0.20240829091221-dffa7562dbe9/go.mod h1:M3b90YRnzqKyyzBEWJGqj8Qff4IDeXnzFw0P9bFw3uk= +github.com/ethereum/go-ethereum v1.14.7 h1:EHpv3dE8evQmpVEQ/Ne2ahB06n2mQptdwqaMNhAT29g= +github.com/ethereum/go-ethereum v1.14.7/go.mod h1:Mq0biU2jbdmKSZoqOj29017ygFrMnB5/Rifwp980W4o= +github.com/ethereum/go-verkle v0.1.1-0.20240306133620-7d920df305f0 h1:KrE8I4reeVvf7C1tm8elRjj4BdscTYzz/WAbYyf/JI4= +github.com/ethereum/go-verkle v0.1.1-0.20240306133620-7d920df305f0/go.mod h1:D9AJLVXSyZQXJQVk8oh1EwjISE+sJTn2duYIZC0dy3w= github.com/facebookgo/ensure v0.0.0-20200202191622-63f1cf65ac4c h1:8ISkoahWXwZR41ois5lSJBSVw4D0OV19Ht/JSTzvSv0= github.com/facebookgo/ensure v0.0.0-20200202191622-63f1cf65ac4c/go.mod h1:Yg+htXGokKKdzcwhuNDwVvN+uBxDGXJ7G/VN1d8fa64= github.com/facebookgo/stack v0.0.0-20160209184415-751773369052 h1:JWuenKqqX8nojtoVVWjGfOF9635RETekkoH6Cc9SX0A= @@ -600,6 +600,8 @@ github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSw github.com/filecoin-project/go-jsonrpc v0.6.0 h1:/fFJIAN/k6EgY90m7qbyfY28woMwyseZmh2gVs5sYjY= github.com/filecoin-project/go-jsonrpc v0.6.0/go.mod h1:/n/niXcS4ZQua6i37LcVbY1TmlJR0UIK9mDFQq2ICek= github.com/fjl/memsize v0.0.0-20190710130421-bcb5799ab5e5/go.mod h1:VvhXpOYNQvB+uIk2RvXzuaQtkQJzzIx6lSBe1xv7hi0= +github.com/fjl/memsize v0.0.2 h1:27txuSD9or+NZlnOWdKUxeBzTAUkWCVh+4Gf2dWFOzA= +github.com/fjl/memsize v0.0.2/go.mod h1:VvhXpOYNQvB+uIk2RvXzuaQtkQJzzIx6lSBe1xv7hi0= github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc= github.com/flynn/noise v1.0.0/go.mod h1:xbMo+0i6+IGbYdJhF31t2eR1BIU0CYc12+BNAKwUTag= github.com/flynn/noise v1.1.0 h1:KjPQoQCEFdZDiP03phOvGi11+SVVhBG2wOWAorLsstg= @@ -685,8 +687,9 @@ github.com/go-openapi/swag v0.19.2/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk= github.com/go-openapi/swag v0.19.8/go.mod h1:ao+8BpOPyKdpQz3AOJfbeEVpLmWAvlT1IfTe5McPyhY= github.com/go-openapi/swag v0.19.11/go.mod h1:Uc0gKkdR+ojzsEpjh39QChyu92vPgIr72POcgHMAgSY= -github.com/go-openapi/swag v0.22.3 h1:yMBqmnQ0gyZvEb/+KzuWZOXgllrXT4SADYbvDaXHv/g= github.com/go-openapi/swag v0.22.3/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+VcZ0yl14= +github.com/go-openapi/swag v0.22.4 h1:QLMzNJnMGPRNDCbySlcj1x01tzU8/9LTTL9hZZZogBU= +github.com/go-openapi/swag v0.22.4/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+VcZ0yl14= github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8ceBS/t7Q= github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8= @@ -727,8 +730,8 @@ github.com/golang-jwt/jwt/v4 v4.5.0/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k= github.com/golang/geo v0.0.0-20190916061304-5b978397cfec/go.mod h1:QZ0nwyI2jOfgRAoBvP+ab5aRr7c9x7lhGEJrKvBwjWI= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= -github.com/golang/glog v1.2.1 h1:OptwRhECazUx5ix5TTWC3EZhsZEHWcYWY4FQHTIubm4= -github.com/golang/glog v1.2.1/go.mod h1:6AhwSGph0fcJtXVM/PEHPqZlFeoLxhs7/t5UDAwmO+w= +github.com/golang/glog v1.2.2 h1:1+mZ9upx1Dh6FmUTFR1naJ77miKiXgALjWOZ3NVFPmY= +github.com/golang/glog v1.2.2/go.mod h1:6AhwSGph0fcJtXVM/PEHPqZlFeoLxhs7/t5UDAwmO+w= github.com/golang/groupcache v0.0.0-20160516000752-02826c3e7903/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= @@ -969,8 +972,8 @@ github.com/holiman/billy v0.0.0-20240216141850-2abb0c79d3c4/go.mod h1:5GuXa7vkL8 github.com/holiman/bloomfilter/v2 v2.0.3 h1:73e0e/V0tCydx14a0SCYS/EWCxgwLZ18CZcZKVu0fao= github.com/holiman/bloomfilter/v2 v2.0.3/go.mod h1:zpoh+gs7qcpqrHr3dB55AMiJwo0iURXE7ZOP9L9hSkA= github.com/holiman/uint256 v1.2.0/go.mod h1:y4ga/t+u+Xwd7CpDgZESaRcWy0I7XMlTMA25ApIH5Jw= -github.com/holiman/uint256 v1.3.1 h1:JfTzmih28bittyHM8z360dCjIA9dbPIBlcTI6lmctQs= -github.com/holiman/uint256 v1.3.1/go.mod h1:EOMSn4q6Nyt9P6efbI3bueV4e1b3dGlUCXeiRV4ng7E= +github.com/holiman/uint256 v1.3.0 h1:4wdcm/tnd0xXdu7iS3ruNvxkWwrb4aeBQv19ayYn8F4= +github.com/holiman/uint256 v1.3.0/go.mod h1:EOMSn4q6Nyt9P6efbI3bueV4e1b3dGlUCXeiRV4ng7E= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/hudl/fargo v1.3.0/go.mod h1:y3CKSmjA+wD2gak7sUSXTAoopbhU08POFhmITJgmKTg= github.com/huin/goupnp v1.0.0/go.mod h1:n9v9KO1tAxYH82qOn+UTIFQDmx5n1Zxd/ClZDMX7Bnc= @@ -1511,8 +1514,8 @@ github.com/open-rpc/meta-schema v0.0.0-20201029221707-1b72ef2ea333 h1:CznVS40zms github.com/open-rpc/meta-schema v0.0.0-20201029221707-1b72ef2ea333/go.mod h1:Ag6rSXkHIckQmjFBCweJEEt1mrTPBv8b9W4aU/NQWfI= github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U= github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM= -github.com/opencontainers/image-spec v1.1.0-rc2.0.20221005185240-3a7f492d3f1b h1:YWuSjZCQAPM8UUBLkYUk1e+rZcvWHJmFb6i6rM44Xs8= -github.com/opencontainers/image-spec v1.1.0-rc2.0.20221005185240-3a7f492d3f1b/go.mod h1:3OVijpioIKYWTqjiG0zfF6wvoJ4fAXGbjdZuI2NgsRQ= +github.com/opencontainers/image-spec v1.1.0 h1:8SG7/vwALn54lVB/0yZ/MMwhFrPYtpEHQb2IpWsCzug= +github.com/opencontainers/image-spec v1.1.0/go.mod h1:W4s4sFTMaBeK1BQLXbG4AdM2szdn85PY75RI83NrTrM= github.com/opencontainers/runc v1.1.3 h1:vIXrkId+0/J2Ymu2m7VjGvbSlAId9XNRPhn2p4b+d8w= github.com/opencontainers/runc v1.1.3/go.mod h1:1J5XiS+vdZ3wCyZybsuxXZWGrgSr8fFJHLXuG2PsnNg= github.com/opencontainers/runtime-spec v1.0.2/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0= @@ -1736,6 +1739,7 @@ github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeV github.com/shurcooL/users v0.0.0-20180125191416-49c67e49c537/go.mod h1:QJTqeLYEDaXHZDBsXlPCDqdhQuJkuw4NOtaxYe3xii4= github.com/shurcooL/webdavfs v0.0.0-20170829043945-18c3829fa133/go.mod h1:hKmq5kWdCj2z2KEozexVbfEZIWiTjhE0+UjmZgPqehw= github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= +github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q= github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88= github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= @@ -1909,8 +1913,8 @@ gitlab.com/NebulousLabs/errors v0.0.0-20200929122200-06c536cf6975/go.mod h1:ZkMZ gitlab.com/NebulousLabs/fastrand v0.0.0-20181126182046-603482d69e40 h1:dizWJqTWjwyD8KGcMOwgrkqu1JIkofYgKkmDeNE7oAs= gitlab.com/NebulousLabs/fastrand v0.0.0-20181126182046-603482d69e40/go.mod h1:rOnSnoRyxMI3fe/7KIbVcsHRGxe30OONv8dEgo+vCfA= go.etcd.io/bbolt v1.3.3/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= -go.etcd.io/bbolt v1.3.6 h1:/ecaJf0sk1l4l6V4awd65v2C3ILy7MSj+s/x1ADCIMU= -go.etcd.io/bbolt v1.3.6/go.mod h1:qXsaaIqmgQH0T+OPdb99Bf+PKfBBQVAdyD6TY9G8XM4= +go.etcd.io/bbolt v1.3.10 h1:+BqfJTcCzTItrop8mq/lbzL8wSGtj94UO/3U31shqG0= +go.etcd.io/bbolt v1.3.10/go.mod h1:bK3UQLPJZly7IlNmV7uVHJDxfe5aK9Ll93e/74Y9oEQ= go.etcd.io/etcd v0.0.0-20191023171146-3cf2f69b5738/go.mod h1:dnLIgRNXwCJa5e+c6mIZCrds/GIG4ncV9HhK5PX7jPg= go.opencensus.io v0.18.0/go.mod h1:vKdFvxhtzZ9onBp9VKHK8z/sRpBMnKAsufL7wlDrCOA= go.opencensus.io v0.20.1/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk= @@ -2190,8 +2194,8 @@ golang.org/x/oauth2 v0.0.0-20220822191816-0ebed06d0094/go.mod h1:h4gKUeWbJ4rQPri golang.org/x/oauth2 v0.0.0-20220909003341-f21342109be1/go.mod h1:h4gKUeWbJ4rQPri7E0u6Gs4e9Ri2zaLxzw5DI5XGrYg= golang.org/x/oauth2 v0.0.0-20221014153046-6fdb5e3db783/go.mod h1:h4gKUeWbJ4rQPri7E0u6Gs4e9Ri2zaLxzw5DI5XGrYg= golang.org/x/oauth2 v0.1.0/go.mod h1:G9FE4dLTsbXUu90h/Pf85g4w1D+SSAgR+q46nJZ8M4A= -golang.org/x/oauth2 v0.21.0 h1:tsimM75w1tF/uws5rbeHzIWxEqElMehnc+iW793zsZs= -golang.org/x/oauth2 v0.21.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= +golang.org/x/oauth2 v0.22.0 h1:BzDx2FehcG7jJwgWLELCdmLuxk2i+x9UDpSiss2u0ZA= +golang.org/x/oauth2 v0.22.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= golang.org/x/perf v0.0.0-20180704124530-6e6d33e29852/go.mod h1:JLpeXjPJfIyPr5TlbXLkXWLhP8nz10XfvxElABhCtcw= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -2273,7 +2277,6 @@ golang.org/x/sys v0.0.0-20200803210538-64077c9b5642/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20200814200057-3d37ad5750ed/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200826173525-f9321e4c35a6/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200905004654-be1d3432aa8f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200923182605-d9f96fdee20d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201201145000-ef89a241ccb3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -2644,8 +2647,8 @@ google.golang.org/genproto v0.0.0-20221014213838-99cd37c6964a/go.mod h1:1vXfmgAz google.golang.org/genproto v0.0.0-20221025140454-527a21cfbd71/go.mod h1:9qHF0xnpdSfF6knlcsnpzUu5y+rpwgbvsyGAZPBMg4s= google.golang.org/genproto v0.0.0-20240227224415-6ceb2ff114de h1:F6qOa9AZTYJXOUEr4jDysRDLrm4PHePlge4v4TGAlxY= google.golang.org/genproto v0.0.0-20240227224415-6ceb2ff114de/go.mod h1:VUhTRKeHn9wwcdrk73nvdC9gF178Tzhmt/qyaFcPLSo= -google.golang.org/genproto/googleapis/api v0.0.0-20240617180043-68d350f18fd4 h1:MuYw1wJzT+ZkybKfaOXKp5hJiZDn2iHaXRw0mRYdHSc= -google.golang.org/genproto/googleapis/api v0.0.0-20240617180043-68d350f18fd4/go.mod h1:px9SlOOZBg1wM1zdnr8jEL4CNGUBZ+ZKYtNPApNQc4c= +google.golang.org/genproto/googleapis/api v0.0.0-20240814211410-ddb44dafa142 h1:wKguEg1hsxI2/L3hUYrpo1RVi48K+uTyzKqprwLXsb8= +google.golang.org/genproto/googleapis/api v0.0.0-20240814211410-ddb44dafa142/go.mod h1:d6be+8HhtEtucleCbxpPW9PA9XwISACu8nvpPqF0BVo= google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1 h1:pPJltXNxVzT4pK9yD8vR9X75DaWYYmLGMsEvBfFQZzQ= google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1/go.mod h1:UqMtugtsSgubUsoxbuAoiCXvqvErP7Gf0so0mK9tHxU= google.golang.org/grpc v1.14.0/go.mod h1:yo6s7OP7yaDglbqo1J04qKzAhqBH6lvTonzMVmEdcZw= @@ -2693,8 +2696,8 @@ google.golang.org/grpc v1.48.0/go.mod h1:vN9eftEi1UMyUsIF80+uQXhHjbXYbm0uXoFCACu google.golang.org/grpc v1.49.0/go.mod h1:ZgQEeidpAuNRZ8iRrlBKXZQP1ghovWIVhdJRyCDK+GI= google.golang.org/grpc v1.50.0/go.mod h1:ZgQEeidpAuNRZ8iRrlBKXZQP1ghovWIVhdJRyCDK+GI= google.golang.org/grpc v1.50.1/go.mod h1:ZgQEeidpAuNRZ8iRrlBKXZQP1ghovWIVhdJRyCDK+GI= -google.golang.org/grpc v1.66.2 h1:3QdXkuq3Bkh7w+ywLdLvM56cmGvQHUMZpiCzt6Rqaoo= -google.golang.org/grpc v1.66.2/go.mod h1:s3/l6xSSCURdVfAnL+TqCNMyTDAGN6+lZeVxnZR128Y= +google.golang.org/grpc v1.67.0 h1:IdH9y6PF5MPSdAntIcpjQ+tXO41pcQsfZV2RxtQgVcw= +google.golang.org/grpc v1.67.0/go.mod h1:1gLDyUQU7CTLJI90u3nXZ9ekeghjeM7pTDZlqFNg2AA= google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.1.0/go.mod h1:6Kw0yEErY5E/yWrBtf03jp27GLLJujG4z/JK95pnjjw= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= @@ -2713,6 +2716,7 @@ google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqw google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg= google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw= +google.golang.org/protobuf v1.35.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/header/header.go b/header/header.go index 669061044e..4db80d0ac3 100644 --- a/header/header.go +++ b/header/header.go @@ -11,8 +11,8 @@ import ( "github.com/tendermint/tendermint/light" core "github.com/tendermint/tendermint/types" - "github.com/celestiaorg/celestia-app/v2/pkg/appconsts" - "github.com/celestiaorg/celestia-app/v2/pkg/da" + "github.com/celestiaorg/celestia-app/v3/pkg/appconsts" + "github.com/celestiaorg/celestia-app/v3/pkg/da" libhead "github.com/celestiaorg/go-header" "github.com/celestiaorg/rsmt2d" ) diff --git a/header/headertest/fraud/testing.go b/header/headertest/fraud/testing.go index 5f4bdca084..0f3b8a11b5 100644 --- a/header/headertest/fraud/testing.go +++ b/header/headertest/fraud/testing.go @@ -10,14 +10,14 @@ import ( tmproto "github.com/tendermint/tendermint/proto/tendermint/types" "github.com/tendermint/tendermint/types" - "github.com/celestiaorg/celestia-app/v2/pkg/da" + "github.com/celestiaorg/celestia-app/v3/pkg/da" "github.com/celestiaorg/nmt" "github.com/celestiaorg/rsmt2d" "github.com/celestiaorg/celestia-node/header" "github.com/celestiaorg/celestia-node/header/headertest" - "github.com/celestiaorg/celestia-node/share/eds/edstest" - "github.com/celestiaorg/celestia-node/share/ipld" + "github.com/celestiaorg/celestia-node/square/eds/edstest" + "github.com/celestiaorg/celestia-node/square/ipld" "github.com/celestiaorg/celestia-node/store" ) diff --git a/header/headertest/testing.go b/header/headertest/testing.go index ddac1995a6..44d93c9db5 100644 --- a/header/headertest/testing.go +++ b/header/headertest/testing.go @@ -17,13 +17,13 @@ import ( "github.com/tendermint/tendermint/types" tmtime "github.com/tendermint/tendermint/types/time" - "github.com/celestiaorg/celestia-app/v2/pkg/da" + "github.com/celestiaorg/celestia-app/v3/pkg/da" libhead "github.com/celestiaorg/go-header" "github.com/celestiaorg/go-header/headertest" "github.com/celestiaorg/rsmt2d" "github.com/celestiaorg/celestia-node/header" - "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/square" ) // TestSuite provides everything you need to test chain of Headers. @@ -66,7 +66,7 @@ func NewTestSuite(t *testing.T, numValidators int, blockTime time.Duration) *Tes } func (s *TestSuite) genesis() *header.ExtendedHeader { - dah := share.EmptyEDSRoots() + dah := square.EmptyEDSRoots() gen := RandRawHeader(s.t) @@ -152,7 +152,7 @@ func (s *TestSuite) NextHeader() *header.ExtendedHeader { return s.head } - dah := share.EmptyEDSRoots() + dah := square.EmptyEDSRoots() height := s.Head().Height() + 1 rh := s.GenRawHeader(height, s.Head().Hash(), libhead.Hash(s.Head().Commit.Hash()), dah.Hash()) s.head = &header.ExtendedHeader{ @@ -229,7 +229,7 @@ func RandExtendedHeader(t testing.TB) *header.ExtendedHeader { } func RandExtendedHeaderAtTimestamp(t testing.TB, timestamp time.Time) *header.ExtendedHeader { - dah := share.EmptyEDSRoots() + dah := square.EmptyEDSRoots() rh := RandRawHeader(t) rh.DataHash = dah.Hash() @@ -328,7 +328,7 @@ func ExtendedHeadersFromEdsses(t testing.TB, edsses []*rsmt2d.ExtendedDataSquare for i, eds := range edsses { gen := RandRawHeader(t) - roots, err := share.NewAxisRoots(eds) + roots, err := square.NewAxisRoots(eds) require.NoError(t, err) gen.DataHash = roots.Hash() gen.ValidatorsHash = valSet.Hash() @@ -358,7 +358,7 @@ func ExtendedHeadersFromEdsses(t testing.TB, edsses []*rsmt2d.ExtendedDataSquare func ExtendedHeaderFromEDS(t testing.TB, height uint64, eds *rsmt2d.ExtendedDataSquare) *header.ExtendedHeader { valSet, vals := RandValidatorSet(10, 10) gen := RandRawHeader(t) - dah, err := share.NewAxisRoots(eds) + dah, err := square.NewAxisRoots(eds) require.NoError(t, err) gen.DataHash = dah.Hash() diff --git a/header/headertest/validate_test.go b/header/headertest/validate_test.go index d7c6e4b1cc..f569f0d6e0 100644 --- a/header/headertest/validate_test.go +++ b/header/headertest/validate_test.go @@ -10,7 +10,7 @@ import ( tmproto "github.com/tendermint/tendermint/proto/tendermint/types" "github.com/tendermint/tendermint/types" - "github.com/celestiaorg/celestia-app/v2/pkg/da" + "github.com/celestiaorg/celestia-app/v3/pkg/da" "github.com/celestiaorg/celestia-node/header" ) @@ -30,7 +30,11 @@ func TestValidate(t *testing.T) { }, { extendedHeader: getExtendedHeader(t, 3), - wantErr: "has version 3, this node supports up to version 2. " + + wantErr: "", + }, + { + extendedHeader: getExtendedHeader(t, 4), + wantErr: "has version 4, this node supports up to version 3. " + "Please upgrade to support new version. Note, 0 is not a valid version", }, } diff --git a/header/pb/extended_header.pb.go b/header/pb/extended_header.pb.go index 03ca6cba06..b1c989532a 100644 --- a/header/pb/extended_header.pb.go +++ b/header/pb/extended_header.pb.go @@ -5,7 +5,7 @@ package header_pb import ( fmt "fmt" - da "github.com/celestiaorg/celestia-app/v2/proto/celestia/core/v1/da" + da "github.com/celestiaorg/celestia-app/v3/proto/celestia/core/v1/da" proto "github.com/gogo/protobuf/proto" types "github.com/tendermint/tendermint/proto/tendermint/types" io "io" diff --git a/header/pb/extended_header.proto b/header/pb/extended_header.proto index aafb575327..e93b64d862 100644 --- a/header/pb/extended_header.proto +++ b/header/pb/extended_header.proto @@ -4,13 +4,13 @@ package header.pb; import "tendermint/types/types.proto"; import "tendermint/types/validator.proto"; -import "celestia/da/data_availability_header.proto"; +import "celestia/core/v1/da/data_availability_header.proto"; message ExtendedHeader { tendermint.types.Header header = 1; tendermint.types.Commit commit = 2; tendermint.types.ValidatorSet validator_set = 3; - celestia.da.DataAvailabilityHeader dah = 4; + celestia.core.v1.da.DataAvailabilityHeader dah = 4; } // Generated with: diff --git a/header/serde.go b/header/serde.go index fae310457b..8c5412ec81 100644 --- a/header/serde.go +++ b/header/serde.go @@ -5,7 +5,7 @@ import ( core "github.com/tendermint/tendermint/types" "golang.org/x/crypto/blake2b" - "github.com/celestiaorg/celestia-app/v2/pkg/da" + "github.com/celestiaorg/celestia-app/v3/pkg/da" header_pb "github.com/celestiaorg/celestia-node/header/pb" ) diff --git a/libs/edssser/edssser.go b/libs/edssser/edssser.go index dfb01e1756..2c0ad624a4 100644 --- a/libs/edssser/edssser.go +++ b/libs/edssser/edssser.go @@ -9,8 +9,8 @@ import ( "testing" "time" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/eds/edstest" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/eds/edstest" "github.com/celestiaorg/celestia-node/store" ) @@ -148,13 +148,13 @@ func (ss *EDSsser) put(ctx context.Context, t *testing.T, height int) (time.Dura defer cancel() // divide by 2 to get ODS size as expected by RandEDS - square := edstest.RandEDS(t, ss.config.EDSSize/2) - roots, err := share.NewAxisRoots(square) + dataSquare := edstest.RandEDS(t, ss.config.EDSSize/2) + roots, err := square.NewAxisRoots(dataSquare) if err != nil { return 0, err } now := time.Now() - err = ss.edsstore.PutODSQ4(ctx, roots, uint64(height), square) + err = ss.edsstore.PutODSQ4(ctx, roots, uint64(height), dataSquare) return time.Since(now), err } diff --git a/libs/keystore/map_keystore.go b/libs/keystore/map_keystore.go index 9efd21f88b..b6355ed85c 100644 --- a/libs/keystore/map_keystore.go +++ b/libs/keystore/map_keystore.go @@ -6,8 +6,8 @@ import ( "github.com/cosmos/cosmos-sdk/crypto/keyring" - "github.com/celestiaorg/celestia-app/v2/app" - "github.com/celestiaorg/celestia-app/v2/app/encoding" + "github.com/celestiaorg/celestia-app/v3/app" + "github.com/celestiaorg/celestia-app/v3/app/encoding" ) // mapKeystore is a simple in-memory Keystore implementation. diff --git a/nodebuilder/blob/blob.go b/nodebuilder/blob/blob.go index b93257e8d9..3d14a3487d 100644 --- a/nodebuilder/blob/blob.go +++ b/nodebuilder/blob/blob.go @@ -3,8 +3,9 @@ package blob import ( "context" + "github.com/celestiaorg/go-square/v2/share" + "github.com/celestiaorg/celestia-node/blob" - "github.com/celestiaorg/celestia-node/share" ) var _ Module = (*API)(nil) diff --git a/nodebuilder/blob/cmd/blob.go b/nodebuilder/blob/cmd/blob.go index 5e57f91e0d..527ac9b2d7 100644 --- a/nodebuilder/blob/cmd/blob.go +++ b/nodebuilder/blob/cmd/blob.go @@ -11,10 +11,11 @@ import ( "github.com/spf13/cobra" + "github.com/celestiaorg/go-square/v2/share" + "github.com/celestiaorg/celestia-node/blob" cmdnode "github.com/celestiaorg/celestia-node/cmd" state "github.com/celestiaorg/celestia-node/nodebuilder/state/cmd" - "github.com/celestiaorg/celestia-node/share" ) // flagFileInput allows the user to provide file path to the json file @@ -285,8 +286,8 @@ func formatData(ns string) func(interface{}) interface{} { for i, b := range blobs { result[i] = tempBlob{ Namespace: ns, - Data: string(b.Data), - ShareVersion: b.ShareVersion, + Data: string(b.Data()), + ShareVersion: uint32(b.ShareVersion()), Commitment: "0x" + hex.EncodeToString(b.Commitment), Index: b.Index(), } @@ -297,8 +298,8 @@ func formatData(ns string) func(interface{}) interface{} { b := data.(*blob.Blob) return tempBlob{ Namespace: ns, - Data: string(b.Data), - ShareVersion: b.ShareVersion, + Data: string(b.Data()), + ShareVersion: uint32(b.ShareVersion()), Commitment: "0x" + hex.EncodeToString(b.Commitment), Index: b.Index(), } diff --git a/nodebuilder/blob/mocks/api.go b/nodebuilder/blob/mocks/api.go index 786fe7d7fb..a7c1d7d909 100644 --- a/nodebuilder/blob/mocks/api.go +++ b/nodebuilder/blob/mocks/api.go @@ -9,8 +9,8 @@ import ( reflect "reflect" blob "github.com/celestiaorg/celestia-node/blob" - share "github.com/celestiaorg/celestia-node/share" state "github.com/celestiaorg/celestia-node/state" + share "github.com/celestiaorg/go-square/v2/share" gomock "github.com/golang/mock/gomock" ) diff --git a/nodebuilder/blob/module.go b/nodebuilder/blob/module.go index cf07ed3732..d62624adf8 100644 --- a/nodebuilder/blob/module.go +++ b/nodebuilder/blob/module.go @@ -9,7 +9,7 @@ import ( "github.com/celestiaorg/celestia-node/header" headerService "github.com/celestiaorg/celestia-node/nodebuilder/header" "github.com/celestiaorg/celestia-node/nodebuilder/state" - "github.com/celestiaorg/celestia-node/share/shwap" + "github.com/celestiaorg/celestia-node/square/shwap" ) func ConstructModule() fx.Option { diff --git a/nodebuilder/core/module.go b/nodebuilder/core/module.go index 441907ce32..f186d724c2 100644 --- a/nodebuilder/core/module.go +++ b/nodebuilder/core/module.go @@ -12,7 +12,7 @@ import ( "github.com/celestiaorg/celestia-node/libs/fxutil" "github.com/celestiaorg/celestia-node/nodebuilder/node" "github.com/celestiaorg/celestia-node/nodebuilder/p2p" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrexsub" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrexsub" "github.com/celestiaorg/celestia-node/store" ) diff --git a/nodebuilder/da/service.go b/nodebuilder/da/service.go index b4b8388b17..b9a87a629c 100644 --- a/nodebuilder/da/service.go +++ b/nodebuilder/da/service.go @@ -10,12 +10,12 @@ import ( logging "github.com/ipfs/go-log/v2" "github.com/rollkit/go-da" - "github.com/celestiaorg/celestia-app/v2/pkg/appconsts" + "github.com/celestiaorg/celestia-app/v3/pkg/appconsts" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/celestia-node/blob" "github.com/celestiaorg/celestia-node/header" nodeblob "github.com/celestiaorg/celestia-node/nodebuilder/blob" - "github.com/celestiaorg/celestia-node/share" "github.com/celestiaorg/celestia-node/state" ) @@ -68,23 +68,32 @@ func (s *Service) Get(ctx context.Context, ids []da.ID, ns da.Namespace) ([]da.B blobs := make([]da.Blob, 0, len(ids)) for _, id := range ids { height, commitment := SplitID(id) - log.Debugw("getting blob", "height", height, "commitment", commitment, "namespace", share.Namespace(ns)) - currentBlob, err := s.blobServ.Get(ctx, height, ns, commitment) - log.Debugw("got blob", "height", height, "commitment", commitment, "namespace", share.Namespace(ns)) + namespace, err := share.NewNamespaceFromBytes(ns) if err != nil { return nil, err } - blobs = append(blobs, currentBlob.Data) + log.Debugw("getting blob", "height", height, "commitment", commitment, "namespace", namespace) + currentBlob, err := s.blobServ.Get(ctx, height, namespace, commitment) + log.Debugw("got blob", "height", height, "commitment", commitment, "namespace", namespace) + if err != nil { + return nil, err + } + blobs = append(blobs, currentBlob.Data()) } return blobs, nil } // GetIDs returns IDs of all Blobs located in DA at given height. func (s *Service) GetIDs(ctx context.Context, height uint64, namespace da.Namespace) (*da.GetIDsResult, error) { + ns, err := share.NewNamespaceFromBytes(namespace) + if err != nil { + return nil, err + } + var ids []da.ID //nolint:prealloc - log.Debugw("getting ids", "height", height, "namespace", share.Namespace(namespace)) - blobs, err := s.blobServ.GetAll(ctx, height, []share.Namespace{namespace}) - log.Debugw("got ids", "height", height, "namespace", share.Namespace(namespace)) + log.Debugw("getting ids", "height", height, "namespace", ns) + blobs, err := s.blobServ.GetAll(ctx, height, []share.Namespace{ns}) + log.Debugw("got ids", "height", height, "namespace", ns) if err != nil { if strings.Contains(err.Error(), blob.ErrBlobNotFound.Error()) { return nil, nil //nolint:nilnil @@ -105,8 +114,12 @@ func (s *Service) GetIDs(ctx context.Context, height uint64, namespace da.Namesp func (s *Service) GetProofs(ctx context.Context, ids []da.ID, namespace da.Namespace) ([]da.Proof, error) { proofs := make([]da.Proof, len(ids)) for i, id := range ids { + ns, err := share.NewNamespaceFromBytes(namespace) + if err != nil { + return nil, err + } height, commitment := SplitID(id) - proof, err := s.blobServ.GetProof(ctx, height, namespace, commitment) + proof, err := s.blobServ.GetProof(ctx, height, ns, commitment) if err != nil { return nil, err } @@ -200,7 +213,11 @@ func (s *Service) blobsAndCommitments( blobs := make([]*blob.Blob, 0, len(daBlobs)) commitments := make([]da.Commitment, 0, len(daBlobs)) for _, daBlob := range daBlobs { - b, err := blob.NewBlobV0(namespace, daBlob) + ns, err := share.NewNamespaceFromBytes(namespace) + if err != nil { + return nil, nil, err + } + b, err := blob.NewBlobV0(ns, daBlob) if err != nil { return nil, nil, err } @@ -230,13 +247,17 @@ func (s *Service) Validate( proofs[i] = blobProof } for i, id := range ids { + ns, err := share.NewNamespaceFromBytes(namespace) + if err != nil { + return nil, err + } height, commitment := SplitID(id) // TODO(tzdybal): for some reason, if proof doesn't match commitment, API returns (false, "blob: // invalid proof") but analysis of the code in celestia-node implies this should never happen - // maybe it's caused by openrpc? there is no way of gently handling errors here, but returned // value is fine for us fmt.Println("proof", proofs[i] == nil, "commitment", commitment == nil) - isIncluded, _ := s.blobServ.Included(ctx, height, namespace, proofs[i], commitment) + isIncluded, _ := s.blobServ.Included(ctx, height, ns, proofs[i], commitment) included[i] = isIncluded } return included, nil diff --git a/nodebuilder/das/constructors.go b/nodebuilder/das/constructors.go index 8d6f9d1168..c3c7602740 100644 --- a/nodebuilder/das/constructors.go +++ b/nodebuilder/das/constructors.go @@ -13,9 +13,9 @@ import ( "github.com/celestiaorg/celestia-node/header" modfraud "github.com/celestiaorg/celestia-node/nodebuilder/fraud" "github.com/celestiaorg/celestia-node/pruner" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/eds/byzantine" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrexsub" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/eds/byzantine" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrexsub" ) var _ Module = (*daserStub)(nil) @@ -39,7 +39,7 @@ func newDaserStub() Module { } func newDASer( - da share.Availability, + da square.Availability, hsub libhead.Subscriber[*header.ExtendedHeader], store libhead.Store[*header.ExtendedHeader], batching datastore.Batching, diff --git a/nodebuilder/fraud/unmarshaler.go b/nodebuilder/fraud/unmarshaler.go index d5e0461f01..e5cf07272e 100644 --- a/nodebuilder/fraud/unmarshaler.go +++ b/nodebuilder/fraud/unmarshaler.go @@ -4,7 +4,7 @@ import ( "github.com/celestiaorg/go-fraud" "github.com/celestiaorg/celestia-node/header" - "github.com/celestiaorg/celestia-node/share/eds/byzantine" + "github.com/celestiaorg/celestia-node/square/eds/byzantine" ) var defaultProofUnmarshaler proofRegistry diff --git a/nodebuilder/header/constructors.go b/nodebuilder/header/constructors.go index 23947a8338..04e36d27ec 100644 --- a/nodebuilder/header/constructors.go +++ b/nodebuilder/header/constructors.go @@ -18,7 +18,7 @@ import ( modfraud "github.com/celestiaorg/celestia-node/nodebuilder/fraud" modp2p "github.com/celestiaorg/celestia-node/nodebuilder/p2p" - "github.com/celestiaorg/celestia-node/share/eds/byzantine" + "github.com/celestiaorg/celestia-node/square/eds/byzantine" ) // newP2PExchange constructs a new Exchange for headers. diff --git a/nodebuilder/init.go b/nodebuilder/init.go index 6c0854ff91..9194a092e0 100644 --- a/nodebuilder/init.go +++ b/nodebuilder/init.go @@ -10,8 +10,8 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/gofrs/flock" - "github.com/celestiaorg/celestia-app/v2/app" - "github.com/celestiaorg/celestia-app/v2/app/encoding" + "github.com/celestiaorg/celestia-app/v3/app" + "github.com/celestiaorg/celestia-app/v3/app/encoding" "github.com/celestiaorg/celestia-node/libs/utils" "github.com/celestiaorg/celestia-node/nodebuilder/node" diff --git a/nodebuilder/init_test.go b/nodebuilder/init_test.go index 99c93d7878..2058a00574 100644 --- a/nodebuilder/init_test.go +++ b/nodebuilder/init_test.go @@ -11,8 +11,8 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/celestiaorg/celestia-app/v2/app" - "github.com/celestiaorg/celestia-app/v2/app/encoding" + "github.com/celestiaorg/celestia-app/v3/app" + "github.com/celestiaorg/celestia-app/v3/app/encoding" "github.com/celestiaorg/celestia-node/nodebuilder/node" ) diff --git a/nodebuilder/node_test.go b/nodebuilder/node_test.go index 8155d7e081..91c057b69c 100644 --- a/nodebuilder/node_test.go +++ b/nodebuilder/node_test.go @@ -17,7 +17,7 @@ import ( "github.com/celestiaorg/celestia-node/header/headertest" "github.com/celestiaorg/celestia-node/nodebuilder/node" - "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/square" ) func TestLifecycle(t *testing.T) { @@ -147,7 +147,7 @@ func TestEmptyBlockExists(t *testing.T) { // ensure an empty block exists in store - eh := headertest.RandExtendedHeaderWithRoot(t, share.EmptyEDSRoots()) + eh := headertest.RandExtendedHeaderWithRoot(t, square.EmptyEDSRoots()) err = node.ShareServ.SharesAvailable(ctx, eh) require.NoError(t, err) diff --git a/nodebuilder/p2p/module.go b/nodebuilder/p2p/module.go index 9538ce03a5..8c819373ae 100644 --- a/nodebuilder/p2p/module.go +++ b/nodebuilder/p2p/module.go @@ -6,7 +6,7 @@ import ( "go.uber.org/fx" "github.com/celestiaorg/celestia-node/nodebuilder/node" - "github.com/celestiaorg/celestia-node/share/ipld" + "github.com/celestiaorg/celestia-node/square/ipld" ) var log = logging.Logger("module/p2p") diff --git a/nodebuilder/p2p/routing.go b/nodebuilder/p2p/routing.go index 53f5377524..65a8a17da2 100644 --- a/nodebuilder/p2p/routing.go +++ b/nodebuilder/p2p/routing.go @@ -10,7 +10,7 @@ import ( "go.uber.org/fx" "github.com/celestiaorg/celestia-node/nodebuilder/node" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/discovery" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/discovery" ) func newDHT( diff --git a/nodebuilder/share/bitswap.go b/nodebuilder/share/bitswap.go index 9316075dfe..26784689ff 100644 --- a/nodebuilder/share/bitswap.go +++ b/nodebuilder/share/bitswap.go @@ -16,7 +16,7 @@ import ( "github.com/celestiaorg/celestia-node/nodebuilder/node" "github.com/celestiaorg/celestia-node/nodebuilder/p2p" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/bitswap" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/bitswap" "github.com/celestiaorg/celestia-node/store" ) diff --git a/nodebuilder/share/cmd/share.go b/nodebuilder/share/cmd/share.go index 1eb21a045f..8ec42a510a 100644 --- a/nodebuilder/share/cmd/share.go +++ b/nodebuilder/share/cmd/share.go @@ -8,10 +8,11 @@ import ( "github.com/spf13/cobra" + "github.com/celestiaorg/go-square/v2/share" + rpc "github.com/celestiaorg/celestia-node/api/rpc/client" cmdnode "github.com/celestiaorg/celestia-node/cmd" "github.com/celestiaorg/celestia-node/header" - "github.com/celestiaorg/celestia-node/share" ) func init() { @@ -127,14 +128,14 @@ var getShare = &cobra.Command{ return data } - ns := hex.EncodeToString(share.GetNamespace(sh)) + ns := hex.EncodeToString(sh.Namespace().Bytes()) return struct { Namespace string `json:"namespace"` Data []byte `json:"data"` }{ Namespace: ns, - Data: share.GetData(sh), + Data: sh.RawData(), } } return cmdnode.PrintOutput(s, err, formatter) diff --git a/nodebuilder/share/config.go b/nodebuilder/share/config.go index 31f2eda5a3..4142925a11 100644 --- a/nodebuilder/share/config.go +++ b/nodebuilder/share/config.go @@ -4,11 +4,11 @@ import ( "fmt" "github.com/celestiaorg/celestia-node/nodebuilder/node" - "github.com/celestiaorg/celestia-node/share/availability/light" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/discovery" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/peers" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrexeds" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrexnd" + "github.com/celestiaorg/celestia-node/square/availability/light" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/discovery" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/peers" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrexeds" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrexnd" "github.com/celestiaorg/celestia-node/store" ) diff --git a/nodebuilder/share/constructors.go b/nodebuilder/share/constructors.go index 62e37477e6..6637ffac24 100644 --- a/nodebuilder/share/constructors.go +++ b/nodebuilder/share/constructors.go @@ -7,15 +7,15 @@ import ( headerServ "github.com/celestiaorg/celestia-node/nodebuilder/header" "github.com/celestiaorg/celestia-node/pruner" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/shwap" - "github.com/celestiaorg/celestia-node/share/shwap/getters" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/bitswap" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrex_getter" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/shwap" + "github.com/celestiaorg/celestia-node/square/shwap/getters" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/bitswap" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrex_getter" "github.com/celestiaorg/celestia-node/store" ) -func newShareModule(getter shwap.Getter, avail share.Availability, header headerServ.Module) Module { +func newShareModule(getter shwap.Getter, avail square.Availability, header headerServ.Module) Module { return &module{getter, avail, header} } diff --git a/nodebuilder/share/mocks/api.go b/nodebuilder/share/mocks/api.go index 682d5d8d48..1498be402a 100644 --- a/nodebuilder/share/mocks/api.go +++ b/nodebuilder/share/mocks/api.go @@ -10,7 +10,7 @@ import ( header "github.com/celestiaorg/celestia-node/header" share "github.com/celestiaorg/celestia-node/nodebuilder/share" - share0 "github.com/celestiaorg/celestia-node/share" + share0 "github.com/celestiaorg/celestia-node/square" rsmt2d "github.com/celestiaorg/rsmt2d" gomock "github.com/golang/mock/gomock" ) diff --git a/nodebuilder/share/module.go b/nodebuilder/share/module.go index f02b4632b5..ac73a681e3 100644 --- a/nodebuilder/share/module.go +++ b/nodebuilder/share/module.go @@ -12,15 +12,15 @@ import ( "github.com/celestiaorg/celestia-node/nodebuilder/node" modp2p "github.com/celestiaorg/celestia-node/nodebuilder/p2p" lightprune "github.com/celestiaorg/celestia-node/pruner/light" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/availability/full" - "github.com/celestiaorg/celestia-node/share/availability/light" - "github.com/celestiaorg/celestia-node/share/shwap" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/peers" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrex_getter" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrexeds" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrexnd" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrexsub" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/availability/full" + "github.com/celestiaorg/celestia-node/square/availability/light" + "github.com/celestiaorg/celestia-node/square/shwap" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/peers" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrex_getter" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrexeds" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrexnd" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrexsub" "github.com/celestiaorg/celestia-node/store" ) @@ -233,14 +233,14 @@ func availabilityComponents(tp node.Type, cfg *Config) fx.Option { return la.Close(ctx) }), )), - fx.Provide(func(avail *light.ShareAvailability) share.Availability { + fx.Provide(func(avail *light.ShareAvailability) square.Availability { return avail }), ) case node.Bridge, node.Full: return fx.Options( fx.Provide(full.NewShareAvailability), - fx.Provide(func(avail *full.ShareAvailability) share.Availability { + fx.Provide(func(avail *full.ShareAvailability) square.Availability { return avail }), ) diff --git a/nodebuilder/share/opts.go b/nodebuilder/share/opts.go index cfea26dbb4..0510c1f11b 100644 --- a/nodebuilder/share/opts.go +++ b/nodebuilder/share/opts.go @@ -3,11 +3,11 @@ package share import ( "errors" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/discovery" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/peers" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrex_getter" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrexeds" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrexnd" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/discovery" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/peers" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrex_getter" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrexeds" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrexnd" "github.com/celestiaorg/celestia-node/store" ) diff --git a/nodebuilder/share/p2p_constructors.go b/nodebuilder/share/p2p_constructors.go index 576db73c97..b505f42e20 100644 --- a/nodebuilder/share/p2p_constructors.go +++ b/nodebuilder/share/p2p_constructors.go @@ -14,9 +14,9 @@ import ( "github.com/celestiaorg/celestia-node/header" "github.com/celestiaorg/celestia-node/nodebuilder/node" modprune "github.com/celestiaorg/celestia-node/nodebuilder/pruner" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/discovery" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/peers" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrexsub" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/discovery" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/peers" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrexsub" ) const ( diff --git a/nodebuilder/share/share.go b/nodebuilder/share/share.go index 0c4798ecdb..701180474c 100644 --- a/nodebuilder/share/share.go +++ b/nodebuilder/share/share.go @@ -5,14 +5,15 @@ import ( "github.com/tendermint/tendermint/types" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt" "github.com/celestiaorg/rsmt2d" "github.com/celestiaorg/celestia-node/header" headerServ "github.com/celestiaorg/celestia-node/nodebuilder/header" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/eds" - "github.com/celestiaorg/celestia-node/share/shwap" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/eds" + "github.com/celestiaorg/celestia-node/square/shwap" ) var _ Module = (*API)(nil) @@ -109,7 +110,7 @@ func (api *API) GetSharesByNamespace( type module struct { shwap.Getter - share.Availability + square.Availability hs headerServ.Module } @@ -131,9 +132,14 @@ func (m module) GetRange(ctx context.Context, height uint64, start, end int) (*G if err != nil { return nil, err } + + shares, err := share.FromBytes(extendedDataSquare.FlattenedODS()[start:end]) + if err != nil { + return nil, err + } return &GetRangeResult{ - extendedDataSquare.FlattenedODS()[start:end], - proof, + Shares: shares, + Proof: proof, }, nil } diff --git a/nodebuilder/state/core.go b/nodebuilder/state/core.go index 39ab732368..f377fe4c6a 100644 --- a/nodebuilder/state/core.go +++ b/nodebuilder/state/core.go @@ -10,7 +10,7 @@ import ( "github.com/celestiaorg/celestia-node/nodebuilder/core" modfraud "github.com/celestiaorg/celestia-node/nodebuilder/fraud" "github.com/celestiaorg/celestia-node/nodebuilder/p2p" - "github.com/celestiaorg/celestia-node/share/eds/byzantine" + "github.com/celestiaorg/celestia-node/square/eds/byzantine" "github.com/celestiaorg/celestia-node/state" ) diff --git a/nodebuilder/store.go b/nodebuilder/store.go index e9a33d122e..e778e9924e 100644 --- a/nodebuilder/store.go +++ b/nodebuilder/store.go @@ -17,10 +17,11 @@ import ( dsbadger "github.com/ipfs/go-ds-badger4" "github.com/mitchellh/go-homedir" + "github.com/celestiaorg/go-square/v2/share" + "github.com/celestiaorg/celestia-node/libs/keystore" nodemod "github.com/celestiaorg/celestia-node/nodebuilder/node" "github.com/celestiaorg/celestia-node/nodebuilder/p2p" - "github.com/celestiaorg/celestia-node/share" ) var ( @@ -278,7 +279,7 @@ func constraintBadgerConfig() *dsbadger.Options { // 2mib default => share.Size - makes sure headers and samples are stored in value log // This *tremendously* reduces the amount of memory used by the node, up to 10 times less during // compaction - opts.ValueThreshold = share.Size + opts.ValueThreshold = share.ShareSize // make sure we don't have any limits for stored headers opts.ValueLogMaxEntries = 100000000 // run value log GC more often to spread the work over time diff --git a/nodebuilder/tests/api_test.go b/nodebuilder/tests/api_test.go index 0a4839345e..09318988fd 100644 --- a/nodebuilder/tests/api_test.go +++ b/nodebuilder/tests/api_test.go @@ -111,9 +111,10 @@ func TestBlobRPC(t *testing.T) { require.NoError(t, err) newBlob, err := blob.NewBlob( - uint8(appBlobs[0].GetShareVersion()), - appBlobs[0].Namespace().Bytes(), - appBlobs[0].GetData(), + appBlobs[0].ShareVersion(), + appBlobs[0].Namespace(), + appBlobs[0].Data(), + appBlobs[0].Signer(), ) require.NoError(t, err) diff --git a/nodebuilder/tests/blob_test.go b/nodebuilder/tests/blob_test.go index bd3c94847a..590aed2166 100644 --- a/nodebuilder/tests/blob_test.go +++ b/nodebuilder/tests/blob_test.go @@ -13,13 +13,12 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - squareblob "github.com/celestiaorg/go-square/blob" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/celestia-node/blob" "github.com/celestiaorg/celestia-node/blob/blobtest" "github.com/celestiaorg/celestia-node/nodebuilder/node" "github.com/celestiaorg/celestia-node/nodebuilder/tests/swamp" - "github.com/celestiaorg/celestia-node/share" "github.com/celestiaorg/celestia-node/state" ) @@ -204,6 +203,6 @@ func TestBlobModule(t *testing.T) { // convert converts a squareblob.Blob to a blob.Blob. // convert may be deduplicated with convertBlobs from the blob package. -func convert(squareBlob *squareblob.Blob) (nodeBlob *blob.Blob, err error) { - return blob.NewBlob(uint8(squareBlob.GetShareVersion()), squareBlob.Namespace().Bytes(), squareBlob.GetData()) +func convert(squareBlob *share.Blob) (nodeBlob *blob.Blob, err error) { + return blob.NewBlob(squareBlob.ShareVersion(), squareBlob.Namespace(), squareBlob.Data(), squareBlob.Signer()) } diff --git a/nodebuilder/tests/da_test.go b/nodebuilder/tests/da_test.go index 9bbdff2b2e..63961e379f 100644 --- a/nodebuilder/tests/da_test.go +++ b/nodebuilder/tests/da_test.go @@ -12,14 +12,14 @@ import ( "github.com/libp2p/go-libp2p/core/peer" "github.com/stretchr/testify/require" - "github.com/celestiaorg/celestia-app/v2/pkg/appconsts" + "github.com/celestiaorg/celestia-app/v3/pkg/appconsts" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/celestia-node/blob" "github.com/celestiaorg/celestia-node/blob/blobtest" "github.com/celestiaorg/celestia-node/nodebuilder/da" "github.com/celestiaorg/celestia-node/nodebuilder/node" "github.com/celestiaorg/celestia-node/nodebuilder/tests/swamp" - "github.com/celestiaorg/celestia-node/share" ) func TestDaModule(t *testing.T) { @@ -27,8 +27,9 @@ func TestDaModule(t *testing.T) { t.Cleanup(cancel) sw := swamp.NewSwamp(t, swamp.WithBlockTime(time.Second)) - namespace, err := share.NewBlobNamespaceV0([]byte("namespace")) + namespace, err := share.NewV0Namespace([]byte("namespace")) require.NoError(t, err) + require.False(t, namespace.IsReserved()) appBlobs0, err := blobtest.GenerateV0Blobs([]int{8, 4}, true) require.NoError(t, err) @@ -39,13 +40,14 @@ func TestDaModule(t *testing.T) { for _, squareBlob := range append(appBlobs0, appBlobs1...) { blob, err := blob.NewBlob( - uint8(squareBlob.GetShareVersion()), - squareBlob.Namespace().Bytes(), - squareBlob.GetData(), + squareBlob.ShareVersion(), + squareBlob.Namespace(), + squareBlob.Data(), + squareBlob.Signer(), ) require.NoError(t, err) blobs = append(blobs, blob) - daBlobs = append(daBlobs, blob.Data) + daBlobs = append(daBlobs, blob.Data()) } require.NoError(t, err) @@ -71,7 +73,7 @@ func TestDaModule(t *testing.T) { fullClient := getAdminClient(ctx, fullNode, t) lightClient := getAdminClient(ctx, lightNode, t) - ids, err := fullClient.DA.Submit(ctx, daBlobs, -1, namespace) + ids, err := fullClient.DA.Submit(ctx, daBlobs, -1, namespace.Bytes()) require.NoError(t, err) test := []struct { @@ -91,10 +93,10 @@ func TestDaModule(t *testing.T) { doFn: func(t *testing.T) { h, _ := da.SplitID(ids[0]) lightClient.Header.WaitForHeight(ctx, h) - proofs, err := lightClient.DA.GetProofs(ctx, ids, namespace) + proofs, err := lightClient.DA.GetProofs(ctx, ids, namespace.Bytes()) require.NoError(t, err) require.NotEmpty(t, proofs) - valid, err := fullClient.DA.Validate(ctx, ids, proofs, namespace) + valid, err := fullClient.DA.Validate(ctx, ids, proofs, namespace.Bytes()) require.NoError(t, err) for _, v := range valid { require.True(t, v) @@ -105,7 +107,7 @@ func TestDaModule(t *testing.T) { name: "GetIDs", doFn: func(t *testing.T) { height, _ := da.SplitID(ids[0]) - result, err := fullClient.DA.GetIDs(ctx, height, namespace) + result, err := fullClient.DA.GetIDs(ctx, height, namespace.Bytes()) require.NoError(t, err) require.EqualValues(t, ids, result.IDs) header, err := lightClient.Header.GetByHeight(ctx, height) @@ -118,7 +120,7 @@ func TestDaModule(t *testing.T) { doFn: func(t *testing.T) { h, _ := da.SplitID(ids[0]) lightClient.Header.WaitForHeight(ctx, h) - fetched, err := lightClient.DA.Get(ctx, ids, namespace) + fetched, err := lightClient.DA.Get(ctx, ids, namespace.Bytes()) require.NoError(t, err) require.Len(t, fetched, len(ids)) for i := range fetched { @@ -129,7 +131,7 @@ func TestDaModule(t *testing.T) { { name: "Commit", doFn: func(t *testing.T) { - fetched, err := fullClient.DA.Commit(ctx, daBlobs, namespace) + fetched, err := fullClient.DA.Commit(ctx, daBlobs, namespace.Bytes()) require.NoError(t, err) require.Len(t, fetched, len(ids)) for i := range fetched { diff --git a/nodebuilder/tests/fraud_test.go b/nodebuilder/tests/fraud_test.go index 524b306ac0..f3ec37c157 100644 --- a/nodebuilder/tests/fraud_test.go +++ b/nodebuilder/tests/fraud_test.go @@ -21,7 +21,7 @@ import ( "github.com/celestiaorg/celestia-node/nodebuilder/core" "github.com/celestiaorg/celestia-node/nodebuilder/node" "github.com/celestiaorg/celestia-node/nodebuilder/tests/swamp" - "github.com/celestiaorg/celestia-node/share/eds/byzantine" + "github.com/celestiaorg/celestia-node/square/eds/byzantine" "github.com/celestiaorg/celestia-node/store" ) diff --git a/nodebuilder/tests/nd_test.go b/nodebuilder/tests/nd_test.go index 960062bc9e..7b295511a6 100644 --- a/nodebuilder/tests/nd_test.go +++ b/nodebuilder/tests/nd_test.go @@ -4,6 +4,7 @@ package tests import ( "context" + "testing" "time" @@ -12,15 +13,16 @@ import ( "github.com/stretchr/testify/require" "go.uber.org/fx" + "github.com/celestiaorg/go-square/v2/share" + "github.com/celestiaorg/celestia-node/nodebuilder" "github.com/celestiaorg/celestia-node/nodebuilder/node" "github.com/celestiaorg/celestia-node/nodebuilder/p2p" "github.com/celestiaorg/celestia-node/nodebuilder/tests/swamp" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/shwap" - "github.com/celestiaorg/celestia-node/share/shwap/getters" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrex_getter" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrexnd" + "github.com/celestiaorg/celestia-node/square/shwap" + "github.com/celestiaorg/celestia-node/square/shwap/getters" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrex_getter" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrexnd" "github.com/celestiaorg/celestia-node/store" ) @@ -68,10 +70,12 @@ func TestShrexNDFromLights(t *testing.T) { // ensure to fetch random namespace (not the reserved namespace) namespace := h.DAH.RowRoots[1][:share.NamespaceSize] + ns, err := share.NewNamespaceFromBytes(namespace) + require.NoError(t, err) - expected, err := bridgeClient.Share.GetSharesByNamespace(reqCtx, h, namespace) + expected, err := bridgeClient.Share.GetSharesByNamespace(reqCtx, h, ns) require.NoError(t, err) - got, err := lightClient.Share.GetSharesByNamespace(reqCtx, h, namespace) + got, err := lightClient.Share.GetSharesByNamespace(reqCtx, h, ns) require.NoError(t, err) require.True(t, len(got[0].Shares) > 0) @@ -142,19 +146,19 @@ func TestShrexNDFromLightsWithBadFulls(t *testing.T) { // ensure to fetch random namespace (not the reserved namespace) namespace := h.DAH.RowRoots[1][:share.NamespaceSize] - - expected, err := bridgeClient.Share.GetSharesByNamespace(reqCtx, h, namespace) + ns, err := share.NewNamespaceFromBytes(namespace) + expected, err := bridgeClient.Share.GetSharesByNamespace(reqCtx, h, ns) require.NoError(t, err) require.True(t, len(expected[0].Shares) > 0) // choose a random full to test fN := fulls[len(fulls)/2] fnClient := getAdminClient(ctx, fN, t) - gotFull, err := fnClient.Share.GetSharesByNamespace(reqCtx, h, namespace) + gotFull, err := fnClient.Share.GetSharesByNamespace(reqCtx, h, ns) require.NoError(t, err) require.True(t, len(gotFull[0].Shares) > 0) - gotLight, err := lightClient.Share.GetSharesByNamespace(reqCtx, h, namespace) + gotLight, err := lightClient.Share.GetSharesByNamespace(reqCtx, h, ns) require.NoError(t, err) require.True(t, len(gotLight[0].Shares) > 0) diff --git a/nodebuilder/tests/prune_test.go b/nodebuilder/tests/prune_test.go index 79f40dccd6..8edf6fae1b 100644 --- a/nodebuilder/tests/prune_test.go +++ b/nodebuilder/tests/prune_test.go @@ -5,6 +5,7 @@ package tests import ( "bytes" "context" + "github.com/celestiaorg/go-square/v2/share" "testing" "time" @@ -20,11 +21,11 @@ import ( "github.com/celestiaorg/celestia-node/nodebuilder/node" "github.com/celestiaorg/celestia-node/nodebuilder/tests/swamp" "github.com/celestiaorg/celestia-node/pruner" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/peers" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrex_getter" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrexeds" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrexnd" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/peers" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrex_getter" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrexeds" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrexnd" ) // TestArchivalBlobSync tests whether a LN is able to sync historical blobs from @@ -116,7 +117,7 @@ func TestArchivalBlobSync(t *testing.T) { type archivalBlob struct { blob *blob.Blob height uint64 - root share.DataHash + root square.DataHash } archivalBlobs := make([]*archivalBlob, 0) @@ -125,17 +126,15 @@ func TestArchivalBlobSync(t *testing.T) { eh, err := archivalFN.HeaderServ.GetByHeight(ctx, uint64(i)) require.NoError(t, err) - if bytes.Equal(eh.DataHash, share.EmptyEDSRoots().Hash()) { + if bytes.Equal(eh.DataHash, square.EmptyEDSRoots().Hash()) { i++ continue } shr, err := archivalFN.ShareServ.GetShare(ctx, eh, 2, 2) require.NoError(t, err) - ns, err := share.NamespaceFromBytes(shr[:share.NamespaceSize]) - require.NoError(t, err) - blobs, err := archivalFN.BlobServ.GetAll(ctx, uint64(i), []share.Namespace{ns}) + blobs, err := archivalFN.BlobServ.GetAll(ctx, uint64(i), []share.Namespace{shr.Namespace()}) require.NoError(t, err) archivalBlobs = append(archivalBlobs, &archivalBlob{ @@ -172,7 +171,7 @@ func TestArchivalBlobSync(t *testing.T) { got, err := ln.BlobServ.Get(ctx, b.height, b.blob.Namespace(), b.blob.Commitment) require.NoError(t, err) assert.Equal(t, b.blob.Commitment, got.Commitment) - assert.Equal(t, b.blob.Data, got.Data) + assert.Equal(t, b.blob.Data(), got.Data()) } } diff --git a/nodebuilder/tests/reconstruct_test.go b/nodebuilder/tests/reconstruct_test.go index 70bcca05be..f5360395cb 100644 --- a/nodebuilder/tests/reconstruct_test.go +++ b/nodebuilder/tests/reconstruct_test.go @@ -19,8 +19,8 @@ import ( "github.com/celestiaorg/celestia-node/nodebuilder/node" "github.com/celestiaorg/celestia-node/nodebuilder/p2p" "github.com/celestiaorg/celestia-node/nodebuilder/tests/swamp" - "github.com/celestiaorg/celestia-node/share/availability/light" - "github.com/celestiaorg/celestia-node/share/eds" + "github.com/celestiaorg/celestia-node/square/availability/light" + "github.com/celestiaorg/celestia-node/square/eds" ) /* diff --git a/nodebuilder/tests/swamp/config.go b/nodebuilder/tests/swamp/config.go index 39740c6d18..7e00541b61 100644 --- a/nodebuilder/tests/swamp/config.go +++ b/nodebuilder/tests/swamp/config.go @@ -3,7 +3,7 @@ package swamp import ( "time" - "github.com/celestiaorg/celestia-app/v2/test/util/testnode" + "github.com/celestiaorg/celestia-app/v3/test/util/testnode" "github.com/celestiaorg/celestia-node/core" ) diff --git a/nodebuilder/tests/swamp/swamp.go b/nodebuilder/tests/swamp/swamp.go index d11c994229..57d46bb64b 100644 --- a/nodebuilder/tests/swamp/swamp.go +++ b/nodebuilder/tests/swamp/swamp.go @@ -19,7 +19,7 @@ import ( "go.uber.org/fx" "golang.org/x/exp/maps" - "github.com/celestiaorg/celestia-app/v2/test/util/testnode" + "github.com/celestiaorg/celestia-app/v3/test/util/testnode" libhead "github.com/celestiaorg/go-header" "github.com/celestiaorg/celestia-node/core" diff --git a/nodebuilder/tests/swamp/swamp_tx.go b/nodebuilder/tests/swamp/swamp_tx.go index 3cfe904ab1..4d6ce6497a 100644 --- a/nodebuilder/tests/swamp/swamp_tx.go +++ b/nodebuilder/tests/swamp/swamp_tx.go @@ -6,7 +6,7 @@ import ( "github.com/cosmos/cosmos-sdk/client/flags" - "github.com/celestiaorg/celestia-app/v2/test/util/testnode" + "github.com/celestiaorg/celestia-app/v3/test/util/testnode" ) // FillBlocks produces the given amount of contiguous blocks with customizable size. diff --git a/pruner/light/pruner.go b/pruner/light/pruner.go index 5739cd8cee..bc0e1732ad 100644 --- a/pruner/light/pruner.go +++ b/pruner/light/pruner.go @@ -9,8 +9,8 @@ import ( "github.com/celestiaorg/celestia-node/header" "github.com/celestiaorg/celestia-node/pruner" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/ipld" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/ipld" ) type Pruner struct { @@ -24,7 +24,7 @@ func NewPruner(bstore blockstore.Blockstore, ds datastore.Batching) pruner.Prune func (p *Pruner) Prune(ctx context.Context, h *header.ExtendedHeader) error { dah := h.DAH - if share.DataHash(dah.Hash()).IsEmptyEDS() { + if square.DataHash(dah.Hash()).IsEmptyEDS() { return nil } @@ -41,6 +41,6 @@ func (p *Pruner) Prune(ctx context.Context, h *header.ExtendedHeader) error { return p.ds.Delete(ctx, rootKey(dah)) } -func rootKey(root *share.AxisRoots) datastore.Key { +func rootKey(root *square.AxisRoots) datastore.Key { return datastore.NewKey(root.String()) } diff --git a/share/namespace_test.go b/share/namespace_test.go deleted file mode 100644 index e6007c245e..0000000000 --- a/share/namespace_test.go +++ /dev/null @@ -1,218 +0,0 @@ -package share - -import ( - "bytes" - "testing" - - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - - appns "github.com/celestiaorg/go-square/namespace" -) - -var ( - validID = append( - appns.NamespaceVersionZeroPrefix, - bytes.Repeat([]byte{1}, appns.NamespaceVersionZeroIDSize)..., - ) - tooShortID = append(appns.NamespaceVersionZeroPrefix, []byte{1}...) - tooLongID = append(appns.NamespaceVersionZeroPrefix, bytes.Repeat([]byte{1}, NamespaceSize)...) - invalidPrefixID = bytes.Repeat([]byte{1}, NamespaceSize) -) - -func TestNewNamespaceV0(t *testing.T) { - type testCase struct { - name string - subNid []byte - expected Namespace - wantErr bool - } - testCases := []testCase{ - { - name: "8 byte id, gets left padded", - subNid: []byte{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08}, - expected: Namespace{ - 0x0, - 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, // filled zeros - 0x0, 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, - }, // id with left padding - wantErr: false, - }, - { - name: "10 byte id, no padding", - subNid: []byte{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x9, 0x10}, - expected: Namespace{ - 0x0, // version - 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, // filled zeros - 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0x10, - }, // id - wantErr: false, - }, - { - name: "11 byte id", - subNid: []byte{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x9, 0x10, 0x11}, - expected: []byte{}, - wantErr: true, - }, - { - name: "nil id", - subNid: nil, - expected: []byte{}, - wantErr: true, - }, - } - - for _, tc := range testCases { - t.Run(tc.name, func(t *testing.T) { - got, err := NewBlobNamespaceV0(tc.subNid) - if tc.wantErr { - assert.Error(t, err) - return - } - assert.NoError(t, err) - assert.Equal(t, tc.expected, got) - }) - } -} - -func TestFrom(t *testing.T) { - type testCase struct { - name string - bytes []byte - wantErr bool - want Namespace - } - validNamespace := []byte{} - validNamespace = append(validNamespace, appns.NamespaceVersionZero) - validNamespace = append(validNamespace, appns.NamespaceVersionZeroPrefix...) - validNamespace = append(validNamespace, bytes.Repeat([]byte{0x1}, appns.NamespaceVersionZeroIDSize)...) - parityNamespace := bytes.Repeat([]byte{0xFF}, NamespaceSize) - - testCases := []testCase{ - { - name: "valid namespace", - bytes: validNamespace, - wantErr: false, - want: append([]byte{appns.NamespaceVersionZero}, validID...), - }, - { - name: "parity namespace", - bytes: parityNamespace, - wantErr: false, - want: append([]byte{appns.NamespaceVersionMax}, bytes.Repeat([]byte{0xFF}, appns.NamespaceIDSize)...), - }, - { - name: "unsupported version", - bytes: append([]byte{1}, append( - appns.NamespaceVersionZeroPrefix, - bytes.Repeat([]byte{1}, NamespaceSize-len(appns.NamespaceVersionZeroPrefix))..., - )...), - wantErr: true, - }, - { - name: "unsupported id: too short", - bytes: append([]byte{appns.NamespaceVersionZero}, tooShortID...), - wantErr: true, - }, - { - name: "unsupported id: too long", - bytes: append([]byte{appns.NamespaceVersionZero}, tooLongID...), - wantErr: true, - }, - { - name: "unsupported id: invalid prefix", - bytes: append([]byte{appns.NamespaceVersionZero}, invalidPrefixID...), - wantErr: true, - }, - } - - for _, tc := range testCases { - t.Run(tc.name, func(t *testing.T) { - got, err := NamespaceFromBytes(tc.bytes) - if tc.wantErr { - assert.Error(t, err) - return - } - assert.NoError(t, err) - assert.Equal(t, tc.want, got) - }) - } -} - -func TestValidateForBlob(t *testing.T) { - type testCase struct { - name string - ns Namespace - wantErr bool - } - - validNamespace, err := NewBlobNamespaceV0(bytes.Repeat([]byte{0x1}, appns.NamespaceVersionZeroIDSize)) - require.NoError(t, err) - - testCases := []testCase{ - { - name: "valid blob namespace", - ns: validNamespace, - wantErr: false, - }, - { - name: "invalid blob namespace: parity shares namespace", - ns: ParitySharesNamespace, - wantErr: true, - }, - { - name: "invalid blob namespace: tail padding namespace", - ns: TailPaddingNamespace, - wantErr: true, - }, - { - name: "invalid blob namespace: tx namespace", - ns: TxNamespace, - wantErr: true, - }, - { - name: "invalid blob namespace: namespace version max", - ns: append([]byte{appns.NamespaceVersionMax}, bytes.Repeat([]byte{0x0}, appns.NamespaceIDSize)...), - wantErr: true, - }, - { - name: "invalid blob namespace: primary reserved namespace", - ns: primaryReservedNamespace(0x10), - wantErr: true, - }, - { - name: "invalid blob namespace: secondary reserved namespace", - ns: secondaryReservedNamespace(0x10), - wantErr: true, - }, - } - - for _, tc := range testCases { - t.Run(tc.name, func(t *testing.T) { - err := tc.ns.ValidateForBlob() - - if tc.wantErr { - assert.Error(t, err) - return - } - assert.NoError(t, err) - }) - } -} - -func primaryReservedNamespace(lastByte byte) Namespace { - result := make([]byte, NamespaceSize) - result = append(result, appns.NamespaceVersionZero) - result = append(result, appns.NamespaceVersionZeroPrefix...) - result = append(result, bytes.Repeat([]byte{0x0}, appns.NamespaceVersionZeroIDSize-1)...) - result = append(result, lastByte) - return result -} - -func secondaryReservedNamespace(lastByte byte) Namespace { - result := make([]byte, NamespaceSize) - result = append(result, appns.NamespaceVersionMax) - result = append(result, bytes.Repeat([]byte{0xFF}, appns.NamespaceIDSize-1)...) - result = append(result, lastByte) - return result -} diff --git a/share/sharetest/testing.go b/share/sharetest/testing.go deleted file mode 100644 index f804e18ce9..0000000000 --- a/share/sharetest/testing.go +++ /dev/null @@ -1,87 +0,0 @@ -package sharetest - -import ( - "bytes" - "math/rand" - "sort" - "sync" - "testing" - "time" - - "github.com/stretchr/testify/require" - - "github.com/celestiaorg/go-square/namespace" - - "github.com/celestiaorg/celestia-node/share" -) - -// RandShares generate 'total' amount of shares filled with random data. -func RandShares(t testing.TB, total int) []share.Share { - if total&(total-1) != 0 { - t.Errorf("total must be power of 2: %d", total) - t.FailNow() - } - - shares := make([]share.Share, total) - for i := range shares { - shr := make([]byte, share.Size) - copy(share.GetNamespace(shr), RandV0Namespace()) - rndMu.Lock() - _, err := rnd.Read(share.GetData(shr)) - rndMu.Unlock() - require.NoError(t, err) - shares[i] = shr - } - sort.Slice(shares, func(i, j int) bool { return bytes.Compare(shares[i], shares[j]) < 0 }) - - return shares -} - -// RandSharesWithNamespace is same the as RandShares, but sets same namespace for all shares. -func RandSharesWithNamespace(t testing.TB, namespace share.Namespace, namespacedAmount, total int) []share.Share { - if total&(total-1) != 0 { - t.Errorf("total must be power of 2: %d", total) - t.FailNow() - } - - if namespacedAmount > total { - t.Errorf("withNamespace must be less than total: %d", total) - t.FailNow() - } - - shares := make([]share.Share, total) - rnd := rand.New(rand.NewSource(time.Now().Unix())) //nolint:gosec - for i := range shares { - shr := make([]byte, share.Size) - if i < namespacedAmount { - copy(share.GetNamespace(shr), namespace) - } else { - copy(share.GetNamespace(shr), RandV0Namespace()) - } - _, err := rnd.Read(share.GetData(shr)) - require.NoError(t, err) - shares[i] = shr - } - sort.Slice(shares, func(i, j int) bool { return bytes.Compare(shares[i], shares[j]) < 0 }) - return shares -} - -// RandV0Namespace generates random valid data namespace for testing purposes. -func RandV0Namespace() share.Namespace { - rb := make([]byte, namespace.NamespaceVersionZeroIDSize) - rndMu.Lock() - rnd.Read(rb) - rndMu.Unlock() - for { - namespace, _ := share.NewBlobNamespaceV0(rb) - if err := namespace.ValidateForData(); err != nil { - continue - } - return namespace - } -} - -var ( - rnd = rand.New(rand.NewSource(time.Now().Unix())) //nolint:gosec - rndMu sync.Mutex -) diff --git a/share/shwap/row_namespace_data_test.go b/share/shwap/row_namespace_data_test.go deleted file mode 100644 index 985f508c7b..0000000000 --- a/share/shwap/row_namespace_data_test.go +++ /dev/null @@ -1,99 +0,0 @@ -package shwap_test - -import ( - "bytes" - "context" - "slices" - "testing" - "time" - - "github.com/stretchr/testify/require" - - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/eds" - "github.com/celestiaorg/celestia-node/share/eds/edstest" - "github.com/celestiaorg/celestia-node/share/sharetest" - "github.com/celestiaorg/celestia-node/share/shwap" -) - -func TestNamespacedRowFromShares(t *testing.T) { - const odsSize = 8 - - minNamespace, err := share.NewBlobNamespaceV0(slices.Concat(bytes.Repeat([]byte{0}, 8), []byte{1, 0})) - require.NoError(t, err) - err = minNamespace.ValidateForData() - require.NoError(t, err) - - for namespacedAmount := 1; namespacedAmount < odsSize; namespacedAmount++ { - shares := sharetest.RandSharesWithNamespace(t, minNamespace, namespacedAmount, odsSize) - parity, err := share.DefaultRSMT2DCodec().Encode(shares) - require.NoError(t, err) - extended := slices.Concat(shares, parity) - - nr, err := shwap.RowNamespaceDataFromShares(extended, minNamespace, 0) - require.NoError(t, err) - require.Equal(t, namespacedAmount, len(nr.Shares)) - } -} - -func TestNamespacedRowFromSharesNonIncluded(t *testing.T) { - // TODO: this will fail until absence proof support is added - t.Skip() - - const odsSize = 8 - // Test absent namespace - shares := sharetest.RandShares(t, odsSize) - absentNs, err := share.GetNamespace(shares[0]).AddInt(1) - require.NoError(t, err) - - parity, err := share.DefaultRSMT2DCodec().Encode(shares) - require.NoError(t, err) - extended := slices.Concat(shares, parity) - - nr, err := shwap.RowNamespaceDataFromShares(extended, absentNs, 0) - require.NoError(t, err) - require.Len(t, nr.Shares, 0) - require.True(t, nr.Proof.IsOfAbsence()) -} - -func TestValidateNamespacedRow(t *testing.T) { - ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) - t.Cleanup(cancel) - - const odsSize = 8 - sharesAmount := odsSize * odsSize - namespace := sharetest.RandV0Namespace() - for amount := 1; amount < sharesAmount; amount++ { - randEDS, root := edstest.RandEDSWithNamespace(t, namespace, amount, odsSize) - rsmt2d := &eds.Rsmt2D{ExtendedDataSquare: randEDS} - nd, err := eds.NamespaceData(ctx, rsmt2d, namespace) - require.NoError(t, err) - require.True(t, len(nd) > 0) - - rowIdxs := share.RowsWithNamespace(root, namespace) - require.Len(t, nd, len(rowIdxs)) - - for i, rowIdx := range rowIdxs { - err = nd[i].Verify(root, namespace, rowIdx) - require.NoError(t, err) - } - } -} - -func TestNamespacedRowProtoEncoding(t *testing.T) { - ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) - t.Cleanup(cancel) - - const odsSize = 8 - namespace := sharetest.RandV0Namespace() - randEDS, _ := edstest.RandEDSWithNamespace(t, namespace, odsSize, odsSize) - rsmt2d := &eds.Rsmt2D{ExtendedDataSquare: randEDS} - nd, err := eds.NamespaceData(ctx, rsmt2d, namespace) - require.NoError(t, err) - require.True(t, len(nd) > 0) - - expected := nd[0] - pb := expected.ToProto() - ndOut := shwap.RowNamespaceDataFromProto(pb) - require.Equal(t, expected, ndOut) -} diff --git a/share/availability.go b/square/availability.go similarity index 97% rename from share/availability.go rename to square/availability.go index 3373a62276..fe2f29bea0 100644 --- a/share/availability.go +++ b/square/availability.go @@ -1,4 +1,4 @@ -package share +package square import ( "context" diff --git a/share/availability/full/availability.go b/square/availability/full/availability.go similarity index 86% rename from share/availability/full/availability.go rename to square/availability/full/availability.go index 91550849c8..af6106cc27 100644 --- a/share/availability/full/availability.go +++ b/square/availability/full/availability.go @@ -10,15 +10,15 @@ import ( "github.com/celestiaorg/celestia-node/header" "github.com/celestiaorg/celestia-node/pruner" "github.com/celestiaorg/celestia-node/pruner/full" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/eds/byzantine" - "github.com/celestiaorg/celestia-node/share/shwap" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/eds/byzantine" + "github.com/celestiaorg/celestia-node/square/shwap" "github.com/celestiaorg/celestia-node/store" ) var log = logging.Logger("share/full") -// ShareAvailability implements share.Availability using the full data square +// ShareAvailability implements square.Availability using the full data square // recovery technique. It is considered "full" because it is required // to download enough shares to fully reconstruct the data square. type ShareAvailability struct { @@ -42,8 +42,8 @@ func NewShareAvailability( func (fa *ShareAvailability) SharesAvailable(ctx context.Context, header *header.ExtendedHeader) error { dah := header.DAH // if the data square is empty, we can safely link the header height in the store to an empty EDS. - if share.DataHash(dah.Hash()).IsEmptyEDS() { - err := fa.store.PutODSQ4(ctx, dah, header.Height(), share.EmptyEDS()) + if square.DataHash(dah.Hash()).IsEmptyEDS() { + err := fa.store.PutODSQ4(ctx, dah, header.Height(), square.EmptyEDS()) if err != nil { return fmt.Errorf("put empty EDS: %w", err) } @@ -71,7 +71,7 @@ func (fa *ShareAvailability) SharesAvailable(ctx context.Context, header *header log.Errorw("availability validation failed", "root", dah.String(), "err", err.Error()) var byzantineErr *byzantine.ErrByzantine if errors.Is(err, shwap.ErrNotFound) || errors.Is(err, context.DeadlineExceeded) && !errors.As(err, &byzantineErr) { - return share.ErrNotAvailable + return square.ErrNotAvailable } return err } diff --git a/share/availability/full/availability_test.go b/square/availability/full/availability_test.go similarity index 86% rename from share/availability/full/availability_test.go rename to square/availability/full/availability_test.go index 95f8bda533..4a03cace50 100644 --- a/share/availability/full/availability_test.go +++ b/square/availability/full/availability_test.go @@ -9,10 +9,10 @@ import ( "github.com/stretchr/testify/require" "github.com/celestiaorg/celestia-node/header/headertest" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/eds/edstest" - "github.com/celestiaorg/celestia-node/share/shwap" - "github.com/celestiaorg/celestia-node/share/shwap/getters/mock" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/eds/edstest" + "github.com/celestiaorg/celestia-node/square/shwap" + "github.com/celestiaorg/celestia-node/square/shwap/getters/mock" "github.com/celestiaorg/celestia-node/store" ) @@ -22,7 +22,7 @@ func TestSharesAvailable(t *testing.T) { // RandServiceWithSquare creates a NewShareAvailability inside, so we can test it eds := edstest.RandEDS(t, 16) - roots, err := share.NewAxisRoots(eds) + roots, err := square.NewAxisRoots(eds) require.NoError(t, err) eh := headertest.RandExtendedHeaderWithRoot(t, roots) @@ -51,7 +51,7 @@ func TestSharesAvailable_StoredEds(t *testing.T) { defer cancel() eds := edstest.RandEDS(t, 4) - roots, err := share.NewAxisRoots(eds) + roots, err := square.NewAxisRoots(eds) require.NoError(t, err) eh := headertest.RandExtendedHeaderWithRoot(t, roots) require.NoError(t, err) @@ -82,7 +82,7 @@ func TestSharesAvailable_ErrNotAvailable(t *testing.T) { defer cancel() eds := edstest.RandEDS(t, 4) - roots, err := share.NewAxisRoots(eds) + roots, err := square.NewAxisRoots(eds) eh := headertest.RandExtendedHeaderWithRoot(t, roots) require.NoError(t, err) @@ -94,6 +94,6 @@ func TestSharesAvailable_ErrNotAvailable(t *testing.T) { for _, getterErr := range errors { getter.EXPECT().GetEDS(gomock.Any(), gomock.Any()).Return(nil, getterErr) err := avail.SharesAvailable(ctx, eh) - require.ErrorIs(t, err, share.ErrNotAvailable) + require.ErrorIs(t, err, square.ErrNotAvailable) } } diff --git a/share/availability/full/reconstruction_test.go b/square/availability/full/reconstruction_test.go similarity index 96% rename from share/availability/full/reconstruction_test.go rename to square/availability/full/reconstruction_test.go index 179a458d36..e52b75d127 100644 --- a/share/availability/full/reconstruction_test.go +++ b/square/availability/full/reconstruction_test.go @@ -12,10 +12,10 @@ package full // "golang.org/x/sync/errgroup" // // "github.com/celestiaorg/celestia-node/header/headertest" -// "github.com/celestiaorg/celestia-node/share" -// "github.com/celestiaorg/celestia-node/share/availability/light" -// availability_test "github.com/celestiaorg/celestia-node/share/availability/test" -// "github.com/celestiaorg/celestia-node/share/eds" +// "github.com/celestiaorg/celestia-node/square" +// "github.com/celestiaorg/celestia-node/square/availability/light" +// availability_test "github.com/celestiaorg/celestia-node/square/availability/test" +// "github.com/celestiaorg/celestia-node/square/eds" //) // // func init() { @@ -260,7 +260,7 @@ package full // // // check that any of the fulls cannot reconstruct on their own // err := errg.Wait() -// require.ErrorIs(t, err, share.ErrNotAvailable) +// require.ErrorIs(t, err, square.ErrNotAvailable) // cancelErr() // // // but after they connect diff --git a/share/availability/full/testing.go b/square/availability/full/testing.go similarity index 62% rename from share/availability/full/testing.go rename to square/availability/full/testing.go index 9ebe3f1c18..fae51c53ca 100644 --- a/share/availability/full/testing.go +++ b/square/availability/full/testing.go @@ -1,45 +1,46 @@ package full // -// import ( +//import ( // "context" +// // "testing" // "time" // // "github.com/ipfs/go-datastore" // "github.com/stretchr/testify/require" // -// "github.com/celestiaorg/celestia-node/share" -// availability_test "github.com/celestiaorg/celestia-node/share/availability/test" -// "github.com/celestiaorg/celestia-node/share/eds" -// "github.com/celestiaorg/celestia-node/share/getters" -// "github.com/celestiaorg/celestia-node/share/ipld" -// "github.com/celestiaorg/celestia-node/share/p2p/discovery" +// "github.com/celestiaorg/celestia-node/square" +// availability_test "github.com/celestiaorg/celestia-node/square/availability/test" +// "github.com/celestiaorg/celestia-node/square/eds" +// "github.com/celestiaorg/celestia-node/square/getters" +// "github.com/celestiaorg/celestia-node/square/ipld" +// "github.com/celestiaorg/celestia-node/square/p2p/discovery" //) // //// GetterWithRandSquare provides a share.Getter filled with 'n' NMT //// trees of 'n' random shares, essentially storing a whole square. -// func GetterWithRandSquare(t *testing.T, n int) (share.Getter, *share.AxisRoots) { +//func GetterWithRandSquare(t *testing.T, n int) (square.Getter, *square.AxisRoots) { // bServ := ipld.NewMemBlockservice() -// getter := getters.NewIPLDGetter(bServ) +// getter := shwap.NewIPLDGetter(bServ) // return getter, availability_test.RandFillBS(t, n, bServ) //} // //// RandNode creates a Full Node filled with a random block of the given size. -// func RandNode(dn *availability_test.TestDagNet, squareSize int) (*availability_test.TestNode, *share.AxisRoots) { +//func RandNode(dn *availability_test.TestDagNet, squareSize int) (*availability_test.TestNode, *square.AxisRoots) { // nd := Node(dn) // return nd, availability_test.RandFillBS(dn.T, squareSize, nd.BlockService) //} // //// Node creates a new empty Full Node. -// func Node(dn *availability_test.TestDagNet) *availability_test.TestNode { +//func Node(dn *availability_test.TestDagNet) *availability_test.TestNode { // nd := dn.NewTestNode() // nd.Getter = getters.NewIPLDGetter(nd.BlockService) // nd.Availability = TestAvailability(dn.T, nd.Getter) // return nd //} // -// func TestAvailability(t *testing.T, getter share.Getter) *ShareAvailability { +//func TestAvailability(t *testing.T, getter square.Getter) *ShareAvailability { // params := discovery.DefaultParameters() // params.AdvertiseInterval = time.Second // params.PeersLimit = 10 diff --git a/share/availability/light/availability.go b/square/availability/light/availability.go similarity index 91% rename from share/availability/light/availability.go rename to square/availability/light/availability.go index 3665711d1f..222463777f 100644 --- a/share/availability/light/availability.go +++ b/square/availability/light/availability.go @@ -11,8 +11,8 @@ import ( logging "github.com/ipfs/go-log/v2" "github.com/celestiaorg/celestia-node/header" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/shwap" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/shwap" ) var ( @@ -21,7 +21,7 @@ var ( writeBatchSize = 2048 ) -// ShareAvailability implements share.Availability using Data Availability Sampling technique. +// ShareAvailability implements square.Availability using Data Availability Sampling technique. // It is light because it does not require the downloading of all the data to verify // its availability. It is assumed that there are a lot of lightAvailability instances // on the network doing sampling over the same Root to collectively verify its availability. @@ -62,7 +62,7 @@ func NewShareAvailability( func (la *ShareAvailability) SharesAvailable(ctx context.Context, header *header.ExtendedHeader) error { dah := header.DAH // short-circuit if the given root is an empty data square - if share.DataHash(dah.Hash()).IsEmptyEDS() { + if square.DataHash(dah.Hash()).IsEmptyEDS() { return nil } @@ -125,7 +125,7 @@ func (la *ShareAvailability) SharesAvailable(ctx context.Context, header *header if errors.Is(ctx.Err(), context.Canceled) { // Availability did not complete due to context cancellation, return context error instead of - // share.ErrNotAvailable + // square.ErrNotAvailable return ctx.Err() } @@ -144,12 +144,12 @@ func (la *ShareAvailability) SharesAvailable(ctx context.Context, header *header "root", dah.String(), "failed_samples", failedSamples, ) - return share.ErrNotAvailable + return square.ErrNotAvailable } return nil } -func rootKey(root *share.AxisRoots) datastore.Key { +func rootKey(root *square.AxisRoots) datastore.Key { return datastore.NewKey(root.String()) } diff --git a/share/availability/light/availability_test.go b/square/availability/light/availability_test.go similarity index 84% rename from share/availability/light/availability_test.go rename to square/availability/light/availability_test.go index b8ec9db784..f2bd6d420f 100644 --- a/share/availability/light/availability_test.go +++ b/square/availability/light/availability_test.go @@ -10,15 +10,16 @@ import ( "github.com/ipfs/go-datastore" "github.com/stretchr/testify/require" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" "github.com/celestiaorg/celestia-node/header" "github.com/celestiaorg/celestia-node/header/headertest" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/eds/edstest" - "github.com/celestiaorg/celestia-node/share/shwap" - "github.com/celestiaorg/celestia-node/share/shwap/getters/mock" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/eds/edstest" + "github.com/celestiaorg/celestia-node/square/shwap" + "github.com/celestiaorg/celestia-node/square/shwap/getters/mock" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex" ) func TestSharesAvailableCaches(t *testing.T) { @@ -26,7 +27,7 @@ func TestSharesAvailableCaches(t *testing.T) { defer cancel() eds := edstest.RandEDS(t, 16) - roots, err := share.NewAxisRoots(eds) + roots, err := square.NewAxisRoots(eds) require.NoError(t, err) eh := headertest.RandExtendedHeaderWithRoot(t, roots) @@ -35,7 +36,12 @@ func TestSharesAvailableCaches(t *testing.T) { GetShare(gomock.Any(), eh, gomock.Any(), gomock.Any()). DoAndReturn( func(_ context.Context, _ *header.ExtendedHeader, row, col int) (share.Share, error) { - return eds.GetCell(uint(row), uint(col)), nil + rawSh := eds.GetCell(uint(row), uint(col)) + sh, err := share.NewShare(rawSh) + if err != nil { + return share.Share{}, err + } + return *sh, nil }). AnyTimes() @@ -66,7 +72,7 @@ func TestSharesAvailableHitsCache(t *testing.T) { getter := mock.NewMockGetter(gomock.NewController(t)) getter.EXPECT(). GetShare(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()). - Return(nil, shrex.ErrNotFound). + Return(share.Share{}, shrex.ErrNotFound). AnyTimes() ds := datastore.NewMapDatastore() @@ -78,7 +84,7 @@ func TestSharesAvailableHitsCache(t *testing.T) { // store doesn't actually have the eds err := avail.SharesAvailable(ctx, eh) - require.ErrorIs(t, err, share.ErrNotAvailable) + require.ErrorIs(t, err, square.ErrNotAvailable) // put success result in cache err = avail.ds.Put(ctx, rootKey(roots), []byte{}) @@ -98,7 +104,7 @@ func TestSharesAvailableEmptyRoot(t *testing.T) { avail := NewShareAvailability(getter, ds) // request for empty eds - eh := headertest.RandExtendedHeaderWithRoot(t, share.EmptyEDSRoots()) + eh := headertest.RandExtendedHeaderWithRoot(t, square.EmptyEDSRoots()) err := avail.SharesAvailable(ctx, eh) require.NoError(t, err) } @@ -113,17 +119,17 @@ func TestSharesAvailableFailed(t *testing.T) { // create new eds, that is not available by getter eds := edstest.RandEDS(t, 16) - roots, err := share.NewAxisRoots(eds) + roots, err := square.NewAxisRoots(eds) require.NoError(t, err) eh := headertest.RandExtendedHeaderWithRoot(t, roots) // getter doesn't have the eds, so it should fail getter.EXPECT(). GetShare(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()). - Return(nil, shrex.ErrNotFound). + Return(share.Share{}, shrex.ErrNotFound). AnyTimes() err = avail.SharesAvailable(ctx, eh) - require.ErrorIs(t, err, share.ErrNotAvailable) + require.ErrorIs(t, err, square.ErrNotAvailable) // cache should have failed results now result, err := avail.ds.Get(ctx, rootKey(roots)) @@ -177,7 +183,7 @@ func (m onceGetter) GetShare(_ context.Context, _ *header.ExtendedHeader, row, c delete(m.available, s) return share.Share{}, nil } - return share.Share{}, share.ErrNotAvailable + return share.Share{}, square.ErrNotAvailable } func (m onceGetter) GetEDS(_ context.Context, _ *header.ExtendedHeader) (*rsmt2d.ExtendedDataSquare, error) { diff --git a/share/availability/light/options.go b/square/availability/light/options.go similarity index 100% rename from share/availability/light/options.go rename to square/availability/light/options.go diff --git a/share/availability/light/sample.go b/square/availability/light/sample.go similarity index 100% rename from share/availability/light/sample.go rename to square/availability/light/sample.go diff --git a/share/availability/light/sample_test.go b/square/availability/light/sample_test.go similarity index 100% rename from share/availability/light/sample_test.go rename to square/availability/light/sample_test.go diff --git a/share/availability/light/testing.go b/square/availability/light/testing.go similarity index 89% rename from share/availability/light/testing.go rename to square/availability/light/testing.go index a7ef3248c4..224e2425a3 100644 --- a/share/availability/light/testing.go +++ b/square/availability/light/testing.go @@ -13,10 +13,10 @@ package light // // "github.com/celestiaorg/celestia-node/header" // "github.com/celestiaorg/celestia-node/header/headertest" -// "github.com/celestiaorg/celestia-node/share" -// availability_test "github.com/celestiaorg/celestia-node/share/availability/test" -// "github.com/celestiaorg/celestia-node/share/getters" -// "github.com/celestiaorg/celestia-node/share/ipld" +// "github.com/celestiaorg/celestia-node/square" +// availability_test "github.com/celestiaorg/celestia-node/square/availability/test" +// "github.com/celestiaorg/celestia-node/square/getters" +// "github.com/celestiaorg/celestia-node/square/ipld" //) // //// GetterWithRandSquare provides a share.Getter filled with 'n' NMT trees of 'n' random shares, @@ -40,7 +40,7 @@ package light //} // //// RandNode creates a Light Node filled with a random block of the given size. -// func RandNode(dn *availability_test.TestDagNet, squareSize int) (*availability_test.TestNode, *share.AxisRoots) { +// func RandNode(dn *availability_test.TestDagNet, squareSize int) (*availability_test.TestNode, *square.AxisRoots) { // nd := Node(dn) // return nd, availability_test.RandFillBS(dn.T, squareSize, nd.BlockService) //} @@ -92,7 +92,7 @@ package light // delete(m.available, s) // return share.Share{}, nil // } -// return share.Share{}, share.ErrNotAvailable +// return share.Share{}, square.ErrNotAvailable //} // // func (m onceGetter) GetEDS(_ context.Context, _ *header.ExtendedHeader) (*rsmt2d.ExtendedDataSquare, error) { diff --git a/share/availability/mocks/availability.go b/square/availability/mocks/availability.go similarity index 100% rename from share/availability/mocks/availability.go rename to square/availability/mocks/availability.go diff --git a/share/availability/test/testing.go b/square/availability/test/testing.go similarity index 92% rename from share/availability/test/testing.go rename to square/availability/test/testing.go index 6a8f1906ca..6296290c4c 100644 --- a/share/availability/test/testing.go +++ b/square/availability/test/testing.go @@ -17,23 +17,24 @@ import ( mocknet "github.com/libp2p/go-libp2p/p2p/net/mock" "github.com/stretchr/testify/require" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/ipld" - "github.com/celestiaorg/celestia-node/share/sharetest" - "github.com/celestiaorg/celestia-node/share/shwap" + "github.com/celestiaorg/go-square/v2/share" + + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/ipld" + "github.com/celestiaorg/celestia-node/square/shwap" ) // RandFillBS fills the given BlockService with a random block of a given size. -func RandFillBS(t *testing.T, n int, bServ blockservice.BlockService) *share.AxisRoots { - shares := sharetest.RandShares(t, n*n) +func RandFillBS(t *testing.T, n int, bServ blockservice.BlockService) *square.AxisRoots { + shares := share.RandShares(n * n) return FillBS(t, bServ, shares) } // FillBS fills the given BlockService with the given shares. -func FillBS(t *testing.T, bServ blockservice.BlockService, shares []share.Share) *share.AxisRoots { +func FillBS(t *testing.T, bServ blockservice.BlockService, shares []share.Share) *square.AxisRoots { eds, err := ipld.AddShares(context.TODO(), shares, bServ) require.NoError(t, err) - roots, err := share.NewAxisRoots(eds) + roots, err := square.NewAxisRoots(eds) require.NoError(t, err) return roots } @@ -41,7 +42,7 @@ func FillBS(t *testing.T, bServ blockservice.BlockService, shares []share.Share) type TestNode struct { net *TestDagNet shwap.Getter - share.Availability + square.Availability blockservice.BlockService host.Host } diff --git a/share/doc.go b/square/doc.go similarity index 88% rename from share/doc.go rename to square/doc.go index 6c6426472f..c28ee5cdab 100644 --- a/share/doc.go +++ b/square/doc.go @@ -1,5 +1,5 @@ /* -Package share contains logic related to the retrieval and random sampling of shares of +Package square contains logic related to the retrieval and random sampling of shares of block data. Though this package contains several useful methods for getting specific shares and/or @@ -14,4 +14,4 @@ the block's availability on the network). Full Availability implementation samples for as many shares as necessary to fully reconstruct the block data. */ -package share +package square diff --git a/share/eds/accessor.go b/square/eds/accessor.go similarity index 80% rename from share/eds/accessor.go rename to square/eds/accessor.go index ca0b475bb2..a290d2aed0 100644 --- a/share/eds/accessor.go +++ b/square/eds/accessor.go @@ -4,23 +4,24 @@ import ( "context" "io" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/shwap" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/shwap" ) // EmptyAccessor is an accessor of an empty EDS block. -var EmptyAccessor = &Rsmt2D{ExtendedDataSquare: share.EmptyEDS()} +var EmptyAccessor = &Rsmt2D{ExtendedDataSquare: square.EmptyEDS()} // Accessor is an interface for accessing extended data square data. type Accessor interface { // Size returns square size of the Accessor. Size(ctx context.Context) int // DataHash returns data hash of the Accessor. - DataHash(ctx context.Context) (share.DataHash, error) - // AxisRoots returns share.AxisRoots (DataAvailabilityHeader) of the Accessor. - AxisRoots(ctx context.Context) (*share.AxisRoots, error) + DataHash(ctx context.Context) (square.DataHash, error) + // AxisRoots returns square.AxisRoots (DataAvailabilityHeader) of the Accessor. + AxisRoots(ctx context.Context) (*square.AxisRoots, error) // Sample returns share and corresponding proof for row and column indices. Implementation can // choose which axis to use for proof. Chosen axis for proof should be indicated in the returned // Sample. diff --git a/share/eds/axis_half.go b/square/eds/axis_half.go similarity index 75% rename from share/eds/axis_half.go rename to square/eds/axis_half.go index 6b48676fe2..d5ef406be8 100644 --- a/share/eds/axis_half.go +++ b/square/eds/axis_half.go @@ -3,11 +3,13 @@ package eds import ( "fmt" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/shwap" + "github.com/celestiaorg/go-square/v2/share" + + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/shwap" ) -var codec = share.DefaultRSMT2DCodec() +var codec = square.DefaultRSMT2DCodec() // AxisHalf represents a half of data for a row or column in the EDS. type AxisHalf struct { @@ -39,15 +41,20 @@ func extendShares(original []share.Share) ([]share.Share, error) { return nil, fmt.Errorf("original shares are empty") } - parity, err := codec.Encode(original) + parity, err := codec.Encode(share.ToBytes(original)) if err != nil { return nil, fmt.Errorf("encoding: %w", err) } + parityShrs, err := share.FromBytes(parity) + if err != nil { + return nil, err + } + sqLen := len(original) * 2 shares := make([]share.Share, sqLen) copy(shares, original) - copy(shares[sqLen/2:], parity) + copy(shares[sqLen/2:], parityShrs) return shares, nil } @@ -61,9 +68,10 @@ func reconstructShares(parity []share.Share) ([]share.Share, error) { for i := sqLen / 2; i < sqLen; i++ { shares[i] = parity[i-sqLen/2] } - _, err := codec.Decode(shares) + shrs, err := codec.Decode(share.ToBytes(shares)) if err != nil { return nil, fmt.Errorf("reconstructing: %w", err) } - return shares, nil + + return share.FromBytes(shrs) } diff --git a/share/eds/axis_half_test.go b/square/eds/axis_half_test.go similarity index 83% rename from share/eds/axis_half_test.go rename to square/eds/axis_half_test.go index 752add5acd..6974080523 100644 --- a/share/eds/axis_half_test.go +++ b/square/eds/axis_half_test.go @@ -5,11 +5,11 @@ import ( "github.com/stretchr/testify/require" - "github.com/celestiaorg/celestia-node/share/sharetest" + "github.com/celestiaorg/go-square/v2/share" ) func TestExtendAxisHalf(t *testing.T) { - shares := sharetest.RandShares(t, 16) + shares := share.RandShares(16) original := AxisHalf{ Shares: shares, diff --git a/share/eds/byzantine/bad_encoding.go b/square/eds/byzantine/bad_encoding.go similarity index 95% rename from share/eds/byzantine/bad_encoding.go rename to square/eds/byzantine/bad_encoding.go index 7e1386a863..8687e7ce1f 100644 --- a/share/eds/byzantine/bad_encoding.go +++ b/square/eds/byzantine/bad_encoding.go @@ -5,13 +5,13 @@ import ( "errors" "fmt" - "github.com/celestiaorg/celestia-app/v2/pkg/wrapper" + "github.com/celestiaorg/celestia-app/v3/pkg/wrapper" "github.com/celestiaorg/go-fraud" "github.com/celestiaorg/rsmt2d" "github.com/celestiaorg/celestia-node/header" - "github.com/celestiaorg/celestia-node/share" - pb "github.com/celestiaorg/celestia-node/share/eds/byzantine/pb" + "github.com/celestiaorg/celestia-node/square" + pb "github.com/celestiaorg/celestia-node/square/eds/byzantine/pb" ) const ( @@ -88,10 +88,14 @@ func (p *BadEncodingProof) UnmarshalBinary(data []byte) error { if err := in.Unmarshal(data); err != nil { return err } + sh, err := ProtoToShare(in.Shares) + if err != nil { + return err + } befp := &BadEncodingProof{ headerHash: in.HeaderHash, BlockHeight: in.Height, - Shares: ProtoToShare(in.Shares), + Shares: sh, Index: in.Index, Axis: rsmt2d.Axis(in.Axis), } @@ -184,10 +188,10 @@ func (p *BadEncodingProof) Validate(hdr *header.ExtendedHeader) error { log.Debugf("%s: %s at index %d", invalidProofPrefix, errIncorrectShare, index) return errIncorrectShare } - shares[index] = shr.Share + shares[index] = shr.Share.ToBytes() } - codec := share.DefaultRSMT2DCodec() + codec := square.DefaultRSMT2DCodec() // We can conclude that the proof is valid in case we proved the inclusion of `Shares` but // the row/col can't be reconstructed, or the building of NMTree fails. diff --git a/share/eds/byzantine/bad_encoding_test.go b/square/eds/byzantine/bad_encoding_test.go similarity index 89% rename from share/eds/byzantine/bad_encoding_test.go rename to square/eds/byzantine/bad_encoding_test.go index f4dbe84e31..c226b2a5cb 100644 --- a/share/eds/byzantine/bad_encoding_test.go +++ b/square/eds/byzantine/bad_encoding_test.go @@ -13,15 +13,15 @@ import ( "github.com/stretchr/testify/require" core "github.com/tendermint/tendermint/types" - "github.com/celestiaorg/celestia-app/v2/test/util/malicious" + "github.com/celestiaorg/celestia-app/v3/test/util/malicious" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt" "github.com/celestiaorg/rsmt2d" "github.com/celestiaorg/celestia-node/header" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/eds/edstest" - "github.com/celestiaorg/celestia-node/share/ipld" - "github.com/celestiaorg/celestia-node/share/sharetest" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/eds/edstest" + "github.com/celestiaorg/celestia-node/square/ipld" ) func TestBEFP_Validate(t *testing.T) { @@ -29,14 +29,14 @@ func TestBEFP_Validate(t *testing.T) { defer t.Cleanup(cancel) bServ := ipld.NewMemBlockservice() - square := edstest.RandByzantineEDS(t, 16) - roots, err := share.NewAxisRoots(square) + byzSquare := edstest.RandByzantineEDS(t, 16) + roots, err := square.NewAxisRoots(byzSquare) require.NoError(t, err) - err = ipld.ImportEDS(ctx, square, bServ) + err = ipld.ImportEDS(ctx, byzSquare, bServ) require.NoError(t, err) var errRsmt2d *rsmt2d.ErrByzantineData - err = square.Repair(roots.RowRoots, roots.ColumnRoots) + err = byzSquare.Repair(roots.RowRoots, roots.ColumnRoots) require.ErrorAs(t, err, &errRsmt2d) byzantine := NewErrByzantine(ctx, bServ.Blockstore(), roots, errRsmt2d) @@ -64,7 +64,7 @@ func TestBEFP_Validate(t *testing.T) { name: "invalid BEFP for valid header", prepareFn: func() error { validSquare := edstest.RandEDS(t, 2) - validRoots, err := share.NewAxisRoots(validSquare) + validRoots, err := square.NewAxisRoots(validSquare) require.NoError(t, err) err = ipld.ImportEDS(ctx, validSquare, bServ) require.NoError(t, err) @@ -89,7 +89,7 @@ func TestBEFP_Validate(t *testing.T) { name: "incorrect share with Proof", prepareFn: func() error { // break the first shareWithProof to test negative case - sh := sharetest.RandShares(t, 2) + sh := share.RandShares(2) nmtProof := nmt.NewInclusionProof(0, 1, nil, false) befp.Shares[0] = &ShareWithProof{sh[0], &nmtProof, rsmt2d.Row} return proof.Validate(&header.ExtendedHeader{DAH: roots}) @@ -160,12 +160,12 @@ func TestIncorrectBadEncodingFraudProof(t *testing.T) { bServ := ipld.NewMemBlockservice() squareSize := 8 - shares := sharetest.RandShares(t, squareSize*squareSize) + shares := share.RandShares(squareSize * squareSize) eds, err := ipld.AddShares(ctx, shares, bServ) require.NoError(t, err) - roots, err := share.NewAxisRoots(eds) + roots, err := square.NewAxisRoots(eds) require.NoError(t, err) // get an arbitrary row @@ -215,12 +215,12 @@ func TestBEFP_ValidateOutOfOrderShares(t *testing.T) { batchAddr := ipld.NewNmtNodeAdder(ctx, bServ, ipld.MaxSizeBatchOption(size*2)) eds, err := rsmt2d.ImportExtendedDataSquare(shares, - share.DefaultRSMT2DCodec(), + square.DefaultRSMT2DCodec(), malicious.NewConstructor(uint64(size), nmt.NodeVisitor(batchAddr.Visit)), ) require.NoError(t, err, "failure to recompute the extended data square") - roots, err := share.NewAxisRoots(eds) + roots, err := square.NewAxisRoots(eds) require.NoError(t, err) var errRsmt2d *rsmt2d.ErrByzantineData @@ -252,7 +252,7 @@ func newNamespacedBlockService() *namespacedBlockService { sha256NamespaceFlagged := uint64(0x7701) // register the nmt hasher to validate the order of namespaces mhcore.Register(sha256NamespaceFlagged, func() hash.Hash { - nh := nmt.NewNmtHasher(share.NewSHA256Hasher(), share.NamespaceSize, true) + nh := nmt.NewNmtHasher(square.NewSHA256Hasher(), share.NamespaceSize, true) nh.Reset() return nh }) @@ -265,7 +265,7 @@ func newNamespacedBlockService() *namespacedBlockService { Codec: sha256NamespaceFlagged, MhType: sha256NamespaceFlagged, // equals to NmtHasher.Size() - MhLength: share.NewSHA256Hasher().Size() + 2*share.NamespaceSize, + MhLength: square.NewSHA256Hasher().Size() + 2*share.NamespaceSize, } return bs } diff --git a/share/eds/byzantine/byzantine.go b/square/eds/byzantine/byzantine.go similarity index 75% rename from share/eds/byzantine/byzantine.go rename to square/eds/byzantine/byzantine.go index 8f7b7c3a3b..80f015529c 100644 --- a/share/eds/byzantine/byzantine.go +++ b/square/eds/byzantine/byzantine.go @@ -6,10 +6,11 @@ import ( "github.com/ipfs/boxo/blockstore" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/ipld" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/ipld" ) // ErrByzantine is a thrown when recovered data square is not correct @@ -32,17 +33,22 @@ func (e *ErrByzantine) Error() string { func NewErrByzantine( ctx context.Context, bStore blockstore.Blockstore, - roots *share.AxisRoots, + roots *square.AxisRoots, errByz *rsmt2d.ErrByzantineData, ) error { sharesWithProof := make([]*ShareWithProof, len(errByz.Shares)) bGetter := ipld.NewBlockservice(bStore, nil) var count int - for index, share := range errByz.Shares { - if len(share) == 0 { + for index, shr := range errByz.Shares { + if len(shr) == 0 { continue } - swp, err := GetShareWithProof(ctx, bGetter, roots, share, errByz.Axis, int(errByz.Index), index) + sh, err := share.NewShare(shr) + if err != nil { + log.Warn("failed to create share", "index", index, "err", err) + continue + } + swp, err := GetShareWithProof(ctx, bGetter, roots, *sh, errByz.Axis, int(errByz.Index), index) if err != nil { log.Warn("requesting proof failed", "errByz", errByz, diff --git a/share/eds/byzantine/pb/share.pb.go b/square/eds/byzantine/pb/share.pb.go similarity index 87% rename from share/eds/byzantine/pb/share.pb.go rename to square/eds/byzantine/pb/share.pb.go index af79d48b13..d31b409560 100644 --- a/share/eds/byzantine/pb/share.pb.go +++ b/square/eds/byzantine/pb/share.pb.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: share/eds/byzantine/pb/share.proto +// source: square/eds/byzantine/pb/share.proto package share_eds_byzantine_pb @@ -45,7 +45,7 @@ func (x Axis) String() string { } func (Axis) EnumDescriptor() ([]byte, []int) { - return fileDescriptor_d28ce8f160a920d1, []int{0} + return fileDescriptor_5c467604cd602917, []int{0} } type Share struct { @@ -58,7 +58,7 @@ func (m *Share) Reset() { *m = Share{} } func (m *Share) String() string { return proto.CompactTextString(m) } func (*Share) ProtoMessage() {} func (*Share) Descriptor() ([]byte, []int) { - return fileDescriptor_d28ce8f160a920d1, []int{0} + return fileDescriptor_5c467604cd602917, []int{0} } func (m *Share) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -120,7 +120,7 @@ func (m *BadEncoding) Reset() { *m = BadEncoding{} } func (m *BadEncoding) String() string { return proto.CompactTextString(m) } func (*BadEncoding) ProtoMessage() {} func (*BadEncoding) Descriptor() ([]byte, []int) { - return fileDescriptor_d28ce8f160a920d1, []int{1} + return fileDescriptor_5c467604cd602917, []int{1} } func (m *BadEncoding) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -191,31 +191,31 @@ func init() { } func init() { - proto.RegisterFile("share/eds/byzantine/pb/share.proto", fileDescriptor_d28ce8f160a920d1) -} - -var fileDescriptor_d28ce8f160a920d1 = []byte{ - // 310 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x91, 0x31, 0x4b, 0xc4, 0x30, - 0x1c, 0xc5, 0x1b, 0xaf, 0x3d, 0xf1, 0x7f, 0x7a, 0x1e, 0x41, 0x8e, 0x20, 0x1a, 0xca, 0x81, 0x50, - 0x1c, 0x52, 0x39, 0x71, 0x71, 0xf3, 0x54, 0x38, 0x41, 0x38, 0x89, 0x83, 0x73, 0x62, 0xe2, 0xb5, - 0x4b, 0x5b, 0x9a, 0x0e, 0xd5, 0xc1, 0xcf, 0xe0, 0x87, 0x72, 0x70, 0xbc, 0xd1, 0x51, 0xda, 0x2f, - 0x22, 0x4d, 0x8b, 0x3a, 0x28, 0xb8, 0xbd, 0xf7, 0xf2, 0x0b, 0x79, 0x8f, 0xc0, 0xc4, 0x44, 0x22, - 0xd7, 0xa1, 0x56, 0x26, 0x94, 0x8f, 0x4f, 0x22, 0x29, 0xe2, 0x44, 0x87, 0x99, 0x0c, 0x6d, 0xcc, - 0xb2, 0x3c, 0x2d, 0x52, 0x3c, 0x6e, 0x8d, 0x56, 0x86, 0x7d, 0x31, 0x2c, 0x93, 0xbb, 0xc3, 0x4c, - 0x86, 0x59, 0x9e, 0xa6, 0x0f, 0x2d, 0x37, 0x79, 0x06, 0xef, 0xb6, 0x21, 0x31, 0x06, 0xf7, 0x42, - 0x14, 0x82, 0x20, 0x1f, 0x05, 0x9b, 0xdc, 0x6a, 0x7c, 0x00, 0xde, 0x4d, 0xc3, 0x92, 0x35, 0x1f, - 0x05, 0x83, 0xe9, 0x36, 0xeb, 0x6e, 0x4a, 0x66, 0x63, 0xde, 0x9e, 0xe2, 0x53, 0xd8, 0xb0, 0xe2, - 0xac, 0x8c, 0x0d, 0xe9, 0xf9, 0x28, 0x18, 0x4e, 0xf7, 0xd8, 0xef, 0xef, 0x33, 0x51, 0xc6, 0x86, - 0x7f, 0xe3, 0x93, 0x57, 0x04, 0x83, 0x99, 0x50, 0x97, 0xc9, 0x7d, 0xaa, 0xe2, 0x64, 0x89, 0x29, - 0xc0, 0x5c, 0x0b, 0xa5, 0xf3, 0xb9, 0x30, 0x51, 0x57, 0xe6, 0x47, 0x82, 0xc7, 0xd0, 0x9f, 0xeb, - 0x78, 0x19, 0x15, 0xb6, 0x93, 0xcb, 0x3b, 0x87, 0x4f, 0xa0, 0x6f, 0x77, 0x34, 0x05, 0x7a, 0xc1, - 0x60, 0xba, 0xff, 0x57, 0x01, 0x4b, 0xf1, 0x0e, 0xc6, 0x3b, 0xe0, 0x5d, 0x25, 0x4a, 0x97, 0xc4, - 0xf5, 0x51, 0xb0, 0xc5, 0x5b, 0x83, 0x8f, 0xc0, 0xb5, 0x5b, 0xbc, 0x7f, 0x6c, 0xb1, 0xe4, 0x21, - 0x01, 0xb7, 0x71, 0x78, 0x1d, 0x7a, 0x7c, 0x71, 0x37, 0x72, 0x1a, 0x71, 0xbe, 0xb8, 0x1e, 0xa1, - 0x19, 0x79, 0xab, 0x28, 0x5a, 0x55, 0x14, 0x7d, 0x54, 0x14, 0xbd, 0xd4, 0xd4, 0x59, 0xd5, 0xd4, - 0x79, 0xaf, 0xa9, 0x23, 0xfb, 0xf6, 0x07, 0x8e, 0x3f, 0x03, 0x00, 0x00, 0xff, 0xff, 0x0f, 0x5d, - 0x8d, 0x6c, 0xcf, 0x01, 0x00, 0x00, + proto.RegisterFile("square/eds/byzantine/pb/share.proto", fileDescriptor_5c467604cd602917) +} + +var fileDescriptor_5c467604cd602917 = []byte{ + // 316 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x91, 0xc1, 0x4b, 0xfb, 0x30, + 0x1c, 0xc5, 0x9b, 0xdf, 0xda, 0xfd, 0xf0, 0x3b, 0x9d, 0x23, 0xc8, 0x08, 0xa2, 0xa1, 0x4c, 0x84, + 0xe2, 0x21, 0x95, 0x89, 0x17, 0x6f, 0x4e, 0x85, 0x09, 0xc2, 0x24, 0x1e, 0x3c, 0x27, 0x26, 0x6e, + 0xbd, 0xb4, 0xb5, 0xa9, 0x50, 0x3d, 0xf8, 0x37, 0xf8, 0x47, 0x79, 0xf0, 0xb8, 0xa3, 0x47, 0x69, + 0xff, 0x11, 0x69, 0x5a, 0xd4, 0x83, 0x82, 0xb7, 0xf7, 0x5e, 0x3e, 0x21, 0xef, 0x11, 0xd8, 0x31, + 0x77, 0xf7, 0x22, 0xd3, 0xa1, 0x56, 0x26, 0x94, 0x0f, 0x8f, 0x22, 0xce, 0xa3, 0x58, 0x87, 0xa9, + 0x0c, 0xcd, 0x42, 0x64, 0x9a, 0xa5, 0x59, 0x92, 0x27, 0x78, 0xd8, 0x18, 0xad, 0x0c, 0xfb, 0x64, + 0x58, 0x2a, 0x37, 0xfb, 0xa9, 0x0c, 0xd3, 0x2c, 0x49, 0x6e, 0x1b, 0x6e, 0xf4, 0x04, 0xde, 0x55, + 0x4d, 0x62, 0x0c, 0xee, 0xa9, 0xc8, 0x05, 0x41, 0x3e, 0x0a, 0x56, 0xb9, 0xd5, 0x78, 0x17, 0xbc, + 0xcb, 0x9a, 0x25, 0xff, 0x7c, 0x14, 0xf4, 0xc6, 0xeb, 0xac, 0xbd, 0x29, 0x99, 0x8d, 0x79, 0x73, + 0x8a, 0x8f, 0x60, 0xc5, 0x8a, 0xe3, 0x22, 0x32, 0xa4, 0xe3, 0xa3, 0xa0, 0x3f, 0xde, 0x62, 0x3f, + 0xbf, 0xcf, 0x44, 0x11, 0x19, 0xfe, 0x85, 0x8f, 0x5e, 0x10, 0xf4, 0x26, 0x42, 0x9d, 0xc5, 0x37, + 0x89, 0x8a, 0xe2, 0x39, 0xa6, 0x00, 0x53, 0x2d, 0x94, 0xce, 0xa6, 0xc2, 0x2c, 0xda, 0x32, 0xdf, + 0x12, 0x3c, 0x84, 0xee, 0x54, 0x47, 0xf3, 0x45, 0x6e, 0x3b, 0xb9, 0xbc, 0x75, 0xf8, 0x10, 0xba, + 0x76, 0x47, 0x5d, 0xa0, 0x13, 0xf4, 0xc6, 0xdb, 0xbf, 0x15, 0xb0, 0x14, 0x6f, 0x61, 0xbc, 0x01, + 0xde, 0x79, 0xac, 0x74, 0x41, 0x5c, 0x1f, 0x05, 0x6b, 0xbc, 0x31, 0x78, 0x1f, 0x5c, 0xbb, 0xc5, + 0xfb, 0xc3, 0x16, 0x4b, 0xee, 0x11, 0x70, 0x6b, 0x87, 0xff, 0x43, 0x87, 0xcf, 0xae, 0x07, 0x4e, + 0x2d, 0x4e, 0x66, 0x17, 0x03, 0x34, 0x21, 0xaf, 0x25, 0x45, 0xcb, 0x92, 0xa2, 0xf7, 0x92, 0xa2, + 0xe7, 0x8a, 0x3a, 0xcb, 0x8a, 0x3a, 0x6f, 0x15, 0x75, 0x64, 0xd7, 0xfe, 0xc0, 0xc1, 0x47, 0x00, + 0x00, 0x00, 0xff, 0xff, 0x7c, 0x07, 0xc6, 0x14, 0xd0, 0x01, 0x00, 0x00, } func (m *Share) Marshal() (dAtA []byte, err error) { diff --git a/share/eds/byzantine/pb/share.proto b/square/eds/byzantine/pb/share.proto similarity index 100% rename from share/eds/byzantine/pb/share.proto rename to square/eds/byzantine/pb/share.proto diff --git a/share/eds/byzantine/share_proof.go b/square/eds/byzantine/share_proof.go similarity index 77% rename from share/eds/byzantine/share_proof.go rename to square/eds/byzantine/share_proof.go index 4dd2c082b6..5d94159a0a 100644 --- a/share/eds/byzantine/share_proof.go +++ b/square/eds/byzantine/share_proof.go @@ -7,13 +7,14 @@ import ( "github.com/ipfs/boxo/blockservice" logging "github.com/ipfs/go-log/v2" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt" nmt_pb "github.com/celestiaorg/nmt/pb" "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/share" - pb "github.com/celestiaorg/celestia-node/share/eds/byzantine/pb" - "github.com/celestiaorg/celestia-node/share/ipld" + "github.com/celestiaorg/celestia-node/square" + pb "github.com/celestiaorg/celestia-node/square/eds/byzantine/pb" + "github.com/celestiaorg/celestia-node/square/ipld" ) var log = logging.Logger("share/byzantine") @@ -29,7 +30,7 @@ type ShareWithProof struct { } // Validate validates inclusion of the share under the given root CID. -func (s *ShareWithProof) Validate(roots *share.AxisRoots, axisType rsmt2d.Axis, axisIdx, shrIdx int) bool { +func (s *ShareWithProof) Validate(roots *square.AxisRoots, axisType rsmt2d.Axis, axisIdx, shrIdx int) bool { var rootHash []byte switch axisType { case rsmt2d.Row: @@ -42,12 +43,12 @@ func (s *ShareWithProof) Validate(roots *share.AxisRoots, axisType rsmt2d.Axis, isParity := shrIdx >= edsSize/2 || axisIdx >= edsSize/2 namespace := share.ParitySharesNamespace if !isParity { - namespace = share.GetNamespace(s.Share) + namespace = s.Share.Namespace() } return s.Proof.VerifyInclusion( - share.NewSHA256Hasher(), - namespace.ToNMT(), - [][]byte{s.Share}, + square.NewSHA256Hasher(), + namespace.Bytes(), + [][]byte{s.Share.ToBytes()}, rootHash, ) } @@ -56,9 +57,8 @@ func (s *ShareWithProof) ShareWithProofToProto() *pb.Share { if s == nil { return &pb.Share{} } - return &pb.Share{ - Data: s.Share, + Data: s.Share.ToBytes(), Proof: &nmt_pb.Proof{ Start: int64(s.Proof.Start()), End: int64(s.Proof.End()), @@ -75,7 +75,7 @@ func (s *ShareWithProof) ShareWithProofToProto() *pb.Share { func GetShareWithProof( ctx context.Context, bGetter blockservice.BlockGetter, - roots *share.AxisRoots, + roots *square.AxisRoots, share share.Share, axisType rsmt2d.Axis, axisIdx, shrIdx int, ) (*ShareWithProof, error) { @@ -114,20 +114,24 @@ func GetShareWithProof( return nil, errors.New("failed to collect proof") } -func ProtoToShare(protoShares []*pb.Share) []*ShareWithProof { +func ProtoToShare(protoShares []*pb.Share) ([]*ShareWithProof, error) { shares := make([]*ShareWithProof, len(protoShares)) - for i, share := range protoShares { - if share.Proof == nil { + for i, protoSh := range protoShares { + if protoSh.Proof == nil { continue } - proof := ProtoToProof(share.Proof) + proof := ProtoToProof(protoSh.Proof) + sh, err := share.NewShare(protoSh.Data) + if err != nil { + return nil, err + } shares[i] = &ShareWithProof{ - Share: share.Data, + Share: *sh, Proof: &proof, - Axis: rsmt2d.Axis(share.ProofAxis), + Axis: rsmt2d.Axis(protoSh.ProofAxis), } } - return shares + return shares, nil } func ProtoToProof(protoProof *nmt_pb.Proof) nmt.Proof { @@ -139,7 +143,7 @@ func ProtoToProof(protoProof *nmt_pb.Proof) nmt.Proof { ) } -func rootHashForCoordinates(r *share.AxisRoots, axisType rsmt2d.Axis, x, y int) []byte { +func rootHashForCoordinates(r *square.AxisRoots, axisType rsmt2d.Axis, x, y int) []byte { if axisType == rsmt2d.Row { return r.RowRoots[y] } diff --git a/share/eds/close_once.go b/square/eds/close_once.go similarity index 85% rename from share/eds/close_once.go rename to square/eds/close_once.go index 2150ff7232..13b2df177b 100644 --- a/share/eds/close_once.go +++ b/square/eds/close_once.go @@ -6,10 +6,11 @@ import ( "io" "sync/atomic" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/shwap" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/shwap" ) var _ AccessorStreamer = (*closeOnce)(nil) @@ -42,14 +43,14 @@ func (c *closeOnce) Size(ctx context.Context) int { return c.f.Size(ctx) } -func (c *closeOnce) DataHash(ctx context.Context) (share.DataHash, error) { +func (c *closeOnce) DataHash(ctx context.Context) (square.DataHash, error) { if c.closed.Load() { return nil, errAccessorClosed } return c.f.DataHash(ctx) } -func (c *closeOnce) AxisRoots(ctx context.Context) (*share.AxisRoots, error) { +func (c *closeOnce) AxisRoots(ctx context.Context) (*square.AxisRoots, error) { if c.closed.Load() { return nil, errAccessorClosed } diff --git a/share/eds/close_once_test.go b/square/eds/close_once_test.go similarity index 83% rename from share/eds/close_once_test.go rename to square/eds/close_once_test.go index c31d9ba099..58da79d840 100644 --- a/share/eds/close_once_test.go +++ b/square/eds/close_once_test.go @@ -8,10 +8,11 @@ import ( "github.com/stretchr/testify/require" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/shwap" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/shwap" ) func TestWithClosedOnce(t *testing.T) { @@ -50,12 +51,12 @@ func (s *stubEdsAccessorCloser) Size(context.Context) int { return 0 } -func (s *stubEdsAccessorCloser) DataHash(context.Context) (share.DataHash, error) { - return share.DataHash{}, nil +func (s *stubEdsAccessorCloser) DataHash(context.Context) (square.DataHash, error) { + return square.DataHash{}, nil } -func (s *stubEdsAccessorCloser) AxisRoots(context.Context) (*share.AxisRoots, error) { - return &share.AxisRoots{}, nil +func (s *stubEdsAccessorCloser) AxisRoots(context.Context) (*square.AxisRoots, error) { + return &square.AxisRoots{}, nil } func (s *stubEdsAccessorCloser) Sample(context.Context, int, int) (shwap.Sample, error) { diff --git a/share/eds/edstest/testing.go b/square/eds/edstest/testing.go similarity index 69% rename from share/eds/edstest/testing.go rename to square/eds/edstest/testing.go index 56d5b3f4b7..8eb11409bb 100644 --- a/share/eds/edstest/testing.go +++ b/square/eds/edstest/testing.go @@ -7,24 +7,22 @@ import ( "github.com/stretchr/testify/require" coretypes "github.com/tendermint/tendermint/types" - "github.com/celestiaorg/celestia-app/v2/app" - "github.com/celestiaorg/celestia-app/v2/app/encoding" - "github.com/celestiaorg/celestia-app/v2/pkg/appconsts" - "github.com/celestiaorg/celestia-app/v2/pkg/da" - "github.com/celestiaorg/celestia-app/v2/pkg/user" - "github.com/celestiaorg/celestia-app/v2/pkg/wrapper" - "github.com/celestiaorg/celestia-app/v2/test/util/blobfactory" - "github.com/celestiaorg/celestia-app/v2/test/util/testfactory" - "github.com/celestiaorg/celestia-app/v2/x/blob/types" - "github.com/celestiaorg/go-square/blob" - "github.com/celestiaorg/go-square/namespace" + "github.com/celestiaorg/celestia-app/v3/app" + "github.com/celestiaorg/celestia-app/v3/app/encoding" + "github.com/celestiaorg/celestia-app/v3/pkg/appconsts" + "github.com/celestiaorg/celestia-app/v3/pkg/da" + "github.com/celestiaorg/celestia-app/v3/pkg/user" + "github.com/celestiaorg/celestia-app/v3/pkg/wrapper" + "github.com/celestiaorg/celestia-app/v3/test/util/blobfactory" + "github.com/celestiaorg/celestia-app/v3/test/util/testfactory" + blobtypes "github.com/celestiaorg/celestia-app/v3/x/blob/types" appshares "github.com/celestiaorg/go-square/shares" - "github.com/celestiaorg/go-square/square" + libSquare "github.com/celestiaorg/go-square/square" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt" "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/sharetest" + "github.com/celestiaorg/celestia-node/square" ) const ( @@ -35,10 +33,10 @@ const ( func RandByzantineEDS(t testing.TB, odsSize int, options ...nmt.Option) *rsmt2d.ExtendedDataSquare { eds := RandEDS(t, odsSize) shares := eds.Flattened() - copy(share.GetData(shares[0]), share.GetData(shares[1])) // corrupting eds + copy(shares[0][share.NamespaceSize:], shares[1][share.NamespaceSize:]) // corrupting eds eds, err := rsmt2d.ImportExtendedDataSquare( shares, - share.DefaultRSMT2DCodec(), + square.DefaultRSMT2DCodec(), wrapper.NewConstructor(uint64(odsSize), options...), ) require.NoError(t, err, "failure to recompute the extended data square") @@ -47,10 +45,10 @@ func RandByzantineEDS(t testing.TB, odsSize int, options ...nmt.Option) *rsmt2d. // RandEDS generates EDS filled with the random data with the given size for original square. func RandEDS(t testing.TB, odsSize int) *rsmt2d.ExtendedDataSquare { - shares := sharetest.RandShares(t, odsSize*odsSize) + shares := share.RandShares(odsSize * odsSize) eds, err := rsmt2d.ComputeExtendedDataSquare( - shares, - share.DefaultRSMT2DCodec(), + share.ToBytes(shares), + square.DefaultRSMT2DCodec(), wrapper.NewConstructor(uint64(odsSize)), ) require.NoError(t, err, "failure to recompute the extended data square") @@ -59,15 +57,15 @@ func RandEDS(t testing.TB, odsSize int) *rsmt2d.ExtendedDataSquare { // RandEDSWithTailPadding generates EDS of given ODS size filled with randomized and tail padding shares. func RandEDSWithTailPadding(t testing.TB, odsSize, padding int) *rsmt2d.ExtendedDataSquare { - shares := sharetest.RandShares(t, odsSize*odsSize) + shares := share.RandShares(odsSize * odsSize) for i := len(shares) - padding; i < len(shares); i++ { - paddingShare := appshares.TailPaddingShare() - shares[i] = paddingShare.ToBytes() + paddingShare := share.TailPaddingShare() + shares[i] = paddingShare } eds, err := rsmt2d.ComputeExtendedDataSquare( - shares, - share.DefaultRSMT2DCodec(), + share.ToBytes(shares), + square.DefaultRSMT2DCodec(), wrapper.NewConstructor(uint64(odsSize)), ) require.NoError(t, err, "failure to recompute the extended data square") @@ -80,21 +78,21 @@ func RandEDSWithNamespace( t testing.TB, namespace share.Namespace, namespacedAmount, odsSize int, -) (*rsmt2d.ExtendedDataSquare, *share.AxisRoots) { - shares := sharetest.RandSharesWithNamespace(t, namespace, namespacedAmount, odsSize*odsSize) +) (*rsmt2d.ExtendedDataSquare, *square.AxisRoots) { + shares := share.RandSharesWithNamespace(namespace, namespacedAmount, odsSize*odsSize) eds, err := rsmt2d.ComputeExtendedDataSquare( - shares, - share.DefaultRSMT2DCodec(), + share.ToBytes(shares), + square.DefaultRSMT2DCodec(), wrapper.NewConstructor(uint64(odsSize)), ) require.NoError(t, err, "failure to recompute the extended data square") - roots, err := share.NewAxisRoots(eds) + roots, err := square.NewAxisRoots(eds) require.NoError(t, err) return eds, roots } -// RandomAxisRoots generates random share.AxisRoots for the given eds size. -func RandomAxisRoots(t testing.TB, edsSize int) *share.AxisRoots { +// RandomAxisRoots generates random square.AxisRoots for the given eds size. +func RandomAxisRoots(t testing.TB, edsSize int) *square.AxisRoots { roots := make([][]byte, edsSize*2) for i := range roots { root := make([]byte, edsSize) @@ -105,7 +103,7 @@ func RandomAxisRoots(t testing.TB, edsSize int) *share.AxisRoots { rows := roots[:edsSize] cols := roots[edsSize:] - return &share.AxisRoots{ + return &square.AxisRoots{ RowRoots: rows, ColumnRoots: cols, } @@ -117,9 +115,9 @@ func GenerateTestBlock( t *testing.T, blobSize, numberOfTransactions int, ) ( - []*types.MsgPayForBlobs, - []*blob.Blob, - []namespace.Namespace, + []*blobtypes.MsgPayForBlobs, + []*share.Blob, + []share.Namespace, *rsmt2d.ExtendedDataSquare, coretypes.Txs, *da.DataAvailabilityHeader, @@ -133,7 +131,7 @@ func GenerateTestBlock( txs := make(coretypes.Txs, 0) txs = append(txs, coreTxs...) - dataSquare, err := square.Construct( + dataSquare, err := libSquare.Construct( txs.ToSliceOfBytes(), appconsts.SquareSizeUpperBound(appconsts.LatestVersion), appconsts.SubtreeRootThreshold(appconsts.LatestVersion), @@ -159,10 +157,10 @@ func GenerateTestBlock( func createTestBlobTransactions( t *testing.T, numberOfTransactions, size int, -) ([]namespace.Namespace, []*types.MsgPayForBlobs, []*blob.Blob, []coretypes.Tx) { - nss := make([]namespace.Namespace, 0) - msgs := make([]*types.MsgPayForBlobs, 0) - blobs := make([]*blob.Blob, 0) +) ([]share.Namespace, []*blobtypes.MsgPayForBlobs, []*share.Blob, []coretypes.Tx) { + nss := make([]share.Namespace, 0) + msgs := make([]*blobtypes.MsgPayForBlobs, 0) + blobs := make([]*share.Blob, 0) coreTxs := make([]coretypes.Tx, 0) config := encoding.MakeConfig(app.ModuleEncodingRegisters...) keyring := testfactory.TestKeyring(config.Codec, accountName) @@ -187,11 +185,11 @@ func createTestBlobTransaction( t *testing.T, signer *user.Signer, size int, -) (namespace.Namespace, *types.MsgPayForBlobs, *blob.Blob, coretypes.Tx) { - ns := namespace.RandomBlobNamespace() +) (share.Namespace, *blobtypes.MsgPayForBlobs, *share.Blob, coretypes.Tx) { + ns := share.RandomBlobNamespace() account := signer.Account(accountName) msg, b := blobfactory.RandMsgPayForBlobsWithNamespaceAndSigner(account.Address().String(), ns, size) - cTx, _, err := signer.CreatePayForBlobs(accountName, []*blob.Blob{b}) + cTx, _, err := signer.CreatePayForBlobs(accountName, []*share.Blob{b}) require.NoError(t, err) return ns, msg, b, cTx } diff --git a/share/eds/nd.go b/square/eds/nd.go similarity index 79% rename from share/eds/nd.go rename to square/eds/nd.go index 36de7a0234..1ba186e083 100644 --- a/share/eds/nd.go +++ b/square/eds/nd.go @@ -4,8 +4,10 @@ import ( "context" "fmt" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/shwap" + "github.com/celestiaorg/go-square/v2/share" + + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/shwap" ) // NamespaceData extracts shares for a specific namespace from an EDS, considering @@ -20,7 +22,7 @@ func NamespaceData( if err != nil { return nil, fmt.Errorf("failed to get AxisRoots: %w", err) } - rowIdxs := share.RowsWithNamespace(roots, namespace) + rowIdxs := square.RowsWithNamespace(roots, namespace) rows := make(shwap.NamespaceData, len(rowIdxs)) for i, idx := range rowIdxs { rows[i], err = eds.RowNamespaceData(ctx, namespace, idx) diff --git a/share/eds/nd_test.go b/square/eds/nd_test.go similarity index 81% rename from share/eds/nd_test.go rename to square/eds/nd_test.go index d711c811bd..dba512a644 100644 --- a/share/eds/nd_test.go +++ b/square/eds/nd_test.go @@ -7,8 +7,9 @@ import ( "github.com/stretchr/testify/require" - "github.com/celestiaorg/celestia-node/share/eds/edstest" - "github.com/celestiaorg/celestia-node/share/sharetest" + "github.com/celestiaorg/go-square/v2/share" + + "github.com/celestiaorg/celestia-node/square/eds/edstest" ) func TestNamespaceData(t *testing.T) { @@ -17,7 +18,7 @@ func TestNamespaceData(t *testing.T) { const odsSize = 8 sharesAmount := odsSize * odsSize - namespace := sharetest.RandV0Namespace() + namespace := share.RandomNamespace() for amount := 1; amount < sharesAmount; amount++ { eds, root := edstest.RandEDSWithNamespace(t, namespace, amount, odsSize) rsmt2d := &Rsmt2D{ExtendedDataSquare: eds} diff --git a/share/eds/proof.go b/square/eds/proof.go similarity index 92% rename from share/eds/proof.go rename to square/eds/proof.go index 58b34d3b79..2e9d8912cc 100644 --- a/share/eds/proof.go +++ b/square/eds/proof.go @@ -6,8 +6,8 @@ import ( coretypes "github.com/tendermint/tendermint/proto/tendermint/types" "github.com/tendermint/tendermint/types" - pkgproof "github.com/celestiaorg/celestia-app/v2/pkg/proof" - "github.com/celestiaorg/go-square/shares" + pkgproof "github.com/celestiaorg/celestia-app/v3/pkg/proof" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" ) @@ -16,7 +16,7 @@ import ( func ProveShares(eds *rsmt2d.ExtendedDataSquare, start, end int) (*types.ShareProof, error) { log.Debugw("proving share range", "start", start, "end", end) - odsShares, err := shares.FromBytes(eds.FlattenedODS()) + odsShares, err := share.FromBytes(eds.FlattenedODS()) if err != nil { return nil, err } @@ -25,7 +25,7 @@ func ProveShares(eds *rsmt2d.ExtendedDataSquare, start, end int) (*types.SharePr return nil, err } log.Debugw("generating the share proof", "start", start, "end", end) - proof, err := pkgproof.NewShareInclusionProofFromEDS(eds, nID, shares.NewRange(start, end)) + proof, err := pkgproof.NewShareInclusionProofFromEDS(eds, nID, share.NewRange(start, end)) if err != nil { return nil, err } diff --git a/share/eds/proofs_cache.go b/square/eds/proofs_cache.go similarity index 93% rename from share/eds/proofs_cache.go rename to square/eds/proofs_cache.go index 3090f46322..6f28240a11 100644 --- a/share/eds/proofs_cache.go +++ b/square/eds/proofs_cache.go @@ -12,13 +12,14 @@ import ( blocks "github.com/ipfs/go-block-format" "github.com/ipfs/go-cid" - "github.com/celestiaorg/celestia-app/v2/pkg/wrapper" + "github.com/celestiaorg/celestia-app/v3/pkg/wrapper" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt" "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/ipld" - "github.com/celestiaorg/celestia-node/share/shwap" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/ipld" + "github.com/celestiaorg/celestia-node/square/shwap" ) var _ AccessorStreamer = (*proofsCache)(nil) @@ -33,9 +34,9 @@ type proofsCache struct { // size caches the size of the data square size atomic.Int32 // dataHash caches the data hash - dataHash atomic.Pointer[share.DataHash] + dataHash atomic.Pointer[square.DataHash] // rootsCache caches the axis roots - rootsCache atomic.Pointer[share.AxisRoots] + rootsCache atomic.Pointer[square.AxisRoots] // axisCacheLock protects proofCache axisCacheLock sync.RWMutex // axisCache caches the axis Shares and proofs. Index in the slice corresponds to the axis type. @@ -83,7 +84,7 @@ func (c *proofsCache) Size(ctx context.Context) int { return int(size) } -func (c *proofsCache) DataHash(ctx context.Context) (share.DataHash, error) { +func (c *proofsCache) DataHash(ctx context.Context) (square.DataHash, error) { dataHash := c.dataHash.Load() if dataHash != nil { return *dataHash, nil @@ -96,7 +97,7 @@ func (c *proofsCache) DataHash(ctx context.Context) (share.DataHash, error) { return loaded, nil } -func (c *proofsCache) AxisRoots(ctx context.Context) (*share.AxisRoots, error) { +func (c *proofsCache) AxisRoots(ctx context.Context) (*square.AxisRoots, error) { roots := c.rootsCache.Load() if roots != nil { return roots, nil @@ -165,7 +166,7 @@ func (c *proofsCache) axisWithProofs(ctx context.Context, axisType rsmt2d.Axis, nmt.NodeVisitor(adder.VisitFn()), ) for _, shr := range ax.shares { - err := tree.Push(shr) + err := tree.Push(shr.ToBytes()) if err != nil { return axisWithProofs{}, fmt.Errorf("push shares: %w", err) } @@ -317,7 +318,7 @@ func (c *proofsCache) getShare(rowIdx, colIdx int) ([]byte, error) { if half.IsParity { colIdx -= odsSize } - return half.Shares[colIdx], nil + return half.Shares[colIdx].ToBytes(), nil } // if share index is from opposite part of axis, obtain full axis shares @@ -325,7 +326,7 @@ func (c *proofsCache) getShare(rowIdx, colIdx int) ([]byte, error) { if err != nil { return nil, fmt.Errorf("reading axis shares: %w", err) } - return shares[colIdx], nil + return shares[colIdx].ToBytes(), nil } // rowProofsGetter implements blockservice.BlockGetter interface diff --git a/share/eds/proofs_cache_test.go b/square/eds/proofs_cache_test.go similarity index 100% rename from share/eds/proofs_cache_test.go rename to square/eds/proofs_cache_test.go diff --git a/share/eds/read.go b/square/eds/read.go similarity index 80% rename from share/eds/read.go rename to square/eds/read.go index 83149ca1ce..0090a7c1a9 100644 --- a/share/eds/read.go +++ b/square/eds/read.go @@ -7,13 +7,15 @@ import ( "fmt" "io" - "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/go-square/v2/share" + + "github.com/celestiaorg/celestia-node/square" ) // ReadAccessor reads up EDS out of the io.Reader until io.EOF and provides. -func ReadAccessor(ctx context.Context, reader io.Reader, root *share.AxisRoots) (*Rsmt2D, error) { +func ReadAccessor(ctx context.Context, reader io.Reader, root *square.AxisRoots) (*Rsmt2D, error) { odsSize := len(root.RowRoots) / 2 - shares, err := ReadShares(reader, share.Size, odsSize) + shares, err := ReadShares(reader, share.ShareSize, odsSize) if err != nil { return nil, fmt.Errorf("failed to read eds from ods bytes: %w", err) } @@ -43,19 +45,22 @@ func ReadShares(r io.Reader, shareSize, odsSize int) ([]share.Share, error) { shares := make([]share.Share, odsSize*odsSize) var total int for i := range shares { - shr := make(share.Share, shareSize) + shr := make([]byte, shareSize) n, err := io.ReadFull(r, shr) if errors.Is(err, io.EOF) { for ; i < len(shares); i++ { - shares[i] = share.TailPadding() + shares[i] = share.TailPaddingShare() } return shares, nil } if err != nil { return nil, fmt.Errorf("reading shares: %w, bytes read: %v", err, total+n) } - - shares[i] = shr + newShare, err := share.NewShare(shr) + if err != nil { + return nil, err + } + shares[i] = *newShare total += n } return shares, nil diff --git a/share/eds/retriever.go b/square/eds/retriever.go similarity index 93% rename from share/eds/retriever.go rename to square/eds/retriever.go index c3483809af..53b79aacd7 100644 --- a/share/eds/retriever.go +++ b/square/eds/retriever.go @@ -15,13 +15,14 @@ import ( "go.opentelemetry.io/otel/codes" "go.opentelemetry.io/otel/trace" - "github.com/celestiaorg/celestia-app/v2/pkg/wrapper" + "github.com/celestiaorg/celestia-app/v3/pkg/wrapper" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt" "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/eds/byzantine" - "github.com/celestiaorg/celestia-node/share/ipld" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/eds/byzantine" + "github.com/celestiaorg/celestia-node/square/ipld" ) var ( @@ -56,7 +57,7 @@ func NewRetriever(bServ blockservice.BlockService) *Retriever { // data square and reconstructs the other three quadrants (3/4). If the requested quadrant is not // available within RetrieveQuadrantTimeout, it starts requesting another quadrant until either the // data is reconstructed, context is canceled or ErrByzantine is generated. -func (r *Retriever) Retrieve(ctx context.Context, roots *share.AxisRoots) (*rsmt2d.ExtendedDataSquare, error) { +func (r *Retriever) Retrieve(ctx context.Context, roots *square.AxisRoots) (*rsmt2d.ExtendedDataSquare, error) { ctx, cancel := context.WithCancel(ctx) defer cancel() // cancels all the ongoing requests if reconstruction succeeds early @@ -106,7 +107,7 @@ func (r *Retriever) Retrieve(ctx context.Context, roots *share.AxisRoots) (*rsmt // quadrant request retries. Also, provides an API // to reconstruct the block once enough shares are fetched. type retrievalSession struct { - roots *share.AxisRoots + roots *square.AxisRoots bget blockservice.BlockGetter adder *ipld.NmtNodeAdder @@ -124,7 +125,7 @@ type retrievalSession struct { } // newSession creates a new retrieval session and kicks off requesting process. -func (r *Retriever) newSession(ctx context.Context, roots *share.AxisRoots) (*retrievalSession, error) { +func (r *Retriever) newSession(ctx context.Context, roots *square.AxisRoots) (*retrievalSession, error) { size := len(roots.RowRoots) adder := ipld.NewNmtNodeAdder(ctx, r.bServ, ipld.MaxSizeBatchOption(size)) @@ -142,7 +143,7 @@ func (r *Retriever) newSession(ctx context.Context, roots *share.AxisRoots) (*re return &tree } - square, err := rsmt2d.NewExtendedDataSquare(share.DefaultRSMT2DCodec(), treeFn, uint(size), share.Size) + square, err := rsmt2d.NewExtendedDataSquare(square.DefaultRSMT2DCodec(), treeFn, uint(size), share.ShareSize) if err != nil { return nil, err } @@ -279,7 +280,7 @@ func (rs *retrievalSession) doRequest(ctx context.Context, q *quadrant) { // and go get shares of left or the right side of the whole col/row axis // the left or the right side of the tree represent some portion of the quadrant // which we put into the rs.square share-by-share by calculating shares' indexes using q.index - ipld.GetShares(ctx, rs.bget, nd.Links()[q.x].Cid, size, func(j int, share share.Share) { + ipld.GetShares(ctx, rs.bget, nd.Links()[q.x].Cid, size, func(j int, rawShare []byte) { // NOTE: Each share can appear twice here, for a Row and Col, respectively. // These shares are always equal, and we allow only the first one to be written // in the square. @@ -306,7 +307,7 @@ func (rs *retrievalSession) doRequest(ctx context.Context, q *quadrant) { if rs.isReconstructed() { return } - if err := rs.square.SetCell(uint(x), uint(y), share); err != nil { + if err := rs.square.SetCell(uint(x), uint(y), rawShare); err != nil { // safe to ignore as: // * share size already verified // * the same share might come from either Row or Col diff --git a/share/eds/retriever_no_race_test.go b/square/eds/retriever_no_race_test.go similarity index 74% rename from share/eds/retriever_no_race_test.go rename to square/eds/retriever_no_race_test.go index e9b8dc1634..43165a0bce 100644 --- a/share/eds/retriever_no_race_test.go +++ b/square/eds/retriever_no_race_test.go @@ -9,14 +9,15 @@ import ( "github.com/stretchr/testify/require" - "github.com/celestiaorg/celestia-app/v2/pkg/wrapper" + "github.com/celestiaorg/celestia-app/v3/pkg/wrapper" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt" "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/eds/byzantine" - "github.com/celestiaorg/celestia-node/share/eds/edstest" - "github.com/celestiaorg/celestia-node/share/ipld" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/eds/byzantine" + "github.com/celestiaorg/celestia-node/square/eds/edstest" + "github.com/celestiaorg/celestia-node/square/ipld" ) func TestRetriever_ByzantineError(t *testing.T) { @@ -36,7 +37,7 @@ func TestRetriever_ByzantineError(t *testing.T) { batchAdder := ipld.NewNmtNodeAdder(ctx, bserv, ipld.MaxSizeBatchOption(width*2)) attackerEDS, err := rsmt2d.ImportExtendedDataSquare( shares, - share.DefaultRSMT2DCodec(), + square.DefaultRSMT2DCodec(), wrapper.NewConstructor(uint64(width), nmt.NodeVisitor(batchAdder.Visit)), ) @@ -45,7 +46,7 @@ func TestRetriever_ByzantineError(t *testing.T) { require.NoError(t, err) // ensure we rcv an error - roots, err := share.NewAxisRoots(attackerEDS) + roots, err := square.NewAxisRoots(attackerEDS) require.NoError(t, err) r := NewRetriever(bserv) _, err = r.Retrieve(ctx, roots) diff --git a/share/eds/retriever_quadrant.go b/square/eds/retriever_quadrant.go similarity index 94% rename from share/eds/retriever_quadrant.go rename to square/eds/retriever_quadrant.go index 97a5b332f2..6450926948 100644 --- a/share/eds/retriever_quadrant.go +++ b/square/eds/retriever_quadrant.go @@ -8,8 +8,8 @@ import ( "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/ipld" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/ipld" ) const ( @@ -49,7 +49,7 @@ type quadrant struct { // newQuadrants constructs a slice of quadrants from DAHeader. // There are always 4 quadrants per each source (row and col), so 8 in total. // The ordering of quadrants is random. -func newQuadrants(roots *share.AxisRoots) []*quadrant { +func newQuadrants(roots *square.AxisRoots) []*quadrant { // combine all the roots into one slice, so they can be easily accessible by index daRoots := [][][]byte{ roots.RowRoots, diff --git a/share/eds/retriever_test.go b/square/eds/retriever_test.go similarity index 92% rename from share/eds/retriever_test.go rename to square/eds/retriever_test.go index 2381b7cd75..1fd2c4632f 100644 --- a/share/eds/retriever_test.go +++ b/square/eds/retriever_test.go @@ -11,15 +11,15 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" "github.com/celestiaorg/celestia-node/header" "github.com/celestiaorg/celestia-node/header/headertest" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/eds/byzantine" - "github.com/celestiaorg/celestia-node/share/eds/edstest" - "github.com/celestiaorg/celestia-node/share/ipld" - "github.com/celestiaorg/celestia-node/share/sharetest" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/eds/byzantine" + "github.com/celestiaorg/celestia-node/square/eds/edstest" + "github.com/celestiaorg/celestia-node/square/ipld" ) func TestRetriever_Retrieve(t *testing.T) { @@ -41,12 +41,12 @@ func TestRetriever_Retrieve(t *testing.T) { {"16x16(med)", 16}, {"32x32(med)", 32}, {"64x64(med)", 64}, - {"128x128(max)", share.MaxSquareSize}, + {"128x128(max)", square.MaxSquareSize}, } for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { // generate EDS - shares := sharetest.RandShares(t, tc.squareSize*tc.squareSize) + shares := share.RandShares(tc.squareSize * tc.squareSize) in, err := ipld.AddShares(ctx, shares, bServ) require.NoError(t, err) @@ -54,7 +54,7 @@ func TestRetriever_Retrieve(t *testing.T) { ctx, cancel := context.WithTimeout(ctx, time.Minute*5) // the timeout is big for the max size which is long defer cancel() - roots, err := share.NewAxisRoots(in) + roots, err := square.NewAxisRoots(in) require.NoError(t, err) out, err := r.Retrieve(ctx, roots) require.NoError(t, err) @@ -75,11 +75,11 @@ func TestRetriever_MultipleRandQuadrants(t *testing.T) { r := NewRetriever(bServ) // generate EDS - shares := sharetest.RandShares(t, squareSize*squareSize) + shares := share.RandShares(squareSize * squareSize) in, err := ipld.AddShares(ctx, shares, bServ) require.NoError(t, err) - roots, err := share.NewAxisRoots(in) + roots, err := square.NewAxisRoots(in) require.NoError(t, err) ses, err := r.newSession(ctx, roots) require.NoError(t, err) diff --git a/share/eds/rsmt2d.go b/square/eds/rsmt2d.go similarity index 68% rename from share/eds/rsmt2d.go rename to square/eds/rsmt2d.go index 416e3530a5..0dfc044498 100644 --- a/share/eds/rsmt2d.go +++ b/square/eds/rsmt2d.go @@ -5,11 +5,12 @@ import ( "fmt" "io" - "github.com/celestiaorg/celestia-app/v2/pkg/wrapper" + "github.com/celestiaorg/celestia-app/v3/pkg/wrapper" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/shwap" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/shwap" ) var _ AccessorStreamer = (*Rsmt2D)(nil) @@ -25,17 +26,17 @@ func (eds *Rsmt2D) Size(context.Context) int { } // DataHash returns data hash of the Accessor. -func (eds *Rsmt2D) DataHash(context.Context) (share.DataHash, error) { - roots, err := share.NewAxisRoots(eds.ExtendedDataSquare) +func (eds *Rsmt2D) DataHash(context.Context) (square.DataHash, error) { + roots, err := square.NewAxisRoots(eds.ExtendedDataSquare) if err != nil { - return share.DataHash{}, fmt.Errorf("while creating data root: %w", err) + return square.DataHash{}, fmt.Errorf("while creating data root: %w", err) } return roots.Hash(), nil } // AxisRoots returns AxisRoots of the Accessor. -func (eds *Rsmt2D) AxisRoots(context.Context) (*share.AxisRoots, error) { - roots, err := share.NewAxisRoots(eds.ExtendedDataSquare) +func (eds *Rsmt2D) AxisRoots(context.Context) (*square.AxisRoots, error) { + roots, err := square.NewAxisRoots(eds.ExtendedDataSquare) if err != nil { return nil, fmt.Errorf("while creating axis roots: %w", err) } @@ -57,11 +58,14 @@ func (eds *Rsmt2D) SampleForProofAxis( proofType rsmt2d.Axis, ) (shwap.Sample, error) { axisIdx, shrIdx := relativeIndexes(rowIdx, colIdx, proofType) - shares := getAxis(eds.ExtendedDataSquare, proofType, axisIdx) + shares, err := getAxis(eds.ExtendedDataSquare, proofType, axisIdx) + if err != nil { + return shwap.Sample{}, err + } tree := wrapper.NewErasuredNamespacedMerkleTree(uint64(eds.Width()/2), uint(axisIdx)) for _, shr := range shares { - err := tree.Push(shr) + err := tree.Push(shr.ToBytes()) if err != nil { return shwap.Sample{}, fmt.Errorf("while pushing shares to NMT: %w", err) } @@ -81,7 +85,10 @@ func (eds *Rsmt2D) SampleForProofAxis( // AxisHalf returns Shares for the first half of the axis of the given type and index. func (eds *Rsmt2D) AxisHalf(_ context.Context, axisType rsmt2d.Axis, axisIdx int) (AxisHalf, error) { - shares := getAxis(eds.ExtendedDataSquare, axisType, axisIdx) + shares, err := getAxis(eds.ExtendedDataSquare, axisType, axisIdx) + if err != nil { + return AxisHalf{}, fmt.Errorf("while getting axis share: %w", err) + } halfShares := shares[:eds.Width()/2] return AxisHalf{ Shares: halfShares, @@ -91,9 +98,13 @@ func (eds *Rsmt2D) AxisHalf(_ context.Context, axisType rsmt2d.Axis, axisIdx int // HalfRow constructs a new shwap.Row from an Extended Data Square based on the specified index and // side. -func (eds *Rsmt2D) HalfRow(idx int, side shwap.RowSide) shwap.Row { +func (eds *Rsmt2D) HalfRow(idx int, side shwap.RowSide) (shwap.Row, error) { shares := eds.ExtendedDataSquare.Row(uint(idx)) - return shwap.RowFromShares(shares, side) + sh, err := share.FromBytes(shares) + if err != nil { + return shwap.Row{}, fmt.Errorf("while converting shares from bytes: %w", err) + } + return shwap.RowFromShares(sh, side), nil } // RowNamespaceData returns data for the given namespace and row index. @@ -103,13 +114,17 @@ func (eds *Rsmt2D) RowNamespaceData( rowIdx int, ) (shwap.RowNamespaceData, error) { shares := eds.Row(uint(rowIdx)) - return shwap.RowNamespaceDataFromShares(shares, namespace, rowIdx) + sh, err := share.FromBytes(shares) + if err != nil { + return shwap.RowNamespaceData{}, fmt.Errorf("while converting shares from bytes: %w", err) + } + return shwap.RowNamespaceDataFromShares(sh, namespace, rowIdx) } // Shares returns data (ODS) shares extracted from the EDS. It returns new copy of the shares each // time. func (eds *Rsmt2D) Shares(_ context.Context) ([]share.Share, error) { - return eds.ExtendedDataSquare.FlattenedODS(), nil + return share.FromBytes(eds.ExtendedDataSquare.FlattenedODS()) } func (eds *Rsmt2D) Close() error { @@ -129,7 +144,7 @@ func (eds *Rsmt2D) Reader() (io.Reader, error) { // Rsmt2DFromShares constructs an Extended Data Square from shares. func Rsmt2DFromShares(shares []share.Share, odsSize int) (*Rsmt2D, error) { treeFn := wrapper.NewConstructor(uint64(odsSize)) - eds, err := rsmt2d.ComputeExtendedDataSquare(shares, share.DefaultRSMT2DCodec(), treeFn) + eds, err := rsmt2d.ComputeExtendedDataSquare(share.ToBytes(shares), square.DefaultRSMT2DCodec(), treeFn) if err != nil { return &Rsmt2D{}, fmt.Errorf("computing extended data square: %w", err) } @@ -137,12 +152,14 @@ func Rsmt2DFromShares(shares []share.Share, odsSize int) (*Rsmt2D, error) { return &Rsmt2D{eds}, nil } -func getAxis(eds *rsmt2d.ExtendedDataSquare, axisType rsmt2d.Axis, axisIdx int) []share.Share { +func getAxis(eds *rsmt2d.ExtendedDataSquare, axisType rsmt2d.Axis, axisIdx int) ([]share.Share, error) { switch axisType { case rsmt2d.Row: - return eds.Row(uint(axisIdx)) + sh, err := share.FromBytes(eds.Row(uint(axisIdx))) + return sh, err case rsmt2d.Col: - return eds.Col(uint(axisIdx)) + sh, err := share.FromBytes(eds.Col(uint(axisIdx))) + return sh, err default: panic("unknown axis") } diff --git a/share/eds/rsmt2d_test.go b/square/eds/rsmt2d_test.go similarity index 78% rename from share/eds/rsmt2d_test.go rename to square/eds/rsmt2d_test.go index a639aa96e0..58ee60211c 100644 --- a/share/eds/rsmt2d_test.go +++ b/square/eds/rsmt2d_test.go @@ -7,11 +7,12 @@ import ( "github.com/stretchr/testify/require" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/eds/edstest" - "github.com/celestiaorg/celestia-node/share/shwap" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/eds/edstest" + "github.com/celestiaorg/celestia-node/square/shwap" ) func TestRsmt2dAccessor(t *testing.T) { @@ -36,12 +37,13 @@ func TestRsmt2dHalfRow(t *testing.T) { for rowIdx := 0; rowIdx < odsSize*2; rowIdx++ { for _, side := range []shwap.RowSide{shwap.Left, shwap.Right} { - row := eds.HalfRow(rowIdx, side) + row, err := eds.HalfRow(rowIdx, side) + require.NoError(t, err) want := eds.Row(uint(rowIdx)) shares, err := row.Shares() require.NoError(t, err) - require.Equal(t, want, shares) + require.Equal(t, want, share.ToBytes(shares)) } } } @@ -58,7 +60,7 @@ func TestRsmt2dSampleForProofAxis(t *testing.T) { require.NoError(t, err) want := eds.GetCell(uint(rowIdx), uint(colIdx)) - require.Equal(t, want, sample.Share) + require.Equal(t, want, sample.Share.ToBytes()) require.Equal(t, proofType, sample.ProofType) require.NotNil(t, sample.Proof) require.Equal(t, sample.Proof.End()-sample.Proof.Start(), 1) @@ -68,9 +70,9 @@ func TestRsmt2dSampleForProofAxis(t *testing.T) { } } -func randRsmt2dAccsessor(t *testing.T, size int) (Rsmt2D, *share.AxisRoots) { +func randRsmt2dAccsessor(t *testing.T, size int) (Rsmt2D, *square.AxisRoots) { eds := edstest.RandEDS(t, size) - root, err := share.NewAxisRoots(eds) + root, err := square.NewAxisRoots(eds) require.NoError(t, err) return Rsmt2D{ExtendedDataSquare: eds}, root } diff --git a/share/eds/share_reader.go b/square/eds/share_reader.go similarity index 100% rename from share/eds/share_reader.go rename to square/eds/share_reader.go diff --git a/share/eds/share_reader_test.go b/square/eds/share_reader_test.go similarity index 87% rename from share/eds/share_reader_test.go rename to square/eds/share_reader_test.go index 3cd67a08cd..cb4e6d19ff 100644 --- a/share/eds/share_reader_test.go +++ b/square/eds/share_reader_test.go @@ -8,8 +8,9 @@ import ( "github.com/stretchr/testify/require" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/eds/edstest" + "github.com/celestiaorg/go-square/v2/share" + + "github.com/celestiaorg/celestia-node/square/eds/edstest" ) func TestShareReader(t *testing.T) { @@ -23,7 +24,7 @@ func TestShareReader(t *testing.T) { reader := NewShareReader(odsSize, getShare) readBytes, err := readWithRandomBuffer(reader, 1024) require.NoError(t, err) - expected := make([]byte, 0, odsSize*odsSize*share.Size) + expected := make([]byte, 0, odsSize*odsSize*share.ShareSize) for _, share := range eds.FlattenedODS() { expected = append(expected, share...) } diff --git a/share/eds/testing.go b/square/eds/testing.go similarity index 89% rename from share/eds/testing.go rename to square/eds/testing.go index 8549cf3ca1..f7a1bf0f89 100644 --- a/share/eds/testing.go +++ b/square/eds/testing.go @@ -10,13 +10,13 @@ import ( "github.com/stretchr/testify/require" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt" "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/eds/edstest" - "github.com/celestiaorg/celestia-node/share/sharetest" - "github.com/celestiaorg/celestia-node/share/shwap" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/eds/edstest" + "github.com/celestiaorg/celestia-node/square/shwap" ) type ( @@ -84,7 +84,7 @@ func testEDSes(t *testing.T, sizes ...int) map[string]*rsmt2d.ExtendedDataSquare testEDSes[fmt.Sprintf("PaddedODS:%d", size)] = paddingEds } - testEDSes["EmptyODS"] = share.EmptyEDS() + testEDSes["EmptyODS"] = square.EmptyEDS() return testEDSes } @@ -110,12 +110,12 @@ func testAccessorDataHash( ) { acc := createAccessor(t, eds) - expected, err := share.NewAxisRoots(eds) + expected, err := square.NewAxisRoots(eds) require.NoError(t, err) datahash, err := acc.DataHash(ctx) require.NoError(t, err) - require.Equal(t, share.DataHash(expected.Hash()), datahash) + require.Equal(t, square.DataHash(expected.Hash()), datahash) } func testAccessorAxisRoots( @@ -126,7 +126,7 @@ func testAccessorAxisRoots( ) { acc := createAccessor(t, eds) - expected, err := share.NewAxisRoots(eds) + expected, err := square.NewAxisRoots(eds) require.NoError(t, err) roots, err := acc.AxisRoots(ctx) @@ -143,7 +143,7 @@ func testAccessorSample( width := int(eds.Width()) t.Run("single thread", func(t *testing.T) { acc := createAccessor(t, eds) - roots, err := share.NewAxisRoots(eds) + roots, err := square.NewAxisRoots(eds) require.NoError(t, err) // t.Parallel() this fails the test for some reason for rowIdx := 0; rowIdx < width; rowIdx++ { @@ -156,7 +156,7 @@ func testAccessorSample( t.Run("parallel", func(t *testing.T) { t.Parallel() acc := createAccessor(t, eds) - roots, err := share.NewAxisRoots(eds) + roots, err := square.NewAxisRoots(eds) require.NoError(t, err) wg := sync.WaitGroup{} for rowIdx := 0; rowIdx < width; rowIdx++ { @@ -174,7 +174,7 @@ func testAccessorSample( t.Run("random", func(t *testing.T) { t.Parallel() acc := createAccessor(t, eds) - roots, err := share.NewAxisRoots(eds) + roots, err := square.NewAxisRoots(eds) require.NoError(t, err) wg := sync.WaitGroup{} @@ -194,7 +194,7 @@ func testSample( ctx context.Context, t *testing.T, acc Accessor, - roots *share.AxisRoots, + roots *square.AxisRoots, rowIdx, colIdx int, ) { shr, err := acc.Sample(ctx, rowIdx, colIdx) @@ -214,7 +214,7 @@ func testAccessorRowNamespaceData( t.Parallel() // generate EDS with random data and some Shares with the same namespace sharesAmount := odsSize * odsSize - namespace := sharetest.RandV0Namespace() + namespace := share.RandomNamespace() // test with different amount of shares for amount := 1; amount < sharesAmount; amount++ { // select random amount of shares, but not less than 1 @@ -250,7 +250,7 @@ func testAccessorRowNamespaceData( t.Parallel() // generate EDS with random data and some Shares with the same namespace eds := edstest.RandEDS(t, odsSize) - roots, err := share.NewAxisRoots(eds) + roots, err := square.NewAxisRoots(eds) require.NoError(t, err) // loop over first half of the rows, because the second half is parity and does not contain @@ -258,7 +258,10 @@ func testAccessorRowNamespaceData( for i, root := range roots.RowRoots[:odsSize] { // select namespace that within the range of root namespaces, but is not included maxNs := nmt.MaxNamespace(root, share.NamespaceSize) - absentNs, err := share.Namespace(maxNs).AddInt(-1) + ns, err := share.NewNamespaceFromBytes(maxNs) + require.NoError(t, err) + + absentNs, err := share.AddInt(ns, -1) require.NoError(t, err) acc := createAccessor(t, eds) @@ -293,9 +296,13 @@ func testAccessorAxisHalf( var expected []share.Share if half.IsParity { - expected = getAxis(eds, axisType, axisIdx)[odsSize:] + expected, err = getAxis(eds, axisType, axisIdx) + require.NoError(t, err) + expected = expected[odsSize:] } else { - expected = getAxis(eds, axisType, axisIdx)[:odsSize] + expected, err = getAxis(eds, axisType, axisIdx) + require.NoError(t, err) + expected = expected[:odsSize] } require.Equal(t, expected, half.Shares) @@ -317,11 +324,15 @@ func testAccessorAxisHalf( var expected []share.Share if half.IsParity { - expected = getAxis(eds, axisType, idx)[odsSize:] + expected, err = getAxis(eds, axisType, idx) + require.NoError(t, err) + expected = expected[odsSize:] } else { - expected = getAxis(eds, axisType, idx)[:odsSize] + expected, err = getAxis(eds, axisType, idx) + require.NoError(t, err) + expected = expected[:odsSize] } - + require.NoError(t, err) require.Equal(t, expected, half.Shares) }(axisType, i) } @@ -346,7 +357,9 @@ func testAccessorShares( shares, err := acc.Shares(ctx) require.NoError(t, err) expected := eds.FlattenedODS() - require.Equal(t, expected, shares) + sh, err := share.FromBytes(expected) + require.NoError(t, err) + require.Equal(t, sh, shares) }() } wg.Wait() @@ -377,7 +390,7 @@ func testReader(ctx context.Context, t *testing.T, eds *rsmt2d.ExtendedDataSquar reader, err := as.Reader() require.NoError(t, err) - roots, err := share.NewAxisRoots(eds) + roots, err := square.NewAxisRoots(eds) require.NoError(t, err) actual, err := ReadAccessor(ctx, reader, roots) diff --git a/share/eds/validation.go b/square/eds/validation.go similarity index 94% rename from share/eds/validation.go rename to square/eds/validation.go index 41ec6c45c4..c8d7c632f7 100644 --- a/share/eds/validation.go +++ b/square/eds/validation.go @@ -6,10 +6,10 @@ import ( "fmt" "sync/atomic" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/shwap" + "github.com/celestiaorg/celestia-node/square/shwap" ) var _ Accessor = validation{} diff --git a/share/eds/validation_test.go b/square/eds/validation_test.go similarity index 92% rename from share/eds/validation_test.go rename to square/eds/validation_test.go index 4be8dc7230..0d0b3bf42e 100644 --- a/share/eds/validation_test.go +++ b/square/eds/validation_test.go @@ -7,11 +7,11 @@ import ( "github.com/stretchr/testify/require" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/share/eds/edstest" - "github.com/celestiaorg/celestia-node/share/sharetest" - "github.com/celestiaorg/celestia-node/share/shwap" + "github.com/celestiaorg/celestia-node/square/eds/edstest" + "github.com/celestiaorg/celestia-node/square/shwap" ) func TestValidation_Sample(t *testing.T) { @@ -91,7 +91,7 @@ func TestValidation_RowNamespaceData(t *testing.T) { accessor := &Rsmt2D{ExtendedDataSquare: randEDS} validation := WithValidation(AccessorAndStreamer(accessor, nil)) - ns := sharetest.RandV0Namespace() + ns := share.RandomNamespace() _, err := validation.RowNamespaceData(context.Background(), ns, tt.rowIdx) if tt.expectFail { require.ErrorIs(t, err, shwap.ErrInvalidID) diff --git a/share/empty.go b/square/empty.go similarity index 76% rename from share/empty.go rename to square/empty.go index 4ffd6ade82..b683715a3e 100644 --- a/share/empty.go +++ b/square/empty.go @@ -1,13 +1,12 @@ -package share +package square import ( "bytes" "fmt" "sync" - "github.com/celestiaorg/celestia-app/v2/pkg/appconsts" - "github.com/celestiaorg/celestia-app/v2/pkg/da" - "github.com/celestiaorg/go-square/shares" + "github.com/celestiaorg/celestia-app/v3/pkg/da" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" ) @@ -30,7 +29,7 @@ func EmptyEDS() *rsmt2d.ExtendedDataSquare { } // EmptyBlockShares returns the shares of the empty block. -func EmptyBlockShares() []Share { +func EmptyBlockShares() []share.Share { initEmpty() return emptyBlockShares } @@ -40,7 +39,7 @@ var ( emptyBlockDataHash DataHash emptyBlockRoots *AxisRoots emptyBlockEDS *rsmt2d.ExtendedDataSquare - emptyBlockShares []Share + emptyBlockShares []share.Share ) // initEmpty enables lazy initialization for constant empty block data. @@ -50,10 +49,10 @@ func initEmpty() { func computeEmpty() { // compute empty block EDS and DAH for it - result := shares.TailPaddingShares(appconsts.MinShareCount) - emptyBlockShares = shares.ToBytes(result) + result := share.TailPaddingShares(share.MinShareCount) + rawEmptyBlockShares := share.ToBytes(result) - eds, err := da.ExtendShares(emptyBlockShares) + eds, err := da.ExtendShares(rawEmptyBlockShares) if err != nil { panic(fmt.Errorf("failed to create empty EDS: %w", err)) } @@ -69,6 +68,11 @@ func computeEmpty() { "expected %s, got %s", minDAH.String(), emptyBlockRoots.String())) } + sh := eds.FlattenedODS() + emptyBlockShares, err = share.FromBytes(sh) + if err != nil { + panic(fmt.Errorf("failed to create shares: %w", err)) + } // precompute Hash, so it's cached internally to avoid potential races emptyBlockDataHash = emptyBlockRoots.Hash() } diff --git a/share/ipld/add.go b/square/ipld/add.go similarity index 90% rename from share/ipld/add.go rename to square/ipld/add.go index 42705557ae..f200f28309 100644 --- a/share/ipld/add.go +++ b/square/ipld/add.go @@ -6,12 +6,13 @@ import ( "github.com/ipfs/boxo/blockservice" - "github.com/celestiaorg/celestia-app/v2/pkg/wrapper" + "github.com/celestiaorg/celestia-app/v3/pkg/wrapper" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt" "github.com/celestiaorg/rsmt2d" "github.com/celestiaorg/celestia-node/libs/utils" - "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/square" ) // AddShares erasures and extends shares to blockservice.BlockService using the provided @@ -30,8 +31,8 @@ func AddShares( // create the nmt wrapper to generate row and col commitments // recompute the eds eds, err := rsmt2d.ComputeExtendedDataSquare( - shares, - share.DefaultRSMT2DCodec(), + share.ToBytes(shares), + square.DefaultRSMT2DCodec(), wrapper.NewConstructor(uint64(squareSize), nmt.NodeVisitor(batchAdder.Visit)), ) @@ -63,7 +64,7 @@ func ImportShares( // recompute the eds eds, err := rsmt2d.ImportExtendedDataSquare( shares, - share.DefaultRSMT2DCodec(), + square.DefaultRSMT2DCodec(), wrapper.NewConstructor(uint64(squareSize/2), nmt.NodeVisitor(batchAdder.Visit)), ) diff --git a/share/ipld/blockserv.go b/square/ipld/blockserv.go similarity index 100% rename from share/ipld/blockserv.go rename to square/ipld/blockserv.go diff --git a/share/ipld/delete.go b/square/ipld/delete.go similarity index 100% rename from share/ipld/delete.go rename to square/ipld/delete.go diff --git a/share/ipld/delete_test.go b/square/ipld/delete_test.go similarity index 94% rename from share/ipld/delete_test.go rename to square/ipld/delete_test.go index 745c938822..e6953ba5f3 100644 --- a/share/ipld/delete_test.go +++ b/square/ipld/delete_test.go @@ -12,7 +12,7 @@ import ( "github.com/ipfs/go-datastore/sync" "github.com/stretchr/testify/require" - "github.com/celestiaorg/celestia-node/share/sharetest" + "github.com/celestiaorg/go-square/v2/share" ) func TestDeleteNode_FullSquare(t *testing.T) { @@ -21,7 +21,7 @@ func TestDeleteNode_FullSquare(t *testing.T) { defer cancel() bServ := NewMemBlockservice() - shares := sharetest.RandShares(t, size*size) + shares := share.RandShares(size * size) eds, err := AddShares(ctx, shares, bServ) require.NoError(t, err) @@ -63,7 +63,7 @@ func TestDeleteNode_Sample(t *testing.T) { defer cancel() full := NewMemBlockservice() - shares := sharetest.RandShares(t, size*size) + shares := share.RandShares(size * size) eds, err := AddShares(ctx, shares, full) require.NoError(t, err) diff --git a/share/ipld/get.go b/square/ipld/get.go similarity index 97% rename from share/ipld/get.go rename to square/ipld/get.go index 9e85f7ccc9..a5769adf40 100644 --- a/share/ipld/get.go +++ b/square/ipld/get.go @@ -11,7 +11,7 @@ import ( "github.com/ipfs/go-cid" ipld "github.com/ipfs/go-ipld-format" - "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/square" ) // NumWorkersLimit sets global limit for workers spawned by GetShares. @@ -26,7 +26,7 @@ import ( // // TODO(@Wondertan): This assumes we have parallelized DASer implemented. Sync the values once it is shipped. // TODO(@Wondertan): Allow configuration of values without global state. -var NumWorkersLimit = share.MaxSquareSize * share.MaxSquareSize / 2 * NumConcurrentSquares +var NumWorkersLimit = square.MaxSquareSize * square.MaxSquareSize / 2 * NumConcurrentSquares // NumConcurrentSquares limits the amount of squares that are fetched // concurrently/simultaneously. diff --git a/share/ipld/get_shares.go b/square/ipld/get_shares.go similarity index 79% rename from share/ipld/get_shares.go rename to square/ipld/get_shares.go index 773e09c7d0..5872daeb41 100644 --- a/share/ipld/get_shares.go +++ b/square/ipld/get_shares.go @@ -7,9 +7,8 @@ import ( "github.com/ipfs/go-cid" format "github.com/ipfs/go-ipld-format" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt" - - "github.com/celestiaorg/celestia-node/share" ) // GetShare fetches and returns the data for leaf `leafIndex` of root `rootCid`. @@ -22,18 +21,22 @@ func GetShare( ) (share.Share, error) { nd, err := GetLeaf(ctx, bGetter, rootCid, leafIndex, totalLeafs) if err != nil { - return nil, err + return share.Share{}, err } - return leafToShare(nd), nil + sh, err := share.NewShare(nd.RawData()[share.NamespaceSize:]) + if err != nil { + return share.Share{}, err + } + return *sh, nil } // GetShares walks the tree of a given root and puts shares into the given 'put' func. // Does not return any error, and returns/unblocks only on success // (got all shares) or on context cancellation. -func GetShares(ctx context.Context, bg blockservice.BlockGetter, root cid.Cid, shares int, put func(int, share.Share)) { +func GetShares(ctx context.Context, bg blockservice.BlockGetter, root cid.Cid, shares int, put func(int, []byte)) { putNode := func(i int, leaf format.Node) { - put(i, leafToShare(leaf)) + put(i, leaf.RawData()[share.NamespaceSize:]) } GetLeaves(ctx, bg, root, shares, putNode) } @@ -63,15 +66,12 @@ func GetSharesByNamespace( shares := make([]share.Share, len(leaves)) for i, leaf := range leaves { if leaf != nil { - shares[i] = leafToShare(leaf) + sh, err := share.NewShare(leaf.RawData()[share.NamespaceSize:]) + if err != nil { + return nil, nil, err + } + shares[i] = *sh } } return shares, data.Proof(), nil } - -// leafToShare converts an NMT leaf into a Share. -func leafToShare(nd format.Node) share.Share { - // * Additional namespace is prepended so that parity data can be identified with a parity - // namespace, which we cut off - return share.GetData(nd.RawData()) -} diff --git a/share/ipld/get_shares_test.go b/square/ipld/get_shares_test.go similarity index 85% rename from share/ipld/get_shares_test.go rename to square/ipld/get_shares_test.go index 220c00d015..75399d77bf 100644 --- a/share/ipld/get_shares_test.go +++ b/square/ipld/get_shares_test.go @@ -1,7 +1,6 @@ package ipld import ( - "bytes" "context" "errors" mrand "math/rand" @@ -15,13 +14,13 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/celestiaorg/celestia-app/v2/pkg/wrapper" + "github.com/celestiaorg/celestia-app/v3/pkg/wrapper" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" "github.com/celestiaorg/celestia-node/libs/utils" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/eds/edstest" - "github.com/celestiaorg/celestia-node/share/sharetest" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/eds/edstest" ) func TestGetShare(t *testing.T) { @@ -32,7 +31,7 @@ func TestGetShare(t *testing.T) { bServ := NewMemBlockservice() // generate random shares for the nmt - shares := sharetest.RandShares(t, size*size) + shares := share.RandShares(size * size) eds, err := AddShares(ctx, shares, bServ) require.NoError(t, err) @@ -54,8 +53,8 @@ func TestBlockRecovery(t *testing.T) { extendedShareCount := extendedSquareWidth * extendedSquareWidth // generate test data - quarterShares := sharetest.RandShares(t, shareCount) - allShares := sharetest.RandShares(t, shareCount) + quarterShares := share.RandShares(shareCount) + allShares := share.RandShares(shareCount) testCases := []struct { name string @@ -74,8 +73,8 @@ func TestBlockRecovery(t *testing.T) { squareSize := utils.SquareSize(len(tc.shares)) testEds, err := rsmt2d.ComputeExtendedDataSquare( - tc.shares, - share.DefaultRSMT2DCodec(), + share.ToBytes(tc.shares), + square.DefaultRSMT2DCodec(), wrapper.NewConstructor(squareSize), ) require.NoError(t, err) @@ -92,7 +91,7 @@ func TestBlockRecovery(t *testing.T) { rdata := removeRandShares(flat, tc.d) testEds, err = rsmt2d.ImportExtendedDataSquare( rdata, - share.DefaultRSMT2DCodec(), + square.DefaultRSMT2DCodec(), wrapper.NewConstructor(squareSize), ) require.NoError(t, err) @@ -105,7 +104,7 @@ func TestBlockRecovery(t *testing.T) { } assert.NoError(t, err) - reds, err := rsmt2d.ImportExtendedDataSquare(rdata, share.DefaultRSMT2DCodec(), wrapper.NewConstructor(squareSize)) + reds, err := rsmt2d.ImportExtendedDataSquare(rdata, square.DefaultRSMT2DCodec(), wrapper.NewConstructor(squareSize)) require.NoError(t, err) // check that the squares are equal assert.Equal(t, testEds.Flattened(), reds.Flattened()) @@ -115,18 +114,18 @@ func TestBlockRecovery(t *testing.T) { func Test_ConvertEDStoShares(t *testing.T) { squareWidth := 16 - shares := sharetest.RandShares(t, squareWidth*squareWidth) + shares := share.RandShares(squareWidth * squareWidth) // compute extended square testEds, err := rsmt2d.ComputeExtendedDataSquare( - shares, - share.DefaultRSMT2DCodec(), + share.ToBytes(shares), + square.DefaultRSMT2DCodec(), wrapper.NewConstructor(uint64(squareWidth)), ) require.NoError(t, err) resshares := testEds.FlattenedODS() - require.Equal(t, shares, resshares) + require.Equal(t, share.ToBytes(shares), resshares) } // removes d shares from data @@ -152,15 +151,15 @@ func TestGetSharesByNamespace(t *testing.T) { tests := []struct { rawData []share.Share }{ - {rawData: sharetest.RandShares(t, 4)}, - {rawData: sharetest.RandShares(t, 16)}, + {rawData: share.RandShares(4)}, + {rawData: share.RandShares(16)}, } for i, tt := range tests { t.Run(strconv.Itoa(i), func(t *testing.T) { // choose random namespace from rand shares expected := tt.rawData[len(tt.rawData)/2] - namespace := share.GetNamespace(expected) + namespace := expected.Namespace() // change rawData to contain several shares with same namespace tt.rawData[(len(tt.rawData)/2)+1] = expected @@ -194,12 +193,12 @@ func TestCollectLeavesByNamespace_IncompleteData(t *testing.T) { t.Cleanup(cancel) bServ := NewMemBlockservice() - shares := sharetest.RandShares(t, 16) + shares := share.RandShares(16) // set all shares to the same namespace id - namespace := share.GetNamespace(shares[0]) + namespace := shares[0].Namespace() for _, shr := range shares { - copy(share.GetNamespace(shr), namespace) + copy(shr.Namespace().Bytes(), namespace.Bytes()) } eds, err := AddShares(ctx, shares, bServ) @@ -238,7 +237,7 @@ func TestCollectLeavesByNamespace_AbsentNamespaceId(t *testing.T) { t.Cleanup(cancel) bServ := NewMemBlockservice() - shares := sharetest.RandShares(t, 1024) + shares := share.RandShares(1024) // set all shares to the same namespace namespaces, err := randomNamespaces(5) @@ -252,10 +251,10 @@ func TestCollectLeavesByNamespace_AbsentNamespaceId(t *testing.T) { secondNamespaceFrom := mrand.Intn(len(shares)-2) + 1 for i, shr := range shares { if i < secondNamespaceFrom { - copy(share.GetNamespace(shr), minIncluded) + copy(shr.Namespace().Bytes(), minIncluded.Bytes()) continue } - copy(share.GetNamespace(shr), maxIncluded) + copy(shr.Namespace().Bytes(), maxIncluded.Bytes()) } tests := []struct { @@ -283,10 +282,10 @@ func TestCollectLeavesByNamespace_MultipleRowsContainingSameNamespaceId(t *testi t.Cleanup(cancel) bServ := NewMemBlockservice() - shares := sharetest.RandShares(t, 16) + shares := share.RandShares(16) // set all shares to the same namespace and data but the last one - namespace := share.GetNamespace(shares[0]) + namespace := shares[0].Namespace() commonNamespaceData := shares[0] for i, nspace := range shares { @@ -294,7 +293,7 @@ func TestCollectLeavesByNamespace_MultipleRowsContainingSameNamespaceId(t *testi break } - copy(nspace, commonNamespaceData) + copy(nspace.ToBytes(), commonNamespaceData.ToBytes()) } eds, err := AddShares(ctx, shares, bServ) @@ -315,7 +314,9 @@ func TestCollectLeavesByNamespace_MultipleRowsContainingSameNamespaceId(t *testi for _, node := range leaves { // test that the data returned by collectLeavesByNamespace for nid // matches the commonNamespaceData that was copied across almost all data - assert.Equal(t, commonNamespaceData, share.GetData(node.RawData())) + sh, err := share.NewShare(node.RawData()[share.NamespaceSize:]) + require.NoError(t, err) + assert.Equal(t, commonNamespaceData, *sh) } } } @@ -328,9 +329,9 @@ func TestGetSharesWithProofsByNamespace(t *testing.T) { tests := []struct { rawData []share.Share }{ - {rawData: sharetest.RandShares(t, 4)}, - {rawData: sharetest.RandShares(t, 16)}, - {rawData: sharetest.RandShares(t, 64)}, + {rawData: share.RandShares(4)}, + {rawData: share.RandShares(16)}, + {rawData: share.RandShares(64)}, } for i, tt := range tests { @@ -345,7 +346,7 @@ func TestGetSharesWithProofsByNamespace(t *testing.T) { } expected := tt.rawData[from] - namespace := share.GetNamespace(expected) + namespace := expected.Namespace() // change rawData to contain several shares with same namespace for i := from; i <= to; i++ { @@ -374,22 +375,22 @@ func TestGetSharesWithProofsByNamespace(t *testing.T) { // construct nodes from shares by prepending namespace var leaves [][]byte for _, shr := range rowShares { - leaves = append(leaves, append(share.GetNamespace(shr), shr...)) + leaves = append(leaves, append(shr.Namespace().Bytes(), shr.ToBytes()...)) } // verify namespace verified := proof.VerifyNamespace( - share.NewSHA256Hasher(), - namespace.ToNMT(), + square.NewSHA256Hasher(), + namespace.Bytes(), leaves, row) require.True(t, verified) // verify inclusion verified = proof.VerifyInclusion( - share.NewSHA256Hasher(), - namespace.ToNMT(), - rowShares, + square.NewSHA256Hasher(), + namespace.Bytes(), + share.ToBytes(rowShares), row) require.True(t, verified) } @@ -424,7 +425,10 @@ func TestBatchSize(t *testing.T) { bs := NewMemBlockservice() randEds := edstest.RandEDS(t, tt.origWidth) - _, err := AddShares(ctx, randEds.FlattenedODS(), bs) + + shrs, err := share.FromBytes(randEds.FlattenedODS()) + require.NoError(t, err) + _, err = AddShares(ctx, shrs, bs) require.NoError(t, err) out, err := bs.Blockstore().AllKeysChan(ctx) @@ -478,7 +482,7 @@ func assertNoRowContainsNID( // if no error returned, check absence proof foundAbsenceRows++ - verified := data.Proof().VerifyNamespace(share.NewSHA256Hasher(), namespace.ToNMT(), nil, rowRoot) + verified := data.Proof().VerifyNamespace(square.NewSHA256Hasher(), namespace.Bytes(), nil, rowRoot) require.True(t, verified) } @@ -492,8 +496,8 @@ func assertNoRowContainsNID( func randomNamespaces(total int) ([]share.Namespace, error) { namespaces := make([]share.Namespace, total) for i := range namespaces { - namespaces[i] = sharetest.RandV0Namespace() + namespaces[i] = share.RandomNamespace() } - sort.Slice(namespaces, func(i, j int) bool { return bytes.Compare(namespaces[i], namespaces[j]) < 0 }) + sort.Slice(namespaces, func(i, j int) bool { return namespaces[i].IsLessThan(namespaces[j]) }) return namespaces, nil } diff --git a/share/ipld/namespace_data.go b/square/ipld/namespace_data.go similarity index 97% rename from share/ipld/namespace_data.go rename to square/ipld/namespace_data.go index 13cd958b47..2c2ddaf3df 100644 --- a/share/ipld/namespace_data.go +++ b/square/ipld/namespace_data.go @@ -11,10 +11,10 @@ import ( "github.com/ipfs/go-cid" ipld "github.com/ipfs/go-ipld-format" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/shwap" + "github.com/celestiaorg/celestia-node/square/shwap" ) var ErrNamespaceOutsideRange = shwap.ErrNamespaceOutsideRange @@ -71,7 +71,7 @@ func NewNamespaceData(maxShares int, namespace share.Namespace, options ...Optio } func (n *NamespaceData) validate(rootCid cid.Cid) error { - if err := n.namespace.Validate(); err != nil { + if err := share.ValidateUserNamespace(n.namespace.Version(), n.namespace.ID()); err != nil { return err } diff --git a/share/ipld/nmt.go b/square/ipld/nmt.go similarity index 93% rename from share/ipld/nmt.go rename to square/ipld/nmt.go index 0a433372b2..c96c081168 100644 --- a/share/ipld/nmt.go +++ b/square/ipld/nmt.go @@ -16,10 +16,10 @@ import ( mh "github.com/multiformats/go-multihash" mhcore "github.com/multiformats/go-multihash/core" - "github.com/celestiaorg/celestia-app/v2/pkg/appconsts" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt" - "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/square" ) var log = logging.Logger("ipld") @@ -42,7 +42,7 @@ const ( InnerNodeSize = NmtHashSize * 2 // LeafNodeSize is the size of data in leaf nodes. - LeafNodeSize = share.NamespaceSize + appconsts.ShareSize + LeafNodeSize = share.NamespaceSize + share.ShareSize // cidPrefixSize is the size of the prepended buffer of the CID encoding // for NamespacedSha256. For more information, see: @@ -58,7 +58,7 @@ const ( func init() { // required for Bitswap to hash and verify inbound data correctly mhcore.Register(sha256NamespaceFlagged, func() hash.Hash { - nh := nmt.NewNmtHasher(share.NewSHA256Hasher(), share.NamespaceSize, true) + nh := nmt.NewNmtHasher(square.NewSHA256Hasher(), share.NamespaceSize, true) nh.Reset() return nh }) @@ -157,7 +157,7 @@ func MustCidFromNamespacedSha256(hash []byte) cid.Cid { // Translate transforms square coordinates into IPLD NMT tree path to a leaf node. // It also adds randomization to evenly spread fetching from Rows and Columns. -func Translate(roots *share.AxisRoots, row, col int) (cid.Cid, int) { +func Translate(roots *square.AxisRoots, row, col int) (cid.Cid, int) { if rand.Intn(2) == 0 { //nolint:gosec return MustCidFromNamespacedSha256(roots.ColumnRoots[col]), row } diff --git a/share/ipld/nmt_adder.go b/square/ipld/nmt_adder.go similarity index 100% rename from share/ipld/nmt_adder.go rename to square/ipld/nmt_adder.go diff --git a/share/ipld/nmt_test.go b/square/ipld/nmt_test.go similarity index 85% rename from share/ipld/nmt_test.go rename to square/ipld/nmt_test.go index 040c68ec1d..a2133492c8 100644 --- a/share/ipld/nmt_test.go +++ b/square/ipld/nmt_test.go @@ -9,8 +9,8 @@ import ( "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/eds/edstest" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/eds/edstest" ) // TestNamespaceFromCID checks that deriving the Namespaced hash from @@ -26,7 +26,7 @@ func TestNamespaceFromCID(t *testing.T) { for i, tt := range tests { t.Run(strconv.Itoa(i), func(t *testing.T) { - roots, err := share.NewAxisRoots(tt.eds) + roots, err := square.NewAxisRoots(tt.eds) require.NoError(t, err) // check to make sure NamespacedHash is correctly derived from CID for _, row := range roots.RowRoots { diff --git a/share/ipld/proof_collector.go b/square/ipld/proof_collector.go similarity index 100% rename from share/ipld/proof_collector.go rename to square/ipld/proof_collector.go diff --git a/share/ipld/proofs.go b/square/ipld/proofs.go similarity index 100% rename from share/ipld/proofs.go rename to square/ipld/proofs.go diff --git a/share/ipld/proofs_test.go b/square/ipld/proofs_test.go similarity index 79% rename from share/ipld/proofs_test.go rename to square/ipld/proofs_test.go index 7ff438e577..ca28499b82 100644 --- a/share/ipld/proofs_test.go +++ b/square/ipld/proofs_test.go @@ -7,11 +7,11 @@ import ( "github.com/stretchr/testify/require" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/sharetest" - "github.com/celestiaorg/celestia-node/share/shwap" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/shwap" ) func TestGetProof(t *testing.T) { @@ -21,11 +21,11 @@ func TestGetProof(t *testing.T) { defer cancel() bServ := NewMemBlockservice() - shares := sharetest.RandShares(t, width*width) + shares := share.RandShares(width * width) in, err := AddShares(ctx, shares, bServ) require.NoError(t, err) - axisRoots, err := share.NewAxisRoots(in) + axisRoots, err := square.NewAxisRoots(in) require.NoError(t, err) for _, proofType := range []rsmt2d.Axis{rsmt2d.Row, rsmt2d.Col} { @@ -45,8 +45,10 @@ func TestGetProof(t *testing.T) { node, err := GetLeaf(ctx, bServ, rootCid, shrIdx, int(in.Width())) require.NoError(t, err) + sh, err := share.NewShare(node.RawData()[share.NamespaceSize:]) + require.NoError(t, err) sample := shwap.Sample{ - Share: share.GetData(node.RawData()), + Share: *sh, Proof: &proof, ProofType: proofType, } diff --git a/share/ipld/test_helpers.go b/square/ipld/test_helpers.go similarity index 100% rename from share/ipld/test_helpers.go rename to square/ipld/test_helpers.go diff --git a/share/ipld/utils.go b/square/ipld/utils.go similarity index 51% rename from share/ipld/utils.go rename to square/ipld/utils.go index b74d1d937d..1333dddd78 100644 --- a/share/ipld/utils.go +++ b/square/ipld/utils.go @@ -3,12 +3,14 @@ package ipld import ( "github.com/ipfs/go-cid" - "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/go-square/v2/share" + + "github.com/celestiaorg/celestia-node/square" ) -// FilterRootByNamespace returns the row roots from the given share.AxisRoots that contain the +// FilterRootByNamespace returns the row roots from the given square.AxisRoots that contain the // namespace. -func FilterRootByNamespace(root *share.AxisRoots, namespace share.Namespace) []cid.Cid { +func FilterRootByNamespace(root *square.AxisRoots, namespace share.Namespace) []cid.Cid { rowRootCIDs := make([]cid.Cid, 0, len(root.RowRoots)) for _, row := range root.RowRoots { if !namespace.IsOutsideRange(row, row) { diff --git a/share/namespace.go b/square/namespace.go similarity index 96% rename from share/namespace.go rename to square/namespace.go index 8e1c5b4bb1..65c5a0390c 100644 --- a/share/namespace.go +++ b/square/namespace.go @@ -1,4 +1,4 @@ -package share +package square import ( "bytes" @@ -8,6 +8,7 @@ import ( "fmt" appns "github.com/celestiaorg/go-square/namespace" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt/namespace" ) @@ -75,10 +76,10 @@ func (n Namespace) ToNMT() namespace.ID { return namespace.ID(n) } -// ToAppNamespace converts the Namespace to App's definition of Namespace. -// TODO: Unify types between node and app -func (n Namespace) ToAppNamespace() appns.Namespace { - return appns.Namespace{Version: n.Version(), ID: n.ID()} +// // ToAppNamespace converts the Namespace to App's definition of Namespace. +// // TODO: Unify types between node and app +func (n Namespace) ToAppNamespace() (share.Namespace, error) { + return share.NewNamespace(n.Version(), n.ID()) } // Len reports the total length of the namespace. diff --git a/share/root.go b/square/root.go similarity index 92% rename from share/root.go rename to square/root.go index ee912c4df2..f4c1045662 100644 --- a/share/root.go +++ b/square/root.go @@ -1,4 +1,4 @@ -package share +package square import ( "bytes" @@ -7,7 +7,8 @@ import ( "fmt" "hash" - "github.com/celestiaorg/celestia-app/v2/pkg/da" + "github.com/celestiaorg/celestia-app/v3/pkg/da" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" ) @@ -58,7 +59,7 @@ func NewAxisRoots(eds *rsmt2d.ExtendedDataSquare) (*AxisRoots, error) { // RowsWithNamespace inspects the AxisRoots for the Namespace and provides // a slices of Row indexes containing the namespace. -func RowsWithNamespace(root *AxisRoots, namespace Namespace) (idxs []int) { +func RowsWithNamespace(root *AxisRoots, namespace share.Namespace) (idxs []int) { for i, row := range root.RowRoots { if !namespace.IsOutsideRange(row, row) { idxs = append(idxs, i) diff --git a/square/share.go b/square/share.go new file mode 100644 index 0000000000..696a6bc948 --- /dev/null +++ b/square/share.go @@ -0,0 +1,40 @@ +package square + +import ( + "github.com/celestiaorg/celestia-app/v3/pkg/appconsts" + "github.com/celestiaorg/go-square/v2/share" + "github.com/celestiaorg/nmt" + "github.com/celestiaorg/rsmt2d" +) + +// DefaultRSMT2DCodec sets the default rsmt2d.Codec for shares. +var DefaultRSMT2DCodec = appconsts.DefaultCodec + +// MaxSquareSize is currently the maximum size supported for unerasured data in +// rsmt2d.ExtendedDataSquare. +var MaxSquareSize = appconsts.SquareSizeUpperBound(appconsts.LatestVersion) + +// ShareWithProof contains data with corresponding Merkle Proof +type ShareWithProof struct { //nolint: revive + // Share is a full data including namespace + share.Share + // Proof is a Merkle Proof of current share + Proof *nmt.Proof + // Axis is a type of axis against which the share proof is computed + Axis rsmt2d.Axis +} + +// Validate validates inclusion of the share under the given root CID. +func (s *ShareWithProof) Validate(rootHash []byte, x, y, edsSize int) bool { + isParity := x >= edsSize/2 || y >= edsSize/2 + namespace := share.ParitySharesNamespace + if !isParity { + namespace = s.Share.Namespace() + } + return s.Proof.VerifyInclusion( + NewSHA256Hasher(), + namespace.Bytes(), + [][]byte{s.Share.ToBytes()}, + rootHash, + ) +} diff --git a/share/shwap/eds.go b/square/shwap/eds.go similarity index 100% rename from share/shwap/eds.go rename to square/shwap/eds.go diff --git a/share/shwap/eds_id.go b/square/shwap/eds_id.go similarity index 100% rename from share/shwap/eds_id.go rename to square/shwap/eds_id.go diff --git a/share/shwap/eds_id_test.go b/square/shwap/eds_id_test.go similarity index 100% rename from share/shwap/eds_id_test.go rename to square/shwap/eds_id_test.go diff --git a/share/shwap/getter.go b/square/shwap/getter.go similarity index 97% rename from share/shwap/getter.go rename to square/shwap/getter.go index 8a2b3389f5..dfbe36432e 100644 --- a/share/shwap/getter.go +++ b/square/shwap/getter.go @@ -5,10 +5,10 @@ import ( "errors" "fmt" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" "github.com/celestiaorg/celestia-node/header" - "github.com/celestiaorg/celestia-node/share" ) var ( diff --git a/share/shwap/getters/cascade.go b/square/shwap/getters/cascade.go similarity index 96% rename from share/shwap/getters/cascade.go rename to square/shwap/getters/cascade.go index bcd36f64c0..5aeddafd30 100644 --- a/share/shwap/getters/cascade.go +++ b/square/shwap/getters/cascade.go @@ -10,13 +10,13 @@ import ( "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/trace" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" "github.com/celestiaorg/celestia-node/header" "github.com/celestiaorg/celestia-node/libs/utils" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/eds/byzantine" - "github.com/celestiaorg/celestia-node/share/shwap" + "github.com/celestiaorg/celestia-node/square/eds/byzantine" + "github.com/celestiaorg/celestia-node/square/shwap" ) var ( @@ -55,7 +55,7 @@ func (cg *CascadeGetter) GetShare( if row >= upperBound || col >= upperBound { err := shwap.ErrOutOfBounds span.RecordError(err) - return nil, err + return share.Share{}, err } get := func(ctx context.Context, get shwap.Getter) (share.Share, error) { return get.GetShare(ctx, header, row, col) diff --git a/share/shwap/getters/cascade_test.go b/square/shwap/getters/cascade_test.go similarity index 97% rename from share/shwap/getters/cascade_test.go rename to square/shwap/getters/cascade_test.go index a23568006f..0012780fbf 100644 --- a/share/shwap/getters/cascade_test.go +++ b/square/shwap/getters/cascade_test.go @@ -12,8 +12,8 @@ import ( "github.com/celestiaorg/rsmt2d" "github.com/celestiaorg/celestia-node/header" - "github.com/celestiaorg/celestia-node/share/shwap" - "github.com/celestiaorg/celestia-node/share/shwap/getters/mock" + "github.com/celestiaorg/celestia-node/square/shwap" + "github.com/celestiaorg/celestia-node/square/shwap/getters/mock" ) func TestCascadeGetter(t *testing.T) { diff --git a/share/shwap/getters/mock/getter.go b/square/shwap/getters/mock/getter.go similarity index 93% rename from share/shwap/getters/mock/getter.go rename to square/shwap/getters/mock/getter.go index 64e04a5132..5eb7be8ef6 100644 --- a/share/shwap/getters/mock/getter.go +++ b/square/shwap/getters/mock/getter.go @@ -9,8 +9,8 @@ import ( reflect "reflect" header "github.com/celestiaorg/celestia-node/header" - share "github.com/celestiaorg/celestia-node/share" - shwap "github.com/celestiaorg/celestia-node/share/shwap" + shwap "github.com/celestiaorg/celestia-node/square/shwap" + share "github.com/celestiaorg/go-square/v2/share" rsmt2d "github.com/celestiaorg/rsmt2d" gomock "github.com/golang/mock/gomock" ) @@ -54,10 +54,10 @@ func (mr *MockGetterMockRecorder) GetEDS(arg0, arg1 interface{}) *gomock.Call { } // GetShare mocks base method. -func (m *MockGetter) GetShare(arg0 context.Context, arg1 *header.ExtendedHeader, arg2, arg3 int) ([]byte, error) { +func (m *MockGetter) GetShare(arg0 context.Context, arg1 *header.ExtendedHeader, arg2, arg3 int) (share.Share, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetShare", arg0, arg1, arg2, arg3) - ret0, _ := ret[0].([]byte) + ret0, _ := ret[0].(share.Share) ret1, _ := ret[1].(error) return ret0, ret1 } diff --git a/share/shwap/getters/testing.go b/square/shwap/getters/testing.go similarity index 77% rename from share/shwap/getters/testing.go rename to square/shwap/getters/testing.go index 3714aa5260..a9eb55d034 100644 --- a/share/shwap/getters/testing.go +++ b/square/shwap/getters/testing.go @@ -7,20 +7,21 @@ import ( "github.com/stretchr/testify/require" - "github.com/celestiaorg/celestia-app/v2/pkg/da" + "github.com/celestiaorg/celestia-app/v3/pkg/da" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" "github.com/celestiaorg/celestia-node/header" "github.com/celestiaorg/celestia-node/header/headertest" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/eds/edstest" - "github.com/celestiaorg/celestia-node/share/shwap" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/eds/edstest" + "github.com/celestiaorg/celestia-node/square/shwap" ) // TestGetter provides a testing SingleEDSGetter and the root of the EDS it holds. func TestGetter(t *testing.T) (shwap.Getter, *header.ExtendedHeader) { eds := edstest.RandEDS(t, 8) - roots, err := share.NewAxisRoots(eds) + roots, err := square.NewAxisRoots(eds) eh := headertest.RandExtendedHeaderWithRoot(t, roots) require.NoError(t, err) return &SingleEDSGetter{ @@ -42,9 +43,14 @@ func (seg *SingleEDSGetter) GetShare( ) (share.Share, error) { err := seg.checkRoots(header.DAH) if err != nil { - return nil, err + return share.Share{}, err + } + rawSh := seg.EDS.GetCell(uint(row), uint(col)) + sh, err := share.NewShare(rawSh) + if err != nil { + return share.Share{}, err } - return seg.EDS.GetCell(uint(row), uint(col)), nil + return *sh, nil } // GetEDS returns a kept EDS if the correct root is given. @@ -65,7 +71,7 @@ func (seg *SingleEDSGetter) GetSharesByNamespace(context.Context, *header.Extend panic("SingleEDSGetter: GetSharesByNamespace is not implemented") } -func (seg *SingleEDSGetter) checkRoots(roots *share.AxisRoots) error { +func (seg *SingleEDSGetter) checkRoots(roots *square.AxisRoots) error { dah, err := da.NewDataAvailabilityHeader(seg.EDS) if err != nil { return err diff --git a/share/shwap/namespace_data.go b/square/shwap/namespace_data.go similarity index 89% rename from share/shwap/namespace_data.go rename to square/shwap/namespace_data.go index 656b886f2a..730d4e1c41 100644 --- a/share/shwap/namespace_data.go +++ b/square/shwap/namespace_data.go @@ -5,7 +5,9 @@ import ( "fmt" "io" - "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/go-square/v2/share" + + "github.com/celestiaorg/celestia-node/square" ) // NamespaceDataName is the name identifier for the namespace data container. @@ -27,8 +29,8 @@ func (nd NamespaceData) Flatten() []share.Share { } // Verify checks the integrity of the NamespaceData against a provided root and namespace. -func (nd NamespaceData) Verify(root *share.AxisRoots, namespace share.Namespace) error { - rowIdxs := share.RowsWithNamespace(root, namespace) +func (nd NamespaceData) Verify(root *square.AxisRoots, namespace share.Namespace) error { + rowIdxs := square.RowsWithNamespace(root, namespace) if len(rowIdxs) != len(nd) { return fmt.Errorf("expected %d rows, found %d rows", len(rowIdxs), len(nd)) } diff --git a/share/shwap/namespace_data_id.go b/square/shwap/namespace_data_id.go similarity index 91% rename from share/shwap/namespace_data_id.go rename to square/shwap/namespace_data_id.go index 63b5f22948..1488e41ba3 100644 --- a/share/shwap/namespace_data_id.go +++ b/square/shwap/namespace_data_id.go @@ -4,7 +4,7 @@ import ( "fmt" "io" - "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/go-square/v2/share" ) // NamespaceDataIDSize defines the total size of a NamespaceDataID in bytes, combining the @@ -48,7 +48,11 @@ func NamespaceDataIDFromBinary(data []byte) (NamespaceDataID, error) { return NamespaceDataID{}, fmt.Errorf("error unmarshaling EDSID: %w", err) } - ns := share.Namespace(data[EdsIDSize:]) + ns, err := share.NewNamespaceFromBytes(data[EdsIDSize:]) + if err != nil { + return NamespaceDataID{}, fmt.Errorf("error unmarshaling namespace: %w", err) + } + ndid := NamespaceDataID{ EdsID: edsID, DataNamespace: ns, @@ -107,7 +111,8 @@ func (ndid NamespaceDataID) Validate() error { if err := ndid.EdsID.Validate(); err != nil { return fmt.Errorf("validating RowID: %w", err) } - if err := ndid.DataNamespace.ValidateForData(); err != nil { + + if err := share.ValidateForData(ndid.DataNamespace); err != nil { return fmt.Errorf("%w: validating DataNamespace: %w", ErrInvalidID, err) } return nil @@ -116,5 +121,5 @@ func (ndid NamespaceDataID) Validate() error { // appendTo helps in appending the binary form of DataNamespace to the serialized RowID data. func (ndid NamespaceDataID) appendTo(data []byte) []byte { data = ndid.EdsID.appendTo(data) - return append(data, ndid.DataNamespace...) + return append(data, ndid.DataNamespace.Bytes()...) } diff --git a/share/shwap/namespace_data_id_test.go b/square/shwap/namespace_data_id_test.go similarity index 87% rename from share/shwap/namespace_data_id_test.go rename to square/shwap/namespace_data_id_test.go index 94b0a39703..daab44cdcf 100644 --- a/share/shwap/namespace_data_id_test.go +++ b/square/shwap/namespace_data_id_test.go @@ -7,11 +7,11 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/celestiaorg/celestia-node/share/sharetest" + "github.com/celestiaorg/go-square/v2/share" ) func TestNamespaceDataID(t *testing.T) { - ns := sharetest.RandV0Namespace() + ns := share.RandomNamespace() id, err := NewNamespaceDataID(1, ns) require.NoError(t, err) @@ -29,7 +29,7 @@ func TestNamespaceDataID(t *testing.T) { } func TestNamespaceDataIDReaderWriter(t *testing.T) { - ns := sharetest.RandV0Namespace() + ns := share.RandomNamespace() id, err := NewNamespaceDataID(1, ns) require.NoError(t, err) diff --git a/share/shwap/p2p/bitswap/bitswap.go b/square/shwap/p2p/bitswap/bitswap.go similarity index 100% rename from share/shwap/p2p/bitswap/bitswap.go rename to square/shwap/p2p/bitswap/bitswap.go diff --git a/share/shwap/p2p/bitswap/block.go b/square/shwap/p2p/bitswap/block.go similarity index 89% rename from share/shwap/p2p/bitswap/block.go rename to square/shwap/p2p/bitswap/block.go index 940afb5bc2..d42697722c 100644 --- a/share/shwap/p2p/bitswap/block.go +++ b/square/shwap/p2p/bitswap/block.go @@ -6,8 +6,8 @@ import ( "github.com/ipfs/go-cid" logger "github.com/ipfs/go-log/v2" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/eds" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/eds" ) var log = logger.Logger("shwap/bitswap") @@ -30,7 +30,7 @@ type Block interface { Marshal() ([]byte, error) // UnmarshalFn returns closure that unmarshal the Block with the Shwap container. // Unmarshalling involves data validation against the given AxisRoots. - UnmarshalFn(*share.AxisRoots) UnmarshalFn + UnmarshalFn(*square.AxisRoots) UnmarshalFn } // UnmarshalFn is a closure produced by a Block that unmarshalls and validates diff --git a/share/shwap/p2p/bitswap/block_fetch.go b/square/shwap/p2p/bitswap/block_fetch.go similarity index 98% rename from share/shwap/p2p/bitswap/block_fetch.go rename to square/shwap/p2p/bitswap/block_fetch.go index 94fe5dbdac..0c6245559d 100644 --- a/share/shwap/p2p/bitswap/block_fetch.go +++ b/square/shwap/p2p/bitswap/block_fetch.go @@ -11,7 +11,7 @@ import ( blocks "github.com/ipfs/go-block-format" "github.com/ipfs/go-cid" - "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/square" ) // WithFetcher instructs [Fetch] to use the given Fetcher. @@ -37,7 +37,7 @@ func WithStore(store blockstore.Blockstore) FetchOption { func Fetch( ctx context.Context, exchg exchange.Interface, - root *share.AxisRoots, + root *square.AxisRoots, blks []Block, opts ...FetchOption, ) error { @@ -62,7 +62,7 @@ func Fetch( func fetch( ctx context.Context, exchg exchange.Interface, - root *share.AxisRoots, + root *square.AxisRoots, blks []Block, opts ...FetchOption, ) error { diff --git a/share/shwap/p2p/bitswap/block_fetch_test.go b/square/shwap/p2p/bitswap/block_fetch_test.go similarity index 98% rename from share/shwap/p2p/bitswap/block_fetch_test.go rename to square/shwap/p2p/bitswap/block_fetch_test.go index 05b0c78b19..43eb529076 100644 --- a/share/shwap/p2p/bitswap/block_fetch_test.go +++ b/square/shwap/p2p/bitswap/block_fetch_test.go @@ -20,7 +20,7 @@ import ( "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/share/eds" + "github.com/celestiaorg/celestia-node/square/eds" ) func TestFetch_Options(t *testing.T) { diff --git a/share/shwap/p2p/bitswap/block_proto.go b/square/shwap/p2p/bitswap/block_proto.go similarity index 92% rename from share/shwap/p2p/bitswap/block_proto.go rename to square/shwap/p2p/bitswap/block_proto.go index 8cab645705..6ab0243abf 100644 --- a/share/shwap/p2p/bitswap/block_proto.go +++ b/square/shwap/p2p/bitswap/block_proto.go @@ -5,7 +5,7 @@ import ( "github.com/ipfs/go-cid" - bitswappb "github.com/celestiaorg/celestia-node/share/shwap/p2p/bitswap/pb" + bitswappb "github.com/celestiaorg/celestia-node/square/shwap/p2p/bitswap/pb" ) // marshalProto wraps the given Block in composition protobuf and marshals it. diff --git a/share/shwap/p2p/bitswap/block_registry.go b/square/shwap/p2p/bitswap/block_registry.go similarity index 100% rename from share/shwap/p2p/bitswap/block_registry.go rename to square/shwap/p2p/bitswap/block_registry.go diff --git a/share/shwap/p2p/bitswap/block_store.go b/square/shwap/p2p/bitswap/block_store.go similarity index 98% rename from share/shwap/p2p/bitswap/block_store.go rename to square/shwap/p2p/bitswap/block_store.go index 910a95c204..ea1cf4e937 100644 --- a/share/shwap/p2p/bitswap/block_store.go +++ b/square/shwap/p2p/bitswap/block_store.go @@ -9,7 +9,7 @@ import ( "github.com/ipfs/go-cid" ipld "github.com/ipfs/go-ipld-format" - "github.com/celestiaorg/celestia-node/share/eds" + "github.com/celestiaorg/celestia-node/square/eds" "github.com/celestiaorg/celestia-node/store" ) diff --git a/share/shwap/p2p/bitswap/block_test.go b/square/shwap/p2p/bitswap/block_test.go similarity index 92% rename from share/shwap/p2p/bitswap/block_test.go rename to square/shwap/p2p/bitswap/block_test.go index 39bb55bc14..e953eb0546 100644 --- a/share/shwap/p2p/bitswap/block_test.go +++ b/square/shwap/p2p/bitswap/block_test.go @@ -13,8 +13,8 @@ import ( dssync "github.com/ipfs/go-datastore/sync" "github.com/stretchr/testify/require" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/eds" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/eds" ) const ( @@ -103,7 +103,7 @@ func (t *testBlock) Marshal() ([]byte, error) { return t.data, nil } -func (t *testBlock) UnmarshalFn(*share.AxisRoots) UnmarshalFn { +func (t *testBlock) UnmarshalFn(*square.AxisRoots) UnmarshalFn { return func(bytes, _ []byte) error { t.data = bytes time.Sleep(time.Millisecond * 1) diff --git a/share/shwap/p2p/bitswap/cid.go b/square/shwap/p2p/bitswap/cid.go similarity index 100% rename from share/shwap/p2p/bitswap/cid.go rename to square/shwap/p2p/bitswap/cid.go diff --git a/share/shwap/p2p/bitswap/getter.go b/square/shwap/p2p/bitswap/getter.go similarity index 92% rename from share/shwap/p2p/bitswap/getter.go rename to square/shwap/p2p/bitswap/getter.go index 9c55650a44..a346032b3e 100644 --- a/share/shwap/p2p/bitswap/getter.go +++ b/square/shwap/p2p/bitswap/getter.go @@ -11,13 +11,14 @@ import ( "go.opentelemetry.io/otel/codes" "go.opentelemetry.io/otel/trace" - "github.com/celestiaorg/celestia-app/v2/pkg/wrapper" + "github.com/celestiaorg/celestia-app/v3/pkg/wrapper" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" "github.com/celestiaorg/celestia-node/header" "github.com/celestiaorg/celestia-node/pruner" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/shwap" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/shwap" ) var tracer = otel.Tracer("shwap/bitswap") @@ -120,11 +121,11 @@ func (g *Getter) GetShare( ) (share.Share, error) { shrs, err := g.GetShares(ctx, hdr, []int{row}, []int{col}) if err != nil { - return nil, err + return share.Share{}, err } if len(shrs) != 1 { - return nil, fmt.Errorf("expected 1 share row, got %d", len(shrs)) + return share.Share{}, fmt.Errorf("expected 1 share row, got %d", len(shrs)) } return shrs[0], nil @@ -186,14 +187,14 @@ func (g *Getter) GetSharesByNamespace( hdr *header.ExtendedHeader, ns share.Namespace, ) (shwap.NamespaceData, error) { - if err := ns.ValidateForData(); err != nil { + if err := share.ValidateForData(ns); err != nil { return nil, err } ctx, span := tracer.Start(ctx, "get-shares-by-namespace") defer span.End() - rowIdxs := share.RowsWithNamespace(hdr.DAH, ns) + rowIdxs := square.RowsWithNamespace(hdr.DAH, ns) blks := make([]Block, len(rowIdxs)) for i, rowNdIdx := range rowIdxs { rndblk, err := NewEmptyRowNamespaceDataBlock(hdr.Height(), rowNdIdx, ns, len(hdr.DAH.RowRoots)) @@ -241,7 +242,7 @@ func (g *Getter) session(ctx context.Context, hdr *header.ExtendedHeader) exchan // edsFromRows imports given Rows and computes EDS out of them, assuming enough Rows were provided. // It is designed to reuse Row halves computed during verification on [Fetch] level. -func edsFromRows(roots *share.AxisRoots, rows []shwap.Row) (*rsmt2d.ExtendedDataSquare, error) { +func edsFromRows(roots *square.AxisRoots, rows []shwap.Row) (*rsmt2d.ExtendedDataSquare, error) { shrs := make([]share.Share, len(roots.RowRoots)*len(roots.RowRoots)) for i, row := range rows { rowShrs, err := row.Shares() @@ -255,8 +256,8 @@ func edsFromRows(roots *share.AxisRoots, rows []shwap.Row) (*rsmt2d.ExtendedData } square, err := rsmt2d.ImportExtendedDataSquare( - shrs, - share.DefaultRSMT2DCodec(), + share.ToBytes(shrs), + square.DefaultRSMT2DCodec(), wrapper.NewConstructor(uint64(len(roots.RowRoots)/2)), ) if err != nil { diff --git a/share/shwap/p2p/bitswap/getter_test.go b/square/shwap/p2p/bitswap/getter_test.go similarity index 54% rename from share/shwap/p2p/bitswap/getter_test.go rename to square/shwap/p2p/bitswap/getter_test.go index 757c34d7a0..64365ed7f2 100644 --- a/share/shwap/p2p/bitswap/getter_test.go +++ b/square/shwap/p2p/bitswap/getter_test.go @@ -5,19 +5,22 @@ import ( "github.com/stretchr/testify/require" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/eds/edstest" - "github.com/celestiaorg/celestia-node/share/shwap" + "github.com/celestiaorg/go-square/v2/share" + + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/eds/edstest" + "github.com/celestiaorg/celestia-node/square/shwap" ) func TestEDSFromRows(t *testing.T) { edsIn := edstest.RandEDS(t, 8) - roots, err := share.NewAxisRoots(edsIn) + roots, err := square.NewAxisRoots(edsIn) require.NoError(t, err) rows := make([]shwap.Row, edsIn.Width()/2) for i := range edsIn.Width() / 2 { - rowShrs := edsIn.Row(i)[:edsIn.Width()/2] + rowShrs, err := share.FromBytes(edsIn.Row(i)[:edsIn.Width()/2]) + require.NoError(t, err) rows[i] = shwap.NewRow(rowShrs, shwap.Left) } diff --git a/share/shwap/p2p/bitswap/pb/bitswap.pb.go b/square/shwap/p2p/bitswap/pb/bitswap.pb.go similarity index 85% rename from share/shwap/p2p/bitswap/pb/bitswap.pb.go rename to square/shwap/p2p/bitswap/pb/bitswap.pb.go index a84077e9ef..e1f425c41b 100644 --- a/share/shwap/p2p/bitswap/pb/bitswap.pb.go +++ b/square/shwap/p2p/bitswap/pb/bitswap.pb.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: share/shwap/p2p/bitswap/pb/bitswap.proto +// source: square/shwap/p2p/bitswap/pb/bitswap.proto package pb @@ -31,7 +31,7 @@ func (m *Block) Reset() { *m = Block{} } func (m *Block) String() string { return proto.CompactTextString(m) } func (*Block) ProtoMessage() {} func (*Block) Descriptor() ([]byte, []int) { - return fileDescriptor_09fd4e2ff1d5ce94, []int{0} + return fileDescriptor_98329a1d35a94c34, []int{0} } func (m *Block) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -79,22 +79,22 @@ func init() { } func init() { - proto.RegisterFile("share/shwap/p2p/bitswap/pb/bitswap.proto", fileDescriptor_09fd4e2ff1d5ce94) + proto.RegisterFile("square/shwap/p2p/bitswap/pb/bitswap.proto", fileDescriptor_98329a1d35a94c34) } -var fileDescriptor_09fd4e2ff1d5ce94 = []byte{ - // 171 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xd2, 0x28, 0xce, 0x48, 0x2c, - 0x4a, 0xd5, 0x2f, 0xce, 0x28, 0x4f, 0x2c, 0xd0, 0x2f, 0x30, 0x2a, 0xd0, 0x4f, 0xca, 0x2c, 0x29, - 0x06, 0xb3, 0x93, 0x60, 0x4c, 0xbd, 0x82, 0xa2, 0xfc, 0x92, 0x7c, 0x21, 0x76, 0x28, 0x57, 0xc9, - 0x9c, 0x8b, 0xd5, 0x29, 0x27, 0x3f, 0x39, 0x5b, 0x48, 0x80, 0x8b, 0x39, 0x39, 0x33, 0x45, 0x82, - 0x51, 0x81, 0x51, 0x83, 0x27, 0x08, 0xc4, 0x14, 0x92, 0xe1, 0xe2, 0x4c, 0xce, 0xcf, 0x2b, 0x49, - 0xcc, 0xcc, 0x4b, 0x2d, 0x92, 0x60, 0x02, 0x8b, 0x23, 0x04, 0x9c, 0x22, 0x4f, 0x3c, 0x92, 0x63, - 0xbc, 0xf0, 0x48, 0x8e, 0xf1, 0xc1, 0x23, 0x39, 0xc6, 0x09, 0x8f, 0xe5, 0x18, 0x2e, 0x3c, 0x96, - 0x63, 0xb8, 0xf1, 0x58, 0x8e, 0x21, 0xca, 0x3e, 0x3d, 0xb3, 0x24, 0xa3, 0x34, 0x49, 0x2f, 0x39, - 0x3f, 0x57, 0x3f, 0x39, 0x35, 0x27, 0xb5, 0xb8, 0x24, 0x33, 0x31, 0xbf, 0x28, 0x1d, 0xce, 0xd6, - 0xcd, 0xcb, 0x4f, 0x01, 0x39, 0x12, 0x97, 0x53, 0x93, 0xd8, 0xc0, 0x6e, 0x34, 0x06, 0x04, 0x00, - 0x00, 0xff, 0xff, 0xe7, 0x9c, 0x32, 0xc5, 0xcf, 0x00, 0x00, 0x00, +var fileDescriptor_98329a1d35a94c34 = []byte{ + // 172 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xd2, 0x2c, 0x2e, 0x2c, 0x4d, + 0x2c, 0x4a, 0xd5, 0x2f, 0xce, 0x28, 0x4f, 0x2c, 0xd0, 0x2f, 0x30, 0x2a, 0xd0, 0x4f, 0xca, 0x2c, + 0x29, 0x06, 0xb3, 0x93, 0x60, 0x4c, 0xbd, 0x82, 0xa2, 0xfc, 0x92, 0x7c, 0x21, 0x76, 0x28, 0x57, + 0xc9, 0x9c, 0x8b, 0xd5, 0x29, 0x27, 0x3f, 0x39, 0x5b, 0x48, 0x80, 0x8b, 0x39, 0x39, 0x33, 0x45, + 0x82, 0x51, 0x81, 0x51, 0x83, 0x27, 0x08, 0xc4, 0x14, 0x92, 0xe1, 0xe2, 0x4c, 0xce, 0xcf, 0x2b, + 0x49, 0xcc, 0xcc, 0x4b, 0x2d, 0x92, 0x60, 0x02, 0x8b, 0x23, 0x04, 0x9c, 0xa2, 0x4e, 0x3c, 0x92, + 0x63, 0xbc, 0xf0, 0x48, 0x8e, 0xf1, 0xc1, 0x23, 0x39, 0xc6, 0x09, 0x8f, 0xe5, 0x18, 0x2e, 0x3c, + 0x96, 0x63, 0xb8, 0xf1, 0x58, 0x8e, 0x21, 0xca, 0x21, 0x3d, 0xb3, 0x24, 0xa3, 0x34, 0x49, 0x2f, + 0x39, 0x3f, 0x57, 0x3f, 0x39, 0x35, 0x27, 0xb5, 0xb8, 0x24, 0x33, 0x31, 0xbf, 0x28, 0x1d, 0xce, + 0xd6, 0xcd, 0xcb, 0x4f, 0x49, 0xd5, 0xc7, 0xe3, 0xd6, 0x24, 0x36, 0xb0, 0x23, 0x8d, 0x01, 0x01, + 0x00, 0x00, 0xff, 0xff, 0x7d, 0xd5, 0x78, 0x73, 0xd1, 0x00, 0x00, 0x00, } func (m *Block) Marshal() (dAtA []byte, err error) { diff --git a/share/shwap/p2p/bitswap/pb/bitswap.proto b/square/shwap/p2p/bitswap/pb/bitswap.proto similarity index 70% rename from share/shwap/p2p/bitswap/pb/bitswap.proto rename to square/shwap/p2p/bitswap/pb/bitswap.proto index 3ba19aa49c..b620e98b60 100644 --- a/share/shwap/p2p/bitswap/pb/bitswap.proto +++ b/square/shwap/p2p/bitswap/pb/bitswap.proto @@ -1,7 +1,7 @@ // Defined in CIP-19 https://github.com/celestiaorg/CIPs/blob/82aeb7dfc472105a11babffd548c730c899a3d24/cips/cip-19.md syntax = "proto3"; package bitswap; -option go_package = "github.com/celestiaorg/celestia-node/share/shwap/p2p/bitswap/pb"; +option go_package = "github.com/celestiaorg/celestia-node/square/shwap/p2p/bitswap/pb"; message Block { bytes cid = 1; diff --git a/share/shwap/p2p/bitswap/row_block.go b/square/shwap/p2p/bitswap/row_block.go similarity index 84% rename from share/shwap/p2p/bitswap/row_block.go rename to square/shwap/p2p/bitswap/row_block.go index 41ff19e791..cfc57dc765 100644 --- a/share/shwap/p2p/bitswap/row_block.go +++ b/square/shwap/p2p/bitswap/row_block.go @@ -8,10 +8,10 @@ import ( "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/eds" - "github.com/celestiaorg/celestia-node/share/shwap" - shwappb "github.com/celestiaorg/celestia-node/share/shwap/pb" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/eds" + "github.com/celestiaorg/celestia-node/square/shwap" + shwappb "github.com/celestiaorg/celestia-node/square/shwap/pb" ) const ( @@ -96,7 +96,7 @@ func (rb *RowBlock) Populate(ctx context.Context, eds eds.Accessor) error { return nil } -func (rb *RowBlock) UnmarshalFn(root *share.AxisRoots) UnmarshalFn { +func (rb *RowBlock) UnmarshalFn(root *square.AxisRoots) UnmarshalFn { return func(cntrData, idData []byte) error { if !rb.Container.IsEmpty() { return nil @@ -116,8 +116,12 @@ func (rb *RowBlock) UnmarshalFn(root *share.AxisRoots) UnmarshalFn { return fmt.Errorf("unmarshaling Row for %+v: %w", rb.ID, err) } - cntr := shwap.RowFromProto(&row) - if err := cntr.Verify(root, rb.ID.RowIndex); err != nil { + cntr, err := shwap.RowFromProto(&row) + if err != nil { + return fmt.Errorf("unmarshaling Row: %w", err) + } + + if err = cntr.Verify(root, rb.ID.RowIndex); err != nil { return fmt.Errorf("validating Row for %+v: %w", rb.ID, err) } diff --git a/share/shwap/p2p/bitswap/row_block_test.go b/square/shwap/p2p/bitswap/row_block_test.go similarity index 82% rename from share/shwap/p2p/bitswap/row_block_test.go rename to square/shwap/p2p/bitswap/row_block_test.go index f609683da5..9b48338957 100644 --- a/share/shwap/p2p/bitswap/row_block_test.go +++ b/square/shwap/p2p/bitswap/row_block_test.go @@ -7,8 +7,8 @@ import ( "github.com/stretchr/testify/require" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/eds/edstest" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/eds/edstest" ) func TestRow_FetchRoundtrip(t *testing.T) { @@ -16,7 +16,7 @@ func TestRow_FetchRoundtrip(t *testing.T) { defer cancel() eds := edstest.RandEDS(t, 4) - root, err := share.NewAxisRoots(eds) + root, err := square.NewAxisRoots(eds) require.NoError(t, err) exchange := newExchangeOverEDS(ctx, t, eds) diff --git a/share/shwap/p2p/bitswap/row_namespace_data_block.go b/square/shwap/p2p/bitswap/row_namespace_data_block.go similarity index 86% rename from share/shwap/p2p/bitswap/row_namespace_data_block.go rename to square/shwap/p2p/bitswap/row_namespace_data_block.go index 312f231027..76778b0f53 100644 --- a/share/shwap/p2p/bitswap/row_namespace_data_block.go +++ b/square/shwap/p2p/bitswap/row_namespace_data_block.go @@ -6,10 +6,12 @@ import ( "github.com/ipfs/go-cid" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/eds" - "github.com/celestiaorg/celestia-node/share/shwap" - shwappb "github.com/celestiaorg/celestia-node/share/shwap/pb" + "github.com/celestiaorg/go-square/v2/share" + + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/eds" + "github.com/celestiaorg/celestia-node/square/shwap" + shwappb "github.com/celestiaorg/celestia-node/square/shwap/pb" ) const ( @@ -100,7 +102,7 @@ func (rndb *RowNamespaceDataBlock) Populate(ctx context.Context, eds eds.Accesso return nil } -func (rndb *RowNamespaceDataBlock) UnmarshalFn(root *share.AxisRoots) UnmarshalFn { +func (rndb *RowNamespaceDataBlock) UnmarshalFn(root *square.AxisRoots) UnmarshalFn { return func(cntrData, idData []byte) error { if !rndb.Container.IsEmpty() { return nil @@ -120,7 +122,10 @@ func (rndb *RowNamespaceDataBlock) UnmarshalFn(root *share.AxisRoots) UnmarshalF return fmt.Errorf("unmarshaling RowNamespaceData for %+v: %w", rndb.ID, err) } - cntr := shwap.RowNamespaceDataFromProto(&rnd) + cntr, err := shwap.RowNamespaceDataFromProto(&rnd) + if err != nil { + return fmt.Errorf("unmarshaling RowNamespaceData for %+v: %w", rndb.ID, err) + } if err := cntr.Verify(root, rndb.ID.DataNamespace, rndb.ID.RowIndex); err != nil { return fmt.Errorf("validating RowNamespaceData for %+v: %w", rndb.ID, err) } diff --git a/share/shwap/p2p/bitswap/row_namespace_data_block_test.go b/square/shwap/p2p/bitswap/row_namespace_data_block_test.go similarity index 75% rename from share/shwap/p2p/bitswap/row_namespace_data_block_test.go rename to square/shwap/p2p/bitswap/row_namespace_data_block_test.go index 27deee8823..fecf5494ca 100644 --- a/share/shwap/p2p/bitswap/row_namespace_data_block_test.go +++ b/square/shwap/p2p/bitswap/row_namespace_data_block_test.go @@ -7,20 +7,21 @@ import ( "github.com/stretchr/testify/require" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/eds/edstest" - "github.com/celestiaorg/celestia-node/share/sharetest" + "github.com/celestiaorg/go-square/v2/share" + + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/eds/edstest" ) func TestRowNamespaceData_FetchRoundtrip(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), time.Second*5) defer cancel() - namespace := sharetest.RandV0Namespace() + namespace := share.RandomNamespace() eds, root := edstest.RandEDSWithNamespace(t, namespace, 64, 16) exchange := newExchangeOverEDS(ctx, t, eds) - rowIdxs := share.RowsWithNamespace(root, namespace) + rowIdxs := square.RowsWithNamespace(root, namespace) blks := make([]Block, len(rowIdxs)) for i, rowIdx := range rowIdxs { blk, err := NewEmptyRowNamespaceDataBlock(1, rowIdx, namespace, len(root.RowRoots)) diff --git a/share/shwap/p2p/bitswap/sample_block.go b/square/shwap/p2p/bitswap/sample_block.go similarity index 84% rename from share/shwap/p2p/bitswap/sample_block.go rename to square/shwap/p2p/bitswap/sample_block.go index c96c5f4d3f..d7e7fdd884 100644 --- a/share/shwap/p2p/bitswap/sample_block.go +++ b/square/shwap/p2p/bitswap/sample_block.go @@ -6,10 +6,10 @@ import ( "github.com/ipfs/go-cid" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/eds" - "github.com/celestiaorg/celestia-node/share/shwap" - shwappb "github.com/celestiaorg/celestia-node/share/shwap/pb" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/eds" + "github.com/celestiaorg/celestia-node/square/shwap" + shwappb "github.com/celestiaorg/celestia-node/square/shwap/pb" ) const ( @@ -95,7 +95,7 @@ func (sb *SampleBlock) Populate(ctx context.Context, eds eds.Accessor) error { return nil } -func (sb *SampleBlock) UnmarshalFn(root *share.AxisRoots) UnmarshalFn { +func (sb *SampleBlock) UnmarshalFn(root *square.AxisRoots) UnmarshalFn { return func(cntrData, idData []byte) error { if !sb.Container.IsEmpty() { return nil @@ -115,8 +115,12 @@ func (sb *SampleBlock) UnmarshalFn(root *share.AxisRoots) UnmarshalFn { return fmt.Errorf("unmarshaling Sample for %+v: %w", sb.ID, err) } - cntr := shwap.SampleFromProto(&sample) - if err := cntr.Verify(root, sb.ID.RowIndex, sb.ID.ShareIndex); err != nil { + cntr, err := shwap.SampleFromProto(&sample) + if err != nil { + return fmt.Errorf("unmarshaling Sample for %+v: %w", sb.ID, err) + } + + if err = cntr.Verify(root, sb.ID.RowIndex, sb.ID.ShareIndex); err != nil { return fmt.Errorf("validating Sample for %+v: %w", sb.ID, err) } diff --git a/share/shwap/p2p/bitswap/sample_block_test.go b/square/shwap/p2p/bitswap/sample_block_test.go similarity index 85% rename from share/shwap/p2p/bitswap/sample_block_test.go rename to square/shwap/p2p/bitswap/sample_block_test.go index 2a28e7e4c9..ec7364e71f 100644 --- a/share/shwap/p2p/bitswap/sample_block_test.go +++ b/square/shwap/p2p/bitswap/sample_block_test.go @@ -7,8 +7,8 @@ import ( "github.com/stretchr/testify/require" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/eds/edstest" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/eds/edstest" ) func TestSample_FetchRoundtrip(t *testing.T) { @@ -16,7 +16,7 @@ func TestSample_FetchRoundtrip(t *testing.T) { defer cancel() eds := edstest.RandEDS(t, 32) - root, err := share.NewAxisRoots(eds) + root, err := square.NewAxisRoots(eds) require.NoError(t, err) exchange := newExchangeOverEDS(ctx, t, eds) diff --git a/share/shwap/p2p/discovery/backoff.go b/square/shwap/p2p/discovery/backoff.go similarity index 100% rename from share/shwap/p2p/discovery/backoff.go rename to square/shwap/p2p/discovery/backoff.go diff --git a/share/shwap/p2p/discovery/backoff_test.go b/square/shwap/p2p/discovery/backoff_test.go similarity index 100% rename from share/shwap/p2p/discovery/backoff_test.go rename to square/shwap/p2p/discovery/backoff_test.go diff --git a/share/shwap/p2p/discovery/dht.go b/square/shwap/p2p/discovery/dht.go similarity index 100% rename from share/shwap/p2p/discovery/dht.go rename to square/shwap/p2p/discovery/dht.go diff --git a/share/shwap/p2p/discovery/discovery.go b/square/shwap/p2p/discovery/discovery.go similarity index 100% rename from share/shwap/p2p/discovery/discovery.go rename to square/shwap/p2p/discovery/discovery.go diff --git a/share/shwap/p2p/discovery/discovery_test.go b/square/shwap/p2p/discovery/discovery_test.go similarity index 100% rename from share/shwap/p2p/discovery/discovery_test.go rename to square/shwap/p2p/discovery/discovery_test.go diff --git a/share/shwap/p2p/discovery/metrics.go b/square/shwap/p2p/discovery/metrics.go similarity index 100% rename from share/shwap/p2p/discovery/metrics.go rename to square/shwap/p2p/discovery/metrics.go diff --git a/share/shwap/p2p/discovery/options.go b/square/shwap/p2p/discovery/options.go similarity index 100% rename from share/shwap/p2p/discovery/options.go rename to square/shwap/p2p/discovery/options.go diff --git a/share/shwap/p2p/discovery/set.go b/square/shwap/p2p/discovery/set.go similarity index 100% rename from share/shwap/p2p/discovery/set.go rename to square/shwap/p2p/discovery/set.go diff --git a/share/shwap/p2p/discovery/set_test.go b/square/shwap/p2p/discovery/set_test.go similarity index 100% rename from share/shwap/p2p/discovery/set_test.go rename to square/shwap/p2p/discovery/set_test.go diff --git a/share/shwap/p2p/shrex/doc.go b/square/shwap/p2p/shrex/doc.go similarity index 100% rename from share/shwap/p2p/shrex/doc.go rename to square/shwap/p2p/shrex/doc.go diff --git a/share/shwap/p2p/shrex/error.go b/square/shwap/p2p/shrex/error.go similarity index 100% rename from share/shwap/p2p/shrex/error.go rename to square/shwap/p2p/shrex/error.go diff --git a/share/shwap/p2p/shrex/error_test.go b/square/shwap/p2p/shrex/error_test.go similarity index 100% rename from share/shwap/p2p/shrex/error_test.go rename to square/shwap/p2p/shrex/error_test.go diff --git a/share/shwap/p2p/shrex/errors.go b/square/shwap/p2p/shrex/errors.go similarity index 100% rename from share/shwap/p2p/shrex/errors.go rename to square/shwap/p2p/shrex/errors.go diff --git a/share/shwap/p2p/shrex/metrics.go b/square/shwap/p2p/shrex/metrics.go similarity index 100% rename from share/shwap/p2p/shrex/metrics.go rename to square/shwap/p2p/shrex/metrics.go diff --git a/share/shwap/p2p/shrex/middleware.go b/square/shwap/p2p/shrex/middleware.go similarity index 100% rename from share/shwap/p2p/shrex/middleware.go rename to square/shwap/p2p/shrex/middleware.go diff --git a/share/shwap/p2p/shrex/params.go b/square/shwap/p2p/shrex/params.go similarity index 100% rename from share/shwap/p2p/shrex/params.go rename to square/shwap/p2p/shrex/params.go diff --git a/share/shwap/p2p/shrex/pb/shrex.pb.go b/square/shwap/p2p/shrex/pb/shrex.pb.go similarity index 81% rename from share/shwap/p2p/shrex/pb/shrex.pb.go rename to square/shwap/p2p/shrex/pb/shrex.pb.go index 88322b1985..48171b5135 100644 --- a/share/shwap/p2p/shrex/pb/shrex.pb.go +++ b/square/shwap/p2p/shrex/pb/shrex.pb.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: share/shwap/p2p/shrex/pb/shrex.proto +// source: square/shwap/p2p/shrex/pb/shrex.proto package pb @@ -50,7 +50,7 @@ func (x Status) String() string { } func (Status) EnumDescriptor() ([]byte, []int) { - return fileDescriptor_68dfd78ade756110, []int{0} + return fileDescriptor_ade548694c6c6a45, []int{0} } type Response struct { @@ -61,7 +61,7 @@ func (m *Response) Reset() { *m = Response{} } func (m *Response) String() string { return proto.CompactTextString(m) } func (*Response) ProtoMessage() {} func (*Response) Descriptor() ([]byte, []int) { - return fileDescriptor_68dfd78ade756110, []int{0} + return fileDescriptor_ade548694c6c6a45, []int{0} } func (m *Response) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -103,25 +103,25 @@ func init() { } func init() { - proto.RegisterFile("share/shwap/p2p/shrex/pb/shrex.proto", fileDescriptor_68dfd78ade756110) + proto.RegisterFile("square/shwap/p2p/shrex/pb/shrex.proto", fileDescriptor_ade548694c6c6a45) } -var fileDescriptor_68dfd78ade756110 = []byte{ +var fileDescriptor_ade548694c6c6a45 = []byte{ // 218 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x29, 0xce, 0x48, 0x2c, - 0x4a, 0xd5, 0x2f, 0xce, 0x28, 0x4f, 0x2c, 0xd0, 0x2f, 0x30, 0x2a, 0xd0, 0x2f, 0xce, 0x28, 0x4a, - 0xad, 0xd0, 0x2f, 0x48, 0x82, 0x30, 0xf4, 0x0a, 0x8a, 0xf2, 0x4b, 0xf2, 0x95, 0xb4, 0xb9, 0x38, - 0x82, 0x52, 0x8b, 0x0b, 0xf2, 0xf3, 0x8a, 0x53, 0x85, 0xe4, 0xb9, 0xd8, 0x8a, 0x4b, 0x12, 0x4b, - 0x4a, 0x8b, 0x25, 0x18, 0x15, 0x18, 0x35, 0xf8, 0x8c, 0xd8, 0xf5, 0x82, 0xc1, 0xdc, 0x20, 0xa8, - 0xb0, 0x96, 0x15, 0x17, 0x1b, 0x44, 0x44, 0x88, 0x9b, 0x8b, 0xdd, 0xd3, 0x2f, 0xcc, 0xd1, 0xc7, - 0xd3, 0x45, 0x80, 0x41, 0x88, 0x8d, 0x8b, 0xc9, 0xdf, 0x5b, 0x80, 0x51, 0x88, 0x97, 0x8b, 0xd3, - 0xcf, 0x3f, 0x24, 0xde, 0xcd, 0x3f, 0xd4, 0xcf, 0x45, 0x80, 0x49, 0x88, 0x87, 0x8b, 0xc3, 0xd3, - 0x2f, 0xc4, 0x35, 0xc8, 0xcf, 0xd1, 0x47, 0x80, 0xd9, 0x29, 0xfc, 0xc4, 0x23, 0x39, 0xc6, 0x0b, - 0x8f, 0xe4, 0x18, 0x1f, 0x3c, 0x92, 0x63, 0x9c, 0xf0, 0x58, 0x8e, 0xe1, 0xc2, 0x63, 0x39, 0x86, - 0x1b, 0x8f, 0xe5, 0x18, 0xa2, 0x6c, 0xd3, 0x33, 0x4b, 0x32, 0x4a, 0x93, 0xf4, 0x92, 0xf3, 0x73, - 0xf5, 0x93, 0x53, 0x73, 0x52, 0x8b, 0x4b, 0x32, 0x13, 0xf3, 0x8b, 0xd2, 0xe1, 0x6c, 0xdd, 0xbc, - 0xfc, 0x14, 0x90, 0x3f, 0xb0, 0xfb, 0x26, 0x89, 0x0d, 0xec, 0x11, 0x63, 0x40, 0x00, 0x00, 0x00, - 0xff, 0xff, 0xd8, 0xb0, 0x4b, 0x58, 0xf0, 0x00, 0x00, 0x00, + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x2d, 0x2e, 0x2c, 0x4d, + 0x2c, 0x4a, 0xd5, 0x2f, 0xce, 0x28, 0x4f, 0x2c, 0xd0, 0x2f, 0x30, 0x2a, 0xd0, 0x2f, 0xce, 0x28, + 0x4a, 0xad, 0xd0, 0x2f, 0x48, 0x82, 0x30, 0xf4, 0x0a, 0x8a, 0xf2, 0x4b, 0xf2, 0x95, 0xb4, 0xb9, + 0x38, 0x82, 0x52, 0x8b, 0x0b, 0xf2, 0xf3, 0x8a, 0x53, 0x85, 0xe4, 0xb9, 0xd8, 0x8a, 0x4b, 0x12, + 0x4b, 0x4a, 0x8b, 0x25, 0x18, 0x15, 0x18, 0x35, 0xf8, 0x8c, 0xd8, 0xf5, 0x82, 0xc1, 0xdc, 0x20, + 0xa8, 0xb0, 0x96, 0x15, 0x17, 0x1b, 0x44, 0x44, 0x88, 0x9b, 0x8b, 0xdd, 0xd3, 0x2f, 0xcc, 0xd1, + 0xc7, 0xd3, 0x45, 0x80, 0x41, 0x88, 0x8d, 0x8b, 0xc9, 0xdf, 0x5b, 0x80, 0x51, 0x88, 0x97, 0x8b, + 0xd3, 0xcf, 0x3f, 0x24, 0xde, 0xcd, 0x3f, 0xd4, 0xcf, 0x45, 0x80, 0x49, 0x88, 0x87, 0x8b, 0xc3, + 0xd3, 0x2f, 0xc4, 0x35, 0xc8, 0xcf, 0xd1, 0x47, 0x80, 0xd9, 0x29, 0xe2, 0xc4, 0x23, 0x39, 0xc6, + 0x0b, 0x8f, 0xe4, 0x18, 0x1f, 0x3c, 0x92, 0x63, 0x9c, 0xf0, 0x58, 0x8e, 0xe1, 0xc2, 0x63, 0x39, + 0x86, 0x1b, 0x8f, 0xe5, 0x18, 0xa2, 0xec, 0xd2, 0x33, 0x4b, 0x32, 0x4a, 0x93, 0xf4, 0x92, 0xf3, + 0x73, 0xf5, 0x93, 0x53, 0x73, 0x52, 0x8b, 0x4b, 0x32, 0x13, 0xf3, 0x8b, 0xd2, 0xe1, 0x6c, 0xdd, + 0xbc, 0xfc, 0x94, 0x54, 0x7d, 0x9c, 0xde, 0x49, 0x62, 0x03, 0xfb, 0xc4, 0x18, 0x10, 0x00, 0x00, + 0xff, 0xff, 0x5d, 0x99, 0xc5, 0x28, 0xf2, 0x00, 0x00, 0x00, } func (m *Response) Marshal() (dAtA []byte, err error) { diff --git a/share/shwap/p2p/shrex/pb/shrex.proto b/square/shwap/p2p/shrex/pb/shrex.proto similarity index 69% rename from share/shwap/p2p/shrex/pb/shrex.proto rename to square/shwap/p2p/shrex/pb/shrex.proto index 7b3a57227d..0dac0f433b 100644 --- a/share/shwap/p2p/shrex/pb/shrex.proto +++ b/square/shwap/p2p/shrex/pb/shrex.proto @@ -1,6 +1,6 @@ syntax = "proto3"; -option go_package = "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/pb"; +option go_package = "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/pb"; enum Status { INVALID = 0; diff --git a/share/shwap/p2p/shrex/peers/doc.go b/square/shwap/p2p/shrex/peers/doc.go similarity index 100% rename from share/shwap/p2p/shrex/peers/doc.go rename to square/shwap/p2p/shrex/peers/doc.go diff --git a/share/shwap/p2p/shrex/peers/manager.go b/square/shwap/p2p/shrex/peers/manager.go similarity index 97% rename from share/shwap/p2p/shrex/peers/manager.go rename to square/shwap/p2p/shrex/peers/manager.go index 857c5ee937..9c77496932 100644 --- a/share/shwap/p2p/shrex/peers/manager.go +++ b/square/shwap/p2p/shrex/peers/manager.go @@ -20,8 +20,8 @@ import ( libhead "github.com/celestiaorg/go-header" "github.com/celestiaorg/celestia-node/header" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrexsub" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrexsub" ) const ( @@ -202,7 +202,7 @@ func (m *Manager) Stop(ctx context.Context) error { // nodes, it will wait until any peer appear in either source or timeout happen. // After fetching data using given peer, caller is required to call returned DoneFunc using // appropriate result value -func (m *Manager) Peer(ctx context.Context, datahash share.DataHash, height uint64, +func (m *Manager) Peer(ctx context.Context, datahash square.DataHash, height uint64, ) (peer.ID, DoneFunc, error) { p := m.validatedPool(datahash.String(), height) @@ -255,7 +255,7 @@ func (m *Manager) UpdateNodePool(peerID peer.ID, isAdded bool) { func (m *Manager) newPeer( ctx context.Context, - datahash share.DataHash, + datahash square.DataHash, peerID peer.ID, source peerSource, poolSize int, @@ -271,7 +271,7 @@ func (m *Manager) newPeer( return peerID, m.doneFunc(datahash, peerID, source), nil } -func (m *Manager) doneFunc(datahash share.DataHash, peerID peer.ID, source peerSource) DoneFunc { +func (m *Manager) doneFunc(datahash square.DataHash, peerID peer.ID, source peerSource) DoneFunc { return func(result result) { log.Debugw("set peer result", "hash", datahash.String(), @@ -437,7 +437,7 @@ func (m *Manager) isBlacklistedPeer(peerID peer.ID) bool { return !m.connGater.InterceptPeerDial(peerID) } -func (m *Manager) isBlacklistedHash(hash share.DataHash) bool { +func (m *Manager) isBlacklistedHash(hash square.DataHash) bool { m.lock.Lock() defer m.lock.Unlock() return m.blacklistedHashes[hash.String()] diff --git a/share/shwap/p2p/shrex/peers/manager_test.go b/square/shwap/p2p/shrex/peers/manager_test.go similarity index 97% rename from share/shwap/p2p/shrex/peers/manager_test.go rename to square/shwap/p2p/shrex/peers/manager_test.go index 592f964e64..46e1024125 100644 --- a/share/shwap/p2p/shrex/peers/manager_test.go +++ b/square/shwap/p2p/shrex/peers/manager_test.go @@ -21,9 +21,9 @@ import ( libhead "github.com/celestiaorg/go-header" "github.com/celestiaorg/celestia-node/header" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/discovery" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrexsub" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/discovery" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrexsub" ) func TestManager(t *testing.T) { @@ -127,13 +127,13 @@ func TestManager(t *testing.T) { // create unvalidated pool peerID := peer.ID("peer1") msg := shrexsub.Notification{ - DataHash: share.DataHash("datahash1datahash1datahash1datahash1datahash1"), + DataHash: square.DataHash("datahash1datahash1datahash1datahash1datahash1"), Height: 2, } manager.Validate(ctx, peerID, msg) // create validated pool - validDataHash := share.DataHash("datahash2") + validDataHash := square.DataHash("datahash2") manager.nodes.add("full") // add FN to unblock Peer call manager.Peer(ctx, validDataHash, h.Height()) //nolint:errcheck require.Len(t, manager.pools, 3) @@ -237,7 +237,7 @@ func TestManager(t *testing.T) { // create shrexSub msg with height lower than first header from headerSub msg := shrexsub.Notification{ - DataHash: share.DataHash("datahash"), + DataHash: square.DataHash("datahash"), Height: h.Height() - 1, } result := manager.Validate(ctx, "peer", msg) @@ -265,7 +265,7 @@ func TestManager(t *testing.T) { // create shrexSub msg with height lower than first header from headerSub msg := shrexsub.Notification{ - DataHash: share.DataHash("datahash"), + DataHash: square.DataHash("datahash"), Height: h.Height() - 1, } result := manager.Validate(ctx, "peer", msg) @@ -308,7 +308,7 @@ func TestManager(t *testing.T) { // create shrexSub msg with height lower than storedPoolsAmount msg := shrexsub.Notification{ - DataHash: share.DataHash("datahash"), + DataHash: square.DataHash("datahash"), Height: h.Height() - storedPoolsAmount - 3, } result := manager.Validate(ctx, "peer", msg) diff --git a/share/shwap/p2p/shrex/peers/metrics.go b/square/shwap/p2p/shrex/peers/metrics.go similarity index 99% rename from share/shwap/p2p/shrex/peers/metrics.go rename to square/shwap/p2p/shrex/peers/metrics.go index d401d6a4fc..67bdb5caf0 100644 --- a/share/shwap/p2p/shrex/peers/metrics.go +++ b/square/shwap/p2p/shrex/peers/metrics.go @@ -13,7 +13,7 @@ import ( "go.opentelemetry.io/otel/metric" "github.com/celestiaorg/celestia-node/libs/utils" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrexsub" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrexsub" ) const ( diff --git a/share/shwap/p2p/shrex/peers/options.go b/square/shwap/p2p/shrex/peers/options.go similarity index 97% rename from share/shwap/p2p/shrex/peers/options.go rename to square/shwap/p2p/shrex/peers/options.go index 10957e7651..cbacca3267 100644 --- a/share/shwap/p2p/shrex/peers/options.go +++ b/square/shwap/p2p/shrex/peers/options.go @@ -7,7 +7,7 @@ import ( libhead "github.com/celestiaorg/go-header" "github.com/celestiaorg/celestia-node/header" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrexsub" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrexsub" ) type Parameters struct { diff --git a/share/shwap/p2p/shrex/peers/pool.go b/square/shwap/p2p/shrex/peers/pool.go similarity index 100% rename from share/shwap/p2p/shrex/peers/pool.go rename to square/shwap/p2p/shrex/peers/pool.go diff --git a/share/shwap/p2p/shrex/peers/pool_test.go b/square/shwap/p2p/shrex/peers/pool_test.go similarity index 100% rename from share/shwap/p2p/shrex/peers/pool_test.go rename to square/shwap/p2p/shrex/peers/pool_test.go diff --git a/share/shwap/p2p/shrex/peers/timedqueue.go b/square/shwap/p2p/shrex/peers/timedqueue.go similarity index 100% rename from share/shwap/p2p/shrex/peers/timedqueue.go rename to square/shwap/p2p/shrex/peers/timedqueue.go diff --git a/share/shwap/p2p/shrex/peers/timedqueue_test.go b/square/shwap/p2p/shrex/peers/timedqueue_test.go similarity index 100% rename from share/shwap/p2p/shrex/peers/timedqueue_test.go rename to square/shwap/p2p/shrex/peers/timedqueue_test.go diff --git a/share/shwap/p2p/shrex/recovery.go b/square/shwap/p2p/shrex/recovery.go similarity index 100% rename from share/shwap/p2p/shrex/recovery.go rename to square/shwap/p2p/shrex/recovery.go diff --git a/share/shwap/p2p/shrex/shrex_getter/shrex.go b/square/shwap/p2p/shrex/shrex_getter/shrex.go similarity index 92% rename from share/shwap/p2p/shrex/shrex_getter/shrex.go rename to square/shwap/p2p/shrex/shrex_getter/shrex.go index 6d9d25115f..099d62272e 100644 --- a/share/shwap/p2p/shrex/shrex_getter/shrex.go +++ b/square/shwap/p2p/shrex/shrex_getter/shrex.go @@ -13,17 +13,18 @@ import ( "go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/trace" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" "github.com/celestiaorg/celestia-node/header" "github.com/celestiaorg/celestia-node/libs/utils" "github.com/celestiaorg/celestia-node/pruner" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/shwap" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/peers" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrexeds" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrexnd" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/shwap" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/peers" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrexeds" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrexnd" ) var ( @@ -146,7 +147,7 @@ func (sg *Getter) Stop(ctx context.Context) error { } func (sg *Getter) GetShare(context.Context, *header.ExtendedHeader, int, int) (share.Share, error) { - return nil, fmt.Errorf("getter/shrex: GetShare %w", shwap.ErrOperationNotSupported) + return share.Share{}, fmt.Errorf("getter/shrex: GetShare %w", shwap.ErrOperationNotSupported) } func (sg *Getter) GetEDS(ctx context.Context, header *header.ExtendedHeader) (*rsmt2d.ExtendedDataSquare, error) { @@ -157,8 +158,8 @@ func (sg *Getter) GetEDS(ctx context.Context, header *header.ExtendedHeader) (*r }() // short circuit if the data root is empty - if header.DAH.Equals(share.EmptyEDSRoots()) { - return share.EmptyEDS(), nil + if header.DAH.Equals(square.EmptyEDSRoots()) { + return square.EmptyEDS(), nil } var attempt int @@ -218,7 +219,7 @@ func (sg *Getter) GetSharesByNamespace( header *header.ExtendedHeader, namespace share.Namespace, ) (shwap.NamespaceData, error) { - if err := namespace.ValidateForData(); err != nil { + if err := share.ValidateForData(namespace); err != nil { return nil, err } var ( @@ -234,7 +235,7 @@ func (sg *Getter) GetSharesByNamespace( // verify that the namespace could exist inside the roots before starting network requests dah := header.DAH - rowIdxs := share.RowsWithNamespace(dah, namespace) + rowIdxs := square.RowsWithNamespace(dah, namespace) if len(rowIdxs) == 0 { return shwap.NamespaceData{}, nil } diff --git a/share/shwap/p2p/shrex/shrex_getter/shrex_test.go b/square/shwap/p2p/shrex/shrex_getter/shrex_test.go similarity index 77% rename from share/shwap/p2p/shrex/shrex_getter/shrex_test.go rename to square/shwap/p2p/shrex/shrex_getter/shrex_test.go index b5f9a30a72..80d7765cdc 100644 --- a/share/shwap/p2p/shrex/shrex_getter/shrex_test.go +++ b/square/shwap/p2p/shrex/shrex_getter/shrex_test.go @@ -17,6 +17,7 @@ import ( "github.com/stretchr/testify/require" libhead "github.com/celestiaorg/go-header" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt" "github.com/celestiaorg/rsmt2d" @@ -24,14 +25,13 @@ import ( "github.com/celestiaorg/celestia-node/header/headertest" "github.com/celestiaorg/celestia-node/pruner/full" "github.com/celestiaorg/celestia-node/pruner/light" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/eds/edstest" - "github.com/celestiaorg/celestia-node/share/sharetest" - "github.com/celestiaorg/celestia-node/share/shwap" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/peers" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrexeds" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrexnd" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrexsub" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/eds/edstest" + "github.com/celestiaorg/celestia-node/square/shwap" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/peers" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrexeds" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrexnd" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrexsub" "github.com/celestiaorg/celestia-node/store" ) @@ -71,7 +71,7 @@ func TestShrexGetter(t *testing.T) { // generate test data size := 64 - namespace := sharetest.RandV0Namespace() + namespace := share.RandomNamespace() height := height.Add(1) randEDS, roots := edstest.RandEDSWithNamespace(t, namespace, size*size, size) eh := headertest.RandExtendedHeaderWithRoot(t, roots) @@ -126,10 +126,10 @@ func TestShrexGetter(t *testing.T) { }) // namespace inside root range - nID, err := addToNamespace(maxNamespace, -1) + nID, err := share.AddInt(maxNamespace, -1) require.NoError(t, err) // check for namespace to be between max and min namespace in root - require.Len(t, share.RowsWithNamespace(roots, nID), 1) + require.Len(t, square.RowsWithNamespace(roots, nID), 1) emptyShares, err := getter.GetSharesByNamespace(ctx, eh, nID) require.NoError(t, err) @@ -138,10 +138,10 @@ func TestShrexGetter(t *testing.T) { require.Nil(t, emptyShares.Verify(roots, nID)) // namespace outside root range - nID, err = addToNamespace(maxNamespace, 1) + nID, err = share.AddInt(maxNamespace, 1) require.NoError(t, err) // check for namespace to be not in root - require.Len(t, share.RowsWithNamespace(roots, nID), 0) + require.Len(t, square.RowsWithNamespace(roots, nID), 0) emptyShares, err = getter.GetSharesByNamespace(ctx, eh, nID) require.NoError(t, err) @@ -167,10 +167,10 @@ func TestShrexGetter(t *testing.T) { Height: height, }) - namespace, err := addToNamespace(maxNamespace, 1) + namespace, err := share.AddInt(maxNamespace, 1) require.NoError(t, err) // check for namespace to be not in root - require.Len(t, share.RowsWithNamespace(roots, namespace), 0) + require.Len(t, square.RowsWithNamespace(roots, namespace), 0) emptyShares, err := getter.GetSharesByNamespace(ctx, eh, namespace) require.NoError(t, err) @@ -277,12 +277,14 @@ func newStore(t *testing.T) (*store.Store, error) { return store.NewStore(store.DefaultParameters(), t.TempDir()) } -func generateTestEDS(t *testing.T) (*rsmt2d.ExtendedDataSquare, *share.AxisRoots, share.Namespace) { +func generateTestEDS(t *testing.T) (*rsmt2d.ExtendedDataSquare, *square.AxisRoots, share.Namespace) { eds := edstest.RandEDS(t, 4) - roots, err := share.NewAxisRoots(eds) + roots, err := square.NewAxisRoots(eds) require.NoError(t, err) max := nmt.MaxNamespace(roots.RowRoots[(len(roots.RowRoots))/2-1], share.NamespaceSize) - return eds, roots, max + ns, err := share.NewNamespaceFromBytes(max) + require.NoError(t, err) + return eds, roots, ns } func testManager( @@ -354,21 +356,21 @@ func addToNamespace(namespace share.Namespace, val int) (share.Namespace, error) return namespace, nil } // Convert the input integer to a byte slice and add it to result slice - result := make([]byte, len(namespace)) + result := make([]byte, namespace.Len()) if val > 0 { - binary.BigEndian.PutUint64(result[len(namespace)-8:], uint64(val)) + binary.BigEndian.PutUint64(result[namespace.Len()-8:], uint64(val)) } else { - binary.BigEndian.PutUint64(result[len(namespace)-8:], uint64(-val)) + binary.BigEndian.PutUint64(result[namespace.Len()-8:], uint64(-val)) } // Perform addition byte by byte var carry int - for i := len(namespace) - 1; i >= 0; i-- { + for i := namespace.Len() - 1; i >= 0; i-- { var sum int if val > 0 { - sum = int(namespace[i]) + int(result[i]) + carry + sum = int(namespace.Bytes()[i]) + int(result[i]) + carry } else { - sum = int(namespace[i]) - int(result[i]) + carry + sum = int(namespace.Bytes()[i]) - int(result[i]) + carry } switch { @@ -387,62 +389,8 @@ func addToNamespace(namespace share.Namespace, val int) (share.Namespace, error) // Handle any remaining carry if carry != 0 { - return nil, errors.New("namespace overflow") + return share.Namespace{}, errors.New("namespace overflow") } - return result, nil -} - -func TestAddToNamespace(t *testing.T) { - testCases := []struct { - name string - value int - input share.Namespace - expected share.Namespace - expectedError error - }{ - { - name: "Positive value addition", - value: 42, - input: share.Namespace{0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}, - expected: share.Namespace{0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x2b}, - expectedError: nil, - }, - { - name: "Negative value addition", - value: -42, - input: share.Namespace{0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}, - expected: share.Namespace{0x1, 0x1, 0x1, 0x1, 0x1, 0x01, 0x1, 0x1, 0x1, 0x0, 0xd7}, - expectedError: nil, - }, - { - name: "Overflow error", - value: 1, - input: share.Namespace{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, - expected: nil, - expectedError: errors.New("namespace overflow"), - }, - { - name: "Overflow error negative", - value: -1, - input: share.Namespace{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, - expected: nil, - expectedError: errors.New("namespace overflow"), - }, - } - - for _, tc := range testCases { - t.Run(tc.name, func(t *testing.T) { - result, err := addToNamespace(tc.input, tc.value) - if tc.expectedError == nil { - require.NoError(t, err) - require.Equal(t, tc.expected, result) - return - } - require.Error(t, err) - if err.Error() != tc.expectedError.Error() { - t.Errorf("Unexpected error message. Expected: %v, Got: %v", tc.expectedError, err) - } - }) - } + return share.NewNamespaceFromBytes(result) } diff --git a/share/shwap/p2p/shrex/shrexeds/client.go b/square/shwap/p2p/shrex/shrexeds/client.go similarity index 93% rename from share/shwap/p2p/shrex/shrexeds/client.go rename to square/shwap/p2p/shrex/shrexeds/client.go index 5239c407f9..88038f568b 100644 --- a/share/shwap/p2p/shrex/shrexeds/client.go +++ b/square/shwap/p2p/shrex/shrexeds/client.go @@ -17,11 +17,11 @@ import ( "github.com/celestiaorg/rsmt2d" "github.com/celestiaorg/celestia-node/libs/utils" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/eds" - "github.com/celestiaorg/celestia-node/share/shwap" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex" - shrexpb "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/pb" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/eds" + "github.com/celestiaorg/celestia-node/square/shwap" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex" + shrexpb "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/pb" ) // Client is responsible for requesting EDSs for blocksync over the ShrEx/EDS protocol. @@ -49,7 +49,7 @@ func NewClient(params *Parameters, host host.Host) (*Client, error) { // RequestEDS requests the ODS from the given peers and returns the EDS upon success. func (c *Client) RequestEDS( ctx context.Context, - root *share.AxisRoots, + root *square.AxisRoots, height uint64, peer peer.ID, ) (*rsmt2d.ExtendedDataSquare, error) { @@ -86,7 +86,7 @@ func (c *Client) RequestEDS( func (c *Client) doRequest( ctx context.Context, - root *share.AxisRoots, + root *square.AxisRoots, height uint64, to peer.ID, ) (*rsmt2d.ExtendedDataSquare, error) { diff --git a/share/shwap/p2p/shrex/shrexeds/doc.go b/square/shwap/p2p/shrex/shrexeds/doc.go similarity index 100% rename from share/shwap/p2p/shrex/shrexeds/doc.go rename to square/shwap/p2p/shrex/shrexeds/doc.go diff --git a/share/shwap/p2p/shrex/shrexeds/exchange_test.go b/square/shwap/p2p/shrex/shrexeds/exchange_test.go similarity index 90% rename from share/shwap/p2p/shrex/shrexeds/exchange_test.go rename to square/shwap/p2p/shrex/shrexeds/exchange_test.go index 89e1dafa1c..76e3e2e2ee 100644 --- a/share/shwap/p2p/shrex/shrexeds/exchange_test.go +++ b/square/shwap/p2p/shrex/shrexeds/exchange_test.go @@ -12,10 +12,10 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/eds/edstest" - "github.com/celestiaorg/celestia-node/share/shwap" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/eds/edstest" + "github.com/celestiaorg/celestia-node/square/shwap" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex" "github.com/celestiaorg/celestia-node/store" ) @@ -30,7 +30,7 @@ func TestExchange_RequestEDS(t *testing.T) { // Testcase: EDS is immediately available t.Run("EDS_Available", func(t *testing.T) { eds := edstest.RandEDS(t, 4) - roots, err := share.NewAxisRoots(eds) + roots, err := square.NewAxisRoots(eds) require.NoError(t, err) height := uint64(1) err = store.PutODSQ4(ctx, roots, height, eds) @@ -44,7 +44,7 @@ func TestExchange_RequestEDS(t *testing.T) { // Testcase: EDS is unavailable initially, but is found after multiple requests t.Run("EDS_AvailableAfterDelay", func(t *testing.T) { eds := edstest.RandEDS(t, 4) - roots, err := share.NewAxisRoots(eds) + roots, err := square.NewAxisRoots(eds) require.NoError(t, err) height := uint64(666) @@ -72,7 +72,7 @@ func TestExchange_RequestEDS(t *testing.T) { // Testcase: Invalid request excludes peer from round-robin, stopping request t.Run("EDS_InvalidRequest", func(t *testing.T) { - emptyRoot := share.EmptyEDSRoots() + emptyRoot := square.EmptyEDSRoots() height := uint64(0) requestedEDS, err := client.RequestEDS(ctx, emptyRoot, height, server.host.ID()) assert.ErrorIs(t, err, shwap.ErrInvalidID) @@ -83,7 +83,7 @@ func TestExchange_RequestEDS(t *testing.T) { timeoutCtx, cancel := context.WithTimeout(ctx, time.Second) t.Cleanup(cancel) eds := edstest.RandEDS(t, 4) - roots, err := share.NewAxisRoots(eds) + roots, err := square.NewAxisRoots(eds) require.NoError(t, err) height := uint64(668) _, err = client.RequestEDS(timeoutCtx, roots, height, server.host.ID()) @@ -119,7 +119,7 @@ func TestExchange_RequestEDS(t *testing.T) { middleware.RateLimitHandler(mockHandler)) // take server concurrency slots with blocked requests - emptyRoot := share.EmptyEDSRoots() + emptyRoot := square.EmptyEDSRoots() for i := 0; i < rateLimit; i++ { go func(i int) { client.RequestEDS(ctx, emptyRoot, 1, server.host.ID()) //nolint:errcheck diff --git a/share/shwap/p2p/shrex/shrexeds/params.go b/square/shwap/p2p/shrex/shrexeds/params.go similarity index 90% rename from share/shwap/p2p/shrex/shrexeds/params.go rename to square/shwap/p2p/shrex/shrexeds/params.go index c5d76fecb2..d3f46a1fd3 100644 --- a/share/shwap/p2p/shrex/shrexeds/params.go +++ b/square/shwap/p2p/shrex/shrexeds/params.go @@ -5,8 +5,8 @@ import ( logging "github.com/ipfs/go-log/v2" - "github.com/celestiaorg/celestia-node/share/shwap" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex" + "github.com/celestiaorg/celestia-node/square/shwap" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex" ) const protocolString = shrex.ProtocolString + shwap.EDSName diff --git a/share/shwap/p2p/shrex/shrexeds/server.go b/square/shwap/p2p/shrex/shrexeds/server.go similarity index 95% rename from share/shwap/p2p/shrex/shrexeds/server.go rename to square/shwap/p2p/shrex/shrexeds/server.go index 0367e7d82e..296acc6051 100644 --- a/share/shwap/p2p/shrex/shrexeds/server.go +++ b/square/shwap/p2p/shrex/shrexeds/server.go @@ -15,10 +15,10 @@ import ( "github.com/celestiaorg/go-libp2p-messenger/serde" "github.com/celestiaorg/celestia-node/libs/utils" - "github.com/celestiaorg/celestia-node/share/eds" - "github.com/celestiaorg/celestia-node/share/shwap" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex" - shrexpb "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/pb" + "github.com/celestiaorg/celestia-node/square/eds" + "github.com/celestiaorg/celestia-node/square/shwap" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex" + shrexpb "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/pb" "github.com/celestiaorg/celestia-node/store" ) diff --git a/share/shwap/p2p/shrex/shrexnd/client.go b/square/shwap/p2p/shrex/shrexnd/client.go similarity index 94% rename from share/shwap/p2p/shrex/shrexnd/client.go rename to square/shwap/p2p/shrex/shrexnd/client.go index a7029a348a..b9fe86d14c 100644 --- a/share/shwap/p2p/shrex/shrexnd/client.go +++ b/square/shwap/p2p/shrex/shrexnd/client.go @@ -14,12 +14,12 @@ import ( "github.com/libp2p/go-libp2p/core/protocol" "github.com/celestiaorg/go-libp2p-messenger/serde" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/celestia-node/libs/utils" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/shwap" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex" - shrexpb "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/pb" + "github.com/celestiaorg/celestia-node/square/shwap" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex" + shrexpb "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/pb" ) // Client implements client side of shrex/nd protocol to obtain namespaced shares data from remote @@ -53,7 +53,7 @@ func (c *Client) RequestND( namespace share.Namespace, peer peer.ID, ) (shwap.NamespaceData, error) { - if err := namespace.ValidateForData(); err != nil { + if err := share.ValidateForData(namespace); err != nil { return nil, err } diff --git a/share/shwap/p2p/shrex/shrexnd/doc.go b/square/shwap/p2p/shrex/shrexnd/doc.go similarity index 100% rename from share/shwap/p2p/shrex/shrexnd/doc.go rename to square/shwap/p2p/shrex/shrexnd/doc.go diff --git a/share/shwap/p2p/shrex/shrexnd/exchange_test.go b/square/shwap/p2p/shrex/shrexnd/exchange_test.go similarity index 85% rename from share/shwap/p2p/shrex/shrexnd/exchange_test.go rename to square/shwap/p2p/shrex/shrexnd/exchange_test.go index 81abdfba26..ea2e07eb06 100644 --- a/share/shwap/p2p/shrex/shrexnd/exchange_test.go +++ b/square/shwap/p2p/shrex/shrexnd/exchange_test.go @@ -12,10 +12,11 @@ import ( mocknet "github.com/libp2p/go-libp2p/p2p/net/mock" "github.com/stretchr/testify/require" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/eds/edstest" - "github.com/celestiaorg/celestia-node/share/sharetest" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex" + "github.com/celestiaorg/go-square/v2/share" + + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/eds/edstest" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex" "github.com/celestiaorg/celestia-node/store" ) @@ -32,7 +33,7 @@ func TestExchange_RequestND_NotFound(t *testing.T) { ctx, cancel := context.WithTimeout(ctx, time.Second) t.Cleanup(cancel) - namespace := sharetest.RandV0Namespace() + namespace := share.RandomNamespace() height := height.Add(1) _, err := client.RequestND(ctx, height, namespace, server.host.ID()) require.ErrorIs(t, err, shrex.ErrNotFound) @@ -43,14 +44,14 @@ func TestExchange_RequestND_NotFound(t *testing.T) { t.Cleanup(cancel) eds := edstest.RandEDS(t, 4) - roots, err := share.NewAxisRoots(eds) + roots, err := square.NewAxisRoots(eds) require.NoError(t, err) height := height.Add(1) err = edsStore.PutODSQ4(ctx, roots, height, eds) require.NoError(t, err) - namespace := sharetest.RandV0Namespace() + namespace := share.RandomNamespace() emptyShares, err := client.RequestND(ctx, height, namespace, server.host.ID()) require.NoError(t, err) require.Empty(t, emptyShares.Flatten()) @@ -94,13 +95,13 @@ func TestExchange_RequestND(t *testing.T) { // take server concurrency slots with blocked requests for i := 0; i < rateLimit; i++ { go func(i int) { - client.RequestND(ctx, 1, sharetest.RandV0Namespace(), server.host.ID()) //nolint:errcheck + client.RequestND(ctx, 1, share.RandomNamespace(), server.host.ID()) //nolint:errcheck }(i) } // wait until all server slots are taken wg.Wait() - _, err = client.RequestND(ctx, 1, sharetest.RandV0Namespace(), server.host.ID()) + _, err = client.RequestND(ctx, 1, share.RandomNamespace(), server.host.ID()) require.ErrorIs(t, err, shrex.ErrRateLimited) }) } diff --git a/share/shwap/p2p/shrex/shrexnd/params.go b/square/shwap/p2p/shrex/shrexnd/params.go similarity index 87% rename from share/shwap/p2p/shrex/shrexnd/params.go rename to square/shwap/p2p/shrex/shrexnd/params.go index 5544ae6b27..6003921c1e 100644 --- a/share/shwap/p2p/shrex/shrexnd/params.go +++ b/square/shwap/p2p/shrex/shrexnd/params.go @@ -5,8 +5,8 @@ import ( logging "github.com/ipfs/go-log/v2" - "github.com/celestiaorg/celestia-node/share/shwap" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex" + "github.com/celestiaorg/celestia-node/square/shwap" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex" ) const protocolString = shrex.ProtocolString + shwap.NamespaceDataName diff --git a/share/shwap/p2p/shrex/shrexnd/server.go b/square/shwap/p2p/shrex/shrexnd/server.go similarity index 96% rename from share/shwap/p2p/shrex/shrexnd/server.go rename to square/shwap/p2p/shrex/shrexnd/server.go index 0193c91ae1..20a7098b74 100644 --- a/share/shwap/p2p/shrex/shrexnd/server.go +++ b/square/shwap/p2p/shrex/shrexnd/server.go @@ -14,10 +14,10 @@ import ( "github.com/celestiaorg/go-libp2p-messenger/serde" "github.com/celestiaorg/celestia-node/libs/utils" - "github.com/celestiaorg/celestia-node/share/eds" - "github.com/celestiaorg/celestia-node/share/shwap" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex" - shrexpb "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/pb" + "github.com/celestiaorg/celestia-node/square/eds" + "github.com/celestiaorg/celestia-node/square/shwap" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex" + shrexpb "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/pb" "github.com/celestiaorg/celestia-node/store" ) diff --git a/share/shwap/p2p/shrex/shrexsub/doc.go b/square/shwap/p2p/shrex/shrexsub/doc.go similarity index 100% rename from share/shwap/p2p/shrex/shrexsub/doc.go rename to square/shwap/p2p/shrex/shrexsub/doc.go diff --git a/share/shwap/p2p/shrex/shrexsub/pb/notification.pb.go b/square/shwap/p2p/shrex/shrexsub/pb/notification.pb.go similarity index 84% rename from share/shwap/p2p/shrex/shrexsub/pb/notification.pb.go rename to square/shwap/p2p/shrex/shrexsub/pb/notification.pb.go index c7cddbba5c..a04cbc56ac 100644 --- a/share/shwap/p2p/shrex/shrexsub/pb/notification.pb.go +++ b/square/shwap/p2p/shrex/shrexsub/pb/notification.pb.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: share/shwap/p2p/shrex/shrexsub/pb/notification.proto +// source: square/shwap/p2p/shrex/shrexsub/pb/notification.proto package share_p2p_shrex_sub @@ -31,7 +31,7 @@ func (m *RecentEDSNotification) Reset() { *m = RecentEDSNotification{} } func (m *RecentEDSNotification) String() string { return proto.CompactTextString(m) } func (*RecentEDSNotification) ProtoMessage() {} func (*RecentEDSNotification) Descriptor() ([]byte, []int) { - return fileDescriptor_c16b670e7e556100, []int{0} + return fileDescriptor_3a5bf8ca81a1e1ac, []int{0} } func (m *RecentEDSNotification) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -79,23 +79,23 @@ func init() { } func init() { - proto.RegisterFile("share/shwap/p2p/shrex/shrexsub/pb/notification.proto", fileDescriptor_c16b670e7e556100) + proto.RegisterFile("square/shwap/p2p/shrex/shrexsub/pb/notification.proto", fileDescriptor_3a5bf8ca81a1e1ac) } -var fileDescriptor_c16b670e7e556100 = []byte{ - // 183 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x32, 0x29, 0xce, 0x48, 0x2c, - 0x4a, 0xd5, 0x2f, 0xce, 0x28, 0x4f, 0x2c, 0xd0, 0x2f, 0x30, 0x2a, 0xd0, 0x2f, 0xce, 0x28, 0x4a, - 0xad, 0x80, 0x90, 0xc5, 0xa5, 0x49, 0xfa, 0x05, 0x49, 0xfa, 0x79, 0xf9, 0x25, 0x99, 0x69, 0x99, - 0xc9, 0x89, 0x25, 0x99, 0xf9, 0x79, 0x7a, 0x05, 0x45, 0xf9, 0x25, 0xf9, 0x42, 0xc2, 0x60, 0x5d, - 0x7a, 0x05, 0x46, 0x05, 0x7a, 0x60, 0x95, 0x7a, 0xc5, 0xa5, 0x49, 0x4a, 0x3e, 0x5c, 0xa2, 0x41, - 0xa9, 0xc9, 0xa9, 0x79, 0x25, 0xae, 0x2e, 0xc1, 0x7e, 0x48, 0x7a, 0x84, 0xc4, 0xb8, 0xd8, 0x32, - 0x52, 0x33, 0xd3, 0x33, 0x4a, 0x24, 0x18, 0x15, 0x18, 0x35, 0x58, 0x82, 0xa0, 0x3c, 0x21, 0x69, - 0x2e, 0xce, 0x94, 0xc4, 0x92, 0xc4, 0xf8, 0x8c, 0xc4, 0xe2, 0x0c, 0x09, 0x26, 0x05, 0x46, 0x0d, - 0x9e, 0x20, 0x0e, 0x90, 0x80, 0x47, 0x62, 0x71, 0x86, 0x93, 0xc4, 0x89, 0x47, 0x72, 0x8c, 0x17, - 0x1e, 0xc9, 0x31, 0x3e, 0x78, 0x24, 0xc7, 0x38, 0xe1, 0xb1, 0x1c, 0xc3, 0x85, 0xc7, 0x72, 0x0c, - 0x37, 0x1e, 0xcb, 0x31, 0x24, 0xb1, 0x81, 0xdd, 0x60, 0x0c, 0x08, 0x00, 0x00, 0xff, 0xff, 0xc0, - 0x55, 0x8a, 0x06, 0xbb, 0x00, 0x00, 0x00, +var fileDescriptor_3a5bf8ca81a1e1ac = []byte{ + // 187 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x32, 0x2d, 0x2e, 0x2c, 0x4d, + 0x2c, 0x4a, 0xd5, 0x2f, 0xce, 0x28, 0x4f, 0x2c, 0xd0, 0x2f, 0x30, 0x2a, 0xd0, 0x2f, 0xce, 0x28, + 0x4a, 0xad, 0x80, 0x90, 0xc5, 0xa5, 0x49, 0xfa, 0x05, 0x49, 0xfa, 0x79, 0xf9, 0x25, 0x99, 0x69, + 0x99, 0xc9, 0x89, 0x25, 0x99, 0xf9, 0x79, 0x7a, 0x05, 0x45, 0xf9, 0x25, 0xf9, 0x42, 0xc2, 0xc5, + 0x19, 0x89, 0x45, 0xa9, 0x7a, 0x05, 0x46, 0x05, 0x7a, 0x60, 0x95, 0x7a, 0xc5, 0xa5, 0x49, 0x4a, + 0x3e, 0x5c, 0xa2, 0x41, 0xa9, 0xc9, 0xa9, 0x79, 0x25, 0xae, 0x2e, 0xc1, 0x7e, 0x48, 0x7a, 0x84, + 0xc4, 0xb8, 0xd8, 0x32, 0x52, 0x33, 0xd3, 0x33, 0x4a, 0x24, 0x18, 0x15, 0x18, 0x35, 0x58, 0x82, + 0xa0, 0x3c, 0x21, 0x69, 0x2e, 0xce, 0x94, 0xc4, 0x92, 0xc4, 0xf8, 0x8c, 0xc4, 0xe2, 0x0c, 0x09, + 0x26, 0x05, 0x46, 0x0d, 0x9e, 0x20, 0x0e, 0x90, 0x80, 0x47, 0x62, 0x71, 0x86, 0x93, 0xc4, 0x89, + 0x47, 0x72, 0x8c, 0x17, 0x1e, 0xc9, 0x31, 0x3e, 0x78, 0x24, 0xc7, 0x38, 0xe1, 0xb1, 0x1c, 0xc3, + 0x85, 0xc7, 0x72, 0x0c, 0x37, 0x1e, 0xcb, 0x31, 0x24, 0xb1, 0x81, 0xdd, 0x60, 0x0c, 0x08, 0x00, + 0x00, 0xff, 0xff, 0x3f, 0x50, 0x64, 0x8f, 0xbc, 0x00, 0x00, 0x00, } func (m *RecentEDSNotification) Marshal() (dAtA []byte, err error) { diff --git a/share/shwap/p2p/shrex/shrexsub/pb/notification.proto b/square/shwap/p2p/shrex/shrexsub/pb/notification.proto similarity index 100% rename from share/shwap/p2p/shrex/shrexsub/pb/notification.proto rename to square/shwap/p2p/shrex/shrexsub/pb/notification.proto diff --git a/share/shwap/p2p/shrex/shrexsub/pubsub.go b/square/shwap/p2p/shrex/shrexsub/pubsub.go similarity index 96% rename from share/shwap/p2p/shrex/shrexsub/pubsub.go rename to square/shwap/p2p/shrex/shrexsub/pubsub.go index d1861cfe12..f2f49233a3 100644 --- a/share/shwap/p2p/shrex/shrexsub/pubsub.go +++ b/square/shwap/p2p/shrex/shrexsub/pubsub.go @@ -9,8 +9,8 @@ import ( "github.com/libp2p/go-libp2p/core/host" "github.com/libp2p/go-libp2p/core/peer" - "github.com/celestiaorg/celestia-node/share" - pb "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrexsub/pb" + "github.com/celestiaorg/celestia-node/square" + pb "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrexsub/pb" ) var log = logging.Logger("shrex-sub") @@ -30,7 +30,7 @@ type BroadcastFn func(context.Context, Notification) error // Notification is the format of message sent by Broadcaster type Notification struct { - DataHash share.DataHash + DataHash square.DataHash Height uint64 } diff --git a/share/shwap/p2p/shrex/shrexsub/pubsub_test.go b/square/shwap/p2p/shrex/shrexsub/pubsub_test.go similarity index 97% rename from share/shwap/p2p/shrex/shrexsub/pubsub_test.go rename to square/shwap/p2p/shrex/shrexsub/pubsub_test.go index 59602da29b..ecaf8519e5 100644 --- a/share/shwap/p2p/shrex/shrexsub/pubsub_test.go +++ b/square/shwap/p2p/shrex/shrexsub/pubsub_test.go @@ -11,7 +11,7 @@ import ( "github.com/stretchr/testify/require" "github.com/tendermint/tendermint/libs/rand" - pb "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrexsub/pb" + pb "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrexsub/pb" ) func TestPubSub(t *testing.T) { diff --git a/share/shwap/p2p/shrex/shrexsub/subscription.go b/square/shwap/p2p/shrex/shrexsub/subscription.go similarity index 94% rename from share/shwap/p2p/shrex/shrexsub/subscription.go rename to square/shwap/p2p/shrex/shrexsub/subscription.go index 5021f090c2..d65928e2c3 100644 --- a/share/shwap/p2p/shrex/shrexsub/subscription.go +++ b/square/shwap/p2p/shrex/shrexsub/subscription.go @@ -6,7 +6,7 @@ import ( pubsub "github.com/libp2p/go-libp2p-pubsub" - pb "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrexsub/pb" + pb "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrexsub/pb" ) // Subscription is a wrapper over pubsub.Subscription that handles diff --git a/share/shwap/pb/shwap.pb.go b/square/shwap/pb/shwap.pb.go similarity index 89% rename from share/shwap/pb/shwap.pb.go rename to square/shwap/pb/shwap.pb.go index 000bf78ca7..12a158882e 100644 --- a/share/shwap/pb/shwap.pb.go +++ b/square/shwap/pb/shwap.pb.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: share/shwap/pb/shwap.proto +// source: square/shwap/pb/shwap.proto package pb @@ -45,7 +45,7 @@ func (x AxisType) String() string { } func (AxisType) EnumDescriptor() ([]byte, []int) { - return fileDescriptor_9431653f3c9f0bcb, []int{0} + return fileDescriptor_d53f2247170ec31c, []int{0} } type Row_HalfSide int32 @@ -70,7 +70,7 @@ func (x Row_HalfSide) String() string { } func (Row_HalfSide) EnumDescriptor() ([]byte, []int) { - return fileDescriptor_9431653f3c9f0bcb, []int{0, 0} + return fileDescriptor_d53f2247170ec31c, []int{0, 0} } type Row struct { @@ -82,7 +82,7 @@ func (m *Row) Reset() { *m = Row{} } func (m *Row) String() string { return proto.CompactTextString(m) } func (*Row) ProtoMessage() {} func (*Row) Descriptor() ([]byte, []int) { - return fileDescriptor_9431653f3c9f0bcb, []int{0} + return fileDescriptor_d53f2247170ec31c, []int{0} } func (m *Row) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -135,7 +135,7 @@ func (m *Sample) Reset() { *m = Sample{} } func (m *Sample) String() string { return proto.CompactTextString(m) } func (*Sample) ProtoMessage() {} func (*Sample) Descriptor() ([]byte, []int) { - return fileDescriptor_9431653f3c9f0bcb, []int{1} + return fileDescriptor_d53f2247170ec31c, []int{1} } func (m *Sample) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -194,7 +194,7 @@ func (m *RowNamespaceData) Reset() { *m = RowNamespaceData{} } func (m *RowNamespaceData) String() string { return proto.CompactTextString(m) } func (*RowNamespaceData) ProtoMessage() {} func (*RowNamespaceData) Descriptor() ([]byte, []int) { - return fileDescriptor_9431653f3c9f0bcb, []int{2} + return fileDescriptor_d53f2247170ec31c, []int{2} } func (m *RowNamespaceData) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -245,7 +245,7 @@ func (m *Share) Reset() { *m = Share{} } func (m *Share) String() string { return proto.CompactTextString(m) } func (*Share) ProtoMessage() {} func (*Share) Descriptor() ([]byte, []int) { - return fileDescriptor_9431653f3c9f0bcb, []int{3} + return fileDescriptor_d53f2247170ec31c, []int{3} } func (m *Share) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -290,34 +290,34 @@ func init() { proto.RegisterType((*Share)(nil), "shwap.Share") } -func init() { proto.RegisterFile("share/shwap/pb/shwap.proto", fileDescriptor_9431653f3c9f0bcb) } +func init() { proto.RegisterFile("square/shwap/pb/shwap.proto", fileDescriptor_d53f2247170ec31c) } -var fileDescriptor_9431653f3c9f0bcb = []byte{ - // 381 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x92, 0x4f, 0x6b, 0xe2, 0x40, - 0x18, 0xc6, 0x33, 0x1b, 0xe3, 0xc6, 0x57, 0xd1, 0x30, 0x7b, 0x09, 0xee, 0x92, 0x95, 0xb0, 0x0b, - 0xb2, 0x60, 0xb2, 0xe8, 0x27, 0xd8, 0xbf, 0xb5, 0x60, 0x6b, 0x19, 0x85, 0x42, 0x2f, 0x61, 0x62, - 0x46, 0x13, 0x88, 0x9d, 0x21, 0x49, 0x49, 0x3d, 0xf7, 0xd0, 0x6b, 0x3f, 0x56, 0x8f, 0x1e, 0x7b, - 0x2c, 0xfa, 0x45, 0x4a, 0x26, 0xb1, 0x14, 0xda, 0x43, 0x6f, 0xbf, 0xcc, 0xf3, 0xcc, 0xbc, 0xcf, - 0x13, 0x5e, 0xe8, 0xa6, 0x21, 0x4d, 0x98, 0x9b, 0x86, 0x39, 0x15, 0xae, 0xf0, 0x4b, 0x70, 0x44, - 0xc2, 0x33, 0x8e, 0x35, 0xf9, 0xd1, 0x6d, 0x0b, 0xdf, 0x15, 0x09, 0xe7, 0xcb, 0xf2, 0xd8, 0xbe, - 0x45, 0xa0, 0x12, 0x9e, 0xe3, 0x01, 0x34, 0xe5, 0xe5, 0xd4, 0x0b, 0x69, 0xbc, 0x34, 0x51, 0x4f, - 0xed, 0x37, 0x87, 0x2d, 0xa7, 0x7c, 0x61, 0x56, 0x28, 0x04, 0x4a, 0xc3, 0x98, 0xc6, 0x4b, 0xfc, - 0x13, 0x1a, 0x85, 0xcf, 0x4b, 0xa3, 0x80, 0x99, 0x1f, 0x7a, 0xa8, 0xdf, 0x1e, 0x7e, 0xaa, 0xcc, - 0x84, 0xe7, 0x4e, 0xe1, 0x99, 0x45, 0x01, 0x23, 0x7a, 0x58, 0x91, 0xfd, 0x15, 0xf4, 0xc3, 0x29, - 0xd6, 0xa1, 0x36, 0xf9, 0xf7, 0x7f, 0x6e, 0x28, 0xb8, 0x01, 0x1a, 0x39, 0x3e, 0x1a, 0xcf, 0x0d, - 0x64, 0xdf, 0x20, 0xa8, 0xcf, 0xe8, 0x5a, 0xc4, 0x0c, 0xdb, 0xa0, 0xc9, 0x59, 0x26, 0xea, 0xa1, - 0x57, 0x31, 0x4a, 0x09, 0x7f, 0x07, 0x4d, 0xf6, 0x90, 0xd3, 0x9b, 0xc3, 0x8e, 0x53, 0xb5, 0xf2, - 0x9d, 0xb3, 0x02, 0x48, 0xa9, 0x62, 0x07, 0x40, 0x82, 0x97, 0x6d, 0x04, 0x33, 0x55, 0x99, 0xb4, - 0x53, 0xbd, 0xf7, 0xeb, 0x3a, 0x4a, 0xe7, 0x1b, 0xc1, 0x48, 0x43, 0x5a, 0x0a, 0xb4, 0x3d, 0x30, - 0x08, 0xcf, 0x4f, 0xe9, 0x9a, 0xa5, 0x82, 0x2e, 0xd8, 0x5f, 0x9a, 0x51, 0xfc, 0x0d, 0xea, 0x65, - 0xf5, 0x37, 0x7f, 0x4b, 0xa5, 0xbd, 0x33, 0x90, 0xfd, 0x19, 0x34, 0x79, 0x0f, 0x63, 0xa8, 0x05, - 0x34, 0xa3, 0xb2, 0x63, 0x8b, 0x48, 0xfe, 0xf1, 0x05, 0xf4, 0x43, 0x28, 0xfc, 0x11, 0x54, 0x32, - 0x3d, 0x37, 0x94, 0x02, 0xfe, 0x4c, 0x27, 0x06, 0xfa, 0x7d, 0x72, 0xbf, 0xb3, 0xd0, 0x76, 0x67, - 0xa1, 0xc7, 0x9d, 0x85, 0xee, 0xf6, 0x96, 0xb2, 0xdd, 0x5b, 0xca, 0xc3, 0xde, 0x52, 0x2e, 0x46, - 0xab, 0x28, 0x0b, 0xaf, 0x7c, 0x67, 0xc1, 0xd7, 0xee, 0x82, 0xc5, 0x2c, 0xcd, 0x22, 0xca, 0x93, - 0xd5, 0x33, 0x0f, 0x2e, 0x79, 0x50, 0xec, 0xc5, 0xcb, 0xed, 0xf0, 0xeb, 0x72, 0x03, 0x46, 0x4f, - 0x01, 0x00, 0x00, 0xff, 0xff, 0x67, 0xb6, 0xc0, 0x8b, 0x36, 0x02, 0x00, 0x00, +var fileDescriptor_d53f2247170ec31c = []byte{ + // 383 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x92, 0x4f, 0x8b, 0xda, 0x40, + 0x18, 0xc6, 0x33, 0x8d, 0xb1, 0xf1, 0x55, 0x34, 0x4c, 0x2f, 0xa1, 0x96, 0x54, 0x42, 0x0b, 0x52, + 0x30, 0x29, 0xb6, 0x5f, 0xa0, 0xff, 0x2d, 0x88, 0x96, 0x51, 0x28, 0xf4, 0x12, 0x26, 0x66, 0x34, + 0x81, 0xd8, 0x99, 0x66, 0x22, 0xa9, 0xe7, 0x1e, 0x7a, 0xdd, 0x8f, 0xb5, 0x47, 0x8f, 0x7b, 0x5c, + 0xf4, 0x8b, 0x2c, 0x99, 0xc4, 0x3d, 0xec, 0xee, 0x61, 0x6f, 0xbf, 0xcc, 0xf3, 0x64, 0xde, 0xe7, + 0x19, 0x5e, 0xe8, 0xcb, 0x3f, 0x3b, 0x9a, 0x31, 0x5f, 0xc6, 0x05, 0x15, 0xbe, 0x08, 0x2b, 0xf0, + 0x44, 0xc6, 0x73, 0x8e, 0x0d, 0xf5, 0xf1, 0xbc, 0x2b, 0x42, 0x5f, 0x64, 0x9c, 0xaf, 0xab, 0x63, + 0xf7, 0x3f, 0x02, 0x9d, 0xf0, 0x02, 0x8f, 0xa0, 0x2d, 0x63, 0x9a, 0x31, 0x19, 0xc4, 0x34, 0x5d, + 0xdb, 0x68, 0xa0, 0x0f, 0xdb, 0xe3, 0x8e, 0x57, 0xdd, 0xb0, 0x28, 0x15, 0x02, 0x95, 0x61, 0x42, + 0xd3, 0x35, 0x7e, 0x0b, 0xad, 0xd2, 0x17, 0xc8, 0x24, 0x62, 0xf6, 0x93, 0x01, 0x1a, 0x76, 0xc7, + 0xcf, 0x6a, 0x33, 0xe1, 0x85, 0x57, 0x7a, 0x16, 0x49, 0xc4, 0x88, 0x19, 0xd7, 0xe4, 0xbe, 0x04, + 0xf3, 0x7c, 0x8a, 0x4d, 0x68, 0x4c, 0xbf, 0x7c, 0x5d, 0x5a, 0x1a, 0x6e, 0x81, 0x41, 0xbe, 0x7f, + 0x9b, 0x2c, 0x2d, 0xe4, 0xfe, 0x43, 0xd0, 0x5c, 0xd0, 0xad, 0x48, 0x19, 0x76, 0xc1, 0x50, 0xb3, + 0x6c, 0x34, 0x40, 0xf7, 0x62, 0x54, 0x12, 0x7e, 0x0d, 0x86, 0xea, 0xa1, 0xa6, 0xb7, 0xc7, 0x3d, + 0xaf, 0x6e, 0x15, 0x7a, 0x3f, 0x4a, 0x20, 0x95, 0x8a, 0x3d, 0x00, 0x05, 0x41, 0xbe, 0x17, 0xcc, + 0xd6, 0x55, 0xd2, 0x5e, 0x7d, 0xdf, 0x87, 0xbf, 0x89, 0x5c, 0xee, 0x05, 0x23, 0x2d, 0x65, 0x29, + 0xd1, 0x0d, 0xc0, 0x22, 0xbc, 0x98, 0xd1, 0x2d, 0x93, 0x82, 0xae, 0xd8, 0x67, 0x9a, 0x53, 0xfc, + 0x0a, 0x9a, 0x55, 0xf5, 0x07, 0x9f, 0xa5, 0xd6, 0x1e, 0x19, 0xc8, 0xed, 0x83, 0xa1, 0xfe, 0xc3, + 0x18, 0x1a, 0x11, 0xcd, 0xa9, 0xea, 0xd8, 0x21, 0x8a, 0xdf, 0xbc, 0x00, 0xf3, 0x1c, 0x0a, 0x3f, + 0x05, 0x9d, 0xcc, 0x7f, 0x5a, 0x5a, 0x09, 0x9f, 0xe6, 0x53, 0x0b, 0x7d, 0x9c, 0x5d, 0x1e, 0x1d, + 0x74, 0x38, 0x3a, 0xe8, 0xfa, 0xe8, 0xa0, 0x8b, 0x93, 0xa3, 0x1d, 0x4e, 0x8e, 0x76, 0x75, 0x72, + 0xb4, 0x5f, 0xef, 0x37, 0x49, 0x1e, 0xef, 0x42, 0x6f, 0xc5, 0xb7, 0xfe, 0x8a, 0xa5, 0x4c, 0xe6, + 0x09, 0xe5, 0xd9, 0xe6, 0x96, 0x47, 0xbf, 0x79, 0xc4, 0xfc, 0x3b, 0xeb, 0x11, 0x36, 0xd5, 0x0a, + 0xbc, 0xbb, 0x09, 0x00, 0x00, 0xff, 0xff, 0x80, 0x9c, 0x55, 0xe0, 0x38, 0x02, 0x00, 0x00, } func (m *Row) Marshal() (dAtA []byte, err error) { diff --git a/share/shwap/pb/shwap.proto b/square/shwap/pb/shwap.proto similarity index 89% rename from share/shwap/pb/shwap.proto rename to square/shwap/pb/shwap.proto index d7daea568a..444844f055 100644 --- a/share/shwap/pb/shwap.proto +++ b/square/shwap/pb/shwap.proto @@ -1,7 +1,7 @@ // Defined in CIP-19 https://github.com/celestiaorg/CIPs/blob/82aeb7dfc472105a11babffd548c730c899a3d24/cips/cip-19.md syntax = "proto3"; package shwap; -option go_package = "github.com/celestiaorg/celestia-node/share/shwap/pb"; +option go_package = "github.com/celestiaorg/celestia-node/square/shwap/pb"; import "pb/proof.proto"; // celestiaorg/nmt/pb/proof.proto diff --git a/share/shwap/row.go b/square/shwap/row.go similarity index 84% rename from share/shwap/row.go rename to square/shwap/row.go index 4e362beee2..b4298c27ab 100644 --- a/share/shwap/row.go +++ b/square/shwap/row.go @@ -4,10 +4,11 @@ import ( "bytes" "fmt" - "github.com/celestiaorg/celestia-app/v2/pkg/wrapper" + "github.com/celestiaorg/celestia-app/v3/pkg/wrapper" + "github.com/celestiaorg/go-square/v2/share" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/shwap/pb" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/shwap/pb" ) // RowName is the name identifier for the row container. @@ -49,11 +50,15 @@ func RowFromShares(shares []share.Share, side RowSide) Row { } // RowFromProto converts a protobuf Row to a Row structure. -func RowFromProto(r *pb.Row) Row { +func RowFromProto(r *pb.Row) (Row, error) { + shrs, err := SharesFromProto(r.SharesHalf) + if err != nil { + return Row{}, err + } return Row{ - halfShares: SharesFromProto(r.SharesHalf), + halfShares: shrs, side: sideFromProto(r.GetHalfSide()), - } + }, nil } // Shares reconstructs the complete row shares from the half provided, using RSMT2D for data @@ -67,7 +72,12 @@ func (r Row) Shares() ([]share.Share, error) { for i, share := range r.halfShares { shares[i+offset] = share } - return share.DefaultRSMT2DCodec().Decode(shares) + + rowShares, err := square.DefaultRSMT2DCodec().Decode(share.ToBytes(shares)) + if err != nil { + return nil, err + } + return share.FromBytes(rowShares) } // ToProto converts the Row to its protobuf representation. @@ -85,7 +95,7 @@ func (r Row) IsEmpty() bool { // Verify checks if the row's shares match the expected number from the root data and validates // the side of the row. -func (r Row) Verify(roots *share.AxisRoots, idx int) error { +func (r Row) Verify(roots *square.AxisRoots, idx int) error { if len(r.halfShares) == 0 { return fmt.Errorf("empty half row") } @@ -93,9 +103,6 @@ func (r Row) Verify(roots *share.AxisRoots, idx int) error { if len(r.halfShares) != expectedShares { return fmt.Errorf("shares size doesn't match root size: %d != %d", len(r.halfShares), expectedShares) } - if err := ValidateShares(r.halfShares); err != nil { - return fmt.Errorf("invalid shares: %w", err) - } if r.side != Left && r.side != Right { return fmt.Errorf("invalid RowSide: %d", r.side) } @@ -108,7 +115,7 @@ func (r Row) Verify(roots *share.AxisRoots, idx int) error { // verifyInclusion verifies the integrity of the row's shares against the provided root hash for the // given row index. -func (r Row) verifyInclusion(roots *share.AxisRoots, idx int) error { +func (r Row) verifyInclusion(roots *square.AxisRoots, idx int) error { shrs, err := r.Shares() if err != nil { return fmt.Errorf("while extending shares: %w", err) @@ -117,7 +124,7 @@ func (r Row) verifyInclusion(roots *share.AxisRoots, idx int) error { sqrLn := uint64(len(shrs) / 2) tree := wrapper.NewErasuredNamespacedMerkleTree(sqrLn, uint(idx)) for _, s := range shrs { - if err := tree.Push(s); err != nil { + if err := tree.Push(s.ToBytes()); err != nil { return fmt.Errorf("while pushing shares to NMT: %w", err) } } diff --git a/share/shwap/row_id.go b/square/shwap/row_id.go similarity index 100% rename from share/shwap/row_id.go rename to square/shwap/row_id.go diff --git a/share/shwap/row_id_test.go b/square/shwap/row_id_test.go similarity index 100% rename from share/shwap/row_id_test.go rename to square/shwap/row_id_test.go diff --git a/share/shwap/row_namespace_data.go b/square/shwap/row_namespace_data.go similarity index 84% rename from share/shwap/row_namespace_data.go rename to square/shwap/row_namespace_data.go index e92f264aa0..e658856fd9 100644 --- a/share/shwap/row_namespace_data.go +++ b/square/shwap/row_namespace_data.go @@ -5,14 +5,15 @@ import ( "fmt" "io" - "github.com/celestiaorg/celestia-app/v2/pkg/appconsts" - "github.com/celestiaorg/celestia-app/v2/pkg/wrapper" + "github.com/celestiaorg/celestia-app/v3/pkg/appconsts" + "github.com/celestiaorg/celestia-app/v3/pkg/wrapper" "github.com/celestiaorg/go-libp2p-messenger/serde" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt" nmt_pb "github.com/celestiaorg/nmt/pb" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/shwap/pb" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/shwap/pb" ) // RowNamespaceDataName is the name identifier for the row namespace data container. @@ -39,13 +40,13 @@ func RowNamespaceDataFromShares( tree := wrapper.NewErasuredNamespacedMerkleTree(uint64(len(shares)/2), uint(rowIndex)) nmtTree := nmt.New( appconsts.NewBaseHashFunc(), - nmt.NamespaceIDSize(appconsts.NamespaceSize), + nmt.NamespaceIDSize(share.NamespaceSize), nmt.IgnoreMaxNamespace(true), ) tree.SetTree(nmtTree) for _, shr := range shares { - if err := tree.Push(shr); err != nil { + if err := tree.Push(shr.ToBytes()); err != nil { return RowNamespaceData{}, fmt.Errorf("failed to build tree for row %d: %w", rowIndex, err) } } @@ -60,7 +61,7 @@ func RowNamespaceDataFromShares( var from, count int for i := range len(shares) / 2 { - if namespace.Equals(share.GetNamespace(shares[i])) { + if namespace.Equals(shares[i].Namespace()) { if count == 0 { from = i } @@ -74,7 +75,7 @@ func RowNamespaceDataFromShares( // if count is 0, then the namespace is not present in the shares. Return non-inclusion proof. if count == 0 { - proof, err := nmtTree.ProveNamespace(namespace.ToNMT()) + proof, err := nmtTree.ProveNamespace(namespace.Bytes()) if err != nil { return RowNamespaceData{}, fmt.Errorf("failed to generate non-inclusion proof for row %d: %w", rowIndex, err) } @@ -99,7 +100,7 @@ func RowNamespaceDataFromShares( } // RowNamespaceDataFromProto constructs RowNamespaceData out of its protobuf representation. -func RowNamespaceDataFromProto(row *pb.RowNamespaceData) RowNamespaceData { +func RowNamespaceDataFromProto(row *pb.RowNamespaceData) (RowNamespaceData, error) { var proof nmt.Proof if row.GetProof().GetLeafHash() != nil { proof = nmt.NewAbsenceProof( @@ -118,10 +119,15 @@ func RowNamespaceDataFromProto(row *pb.RowNamespaceData) RowNamespaceData { ) } + shares, err := SharesFromProto(row.GetShares()) + if err != nil { + return RowNamespaceData{}, err + } + return RowNamespaceData{ - Shares: SharesFromProto(row.GetShares()), + Shares: shares, Proof: &proof, - } + }, nil } // ToProto converts RowNamespaceData to its protobuf representation for serialization. @@ -144,7 +150,7 @@ func (rnd RowNamespaceData) IsEmpty() bool { } // Verify checks validity of the RowNamespaceData against the AxisRoots, Namespace and Row index. -func (rnd RowNamespaceData) Verify(roots *share.AxisRoots, namespace share.Namespace, rowIdx int) error { +func (rnd RowNamespaceData) Verify(roots *square.AxisRoots, namespace share.Namespace, rowIdx int) error { if rnd.Proof == nil || rnd.Proof.IsEmptyProof() { return fmt.Errorf("nil proof") } @@ -156,10 +162,6 @@ func (rnd RowNamespaceData) Verify(roots *share.AxisRoots, namespace share.Names return fmt.Errorf("non-empty shares with absence proof for row %d", rowIdx) } - if err := ValidateShares(rnd.Shares); err != nil { - return fmt.Errorf("invalid shares: %w", err) - } - rowRoot := roots.RowRoots[rowIdx] if namespace.IsOutsideRange(rowRoot, rowRoot) { return fmt.Errorf("namespace out of range for row %d", rowIdx) @@ -175,16 +177,16 @@ func (rnd RowNamespaceData) Verify(roots *share.AxisRoots, namespace share.Names func (rnd RowNamespaceData) verifyInclusion(rowRoot []byte, namespace share.Namespace) bool { leaves := make([][]byte, 0, len(rnd.Shares)) for _, sh := range rnd.Shares { - namespaceBytes := share.GetNamespace(sh) - leave := make([]byte, len(sh)+len(namespaceBytes)) + namespaceBytes := sh.Namespace().Bytes() + leave := make([]byte, len(sh.ToBytes())+len(namespaceBytes)) copy(leave, namespaceBytes) - copy(leave[len(namespaceBytes):], sh) + copy(leave[len(namespaceBytes):], sh.ToBytes()) // rework leaves = append(leaves, leave) } return rnd.Proof.VerifyNamespace( - share.NewSHA256Hasher(), - namespace.ToNMT(), + square.NewSHA256Hasher(), + namespace.Bytes(), leaves, rowRoot, ) @@ -199,8 +201,8 @@ func (rnd *RowNamespaceData) ReadFrom(reader io.Reader) (int64, error) { return int64(n), fmt.Errorf("reading RowNamespaceData: %w", err) } - *rnd = RowNamespaceDataFromProto(&pbrnd) - return int64(n), nil + *rnd, err = RowNamespaceDataFromProto(&pbrnd) + return int64(n), err } // WriteTo writes length-delimited protobuf representation of RowNamespaceData. diff --git a/share/shwap/row_namespace_data_id.go b/square/shwap/row_namespace_data_id.go similarity index 94% rename from share/shwap/row_namespace_data_id.go rename to square/shwap/row_namespace_data_id.go index 9ae87e0ee4..cdada45b03 100644 --- a/share/shwap/row_namespace_data_id.go +++ b/square/shwap/row_namespace_data_id.go @@ -4,7 +4,7 @@ import ( "fmt" "io" - "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/go-square/v2/share" ) // RowNamespaceDataIDSize defines the total size of a RowNamespaceDataID in bytes, combining the @@ -55,9 +55,10 @@ func RowNamespaceDataIDFromBinary(data []byte) (RowNamespaceDataID, error) { return RowNamespaceDataID{}, fmt.Errorf("unmarshaling RowID: %w", err) } + ns, err := share.NewNamespaceFromBytes(data[RowIDSize:]) rndid := RowNamespaceDataID{ RowID: rid, - DataNamespace: data[RowIDSize:], + DataNamespace: ns, } if err := rndid.Validate(); err != nil { return RowNamespaceDataID{}, fmt.Errorf("validating RowNamespaceDataID: %w", err) @@ -122,7 +123,7 @@ func (rndid RowNamespaceDataID) Validate() error { if err := rndid.RowID.Validate(); err != nil { return fmt.Errorf("validating RowID: %w", err) } - if err := rndid.DataNamespace.ValidateForData(); err != nil { + if err := share.ValidateForData(rndid.DataNamespace); err != nil { return fmt.Errorf("%w: validating DataNamespace: %w", ErrInvalidID, err) } @@ -132,5 +133,5 @@ func (rndid RowNamespaceDataID) Validate() error { // appendTo helps in appending the binary form of DataNamespace to the serialized RowID data. func (rndid RowNamespaceDataID) appendTo(data []byte) []byte { data = rndid.RowID.appendTo(data) - return append(data, rndid.DataNamespace...) + return append(data, rndid.DataNamespace.Bytes()...) } diff --git a/share/shwap/row_namespace_data_id_test.go b/square/shwap/row_namespace_data_id_test.go similarity index 88% rename from share/shwap/row_namespace_data_id_test.go rename to square/shwap/row_namespace_data_id_test.go index dd3aa6b689..658072c58a 100644 --- a/share/shwap/row_namespace_data_id_test.go +++ b/square/shwap/row_namespace_data_id_test.go @@ -7,12 +7,12 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/celestiaorg/celestia-node/share/sharetest" + "github.com/celestiaorg/go-square/v2/share" ) func TestRowNamespaceDataID(t *testing.T) { edsSize := 4 - ns := sharetest.RandV0Namespace() + ns := share.RandomNamespace() id, err := NewRowNamespaceDataID(1, 1, ns, edsSize) require.NoError(t, err) @@ -31,7 +31,7 @@ func TestRowNamespaceDataID(t *testing.T) { func TestRowNamespaceDataIDReaderWriter(t *testing.T) { edsSize := 4 - ns := sharetest.RandV0Namespace() + ns := share.RandomNamespace() id, err := NewRowNamespaceDataID(1, 1, ns, edsSize) require.NoError(t, err) diff --git a/square/shwap/row_namespace_data_test.go b/square/shwap/row_namespace_data_test.go new file mode 100644 index 0000000000..b120919d13 --- /dev/null +++ b/square/shwap/row_namespace_data_test.go @@ -0,0 +1,107 @@ +package shwap_test + +import ( + "bytes" + "context" + "slices" + "testing" + "time" + + "github.com/stretchr/testify/require" + + "github.com/celestiaorg/go-square/v2/share" + + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/eds" + "github.com/celestiaorg/celestia-node/square/eds/edstest" + "github.com/celestiaorg/celestia-node/square/shwap" +) + +func TestNamespacedRowFromShares(t *testing.T) { + const odsSize = 8 + + minNamespace, err := share.NewV0Namespace(slices.Concat(bytes.Repeat([]byte{0}, 8), []byte{1, 0})) + require.NoError(t, err) + err = share.ValidateForData(minNamespace) + require.NoError(t, err) + + for namespacedAmount := 1; namespacedAmount < odsSize; namespacedAmount++ { + shares := share.RandSharesWithNamespace(minNamespace, namespacedAmount, odsSize) + parity, err := square.DefaultRSMT2DCodec().Encode(share.ToBytes(shares)) + require.NoError(t, err) + + paritySh, err := share.FromBytes(parity) + require.NoError(t, err) + extended := slices.Concat(shares, paritySh) + + nr, err := shwap.RowNamespaceDataFromShares(extended, minNamespace, 0) + require.NoError(t, err) + require.Equal(t, namespacedAmount, len(nr.Shares)) + } +} + +//func TestNamespacedRowFromSharesNonIncluded(t *testing.T) { +// // TODO: this will fail until absence proof support is added +// t.Skip() +// +// const odsSize = 8 +// // Test absent namespace +// shares := share.RandShares( odsSize) +// absentNs, err := square.GetNamespace(shares[0]).AddInt(1) +// require.NoError(t, err) +// +// parity, err := square.DefaultRSMT2DCodec().Encode(shares) +// require.NoError(t, err) +// extended := slices.Concat(shares, parity) +// +// shrs, err := share.FromBytes(extended) +// require.NoError(t, err) +// +// nr, err := shwap.RowNamespaceDataFromShares(shrs, absentNs, 0) +// require.NoError(t, err) +// require.Len(t, nr.Shares, 0) +// require.True(t, nr.Proof.IsOfAbsence()) +//} + +//func TestValidateNamespacedRow(t *testing.T) { +// ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) +// t.Cleanup(cancel) +// +// const odsSize = 8 +// sharesAmount := odsSize * odsSize +// namespace := sharetest.RandV0Namespace() +// for amount := 1; amount < sharesAmount; amount++ { +// randEDS, root := edstest.RandEDSWithNamespace(t, namespace, amount, odsSize) +// rsmt2d := &eds.Rsmt2D{ExtendedDataSquare: randEDS} +// nd, err := eds.NamespaceData(ctx, rsmt2d, namespace) +// require.NoError(t, err) +// require.True(t, len(nd) > 0) +// +// rowIdxs := square.RowsWithNamespace(root, namespace) +// require.Len(t, nd, len(rowIdxs)) +// +// for i, rowIdx := range rowIdxs { +// err = nd[i].Verify(root, namespace, rowIdx) +// require.NoError(t, err) +// } +// } +//} + +func TestNamespacedRowProtoEncoding(t *testing.T) { + ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) + t.Cleanup(cancel) + + const odsSize = 8 + namespace := share.RandomNamespace() + randEDS, _ := edstest.RandEDSWithNamespace(t, namespace, odsSize, odsSize) + rsmt2d := &eds.Rsmt2D{ExtendedDataSquare: randEDS} + nd, err := eds.NamespaceData(ctx, rsmt2d, namespace) + require.NoError(t, err) + require.True(t, len(nd) > 0) + + expected := nd[0] + pb := expected.ToProto() + ndOut, err := shwap.RowNamespaceDataFromProto(pb) + require.NoError(t, err) + require.Equal(t, expected, ndOut) +} diff --git a/share/shwap/row_test.go b/square/shwap/row_test.go similarity index 74% rename from share/shwap/row_test.go rename to square/shwap/row_test.go index 353007b3a6..9bb9aded59 100644 --- a/share/shwap/row_test.go +++ b/square/shwap/row_test.go @@ -5,8 +5,10 @@ import ( "github.com/stretchr/testify/require" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/eds/edstest" + "github.com/celestiaorg/go-square/v2/share" + + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/eds/edstest" ) func TestRowFromShares(t *testing.T) { @@ -15,7 +17,9 @@ func TestRowFromShares(t *testing.T) { for rowIdx := 0; rowIdx < odsSize*2; rowIdx++ { for _, side := range []RowSide{Left, Right} { - shares := eds.Row(uint(rowIdx)) + shrs := eds.Row(uint(rowIdx)) + shares, err := share.FromBytes(shrs) + require.NoError(t, err) row := RowFromShares(shares, side) extended, err := row.Shares() require.NoError(t, err) @@ -36,15 +40,17 @@ func TestRowFromShares(t *testing.T) { func TestRowValidate(t *testing.T) { const odsSize = 8 eds := edstest.RandEDS(t, odsSize) - root, err := share.NewAxisRoots(eds) + root, err := square.NewAxisRoots(eds) require.NoError(t, err) for rowIdx := 0; rowIdx < odsSize*2; rowIdx++ { for _, side := range []RowSide{Left, Right} { - shares := eds.Row(uint(rowIdx)) + shrs := eds.Row(uint(rowIdx)) + shares, err := share.FromBytes(shrs) + require.NoError(t, err) row := RowFromShares(shares, side) - err := row.Verify(root, rowIdx) + err = row.Verify(root, rowIdx) require.NoError(t, err) err = row.Verify(root, rowIdx) require.NoError(t, err) @@ -54,9 +60,11 @@ func TestRowValidate(t *testing.T) { func TestRowValidateNegativeCases(t *testing.T) { eds := edstest.RandEDS(t, 8) // Generate a random Extended Data Square of size 8 - root, err := share.NewAxisRoots(eds) + root, err := square.NewAxisRoots(eds) + require.NoError(t, err) + shrs := eds.Row(0) + shares, err := share.FromBytes(shrs) require.NoError(t, err) - shares := eds.Row(0) row := RowFromShares(shares, Left) // Test with incorrect side specification @@ -67,7 +75,9 @@ func TestRowValidateNegativeCases(t *testing.T) { // Test with invalid shares (more shares than expected) incorrectShares := make([]share.Share, (eds.Width()/2)+1) // Adding an extra share for i := range incorrectShares { - incorrectShares[i] = eds.GetCell(uint(i), 0) + shr, err := share.NewShare(eds.GetCell(uint(i), 0)) + require.NoError(t, err) + incorrectShares[i] = *shr } invalidRow := Row{halfShares: incorrectShares, side: Left} err = invalidRow.Verify(root, 0) @@ -90,11 +100,14 @@ func TestRowProtoEncoding(t *testing.T) { for rowIdx := 0; rowIdx < odsSize*2; rowIdx++ { for _, side := range []RowSide{Left, Right} { - shares := eds.Row(uint(rowIdx)) + shrs := eds.Row(uint(rowIdx)) + shares, err := share.FromBytes(shrs) + require.NoError(t, err) row := RowFromShares(shares, side) pb := row.ToProto() - rowOut := RowFromProto(pb) + rowOut, err := RowFromProto(pb) + require.NoError(t, err) require.Equal(t, row, rowOut) } } @@ -105,9 +118,11 @@ func TestRowProtoEncoding(t *testing.T) { func BenchmarkRowValidate(b *testing.B) { const odsSize = 32 eds := edstest.RandEDS(b, odsSize) - root, err := share.NewAxisRoots(eds) + root, err := square.NewAxisRoots(eds) + require.NoError(b, err) + shrs := eds.Row(0) + shares, err := share.FromBytes(shrs) require.NoError(b, err) - shares := eds.Row(0) row := RowFromShares(shares, Left) b.ResetTimer() diff --git a/share/shwap/sample.go b/square/shwap/sample.go similarity index 82% rename from share/shwap/sample.go rename to square/shwap/sample.go index 48ae22088a..2e24918e0a 100644 --- a/share/shwap/sample.go +++ b/square/shwap/sample.go @@ -4,13 +4,14 @@ import ( "errors" "fmt" - "github.com/celestiaorg/celestia-app/v2/pkg/wrapper" + "github.com/celestiaorg/celestia-app/v3/pkg/wrapper" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt" nmt_pb "github.com/celestiaorg/nmt/pb" "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/shwap/pb" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/shwap/pb" ) // SampleName is the name identifier for the sample container. @@ -33,7 +34,7 @@ type Sample struct { func SampleFromShares(shares []share.Share, proofType rsmt2d.Axis, axisIdx, shrIdx int) (Sample, error) { tree := wrapper.NewErasuredNamespacedMerkleTree(uint64(len(shares)/2), uint(axisIdx)) for _, shr := range shares { - err := tree.Push(shr) + err := tree.Push(shr.ToBytes()) if err != nil { return Sample{}, err } @@ -52,24 +53,30 @@ func SampleFromShares(shares []share.Share, proofType rsmt2d.Axis, axisIdx, shrI } // SampleFromProto converts a protobuf Sample back into its domain model equivalent. -func SampleFromProto(s *pb.Sample) Sample { +func SampleFromProto(s *pb.Sample) (Sample, error) { proof := nmt.NewInclusionProof( int(s.GetProof().GetStart()), int(s.GetProof().GetEnd()), s.GetProof().GetNodes(), s.GetProof().GetIsMaxNamespaceIgnored(), ) + + shrs, err := ShareFromProto(s.GetShare()) + if err != nil { + return Sample{}, err + } + return Sample{ - Share: ShareFromProto(s.GetShare()), + Share: shrs, Proof: &proof, ProofType: rsmt2d.Axis(s.GetProofType()), - } + }, nil } // ToProto converts a Sample into its protobuf representation for serialization purposes. func (s Sample) ToProto() *pb.Sample { return &pb.Sample{ - Share: &pb.Share{Data: s.Share}, + Share: &pb.Share{Data: s.Share.ToBytes()}, Proof: &nmt_pb.Proof{ Start: int64(s.Proof.Start()), End: int64(s.Proof.End()), @@ -88,13 +95,10 @@ func (s Sample) IsEmpty() bool { // Verify checks the inclusion of the share using its Merkle proof under the specified AxisRoots. // Returns an error if the proof is invalid or does not correspond to the indicated proof type. -func (s Sample) Verify(roots *share.AxisRoots, rowIdx, colIdx int) error { +func (s Sample) Verify(roots *square.AxisRoots, rowIdx, colIdx int) error { if s.Proof == nil || s.Proof.IsEmptyProof() { return errors.New("nil proof") } - if err := share.ValidateShare(s.Share); err != nil { - return err - } if s.ProofType != rsmt2d.Row && s.ProofType != rsmt2d.Col { return fmt.Errorf("invalid SampleProofType: %d", s.ProofType) } @@ -105,14 +109,14 @@ func (s Sample) Verify(roots *share.AxisRoots, rowIdx, colIdx int) error { } // verifyInclusion checks if the share is included in the given root hash at the specified indices. -func (s Sample) verifyInclusion(roots *share.AxisRoots, rowIdx, colIdx int) bool { +func (s Sample) verifyInclusion(roots *square.AxisRoots, rowIdx, colIdx int) bool { size := len(roots.RowRoots) namespace := inclusionNamespace(s.Share, rowIdx, colIdx, size) - rootHash := share.RootHashForCoordinates(roots, s.ProofType, uint(rowIdx), uint(colIdx)) + rootHash := square.RootHashForCoordinates(roots, s.ProofType, uint(rowIdx), uint(colIdx)) return s.Proof.VerifyInclusion( - share.NewSHA256Hasher(), - namespace.ToNMT(), - [][]byte{s.Share}, + square.NewSHA256Hasher(), + namespace.Bytes(), + [][]byte{s.Share.ToBytes()}, rootHash, ) } @@ -126,5 +130,5 @@ func inclusionNamespace(sh share.Share, rowIdx, colIdx, squareSize int) share.Na if isParity { return share.ParitySharesNamespace } - return share.GetNamespace(sh) + return sh.Namespace() } diff --git a/share/shwap/sample_id.go b/square/shwap/sample_id.go similarity index 100% rename from share/shwap/sample_id.go rename to square/shwap/sample_id.go diff --git a/share/shwap/sample_id_test.go b/square/shwap/sample_id_test.go similarity index 100% rename from share/shwap/sample_id_test.go rename to square/shwap/sample_id_test.go diff --git a/share/shwap/sample_test.go b/square/shwap/sample_test.go similarity index 83% rename from share/shwap/sample_test.go rename to square/shwap/sample_test.go index ea57f68e94..a2b4aa1e53 100644 --- a/share/shwap/sample_test.go +++ b/square/shwap/sample_test.go @@ -6,18 +6,19 @@ import ( "github.com/stretchr/testify/require" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/eds" - "github.com/celestiaorg/celestia-node/share/eds/edstest" - "github.com/celestiaorg/celestia-node/share/shwap" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/eds" + "github.com/celestiaorg/celestia-node/square/eds/edstest" + "github.com/celestiaorg/celestia-node/square/shwap" ) func TestSampleValidate(t *testing.T) { const odsSize = 8 randEDS := edstest.RandEDS(t, odsSize) - root, err := share.NewAxisRoots(randEDS) + root, err := square.NewAxisRoots(randEDS) require.NoError(t, err) inMem := eds.Rsmt2D{ExtendedDataSquare: randEDS} @@ -37,7 +38,7 @@ func TestSampleValidate(t *testing.T) { func TestSampleNegativeVerifyInclusion(t *testing.T) { const odsSize = 8 randEDS := edstest.RandEDS(t, odsSize) - root, err := share.NewAxisRoots(randEDS) + root, err := square.NewAxisRoots(randEDS) require.NoError(t, err) inMem := eds.Rsmt2D{ExtendedDataSquare: randEDS} @@ -51,7 +52,11 @@ func TestSampleNegativeVerifyInclusion(t *testing.T) { require.ErrorIs(t, err, shwap.ErrFailedVerification) // Corrupt the share - sample.Share[0] ^= 0xFF + b := sample.Share.ToBytes() + b[0] ^= 0xFF + shr, err := share.NewShare(b) + require.NoError(t, err) + sample.Share = *shr err = sample.Verify(root, 0, 0) require.ErrorIs(t, err, shwap.ErrFailedVerification) @@ -82,7 +87,7 @@ func TestSampleProtoEncoding(t *testing.T) { require.NoError(t, err) pb := sample.ToProto() - sampleOut := shwap.SampleFromProto(pb) + sampleOut, err := shwap.SampleFromProto(pb) require.NoError(t, err) require.Equal(t, sample, sampleOut) } @@ -95,7 +100,7 @@ func TestSampleProtoEncoding(t *testing.T) { func BenchmarkSampleValidate(b *testing.B) { const odsSize = 32 randEDS := edstest.RandEDS(b, odsSize) - root, err := share.NewAxisRoots(randEDS) + root, err := square.NewAxisRoots(randEDS) require.NoError(b, err) inMem := eds.Rsmt2D{ExtendedDataSquare: randEDS} sample, err := inMem.SampleForProofAxis(0, 0, rsmt2d.Row) diff --git a/share/shwap/share.go b/square/shwap/share.go similarity index 59% rename from share/shwap/share.go rename to square/shwap/share.go index a7f7ef67b7..76b68e0eff 100644 --- a/share/shwap/share.go +++ b/square/shwap/share.go @@ -3,18 +3,23 @@ package shwap import ( "fmt" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/shwap/pb" + "github.com/celestiaorg/go-square/v2/share" + + "github.com/celestiaorg/celestia-node/square/shwap/pb" ) // ShareFromProto converts a protobuf Share object to the application's internal share // representation. It returns nil if the input protobuf Share is nil, ensuring safe handling of nil // values. -func ShareFromProto(s *pb.Share) share.Share { +func ShareFromProto(s *pb.Share) (share.Share, error) { if s == nil { - return nil + return share.Share{}, nil + } + sh, err := share.NewShare(s.Data) + if err != nil { + return share.Share{}, err } - return s.Data + return *sh, err } // SharesToProto converts a slice of Shares from the application's internal representation to a @@ -23,27 +28,21 @@ func ShareFromProto(s *pb.Share) share.Share { func SharesToProto(shrs []share.Share) []*pb.Share { protoShares := make([]*pb.Share, len(shrs)) for i, shr := range shrs { - protoShares[i] = &pb.Share{Data: shr} + protoShares[i] = &pb.Share{Data: shr.ToBytes()} } return protoShares } // SharesFromProto converts a slice of protobuf Share objects to the application's internal slice // of Shares. It ensures that each Share is correctly transformed using the ShareFromProto function. -func SharesFromProto(shrs []*pb.Share) []share.Share { +func SharesFromProto(shrs []*pb.Share) ([]share.Share, error) { shares := make([]share.Share, len(shrs)) + var err error for i, shr := range shrs { - shares[i] = ShareFromProto(shr) - } - return shares -} - -// ValidateShares takes the slice of shares and checks their conformance to share format. -func ValidateShares(shares []share.Share) error { - for i, shr := range shares { - if err := share.ValidateShare(shr); err != nil { - return fmt.Errorf("while validating share at index %d: %w", i, err) + shares[i], err = ShareFromProto(shr) + if err != nil { + return nil, fmt.Errorf("invalid share at index %d: %w", i, err) } } - return nil + return shares, nil } diff --git a/state/core_access.go b/state/core_access.go index 6cd8fe7a58..f36798c261 100644 --- a/state/core_access.go +++ b/state/core_access.go @@ -22,10 +22,10 @@ import ( "google.golang.org/grpc/connectivity" "google.golang.org/grpc/credentials/insecure" - "github.com/celestiaorg/celestia-app/v2/app" - "github.com/celestiaorg/celestia-app/v2/app/encoding" - apperrors "github.com/celestiaorg/celestia-app/v2/app/errors" - "github.com/celestiaorg/celestia-app/v2/pkg/user" + "github.com/celestiaorg/celestia-app/v3/app" + "github.com/celestiaorg/celestia-app/v3/app/encoding" + apperrors "github.com/celestiaorg/celestia-app/v3/app/errors" + "github.com/celestiaorg/celestia-app/v3/pkg/user" libhead "github.com/celestiaorg/go-header" "github.com/celestiaorg/celestia-node/header" @@ -220,7 +220,7 @@ func (ca *CoreAccessor) SubmitPayForBlob( if gas == 0 { blobSizes := make([]uint32, len(appblobs)) for i, blob := range appblobs { - blobSizes[i] = uint32(len(blob.GetData())) + blobSizes[i] = uint32(len(blob.Data())) } gas = estimateGasForBlobs(blobSizes) } diff --git a/state/core_access_test.go b/state/core_access_test.go index 8853cb17be..f44057bbea 100644 --- a/state/core_access_test.go +++ b/state/core_access_test.go @@ -14,14 +14,12 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/celestiaorg/celestia-app/v2/app" - appconsts "github.com/celestiaorg/celestia-app/v2/pkg/appconsts" - genesis "github.com/celestiaorg/celestia-app/v2/test/util/genesis" - "github.com/celestiaorg/celestia-app/v2/test/util/testnode" - apptypes "github.com/celestiaorg/celestia-app/v2/x/blob/types" - squareblob "github.com/celestiaorg/go-square/blob" - - "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-app/v3/app" + "github.com/celestiaorg/celestia-app/v3/pkg/appconsts" + "github.com/celestiaorg/celestia-app/v3/test/util/genesis" + "github.com/celestiaorg/celestia-app/v3/test/util/testnode" + apptypes "github.com/celestiaorg/celestia-app/v3/x/blob/types" + "github.com/celestiaorg/go-square/v2/share" ) func TestSubmitPayForBlob(t *testing.T) { @@ -34,30 +32,33 @@ func TestSubmitPayForBlob(t *testing.T) { _ = ca.Stop(ctx) }) - ns, err := share.NewBlobNamespaceV0([]byte("namespace")) + ns, err := share.NewV0Namespace([]byte("namespace")) + require.NoError(t, err) + require.False(t, ns.IsReserved()) + require.NoError(t, err) - blobbyTheBlob, err := apptypes.NewBlob(ns.ToAppNamespace(), []byte("data"), 0) + blobbyTheBlob, err := share.NewV0Blob(ns, []byte("data")) require.NoError(t, err) testcases := []struct { name string - blobs []*squareblob.Blob + blobs []*share.Blob gasPrice float64 gasLim uint64 expErr error }{ { name: "empty blobs", - blobs: []*squareblob.Blob{}, + blobs: []*share.Blob{}, gasPrice: DefaultGasPrice, gasLim: 0, expErr: errors.New("state: no blobs provided"), }, { name: "good blob with user provided gas and fees", - blobs: []*squareblob.Blob{blobbyTheBlob}, + blobs: []*share.Blob{blobbyTheBlob}, gasPrice: 0.005, - gasLim: apptypes.DefaultEstimateGas([]uint32{uint32(len(blobbyTheBlob.GetData()))}), + gasLim: apptypes.DefaultEstimateGas([]uint32{uint32(blobbyTheBlob.DataLen())}), expErr: nil, }, // TODO: add more test cases. The problem right now is that the celestia-app doesn't diff --git a/state/integration_test.go b/state/integration_test.go index 5a9a0892ea..8680b4d181 100644 --- a/state/integration_test.go +++ b/state/integration_test.go @@ -16,9 +16,9 @@ import ( rpcclient "github.com/tendermint/tendermint/rpc/client" "google.golang.org/grpc" - "github.com/celestiaorg/celestia-app/v2/pkg/appconsts" - "github.com/celestiaorg/celestia-app/v2/test/util/genesis" - "github.com/celestiaorg/celestia-app/v2/test/util/testnode" + "github.com/celestiaorg/celestia-app/v3/pkg/appconsts" + "github.com/celestiaorg/celestia-app/v3/test/util/genesis" + "github.com/celestiaorg/celestia-app/v3/test/util/testnode" libhead "github.com/celestiaorg/go-header" "github.com/celestiaorg/celestia-node/core" diff --git a/state/state.go b/state/state.go index 5f09bcc19b..bb423bba34 100644 --- a/state/state.go +++ b/state/state.go @@ -8,7 +8,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" coretypes "github.com/tendermint/tendermint/types" - squareblob "github.com/celestiaorg/go-square/blob" + "github.com/celestiaorg/go-square/v2/share" ) // Balance is an alias to the Coin type from Cosmos-SDK. @@ -27,7 +27,7 @@ type Address struct { } // Blob is an alias of Blob from go-square. -type Blob = squareblob.Blob +type Blob = share.Blob // ValAddress is an alias to the ValAddress type from Cosmos-SDK. type ValAddress = sdk.ValAddress diff --git a/state/tx_config.go b/state/tx_config.go index 0c0ea5e372..179a33050a 100644 --- a/state/tx_config.go +++ b/state/tx_config.go @@ -8,8 +8,8 @@ import ( "github.com/cosmos/cosmos-sdk/crypto/keyring" sdktypes "github.com/cosmos/cosmos-sdk/types" - "github.com/celestiaorg/celestia-app/v2/pkg/user" - apptypes "github.com/celestiaorg/celestia-app/v2/x/blob/types" + "github.com/celestiaorg/celestia-app/v3/pkg/user" + apptypes "github.com/celestiaorg/celestia-app/v3/x/blob/types" ) const ( diff --git a/store/cache/accessor_cache.go b/store/cache/accessor_cache.go index 893c73b7a9..2b99bfee13 100644 --- a/store/cache/accessor_cache.go +++ b/store/cache/accessor_cache.go @@ -10,7 +10,7 @@ import ( lru "github.com/hashicorp/golang-lru/v2" - "github.com/celestiaorg/celestia-node/share/eds" + "github.com/celestiaorg/celestia-node/square/eds" ) const defaultCloseTimeout = time.Minute diff --git a/store/cache/accessor_cache_test.go b/store/cache/accessor_cache_test.go index 876a4fdc5a..16fd7d1a7d 100644 --- a/store/cache/accessor_cache_test.go +++ b/store/cache/accessor_cache_test.go @@ -11,11 +11,12 @@ import ( "github.com/stretchr/testify/require" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/eds" - "github.com/celestiaorg/celestia-node/share/shwap" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/eds" + "github.com/celestiaorg/celestia-node/square/shwap" ) func TestAccessorCache(t *testing.T) { @@ -306,11 +307,11 @@ func (m *mockAccessor) Size(context.Context) int { panic("implement me") } -func (m *mockAccessor) DataHash(context.Context) (share.DataHash, error) { +func (m *mockAccessor) DataHash(context.Context) (square.DataHash, error) { panic("implement me") } -func (m *mockAccessor) AxisRoots(context.Context) (*share.AxisRoots, error) { +func (m *mockAccessor) AxisRoots(context.Context) (*square.AxisRoots, error) { panic("implement me") } diff --git a/store/cache/cache.go b/store/cache/cache.go index 10e7dffcb3..6e5438913a 100644 --- a/store/cache/cache.go +++ b/store/cache/cache.go @@ -7,7 +7,7 @@ import ( logging "github.com/ipfs/go-log/v2" "go.opentelemetry.io/otel" - "github.com/celestiaorg/celestia-node/share/eds" + "github.com/celestiaorg/celestia-node/square/eds" ) var ( diff --git a/store/cache/doublecache.go b/store/cache/doublecache.go index d0fb2c47b9..f06bd06fe7 100644 --- a/store/cache/doublecache.go +++ b/store/cache/doublecache.go @@ -5,7 +5,7 @@ import ( "errors" "fmt" - "github.com/celestiaorg/celestia-node/share/eds" + "github.com/celestiaorg/celestia-node/square/eds" ) // DoubleCache represents a Cache that looks into multiple caches one by one. diff --git a/store/cache/noop.go b/store/cache/noop.go index 1a8aeb16c2..5be2eef20b 100644 --- a/store/cache/noop.go +++ b/store/cache/noop.go @@ -4,11 +4,12 @@ import ( "context" "io" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/eds" - "github.com/celestiaorg/celestia-node/share/shwap" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/eds" + "github.com/celestiaorg/celestia-node/square/shwap" ) var _ Cache = (*NoopCache)(nil) @@ -50,12 +51,12 @@ func (n NoopFile) Size(context.Context) int { return 0 } -func (n NoopFile) DataHash(context.Context) (share.DataHash, error) { - return share.DataHash{}, nil +func (n NoopFile) DataHash(context.Context) (square.DataHash, error) { + return square.DataHash{}, nil } -func (n NoopFile) AxisRoots(context.Context) (*share.AxisRoots, error) { - return &share.AxisRoots{}, nil +func (n NoopFile) AxisRoots(context.Context) (*square.AxisRoots, error) { + return &square.AxisRoots{}, nil } func (n NoopFile) Sample(context.Context, int, int) (shwap.Sample, error) { diff --git a/store/file/codec_test.go b/store/file/codec_test.go index 857c16aff0..0ab9b7c5bb 100644 --- a/store/file/codec_test.go +++ b/store/file/codec_test.go @@ -7,7 +7,7 @@ import ( "github.com/klauspost/reedsolomon" "github.com/stretchr/testify/require" - "github.com/celestiaorg/celestia-node/share/sharetest" + "github.com/celestiaorg/go-square/v2/share" ) func BenchmarkCodec(b *testing.B) { @@ -70,13 +70,13 @@ func BenchmarkCodec(b *testing.B) { func newShards(b testing.TB, size int, fillParity bool) [][]byte { shards := make([][]byte, size) - original := sharetest.RandShares(b, size/2) - copy(shards, original) + original := share.RandShares(size / 2) + copy(shards, share.ToBytes(original)) if fillParity { // fill with parity empty Shares for j := len(original); j < len(shards); j++ { - shards[j] = make([]byte, len(original[0])) + shards[j] = make([]byte, share.ShareSize) } } return shards diff --git a/store/file/header.go b/store/file/header.go index 7c2d8c7924..bb5f891870 100644 --- a/store/file/header.go +++ b/store/file/header.go @@ -5,7 +5,7 @@ import ( "fmt" "io" - "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/square" ) // headerVOSize is the size of the headerV0 in bytes. It has more space than the headerV0 struct @@ -23,7 +23,7 @@ type headerV0 struct { shareSize uint16 squareSize uint16 - datahash share.DataHash + datahash square.DataHash } type fileVersion uint8 @@ -75,7 +75,7 @@ func (h *headerV0) Size() int { func (h *headerV0) RootsSize() int { // axis roots are stored in two parts: row roots and column roots, each part has size equal to // the square size. Thus, the total amount of roots is equal to the square size * 2. - return share.AxisRootSize * h.SquareSize() * 2 + return square.AxisRootSize * h.SquareSize() * 2 } func (h *headerV0) OffsetWithRoots() int { diff --git a/store/file/ods.go b/store/file/ods.go index a97efb85ec..738109fae4 100644 --- a/store/file/ods.go +++ b/store/file/ods.go @@ -9,11 +9,12 @@ import ( "os" "sync" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/eds" - "github.com/celestiaorg/celestia-node/share/shwap" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/eds" + "github.com/celestiaorg/celestia-node/square/shwap" ) var _ eds.AccessorStreamer = (*ODS)(nil) @@ -33,7 +34,7 @@ type ODS struct { // repeated file reads. - Serving full ODS data by Shares(). // Storing the square in memory allows for efficient single-read operations, avoiding the need for // piecemeal reads by rows or columns, and facilitates quick access to data for these operations. - ods square + ods dataSquare // disableCache is a flag that, when set to true, disables the in-memory cache of the original data // Used for testing and benchmarking purposes, this flag allows for the evaluation of the // performance. @@ -45,7 +46,7 @@ type ODS struct { // It may leave partially written file if any of the writes fail. func CreateODS( path string, - roots *share.AxisRoots, + roots *square.AxisRoots, eds *rsmt2d.ExtendedDataSquare, ) error { mod := os.O_RDWR | os.O_CREATE | os.O_EXCL // ensure we fail if already exist @@ -71,7 +72,7 @@ func CreateODS( } // writeQ4File full ODS content into OS File. -func writeODSFile(f *os.File, axisRoots *share.AxisRoots, eds *rsmt2d.ExtendedDataSquare, hdr *headerV0) error { +func writeODSFile(f *os.File, axisRoots *square.AxisRoots, eds *rsmt2d.ExtendedDataSquare, hdr *headerV0) error { // buffering gives us ~4x speed up buf := bufio.NewWriterSize(f, writeBufferSize) @@ -101,11 +102,15 @@ func writeODS(w io.Writer, eds *rsmt2d.ExtendedDataSquare) error { for i := range eds.Width() / 2 { for j := range eds.Width() / 2 { shr := eds.GetCell(i, j) // TODO: Avoid copying inside GetCell - if share.GetNamespace(shr).Equals(share.TailPaddingNamespace) { + ns, err := share.NewNamespace(shr[share.VersionIndex], shr[share.VersionIndex:share.NamespaceIDSize]) + if err != nil { + return fmt.Errorf("creating namespace: %w", err) + } + if ns.Equals(share.TailPaddingNamespace) { return nil } - _, err := w.Write(shr) + _, err = w.Write(shr) if err != nil { return fmt.Errorf("writing share: %w", err) } @@ -115,7 +120,7 @@ func writeODS(w io.Writer, eds *rsmt2d.ExtendedDataSquare) error { } // writeAxisRoots writes RowRoots followed by ColumnRoots. -func writeAxisRoots(w io.Writer, roots *share.AxisRoots) error { +func writeAxisRoots(w io.Writer, roots *square.AxisRoots) error { for _, root := range roots.RowRoots { if _, err := w.Write(root); err != nil { return fmt.Errorf("writing row roots: %w", err) @@ -184,13 +189,13 @@ func (o *ODS) size() int { } // DataHash returns root hash of Accessor's underlying EDS. -func (o *ODS) DataHash(context.Context) (share.DataHash, error) { +func (o *ODS) DataHash(context.Context) (square.DataHash, error) { return o.hdr.datahash, nil } // AxisRoots reads AxisRoots stored in the file. AxisRoots are stored after the header and before // the ODS data. -func (o *ODS) AxisRoots(context.Context) (*share.AxisRoots, error) { +func (o *ODS) AxisRoots(context.Context) (*square.AxisRoots, error) { roots := make([]byte, o.hdr.RootsSize()) n, err := o.fl.ReadAt(roots, int64(o.hdr.Size())) if err != nil { @@ -202,10 +207,10 @@ func (o *ODS) AxisRoots(context.Context) (*share.AxisRoots, error) { rowRoots := make([][]byte, o.size()) colRoots := make([][]byte, o.size()) for i := 0; i < o.size(); i++ { - rowRoots[i] = roots[i*share.AxisRootSize : (i+1)*share.AxisRootSize] - colRoots[i] = roots[(o.size()+i)*share.AxisRootSize : (o.size()+i+1)*share.AxisRootSize] + rowRoots[i] = roots[i*square.AxisRootSize : (i+1)*square.AxisRootSize] + colRoots[i] = roots[(o.size()+i)*square.AxisRootSize : (o.size()+i+1)*square.AxisRootSize] } - axisRoots := &share.AxisRoots{ + axisRoots := &square.AxisRoots{ RowRoots: rowRoots, ColumnRoots: colRoots, } @@ -338,7 +343,7 @@ func (o *ODS) readAxisHalf(axisType rsmt2d.Axis, axisIdx int) (eds.AxisHalf, err }, nil } -func (o *ODS) readODS() (square, error) { +func (o *ODS) readODS() (dataSquare, error) { if !o.disableCache { o.lock.RLock() ods := o.ods @@ -399,10 +404,14 @@ func readRowHalf(r io.ReaderAt, rowIdx int, hdr *headerV0, offset int) ([]share. if i > shrsRead-1 { // partial or empty row was read // fill the rest with tail padding it - shares[i] = share.TailPadding() + shares[i] = share.TailPaddingShare() continue } - shares[i] = axsData[i*hdr.ShareSize() : (i+1)*hdr.ShareSize()] + sh, err := share.NewShare(axsData[i*hdr.ShareSize() : (i+1)*hdr.ShareSize()]) + if err != nil { + return nil, err + } + shares[i] = *sh } return shares, nil } @@ -416,7 +425,7 @@ func readColHalf(r io.ReaderAt, colIdx int, hdr *headerV0, offset int) ([]share. pos := colIdx + i*odsLn offset := offset + pos*hdr.ShareSize() - shr := make(share.Share, hdr.ShareSize()) + shr := make([]byte, hdr.ShareSize()) n, err := r.ReadAt(shr, int64(offset)) if err != nil && !errors.Is(err, io.EOF) { // unknown error @@ -426,12 +435,17 @@ func readColHalf(r io.ReaderAt, colIdx int, hdr *headerV0, offset int) ([]share. // no shares left // fill the rest with tail padding for ; i < len(shares); i++ { - shares[i] = share.TailPadding() + shares[i] = share.TailPaddingShare() } return shares, nil } + + sh, err := share.NewShare(shr) + if err != nil { + return nil, err + } // we got a share - shares[i] = shr + shares[i] = *sh } return shares, nil } diff --git a/store/file/ods_q4.go b/store/file/ods_q4.go index e0f396e79e..ce1c00f7b5 100644 --- a/store/file/ods_q4.go +++ b/store/file/ods_q4.go @@ -9,11 +9,12 @@ import ( "sync" "sync/atomic" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/eds" - "github.com/celestiaorg/celestia-node/share/shwap" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/eds" + "github.com/celestiaorg/celestia-node/square/shwap" ) var _ eds.AccessorStreamer = (*ODSQ4)(nil) @@ -36,7 +37,7 @@ type ODSQ4 struct { // CreateODSQ4 creates ODS and Q4 files under the given FS paths. func CreateODSQ4( pathODS, pathQ4 string, - roots *share.AxisRoots, + roots *square.AxisRoots, eds *rsmt2d.ExtendedDataSquare, ) error { errCh := make(chan error) @@ -113,11 +114,11 @@ func (odsq4 *ODSQ4) Size(ctx context.Context) int { return odsq4.ods.Size(ctx) } -func (odsq4 *ODSQ4) DataHash(ctx context.Context) (share.DataHash, error) { +func (odsq4 *ODSQ4) DataHash(ctx context.Context) (square.DataHash, error) { return odsq4.ods.DataHash(ctx) } -func (odsq4 *ODSQ4) AxisRoots(ctx context.Context) (*share.AxisRoots, error) { +func (odsq4 *ODSQ4) AxisRoots(ctx context.Context) (*square.AxisRoots, error) { return odsq4.ods.AxisRoots(ctx) } diff --git a/store/file/ods_q4_test.go b/store/file/ods_q4_test.go index 0265887135..83e94d8a96 100644 --- a/store/file/ods_q4_test.go +++ b/store/file/ods_q4_test.go @@ -12,11 +12,12 @@ import ( "github.com/stretchr/testify/require" "github.com/tendermint/tendermint/libs/rand" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/eds" - "github.com/celestiaorg/celestia-node/share/eds/edstest" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/eds" + "github.com/celestiaorg/celestia-node/square/eds/edstest" ) func TestCreateODSQ4File(t *testing.T) { @@ -29,7 +30,7 @@ func TestCreateODSQ4File(t *testing.T) { shares, err := odsq4.Shares(ctx) require.NoError(t, err) expected := edsIn.FlattenedODS() - require.Equal(t, expected, shares) + require.Equal(t, expected, share.ToBytes(shares)) require.NoError(t, odsq4.Close()) } @@ -181,7 +182,7 @@ func createODSQ4Accessor(t testing.TB, eds *rsmt2d.ExtendedDataSquare) eds.Acces func createODSQ4File(t testing.TB, eds *rsmt2d.ExtendedDataSquare) *ODSQ4 { path := t.TempDir() + "/" + strconv.Itoa(rand.Intn(1000)) - roots, err := share.NewAxisRoots(eds) + roots, err := square.NewAxisRoots(eds) require.NoError(t, err) pathODS, pathQ4 := path+".ods", path+".q4" err = CreateODSQ4(pathODS, pathQ4, roots, eds) diff --git a/store/file/ods_test.go b/store/file/ods_test.go index 5d79d21a2a..73c3ff2f89 100644 --- a/store/file/ods_test.go +++ b/store/file/ods_test.go @@ -12,11 +12,12 @@ import ( "github.com/stretchr/testify/require" "github.com/tendermint/tendermint/libs/rand" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/eds" - "github.com/celestiaorg/celestia-node/share/eds/edstest" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/eds" + "github.com/celestiaorg/celestia-node/square/eds/edstest" ) func TestCreateODSFile(t *testing.T) { @@ -25,18 +26,18 @@ func TestCreateODSFile(t *testing.T) { edsIn := edstest.RandEDS(t, 8) f := createODSFile(t, edsIn) - readRoots, err := share.NewAxisRoots(edsIn) + readRoots, err := square.NewAxisRoots(edsIn) require.NoError(t, err) shares, err := f.Shares(ctx) require.NoError(t, err) expected := edsIn.FlattenedODS() - require.Equal(t, expected, shares) + require.Equal(t, expected, share.ToBytes(shares)) roots, err := f.AxisRoots(ctx) require.NoError(t, err) - require.Equal(t, share.DataHash(roots.Hash()), f.hdr.datahash) + require.Equal(t, square.DataHash(roots.Hash()), f.hdr.datahash) require.True(t, roots.Equals(readRoots)) require.NoError(t, f.Close()) } @@ -50,7 +51,7 @@ func TestReadODSFromFile(t *testing.T) { for i, row := range ods { original := eds.Row(uint(i))[:eds.Width()/2] require.True(t, len(original) == len(row)) - require.Equal(t, original, row) + require.Equal(t, original, share.ToBytes(row)) } } @@ -250,7 +251,7 @@ func createCachedStreamer(t testing.TB, eds *rsmt2d.ExtendedDataSquare) eds.Acce func createODSFile(t testing.TB, eds *rsmt2d.ExtendedDataSquare) *ODS { path := t.TempDir() + "/" + strconv.Itoa(rand.Intn(1000)) - roots, err := share.NewAxisRoots(eds) + roots, err := square.NewAxisRoots(eds) require.NoError(t, err) err = CreateODS(path, roots, eds) require.NoError(t, err) diff --git a/store/file/q4.go b/store/file/q4.go index 7025f8adb3..9bb29599fc 100644 --- a/store/file/q4.go +++ b/store/file/q4.go @@ -9,7 +9,7 @@ import ( "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/share/eds" + "github.com/celestiaorg/celestia-node/square/eds" ) // q4 stores the fourth quadrant of the square. diff --git a/store/file/square.go b/store/file/square.go index c1a432e3a8..a12cf41c03 100644 --- a/store/file/square.go +++ b/store/file/square.go @@ -6,47 +6,47 @@ import ( "golang.org/x/sync/errgroup" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/eds" + "github.com/celestiaorg/celestia-node/square/eds" ) -type square [][]share.Share +type dataSquare [][]share.Share // readSquare reads Shares from the reader and returns a square. It assumes that the reader is // positioned at the beginning of the Shares. It knows the size of the Shares and the size of the // square, so reads from reader are limited to exactly the amount of data required. -func readSquare(r io.Reader, shareSize, edsSize int) (square, error) { +func readSquare(r io.Reader, shareSize, edsSize int) (dataSquare, error) { odsLn := edsSize / 2 shares, err := eds.ReadShares(r, shareSize, odsLn) if err != nil { return nil, fmt.Errorf("reading shares: %w", err) } - square := make(square, odsLn) + square := make(dataSquare, odsLn) for i := range square { square[i] = shares[i*odsLn : (i+1)*odsLn] } return square, nil } -func (s square) reader() (io.Reader, error) { +func (s dataSquare) reader() (io.Reader, error) { if s == nil { return nil, fmt.Errorf("ods file not cached") } getShare := func(rowIdx, colIdx int) ([]byte, error) { - return s[rowIdx][colIdx], nil + return s[rowIdx][colIdx].ToBytes(), nil } reader := eds.NewShareReader(s.size(), getShare) return reader, nil } -func (s square) size() int { +func (s dataSquare) size() int { return len(s) } -func (s square) shares() ([]share.Share, error) { +func (s dataSquare) shares() ([]share.Share, error) { shares := make([]share.Share, 0, s.size()*s.size()) for _, row := range s { shares = append(shares, row...) @@ -54,7 +54,7 @@ func (s square) shares() ([]share.Share, error) { return shares, nil } -func (s square) axisHalf(axisType rsmt2d.Axis, axisIdx int) (eds.AxisHalf, error) { +func (s dataSquare) axisHalf(axisType rsmt2d.Axis, axisIdx int) (eds.AxisHalf, error) { if s == nil { return eds.AxisHalf{}, fmt.Errorf("square is nil") } @@ -83,7 +83,7 @@ func (s square) axisHalf(axisType rsmt2d.Axis, axisIdx int) (eds.AxisHalf, error }, nil } -func (s square) computeAxisHalf( +func (s dataSquare) computeAxisHalf( axisType rsmt2d.Axis, axisIdx int, ) (eds.AxisHalf, error) { @@ -106,9 +106,9 @@ func (s square) computeAxisHalf( shards := make([][]byte, s.size()*2) if half.IsParity { - copy(shards[s.size():], half.Shares) + copy(shards[s.size():], share.ToBytes(half.Shares)) } else { - copy(shards, half.Shares) + copy(shards, share.ToBytes(half.Shares)) } target := make([]bool, s.size()*2) @@ -119,7 +119,11 @@ func (s square) computeAxisHalf( return fmt.Errorf("reconstruct some: %w", err) } - shares[i] = shards[axisIdx] + shard, err := share.NewShare(shards[axisIdx]) + if err != nil { + return fmt.Errorf("creating share: %w", err) + } + shares[i] = *shard return nil }) } diff --git a/store/getter.go b/store/getter.go index 7a78aa8fc5..e436aa0489 100644 --- a/store/getter.go +++ b/store/getter.go @@ -5,13 +5,13 @@ import ( "errors" "fmt" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" "github.com/celestiaorg/celestia-node/header" "github.com/celestiaorg/celestia-node/libs/utils" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/eds" - "github.com/celestiaorg/celestia-node/share/shwap" + "github.com/celestiaorg/celestia-node/square/eds" + "github.com/celestiaorg/celestia-node/square/shwap" ) var _ shwap.Getter = (*Getter)(nil) @@ -28,9 +28,9 @@ func (g *Getter) GetShare(ctx context.Context, h *header.ExtendedHeader, row, co acc, err := g.store.GetByHeight(ctx, h.Height()) if err != nil { if errors.Is(err, ErrNotFound) { - return nil, shwap.ErrNotFound + return share.Share{}, shwap.ErrNotFound } - return nil, fmt.Errorf("get accessor from store:%w", err) + return share.Share{}, fmt.Errorf("get accessor from store:%w", err) } logger := log.With( "height", h.Height(), @@ -41,7 +41,7 @@ func (g *Getter) GetShare(ctx context.Context, h *header.ExtendedHeader, row, co sample, err := acc.Sample(ctx, row, col) if err != nil { - return nil, fmt.Errorf("get sample from accessor:%w", err) + return share.Share{}, fmt.Errorf("get sample from accessor:%w", err) } return sample.Share, nil } diff --git a/store/getter_test.go b/store/getter_test.go index 9e2b06feda..5693e2cc57 100644 --- a/store/getter_test.go +++ b/store/getter_test.go @@ -7,10 +7,11 @@ import ( "github.com/stretchr/testify/require" + "github.com/celestiaorg/go-square/v2/share" + "github.com/celestiaorg/celestia-node/header/headertest" - "github.com/celestiaorg/celestia-node/share/eds/edstest" - "github.com/celestiaorg/celestia-node/share/sharetest" - "github.com/celestiaorg/celestia-node/share/shwap" + "github.com/celestiaorg/celestia-node/square/eds/edstest" + "github.com/celestiaorg/celestia-node/square/shwap" ) func TestStoreGetter(t *testing.T) { @@ -37,7 +38,7 @@ func TestStoreGetter(t *testing.T) { for j := 0; j < squareSize; j++ { share, err := sg.GetShare(ctx, eh, i, j) require.NoError(t, err) - require.Equal(t, eds.GetCell(uint(i), uint(j)), share) + require.Equal(t, eds.GetCell(uint(i), uint(j)), share.ToBytes()) } } @@ -66,7 +67,7 @@ func TestStoreGetter(t *testing.T) { }) t.Run("GetSharesByNamespace", func(t *testing.T) { - ns := sharetest.RandV0Namespace() + ns := share.RandomNamespace() eds, roots := edstest.RandEDSWithNamespace(t, ns, 8, 16) eh := headertest.RandExtendedHeaderWithRoot(t, roots) height := height.Add(1) @@ -79,7 +80,7 @@ func TestStoreGetter(t *testing.T) { require.NoError(t, shares.Verify(eh.DAH, ns)) // namespace not found - randNamespace := sharetest.RandV0Namespace() + randNamespace := share.RandomNamespace() emptyShares, err := sg.GetSharesByNamespace(ctx, eh, randNamespace) require.NoError(t, err) require.Empty(t, emptyShares.Flatten()) diff --git a/store/store.go b/store/store.go index 554337275e..f9fabe7c67 100644 --- a/store/store.go +++ b/store/store.go @@ -14,8 +14,8 @@ import ( "github.com/celestiaorg/rsmt2d" "github.com/celestiaorg/celestia-node/libs/utils" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/eds" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/eds" "github.com/celestiaorg/celestia-node/store/cache" "github.com/celestiaorg/celestia-node/store/file" ) @@ -92,7 +92,7 @@ func (s *Store) Stop(context.Context) error { func (s *Store) PutODSQ4( ctx context.Context, - roots *share.AxisRoots, + roots *square.AxisRoots, height uint64, square *rsmt2d.ExtendedDataSquare, ) error { @@ -101,7 +101,7 @@ func (s *Store) PutODSQ4( func (s *Store) PutODS( ctx context.Context, - roots *share.AxisRoots, + roots *square.AxisRoots, height uint64, square *rsmt2d.ExtendedDataSquare, ) error { @@ -110,12 +110,12 @@ func (s *Store) PutODS( func (s *Store) put( ctx context.Context, - roots *share.AxisRoots, + roots *square.AxisRoots, height uint64, - square *rsmt2d.ExtendedDataSquare, + dataSquare *rsmt2d.ExtendedDataSquare, writeQ4 bool, ) error { - datahash := share.DataHash(roots.Hash()) + datahash := square.DataHash(roots.Hash()) // we don't need to store empty EDS, just link the height to the empty file if datahash.IsEmptyEDS() { lock := s.stripLock.byHeight(height) @@ -129,7 +129,7 @@ func (s *Store) put( } // put to cache before writing to make it accessible while write is happening - accessor := &eds.Rsmt2D{ExtendedDataSquare: square} + accessor := &eds.Rsmt2D{ExtendedDataSquare: dataSquare} acc, err := s.cache.GetOrLoad(ctx, height, accessorLoader(accessor)) if err != nil { log.Warnf("failed to put Accessor in the recent cache: %s", err) @@ -145,9 +145,9 @@ func (s *Store) put( var exists bool if writeQ4 { - exists, err = s.createODSQ4File(square, roots, height) + exists, err = s.createODSQ4File(dataSquare, roots, height) } else { - exists, err = s.createODSFile(square, roots, height) + exists, err = s.createODSFile(dataSquare, roots, height) } if exists { @@ -155,17 +155,17 @@ func (s *Store) put( return nil } if err != nil { - s.metrics.observePut(ctx, time.Since(tNow), square.Width(), writeQ4, true) + s.metrics.observePut(ctx, time.Since(tNow), dataSquare.Width(), writeQ4, true) return fmt.Errorf("creating file: %w", err) } - s.metrics.observePut(ctx, time.Since(tNow), square.Width(), writeQ4, false) + s.metrics.observePut(ctx, time.Since(tNow), dataSquare.Width(), writeQ4, false) return nil } func (s *Store) createODSQ4File( square *rsmt2d.ExtendedDataSquare, - roots *share.AxisRoots, + roots *square.AxisRoots, height uint64, ) (bool, error) { pathODS := s.hashToPath(roots.Hash(), odsFileExt) @@ -231,7 +231,7 @@ func (s *Store) validateAndRecoverODSQ4( func (s *Store) createODSFile( square *rsmt2d.ExtendedDataSquare, - roots *share.AxisRoots, + roots *square.AxisRoots, height uint64, ) (bool, error) { pathODS := s.hashToPath(roots.Hash(), odsFileExt) @@ -311,15 +311,15 @@ func (s *Store) linkHeight(datahash share.DataHash, height uint64) error { // It overrides existing empty file to ensure disk format is always consistent with the canonical // in-mem representation. func (s *Store) populateEmptyFile() error { - pathOds := s.hashToPath(share.EmptyEDSDataHash(), odsFileExt) - pathQ4 := s.hashToPath(share.EmptyEDSDataHash(), q4FileExt) + pathOds := s.hashToPath(square.EmptyEDSDataHash(), odsFileExt) + pathQ4 := s.hashToPath(square.EmptyEDSDataHash(), q4FileExt) err := errors.Join(remove(pathOds), remove(pathQ4)) if err != nil { return fmt.Errorf("cleaning old empty EDS file: %w", err) } - err = file.CreateODSQ4(pathOds, pathQ4, share.EmptyEDSRoots(), eds.EmptyAccessor.ExtendedDataSquare) + err = file.CreateODSQ4(pathOds, pathQ4, square.EmptyEDSRoots(), eds.EmptyAccessor.ExtendedDataSquare) if err != nil { return fmt.Errorf("creating fresh empty EDS file: %w", err) } @@ -327,7 +327,7 @@ func (s *Store) populateEmptyFile() error { return nil } -func (s *Store) GetByHash(ctx context.Context, datahash share.DataHash) (eds.AccessorStreamer, error) { +func (s *Store) GetByHash(ctx context.Context, datahash square.DataHash) (eds.AccessorStreamer, error) { if datahash.IsEmptyEDS() { return eds.EmptyAccessor, nil } @@ -341,7 +341,7 @@ func (s *Store) GetByHash(ctx context.Context, datahash share.DataHash) (eds.Acc return f, err } -func (s *Store) getByHash(ctx context.Context, datahash share.DataHash) (eds.AccessorStreamer, error) { +func (s *Store) getByHash(ctx context.Context, datahash square.DataHash) (eds.AccessorStreamer, error) { path := s.hashToPath(datahash, odsFileExt) return s.openAccessor(ctx, path) } @@ -390,7 +390,7 @@ func (s *Store) openAccessor(ctx context.Context, path string) (eds.AccessorStre return wrapAccessor(odsQ4), nil } -func (s *Store) HasByHash(ctx context.Context, datahash share.DataHash) (bool, error) { +func (s *Store) HasByHash(ctx context.Context, datahash square.DataHash) (bool, error) { if datahash.IsEmptyEDS() { return true, nil } @@ -405,7 +405,7 @@ func (s *Store) HasByHash(ctx context.Context, datahash share.DataHash) (bool, e return exist, err } -func (s *Store) hasByHash(datahash share.DataHash) (bool, error) { +func (s *Store) hasByHash(datahash square.DataHash) (bool, error) { // For now, we assume that if ODS exists, the Q4 exists as well. path := s.hashToPath(datahash, odsFileExt) return exists(path) @@ -432,7 +432,7 @@ func (s *Store) hasByHeight(height uint64) (bool, error) { return exists(pathODS) } -func (s *Store) RemoveODSQ4(ctx context.Context, height uint64, datahash share.DataHash) error { +func (s *Store) RemoveODSQ4(ctx context.Context, height uint64, datahash square.DataHash) error { lock := s.stripLock.byHashAndHeight(datahash, height) lock.lock() defer lock.unlock() @@ -443,7 +443,7 @@ func (s *Store) RemoveODSQ4(ctx context.Context, height uint64, datahash share.D return err } -func (s *Store) removeODSQ4(height uint64, datahash share.DataHash) error { +func (s *Store) removeODSQ4(height uint64, datahash square.DataHash) error { if err := s.removeODS(height, datahash); err != nil { return fmt.Errorf("removing ODS: %w", err) } @@ -453,7 +453,7 @@ func (s *Store) removeODSQ4(height uint64, datahash share.DataHash) error { return nil } -func (s *Store) removeODS(height uint64, datahash share.DataHash) error { +func (s *Store) removeODS(height uint64, datahash square.DataHash) error { if err := s.cache.Remove(height); err != nil { return fmt.Errorf("removing from cache: %w", err) } @@ -475,7 +475,7 @@ func (s *Store) removeODS(height uint64, datahash share.DataHash) error { return nil } -func (s *Store) RemoveQ4(ctx context.Context, height uint64, datahash share.DataHash) error { +func (s *Store) RemoveQ4(ctx context.Context, height uint64, datahash square.DataHash) error { lock := s.stripLock.byHashAndHeight(datahash, height) lock.lock() defer lock.unlock() @@ -486,7 +486,7 @@ func (s *Store) RemoveQ4(ctx context.Context, height uint64, datahash share.Data return err } -func (s *Store) removeQ4(height uint64, datahash share.DataHash) error { +func (s *Store) removeQ4(height uint64, datahash square.DataHash) error { // if datahash is empty, we don't need to remove the Q4 file if datahash.IsEmptyEDS() { return nil @@ -504,7 +504,7 @@ func (s *Store) removeQ4(height uint64, datahash share.DataHash) error { return nil } -func (s *Store) hashToPath(datahash share.DataHash, ext string) string { +func (s *Store) hashToPath(datahash square.DataHash, ext string) string { return filepath.Join(s.basepath, blocksPath, datahash.String()) + ext } diff --git a/store/store_cache.go b/store/store_cache.go index 9e552312fd..a9d5e4882d 100644 --- a/store/store_cache.go +++ b/store/store_cache.go @@ -4,7 +4,7 @@ import ( "context" "fmt" - "github.com/celestiaorg/celestia-node/share/eds" + "github.com/celestiaorg/celestia-node/square/eds" "github.com/celestiaorg/celestia-node/store/cache" ) diff --git a/store/store_test.go b/store/store_test.go index f3b4a0d5f2..45c9bcdede 100644 --- a/store/store_test.go +++ b/store/store_test.go @@ -10,10 +10,11 @@ import ( "github.com/stretchr/testify/require" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/eds/edstest" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/eds/edstest" "github.com/celestiaorg/celestia-node/store/cache" "github.com/celestiaorg/celestia-node/store/file" ) @@ -117,154 +118,160 @@ func TestEDSStore(t *testing.T) { f, err := edsStore.cache.Get(height) require.NoError(t, err) require.NoError(t, f.Close()) - // check that cached file is the same eds fromFile, err := f.Shares(ctx) require.NoError(t, err) require.NoError(t, f.Close()) expected := eds.FlattenedODS() - require.Equal(t, expected, fromFile) + require.Equal(t, expected, share.ToBytes(fromFile)) }) - t.Run("Second Put should be noop", func(t *testing.T) { - dir := t.TempDir() - edsStore, err := NewStore(paramsNoCache(), dir) - require.NoError(t, err) + // check that cached file is the same eds + fromFile, err := f.Shares(ctx) + require.NoError(t, err) + require.NoError(t, f.Close()) + expected := eds.FlattenedODS() + require.Equal(t, expected, fromFile) + }) - eds, roots := test.newEds(t) - height := height.Add(1) + t.Run("Second Put should be noop", func(t *testing.T) { + dir := t.TempDir() + edsStore, err := NewStore(paramsNoCache(), dir) + require.NoError(t, err) - err = test.putFn(edsStore)(ctx, roots, height, eds) - require.NoError(t, err) - // ensure correct amount of files and links are written - ensureAmountFileAndLinks(t, dir, test.addedFiles, test.addedLinks) + eds, roots := test.newEds(t) + height := height.Add(1) - err = test.putFn(edsStore)(ctx, roots, height, eds) - require.NoError(t, err) + err = test.putFn(edsStore)(ctx, roots, height, eds) + require.NoError(t, err) + // ensure correct amount of files and links are written + ensureAmountFileAndLinks(t, dir, test.addedFiles, test.addedLinks) - // ensure no new files or links are written - ensureAmountFileAndLinks(t, dir, test.addedFiles, test.addedLinks) - }) + err = test.putFn(edsStore)(ctx, roots, height, eds) + require.NoError(t, err) - t.Run("Second Put after partial write", func(t *testing.T) { - dir := t.TempDir() - edsStore, err := NewStore(paramsNoCache(), dir) - require.NoError(t, err) + // ensure no new files or links are written + ensureAmountFileAndLinks(t, dir, test.addedFiles, test.addedLinks) + }) - eds, roots := test.newEds(t) - height := height.Add(1) + t.Run("Second Put after partial write", func(t *testing.T) { + dir := t.TempDir() + edsStore, err := NewStore(paramsNoCache(), dir) + require.NoError(t, err) - err = test.putFn(edsStore)(ctx, roots, height, eds) - require.NoError(t, err) - // remove link - pathLink := edsStore.heightToPath(height, odsFileExt) - err = remove(pathLink) - require.NoError(t, err) - ensureAmountLinks(t, dir, 0) + eds, roots := test.newEds(t) + height := height.Add(1) - // put should write the missing link - err = test.putFn(edsStore)(ctx, roots, height, eds) - require.NoError(t, err) - ensureAmountLinks(t, dir, test.addedLinks) - }) + err = test.putFn(edsStore)(ctx, roots, height, eds) + require.NoError(t, err) + // remove link + pathLink := edsStore.heightToPath(height, odsFileExt) + err = remove(pathLink) + require.NoError(t, err) + ensureAmountLinks(t, dir, 0) - t.Run("RemoveODSQ4", func(t *testing.T) { - dir := t.TempDir() - edsStore, err := NewStore(DefaultParameters(), dir) - require.NoError(t, err) + // put should write the missing link + err = test.putFn(edsStore)(ctx, roots, height, eds) + require.NoError(t, err) + ensureAmountLinks(t, dir, test.addedLinks) + }) - eds, roots := test.newEds(t) - height := height.Add(1) - err = test.putFn(edsStore)(ctx, roots, height, eds) - require.NoError(t, err) - ensureAmountFileAndLinks(t, dir, test.addedFiles, test.addedLinks) + t.Run("RemoveODSQ4", func(t *testing.T) { + dir := t.TempDir() + edsStore, err := NewStore(DefaultParameters(), dir) + require.NoError(t, err) - hash := share.DataHash(roots.Hash()) - err = edsStore.RemoveODSQ4(ctx, height, hash) - require.NoError(t, err) + eds, roots := test.newEds(t) + height := height.Add(1) + err = test.putFn(edsStore)(ctx, roots, height, eds) + require.NoError(t, err) + ensureAmountFileAndLinks(t, dir, test.addedFiles, test.addedLinks) - // file should be removed from cache - _, err = edsStore.cache.Get(height) - require.ErrorIs(t, err, cache.ErrCacheMiss) + hash := share.DataHash(roots.Hash()) + err = edsStore.RemoveODSQ4(ctx, height, hash) + require.NoError(t, err) - // empty file should be accessible by hash, non-empty file should not - hasByHash := hash.IsEmptyEDS() - // all files should not be accessible by height - hasByHashAndHeight(t, edsStore, ctx, hash, height, hasByHash, false) + // file should be removed from cache + _, err = edsStore.cache.Get(height) + require.ErrorIs(t, err, cache.ErrCacheMiss) - // ensure all files and links are removed - ensureAmountFileAndLinks(t, dir, 0, 0) - }) + // empty file should be accessible by hash, non-empty file should not + hasByHash := hash.IsEmptyEDS() + // all files should not be accessible by height + hasByHashAndHeight(t, edsStore, ctx, hash, height, hasByHash, false) - t.Run("RemoveQ4", func(t *testing.T) { - dir := t.TempDir() - edsStore, err := NewStore(DefaultParameters(), dir) - require.NoError(t, err) + // ensure all files and links are removed + ensureAmountFileAndLinks(t, dir, 0, 0) + }) - eds, roots := test.newEds(t) - height := height.Add(1) - err = test.putFn(edsStore)(ctx, roots, height, eds) - require.NoError(t, err) - ensureAmountFileAndLinks(t, dir, test.addedFiles, test.addedLinks) + t.Run("RemoveQ4", func(t *testing.T) { + dir := t.TempDir() + edsStore, err := NewStore(DefaultParameters(), dir) + require.NoError(t, err) - hash := share.DataHash(roots.Hash()) - err = edsStore.RemoveQ4(ctx, height, hash) - require.NoError(t, err) + eds, roots := test.newEds(t) + height := height.Add(1) + err = test.putFn(edsStore)(ctx, roots, height, eds) + require.NoError(t, err) + ensureAmountFileAndLinks(t, dir, test.addedFiles, test.addedLinks) - // file should be removed from cache - _, err = edsStore.cache.Get(height) - require.ErrorIs(t, err, cache.ErrCacheMiss) + hash := share.DataHash(roots.Hash()) + err = edsStore.RemoveQ4(ctx, height, hash) + require.NoError(t, err) - // ods file should still be accessible by hash and height - hasByHashAndHeight(t, edsStore, ctx, hash, height, true, true) + // file should be removed from cache + _, err = edsStore.cache.Get(height) + require.ErrorIs(t, err, cache.ErrCacheMiss) - // ensure ods file and link are not removed - ensureAmountFileAndLinks(t, dir, test.filesAfterRemoveQ4, test.addedLinks) - }) + // ods file should still be accessible by hash and height + hasByHashAndHeight(t, edsStore, ctx, hash, height, true, true) - t.Run("GetByHeight", func(t *testing.T) { - dir := t.TempDir() - edsStore, err := NewStore(DefaultParameters(), dir) - require.NoError(t, err) + // ensure ods file and link are not removed + ensureAmountFileAndLinks(t, dir, test.filesAfterRemoveQ4, test.addedLinks) + }) - eds, roots := test.newEds(t) - height := height.Add(1) - err = test.putFn(edsStore)(ctx, roots, height, eds) - require.NoError(t, err) - ensureAmountFileAndLinks(t, dir, test.addedFiles, test.addedLinks) + t.Run("GetByHeight", func(t *testing.T) { + dir := t.TempDir() + edsStore, err := NewStore(DefaultParameters(), dir) + require.NoError(t, err) - f, err := edsStore.GetByHeight(ctx, height) - require.NoError(t, err) + eds, roots := test.newEds(t) + height := height.Add(1) + err = test.putFn(edsStore)(ctx, roots, height, eds) + require.NoError(t, err) + ensureAmountFileAndLinks(t, dir, test.addedFiles, test.addedLinks) - // check that file is the same eds - fromFile, err := f.Shares(ctx) - require.NoError(t, err) - require.NoError(t, f.Close()) - expected := eds.FlattenedODS() - require.Equal(t, expected, fromFile) - }) + f, err := edsStore.GetByHeight(ctx, height) + require.NoError(t, err) - t.Run("GetByHash", func(t *testing.T) { - dir := t.TempDir() - edsStore, err := NewStore(DefaultParameters(), dir) - require.NoError(t, err) + // check that file is the same eds + fromFile, err := f.Shares(ctx) + require.NoError(t, err) + require.NoError(t, f.Close()) + expected := eds.FlattenedODS() + require.Equal(t, expected, fromFile) + }) - eds, roots := test.newEds(t) - height := height.Add(1) - err = test.putFn(edsStore)(ctx, roots, height, eds) - require.NoError(t, err) - ensureAmountFileAndLinks(t, dir, test.addedFiles, test.addedLinks) + t.Run("GetByHash", func(t *testing.T) { + dir := t.TempDir() + edsStore, err := NewStore(DefaultParameters(), dir) + require.NoError(t, err) - f, err := edsStore.GetByHash(ctx, roots.Hash()) - require.NoError(t, err) + eds, roots := test.newEds(t) + height := height.Add(1) + err = test.putFn(edsStore)(ctx, roots, height, eds) + require.NoError(t, err) + ensureAmountFileAndLinks(t, dir, test.addedFiles, test.addedLinks) - // check that cached file is the same eds - fromFile, err := f.Shares(ctx) - require.NoError(t, err) - require.NoError(t, f.Close()) - expected := eds.FlattenedODS() - require.Equal(t, expected, fromFile) - }) + f, err := edsStore.GetByHash(ctx, roots.Hash()) + require.NoError(t, err) + + // check that cached file is the same eds + fromFile, err := f.Shares(ctx) + require.NoError(t, err) + require.NoError(t, f.Close()) + expected := eds.FlattenedODS() + require.Equal(t, expected, fromFile) }) } @@ -419,7 +426,7 @@ func BenchmarkStore(b *testing.B) { b.Cleanup(cancel) eds := edstest.RandEDS(b, 128) - roots, err := share.NewAxisRoots(eds) + roots, err := square.NewAxisRoots(eds) require.NoError(b, err) // BenchmarkStore/put_128-16 186 6623266 ns/op @@ -470,9 +477,9 @@ func BenchmarkStore(b *testing.B) { }) } -func randomEDS(t testing.TB) (*rsmt2d.ExtendedDataSquare, *share.AxisRoots) { +func randomEDS(t testing.TB) (*rsmt2d.ExtendedDataSquare, *square.AxisRoots) { eds := edstest.RandEDS(t, 4) - roots, err := share.NewAxisRoots(eds) + roots, err := square.NewAxisRoots(eds) require.NoError(t, err) return eds, roots @@ -505,7 +512,7 @@ func hasByHashAndHeight( t testing.TB, store *Store, ctx context.Context, - hash share.DataHash, + hash square.DataHash, height uint64, hasByHash, hasByHeight bool, ) { diff --git a/store/striplock.go b/store/striplock.go index 4738453c77..eb23facab2 100644 --- a/store/striplock.go +++ b/store/striplock.go @@ -3,7 +3,7 @@ package store import ( "sync" - "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/square" ) // TODO: move to utils @@ -31,14 +31,14 @@ func (l *striplock) byHeight(height uint64) *sync.RWMutex { return l.heights[lkIdx] } -func (l *striplock) byHash(datahash share.DataHash) *sync.RWMutex { +func (l *striplock) byHash(datahash square.DataHash) *sync.RWMutex { // Use the last 2 bytes of the hash as key to distribute the locks last := uint16(datahash[len(datahash)-1]) | uint16(datahash[len(datahash)-2])<<8 lkIdx := last % uint16(len(l.datahashes)) return l.datahashes[lkIdx] } -func (l *striplock) byHashAndHeight(datahash share.DataHash, height uint64) *multiLock { +func (l *striplock) byHashAndHeight(datahash square.DataHash, height uint64) *multiLock { return &multiLock{[]*sync.RWMutex{l.byHash(datahash), l.byHeight(height)}} } From be1add2dcc9c301f3ecec01b5aeb1cebbe3b08fd Mon Sep 17 00:00:00 2001 From: vgonkivs Date: Fri, 4 Oct 2024 13:12:29 +0300 Subject: [PATCH 02/21] fixes --- blob/blob.go | 7 +++++-- blob/service.go | 11 +++++++++-- nodebuilder/state/mocks/api.go | 4 ++-- nodebuilder/state/state.go | 8 +++++--- nodebuilder/state/stub.go | 4 +++- nodebuilder/tests/nd_test.go | 1 - nodebuilder/tests/prune_test.go | 3 ++- square/shwap/row_namespace_data.go | 2 +- state/core_access.go | 3 ++- state/state.go | 5 ----- 10 files changed, 29 insertions(+), 19 deletions(-) diff --git a/blob/blob.go b/blob/blob.go index 6f4029c0b4..d2c41fae6a 100644 --- a/blob/blob.go +++ b/blob/blob.go @@ -86,11 +86,14 @@ func NewBlob(shareVersion uint8, namespace share.Namespace, data, signer []byte) return nil, fmt.Errorf("blob data must be > 0 && <= %d, but it was %d bytes", appconsts.DefaultMaxBytes, len(data)) } - if err := share.ValidateUserNamespace(namespace.Version(), namespace.ID()); err != nil { + if err := share.ValidateForData(namespace); err != nil { return nil, fmt.Errorf("invalid user namespace: %w", err) } if !namespace.IsUsableNamespace() { - return nil, fmt.Errorf("namespace %s is not usable", namespace.ID()) // rename + return nil, fmt.Errorf("parity of tail padding namespaces %s are not allowed", namespace.ID()) + } + if namespace.IsReserved() { + return nil, fmt.Errorf("reserved namespace %s is not allowed", namespace.ID()) } squareBlob, err := share.NewBlob(namespace, data, shareVersion, signer) diff --git a/blob/service.go b/blob/service.go index f40114b8c8..f95091d9d2 100644 --- a/blob/service.go +++ b/blob/service.go @@ -45,7 +45,7 @@ type SubmitOptions = state.TxConfig // avoid a circular dependency between the blob and the state package, since the state package needs // the blob.Blob type for this signature. type Submitter interface { - SubmitPayForBlob(context.Context, []*state.Blob, *state.TxConfig) (*types.TxResponse, error) + SubmitPayForBlob(context.Context, []*share.Blob, *state.TxConfig) (*types.TxResponse, error) } type Service struct { @@ -171,9 +171,16 @@ func (s *Service) Submit(ctx context.Context, blobs []*Blob, txConfig *SubmitOpt squareBlobs := make([]*share.Blob, len(blobs)) for i := range blobs { - if err := share.ValidateForData(blobs[i].Namespace()); err != nil { + namespace := blobs[i].Namespace() + if err := share.ValidateForData(namespace); err != nil { return 0, err } + if !blobs[i].Namespace().IsUsableNamespace() { + return 0, fmt.Errorf("parity of tail padding namespaces %s are not allowed", namespace.ID()) + } + if blobs[i].Namespace().IsReserved() { + return 0, fmt.Errorf("reserved namespace %s is not allowed", namespace.ID()) + } squareBlobs[i] = blobs[i].Blob } diff --git a/nodebuilder/state/mocks/api.go b/nodebuilder/state/mocks/api.go index 6b75b48a52..59ba400b5e 100644 --- a/nodebuilder/state/mocks/api.go +++ b/nodebuilder/state/mocks/api.go @@ -10,7 +10,7 @@ import ( math "cosmossdk.io/math" state "github.com/celestiaorg/celestia-node/state" - blob "github.com/celestiaorg/go-square/blob" + share "github.com/celestiaorg/go-square/v2/share" types "github.com/cosmos/cosmos-sdk/types" types0 "github.com/cosmos/cosmos-sdk/x/staking/types" gomock "github.com/golang/mock/gomock" @@ -205,7 +205,7 @@ func (mr *MockModuleMockRecorder) RevokeGrantFee(arg0, arg1, arg2 interface{}) * } // SubmitPayForBlob mocks base method. -func (m *MockModule) SubmitPayForBlob(arg0 context.Context, arg1 []*blob.Blob, arg2 *state.TxConfig) (*types.TxResponse, error) { +func (m *MockModule) SubmitPayForBlob(arg0 context.Context, arg1 []*share.Blob, arg2 *state.TxConfig) (*types.TxResponse, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "SubmitPayForBlob", arg0, arg1, arg2) ret0, _ := ret[0].(*types.TxResponse) diff --git a/nodebuilder/state/state.go b/nodebuilder/state/state.go index 829ad55609..7fe2073f8b 100644 --- a/nodebuilder/state/state.go +++ b/nodebuilder/state/state.go @@ -5,6 +5,8 @@ import ( "github.com/cosmos/cosmos-sdk/x/staking/types" + "github.com/celestiaorg/go-square/v2/share" + "github.com/celestiaorg/celestia-node/state" ) @@ -37,7 +39,7 @@ type Module interface { // SubmitPayForBlob builds, signs and submits a PayForBlob transaction. SubmitPayForBlob( ctx context.Context, - blobs []*state.Blob, + blobs []*share.Blob, config *state.TxConfig, ) (*state.TxResponse, error) // CancelUnbondingDelegation cancels a user's pending undelegation from a validator. @@ -112,7 +114,7 @@ type API struct { ) (*state.TxResponse, error) `perm:"write"` SubmitPayForBlob func( ctx context.Context, - blobs []*state.Blob, + blobs []*share.Blob, config *state.TxConfig, ) (*state.TxResponse, error) `perm:"write"` CancelUnbondingDelegation func( @@ -186,7 +188,7 @@ func (api *API) Transfer( func (api *API) SubmitPayForBlob( ctx context.Context, - blobs []*state.Blob, + blobs []*share.Blob, config *state.TxConfig, ) (*state.TxResponse, error) { return api.Internal.SubmitPayForBlob(ctx, blobs, config) diff --git a/nodebuilder/state/stub.go b/nodebuilder/state/stub.go index c08919fd28..bd26068a52 100644 --- a/nodebuilder/state/stub.go +++ b/nodebuilder/state/stub.go @@ -6,6 +6,8 @@ import ( "github.com/cosmos/cosmos-sdk/x/staking/types" + "github.com/celestiaorg/go-square/v2/share" + "github.com/celestiaorg/celestia-node/state" ) @@ -42,7 +44,7 @@ func (s stubbedStateModule) Transfer( func (s stubbedStateModule) SubmitPayForBlob( context.Context, - []*state.Blob, + []*share.Blob, *state.TxConfig, ) (*state.TxResponse, error) { return nil, ErrNoStateAccess diff --git a/nodebuilder/tests/nd_test.go b/nodebuilder/tests/nd_test.go index 7b295511a6..a7c6e35ffa 100644 --- a/nodebuilder/tests/nd_test.go +++ b/nodebuilder/tests/nd_test.go @@ -4,7 +4,6 @@ package tests import ( "context" - "testing" "time" diff --git a/nodebuilder/tests/prune_test.go b/nodebuilder/tests/prune_test.go index 8edf6fae1b..14b26a219d 100644 --- a/nodebuilder/tests/prune_test.go +++ b/nodebuilder/tests/prune_test.go @@ -5,7 +5,6 @@ package tests import ( "bytes" "context" - "github.com/celestiaorg/go-square/v2/share" "testing" "time" @@ -14,6 +13,8 @@ import ( "github.com/stretchr/testify/require" "go.uber.org/fx" + "github.com/celestiaorg/go-square/v2/share" + "github.com/celestiaorg/celestia-node/blob" "github.com/celestiaorg/celestia-node/libs/fxutil" "github.com/celestiaorg/celestia-node/nodebuilder" diff --git a/square/shwap/row_namespace_data.go b/square/shwap/row_namespace_data.go index e658856fd9..761652ebff 100644 --- a/square/shwap/row_namespace_data.go +++ b/square/shwap/row_namespace_data.go @@ -180,7 +180,7 @@ func (rnd RowNamespaceData) verifyInclusion(rowRoot []byte, namespace share.Name namespaceBytes := sh.Namespace().Bytes() leave := make([]byte, len(sh.ToBytes())+len(namespaceBytes)) copy(leave, namespaceBytes) - copy(leave[len(namespaceBytes):], sh.ToBytes()) // rework + copy(leave[len(namespaceBytes):], sh.ToBytes()) leaves = append(leaves, leave) } diff --git a/state/core_access.go b/state/core_access.go index f36798c261..c768a89c9d 100644 --- a/state/core_access.go +++ b/state/core_access.go @@ -27,6 +27,7 @@ import ( apperrors "github.com/celestiaorg/celestia-app/v3/app/errors" "github.com/celestiaorg/celestia-app/v3/pkg/user" libhead "github.com/celestiaorg/go-header" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/celestia-node/header" ) @@ -200,7 +201,7 @@ func (ca *CoreAccessor) cancelCtx() { // TxResponse. The user can specify additional options that can bee applied to the Tx. func (ca *CoreAccessor) SubmitPayForBlob( ctx context.Context, - appblobs []*Blob, + appblobs []*share.Blob, cfg *TxConfig, ) (*TxResponse, error) { if len(appblobs) == 0 { diff --git a/state/state.go b/state/state.go index bb423bba34..d55bb6901c 100644 --- a/state/state.go +++ b/state/state.go @@ -7,8 +7,6 @@ import ( "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" coretypes "github.com/tendermint/tendermint/types" - - "github.com/celestiaorg/go-square/v2/share" ) // Balance is an alias to the Coin type from Cosmos-SDK. @@ -26,9 +24,6 @@ type Address struct { sdk.Address } -// Blob is an alias of Blob from go-square. -type Blob = share.Blob - // ValAddress is an alias to the ValAddress type from Cosmos-SDK. type ValAddress = sdk.ValAddress From 85469bd4af740532ccfb91681e5c5dcb4f886a72 Mon Sep 17 00:00:00 2001 From: vgonkivs Date: Fri, 4 Oct 2024 13:12:46 +0300 Subject: [PATCH 03/21] bump app to v3 latest commit --- go.mod | 7 +++---- go.sum | 27 ++++++--------------------- 2 files changed, 9 insertions(+), 25 deletions(-) diff --git a/go.mod b/go.mod index 5e54b7f402..4c091a9dc0 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/BurntSushi/toml v1.4.1-0.20240526193622-a339e1f7089c github.com/alecthomas/jsonschema v0.0.0-20220216202328-9eeeec9d044b github.com/benbjohnson/clock v1.3.5 - github.com/celestiaorg/celestia-app/v3 v3.0.0 + github.com/celestiaorg/celestia-app/v3 v3.0.0-20241003134616-c713401b0f69 github.com/celestiaorg/go-fraud v0.2.1 github.com/celestiaorg/go-header v0.6.2 github.com/celestiaorg/go-libp2p-messenger v0.2.0 @@ -321,7 +321,7 @@ require ( go.uber.org/mock v0.4.0 // indirect go.uber.org/multierr v1.11.0 // indirect golang.org/x/mod v0.21.0 // indirect - golang.org/x/net v0.28.0 // indirect + golang.org/x/net v0.29.0 // indirect golang.org/x/oauth2 v0.22.0 // indirect golang.org/x/sys v0.25.0 // indirect golang.org/x/term v0.24.0 // indirect @@ -337,13 +337,12 @@ require ( gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect lukechampine.com/blake3 v1.3.0 // indirect - nhooyr.io/websocket v1.8.7 // indirect + nhooyr.io/websocket v1.8.17 // indirect rsc.io/tmplfunc v0.0.3 // indirect sigs.k8s.io/yaml v1.4.0 // indirect ) replace ( - github.com/celestiaorg/celestia-app/v3 v3.0.0 => ../celestia-app github.com/celestiaorg/go-square/v2 v2.0.0 => ../go-square github.com/cosmos/cosmos-sdk => github.com/celestiaorg/cosmos-sdk v1.24.1-sdk-v0.46.16 github.com/filecoin-project/dagstore => github.com/celestiaorg/dagstore v0.0.0-20230824094345-537c012aa403 diff --git a/go.sum b/go.sum index 2639195177..d54552c19c 100644 --- a/go.sum +++ b/go.sum @@ -345,6 +345,8 @@ github.com/c-bata/go-prompt v0.2.2/go.mod h1:VzqtzE2ksDBcdln8G7mk2RX9QyGjH+OVqOC github.com/casbin/casbin/v2 v2.1.2/go.mod h1:YcPU1XXisHhLzuxH9coDNf2FbKpjGlbCg3n9yuLkIJQ= github.com/celestiaorg/blobstream-contracts/v3 v3.1.0 h1:h1Y4V3EMQ2mFmNtWt2sIhZIuyASInj1a9ExI8xOsTOw= github.com/celestiaorg/blobstream-contracts/v3 v3.1.0/go.mod h1:x4DKyfKOSv1ZJM9NwV+Pw01kH2CD7N5zTFclXIVJ6GQ= +github.com/celestiaorg/celestia-app/v3 v3.0.0-20241003134616-c713401b0f69 h1:9myDWDouFiGMU0QY7wrIksanHNn8o7FLWDO0PwsOTAo= +github.com/celestiaorg/celestia-app/v3 v3.0.0-20241003134616-c713401b0f69/go.mod h1:OPcaIRGQ5Ke3btFSbfBeGNsh5ZXNUpLs4fcOGUFQaSo= github.com/celestiaorg/celestia-core v1.42.0-tm-v0.34.35 h1:bWy5XOgeuuSLe0Lc/htL9/QLEURBjA1JTvEko6bEBhg= github.com/celestiaorg/celestia-core v1.42.0-tm-v0.34.35/go.mod h1:/fK0n3ps09t5uErBQe1QZbrE81L81MNUzWpFyWQLDT0= github.com/celestiaorg/cosmos-sdk v1.24.1-sdk-v0.46.16 h1:SeQ7Y/CyOcUMKo7mQiexaj/pZ/xIgyuZFIwYZwpSkWE= @@ -632,11 +634,8 @@ github.com/getkin/kin-openapi v0.61.0/go.mod h1:7Yn5whZr5kJi6t+kShccXS8ae1APpYTW github.com/getsentry/sentry-go v0.27.0 h1:Pv98CIbtB3LkMWmXi4Joa5OOcwbmnX88sF5qbK3r3Ps= github.com/getsentry/sentry-go v0.27.0/go.mod h1:lc76E2QywIyW8WuBnwl8Lc4bkmQH4+w1gwTf25trprY= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= -github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= github.com/gin-gonic/gin v1.6.3/go.mod h1:75u5sXoLsGZoRN5Sgbi1eraJ4GU3++wFwWzhwvtwp4M= -github.com/gin-gonic/gin v1.7.0 h1:jGB9xAJQ12AIGNB4HguylppmDK1Am9ppF7XnGXXJuoU= -github.com/gin-gonic/gin v1.7.0/go.mod h1:jD2toBW3GZUr5UMcdrwQA10I7RuaFOl/SGeDjXkfUtY= github.com/gliderlabs/ssh v0.1.1/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0= github.com/glycerine/go-unsnap-stream v0.0.0-20180323001048-9f0cb55181dd/go.mod h1:/20jfyN9Y5QPEAprSgKAUr+glWDY39ZiUEAYOEv5dsE= github.com/glycerine/goconvey v0.0.0-20190410193231-58a59202ab31/go.mod h1:Ogl1Tioa0aV7gstGFO7KhffUsb9M4ydbEbbxpcEDc24= @@ -691,13 +690,9 @@ github.com/go-openapi/swag v0.22.3/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+ github.com/go-openapi/swag v0.22.4 h1:QLMzNJnMGPRNDCbySlcj1x01tzU8/9LTTL9hZZZogBU= github.com/go-openapi/swag v0.22.4/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+VcZ0yl14= github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= -github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8ceBS/t7Q= github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8= -github.com/go-playground/universal-translator v0.17.0 h1:icxd5fm+REJzpZx7ZfpaD876Lmtgy7VtROAbHHXk8no= github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA= github.com/go-playground/validator/v10 v10.2.0/go.mod h1:uOYAAleCW8F/7oMFd6aG0GOhaH6EGOAJShg8Id5JGkI= -github.com/go-playground/validator/v10 v10.11.2 h1:q3SHpufmypg+erIExEKUmsgmhDTyhcJ38oeKGACXohU= -github.com/go-playground/validator/v10 v10.11.2/go.mod h1:NieE624vt4SCTJtD87arVLvdmjPAeV8BQlHtMnw9D7s= github.com/go-sourcemap/sourcemap v2.1.3+incompatible/go.mod h1:F8jJfvm2KbVjc5NqelyYJmf/v5J0dwNLS2mL4sNA1Jg= github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w= github.com/go-sql-driver/mysql v1.4.1/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w= @@ -706,11 +701,8 @@ github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg78 github.com/go-task/slim-sprig/v3 v3.0.0 h1:sUs3vkvUymDpBKi3qH1YSqBQk9+9D/8M2mN1vB6EwHI= github.com/go-task/slim-sprig/v3 v3.0.0/go.mod h1:W848ghGpv3Qj3dhTPRyJypKRiqCdHZiAzKg9hl15HA8= github.com/go-yaml/yaml v2.1.0+incompatible/go.mod h1:w2MrLa16VYP0jy6N7M5kHaCkaLENm+P+Tv+MfurjSw0= -github.com/gobwas/httphead v0.0.0-20180130184737-2c6c146eadee h1:s+21KNqlpePfkah2I+gwHF8xmJWRjooY+5248k6m4A0= github.com/gobwas/httphead v0.0.0-20180130184737-2c6c146eadee/go.mod h1:L0fX3K22YWvt/FAX9NnzrNzcI4wNYi9Yku4O0LKYflo= -github.com/gobwas/pool v0.2.0 h1:QEmUOlnSjWtnpRGHF3SauEiOsy82Cup83Vf2LcMlnc8= github.com/gobwas/pool v0.2.0/go.mod h1:q8bcK0KcYlCgd9e7WYLm9LpyS+YeLd8JVDW6WezmKEw= -github.com/gobwas/ws v1.0.2 h1:CoAavW/wd/kulfZmSIBt6p24n4j7tHgNVCjsfHVNUbo= github.com/gobwas/ws v1.0.2/go.mod h1:szmBTxLgaFppYjEmNtny/v3w89xOydFnnZMcgRRu/EM= github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 h1:ZpnhV/YsD2/4cESfV5+Hoeu/iUR3ruzNvZ+yQfO03a0= github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2/go.mod h1:bBOAhwG1umN6/6ZUMtDFBMQR8jRg9O75tm9K00oMsK4= @@ -1101,7 +1093,6 @@ github.com/json-iterator/go v1.1.8/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/u github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= github.com/json-iterator/go v1.1.11/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= -github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk= @@ -1159,7 +1150,6 @@ github.com/labstack/echo/v4 v4.2.1/go.mod h1:AA49e0DZ8kk5jTOOCKNuPR6oTnBS0dYiM4F github.com/labstack/gommon v0.3.0/go.mod h1:MULnywXg0yavhxWKc+lOruYdAhDwPK9wf0OL7NoOu+k= github.com/leanovate/gopter v0.2.9 h1:fQjYxZaynp97ozCzfOyOuAGOU4aU/z37zf/tOujFk7c= github.com/leanovate/gopter v0.2.9/go.mod h1:U2L/78B+KVFIx2VmW6onHJQzXtFb+p5y3y2Sh+Jxxv8= -github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y= github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII= github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw= @@ -1390,11 +1380,9 @@ github.com/mmcloughlin/addchain v0.4.0 h1:SobOdjm2xLj1KkXN5/n0xTIWyZA2+s99UCY1iP github.com/mmcloughlin/addchain v0.4.0/go.mod h1:A86O+tHqZLMNO4w6ZZ4FlVQEadcoqkyU72HC5wJ4RlU= github.com/mmcloughlin/profile v0.1.1/go.mod h1:IhHD7q1ooxgwTgjxQYkACGA77oFTDdFVejUS1/tS/qU= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= -github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= -github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= github.com/modocache/gover v0.0.0-20171022184752-b58185e213c5/go.mod h1:caMODM3PzxT8aQXRPkAt8xlV/e7d7w8GM5g0fa5F0D8= github.com/mr-tron/base58 v1.1.0/go.mod h1:xcD2VGqlgYjBdcBLw+TuYLr8afG+Hj8g2eTVqeSzSU8= @@ -1853,12 +1841,9 @@ github.com/tyler-smith/go-bip39 v1.0.1-0.20181017060643-dbb3b84ba2ef/go.mod h1:s github.com/tyler-smith/go-bip39 v1.0.2/go.mod h1:sJ5fKU0s6JVwZjjcUEX2zFOnvq0ASQ2K9Zr6cf67kNs= github.com/tyler-smith/go-bip39 v1.1.0 h1:5eUemwrMargf3BSLRRCalXT93Ns6pQJIjYQN2nyfOP8= github.com/tyler-smith/go-bip39 v1.1.0/go.mod h1:gUYDtqQw1JS3ZJ8UWVcGTGqqr6YIN3CWg+kkNaLt55U= -github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo= github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw= github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0= github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY= -github.com/ugorji/go/codec v1.2.9 h1:rmenucSohSTiyL09Y+l2OCk+FrMxGMzho2+tjr5ticU= -github.com/ugorji/go/codec v1.2.9/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg= github.com/ulikunitz/xz v0.5.10 h1:t92gobL9l3HE202wg3rlk19F6X+JOxl9BBrCCMYEYd8= github.com/ulikunitz/xz v0.5.10/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14= github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA= @@ -2165,8 +2150,8 @@ golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns= golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= golang.org/x/net v0.14.0/go.mod h1:PpSgVXXLK0OxS0F31C1/tv6XNguvCrnXIDrFMspZIUI= golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY= -golang.org/x/net v0.28.0 h1:a9JDOJc5GMUJ0+UDqmLT86WiEy7iWyIhz8gz8E4e5hE= -golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg= +golang.org/x/net v0.29.0 h1:5ORfpBpCs4HzDYoodCDBbwHzdR5UrLBZ3sOnUJmFoHo= +golang.org/x/net v0.29.0/go.mod h1:gLkgy8jTGERgjzMic6DS9+SP0ajcu6Xu3Orq/SpETg0= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20181017192945-9dcd33a902f4/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20181203162652-d668ce993890/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= @@ -2773,8 +2758,8 @@ lukechampine.com/blake3 v1.1.7/go.mod h1:tkKEOtDkNtklkXtLNEOGNq5tcV90tJiA1vAA12R lukechampine.com/blake3 v1.3.0 h1:sJ3XhFINmHSrYCgl958hscfIa3bw8x4DqMP3u1YvoYE= lukechampine.com/blake3 v1.3.0/go.mod h1:0OFRp7fBtAylGVCO40o87sbupkyIGgbpv1+M1k1LM6k= nhooyr.io/websocket v1.8.6/go.mod h1:B70DZP8IakI65RVQ51MsWP/8jndNma26DVA/nFSCgW0= -nhooyr.io/websocket v1.8.7 h1:usjR2uOr/zjjkVMy0lW+PPohFok7PCow5sDjLgX4P4g= -nhooyr.io/websocket v1.8.7/go.mod h1:B70DZP8IakI65RVQ51MsWP/8jndNma26DVA/nFSCgW0= +nhooyr.io/websocket v1.8.17 h1:KEVeLJkUywCKVsnLIDlD/5gtayKp8VoCkksHCGGfT9Y= +nhooyr.io/websocket v1.8.17/go.mod h1:rN9OFWIUwuxg4fR5tELlYC04bXYowCP9GX47ivo2l+c= pgregory.net/rapid v1.1.0 h1:CMa0sjHSru3puNx+J0MIAuiiEV4N0qj8/cMWGBBCsjw= pgregory.net/rapid v1.1.0/go.mod h1:PY5XlDGj0+V1FCq0o192FdRhpKHGTRIWBgqjDBTrq04= rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= From 8df5292f906d0cc4031acabf412ccd1ebcafaddf Mon Sep 17 00:00:00 2001 From: vgonkivs Date: Mon, 7 Oct 2024 13:29:46 +0300 Subject: [PATCH 04/21] return share package back --- api/docgen/examples.go | 10 +- api/gateway/availability.go | 4 +- api/gateway/share.go | 24 +- api/gateway/share_test.go | 10 +- blob/blob.go | 32 ++- blob/blob_test.go | 6 +- blob/blobtest/testing.go | 22 +- blob/commitment_proof.go | 6 +- blob/helper.go | 10 +- blob/helper_test.go | 20 +- blob/parser.go | 14 +- blob/service.go | 54 ++-- blob/service_test.go | 90 +++---- cmd/cel-shed/shwap.go | 2 +- cmd/util.go | 8 +- cmd/util_test.go | 4 +- core/eds.go | 10 +- core/eds_test.go | 10 +- core/exchange_test.go | 12 +- core/header_test.go | 4 +- core/listener.go | 2 +- core/listener_no_race_test.go | 4 +- core/listener_test.go | 2 +- das/coordinator.go | 2 +- das/coordinator_test.go | 6 +- das/daser.go | 10 +- das/daser_test.go | 12 +- das/worker.go | 2 +- docs/adr/adr-011-blocksync-overhaul-part-1.md | 2 +- header/headertest/fraud/testing.go | 4 +- header/headertest/testing.go | 12 +- libs/edssser/edssser.go | 10 +- nodebuilder/blob/blob.go | 38 +-- nodebuilder/blob/cmd/blob.go | 4 +- nodebuilder/blob/module.go | 2 +- nodebuilder/core/module.go | 2 +- nodebuilder/da/service.go | 14 +- nodebuilder/das/constructors.go | 8 +- nodebuilder/fraud/unmarshaler.go | 2 +- nodebuilder/header/constructors.go | 2 +- nodebuilder/node_test.go | 4 +- nodebuilder/p2p/module.go | 2 +- nodebuilder/p2p/routing.go | 2 +- nodebuilder/share/bitswap.go | 2 +- nodebuilder/share/cmd/share.go | 4 +- nodebuilder/share/config.go | 10 +- nodebuilder/share/constructors.go | 12 +- nodebuilder/share/mocks/api.go | 6 +- nodebuilder/share/module.go | 22 +- nodebuilder/share/opts.go | 10 +- nodebuilder/share/p2p_constructors.go | 6 +- nodebuilder/share/share.go | 40 +-- nodebuilder/state/core.go | 2 +- nodebuilder/state/state.go | 8 +- nodebuilder/state/stub.go | 4 +- nodebuilder/store.go | 6 +- nodebuilder/tests/blob_test.go | 8 +- nodebuilder/tests/da_test.go | 4 +- nodebuilder/tests/fraud_test.go | 2 +- nodebuilder/tests/nd_test.go | 18 +- nodebuilder/tests/prune_test.go | 18 +- nodebuilder/tests/reconstruct_test.go | 4 +- nodebuilder/tests/sync_test.go | 8 +- pruner/light/pruner.go | 8 +- {square => share}/availability.go | 2 +- .../availability/full/availability.go | 16 +- .../availability/full/availability_test.go | 16 +- .../availability/full/reconstruction_test.go | 10 +- .../availability/full/testing.go | 22 +- .../availability/light/availability.go | 14 +- .../availability/light/availability_test.go | 40 +-- .../availability/light/options.go | 0 .../availability/light/sample.go | 2 +- .../availability/light/sample_test.go | 0 .../availability/light/testing.go | 32 +-- .../availability/mocks/availability.go | 0 .../availability/test/testing.go | 18 +- {square => share}/doc.go | 4 +- {square => share}/eds/accessor.go | 18 +- {square => share}/eds/axis_half.go | 28 +-- {square => share}/eds/axis_half_test.go | 4 +- .../eds/byzantine/bad_encoding.go | 8 +- .../eds/byzantine/bad_encoding_test.go | 26 +- {square => share}/eds/byzantine/byzantine.go | 12 +- .../eds/byzantine/pb/share.pb.go | 58 ++--- .../eds/byzantine/pb/share.proto | 0 .../eds/byzantine/share_proof.go | 26 +- {square => share}/eds/close_once.go | 14 +- {square => share}/eds/close_once_test.go | 22 +- {square => share}/eds/edstest/testing.go | 62 ++--- {square => share}/eds/nd.go | 10 +- {square => share}/eds/nd_test.go | 6 +- {square => share}/eds/proof.go | 6 +- {square => share}/eds/proofs_cache.go | 28 +-- {square => share}/eds/proofs_cache_test.go | 0 {square => share}/eds/read.go | 16 +- {square => share}/eds/retriever.go | 20 +- .../eds/retriever_no_race_test.go | 16 +- {square => share}/eds/retriever_quadrant.go | 8 +- {square => share}/eds/retriever_test.go | 20 +- {square => share}/eds/rsmt2d.go | 38 +-- {square => share}/eds/rsmt2d_test.go | 14 +- {square => share}/eds/share_reader.go | 0 {square => share}/eds/share_reader_test.go | 6 +- {square => share}/eds/testing.go | 42 ++-- {square => share}/eds/validation.go | 6 +- {square => share}/eds/validation_test.go | 8 +- {square => share}/empty.go | 16 +- {square => share}/ipld/add.go | 12 +- {square => share}/ipld/blockserv.go | 0 {square => share}/ipld/delete.go | 0 {square => share}/ipld/delete_test.go | 6 +- {square => share}/ipld/get.go | 4 +- {square => share}/ipld/get_shares.go | 20 +- {square => share}/ipld/get_shares_test.go | 78 +++--- {square => share}/ipld/namespace_data.go | 10 +- {square => share}/ipld/nmt.go | 12 +- {square => share}/ipld/nmt_adder.go | 0 {square => share}/ipld/nmt_test.go | 6 +- {square => share}/ipld/proof_collector.go | 0 {square => share}/ipld/proofs.go | 0 {square => share}/ipld/proofs_test.go | 12 +- {square => share}/ipld/test_helpers.go | 0 {square => share}/ipld/utils.go | 8 +- {square => share}/root.go | 10 +- share/share.go | 57 +---- {square => share}/shwap/eds.go | 2 +- {square => share}/shwap/eds_id.go | 0 {square => share}/shwap/eds_id_test.go | 0 {square => share}/shwap/getter.go | 6 +- {square => share}/shwap/getters/cascade.go | 14 +- .../shwap/getters/cascade_test.go | 4 +- .../shwap/getters/mock/getter.go | 2 +- {square => share}/shwap/getters/testing.go | 22 +- {square => share}/shwap/namespace_data.go | 12 +- {square => share}/shwap/namespace_data_id.go | 12 +- .../shwap/namespace_data_id_test.go | 6 +- .../shwap/p2p/bitswap/bitswap.go | 0 {square => share}/shwap/p2p/bitswap/block.go | 6 +- .../shwap/p2p/bitswap/block_fetch.go | 6 +- .../shwap/p2p/bitswap/block_fetch_test.go | 2 +- .../shwap/p2p/bitswap/block_proto.go | 2 +- .../shwap/p2p/bitswap/block_registry.go | 0 .../shwap/p2p/bitswap/block_store.go | 2 +- .../shwap/p2p/bitswap/block_test.go | 6 +- {square => share}/shwap/p2p/bitswap/cid.go | 0 {square => share}/shwap/p2p/bitswap/getter.go | 32 +-- .../shwap/p2p/bitswap/getter_test.go | 12 +- .../shwap/p2p/bitswap/pb/bitswap.pb.go | 32 +-- .../shwap/p2p/bitswap/pb/bitswap.proto | 2 +- .../shwap/p2p/bitswap/row_block.go | 10 +- .../shwap/p2p/bitswap/row_block_test.go | 6 +- .../p2p/bitswap/row_namespace_data_block.go | 14 +- .../bitswap/row_namespace_data_block_test.go | 10 +- .../shwap/p2p/bitswap/sample_block.go | 10 +- .../shwap/p2p/bitswap/sample_block_test.go | 6 +- .../shwap/p2p/discovery/backoff.go | 0 .../shwap/p2p/discovery/backoff_test.go | 0 {square => share}/shwap/p2p/discovery/dht.go | 0 .../shwap/p2p/discovery/discovery.go | 0 .../shwap/p2p/discovery/discovery_test.go | 0 .../shwap/p2p/discovery/metrics.go | 0 .../shwap/p2p/discovery/options.go | 0 {square => share}/shwap/p2p/discovery/set.go | 0 .../shwap/p2p/discovery/set_test.go | 0 {square => share}/shwap/p2p/shrex/doc.go | 2 +- {square => share}/shwap/p2p/shrex/error.go | 0 .../shwap/p2p/shrex/error_test.go | 0 {square => share}/shwap/p2p/shrex/errors.go | 0 {square => share}/shwap/p2p/shrex/metrics.go | 0 .../shwap/p2p/shrex/middleware.go | 0 {square => share}/shwap/p2p/shrex/params.go | 0 .../shwap/p2p/shrex/pb/shrex.pb.go | 38 +-- .../shwap/p2p/shrex/pb/shrex.proto | 2 +- .../shwap/p2p/shrex/peers/doc.go | 0 .../shwap/p2p/shrex/peers/manager.go | 12 +- .../shwap/p2p/shrex/peers/manager_test.go | 16 +- .../shwap/p2p/shrex/peers/metrics.go | 2 +- .../shwap/p2p/shrex/peers/options.go | 2 +- .../shwap/p2p/shrex/peers/pool.go | 0 .../shwap/p2p/shrex/peers/pool_test.go | 0 .../shwap/p2p/shrex/peers/timedqueue.go | 0 .../shwap/p2p/shrex/peers/timedqueue_test.go | 0 {square => share}/shwap/p2p/shrex/recovery.go | 0 .../shwap/p2p/shrex/shrex_getter/shrex.go | 30 +-- .../p2p/shrex/shrex_getter/shrex_test.go | 52 ++-- .../shwap/p2p/shrex/shrexeds/client.go | 14 +- .../shwap/p2p/shrex/shrexeds/doc.go | 2 +- .../shwap/p2p/shrex/shrexeds/exchange_test.go | 18 +- .../shwap/p2p/shrex/shrexeds/params.go | 4 +- .../shwap/p2p/shrex/shrexeds/server.go | 8 +- .../shwap/p2p/shrex/shrexnd/client.go | 16 +- .../shwap/p2p/shrex/shrexnd/doc.go | 4 +- .../shwap/p2p/shrex/shrexnd/exchange_test.go | 18 +- .../shwap/p2p/shrex/shrexnd/params.go | 4 +- .../shwap/p2p/shrex/shrexnd/server.go | 8 +- .../shwap/p2p/shrex/shrexsub/doc.go | 2 +- .../p2p/shrex/shrexsub/pb/notification.pb.go | 38 +-- .../p2p/shrex/shrexsub/pb/notification.proto | 2 +- .../shwap/p2p/shrex/shrexsub/pubsub.go | 6 +- .../shwap/p2p/shrex/shrexsub/pubsub_test.go | 2 +- .../shwap/p2p/shrex/shrexsub/subscription.go | 2 +- {square => share}/shwap/pb/shwap.pb.go | 68 ++--- {square => share}/shwap/pb/shwap.proto | 2 +- {square => share}/shwap/row.go | 28 +-- {square => share}/shwap/row_id.go | 2 +- {square => share}/shwap/row_id_test.go | 0 {square => share}/shwap/row_namespace_data.go | 24 +- .../shwap/row_namespace_data_id.go | 14 +- .../shwap/row_namespace_data_id_test.go | 6 +- .../shwap/row_namespace_data_test.go | 32 +-- {square => share}/shwap/row_test.go | 30 +-- {square => share}/shwap/sample.go | 32 +-- {square => share}/shwap/sample_id.go | 0 {square => share}/shwap/sample_id_test.go | 0 {square => share}/shwap/sample_test.go | 18 +- {square => share}/shwap/share.go | 18 +- square/namespace.go | 233 ------------------ square/share.go | 40 --- state/core_access.go | 4 +- state/core_access_test.go | 12 +- store/cache/accessor_cache.go | 2 +- store/cache/accessor_cache_test.go | 16 +- store/cache/cache.go | 2 +- store/cache/doublecache.go | 2 +- store/cache/noop.go | 22 +- store/file/codec_test.go | 8 +- store/file/header.go | 6 +- store/file/ods.go | 60 ++--- store/file/ods_q4.go | 18 +- store/file/ods_q4_test.go | 12 +- store/file/ods_test.go | 18 +- store/file/q4.go | 4 +- store/file/square.go | 34 +-- store/getter.go | 16 +- store/getter_test.go | 10 +- store/store.go | 54 ++-- store/store_cache.go | 2 +- store/store_test.go | 14 +- store/striplock.go | 6 +- 240 files changed, 1374 insertions(+), 1688 deletions(-) rename {square => share}/availability.go (97%) rename {square => share}/availability/full/availability.go (83%) rename {square => share}/availability/full/availability_test.go (86%) rename {square => share}/availability/full/reconstruction_test.go (96%) rename {square => share}/availability/full/testing.go (63%) rename {square => share}/availability/light/availability.go (91%) rename {square => share}/availability/light/availability_test.go (83%) rename {square => share}/availability/light/options.go (100%) rename {square => share}/availability/light/sample.go (98%) rename {square => share}/availability/light/sample_test.go (100%) rename {square => share}/availability/light/testing.go (70%) rename {square => share}/availability/mocks/availability.go (100%) rename {square => share}/availability/test/testing.go (92%) rename {square => share}/doc.go (88%) rename {square => share}/eds/accessor.go (72%) rename {square => share}/eds/axis_half.go (62%) rename {square => share}/eds/axis_half_test.go (84%) rename {square => share}/eds/byzantine/bad_encoding.go (97%) rename {square => share}/eds/byzantine/bad_encoding_test.go (92%) rename {square => share}/eds/byzantine/byzantine.go (87%) rename {square => share}/eds/byzantine/pb/share.pb.go (87%) rename {square => share}/eds/byzantine/pb/share.proto (100%) rename {square => share}/eds/byzantine/share_proof.go (84%) rename {square => share}/eds/close_once.go (80%) rename {square => share}/eds/close_once_test.go (72%) rename {square => share}/eds/edstest/testing.go (78%) rename {square => share}/eds/nd.go (75%) rename {square => share}/eds/nd_test.go (81%) rename {square => share}/eds/proof.go (94%) rename {square => share}/eds/proofs_cache.go (92%) rename {square => share}/eds/proofs_cache_test.go (100%) rename {square => share}/eds/read.go (77%) rename {square => share}/eds/retriever.go (94%) rename {square => share}/eds/retriever_no_race_test.go (72%) rename {square => share}/eds/retriever_quadrant.go (92%) rename {square => share}/eds/retriever_test.go (92%) rename {square => share}/eds/rsmt2d.go (78%) rename {square => share}/eds/rsmt2d_test.go (83%) rename {square => share}/eds/share_reader.go (100%) rename {square => share}/eds/share_reader_test.go (86%) rename {square => share}/eds/testing.go (92%) rename {square => share}/eds/validation.go (92%) rename {square => share}/eds/validation_test.go (92%) rename {square => share}/empty.go (82%) rename {square => share}/ipld/add.go (91%) rename {square => share}/ipld/blockserv.go (100%) rename {square => share}/ipld/delete.go (100%) rename {square => share}/ipld/delete_test.go (95%) rename {square => share}/ipld/get.go (97%) rename {square => share}/ipld/get_shares.go (79%) rename {square => share}/ipld/get_shares_test.go (87%) rename {square => share}/ipld/namespace_data.go (96%) rename {square => share}/ipld/nmt.go (92%) rename {square => share}/ipld/nmt_adder.go (100%) rename {square => share}/ipld/nmt_test.go (85%) rename {square => share}/ipld/proof_collector.go (100%) rename {square => share}/ipld/proofs.go (100%) rename {square => share}/ipld/proofs_test.go (81%) rename {square => share}/ipld/test_helpers.go (100%) rename {square => share}/ipld/utils.go (51%) rename {square => share}/root.go (89%) rename {square => share}/shwap/eds.go (68%) rename {square => share}/shwap/eds_id.go (100%) rename {square => share}/shwap/eds_id_test.go (100%) rename {square => share}/shwap/getter.go (89%) rename {square => share}/shwap/getters/cascade.go (93%) rename {square => share}/shwap/getters/cascade_test.go (97%) rename {square => share}/shwap/getters/mock/getter.go (98%) rename {square => share}/shwap/getters/testing.go (79%) rename {square => share}/shwap/namespace_data.go (85%) rename {square => share}/shwap/namespace_data_id.go (90%) rename {square => share}/shwap/namespace_data_id_test.go (88%) rename {square => share}/shwap/p2p/bitswap/bitswap.go (100%) rename {square => share}/shwap/p2p/bitswap/block.go (89%) rename {square => share}/shwap/p2p/bitswap/block_fetch.go (98%) rename {square => share}/shwap/p2p/bitswap/block_fetch_test.go (98%) rename {square => share}/shwap/p2p/bitswap/block_proto.go (92%) rename {square => share}/shwap/p2p/bitswap/block_registry.go (100%) rename {square => share}/shwap/p2p/bitswap/block_store.go (98%) rename {square => share}/shwap/p2p/bitswap/block_test.go (92%) rename {square => share}/shwap/p2p/bitswap/cid.go (100%) rename {square => share}/shwap/p2p/bitswap/getter.go (90%) rename {square => share}/shwap/p2p/bitswap/getter_test.go (57%) rename {square => share}/shwap/p2p/bitswap/pb/bitswap.pb.go (85%) rename {square => share}/shwap/p2p/bitswap/pb/bitswap.proto (70%) rename {square => share}/shwap/p2p/bitswap/row_block.go (90%) rename {square => share}/shwap/p2p/bitswap/row_block_test.go (82%) rename {square => share}/shwap/p2p/bitswap/row_namespace_data_block.go (89%) rename {square => share}/shwap/p2p/bitswap/row_namespace_data_block_test.go (76%) rename {square => share}/shwap/p2p/bitswap/sample_block.go (90%) rename {square => share}/shwap/p2p/bitswap/sample_block_test.go (85%) rename {square => share}/shwap/p2p/discovery/backoff.go (100%) rename {square => share}/shwap/p2p/discovery/backoff_test.go (100%) rename {square => share}/shwap/p2p/discovery/dht.go (100%) rename {square => share}/shwap/p2p/discovery/discovery.go (100%) rename {square => share}/shwap/p2p/discovery/discovery_test.go (100%) rename {square => share}/shwap/p2p/discovery/metrics.go (100%) rename {square => share}/shwap/p2p/discovery/options.go (100%) rename {square => share}/shwap/p2p/discovery/set.go (100%) rename {square => share}/shwap/p2p/discovery/set_test.go (100%) rename {square => share}/shwap/p2p/shrex/doc.go (94%) rename {square => share}/shwap/p2p/shrex/error.go (100%) rename {square => share}/shwap/p2p/shrex/error_test.go (100%) rename {square => share}/shwap/p2p/shrex/errors.go (100%) rename {square => share}/shwap/p2p/shrex/metrics.go (100%) rename {square => share}/shwap/p2p/shrex/middleware.go (100%) rename {square => share}/shwap/p2p/shrex/params.go (100%) rename {square => share}/shwap/p2p/shrex/pb/shrex.pb.go (81%) rename {square => share}/shwap/p2p/shrex/pb/shrex.proto (69%) rename {square => share}/shwap/p2p/shrex/peers/doc.go (100%) rename {square => share}/shwap/p2p/shrex/peers/manager.go (97%) rename {square => share}/shwap/p2p/shrex/peers/manager_test.go (97%) rename {square => share}/shwap/p2p/shrex/peers/metrics.go (99%) rename {square => share}/shwap/p2p/shrex/peers/options.go (97%) rename {square => share}/shwap/p2p/shrex/peers/pool.go (100%) rename {square => share}/shwap/p2p/shrex/peers/pool_test.go (100%) rename {square => share}/shwap/p2p/shrex/peers/timedqueue.go (100%) rename {square => share}/shwap/p2p/shrex/peers/timedqueue_test.go (100%) rename {square => share}/shwap/p2p/shrex/recovery.go (100%) rename {square => share}/shwap/p2p/shrex/shrex_getter/shrex.go (90%) rename {square => share}/shwap/p2p/shrex/shrex_getter/shrex_test.go (87%) rename {square => share}/shwap/p2p/shrex/shrexeds/client.go (93%) rename {square => share}/shwap/p2p/shrex/shrexeds/doc.go (98%) rename {square => share}/shwap/p2p/shrex/shrexeds/exchange_test.go (90%) rename {square => share}/shwap/p2p/shrex/shrexeds/params.go (90%) rename {square => share}/shwap/p2p/shrex/shrexeds/server.go (95%) rename {square => share}/shwap/p2p/shrex/shrexnd/client.go (92%) rename {square => share}/shwap/p2p/shrex/shrexnd/doc.go (91%) rename {square => share}/shwap/p2p/shrex/shrexnd/exchange_test.go (85%) rename {square => share}/shwap/p2p/shrex/shrexnd/params.go (87%) rename {square => share}/shwap/p2p/shrex/shrexnd/server.go (96%) rename {square => share}/shwap/p2p/shrex/shrexsub/doc.go (97%) rename {square => share}/shwap/p2p/shrex/shrexsub/pb/notification.pb.go (83%) rename {square => share}/shwap/p2p/shrex/shrexsub/pb/notification.proto (75%) rename {square => share}/shwap/p2p/shrex/shrexsub/pubsub.go (96%) rename {square => share}/shwap/p2p/shrex/shrexsub/pubsub_test.go (97%) rename {square => share}/shwap/p2p/shrex/shrexsub/subscription.go (94%) rename {square => share}/shwap/pb/shwap.pb.go (89%) rename {square => share}/shwap/pb/shwap.proto (89%) rename {square => share}/shwap/row.go (80%) rename {square => share}/shwap/row_id.go (99%) rename {square => share}/shwap/row_id_test.go (100%) rename {square => share}/shwap/row_namespace_data.go (90%) rename {square => share}/shwap/row_namespace_data_id.go (88%) rename {square => share}/shwap/row_namespace_data_id_test.go (89%) rename {square => share}/shwap/row_namespace_data_test.go (71%) rename {square => share}/shwap/row_test.go (80%) rename {square => share}/shwap/sample.go (75%) rename {square => share}/shwap/sample_id.go (100%) rename {square => share}/shwap/sample_id_test.go (100%) rename {square => share}/shwap/sample_test.go (87%) rename {square => share}/shwap/share.go (70%) delete mode 100644 square/namespace.go delete mode 100644 square/share.go diff --git a/api/docgen/examples.go b/api/docgen/examples.go index acb5fdb08a..dff8e0baa8 100644 --- a/api/docgen/examples.go +++ b/api/docgen/examples.go @@ -22,15 +22,15 @@ import ( "github.com/celestiaorg/go-fraud" libhead "github.com/celestiaorg/go-header" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" "github.com/celestiaorg/celestia-node/blob" "github.com/celestiaorg/celestia-node/das" "github.com/celestiaorg/celestia-node/header" "github.com/celestiaorg/celestia-node/nodebuilder/node" - "github.com/celestiaorg/celestia-node/square" - "github.com/celestiaorg/celestia-node/square/eds/byzantine" + "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/share/eds/byzantine" "github.com/celestiaorg/celestia-node/state" ) @@ -80,7 +80,7 @@ var ExampleValues = map[reflect.Type]interface{}{ } func init() { - addToExampleValues(square.EmptyEDS()) + addToExampleValues(share.EmptyEDS()) addr, err := sdk.AccAddressFromBech32("celestia1377k5an3f94v6wyaceu0cf4nq6gk2jtpc46g7h") if err != nil { panic(err) @@ -166,7 +166,7 @@ func init() { // randomly generated namespace that's used in the blob example above // (AAAAAAAAAAAAAAAAAAAAAAAAAAAAAMJ/xGlNMdE=) - namespace, err := share.NewV0Namespace([]byte{0xc2, 0x7f, 0xc4, 0x69, 0x4d, 0x31, 0xd1}) + namespace, err := gosquare.NewV0Namespace([]byte{0xc2, 0x7f, 0xc4, 0x69, 0x4d, 0x31, 0xd1}) if err != nil { panic(err) } diff --git a/api/gateway/availability.go b/api/gateway/availability.go index f9372018af..e8e96083d5 100644 --- a/api/gateway/availability.go +++ b/api/gateway/availability.go @@ -8,7 +8,7 @@ import ( "github.com/gorilla/mux" - "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/share" ) const heightAvailabilityEndpoint = "/data_available" @@ -45,7 +45,7 @@ func (h *Handler) handleHeightAvailabilityRequest(w http.ResponseWriter, r *http if werr != nil { log.Errorw("serving request", "endpoint", heightAvailabilityEndpoint, "err", err) } - case errors.Is(err, square.ErrNotAvailable): + case errors.Is(err, share.ErrNotAvailable): resp, err := json.Marshal(&AvailabilityResponse{Available: false}) if err != nil { writeError(w, http.StatusInternalServerError, heightAvailabilityEndpoint, err) diff --git a/api/gateway/share.go b/api/gateway/share.go index f6b5156ab4..8e5b898b5a 100644 --- a/api/gateway/share.go +++ b/api/gateway/share.go @@ -9,7 +9,7 @@ import ( "github.com/gorilla/mux" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" ) const ( @@ -22,8 +22,8 @@ var namespaceKey = "nid" // NamespacedSharesResponse represents the response to a // SharesByNamespace request. type NamespacedSharesResponse struct { - Shares []share.Share `json:"shares"` - Height uint64 `json:"height"` + Shares []gosquare.Share `json:"shares"` + Height uint64 `json:"height"` } // NamespacedDataResponse represents the response to a @@ -88,7 +88,7 @@ func (h *Handler) handleDataByNamespaceRequest(w http.ResponseWriter, r *http.Re } } -func (h *Handler) getShares(ctx context.Context, height uint64, namespace share.Namespace) ([]share.Share, error) { +func (h *Handler) getShares(ctx context.Context, height uint64, namespace gosquare.Namespace) ([]gosquare.Share, error) { header, err := h.header.GetByHeight(ctx, height) if err != nil { return nil, err @@ -102,8 +102,8 @@ func (h *Handler) getShares(ctx context.Context, height uint64, namespace share. return shares.Flatten(), nil } -func dataFromShares(input []share.Share) (data [][]byte, err error) { - sequences, err := share.ParseShares(input, false) +func dataFromShares(input []gosquare.Share) (data [][]byte, err error) { + sequences, err := gosquare.ParseShares(input, false) if err != nil { return nil, err } @@ -117,24 +117,24 @@ func dataFromShares(input []share.Share) (data [][]byte, err error) { return data, nil } -func parseGetByNamespaceArgs(r *http.Request) (height uint64, namespace share.Namespace, err error) { +func parseGetByNamespaceArgs(r *http.Request) (height uint64, namespace gosquare.Namespace, err error) { vars := mux.Vars(r) // if a height was given, parse it, otherwise get namespaced shares/data from the latest header if strHeight, ok := vars[heightKey]; ok { height, err = strconv.ParseUint(strHeight, 10, 64) if err != nil { - return 0, share.Namespace{}, err + return 0, gosquare.Namespace{}, err } } hexNamespace := vars[namespaceKey] nsString, err := hex.DecodeString(hexNamespace) if err != nil { - return 0, share.Namespace{}, err + return 0, gosquare.Namespace{}, err } - ns, err := share.NewNamespaceFromBytes(nsString) + ns, err := gosquare.NewNamespaceFromBytes(nsString) if err != nil { - return 0, share.Namespace{}, err + return 0, gosquare.Namespace{}, err } namespace = ns - return height, namespace, share.ValidateForData(namespace) + return height, namespace, gosquare.ValidateForData(namespace) } diff --git a/api/gateway/share_test.go b/api/gateway/share_test.go index b51d043f73..53c20bdbb6 100644 --- a/api/gateway/share_test.go +++ b/api/gateway/share_test.go @@ -6,7 +6,7 @@ import ( "github.com/stretchr/testify/require" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" ) func Test_dataFromShares(t *testing.T) { @@ -16,10 +16,10 @@ func Test_dataFromShares(t *testing.T) { []byte("BEEEEAHP"), } - ns := share.RandomNamespace() - sss := share.NewSparseShareSplitter() + ns := gosquare.RandomNamespace() + sss := gosquare.NewSparseShareSplitter() for _, data := range testData { - b, err := share.NewBlob(ns, data, share.ShareVersionZero, nil) + b, err := gosquare.NewBlob(ns, data, gosquare.ShareVersionZero, nil) require.NoError(t, err) require.NoError(t, sss.Write(b)) } @@ -32,7 +32,7 @@ func Test_dataFromShares(t *testing.T) { rawSSSShares[i] = d } - shrs, err := share.FromBytes(rawSSSShares) + shrs, err := gosquare.FromBytes(rawSSSShares) require.NoError(t, err) parsedSSSShares, err := dataFromShares(shrs) require.NoError(t, err) diff --git a/blob/blob.go b/blob/blob.go index d2c41fae6a..dbf9e7475e 100644 --- a/blob/blob.go +++ b/blob/blob.go @@ -10,7 +10,7 @@ import ( app "github.com/celestiaorg/celestia-app/v3/pkg/appconsts/v2" "github.com/celestiaorg/go-square/merkle" "github.com/celestiaorg/go-square/v2/inclusion" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt" ) @@ -59,7 +59,7 @@ func (p Proof) equal(input Proof) error { // Blob represents any application-specific binary data that anyone can submit to Celestia. type Blob struct { - *share.Blob `json:"blob"` + *gosquare.Blob `json:"blob"` Commitment Commitment `json:"commitment"` @@ -70,33 +70,31 @@ type Blob struct { // NewBlobV0 constructs a new blob from the provided Namespace and data. // The blob will be formatted as v0 shares. -func NewBlobV0(namespace share.Namespace, data []byte) (*Blob, error) { - return NewBlob(share.ShareVersionZero, namespace, data, nil) +func NewBlobV0(namespace gosquare.Namespace, data []byte) (*Blob, error) { + return NewBlob(gosquare.ShareVersionZero, namespace, data, nil) } // NewBlobV1 constructs a new blob from the provided Namespace and data. // The blob will be formatted as v0 shares. -func NewBlobV1(namespace share.Namespace, data, signer []byte) (*Blob, error) { - return NewBlob(share.ShareVersionOne, namespace, data, signer) +func NewBlobV1(namespace gosquare.Namespace, data, signer []byte) (*Blob, error) { + return NewBlob(gosquare.ShareVersionOne, namespace, data, signer) } // NewBlob constructs a new blob from the provided Namespace, data and share version. -func NewBlob(shareVersion uint8, namespace share.Namespace, data, signer []byte) (*Blob, error) { +func NewBlob(shareVersion uint8, namespace gosquare.Namespace, data, signer []byte) (*Blob, error) { if len(data) == 0 || len(data) > appconsts.DefaultMaxBytes { return nil, fmt.Errorf("blob data must be > 0 && <= %d, but it was %d bytes", appconsts.DefaultMaxBytes, len(data)) } - if err := share.ValidateForData(namespace); err != nil { + if err := gosquare.ValidateForData(namespace); err != nil { return nil, fmt.Errorf("invalid user namespace: %w", err) } - if !namespace.IsUsableNamespace() { - return nil, fmt.Errorf("parity of tail padding namespaces %s are not allowed", namespace.ID()) - } - if namespace.IsReserved() { - return nil, fmt.Errorf("reserved namespace %s is not allowed", namespace.ID()) + + if !gosquare.IsBlobNamespace(namespace) { + return nil, fmt.Errorf("namespace %s is not a blob namespace", namespace) } - squareBlob, err := share.NewBlob(namespace, data, shareVersion, signer) + squareBlob, err := gosquare.NewBlob(namespace, data, shareVersion, signer) if err != nil { return nil, err } @@ -109,7 +107,7 @@ func NewBlob(shareVersion uint8, namespace share.Namespace, data, signer []byte) } // Namespace returns blob's namespace. -func (b *Blob) Namespace() share.Namespace { +func (b *Blob) Namespace() gosquare.Namespace { return b.Blob.Namespace() } @@ -129,7 +127,7 @@ func (b *Blob) Length() (int, error) { if len(s) == 0 { return 0, errors.New("blob with zero shares received") } - return share.SparseSharesNeeded(s[0].SequenceLen()), nil + return gosquare.SparseSharesNeeded(s[0].SequenceLen()), nil } // Signer returns blob's author. @@ -169,7 +167,7 @@ func (b *Blob) UnmarshalJSON(data []byte) error { return err } - ns, err := share.NewNamespaceFromBytes(jsonBlob.Namespace) + ns, err := gosquare.NewNamespaceFromBytes(jsonBlob.Namespace) if err != nil { return err } diff --git a/blob/blob_test.go b/blob/blob_test.go index 20871706d5..9ea7dcf49a 100644 --- a/blob/blob_test.go +++ b/blob/blob_test.go @@ -9,7 +9,7 @@ import ( "github.com/celestiaorg/go-square/merkle" "github.com/celestiaorg/go-square/v2/inclusion" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/celestia-node/blob/blobtest" ) @@ -50,7 +50,7 @@ func TestBlob(t *testing.T) { name: "verify namespace", expectedRes: func(t *testing.T) { ns := blob[0].Namespace() - require.NoError(t, share.ValidateUserNamespace(ns.Version(), ns.ID())) + require.NoError(t, gosquare.ValidateUserNamespace(ns.Version(), ns.ID())) }, }, { @@ -91,7 +91,7 @@ func TestBlob(t *testing.T) { } } -func convertBlobs(appBlobs ...*share.Blob) ([]*Blob, error) { +func convertBlobs(appBlobs ...*gosquare.Blob) ([]*Blob, error) { blobs := make([]*Blob, 0, len(appBlobs)) for _, appBlob := range appBlobs { blob, err := NewBlob(appBlob.ShareVersion(), appBlob.Namespace(), appBlob.Data(), appBlob.Signer()) diff --git a/blob/blobtest/testing.go b/blob/blobtest/testing.go index e509e36af3..6443ae1c9a 100644 --- a/blob/blobtest/testing.go +++ b/blob/blobtest/testing.go @@ -1,31 +1,31 @@ package blobtest import ( + "encoding/binary" "fmt" tmrand "github.com/tendermint/tendermint/libs/rand" "github.com/celestiaorg/celestia-app/v3/test/util/testfactory" - "github.com/celestiaorg/go-square/shares" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" ) // GenerateV0Blobs is a test utility producing v0 share formatted blobs with the // requested size and random namespaces. -func GenerateV0Blobs(sizes []int, sameNamespace bool) ([]*share.Blob, error) { - blobs := make([]*share.Blob, 0, len(sizes)) +func GenerateV0Blobs(sizes []int, sameNamespace bool) ([]*gosquare.Blob, error) { + blobs := make([]*gosquare.Blob, 0, len(sizes)) for _, size := range sizes { - size := RawBlobSize(share.FirstSparseShareContentSize * size) + size := RawBlobSize(gosquare.FirstSparseShareContentSize * size) appBlob := testfactory.GenerateRandomBlob(size) if !sameNamespace { - namespace, err := share.NewV0Namespace(tmrand.Bytes(7)) + namespace, err := gosquare.NewV0Namespace(tmrand.Bytes(7)) if err != nil { return nil, err } if namespace.IsReserved() { return nil, fmt.Errorf("reserved namespace") } - appBlob, err = share.NewV0Blob(namespace, appBlob.Data()) + appBlob, err = gosquare.NewV0Blob(namespace, appBlob.Data()) if err != nil { return nil, err } @@ -37,5 +37,11 @@ func GenerateV0Blobs(sizes []int, sameNamespace bool) ([]*share.Blob, error) { } func RawBlobSize(totalSize int) int { - return totalSize - shares.DelimLen(uint64(totalSize)) + return totalSize - delimLen(uint64(totalSize)) +} + +// delimLen calculates the length of the delimiter for a given unit size +func delimLen(size uint64) int { + lenBuf := make([]byte, binary.MaxVarintLen64) + return binary.PutUvarint(lenBuf, size) } diff --git a/blob/commitment_proof.go b/blob/commitment_proof.go index d59614a693..68fbc33c28 100644 --- a/blob/commitment_proof.go +++ b/blob/commitment_proof.go @@ -8,7 +8,7 @@ import ( "github.com/celestiaorg/celestia-app/v3/pkg/appconsts" "github.com/celestiaorg/celestia-app/v3/pkg/proof" "github.com/celestiaorg/go-square/v2/inclusion" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt" "github.com/celestiaorg/nmt/namespace" ) @@ -81,7 +81,7 @@ func (commitmentProof *CommitmentProof) Validate() error { } // Verify verifies that a commitment proof is valid, i.e., the subtree roots commit -// to some data that was posted to a square. +// to some data that was posted to a share. // Expects the commitment proof to be properly formulated and validated // using the Validate() function. func (commitmentProof *CommitmentProof) Verify(root []byte, subtreeRootThreshold int) (bool, error) { @@ -94,7 +94,7 @@ func (commitmentProof *CommitmentProof) Verify(root []byte, subtreeRootThreshold return false, err } - nmtHasher := nmt.NewNmtHasher(appconsts.NewBaseHashFunc(), share.NamespaceSize, true) + nmtHasher := nmt.NewNmtHasher(appconsts.NewBaseHashFunc(), gosquare.NamespaceSize, true) // computes the total number of shares proven. numberOfShares := 0 diff --git a/blob/helper.go b/blob/helper.go index 3b81fce5be..076861548e 100644 --- a/blob/helper.go +++ b/blob/helper.go @@ -4,16 +4,16 @@ import ( "fmt" "sort" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" ) // BlobsToShares accepts blobs and convert them to the Shares. -func BlobsToShares(nodeBlobs ...*Blob) ([]share.Share, error) { +func BlobsToShares(nodeBlobs ...*Blob) ([]gosquare.Share, error) { sort.Slice(nodeBlobs, func(i, j int) bool { return nodeBlobs[i].Blob.Namespace().Compare(nodeBlobs[j].Blob.Namespace()) < 0 }) - splitter := share.NewSparseShareSplitter() + splitter := gosquare.NewSparseShareSplitter() for i, nodeBlob := range nodeBlobs { err := splitter.Write(nodeBlob.Blob) if err != nil { @@ -25,8 +25,8 @@ func BlobsToShares(nodeBlobs ...*Blob) ([]share.Share, error) { } // ToAppBlobs converts node's blob type to the blob type from go-square. -func ToAppBlobs(blobs ...*Blob) []*share.Blob { - appBlobs := make([]*share.Blob, len(blobs)) +func ToAppBlobs(blobs ...*Blob) []*gosquare.Blob { + appBlobs := make([]*gosquare.Blob, len(blobs)) for i := range blobs { appBlobs[i] = blobs[i].Blob } diff --git a/blob/helper_test.go b/blob/helper_test.go index f4ac403b97..9fb6992d67 100644 --- a/blob/helper_test.go +++ b/blob/helper_test.go @@ -7,17 +7,17 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" ) func TestBlobsToShares(t *testing.T) { t.Run("should sort blobs by namespace in ascending order", func(t *testing.T) { - namespaceA := share.MustNewV0Namespace(bytes.Repeat([]byte{0xa}, 10)) - namespaceB := share.MustNewV0Namespace(bytes.Repeat([]byte{0xb}, 10)) + namespaceA := gosquare.MustNewV0Namespace(bytes.Repeat([]byte{0xa}, 10)) + namespaceB := gosquare.MustNewV0Namespace(bytes.Repeat([]byte{0xb}, 10)) - blobA, err := NewBlob(share.ShareVersionZero, namespaceA, []byte("dataA"), nil) + blobA, err := NewBlob(gosquare.ShareVersionZero, namespaceA, []byte("dataA"), nil) require.NoError(t, err) - blobB, err := NewBlob(share.ShareVersionZero, namespaceB, []byte("dataB"), nil) + blobB, err := NewBlob(gosquare.ShareVersionZero, namespaceB, []byte("dataB"), nil) require.NoError(t, err) got, err := BlobsToShares(blobB, blobA) @@ -29,15 +29,15 @@ func TestBlobsToShares(t *testing.T) { } func TestToAppBlobs(t *testing.T) { - namespaceA := share.MustNewV0Namespace(bytes.Repeat([]byte{0xa}, 10)) - namespaceB := share.MustNewV0Namespace(bytes.Repeat([]byte{0xb}, 10)) + namespaceA := gosquare.MustNewV0Namespace(bytes.Repeat([]byte{0xa}, 10)) + namespaceB := gosquare.MustNewV0Namespace(bytes.Repeat([]byte{0xb}, 10)) - blobA, err := NewBlob(share.ShareVersionZero, namespaceA, []byte("dataA"), nil) + blobA, err := NewBlob(gosquare.ShareVersionZero, namespaceA, []byte("dataA"), nil) require.NoError(t, err) - blobB, err := NewBlob(share.ShareVersionZero, namespaceB, []byte("dataB"), nil) + blobB, err := NewBlob(gosquare.ShareVersionZero, namespaceB, []byte("dataB"), nil) require.NoError(t, err) got := ToAppBlobs(blobA, blobB) - assert.Equal(t, []*share.Blob{blobA.Blob, blobB.Blob}, got) + assert.Equal(t, []*gosquare.Blob{blobA.Blob, blobB.Blob}, got) } diff --git a/blob/parser.go b/blob/parser.go index d693b3a8c3..ad452329d2 100644 --- a/blob/parser.go +++ b/blob/parser.go @@ -6,7 +6,7 @@ import ( "github.com/celestiaorg/go-square/merkle" "github.com/celestiaorg/go-square/v2/inclusion" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" ) // parser helps to collect shares and transform them into a blob. @@ -17,13 +17,13 @@ type parser struct { // length is an amount of the shares needed to build the blob. length int // shares is a set of shares to build the blob. - shares []share.Share + shares []gosquare.Share verifyFn func(blob *Blob) bool } // set tries to find the first blob's share by skipping padding shares and // sets the metadata of the blob(index and length) -func (p *parser) set(index int, shrs []share.Share) ([]share.Share, error) { +func (p *parser) set(index int, shrs []gosquare.Share) ([]gosquare.Share, error) { if len(shrs) == 0 { return nil, errEmptyShares } @@ -40,14 +40,14 @@ func (p *parser) set(index int, shrs []share.Share) ([]share.Share, error) { // `+=` as index could be updated in `skipPadding` p.index += index length := shrs[0].SequenceLen() - p.length = share.SparseSharesNeeded(length) + p.length = gosquare.SparseSharesNeeded(length) return shrs, nil } // addShares sets shares until the blob is completed and extra remaining shares back. // It assumes that the remaining shares required for blob completeness are correct and // do not include padding shares. -func (p *parser) addShares(shares []share.Share) (shrs []share.Share, isComplete bool) { +func (p *parser) addShares(shares []gosquare.Share) (shrs []gosquare.Share, isComplete bool) { index := -1 for i, sh := range shares { p.shares = append(p.shares, sh) @@ -75,7 +75,7 @@ func (p *parser) parse() (*Blob, error) { return nil, fmt.Errorf("invalid shares amount. want:%d, have:%d", p.length, len(p.shares)) } - blobs, err := share.ParseBlobs(p.shares) + blobs, err := gosquare.ParseBlobs(p.shares) if err != nil { return nil, err } @@ -98,7 +98,7 @@ func (p *parser) parse() (*Blob, error) { // skipPadding iterates through the shares until non-padding share will be found. It guarantees that // the returned set of shares will start with non-padding share(or empty set of shares). -func (p *parser) skipPadding(shares []share.Share) ([]share.Share, error) { +func (p *parser) skipPadding(shares []gosquare.Share) ([]gosquare.Share, error) { if len(shares) == 0 { return nil, errEmptyShares } diff --git a/blob/service.go b/blob/service.go index f95091d9d2..9ccf92825a 100644 --- a/blob/service.go +++ b/blob/service.go @@ -19,13 +19,13 @@ import ( "github.com/celestiaorg/celestia-app/v3/pkg/appconsts" pkgproof "github.com/celestiaorg/celestia-app/v3/pkg/proof" "github.com/celestiaorg/go-square/v2/inclusion" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt" "github.com/celestiaorg/rsmt2d" "github.com/celestiaorg/celestia-node/header" "github.com/celestiaorg/celestia-node/libs/utils" - "github.com/celestiaorg/celestia-node/square/shwap" + "github.com/celestiaorg/celestia-node/share/shwap" "github.com/celestiaorg/celestia-node/state" ) @@ -45,7 +45,7 @@ type SubmitOptions = state.TxConfig // avoid a circular dependency between the blob and the state package, since the state package needs // the blob.Blob type for this signature. type Submitter interface { - SubmitPayForBlob(context.Context, []*share.Blob, *state.TxConfig) (*types.TxResponse, error) + SubmitPayForBlob(context.Context, []*gosquare.Blob, *state.TxConfig) (*types.TxResponse, error) } type Service struct { @@ -98,7 +98,7 @@ type SubscriptionResponse struct { // The channel will be closed when the context is canceled or the service is stopped. // Please note that no errors are returned: underlying operations are retried until successful. // Additionally, not reading from the returned channel will cause the stream to close after 16 messages. -func (s *Service) Subscribe(ctx context.Context, ns share.Namespace) (<-chan *SubscriptionResponse, error) { +func (s *Service) Subscribe(ctx context.Context, ns gosquare.Namespace) (<-chan *SubscriptionResponse, error) { if s.ctx == nil { return nil, fmt.Errorf("service has not been started") } @@ -132,7 +132,7 @@ func (s *Service) Subscribe(ctx context.Context, ns share.Namespace) (<-chan *Su var blobs []*Blob var err error for { - blobs, err = s.getAll(ctx, header, []share.Namespace{ns}) + blobs, err = s.getAll(ctx, header, []gosquare.Namespace{ns}) if ctx.Err() != nil { // context canceled, continuing would lead to unexpected missed heights for the client log.Debugw("blobsub: canceling subscription due to user ctx closing", "namespace", ns.ID()) @@ -169,18 +169,16 @@ func (s *Service) Subscribe(ctx context.Context, ns share.Namespace) (<-chan *Su func (s *Service) Submit(ctx context.Context, blobs []*Blob, txConfig *SubmitOptions) (uint64, error) { log.Debugw("submitting blobs", "amount", len(blobs)) - squareBlobs := make([]*share.Blob, len(blobs)) + squareBlobs := make([]*gosquare.Blob, len(blobs)) for i := range blobs { namespace := blobs[i].Namespace() - if err := share.ValidateForData(namespace); err != nil { + if err := gosquare.ValidateForData(namespace); err != nil { return 0, err } - if !blobs[i].Namespace().IsUsableNamespace() { - return 0, fmt.Errorf("parity of tail padding namespaces %s are not allowed", namespace.ID()) - } - if blobs[i].Namespace().IsReserved() { - return 0, fmt.Errorf("reserved namespace %s is not allowed", namespace.ID()) + if !gosquare.IsBlobNamespace(namespace) { + return 0, fmt.Errorf("not allowed namespace %s were used to build the blob", namespace.ID()) } + squareBlobs[i] = blobs[i].Blob } @@ -198,7 +196,7 @@ func (s *Service) Submit(ctx context.Context, blobs []*Blob, txConfig *SubmitOpt func (s *Service) Get( ctx context.Context, height uint64, - namespace share.Namespace, + namespace gosquare.Namespace, commitment Commitment, ) (blob *Blob, err error) { ctx, span := tracer.Start(ctx, "get") @@ -224,7 +222,7 @@ func (s *Service) Get( func (s *Service) GetProof( ctx context.Context, height uint64, - namespace share.Namespace, + namespace gosquare.Namespace, commitment Commitment, ) (proof *Proof, err error) { ctx, span := tracer.Start(ctx, "get-proof") @@ -253,7 +251,7 @@ func (s *Service) GetProof( // the user will receive all found blobs along with a combined error message. // // All blobs will preserve the order of the namespaces that were requested. -func (s *Service) GetAll(ctx context.Context, height uint64, namespaces []share.Namespace) ([]*Blob, error) { +func (s *Service) GetAll(ctx context.Context, height uint64, namespaces []gosquare.Namespace) ([]*Blob, error) { header, err := s.headerGetter(ctx, height) if err != nil { return nil, err @@ -265,7 +263,7 @@ func (s *Service) GetAll(ctx context.Context, height uint64, namespaces []share. func (s *Service) getAll( ctx context.Context, header *header.ExtendedHeader, - namespaces []share.Namespace, + namespaces []gosquare.Namespace, ) ([]*Blob, error) { height := header.Height() var ( @@ -275,7 +273,7 @@ func (s *Service) getAll( ) for i, namespace := range namespaces { wg.Add(1) - go func(i int, namespace share.Namespace) { + go func(i int, namespace gosquare.Namespace) { log.Debugw("retrieving all blobs from", "namespace", namespace.String(), "height", height) defer wg.Done() @@ -304,7 +302,7 @@ func (s *Service) getAll( func (s *Service) Included( ctx context.Context, height uint64, - namespace share.Namespace, + namespace gosquare.Namespace, proof *Proof, commitment Commitment, ) (_ bool, err error) { @@ -339,7 +337,7 @@ func (s *Service) Included( func (s *Service) retrieve( ctx context.Context, height uint64, - namespace share.Namespace, + namespace gosquare.Namespace, sharesParser *parser, ) (_ *Blob, _ *Proof, err error) { log.Infow("requesting blob", @@ -383,7 +381,7 @@ func (s *Service) retrieve( attribute.Int64("eds-size", int64(len(header.DAH.RowRoots))))) var ( - appShares = make([]share.Share, 0) + appShares = make([]gosquare.Share, 0) proofs = make(Proof, 0) ) @@ -402,7 +400,7 @@ func (s *Service) retrieve( for { var ( isComplete bool - shrs []share.Share + shrs []gosquare.Share wasEmpty = sharesParser.isEmpty() ) @@ -473,7 +471,7 @@ func (s *Service) retrieve( // them to Blobs. func (s *Service) getBlobs( ctx context.Context, - namespace share.Namespace, + namespace gosquare.Namespace, header *header.ExtendedHeader, ) (_ []*Blob, err error) { ctx, span := tracer.Start(ctx, "get-blobs") @@ -499,7 +497,7 @@ func (s *Service) getBlobs( func (s *Service) GetCommitmentProof( ctx context.Context, height uint64, - namespace share.Namespace, + namespace gosquare.Namespace, shareCommitment []byte, ) (*CommitmentProof, error) { log.Debugw("proving share commitment", "height", height, "commitment", shareCommitment, "namespace", namespace) @@ -561,8 +559,8 @@ func (s *Service) GetCommitmentProof( func ProveCommitment( eds *rsmt2d.ExtendedDataSquare, - namespace share.Namespace, - blobShares []share.Share, + namespace gosquare.Namespace, + blobShares []gosquare.Share, ) (*CommitmentProof, error) { // find the blob shares in the EDS blobSharesStartIndex := -1 @@ -585,7 +583,7 @@ func ProveCommitment( sharesProof, err := pkgproof.NewShareInclusionProofFromEDS( eds, namespace, - share.NewRange(blobSharesStartIndex, blobSharesStartIndex+len(blobShares)), + gosquare.NewRange(blobSharesStartIndex, blobSharesStartIndex+len(blobShares)), ) if err != nil { return nil, err @@ -646,7 +644,7 @@ func ProveCommitment( // computeSubtreeRoots takes a set of shares and ranges and returns the corresponding subtree roots. // the offset is the number of shares that are before the subtree roots we're calculating. -func computeSubtreeRoots(shares []share.Share, ranges []nmt.LeafRange, offset int) ([][]byte, error) { +func computeSubtreeRoots(shares []gosquare.Share, ranges []nmt.LeafRange, offset int) ([][]byte, error) { if len(shares) == 0 { return nil, fmt.Errorf("cannot compute subtree roots for an empty shares list") } @@ -661,7 +659,7 @@ func computeSubtreeRoots(shares []share.Share, ranges []nmt.LeafRange, offset in tree := nmt.New( appconsts.NewBaseHashFunc(), nmt.IgnoreMaxNamespace(true), - nmt.NamespaceIDSize(share.NamespaceSize), + nmt.NamespaceIDSize(gosquare.NamespaceSize), ) for _, sh := range shares { leafData := make([]byte, 0) diff --git a/blob/service_test.go b/blob/service_test.go index 1114b84a97..c78b00c0fa 100644 --- a/blob/service_test.go +++ b/blob/service_test.go @@ -26,7 +26,7 @@ import ( squarens "github.com/celestiaorg/go-square/namespace" appshares "github.com/celestiaorg/go-square/shares" "github.com/celestiaorg/go-square/v2/inclusion" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt" "github.com/celestiaorg/rsmt2d" @@ -34,12 +34,12 @@ import ( "github.com/celestiaorg/celestia-node/header" "github.com/celestiaorg/celestia-node/header/headertest" "github.com/celestiaorg/celestia-node/libs/utils" - "github.com/celestiaorg/celestia-node/square" - "github.com/celestiaorg/celestia-node/square/eds" - "github.com/celestiaorg/celestia-node/square/eds/edstest" - "github.com/celestiaorg/celestia-node/square/ipld" - "github.com/celestiaorg/celestia-node/square/shwap" - "github.com/celestiaorg/celestia-node/square/shwap/getters/mock" + "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/share/eds" + "github.com/celestiaorg/celestia-node/share/eds/edstest" + "github.com/celestiaorg/celestia-node/share/ipld" + "github.com/celestiaorg/celestia-node/share/shwap" + "github.com/celestiaorg/celestia-node/share/shwap/getters/mock" ) func TestBlobService_Get(t *testing.T) { @@ -94,7 +94,7 @@ func TestBlobService_Get(t *testing.T) { { name: "get all with the same namespace", doFn: func() (interface{}, error) { - return service.GetAll(ctx, 1, []share.Namespace{blobsWithSameNamespace[0].Namespace()}) + return service.GetAll(ctx, 1, []gosquare.Namespace{blobsWithSameNamespace[0].Namespace()}) }, expectedResult: func(res interface{}, err error) { require.NoError(t, err) @@ -123,7 +123,7 @@ func TestBlobService_Get(t *testing.T) { blobsWithDiffNamespaces[1].Commitment, ) require.NoError(t, err) - b23, err := service.GetAll(ctx, 1, []share.Namespace{blobsWithSameNamespace[0].Namespace()}) + b23, err := service.GetAll(ctx, 1, []gosquare.Namespace{blobsWithSameNamespace[0].Namespace()}) require.NoError(t, err) return []*Blob{b0, b1, b23[0], b23[1]}, nil }, @@ -159,10 +159,10 @@ func TestBlobService_Get(t *testing.T) { { name: "get all with different namespaces", doFn: func() (interface{}, error) { - nid, err := share.NewV0Namespace(tmrand.Bytes(7)) + nid, err := gosquare.NewV0Namespace(tmrand.Bytes(7)) require.NoError(t, err) b, err := service.GetAll(ctx, 1, - []share.Namespace{ + []gosquare.Namespace{ blobsWithDiffNamespaces[0].Namespace(), nid, blobsWithDiffNamespaces[1].Namespace(), }, @@ -236,13 +236,13 @@ func TestBlobService_Get(t *testing.T) { proof, ok := res.(*Proof) assert.True(t, ok) - verifyFn := func(t *testing.T, rawShares [][]byte, proof *Proof, namespace share.Namespace) { + verifyFn := func(t *testing.T, rawShares [][]byte, proof *Proof, namespace gosquare.Namespace) { for _, row := range header.DAH.RowRoots { to := 0 for _, p := range *proof { from := to to = p.End() - p.Start() + from - eq := p.VerifyInclusion(square.NewSHA256Hasher(), namespace.Bytes(), rawShares[from:to], row) + eq := p.VerifyInclusion(share.NewSHA256Hasher(), namespace.Bytes(), rawShares[from:to], row) if eq == true { return } @@ -253,7 +253,7 @@ func TestBlobService_Get(t *testing.T) { rawShares, err := BlobsToShares(blobsWithDiffNamespaces[1]) require.NoError(t, err) - verifyFn(t, share.ToBytes(rawShares), proof, blobsWithDiffNamespaces[1].Namespace()) + verifyFn(t, gosquare.ToBytes(rawShares), proof, blobsWithDiffNamespaces[1].Namespace()) }, }, { @@ -358,9 +358,9 @@ func TestBlobService_Get(t *testing.T) { { name: "empty result and err when blobs were not found ", doFn: func() (interface{}, error) { - nid, err := share.NewV0Namespace(tmrand.Bytes(squarens.NamespaceVersionZeroIDSize)) + nid, err := gosquare.NewV0Namespace(tmrand.Bytes(squarens.NamespaceVersionZeroIDSize)) require.NoError(t, err) - return service.GetAll(ctx, 1, []share.Namespace{nid}) + return service.GetAll(ctx, 1, []gosquare.Namespace{nid}) }, expectedResult: func(i interface{}, err error) { blobs, ok := i.([]*Blob) @@ -417,7 +417,7 @@ func TestBlobService_Get(t *testing.T) { GetSharesByNamespace(gomock.Any(), gomock.Any(), gomock.Any()). DoAndReturn( func( - ctx context.Context, h *header.ExtendedHeader, ns share.Namespace, + ctx context.Context, h *header.ExtendedHeader, ns gosquare.Namespace, ) (shwap.NamespaceData, error) { if ns.Equals(blobsWithDiffNamespaces[0].Namespace()) { return nil, errors.New("internal error") @@ -427,7 +427,7 @@ func TestBlobService_Get(t *testing.T) { service.shareGetter = getterWrapper return service.GetAll(ctx, 1, - []share.Namespace{ + []gosquare.Namespace{ blobsWithDiffNamespaces[0].Namespace(), blobsWithSameNamespace[0].Namespace(), }, @@ -465,16 +465,16 @@ func TestService_GetSingleBlobWithoutPadding(t *testing.T) { blobs, err := convertBlobs(appBlob...) require.NoError(t, err) - padding0, err := share.NamespacePaddingShare(blobs[0].Namespace(), share.ShareVersionZero) + padding0, err := gosquare.NamespacePaddingShare(blobs[0].Namespace(), gosquare.ShareVersionZero) require.NoError(t, err) - padding1, err := share.NamespacePaddingShare(blobs[1].Namespace(), share.ShareVersionZero) + padding1, err := gosquare.NamespacePaddingShare(blobs[1].Namespace(), gosquare.ShareVersionZero) require.NoError(t, err) rawShares0, err := BlobsToShares(blobs[0]) require.NoError(t, err) rawShares1, err := BlobsToShares(blobs[1]) require.NoError(t, err) - rawShares := make([]share.Share, 0) + rawShares := make([]gosquare.Share, 0) rawShares = append(rawShares, append(rawShares0, padding0)...) rawShares = append(rawShares, append(rawShares1, padding1)...) service := createService(ctx, t, rawShares) @@ -543,10 +543,10 @@ func TestService_GetAllWithoutPadding(t *testing.T) { blobs, err := convertBlobs(appBlob...) require.NoError(t, err) - rawShares := make([]share.Share, 0) + rawShares := make([]gosquare.Share, 0) require.NoError(t, err) - padding, err := share.NamespacePaddingShare(blobs[0].Namespace(), share.ShareVersionZero) + padding, err := gosquare.NamespacePaddingShare(blobs[0].Namespace(), gosquare.ShareVersionZero) require.NoError(t, err) for i := 0; i < 2; i++ { @@ -567,7 +567,7 @@ func TestService_GetAllWithoutPadding(t *testing.T) { rawShares = append(rawShares, sh...) service := createService(ctx, t, rawShares) - newBlobs, err := service.GetAll(ctx, 1, []share.Namespace{blobs[0].Namespace()}) + newBlobs, err := service.GetAll(ctx, 1, []gosquare.Namespace{blobs[0].Namespace()}) require.NoError(t, err) assert.Equal(t, len(newBlobs), len(blobs)) @@ -590,13 +590,13 @@ func TestService_GetAllWithoutPadding(t *testing.T) { } func TestAllPaddingSharesInEDS(t *testing.T) { - nid, err := share.NewV0Namespace(tmrand.Bytes(7)) + nid, err := gosquare.NewV0Namespace(tmrand.Bytes(7)) require.NoError(t, err) - padding, err := share.NamespacePaddingShare(nid, share.ShareVersionZero) + padding, err := gosquare.NamespacePaddingShare(nid, gosquare.ShareVersionZero) require.NoError(t, err) - rawShares := make([]share.Share, 16) + rawShares := make([]gosquare.Share, 16) for i := 0; i < 16; i++ { rawShares[i] = padding } @@ -605,26 +605,26 @@ func TestAllPaddingSharesInEDS(t *testing.T) { t.Cleanup(cancel) service := createService(ctx, t, rawShares) - newBlobs, err := service.GetAll(ctx, 1, []share.Namespace{nid}) + newBlobs, err := service.GetAll(ctx, 1, []gosquare.Namespace{nid}) require.NoError(t, err) assert.Empty(t, newBlobs) } func TestSkipPaddingsAndRetrieveBlob(t *testing.T) { - nid := share.RandomBlobNamespace() - padding, err := share.NamespacePaddingShare(nid, share.ShareVersionZero) + nid := gosquare.RandomBlobNamespace() + padding, err := gosquare.NamespacePaddingShare(nid, gosquare.ShareVersionZero) require.NoError(t, err) - rawShares := make([]share.Share, 0, 64) + rawShares := make([]gosquare.Share, 0, 64) for i := 0; i < 58; i++ { rawShares = append(rawShares, padding) } - size := blobtest.RawBlobSize(share.FirstSparseShareContentSize * 6) - ns, err := share.NewNamespace(nid.Version(), nid.ID()) + size := blobtest.RawBlobSize(gosquare.FirstSparseShareContentSize * 6) + ns, err := gosquare.NewNamespace(nid.Version(), nid.ID()) require.NoError(t, err) data := tmrand.Bytes(size) - appBlob, err := share.NewBlob(ns, data, share.ShareVersionZero, nil) + appBlob, err := gosquare.NewBlob(ns, data, gosquare.ShareVersionZero, nil) require.NoError(t, err) blobs, err := convertBlobs(appBlob) @@ -638,7 +638,7 @@ func TestSkipPaddingsAndRetrieveBlob(t *testing.T) { t.Cleanup(cancel) service := createService(ctx, t, rawShares) - newBlob, err := service.GetAll(ctx, 1, []share.Namespace{nid}) + newBlob, err := service.GetAll(ctx, 1, []gosquare.Namespace{nid}) require.NoError(t, err) require.Len(t, newBlob, 1) require.True(t, newBlob[0].compareCommitments(blobs[0].Commitment)) @@ -674,7 +674,7 @@ func TestService_Subscribe(t *testing.T) { }) t.Run("subscription with no matching blobs", func(t *testing.T) { - ns, err := share.NewV0Namespace([]byte("nonexist")) + ns, err := gosquare.NewV0Namespace([]byte("nonexist")) require.NoError(t, err) subCh, err := service.Subscribe(ctx, ns) @@ -878,7 +878,7 @@ func createServiceWithSub(ctx context.Context, t testing.TB, blobs []*Blob) *Ser shareGetter := mock.NewMockGetter(ctrl) shareGetter.EXPECT().GetSharesByNamespace(gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes(). - DoAndReturn(func(ctx context.Context, h *header.ExtendedHeader, ns share.Namespace) (shwap.NamespaceData, error) { + DoAndReturn(func(ctx context.Context, h *header.ExtendedHeader, ns gosquare.Namespace) (shwap.NamespaceData, error) { idx := int(h.Height()) - 1 accessor := &eds.Rsmt2D{ExtendedDataSquare: edsses[idx]} nd, err := eds.NamespaceData(ctx, accessor, ns) @@ -887,11 +887,11 @@ func createServiceWithSub(ctx context.Context, t testing.TB, blobs []*Blob) *Ser return NewService(nil, shareGetter, fn, fn2) } -func createService(ctx context.Context, t testing.TB, shares []share.Share) *Service { +func createService(ctx context.Context, t testing.TB, shares []gosquare.Share) *Service { odsSize := int(utils.SquareSize(len(shares))) square, err := rsmt2d.ComputeExtendedDataSquare( - share.ToBytes(shares), - square.DefaultRSMT2DCodec(), + gosquare.ToBytes(shares), + share.DefaultRSMT2DCodec(), wrapper.NewConstructor(uint64(odsSize))) require.NoError(t, err) @@ -899,12 +899,12 @@ func createService(ctx context.Context, t testing.TB, shares []share.Share) *Ser ctrl := gomock.NewController(t) shareGetter := mock.NewMockGetter(ctrl) shareGetter.EXPECT().GetSharesByNamespace(gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes(). - DoAndReturn(func(ctx context.Context, h *header.ExtendedHeader, ns share.Namespace) (shwap.NamespaceData, error) { + DoAndReturn(func(ctx context.Context, h *header.ExtendedHeader, ns gosquare.Namespace) (shwap.NamespaceData, error) { nd, err := eds.NamespaceData(ctx, accessor, ns) return nd, err }) shareGetter.EXPECT().GetShare(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes(). - DoAndReturn(func(ctx context.Context, h *header.ExtendedHeader, row, col int) (share.Share, error) { + DoAndReturn(func(ctx context.Context, h *header.ExtendedHeader, row, col int) (gosquare.Share, error) { s, err := accessor.Sample(ctx, row, col) return s.Share, err }) @@ -995,8 +995,8 @@ func proveAndVerifyShareCommitments(t *testing.T, blobSize int) { func generateCommitmentProofFromBlock( t *testing.T, eds *rsmt2d.ExtendedDataSquare, - ns share.Namespace, - blob *share.Blob, + ns gosquare.Namespace, + blob *gosquare.Blob, dataRoot []byte, ) CommitmentProof { // create the blob from the data @@ -1025,7 +1025,7 @@ func generateCommitmentProofFromBlock( sharesProof, err := pkgproof.NewShareInclusionProofFromEDS( eds, ns, - share.NewRange(startShareIndex, startShareIndex+len(blobShares)), + gosquare.NewRange(startShareIndex, startShareIndex+len(blobShares)), ) require.NoError(t, err) require.NoError(t, sharesProof.Validate(dataRoot)) diff --git a/cmd/cel-shed/shwap.go b/cmd/cel-shed/shwap.go index 60a6d237ac..2d88e59ca9 100644 --- a/cmd/cel-shed/shwap.go +++ b/cmd/cel-shed/shwap.go @@ -7,7 +7,7 @@ import ( "github.com/ipfs/go-cid" "github.com/spf13/cobra" - "github.com/celestiaorg/celestia-node/square/shwap/p2p/bitswap" + "github.com/celestiaorg/celestia-node/share/shwap/p2p/bitswap" ) func init() { diff --git a/cmd/util.go b/cmd/util.go index 16ff39d5d7..c2609b1266 100644 --- a/cmd/util.go +++ b/cmd/util.go @@ -11,7 +11,7 @@ import ( "github.com/spf13/cobra" flag "github.com/spf13/pflag" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/celestia-node/nodebuilder/core" "github.com/celestiaorg/celestia-node/nodebuilder/gateway" @@ -48,14 +48,14 @@ func PrintOutput(data interface{}, err error, formatData func(interface{}) inter // ParseV0Namespace parses a namespace from a base64 or hex string. The param // is expected to be the user-specified portion of a v0 namespace ID (i.e. the // last 10 bytes). -func ParseV0Namespace(param string) (share.Namespace, error) { +func ParseV0Namespace(param string) (gosquare.Namespace, error) { userBytes, err := DecodeToBytes(param) if err != nil { - return share.Namespace{}, err + return gosquare.Namespace{}, err } // if the namespace ID is <= 10 bytes, left pad it with 0s - return share.NewV0Namespace(userBytes) + return gosquare.NewV0Namespace(userBytes) } // DecodeToBytes decodes a Base64 or hex input string into a byte slice. diff --git a/cmd/util_test.go b/cmd/util_test.go index 97dc7cc83c..05f6226639 100644 --- a/cmd/util_test.go +++ b/cmd/util_test.go @@ -6,7 +6,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" ) func Test_parseNamespaceID(t *testing.T) { @@ -77,7 +77,7 @@ func Test_parseNamespaceID(t *testing.T) { } assert.NoError(t, err) - ns, err := share.NewNamespaceFromBytes(tc.want) + ns, err := gosquare.NewNamespaceFromBytes(tc.want) require.NoError(t, err) assert.Equal(t, ns, got) }) diff --git a/core/eds.go b/core/eds.go index b4d4fdfbcb..3104b70824 100644 --- a/core/eds.go +++ b/core/eds.go @@ -11,14 +11,14 @@ import ( "github.com/celestiaorg/celestia-app/v3/pkg/wrapper" "github.com/celestiaorg/go-square/shares" libSquare "github.com/celestiaorg/go-square/v2" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt" "github.com/celestiaorg/rsmt2d" "github.com/celestiaorg/celestia-node/header" "github.com/celestiaorg/celestia-node/pruner" "github.com/celestiaorg/celestia-node/pruner/full" - "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/share" "github.com/celestiaorg/celestia-node/store" ) @@ -27,11 +27,11 @@ import ( // nil is returned in place of the eds. func extendBlock(data types.Data, appVersion uint64, options ...nmt.Option) (*rsmt2d.ExtendedDataSquare, error) { if app.IsEmptyBlock(data, appVersion) { - return square.EmptyEDS(), nil + return share.EmptyEDS(), nil } // Construct the data square from the block's transactions - dataSquare, err := libSquare.Construct( + square, err := libSquare.Construct( data.Txs.ToSliceOfBytes(), appconsts.SquareSizeUpperBound(appVersion), appconsts.SubtreeRootThreshold(appVersion), @@ -39,7 +39,7 @@ func extendBlock(data types.Data, appVersion uint64, options ...nmt.Option) (*rs if err != nil { return nil, err } - return extendShares(share.ToBytes(dataSquare), options...) + return extendShares(gosquare.ToBytes(square), options...) } func extendShares(s [][]byte, options ...nmt.Option) (*rsmt2d.ExtendedDataSquare, error) { diff --git a/core/eds_test.go b/core/eds_test.go index ff4f6be808..3bed7ea94e 100644 --- a/core/eds_test.go +++ b/core/eds_test.go @@ -10,7 +10,7 @@ import ( "github.com/celestiaorg/celestia-app/v3/app" "github.com/celestiaorg/celestia-app/v3/pkg/appconsts" - "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/share" ) // TestTrulyEmptySquare ensures that a truly empty square (square size 1 and no @@ -24,7 +24,7 @@ func TestTrulyEmptySquare(t *testing.T) { eds, err := extendBlock(data, appconsts.LatestVersion) require.NoError(t, err) - require.True(t, eds.Equals(square.EmptyEDS())) + require.True(t, eds.Equals(share.EmptyEDS())) } // TestEmptySquareWithZeroTxs tests that the datahash of a block with no transactions @@ -40,13 +40,13 @@ func TestEmptySquareWithZeroTxs(t *testing.T) { eds, err := extendBlock(data, appconsts.LatestVersion) require.NoError(t, err) - require.True(t, eds.Equals(square.EmptyEDS())) + require.True(t, eds.Equals(share.EmptyEDS())) // force extend the square using an empty block and compare with the min DAH eds, err = app.ExtendBlock(data, appconsts.LatestVersion) require.NoError(t, err) - roots, err := square.NewAxisRoots(eds) + roots, err := share.NewAxisRoots(eds) require.NoError(t, err) - assert.Equal(t, square.EmptyEDSRoots().Hash(), roots.Hash()) + assert.Equal(t, share.EmptyEDSRoots().Hash(), roots.Hash()) } diff --git a/core/exchange_test.go b/core/exchange_test.go index c7c1b6e3ab..c0b925b51d 100644 --- a/core/exchange_test.go +++ b/core/exchange_test.go @@ -14,7 +14,7 @@ import ( "github.com/celestiaorg/celestia-node/header" "github.com/celestiaorg/celestia-node/pruner" - "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/share" "github.com/celestiaorg/celestia-node/store" ) @@ -103,7 +103,7 @@ func TestExchange_DoNotStoreHistoric(t *testing.T) { assert.False(t, has) // empty EDSs are expected to exist in the store, so we skip them - if h.DAH.Equals(square.EmptyEDSRoots()) { + if h.DAH.Equals(share.EmptyEDSRoots()) { continue } has, err = store.HasByHash(ctx, h.DAH.Hash()) @@ -147,7 +147,7 @@ func generateNonEmptyBlocks( fetcher *BlockFetcher, cfg *testnode.Config, cctx testnode.Context, -) []square.DataHash { +) []share.DataHash { // generate several non-empty blocks generateCtx, generateCtxCancel := context.WithCancel(context.Background()) @@ -160,7 +160,7 @@ func generateNonEmptyBlocks( go fillBlocks(t, generateCtx, cfg, cctx) - hashes := make([]square.DataHash, 0, 20) + hashes := make([]share.DataHash, 0, 20) i := 0 for i < 20 { @@ -168,10 +168,10 @@ func generateNonEmptyBlocks( case b, ok := <-sub: require.True(t, ok) - if bytes.Equal(square.EmptyEDSDataHash(), b.Data.Hash()) { + if bytes.Equal(share.EmptyEDSDataHash(), b.Data.Hash()) { continue } - hashes = append(hashes, square.DataHash(b.Data.Hash())) + hashes = append(hashes, share.DataHash(b.Data.Hash())) i++ case <-ctx.Done(): t.Fatal("failed to fill blocks within timeout") diff --git a/core/header_test.go b/core/header_test.go index 87c4378bb4..7b7eb3a7b7 100644 --- a/core/header_test.go +++ b/core/header_test.go @@ -13,7 +13,7 @@ import ( "github.com/celestiaorg/celestia-node/header" "github.com/celestiaorg/celestia-node/header/headertest" - "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/share" ) func TestMakeExtendedHeaderForEmptyBlock(t *testing.T) { @@ -40,7 +40,7 @@ func TestMakeExtendedHeaderForEmptyBlock(t *testing.T) { headerExt, err := header.MakeExtendedHeader(&b.Header, comm, val, eds) require.NoError(t, err) - assert.Equal(t, square.EmptyEDSRoots(), headerExt.DAH) + assert.Equal(t, share.EmptyEDSRoots(), headerExt.DAH) } func TestMismatchedDataHash_ComputedRoot(t *testing.T) { diff --git a/core/listener.go b/core/listener.go index 694675d420..67e532d970 100644 --- a/core/listener.go +++ b/core/listener.go @@ -15,7 +15,7 @@ import ( "github.com/celestiaorg/celestia-node/header" "github.com/celestiaorg/celestia-node/pruner" - "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrexsub" + "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrexsub" "github.com/celestiaorg/celestia-node/store" ) diff --git a/core/listener_no_race_test.go b/core/listener_no_race_test.go index 3c67932104..b7d26fba36 100644 --- a/core/listener_no_race_test.go +++ b/core/listener_no_race_test.go @@ -11,7 +11,7 @@ import ( "github.com/cosmos/cosmos-sdk/client/flags" "github.com/stretchr/testify/require" - "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/share" "github.com/celestiaorg/celestia-node/store" ) @@ -43,7 +43,7 @@ func TestListenerWithNonEmptyBlocks(t *testing.T) { require.NoError(t, err) t.Cleanup(sub.Cancel) - empty := square.EmptyEDSRoots() + empty := share.EmptyEDSRoots() // TODO extract 16 for i := 0; i < 16; i++ { accounts := cfg.Genesis.Accounts() diff --git a/core/listener_test.go b/core/listener_test.go index 54a52864cf..252c6e88c1 100644 --- a/core/listener_test.go +++ b/core/listener_test.go @@ -16,7 +16,7 @@ import ( "github.com/celestiaorg/celestia-node/header" nodep2p "github.com/celestiaorg/celestia-node/nodebuilder/p2p" "github.com/celestiaorg/celestia-node/pruner" - "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrexsub" + "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrexsub" "github.com/celestiaorg/celestia-node/store" ) diff --git a/das/coordinator.go b/das/coordinator.go index c5ad1a668c..aff41bac8c 100644 --- a/das/coordinator.go +++ b/das/coordinator.go @@ -8,7 +8,7 @@ import ( libhead "github.com/celestiaorg/go-header" "github.com/celestiaorg/celestia-node/header" - "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrexsub" + "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrexsub" ) // samplingCoordinator runs and coordinates sampling workers and updates current sampling state diff --git a/das/coordinator_test.go b/das/coordinator_test.go index 3b5b7f793a..a94a9a4e6f 100644 --- a/das/coordinator_test.go +++ b/das/coordinator_test.go @@ -13,8 +13,8 @@ import ( "github.com/tendermint/tendermint/types" "github.com/celestiaorg/celestia-node/header" - "github.com/celestiaorg/celestia-node/square" - "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrexsub" + "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrexsub" ) func TestCoordinator(t *testing.T) { @@ -432,7 +432,7 @@ func (m *mockSampler) discover(ctx context.Context, newHeight uint64, emit liste emit(ctx, &header.ExtendedHeader{ Commit: &types.Commit{}, RawHeader: header.RawHeader{Height: int64(newHeight)}, - DAH: &square.AxisRoots{RowRoots: make([][]byte, 0)}, + DAH: &share.AxisRoots{RowRoots: make([][]byte, 0)}, }) } diff --git a/das/daser.go b/das/daser.go index cf8056ff95..2b0b84ba29 100644 --- a/das/daser.go +++ b/das/daser.go @@ -14,9 +14,9 @@ import ( "github.com/celestiaorg/celestia-node/header" "github.com/celestiaorg/celestia-node/pruner" - "github.com/celestiaorg/celestia-node/square" - "github.com/celestiaorg/celestia-node/square/eds/byzantine" - "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrexsub" + "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/share/eds/byzantine" + "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrexsub" ) var log = logging.Logger("das") @@ -30,7 +30,7 @@ var errOutsideSamplingWindow = fmt.Errorf("skipping header outside of sampling w type DASer struct { params Parameters - da square.Availability + da share.Availability bcast fraud.Broadcaster[*header.ExtendedHeader] hsub libhead.Subscriber[*header.ExtendedHeader] // listens for new headers in the network getter libhead.Getter[*header.ExtendedHeader] // retrieves past headers @@ -51,7 +51,7 @@ type ( // NewDASer creates a new DASer. func NewDASer( - da square.Availability, + da share.Availability, hsub libhead.Subscriber[*header.ExtendedHeader], getter libhead.Getter[*header.ExtendedHeader], dstore datastore.Datastore, diff --git a/das/daser_test.go b/das/daser_test.go index bf4516f40f..c67e5c06e2 100644 --- a/das/daser_test.go +++ b/das/daser_test.go @@ -20,9 +20,9 @@ import ( "github.com/celestiaorg/celestia-node/header" "github.com/celestiaorg/celestia-node/header/headertest" "github.com/celestiaorg/celestia-node/pruner" - "github.com/celestiaorg/celestia-node/square" - "github.com/celestiaorg/celestia-node/square/availability/mocks" - "github.com/celestiaorg/celestia-node/square/eds/edstest" + "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/share/availability/mocks" + "github.com/celestiaorg/celestia-node/share/eds/edstest" ) var timeout = time.Second * 15 @@ -285,7 +285,7 @@ func TestDASer_SamplingWindow(t *testing.T) { // createDASerSubcomponents takes numGetter (number of headers // to store in mockGetter) and numSub (number of headers to store // in the mock header.Subscriber), returning a newly instantiated -// mockGetter, square.Availability, and mock header.Subscriber. +// mockGetter, share.Availability, and mock header.Subscriber. func createDASerSubcomponents( t *testing.T, numGetter, @@ -399,7 +399,7 @@ type benchGetterStub struct { func newBenchGetter() benchGetterStub { return benchGetterStub{header: &header.ExtendedHeader{ - DAH: &square.AxisRoots{RowRoots: make([][]byte, 0)}, + DAH: &share.AxisRoots{RowRoots: make([][]byte, 0)}, }} } @@ -420,7 +420,7 @@ func (m getterStub) GetByHeight(_ context.Context, height uint64) (*header.Exten return &header.ExtendedHeader{ Commit: &types.Commit{}, RawHeader: header.RawHeader{Height: int64(height)}, - DAH: &square.AxisRoots{RowRoots: make([][]byte, 0)}, + DAH: &share.AxisRoots{RowRoots: make([][]byte, 0)}, }, nil } diff --git a/das/worker.go b/das/worker.go index 4da0acd89e..88ca387211 100644 --- a/das/worker.go +++ b/das/worker.go @@ -10,7 +10,7 @@ import ( libhead "github.com/celestiaorg/go-header" "github.com/celestiaorg/celestia-node/header" - "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrexsub" + "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrexsub" ) type jobType string diff --git a/docs/adr/adr-011-blocksync-overhaul-part-1.md b/docs/adr/adr-011-blocksync-overhaul-part-1.md index 50318efa09..0173e78efb 100644 --- a/docs/adr/adr-011-blocksync-overhaul-part-1.md +++ b/docs/adr/adr-011-blocksync-overhaul-part-1.md @@ -301,7 +301,7 @@ The `GetDAH` method returns the DAH (`share.Root`) of the EDS identified by `Dat ```go // GetDAH returns the DataAvailabilityHeader for the EDS identified by DataHash. -func (s *Store) GetDAH(context.Context, square.DataHash) (*share.Root, error) +func (s *Store) GetDAH(context.Context, share.DataHash) (*share.Root, error) ``` ##### `eds.Store.Get` diff --git a/header/headertest/fraud/testing.go b/header/headertest/fraud/testing.go index 0f3b8a11b5..546da7dd58 100644 --- a/header/headertest/fraud/testing.go +++ b/header/headertest/fraud/testing.go @@ -16,8 +16,8 @@ import ( "github.com/celestiaorg/celestia-node/header" "github.com/celestiaorg/celestia-node/header/headertest" - "github.com/celestiaorg/celestia-node/square/eds/edstest" - "github.com/celestiaorg/celestia-node/square/ipld" + "github.com/celestiaorg/celestia-node/share/eds/edstest" + "github.com/celestiaorg/celestia-node/share/ipld" "github.com/celestiaorg/celestia-node/store" ) diff --git a/header/headertest/testing.go b/header/headertest/testing.go index 44d93c9db5..251592a9a5 100644 --- a/header/headertest/testing.go +++ b/header/headertest/testing.go @@ -23,7 +23,7 @@ import ( "github.com/celestiaorg/rsmt2d" "github.com/celestiaorg/celestia-node/header" - "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/share" ) // TestSuite provides everything you need to test chain of Headers. @@ -66,7 +66,7 @@ func NewTestSuite(t *testing.T, numValidators int, blockTime time.Duration) *Tes } func (s *TestSuite) genesis() *header.ExtendedHeader { - dah := square.EmptyEDSRoots() + dah := share.EmptyEDSRoots() gen := RandRawHeader(s.t) @@ -152,7 +152,7 @@ func (s *TestSuite) NextHeader() *header.ExtendedHeader { return s.head } - dah := square.EmptyEDSRoots() + dah := share.EmptyEDSRoots() height := s.Head().Height() + 1 rh := s.GenRawHeader(height, s.Head().Hash(), libhead.Hash(s.Head().Commit.Hash()), dah.Hash()) s.head = &header.ExtendedHeader{ @@ -229,7 +229,7 @@ func RandExtendedHeader(t testing.TB) *header.ExtendedHeader { } func RandExtendedHeaderAtTimestamp(t testing.TB, timestamp time.Time) *header.ExtendedHeader { - dah := square.EmptyEDSRoots() + dah := share.EmptyEDSRoots() rh := RandRawHeader(t) rh.DataHash = dah.Hash() @@ -328,7 +328,7 @@ func ExtendedHeadersFromEdsses(t testing.TB, edsses []*rsmt2d.ExtendedDataSquare for i, eds := range edsses { gen := RandRawHeader(t) - roots, err := square.NewAxisRoots(eds) + roots, err := share.NewAxisRoots(eds) require.NoError(t, err) gen.DataHash = roots.Hash() gen.ValidatorsHash = valSet.Hash() @@ -358,7 +358,7 @@ func ExtendedHeadersFromEdsses(t testing.TB, edsses []*rsmt2d.ExtendedDataSquare func ExtendedHeaderFromEDS(t testing.TB, height uint64, eds *rsmt2d.ExtendedDataSquare) *header.ExtendedHeader { valSet, vals := RandValidatorSet(10, 10) gen := RandRawHeader(t) - dah, err := square.NewAxisRoots(eds) + dah, err := share.NewAxisRoots(eds) require.NoError(t, err) gen.DataHash = dah.Hash() diff --git a/libs/edssser/edssser.go b/libs/edssser/edssser.go index 2c0ad624a4..dfb01e1756 100644 --- a/libs/edssser/edssser.go +++ b/libs/edssser/edssser.go @@ -9,8 +9,8 @@ import ( "testing" "time" - "github.com/celestiaorg/celestia-node/square" - "github.com/celestiaorg/celestia-node/square/eds/edstest" + "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/share/eds/edstest" "github.com/celestiaorg/celestia-node/store" ) @@ -148,13 +148,13 @@ func (ss *EDSsser) put(ctx context.Context, t *testing.T, height int) (time.Dura defer cancel() // divide by 2 to get ODS size as expected by RandEDS - dataSquare := edstest.RandEDS(t, ss.config.EDSSize/2) - roots, err := square.NewAxisRoots(dataSquare) + square := edstest.RandEDS(t, ss.config.EDSSize/2) + roots, err := share.NewAxisRoots(square) if err != nil { return 0, err } now := time.Now() - err = ss.edsstore.PutODSQ4(ctx, roots, uint64(height), dataSquare) + err = ss.edsstore.PutODSQ4(ctx, roots, uint64(height), square) return time.Since(now), err } diff --git a/nodebuilder/blob/blob.go b/nodebuilder/blob/blob.go index 3d14a3487d..f89b58a29e 100644 --- a/nodebuilder/blob/blob.go +++ b/nodebuilder/blob/blob.go @@ -3,7 +3,7 @@ package blob import ( "context" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/celestia-node/blob" ) @@ -19,7 +19,7 @@ type Module interface { // Uses default wallet registered on the Node. Submit(_ context.Context, _ []*blob.Blob, _ *blob.SubmitOptions) (height uint64, _ error) // Get retrieves the blob by commitment under the given namespace and height. - Get(_ context.Context, height uint64, _ share.Namespace, _ blob.Commitment) (*blob.Blob, error) + Get(_ context.Context, height uint64, _ gosquare.Namespace, _ blob.Commitment) (*blob.Blob, error) // GetAll returns all blobs under the given namespaces at the given height. // If all blobs were found without any errors, the user will receive a list of blobs. // If the BlobService couldn't find any blobs under the requested namespaces, @@ -29,21 +29,21 @@ type Module interface { // the user will receive all found blobs along with a combined error message. // // All blobs will preserve the order of the namespaces that were requested. - GetAll(_ context.Context, height uint64, _ []share.Namespace) ([]*blob.Blob, error) + GetAll(_ context.Context, height uint64, _ []gosquare.Namespace) ([]*blob.Blob, error) // GetProof retrieves proofs in the given namespaces at the given height by commitment. - GetProof(_ context.Context, height uint64, _ share.Namespace, _ blob.Commitment) (*blob.Proof, error) + GetProof(_ context.Context, height uint64, _ gosquare.Namespace, _ blob.Commitment) (*blob.Proof, error) // Included checks whether a blob's given commitment(Merkle subtree root) is included at // given height and under the namespace. - Included(_ context.Context, height uint64, _ share.Namespace, _ *blob.Proof, _ blob.Commitment) (bool, error) + Included(_ context.Context, height uint64, _ gosquare.Namespace, _ *blob.Proof, _ blob.Commitment) (bool, error) // GetCommitmentProof generates a commitment proof for a share commitment. GetCommitmentProof( ctx context.Context, height uint64, - namespace share.Namespace, + namespace gosquare.Namespace, shareCommitment []byte, ) (*blob.CommitmentProof, error) // Subscribe to published blobs from the given namespace as they are included. - Subscribe(_ context.Context, _ share.Namespace) (<-chan *blob.SubscriptionResponse, error) + Subscribe(_ context.Context, _ gosquare.Namespace) (<-chan *blob.SubscriptionResponse, error) } type API struct { @@ -56,36 +56,36 @@ type API struct { Get func( context.Context, uint64, - share.Namespace, + gosquare.Namespace, blob.Commitment, ) (*blob.Blob, error) `perm:"read"` GetAll func( context.Context, uint64, - []share.Namespace, + []gosquare.Namespace, ) ([]*blob.Blob, error) `perm:"read"` GetProof func( context.Context, uint64, - share.Namespace, + gosquare.Namespace, blob.Commitment, ) (*blob.Proof, error) `perm:"read"` Included func( context.Context, uint64, - share.Namespace, + gosquare.Namespace, *blob.Proof, blob.Commitment, ) (bool, error) `perm:"read"` GetCommitmentProof func( ctx context.Context, height uint64, - namespace share.Namespace, + namespace gosquare.Namespace, shareCommitment []byte, ) (*blob.CommitmentProof, error) `perm:"read"` Subscribe func( context.Context, - share.Namespace, + gosquare.Namespace, ) (<-chan *blob.SubscriptionResponse, error) `perm:"read"` } } @@ -97,20 +97,20 @@ func (api *API) Submit(ctx context.Context, blobs []*blob.Blob, options *blob.Su func (api *API) Get( ctx context.Context, height uint64, - namespace share.Namespace, + namespace gosquare.Namespace, commitment blob.Commitment, ) (*blob.Blob, error) { return api.Internal.Get(ctx, height, namespace, commitment) } -func (api *API) GetAll(ctx context.Context, height uint64, namespaces []share.Namespace) ([]*blob.Blob, error) { +func (api *API) GetAll(ctx context.Context, height uint64, namespaces []gosquare.Namespace) ([]*blob.Blob, error) { return api.Internal.GetAll(ctx, height, namespaces) } func (api *API) GetProof( ctx context.Context, height uint64, - namespace share.Namespace, + namespace gosquare.Namespace, commitment blob.Commitment, ) (*blob.Proof, error) { return api.Internal.GetProof(ctx, height, namespace, commitment) @@ -119,7 +119,7 @@ func (api *API) GetProof( func (api *API) GetCommitmentProof( ctx context.Context, height uint64, - namespace share.Namespace, + namespace gosquare.Namespace, shareCommitment []byte, ) (*blob.CommitmentProof, error) { return api.Internal.GetCommitmentProof(ctx, height, namespace, shareCommitment) @@ -128,7 +128,7 @@ func (api *API) GetCommitmentProof( func (api *API) Included( ctx context.Context, height uint64, - namespace share.Namespace, + namespace gosquare.Namespace, proof *blob.Proof, commitment blob.Commitment, ) (bool, error) { @@ -137,7 +137,7 @@ func (api *API) Included( func (api *API) Subscribe( ctx context.Context, - namespace share.Namespace, + namespace gosquare.Namespace, ) (<-chan *blob.SubscriptionResponse, error) { return api.Internal.Subscribe(ctx, namespace) } diff --git a/nodebuilder/blob/cmd/blob.go b/nodebuilder/blob/cmd/blob.go index 527ac9b2d7..2be5df5c0c 100644 --- a/nodebuilder/blob/cmd/blob.go +++ b/nodebuilder/blob/cmd/blob.go @@ -11,7 +11,7 @@ import ( "github.com/spf13/cobra" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/celestia-node/blob" cmdnode "github.com/celestiaorg/celestia-node/cmd" @@ -106,7 +106,7 @@ var getAllCmd = &cobra.Command{ return fmt.Errorf("error parsing a namespace: %w", err) } - blobs, err := client.Blob.GetAll(cmd.Context(), height, []share.Namespace{namespace}) + blobs, err := client.Blob.GetAll(cmd.Context(), height, []gosquare.Namespace{namespace}) return cmdnode.PrintOutput(blobs, err, formatData(args[1])) }, } diff --git a/nodebuilder/blob/module.go b/nodebuilder/blob/module.go index d62624adf8..cf07ed3732 100644 --- a/nodebuilder/blob/module.go +++ b/nodebuilder/blob/module.go @@ -9,7 +9,7 @@ import ( "github.com/celestiaorg/celestia-node/header" headerService "github.com/celestiaorg/celestia-node/nodebuilder/header" "github.com/celestiaorg/celestia-node/nodebuilder/state" - "github.com/celestiaorg/celestia-node/square/shwap" + "github.com/celestiaorg/celestia-node/share/shwap" ) func ConstructModule() fx.Option { diff --git a/nodebuilder/core/module.go b/nodebuilder/core/module.go index f186d724c2..441907ce32 100644 --- a/nodebuilder/core/module.go +++ b/nodebuilder/core/module.go @@ -12,7 +12,7 @@ import ( "github.com/celestiaorg/celestia-node/libs/fxutil" "github.com/celestiaorg/celestia-node/nodebuilder/node" "github.com/celestiaorg/celestia-node/nodebuilder/p2p" - "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrexsub" + "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrexsub" "github.com/celestiaorg/celestia-node/store" ) diff --git a/nodebuilder/da/service.go b/nodebuilder/da/service.go index b9a87a629c..ed8e5054b2 100644 --- a/nodebuilder/da/service.go +++ b/nodebuilder/da/service.go @@ -11,7 +11,7 @@ import ( "github.com/rollkit/go-da" "github.com/celestiaorg/celestia-app/v3/pkg/appconsts" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/celestia-node/blob" "github.com/celestiaorg/celestia-node/header" @@ -68,7 +68,7 @@ func (s *Service) Get(ctx context.Context, ids []da.ID, ns da.Namespace) ([]da.B blobs := make([]da.Blob, 0, len(ids)) for _, id := range ids { height, commitment := SplitID(id) - namespace, err := share.NewNamespaceFromBytes(ns) + namespace, err := gosquare.NewNamespaceFromBytes(ns) if err != nil { return nil, err } @@ -85,14 +85,14 @@ func (s *Service) Get(ctx context.Context, ids []da.ID, ns da.Namespace) ([]da.B // GetIDs returns IDs of all Blobs located in DA at given height. func (s *Service) GetIDs(ctx context.Context, height uint64, namespace da.Namespace) (*da.GetIDsResult, error) { - ns, err := share.NewNamespaceFromBytes(namespace) + ns, err := gosquare.NewNamespaceFromBytes(namespace) if err != nil { return nil, err } var ids []da.ID //nolint:prealloc log.Debugw("getting ids", "height", height, "namespace", ns) - blobs, err := s.blobServ.GetAll(ctx, height, []share.Namespace{ns}) + blobs, err := s.blobServ.GetAll(ctx, height, []gosquare.Namespace{ns}) log.Debugw("got ids", "height", height, "namespace", ns) if err != nil { if strings.Contains(err.Error(), blob.ErrBlobNotFound.Error()) { @@ -114,7 +114,7 @@ func (s *Service) GetIDs(ctx context.Context, height uint64, namespace da.Namesp func (s *Service) GetProofs(ctx context.Context, ids []da.ID, namespace da.Namespace) ([]da.Proof, error) { proofs := make([]da.Proof, len(ids)) for i, id := range ids { - ns, err := share.NewNamespaceFromBytes(namespace) + ns, err := gosquare.NewNamespaceFromBytes(namespace) if err != nil { return nil, err } @@ -213,7 +213,7 @@ func (s *Service) blobsAndCommitments( blobs := make([]*blob.Blob, 0, len(daBlobs)) commitments := make([]da.Commitment, 0, len(daBlobs)) for _, daBlob := range daBlobs { - ns, err := share.NewNamespaceFromBytes(namespace) + ns, err := gosquare.NewNamespaceFromBytes(namespace) if err != nil { return nil, nil, err } @@ -247,7 +247,7 @@ func (s *Service) Validate( proofs[i] = blobProof } for i, id := range ids { - ns, err := share.NewNamespaceFromBytes(namespace) + ns, err := gosquare.NewNamespaceFromBytes(namespace) if err != nil { return nil, err } diff --git a/nodebuilder/das/constructors.go b/nodebuilder/das/constructors.go index c3c7602740..8d6f9d1168 100644 --- a/nodebuilder/das/constructors.go +++ b/nodebuilder/das/constructors.go @@ -13,9 +13,9 @@ import ( "github.com/celestiaorg/celestia-node/header" modfraud "github.com/celestiaorg/celestia-node/nodebuilder/fraud" "github.com/celestiaorg/celestia-node/pruner" - "github.com/celestiaorg/celestia-node/square" - "github.com/celestiaorg/celestia-node/square/eds/byzantine" - "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrexsub" + "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/share/eds/byzantine" + "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrexsub" ) var _ Module = (*daserStub)(nil) @@ -39,7 +39,7 @@ func newDaserStub() Module { } func newDASer( - da square.Availability, + da share.Availability, hsub libhead.Subscriber[*header.ExtendedHeader], store libhead.Store[*header.ExtendedHeader], batching datastore.Batching, diff --git a/nodebuilder/fraud/unmarshaler.go b/nodebuilder/fraud/unmarshaler.go index e5cf07272e..d5e0461f01 100644 --- a/nodebuilder/fraud/unmarshaler.go +++ b/nodebuilder/fraud/unmarshaler.go @@ -4,7 +4,7 @@ import ( "github.com/celestiaorg/go-fraud" "github.com/celestiaorg/celestia-node/header" - "github.com/celestiaorg/celestia-node/square/eds/byzantine" + "github.com/celestiaorg/celestia-node/share/eds/byzantine" ) var defaultProofUnmarshaler proofRegistry diff --git a/nodebuilder/header/constructors.go b/nodebuilder/header/constructors.go index 04e36d27ec..23947a8338 100644 --- a/nodebuilder/header/constructors.go +++ b/nodebuilder/header/constructors.go @@ -18,7 +18,7 @@ import ( modfraud "github.com/celestiaorg/celestia-node/nodebuilder/fraud" modp2p "github.com/celestiaorg/celestia-node/nodebuilder/p2p" - "github.com/celestiaorg/celestia-node/square/eds/byzantine" + "github.com/celestiaorg/celestia-node/share/eds/byzantine" ) // newP2PExchange constructs a new Exchange for headers. diff --git a/nodebuilder/node_test.go b/nodebuilder/node_test.go index 91c057b69c..8155d7e081 100644 --- a/nodebuilder/node_test.go +++ b/nodebuilder/node_test.go @@ -17,7 +17,7 @@ import ( "github.com/celestiaorg/celestia-node/header/headertest" "github.com/celestiaorg/celestia-node/nodebuilder/node" - "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/share" ) func TestLifecycle(t *testing.T) { @@ -147,7 +147,7 @@ func TestEmptyBlockExists(t *testing.T) { // ensure an empty block exists in store - eh := headertest.RandExtendedHeaderWithRoot(t, square.EmptyEDSRoots()) + eh := headertest.RandExtendedHeaderWithRoot(t, share.EmptyEDSRoots()) err = node.ShareServ.SharesAvailable(ctx, eh) require.NoError(t, err) diff --git a/nodebuilder/p2p/module.go b/nodebuilder/p2p/module.go index 8c819373ae..9538ce03a5 100644 --- a/nodebuilder/p2p/module.go +++ b/nodebuilder/p2p/module.go @@ -6,7 +6,7 @@ import ( "go.uber.org/fx" "github.com/celestiaorg/celestia-node/nodebuilder/node" - "github.com/celestiaorg/celestia-node/square/ipld" + "github.com/celestiaorg/celestia-node/share/ipld" ) var log = logging.Logger("module/p2p") diff --git a/nodebuilder/p2p/routing.go b/nodebuilder/p2p/routing.go index 65a8a17da2..53f5377524 100644 --- a/nodebuilder/p2p/routing.go +++ b/nodebuilder/p2p/routing.go @@ -10,7 +10,7 @@ import ( "go.uber.org/fx" "github.com/celestiaorg/celestia-node/nodebuilder/node" - "github.com/celestiaorg/celestia-node/square/shwap/p2p/discovery" + "github.com/celestiaorg/celestia-node/share/shwap/p2p/discovery" ) func newDHT( diff --git a/nodebuilder/share/bitswap.go b/nodebuilder/share/bitswap.go index 26784689ff..9316075dfe 100644 --- a/nodebuilder/share/bitswap.go +++ b/nodebuilder/share/bitswap.go @@ -16,7 +16,7 @@ import ( "github.com/celestiaorg/celestia-node/nodebuilder/node" "github.com/celestiaorg/celestia-node/nodebuilder/p2p" - "github.com/celestiaorg/celestia-node/square/shwap/p2p/bitswap" + "github.com/celestiaorg/celestia-node/share/shwap/p2p/bitswap" "github.com/celestiaorg/celestia-node/store" ) diff --git a/nodebuilder/share/cmd/share.go b/nodebuilder/share/cmd/share.go index 8ec42a510a..b4abbabc52 100644 --- a/nodebuilder/share/cmd/share.go +++ b/nodebuilder/share/cmd/share.go @@ -8,7 +8,7 @@ import ( "github.com/spf13/cobra" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" rpc "github.com/celestiaorg/celestia-node/api/rpc/client" cmdnode "github.com/celestiaorg/celestia-node/cmd" @@ -123,7 +123,7 @@ var getShare = &cobra.Command{ s, err := client.Share.GetShare(cmd.Context(), eh, int(row), int(col)) formatter := func(data interface{}) interface{} { - sh, ok := data.(share.Share) + sh, ok := data.(gosquare.Share) if !ok { return data } diff --git a/nodebuilder/share/config.go b/nodebuilder/share/config.go index 4142925a11..31f2eda5a3 100644 --- a/nodebuilder/share/config.go +++ b/nodebuilder/share/config.go @@ -4,11 +4,11 @@ import ( "fmt" "github.com/celestiaorg/celestia-node/nodebuilder/node" - "github.com/celestiaorg/celestia-node/square/availability/light" - "github.com/celestiaorg/celestia-node/square/shwap/p2p/discovery" - "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/peers" - "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrexeds" - "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrexnd" + "github.com/celestiaorg/celestia-node/share/availability/light" + "github.com/celestiaorg/celestia-node/share/shwap/p2p/discovery" + "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/peers" + "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrexeds" + "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrexnd" "github.com/celestiaorg/celestia-node/store" ) diff --git a/nodebuilder/share/constructors.go b/nodebuilder/share/constructors.go index 6637ffac24..62e37477e6 100644 --- a/nodebuilder/share/constructors.go +++ b/nodebuilder/share/constructors.go @@ -7,15 +7,15 @@ import ( headerServ "github.com/celestiaorg/celestia-node/nodebuilder/header" "github.com/celestiaorg/celestia-node/pruner" - "github.com/celestiaorg/celestia-node/square" - "github.com/celestiaorg/celestia-node/square/shwap" - "github.com/celestiaorg/celestia-node/square/shwap/getters" - "github.com/celestiaorg/celestia-node/square/shwap/p2p/bitswap" - "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrex_getter" + "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/share/shwap" + "github.com/celestiaorg/celestia-node/share/shwap/getters" + "github.com/celestiaorg/celestia-node/share/shwap/p2p/bitswap" + "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrex_getter" "github.com/celestiaorg/celestia-node/store" ) -func newShareModule(getter shwap.Getter, avail square.Availability, header headerServ.Module) Module { +func newShareModule(getter shwap.Getter, avail share.Availability, header headerServ.Module) Module { return &module{getter, avail, header} } diff --git a/nodebuilder/share/mocks/api.go b/nodebuilder/share/mocks/api.go index 1498be402a..e2d201757a 100644 --- a/nodebuilder/share/mocks/api.go +++ b/nodebuilder/share/mocks/api.go @@ -10,7 +10,7 @@ import ( header "github.com/celestiaorg/celestia-node/header" share "github.com/celestiaorg/celestia-node/nodebuilder/share" - share0 "github.com/celestiaorg/celestia-node/square" + share0 "github.com/celestiaorg/go-square/v2/share" rsmt2d "github.com/celestiaorg/rsmt2d" gomock "github.com/golang/mock/gomock" ) @@ -69,10 +69,10 @@ func (mr *MockModuleMockRecorder) GetRange(arg0, arg1, arg2, arg3 interface{}) * } // GetShare mocks base method. -func (m *MockModule) GetShare(arg0 context.Context, arg1 *header.ExtendedHeader, arg2, arg3 int) ([]byte, error) { +func (m *MockModule) GetShare(arg0 context.Context, arg1 *header.ExtendedHeader, arg2, arg3 int) (share0.Share, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetShare", arg0, arg1, arg2, arg3) - ret0, _ := ret[0].([]byte) + ret0, _ := ret[0].(share0.Share) ret1, _ := ret[1].(error) return ret0, ret1 } diff --git a/nodebuilder/share/module.go b/nodebuilder/share/module.go index ac73a681e3..f02b4632b5 100644 --- a/nodebuilder/share/module.go +++ b/nodebuilder/share/module.go @@ -12,15 +12,15 @@ import ( "github.com/celestiaorg/celestia-node/nodebuilder/node" modp2p "github.com/celestiaorg/celestia-node/nodebuilder/p2p" lightprune "github.com/celestiaorg/celestia-node/pruner/light" - "github.com/celestiaorg/celestia-node/square" - "github.com/celestiaorg/celestia-node/square/availability/full" - "github.com/celestiaorg/celestia-node/square/availability/light" - "github.com/celestiaorg/celestia-node/square/shwap" - "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/peers" - "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrex_getter" - "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrexeds" - "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrexnd" - "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrexsub" + "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/share/availability/full" + "github.com/celestiaorg/celestia-node/share/availability/light" + "github.com/celestiaorg/celestia-node/share/shwap" + "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/peers" + "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrex_getter" + "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrexeds" + "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrexnd" + "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrexsub" "github.com/celestiaorg/celestia-node/store" ) @@ -233,14 +233,14 @@ func availabilityComponents(tp node.Type, cfg *Config) fx.Option { return la.Close(ctx) }), )), - fx.Provide(func(avail *light.ShareAvailability) square.Availability { + fx.Provide(func(avail *light.ShareAvailability) share.Availability { return avail }), ) case node.Bridge, node.Full: return fx.Options( fx.Provide(full.NewShareAvailability), - fx.Provide(func(avail *full.ShareAvailability) square.Availability { + fx.Provide(func(avail *full.ShareAvailability) share.Availability { return avail }), ) diff --git a/nodebuilder/share/opts.go b/nodebuilder/share/opts.go index 0510c1f11b..cfea26dbb4 100644 --- a/nodebuilder/share/opts.go +++ b/nodebuilder/share/opts.go @@ -3,11 +3,11 @@ package share import ( "errors" - "github.com/celestiaorg/celestia-node/square/shwap/p2p/discovery" - "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/peers" - "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrex_getter" - "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrexeds" - "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrexnd" + "github.com/celestiaorg/celestia-node/share/shwap/p2p/discovery" + "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/peers" + "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrex_getter" + "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrexeds" + "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrexnd" "github.com/celestiaorg/celestia-node/store" ) diff --git a/nodebuilder/share/p2p_constructors.go b/nodebuilder/share/p2p_constructors.go index b505f42e20..576db73c97 100644 --- a/nodebuilder/share/p2p_constructors.go +++ b/nodebuilder/share/p2p_constructors.go @@ -14,9 +14,9 @@ import ( "github.com/celestiaorg/celestia-node/header" "github.com/celestiaorg/celestia-node/nodebuilder/node" modprune "github.com/celestiaorg/celestia-node/nodebuilder/pruner" - "github.com/celestiaorg/celestia-node/square/shwap/p2p/discovery" - "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/peers" - "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrexsub" + "github.com/celestiaorg/celestia-node/share/shwap/p2p/discovery" + "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/peers" + "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrexsub" ) const ( diff --git a/nodebuilder/share/share.go b/nodebuilder/share/share.go index 701180474c..891198687a 100644 --- a/nodebuilder/share/share.go +++ b/nodebuilder/share/share.go @@ -5,15 +5,15 @@ import ( "github.com/tendermint/tendermint/types" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt" "github.com/celestiaorg/rsmt2d" "github.com/celestiaorg/celestia-node/header" headerServ "github.com/celestiaorg/celestia-node/nodebuilder/header" - "github.com/celestiaorg/celestia-node/square" - "github.com/celestiaorg/celestia-node/square/eds" - "github.com/celestiaorg/celestia-node/square/shwap" + "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/share/eds" + "github.com/celestiaorg/celestia-node/share/shwap" ) var _ Module = (*API)(nil) @@ -21,14 +21,14 @@ var _ Module = (*API)(nil) // GetRangeResult wraps the return value of the GetRange endpoint // because Json-RPC doesn't support more than two return values. type GetRangeResult struct { - Shares []share.Share + Shares []gosquare.Share Proof *types.ShareProof } // Module provides access to any data square or block share on the network. // // All Get methods provided on Module follow the following flow: -// 1. Check local storage for the requested Share. +// 1. Check local storage for the requested gosquare. // 2. If exists // * Load from disk // * Return @@ -46,13 +46,13 @@ type Module interface { // ExtendedHeader are available on the Network. SharesAvailable(context.Context, *header.ExtendedHeader) error // GetShare gets a Share by coordinates in EDS. - GetShare(ctx context.Context, header *header.ExtendedHeader, row, col int) (share.Share, error) + GetShare(ctx context.Context, header *header.ExtendedHeader, row, col int) (gosquare.Share, error) // GetEDS gets the full EDS identified by the given extended header. GetEDS(ctx context.Context, header *header.ExtendedHeader) (*rsmt2d.ExtendedDataSquare, error) // GetSharesByNamespace gets all shares from an EDS within the given namespace. // Shares are returned in a row-by-row order if the namespace spans multiple rows. GetSharesByNamespace( - ctx context.Context, header *header.ExtendedHeader, namespace share.Namespace, + ctx context.Context, header *header.ExtendedHeader, namespace gosquare.Namespace, ) (NamespacedShares, error) // GetRange gets a list of shares and their corresponding proof. GetRange(ctx context.Context, height uint64, start, end int) (*GetRangeResult, error) @@ -66,7 +66,7 @@ type API struct { ctx context.Context, header *header.ExtendedHeader, row, col int, - ) (share.Share, error) `perm:"read"` + ) (gosquare.Share, error) `perm:"read"` GetEDS func( ctx context.Context, header *header.ExtendedHeader, @@ -74,7 +74,7 @@ type API struct { GetSharesByNamespace func( ctx context.Context, header *header.ExtendedHeader, - namespace share.Namespace, + namespace gosquare.Namespace, ) (NamespacedShares, error) `perm:"read"` GetRange func( ctx context.Context, @@ -88,7 +88,7 @@ func (api *API) SharesAvailable(ctx context.Context, header *header.ExtendedHead return api.Internal.SharesAvailable(ctx, header) } -func (api *API) GetShare(ctx context.Context, header *header.ExtendedHeader, row, col int) (share.Share, error) { +func (api *API) GetShare(ctx context.Context, header *header.ExtendedHeader, row, col int) (gosquare.Share, error) { return api.Internal.GetShare(ctx, header, row, col) } @@ -103,14 +103,14 @@ func (api *API) GetRange(ctx context.Context, height uint64, start, end int) (*G func (api *API) GetSharesByNamespace( ctx context.Context, header *header.ExtendedHeader, - namespace share.Namespace, + namespace gosquare.Namespace, ) (NamespacedShares, error) { return api.Internal.GetSharesByNamespace(ctx, header, namespace) } type module struct { shwap.Getter - square.Availability + share.Availability hs headerServ.Module } @@ -133,7 +133,7 @@ func (m module) GetRange(ctx context.Context, height uint64, start, end int) (*G return nil, err } - shares, err := share.FromBytes(extendedDataSquare.FlattenedODS()[start:end]) + shares, err := gosquare.FromBytes(extendedDataSquare.FlattenedODS()[start:end]) if err != nil { return nil, err } @@ -146,7 +146,7 @@ func (m module) GetRange(ctx context.Context, height uint64, start, end int) (*G func (m module) GetSharesByNamespace( ctx context.Context, header *header.ExtendedHeader, - namespace share.Namespace, + namespace gosquare.Namespace, ) (NamespacedShares, error) { nd, err := m.Getter.GetSharesByNamespace(ctx, header, namespace) if err != nil { @@ -156,19 +156,19 @@ func (m module) GetSharesByNamespace( } // NamespacedShares represents all shares with proofs within a specific namespace of an EDS. -// This is a copy of the share.NamespacedShares type, that is used to avoid breaking changes +// This is a copy of the gosquare.NamespacedShares type, that is used to avoid breaking changes // in the API. type NamespacedShares []NamespacedRow // NamespacedRow represents all shares with proofs within a specific namespace of a single EDS row. type NamespacedRow struct { - Shares []share.Share `json:"shares"` - Proof *nmt.Proof `json:"proof"` + Shares []gosquare.Share `json:"shares"` + Proof *nmt.Proof `json:"proof"` } // Flatten returns the concatenated slice of all NamespacedRow shares. -func (ns NamespacedShares) Flatten() []share.Share { - var shares []share.Share +func (ns NamespacedShares) Flatten() []gosquare.Share { + var shares []gosquare.Share for _, row := range ns { shares = append(shares, row.Shares...) } diff --git a/nodebuilder/state/core.go b/nodebuilder/state/core.go index f377fe4c6a..39ab732368 100644 --- a/nodebuilder/state/core.go +++ b/nodebuilder/state/core.go @@ -10,7 +10,7 @@ import ( "github.com/celestiaorg/celestia-node/nodebuilder/core" modfraud "github.com/celestiaorg/celestia-node/nodebuilder/fraud" "github.com/celestiaorg/celestia-node/nodebuilder/p2p" - "github.com/celestiaorg/celestia-node/square/eds/byzantine" + "github.com/celestiaorg/celestia-node/share/eds/byzantine" "github.com/celestiaorg/celestia-node/state" ) diff --git a/nodebuilder/state/state.go b/nodebuilder/state/state.go index 7fe2073f8b..d1c2193a33 100644 --- a/nodebuilder/state/state.go +++ b/nodebuilder/state/state.go @@ -5,7 +5,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/staking/types" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/celestia-node/state" ) @@ -39,7 +39,7 @@ type Module interface { // SubmitPayForBlob builds, signs and submits a PayForBlob transaction. SubmitPayForBlob( ctx context.Context, - blobs []*share.Blob, + blobs []*gosquare.Blob, config *state.TxConfig, ) (*state.TxResponse, error) // CancelUnbondingDelegation cancels a user's pending undelegation from a validator. @@ -114,7 +114,7 @@ type API struct { ) (*state.TxResponse, error) `perm:"write"` SubmitPayForBlob func( ctx context.Context, - blobs []*share.Blob, + blobs []*gosquare.Blob, config *state.TxConfig, ) (*state.TxResponse, error) `perm:"write"` CancelUnbondingDelegation func( @@ -188,7 +188,7 @@ func (api *API) Transfer( func (api *API) SubmitPayForBlob( ctx context.Context, - blobs []*share.Blob, + blobs []*gosquare.Blob, config *state.TxConfig, ) (*state.TxResponse, error) { return api.Internal.SubmitPayForBlob(ctx, blobs, config) diff --git a/nodebuilder/state/stub.go b/nodebuilder/state/stub.go index bd26068a52..fb8a1402f2 100644 --- a/nodebuilder/state/stub.go +++ b/nodebuilder/state/stub.go @@ -6,7 +6,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/staking/types" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/celestia-node/state" ) @@ -44,7 +44,7 @@ func (s stubbedStateModule) Transfer( func (s stubbedStateModule) SubmitPayForBlob( context.Context, - []*share.Blob, + []*gosquare.Blob, *state.TxConfig, ) (*state.TxResponse, error) { return nil, ErrNoStateAccess diff --git a/nodebuilder/store.go b/nodebuilder/store.go index e778e9924e..61048c41b3 100644 --- a/nodebuilder/store.go +++ b/nodebuilder/store.go @@ -17,7 +17,7 @@ import ( dsbadger "github.com/ipfs/go-ds-badger4" "github.com/mitchellh/go-homedir" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/celestia-node/libs/keystore" nodemod "github.com/celestiaorg/celestia-node/nodebuilder/node" @@ -276,10 +276,10 @@ func dataPath(base string) string { func constraintBadgerConfig() *dsbadger.Options { opts := dsbadger.DefaultOptions // this must be copied // ValueLog: - // 2mib default => share.Size - makes sure headers and samples are stored in value log + // 2mib default => gosquare.Size - makes sure headers and samples are stored in value log // This *tremendously* reduces the amount of memory used by the node, up to 10 times less during // compaction - opts.ValueThreshold = share.ShareSize + opts.ValueThreshold = gosquare.ShareSize // make sure we don't have any limits for stored headers opts.ValueLogMaxEntries = 100000000 // run value log GC more often to spread the work over time diff --git a/nodebuilder/tests/blob_test.go b/nodebuilder/tests/blob_test.go index 590aed2166..ba949a7aa4 100644 --- a/nodebuilder/tests/blob_test.go +++ b/nodebuilder/tests/blob_test.go @@ -13,7 +13,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/celestia-node/blob" "github.com/celestiaorg/celestia-node/blob/blobtest" @@ -87,7 +87,7 @@ func TestBlobModule(t *testing.T) { doFn: func(t *testing.T) { // https://github.com/celestiaorg/celestia-node/issues/2915 time.Sleep(time.Second) - newBlobs, err := fullClient.Blob.GetAll(ctx, height, []share.Namespace{blobs[0].Namespace()}) + newBlobs, err := fullClient.Blob.GetAll(ctx, height, []gosquare.Namespace{blobs[0].Namespace()}) require.NoError(t, err) require.Len(t, newBlobs, len(appBlobs0)) require.True(t, bytes.Equal(blobs[0].Commitment, newBlobs[0].Commitment)) @@ -126,7 +126,7 @@ func TestBlobModule(t *testing.T) { require.Error(t, err) require.ErrorContains(t, err, blob.ErrBlobNotFound.Error()) - blobs, err := fullClient.Blob.GetAll(ctx, height, []share.Namespace{newBlob.Namespace()}) + blobs, err := fullClient.Blob.GetAll(ctx, height, []gosquare.Namespace{newBlob.Namespace()}) require.NoError(t, err) assert.Empty(t, blobs) }, @@ -203,6 +203,6 @@ func TestBlobModule(t *testing.T) { // convert converts a squareblob.Blob to a blob.Blob. // convert may be deduplicated with convertBlobs from the blob package. -func convert(squareBlob *share.Blob) (nodeBlob *blob.Blob, err error) { +func convert(squareBlob *gosquare.Blob) (nodeBlob *blob.Blob, err error) { return blob.NewBlob(squareBlob.ShareVersion(), squareBlob.Namespace(), squareBlob.Data(), squareBlob.Signer()) } diff --git a/nodebuilder/tests/da_test.go b/nodebuilder/tests/da_test.go index 63961e379f..77708e7c49 100644 --- a/nodebuilder/tests/da_test.go +++ b/nodebuilder/tests/da_test.go @@ -13,7 +13,7 @@ import ( "github.com/stretchr/testify/require" "github.com/celestiaorg/celestia-app/v3/pkg/appconsts" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/celestia-node/blob" "github.com/celestiaorg/celestia-node/blob/blobtest" @@ -27,7 +27,7 @@ func TestDaModule(t *testing.T) { t.Cleanup(cancel) sw := swamp.NewSwamp(t, swamp.WithBlockTime(time.Second)) - namespace, err := share.NewV0Namespace([]byte("namespace")) + namespace, err := gosquare.NewV0Namespace([]byte("namespace")) require.NoError(t, err) require.False(t, namespace.IsReserved()) diff --git a/nodebuilder/tests/fraud_test.go b/nodebuilder/tests/fraud_test.go index f3ec37c157..524b306ac0 100644 --- a/nodebuilder/tests/fraud_test.go +++ b/nodebuilder/tests/fraud_test.go @@ -21,7 +21,7 @@ import ( "github.com/celestiaorg/celestia-node/nodebuilder/core" "github.com/celestiaorg/celestia-node/nodebuilder/node" "github.com/celestiaorg/celestia-node/nodebuilder/tests/swamp" - "github.com/celestiaorg/celestia-node/square/eds/byzantine" + "github.com/celestiaorg/celestia-node/share/eds/byzantine" "github.com/celestiaorg/celestia-node/store" ) diff --git a/nodebuilder/tests/nd_test.go b/nodebuilder/tests/nd_test.go index a7c6e35ffa..04cac8195b 100644 --- a/nodebuilder/tests/nd_test.go +++ b/nodebuilder/tests/nd_test.go @@ -12,16 +12,16 @@ import ( "github.com/stretchr/testify/require" "go.uber.org/fx" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/celestia-node/nodebuilder" "github.com/celestiaorg/celestia-node/nodebuilder/node" "github.com/celestiaorg/celestia-node/nodebuilder/p2p" "github.com/celestiaorg/celestia-node/nodebuilder/tests/swamp" - "github.com/celestiaorg/celestia-node/square/shwap" - "github.com/celestiaorg/celestia-node/square/shwap/getters" - "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrex_getter" - "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrexnd" + "github.com/celestiaorg/celestia-node/share/shwap" + "github.com/celestiaorg/celestia-node/share/shwap/getters" + "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrex_getter" + "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrexnd" "github.com/celestiaorg/celestia-node/store" ) @@ -68,8 +68,8 @@ func TestShrexNDFromLights(t *testing.T) { reqCtx, cancel := context.WithTimeout(ctx, time.Second*5) // ensure to fetch random namespace (not the reserved namespace) - namespace := h.DAH.RowRoots[1][:share.NamespaceSize] - ns, err := share.NewNamespaceFromBytes(namespace) + namespace := h.DAH.RowRoots[1][:gosquare.NamespaceSize] + ns, err := gosquare.NewNamespaceFromBytes(namespace) require.NoError(t, err) expected, err := bridgeClient.Share.GetSharesByNamespace(reqCtx, h, ns) @@ -144,8 +144,8 @@ func TestShrexNDFromLightsWithBadFulls(t *testing.T) { reqCtx, cancel := context.WithTimeout(ctx, time.Second*5) // ensure to fetch random namespace (not the reserved namespace) - namespace := h.DAH.RowRoots[1][:share.NamespaceSize] - ns, err := share.NewNamespaceFromBytes(namespace) + namespace := h.DAH.RowRoots[1][:gosquare.NamespaceSize] + ns, err := gosquare.NewNamespaceFromBytes(namespace) expected, err := bridgeClient.Share.GetSharesByNamespace(reqCtx, h, ns) require.NoError(t, err) require.True(t, len(expected[0].Shares) > 0) diff --git a/nodebuilder/tests/prune_test.go b/nodebuilder/tests/prune_test.go index 14b26a219d..047981102c 100644 --- a/nodebuilder/tests/prune_test.go +++ b/nodebuilder/tests/prune_test.go @@ -13,7 +13,7 @@ import ( "github.com/stretchr/testify/require" "go.uber.org/fx" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/celestia-node/blob" "github.com/celestiaorg/celestia-node/libs/fxutil" @@ -22,11 +22,11 @@ import ( "github.com/celestiaorg/celestia-node/nodebuilder/node" "github.com/celestiaorg/celestia-node/nodebuilder/tests/swamp" "github.com/celestiaorg/celestia-node/pruner" - "github.com/celestiaorg/celestia-node/square" - "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/peers" - "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrex_getter" - "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrexeds" - "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrexnd" + "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/peers" + "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrex_getter" + "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrexeds" + "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrexnd" ) // TestArchivalBlobSync tests whether a LN is able to sync historical blobs from @@ -118,7 +118,7 @@ func TestArchivalBlobSync(t *testing.T) { type archivalBlob struct { blob *blob.Blob height uint64 - root square.DataHash + root share.DataHash } archivalBlobs := make([]*archivalBlob, 0) @@ -127,7 +127,7 @@ func TestArchivalBlobSync(t *testing.T) { eh, err := archivalFN.HeaderServ.GetByHeight(ctx, uint64(i)) require.NoError(t, err) - if bytes.Equal(eh.DataHash, square.EmptyEDSRoots().Hash()) { + if bytes.Equal(eh.DataHash, share.EmptyEDSRoots().Hash()) { i++ continue } @@ -135,7 +135,7 @@ func TestArchivalBlobSync(t *testing.T) { shr, err := archivalFN.ShareServ.GetShare(ctx, eh, 2, 2) require.NoError(t, err) - blobs, err := archivalFN.BlobServ.GetAll(ctx, uint64(i), []share.Namespace{shr.Namespace()}) + blobs, err := archivalFN.BlobServ.GetAll(ctx, uint64(i), []gosquare.Namespace{shr.Namespace()}) require.NoError(t, err) archivalBlobs = append(archivalBlobs, &archivalBlob{ diff --git a/nodebuilder/tests/reconstruct_test.go b/nodebuilder/tests/reconstruct_test.go index f5360395cb..70bcca05be 100644 --- a/nodebuilder/tests/reconstruct_test.go +++ b/nodebuilder/tests/reconstruct_test.go @@ -19,8 +19,8 @@ import ( "github.com/celestiaorg/celestia-node/nodebuilder/node" "github.com/celestiaorg/celestia-node/nodebuilder/p2p" "github.com/celestiaorg/celestia-node/nodebuilder/tests/swamp" - "github.com/celestiaorg/celestia-node/square/availability/light" - "github.com/celestiaorg/celestia-node/square/eds" + "github.com/celestiaorg/celestia-node/share/availability/light" + "github.com/celestiaorg/celestia-node/share/eds" ) /* diff --git a/nodebuilder/tests/sync_test.go b/nodebuilder/tests/sync_test.go index 90baabd218..780619146c 100644 --- a/nodebuilder/tests/sync_test.go +++ b/nodebuilder/tests/sync_test.go @@ -77,7 +77,7 @@ func TestSyncAgainstBridge_NonEmptyChain(t *testing.T) { assert.EqualValues(t, h.Commit.BlockID.Hash, sw.GetCoreBlockHashByHeight(ctx, numBlocks)) // check that the light node has also sampled over the block at height 20 - err = lightClient.Share.SharesAvailable(ctx, h) + err = lightClient.gosquare.SharesAvailable(ctx, h) assert.NoError(t, err) // wait until the entire chain (up to network head) has been sampled @@ -97,7 +97,7 @@ func TestSyncAgainstBridge_NonEmptyChain(t *testing.T) { assert.EqualValues(t, h.Commit.BlockID.Hash, sw.GetCoreBlockHashByHeight(ctx, numBlocks)) // check to ensure the full node can sync the 20th block's data - err = fullClient.Share.SharesAvailable(ctx, h) + err = fullClient.gosquare.SharesAvailable(ctx, h) assert.NoError(t, err) // wait for full node to sync up the blocks from genesis -> network head. @@ -167,7 +167,7 @@ func TestSyncAgainstBridge_EmptyChain(t *testing.T) { assert.EqualValues(t, h.Commit.BlockID.Hash, sw.GetCoreBlockHashByHeight(ctx, numBlocks)) // check that the light node has also sampled over the block at height 20 - err = lightClient.Share.SharesAvailable(ctx, h) + err = lightClient.gosquare.SharesAvailable(ctx, h) assert.NoError(t, err) // wait until the entire chain (up to network head) has been sampled @@ -187,7 +187,7 @@ func TestSyncAgainstBridge_EmptyChain(t *testing.T) { assert.EqualValues(t, h.Commit.BlockID.Hash, sw.GetCoreBlockHashByHeight(ctx, numBlocks)) // check to ensure the full node can sync the 20th block's data - err = fullClient.Share.SharesAvailable(ctx, h) + err = fullClient.gosquare.SharesAvailable(ctx, h) assert.NoError(t, err) // wait for full node to sync up the blocks from genesis -> network head. diff --git a/pruner/light/pruner.go b/pruner/light/pruner.go index bc0e1732ad..5739cd8cee 100644 --- a/pruner/light/pruner.go +++ b/pruner/light/pruner.go @@ -9,8 +9,8 @@ import ( "github.com/celestiaorg/celestia-node/header" "github.com/celestiaorg/celestia-node/pruner" - "github.com/celestiaorg/celestia-node/square" - "github.com/celestiaorg/celestia-node/square/ipld" + "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/share/ipld" ) type Pruner struct { @@ -24,7 +24,7 @@ func NewPruner(bstore blockstore.Blockstore, ds datastore.Batching) pruner.Prune func (p *Pruner) Prune(ctx context.Context, h *header.ExtendedHeader) error { dah := h.DAH - if square.DataHash(dah.Hash()).IsEmptyEDS() { + if share.DataHash(dah.Hash()).IsEmptyEDS() { return nil } @@ -41,6 +41,6 @@ func (p *Pruner) Prune(ctx context.Context, h *header.ExtendedHeader) error { return p.ds.Delete(ctx, rootKey(dah)) } -func rootKey(root *square.AxisRoots) datastore.Key { +func rootKey(root *share.AxisRoots) datastore.Key { return datastore.NewKey(root.String()) } diff --git a/square/availability.go b/share/availability.go similarity index 97% rename from square/availability.go rename to share/availability.go index fe2f29bea0..3373a62276 100644 --- a/square/availability.go +++ b/share/availability.go @@ -1,4 +1,4 @@ -package square +package share import ( "context" diff --git a/square/availability/full/availability.go b/share/availability/full/availability.go similarity index 83% rename from square/availability/full/availability.go rename to share/availability/full/availability.go index af6106cc27..32d889ff67 100644 --- a/square/availability/full/availability.go +++ b/share/availability/full/availability.go @@ -10,17 +10,17 @@ import ( "github.com/celestiaorg/celestia-node/header" "github.com/celestiaorg/celestia-node/pruner" "github.com/celestiaorg/celestia-node/pruner/full" - "github.com/celestiaorg/celestia-node/square" - "github.com/celestiaorg/celestia-node/square/eds/byzantine" - "github.com/celestiaorg/celestia-node/square/shwap" + "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/share/eds/byzantine" + "github.com/celestiaorg/celestia-node/share/shwap" "github.com/celestiaorg/celestia-node/store" ) var log = logging.Logger("share/full") -// ShareAvailability implements square.Availability using the full data square +// ShareAvailability implements share.Availability using the full data square // recovery technique. It is considered "full" because it is required -// to download enough shares to fully reconstruct the data square. +// to download enough shares to fully reconstruct the data share. type ShareAvailability struct { store *store.Store getter shwap.Getter @@ -42,8 +42,8 @@ func NewShareAvailability( func (fa *ShareAvailability) SharesAvailable(ctx context.Context, header *header.ExtendedHeader) error { dah := header.DAH // if the data square is empty, we can safely link the header height in the store to an empty EDS. - if square.DataHash(dah.Hash()).IsEmptyEDS() { - err := fa.store.PutODSQ4(ctx, dah, header.Height(), square.EmptyEDS()) + if share.DataHash(dah.Hash()).IsEmptyEDS() { + err := fa.store.PutODSQ4(ctx, dah, header.Height(), share.EmptyEDS()) if err != nil { return fmt.Errorf("put empty EDS: %w", err) } @@ -71,7 +71,7 @@ func (fa *ShareAvailability) SharesAvailable(ctx context.Context, header *header log.Errorw("availability validation failed", "root", dah.String(), "err", err.Error()) var byzantineErr *byzantine.ErrByzantine if errors.Is(err, shwap.ErrNotFound) || errors.Is(err, context.DeadlineExceeded) && !errors.As(err, &byzantineErr) { - return square.ErrNotAvailable + return share.ErrNotAvailable } return err } diff --git a/square/availability/full/availability_test.go b/share/availability/full/availability_test.go similarity index 86% rename from square/availability/full/availability_test.go rename to share/availability/full/availability_test.go index 4a03cace50..95f8bda533 100644 --- a/square/availability/full/availability_test.go +++ b/share/availability/full/availability_test.go @@ -9,10 +9,10 @@ import ( "github.com/stretchr/testify/require" "github.com/celestiaorg/celestia-node/header/headertest" - "github.com/celestiaorg/celestia-node/square" - "github.com/celestiaorg/celestia-node/square/eds/edstest" - "github.com/celestiaorg/celestia-node/square/shwap" - "github.com/celestiaorg/celestia-node/square/shwap/getters/mock" + "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/share/eds/edstest" + "github.com/celestiaorg/celestia-node/share/shwap" + "github.com/celestiaorg/celestia-node/share/shwap/getters/mock" "github.com/celestiaorg/celestia-node/store" ) @@ -22,7 +22,7 @@ func TestSharesAvailable(t *testing.T) { // RandServiceWithSquare creates a NewShareAvailability inside, so we can test it eds := edstest.RandEDS(t, 16) - roots, err := square.NewAxisRoots(eds) + roots, err := share.NewAxisRoots(eds) require.NoError(t, err) eh := headertest.RandExtendedHeaderWithRoot(t, roots) @@ -51,7 +51,7 @@ func TestSharesAvailable_StoredEds(t *testing.T) { defer cancel() eds := edstest.RandEDS(t, 4) - roots, err := square.NewAxisRoots(eds) + roots, err := share.NewAxisRoots(eds) require.NoError(t, err) eh := headertest.RandExtendedHeaderWithRoot(t, roots) require.NoError(t, err) @@ -82,7 +82,7 @@ func TestSharesAvailable_ErrNotAvailable(t *testing.T) { defer cancel() eds := edstest.RandEDS(t, 4) - roots, err := square.NewAxisRoots(eds) + roots, err := share.NewAxisRoots(eds) eh := headertest.RandExtendedHeaderWithRoot(t, roots) require.NoError(t, err) @@ -94,6 +94,6 @@ func TestSharesAvailable_ErrNotAvailable(t *testing.T) { for _, getterErr := range errors { getter.EXPECT().GetEDS(gomock.Any(), gomock.Any()).Return(nil, getterErr) err := avail.SharesAvailable(ctx, eh) - require.ErrorIs(t, err, square.ErrNotAvailable) + require.ErrorIs(t, err, share.ErrNotAvailable) } } diff --git a/square/availability/full/reconstruction_test.go b/share/availability/full/reconstruction_test.go similarity index 96% rename from square/availability/full/reconstruction_test.go rename to share/availability/full/reconstruction_test.go index e52b75d127..179a458d36 100644 --- a/square/availability/full/reconstruction_test.go +++ b/share/availability/full/reconstruction_test.go @@ -12,10 +12,10 @@ package full // "golang.org/x/sync/errgroup" // // "github.com/celestiaorg/celestia-node/header/headertest" -// "github.com/celestiaorg/celestia-node/square" -// "github.com/celestiaorg/celestia-node/square/availability/light" -// availability_test "github.com/celestiaorg/celestia-node/square/availability/test" -// "github.com/celestiaorg/celestia-node/square/eds" +// "github.com/celestiaorg/celestia-node/share" +// "github.com/celestiaorg/celestia-node/share/availability/light" +// availability_test "github.com/celestiaorg/celestia-node/share/availability/test" +// "github.com/celestiaorg/celestia-node/share/eds" //) // // func init() { @@ -260,7 +260,7 @@ package full // // // check that any of the fulls cannot reconstruct on their own // err := errg.Wait() -// require.ErrorIs(t, err, square.ErrNotAvailable) +// require.ErrorIs(t, err, share.ErrNotAvailable) // cancelErr() // // // but after they connect diff --git a/square/availability/full/testing.go b/share/availability/full/testing.go similarity index 63% rename from square/availability/full/testing.go rename to share/availability/full/testing.go index fae51c53ca..d4e7ee4f0c 100644 --- a/square/availability/full/testing.go +++ b/share/availability/full/testing.go @@ -10,24 +10,24 @@ package full // "github.com/ipfs/go-datastore" // "github.com/stretchr/testify/require" // -// "github.com/celestiaorg/celestia-node/square" -// availability_test "github.com/celestiaorg/celestia-node/square/availability/test" -// "github.com/celestiaorg/celestia-node/square/eds" -// "github.com/celestiaorg/celestia-node/square/getters" -// "github.com/celestiaorg/celestia-node/square/ipld" -// "github.com/celestiaorg/celestia-node/square/p2p/discovery" +// "github.com/celestiaorg/celestia-node/share" +// availability_test "github.com/celestiaorg/celestia-node/share/availability/test" +// "github.com/celestiaorg/celestia-node/share/eds" +// "github.com/celestiaorg/celestia-node/share/getters" +// "github.com/celestiaorg/celestia-node/share/ipld" +// "github.com/celestiaorg/celestia-node/share/p2p/discovery" //) // -//// GetterWithRandSquare provides a share.Getter filled with 'n' NMT -//// trees of 'n' random shares, essentially storing a whole square. -//func GetterWithRandSquare(t *testing.T, n int) (square.Getter, *square.AxisRoots) { +//// GetterWithRandSquare provides a gosquare.Getter filled with 'n' NMT +//// trees of 'n' random shares, essentially storing a whole share. +//func GetterWithRandSquare(t *testing.T, n int) (share.Getter, *share.AxisRoots) { // bServ := ipld.NewMemBlockservice() // getter := shwap.NewIPLDGetter(bServ) // return getter, availability_test.RandFillBS(t, n, bServ) //} // //// RandNode creates a Full Node filled with a random block of the given size. -//func RandNode(dn *availability_test.TestDagNet, squareSize int) (*availability_test.TestNode, *square.AxisRoots) { +//func RandNode(dn *availability_test.TestDagNet, squareSize int) (*availability_test.TestNode, *share.AxisRoots) { // nd := Node(dn) // return nd, availability_test.RandFillBS(dn.T, squareSize, nd.BlockService) //} @@ -40,7 +40,7 @@ package full // return nd //} // -//func TestAvailability(t *testing.T, getter square.Getter) *ShareAvailability { +//func TestAvailability(t *testing.T, getter share.Getter) *ShareAvailability { // params := discovery.DefaultParameters() // params.AdvertiseInterval = time.Second // params.PeersLimit = 10 diff --git a/square/availability/light/availability.go b/share/availability/light/availability.go similarity index 91% rename from square/availability/light/availability.go rename to share/availability/light/availability.go index 222463777f..3665711d1f 100644 --- a/square/availability/light/availability.go +++ b/share/availability/light/availability.go @@ -11,8 +11,8 @@ import ( logging "github.com/ipfs/go-log/v2" "github.com/celestiaorg/celestia-node/header" - "github.com/celestiaorg/celestia-node/square" - "github.com/celestiaorg/celestia-node/square/shwap" + "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/share/shwap" ) var ( @@ -21,7 +21,7 @@ var ( writeBatchSize = 2048 ) -// ShareAvailability implements square.Availability using Data Availability Sampling technique. +// ShareAvailability implements share.Availability using Data Availability Sampling technique. // It is light because it does not require the downloading of all the data to verify // its availability. It is assumed that there are a lot of lightAvailability instances // on the network doing sampling over the same Root to collectively verify its availability. @@ -62,7 +62,7 @@ func NewShareAvailability( func (la *ShareAvailability) SharesAvailable(ctx context.Context, header *header.ExtendedHeader) error { dah := header.DAH // short-circuit if the given root is an empty data square - if square.DataHash(dah.Hash()).IsEmptyEDS() { + if share.DataHash(dah.Hash()).IsEmptyEDS() { return nil } @@ -125,7 +125,7 @@ func (la *ShareAvailability) SharesAvailable(ctx context.Context, header *header if errors.Is(ctx.Err(), context.Canceled) { // Availability did not complete due to context cancellation, return context error instead of - // square.ErrNotAvailable + // share.ErrNotAvailable return ctx.Err() } @@ -144,12 +144,12 @@ func (la *ShareAvailability) SharesAvailable(ctx context.Context, header *header "root", dah.String(), "failed_samples", failedSamples, ) - return square.ErrNotAvailable + return share.ErrNotAvailable } return nil } -func rootKey(root *square.AxisRoots) datastore.Key { +func rootKey(root *share.AxisRoots) datastore.Key { return datastore.NewKey(root.String()) } diff --git a/square/availability/light/availability_test.go b/share/availability/light/availability_test.go similarity index 83% rename from square/availability/light/availability_test.go rename to share/availability/light/availability_test.go index f2bd6d420f..190aa2f7a6 100644 --- a/square/availability/light/availability_test.go +++ b/share/availability/light/availability_test.go @@ -10,16 +10,16 @@ import ( "github.com/ipfs/go-datastore" "github.com/stretchr/testify/require" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" "github.com/celestiaorg/celestia-node/header" "github.com/celestiaorg/celestia-node/header/headertest" - "github.com/celestiaorg/celestia-node/square" - "github.com/celestiaorg/celestia-node/square/eds/edstest" - "github.com/celestiaorg/celestia-node/square/shwap" - "github.com/celestiaorg/celestia-node/square/shwap/getters/mock" - "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex" + "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/share/eds/edstest" + "github.com/celestiaorg/celestia-node/share/shwap" + "github.com/celestiaorg/celestia-node/share/shwap/getters/mock" + "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex" ) func TestSharesAvailableCaches(t *testing.T) { @@ -27,7 +27,7 @@ func TestSharesAvailableCaches(t *testing.T) { defer cancel() eds := edstest.RandEDS(t, 16) - roots, err := square.NewAxisRoots(eds) + roots, err := share.NewAxisRoots(eds) require.NoError(t, err) eh := headertest.RandExtendedHeaderWithRoot(t, roots) @@ -35,11 +35,11 @@ func TestSharesAvailableCaches(t *testing.T) { getter.EXPECT(). GetShare(gomock.Any(), eh, gomock.Any(), gomock.Any()). DoAndReturn( - func(_ context.Context, _ *header.ExtendedHeader, row, col int) (share.Share, error) { + func(_ context.Context, _ *header.ExtendedHeader, row, col int) (gosquare.Share, error) { rawSh := eds.GetCell(uint(row), uint(col)) - sh, err := share.NewShare(rawSh) + sh, err := gosquare.NewShare(rawSh) if err != nil { - return share.Share{}, err + return gosquare.Share{}, err } return *sh, nil }). @@ -72,7 +72,7 @@ func TestSharesAvailableHitsCache(t *testing.T) { getter := mock.NewMockGetter(gomock.NewController(t)) getter.EXPECT(). GetShare(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()). - Return(share.Share{}, shrex.ErrNotFound). + Return(gosquare.Share{}, shrex.ErrNotFound). AnyTimes() ds := datastore.NewMapDatastore() @@ -84,7 +84,7 @@ func TestSharesAvailableHitsCache(t *testing.T) { // store doesn't actually have the eds err := avail.SharesAvailable(ctx, eh) - require.ErrorIs(t, err, square.ErrNotAvailable) + require.ErrorIs(t, err, share.ErrNotAvailable) // put success result in cache err = avail.ds.Put(ctx, rootKey(roots), []byte{}) @@ -104,7 +104,7 @@ func TestSharesAvailableEmptyRoot(t *testing.T) { avail := NewShareAvailability(getter, ds) // request for empty eds - eh := headertest.RandExtendedHeaderWithRoot(t, square.EmptyEDSRoots()) + eh := headertest.RandExtendedHeaderWithRoot(t, share.EmptyEDSRoots()) err := avail.SharesAvailable(ctx, eh) require.NoError(t, err) } @@ -119,17 +119,17 @@ func TestSharesAvailableFailed(t *testing.T) { // create new eds, that is not available by getter eds := edstest.RandEDS(t, 16) - roots, err := square.NewAxisRoots(eds) + roots, err := share.NewAxisRoots(eds) require.NoError(t, err) eh := headertest.RandExtendedHeaderWithRoot(t, roots) // getter doesn't have the eds, so it should fail getter.EXPECT(). GetShare(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()). - Return(share.Share{}, shrex.ErrNotFound). + Return(gosquare.Share{}, shrex.ErrNotFound). AnyTimes() err = avail.SharesAvailable(ctx, eh) - require.ErrorIs(t, err, square.ErrNotAvailable) + require.ErrorIs(t, err, share.ErrNotAvailable) // cache should have failed results now result, err := avail.ds.Get(ctx, rootKey(roots)) @@ -175,15 +175,15 @@ func (m onceGetter) AddSamples(samples []Sample) { } } -func (m onceGetter) GetShare(_ context.Context, _ *header.ExtendedHeader, row, col int) (share.Share, error) { +func (m onceGetter) GetShare(_ context.Context, _ *header.ExtendedHeader, row, col int) (gosquare.Share, error) { m.Lock() defer m.Unlock() s := Sample{Row: uint16(row), Col: uint16(col)} if _, ok := m.available[s]; ok { delete(m.available, s) - return share.Share{}, nil + return gosquare.Share{}, nil } - return share.Share{}, square.ErrNotAvailable + return gosquare.Share{}, share.ErrNotAvailable } func (m onceGetter) GetEDS(_ context.Context, _ *header.ExtendedHeader) (*rsmt2d.ExtendedDataSquare, error) { @@ -193,7 +193,7 @@ func (m onceGetter) GetEDS(_ context.Context, _ *header.ExtendedHeader) (*rsmt2d func (m onceGetter) GetSharesByNamespace( _ context.Context, _ *header.ExtendedHeader, - _ share.Namespace, + _ gosquare.Namespace, ) (shwap.NamespaceData, error) { panic("not implemented") } diff --git a/square/availability/light/options.go b/share/availability/light/options.go similarity index 100% rename from square/availability/light/options.go rename to share/availability/light/options.go diff --git a/square/availability/light/sample.go b/share/availability/light/sample.go similarity index 98% rename from square/availability/light/sample.go rename to share/availability/light/sample.go index c8061cdb1e..c3021b2e1f 100644 --- a/square/availability/light/sample.go +++ b/share/availability/light/sample.go @@ -8,7 +8,7 @@ import ( "math/big" ) -// Sample is a point in 2D space over square. +// Sample is a point in 2D space over share. type Sample struct { Row, Col uint16 } diff --git a/square/availability/light/sample_test.go b/share/availability/light/sample_test.go similarity index 100% rename from square/availability/light/sample_test.go rename to share/availability/light/sample_test.go diff --git a/square/availability/light/testing.go b/share/availability/light/testing.go similarity index 70% rename from square/availability/light/testing.go rename to share/availability/light/testing.go index 224e2425a3..a777a6ac9e 100644 --- a/square/availability/light/testing.go +++ b/share/availability/light/testing.go @@ -13,15 +13,15 @@ package light // // "github.com/celestiaorg/celestia-node/header" // "github.com/celestiaorg/celestia-node/header/headertest" -// "github.com/celestiaorg/celestia-node/square" -// availability_test "github.com/celestiaorg/celestia-node/square/availability/test" -// "github.com/celestiaorg/celestia-node/square/getters" -// "github.com/celestiaorg/celestia-node/square/ipld" +// "github.com/celestiaorg/celestia-node/share" +// availability_test "github.com/celestiaorg/celestia-node/share/availability/test" +// "github.com/celestiaorg/celestia-node/share/getters" +// "github.com/celestiaorg/celestia-node/share/ipld" //) // -//// GetterWithRandSquare provides a share.Getter filled with 'n' NMT trees of 'n' random shares, -//// essentially storing a whole square. -// func GetterWithRandSquare(t *testing.T, n int) (share.Getter, *header.ExtendedHeader) { +//// GetterWithRandSquare provides a gosquare.Getter filled with 'n' NMT trees of 'n' random shares, +//// essentially storing a whole share. +// func GetterWithRandSquare(t *testing.T, n int) (gosquare.Getter, *header.ExtendedHeader) { // bServ := ipld.NewMemBlockservice() // getter := getters.NewIPLDGetter(bServ) // root := availability_test.RandFillBS(t, n, bServ) @@ -31,16 +31,16 @@ package light // return getter, eh //} // -//// EmptyGetter provides an unfilled share.Getter with corresponding blockservice.BlockService than +//// EmptyGetter provides an unfilled gosquare.Getter with corresponding blockservice.BlockService than //// can be filled by the test. -// func EmptyGetter() (share.Getter, blockservice.BlockService) { +// func EmptyGetter() (gosquare.Getter, blockservice.BlockService) { // bServ := ipld.NewMemBlockservice() // getter := getters.NewIPLDGetter(bServ) // return getter, bServ //} // //// RandNode creates a Light Node filled with a random block of the given size. -// func RandNode(dn *availability_test.TestDagNet, squareSize int) (*availability_test.TestNode, *square.AxisRoots) { +// func RandNode(dn *availability_test.TestDagNet, squareSize int) (*availability_test.TestNode, *share.AxisRoots) { // nd := Node(dn) // return nd, availability_test.RandFillBS(dn.T, squareSize, nd.BlockService) //} @@ -53,7 +53,7 @@ package light // return nd //} // -// func TestAvailability(getter share.Getter) *ShareAvailability { +// func TestAvailability(getter gosquare.Getter) *ShareAvailability { // ds := datastore.NewMapDatastore() // return NewShareAvailability(getter, ds) //} @@ -84,15 +84,15 @@ package light // } //} // -// func (m onceGetter) GetShare(_ context.Context, _ *header.ExtendedHeader, row, col int) (share.Share, error) { +// func (m onceGetter) GetShare(_ context.Context, _ *header.ExtendedHeader, row, col int) (gosquare.Share, error) { // m.Lock() // defer m.Unlock() // s := Sample{Row: uint16(row), Col: uint16(col)} // if _, ok := m.available[s]; ok { // delete(m.available, s) -// return share.Share{}, nil +// return gosquare.Share{}, nil // } -// return share.Share{}, square.ErrNotAvailable +// return gosquare.Share{}, share.ErrNotAvailable //} // // func (m onceGetter) GetEDS(_ context.Context, _ *header.ExtendedHeader) (*rsmt2d.ExtendedDataSquare, error) { @@ -102,7 +102,7 @@ package light // func (m onceGetter) GetSharesByNamespace( // _ context.Context, // _ *header.ExtendedHeader, -// _ share.Namespace, -// ) (share.NamespacedShares, error) { +// _ gosquare.Namespace, +// ) (gosquare.NamespacedShares, error) { // panic("not implemented") // } diff --git a/square/availability/mocks/availability.go b/share/availability/mocks/availability.go similarity index 100% rename from square/availability/mocks/availability.go rename to share/availability/mocks/availability.go diff --git a/square/availability/test/testing.go b/share/availability/test/testing.go similarity index 92% rename from square/availability/test/testing.go rename to share/availability/test/testing.go index 6296290c4c..1db8a5433b 100644 --- a/square/availability/test/testing.go +++ b/share/availability/test/testing.go @@ -17,24 +17,24 @@ import ( mocknet "github.com/libp2p/go-libp2p/p2p/net/mock" "github.com/stretchr/testify/require" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" - "github.com/celestiaorg/celestia-node/square" - "github.com/celestiaorg/celestia-node/square/ipld" - "github.com/celestiaorg/celestia-node/square/shwap" + "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/share/ipld" + "github.com/celestiaorg/celestia-node/share/shwap" ) // RandFillBS fills the given BlockService with a random block of a given size. -func RandFillBS(t *testing.T, n int, bServ blockservice.BlockService) *square.AxisRoots { - shares := share.RandShares(n * n) +func RandFillBS(t *testing.T, n int, bServ blockservice.BlockService) *share.AxisRoots { + shares := gosquare.RandShares(n * n) return FillBS(t, bServ, shares) } // FillBS fills the given BlockService with the given shares. -func FillBS(t *testing.T, bServ blockservice.BlockService, shares []share.Share) *square.AxisRoots { +func FillBS(t *testing.T, bServ blockservice.BlockService, shares []gosquare.Share) *share.AxisRoots { eds, err := ipld.AddShares(context.TODO(), shares, bServ) require.NoError(t, err) - roots, err := square.NewAxisRoots(eds) + roots, err := share.NewAxisRoots(eds) require.NoError(t, err) return roots } @@ -42,7 +42,7 @@ func FillBS(t *testing.T, bServ blockservice.BlockService, shares []share.Share) type TestNode struct { net *TestDagNet shwap.Getter - square.Availability + share.Availability blockservice.BlockService host.Host } diff --git a/square/doc.go b/share/doc.go similarity index 88% rename from square/doc.go rename to share/doc.go index c28ee5cdab..90dea3f243 100644 --- a/square/doc.go +++ b/share/doc.go @@ -1,5 +1,5 @@ /* -Package square contains logic related to the retrieval and random sampling of shares of +package share contains logic related to the retrieval and random sampling of shares of block data. Though this package contains several useful methods for getting specific shares and/or @@ -14,4 +14,4 @@ the block's availability on the network). Full Availability implementation samples for as many shares as necessary to fully reconstruct the block data. */ -package square +package share diff --git a/square/eds/accessor.go b/share/eds/accessor.go similarity index 72% rename from square/eds/accessor.go rename to share/eds/accessor.go index a290d2aed0..4dc4732a1e 100644 --- a/square/eds/accessor.go +++ b/share/eds/accessor.go @@ -4,24 +4,24 @@ import ( "context" "io" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/square" - "github.com/celestiaorg/celestia-node/square/shwap" + "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/share/shwap" ) // EmptyAccessor is an accessor of an empty EDS block. -var EmptyAccessor = &Rsmt2D{ExtendedDataSquare: square.EmptyEDS()} +var EmptyAccessor = &Rsmt2D{ExtendedDataSquare: share.EmptyEDS()} // Accessor is an interface for accessing extended data square data. type Accessor interface { // Size returns square size of the Accessor. Size(ctx context.Context) int // DataHash returns data hash of the Accessor. - DataHash(ctx context.Context) (square.DataHash, error) - // AxisRoots returns square.AxisRoots (DataAvailabilityHeader) of the Accessor. - AxisRoots(ctx context.Context) (*square.AxisRoots, error) + DataHash(ctx context.Context) (share.DataHash, error) + // AxisRoots returns share.AxisRoots (DataAvailabilityHeader) of the Accessor. + AxisRoots(ctx context.Context) (*share.AxisRoots, error) // Sample returns share and corresponding proof for row and column indices. Implementation can // choose which axis to use for proof. Chosen axis for proof should be indicated in the returned // Sample. @@ -30,9 +30,9 @@ type Accessor interface { // implementation. Implementations should indicate the side in the returned AxisHalf. AxisHalf(ctx context.Context, axisType rsmt2d.Axis, axisIdx int) (AxisHalf, error) // RowNamespaceData returns data for the given namespace and row index. - RowNamespaceData(ctx context.Context, namespace share.Namespace, rowIdx int) (shwap.RowNamespaceData, error) + RowNamespaceData(ctx context.Context, namespace gosquare.Namespace, rowIdx int) (shwap.RowNamespaceData, error) // Shares returns data (ODS) shares extracted from the Accessor. - Shares(ctx context.Context) ([]share.Share, error) + Shares(ctx context.Context) ([]gosquare.Share, error) } // AccessorStreamer is an interface that groups Accessor and Streamer interfaces. diff --git a/square/eds/axis_half.go b/share/eds/axis_half.go similarity index 62% rename from square/eds/axis_half.go rename to share/eds/axis_half.go index d5ef406be8..37ad7dede6 100644 --- a/square/eds/axis_half.go +++ b/share/eds/axis_half.go @@ -3,17 +3,17 @@ package eds import ( "fmt" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" - "github.com/celestiaorg/celestia-node/square" - "github.com/celestiaorg/celestia-node/square/shwap" + "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/share/shwap" ) -var codec = square.DefaultRSMT2DCodec() +var codec = share.DefaultRSMT2DCodec() // AxisHalf represents a half of data for a row or column in the EDS. type AxisHalf struct { - Shares []share.Share + Shares []gosquare.Share // IsParity indicates whether the half is parity or data. IsParity bool } @@ -28,7 +28,7 @@ func (a AxisHalf) ToRow() shwap.Row { } // Extended returns full axis shares from half axis shares. -func (a AxisHalf) Extended() ([]share.Share, error) { +func (a AxisHalf) Extended() ([]gosquare.Share, error) { if a.IsParity { return reconstructShares(a.Shares) } @@ -36,42 +36,42 @@ func (a AxisHalf) Extended() ([]share.Share, error) { } // extendShares constructs full axis shares from original half axis shares. -func extendShares(original []share.Share) ([]share.Share, error) { +func extendShares(original []gosquare.Share) ([]gosquare.Share, error) { if len(original) == 0 { return nil, fmt.Errorf("original shares are empty") } - parity, err := codec.Encode(share.ToBytes(original)) + parity, err := codec.Encode(gosquare.ToBytes(original)) if err != nil { return nil, fmt.Errorf("encoding: %w", err) } - parityShrs, err := share.FromBytes(parity) + parityShrs, err := gosquare.FromBytes(parity) if err != nil { return nil, err } sqLen := len(original) * 2 - shares := make([]share.Share, sqLen) + shares := make([]gosquare.Share, sqLen) copy(shares, original) copy(shares[sqLen/2:], parityShrs) return shares, nil } -func reconstructShares(parity []share.Share) ([]share.Share, error) { +func reconstructShares(parity []gosquare.Share) ([]gosquare.Share, error) { if len(parity) == 0 { return nil, fmt.Errorf("parity shares are empty") } sqLen := len(parity) * 2 - shares := make([]share.Share, sqLen) + shares := make([]gosquare.Share, sqLen) for i := sqLen / 2; i < sqLen; i++ { shares[i] = parity[i-sqLen/2] } - shrs, err := codec.Decode(share.ToBytes(shares)) + shrs, err := codec.Decode(gosquare.ToBytes(shares)) if err != nil { return nil, fmt.Errorf("reconstructing: %w", err) } - return share.FromBytes(shrs) + return gosquare.FromBytes(shrs) } diff --git a/square/eds/axis_half_test.go b/share/eds/axis_half_test.go similarity index 84% rename from square/eds/axis_half_test.go rename to share/eds/axis_half_test.go index 6974080523..77165eabce 100644 --- a/square/eds/axis_half_test.go +++ b/share/eds/axis_half_test.go @@ -5,11 +5,11 @@ import ( "github.com/stretchr/testify/require" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" ) func TestExtendAxisHalf(t *testing.T) { - shares := share.RandShares(16) + shares := gosquare.RandShares(16) original := AxisHalf{ Shares: shares, diff --git a/square/eds/byzantine/bad_encoding.go b/share/eds/byzantine/bad_encoding.go similarity index 97% rename from square/eds/byzantine/bad_encoding.go rename to share/eds/byzantine/bad_encoding.go index 8687e7ce1f..8b4586d83c 100644 --- a/square/eds/byzantine/bad_encoding.go +++ b/share/eds/byzantine/bad_encoding.go @@ -10,8 +10,8 @@ import ( "github.com/celestiaorg/rsmt2d" "github.com/celestiaorg/celestia-node/header" - "github.com/celestiaorg/celestia-node/square" - pb "github.com/celestiaorg/celestia-node/square/eds/byzantine/pb" + "github.com/celestiaorg/celestia-node/share" + pb "github.com/celestiaorg/celestia-node/share/eds/byzantine/pb" ) const ( @@ -152,7 +152,7 @@ func (p *BadEncodingProof) Validate(hdr *header.ExtendedHeader) error { // Since p.Shares should contain all the shares from either a row or a // column, it should exactly match the number of row roots. In this // context, the number of row roots is the width of the extended data - // square. + // share. log.Infof("%s: %s (%d >= %d)", invalidProofPrefix, errIncorrectAmountOfShares, int(p.Index), width, ) @@ -191,7 +191,7 @@ func (p *BadEncodingProof) Validate(hdr *header.ExtendedHeader) error { shares[index] = shr.Share.ToBytes() } - codec := square.DefaultRSMT2DCodec() + codec := share.DefaultRSMT2DCodec() // We can conclude that the proof is valid in case we proved the inclusion of `Shares` but // the row/col can't be reconstructed, or the building of NMTree fails. diff --git a/square/eds/byzantine/bad_encoding_test.go b/share/eds/byzantine/bad_encoding_test.go similarity index 92% rename from square/eds/byzantine/bad_encoding_test.go rename to share/eds/byzantine/bad_encoding_test.go index c226b2a5cb..4a849aaaa0 100644 --- a/square/eds/byzantine/bad_encoding_test.go +++ b/share/eds/byzantine/bad_encoding_test.go @@ -14,14 +14,14 @@ import ( core "github.com/tendermint/tendermint/types" "github.com/celestiaorg/celestia-app/v3/test/util/malicious" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt" "github.com/celestiaorg/rsmt2d" "github.com/celestiaorg/celestia-node/header" - "github.com/celestiaorg/celestia-node/square" - "github.com/celestiaorg/celestia-node/square/eds/edstest" - "github.com/celestiaorg/celestia-node/square/ipld" + "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/share/eds/edstest" + "github.com/celestiaorg/celestia-node/share/ipld" ) func TestBEFP_Validate(t *testing.T) { @@ -30,7 +30,7 @@ func TestBEFP_Validate(t *testing.T) { bServ := ipld.NewMemBlockservice() byzSquare := edstest.RandByzantineEDS(t, 16) - roots, err := square.NewAxisRoots(byzSquare) + roots, err := share.NewAxisRoots(byzSquare) require.NoError(t, err) err = ipld.ImportEDS(ctx, byzSquare, bServ) require.NoError(t, err) @@ -64,7 +64,7 @@ func TestBEFP_Validate(t *testing.T) { name: "invalid BEFP for valid header", prepareFn: func() error { validSquare := edstest.RandEDS(t, 2) - validRoots, err := square.NewAxisRoots(validSquare) + validRoots, err := share.NewAxisRoots(validSquare) require.NoError(t, err) err = ipld.ImportEDS(ctx, validSquare, bServ) require.NoError(t, err) @@ -89,7 +89,7 @@ func TestBEFP_Validate(t *testing.T) { name: "incorrect share with Proof", prepareFn: func() error { // break the first shareWithProof to test negative case - sh := share.RandShares(2) + sh := gosquare.RandShares(2) nmtProof := nmt.NewInclusionProof(0, 1, nil, false) befp.Shares[0] = &ShareWithProof{sh[0], &nmtProof, rsmt2d.Row} return proof.Validate(&header.ExtendedHeader{DAH: roots}) @@ -160,12 +160,12 @@ func TestIncorrectBadEncodingFraudProof(t *testing.T) { bServ := ipld.NewMemBlockservice() squareSize := 8 - shares := share.RandShares(squareSize * squareSize) + shares := gosquare.RandShares(squareSize * squareSize) eds, err := ipld.AddShares(ctx, shares, bServ) require.NoError(t, err) - roots, err := square.NewAxisRoots(eds) + roots, err := share.NewAxisRoots(eds) require.NoError(t, err) // get an arbitrary row @@ -215,12 +215,12 @@ func TestBEFP_ValidateOutOfOrderShares(t *testing.T) { batchAddr := ipld.NewNmtNodeAdder(ctx, bServ, ipld.MaxSizeBatchOption(size*2)) eds, err := rsmt2d.ImportExtendedDataSquare(shares, - square.DefaultRSMT2DCodec(), + share.DefaultRSMT2DCodec(), malicious.NewConstructor(uint64(size), nmt.NodeVisitor(batchAddr.Visit)), ) require.NoError(t, err, "failure to recompute the extended data square") - roots, err := square.NewAxisRoots(eds) + roots, err := share.NewAxisRoots(eds) require.NoError(t, err) var errRsmt2d *rsmt2d.ErrByzantineData @@ -252,7 +252,7 @@ func newNamespacedBlockService() *namespacedBlockService { sha256NamespaceFlagged := uint64(0x7701) // register the nmt hasher to validate the order of namespaces mhcore.Register(sha256NamespaceFlagged, func() hash.Hash { - nh := nmt.NewNmtHasher(square.NewSHA256Hasher(), share.NamespaceSize, true) + nh := nmt.NewNmtHasher(share.NewSHA256Hasher(), gosquare.NamespaceSize, true) nh.Reset() return nh }) @@ -265,7 +265,7 @@ func newNamespacedBlockService() *namespacedBlockService { Codec: sha256NamespaceFlagged, MhType: sha256NamespaceFlagged, // equals to NmtHasher.Size() - MhLength: square.NewSHA256Hasher().Size() + 2*share.NamespaceSize, + MhLength: share.NewSHA256Hasher().Size() + 2*gosquare.NamespaceSize, } return bs } diff --git a/square/eds/byzantine/byzantine.go b/share/eds/byzantine/byzantine.go similarity index 87% rename from square/eds/byzantine/byzantine.go rename to share/eds/byzantine/byzantine.go index 80f015529c..cd0c54b9fc 100644 --- a/square/eds/byzantine/byzantine.go +++ b/share/eds/byzantine/byzantine.go @@ -6,18 +6,18 @@ import ( "github.com/ipfs/boxo/blockstore" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/square" - "github.com/celestiaorg/celestia-node/square/ipld" + "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/share/ipld" ) // ErrByzantine is a thrown when recovered data square is not correct // (merkle proofs do not match parity erasure-coding data). // // It is converted from rsmt2d.ByzantineRow/Col + -// Merkle Proof for each share. +// Merkle Proof for each gosquare. type ErrByzantine struct { Index uint32 Shares []*ShareWithProof @@ -33,7 +33,7 @@ func (e *ErrByzantine) Error() string { func NewErrByzantine( ctx context.Context, bStore blockstore.Blockstore, - roots *square.AxisRoots, + roots *share.AxisRoots, errByz *rsmt2d.ErrByzantineData, ) error { sharesWithProof := make([]*ShareWithProof, len(errByz.Shares)) @@ -43,7 +43,7 @@ func NewErrByzantine( if len(shr) == 0 { continue } - sh, err := share.NewShare(shr) + sh, err := gosquare.NewShare(shr) if err != nil { log.Warn("failed to create share", "index", index, "err", err) continue diff --git a/square/eds/byzantine/pb/share.pb.go b/share/eds/byzantine/pb/share.pb.go similarity index 87% rename from square/eds/byzantine/pb/share.pb.go rename to share/eds/byzantine/pb/share.pb.go index d31b409560..af79d48b13 100644 --- a/square/eds/byzantine/pb/share.pb.go +++ b/share/eds/byzantine/pb/share.pb.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: square/eds/byzantine/pb/share.proto +// source: share/eds/byzantine/pb/share.proto package share_eds_byzantine_pb @@ -45,7 +45,7 @@ func (x Axis) String() string { } func (Axis) EnumDescriptor() ([]byte, []int) { - return fileDescriptor_5c467604cd602917, []int{0} + return fileDescriptor_d28ce8f160a920d1, []int{0} } type Share struct { @@ -58,7 +58,7 @@ func (m *Share) Reset() { *m = Share{} } func (m *Share) String() string { return proto.CompactTextString(m) } func (*Share) ProtoMessage() {} func (*Share) Descriptor() ([]byte, []int) { - return fileDescriptor_5c467604cd602917, []int{0} + return fileDescriptor_d28ce8f160a920d1, []int{0} } func (m *Share) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -120,7 +120,7 @@ func (m *BadEncoding) Reset() { *m = BadEncoding{} } func (m *BadEncoding) String() string { return proto.CompactTextString(m) } func (*BadEncoding) ProtoMessage() {} func (*BadEncoding) Descriptor() ([]byte, []int) { - return fileDescriptor_5c467604cd602917, []int{1} + return fileDescriptor_d28ce8f160a920d1, []int{1} } func (m *BadEncoding) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -191,31 +191,31 @@ func init() { } func init() { - proto.RegisterFile("square/eds/byzantine/pb/share.proto", fileDescriptor_5c467604cd602917) -} - -var fileDescriptor_5c467604cd602917 = []byte{ - // 316 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x91, 0xc1, 0x4b, 0xfb, 0x30, - 0x1c, 0xc5, 0x9b, 0xdf, 0xda, 0xfd, 0xf0, 0x3b, 0x9d, 0x23, 0xc8, 0x08, 0xa2, 0xa1, 0x4c, 0x84, - 0xe2, 0x21, 0x95, 0x89, 0x17, 0x6f, 0x4e, 0x85, 0x09, 0xc2, 0x24, 0x1e, 0x3c, 0x27, 0x26, 0x6e, - 0xbd, 0xb4, 0xb5, 0xa9, 0x50, 0x3d, 0xf8, 0x37, 0xf8, 0x47, 0x79, 0xf0, 0xb8, 0xa3, 0x47, 0x69, - 0xff, 0x11, 0x69, 0x5a, 0xd4, 0x83, 0x82, 0xb7, 0xf7, 0x5e, 0x3e, 0x21, 0xef, 0x11, 0xd8, 0x31, - 0x77, 0xf7, 0x22, 0xd3, 0xa1, 0x56, 0x26, 0x94, 0x0f, 0x8f, 0x22, 0xce, 0xa3, 0x58, 0x87, 0xa9, - 0x0c, 0xcd, 0x42, 0x64, 0x9a, 0xa5, 0x59, 0x92, 0x27, 0x78, 0xd8, 0x18, 0xad, 0x0c, 0xfb, 0x64, - 0x58, 0x2a, 0x37, 0xfb, 0xa9, 0x0c, 0xd3, 0x2c, 0x49, 0x6e, 0x1b, 0x6e, 0xf4, 0x04, 0xde, 0x55, - 0x4d, 0x62, 0x0c, 0xee, 0xa9, 0xc8, 0x05, 0x41, 0x3e, 0x0a, 0x56, 0xb9, 0xd5, 0x78, 0x17, 0xbc, - 0xcb, 0x9a, 0x25, 0xff, 0x7c, 0x14, 0xf4, 0xc6, 0xeb, 0xac, 0xbd, 0x29, 0x99, 0x8d, 0x79, 0x73, - 0x8a, 0x8f, 0x60, 0xc5, 0x8a, 0xe3, 0x22, 0x32, 0xa4, 0xe3, 0xa3, 0xa0, 0x3f, 0xde, 0x62, 0x3f, - 0xbf, 0xcf, 0x44, 0x11, 0x19, 0xfe, 0x85, 0x8f, 0x5e, 0x10, 0xf4, 0x26, 0x42, 0x9d, 0xc5, 0x37, - 0x89, 0x8a, 0xe2, 0x39, 0xa6, 0x00, 0x53, 0x2d, 0x94, 0xce, 0xa6, 0xc2, 0x2c, 0xda, 0x32, 0xdf, - 0x12, 0x3c, 0x84, 0xee, 0x54, 0x47, 0xf3, 0x45, 0x6e, 0x3b, 0xb9, 0xbc, 0x75, 0xf8, 0x10, 0xba, - 0x76, 0x47, 0x5d, 0xa0, 0x13, 0xf4, 0xc6, 0xdb, 0xbf, 0x15, 0xb0, 0x14, 0x6f, 0x61, 0xbc, 0x01, - 0xde, 0x79, 0xac, 0x74, 0x41, 0x5c, 0x1f, 0x05, 0x6b, 0xbc, 0x31, 0x78, 0x1f, 0x5c, 0xbb, 0xc5, - 0xfb, 0xc3, 0x16, 0x4b, 0xee, 0x11, 0x70, 0x6b, 0x87, 0xff, 0x43, 0x87, 0xcf, 0xae, 0x07, 0x4e, - 0x2d, 0x4e, 0x66, 0x17, 0x03, 0x34, 0x21, 0xaf, 0x25, 0x45, 0xcb, 0x92, 0xa2, 0xf7, 0x92, 0xa2, - 0xe7, 0x8a, 0x3a, 0xcb, 0x8a, 0x3a, 0x6f, 0x15, 0x75, 0x64, 0xd7, 0xfe, 0xc0, 0xc1, 0x47, 0x00, - 0x00, 0x00, 0xff, 0xff, 0x7c, 0x07, 0xc6, 0x14, 0xd0, 0x01, 0x00, 0x00, + proto.RegisterFile("share/eds/byzantine/pb/share.proto", fileDescriptor_d28ce8f160a920d1) +} + +var fileDescriptor_d28ce8f160a920d1 = []byte{ + // 310 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x91, 0x31, 0x4b, 0xc4, 0x30, + 0x1c, 0xc5, 0x1b, 0xaf, 0x3d, 0xf1, 0x7f, 0x7a, 0x1e, 0x41, 0x8e, 0x20, 0x1a, 0xca, 0x81, 0x50, + 0x1c, 0x52, 0x39, 0x71, 0x71, 0xf3, 0x54, 0x38, 0x41, 0x38, 0x89, 0x83, 0x73, 0x62, 0xe2, 0xb5, + 0x4b, 0x5b, 0x9a, 0x0e, 0xd5, 0xc1, 0xcf, 0xe0, 0x87, 0x72, 0x70, 0xbc, 0xd1, 0x51, 0xda, 0x2f, + 0x22, 0x4d, 0x8b, 0x3a, 0x28, 0xb8, 0xbd, 0xf7, 0xf2, 0x0b, 0x79, 0x8f, 0xc0, 0xc4, 0x44, 0x22, + 0xd7, 0xa1, 0x56, 0x26, 0x94, 0x8f, 0x4f, 0x22, 0x29, 0xe2, 0x44, 0x87, 0x99, 0x0c, 0x6d, 0xcc, + 0xb2, 0x3c, 0x2d, 0x52, 0x3c, 0x6e, 0x8d, 0x56, 0x86, 0x7d, 0x31, 0x2c, 0x93, 0xbb, 0xc3, 0x4c, + 0x86, 0x59, 0x9e, 0xa6, 0x0f, 0x2d, 0x37, 0x79, 0x06, 0xef, 0xb6, 0x21, 0x31, 0x06, 0xf7, 0x42, + 0x14, 0x82, 0x20, 0x1f, 0x05, 0x9b, 0xdc, 0x6a, 0x7c, 0x00, 0xde, 0x4d, 0xc3, 0x92, 0x35, 0x1f, + 0x05, 0x83, 0xe9, 0x36, 0xeb, 0x6e, 0x4a, 0x66, 0x63, 0xde, 0x9e, 0xe2, 0x53, 0xd8, 0xb0, 0xe2, + 0xac, 0x8c, 0x0d, 0xe9, 0xf9, 0x28, 0x18, 0x4e, 0xf7, 0xd8, 0xef, 0xef, 0x33, 0x51, 0xc6, 0x86, + 0x7f, 0xe3, 0x93, 0x57, 0x04, 0x83, 0x99, 0x50, 0x97, 0xc9, 0x7d, 0xaa, 0xe2, 0x64, 0x89, 0x29, + 0xc0, 0x5c, 0x0b, 0xa5, 0xf3, 0xb9, 0x30, 0x51, 0x57, 0xe6, 0x47, 0x82, 0xc7, 0xd0, 0x9f, 0xeb, + 0x78, 0x19, 0x15, 0xb6, 0x93, 0xcb, 0x3b, 0x87, 0x4f, 0xa0, 0x6f, 0x77, 0x34, 0x05, 0x7a, 0xc1, + 0x60, 0xba, 0xff, 0x57, 0x01, 0x4b, 0xf1, 0x0e, 0xc6, 0x3b, 0xe0, 0x5d, 0x25, 0x4a, 0x97, 0xc4, + 0xf5, 0x51, 0xb0, 0xc5, 0x5b, 0x83, 0x8f, 0xc0, 0xb5, 0x5b, 0xbc, 0x7f, 0x6c, 0xb1, 0xe4, 0x21, + 0x01, 0xb7, 0x71, 0x78, 0x1d, 0x7a, 0x7c, 0x71, 0x37, 0x72, 0x1a, 0x71, 0xbe, 0xb8, 0x1e, 0xa1, + 0x19, 0x79, 0xab, 0x28, 0x5a, 0x55, 0x14, 0x7d, 0x54, 0x14, 0xbd, 0xd4, 0xd4, 0x59, 0xd5, 0xd4, + 0x79, 0xaf, 0xa9, 0x23, 0xfb, 0xf6, 0x07, 0x8e, 0x3f, 0x03, 0x00, 0x00, 0xff, 0xff, 0x0f, 0x5d, + 0x8d, 0x6c, 0xcf, 0x01, 0x00, 0x00, } func (m *Share) Marshal() (dAtA []byte, err error) { diff --git a/square/eds/byzantine/pb/share.proto b/share/eds/byzantine/pb/share.proto similarity index 100% rename from square/eds/byzantine/pb/share.proto rename to share/eds/byzantine/pb/share.proto diff --git a/square/eds/byzantine/share_proof.go b/share/eds/byzantine/share_proof.go similarity index 84% rename from square/eds/byzantine/share_proof.go rename to share/eds/byzantine/share_proof.go index 5d94159a0a..51cf4b9793 100644 --- a/square/eds/byzantine/share_proof.go +++ b/share/eds/byzantine/share_proof.go @@ -7,14 +7,14 @@ import ( "github.com/ipfs/boxo/blockservice" logging "github.com/ipfs/go-log/v2" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt" nmt_pb "github.com/celestiaorg/nmt/pb" "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/square" - pb "github.com/celestiaorg/celestia-node/square/eds/byzantine/pb" - "github.com/celestiaorg/celestia-node/square/ipld" + "github.com/celestiaorg/celestia-node/share" + pb "github.com/celestiaorg/celestia-node/share/eds/byzantine/pb" + "github.com/celestiaorg/celestia-node/share/ipld" ) var log = logging.Logger("share/byzantine") @@ -22,7 +22,7 @@ var log = logging.Logger("share/byzantine") // ShareWithProof contains data with corresponding Merkle Proof type ShareWithProof struct { // Share is a full data including namespace - share.Share + gosquare.Share // Proof is a Merkle Proof of current share Proof *nmt.Proof // Axis is a proof axis @@ -30,7 +30,7 @@ type ShareWithProof struct { } // Validate validates inclusion of the share under the given root CID. -func (s *ShareWithProof) Validate(roots *square.AxisRoots, axisType rsmt2d.Axis, axisIdx, shrIdx int) bool { +func (s *ShareWithProof) Validate(roots *share.AxisRoots, axisType rsmt2d.Axis, axisIdx, shrIdx int) bool { var rootHash []byte switch axisType { case rsmt2d.Row: @@ -41,12 +41,12 @@ func (s *ShareWithProof) Validate(roots *square.AxisRoots, axisType rsmt2d.Axis, edsSize := len(roots.RowRoots) isParity := shrIdx >= edsSize/2 || axisIdx >= edsSize/2 - namespace := share.ParitySharesNamespace + namespace := gosquare.ParitySharesNamespace if !isParity { namespace = s.Share.Namespace() } return s.Proof.VerifyInclusion( - square.NewSHA256Hasher(), + share.NewSHA256Hasher(), namespace.Bytes(), [][]byte{s.Share.ToBytes()}, rootHash, @@ -70,13 +70,13 @@ func (s *ShareWithProof) ShareWithProofToProto() *pb.Share { } } -// GetShareWithProof attempts to get a share with proof for the given share. It first tries to get +// GetShareWithProof attempts to get a share with proof for the given gosquare. It first tries to get // a row proof and if that fails or proof is invalid, it tries to get a column proof. func GetShareWithProof( ctx context.Context, bGetter blockservice.BlockGetter, - roots *square.AxisRoots, - share share.Share, + roots *share.AxisRoots, + share gosquare.Share, axisType rsmt2d.Axis, axisIdx, shrIdx int, ) (*ShareWithProof, error) { if axisType == rsmt2d.Col { @@ -121,7 +121,7 @@ func ProtoToShare(protoShares []*pb.Share) ([]*ShareWithProof, error) { continue } proof := ProtoToProof(protoSh.Proof) - sh, err := share.NewShare(protoSh.Data) + sh, err := gosquare.NewShare(protoSh.Data) if err != nil { return nil, err } @@ -143,7 +143,7 @@ func ProtoToProof(protoProof *nmt_pb.Proof) nmt.Proof { ) } -func rootHashForCoordinates(r *square.AxisRoots, axisType rsmt2d.Axis, x, y int) []byte { +func rootHashForCoordinates(r *share.AxisRoots, axisType rsmt2d.Axis, x, y int) []byte { if axisType == rsmt2d.Row { return r.RowRoots[y] } diff --git a/square/eds/close_once.go b/share/eds/close_once.go similarity index 80% rename from square/eds/close_once.go rename to share/eds/close_once.go index 13b2df177b..773eea2be9 100644 --- a/square/eds/close_once.go +++ b/share/eds/close_once.go @@ -6,11 +6,11 @@ import ( "io" "sync/atomic" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/square" - "github.com/celestiaorg/celestia-node/square/shwap" + "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/share/shwap" ) var _ AccessorStreamer = (*closeOnce)(nil) @@ -43,14 +43,14 @@ func (c *closeOnce) Size(ctx context.Context) int { return c.f.Size(ctx) } -func (c *closeOnce) DataHash(ctx context.Context) (square.DataHash, error) { +func (c *closeOnce) DataHash(ctx context.Context) (share.DataHash, error) { if c.closed.Load() { return nil, errAccessorClosed } return c.f.DataHash(ctx) } -func (c *closeOnce) AxisRoots(ctx context.Context) (*square.AxisRoots, error) { +func (c *closeOnce) AxisRoots(ctx context.Context) (*share.AxisRoots, error) { if c.closed.Load() { return nil, errAccessorClosed } @@ -77,7 +77,7 @@ func (c *closeOnce) AxisHalf( func (c *closeOnce) RowNamespaceData( ctx context.Context, - namespace share.Namespace, + namespace gosquare.Namespace, rowIdx int, ) (shwap.RowNamespaceData, error) { if c.closed.Load() { @@ -86,7 +86,7 @@ func (c *closeOnce) RowNamespaceData( return c.f.RowNamespaceData(ctx, namespace, rowIdx) } -func (c *closeOnce) Shares(ctx context.Context) ([]share.Share, error) { +func (c *closeOnce) Shares(ctx context.Context) ([]gosquare.Share, error) { if c.closed.Load() { return nil, errAccessorClosed } diff --git a/square/eds/close_once_test.go b/share/eds/close_once_test.go similarity index 72% rename from square/eds/close_once_test.go rename to share/eds/close_once_test.go index 58da79d840..cc41954ef5 100644 --- a/square/eds/close_once_test.go +++ b/share/eds/close_once_test.go @@ -8,11 +8,11 @@ import ( "github.com/stretchr/testify/require" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/square" - "github.com/celestiaorg/celestia-node/square/shwap" + "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/share/shwap" ) func TestWithClosedOnce(t *testing.T) { @@ -24,7 +24,7 @@ func TestWithClosedOnce(t *testing.T) { require.NoError(t, err) _, err = closedOnce.AxisHalf(ctx, rsmt2d.Row, 0) require.NoError(t, err) - _, err = closedOnce.RowNamespaceData(ctx, share.Namespace{}, 0) + _, err = closedOnce.RowNamespaceData(ctx, gosquare.Namespace{}, 0) require.NoError(t, err) _, err = closedOnce.Shares(ctx) require.NoError(t, err) @@ -37,7 +37,7 @@ func TestWithClosedOnce(t *testing.T) { require.ErrorIs(t, err, errAccessorClosed) _, err = closedOnce.AxisHalf(ctx, rsmt2d.Row, 0) require.ErrorIs(t, err, errAccessorClosed) - _, err = closedOnce.RowNamespaceData(ctx, share.Namespace{}, 0) + _, err = closedOnce.RowNamespaceData(ctx, gosquare.Namespace{}, 0) require.ErrorIs(t, err, errAccessorClosed) _, err = closedOnce.Shares(ctx) require.ErrorIs(t, err, errAccessorClosed) @@ -51,12 +51,12 @@ func (s *stubEdsAccessorCloser) Size(context.Context) int { return 0 } -func (s *stubEdsAccessorCloser) DataHash(context.Context) (square.DataHash, error) { - return square.DataHash{}, nil +func (s *stubEdsAccessorCloser) DataHash(context.Context) (share.DataHash, error) { + return share.DataHash{}, nil } -func (s *stubEdsAccessorCloser) AxisRoots(context.Context) (*square.AxisRoots, error) { - return &square.AxisRoots{}, nil +func (s *stubEdsAccessorCloser) AxisRoots(context.Context) (*share.AxisRoots, error) { + return &share.AxisRoots{}, nil } func (s *stubEdsAccessorCloser) Sample(context.Context, int, int) (shwap.Sample, error) { @@ -69,13 +69,13 @@ func (s *stubEdsAccessorCloser) AxisHalf(context.Context, rsmt2d.Axis, int) (Axi func (s *stubEdsAccessorCloser) RowNamespaceData( context.Context, - share.Namespace, + gosquare.Namespace, int, ) (shwap.RowNamespaceData, error) { return shwap.RowNamespaceData{}, nil } -func (s *stubEdsAccessorCloser) Shares(context.Context) ([]share.Share, error) { +func (s *stubEdsAccessorCloser) Shares(context.Context) ([]gosquare.Share, error) { return nil, nil } diff --git a/square/eds/edstest/testing.go b/share/eds/edstest/testing.go similarity index 78% rename from square/eds/edstest/testing.go rename to share/eds/edstest/testing.go index 8eb11409bb..a3e84073b6 100644 --- a/square/eds/edstest/testing.go +++ b/share/eds/edstest/testing.go @@ -18,11 +18,11 @@ import ( blobtypes "github.com/celestiaorg/celestia-app/v3/x/blob/types" appshares "github.com/celestiaorg/go-square/shares" libSquare "github.com/celestiaorg/go-square/square" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt" "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/share" ) const ( @@ -33,22 +33,22 @@ const ( func RandByzantineEDS(t testing.TB, odsSize int, options ...nmt.Option) *rsmt2d.ExtendedDataSquare { eds := RandEDS(t, odsSize) shares := eds.Flattened() - copy(shares[0][share.NamespaceSize:], shares[1][share.NamespaceSize:]) // corrupting eds + copy(shares[0][gosquare.NamespaceSize:], shares[1][gosquare.NamespaceSize:]) // corrupting eds eds, err := rsmt2d.ImportExtendedDataSquare( shares, - square.DefaultRSMT2DCodec(), + share.DefaultRSMT2DCodec(), wrapper.NewConstructor(uint64(odsSize), options...), ) require.NoError(t, err, "failure to recompute the extended data square") return eds } -// RandEDS generates EDS filled with the random data with the given size for original square. +// RandEDS generates EDS filled with the random data with the given size for original share. func RandEDS(t testing.TB, odsSize int) *rsmt2d.ExtendedDataSquare { - shares := share.RandShares(odsSize * odsSize) + shares := gosquare.RandShares(odsSize * odsSize) eds, err := rsmt2d.ComputeExtendedDataSquare( - share.ToBytes(shares), - square.DefaultRSMT2DCodec(), + gosquare.ToBytes(shares), + share.DefaultRSMT2DCodec(), wrapper.NewConstructor(uint64(odsSize)), ) require.NoError(t, err, "failure to recompute the extended data square") @@ -57,15 +57,15 @@ func RandEDS(t testing.TB, odsSize int) *rsmt2d.ExtendedDataSquare { // RandEDSWithTailPadding generates EDS of given ODS size filled with randomized and tail padding shares. func RandEDSWithTailPadding(t testing.TB, odsSize, padding int) *rsmt2d.ExtendedDataSquare { - shares := share.RandShares(odsSize * odsSize) + shares := gosquare.RandShares(odsSize * odsSize) for i := len(shares) - padding; i < len(shares); i++ { - paddingShare := share.TailPaddingShare() + paddingShare := gosquare.TailPaddingShare() shares[i] = paddingShare } eds, err := rsmt2d.ComputeExtendedDataSquare( - share.ToBytes(shares), - square.DefaultRSMT2DCodec(), + gosquare.ToBytes(shares), + share.DefaultRSMT2DCodec(), wrapper.NewConstructor(uint64(odsSize)), ) require.NoError(t, err, "failure to recompute the extended data square") @@ -76,23 +76,23 @@ func RandEDSWithTailPadding(t testing.TB, odsSize, padding int) *rsmt2d.Extended // namespacedAmount of shares with the given namespace. func RandEDSWithNamespace( t testing.TB, - namespace share.Namespace, + namespace gosquare.Namespace, namespacedAmount, odsSize int, -) (*rsmt2d.ExtendedDataSquare, *square.AxisRoots) { - shares := share.RandSharesWithNamespace(namespace, namespacedAmount, odsSize*odsSize) +) (*rsmt2d.ExtendedDataSquare, *share.AxisRoots) { + shares := gosquare.RandSharesWithNamespace(namespace, namespacedAmount, odsSize*odsSize) eds, err := rsmt2d.ComputeExtendedDataSquare( - share.ToBytes(shares), - square.DefaultRSMT2DCodec(), + gosquare.ToBytes(shares), + share.DefaultRSMT2DCodec(), wrapper.NewConstructor(uint64(odsSize)), ) require.NoError(t, err, "failure to recompute the extended data square") - roots, err := square.NewAxisRoots(eds) + roots, err := share.NewAxisRoots(eds) require.NoError(t, err) return eds, roots } -// RandomAxisRoots generates random square.AxisRoots for the given eds size. -func RandomAxisRoots(t testing.TB, edsSize int) *square.AxisRoots { +// RandomAxisRoots generates random share.AxisRoots for the given eds size. +func RandomAxisRoots(t testing.TB, edsSize int) *share.AxisRoots { roots := make([][]byte, edsSize*2) for i := range roots { root := make([]byte, edsSize) @@ -103,7 +103,7 @@ func RandomAxisRoots(t testing.TB, edsSize int) *square.AxisRoots { rows := roots[:edsSize] cols := roots[edsSize:] - return &square.AxisRoots{ + return &share.AxisRoots{ RowRoots: rows, ColumnRoots: cols, } @@ -116,8 +116,8 @@ func GenerateTestBlock( blobSize, numberOfTransactions int, ) ( []*blobtypes.MsgPayForBlobs, - []*share.Blob, - []share.Namespace, + []*gosquare.Blob, + []gosquare.Namespace, *rsmt2d.ExtendedDataSquare, coretypes.Txs, *da.DataAvailabilityHeader, @@ -131,7 +131,7 @@ func GenerateTestBlock( txs := make(coretypes.Txs, 0) txs = append(txs, coreTxs...) - dataSquare, err := libSquare.Construct( + square, err := libSquare.Construct( txs.ToSliceOfBytes(), appconsts.SquareSizeUpperBound(appconsts.LatestVersion), appconsts.SubtreeRootThreshold(appconsts.LatestVersion), @@ -139,7 +139,7 @@ func GenerateTestBlock( require.NoError(t, err) // erasure the data square which we use to create the data root. - eds, err := da.ExtendShares(appshares.ToBytes(dataSquare)) + eds, err := da.ExtendShares(appshares.ToBytes(square)) require.NoError(t, err) // create the new data root by creating the data availability header (merkle @@ -157,10 +157,10 @@ func GenerateTestBlock( func createTestBlobTransactions( t *testing.T, numberOfTransactions, size int, -) ([]share.Namespace, []*blobtypes.MsgPayForBlobs, []*share.Blob, []coretypes.Tx) { - nss := make([]share.Namespace, 0) +) ([]gosquare.Namespace, []*blobtypes.MsgPayForBlobs, []*gosquare.Blob, []coretypes.Tx) { + nss := make([]gosquare.Namespace, 0) msgs := make([]*blobtypes.MsgPayForBlobs, 0) - blobs := make([]*share.Blob, 0) + blobs := make([]*gosquare.Blob, 0) coreTxs := make([]coretypes.Tx, 0) config := encoding.MakeConfig(app.ModuleEncodingRegisters...) keyring := testfactory.TestKeyring(config.Codec, accountName) @@ -185,11 +185,11 @@ func createTestBlobTransaction( t *testing.T, signer *user.Signer, size int, -) (share.Namespace, *blobtypes.MsgPayForBlobs, *share.Blob, coretypes.Tx) { - ns := share.RandomBlobNamespace() +) (gosquare.Namespace, *blobtypes.MsgPayForBlobs, *gosquare.Blob, coretypes.Tx) { + ns := gosquare.RandomBlobNamespace() account := signer.Account(accountName) msg, b := blobfactory.RandMsgPayForBlobsWithNamespaceAndSigner(account.Address().String(), ns, size) - cTx, _, err := signer.CreatePayForBlobs(accountName, []*share.Blob{b}) + cTx, _, err := signer.CreatePayForBlobs(accountName, []*gosquare.Blob{b}) require.NoError(t, err) return ns, msg, b, cTx } diff --git a/square/eds/nd.go b/share/eds/nd.go similarity index 75% rename from square/eds/nd.go rename to share/eds/nd.go index 1ba186e083..6215493c68 100644 --- a/square/eds/nd.go +++ b/share/eds/nd.go @@ -4,10 +4,10 @@ import ( "context" "fmt" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" - "github.com/celestiaorg/celestia-node/square" - "github.com/celestiaorg/celestia-node/square/shwap" + "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/share/shwap" ) // NamespaceData extracts shares for a specific namespace from an EDS, considering @@ -16,13 +16,13 @@ import ( func NamespaceData( ctx context.Context, eds Accessor, - namespace share.Namespace, + namespace gosquare.Namespace, ) (shwap.NamespaceData, error) { roots, err := eds.AxisRoots(ctx) if err != nil { return nil, fmt.Errorf("failed to get AxisRoots: %w", err) } - rowIdxs := square.RowsWithNamespace(roots, namespace) + rowIdxs := share.RowsWithNamespace(roots, namespace) rows := make(shwap.NamespaceData, len(rowIdxs)) for i, idx := range rowIdxs { rows[i], err = eds.RowNamespaceData(ctx, namespace, idx) diff --git a/square/eds/nd_test.go b/share/eds/nd_test.go similarity index 81% rename from square/eds/nd_test.go rename to share/eds/nd_test.go index dba512a644..63c1883bf2 100644 --- a/square/eds/nd_test.go +++ b/share/eds/nd_test.go @@ -7,9 +7,9 @@ import ( "github.com/stretchr/testify/require" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" - "github.com/celestiaorg/celestia-node/square/eds/edstest" + "github.com/celestiaorg/celestia-node/share/eds/edstest" ) func TestNamespaceData(t *testing.T) { @@ -18,7 +18,7 @@ func TestNamespaceData(t *testing.T) { const odsSize = 8 sharesAmount := odsSize * odsSize - namespace := share.RandomNamespace() + namespace := gosquare.RandomNamespace() for amount := 1; amount < sharesAmount; amount++ { eds, root := edstest.RandEDSWithNamespace(t, namespace, amount, odsSize) rsmt2d := &Rsmt2D{ExtendedDataSquare: eds} diff --git a/square/eds/proof.go b/share/eds/proof.go similarity index 94% rename from square/eds/proof.go rename to share/eds/proof.go index 2e9d8912cc..d649ed7772 100644 --- a/square/eds/proof.go +++ b/share/eds/proof.go @@ -7,7 +7,7 @@ import ( "github.com/tendermint/tendermint/types" pkgproof "github.com/celestiaorg/celestia-app/v3/pkg/proof" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" ) @@ -16,7 +16,7 @@ import ( func ProveShares(eds *rsmt2d.ExtendedDataSquare, start, end int) (*types.ShareProof, error) { log.Debugw("proving share range", "start", start, "end", end) - odsShares, err := share.FromBytes(eds.FlattenedODS()) + odsShares, err := gosquare.FromBytes(eds.FlattenedODS()) if err != nil { return nil, err } @@ -25,7 +25,7 @@ func ProveShares(eds *rsmt2d.ExtendedDataSquare, start, end int) (*types.SharePr return nil, err } log.Debugw("generating the share proof", "start", start, "end", end) - proof, err := pkgproof.NewShareInclusionProofFromEDS(eds, nID, share.NewRange(start, end)) + proof, err := pkgproof.NewShareInclusionProofFromEDS(eds, nID, gosquare.NewRange(start, end)) if err != nil { return nil, err } diff --git a/square/eds/proofs_cache.go b/share/eds/proofs_cache.go similarity index 92% rename from square/eds/proofs_cache.go rename to share/eds/proofs_cache.go index 6f28240a11..32af960ff6 100644 --- a/square/eds/proofs_cache.go +++ b/share/eds/proofs_cache.go @@ -13,13 +13,13 @@ import ( "github.com/ipfs/go-cid" "github.com/celestiaorg/celestia-app/v3/pkg/wrapper" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt" "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/square" - "github.com/celestiaorg/celestia-node/square/ipld" - "github.com/celestiaorg/celestia-node/square/shwap" + "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/share/ipld" + "github.com/celestiaorg/celestia-node/share/shwap" ) var _ AccessorStreamer = (*proofsCache)(nil) @@ -34,9 +34,9 @@ type proofsCache struct { // size caches the size of the data square size atomic.Int32 // dataHash caches the data hash - dataHash atomic.Pointer[square.DataHash] + dataHash atomic.Pointer[share.DataHash] // rootsCache caches the axis roots - rootsCache atomic.Pointer[square.AxisRoots] + rootsCache atomic.Pointer[share.AxisRoots] // axisCacheLock protects proofCache axisCacheLock sync.RWMutex // axisCache caches the axis Shares and proofs. Index in the slice corresponds to the axis type. @@ -51,11 +51,11 @@ type proofsCache struct { type axisWithProofs struct { half AxisHalf // shares are the extended axis Shares - shares []share.Share + shares []gosquare.Share // root caches the root of the tree. It will be set only when proofs are calculated root []byte // proofs are stored in a blockservice.BlockGetter by their CID. It will be set only when proofs - // are calculated and will be used to get the proof for a specific share. BlockGetter is used to + // are calculated and will be used to get the proof for a specific gosquare. BlockGetter is used to // reuse ipld based proof generation logic, which traverses the tree from the root to the leafs and // collects the nodes on the path. This is temporary and will be replaced with a more efficient // proof caching mechanism in nmt package, once it is implemented. @@ -84,7 +84,7 @@ func (c *proofsCache) Size(ctx context.Context) int { return int(size) } -func (c *proofsCache) DataHash(ctx context.Context) (square.DataHash, error) { +func (c *proofsCache) DataHash(ctx context.Context) (share.DataHash, error) { dataHash := c.dataHash.Load() if dataHash != nil { return *dataHash, nil @@ -97,7 +97,7 @@ func (c *proofsCache) DataHash(ctx context.Context) (square.DataHash, error) { return loaded, nil } -func (c *proofsCache) AxisRoots(ctx context.Context) (*square.AxisRoots, error) { +func (c *proofsCache) AxisRoots(ctx context.Context) (*share.AxisRoots, error) { roots := c.rootsCache.Load() if roots != nil { return roots, nil @@ -213,7 +213,7 @@ func (c *proofsCache) AxisHalf(ctx context.Context, axisType rsmt2d.Axis, axisId func (c *proofsCache) RowNamespaceData( ctx context.Context, - namespace share.Namespace, + namespace gosquare.Namespace, rowIdx int, ) (shwap.RowNamespaceData, error) { ax, err := c.axisWithProofs(ctx, rsmt2d.Row, rowIdx) @@ -232,9 +232,9 @@ func (c *proofsCache) RowNamespaceData( }, nil } -func (c *proofsCache) Shares(ctx context.Context) ([]share.Share, error) { +func (c *proofsCache) Shares(ctx context.Context) ([]gosquare.Share, error) { odsSize := c.Size(ctx) / 2 - shares := make([]share.Share, 0, odsSize*odsSize) + shares := make([]gosquare.Share, 0, odsSize*odsSize) for i := 0; i < c.Size(ctx)/2; i++ { ax, err := c.AxisHalf(ctx, rsmt2d.Row, i) if err != nil { @@ -265,7 +265,7 @@ func (c *proofsCache) Close() error { return c.inner.Close() } -func (c *proofsCache) axisShares(ctx context.Context, axisType rsmt2d.Axis, axisIdx int) ([]share.Share, error) { +func (c *proofsCache) axisShares(ctx context.Context, axisType rsmt2d.Axis, axisIdx int) ([]gosquare.Share, error) { ax, ok := c.getAxisFromCache(axisType, axisIdx) if ok && len(ax.shares) != 0 { return ax.shares, nil diff --git a/square/eds/proofs_cache_test.go b/share/eds/proofs_cache_test.go similarity index 100% rename from square/eds/proofs_cache_test.go rename to share/eds/proofs_cache_test.go diff --git a/square/eds/read.go b/share/eds/read.go similarity index 77% rename from square/eds/read.go rename to share/eds/read.go index 0090a7c1a9..38afba4199 100644 --- a/square/eds/read.go +++ b/share/eds/read.go @@ -7,15 +7,15 @@ import ( "fmt" "io" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" - "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/share" ) // ReadAccessor reads up EDS out of the io.Reader until io.EOF and provides. -func ReadAccessor(ctx context.Context, reader io.Reader, root *square.AxisRoots) (*Rsmt2D, error) { +func ReadAccessor(ctx context.Context, reader io.Reader, root *share.AxisRoots) (*Rsmt2D, error) { odsSize := len(root.RowRoots) / 2 - shares, err := ReadShares(reader, share.ShareSize, odsSize) + shares, err := ReadShares(reader, gosquare.ShareSize, odsSize) if err != nil { return nil, fmt.Errorf("failed to read eds from ods bytes: %w", err) } @@ -41,22 +41,22 @@ func ReadAccessor(ctx context.Context, reader io.Reader, root *square.AxisRoots) // ReadShares reads shares from the provided io.Reader until EOF. If EOF is reached, the remaining shares // are populated as tail padding shares. Provided reader must contain shares in row-major order. -func ReadShares(r io.Reader, shareSize, odsSize int) ([]share.Share, error) { - shares := make([]share.Share, odsSize*odsSize) +func ReadShares(r io.Reader, shareSize, odsSize int) ([]gosquare.Share, error) { + shares := make([]gosquare.Share, odsSize*odsSize) var total int for i := range shares { shr := make([]byte, shareSize) n, err := io.ReadFull(r, shr) if errors.Is(err, io.EOF) { for ; i < len(shares); i++ { - shares[i] = share.TailPaddingShare() + shares[i] = gosquare.TailPaddingShare() } return shares, nil } if err != nil { return nil, fmt.Errorf("reading shares: %w, bytes read: %v", err, total+n) } - newShare, err := share.NewShare(shr) + newShare, err := gosquare.NewShare(shr) if err != nil { return nil, err } diff --git a/square/eds/retriever.go b/share/eds/retriever.go similarity index 94% rename from square/eds/retriever.go rename to share/eds/retriever.go index 53b79aacd7..d8111289af 100644 --- a/square/eds/retriever.go +++ b/share/eds/retriever.go @@ -16,13 +16,13 @@ import ( "go.opentelemetry.io/otel/trace" "github.com/celestiaorg/celestia-app/v3/pkg/wrapper" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt" "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/square" - "github.com/celestiaorg/celestia-node/square/eds/byzantine" - "github.com/celestiaorg/celestia-node/square/ipld" + "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/share/eds/byzantine" + "github.com/celestiaorg/celestia-node/share/ipld" ) var ( @@ -41,7 +41,7 @@ var ( // ---- ---- // // Retriever randomly picks one of the data square quadrants and tries to request them one by one -// until it is able to reconstruct the whole square. +// until it is able to reconstruct the whole share. type Retriever struct { bServ blockservice.BlockService } @@ -57,7 +57,7 @@ func NewRetriever(bServ blockservice.BlockService) *Retriever { // data square and reconstructs the other three quadrants (3/4). If the requested quadrant is not // available within RetrieveQuadrantTimeout, it starts requesting another quadrant until either the // data is reconstructed, context is canceled or ErrByzantine is generated. -func (r *Retriever) Retrieve(ctx context.Context, roots *square.AxisRoots) (*rsmt2d.ExtendedDataSquare, error) { +func (r *Retriever) Retrieve(ctx context.Context, roots *share.AxisRoots) (*rsmt2d.ExtendedDataSquare, error) { ctx, cancel := context.WithCancel(ctx) defer cancel() // cancels all the ongoing requests if reconstruction succeeds early @@ -107,7 +107,7 @@ func (r *Retriever) Retrieve(ctx context.Context, roots *square.AxisRoots) (*rsm // quadrant request retries. Also, provides an API // to reconstruct the block once enough shares are fetched. type retrievalSession struct { - roots *square.AxisRoots + roots *share.AxisRoots bget blockservice.BlockGetter adder *ipld.NmtNodeAdder @@ -125,7 +125,7 @@ type retrievalSession struct { } // newSession creates a new retrieval session and kicks off requesting process. -func (r *Retriever) newSession(ctx context.Context, roots *square.AxisRoots) (*retrievalSession, error) { +func (r *Retriever) newSession(ctx context.Context, roots *share.AxisRoots) (*retrievalSession, error) { size := len(roots.RowRoots) adder := ipld.NewNmtNodeAdder(ctx, r.bServ, ipld.MaxSizeBatchOption(size)) @@ -143,7 +143,7 @@ func (r *Retriever) newSession(ctx context.Context, roots *square.AxisRoots) (*r return &tree } - square, err := rsmt2d.NewExtendedDataSquare(square.DefaultRSMT2DCodec(), treeFn, uint(size), share.ShareSize) + square, err := rsmt2d.NewExtendedDataSquare(share.DefaultRSMT2DCodec(), treeFn, uint(size), gosquare.ShareSize) if err != nil { return nil, err } @@ -283,7 +283,7 @@ func (rs *retrievalSession) doRequest(ctx context.Context, q *quadrant) { ipld.GetShares(ctx, rs.bget, nd.Links()[q.x].Cid, size, func(j int, rawShare []byte) { // NOTE: Each share can appear twice here, for a Row and Col, respectively. // These shares are always equal, and we allow only the first one to be written - // in the square. + // in the share. // NOTE-2: We may never actually fetch shares from the network *twice*. // Once a share is downloaded from the network it may be cached on the IPLD(blockservice) level. // diff --git a/square/eds/retriever_no_race_test.go b/share/eds/retriever_no_race_test.go similarity index 72% rename from square/eds/retriever_no_race_test.go rename to share/eds/retriever_no_race_test.go index 43165a0bce..b27d9c5264 100644 --- a/square/eds/retriever_no_race_test.go +++ b/share/eds/retriever_no_race_test.go @@ -10,14 +10,14 @@ import ( "github.com/stretchr/testify/require" "github.com/celestiaorg/celestia-app/v3/pkg/wrapper" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt" "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/square" - "github.com/celestiaorg/celestia-node/square/eds/byzantine" - "github.com/celestiaorg/celestia-node/square/eds/edstest" - "github.com/celestiaorg/celestia-node/square/ipld" + "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/share/eds/byzantine" + "github.com/celestiaorg/celestia-node/share/eds/edstest" + "github.com/celestiaorg/celestia-node/share/ipld" ) func TestRetriever_ByzantineError(t *testing.T) { @@ -31,13 +31,13 @@ func TestRetriever_ByzantineError(t *testing.T) { require.NoError(t, err) // corrupt shares so that eds erasure coding does not match - copy(shares[14][share.NamespaceSize:], shares[15][share.NamespaceSize:]) + copy(shares[14][gosquare.NamespaceSize:], shares[15][gosquare.NamespaceSize:]) // import corrupted eds batchAdder := ipld.NewNmtNodeAdder(ctx, bserv, ipld.MaxSizeBatchOption(width*2)) attackerEDS, err := rsmt2d.ImportExtendedDataSquare( shares, - square.DefaultRSMT2DCodec(), + share.DefaultRSMT2DCodec(), wrapper.NewConstructor(uint64(width), nmt.NodeVisitor(batchAdder.Visit)), ) @@ -46,7 +46,7 @@ func TestRetriever_ByzantineError(t *testing.T) { require.NoError(t, err) // ensure we rcv an error - roots, err := square.NewAxisRoots(attackerEDS) + roots, err := share.NewAxisRoots(attackerEDS) require.NoError(t, err) r := NewRetriever(bserv) _, err = r.Retrieve(ctx, roots) diff --git a/square/eds/retriever_quadrant.go b/share/eds/retriever_quadrant.go similarity index 92% rename from square/eds/retriever_quadrant.go rename to share/eds/retriever_quadrant.go index 6450926948..0b5bffb311 100644 --- a/square/eds/retriever_quadrant.go +++ b/share/eds/retriever_quadrant.go @@ -8,8 +8,8 @@ import ( "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/square" - "github.com/celestiaorg/celestia-node/square/ipld" + "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/share/ipld" ) const ( @@ -49,7 +49,7 @@ type quadrant struct { // newQuadrants constructs a slice of quadrants from DAHeader. // There are always 4 quadrants per each source (row and col), so 8 in total. // The ordering of quadrants is random. -func newQuadrants(roots *square.AxisRoots) []*quadrant { +func newQuadrants(roots *share.AxisRoots) []*quadrant { // combine all the roots into one slice, so they can be easily accessible by index daRoots := [][][]byte{ roots.RowRoots, @@ -87,7 +87,7 @@ func newQuadrants(roots *square.AxisRoots) []*quadrant { return quadrants } -// pos calculates position of a share in a data square. +// pos calculates position of a share in a data share. func (q *quadrant) pos(rootIdx, cellIdx int) (int, int) { cellIdx += len(q.roots) * q.x rootIdx += len(q.roots) * q.y diff --git a/square/eds/retriever_test.go b/share/eds/retriever_test.go similarity index 92% rename from square/eds/retriever_test.go rename to share/eds/retriever_test.go index 1fd2c4632f..69980dcfc1 100644 --- a/square/eds/retriever_test.go +++ b/share/eds/retriever_test.go @@ -11,15 +11,15 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" "github.com/celestiaorg/celestia-node/header" "github.com/celestiaorg/celestia-node/header/headertest" - "github.com/celestiaorg/celestia-node/square" - "github.com/celestiaorg/celestia-node/square/eds/byzantine" - "github.com/celestiaorg/celestia-node/square/eds/edstest" - "github.com/celestiaorg/celestia-node/square/ipld" + "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/share/eds/byzantine" + "github.com/celestiaorg/celestia-node/share/eds/edstest" + "github.com/celestiaorg/celestia-node/share/ipld" ) func TestRetriever_Retrieve(t *testing.T) { @@ -41,12 +41,12 @@ func TestRetriever_Retrieve(t *testing.T) { {"16x16(med)", 16}, {"32x32(med)", 32}, {"64x64(med)", 64}, - {"128x128(max)", square.MaxSquareSize}, + {"128x128(max)", share.MaxSquareSize}, } for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { // generate EDS - shares := share.RandShares(tc.squareSize * tc.squareSize) + shares := gosquare.RandShares(tc.squareSize * tc.squareSize) in, err := ipld.AddShares(ctx, shares, bServ) require.NoError(t, err) @@ -54,7 +54,7 @@ func TestRetriever_Retrieve(t *testing.T) { ctx, cancel := context.WithTimeout(ctx, time.Minute*5) // the timeout is big for the max size which is long defer cancel() - roots, err := square.NewAxisRoots(in) + roots, err := share.NewAxisRoots(in) require.NoError(t, err) out, err := r.Retrieve(ctx, roots) require.NoError(t, err) @@ -75,11 +75,11 @@ func TestRetriever_MultipleRandQuadrants(t *testing.T) { r := NewRetriever(bServ) // generate EDS - shares := share.RandShares(squareSize * squareSize) + shares := gosquare.RandShares(squareSize * squareSize) in, err := ipld.AddShares(ctx, shares, bServ) require.NoError(t, err) - roots, err := square.NewAxisRoots(in) + roots, err := share.NewAxisRoots(in) require.NoError(t, err) ses, err := r.newSession(ctx, roots) require.NoError(t, err) diff --git a/square/eds/rsmt2d.go b/share/eds/rsmt2d.go similarity index 78% rename from square/eds/rsmt2d.go rename to share/eds/rsmt2d.go index 0dfc044498..39e2973a38 100644 --- a/square/eds/rsmt2d.go +++ b/share/eds/rsmt2d.go @@ -6,11 +6,11 @@ import ( "io" "github.com/celestiaorg/celestia-app/v3/pkg/wrapper" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/square" - "github.com/celestiaorg/celestia-node/square/shwap" + "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/share/shwap" ) var _ AccessorStreamer = (*Rsmt2D)(nil) @@ -20,23 +20,23 @@ type Rsmt2D struct { *rsmt2d.ExtendedDataSquare } -// Size returns the size of the Extended Data Square. +// Size returns the size of the Extended Data share. func (eds *Rsmt2D) Size(context.Context) int { return int(eds.Width()) } // DataHash returns data hash of the Accessor. -func (eds *Rsmt2D) DataHash(context.Context) (square.DataHash, error) { - roots, err := square.NewAxisRoots(eds.ExtendedDataSquare) +func (eds *Rsmt2D) DataHash(context.Context) (share.DataHash, error) { + roots, err := share.NewAxisRoots(eds.ExtendedDataSquare) if err != nil { - return square.DataHash{}, fmt.Errorf("while creating data root: %w", err) + return share.DataHash{}, fmt.Errorf("while creating data root: %w", err) } return roots.Hash(), nil } // AxisRoots returns AxisRoots of the Accessor. -func (eds *Rsmt2D) AxisRoots(context.Context) (*square.AxisRoots, error) { - roots, err := square.NewAxisRoots(eds.ExtendedDataSquare) +func (eds *Rsmt2D) AxisRoots(context.Context) (*share.AxisRoots, error) { + roots, err := share.NewAxisRoots(eds.ExtendedDataSquare) if err != nil { return nil, fmt.Errorf("while creating axis roots: %w", err) } @@ -100,7 +100,7 @@ func (eds *Rsmt2D) AxisHalf(_ context.Context, axisType rsmt2d.Axis, axisIdx int // side. func (eds *Rsmt2D) HalfRow(idx int, side shwap.RowSide) (shwap.Row, error) { shares := eds.ExtendedDataSquare.Row(uint(idx)) - sh, err := share.FromBytes(shares) + sh, err := gosquare.FromBytes(shares) if err != nil { return shwap.Row{}, fmt.Errorf("while converting shares from bytes: %w", err) } @@ -110,11 +110,11 @@ func (eds *Rsmt2D) HalfRow(idx int, side shwap.RowSide) (shwap.Row, error) { // RowNamespaceData returns data for the given namespace and row index. func (eds *Rsmt2D) RowNamespaceData( _ context.Context, - namespace share.Namespace, + namespace gosquare.Namespace, rowIdx int, ) (shwap.RowNamespaceData, error) { shares := eds.Row(uint(rowIdx)) - sh, err := share.FromBytes(shares) + sh, err := gosquare.FromBytes(shares) if err != nil { return shwap.RowNamespaceData{}, fmt.Errorf("while converting shares from bytes: %w", err) } @@ -123,8 +123,8 @@ func (eds *Rsmt2D) RowNamespaceData( // Shares returns data (ODS) shares extracted from the EDS. It returns new copy of the shares each // time. -func (eds *Rsmt2D) Shares(_ context.Context) ([]share.Share, error) { - return share.FromBytes(eds.ExtendedDataSquare.FlattenedODS()) +func (eds *Rsmt2D) Shares(_ context.Context) ([]gosquare.Share, error) { + return gosquare.FromBytes(eds.ExtendedDataSquare.FlattenedODS()) } func (eds *Rsmt2D) Close() error { @@ -142,9 +142,9 @@ func (eds *Rsmt2D) Reader() (io.Reader, error) { } // Rsmt2DFromShares constructs an Extended Data Square from shares. -func Rsmt2DFromShares(shares []share.Share, odsSize int) (*Rsmt2D, error) { +func Rsmt2DFromShares(shares []gosquare.Share, odsSize int) (*Rsmt2D, error) { treeFn := wrapper.NewConstructor(uint64(odsSize)) - eds, err := rsmt2d.ComputeExtendedDataSquare(share.ToBytes(shares), square.DefaultRSMT2DCodec(), treeFn) + eds, err := rsmt2d.ComputeExtendedDataSquare(gosquare.ToBytes(shares), share.DefaultRSMT2DCodec(), treeFn) if err != nil { return &Rsmt2D{}, fmt.Errorf("computing extended data square: %w", err) } @@ -152,13 +152,13 @@ func Rsmt2DFromShares(shares []share.Share, odsSize int) (*Rsmt2D, error) { return &Rsmt2D{eds}, nil } -func getAxis(eds *rsmt2d.ExtendedDataSquare, axisType rsmt2d.Axis, axisIdx int) ([]share.Share, error) { +func getAxis(eds *rsmt2d.ExtendedDataSquare, axisType rsmt2d.Axis, axisIdx int) ([]gosquare.Share, error) { switch axisType { case rsmt2d.Row: - sh, err := share.FromBytes(eds.Row(uint(axisIdx))) + sh, err := gosquare.FromBytes(eds.Row(uint(axisIdx))) return sh, err case rsmt2d.Col: - sh, err := share.FromBytes(eds.Col(uint(axisIdx))) + sh, err := gosquare.FromBytes(eds.Col(uint(axisIdx))) return sh, err default: panic("unknown axis") diff --git a/square/eds/rsmt2d_test.go b/share/eds/rsmt2d_test.go similarity index 83% rename from square/eds/rsmt2d_test.go rename to share/eds/rsmt2d_test.go index 58ee60211c..fa76b03a09 100644 --- a/square/eds/rsmt2d_test.go +++ b/share/eds/rsmt2d_test.go @@ -7,12 +7,12 @@ import ( "github.com/stretchr/testify/require" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/square" - "github.com/celestiaorg/celestia-node/square/eds/edstest" - "github.com/celestiaorg/celestia-node/square/shwap" + "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/share/eds/edstest" + "github.com/celestiaorg/celestia-node/share/shwap" ) func TestRsmt2dAccessor(t *testing.T) { @@ -43,7 +43,7 @@ func TestRsmt2dHalfRow(t *testing.T) { want := eds.Row(uint(rowIdx)) shares, err := row.Shares() require.NoError(t, err) - require.Equal(t, want, share.ToBytes(shares)) + require.Equal(t, want, gosquare.ToBytes(shares)) } } } @@ -70,9 +70,9 @@ func TestRsmt2dSampleForProofAxis(t *testing.T) { } } -func randRsmt2dAccsessor(t *testing.T, size int) (Rsmt2D, *square.AxisRoots) { +func randRsmt2dAccsessor(t *testing.T, size int) (Rsmt2D, *share.AxisRoots) { eds := edstest.RandEDS(t, size) - root, err := square.NewAxisRoots(eds) + root, err := share.NewAxisRoots(eds) require.NoError(t, err) return Rsmt2D{ExtendedDataSquare: eds}, root } diff --git a/square/eds/share_reader.go b/share/eds/share_reader.go similarity index 100% rename from square/eds/share_reader.go rename to share/eds/share_reader.go diff --git a/square/eds/share_reader_test.go b/share/eds/share_reader_test.go similarity index 86% rename from square/eds/share_reader_test.go rename to share/eds/share_reader_test.go index cb4e6d19ff..165cc25f42 100644 --- a/square/eds/share_reader_test.go +++ b/share/eds/share_reader_test.go @@ -8,9 +8,9 @@ import ( "github.com/stretchr/testify/require" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" - "github.com/celestiaorg/celestia-node/square/eds/edstest" + "github.com/celestiaorg/celestia-node/share/eds/edstest" ) func TestShareReader(t *testing.T) { @@ -24,7 +24,7 @@ func TestShareReader(t *testing.T) { reader := NewShareReader(odsSize, getShare) readBytes, err := readWithRandomBuffer(reader, 1024) require.NoError(t, err) - expected := make([]byte, 0, odsSize*odsSize*share.ShareSize) + expected := make([]byte, 0, odsSize*odsSize*gosquare.ShareSize) for _, share := range eds.FlattenedODS() { expected = append(expected, share...) } diff --git a/square/eds/testing.go b/share/eds/testing.go similarity index 92% rename from square/eds/testing.go rename to share/eds/testing.go index f7a1bf0f89..b6b448a075 100644 --- a/square/eds/testing.go +++ b/share/eds/testing.go @@ -10,13 +10,13 @@ import ( "github.com/stretchr/testify/require" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt" "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/square" - "github.com/celestiaorg/celestia-node/square/eds/edstest" - "github.com/celestiaorg/celestia-node/square/shwap" + "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/share/eds/edstest" + "github.com/celestiaorg/celestia-node/share/shwap" ) type ( @@ -84,7 +84,7 @@ func testEDSes(t *testing.T, sizes ...int) map[string]*rsmt2d.ExtendedDataSquare testEDSes[fmt.Sprintf("PaddedODS:%d", size)] = paddingEds } - testEDSes["EmptyODS"] = square.EmptyEDS() + testEDSes["EmptyODS"] = share.EmptyEDS() return testEDSes } @@ -110,12 +110,12 @@ func testAccessorDataHash( ) { acc := createAccessor(t, eds) - expected, err := square.NewAxisRoots(eds) + expected, err := share.NewAxisRoots(eds) require.NoError(t, err) datahash, err := acc.DataHash(ctx) require.NoError(t, err) - require.Equal(t, square.DataHash(expected.Hash()), datahash) + require.Equal(t, share.DataHash(expected.Hash()), datahash) } func testAccessorAxisRoots( @@ -126,7 +126,7 @@ func testAccessorAxisRoots( ) { acc := createAccessor(t, eds) - expected, err := square.NewAxisRoots(eds) + expected, err := share.NewAxisRoots(eds) require.NoError(t, err) roots, err := acc.AxisRoots(ctx) @@ -143,7 +143,7 @@ func testAccessorSample( width := int(eds.Width()) t.Run("single thread", func(t *testing.T) { acc := createAccessor(t, eds) - roots, err := square.NewAxisRoots(eds) + roots, err := share.NewAxisRoots(eds) require.NoError(t, err) // t.Parallel() this fails the test for some reason for rowIdx := 0; rowIdx < width; rowIdx++ { @@ -156,7 +156,7 @@ func testAccessorSample( t.Run("parallel", func(t *testing.T) { t.Parallel() acc := createAccessor(t, eds) - roots, err := square.NewAxisRoots(eds) + roots, err := share.NewAxisRoots(eds) require.NoError(t, err) wg := sync.WaitGroup{} for rowIdx := 0; rowIdx < width; rowIdx++ { @@ -174,7 +174,7 @@ func testAccessorSample( t.Run("random", func(t *testing.T) { t.Parallel() acc := createAccessor(t, eds) - roots, err := square.NewAxisRoots(eds) + roots, err := share.NewAxisRoots(eds) require.NoError(t, err) wg := sync.WaitGroup{} @@ -194,7 +194,7 @@ func testSample( ctx context.Context, t *testing.T, acc Accessor, - roots *square.AxisRoots, + roots *share.AxisRoots, rowIdx, colIdx int, ) { shr, err := acc.Sample(ctx, rowIdx, colIdx) @@ -214,7 +214,7 @@ func testAccessorRowNamespaceData( t.Parallel() // generate EDS with random data and some Shares with the same namespace sharesAmount := odsSize * odsSize - namespace := share.RandomNamespace() + namespace := gosquare.RandomNamespace() // test with different amount of shares for amount := 1; amount < sharesAmount; amount++ { // select random amount of shares, but not less than 1 @@ -250,18 +250,18 @@ func testAccessorRowNamespaceData( t.Parallel() // generate EDS with random data and some Shares with the same namespace eds := edstest.RandEDS(t, odsSize) - roots, err := square.NewAxisRoots(eds) + roots, err := share.NewAxisRoots(eds) require.NoError(t, err) // loop over first half of the rows, because the second half is parity and does not contain // namespaced shares for i, root := range roots.RowRoots[:odsSize] { // select namespace that within the range of root namespaces, but is not included - maxNs := nmt.MaxNamespace(root, share.NamespaceSize) - ns, err := share.NewNamespaceFromBytes(maxNs) + maxNs := nmt.MaxNamespace(root, gosquare.NamespaceSize) + ns, err := gosquare.NewNamespaceFromBytes(maxNs) require.NoError(t, err) - absentNs, err := share.AddInt(ns, -1) + absentNs, err := gosquare.AddInt(ns, -1) require.NoError(t, err) acc := createAccessor(t, eds) @@ -294,7 +294,7 @@ func testAccessorAxisHalf( require.NoError(t, err) require.Len(t, half.Shares, odsSize) - var expected []share.Share + var expected []gosquare.Share if half.IsParity { expected, err = getAxis(eds, axisType, axisIdx) require.NoError(t, err) @@ -322,7 +322,7 @@ func testAccessorAxisHalf( require.NoError(t, err) require.Len(t, half.Shares, odsSize) - var expected []share.Share + var expected []gosquare.Share if half.IsParity { expected, err = getAxis(eds, axisType, idx) require.NoError(t, err) @@ -357,7 +357,7 @@ func testAccessorShares( shares, err := acc.Shares(ctx) require.NoError(t, err) expected := eds.FlattenedODS() - sh, err := share.FromBytes(expected) + sh, err := gosquare.FromBytes(expected) require.NoError(t, err) require.Equal(t, sh, shares) }() @@ -390,7 +390,7 @@ func testReader(ctx context.Context, t *testing.T, eds *rsmt2d.ExtendedDataSquar reader, err := as.Reader() require.NoError(t, err) - roots, err := square.NewAxisRoots(eds) + roots, err := share.NewAxisRoots(eds) require.NoError(t, err) actual, err := ReadAccessor(ctx, reader, roots) diff --git a/square/eds/validation.go b/share/eds/validation.go similarity index 92% rename from square/eds/validation.go rename to share/eds/validation.go index c8d7c632f7..eca404ab99 100644 --- a/square/eds/validation.go +++ b/share/eds/validation.go @@ -6,10 +6,10 @@ import ( "fmt" "sync/atomic" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/square/shwap" + "github.com/celestiaorg/celestia-node/share/shwap" ) var _ Accessor = validation{} @@ -56,7 +56,7 @@ func (f validation) AxisHalf(ctx context.Context, axisType rsmt2d.Axis, axisIdx func (f validation) RowNamespaceData( ctx context.Context, - namespace share.Namespace, + namespace gosquare.Namespace, rowIdx int, ) (shwap.RowNamespaceData, error) { _, err := shwap.NewRowNamespaceDataID(1, rowIdx, namespace, f.Size(ctx)) diff --git a/square/eds/validation_test.go b/share/eds/validation_test.go similarity index 92% rename from square/eds/validation_test.go rename to share/eds/validation_test.go index 0d0b3bf42e..f5ac0d5588 100644 --- a/square/eds/validation_test.go +++ b/share/eds/validation_test.go @@ -7,11 +7,11 @@ import ( "github.com/stretchr/testify/require" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/square/eds/edstest" - "github.com/celestiaorg/celestia-node/square/shwap" + "github.com/celestiaorg/celestia-node/share/eds/edstest" + "github.com/celestiaorg/celestia-node/share/shwap" ) func TestValidation_Sample(t *testing.T) { @@ -91,7 +91,7 @@ func TestValidation_RowNamespaceData(t *testing.T) { accessor := &Rsmt2D{ExtendedDataSquare: randEDS} validation := WithValidation(AccessorAndStreamer(accessor, nil)) - ns := share.RandomNamespace() + ns := gosquare.RandomNamespace() _, err := validation.RowNamespaceData(context.Background(), ns, tt.rowIdx) if tt.expectFail { require.ErrorIs(t, err, shwap.ErrInvalidID) diff --git a/square/empty.go b/share/empty.go similarity index 82% rename from square/empty.go rename to share/empty.go index b683715a3e..ce82915180 100644 --- a/square/empty.go +++ b/share/empty.go @@ -1,4 +1,4 @@ -package square +package share import ( "bytes" @@ -6,7 +6,7 @@ import ( "sync" "github.com/celestiaorg/celestia-app/v3/pkg/da" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" ) @@ -22,14 +22,14 @@ func EmptyEDSRoots() *AxisRoots { return emptyBlockRoots } -// EmptyEDS returns the EDS of the empty block data square. +// EmptyEDS returns the EDS of the empty block data share. func EmptyEDS() *rsmt2d.ExtendedDataSquare { initEmpty() return emptyBlockEDS } // EmptyBlockShares returns the shares of the empty block. -func EmptyBlockShares() []share.Share { +func EmptyBlockShares() []gosquare.Share { initEmpty() return emptyBlockShares } @@ -39,7 +39,7 @@ var ( emptyBlockDataHash DataHash emptyBlockRoots *AxisRoots emptyBlockEDS *rsmt2d.ExtendedDataSquare - emptyBlockShares []share.Share + emptyBlockShares []gosquare.Share ) // initEmpty enables lazy initialization for constant empty block data. @@ -49,8 +49,8 @@ func initEmpty() { func computeEmpty() { // compute empty block EDS and DAH for it - result := share.TailPaddingShares(share.MinShareCount) - rawEmptyBlockShares := share.ToBytes(result) + result := gosquare.TailPaddingShares(gosquare.MinShareCount) + rawEmptyBlockShares := gosquare.ToBytes(result) eds, err := da.ExtendShares(rawEmptyBlockShares) if err != nil { @@ -69,7 +69,7 @@ func computeEmpty() { } sh := eds.FlattenedODS() - emptyBlockShares, err = share.FromBytes(sh) + emptyBlockShares, err = gosquare.FromBytes(sh) if err != nil { panic(fmt.Errorf("failed to create shares: %w", err)) } diff --git a/square/ipld/add.go b/share/ipld/add.go similarity index 91% rename from square/ipld/add.go rename to share/ipld/add.go index f200f28309..8a182bce2f 100644 --- a/square/ipld/add.go +++ b/share/ipld/add.go @@ -7,19 +7,19 @@ import ( "github.com/ipfs/boxo/blockservice" "github.com/celestiaorg/celestia-app/v3/pkg/wrapper" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt" "github.com/celestiaorg/rsmt2d" "github.com/celestiaorg/celestia-node/libs/utils" - "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/share" ) // AddShares erasures and extends shares to blockservice.BlockService using the provided // ipld.NodeAdder. func AddShares( ctx context.Context, - shares []share.Share, + shares []gosquare.Share, adder blockservice.BlockService, ) (*rsmt2d.ExtendedDataSquare, error) { if len(shares) == 0 { @@ -31,8 +31,8 @@ func AddShares( // create the nmt wrapper to generate row and col commitments // recompute the eds eds, err := rsmt2d.ComputeExtendedDataSquare( - share.ToBytes(shares), - square.DefaultRSMT2DCodec(), + gosquare.ToBytes(shares), + share.DefaultRSMT2DCodec(), wrapper.NewConstructor(uint64(squareSize), nmt.NodeVisitor(batchAdder.Visit)), ) @@ -64,7 +64,7 @@ func ImportShares( // recompute the eds eds, err := rsmt2d.ImportExtendedDataSquare( shares, - square.DefaultRSMT2DCodec(), + share.DefaultRSMT2DCodec(), wrapper.NewConstructor(uint64(squareSize/2), nmt.NodeVisitor(batchAdder.Visit)), ) diff --git a/square/ipld/blockserv.go b/share/ipld/blockserv.go similarity index 100% rename from square/ipld/blockserv.go rename to share/ipld/blockserv.go diff --git a/square/ipld/delete.go b/share/ipld/delete.go similarity index 100% rename from square/ipld/delete.go rename to share/ipld/delete.go diff --git a/square/ipld/delete_test.go b/share/ipld/delete_test.go similarity index 95% rename from square/ipld/delete_test.go rename to share/ipld/delete_test.go index e6953ba5f3..ff879a10b8 100644 --- a/square/ipld/delete_test.go +++ b/share/ipld/delete_test.go @@ -12,7 +12,7 @@ import ( "github.com/ipfs/go-datastore/sync" "github.com/stretchr/testify/require" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" ) func TestDeleteNode_FullSquare(t *testing.T) { @@ -21,7 +21,7 @@ func TestDeleteNode_FullSquare(t *testing.T) { defer cancel() bServ := NewMemBlockservice() - shares := share.RandShares(size * size) + shares := gosquare.RandShares(size * size) eds, err := AddShares(ctx, shares, bServ) require.NoError(t, err) @@ -63,7 +63,7 @@ func TestDeleteNode_Sample(t *testing.T) { defer cancel() full := NewMemBlockservice() - shares := share.RandShares(size * size) + shares := gosquare.RandShares(size * size) eds, err := AddShares(ctx, shares, full) require.NoError(t, err) diff --git a/square/ipld/get.go b/share/ipld/get.go similarity index 97% rename from square/ipld/get.go rename to share/ipld/get.go index a5769adf40..9e85f7ccc9 100644 --- a/square/ipld/get.go +++ b/share/ipld/get.go @@ -11,7 +11,7 @@ import ( "github.com/ipfs/go-cid" ipld "github.com/ipfs/go-ipld-format" - "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/share" ) // NumWorkersLimit sets global limit for workers spawned by GetShares. @@ -26,7 +26,7 @@ import ( // // TODO(@Wondertan): This assumes we have parallelized DASer implemented. Sync the values once it is shipped. // TODO(@Wondertan): Allow configuration of values without global state. -var NumWorkersLimit = square.MaxSquareSize * square.MaxSquareSize / 2 * NumConcurrentSquares +var NumWorkersLimit = share.MaxSquareSize * share.MaxSquareSize / 2 * NumConcurrentSquares // NumConcurrentSquares limits the amount of squares that are fetched // concurrently/simultaneously. diff --git a/square/ipld/get_shares.go b/share/ipld/get_shares.go similarity index 79% rename from square/ipld/get_shares.go rename to share/ipld/get_shares.go index 5872daeb41..172a576834 100644 --- a/square/ipld/get_shares.go +++ b/share/ipld/get_shares.go @@ -7,7 +7,7 @@ import ( "github.com/ipfs/go-cid" format "github.com/ipfs/go-ipld-format" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt" ) @@ -18,15 +18,15 @@ func GetShare( rootCid cid.Cid, leafIndex int, totalLeafs int, // this corresponds to the extended square width -) (share.Share, error) { +) (gosquare.Share, error) { nd, err := GetLeaf(ctx, bGetter, rootCid, leafIndex, totalLeafs) if err != nil { - return share.Share{}, err + return gosquare.Share{}, err } - sh, err := share.NewShare(nd.RawData()[share.NamespaceSize:]) + sh, err := gosquare.NewShare(nd.RawData()[gosquare.NamespaceSize:]) if err != nil { - return share.Share{}, err + return gosquare.Share{}, err } return *sh, nil } @@ -36,7 +36,7 @@ func GetShare( // (got all shares) or on context cancellation. func GetShares(ctx context.Context, bg blockservice.BlockGetter, root cid.Cid, shares int, put func(int, []byte)) { putNode := func(i int, leaf format.Node) { - put(i, leaf.RawData()[share.NamespaceSize:]) + put(i, leaf.RawData()[gosquare.NamespaceSize:]) } GetLeaves(ctx, bg, root, shares, putNode) } @@ -48,9 +48,9 @@ func GetSharesByNamespace( ctx context.Context, bGetter blockservice.BlockGetter, root []byte, - namespace share.Namespace, + namespace gosquare.Namespace, maxShares int, -) ([]share.Share, *nmt.Proof, error) { +) ([]gosquare.Share, *nmt.Proof, error) { rootCid := MustCidFromNamespacedSha256(root) data := NewNamespaceData(maxShares, namespace, WithLeaves(), WithProofs()) err := data.CollectLeavesByNamespace(ctx, bGetter, rootCid) @@ -63,10 +63,10 @@ func GetSharesByNamespace( return nil, data.Proof(), nil } - shares := make([]share.Share, len(leaves)) + shares := make([]gosquare.Share, len(leaves)) for i, leaf := range leaves { if leaf != nil { - sh, err := share.NewShare(leaf.RawData()[share.NamespaceSize:]) + sh, err := gosquare.NewShare(leaf.RawData()[gosquare.NamespaceSize:]) if err != nil { return nil, nil, err } diff --git a/square/ipld/get_shares_test.go b/share/ipld/get_shares_test.go similarity index 87% rename from square/ipld/get_shares_test.go rename to share/ipld/get_shares_test.go index 75399d77bf..2c17790c36 100644 --- a/square/ipld/get_shares_test.go +++ b/share/ipld/get_shares_test.go @@ -15,12 +15,12 @@ import ( "github.com/stretchr/testify/require" "github.com/celestiaorg/celestia-app/v3/pkg/wrapper" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" "github.com/celestiaorg/celestia-node/libs/utils" - "github.com/celestiaorg/celestia-node/square" - "github.com/celestiaorg/celestia-node/square/eds/edstest" + "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/share/eds/edstest" ) func TestGetShare(t *testing.T) { @@ -31,7 +31,7 @@ func TestGetShare(t *testing.T) { bServ := NewMemBlockservice() // generate random shares for the nmt - shares := share.RandShares(size * size) + shares := gosquare.RandShares(size * size) eds, err := AddShares(ctx, shares, bServ) require.NoError(t, err) @@ -53,12 +53,12 @@ func TestBlockRecovery(t *testing.T) { extendedShareCount := extendedSquareWidth * extendedSquareWidth // generate test data - quarterShares := share.RandShares(shareCount) - allShares := share.RandShares(shareCount) + quarterShares := gosquare.RandShares(shareCount) + allShares := gosquare.RandShares(shareCount) testCases := []struct { name string - shares []share.Share + shares []gosquare.Share expectErr bool errString string d int // number of shares to delete @@ -73,8 +73,8 @@ func TestBlockRecovery(t *testing.T) { squareSize := utils.SquareSize(len(tc.shares)) testEds, err := rsmt2d.ComputeExtendedDataSquare( - share.ToBytes(tc.shares), - square.DefaultRSMT2DCodec(), + gosquare.ToBytes(tc.shares), + share.DefaultRSMT2DCodec(), wrapper.NewConstructor(squareSize), ) require.NoError(t, err) @@ -91,7 +91,7 @@ func TestBlockRecovery(t *testing.T) { rdata := removeRandShares(flat, tc.d) testEds, err = rsmt2d.ImportExtendedDataSquare( rdata, - square.DefaultRSMT2DCodec(), + share.DefaultRSMT2DCodec(), wrapper.NewConstructor(squareSize), ) require.NoError(t, err) @@ -104,7 +104,7 @@ func TestBlockRecovery(t *testing.T) { } assert.NoError(t, err) - reds, err := rsmt2d.ImportExtendedDataSquare(rdata, square.DefaultRSMT2DCodec(), wrapper.NewConstructor(squareSize)) + reds, err := rsmt2d.ImportExtendedDataSquare(rdata, share.DefaultRSMT2DCodec(), wrapper.NewConstructor(squareSize)) require.NoError(t, err) // check that the squares are equal assert.Equal(t, testEds.Flattened(), reds.Flattened()) @@ -114,18 +114,18 @@ func TestBlockRecovery(t *testing.T) { func Test_ConvertEDStoShares(t *testing.T) { squareWidth := 16 - shares := share.RandShares(squareWidth * squareWidth) + shares := gosquare.RandShares(squareWidth * squareWidth) // compute extended square testEds, err := rsmt2d.ComputeExtendedDataSquare( - share.ToBytes(shares), - square.DefaultRSMT2DCodec(), + gosquare.ToBytes(shares), + share.DefaultRSMT2DCodec(), wrapper.NewConstructor(uint64(squareWidth)), ) require.NoError(t, err) resshares := testEds.FlattenedODS() - require.Equal(t, share.ToBytes(shares), resshares) + require.Equal(t, gosquare.ToBytes(shares), resshares) } // removes d shares from data @@ -149,10 +149,10 @@ func TestGetSharesByNamespace(t *testing.T) { bServ := NewMemBlockservice() tests := []struct { - rawData []share.Share + rawData []gosquare.Share }{ - {rawData: share.RandShares(4)}, - {rawData: share.RandShares(16)}, + {rawData: gosquare.RandShares(4)}, + {rawData: gosquare.RandShares(16)}, } for i, tt := range tests { @@ -167,7 +167,7 @@ func TestGetSharesByNamespace(t *testing.T) { eds, err := AddShares(ctx, tt.rawData, bServ) require.NoError(t, err) - var shares []share.Share + var shares []gosquare.Share rowRoots, err := eds.RowRoots() require.NoError(t, err) for _, row := range rowRoots { @@ -193,7 +193,7 @@ func TestCollectLeavesByNamespace_IncompleteData(t *testing.T) { t.Cleanup(cancel) bServ := NewMemBlockservice() - shares := share.RandShares(16) + shares := gosquare.RandShares(16) // set all shares to the same namespace id namespace := shares[0].Namespace() @@ -237,7 +237,7 @@ func TestCollectLeavesByNamespace_AbsentNamespaceId(t *testing.T) { t.Cleanup(cancel) bServ := NewMemBlockservice() - shares := share.RandShares(1024) + shares := gosquare.RandShares(1024) // set all shares to the same namespace namespaces, err := randomNamespaces(5) @@ -259,8 +259,8 @@ func TestCollectLeavesByNamespace_AbsentNamespaceId(t *testing.T) { tests := []struct { name string - data []share.Share - missingNamespace share.Namespace + data []gosquare.Share + missingNamespace gosquare.Namespace isAbsence bool }{ {name: "Namespace less than the minimum namespace in data", data: shares, missingNamespace: minNamespace}, @@ -282,7 +282,7 @@ func TestCollectLeavesByNamespace_MultipleRowsContainingSameNamespaceId(t *testi t.Cleanup(cancel) bServ := NewMemBlockservice() - shares := share.RandShares(16) + shares := gosquare.RandShares(16) // set all shares to the same namespace and data but the last one namespace := shares[0].Namespace() @@ -314,7 +314,7 @@ func TestCollectLeavesByNamespace_MultipleRowsContainingSameNamespaceId(t *testi for _, node := range leaves { // test that the data returned by collectLeavesByNamespace for nid // matches the commonNamespaceData that was copied across almost all data - sh, err := share.NewShare(node.RawData()[share.NamespaceSize:]) + sh, err := gosquare.NewShare(node.RawData()[gosquare.NamespaceSize:]) require.NoError(t, err) assert.Equal(t, commonNamespaceData, *sh) } @@ -327,11 +327,11 @@ func TestGetSharesWithProofsByNamespace(t *testing.T) { bServ := NewMemBlockservice() tests := []struct { - rawData []share.Share + rawData []gosquare.Share }{ - {rawData: share.RandShares(4)}, - {rawData: share.RandShares(16)}, - {rawData: share.RandShares(64)}, + {rawData: gosquare.RandShares(4)}, + {rawData: gosquare.RandShares(16)}, + {rawData: gosquare.RandShares(64)}, } for i, tt := range tests { @@ -357,7 +357,7 @@ func TestGetSharesWithProofsByNamespace(t *testing.T) { eds, err := AddShares(ctx, tt.rawData, bServ) require.NoError(t, err) - var shares []share.Share + var shares []gosquare.Share rowRoots, err := eds.RowRoots() require.NoError(t, err) for _, row := range rowRoots { @@ -380,7 +380,7 @@ func TestGetSharesWithProofsByNamespace(t *testing.T) { // verify namespace verified := proof.VerifyNamespace( - square.NewSHA256Hasher(), + share.NewSHA256Hasher(), namespace.Bytes(), leaves, row) @@ -388,9 +388,9 @@ func TestGetSharesWithProofsByNamespace(t *testing.T) { // verify inclusion verified = proof.VerifyInclusion( - square.NewSHA256Hasher(), + share.NewSHA256Hasher(), namespace.Bytes(), - share.ToBytes(rowShares), + gosquare.ToBytes(rowShares), row) require.True(t, verified) } @@ -426,7 +426,7 @@ func TestBatchSize(t *testing.T) { randEds := edstest.RandEDS(t, tt.origWidth) - shrs, err := share.FromBytes(randEds.FlattenedODS()) + shrs, err := gosquare.FromBytes(randEds.FlattenedODS()) require.NoError(t, err) _, err = AddShares(ctx, shrs, bs) require.NoError(t, err) @@ -449,7 +449,7 @@ func assertNoRowContainsNID( t *testing.T, bServ blockservice.BlockService, eds *rsmt2d.ExtendedDataSquare, - namespace share.Namespace, + namespace gosquare.Namespace, isAbsent bool, ) { rowRoots, err := eds.RowRoots() @@ -482,7 +482,7 @@ func assertNoRowContainsNID( // if no error returned, check absence proof foundAbsenceRows++ - verified := data.Proof().VerifyNamespace(square.NewSHA256Hasher(), namespace.Bytes(), nil, rowRoot) + verified := data.Proof().VerifyNamespace(share.NewSHA256Hasher(), namespace.Bytes(), nil, rowRoot) require.True(t, verified) } @@ -493,10 +493,10 @@ func assertNoRowContainsNID( } } -func randomNamespaces(total int) ([]share.Namespace, error) { - namespaces := make([]share.Namespace, total) +func randomNamespaces(total int) ([]gosquare.Namespace, error) { + namespaces := make([]gosquare.Namespace, total) for i := range namespaces { - namespaces[i] = share.RandomNamespace() + namespaces[i] = gosquare.RandomNamespace() } sort.Slice(namespaces, func(i, j int) bool { return namespaces[i].IsLessThan(namespaces[j]) }) return namespaces, nil diff --git a/square/ipld/namespace_data.go b/share/ipld/namespace_data.go similarity index 96% rename from square/ipld/namespace_data.go rename to share/ipld/namespace_data.go index 2c2ddaf3df..194b14dddd 100644 --- a/square/ipld/namespace_data.go +++ b/share/ipld/namespace_data.go @@ -11,10 +11,10 @@ import ( "github.com/ipfs/go-cid" ipld "github.com/ipfs/go-ipld-format" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt" - "github.com/celestiaorg/celestia-node/square/shwap" + "github.com/celestiaorg/celestia-node/share/shwap" ) var ErrNamespaceOutsideRange = shwap.ErrNamespaceOutsideRange @@ -46,13 +46,13 @@ type NamespaceData struct { bounds fetchedBounds maxShares int - namespace share.Namespace + namespace gosquare.Namespace isAbsentNamespace atomic.Bool absenceProofLeaf ipld.Node } -func NewNamespaceData(maxShares int, namespace share.Namespace, options ...Option) *NamespaceData { +func NewNamespaceData(maxShares int, namespace gosquare.Namespace, options ...Option) *NamespaceData { data := &NamespaceData{ maxShares: maxShares, namespace: namespace, @@ -71,7 +71,7 @@ func NewNamespaceData(maxShares int, namespace share.Namespace, options ...Optio } func (n *NamespaceData) validate(rootCid cid.Cid) error { - if err := share.ValidateUserNamespace(n.namespace.Version(), n.namespace.ID()); err != nil { + if err := gosquare.ValidateUserNamespace(n.namespace.Version(), n.namespace.ID()); err != nil { return err } diff --git a/square/ipld/nmt.go b/share/ipld/nmt.go similarity index 92% rename from square/ipld/nmt.go rename to share/ipld/nmt.go index c96c081168..4dad93df36 100644 --- a/square/ipld/nmt.go +++ b/share/ipld/nmt.go @@ -16,10 +16,10 @@ import ( mh "github.com/multiformats/go-multihash" mhcore "github.com/multiformats/go-multihash/core" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt" - "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/share" ) var log = logging.Logger("ipld") @@ -36,13 +36,13 @@ const ( sha256NamespaceFlagged = 0x7701 // NmtHashSize is the size of a digest created by an NMT in bytes. - NmtHashSize = 2*share.NamespaceSize + sha256.Size + NmtHashSize = 2*gosquare.NamespaceSize + sha256.Size // InnerNodeSize is the size of data in inner nodes. InnerNodeSize = NmtHashSize * 2 // LeafNodeSize is the size of data in leaf nodes. - LeafNodeSize = share.NamespaceSize + share.ShareSize + LeafNodeSize = gosquare.NamespaceSize + gosquare.ShareSize // cidPrefixSize is the size of the prepended buffer of the CID encoding // for NamespacedSha256. For more information, see: @@ -58,7 +58,7 @@ const ( func init() { // required for Bitswap to hash and verify inbound data correctly mhcore.Register(sha256NamespaceFlagged, func() hash.Hash { - nh := nmt.NewNmtHasher(square.NewSHA256Hasher(), share.NamespaceSize, true) + nh := nmt.NewNmtHasher(share.NewSHA256Hasher(), gosquare.NamespaceSize, true) nh.Reset() return nh }) @@ -157,7 +157,7 @@ func MustCidFromNamespacedSha256(hash []byte) cid.Cid { // Translate transforms square coordinates into IPLD NMT tree path to a leaf node. // It also adds randomization to evenly spread fetching from Rows and Columns. -func Translate(roots *square.AxisRoots, row, col int) (cid.Cid, int) { +func Translate(roots *share.AxisRoots, row, col int) (cid.Cid, int) { if rand.Intn(2) == 0 { //nolint:gosec return MustCidFromNamespacedSha256(roots.ColumnRoots[col]), row } diff --git a/square/ipld/nmt_adder.go b/share/ipld/nmt_adder.go similarity index 100% rename from square/ipld/nmt_adder.go rename to share/ipld/nmt_adder.go diff --git a/square/ipld/nmt_test.go b/share/ipld/nmt_test.go similarity index 85% rename from square/ipld/nmt_test.go rename to share/ipld/nmt_test.go index a2133492c8..040c68ec1d 100644 --- a/square/ipld/nmt_test.go +++ b/share/ipld/nmt_test.go @@ -9,8 +9,8 @@ import ( "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/square" - "github.com/celestiaorg/celestia-node/square/eds/edstest" + "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/share/eds/edstest" ) // TestNamespaceFromCID checks that deriving the Namespaced hash from @@ -26,7 +26,7 @@ func TestNamespaceFromCID(t *testing.T) { for i, tt := range tests { t.Run(strconv.Itoa(i), func(t *testing.T) { - roots, err := square.NewAxisRoots(tt.eds) + roots, err := share.NewAxisRoots(tt.eds) require.NoError(t, err) // check to make sure NamespacedHash is correctly derived from CID for _, row := range roots.RowRoots { diff --git a/square/ipld/proof_collector.go b/share/ipld/proof_collector.go similarity index 100% rename from square/ipld/proof_collector.go rename to share/ipld/proof_collector.go diff --git a/square/ipld/proofs.go b/share/ipld/proofs.go similarity index 100% rename from square/ipld/proofs.go rename to share/ipld/proofs.go diff --git a/square/ipld/proofs_test.go b/share/ipld/proofs_test.go similarity index 81% rename from square/ipld/proofs_test.go rename to share/ipld/proofs_test.go index ca28499b82..d7185d886e 100644 --- a/square/ipld/proofs_test.go +++ b/share/ipld/proofs_test.go @@ -7,11 +7,11 @@ import ( "github.com/stretchr/testify/require" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/square" - "github.com/celestiaorg/celestia-node/square/shwap" + "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/share/shwap" ) func TestGetProof(t *testing.T) { @@ -21,11 +21,11 @@ func TestGetProof(t *testing.T) { defer cancel() bServ := NewMemBlockservice() - shares := share.RandShares(width * width) + shares := gosquare.RandShares(width * width) in, err := AddShares(ctx, shares, bServ) require.NoError(t, err) - axisRoots, err := square.NewAxisRoots(in) + axisRoots, err := share.NewAxisRoots(in) require.NoError(t, err) for _, proofType := range []rsmt2d.Axis{rsmt2d.Row, rsmt2d.Col} { @@ -45,7 +45,7 @@ func TestGetProof(t *testing.T) { node, err := GetLeaf(ctx, bServ, rootCid, shrIdx, int(in.Width())) require.NoError(t, err) - sh, err := share.NewShare(node.RawData()[share.NamespaceSize:]) + sh, err := gosquare.NewShare(node.RawData()[gosquare.NamespaceSize:]) require.NoError(t, err) sample := shwap.Sample{ Share: *sh, diff --git a/square/ipld/test_helpers.go b/share/ipld/test_helpers.go similarity index 100% rename from square/ipld/test_helpers.go rename to share/ipld/test_helpers.go diff --git a/square/ipld/utils.go b/share/ipld/utils.go similarity index 51% rename from square/ipld/utils.go rename to share/ipld/utils.go index 1333dddd78..62acc24961 100644 --- a/square/ipld/utils.go +++ b/share/ipld/utils.go @@ -3,14 +3,14 @@ package ipld import ( "github.com/ipfs/go-cid" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" - "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/share" ) -// FilterRootByNamespace returns the row roots from the given square.AxisRoots that contain the +// FilterRootByNamespace returns the row roots from the given share.AxisRoots that contain the // namespace. -func FilterRootByNamespace(root *square.AxisRoots, namespace share.Namespace) []cid.Cid { +func FilterRootByNamespace(root *share.AxisRoots, namespace gosquare.Namespace) []cid.Cid { rowRootCIDs := make([]cid.Cid, 0, len(root.RowRoots)) for _, row := range root.RowRoots { if !namespace.IsOutsideRange(row, row) { diff --git a/square/root.go b/share/root.go similarity index 89% rename from square/root.go rename to share/root.go index f4c1045662..b0c2357a52 100644 --- a/square/root.go +++ b/share/root.go @@ -1,4 +1,4 @@ -package square +package share import ( "bytes" @@ -8,7 +8,7 @@ import ( "hash" "github.com/celestiaorg/celestia-app/v3/pkg/da" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" ) @@ -20,7 +20,7 @@ const ( ) // AxisRoots represents root commitment to multiple Shares. -// In practice, it is a commitment to all the Data in a square. +// In practice, it is a commitment to all the Data in a share. type AxisRoots = da.DataAvailabilityHeader // DataHash is a representation of the AxisRoots hash. @@ -48,7 +48,7 @@ func NewSHA256Hasher() hash.Hash { } // NewAxisRoots generates AxisRoots(DataAvailabilityHeader) using the -// provided extended data square. +// provided extended data share. func NewAxisRoots(eds *rsmt2d.ExtendedDataSquare) (*AxisRoots, error) { dah, err := da.NewDataAvailabilityHeader(eds) if err != nil { @@ -59,7 +59,7 @@ func NewAxisRoots(eds *rsmt2d.ExtendedDataSquare) (*AxisRoots, error) { // RowsWithNamespace inspects the AxisRoots for the Namespace and provides // a slices of Row indexes containing the namespace. -func RowsWithNamespace(root *AxisRoots, namespace share.Namespace) (idxs []int) { +func RowsWithNamespace(root *AxisRoots, namespace gosquare.Namespace) (idxs []int) { for i, row := range root.RowRoots { if !namespace.IsOutsideRange(row, row) { idxs = append(idxs, i) diff --git a/share/share.go b/share/share.go index 5f312407ab..3fb654a1a0 100644 --- a/share/share.go +++ b/share/share.go @@ -1,10 +1,8 @@ package share import ( - "fmt" - - "github.com/celestiaorg/celestia-app/v2/pkg/appconsts" - "github.com/celestiaorg/go-square/shares" + "github.com/celestiaorg/celestia-app/v3/pkg/appconsts" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt" "github.com/celestiaorg/rsmt2d" ) @@ -12,48 +10,14 @@ import ( // DefaultRSMT2DCodec sets the default rsmt2d.Codec for shares. var DefaultRSMT2DCodec = appconsts.DefaultCodec -const ( - // Size is a system-wide size of a share, including both data and namespace GetNamespace - Size = appconsts.ShareSize -) - // MaxSquareSize is currently the maximum size supported for unerasured data in // rsmt2d.ExtendedDataSquare. var MaxSquareSize = appconsts.SquareSizeUpperBound(appconsts.LatestVersion) -// Share contains the raw share data without the corresponding namespace. -// NOTE: Alias for the byte is chosen to keep maximal compatibility, especially with rsmt2d. -// Ideally, we should define reusable type elsewhere and make everyone(Core, rsmt2d, ipld) to rely -// on it. -type Share = []byte - -// GetNamespace slices Namespace out of the Share. -func GetNamespace(s Share) Namespace { - return s[:NamespaceSize] -} - -// GetData slices out data of the Share. -func GetData(s Share) []byte { - return s[NamespaceSize:] -} - -// ValidateShare checks the size of a given share. -func ValidateShare(s Share) error { - if len(s) != Size { - return fmt.Errorf("invalid share size: %d", len(s)) - } - return nil -} - -// TailPadding is a constant tail padding share exported for reuse -func TailPadding() Share { - return tailPadding -} - // ShareWithProof contains data with corresponding Merkle Proof type ShareWithProof struct { //nolint: revive // Share is a full data including namespace - Share + gosquare.Share // Proof is a Merkle Proof of current share Proof *nmt.Proof // Axis is a type of axis against which the share proof is computed @@ -63,21 +27,14 @@ type ShareWithProof struct { //nolint: revive // Validate validates inclusion of the share under the given root CID. func (s *ShareWithProof) Validate(rootHash []byte, x, y, edsSize int) bool { isParity := x >= edsSize/2 || y >= edsSize/2 - namespace := ParitySharesNamespace + namespace := gosquare.ParitySharesNamespace if !isParity { - namespace = GetNamespace(s.Share) + namespace = s.Share.Namespace() } return s.Proof.VerifyInclusion( NewSHA256Hasher(), - namespace.ToNMT(), - [][]byte{s.Share}, + namespace.Bytes(), + [][]byte{s.Share.ToBytes()}, rootHash, ) } - -var tailPadding Share - -func init() { - shr := shares.TailPaddingShare() - tailPadding = shr.ToBytes() -} diff --git a/square/shwap/eds.go b/share/shwap/eds.go similarity index 68% rename from square/shwap/eds.go rename to share/shwap/eds.go index 2d856c5317..8ea8665507 100644 --- a/square/shwap/eds.go +++ b/share/shwap/eds.go @@ -1,6 +1,6 @@ package shwap -// EDSName is the name identifier for the Extended Data Square. +// EDSName is the name identifier for the Extended Data share. const EDSName = "eds_v0" // NOTE: There is no EDS container as it's already defined by rsmt2d and eds.Accessor interface. diff --git a/square/shwap/eds_id.go b/share/shwap/eds_id.go similarity index 100% rename from square/shwap/eds_id.go rename to share/shwap/eds_id.go diff --git a/square/shwap/eds_id_test.go b/share/shwap/eds_id_test.go similarity index 100% rename from square/shwap/eds_id_test.go rename to share/shwap/eds_id_test.go diff --git a/square/shwap/getter.go b/share/shwap/getter.go similarity index 89% rename from square/shwap/getter.go rename to share/shwap/getter.go index dfbe36432e..fbb1050e63 100644 --- a/square/shwap/getter.go +++ b/share/shwap/getter.go @@ -5,7 +5,7 @@ import ( "errors" "fmt" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" "github.com/celestiaorg/celestia-node/header" @@ -30,7 +30,7 @@ var ( //go:generate mockgen -destination=getters/mock/getter.go -package=mock . Getter type Getter interface { // GetShare gets a Share by coordinates in EDS. - GetShare(ctx context.Context, header *header.ExtendedHeader, row, col int) (share.Share, error) + GetShare(ctx context.Context, header *header.ExtendedHeader, row, col int) (gosquare.Share, error) // GetEDS gets the full EDS identified by the given extended header. GetEDS(context.Context, *header.ExtendedHeader) (*rsmt2d.ExtendedDataSquare, error) @@ -40,5 +40,5 @@ type Getter interface { // Inclusion of returned data could be verified using Verify method on NamespacedShares. // If no shares are found for target namespace non-inclusion could be also verified by calling // Verify method. - GetSharesByNamespace(context.Context, *header.ExtendedHeader, share.Namespace) (NamespaceData, error) + GetSharesByNamespace(context.Context, *header.ExtendedHeader, gosquare.Namespace) (NamespaceData, error) } diff --git a/square/shwap/getters/cascade.go b/share/shwap/getters/cascade.go similarity index 93% rename from square/shwap/getters/cascade.go rename to share/shwap/getters/cascade.go index 5aeddafd30..80736198e6 100644 --- a/square/shwap/getters/cascade.go +++ b/share/shwap/getters/cascade.go @@ -10,13 +10,13 @@ import ( "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/trace" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" "github.com/celestiaorg/celestia-node/header" "github.com/celestiaorg/celestia-node/libs/utils" - "github.com/celestiaorg/celestia-node/square/eds/byzantine" - "github.com/celestiaorg/celestia-node/square/shwap" + "github.com/celestiaorg/celestia-node/share/eds/byzantine" + "github.com/celestiaorg/celestia-node/share/shwap" ) var ( @@ -44,7 +44,7 @@ func NewCascadeGetter(getters []shwap.Getter) *CascadeGetter { // GetShare gets a share from any of registered shwap.Getters in cascading order. func (cg *CascadeGetter) GetShare( ctx context.Context, header *header.ExtendedHeader, row, col int, -) (share.Share, error) { +) (gosquare.Share, error) { ctx, span := tracer.Start(ctx, "cascade/get-share", trace.WithAttributes( attribute.Int("row", row), attribute.Int("col", col), @@ -55,9 +55,9 @@ func (cg *CascadeGetter) GetShare( if row >= upperBound || col >= upperBound { err := shwap.ErrOutOfBounds span.RecordError(err) - return share.Share{}, err + return gosquare.Share{}, err } - get := func(ctx context.Context, get shwap.Getter) (share.Share, error) { + get := func(ctx context.Context, get shwap.Getter) (gosquare.Share, error) { return get.GetShare(ctx, header, row, col) } @@ -83,7 +83,7 @@ func (cg *CascadeGetter) GetEDS( func (cg *CascadeGetter) GetSharesByNamespace( ctx context.Context, header *header.ExtendedHeader, - namespace share.Namespace, + namespace gosquare.Namespace, ) (shwap.NamespaceData, error) { ctx, span := tracer.Start(ctx, "cascade/get-shares-by-namespace", trace.WithAttributes( attribute.String("namespace", namespace.String()), diff --git a/square/shwap/getters/cascade_test.go b/share/shwap/getters/cascade_test.go similarity index 97% rename from square/shwap/getters/cascade_test.go rename to share/shwap/getters/cascade_test.go index 0012780fbf..a23568006f 100644 --- a/square/shwap/getters/cascade_test.go +++ b/share/shwap/getters/cascade_test.go @@ -12,8 +12,8 @@ import ( "github.com/celestiaorg/rsmt2d" "github.com/celestiaorg/celestia-node/header" - "github.com/celestiaorg/celestia-node/square/shwap" - "github.com/celestiaorg/celestia-node/square/shwap/getters/mock" + "github.com/celestiaorg/celestia-node/share/shwap" + "github.com/celestiaorg/celestia-node/share/shwap/getters/mock" ) func TestCascadeGetter(t *testing.T) { diff --git a/square/shwap/getters/mock/getter.go b/share/shwap/getters/mock/getter.go similarity index 98% rename from square/shwap/getters/mock/getter.go rename to share/shwap/getters/mock/getter.go index 5eb7be8ef6..41146b3a73 100644 --- a/square/shwap/getters/mock/getter.go +++ b/share/shwap/getters/mock/getter.go @@ -9,7 +9,7 @@ import ( reflect "reflect" header "github.com/celestiaorg/celestia-node/header" - shwap "github.com/celestiaorg/celestia-node/square/shwap" + shwap "github.com/celestiaorg/celestia-node/share/shwap" share "github.com/celestiaorg/go-square/v2/share" rsmt2d "github.com/celestiaorg/rsmt2d" gomock "github.com/golang/mock/gomock" diff --git a/square/shwap/getters/testing.go b/share/shwap/getters/testing.go similarity index 79% rename from square/shwap/getters/testing.go rename to share/shwap/getters/testing.go index a9eb55d034..55a5580a90 100644 --- a/square/shwap/getters/testing.go +++ b/share/shwap/getters/testing.go @@ -8,20 +8,20 @@ import ( "github.com/stretchr/testify/require" "github.com/celestiaorg/celestia-app/v3/pkg/da" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" "github.com/celestiaorg/celestia-node/header" "github.com/celestiaorg/celestia-node/header/headertest" - "github.com/celestiaorg/celestia-node/square" - "github.com/celestiaorg/celestia-node/square/eds/edstest" - "github.com/celestiaorg/celestia-node/square/shwap" + "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/share/eds/edstest" + "github.com/celestiaorg/celestia-node/share/shwap" ) // TestGetter provides a testing SingleEDSGetter and the root of the EDS it holds. func TestGetter(t *testing.T) (shwap.Getter, *header.ExtendedHeader) { eds := edstest.RandEDS(t, 8) - roots, err := square.NewAxisRoots(eds) + roots, err := share.NewAxisRoots(eds) eh := headertest.RandExtendedHeaderWithRoot(t, roots) require.NoError(t, err) return &SingleEDSGetter{ @@ -40,15 +40,15 @@ func (seg *SingleEDSGetter) GetShare( _ context.Context, header *header.ExtendedHeader, row, col int, -) (share.Share, error) { +) (gosquare.Share, error) { err := seg.checkRoots(header.DAH) if err != nil { - return share.Share{}, err + return gosquare.Share{}, err } rawSh := seg.EDS.GetCell(uint(row), uint(col)) - sh, err := share.NewShare(rawSh) + sh, err := gosquare.NewShare(rawSh) if err != nil { - return share.Share{}, err + return gosquare.Share{}, err } return *sh, nil } @@ -66,12 +66,12 @@ func (seg *SingleEDSGetter) GetEDS( } // GetSharesByNamespace returns NamespacedShares from a kept EDS if the correct root is given. -func (seg *SingleEDSGetter) GetSharesByNamespace(context.Context, *header.ExtendedHeader, share.Namespace, +func (seg *SingleEDSGetter) GetSharesByNamespace(context.Context, *header.ExtendedHeader, gosquare.Namespace, ) (shwap.NamespaceData, error) { panic("SingleEDSGetter: GetSharesByNamespace is not implemented") } -func (seg *SingleEDSGetter) checkRoots(roots *square.AxisRoots) error { +func (seg *SingleEDSGetter) checkRoots(roots *share.AxisRoots) error { dah, err := da.NewDataAvailabilityHeader(seg.EDS) if err != nil { return err diff --git a/square/shwap/namespace_data.go b/share/shwap/namespace_data.go similarity index 85% rename from square/shwap/namespace_data.go rename to share/shwap/namespace_data.go index 730d4e1c41..b98c210656 100644 --- a/square/shwap/namespace_data.go +++ b/share/shwap/namespace_data.go @@ -5,9 +5,9 @@ import ( "fmt" "io" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" - "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/share" ) // NamespaceDataName is the name identifier for the namespace data container. @@ -20,8 +20,8 @@ const NamespaceDataName = "nd_v0" type NamespaceData []RowNamespaceData // Flatten combines all shares from all rows within the namespace into a single slice. -func (nd NamespaceData) Flatten() []share.Share { - var shares []share.Share +func (nd NamespaceData) Flatten() []gosquare.Share { + var shares []gosquare.Share for _, row := range nd { shares = append(shares, row.Shares...) } @@ -29,8 +29,8 @@ func (nd NamespaceData) Flatten() []share.Share { } // Verify checks the integrity of the NamespaceData against a provided root and namespace. -func (nd NamespaceData) Verify(root *square.AxisRoots, namespace share.Namespace) error { - rowIdxs := square.RowsWithNamespace(root, namespace) +func (nd NamespaceData) Verify(root *share.AxisRoots, namespace gosquare.Namespace) error { + rowIdxs := share.RowsWithNamespace(root, namespace) if len(rowIdxs) != len(nd) { return fmt.Errorf("expected %d rows, found %d rows", len(rowIdxs), len(nd)) } diff --git a/square/shwap/namespace_data_id.go b/share/shwap/namespace_data_id.go similarity index 90% rename from square/shwap/namespace_data_id.go rename to share/shwap/namespace_data_id.go index 1488e41ba3..3e4b288c3f 100644 --- a/square/shwap/namespace_data_id.go +++ b/share/shwap/namespace_data_id.go @@ -4,24 +4,24 @@ import ( "fmt" "io" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" ) // NamespaceDataIDSize defines the total size of a NamespaceDataID in bytes, combining the // size of a EdsID and the size of a Namespace. -const NamespaceDataIDSize = EdsIDSize + share.NamespaceSize +const NamespaceDataIDSize = EdsIDSize + gosquare.NamespaceSize // NamespaceDataID filters the data in the EDS by a specific namespace. type NamespaceDataID struct { // Embedding EdsID to include the block height. EdsID // DataNamespace will be used to identify the data within the EDS. - DataNamespace share.Namespace + DataNamespace gosquare.Namespace } // NewNamespaceDataID creates a new NamespaceDataID with the specified parameters. It // validates the namespace and returns an error if it is invalid. -func NewNamespaceDataID(height uint64, namespace share.Namespace) (NamespaceDataID, error) { +func NewNamespaceDataID(height uint64, namespace gosquare.Namespace) (NamespaceDataID, error) { ndid := NamespaceDataID{ EdsID: EdsID{ Height: height, @@ -48,7 +48,7 @@ func NamespaceDataIDFromBinary(data []byte) (NamespaceDataID, error) { return NamespaceDataID{}, fmt.Errorf("error unmarshaling EDSID: %w", err) } - ns, err := share.NewNamespaceFromBytes(data[EdsIDSize:]) + ns, err := gosquare.NewNamespaceFromBytes(data[EdsIDSize:]) if err != nil { return NamespaceDataID{}, fmt.Errorf("error unmarshaling namespace: %w", err) } @@ -112,7 +112,7 @@ func (ndid NamespaceDataID) Validate() error { return fmt.Errorf("validating RowID: %w", err) } - if err := share.ValidateForData(ndid.DataNamespace); err != nil { + if err := gosquare.ValidateForData(ndid.DataNamespace); err != nil { return fmt.Errorf("%w: validating DataNamespace: %w", ErrInvalidID, err) } return nil diff --git a/square/shwap/namespace_data_id_test.go b/share/shwap/namespace_data_id_test.go similarity index 88% rename from square/shwap/namespace_data_id_test.go rename to share/shwap/namespace_data_id_test.go index daab44cdcf..c978db85a4 100644 --- a/square/shwap/namespace_data_id_test.go +++ b/share/shwap/namespace_data_id_test.go @@ -7,11 +7,11 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" ) func TestNamespaceDataID(t *testing.T) { - ns := share.RandomNamespace() + ns := gosquare.RandomNamespace() id, err := NewNamespaceDataID(1, ns) require.NoError(t, err) @@ -29,7 +29,7 @@ func TestNamespaceDataID(t *testing.T) { } func TestNamespaceDataIDReaderWriter(t *testing.T) { - ns := share.RandomNamespace() + ns := gosquare.RandomNamespace() id, err := NewNamespaceDataID(1, ns) require.NoError(t, err) diff --git a/square/shwap/p2p/bitswap/bitswap.go b/share/shwap/p2p/bitswap/bitswap.go similarity index 100% rename from square/shwap/p2p/bitswap/bitswap.go rename to share/shwap/p2p/bitswap/bitswap.go diff --git a/square/shwap/p2p/bitswap/block.go b/share/shwap/p2p/bitswap/block.go similarity index 89% rename from square/shwap/p2p/bitswap/block.go rename to share/shwap/p2p/bitswap/block.go index d42697722c..940afb5bc2 100644 --- a/square/shwap/p2p/bitswap/block.go +++ b/share/shwap/p2p/bitswap/block.go @@ -6,8 +6,8 @@ import ( "github.com/ipfs/go-cid" logger "github.com/ipfs/go-log/v2" - "github.com/celestiaorg/celestia-node/square" - "github.com/celestiaorg/celestia-node/square/eds" + "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/share/eds" ) var log = logger.Logger("shwap/bitswap") @@ -30,7 +30,7 @@ type Block interface { Marshal() ([]byte, error) // UnmarshalFn returns closure that unmarshal the Block with the Shwap container. // Unmarshalling involves data validation against the given AxisRoots. - UnmarshalFn(*square.AxisRoots) UnmarshalFn + UnmarshalFn(*share.AxisRoots) UnmarshalFn } // UnmarshalFn is a closure produced by a Block that unmarshalls and validates diff --git a/square/shwap/p2p/bitswap/block_fetch.go b/share/shwap/p2p/bitswap/block_fetch.go similarity index 98% rename from square/shwap/p2p/bitswap/block_fetch.go rename to share/shwap/p2p/bitswap/block_fetch.go index 0c6245559d..94fe5dbdac 100644 --- a/square/shwap/p2p/bitswap/block_fetch.go +++ b/share/shwap/p2p/bitswap/block_fetch.go @@ -11,7 +11,7 @@ import ( blocks "github.com/ipfs/go-block-format" "github.com/ipfs/go-cid" - "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/share" ) // WithFetcher instructs [Fetch] to use the given Fetcher. @@ -37,7 +37,7 @@ func WithStore(store blockstore.Blockstore) FetchOption { func Fetch( ctx context.Context, exchg exchange.Interface, - root *square.AxisRoots, + root *share.AxisRoots, blks []Block, opts ...FetchOption, ) error { @@ -62,7 +62,7 @@ func Fetch( func fetch( ctx context.Context, exchg exchange.Interface, - root *square.AxisRoots, + root *share.AxisRoots, blks []Block, opts ...FetchOption, ) error { diff --git a/square/shwap/p2p/bitswap/block_fetch_test.go b/share/shwap/p2p/bitswap/block_fetch_test.go similarity index 98% rename from square/shwap/p2p/bitswap/block_fetch_test.go rename to share/shwap/p2p/bitswap/block_fetch_test.go index 43eb529076..05b0c78b19 100644 --- a/square/shwap/p2p/bitswap/block_fetch_test.go +++ b/share/shwap/p2p/bitswap/block_fetch_test.go @@ -20,7 +20,7 @@ import ( "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/square/eds" + "github.com/celestiaorg/celestia-node/share/eds" ) func TestFetch_Options(t *testing.T) { diff --git a/square/shwap/p2p/bitswap/block_proto.go b/share/shwap/p2p/bitswap/block_proto.go similarity index 92% rename from square/shwap/p2p/bitswap/block_proto.go rename to share/shwap/p2p/bitswap/block_proto.go index 6ab0243abf..8cab645705 100644 --- a/square/shwap/p2p/bitswap/block_proto.go +++ b/share/shwap/p2p/bitswap/block_proto.go @@ -5,7 +5,7 @@ import ( "github.com/ipfs/go-cid" - bitswappb "github.com/celestiaorg/celestia-node/square/shwap/p2p/bitswap/pb" + bitswappb "github.com/celestiaorg/celestia-node/share/shwap/p2p/bitswap/pb" ) // marshalProto wraps the given Block in composition protobuf and marshals it. diff --git a/square/shwap/p2p/bitswap/block_registry.go b/share/shwap/p2p/bitswap/block_registry.go similarity index 100% rename from square/shwap/p2p/bitswap/block_registry.go rename to share/shwap/p2p/bitswap/block_registry.go diff --git a/square/shwap/p2p/bitswap/block_store.go b/share/shwap/p2p/bitswap/block_store.go similarity index 98% rename from square/shwap/p2p/bitswap/block_store.go rename to share/shwap/p2p/bitswap/block_store.go index ea1cf4e937..910a95c204 100644 --- a/square/shwap/p2p/bitswap/block_store.go +++ b/share/shwap/p2p/bitswap/block_store.go @@ -9,7 +9,7 @@ import ( "github.com/ipfs/go-cid" ipld "github.com/ipfs/go-ipld-format" - "github.com/celestiaorg/celestia-node/square/eds" + "github.com/celestiaorg/celestia-node/share/eds" "github.com/celestiaorg/celestia-node/store" ) diff --git a/square/shwap/p2p/bitswap/block_test.go b/share/shwap/p2p/bitswap/block_test.go similarity index 92% rename from square/shwap/p2p/bitswap/block_test.go rename to share/shwap/p2p/bitswap/block_test.go index e953eb0546..39bb55bc14 100644 --- a/square/shwap/p2p/bitswap/block_test.go +++ b/share/shwap/p2p/bitswap/block_test.go @@ -13,8 +13,8 @@ import ( dssync "github.com/ipfs/go-datastore/sync" "github.com/stretchr/testify/require" - "github.com/celestiaorg/celestia-node/square" - "github.com/celestiaorg/celestia-node/square/eds" + "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/share/eds" ) const ( @@ -103,7 +103,7 @@ func (t *testBlock) Marshal() ([]byte, error) { return t.data, nil } -func (t *testBlock) UnmarshalFn(*square.AxisRoots) UnmarshalFn { +func (t *testBlock) UnmarshalFn(*share.AxisRoots) UnmarshalFn { return func(bytes, _ []byte) error { t.data = bytes time.Sleep(time.Millisecond * 1) diff --git a/square/shwap/p2p/bitswap/cid.go b/share/shwap/p2p/bitswap/cid.go similarity index 100% rename from square/shwap/p2p/bitswap/cid.go rename to share/shwap/p2p/bitswap/cid.go diff --git a/square/shwap/p2p/bitswap/getter.go b/share/shwap/p2p/bitswap/getter.go similarity index 90% rename from square/shwap/p2p/bitswap/getter.go rename to share/shwap/p2p/bitswap/getter.go index a346032b3e..86ce510cb6 100644 --- a/square/shwap/p2p/bitswap/getter.go +++ b/share/shwap/p2p/bitswap/getter.go @@ -12,18 +12,18 @@ import ( "go.opentelemetry.io/otel/trace" "github.com/celestiaorg/celestia-app/v3/pkg/wrapper" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" "github.com/celestiaorg/celestia-node/header" "github.com/celestiaorg/celestia-node/pruner" - "github.com/celestiaorg/celestia-node/square" - "github.com/celestiaorg/celestia-node/square/shwap" + "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/share/shwap" ) var tracer = otel.Tracer("shwap/bitswap") -// Getter implements share.Getter. +// Getter implements gosquare.Getter. type Getter struct { exchange exchange.SessionExchange bstore blockstore.Blockstore @@ -72,7 +72,7 @@ func (g *Getter) GetShares( ctx context.Context, hdr *header.ExtendedHeader, rowIdxs, colIdxs []int, -) ([]share.Share, error) { +) ([]gosquare.Share, error) { if len(rowIdxs) != len(colIdxs) { return nil, fmt.Errorf("row indecies and col indices must be same length") } @@ -104,7 +104,7 @@ func (g *Getter) GetShares( return nil, err } - shares := make([]share.Share, len(blks)) + shares := make([]gosquare.Share, len(blks)) for i, blk := range blks { shares[i] = blk.(*SampleBlock).Container.Share } @@ -118,14 +118,14 @@ func (g *Getter) GetShare( ctx context.Context, hdr *header.ExtendedHeader, row, col int, -) (share.Share, error) { +) (gosquare.Share, error) { shrs, err := g.GetShares(ctx, hdr, []int{row}, []int{col}) if err != nil { - return share.Share{}, err + return gosquare.Share{}, err } if len(shrs) != 1 { - return share.Share{}, fmt.Errorf("expected 1 share row, got %d", len(shrs)) + return gosquare.Share{}, fmt.Errorf("expected 1 share row, got %d", len(shrs)) } return shrs[0], nil @@ -185,16 +185,16 @@ func (g *Getter) GetEDS( func (g *Getter) GetSharesByNamespace( ctx context.Context, hdr *header.ExtendedHeader, - ns share.Namespace, + ns gosquare.Namespace, ) (shwap.NamespaceData, error) { - if err := share.ValidateForData(ns); err != nil { + if err := gosquare.ValidateForData(ns); err != nil { return nil, err } ctx, span := tracer.Start(ctx, "get-shares-by-namespace") defer span.End() - rowIdxs := square.RowsWithNamespace(hdr.DAH, ns) + rowIdxs := share.RowsWithNamespace(hdr.DAH, ns) blks := make([]Block, len(rowIdxs)) for i, rowNdIdx := range rowIdxs { rndblk, err := NewEmptyRowNamespaceDataBlock(hdr.Height(), rowNdIdx, ns, len(hdr.DAH.RowRoots)) @@ -242,8 +242,8 @@ func (g *Getter) session(ctx context.Context, hdr *header.ExtendedHeader) exchan // edsFromRows imports given Rows and computes EDS out of them, assuming enough Rows were provided. // It is designed to reuse Row halves computed during verification on [Fetch] level. -func edsFromRows(roots *square.AxisRoots, rows []shwap.Row) (*rsmt2d.ExtendedDataSquare, error) { - shrs := make([]share.Share, len(roots.RowRoots)*len(roots.RowRoots)) +func edsFromRows(roots *share.AxisRoots, rows []shwap.Row) (*rsmt2d.ExtendedDataSquare, error) { + shrs := make([]gosquare.Share, len(roots.RowRoots)*len(roots.RowRoots)) for i, row := range rows { rowShrs, err := row.Shares() if err != nil { @@ -256,8 +256,8 @@ func edsFromRows(roots *square.AxisRoots, rows []shwap.Row) (*rsmt2d.ExtendedDat } square, err := rsmt2d.ImportExtendedDataSquare( - share.ToBytes(shrs), - square.DefaultRSMT2DCodec(), + gosquare.ToBytes(shrs), + share.DefaultRSMT2DCodec(), wrapper.NewConstructor(uint64(len(roots.RowRoots)/2)), ) if err != nil { diff --git a/square/shwap/p2p/bitswap/getter_test.go b/share/shwap/p2p/bitswap/getter_test.go similarity index 57% rename from square/shwap/p2p/bitswap/getter_test.go rename to share/shwap/p2p/bitswap/getter_test.go index 64365ed7f2..e543e0f76f 100644 --- a/square/shwap/p2p/bitswap/getter_test.go +++ b/share/shwap/p2p/bitswap/getter_test.go @@ -5,21 +5,21 @@ import ( "github.com/stretchr/testify/require" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" - "github.com/celestiaorg/celestia-node/square" - "github.com/celestiaorg/celestia-node/square/eds/edstest" - "github.com/celestiaorg/celestia-node/square/shwap" + "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/share/eds/edstest" + "github.com/celestiaorg/celestia-node/share/shwap" ) func TestEDSFromRows(t *testing.T) { edsIn := edstest.RandEDS(t, 8) - roots, err := square.NewAxisRoots(edsIn) + roots, err := share.NewAxisRoots(edsIn) require.NoError(t, err) rows := make([]shwap.Row, edsIn.Width()/2) for i := range edsIn.Width() / 2 { - rowShrs, err := share.FromBytes(edsIn.Row(i)[:edsIn.Width()/2]) + rowShrs, err := gosquare.FromBytes(edsIn.Row(i)[:edsIn.Width()/2]) require.NoError(t, err) rows[i] = shwap.NewRow(rowShrs, shwap.Left) } diff --git a/square/shwap/p2p/bitswap/pb/bitswap.pb.go b/share/shwap/p2p/bitswap/pb/bitswap.pb.go similarity index 85% rename from square/shwap/p2p/bitswap/pb/bitswap.pb.go rename to share/shwap/p2p/bitswap/pb/bitswap.pb.go index e1f425c41b..a84077e9ef 100644 --- a/square/shwap/p2p/bitswap/pb/bitswap.pb.go +++ b/share/shwap/p2p/bitswap/pb/bitswap.pb.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: square/shwap/p2p/bitswap/pb/bitswap.proto +// source: share/shwap/p2p/bitswap/pb/bitswap.proto package pb @@ -31,7 +31,7 @@ func (m *Block) Reset() { *m = Block{} } func (m *Block) String() string { return proto.CompactTextString(m) } func (*Block) ProtoMessage() {} func (*Block) Descriptor() ([]byte, []int) { - return fileDescriptor_98329a1d35a94c34, []int{0} + return fileDescriptor_09fd4e2ff1d5ce94, []int{0} } func (m *Block) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -79,22 +79,22 @@ func init() { } func init() { - proto.RegisterFile("square/shwap/p2p/bitswap/pb/bitswap.proto", fileDescriptor_98329a1d35a94c34) + proto.RegisterFile("share/shwap/p2p/bitswap/pb/bitswap.proto", fileDescriptor_09fd4e2ff1d5ce94) } -var fileDescriptor_98329a1d35a94c34 = []byte{ - // 172 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xd2, 0x2c, 0x2e, 0x2c, 0x4d, - 0x2c, 0x4a, 0xd5, 0x2f, 0xce, 0x28, 0x4f, 0x2c, 0xd0, 0x2f, 0x30, 0x2a, 0xd0, 0x4f, 0xca, 0x2c, - 0x29, 0x06, 0xb3, 0x93, 0x60, 0x4c, 0xbd, 0x82, 0xa2, 0xfc, 0x92, 0x7c, 0x21, 0x76, 0x28, 0x57, - 0xc9, 0x9c, 0x8b, 0xd5, 0x29, 0x27, 0x3f, 0x39, 0x5b, 0x48, 0x80, 0x8b, 0x39, 0x39, 0x33, 0x45, - 0x82, 0x51, 0x81, 0x51, 0x83, 0x27, 0x08, 0xc4, 0x14, 0x92, 0xe1, 0xe2, 0x4c, 0xce, 0xcf, 0x2b, - 0x49, 0xcc, 0xcc, 0x4b, 0x2d, 0x92, 0x60, 0x02, 0x8b, 0x23, 0x04, 0x9c, 0xa2, 0x4e, 0x3c, 0x92, - 0x63, 0xbc, 0xf0, 0x48, 0x8e, 0xf1, 0xc1, 0x23, 0x39, 0xc6, 0x09, 0x8f, 0xe5, 0x18, 0x2e, 0x3c, - 0x96, 0x63, 0xb8, 0xf1, 0x58, 0x8e, 0x21, 0xca, 0x21, 0x3d, 0xb3, 0x24, 0xa3, 0x34, 0x49, 0x2f, - 0x39, 0x3f, 0x57, 0x3f, 0x39, 0x35, 0x27, 0xb5, 0xb8, 0x24, 0x33, 0x31, 0xbf, 0x28, 0x1d, 0xce, - 0xd6, 0xcd, 0xcb, 0x4f, 0x49, 0xd5, 0xc7, 0xe3, 0xd6, 0x24, 0x36, 0xb0, 0x23, 0x8d, 0x01, 0x01, - 0x00, 0x00, 0xff, 0xff, 0x7d, 0xd5, 0x78, 0x73, 0xd1, 0x00, 0x00, 0x00, +var fileDescriptor_09fd4e2ff1d5ce94 = []byte{ + // 171 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xd2, 0x28, 0xce, 0x48, 0x2c, + 0x4a, 0xd5, 0x2f, 0xce, 0x28, 0x4f, 0x2c, 0xd0, 0x2f, 0x30, 0x2a, 0xd0, 0x4f, 0xca, 0x2c, 0x29, + 0x06, 0xb3, 0x93, 0x60, 0x4c, 0xbd, 0x82, 0xa2, 0xfc, 0x92, 0x7c, 0x21, 0x76, 0x28, 0x57, 0xc9, + 0x9c, 0x8b, 0xd5, 0x29, 0x27, 0x3f, 0x39, 0x5b, 0x48, 0x80, 0x8b, 0x39, 0x39, 0x33, 0x45, 0x82, + 0x51, 0x81, 0x51, 0x83, 0x27, 0x08, 0xc4, 0x14, 0x92, 0xe1, 0xe2, 0x4c, 0xce, 0xcf, 0x2b, 0x49, + 0xcc, 0xcc, 0x4b, 0x2d, 0x92, 0x60, 0x02, 0x8b, 0x23, 0x04, 0x9c, 0x22, 0x4f, 0x3c, 0x92, 0x63, + 0xbc, 0xf0, 0x48, 0x8e, 0xf1, 0xc1, 0x23, 0x39, 0xc6, 0x09, 0x8f, 0xe5, 0x18, 0x2e, 0x3c, 0x96, + 0x63, 0xb8, 0xf1, 0x58, 0x8e, 0x21, 0xca, 0x3e, 0x3d, 0xb3, 0x24, 0xa3, 0x34, 0x49, 0x2f, 0x39, + 0x3f, 0x57, 0x3f, 0x39, 0x35, 0x27, 0xb5, 0xb8, 0x24, 0x33, 0x31, 0xbf, 0x28, 0x1d, 0xce, 0xd6, + 0xcd, 0xcb, 0x4f, 0x01, 0x39, 0x12, 0x97, 0x53, 0x93, 0xd8, 0xc0, 0x6e, 0x34, 0x06, 0x04, 0x00, + 0x00, 0xff, 0xff, 0xe7, 0x9c, 0x32, 0xc5, 0xcf, 0x00, 0x00, 0x00, } func (m *Block) Marshal() (dAtA []byte, err error) { diff --git a/square/shwap/p2p/bitswap/pb/bitswap.proto b/share/shwap/p2p/bitswap/pb/bitswap.proto similarity index 70% rename from square/shwap/p2p/bitswap/pb/bitswap.proto rename to share/shwap/p2p/bitswap/pb/bitswap.proto index b620e98b60..3ba19aa49c 100644 --- a/square/shwap/p2p/bitswap/pb/bitswap.proto +++ b/share/shwap/p2p/bitswap/pb/bitswap.proto @@ -1,7 +1,7 @@ // Defined in CIP-19 https://github.com/celestiaorg/CIPs/blob/82aeb7dfc472105a11babffd548c730c899a3d24/cips/cip-19.md syntax = "proto3"; package bitswap; -option go_package = "github.com/celestiaorg/celestia-node/square/shwap/p2p/bitswap/pb"; +option go_package = "github.com/celestiaorg/celestia-node/share/shwap/p2p/bitswap/pb"; message Block { bytes cid = 1; diff --git a/square/shwap/p2p/bitswap/row_block.go b/share/shwap/p2p/bitswap/row_block.go similarity index 90% rename from square/shwap/p2p/bitswap/row_block.go rename to share/shwap/p2p/bitswap/row_block.go index cfc57dc765..4763f63954 100644 --- a/square/shwap/p2p/bitswap/row_block.go +++ b/share/shwap/p2p/bitswap/row_block.go @@ -8,10 +8,10 @@ import ( "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/square" - "github.com/celestiaorg/celestia-node/square/eds" - "github.com/celestiaorg/celestia-node/square/shwap" - shwappb "github.com/celestiaorg/celestia-node/square/shwap/pb" + "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/share/eds" + "github.com/celestiaorg/celestia-node/share/shwap" + shwappb "github.com/celestiaorg/celestia-node/share/shwap/pb" ) const ( @@ -96,7 +96,7 @@ func (rb *RowBlock) Populate(ctx context.Context, eds eds.Accessor) error { return nil } -func (rb *RowBlock) UnmarshalFn(root *square.AxisRoots) UnmarshalFn { +func (rb *RowBlock) UnmarshalFn(root *share.AxisRoots) UnmarshalFn { return func(cntrData, idData []byte) error { if !rb.Container.IsEmpty() { return nil diff --git a/square/shwap/p2p/bitswap/row_block_test.go b/share/shwap/p2p/bitswap/row_block_test.go similarity index 82% rename from square/shwap/p2p/bitswap/row_block_test.go rename to share/shwap/p2p/bitswap/row_block_test.go index 9b48338957..f609683da5 100644 --- a/square/shwap/p2p/bitswap/row_block_test.go +++ b/share/shwap/p2p/bitswap/row_block_test.go @@ -7,8 +7,8 @@ import ( "github.com/stretchr/testify/require" - "github.com/celestiaorg/celestia-node/square" - "github.com/celestiaorg/celestia-node/square/eds/edstest" + "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/share/eds/edstest" ) func TestRow_FetchRoundtrip(t *testing.T) { @@ -16,7 +16,7 @@ func TestRow_FetchRoundtrip(t *testing.T) { defer cancel() eds := edstest.RandEDS(t, 4) - root, err := square.NewAxisRoots(eds) + root, err := share.NewAxisRoots(eds) require.NoError(t, err) exchange := newExchangeOverEDS(ctx, t, eds) diff --git a/square/shwap/p2p/bitswap/row_namespace_data_block.go b/share/shwap/p2p/bitswap/row_namespace_data_block.go similarity index 89% rename from square/shwap/p2p/bitswap/row_namespace_data_block.go rename to share/shwap/p2p/bitswap/row_namespace_data_block.go index 76778b0f53..704ad3f616 100644 --- a/square/shwap/p2p/bitswap/row_namespace_data_block.go +++ b/share/shwap/p2p/bitswap/row_namespace_data_block.go @@ -6,12 +6,12 @@ import ( "github.com/ipfs/go-cid" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" - "github.com/celestiaorg/celestia-node/square" - "github.com/celestiaorg/celestia-node/square/eds" - "github.com/celestiaorg/celestia-node/square/shwap" - shwappb "github.com/celestiaorg/celestia-node/square/shwap/pb" + "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/share/eds" + "github.com/celestiaorg/celestia-node/share/shwap" + shwappb "github.com/celestiaorg/celestia-node/share/shwap/pb" ) const ( @@ -44,7 +44,7 @@ type RowNamespaceDataBlock struct { func NewEmptyRowNamespaceDataBlock( height uint64, rowIdx int, - namespace share.Namespace, + namespace gosquare.Namespace, edsSize int, ) (*RowNamespaceDataBlock, error) { id, err := shwap.NewRowNamespaceDataID(height, rowIdx, namespace, edsSize) @@ -102,7 +102,7 @@ func (rndb *RowNamespaceDataBlock) Populate(ctx context.Context, eds eds.Accesso return nil } -func (rndb *RowNamespaceDataBlock) UnmarshalFn(root *square.AxisRoots) UnmarshalFn { +func (rndb *RowNamespaceDataBlock) UnmarshalFn(root *share.AxisRoots) UnmarshalFn { return func(cntrData, idData []byte) error { if !rndb.Container.IsEmpty() { return nil diff --git a/square/shwap/p2p/bitswap/row_namespace_data_block_test.go b/share/shwap/p2p/bitswap/row_namespace_data_block_test.go similarity index 76% rename from square/shwap/p2p/bitswap/row_namespace_data_block_test.go rename to share/shwap/p2p/bitswap/row_namespace_data_block_test.go index fecf5494ca..552c0d31fe 100644 --- a/square/shwap/p2p/bitswap/row_namespace_data_block_test.go +++ b/share/shwap/p2p/bitswap/row_namespace_data_block_test.go @@ -7,21 +7,21 @@ import ( "github.com/stretchr/testify/require" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" - "github.com/celestiaorg/celestia-node/square" - "github.com/celestiaorg/celestia-node/square/eds/edstest" + "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/share/eds/edstest" ) func TestRowNamespaceData_FetchRoundtrip(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), time.Second*5) defer cancel() - namespace := share.RandomNamespace() + namespace := gosquare.RandomNamespace() eds, root := edstest.RandEDSWithNamespace(t, namespace, 64, 16) exchange := newExchangeOverEDS(ctx, t, eds) - rowIdxs := square.RowsWithNamespace(root, namespace) + rowIdxs := share.RowsWithNamespace(root, namespace) blks := make([]Block, len(rowIdxs)) for i, rowIdx := range rowIdxs { blk, err := NewEmptyRowNamespaceDataBlock(1, rowIdx, namespace, len(root.RowRoots)) diff --git a/square/shwap/p2p/bitswap/sample_block.go b/share/shwap/p2p/bitswap/sample_block.go similarity index 90% rename from square/shwap/p2p/bitswap/sample_block.go rename to share/shwap/p2p/bitswap/sample_block.go index d7e7fdd884..062369c0be 100644 --- a/square/shwap/p2p/bitswap/sample_block.go +++ b/share/shwap/p2p/bitswap/sample_block.go @@ -6,10 +6,10 @@ import ( "github.com/ipfs/go-cid" - "github.com/celestiaorg/celestia-node/square" - "github.com/celestiaorg/celestia-node/square/eds" - "github.com/celestiaorg/celestia-node/square/shwap" - shwappb "github.com/celestiaorg/celestia-node/square/shwap/pb" + "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/share/eds" + "github.com/celestiaorg/celestia-node/share/shwap" + shwappb "github.com/celestiaorg/celestia-node/share/shwap/pb" ) const ( @@ -95,7 +95,7 @@ func (sb *SampleBlock) Populate(ctx context.Context, eds eds.Accessor) error { return nil } -func (sb *SampleBlock) UnmarshalFn(root *square.AxisRoots) UnmarshalFn { +func (sb *SampleBlock) UnmarshalFn(root *share.AxisRoots) UnmarshalFn { return func(cntrData, idData []byte) error { if !sb.Container.IsEmpty() { return nil diff --git a/square/shwap/p2p/bitswap/sample_block_test.go b/share/shwap/p2p/bitswap/sample_block_test.go similarity index 85% rename from square/shwap/p2p/bitswap/sample_block_test.go rename to share/shwap/p2p/bitswap/sample_block_test.go index ec7364e71f..2a28e7e4c9 100644 --- a/square/shwap/p2p/bitswap/sample_block_test.go +++ b/share/shwap/p2p/bitswap/sample_block_test.go @@ -7,8 +7,8 @@ import ( "github.com/stretchr/testify/require" - "github.com/celestiaorg/celestia-node/square" - "github.com/celestiaorg/celestia-node/square/eds/edstest" + "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/share/eds/edstest" ) func TestSample_FetchRoundtrip(t *testing.T) { @@ -16,7 +16,7 @@ func TestSample_FetchRoundtrip(t *testing.T) { defer cancel() eds := edstest.RandEDS(t, 32) - root, err := square.NewAxisRoots(eds) + root, err := share.NewAxisRoots(eds) require.NoError(t, err) exchange := newExchangeOverEDS(ctx, t, eds) diff --git a/square/shwap/p2p/discovery/backoff.go b/share/shwap/p2p/discovery/backoff.go similarity index 100% rename from square/shwap/p2p/discovery/backoff.go rename to share/shwap/p2p/discovery/backoff.go diff --git a/square/shwap/p2p/discovery/backoff_test.go b/share/shwap/p2p/discovery/backoff_test.go similarity index 100% rename from square/shwap/p2p/discovery/backoff_test.go rename to share/shwap/p2p/discovery/backoff_test.go diff --git a/square/shwap/p2p/discovery/dht.go b/share/shwap/p2p/discovery/dht.go similarity index 100% rename from square/shwap/p2p/discovery/dht.go rename to share/shwap/p2p/discovery/dht.go diff --git a/square/shwap/p2p/discovery/discovery.go b/share/shwap/p2p/discovery/discovery.go similarity index 100% rename from square/shwap/p2p/discovery/discovery.go rename to share/shwap/p2p/discovery/discovery.go diff --git a/square/shwap/p2p/discovery/discovery_test.go b/share/shwap/p2p/discovery/discovery_test.go similarity index 100% rename from square/shwap/p2p/discovery/discovery_test.go rename to share/shwap/p2p/discovery/discovery_test.go diff --git a/square/shwap/p2p/discovery/metrics.go b/share/shwap/p2p/discovery/metrics.go similarity index 100% rename from square/shwap/p2p/discovery/metrics.go rename to share/shwap/p2p/discovery/metrics.go diff --git a/square/shwap/p2p/discovery/options.go b/share/shwap/p2p/discovery/options.go similarity index 100% rename from square/shwap/p2p/discovery/options.go rename to share/shwap/p2p/discovery/options.go diff --git a/square/shwap/p2p/discovery/set.go b/share/shwap/p2p/discovery/set.go similarity index 100% rename from square/shwap/p2p/discovery/set.go rename to share/shwap/p2p/discovery/set.go diff --git a/square/shwap/p2p/discovery/set_test.go b/share/shwap/p2p/discovery/set_test.go similarity index 100% rename from square/shwap/p2p/discovery/set_test.go rename to share/shwap/p2p/discovery/set_test.go diff --git a/square/shwap/p2p/shrex/doc.go b/share/shwap/p2p/shrex/doc.go similarity index 94% rename from square/shwap/p2p/shrex/doc.go rename to share/shwap/p2p/shrex/doc.go index 9654532842..fee7a07c93 100644 --- a/square/shwap/p2p/shrex/doc.go +++ b/share/shwap/p2p/shrex/doc.go @@ -8,7 +8,7 @@ // // - shrexeds: a request/response protocol that is used to request extended data square shares from peers. // This protocol exchanges the original data square in between the client and server, and it's up to the -// receiver to compute the extended data square. +// receiver to compute the extended data share. // // This package also defines a peer manager that is used to manage network peers that can be used to exchange // shares. The peer manager is primarily responsible for providing peers to request shares from, diff --git a/square/shwap/p2p/shrex/error.go b/share/shwap/p2p/shrex/error.go similarity index 100% rename from square/shwap/p2p/shrex/error.go rename to share/shwap/p2p/shrex/error.go diff --git a/square/shwap/p2p/shrex/error_test.go b/share/shwap/p2p/shrex/error_test.go similarity index 100% rename from square/shwap/p2p/shrex/error_test.go rename to share/shwap/p2p/shrex/error_test.go diff --git a/square/shwap/p2p/shrex/errors.go b/share/shwap/p2p/shrex/errors.go similarity index 100% rename from square/shwap/p2p/shrex/errors.go rename to share/shwap/p2p/shrex/errors.go diff --git a/square/shwap/p2p/shrex/metrics.go b/share/shwap/p2p/shrex/metrics.go similarity index 100% rename from square/shwap/p2p/shrex/metrics.go rename to share/shwap/p2p/shrex/metrics.go diff --git a/square/shwap/p2p/shrex/middleware.go b/share/shwap/p2p/shrex/middleware.go similarity index 100% rename from square/shwap/p2p/shrex/middleware.go rename to share/shwap/p2p/shrex/middleware.go diff --git a/square/shwap/p2p/shrex/params.go b/share/shwap/p2p/shrex/params.go similarity index 100% rename from square/shwap/p2p/shrex/params.go rename to share/shwap/p2p/shrex/params.go diff --git a/square/shwap/p2p/shrex/pb/shrex.pb.go b/share/shwap/p2p/shrex/pb/shrex.pb.go similarity index 81% rename from square/shwap/p2p/shrex/pb/shrex.pb.go rename to share/shwap/p2p/shrex/pb/shrex.pb.go index 48171b5135..88322b1985 100644 --- a/square/shwap/p2p/shrex/pb/shrex.pb.go +++ b/share/shwap/p2p/shrex/pb/shrex.pb.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: square/shwap/p2p/shrex/pb/shrex.proto +// source: share/shwap/p2p/shrex/pb/shrex.proto package pb @@ -50,7 +50,7 @@ func (x Status) String() string { } func (Status) EnumDescriptor() ([]byte, []int) { - return fileDescriptor_ade548694c6c6a45, []int{0} + return fileDescriptor_68dfd78ade756110, []int{0} } type Response struct { @@ -61,7 +61,7 @@ func (m *Response) Reset() { *m = Response{} } func (m *Response) String() string { return proto.CompactTextString(m) } func (*Response) ProtoMessage() {} func (*Response) Descriptor() ([]byte, []int) { - return fileDescriptor_ade548694c6c6a45, []int{0} + return fileDescriptor_68dfd78ade756110, []int{0} } func (m *Response) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -103,25 +103,25 @@ func init() { } func init() { - proto.RegisterFile("square/shwap/p2p/shrex/pb/shrex.proto", fileDescriptor_ade548694c6c6a45) + proto.RegisterFile("share/shwap/p2p/shrex/pb/shrex.proto", fileDescriptor_68dfd78ade756110) } -var fileDescriptor_ade548694c6c6a45 = []byte{ +var fileDescriptor_68dfd78ade756110 = []byte{ // 218 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x2d, 0x2e, 0x2c, 0x4d, - 0x2c, 0x4a, 0xd5, 0x2f, 0xce, 0x28, 0x4f, 0x2c, 0xd0, 0x2f, 0x30, 0x2a, 0xd0, 0x2f, 0xce, 0x28, - 0x4a, 0xad, 0xd0, 0x2f, 0x48, 0x82, 0x30, 0xf4, 0x0a, 0x8a, 0xf2, 0x4b, 0xf2, 0x95, 0xb4, 0xb9, - 0x38, 0x82, 0x52, 0x8b, 0x0b, 0xf2, 0xf3, 0x8a, 0x53, 0x85, 0xe4, 0xb9, 0xd8, 0x8a, 0x4b, 0x12, - 0x4b, 0x4a, 0x8b, 0x25, 0x18, 0x15, 0x18, 0x35, 0xf8, 0x8c, 0xd8, 0xf5, 0x82, 0xc1, 0xdc, 0x20, - 0xa8, 0xb0, 0x96, 0x15, 0x17, 0x1b, 0x44, 0x44, 0x88, 0x9b, 0x8b, 0xdd, 0xd3, 0x2f, 0xcc, 0xd1, - 0xc7, 0xd3, 0x45, 0x80, 0x41, 0x88, 0x8d, 0x8b, 0xc9, 0xdf, 0x5b, 0x80, 0x51, 0x88, 0x97, 0x8b, - 0xd3, 0xcf, 0x3f, 0x24, 0xde, 0xcd, 0x3f, 0xd4, 0xcf, 0x45, 0x80, 0x49, 0x88, 0x87, 0x8b, 0xc3, - 0xd3, 0x2f, 0xc4, 0x35, 0xc8, 0xcf, 0xd1, 0x47, 0x80, 0xd9, 0x29, 0xe2, 0xc4, 0x23, 0x39, 0xc6, - 0x0b, 0x8f, 0xe4, 0x18, 0x1f, 0x3c, 0x92, 0x63, 0x9c, 0xf0, 0x58, 0x8e, 0xe1, 0xc2, 0x63, 0x39, - 0x86, 0x1b, 0x8f, 0xe5, 0x18, 0xa2, 0xec, 0xd2, 0x33, 0x4b, 0x32, 0x4a, 0x93, 0xf4, 0x92, 0xf3, - 0x73, 0xf5, 0x93, 0x53, 0x73, 0x52, 0x8b, 0x4b, 0x32, 0x13, 0xf3, 0x8b, 0xd2, 0xe1, 0x6c, 0xdd, - 0xbc, 0xfc, 0x94, 0x54, 0x7d, 0x9c, 0xde, 0x49, 0x62, 0x03, 0xfb, 0xc4, 0x18, 0x10, 0x00, 0x00, - 0xff, 0xff, 0x5d, 0x99, 0xc5, 0x28, 0xf2, 0x00, 0x00, 0x00, + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x29, 0xce, 0x48, 0x2c, + 0x4a, 0xd5, 0x2f, 0xce, 0x28, 0x4f, 0x2c, 0xd0, 0x2f, 0x30, 0x2a, 0xd0, 0x2f, 0xce, 0x28, 0x4a, + 0xad, 0xd0, 0x2f, 0x48, 0x82, 0x30, 0xf4, 0x0a, 0x8a, 0xf2, 0x4b, 0xf2, 0x95, 0xb4, 0xb9, 0x38, + 0x82, 0x52, 0x8b, 0x0b, 0xf2, 0xf3, 0x8a, 0x53, 0x85, 0xe4, 0xb9, 0xd8, 0x8a, 0x4b, 0x12, 0x4b, + 0x4a, 0x8b, 0x25, 0x18, 0x15, 0x18, 0x35, 0xf8, 0x8c, 0xd8, 0xf5, 0x82, 0xc1, 0xdc, 0x20, 0xa8, + 0xb0, 0x96, 0x15, 0x17, 0x1b, 0x44, 0x44, 0x88, 0x9b, 0x8b, 0xdd, 0xd3, 0x2f, 0xcc, 0xd1, 0xc7, + 0xd3, 0x45, 0x80, 0x41, 0x88, 0x8d, 0x8b, 0xc9, 0xdf, 0x5b, 0x80, 0x51, 0x88, 0x97, 0x8b, 0xd3, + 0xcf, 0x3f, 0x24, 0xde, 0xcd, 0x3f, 0xd4, 0xcf, 0x45, 0x80, 0x49, 0x88, 0x87, 0x8b, 0xc3, 0xd3, + 0x2f, 0xc4, 0x35, 0xc8, 0xcf, 0xd1, 0x47, 0x80, 0xd9, 0x29, 0xfc, 0xc4, 0x23, 0x39, 0xc6, 0x0b, + 0x8f, 0xe4, 0x18, 0x1f, 0x3c, 0x92, 0x63, 0x9c, 0xf0, 0x58, 0x8e, 0xe1, 0xc2, 0x63, 0x39, 0x86, + 0x1b, 0x8f, 0xe5, 0x18, 0xa2, 0x6c, 0xd3, 0x33, 0x4b, 0x32, 0x4a, 0x93, 0xf4, 0x92, 0xf3, 0x73, + 0xf5, 0x93, 0x53, 0x73, 0x52, 0x8b, 0x4b, 0x32, 0x13, 0xf3, 0x8b, 0xd2, 0xe1, 0x6c, 0xdd, 0xbc, + 0xfc, 0x14, 0x90, 0x3f, 0xb0, 0xfb, 0x26, 0x89, 0x0d, 0xec, 0x11, 0x63, 0x40, 0x00, 0x00, 0x00, + 0xff, 0xff, 0xd8, 0xb0, 0x4b, 0x58, 0xf0, 0x00, 0x00, 0x00, } func (m *Response) Marshal() (dAtA []byte, err error) { diff --git a/square/shwap/p2p/shrex/pb/shrex.proto b/share/shwap/p2p/shrex/pb/shrex.proto similarity index 69% rename from square/shwap/p2p/shrex/pb/shrex.proto rename to share/shwap/p2p/shrex/pb/shrex.proto index 0dac0f433b..7b3a57227d 100644 --- a/square/shwap/p2p/shrex/pb/shrex.proto +++ b/share/shwap/p2p/shrex/pb/shrex.proto @@ -1,6 +1,6 @@ syntax = "proto3"; -option go_package = "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/pb"; +option go_package = "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/pb"; enum Status { INVALID = 0; diff --git a/square/shwap/p2p/shrex/peers/doc.go b/share/shwap/p2p/shrex/peers/doc.go similarity index 100% rename from square/shwap/p2p/shrex/peers/doc.go rename to share/shwap/p2p/shrex/peers/doc.go diff --git a/square/shwap/p2p/shrex/peers/manager.go b/share/shwap/p2p/shrex/peers/manager.go similarity index 97% rename from square/shwap/p2p/shrex/peers/manager.go rename to share/shwap/p2p/shrex/peers/manager.go index 9c77496932..857c5ee937 100644 --- a/square/shwap/p2p/shrex/peers/manager.go +++ b/share/shwap/p2p/shrex/peers/manager.go @@ -20,8 +20,8 @@ import ( libhead "github.com/celestiaorg/go-header" "github.com/celestiaorg/celestia-node/header" - "github.com/celestiaorg/celestia-node/square" - "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrexsub" + "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrexsub" ) const ( @@ -202,7 +202,7 @@ func (m *Manager) Stop(ctx context.Context) error { // nodes, it will wait until any peer appear in either source or timeout happen. // After fetching data using given peer, caller is required to call returned DoneFunc using // appropriate result value -func (m *Manager) Peer(ctx context.Context, datahash square.DataHash, height uint64, +func (m *Manager) Peer(ctx context.Context, datahash share.DataHash, height uint64, ) (peer.ID, DoneFunc, error) { p := m.validatedPool(datahash.String(), height) @@ -255,7 +255,7 @@ func (m *Manager) UpdateNodePool(peerID peer.ID, isAdded bool) { func (m *Manager) newPeer( ctx context.Context, - datahash square.DataHash, + datahash share.DataHash, peerID peer.ID, source peerSource, poolSize int, @@ -271,7 +271,7 @@ func (m *Manager) newPeer( return peerID, m.doneFunc(datahash, peerID, source), nil } -func (m *Manager) doneFunc(datahash square.DataHash, peerID peer.ID, source peerSource) DoneFunc { +func (m *Manager) doneFunc(datahash share.DataHash, peerID peer.ID, source peerSource) DoneFunc { return func(result result) { log.Debugw("set peer result", "hash", datahash.String(), @@ -437,7 +437,7 @@ func (m *Manager) isBlacklistedPeer(peerID peer.ID) bool { return !m.connGater.InterceptPeerDial(peerID) } -func (m *Manager) isBlacklistedHash(hash square.DataHash) bool { +func (m *Manager) isBlacklistedHash(hash share.DataHash) bool { m.lock.Lock() defer m.lock.Unlock() return m.blacklistedHashes[hash.String()] diff --git a/square/shwap/p2p/shrex/peers/manager_test.go b/share/shwap/p2p/shrex/peers/manager_test.go similarity index 97% rename from square/shwap/p2p/shrex/peers/manager_test.go rename to share/shwap/p2p/shrex/peers/manager_test.go index 46e1024125..592f964e64 100644 --- a/square/shwap/p2p/shrex/peers/manager_test.go +++ b/share/shwap/p2p/shrex/peers/manager_test.go @@ -21,9 +21,9 @@ import ( libhead "github.com/celestiaorg/go-header" "github.com/celestiaorg/celestia-node/header" - "github.com/celestiaorg/celestia-node/square" - "github.com/celestiaorg/celestia-node/square/shwap/p2p/discovery" - "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrexsub" + "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/share/shwap/p2p/discovery" + "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrexsub" ) func TestManager(t *testing.T) { @@ -127,13 +127,13 @@ func TestManager(t *testing.T) { // create unvalidated pool peerID := peer.ID("peer1") msg := shrexsub.Notification{ - DataHash: square.DataHash("datahash1datahash1datahash1datahash1datahash1"), + DataHash: share.DataHash("datahash1datahash1datahash1datahash1datahash1"), Height: 2, } manager.Validate(ctx, peerID, msg) // create validated pool - validDataHash := square.DataHash("datahash2") + validDataHash := share.DataHash("datahash2") manager.nodes.add("full") // add FN to unblock Peer call manager.Peer(ctx, validDataHash, h.Height()) //nolint:errcheck require.Len(t, manager.pools, 3) @@ -237,7 +237,7 @@ func TestManager(t *testing.T) { // create shrexSub msg with height lower than first header from headerSub msg := shrexsub.Notification{ - DataHash: square.DataHash("datahash"), + DataHash: share.DataHash("datahash"), Height: h.Height() - 1, } result := manager.Validate(ctx, "peer", msg) @@ -265,7 +265,7 @@ func TestManager(t *testing.T) { // create shrexSub msg with height lower than first header from headerSub msg := shrexsub.Notification{ - DataHash: square.DataHash("datahash"), + DataHash: share.DataHash("datahash"), Height: h.Height() - 1, } result := manager.Validate(ctx, "peer", msg) @@ -308,7 +308,7 @@ func TestManager(t *testing.T) { // create shrexSub msg with height lower than storedPoolsAmount msg := shrexsub.Notification{ - DataHash: square.DataHash("datahash"), + DataHash: share.DataHash("datahash"), Height: h.Height() - storedPoolsAmount - 3, } result := manager.Validate(ctx, "peer", msg) diff --git a/square/shwap/p2p/shrex/peers/metrics.go b/share/shwap/p2p/shrex/peers/metrics.go similarity index 99% rename from square/shwap/p2p/shrex/peers/metrics.go rename to share/shwap/p2p/shrex/peers/metrics.go index 67bdb5caf0..d401d6a4fc 100644 --- a/square/shwap/p2p/shrex/peers/metrics.go +++ b/share/shwap/p2p/shrex/peers/metrics.go @@ -13,7 +13,7 @@ import ( "go.opentelemetry.io/otel/metric" "github.com/celestiaorg/celestia-node/libs/utils" - "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrexsub" + "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrexsub" ) const ( diff --git a/square/shwap/p2p/shrex/peers/options.go b/share/shwap/p2p/shrex/peers/options.go similarity index 97% rename from square/shwap/p2p/shrex/peers/options.go rename to share/shwap/p2p/shrex/peers/options.go index cbacca3267..10957e7651 100644 --- a/square/shwap/p2p/shrex/peers/options.go +++ b/share/shwap/p2p/shrex/peers/options.go @@ -7,7 +7,7 @@ import ( libhead "github.com/celestiaorg/go-header" "github.com/celestiaorg/celestia-node/header" - "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrexsub" + "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrexsub" ) type Parameters struct { diff --git a/square/shwap/p2p/shrex/peers/pool.go b/share/shwap/p2p/shrex/peers/pool.go similarity index 100% rename from square/shwap/p2p/shrex/peers/pool.go rename to share/shwap/p2p/shrex/peers/pool.go diff --git a/square/shwap/p2p/shrex/peers/pool_test.go b/share/shwap/p2p/shrex/peers/pool_test.go similarity index 100% rename from square/shwap/p2p/shrex/peers/pool_test.go rename to share/shwap/p2p/shrex/peers/pool_test.go diff --git a/square/shwap/p2p/shrex/peers/timedqueue.go b/share/shwap/p2p/shrex/peers/timedqueue.go similarity index 100% rename from square/shwap/p2p/shrex/peers/timedqueue.go rename to share/shwap/p2p/shrex/peers/timedqueue.go diff --git a/square/shwap/p2p/shrex/peers/timedqueue_test.go b/share/shwap/p2p/shrex/peers/timedqueue_test.go similarity index 100% rename from square/shwap/p2p/shrex/peers/timedqueue_test.go rename to share/shwap/p2p/shrex/peers/timedqueue_test.go diff --git a/square/shwap/p2p/shrex/recovery.go b/share/shwap/p2p/shrex/recovery.go similarity index 100% rename from square/shwap/p2p/shrex/recovery.go rename to share/shwap/p2p/shrex/recovery.go diff --git a/square/shwap/p2p/shrex/shrex_getter/shrex.go b/share/shwap/p2p/shrex/shrex_getter/shrex.go similarity index 90% rename from square/shwap/p2p/shrex/shrex_getter/shrex.go rename to share/shwap/p2p/shrex/shrex_getter/shrex.go index 099d62272e..c87b6990a5 100644 --- a/square/shwap/p2p/shrex/shrex_getter/shrex.go +++ b/share/shwap/p2p/shrex/shrex_getter/shrex.go @@ -13,18 +13,18 @@ import ( "go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/trace" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" "github.com/celestiaorg/celestia-node/header" "github.com/celestiaorg/celestia-node/libs/utils" "github.com/celestiaorg/celestia-node/pruner" - "github.com/celestiaorg/celestia-node/square" - "github.com/celestiaorg/celestia-node/square/shwap" - "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex" - "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/peers" - "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrexeds" - "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrexnd" + "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/share/shwap" + "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex" + "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/peers" + "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrexeds" + "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrexnd" ) var ( @@ -91,7 +91,7 @@ func (sg *Getter) WithMetrics() error { return nil } -// Getter is a share.Getter that uses the shrex/eds and shrex/nd protocol to retrieve shares. +// Getter is a gosquare.Getter that uses the shrex/eds and shrex/nd protocol to retrieve shares. type Getter struct { edsClient *shrexeds.Client ndClient *shrexnd.Client @@ -146,8 +146,8 @@ func (sg *Getter) Stop(ctx context.Context) error { return sg.archivalPeerManager.Stop(ctx) } -func (sg *Getter) GetShare(context.Context, *header.ExtendedHeader, int, int) (share.Share, error) { - return share.Share{}, fmt.Errorf("getter/shrex: GetShare %w", shwap.ErrOperationNotSupported) +func (sg *Getter) GetShare(context.Context, *header.ExtendedHeader, int, int) (gosquare.Share, error) { + return gosquare.Share{}, fmt.Errorf("getter/shrex: GetShare %w", shwap.ErrOperationNotSupported) } func (sg *Getter) GetEDS(ctx context.Context, header *header.ExtendedHeader) (*rsmt2d.ExtendedDataSquare, error) { @@ -158,8 +158,8 @@ func (sg *Getter) GetEDS(ctx context.Context, header *header.ExtendedHeader) (*r }() // short circuit if the data root is empty - if header.DAH.Equals(square.EmptyEDSRoots()) { - return square.EmptyEDS(), nil + if header.DAH.Equals(share.EmptyEDSRoots()) { + return share.EmptyEDS(), nil } var attempt int @@ -217,9 +217,9 @@ func (sg *Getter) GetEDS(ctx context.Context, header *header.ExtendedHeader) (*r func (sg *Getter) GetSharesByNamespace( ctx context.Context, header *header.ExtendedHeader, - namespace share.Namespace, + namespace gosquare.Namespace, ) (shwap.NamespaceData, error) { - if err := share.ValidateForData(namespace); err != nil { + if err := gosquare.ValidateForData(namespace); err != nil { return nil, err } var ( @@ -235,7 +235,7 @@ func (sg *Getter) GetSharesByNamespace( // verify that the namespace could exist inside the roots before starting network requests dah := header.DAH - rowIdxs := square.RowsWithNamespace(dah, namespace) + rowIdxs := share.RowsWithNamespace(dah, namespace) if len(rowIdxs) == 0 { return shwap.NamespaceData{}, nil } diff --git a/square/shwap/p2p/shrex/shrex_getter/shrex_test.go b/share/shwap/p2p/shrex/shrex_getter/shrex_test.go similarity index 87% rename from square/shwap/p2p/shrex/shrex_getter/shrex_test.go rename to share/shwap/p2p/shrex/shrex_getter/shrex_test.go index 80d7765cdc..167a0b40a1 100644 --- a/square/shwap/p2p/shrex/shrex_getter/shrex_test.go +++ b/share/shwap/p2p/shrex/shrex_getter/shrex_test.go @@ -17,7 +17,7 @@ import ( "github.com/stretchr/testify/require" libhead "github.com/celestiaorg/go-header" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt" "github.com/celestiaorg/rsmt2d" @@ -25,13 +25,13 @@ import ( "github.com/celestiaorg/celestia-node/header/headertest" "github.com/celestiaorg/celestia-node/pruner/full" "github.com/celestiaorg/celestia-node/pruner/light" - "github.com/celestiaorg/celestia-node/square" - "github.com/celestiaorg/celestia-node/square/eds/edstest" - "github.com/celestiaorg/celestia-node/square/shwap" - "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/peers" - "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrexeds" - "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrexnd" - "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrexsub" + "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/share/eds/edstest" + "github.com/celestiaorg/celestia-node/share/shwap" + "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/peers" + "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrexeds" + "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrexnd" + "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrexsub" "github.com/celestiaorg/celestia-node/store" ) @@ -71,7 +71,7 @@ func TestShrexGetter(t *testing.T) { // generate test data size := 64 - namespace := share.RandomNamespace() + namespace := gosquare.RandomNamespace() height := height.Add(1) randEDS, roots := edstest.RandEDSWithNamespace(t, namespace, size*size, size) eh := headertest.RandExtendedHeaderWithRoot(t, roots) @@ -126,10 +126,10 @@ func TestShrexGetter(t *testing.T) { }) // namespace inside root range - nID, err := share.AddInt(maxNamespace, -1) + nID, err := gosquare.AddInt(maxNamespace, -1) require.NoError(t, err) // check for namespace to be between max and min namespace in root - require.Len(t, square.RowsWithNamespace(roots, nID), 1) + require.Len(t, share.RowsWithNamespace(roots, nID), 1) emptyShares, err := getter.GetSharesByNamespace(ctx, eh, nID) require.NoError(t, err) @@ -138,10 +138,10 @@ func TestShrexGetter(t *testing.T) { require.Nil(t, emptyShares.Verify(roots, nID)) // namespace outside root range - nID, err = share.AddInt(maxNamespace, 1) + nID, err = gosquare.AddInt(maxNamespace, 1) require.NoError(t, err) // check for namespace to be not in root - require.Len(t, square.RowsWithNamespace(roots, nID), 0) + require.Len(t, share.RowsWithNamespace(roots, nID), 0) emptyShares, err = getter.GetSharesByNamespace(ctx, eh, nID) require.NoError(t, err) @@ -167,10 +167,10 @@ func TestShrexGetter(t *testing.T) { Height: height, }) - namespace, err := share.AddInt(maxNamespace, 1) + namespace, err := gosquare.AddInt(maxNamespace, 1) require.NoError(t, err) // check for namespace to be not in root - require.Len(t, square.RowsWithNamespace(roots, namespace), 0) + require.Len(t, share.RowsWithNamespace(roots, namespace), 0) emptyShares, err := getter.GetSharesByNamespace(ctx, eh, namespace) require.NoError(t, err) @@ -277,12 +277,12 @@ func newStore(t *testing.T) (*store.Store, error) { return store.NewStore(store.DefaultParameters(), t.TempDir()) } -func generateTestEDS(t *testing.T) (*rsmt2d.ExtendedDataSquare, *square.AxisRoots, share.Namespace) { +func generateTestEDS(t *testing.T) (*rsmt2d.ExtendedDataSquare, *share.AxisRoots, gosquare.Namespace) { eds := edstest.RandEDS(t, 4) - roots, err := square.NewAxisRoots(eds) + roots, err := share.NewAxisRoots(eds) require.NoError(t, err) - max := nmt.MaxNamespace(roots.RowRoots[(len(roots.RowRoots))/2-1], share.NamespaceSize) - ns, err := share.NewNamespaceFromBytes(max) + max := nmt.MaxNamespace(roots.RowRoots[(len(roots.RowRoots))/2-1], gosquare.NamespaceSize) + ns, err := gosquare.NewNamespaceFromBytes(max) require.NoError(t, err) return eds, roots, ns } @@ -351,21 +351,21 @@ func newEDSClientServer( // addToNamespace adds arbitrary int value to namespace, treating namespace as big-endian // implementation of int -func addToNamespace(namespace share.Namespace, val int) (share.Namespace, error) { +func addToNamespace(namespace gosquare.Namespace, val int) (gosquare.Namespace, error) { if val == 0 { return namespace, nil } // Convert the input integer to a byte slice and add it to result slice - result := make([]byte, namespace.Len()) + result := make([]byte, gosquare.NamespaceSize) if val > 0 { - binary.BigEndian.PutUint64(result[namespace.Len()-8:], uint64(val)) + binary.BigEndian.PutUint64(result[gosquare.NamespaceSize-8:], uint64(val)) } else { - binary.BigEndian.PutUint64(result[namespace.Len()-8:], uint64(-val)) + binary.BigEndian.PutUint64(result[gosquare.NamespaceSize-8:], uint64(-val)) } // Perform addition byte by byte var carry int - for i := namespace.Len() - 1; i >= 0; i-- { + for i := gosquare.NamespaceSize - 1; i >= 0; i-- { var sum int if val > 0 { sum = int(namespace.Bytes()[i]) + int(result[i]) + carry @@ -389,8 +389,8 @@ func addToNamespace(namespace share.Namespace, val int) (share.Namespace, error) // Handle any remaining carry if carry != 0 { - return share.Namespace{}, errors.New("namespace overflow") + return gosquare.Namespace{}, errors.New("namespace overflow") } - return share.NewNamespaceFromBytes(result) + return gosquare.NewNamespaceFromBytes(result) } diff --git a/square/shwap/p2p/shrex/shrexeds/client.go b/share/shwap/p2p/shrex/shrexeds/client.go similarity index 93% rename from square/shwap/p2p/shrex/shrexeds/client.go rename to share/shwap/p2p/shrex/shrexeds/client.go index 88038f568b..5239c407f9 100644 --- a/square/shwap/p2p/shrex/shrexeds/client.go +++ b/share/shwap/p2p/shrex/shrexeds/client.go @@ -17,11 +17,11 @@ import ( "github.com/celestiaorg/rsmt2d" "github.com/celestiaorg/celestia-node/libs/utils" - "github.com/celestiaorg/celestia-node/square" - "github.com/celestiaorg/celestia-node/square/eds" - "github.com/celestiaorg/celestia-node/square/shwap" - "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex" - shrexpb "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/pb" + "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/share/eds" + "github.com/celestiaorg/celestia-node/share/shwap" + "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex" + shrexpb "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/pb" ) // Client is responsible for requesting EDSs for blocksync over the ShrEx/EDS protocol. @@ -49,7 +49,7 @@ func NewClient(params *Parameters, host host.Host) (*Client, error) { // RequestEDS requests the ODS from the given peers and returns the EDS upon success. func (c *Client) RequestEDS( ctx context.Context, - root *square.AxisRoots, + root *share.AxisRoots, height uint64, peer peer.ID, ) (*rsmt2d.ExtendedDataSquare, error) { @@ -86,7 +86,7 @@ func (c *Client) RequestEDS( func (c *Client) doRequest( ctx context.Context, - root *square.AxisRoots, + root *share.AxisRoots, height uint64, to peer.ID, ) (*rsmt2d.ExtendedDataSquare, error) { diff --git a/square/shwap/p2p/shrex/shrexeds/doc.go b/share/shwap/p2p/shrex/shrexeds/doc.go similarity index 98% rename from square/shwap/p2p/shrex/shrexeds/doc.go rename to share/shwap/p2p/shrex/shrexeds/doc.go index 6bad3061f9..8272bd8470 100644 --- a/square/shwap/p2p/shrex/shrexeds/doc.go +++ b/share/shwap/p2p/shrex/shrexeds/doc.go @@ -3,7 +3,7 @@ // // This protocol is a request/response protocol that allows for sending requests for extended data squares by data root // to the peers in the network and receiving a response containing the original data square(s), which is used -// to recompute the extended data square. +// to recompute the extended data share. // // The streams are established using the protocol ID: // diff --git a/square/shwap/p2p/shrex/shrexeds/exchange_test.go b/share/shwap/p2p/shrex/shrexeds/exchange_test.go similarity index 90% rename from square/shwap/p2p/shrex/shrexeds/exchange_test.go rename to share/shwap/p2p/shrex/shrexeds/exchange_test.go index 76e3e2e2ee..89e1dafa1c 100644 --- a/square/shwap/p2p/shrex/shrexeds/exchange_test.go +++ b/share/shwap/p2p/shrex/shrexeds/exchange_test.go @@ -12,10 +12,10 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/celestiaorg/celestia-node/square" - "github.com/celestiaorg/celestia-node/square/eds/edstest" - "github.com/celestiaorg/celestia-node/square/shwap" - "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex" + "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/share/eds/edstest" + "github.com/celestiaorg/celestia-node/share/shwap" + "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex" "github.com/celestiaorg/celestia-node/store" ) @@ -30,7 +30,7 @@ func TestExchange_RequestEDS(t *testing.T) { // Testcase: EDS is immediately available t.Run("EDS_Available", func(t *testing.T) { eds := edstest.RandEDS(t, 4) - roots, err := square.NewAxisRoots(eds) + roots, err := share.NewAxisRoots(eds) require.NoError(t, err) height := uint64(1) err = store.PutODSQ4(ctx, roots, height, eds) @@ -44,7 +44,7 @@ func TestExchange_RequestEDS(t *testing.T) { // Testcase: EDS is unavailable initially, but is found after multiple requests t.Run("EDS_AvailableAfterDelay", func(t *testing.T) { eds := edstest.RandEDS(t, 4) - roots, err := square.NewAxisRoots(eds) + roots, err := share.NewAxisRoots(eds) require.NoError(t, err) height := uint64(666) @@ -72,7 +72,7 @@ func TestExchange_RequestEDS(t *testing.T) { // Testcase: Invalid request excludes peer from round-robin, stopping request t.Run("EDS_InvalidRequest", func(t *testing.T) { - emptyRoot := square.EmptyEDSRoots() + emptyRoot := share.EmptyEDSRoots() height := uint64(0) requestedEDS, err := client.RequestEDS(ctx, emptyRoot, height, server.host.ID()) assert.ErrorIs(t, err, shwap.ErrInvalidID) @@ -83,7 +83,7 @@ func TestExchange_RequestEDS(t *testing.T) { timeoutCtx, cancel := context.WithTimeout(ctx, time.Second) t.Cleanup(cancel) eds := edstest.RandEDS(t, 4) - roots, err := square.NewAxisRoots(eds) + roots, err := share.NewAxisRoots(eds) require.NoError(t, err) height := uint64(668) _, err = client.RequestEDS(timeoutCtx, roots, height, server.host.ID()) @@ -119,7 +119,7 @@ func TestExchange_RequestEDS(t *testing.T) { middleware.RateLimitHandler(mockHandler)) // take server concurrency slots with blocked requests - emptyRoot := square.EmptyEDSRoots() + emptyRoot := share.EmptyEDSRoots() for i := 0; i < rateLimit; i++ { go func(i int) { client.RequestEDS(ctx, emptyRoot, 1, server.host.ID()) //nolint:errcheck diff --git a/square/shwap/p2p/shrex/shrexeds/params.go b/share/shwap/p2p/shrex/shrexeds/params.go similarity index 90% rename from square/shwap/p2p/shrex/shrexeds/params.go rename to share/shwap/p2p/shrex/shrexeds/params.go index d3f46a1fd3..c5d76fecb2 100644 --- a/square/shwap/p2p/shrex/shrexeds/params.go +++ b/share/shwap/p2p/shrex/shrexeds/params.go @@ -5,8 +5,8 @@ import ( logging "github.com/ipfs/go-log/v2" - "github.com/celestiaorg/celestia-node/square/shwap" - "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex" + "github.com/celestiaorg/celestia-node/share/shwap" + "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex" ) const protocolString = shrex.ProtocolString + shwap.EDSName diff --git a/square/shwap/p2p/shrex/shrexeds/server.go b/share/shwap/p2p/shrex/shrexeds/server.go similarity index 95% rename from square/shwap/p2p/shrex/shrexeds/server.go rename to share/shwap/p2p/shrex/shrexeds/server.go index 296acc6051..0367e7d82e 100644 --- a/square/shwap/p2p/shrex/shrexeds/server.go +++ b/share/shwap/p2p/shrex/shrexeds/server.go @@ -15,10 +15,10 @@ import ( "github.com/celestiaorg/go-libp2p-messenger/serde" "github.com/celestiaorg/celestia-node/libs/utils" - "github.com/celestiaorg/celestia-node/square/eds" - "github.com/celestiaorg/celestia-node/square/shwap" - "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex" - shrexpb "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/pb" + "github.com/celestiaorg/celestia-node/share/eds" + "github.com/celestiaorg/celestia-node/share/shwap" + "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex" + shrexpb "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/pb" "github.com/celestiaorg/celestia-node/store" ) diff --git a/square/shwap/p2p/shrex/shrexnd/client.go b/share/shwap/p2p/shrex/shrexnd/client.go similarity index 92% rename from square/shwap/p2p/shrex/shrexnd/client.go rename to share/shwap/p2p/shrex/shrexnd/client.go index b9fe86d14c..d5c1938f9f 100644 --- a/square/shwap/p2p/shrex/shrexnd/client.go +++ b/share/shwap/p2p/shrex/shrexnd/client.go @@ -14,12 +14,12 @@ import ( "github.com/libp2p/go-libp2p/core/protocol" "github.com/celestiaorg/go-libp2p-messenger/serde" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/celestia-node/libs/utils" - "github.com/celestiaorg/celestia-node/square/shwap" - "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex" - shrexpb "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/pb" + "github.com/celestiaorg/celestia-node/share/shwap" + "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex" + shrexpb "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/pb" ) // Client implements client side of shrex/nd protocol to obtain namespaced shares data from remote @@ -46,14 +46,14 @@ func NewClient(params *Parameters, host host.Host) (*Client, error) { } // RequestND requests namespaced data from the given peer. -// Returns NamespaceData with unverified inclusion proofs against the share.Root. +// Returns NamespaceData with unverified inclusion proofs against the gosquare.Root. func (c *Client) RequestND( ctx context.Context, height uint64, - namespace share.Namespace, + namespace gosquare.Namespace, peer peer.ID, ) (shwap.NamespaceData, error) { - if err := share.ValidateForData(namespace); err != nil { + if err := gosquare.ValidateForData(namespace); err != nil { return nil, err } @@ -83,7 +83,7 @@ func (c *Client) RequestND( func (c *Client) doRequest( ctx context.Context, height uint64, - namespace share.Namespace, + namespace gosquare.Namespace, peerID peer.ID, ) (shwap.NamespaceData, error) { streamOpenCtx, cancel := context.WithTimeout(ctx, c.params.ServerReadTimeout) diff --git a/square/shwap/p2p/shrex/shrexnd/doc.go b/share/shwap/p2p/shrex/shrexnd/doc.go similarity index 91% rename from square/shwap/p2p/shrex/shrexnd/doc.go rename to share/shwap/p2p/shrex/shrexnd/doc.go index 74ba7397e8..251a86dcb0 100644 --- a/square/shwap/p2p/shrex/shrexnd/doc.go +++ b/share/shwap/p2p/shrex/shrexnd/doc.go @@ -22,7 +22,7 @@ // // data, err := client.RequestND(ctx, dataRoot, peerID, namespaceID) // -// where data is of type [share.NamespacedShares] +// where data is of type [gosquare.NamespacedShares] // // To use a shrexnd server to respond to requests from peers, you must first create a new `shrexnd.Server` instance by: // @@ -31,7 +31,7 @@ // // server, err := shrexnd.NewServer(params, host, store, storeShareGetter) // -// where store is of type [share.Store] and storeShareGetter is of type [share.Getter] +// where store is of type [gosquare.Store] and storeShareGetter is of type [gosquare.Getter] // // 2. Start the server by calling `Start` on the server: // diff --git a/square/shwap/p2p/shrex/shrexnd/exchange_test.go b/share/shwap/p2p/shrex/shrexnd/exchange_test.go similarity index 85% rename from square/shwap/p2p/shrex/shrexnd/exchange_test.go rename to share/shwap/p2p/shrex/shrexnd/exchange_test.go index ea2e07eb06..5414d781e5 100644 --- a/square/shwap/p2p/shrex/shrexnd/exchange_test.go +++ b/share/shwap/p2p/shrex/shrexnd/exchange_test.go @@ -12,11 +12,11 @@ import ( mocknet "github.com/libp2p/go-libp2p/p2p/net/mock" "github.com/stretchr/testify/require" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" - "github.com/celestiaorg/celestia-node/square" - "github.com/celestiaorg/celestia-node/square/eds/edstest" - "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex" + "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/share/eds/edstest" + "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex" "github.com/celestiaorg/celestia-node/store" ) @@ -33,7 +33,7 @@ func TestExchange_RequestND_NotFound(t *testing.T) { ctx, cancel := context.WithTimeout(ctx, time.Second) t.Cleanup(cancel) - namespace := share.RandomNamespace() + namespace := gosquare.RandomNamespace() height := height.Add(1) _, err := client.RequestND(ctx, height, namespace, server.host.ID()) require.ErrorIs(t, err, shrex.ErrNotFound) @@ -44,14 +44,14 @@ func TestExchange_RequestND_NotFound(t *testing.T) { t.Cleanup(cancel) eds := edstest.RandEDS(t, 4) - roots, err := square.NewAxisRoots(eds) + roots, err := share.NewAxisRoots(eds) require.NoError(t, err) height := height.Add(1) err = edsStore.PutODSQ4(ctx, roots, height, eds) require.NoError(t, err) - namespace := share.RandomNamespace() + namespace := gosquare.RandomNamespace() emptyShares, err := client.RequestND(ctx, height, namespace, server.host.ID()) require.NoError(t, err) require.Empty(t, emptyShares.Flatten()) @@ -95,13 +95,13 @@ func TestExchange_RequestND(t *testing.T) { // take server concurrency slots with blocked requests for i := 0; i < rateLimit; i++ { go func(i int) { - client.RequestND(ctx, 1, share.RandomNamespace(), server.host.ID()) //nolint:errcheck + client.RequestND(ctx, 1, gosquare.RandomNamespace(), server.host.ID()) //nolint:errcheck }(i) } // wait until all server slots are taken wg.Wait() - _, err = client.RequestND(ctx, 1, share.RandomNamespace(), server.host.ID()) + _, err = client.RequestND(ctx, 1, gosquare.RandomNamespace(), server.host.ID()) require.ErrorIs(t, err, shrex.ErrRateLimited) }) } diff --git a/square/shwap/p2p/shrex/shrexnd/params.go b/share/shwap/p2p/shrex/shrexnd/params.go similarity index 87% rename from square/shwap/p2p/shrex/shrexnd/params.go rename to share/shwap/p2p/shrex/shrexnd/params.go index 6003921c1e..5544ae6b27 100644 --- a/square/shwap/p2p/shrex/shrexnd/params.go +++ b/share/shwap/p2p/shrex/shrexnd/params.go @@ -5,8 +5,8 @@ import ( logging "github.com/ipfs/go-log/v2" - "github.com/celestiaorg/celestia-node/square/shwap" - "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex" + "github.com/celestiaorg/celestia-node/share/shwap" + "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex" ) const protocolString = shrex.ProtocolString + shwap.NamespaceDataName diff --git a/square/shwap/p2p/shrex/shrexnd/server.go b/share/shwap/p2p/shrex/shrexnd/server.go similarity index 96% rename from square/shwap/p2p/shrex/shrexnd/server.go rename to share/shwap/p2p/shrex/shrexnd/server.go index 20a7098b74..0193c91ae1 100644 --- a/square/shwap/p2p/shrex/shrexnd/server.go +++ b/share/shwap/p2p/shrex/shrexnd/server.go @@ -14,10 +14,10 @@ import ( "github.com/celestiaorg/go-libp2p-messenger/serde" "github.com/celestiaorg/celestia-node/libs/utils" - "github.com/celestiaorg/celestia-node/square/eds" - "github.com/celestiaorg/celestia-node/square/shwap" - "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex" - shrexpb "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/pb" + "github.com/celestiaorg/celestia-node/share/eds" + "github.com/celestiaorg/celestia-node/share/shwap" + "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex" + shrexpb "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/pb" "github.com/celestiaorg/celestia-node/store" ) diff --git a/square/shwap/p2p/shrex/shrexsub/doc.go b/share/shwap/p2p/shrex/shrexsub/doc.go similarity index 97% rename from square/shwap/p2p/shrex/shrexsub/doc.go rename to share/shwap/p2p/shrex/shrexsub/doc.go index 95d08361a2..3ca4919581 100644 --- a/square/shwap/p2p/shrex/shrexsub/doc.go +++ b/share/shwap/p2p/shrex/shrexsub/doc.go @@ -28,7 +28,7 @@ // // where `notification` is of type [shrexsub.Notification]. // -// and `DataHash` is the hash of the share that you want to broadcast, and `Height` is the height of the share. +// and `DataHash` is the hash of the share that you want to broadcast, and `Height` is the height of the gosquare. // // You can also subscribe to the pubsub topic by: // diff --git a/square/shwap/p2p/shrex/shrexsub/pb/notification.pb.go b/share/shwap/p2p/shrex/shrexsub/pb/notification.pb.go similarity index 83% rename from square/shwap/p2p/shrex/shrexsub/pb/notification.pb.go rename to share/shwap/p2p/shrex/shrexsub/pb/notification.pb.go index a04cbc56ac..939e4774e3 100644 --- a/square/shwap/p2p/shrex/shrexsub/pb/notification.pb.go +++ b/share/shwap/p2p/shrex/shrexsub/pb/notification.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: square/shwap/p2p/shrex/shrexsub/pb/notification.proto +// source: share/shwap/p2p/shrex/shrexsub/pb/notification.proto -package share_p2p_shrex_sub +package gosquare_p2p_shrex_sub import ( fmt "fmt" @@ -31,7 +31,7 @@ func (m *RecentEDSNotification) Reset() { *m = RecentEDSNotification{} } func (m *RecentEDSNotification) String() string { return proto.CompactTextString(m) } func (*RecentEDSNotification) ProtoMessage() {} func (*RecentEDSNotification) Descriptor() ([]byte, []int) { - return fileDescriptor_3a5bf8ca81a1e1ac, []int{0} + return fileDescriptor_c16b670e7e556100, []int{0} } func (m *RecentEDSNotification) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -75,27 +75,27 @@ func (m *RecentEDSNotification) GetDataHash() []byte { } func init() { - proto.RegisterType((*RecentEDSNotification)(nil), "share.p2p.shrex.sub.RecentEDSNotification") + proto.RegisterType((*RecentEDSNotification)(nil), "gosquare.p2p.shrex.sub.RecentEDSNotification") } func init() { - proto.RegisterFile("square/shwap/p2p/shrex/shrexsub/pb/notification.proto", fileDescriptor_3a5bf8ca81a1e1ac) + proto.RegisterFile("share/shwap/p2p/shrex/shrexsub/pb/notification.proto", fileDescriptor_c16b670e7e556100) } -var fileDescriptor_3a5bf8ca81a1e1ac = []byte{ - // 187 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x32, 0x2d, 0x2e, 0x2c, 0x4d, - 0x2c, 0x4a, 0xd5, 0x2f, 0xce, 0x28, 0x4f, 0x2c, 0xd0, 0x2f, 0x30, 0x2a, 0xd0, 0x2f, 0xce, 0x28, - 0x4a, 0xad, 0x80, 0x90, 0xc5, 0xa5, 0x49, 0xfa, 0x05, 0x49, 0xfa, 0x79, 0xf9, 0x25, 0x99, 0x69, - 0x99, 0xc9, 0x89, 0x25, 0x99, 0xf9, 0x79, 0x7a, 0x05, 0x45, 0xf9, 0x25, 0xf9, 0x42, 0xc2, 0xc5, - 0x19, 0x89, 0x45, 0xa9, 0x7a, 0x05, 0x46, 0x05, 0x7a, 0x60, 0x95, 0x7a, 0xc5, 0xa5, 0x49, 0x4a, - 0x3e, 0x5c, 0xa2, 0x41, 0xa9, 0xc9, 0xa9, 0x79, 0x25, 0xae, 0x2e, 0xc1, 0x7e, 0x48, 0x7a, 0x84, - 0xc4, 0xb8, 0xd8, 0x32, 0x52, 0x33, 0xd3, 0x33, 0x4a, 0x24, 0x18, 0x15, 0x18, 0x35, 0x58, 0x82, - 0xa0, 0x3c, 0x21, 0x69, 0x2e, 0xce, 0x94, 0xc4, 0x92, 0xc4, 0xf8, 0x8c, 0xc4, 0xe2, 0x0c, 0x09, - 0x26, 0x05, 0x46, 0x0d, 0x9e, 0x20, 0x0e, 0x90, 0x80, 0x47, 0x62, 0x71, 0x86, 0x93, 0xc4, 0x89, - 0x47, 0x72, 0x8c, 0x17, 0x1e, 0xc9, 0x31, 0x3e, 0x78, 0x24, 0xc7, 0x38, 0xe1, 0xb1, 0x1c, 0xc3, - 0x85, 0xc7, 0x72, 0x0c, 0x37, 0x1e, 0xcb, 0x31, 0x24, 0xb1, 0x81, 0xdd, 0x60, 0x0c, 0x08, 0x00, - 0x00, 0xff, 0xff, 0x3f, 0x50, 0x64, 0x8f, 0xbc, 0x00, 0x00, 0x00, +var fileDescriptor_c16b670e7e556100 = []byte{ + // 189 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x32, 0x29, 0xce, 0x48, 0x2c, + 0x4a, 0xd5, 0x2f, 0xce, 0x28, 0x4f, 0x2c, 0xd0, 0x2f, 0x30, 0x2a, 0xd0, 0x2f, 0xce, 0x28, 0x4a, + 0xad, 0x80, 0x90, 0xc5, 0xa5, 0x49, 0xfa, 0x05, 0x49, 0xfa, 0x79, 0xf9, 0x25, 0x99, 0x69, 0x99, + 0xc9, 0x89, 0x25, 0x99, 0xf9, 0x79, 0x7a, 0x05, 0x45, 0xf9, 0x25, 0xf9, 0x42, 0x62, 0xe9, 0xf9, + 0xc5, 0x85, 0xa5, 0x89, 0x45, 0xa9, 0x7a, 0x05, 0x46, 0x05, 0x7a, 0x60, 0xc5, 0x7a, 0xc5, 0xa5, + 0x49, 0x4a, 0x3e, 0x5c, 0xa2, 0x41, 0xa9, 0xc9, 0xa9, 0x79, 0x25, 0xae, 0x2e, 0xc1, 0x7e, 0x48, + 0xda, 0x84, 0xc4, 0xb8, 0xd8, 0x32, 0x52, 0x33, 0xd3, 0x33, 0x4a, 0x24, 0x18, 0x15, 0x18, 0x35, + 0x58, 0x82, 0xa0, 0x3c, 0x21, 0x69, 0x2e, 0xce, 0x94, 0xc4, 0x92, 0xc4, 0xf8, 0x8c, 0xc4, 0xe2, + 0x0c, 0x09, 0x26, 0x05, 0x46, 0x0d, 0x9e, 0x20, 0x0e, 0x90, 0x80, 0x47, 0x62, 0x71, 0x86, 0x93, + 0xc4, 0x89, 0x47, 0x72, 0x8c, 0x17, 0x1e, 0xc9, 0x31, 0x3e, 0x78, 0x24, 0xc7, 0x38, 0xe1, 0xb1, + 0x1c, 0xc3, 0x85, 0xc7, 0x72, 0x0c, 0x37, 0x1e, 0xcb, 0x31, 0x24, 0xb1, 0x81, 0x9d, 0x61, 0x0c, + 0x08, 0x00, 0x00, 0xff, 0xff, 0xa9, 0x5f, 0xae, 0x6a, 0xbe, 0x00, 0x00, 0x00, } func (m *RecentEDSNotification) Marshal() (dAtA []byte, err error) { diff --git a/square/shwap/p2p/shrex/shrexsub/pb/notification.proto b/share/shwap/p2p/shrex/shrexsub/pb/notification.proto similarity index 75% rename from square/shwap/p2p/shrex/shrexsub/pb/notification.proto rename to share/shwap/p2p/shrex/shrexsub/pb/notification.proto index d96cf3369e..c2aa88b70f 100644 --- a/square/shwap/p2p/shrex/shrexsub/pb/notification.proto +++ b/share/shwap/p2p/shrex/shrexsub/pb/notification.proto @@ -1,6 +1,6 @@ syntax = "proto3"; -package share.p2p.shrex.sub; +package gosquare.p2p.shrex.sub; message RecentEDSNotification { uint64 height = 1; diff --git a/square/shwap/p2p/shrex/shrexsub/pubsub.go b/share/shwap/p2p/shrex/shrexsub/pubsub.go similarity index 96% rename from square/shwap/p2p/shrex/shrexsub/pubsub.go rename to share/shwap/p2p/shrex/shrexsub/pubsub.go index f2f49233a3..d1861cfe12 100644 --- a/square/shwap/p2p/shrex/shrexsub/pubsub.go +++ b/share/shwap/p2p/shrex/shrexsub/pubsub.go @@ -9,8 +9,8 @@ import ( "github.com/libp2p/go-libp2p/core/host" "github.com/libp2p/go-libp2p/core/peer" - "github.com/celestiaorg/celestia-node/square" - pb "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrexsub/pb" + "github.com/celestiaorg/celestia-node/share" + pb "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrexsub/pb" ) var log = logging.Logger("shrex-sub") @@ -30,7 +30,7 @@ type BroadcastFn func(context.Context, Notification) error // Notification is the format of message sent by Broadcaster type Notification struct { - DataHash square.DataHash + DataHash share.DataHash Height uint64 } diff --git a/square/shwap/p2p/shrex/shrexsub/pubsub_test.go b/share/shwap/p2p/shrex/shrexsub/pubsub_test.go similarity index 97% rename from square/shwap/p2p/shrex/shrexsub/pubsub_test.go rename to share/shwap/p2p/shrex/shrexsub/pubsub_test.go index ecaf8519e5..59602da29b 100644 --- a/square/shwap/p2p/shrex/shrexsub/pubsub_test.go +++ b/share/shwap/p2p/shrex/shrexsub/pubsub_test.go @@ -11,7 +11,7 @@ import ( "github.com/stretchr/testify/require" "github.com/tendermint/tendermint/libs/rand" - pb "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrexsub/pb" + pb "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrexsub/pb" ) func TestPubSub(t *testing.T) { diff --git a/square/shwap/p2p/shrex/shrexsub/subscription.go b/share/shwap/p2p/shrex/shrexsub/subscription.go similarity index 94% rename from square/shwap/p2p/shrex/shrexsub/subscription.go rename to share/shwap/p2p/shrex/shrexsub/subscription.go index d65928e2c3..5021f090c2 100644 --- a/square/shwap/p2p/shrex/shrexsub/subscription.go +++ b/share/shwap/p2p/shrex/shrexsub/subscription.go @@ -6,7 +6,7 @@ import ( pubsub "github.com/libp2p/go-libp2p-pubsub" - pb "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrexsub/pb" + pb "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrexsub/pb" ) // Subscription is a wrapper over pubsub.Subscription that handles diff --git a/square/shwap/pb/shwap.pb.go b/share/shwap/pb/shwap.pb.go similarity index 89% rename from square/shwap/pb/shwap.pb.go rename to share/shwap/pb/shwap.pb.go index 12a158882e..000bf78ca7 100644 --- a/square/shwap/pb/shwap.pb.go +++ b/share/shwap/pb/shwap.pb.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: square/shwap/pb/shwap.proto +// source: share/shwap/pb/shwap.proto package pb @@ -45,7 +45,7 @@ func (x AxisType) String() string { } func (AxisType) EnumDescriptor() ([]byte, []int) { - return fileDescriptor_d53f2247170ec31c, []int{0} + return fileDescriptor_9431653f3c9f0bcb, []int{0} } type Row_HalfSide int32 @@ -70,7 +70,7 @@ func (x Row_HalfSide) String() string { } func (Row_HalfSide) EnumDescriptor() ([]byte, []int) { - return fileDescriptor_d53f2247170ec31c, []int{0, 0} + return fileDescriptor_9431653f3c9f0bcb, []int{0, 0} } type Row struct { @@ -82,7 +82,7 @@ func (m *Row) Reset() { *m = Row{} } func (m *Row) String() string { return proto.CompactTextString(m) } func (*Row) ProtoMessage() {} func (*Row) Descriptor() ([]byte, []int) { - return fileDescriptor_d53f2247170ec31c, []int{0} + return fileDescriptor_9431653f3c9f0bcb, []int{0} } func (m *Row) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -135,7 +135,7 @@ func (m *Sample) Reset() { *m = Sample{} } func (m *Sample) String() string { return proto.CompactTextString(m) } func (*Sample) ProtoMessage() {} func (*Sample) Descriptor() ([]byte, []int) { - return fileDescriptor_d53f2247170ec31c, []int{1} + return fileDescriptor_9431653f3c9f0bcb, []int{1} } func (m *Sample) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -194,7 +194,7 @@ func (m *RowNamespaceData) Reset() { *m = RowNamespaceData{} } func (m *RowNamespaceData) String() string { return proto.CompactTextString(m) } func (*RowNamespaceData) ProtoMessage() {} func (*RowNamespaceData) Descriptor() ([]byte, []int) { - return fileDescriptor_d53f2247170ec31c, []int{2} + return fileDescriptor_9431653f3c9f0bcb, []int{2} } func (m *RowNamespaceData) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -245,7 +245,7 @@ func (m *Share) Reset() { *m = Share{} } func (m *Share) String() string { return proto.CompactTextString(m) } func (*Share) ProtoMessage() {} func (*Share) Descriptor() ([]byte, []int) { - return fileDescriptor_d53f2247170ec31c, []int{3} + return fileDescriptor_9431653f3c9f0bcb, []int{3} } func (m *Share) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -290,34 +290,34 @@ func init() { proto.RegisterType((*Share)(nil), "shwap.Share") } -func init() { proto.RegisterFile("square/shwap/pb/shwap.proto", fileDescriptor_d53f2247170ec31c) } +func init() { proto.RegisterFile("share/shwap/pb/shwap.proto", fileDescriptor_9431653f3c9f0bcb) } -var fileDescriptor_d53f2247170ec31c = []byte{ - // 383 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x92, 0x4f, 0x8b, 0xda, 0x40, - 0x18, 0xc6, 0x33, 0x8d, 0xb1, 0xf1, 0x55, 0x34, 0x4c, 0x2f, 0xa1, 0x96, 0x54, 0x42, 0x0b, 0x52, - 0x30, 0x29, 0xb6, 0x5f, 0xa0, 0xff, 0x2d, 0x88, 0x96, 0x51, 0x28, 0xf4, 0x12, 0x26, 0x66, 0x34, - 0x81, 0xd8, 0x99, 0x66, 0x22, 0xa9, 0xe7, 0x1e, 0x7a, 0xdd, 0x8f, 0xb5, 0x47, 0x8f, 0x7b, 0x5c, - 0xf4, 0x8b, 0x2c, 0x99, 0xc4, 0x3d, 0xec, 0xee, 0x61, 0x6f, 0xbf, 0xcc, 0xf3, 0x64, 0xde, 0xe7, - 0x19, 0x5e, 0xe8, 0xcb, 0x3f, 0x3b, 0x9a, 0x31, 0x5f, 0xc6, 0x05, 0x15, 0xbe, 0x08, 0x2b, 0xf0, - 0x44, 0xc6, 0x73, 0x8e, 0x0d, 0xf5, 0xf1, 0xbc, 0x2b, 0x42, 0x5f, 0x64, 0x9c, 0xaf, 0xab, 0x63, - 0xf7, 0x3f, 0x02, 0x9d, 0xf0, 0x02, 0x8f, 0xa0, 0x2d, 0x63, 0x9a, 0x31, 0x19, 0xc4, 0x34, 0x5d, - 0xdb, 0x68, 0xa0, 0x0f, 0xdb, 0xe3, 0x8e, 0x57, 0xdd, 0xb0, 0x28, 0x15, 0x02, 0x95, 0x61, 0x42, - 0xd3, 0x35, 0x7e, 0x0b, 0xad, 0xd2, 0x17, 0xc8, 0x24, 0x62, 0xf6, 0x93, 0x01, 0x1a, 0x76, 0xc7, - 0xcf, 0x6a, 0x33, 0xe1, 0x85, 0x57, 0x7a, 0x16, 0x49, 0xc4, 0x88, 0x19, 0xd7, 0xe4, 0xbe, 0x04, - 0xf3, 0x7c, 0x8a, 0x4d, 0x68, 0x4c, 0xbf, 0x7c, 0x5d, 0x5a, 0x1a, 0x6e, 0x81, 0x41, 0xbe, 0x7f, - 0x9b, 0x2c, 0x2d, 0xe4, 0xfe, 0x43, 0xd0, 0x5c, 0xd0, 0xad, 0x48, 0x19, 0x76, 0xc1, 0x50, 0xb3, - 0x6c, 0x34, 0x40, 0xf7, 0x62, 0x54, 0x12, 0x7e, 0x0d, 0x86, 0xea, 0xa1, 0xa6, 0xb7, 0xc7, 0x3d, - 0xaf, 0x6e, 0x15, 0x7a, 0x3f, 0x4a, 0x20, 0x95, 0x8a, 0x3d, 0x00, 0x05, 0x41, 0xbe, 0x17, 0xcc, - 0xd6, 0x55, 0xd2, 0x5e, 0x7d, 0xdf, 0x87, 0xbf, 0x89, 0x5c, 0xee, 0x05, 0x23, 0x2d, 0x65, 0x29, - 0xd1, 0x0d, 0xc0, 0x22, 0xbc, 0x98, 0xd1, 0x2d, 0x93, 0x82, 0xae, 0xd8, 0x67, 0x9a, 0x53, 0xfc, - 0x0a, 0x9a, 0x55, 0xf5, 0x07, 0x9f, 0xa5, 0xd6, 0x1e, 0x19, 0xc8, 0xed, 0x83, 0xa1, 0xfe, 0xc3, - 0x18, 0x1a, 0x11, 0xcd, 0xa9, 0xea, 0xd8, 0x21, 0x8a, 0xdf, 0xbc, 0x00, 0xf3, 0x1c, 0x0a, 0x3f, - 0x05, 0x9d, 0xcc, 0x7f, 0x5a, 0x5a, 0x09, 0x9f, 0xe6, 0x53, 0x0b, 0x7d, 0x9c, 0x5d, 0x1e, 0x1d, - 0x74, 0x38, 0x3a, 0xe8, 0xfa, 0xe8, 0xa0, 0x8b, 0x93, 0xa3, 0x1d, 0x4e, 0x8e, 0x76, 0x75, 0x72, - 0xb4, 0x5f, 0xef, 0x37, 0x49, 0x1e, 0xef, 0x42, 0x6f, 0xc5, 0xb7, 0xfe, 0x8a, 0xa5, 0x4c, 0xe6, - 0x09, 0xe5, 0xd9, 0xe6, 0x96, 0x47, 0xbf, 0x79, 0xc4, 0xfc, 0x3b, 0xeb, 0x11, 0x36, 0xd5, 0x0a, - 0xbc, 0xbb, 0x09, 0x00, 0x00, 0xff, 0xff, 0x80, 0x9c, 0x55, 0xe0, 0x38, 0x02, 0x00, 0x00, +var fileDescriptor_9431653f3c9f0bcb = []byte{ + // 381 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x92, 0x4f, 0x6b, 0xe2, 0x40, + 0x18, 0xc6, 0x33, 0x1b, 0xe3, 0xc6, 0x57, 0xd1, 0x30, 0x7b, 0x09, 0xee, 0x92, 0x95, 0xb0, 0x0b, + 0xb2, 0x60, 0xb2, 0xe8, 0x27, 0xd8, 0xbf, 0xb5, 0x60, 0x6b, 0x19, 0x85, 0x42, 0x2f, 0x61, 0x62, + 0x46, 0x13, 0x88, 0x9d, 0x21, 0x49, 0x49, 0x3d, 0xf7, 0xd0, 0x6b, 0x3f, 0x56, 0x8f, 0x1e, 0x7b, + 0x2c, 0xfa, 0x45, 0x4a, 0x26, 0xb1, 0x14, 0xda, 0x43, 0x6f, 0xbf, 0xcc, 0xf3, 0xcc, 0xbc, 0xcf, + 0x13, 0x5e, 0xe8, 0xa6, 0x21, 0x4d, 0x98, 0x9b, 0x86, 0x39, 0x15, 0xae, 0xf0, 0x4b, 0x70, 0x44, + 0xc2, 0x33, 0x8e, 0x35, 0xf9, 0xd1, 0x6d, 0x0b, 0xdf, 0x15, 0x09, 0xe7, 0xcb, 0xf2, 0xd8, 0xbe, + 0x45, 0xa0, 0x12, 0x9e, 0xe3, 0x01, 0x34, 0xe5, 0xe5, 0xd4, 0x0b, 0x69, 0xbc, 0x34, 0x51, 0x4f, + 0xed, 0x37, 0x87, 0x2d, 0xa7, 0x7c, 0x61, 0x56, 0x28, 0x04, 0x4a, 0xc3, 0x98, 0xc6, 0x4b, 0xfc, + 0x13, 0x1a, 0x85, 0xcf, 0x4b, 0xa3, 0x80, 0x99, 0x1f, 0x7a, 0xa8, 0xdf, 0x1e, 0x7e, 0xaa, 0xcc, + 0x84, 0xe7, 0x4e, 0xe1, 0x99, 0x45, 0x01, 0x23, 0x7a, 0x58, 0x91, 0xfd, 0x15, 0xf4, 0xc3, 0x29, + 0xd6, 0xa1, 0x36, 0xf9, 0xf7, 0x7f, 0x6e, 0x28, 0xb8, 0x01, 0x1a, 0x39, 0x3e, 0x1a, 0xcf, 0x0d, + 0x64, 0xdf, 0x20, 0xa8, 0xcf, 0xe8, 0x5a, 0xc4, 0x0c, 0xdb, 0xa0, 0xc9, 0x59, 0x26, 0xea, 0xa1, + 0x57, 0x31, 0x4a, 0x09, 0x7f, 0x07, 0x4d, 0xf6, 0x90, 0xd3, 0x9b, 0xc3, 0x8e, 0x53, 0xb5, 0xf2, + 0x9d, 0xb3, 0x02, 0x48, 0xa9, 0x62, 0x07, 0x40, 0x82, 0x97, 0x6d, 0x04, 0x33, 0x55, 0x99, 0xb4, + 0x53, 0xbd, 0xf7, 0xeb, 0x3a, 0x4a, 0xe7, 0x1b, 0xc1, 0x48, 0x43, 0x5a, 0x0a, 0xb4, 0x3d, 0x30, + 0x08, 0xcf, 0x4f, 0xe9, 0x9a, 0xa5, 0x82, 0x2e, 0xd8, 0x5f, 0x9a, 0x51, 0xfc, 0x0d, 0xea, 0x65, + 0xf5, 0x37, 0x7f, 0x4b, 0xa5, 0xbd, 0x33, 0x90, 0xfd, 0x19, 0x34, 0x79, 0x0f, 0x63, 0xa8, 0x05, + 0x34, 0xa3, 0xb2, 0x63, 0x8b, 0x48, 0xfe, 0xf1, 0x05, 0xf4, 0x43, 0x28, 0xfc, 0x11, 0x54, 0x32, + 0x3d, 0x37, 0x94, 0x02, 0xfe, 0x4c, 0x27, 0x06, 0xfa, 0x7d, 0x72, 0xbf, 0xb3, 0xd0, 0x76, 0x67, + 0xa1, 0xc7, 0x9d, 0x85, 0xee, 0xf6, 0x96, 0xb2, 0xdd, 0x5b, 0xca, 0xc3, 0xde, 0x52, 0x2e, 0x46, + 0xab, 0x28, 0x0b, 0xaf, 0x7c, 0x67, 0xc1, 0xd7, 0xee, 0x82, 0xc5, 0x2c, 0xcd, 0x22, 0xca, 0x93, + 0xd5, 0x33, 0x0f, 0x2e, 0x79, 0x50, 0xec, 0xc5, 0xcb, 0xed, 0xf0, 0xeb, 0x72, 0x03, 0x46, 0x4f, + 0x01, 0x00, 0x00, 0xff, 0xff, 0x67, 0xb6, 0xc0, 0x8b, 0x36, 0x02, 0x00, 0x00, } func (m *Row) Marshal() (dAtA []byte, err error) { diff --git a/square/shwap/pb/shwap.proto b/share/shwap/pb/shwap.proto similarity index 89% rename from square/shwap/pb/shwap.proto rename to share/shwap/pb/shwap.proto index 444844f055..d7daea568a 100644 --- a/square/shwap/pb/shwap.proto +++ b/share/shwap/pb/shwap.proto @@ -1,7 +1,7 @@ // Defined in CIP-19 https://github.com/celestiaorg/CIPs/blob/82aeb7dfc472105a11babffd548c730c899a3d24/cips/cip-19.md syntax = "proto3"; package shwap; -option go_package = "github.com/celestiaorg/celestia-node/square/shwap/pb"; +option go_package = "github.com/celestiaorg/celestia-node/share/shwap/pb"; import "pb/proof.proto"; // celestiaorg/nmt/pb/proof.proto diff --git a/square/shwap/row.go b/share/shwap/row.go similarity index 80% rename from square/shwap/row.go rename to share/shwap/row.go index b4298c27ab..013dd3d2bf 100644 --- a/square/shwap/row.go +++ b/share/shwap/row.go @@ -5,10 +5,10 @@ import ( "fmt" "github.com/celestiaorg/celestia-app/v3/pkg/wrapper" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" - "github.com/celestiaorg/celestia-node/square" - "github.com/celestiaorg/celestia-node/square/shwap/pb" + "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/share/shwap/pb" ) // RowName is the name identifier for the row container. @@ -24,12 +24,12 @@ const ( // Row represents a portion of a row in an EDS, either left or right half. type Row struct { - halfShares []share.Share // halfShares holds the shares of either the left or right half of a row. - side RowSide // side indicates whether the row half is left or right. + halfShares []gosquare.Share // halfShares holds the shares of either the left or right half of a row. + side RowSide // side indicates whether the row half is left or right. } // NewRow creates a new Row with the specified shares and side. -func NewRow(halfShares []share.Share, side RowSide) Row { +func NewRow(halfShares []gosquare.Share, side RowSide) Row { return Row{ halfShares: halfShares, side: side, @@ -38,8 +38,8 @@ func NewRow(halfShares []share.Share, side RowSide) Row { // RowFromShares constructs a new Row from an Extended Data Square based on the specified index and // side. -func RowFromShares(shares []share.Share, side RowSide) Row { - var halfShares []share.Share +func RowFromShares(shares []gosquare.Share, side RowSide) Row { + var halfShares []gosquare.Share if side == Right { halfShares = shares[len(shares)/2:] // Take the right half of the shares. } else { @@ -63,8 +63,8 @@ func RowFromProto(r *pb.Row) (Row, error) { // Shares reconstructs the complete row shares from the half provided, using RSMT2D for data // recovery if needed. -func (r Row) Shares() ([]share.Share, error) { - shares := make([]share.Share, len(r.halfShares)*2) +func (r Row) Shares() ([]gosquare.Share, error) { + shares := make([]gosquare.Share, len(r.halfShares)*2) offset := 0 if r.side == Right { offset = len(r.halfShares) // Position the halfShares in the second half if it's the right side. @@ -73,11 +73,11 @@ func (r Row) Shares() ([]share.Share, error) { shares[i+offset] = share } - rowShares, err := square.DefaultRSMT2DCodec().Decode(share.ToBytes(shares)) + rowShares, err := share.DefaultRSMT2DCodec().Decode(gosquare.ToBytes(shares)) if err != nil { return nil, err } - return share.FromBytes(rowShares) + return gosquare.FromBytes(rowShares) } // ToProto converts the Row to its protobuf representation. @@ -95,7 +95,7 @@ func (r Row) IsEmpty() bool { // Verify checks if the row's shares match the expected number from the root data and validates // the side of the row. -func (r Row) Verify(roots *square.AxisRoots, idx int) error { +func (r Row) Verify(roots *share.AxisRoots, idx int) error { if len(r.halfShares) == 0 { return fmt.Errorf("empty half row") } @@ -115,7 +115,7 @@ func (r Row) Verify(roots *square.AxisRoots, idx int) error { // verifyInclusion verifies the integrity of the row's shares against the provided root hash for the // given row index. -func (r Row) verifyInclusion(roots *square.AxisRoots, idx int) error { +func (r Row) verifyInclusion(roots *share.AxisRoots, idx int) error { shrs, err := r.Shares() if err != nil { return fmt.Errorf("while extending shares: %w", err) diff --git a/square/shwap/row_id.go b/share/shwap/row_id.go similarity index 99% rename from square/shwap/row_id.go rename to share/shwap/row_id.go index acc0495ef4..169458fcbb 100644 --- a/square/shwap/row_id.go +++ b/share/shwap/row_id.go @@ -14,7 +14,7 @@ const RowIDSize = EdsIDSize + 2 // with the row's index. type RowID struct { EdsID // Embedding EdsID to include the block height in RowID. - RowIndex int // RowIndex specifies the position of the row within the data square. + RowIndex int // RowIndex specifies the position of the row within the data share. } // NewRowID creates a new RowID with the specified block height, row index, and EDS size. diff --git a/square/shwap/row_id_test.go b/share/shwap/row_id_test.go similarity index 100% rename from square/shwap/row_id_test.go rename to share/shwap/row_id_test.go diff --git a/square/shwap/row_namespace_data.go b/share/shwap/row_namespace_data.go similarity index 90% rename from square/shwap/row_namespace_data.go rename to share/shwap/row_namespace_data.go index 761652ebff..294e0b4a9e 100644 --- a/square/shwap/row_namespace_data.go +++ b/share/shwap/row_namespace_data.go @@ -8,12 +8,12 @@ import ( "github.com/celestiaorg/celestia-app/v3/pkg/appconsts" "github.com/celestiaorg/celestia-app/v3/pkg/wrapper" "github.com/celestiaorg/go-libp2p-messenger/serde" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt" nmt_pb "github.com/celestiaorg/nmt/pb" - "github.com/celestiaorg/celestia-node/square" - "github.com/celestiaorg/celestia-node/square/shwap/pb" + "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/share/shwap/pb" ) // RowNamespaceDataName is the name identifier for the row namespace data container. @@ -26,21 +26,21 @@ var ErrNamespaceOutsideRange = errors.New("target namespace is outside of namesp // RowNamespaceData holds shares and their corresponding proof for a single row within a namespace. type RowNamespaceData struct { - Shares []share.Share `json:"shares"` // Shares within the namespace. - Proof *nmt.Proof `json:"proof"` // Proof of the shares' inclusion in the namespace. + Shares []gosquare.Share `json:"shares"` // Shares within the namespace. + Proof *nmt.Proof `json:"proof"` // Proof of the shares' inclusion in the namespace. } // RowNamespaceDataFromShares extracts and constructs a RowNamespaceData from shares within the // specified namespace. func RowNamespaceDataFromShares( - shares []share.Share, - namespace share.Namespace, + shares []gosquare.Share, + namespace gosquare.Namespace, rowIndex int, ) (RowNamespaceData, error) { tree := wrapper.NewErasuredNamespacedMerkleTree(uint64(len(shares)/2), uint(rowIndex)) nmtTree := nmt.New( appconsts.NewBaseHashFunc(), - nmt.NamespaceIDSize(share.NamespaceSize), + nmt.NamespaceIDSize(gosquare.NamespaceSize), nmt.IgnoreMaxNamespace(true), ) tree.SetTree(nmtTree) @@ -85,7 +85,7 @@ func RowNamespaceDataFromShares( }, nil } - namespacedShares := make([]share.Share, count) + namespacedShares := make([]gosquare.Share, count) copy(namespacedShares, shares[from:from+count]) proof, err := tree.ProveRange(from, from+count) @@ -150,7 +150,7 @@ func (rnd RowNamespaceData) IsEmpty() bool { } // Verify checks validity of the RowNamespaceData against the AxisRoots, Namespace and Row index. -func (rnd RowNamespaceData) Verify(roots *square.AxisRoots, namespace share.Namespace, rowIdx int) error { +func (rnd RowNamespaceData) Verify(roots *share.AxisRoots, namespace gosquare.Namespace, rowIdx int) error { if rnd.Proof == nil || rnd.Proof.IsEmptyProof() { return fmt.Errorf("nil proof") } @@ -174,7 +174,7 @@ func (rnd RowNamespaceData) Verify(roots *square.AxisRoots, namespace share.Name } // verifyInclusion checks the inclusion of the row's shares in the provided root using NMT. -func (rnd RowNamespaceData) verifyInclusion(rowRoot []byte, namespace share.Namespace) bool { +func (rnd RowNamespaceData) verifyInclusion(rowRoot []byte, namespace gosquare.Namespace) bool { leaves := make([][]byte, 0, len(rnd.Shares)) for _, sh := range rnd.Shares { namespaceBytes := sh.Namespace().Bytes() @@ -185,7 +185,7 @@ func (rnd RowNamespaceData) verifyInclusion(rowRoot []byte, namespace share.Name } return rnd.Proof.VerifyNamespace( - square.NewSHA256Hasher(), + share.NewSHA256Hasher(), namespace.Bytes(), leaves, rowRoot, diff --git a/square/shwap/row_namespace_data_id.go b/share/shwap/row_namespace_data_id.go similarity index 88% rename from square/shwap/row_namespace_data_id.go rename to share/shwap/row_namespace_data_id.go index cdada45b03..f0f20e58b9 100644 --- a/square/shwap/row_namespace_data_id.go +++ b/share/shwap/row_namespace_data_id.go @@ -4,18 +4,18 @@ import ( "fmt" "io" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" ) // RowNamespaceDataIDSize defines the total size of a RowNamespaceDataID in bytes, combining the // size of a RowID and the size of a Namespace. -const RowNamespaceDataIDSize = RowIDSize + share.NamespaceSize +const RowNamespaceDataIDSize = RowIDSize + gosquare.NamespaceSize // RowNamespaceDataID uniquely identifies a piece of namespaced data within a row of an Extended // Data Square (EDS). type RowNamespaceDataID struct { - RowID // Embedded RowID representing the specific row in the EDS. - DataNamespace share.Namespace // DataNamespace is a string representation of the namespace to facilitate comparisons. + RowID // Embedded RowID representing the specific row in the EDS. + DataNamespace gosquare.Namespace // DataNamespace is a string representation of the namespace to facilitate comparisons. } // NewRowNamespaceDataID creates a new RowNamespaceDataID with the specified parameters. It @@ -23,7 +23,7 @@ type RowNamespaceDataID struct { func NewRowNamespaceDataID( height uint64, rowIdx int, - namespace share.Namespace, + namespace gosquare.Namespace, edsSize int, ) (RowNamespaceDataID, error) { did := RowNamespaceDataID{ @@ -55,7 +55,7 @@ func RowNamespaceDataIDFromBinary(data []byte) (RowNamespaceDataID, error) { return RowNamespaceDataID{}, fmt.Errorf("unmarshaling RowID: %w", err) } - ns, err := share.NewNamespaceFromBytes(data[RowIDSize:]) + ns, err := gosquare.NewNamespaceFromBytes(data[RowIDSize:]) rndid := RowNamespaceDataID{ RowID: rid, DataNamespace: ns, @@ -123,7 +123,7 @@ func (rndid RowNamespaceDataID) Validate() error { if err := rndid.RowID.Validate(); err != nil { return fmt.Errorf("validating RowID: %w", err) } - if err := share.ValidateForData(rndid.DataNamespace); err != nil { + if err := gosquare.ValidateForData(rndid.DataNamespace); err != nil { return fmt.Errorf("%w: validating DataNamespace: %w", ErrInvalidID, err) } diff --git a/square/shwap/row_namespace_data_id_test.go b/share/shwap/row_namespace_data_id_test.go similarity index 89% rename from square/shwap/row_namespace_data_id_test.go rename to share/shwap/row_namespace_data_id_test.go index 658072c58a..c59e34753f 100644 --- a/square/shwap/row_namespace_data_id_test.go +++ b/share/shwap/row_namespace_data_id_test.go @@ -7,12 +7,12 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" ) func TestRowNamespaceDataID(t *testing.T) { edsSize := 4 - ns := share.RandomNamespace() + ns := gosquare.RandomNamespace() id, err := NewRowNamespaceDataID(1, 1, ns, edsSize) require.NoError(t, err) @@ -31,7 +31,7 @@ func TestRowNamespaceDataID(t *testing.T) { func TestRowNamespaceDataIDReaderWriter(t *testing.T) { edsSize := 4 - ns := share.RandomNamespace() + ns := gosquare.RandomNamespace() id, err := NewRowNamespaceDataID(1, 1, ns, edsSize) require.NoError(t, err) diff --git a/square/shwap/row_namespace_data_test.go b/share/shwap/row_namespace_data_test.go similarity index 71% rename from square/shwap/row_namespace_data_test.go rename to share/shwap/row_namespace_data_test.go index b120919d13..ec922e98ca 100644 --- a/square/shwap/row_namespace_data_test.go +++ b/share/shwap/row_namespace_data_test.go @@ -9,28 +9,28 @@ import ( "github.com/stretchr/testify/require" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" - "github.com/celestiaorg/celestia-node/square" - "github.com/celestiaorg/celestia-node/square/eds" - "github.com/celestiaorg/celestia-node/square/eds/edstest" - "github.com/celestiaorg/celestia-node/square/shwap" + "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/share/eds" + "github.com/celestiaorg/celestia-node/share/eds/edstest" + "github.com/celestiaorg/celestia-node/share/shwap" ) func TestNamespacedRowFromShares(t *testing.T) { const odsSize = 8 - minNamespace, err := share.NewV0Namespace(slices.Concat(bytes.Repeat([]byte{0}, 8), []byte{1, 0})) + minNamespace, err := gosquare.NewV0Namespace(slices.Concat(bytes.Repeat([]byte{0}, 8), []byte{1, 0})) require.NoError(t, err) - err = share.ValidateForData(minNamespace) + err = gosquare.ValidateForData(minNamespace) require.NoError(t, err) for namespacedAmount := 1; namespacedAmount < odsSize; namespacedAmount++ { - shares := share.RandSharesWithNamespace(minNamespace, namespacedAmount, odsSize) - parity, err := square.DefaultRSMT2DCodec().Encode(share.ToBytes(shares)) + shares := gosquare.RandSharesWithNamespace(minNamespace, namespacedAmount, odsSize) + parity, err := share.DefaultRSMT2DCodec().Encode(gosquare.ToBytes(shares)) require.NoError(t, err) - paritySh, err := share.FromBytes(parity) + paritySh, err := gosquare.FromBytes(parity) require.NoError(t, err) extended := slices.Concat(shares, paritySh) @@ -46,15 +46,15 @@ func TestNamespacedRowFromShares(t *testing.T) { // // const odsSize = 8 // // Test absent namespace -// shares := share.RandShares( odsSize) -// absentNs, err := square.GetNamespace(shares[0]).AddInt(1) +// shares := gosquare.RandShares( odsSize) +// absentNs, err := share.GetNamespace(shares[0]).AddInt(1) // require.NoError(t, err) // -// parity, err := square.DefaultRSMT2DCodec().Encode(shares) +// parity, err := share.DefaultRSMT2DCodec().Encode(shares) // require.NoError(t, err) // extended := slices.Concat(shares, parity) // -// shrs, err := share.FromBytes(extended) +// shrs, err := gosquare.FromBytes(extended) // require.NoError(t, err) // // nr, err := shwap.RowNamespaceDataFromShares(shrs, absentNs, 0) @@ -77,7 +77,7 @@ func TestNamespacedRowFromShares(t *testing.T) { // require.NoError(t, err) // require.True(t, len(nd) > 0) // -// rowIdxs := square.RowsWithNamespace(root, namespace) +// rowIdxs := share.RowsWithNamespace(root, namespace) // require.Len(t, nd, len(rowIdxs)) // // for i, rowIdx := range rowIdxs { @@ -92,7 +92,7 @@ func TestNamespacedRowProtoEncoding(t *testing.T) { t.Cleanup(cancel) const odsSize = 8 - namespace := share.RandomNamespace() + namespace := gosquare.RandomNamespace() randEDS, _ := edstest.RandEDSWithNamespace(t, namespace, odsSize, odsSize) rsmt2d := &eds.Rsmt2D{ExtendedDataSquare: randEDS} nd, err := eds.NamespaceData(ctx, rsmt2d, namespace) diff --git a/square/shwap/row_test.go b/share/shwap/row_test.go similarity index 80% rename from square/shwap/row_test.go rename to share/shwap/row_test.go index 9bb9aded59..e2936ab245 100644 --- a/square/shwap/row_test.go +++ b/share/shwap/row_test.go @@ -5,10 +5,10 @@ import ( "github.com/stretchr/testify/require" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" - "github.com/celestiaorg/celestia-node/square" - "github.com/celestiaorg/celestia-node/square/eds/edstest" + "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/share/eds/edstest" ) func TestRowFromShares(t *testing.T) { @@ -18,14 +18,14 @@ func TestRowFromShares(t *testing.T) { for rowIdx := 0; rowIdx < odsSize*2; rowIdx++ { for _, side := range []RowSide{Left, Right} { shrs := eds.Row(uint(rowIdx)) - shares, err := share.FromBytes(shrs) + shares, err := gosquare.FromBytes(shrs) require.NoError(t, err) row := RowFromShares(shares, side) extended, err := row.Shares() require.NoError(t, err) require.Equal(t, shares, extended) - var half []share.Share + var half []gosquare.Share if side == Right { half = shares[odsSize:] } else { @@ -40,13 +40,13 @@ func TestRowFromShares(t *testing.T) { func TestRowValidate(t *testing.T) { const odsSize = 8 eds := edstest.RandEDS(t, odsSize) - root, err := square.NewAxisRoots(eds) + root, err := share.NewAxisRoots(eds) require.NoError(t, err) for rowIdx := 0; rowIdx < odsSize*2; rowIdx++ { for _, side := range []RowSide{Left, Right} { shrs := eds.Row(uint(rowIdx)) - shares, err := share.FromBytes(shrs) + shares, err := gosquare.FromBytes(shrs) require.NoError(t, err) row := RowFromShares(shares, side) @@ -60,10 +60,10 @@ func TestRowValidate(t *testing.T) { func TestRowValidateNegativeCases(t *testing.T) { eds := edstest.RandEDS(t, 8) // Generate a random Extended Data Square of size 8 - root, err := square.NewAxisRoots(eds) + root, err := share.NewAxisRoots(eds) require.NoError(t, err) shrs := eds.Row(0) - shares, err := share.FromBytes(shrs) + shares, err := gosquare.FromBytes(shrs) require.NoError(t, err) row := RowFromShares(shares, Left) @@ -73,9 +73,9 @@ func TestRowValidateNegativeCases(t *testing.T) { require.Error(t, err, "should error on invalid row side") // Test with invalid shares (more shares than expected) - incorrectShares := make([]share.Share, (eds.Width()/2)+1) // Adding an extra share + incorrectShares := make([]gosquare.Share, (eds.Width()/2)+1) // Adding an extra share for i := range incorrectShares { - shr, err := share.NewShare(eds.GetCell(uint(i), 0)) + shr, err := gosquare.NewShare(eds.GetCell(uint(i), 0)) require.NoError(t, err) incorrectShares[i] = *shr } @@ -84,7 +84,7 @@ func TestRowValidateNegativeCases(t *testing.T) { require.Error(t, err, "should error on incorrect number of shares") // Test with empty shares - emptyRow := Row{halfShares: []share.Share{}, side: Left} + emptyRow := Row{halfShares: []gosquare.Share{}, side: Left} err = emptyRow.Verify(root, 0) require.Error(t, err, "should error on empty halfShares") @@ -101,7 +101,7 @@ func TestRowProtoEncoding(t *testing.T) { for rowIdx := 0; rowIdx < odsSize*2; rowIdx++ { for _, side := range []RowSide{Left, Right} { shrs := eds.Row(uint(rowIdx)) - shares, err := share.FromBytes(shrs) + shares, err := gosquare.FromBytes(shrs) require.NoError(t, err) row := RowFromShares(shares, side) @@ -118,10 +118,10 @@ func TestRowProtoEncoding(t *testing.T) { func BenchmarkRowValidate(b *testing.B) { const odsSize = 32 eds := edstest.RandEDS(b, odsSize) - root, err := square.NewAxisRoots(eds) + root, err := share.NewAxisRoots(eds) require.NoError(b, err) shrs := eds.Row(0) - shares, err := share.FromBytes(shrs) + shares, err := gosquare.FromBytes(shrs) require.NoError(b, err) row := RowFromShares(shares, Left) diff --git a/square/shwap/sample.go b/share/shwap/sample.go similarity index 75% rename from square/shwap/sample.go rename to share/shwap/sample.go index 2e24918e0a..dd9e7cc1f9 100644 --- a/square/shwap/sample.go +++ b/share/shwap/sample.go @@ -5,13 +5,13 @@ import ( "fmt" "github.com/celestiaorg/celestia-app/v3/pkg/wrapper" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt" nmt_pb "github.com/celestiaorg/nmt/pb" "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/square" - "github.com/celestiaorg/celestia-node/square/shwap/pb" + "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/share/shwap/pb" ) // SampleName is the name identifier for the sample container. @@ -22,16 +22,16 @@ const SampleName = "sample_v0" var ErrFailedVerification = errors.New("failed to verify inclusion") // Sample represents a data share along with its Merkle proof, used to validate the share's -// inclusion in a data square. +// inclusion in a data share. type Sample struct { - share.Share // Embeds the Share which includes the data with namespace. - Proof *nmt.Proof // Proof is the Merkle Proof validating the share's inclusion. - ProofType rsmt2d.Axis // ProofType indicates whether the proof is against a row or a column. + gosquare.Share // Embeds the Share which includes the data with namespace. + Proof *nmt.Proof // Proof is the Merkle Proof validating the share's inclusion. + ProofType rsmt2d.Axis // ProofType indicates whether the proof is against a row or a column. } // SampleFromShares creates a Sample from a list of shares, using the specified proof type and // the share index to be included in the sample. -func SampleFromShares(shares []share.Share, proofType rsmt2d.Axis, axisIdx, shrIdx int) (Sample, error) { +func SampleFromShares(shares []gosquare.Share, proofType rsmt2d.Axis, axisIdx, shrIdx int) (Sample, error) { tree := wrapper.NewErasuredNamespacedMerkleTree(uint64(len(shares)/2), uint(axisIdx)) for _, shr := range shares { err := tree.Push(shr.ToBytes()) @@ -95,7 +95,7 @@ func (s Sample) IsEmpty() bool { // Verify checks the inclusion of the share using its Merkle proof under the specified AxisRoots. // Returns an error if the proof is invalid or does not correspond to the indicated proof type. -func (s Sample) Verify(roots *square.AxisRoots, rowIdx, colIdx int) error { +func (s Sample) Verify(roots *share.AxisRoots, rowIdx, colIdx int) error { if s.Proof == nil || s.Proof.IsEmptyProof() { return errors.New("nil proof") } @@ -109,26 +109,26 @@ func (s Sample) Verify(roots *square.AxisRoots, rowIdx, colIdx int) error { } // verifyInclusion checks if the share is included in the given root hash at the specified indices. -func (s Sample) verifyInclusion(roots *square.AxisRoots, rowIdx, colIdx int) bool { +func (s Sample) verifyInclusion(roots *share.AxisRoots, rowIdx, colIdx int) bool { size := len(roots.RowRoots) namespace := inclusionNamespace(s.Share, rowIdx, colIdx, size) - rootHash := square.RootHashForCoordinates(roots, s.ProofType, uint(rowIdx), uint(colIdx)) + rootHash := share.RootHashForCoordinates(roots, s.ProofType, uint(rowIdx), uint(colIdx)) return s.Proof.VerifyInclusion( - square.NewSHA256Hasher(), + share.NewSHA256Hasher(), namespace.Bytes(), [][]byte{s.Share.ToBytes()}, rootHash, ) } -// inclusionNamespace returns the namespace for the share based on its position in the square. +// inclusionNamespace returns the namespace for the share based on its position in the share. // Shares from extended part of the square are considered parity shares. It means that -// parity shares are located outside of first quadrant of the square. According to the nmt +// parity shares are located outside of first quadrant of the share. According to the nmt // specification, the parity shares are prefixed with the namespace of the parity shares. -func inclusionNamespace(sh share.Share, rowIdx, colIdx, squareSize int) share.Namespace { +func inclusionNamespace(sh gosquare.Share, rowIdx, colIdx, squareSize int) gosquare.Namespace { isParity := colIdx >= squareSize/2 || rowIdx >= squareSize/2 if isParity { - return share.ParitySharesNamespace + return gosquare.ParitySharesNamespace } return sh.Namespace() } diff --git a/square/shwap/sample_id.go b/share/shwap/sample_id.go similarity index 100% rename from square/shwap/sample_id.go rename to share/shwap/sample_id.go diff --git a/square/shwap/sample_id_test.go b/share/shwap/sample_id_test.go similarity index 100% rename from square/shwap/sample_id_test.go rename to share/shwap/sample_id_test.go diff --git a/square/shwap/sample_test.go b/share/shwap/sample_test.go similarity index 87% rename from square/shwap/sample_test.go rename to share/shwap/sample_test.go index a2b4aa1e53..031bec7834 100644 --- a/square/shwap/sample_test.go +++ b/share/shwap/sample_test.go @@ -6,19 +6,19 @@ import ( "github.com/stretchr/testify/require" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/square" - "github.com/celestiaorg/celestia-node/square/eds" - "github.com/celestiaorg/celestia-node/square/eds/edstest" - "github.com/celestiaorg/celestia-node/square/shwap" + "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/share/eds" + "github.com/celestiaorg/celestia-node/share/eds/edstest" + "github.com/celestiaorg/celestia-node/share/shwap" ) func TestSampleValidate(t *testing.T) { const odsSize = 8 randEDS := edstest.RandEDS(t, odsSize) - root, err := square.NewAxisRoots(randEDS) + root, err := share.NewAxisRoots(randEDS) require.NoError(t, err) inMem := eds.Rsmt2D{ExtendedDataSquare: randEDS} @@ -38,7 +38,7 @@ func TestSampleValidate(t *testing.T) { func TestSampleNegativeVerifyInclusion(t *testing.T) { const odsSize = 8 randEDS := edstest.RandEDS(t, odsSize) - root, err := square.NewAxisRoots(randEDS) + root, err := share.NewAxisRoots(randEDS) require.NoError(t, err) inMem := eds.Rsmt2D{ExtendedDataSquare: randEDS} @@ -54,7 +54,7 @@ func TestSampleNegativeVerifyInclusion(t *testing.T) { // Corrupt the share b := sample.Share.ToBytes() b[0] ^= 0xFF - shr, err := share.NewShare(b) + shr, err := gosquare.NewShare(b) require.NoError(t, err) sample.Share = *shr err = sample.Verify(root, 0, 0) @@ -100,7 +100,7 @@ func TestSampleProtoEncoding(t *testing.T) { func BenchmarkSampleValidate(b *testing.B) { const odsSize = 32 randEDS := edstest.RandEDS(b, odsSize) - root, err := square.NewAxisRoots(randEDS) + root, err := share.NewAxisRoots(randEDS) require.NoError(b, err) inMem := eds.Rsmt2D{ExtendedDataSquare: randEDS} sample, err := inMem.SampleForProofAxis(0, 0, rsmt2d.Row) diff --git a/square/shwap/share.go b/share/shwap/share.go similarity index 70% rename from square/shwap/share.go rename to share/shwap/share.go index 76b68e0eff..f10048636e 100644 --- a/square/shwap/share.go +++ b/share/shwap/share.go @@ -3,21 +3,21 @@ package shwap import ( "fmt" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" - "github.com/celestiaorg/celestia-node/square/shwap/pb" + "github.com/celestiaorg/celestia-node/share/shwap/pb" ) // ShareFromProto converts a protobuf Share object to the application's internal share // representation. It returns nil if the input protobuf Share is nil, ensuring safe handling of nil // values. -func ShareFromProto(s *pb.Share) (share.Share, error) { +func ShareFromProto(s *pb.Share) (gosquare.Share, error) { if s == nil { - return share.Share{}, nil + return gosquare.Share{}, nil } - sh, err := share.NewShare(s.Data) + sh, err := gosquare.NewShare(s.Data) if err != nil { - return share.Share{}, err + return gosquare.Share{}, err } return *sh, err } @@ -25,7 +25,7 @@ func ShareFromProto(s *pb.Share) (share.Share, error) { // SharesToProto converts a slice of Shares from the application's internal representation to a // slice of protobuf Share objects. This function allocates memory for the protobuf objects and // copies data from the input slice. -func SharesToProto(shrs []share.Share) []*pb.Share { +func SharesToProto(shrs []gosquare.Share) []*pb.Share { protoShares := make([]*pb.Share, len(shrs)) for i, shr := range shrs { protoShares[i] = &pb.Share{Data: shr.ToBytes()} @@ -35,8 +35,8 @@ func SharesToProto(shrs []share.Share) []*pb.Share { // SharesFromProto converts a slice of protobuf Share objects to the application's internal slice // of Shares. It ensures that each Share is correctly transformed using the ShareFromProto function. -func SharesFromProto(shrs []*pb.Share) ([]share.Share, error) { - shares := make([]share.Share, len(shrs)) +func SharesFromProto(shrs []*pb.Share) ([]gosquare.Share, error) { + shares := make([]gosquare.Share, len(shrs)) var err error for i, shr := range shrs { shares[i], err = ShareFromProto(shr) diff --git a/square/namespace.go b/square/namespace.go deleted file mode 100644 index 65c5a0390c..0000000000 --- a/square/namespace.go +++ /dev/null @@ -1,233 +0,0 @@ -package square - -import ( - "bytes" - "encoding/binary" - "encoding/hex" - "errors" - "fmt" - - appns "github.com/celestiaorg/go-square/namespace" - "github.com/celestiaorg/go-square/v2/share" - "github.com/celestiaorg/nmt/namespace" -) - -// NamespaceSize is a system-wide size for NMT namespaces. -const NamespaceSize = appns.NamespaceSize - -// Various reserved namespaces. -var ( - // MaxPrimaryReservedNamespace is the highest primary reserved namespace. - // Namespaces lower than this are reserved for protocol use. - MaxPrimaryReservedNamespace = Namespace(appns.MaxPrimaryReservedNamespace.Bytes()) - // MinSecondaryReservedNamespace is the lowest secondary reserved namespace - // reserved for protocol use. Namespaces higher than this are reserved for - // protocol use. - MinSecondaryReservedNamespace = Namespace(appns.MinSecondaryReservedNamespace.Bytes()) - ParitySharesNamespace = Namespace(appns.ParitySharesNamespace.Bytes()) - TailPaddingNamespace = Namespace(appns.TailPaddingNamespace.Bytes()) - PrimaryReservedPaddingNamespace = Namespace(appns.PrimaryReservedPaddingNamespace.Bytes()) - TxNamespace = Namespace(appns.TxNamespace.Bytes()) - PayForBlobNamespace = Namespace(appns.PayForBlobNamespace.Bytes()) - ISRNamespace = Namespace(appns.IntermediateStateRootsNamespace.Bytes()) -) - -// Namespace represents namespace of a Share. -// Consists of version byte and namespace ID. -type Namespace []byte - -// NewBlobNamespaceV0 takes a variable size byte slice and creates a valid version 0 Blob Namespace. -// The byte slice must be <= 10 bytes. -// If it is less than 10 bytes, it will be left padded to size 10 with 0s. -// Use predefined namespaces above, if non-blob namespace is needed. -func NewBlobNamespaceV0(id []byte) (Namespace, error) { - if len(id) == 0 || len(id) > appns.NamespaceVersionZeroIDSize { - return nil, fmt.Errorf( - "namespace id must be > 0 && <= %d, but it was %d bytes", appns.NamespaceVersionZeroIDSize, len(id)) - } - - n := make(Namespace, NamespaceSize) - // version and zero padding are already set as zero, - // so simply copying subNID to the end is enough to comply the V0 spec - copy(n[len(n)-len(id):], id) - return n, n.ValidateForBlob() -} - -// NamespaceFromBytes converts bytes into Namespace and validates it. -func NamespaceFromBytes(b []byte) (Namespace, error) { - n := Namespace(b) - return n, n.Validate() -} - -// Version reports version of the Namespace. -func (n Namespace) Version() byte { - return n[appns.NamespaceVersionSize-1] -} - -// ID reports ID of the Namespace. -func (n Namespace) ID() namespace.ID { - return namespace.ID(n[appns.NamespaceVersionSize:]) -} - -// ToNMT converts the whole Namespace(both Version and ID parts) into NMT's namespace.ID -// NOTE: Once https://github.com/celestiaorg/nmt/issues/206 is closed Namespace should become NNT's -// type. -func (n Namespace) ToNMT() namespace.ID { - return namespace.ID(n) -} - -// // ToAppNamespace converts the Namespace to App's definition of Namespace. -// // TODO: Unify types between node and app -func (n Namespace) ToAppNamespace() (share.Namespace, error) { - return share.NewNamespace(n.Version(), n.ID()) -} - -// Len reports the total length of the namespace. -func (n Namespace) Len() int { - return len(n) -} - -// String stringifies the Namespace. -func (n Namespace) String() string { - return hex.EncodeToString(n) -} - -// Equals compares two Namespaces. -func (n Namespace) Equals(target Namespace) bool { - return bytes.Equal(n, target) -} - -// Validate checks if the namespace is correct. -func (n Namespace) Validate() error { - if n.Len() != NamespaceSize { - return fmt.Errorf("invalid namespace length: expected %d, got %d", NamespaceSize, n.Len()) - } - if n.Version() != appns.NamespaceVersionZero && n.Version() != appns.NamespaceVersionMax { - return fmt.Errorf("invalid namespace version %v", n.Version()) - } - if len(n.ID()) != appns.NamespaceIDSize { - return fmt.Errorf("invalid namespace id length: expected %d, got %d", appns.NamespaceIDSize, n.ID().Size()) - } - if n.Version() == appns.NamespaceVersionZero && !bytes.HasPrefix(n.ID(), appns.NamespaceVersionZeroPrefix) { - return fmt.Errorf("invalid namespace id: expect %d leading zeroes", len(appns.NamespaceVersionZeroPrefix)) - } - return nil -} - -// ValidateForData checks if the Namespace is of real/useful data. -func (n Namespace) ValidateForData() error { - if err := n.Validate(); err != nil { - return err - } - if n.Equals(ParitySharesNamespace) || n.Equals(TailPaddingNamespace) { - return fmt.Errorf("invalid data namespace(%s): parity and tail padding namespace are forbidden", n) - } - if n.Version() != appns.NamespaceVersionZero { - return fmt.Errorf("invalid data namespace(%s): only version 0 is supported", n) - } - return nil -} - -// ValidateForBlob checks if the Namespace is valid blob namespace. -func (n Namespace) ValidateForBlob() error { - if err := n.ValidateForData(); err != nil { - return err - } - if bytes.Compare(n, MaxPrimaryReservedNamespace) < 1 { - return fmt.Errorf("invalid blob namespace(%s): reserved namespaces are forbidden", n) - } - if bytes.Compare(n, MinSecondaryReservedNamespace) > -1 { - return fmt.Errorf("invalid blob namespace(%s): reserved namespaces are forbidden", n) - } - return nil -} - -// IsAboveMax checks if the namespace is above the maximum namespace of the given hash. -func (n Namespace) IsAboveMax(nodeHash []byte) bool { - return !n.IsLessOrEqual(nodeHash[n.Len() : n.Len()*2]) -} - -// IsBelowMin checks if the target namespace is below the minimum namespace of the given hash. -func (n Namespace) IsBelowMin(nodeHash []byte) bool { - return n.IsLess(nodeHash[:n.Len()]) -} - -// IsOutsideRange checks if the namespace is outside the min-max range of the given hashes. -func (n Namespace) IsOutsideRange(leftNodeHash, rightNodeHash []byte) bool { - return n.IsBelowMin(leftNodeHash) || n.IsAboveMax(rightNodeHash) -} - -// Repeat copies the Namespace t times. -func (n Namespace) Repeat(t int) []Namespace { - ns := make([]Namespace, t) - for i := 0; i < t; i++ { - ns[i] = n - } - return ns -} - -// IsLess reports if the Namespace is less than the target. -func (n Namespace) IsLess(target Namespace) bool { - return bytes.Compare(n, target) == -1 -} - -// IsLessOrEqual reports if the Namespace is less than the target. -func (n Namespace) IsLessOrEqual(target Namespace) bool { - return bytes.Compare(n, target) < 1 -} - -// IsGreater reports if the Namespace is greater than the target. -func (n Namespace) IsGreater(target Namespace) bool { - return bytes.Compare(n, target) == 1 -} - -// IsGreaterOrEqualThan reports if the Namespace is greater or equal than the target. -func (n Namespace) IsGreaterOrEqualThan(target Namespace) bool { - return bytes.Compare(n, target) > -1 -} - -// AddInt adds arbitrary int value to namespace, treating namespace as big-endian -// implementation of int -func (n Namespace) AddInt(val int) (Namespace, error) { - if val == 0 { - return n, nil - } - // Convert the input integer to a byte slice and add it to result slice - result := make([]byte, len(n)) - if val > 0 { - binary.BigEndian.PutUint64(result[len(n)-8:], uint64(val)) - } else { - binary.BigEndian.PutUint64(result[len(n)-8:], uint64(-val)) - } - - // Perform addition byte by byte - var carry int - for i := len(n) - 1; i >= 0; i-- { - var sum int - if val > 0 { - sum = int(n[i]) + int(result[i]) + carry - } else { - sum = int(n[i]) - int(result[i]) + carry - } - - switch { - case sum > 255: - carry = 1 - sum -= 256 - case sum < 0: - carry = -1 - sum += 256 - default: - carry = 0 - } - - result[i] = uint8(sum) - } - - // Handle any remaining carry - if carry != 0 { - return nil, errors.New("namespace overflow") - } - - return result, nil -} diff --git a/square/share.go b/square/share.go deleted file mode 100644 index 696a6bc948..0000000000 --- a/square/share.go +++ /dev/null @@ -1,40 +0,0 @@ -package square - -import ( - "github.com/celestiaorg/celestia-app/v3/pkg/appconsts" - "github.com/celestiaorg/go-square/v2/share" - "github.com/celestiaorg/nmt" - "github.com/celestiaorg/rsmt2d" -) - -// DefaultRSMT2DCodec sets the default rsmt2d.Codec for shares. -var DefaultRSMT2DCodec = appconsts.DefaultCodec - -// MaxSquareSize is currently the maximum size supported for unerasured data in -// rsmt2d.ExtendedDataSquare. -var MaxSquareSize = appconsts.SquareSizeUpperBound(appconsts.LatestVersion) - -// ShareWithProof contains data with corresponding Merkle Proof -type ShareWithProof struct { //nolint: revive - // Share is a full data including namespace - share.Share - // Proof is a Merkle Proof of current share - Proof *nmt.Proof - // Axis is a type of axis against which the share proof is computed - Axis rsmt2d.Axis -} - -// Validate validates inclusion of the share under the given root CID. -func (s *ShareWithProof) Validate(rootHash []byte, x, y, edsSize int) bool { - isParity := x >= edsSize/2 || y >= edsSize/2 - namespace := share.ParitySharesNamespace - if !isParity { - namespace = s.Share.Namespace() - } - return s.Proof.VerifyInclusion( - NewSHA256Hasher(), - namespace.Bytes(), - [][]byte{s.Share.ToBytes()}, - rootHash, - ) -} diff --git a/state/core_access.go b/state/core_access.go index c768a89c9d..4fbeb52326 100644 --- a/state/core_access.go +++ b/state/core_access.go @@ -27,7 +27,7 @@ import ( apperrors "github.com/celestiaorg/celestia-app/v3/app/errors" "github.com/celestiaorg/celestia-app/v3/pkg/user" libhead "github.com/celestiaorg/go-header" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/celestia-node/header" ) @@ -201,7 +201,7 @@ func (ca *CoreAccessor) cancelCtx() { // TxResponse. The user can specify additional options that can bee applied to the Tx. func (ca *CoreAccessor) SubmitPayForBlob( ctx context.Context, - appblobs []*share.Blob, + appblobs []*gosquare.Blob, cfg *TxConfig, ) (*TxResponse, error) { if len(appblobs) == 0 { diff --git a/state/core_access_test.go b/state/core_access_test.go index f44057bbea..684d1963ac 100644 --- a/state/core_access_test.go +++ b/state/core_access_test.go @@ -19,7 +19,7 @@ import ( "github.com/celestiaorg/celestia-app/v3/test/util/genesis" "github.com/celestiaorg/celestia-app/v3/test/util/testnode" apptypes "github.com/celestiaorg/celestia-app/v3/x/blob/types" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" ) func TestSubmitPayForBlob(t *testing.T) { @@ -32,31 +32,31 @@ func TestSubmitPayForBlob(t *testing.T) { _ = ca.Stop(ctx) }) - ns, err := share.NewV0Namespace([]byte("namespace")) + ns, err := gosquare.NewV0Namespace([]byte("namespace")) require.NoError(t, err) require.False(t, ns.IsReserved()) require.NoError(t, err) - blobbyTheBlob, err := share.NewV0Blob(ns, []byte("data")) + blobbyTheBlob, err := gosquare.NewV0Blob(ns, []byte("data")) require.NoError(t, err) testcases := []struct { name string - blobs []*share.Blob + blobs []*gosquare.Blob gasPrice float64 gasLim uint64 expErr error }{ { name: "empty blobs", - blobs: []*share.Blob{}, + blobs: []*gosquare.Blob{}, gasPrice: DefaultGasPrice, gasLim: 0, expErr: errors.New("state: no blobs provided"), }, { name: "good blob with user provided gas and fees", - blobs: []*share.Blob{blobbyTheBlob}, + blobs: []*gosquare.Blob{blobbyTheBlob}, gasPrice: 0.005, gasLim: apptypes.DefaultEstimateGas([]uint32{uint32(blobbyTheBlob.DataLen())}), expErr: nil, diff --git a/store/cache/accessor_cache.go b/store/cache/accessor_cache.go index 2b99bfee13..893c73b7a9 100644 --- a/store/cache/accessor_cache.go +++ b/store/cache/accessor_cache.go @@ -10,7 +10,7 @@ import ( lru "github.com/hashicorp/golang-lru/v2" - "github.com/celestiaorg/celestia-node/square/eds" + "github.com/celestiaorg/celestia-node/share/eds" ) const defaultCloseTimeout = time.Minute diff --git a/store/cache/accessor_cache_test.go b/store/cache/accessor_cache_test.go index 16fd7d1a7d..d1847dd6da 100644 --- a/store/cache/accessor_cache_test.go +++ b/store/cache/accessor_cache_test.go @@ -11,12 +11,12 @@ import ( "github.com/stretchr/testify/require" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/square" - "github.com/celestiaorg/celestia-node/square/eds" - "github.com/celestiaorg/celestia-node/square/shwap" + "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/share/eds" + "github.com/celestiaorg/celestia-node/share/shwap" ) func TestAccessorCache(t *testing.T) { @@ -307,11 +307,11 @@ func (m *mockAccessor) Size(context.Context) int { panic("implement me") } -func (m *mockAccessor) DataHash(context.Context) (square.DataHash, error) { +func (m *mockAccessor) DataHash(context.Context) (share.DataHash, error) { panic("implement me") } -func (m *mockAccessor) AxisRoots(context.Context) (*square.AxisRoots, error) { +func (m *mockAccessor) AxisRoots(context.Context) (*share.AxisRoots, error) { panic("implement me") } @@ -323,11 +323,11 @@ func (m *mockAccessor) AxisHalf(context.Context, rsmt2d.Axis, int) (eds.AxisHalf panic("implement me") } -func (m *mockAccessor) RowNamespaceData(context.Context, share.Namespace, int) (shwap.RowNamespaceData, error) { +func (m *mockAccessor) RowNamespaceData(context.Context, gosquare.Namespace, int) (shwap.RowNamespaceData, error) { panic("implement me") } -func (m *mockAccessor) Shares(context.Context) ([]share.Share, error) { +func (m *mockAccessor) Shares(context.Context) ([]gosquare.Share, error) { panic("implement me") } diff --git a/store/cache/cache.go b/store/cache/cache.go index 6e5438913a..10e7dffcb3 100644 --- a/store/cache/cache.go +++ b/store/cache/cache.go @@ -7,7 +7,7 @@ import ( logging "github.com/ipfs/go-log/v2" "go.opentelemetry.io/otel" - "github.com/celestiaorg/celestia-node/square/eds" + "github.com/celestiaorg/celestia-node/share/eds" ) var ( diff --git a/store/cache/doublecache.go b/store/cache/doublecache.go index f06bd06fe7..d0fb2c47b9 100644 --- a/store/cache/doublecache.go +++ b/store/cache/doublecache.go @@ -5,7 +5,7 @@ import ( "errors" "fmt" - "github.com/celestiaorg/celestia-node/square/eds" + "github.com/celestiaorg/celestia-node/share/eds" ) // DoubleCache represents a Cache that looks into multiple caches one by one. diff --git a/store/cache/noop.go b/store/cache/noop.go index 5be2eef20b..ad98c4d98d 100644 --- a/store/cache/noop.go +++ b/store/cache/noop.go @@ -4,12 +4,12 @@ import ( "context" "io" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/square" - "github.com/celestiaorg/celestia-node/square/eds" - "github.com/celestiaorg/celestia-node/square/shwap" + "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/share/eds" + "github.com/celestiaorg/celestia-node/share/shwap" ) var _ Cache = (*NoopCache)(nil) @@ -51,12 +51,12 @@ func (n NoopFile) Size(context.Context) int { return 0 } -func (n NoopFile) DataHash(context.Context) (square.DataHash, error) { - return square.DataHash{}, nil +func (n NoopFile) DataHash(context.Context) (share.DataHash, error) { + return share.DataHash{}, nil } -func (n NoopFile) AxisRoots(context.Context) (*square.AxisRoots, error) { - return &square.AxisRoots{}, nil +func (n NoopFile) AxisRoots(context.Context) (*share.AxisRoots, error) { + return &share.AxisRoots{}, nil } func (n NoopFile) Sample(context.Context, int, int) (shwap.Sample, error) { @@ -67,12 +67,12 @@ func (n NoopFile) AxisHalf(context.Context, rsmt2d.Axis, int) (eds.AxisHalf, err return eds.AxisHalf{}, nil } -func (n NoopFile) RowNamespaceData(context.Context, share.Namespace, int) (shwap.RowNamespaceData, error) { +func (n NoopFile) RowNamespaceData(context.Context, gosquare.Namespace, int) (shwap.RowNamespaceData, error) { return shwap.RowNamespaceData{}, nil } -func (n NoopFile) Shares(context.Context) ([]share.Share, error) { - return []share.Share{}, nil +func (n NoopFile) Shares(context.Context) ([]gosquare.Share, error) { + return []gosquare.Share{}, nil } func (n NoopFile) Close() error { diff --git a/store/file/codec_test.go b/store/file/codec_test.go index 0ab9b7c5bb..7a0489e4d5 100644 --- a/store/file/codec_test.go +++ b/store/file/codec_test.go @@ -7,7 +7,7 @@ import ( "github.com/klauspost/reedsolomon" "github.com/stretchr/testify/require" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" ) func BenchmarkCodec(b *testing.B) { @@ -70,13 +70,13 @@ func BenchmarkCodec(b *testing.B) { func newShards(b testing.TB, size int, fillParity bool) [][]byte { shards := make([][]byte, size) - original := share.RandShares(size / 2) - copy(shards, share.ToBytes(original)) + original := gosquare.RandShares(size / 2) + copy(shards, gosquare.ToBytes(original)) if fillParity { // fill with parity empty Shares for j := len(original); j < len(shards); j++ { - shards[j] = make([]byte, share.ShareSize) + shards[j] = make([]byte, gosquare.ShareSize) } } return shards diff --git a/store/file/header.go b/store/file/header.go index bb5f891870..7c2d8c7924 100644 --- a/store/file/header.go +++ b/store/file/header.go @@ -5,7 +5,7 @@ import ( "fmt" "io" - "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/share" ) // headerVOSize is the size of the headerV0 in bytes. It has more space than the headerV0 struct @@ -23,7 +23,7 @@ type headerV0 struct { shareSize uint16 squareSize uint16 - datahash square.DataHash + datahash share.DataHash } type fileVersion uint8 @@ -75,7 +75,7 @@ func (h *headerV0) Size() int { func (h *headerV0) RootsSize() int { // axis roots are stored in two parts: row roots and column roots, each part has size equal to // the square size. Thus, the total amount of roots is equal to the square size * 2. - return square.AxisRootSize * h.SquareSize() * 2 + return share.AxisRootSize * h.SquareSize() * 2 } func (h *headerV0) OffsetWithRoots() int { diff --git a/store/file/ods.go b/store/file/ods.go index 738109fae4..8ee29d2af0 100644 --- a/store/file/ods.go +++ b/store/file/ods.go @@ -9,12 +9,12 @@ import ( "os" "sync" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/square" - "github.com/celestiaorg/celestia-node/square/eds" - "github.com/celestiaorg/celestia-node/square/shwap" + "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/share/eds" + "github.com/celestiaorg/celestia-node/share/shwap" ) var _ eds.AccessorStreamer = (*ODS)(nil) @@ -34,7 +34,7 @@ type ODS struct { // repeated file reads. - Serving full ODS data by Shares(). // Storing the square in memory allows for efficient single-read operations, avoiding the need for // piecemeal reads by rows or columns, and facilitates quick access to data for these operations. - ods dataSquare + ods square // disableCache is a flag that, when set to true, disables the in-memory cache of the original data // Used for testing and benchmarking purposes, this flag allows for the evaluation of the // performance. @@ -46,7 +46,7 @@ type ODS struct { // It may leave partially written file if any of the writes fail. func CreateODS( path string, - roots *square.AxisRoots, + roots *share.AxisRoots, eds *rsmt2d.ExtendedDataSquare, ) error { mod := os.O_RDWR | os.O_CREATE | os.O_EXCL // ensure we fail if already exist @@ -72,7 +72,7 @@ func CreateODS( } // writeQ4File full ODS content into OS File. -func writeODSFile(f *os.File, axisRoots *square.AxisRoots, eds *rsmt2d.ExtendedDataSquare, hdr *headerV0) error { +func writeODSFile(f *os.File, axisRoots *share.AxisRoots, eds *rsmt2d.ExtendedDataSquare, hdr *headerV0) error { // buffering gives us ~4x speed up buf := bufio.NewWriterSize(f, writeBufferSize) @@ -97,16 +97,16 @@ func writeODSFile(f *os.File, axisRoots *square.AxisRoots, eds *rsmt2d.ExtendedD // writeODS writes the first quadrant(ODS) of the square to the writer. It writes the quadrant in // row-major order. Write finishes once all the shares are written or on the first instance of tail -// padding share. Tail padding share are constant and aren't stored. +// padding gosquare. Tail padding share are constant and aren't stored. func writeODS(w io.Writer, eds *rsmt2d.ExtendedDataSquare) error { for i := range eds.Width() / 2 { for j := range eds.Width() / 2 { shr := eds.GetCell(i, j) // TODO: Avoid copying inside GetCell - ns, err := share.NewNamespace(shr[share.VersionIndex], shr[share.VersionIndex:share.NamespaceIDSize]) + ns, err := gosquare.NewNamespace(shr[gosquare.VersionIndex], shr[gosquare.VersionIndex:gosquare.NamespaceIDSize]) if err != nil { return fmt.Errorf("creating namespace: %w", err) } - if ns.Equals(share.TailPaddingNamespace) { + if ns.Equals(gosquare.TailPaddingNamespace) { return nil } @@ -120,7 +120,7 @@ func writeODS(w io.Writer, eds *rsmt2d.ExtendedDataSquare) error { } // writeAxisRoots writes RowRoots followed by ColumnRoots. -func writeAxisRoots(w io.Writer, roots *square.AxisRoots) error { +func writeAxisRoots(w io.Writer, roots *share.AxisRoots) error { for _, root := range roots.RowRoots { if _, err := w.Write(root); err != nil { return fmt.Errorf("writing row roots: %w", err) @@ -189,13 +189,13 @@ func (o *ODS) size() int { } // DataHash returns root hash of Accessor's underlying EDS. -func (o *ODS) DataHash(context.Context) (square.DataHash, error) { +func (o *ODS) DataHash(context.Context) (share.DataHash, error) { return o.hdr.datahash, nil } // AxisRoots reads AxisRoots stored in the file. AxisRoots are stored after the header and before // the ODS data. -func (o *ODS) AxisRoots(context.Context) (*square.AxisRoots, error) { +func (o *ODS) AxisRoots(context.Context) (*share.AxisRoots, error) { roots := make([]byte, o.hdr.RootsSize()) n, err := o.fl.ReadAt(roots, int64(o.hdr.Size())) if err != nil { @@ -207,10 +207,10 @@ func (o *ODS) AxisRoots(context.Context) (*square.AxisRoots, error) { rowRoots := make([][]byte, o.size()) colRoots := make([][]byte, o.size()) for i := 0; i < o.size(); i++ { - rowRoots[i] = roots[i*square.AxisRootSize : (i+1)*square.AxisRootSize] - colRoots[i] = roots[(o.size()+i)*square.AxisRootSize : (o.size()+i+1)*square.AxisRootSize] + rowRoots[i] = roots[i*share.AxisRootSize : (i+1)*share.AxisRootSize] + colRoots[i] = roots[(o.size()+i)*share.AxisRootSize : (o.size()+i+1)*share.AxisRootSize] } - axisRoots := &square.AxisRoots{ + axisRoots := &share.AxisRoots{ RowRoots: rowRoots, ColumnRoots: colRoots, } @@ -250,7 +250,7 @@ func (o *ODS) Sample(ctx context.Context, rowIdx, colIdx int) (shwap.Sample, err // implementation. Implementations should indicate the side in the returned AxisHalf. func (o *ODS) AxisHalf(_ context.Context, axisType rsmt2d.Axis, axisIdx int) (eds.AxisHalf, error) { // Read the axis from the file if the axis is a row and from the top half of the square, or if the - // axis is a column and from the left half of the square. + // axis is a column and from the left half of the share. if axisIdx < o.size()/2 { half, err := o.readAxisHalf(axisType, axisIdx) if err != nil { @@ -275,7 +275,7 @@ func (o *ODS) AxisHalf(_ context.Context, axisType rsmt2d.Axis, axisIdx int) (ed // RowNamespaceData returns data for the given namespace and row index. func (o *ODS) RowNamespaceData( ctx context.Context, - namespace share.Namespace, + namespace gosquare.Namespace, rowIdx int, ) (shwap.RowNamespaceData, error) { shares, err := o.axis(ctx, rsmt2d.Row, rowIdx) @@ -286,7 +286,7 @@ func (o *ODS) RowNamespaceData( } // Shares returns data shares extracted from the Accessor. -func (o *ODS) Shares(context.Context) ([]share.Share, error) { +func (o *ODS) Shares(context.Context) ([]gosquare.Share, error) { ods, err := o.readODS() if err != nil { return nil, err @@ -310,7 +310,7 @@ func (o *ODS) Reader() (io.Reader, error) { return reader, nil } -func (o *ODS) axis(ctx context.Context, axisType rsmt2d.Axis, axisIdx int) ([]share.Share, error) { +func (o *ODS) axis(ctx context.Context, axisType rsmt2d.Axis, axisIdx int) ([]gosquare.Share, error) { half, err := o.AxisHalf(ctx, axisType, axisIdx) if err != nil { return nil, err @@ -343,7 +343,7 @@ func (o *ODS) readAxisHalf(axisType rsmt2d.Axis, axisIdx int) (eds.AxisHalf, err }, nil } -func (o *ODS) readODS() (dataSquare, error) { +func (o *ODS) readODS() (square, error) { if !o.disableCache { o.lock.RLock() ods := o.ods @@ -373,7 +373,7 @@ func (o *ODS) readODS() (dataSquare, error) { return ods, nil } -func readAxisHalf(r io.ReaderAt, axisTp rsmt2d.Axis, axisIdx int, hdr *headerV0, offset int) ([]share.Share, error) { +func readAxisHalf(r io.ReaderAt, axisTp rsmt2d.Axis, axisIdx int, hdr *headerV0, offset int) ([]gosquare.Share, error) { switch axisTp { case rsmt2d.Row: return readRowHalf(r, axisIdx, hdr, offset) @@ -386,12 +386,12 @@ func readAxisHalf(r io.ReaderAt, axisTp rsmt2d.Axis, axisIdx int, hdr *headerV0, // readRowHalf reads specific Row half from the file in a single IO operation. // If some or all shares are missing, tail padding shares are returned instead. -func readRowHalf(r io.ReaderAt, rowIdx int, hdr *headerV0, offset int) ([]share.Share, error) { +func readRowHalf(r io.ReaderAt, rowIdx int, hdr *headerV0, offset int) ([]gosquare.Share, error) { odsLn := hdr.SquareSize() / 2 rowOffset := rowIdx * odsLn * hdr.ShareSize() offset += rowOffset - shares := make([]share.Share, odsLn) + shares := make([]gosquare.Share, odsLn) axsData := make([]byte, odsLn*hdr.ShareSize()) n, err := r.ReadAt(axsData, int64(offset)) if err != nil && !errors.Is(err, io.EOF) { @@ -404,10 +404,10 @@ func readRowHalf(r io.ReaderAt, rowIdx int, hdr *headerV0, offset int) ([]share. if i > shrsRead-1 { // partial or empty row was read // fill the rest with tail padding it - shares[i] = share.TailPaddingShare() + shares[i] = gosquare.TailPaddingShare() continue } - sh, err := share.NewShare(axsData[i*hdr.ShareSize() : (i+1)*hdr.ShareSize()]) + sh, err := gosquare.NewShare(axsData[i*hdr.ShareSize() : (i+1)*hdr.ShareSize()]) if err != nil { return nil, err } @@ -418,9 +418,9 @@ func readRowHalf(r io.ReaderAt, rowIdx int, hdr *headerV0, offset int) ([]share. // readColHalf reads specific Col half from the file in a single IO operation. // If some or all shares are missing, tail padding shares are returned instead. -func readColHalf(r io.ReaderAt, colIdx int, hdr *headerV0, offset int) ([]share.Share, error) { +func readColHalf(r io.ReaderAt, colIdx int, hdr *headerV0, offset int) ([]gosquare.Share, error) { odsLn := hdr.SquareSize() / 2 - shares := make([]share.Share, odsLn) + shares := make([]gosquare.Share, odsLn) for i := range shares { pos := colIdx + i*odsLn offset := offset + pos*hdr.ShareSize() @@ -435,12 +435,12 @@ func readColHalf(r io.ReaderAt, colIdx int, hdr *headerV0, offset int) ([]share. // no shares left // fill the rest with tail padding for ; i < len(shares); i++ { - shares[i] = share.TailPaddingShare() + shares[i] = gosquare.TailPaddingShare() } return shares, nil } - sh, err := share.NewShare(shr) + sh, err := gosquare.NewShare(shr) if err != nil { return nil, err } diff --git a/store/file/ods_q4.go b/store/file/ods_q4.go index ce1c00f7b5..6c50b39823 100644 --- a/store/file/ods_q4.go +++ b/store/file/ods_q4.go @@ -9,12 +9,12 @@ import ( "sync" "sync/atomic" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/square" - "github.com/celestiaorg/celestia-node/square/eds" - "github.com/celestiaorg/celestia-node/square/shwap" + "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/share/eds" + "github.com/celestiaorg/celestia-node/share/shwap" ) var _ eds.AccessorStreamer = (*ODSQ4)(nil) @@ -37,7 +37,7 @@ type ODSQ4 struct { // CreateODSQ4 creates ODS and Q4 files under the given FS paths. func CreateODSQ4( pathODS, pathQ4 string, - roots *square.AxisRoots, + roots *share.AxisRoots, eds *rsmt2d.ExtendedDataSquare, ) error { errCh := make(chan error) @@ -114,11 +114,11 @@ func (odsq4 *ODSQ4) Size(ctx context.Context) int { return odsq4.ods.Size(ctx) } -func (odsq4 *ODSQ4) DataHash(ctx context.Context) (square.DataHash, error) { +func (odsq4 *ODSQ4) DataHash(ctx context.Context) (share.DataHash, error) { return odsq4.ods.DataHash(ctx) } -func (odsq4 *ODSQ4) AxisRoots(ctx context.Context) (*square.AxisRoots, error) { +func (odsq4 *ODSQ4) AxisRoots(ctx context.Context) (*share.AxisRoots, error) { return odsq4.ods.AxisRoots(ctx) } @@ -149,7 +149,7 @@ func (odsq4 *ODSQ4) AxisHalf(ctx context.Context, axisType rsmt2d.Axis, axisIdx } func (odsq4 *ODSQ4) RowNamespaceData(ctx context.Context, - namespace share.Namespace, + namespace gosquare.Namespace, rowIdx int, ) (shwap.RowNamespaceData, error) { half, err := odsq4.AxisHalf(ctx, rsmt2d.Row, rowIdx) @@ -163,7 +163,7 @@ func (odsq4 *ODSQ4) RowNamespaceData(ctx context.Context, return shwap.RowNamespaceDataFromShares(shares, namespace, rowIdx) } -func (odsq4 *ODSQ4) Shares(ctx context.Context) ([]share.Share, error) { +func (odsq4 *ODSQ4) Shares(ctx context.Context) ([]gosquare.Share, error) { return odsq4.ods.Shares(ctx) } diff --git a/store/file/ods_q4_test.go b/store/file/ods_q4_test.go index 83e94d8a96..8795ca9cd4 100644 --- a/store/file/ods_q4_test.go +++ b/store/file/ods_q4_test.go @@ -12,12 +12,12 @@ import ( "github.com/stretchr/testify/require" "github.com/tendermint/tendermint/libs/rand" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/square" - "github.com/celestiaorg/celestia-node/square/eds" - "github.com/celestiaorg/celestia-node/square/eds/edstest" + "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/share/eds" + "github.com/celestiaorg/celestia-node/share/eds/edstest" ) func TestCreateODSQ4File(t *testing.T) { @@ -30,7 +30,7 @@ func TestCreateODSQ4File(t *testing.T) { shares, err := odsq4.Shares(ctx) require.NoError(t, err) expected := edsIn.FlattenedODS() - require.Equal(t, expected, share.ToBytes(shares)) + require.Equal(t, expected, gosquare.ToBytes(shares)) require.NoError(t, odsq4.Close()) } @@ -182,7 +182,7 @@ func createODSQ4Accessor(t testing.TB, eds *rsmt2d.ExtendedDataSquare) eds.Acces func createODSQ4File(t testing.TB, eds *rsmt2d.ExtendedDataSquare) *ODSQ4 { path := t.TempDir() + "/" + strconv.Itoa(rand.Intn(1000)) - roots, err := square.NewAxisRoots(eds) + roots, err := share.NewAxisRoots(eds) require.NoError(t, err) pathODS, pathQ4 := path+".ods", path+".q4" err = CreateODSQ4(pathODS, pathQ4, roots, eds) diff --git a/store/file/ods_test.go b/store/file/ods_test.go index 73c3ff2f89..b5b7deed21 100644 --- a/store/file/ods_test.go +++ b/store/file/ods_test.go @@ -12,12 +12,12 @@ import ( "github.com/stretchr/testify/require" "github.com/tendermint/tendermint/libs/rand" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/square" - "github.com/celestiaorg/celestia-node/square/eds" - "github.com/celestiaorg/celestia-node/square/eds/edstest" + "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/share/eds" + "github.com/celestiaorg/celestia-node/share/eds/edstest" ) func TestCreateODSFile(t *testing.T) { @@ -26,18 +26,18 @@ func TestCreateODSFile(t *testing.T) { edsIn := edstest.RandEDS(t, 8) f := createODSFile(t, edsIn) - readRoots, err := square.NewAxisRoots(edsIn) + readRoots, err := share.NewAxisRoots(edsIn) require.NoError(t, err) shares, err := f.Shares(ctx) require.NoError(t, err) expected := edsIn.FlattenedODS() - require.Equal(t, expected, share.ToBytes(shares)) + require.Equal(t, expected, gosquare.ToBytes(shares)) roots, err := f.AxisRoots(ctx) require.NoError(t, err) - require.Equal(t, square.DataHash(roots.Hash()), f.hdr.datahash) + require.Equal(t, share.DataHash(roots.Hash()), f.hdr.datahash) require.True(t, roots.Equals(readRoots)) require.NoError(t, f.Close()) } @@ -51,7 +51,7 @@ func TestReadODSFromFile(t *testing.T) { for i, row := range ods { original := eds.Row(uint(i))[:eds.Width()/2] require.True(t, len(original) == len(row)) - require.Equal(t, original, share.ToBytes(row)) + require.Equal(t, original, gosquare.ToBytes(row)) } } @@ -251,7 +251,7 @@ func createCachedStreamer(t testing.TB, eds *rsmt2d.ExtendedDataSquare) eds.Acce func createODSFile(t testing.TB, eds *rsmt2d.ExtendedDataSquare) *ODS { path := t.TempDir() + "/" + strconv.Itoa(rand.Intn(1000)) - roots, err := square.NewAxisRoots(eds) + roots, err := share.NewAxisRoots(eds) require.NoError(t, err) err = CreateODS(path, roots, eds) require.NoError(t, err) diff --git a/store/file/q4.go b/store/file/q4.go index 9bb29599fc..a6f848c284 100644 --- a/store/file/q4.go +++ b/store/file/q4.go @@ -9,10 +9,10 @@ import ( "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/square/eds" + "github.com/celestiaorg/celestia-node/share/eds" ) -// q4 stores the fourth quadrant of the square. +// q4 stores the fourth quadrant of the share. type q4 struct { hdr *headerV0 file *os.File diff --git a/store/file/square.go b/store/file/square.go index a12cf41c03..5e9eb53786 100644 --- a/store/file/square.go +++ b/store/file/square.go @@ -6,32 +6,32 @@ import ( "golang.org/x/sync/errgroup" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/square/eds" + "github.com/celestiaorg/celestia-node/share/eds" ) -type dataSquare [][]share.Share +type square [][]gosquare.Share -// readSquare reads Shares from the reader and returns a square. It assumes that the reader is +// readSquare reads Shares from the reader and returns a share. It assumes that the reader is // positioned at the beginning of the Shares. It knows the size of the Shares and the size of the // square, so reads from reader are limited to exactly the amount of data required. -func readSquare(r io.Reader, shareSize, edsSize int) (dataSquare, error) { +func readSquare(r io.Reader, shareSize, edsSize int) (square, error) { odsLn := edsSize / 2 shares, err := eds.ReadShares(r, shareSize, odsLn) if err != nil { return nil, fmt.Errorf("reading shares: %w", err) } - square := make(dataSquare, odsLn) + square := make(square, odsLn) for i := range square { square[i] = shares[i*odsLn : (i+1)*odsLn] } return square, nil } -func (s dataSquare) reader() (io.Reader, error) { +func (s square) reader() (io.Reader, error) { if s == nil { return nil, fmt.Errorf("ods file not cached") } @@ -42,19 +42,19 @@ func (s dataSquare) reader() (io.Reader, error) { return reader, nil } -func (s dataSquare) size() int { +func (s square) size() int { return len(s) } -func (s dataSquare) shares() ([]share.Share, error) { - shares := make([]share.Share, 0, s.size()*s.size()) +func (s square) shares() ([]gosquare.Share, error) { + shares := make([]gosquare.Share, 0, s.size()*s.size()) for _, row := range s { shares = append(shares, row...) } return shares, nil } -func (s dataSquare) axisHalf(axisType rsmt2d.Axis, axisIdx int) (eds.AxisHalf, error) { +func (s square) axisHalf(axisType rsmt2d.Axis, axisIdx int) (eds.AxisHalf, error) { if s == nil { return eds.AxisHalf{}, fmt.Errorf("square is nil") } @@ -73,7 +73,7 @@ func (s dataSquare) axisHalf(axisType rsmt2d.Axis, axisIdx int) (eds.AxisHalf, e } // construct half column from row ordered square - col := make([]share.Share, s.size()) + col := make([]gosquare.Share, s.size()) for i := 0; i < s.size(); i++ { col[i] = s[i][axisIdx] } @@ -83,11 +83,11 @@ func (s dataSquare) axisHalf(axisType rsmt2d.Axis, axisIdx int) (eds.AxisHalf, e }, nil } -func (s dataSquare) computeAxisHalf( +func (s square) computeAxisHalf( axisType rsmt2d.Axis, axisIdx int, ) (eds.AxisHalf, error) { - shares := make([]share.Share, s.size()) + shares := make([]gosquare.Share, s.size()) // extend opposite half of the square while collecting Shares for the first half of required axis g := errgroup.Group{} @@ -106,9 +106,9 @@ func (s dataSquare) computeAxisHalf( shards := make([][]byte, s.size()*2) if half.IsParity { - copy(shards[s.size():], share.ToBytes(half.Shares)) + copy(shards[s.size():], gosquare.ToBytes(half.Shares)) } else { - copy(shards, share.ToBytes(half.Shares)) + copy(shards, gosquare.ToBytes(half.Shares)) } target := make([]bool, s.size()*2) @@ -119,7 +119,7 @@ func (s dataSquare) computeAxisHalf( return fmt.Errorf("reconstruct some: %w", err) } - shard, err := share.NewShare(shards[axisIdx]) + shard, err := gosquare.NewShare(shards[axisIdx]) if err != nil { return fmt.Errorf("creating share: %w", err) } diff --git a/store/getter.go b/store/getter.go index e436aa0489..96b9d37d10 100644 --- a/store/getter.go +++ b/store/getter.go @@ -5,13 +5,13 @@ import ( "errors" "fmt" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" "github.com/celestiaorg/celestia-node/header" "github.com/celestiaorg/celestia-node/libs/utils" - "github.com/celestiaorg/celestia-node/square/eds" - "github.com/celestiaorg/celestia-node/square/shwap" + "github.com/celestiaorg/celestia-node/share/eds" + "github.com/celestiaorg/celestia-node/share/shwap" ) var _ shwap.Getter = (*Getter)(nil) @@ -24,13 +24,13 @@ func NewGetter(store *Store) *Getter { return &Getter{store: store} } -func (g *Getter) GetShare(ctx context.Context, h *header.ExtendedHeader, row, col int) (share.Share, error) { +func (g *Getter) GetShare(ctx context.Context, h *header.ExtendedHeader, row, col int) (gosquare.Share, error) { acc, err := g.store.GetByHeight(ctx, h.Height()) if err != nil { if errors.Is(err, ErrNotFound) { - return share.Share{}, shwap.ErrNotFound + return gosquare.Share{}, shwap.ErrNotFound } - return share.Share{}, fmt.Errorf("get accessor from store:%w", err) + return gosquare.Share{}, fmt.Errorf("get accessor from store:%w", err) } logger := log.With( "height", h.Height(), @@ -41,7 +41,7 @@ func (g *Getter) GetShare(ctx context.Context, h *header.ExtendedHeader, row, co sample, err := acc.Sample(ctx, row, col) if err != nil { - return share.Share{}, fmt.Errorf("get sample from accessor:%w", err) + return gosquare.Share{}, fmt.Errorf("get sample from accessor:%w", err) } return sample.Share, nil } @@ -71,7 +71,7 @@ func (g *Getter) GetEDS(ctx context.Context, h *header.ExtendedHeader) (*rsmt2d. func (g *Getter) GetSharesByNamespace( ctx context.Context, h *header.ExtendedHeader, - ns share.Namespace, + ns gosquare.Namespace, ) (shwap.NamespaceData, error) { acc, err := g.store.GetByHeight(ctx, h.Height()) if err != nil { diff --git a/store/getter_test.go b/store/getter_test.go index 5693e2cc57..9d6defea45 100644 --- a/store/getter_test.go +++ b/store/getter_test.go @@ -7,11 +7,11 @@ import ( "github.com/stretchr/testify/require" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/celestia-node/header/headertest" - "github.com/celestiaorg/celestia-node/square/eds/edstest" - "github.com/celestiaorg/celestia-node/square/shwap" + "github.com/celestiaorg/celestia-node/share/eds/edstest" + "github.com/celestiaorg/celestia-node/share/shwap" ) func TestStoreGetter(t *testing.T) { @@ -67,7 +67,7 @@ func TestStoreGetter(t *testing.T) { }) t.Run("GetSharesByNamespace", func(t *testing.T) { - ns := share.RandomNamespace() + ns := gosquare.RandomNamespace() eds, roots := edstest.RandEDSWithNamespace(t, ns, 8, 16) eh := headertest.RandExtendedHeaderWithRoot(t, roots) height := height.Add(1) @@ -80,7 +80,7 @@ func TestStoreGetter(t *testing.T) { require.NoError(t, shares.Verify(eh.DAH, ns)) // namespace not found - randNamespace := share.RandomNamespace() + randNamespace := gosquare.RandomNamespace() emptyShares, err := sg.GetSharesByNamespace(ctx, eh, randNamespace) require.NoError(t, err) require.Empty(t, emptyShares.Flatten()) diff --git a/store/store.go b/store/store.go index f9fabe7c67..554337275e 100644 --- a/store/store.go +++ b/store/store.go @@ -14,8 +14,8 @@ import ( "github.com/celestiaorg/rsmt2d" "github.com/celestiaorg/celestia-node/libs/utils" - "github.com/celestiaorg/celestia-node/square" - "github.com/celestiaorg/celestia-node/square/eds" + "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/share/eds" "github.com/celestiaorg/celestia-node/store/cache" "github.com/celestiaorg/celestia-node/store/file" ) @@ -92,7 +92,7 @@ func (s *Store) Stop(context.Context) error { func (s *Store) PutODSQ4( ctx context.Context, - roots *square.AxisRoots, + roots *share.AxisRoots, height uint64, square *rsmt2d.ExtendedDataSquare, ) error { @@ -101,7 +101,7 @@ func (s *Store) PutODSQ4( func (s *Store) PutODS( ctx context.Context, - roots *square.AxisRoots, + roots *share.AxisRoots, height uint64, square *rsmt2d.ExtendedDataSquare, ) error { @@ -110,12 +110,12 @@ func (s *Store) PutODS( func (s *Store) put( ctx context.Context, - roots *square.AxisRoots, + roots *share.AxisRoots, height uint64, - dataSquare *rsmt2d.ExtendedDataSquare, + square *rsmt2d.ExtendedDataSquare, writeQ4 bool, ) error { - datahash := square.DataHash(roots.Hash()) + datahash := share.DataHash(roots.Hash()) // we don't need to store empty EDS, just link the height to the empty file if datahash.IsEmptyEDS() { lock := s.stripLock.byHeight(height) @@ -129,7 +129,7 @@ func (s *Store) put( } // put to cache before writing to make it accessible while write is happening - accessor := &eds.Rsmt2D{ExtendedDataSquare: dataSquare} + accessor := &eds.Rsmt2D{ExtendedDataSquare: square} acc, err := s.cache.GetOrLoad(ctx, height, accessorLoader(accessor)) if err != nil { log.Warnf("failed to put Accessor in the recent cache: %s", err) @@ -145,9 +145,9 @@ func (s *Store) put( var exists bool if writeQ4 { - exists, err = s.createODSQ4File(dataSquare, roots, height) + exists, err = s.createODSQ4File(square, roots, height) } else { - exists, err = s.createODSFile(dataSquare, roots, height) + exists, err = s.createODSFile(square, roots, height) } if exists { @@ -155,17 +155,17 @@ func (s *Store) put( return nil } if err != nil { - s.metrics.observePut(ctx, time.Since(tNow), dataSquare.Width(), writeQ4, true) + s.metrics.observePut(ctx, time.Since(tNow), square.Width(), writeQ4, true) return fmt.Errorf("creating file: %w", err) } - s.metrics.observePut(ctx, time.Since(tNow), dataSquare.Width(), writeQ4, false) + s.metrics.observePut(ctx, time.Since(tNow), square.Width(), writeQ4, false) return nil } func (s *Store) createODSQ4File( square *rsmt2d.ExtendedDataSquare, - roots *square.AxisRoots, + roots *share.AxisRoots, height uint64, ) (bool, error) { pathODS := s.hashToPath(roots.Hash(), odsFileExt) @@ -231,7 +231,7 @@ func (s *Store) validateAndRecoverODSQ4( func (s *Store) createODSFile( square *rsmt2d.ExtendedDataSquare, - roots *square.AxisRoots, + roots *share.AxisRoots, height uint64, ) (bool, error) { pathODS := s.hashToPath(roots.Hash(), odsFileExt) @@ -311,15 +311,15 @@ func (s *Store) linkHeight(datahash share.DataHash, height uint64) error { // It overrides existing empty file to ensure disk format is always consistent with the canonical // in-mem representation. func (s *Store) populateEmptyFile() error { - pathOds := s.hashToPath(square.EmptyEDSDataHash(), odsFileExt) - pathQ4 := s.hashToPath(square.EmptyEDSDataHash(), q4FileExt) + pathOds := s.hashToPath(share.EmptyEDSDataHash(), odsFileExt) + pathQ4 := s.hashToPath(share.EmptyEDSDataHash(), q4FileExt) err := errors.Join(remove(pathOds), remove(pathQ4)) if err != nil { return fmt.Errorf("cleaning old empty EDS file: %w", err) } - err = file.CreateODSQ4(pathOds, pathQ4, square.EmptyEDSRoots(), eds.EmptyAccessor.ExtendedDataSquare) + err = file.CreateODSQ4(pathOds, pathQ4, share.EmptyEDSRoots(), eds.EmptyAccessor.ExtendedDataSquare) if err != nil { return fmt.Errorf("creating fresh empty EDS file: %w", err) } @@ -327,7 +327,7 @@ func (s *Store) populateEmptyFile() error { return nil } -func (s *Store) GetByHash(ctx context.Context, datahash square.DataHash) (eds.AccessorStreamer, error) { +func (s *Store) GetByHash(ctx context.Context, datahash share.DataHash) (eds.AccessorStreamer, error) { if datahash.IsEmptyEDS() { return eds.EmptyAccessor, nil } @@ -341,7 +341,7 @@ func (s *Store) GetByHash(ctx context.Context, datahash square.DataHash) (eds.Ac return f, err } -func (s *Store) getByHash(ctx context.Context, datahash square.DataHash) (eds.AccessorStreamer, error) { +func (s *Store) getByHash(ctx context.Context, datahash share.DataHash) (eds.AccessorStreamer, error) { path := s.hashToPath(datahash, odsFileExt) return s.openAccessor(ctx, path) } @@ -390,7 +390,7 @@ func (s *Store) openAccessor(ctx context.Context, path string) (eds.AccessorStre return wrapAccessor(odsQ4), nil } -func (s *Store) HasByHash(ctx context.Context, datahash square.DataHash) (bool, error) { +func (s *Store) HasByHash(ctx context.Context, datahash share.DataHash) (bool, error) { if datahash.IsEmptyEDS() { return true, nil } @@ -405,7 +405,7 @@ func (s *Store) HasByHash(ctx context.Context, datahash square.DataHash) (bool, return exist, err } -func (s *Store) hasByHash(datahash square.DataHash) (bool, error) { +func (s *Store) hasByHash(datahash share.DataHash) (bool, error) { // For now, we assume that if ODS exists, the Q4 exists as well. path := s.hashToPath(datahash, odsFileExt) return exists(path) @@ -432,7 +432,7 @@ func (s *Store) hasByHeight(height uint64) (bool, error) { return exists(pathODS) } -func (s *Store) RemoveODSQ4(ctx context.Context, height uint64, datahash square.DataHash) error { +func (s *Store) RemoveODSQ4(ctx context.Context, height uint64, datahash share.DataHash) error { lock := s.stripLock.byHashAndHeight(datahash, height) lock.lock() defer lock.unlock() @@ -443,7 +443,7 @@ func (s *Store) RemoveODSQ4(ctx context.Context, height uint64, datahash square. return err } -func (s *Store) removeODSQ4(height uint64, datahash square.DataHash) error { +func (s *Store) removeODSQ4(height uint64, datahash share.DataHash) error { if err := s.removeODS(height, datahash); err != nil { return fmt.Errorf("removing ODS: %w", err) } @@ -453,7 +453,7 @@ func (s *Store) removeODSQ4(height uint64, datahash square.DataHash) error { return nil } -func (s *Store) removeODS(height uint64, datahash square.DataHash) error { +func (s *Store) removeODS(height uint64, datahash share.DataHash) error { if err := s.cache.Remove(height); err != nil { return fmt.Errorf("removing from cache: %w", err) } @@ -475,7 +475,7 @@ func (s *Store) removeODS(height uint64, datahash square.DataHash) error { return nil } -func (s *Store) RemoveQ4(ctx context.Context, height uint64, datahash square.DataHash) error { +func (s *Store) RemoveQ4(ctx context.Context, height uint64, datahash share.DataHash) error { lock := s.stripLock.byHashAndHeight(datahash, height) lock.lock() defer lock.unlock() @@ -486,7 +486,7 @@ func (s *Store) RemoveQ4(ctx context.Context, height uint64, datahash square.Dat return err } -func (s *Store) removeQ4(height uint64, datahash square.DataHash) error { +func (s *Store) removeQ4(height uint64, datahash share.DataHash) error { // if datahash is empty, we don't need to remove the Q4 file if datahash.IsEmptyEDS() { return nil @@ -504,7 +504,7 @@ func (s *Store) removeQ4(height uint64, datahash square.DataHash) error { return nil } -func (s *Store) hashToPath(datahash square.DataHash, ext string) string { +func (s *Store) hashToPath(datahash share.DataHash, ext string) string { return filepath.Join(s.basepath, blocksPath, datahash.String()) + ext } diff --git a/store/store_cache.go b/store/store_cache.go index a9d5e4882d..9e552312fd 100644 --- a/store/store_cache.go +++ b/store/store_cache.go @@ -4,7 +4,7 @@ import ( "context" "fmt" - "github.com/celestiaorg/celestia-node/square/eds" + "github.com/celestiaorg/celestia-node/share/eds" "github.com/celestiaorg/celestia-node/store/cache" ) diff --git a/store/store_test.go b/store/store_test.go index 45c9bcdede..dbf44928a2 100644 --- a/store/store_test.go +++ b/store/store_test.go @@ -10,11 +10,11 @@ import ( "github.com/stretchr/testify/require" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/square" - "github.com/celestiaorg/celestia-node/square/eds/edstest" + "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/share/eds/edstest" "github.com/celestiaorg/celestia-node/store/cache" "github.com/celestiaorg/celestia-node/store/file" ) @@ -426,7 +426,7 @@ func BenchmarkStore(b *testing.B) { b.Cleanup(cancel) eds := edstest.RandEDS(b, 128) - roots, err := square.NewAxisRoots(eds) + roots, err := share.NewAxisRoots(eds) require.NoError(b, err) // BenchmarkStore/put_128-16 186 6623266 ns/op @@ -477,9 +477,9 @@ func BenchmarkStore(b *testing.B) { }) } -func randomEDS(t testing.TB) (*rsmt2d.ExtendedDataSquare, *square.AxisRoots) { +func randomEDS(t testing.TB) (*rsmt2d.ExtendedDataSquare, *share.AxisRoots) { eds := edstest.RandEDS(t, 4) - roots, err := square.NewAxisRoots(eds) + roots, err := share.NewAxisRoots(eds) require.NoError(t, err) return eds, roots @@ -512,7 +512,7 @@ func hasByHashAndHeight( t testing.TB, store *Store, ctx context.Context, - hash square.DataHash, + hash share.DataHash, height uint64, hasByHash, hasByHeight bool, ) { diff --git a/store/striplock.go b/store/striplock.go index eb23facab2..4738453c77 100644 --- a/store/striplock.go +++ b/store/striplock.go @@ -3,7 +3,7 @@ package store import ( "sync" - "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/share" ) // TODO: move to utils @@ -31,14 +31,14 @@ func (l *striplock) byHeight(height uint64) *sync.RWMutex { return l.heights[lkIdx] } -func (l *striplock) byHash(datahash square.DataHash) *sync.RWMutex { +func (l *striplock) byHash(datahash share.DataHash) *sync.RWMutex { // Use the last 2 bytes of the hash as key to distribute the locks last := uint16(datahash[len(datahash)-1]) | uint16(datahash[len(datahash)-2])<<8 lkIdx := last % uint16(len(l.datahashes)) return l.datahashes[lkIdx] } -func (l *striplock) byHashAndHeight(datahash square.DataHash, height uint64) *multiLock { +func (l *striplock) byHashAndHeight(datahash share.DataHash, height uint64) *multiLock { return &multiLock{[]*sync.RWMutex{l.byHash(datahash), l.byHeight(height)}} } From 27f4540e7fa21c5ddc0ea8adf2519594f884986a Mon Sep 17 00:00:00 2001 From: vgonkivs Date: Mon, 7 Oct 2024 16:23:55 +0300 Subject: [PATCH 05/21] bump go-square v2 --- go.mod | 2 +- go.sum | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 4c091a9dc0..19f05e3601 100644 --- a/go.mod +++ b/go.mod @@ -343,7 +343,7 @@ require ( ) replace ( - github.com/celestiaorg/go-square/v2 v2.0.0 => ../go-square + github.com/celestiaorg/go-square/v2 v2.0.0 => github.com/celestiaorg/go-square/v2 v2.0.1-0.20241007123147-1359db0f487c github.com/cosmos/cosmos-sdk => github.com/celestiaorg/cosmos-sdk v1.24.1-sdk-v0.46.16 github.com/filecoin-project/dagstore => github.com/celestiaorg/dagstore v0.0.0-20230824094345-537c012aa403 github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1 diff --git a/go.sum b/go.sum index d54552c19c..fbf9b4359e 100644 --- a/go.sum +++ b/go.sum @@ -361,6 +361,8 @@ github.com/celestiaorg/go-square v1.1.0 h1:K4tBL5PCJwDtpBfyDxxZ3N962aC9VYb5/bw3L github.com/celestiaorg/go-square v1.1.0/go.mod h1:1EXMErhDrWJM8B8V9hN7dqJ2kUTClfwdqMOmF9yQUa0= github.com/celestiaorg/go-square/merkle v0.0.0-20240117232118-fd78256df076 h1:PYInrsYzrDIsZW9Yb86OTi2aEKuPcpgJt6Mc0Jlc/yg= github.com/celestiaorg/go-square/merkle v0.0.0-20240117232118-fd78256df076/go.mod h1:hlidgivKyvv7m4Yl2Fdf2mSTmazZYxX8+bnr5IQrI98= +github.com/celestiaorg/go-square/v2 v2.0.1-0.20241007123147-1359db0f487c h1:HOXirS9jNTqKSz/Iv7PauWuaC6Dt5RIPg95xhP2q5Mw= +github.com/celestiaorg/go-square/v2 v2.0.1-0.20241007123147-1359db0f487c/go.mod h1:y0BolG0tRM7UN1sAQyDDUkT+aMJPwFIjviVvnCB62C0= github.com/celestiaorg/merkletree v0.0.0-20230308153949-c33506a7aa26 h1:P2RI1xJ49EZ8cuHMcH+ZSBonfRDtBS8OS9Jdt1BWX3k= github.com/celestiaorg/merkletree v0.0.0-20230308153949-c33506a7aa26/go.mod h1:2m8ukndOegwB0PU0AfJCwDUQHqd7QQRlSXvQL5VToVY= github.com/celestiaorg/nmt v0.22.1 h1:t7fqoP5MJ8mBns5DB2XjfcPxQpS3CKMkY+v+BEkDxYc= From 74a2f55c2a0f76121ce8d71ecaf8acf7b3c6073f Mon Sep 17 00:00:00 2001 From: vgonkivs Date: Mon, 7 Oct 2024 16:38:27 +0300 Subject: [PATCH 06/21] fix lint --- api/gateway/share.go | 6 ++- blob/helper.go | 1 - blob/service_test.go | 3 +- share/availability/full/testing.go | 11 ++-- .../p2p/shrex/shrex_getter/shrex_test.go | 48 ----------------- share/shwap/row_namespace_data_id.go | 8 ++- share/shwap/row_namespace_data_test.go | 52 +++++++++---------- 7 files changed, 44 insertions(+), 85 deletions(-) diff --git a/api/gateway/share.go b/api/gateway/share.go index 8e5b898b5a..9de2f104d9 100644 --- a/api/gateway/share.go +++ b/api/gateway/share.go @@ -88,7 +88,11 @@ func (h *Handler) handleDataByNamespaceRequest(w http.ResponseWriter, r *http.Re } } -func (h *Handler) getShares(ctx context.Context, height uint64, namespace gosquare.Namespace) ([]gosquare.Share, error) { +func (h *Handler) getShares( + ctx context.Context, + height uint64, + namespace gosquare.Namespace, +) ([]gosquare.Share, error) { header, err := h.header.GetByHeight(ctx, height) if err != nil { return nil, err diff --git a/blob/helper.go b/blob/helper.go index 076861548e..bddefdbf52 100644 --- a/blob/helper.go +++ b/blob/helper.go @@ -19,7 +19,6 @@ func BlobsToShares(nodeBlobs ...*Blob) ([]gosquare.Share, error) { if err != nil { return nil, fmt.Errorf("failed to split blob at index: %d: %w", i, err) } - } return splitter.Export(), nil } diff --git a/blob/service_test.go b/blob/service_test.go index c78b00c0fa..fe61b49c08 100644 --- a/blob/service_test.go +++ b/blob/service_test.go @@ -564,6 +564,7 @@ func TestService_GetAllWithoutPadding(t *testing.T) { rawShares = append(rawShares, append(sh, padding, padding, padding)...) sh, err = BlobsToShares(blobs[4]) + require.NoError(t, err) rawShares = append(rawShares, sh...) service := createService(ctx, t, rawShares) @@ -953,7 +954,7 @@ func proveAndVerifyShareCommitments(t *testing.T, blobSize int) { msgs, blobs, nss, eds, _, _, dataRoot := edstest.GenerateTestBlock(t, blobSize, 10) for msgIndex, msg := range msgs { t.Run(fmt.Sprintf("msgIndex=%d", msgIndex), func(t *testing.T) { - blb, err := NewBlob(uint8(blobs[msgIndex].ShareVersion()), nss[msgIndex], blobs[msgIndex].Data(), nil) + blb, err := NewBlob(blobs[msgIndex].ShareVersion(), nss[msgIndex], blobs[msgIndex].Data(), nil) require.NoError(t, err) blobShares, err := BlobsToShares(blb) require.NoError(t, err) diff --git a/share/availability/full/testing.go b/share/availability/full/testing.go index d4e7ee4f0c..b43f767c89 100644 --- a/share/availability/full/testing.go +++ b/share/availability/full/testing.go @@ -1,7 +1,6 @@ package full -// -//import ( +// import ( // "context" // // "testing" @@ -20,27 +19,27 @@ package full // //// GetterWithRandSquare provides a gosquare.Getter filled with 'n' NMT //// trees of 'n' random shares, essentially storing a whole share. -//func GetterWithRandSquare(t *testing.T, n int) (share.Getter, *share.AxisRoots) { +// func GetterWithRandSquare(t *testing.T, n int) (share.Getter, *share.AxisRoots) { // bServ := ipld.NewMemBlockservice() // getter := shwap.NewIPLDGetter(bServ) // return getter, availability_test.RandFillBS(t, n, bServ) //} // //// RandNode creates a Full Node filled with a random block of the given size. -//func RandNode(dn *availability_test.TestDagNet, squareSize int) (*availability_test.TestNode, *share.AxisRoots) { +// func RandNode(dn *availability_test.TestDagNet, squareSize int) (*availability_test.TestNode, *share.AxisRoots) { // nd := Node(dn) // return nd, availability_test.RandFillBS(dn.T, squareSize, nd.BlockService) //} // //// Node creates a new empty Full Node. -//func Node(dn *availability_test.TestDagNet) *availability_test.TestNode { +// func Node(dn *availability_test.TestDagNet) *availability_test.TestNode { // nd := dn.NewTestNode() // nd.Getter = getters.NewIPLDGetter(nd.BlockService) // nd.Availability = TestAvailability(dn.T, nd.Getter) // return nd //} // -//func TestAvailability(t *testing.T, getter share.Getter) *ShareAvailability { +// func TestAvailability(t *testing.T, getter share.Getter) *ShareAvailability { // params := discovery.DefaultParameters() // params.AdvertiseInterval = time.Second // params.PeersLimit = 10 diff --git a/share/shwap/p2p/shrex/shrex_getter/shrex_test.go b/share/shwap/p2p/shrex/shrex_getter/shrex_test.go index 167a0b40a1..10e151fe6f 100644 --- a/share/shwap/p2p/shrex/shrex_getter/shrex_test.go +++ b/share/shwap/p2p/shrex/shrex_getter/shrex_test.go @@ -2,8 +2,6 @@ package shrex_getter //nolint:stylecheck // underscore in pkg name will be fixed import ( "context" - "encoding/binary" - "errors" "sync/atomic" "testing" "time" @@ -348,49 +346,3 @@ func newEDSClientServer( require.NoError(t, err) return client, server } - -// addToNamespace adds arbitrary int value to namespace, treating namespace as big-endian -// implementation of int -func addToNamespace(namespace gosquare.Namespace, val int) (gosquare.Namespace, error) { - if val == 0 { - return namespace, nil - } - // Convert the input integer to a byte slice and add it to result slice - result := make([]byte, gosquare.NamespaceSize) - if val > 0 { - binary.BigEndian.PutUint64(result[gosquare.NamespaceSize-8:], uint64(val)) - } else { - binary.BigEndian.PutUint64(result[gosquare.NamespaceSize-8:], uint64(-val)) - } - - // Perform addition byte by byte - var carry int - for i := gosquare.NamespaceSize - 1; i >= 0; i-- { - var sum int - if val > 0 { - sum = int(namespace.Bytes()[i]) + int(result[i]) + carry - } else { - sum = int(namespace.Bytes()[i]) - int(result[i]) + carry - } - - switch { - case sum > 255: - carry = 1 - sum -= 256 - case sum < 0: - carry = -1 - sum += 256 - default: - carry = 0 - } - - result[i] = uint8(sum) - } - - // Handle any remaining carry - if carry != 0 { - return gosquare.Namespace{}, errors.New("namespace overflow") - } - - return gosquare.NewNamespaceFromBytes(result) -} diff --git a/share/shwap/row_namespace_data_id.go b/share/shwap/row_namespace_data_id.go index f0f20e58b9..c9c8050b6c 100644 --- a/share/shwap/row_namespace_data_id.go +++ b/share/shwap/row_namespace_data_id.go @@ -14,8 +14,9 @@ const RowNamespaceDataIDSize = RowIDSize + gosquare.NamespaceSize // RowNamespaceDataID uniquely identifies a piece of namespaced data within a row of an Extended // Data Square (EDS). type RowNamespaceDataID struct { - RowID // Embedded RowID representing the specific row in the EDS. - DataNamespace gosquare.Namespace // DataNamespace is a string representation of the namespace to facilitate comparisons. + RowID // Embedded RowID representing the specific row in the EDS. + // DataNamespace is a string representation of the namespace to facilitate comparisons. + DataNamespace gosquare.Namespace } // NewRowNamespaceDataID creates a new RowNamespaceDataID with the specified parameters. It @@ -56,6 +57,9 @@ func RowNamespaceDataIDFromBinary(data []byte) (RowNamespaceDataID, error) { } ns, err := gosquare.NewNamespaceFromBytes(data[RowIDSize:]) + if err != nil { + return RowNamespaceDataID{}, fmt.Errorf("invalid namespace format: %w", err) + } rndid := RowNamespaceDataID{ RowID: rid, DataNamespace: ns, diff --git a/share/shwap/row_namespace_data_test.go b/share/shwap/row_namespace_data_test.go index ec922e98ca..b0c9110347 100644 --- a/share/shwap/row_namespace_data_test.go +++ b/share/shwap/row_namespace_data_test.go @@ -40,12 +40,12 @@ func TestNamespacedRowFromShares(t *testing.T) { } } -//func TestNamespacedRowFromSharesNonIncluded(t *testing.T) { -// // TODO: this will fail until absence proof support is added +// func TestNamespacedRowFromSharesNonIncluded(t *testing.T) { +// //TODO: this will fail until absence proof support is added // t.Skip() // // const odsSize = 8 -// // Test absent namespace +// //Test absent namespace // shares := gosquare.RandShares( odsSize) // absentNs, err := share.GetNamespace(shares[0]).AddInt(1) // require.NoError(t, err) @@ -63,29 +63,29 @@ func TestNamespacedRowFromShares(t *testing.T) { // require.True(t, nr.Proof.IsOfAbsence()) //} -//func TestValidateNamespacedRow(t *testing.T) { -// ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) -// t.Cleanup(cancel) -// -// const odsSize = 8 -// sharesAmount := odsSize * odsSize -// namespace := sharetest.RandV0Namespace() -// for amount := 1; amount < sharesAmount; amount++ { -// randEDS, root := edstest.RandEDSWithNamespace(t, namespace, amount, odsSize) -// rsmt2d := &eds.Rsmt2D{ExtendedDataSquare: randEDS} -// nd, err := eds.NamespaceData(ctx, rsmt2d, namespace) -// require.NoError(t, err) -// require.True(t, len(nd) > 0) -// -// rowIdxs := share.RowsWithNamespace(root, namespace) -// require.Len(t, nd, len(rowIdxs)) -// -// for i, rowIdx := range rowIdxs { -// err = nd[i].Verify(root, namespace, rowIdx) -// require.NoError(t, err) -// } -// } -//} +func TestValidateNamespacedRow(t *testing.T) { + ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) + t.Cleanup(cancel) + + const odsSize = 8 + sharesAmount := odsSize * odsSize + namespace := gosquare.RandomNamespace() + for amount := 1; amount < sharesAmount; amount++ { + randEDS, root := edstest.RandEDSWithNamespace(t, namespace, amount, odsSize) + rsmt2d := &eds.Rsmt2D{ExtendedDataSquare: randEDS} + nd, err := eds.NamespaceData(ctx, rsmt2d, namespace) + require.NoError(t, err) + require.True(t, len(nd) > 0) + + rowIdxs := share.RowsWithNamespace(root, namespace) + require.Len(t, nd, len(rowIdxs)) + + for i, rowIdx := range rowIdxs { + err = nd[i].Verify(root, namespace, rowIdx) + require.NoError(t, err) + } + } +} func TestNamespacedRowProtoEncoding(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) From 4cb3dcb4cc720134c78ef91db9c83e6291b7dbee Mon Sep 17 00:00:00 2001 From: vgonkivs Date: Thu, 10 Oct 2024 12:39:06 +0300 Subject: [PATCH 07/21] bump app to the alpha version --- go.mod | 13 +++++++------ go.sum | 44 ++++++++++++++++++++------------------------ 2 files changed, 27 insertions(+), 30 deletions(-) diff --git a/go.mod b/go.mod index 19f05e3601..bea5484afa 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/BurntSushi/toml v1.4.1-0.20240526193622-a339e1f7089c github.com/alecthomas/jsonschema v0.0.0-20220216202328-9eeeec9d044b github.com/benbjohnson/clock v1.3.5 - github.com/celestiaorg/celestia-app/v3 v3.0.0-20241003134616-c713401b0f69 + github.com/celestiaorg/celestia-app/v3 v3.0.0-alpha github.com/celestiaorg/go-fraud v0.2.1 github.com/celestiaorg/go-header v0.6.2 github.com/celestiaorg/go-libp2p-messenger v0.2.0 @@ -75,7 +75,7 @@ require ( golang.org/x/exp v0.0.0-20240904232852-e7e105dedf7e golang.org/x/sync v0.8.0 golang.org/x/text v0.18.0 - google.golang.org/grpc v1.67.0 + google.golang.org/grpc v1.67.1 google.golang.org/protobuf v1.35.1 ) @@ -100,7 +100,6 @@ require ( github.com/bgentry/speakeasy v0.1.0 // indirect github.com/bits-and-blooms/bitset v1.13.0 // indirect github.com/btcsuite/btcd/btcec/v2 v2.3.4 // indirect - github.com/bufbuild/protocompile v0.14.1 // indirect github.com/celestiaorg/blobstream-contracts/v3 v3.1.0 // indirect github.com/celestiaorg/merkletree v0.0.0-20230308153949-c33506a7aa26 // indirect github.com/cenkalti/backoff/v4 v4.3.0 // indirect @@ -124,6 +123,7 @@ require ( github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v6 v6.1.2 // indirect github.com/cosmos/ibc-go/v6 v6.3.0 // indirect github.com/cosmos/ledger-cosmos-go v0.13.2 // indirect + github.com/crate-crypto/go-ipa v0.0.0-20240223125850-b1e8a79f509c // indirect github.com/crate-crypto/go-kzg-4844 v1.0.0 // indirect github.com/creachadair/taskgroup v0.3.2 // indirect github.com/cskr/pubsub v1.0.2 // indirect @@ -143,7 +143,8 @@ require ( github.com/elastic/gosigar v0.14.3 // indirect github.com/etclabscore/go-jsonschema-walk v0.0.6 // indirect github.com/ethereum/c-kzg-4844 v1.0.0 // indirect - github.com/ethereum/go-ethereum v1.14.7 // indirect + github.com/ethereum/go-ethereum v1.14.11 // indirect + github.com/ethereum/go-verkle v0.1.1-0.20240829091221-dffa7562dbe9 // indirect github.com/felixge/httpsnoop v1.0.4 // indirect github.com/flynn/noise v1.1.0 // indirect github.com/francoispqt/gojay v1.2.13 // indirect @@ -197,7 +198,7 @@ require ( github.com/hashicorp/golang-lru/arc/v2 v2.0.7 // indirect github.com/hashicorp/hcl v1.0.0 // indirect github.com/hdevalence/ed25519consensus v0.0.0-20220222234857-c00d1f31bab3 // indirect - github.com/holiman/uint256 v1.3.0 // indirect + github.com/holiman/uint256 v1.3.1 // indirect github.com/huin/goupnp v1.3.0 // indirect github.com/iancoleman/orderedmap v0.2.0 // indirect github.com/improbable-eng/grpc-web v0.15.0 // indirect @@ -344,7 +345,7 @@ require ( replace ( github.com/celestiaorg/go-square/v2 v2.0.0 => github.com/celestiaorg/go-square/v2 v2.0.1-0.20241007123147-1359db0f487c - github.com/cosmos/cosmos-sdk => github.com/celestiaorg/cosmos-sdk v1.24.1-sdk-v0.46.16 + github.com/cosmos/cosmos-sdk => github.com/celestiaorg/cosmos-sdk v1.25.0-sdk-v0.46.16 github.com/filecoin-project/dagstore => github.com/celestiaorg/dagstore v0.0.0-20230824094345-537c012aa403 github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1 // broken goleveldb needs to be replaced for the cosmos-sdk and celestia-app diff --git a/go.sum b/go.sum index fbf9b4359e..e5d95552b5 100644 --- a/go.sum +++ b/go.sum @@ -345,12 +345,12 @@ github.com/c-bata/go-prompt v0.2.2/go.mod h1:VzqtzE2ksDBcdln8G7mk2RX9QyGjH+OVqOC github.com/casbin/casbin/v2 v2.1.2/go.mod h1:YcPU1XXisHhLzuxH9coDNf2FbKpjGlbCg3n9yuLkIJQ= github.com/celestiaorg/blobstream-contracts/v3 v3.1.0 h1:h1Y4V3EMQ2mFmNtWt2sIhZIuyASInj1a9ExI8xOsTOw= github.com/celestiaorg/blobstream-contracts/v3 v3.1.0/go.mod h1:x4DKyfKOSv1ZJM9NwV+Pw01kH2CD7N5zTFclXIVJ6GQ= -github.com/celestiaorg/celestia-app/v3 v3.0.0-20241003134616-c713401b0f69 h1:9myDWDouFiGMU0QY7wrIksanHNn8o7FLWDO0PwsOTAo= -github.com/celestiaorg/celestia-app/v3 v3.0.0-20241003134616-c713401b0f69/go.mod h1:OPcaIRGQ5Ke3btFSbfBeGNsh5ZXNUpLs4fcOGUFQaSo= +github.com/celestiaorg/celestia-app/v3 v3.0.0-alpha h1:byrIhd4DJvNeayhs3zuHxpDO5AdM3WX5Wlp2sNO+OBo= +github.com/celestiaorg/celestia-app/v3 v3.0.0-alpha/go.mod h1:Tohj2wSurPa7rVqzC/nvhxMs7GvXKzYiy03cuuGpPIo= github.com/celestiaorg/celestia-core v1.42.0-tm-v0.34.35 h1:bWy5XOgeuuSLe0Lc/htL9/QLEURBjA1JTvEko6bEBhg= github.com/celestiaorg/celestia-core v1.42.0-tm-v0.34.35/go.mod h1:/fK0n3ps09t5uErBQe1QZbrE81L81MNUzWpFyWQLDT0= -github.com/celestiaorg/cosmos-sdk v1.24.1-sdk-v0.46.16 h1:SeQ7Y/CyOcUMKo7mQiexaj/pZ/xIgyuZFIwYZwpSkWE= -github.com/celestiaorg/cosmos-sdk v1.24.1-sdk-v0.46.16/go.mod h1:Bpl1LSWiDpQumgOhhMTZBMopqa0j7fRasIhvTZB44P0= +github.com/celestiaorg/cosmos-sdk v1.25.0-sdk-v0.46.16 h1:f+fTe7GGk0/qgdzyqB8kk8EcDf9d6MC22khBTQiDXsU= +github.com/celestiaorg/cosmos-sdk v1.25.0-sdk-v0.46.16/go.mod h1:07Z8HJqS8Rw4XlZ+ok3D3NM/X/in8mvcGLvl0Zb5wrA= github.com/celestiaorg/go-fraud v0.2.1 h1:oYhxI0gM/EpGRgbVQdRI/LSlqyT65g/WhQGSVGfx09w= github.com/celestiaorg/go-fraud v0.2.1/go.mod h1:lNY1i4K6kUeeE60Z2VK8WXd+qXb8KRzfBhvwPkK6aUc= github.com/celestiaorg/go-header v0.6.2 h1:qgWyJQg+/x6k4QAfN1rPt2HXHZjQOmCqD0ct4dFBIZY= @@ -420,8 +420,8 @@ github.com/cockroachdb/fifo v0.0.0-20240606204812-0bbfbd93a7ce h1:giXvy4KSc/6g/e github.com/cockroachdb/fifo v0.0.0-20240606204812-0bbfbd93a7ce/go.mod h1:9/y3cnZ5GKakj/H4y9r9GTjCvAFta7KLgSHPJJYc52M= github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b h1:r6VH0faHjZeQy818SGhaone5OnYfxFR/+AzdY3sf5aE= github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b/go.mod h1:Vz9DsVWQQhf3vs21MhPMZpMGSht7O/2vFW2xusFUVOs= -github.com/cockroachdb/pebble v1.1.1 h1:XnKU22oiCLy2Xn8vp1re67cXg4SAasg/WDt1NtcRFaw= -github.com/cockroachdb/pebble v1.1.1/go.mod h1:4exszw1r40423ZsmkG/09AFEG83I0uDgfujJdbL6kYU= +github.com/cockroachdb/pebble v1.1.2 h1:CUh2IPtR4swHlEj48Rhfzw6l/d0qA31fItcIszQVIsA= +github.com/cockroachdb/pebble v1.1.2/go.mod h1:4exszw1r40423ZsmkG/09AFEG83I0uDgfujJdbL6kYU= github.com/cockroachdb/redact v1.1.5 h1:u1PMllDkdFfPWaNGMyLD1+so+aq3uUItthCFqzwPJ30= github.com/cockroachdb/redact v1.1.5/go.mod h1:BVNblN9mBWFyMyqK1k3AAiSxhvhfK2oOZZ2lK+dpvRg= github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 h1:zuQyyAKVxetITBuuhv3BI9cMrmStnpT18zmgmTxunpo= @@ -585,10 +585,10 @@ github.com/etclabscore/go-openrpc-reflect v0.0.37/go.mod h1:0404Ky3igAasAOpyj1eE github.com/ethereum/c-kzg-4844 v1.0.0 h1:0X1LBXxaEtYD9xsyj9B9ctQEZIpnvVDeoBx8aHEwTNA= github.com/ethereum/c-kzg-4844 v1.0.0/go.mod h1:VewdlzQmpT5QSrVhbBuGoCdFJkpaJlO1aQputP83wc0= github.com/ethereum/go-ethereum v1.10.17/go.mod h1:Lt5WzjM07XlXc95YzrhosmR4J9Ahd6X2wyEV2SvGhk0= -github.com/ethereum/go-ethereum v1.14.7 h1:EHpv3dE8evQmpVEQ/Ne2ahB06n2mQptdwqaMNhAT29g= -github.com/ethereum/go-ethereum v1.14.7/go.mod h1:Mq0biU2jbdmKSZoqOj29017ygFrMnB5/Rifwp980W4o= -github.com/ethereum/go-verkle v0.1.1-0.20240306133620-7d920df305f0 h1:KrE8I4reeVvf7C1tm8elRjj4BdscTYzz/WAbYyf/JI4= -github.com/ethereum/go-verkle v0.1.1-0.20240306133620-7d920df305f0/go.mod h1:D9AJLVXSyZQXJQVk8oh1EwjISE+sJTn2duYIZC0dy3w= +github.com/ethereum/go-ethereum v1.14.11 h1:8nFDCUUE67rPc6AKxFj7JKaOa2W/W1Rse3oS6LvvxEY= +github.com/ethereum/go-ethereum v1.14.11/go.mod h1:+l/fr42Mma+xBnhefL/+z11/hcmJ2egl+ScIVPjhc7E= +github.com/ethereum/go-verkle v0.1.1-0.20240829091221-dffa7562dbe9 h1:8NfxH2iXvJ60YRB8ChToFTUzl8awsc3cJ8CbLjGIl/A= +github.com/ethereum/go-verkle v0.1.1-0.20240829091221-dffa7562dbe9/go.mod h1:M3b90YRnzqKyyzBEWJGqj8Qff4IDeXnzFw0P9bFw3uk= github.com/facebookgo/ensure v0.0.0-20200202191622-63f1cf65ac4c h1:8ISkoahWXwZR41ois5lSJBSVw4D0OV19Ht/JSTzvSv0= github.com/facebookgo/ensure v0.0.0-20200202191622-63f1cf65ac4c/go.mod h1:Yg+htXGokKKdzcwhuNDwVvN+uBxDGXJ7G/VN1d8fa64= github.com/facebookgo/stack v0.0.0-20160209184415-751773369052 h1:JWuenKqqX8nojtoVVWjGfOF9635RETekkoH6Cc9SX0A= @@ -604,8 +604,6 @@ github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSw github.com/filecoin-project/go-jsonrpc v0.6.0 h1:/fFJIAN/k6EgY90m7qbyfY28woMwyseZmh2gVs5sYjY= github.com/filecoin-project/go-jsonrpc v0.6.0/go.mod h1:/n/niXcS4ZQua6i37LcVbY1TmlJR0UIK9mDFQq2ICek= github.com/fjl/memsize v0.0.0-20190710130421-bcb5799ab5e5/go.mod h1:VvhXpOYNQvB+uIk2RvXzuaQtkQJzzIx6lSBe1xv7hi0= -github.com/fjl/memsize v0.0.2 h1:27txuSD9or+NZlnOWdKUxeBzTAUkWCVh+4Gf2dWFOzA= -github.com/fjl/memsize v0.0.2/go.mod h1:VvhXpOYNQvB+uIk2RvXzuaQtkQJzzIx6lSBe1xv7hi0= github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc= github.com/flynn/noise v1.0.0/go.mod h1:xbMo+0i6+IGbYdJhF31t2eR1BIU0CYc12+BNAKwUTag= github.com/flynn/noise v1.1.0 h1:KjPQoQCEFdZDiP03phOvGi11+SVVhBG2wOWAorLsstg= @@ -936,9 +934,8 @@ github.com/hashicorp/go-safetemp v1.0.0/go.mod h1:oaerMy3BhqiTbVye6QuFhFtIceqFoD github.com/hashicorp/go-sockaddr v1.0.0/go.mod h1:7Xibr9yA9JjQq1JpNB2Vw7kxv8xerXegt+ozgdvDeDU= github.com/hashicorp/go-syslog v1.0.0/go.mod h1:qPfqrKkXGihmCqbJM2mZgkZGvKG1dFdvsLplgctolz4= github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= +github.com/hashicorp/go-uuid v1.0.1 h1:fv1ep09latC32wFoVwnqcnKJGnMSdBanPczbHAYm1BE= github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= -github.com/hashicorp/go-uuid v1.0.2 h1:cfejS+Tpcp13yd5nYHWDI6qVCny6wyX2Mt5SGur2IGE= -github.com/hashicorp/go-uuid v1.0.2/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= github.com/hashicorp/go-version v1.2.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= github.com/hashicorp/go-version v1.6.0 h1:feTTfFNnjP967rlCxM/I9g701jU+RN74YKx2mOkIeek= github.com/hashicorp/go-version v1.6.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= @@ -966,8 +963,8 @@ github.com/holiman/billy v0.0.0-20240216141850-2abb0c79d3c4/go.mod h1:5GuXa7vkL8 github.com/holiman/bloomfilter/v2 v2.0.3 h1:73e0e/V0tCydx14a0SCYS/EWCxgwLZ18CZcZKVu0fao= github.com/holiman/bloomfilter/v2 v2.0.3/go.mod h1:zpoh+gs7qcpqrHr3dB55AMiJwo0iURXE7ZOP9L9hSkA= github.com/holiman/uint256 v1.2.0/go.mod h1:y4ga/t+u+Xwd7CpDgZESaRcWy0I7XMlTMA25ApIH5Jw= -github.com/holiman/uint256 v1.3.0 h1:4wdcm/tnd0xXdu7iS3ruNvxkWwrb4aeBQv19ayYn8F4= -github.com/holiman/uint256 v1.3.0/go.mod h1:EOMSn4q6Nyt9P6efbI3bueV4e1b3dGlUCXeiRV4ng7E= +github.com/holiman/uint256 v1.3.1 h1:JfTzmih28bittyHM8z360dCjIA9dbPIBlcTI6lmctQs= +github.com/holiman/uint256 v1.3.1/go.mod h1:EOMSn4q6Nyt9P6efbI3bueV4e1b3dGlUCXeiRV4ng7E= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/hudl/fargo v1.3.0/go.mod h1:y3CKSmjA+wD2gak7sUSXTAoopbhU08POFhmITJgmKTg= github.com/huin/goupnp v1.0.0/go.mod h1:n9v9KO1tAxYH82qOn+UTIFQDmx5n1Zxd/ClZDMX7Bnc= @@ -1328,8 +1325,8 @@ github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzp github.com/mattn/go-runewidth v0.0.3/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= -github.com/mattn/go-runewidth v0.0.14 h1:+xnbZSEeDbOIg5/mE6JF0w6n9duR1l3/WmbinWVwUuU= -github.com/mattn/go-runewidth v0.0.14/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= +github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU= +github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= github.com/mattn/go-sqlite3 v1.11.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc= github.com/mattn/go-tty v0.0.0-20180907095812-13ff1204f104/go.mod h1:XPvLUNfbS4fJH25nqRHfWLMa1ONC8Amw+mIA639KxkE= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= @@ -1672,8 +1669,8 @@ github.com/regen-network/cosmos-proto v0.3.1/go.mod h1:jO0sVX6a1B36nmE8C9xBFXpNw github.com/regen-network/protobuf v1.3.3-alpha.regen.1 h1:OHEc+q5iIAXpqiqFKeLpu5NwTIkVXUs48vFMwzqpqY4= github.com/regen-network/protobuf v1.3.3-alpha.regen.1/go.mod h1:2DjTFR1HhMQhiWC5sZ4OhQ3+NtdbZ6oBDKQwq5Ou+FI= github.com/retailnext/hllpp v1.0.1-0.20180308014038-101a6d2f8b52/go.mod h1:RDpi1RftBQPUCDRw6SmxeaREsAaRKnOclghuzp/WRzc= -github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis= -github.com/rivo/uniseg v0.4.4/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= +github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY= +github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rjeczalik/notify v0.9.1/go.mod h1:rKwnCoCGeuQnwBtTSPL9Dad03Vh2n40ePRrjvIXnJho= github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= @@ -2683,8 +2680,8 @@ google.golang.org/grpc v1.48.0/go.mod h1:vN9eftEi1UMyUsIF80+uQXhHjbXYbm0uXoFCACu google.golang.org/grpc v1.49.0/go.mod h1:ZgQEeidpAuNRZ8iRrlBKXZQP1ghovWIVhdJRyCDK+GI= google.golang.org/grpc v1.50.0/go.mod h1:ZgQEeidpAuNRZ8iRrlBKXZQP1ghovWIVhdJRyCDK+GI= google.golang.org/grpc v1.50.1/go.mod h1:ZgQEeidpAuNRZ8iRrlBKXZQP1ghovWIVhdJRyCDK+GI= -google.golang.org/grpc v1.67.0 h1:IdH9y6PF5MPSdAntIcpjQ+tXO41pcQsfZV2RxtQgVcw= -google.golang.org/grpc v1.67.0/go.mod h1:1gLDyUQU7CTLJI90u3nXZ9ekeghjeM7pTDZlqFNg2AA= +google.golang.org/grpc v1.67.1 h1:zWnc1Vrcno+lHZCOofnIMvycFcc0QRGIzm9dhnDX68E= +google.golang.org/grpc v1.67.1/go.mod h1:1gLDyUQU7CTLJI90u3nXZ9ekeghjeM7pTDZlqFNg2AA= google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.1.0/go.mod h1:6Kw0yEErY5E/yWrBtf03jp27GLLJujG4z/JK95pnjjw= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= @@ -2701,8 +2698,7 @@ google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQ google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= -google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg= -google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw= +google.golang.org/protobuf v1.35.1 h1:m3LfL6/Ca+fqnjnlqQXNpFPABW1UD7mjh8KO2mKFytA= google.golang.org/protobuf v1.35.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= From ecfa59629ee1053df13d5b9cb2c0f4e9bc43e3d6 Mon Sep 17 00:00:00 2001 From: Viacheslav Date: Fri, 11 Oct 2024 13:51:43 +0300 Subject: [PATCH 08/21] apply suggestions Co-authored-by: Rootul P --- blob/blob.go | 6 +++--- blob/commitment_proof.go | 2 +- nodebuilder/store.go | 2 +- nodebuilder/tests/blob_test.go | 2 +- share/availability/full/availability.go | 2 +- share/availability/light/sample.go | 2 +- share/availability/light/testing.go | 2 +- share/eds/byzantine/bad_encoding.go | 2 +- share/eds/byzantine/share_proof.go | 2 +- share/eds/edstest/testing.go | 2 +- share/eds/proofs_cache.go | 2 +- share/eds/retriever.go | 4 ++-- share/eds/retriever_quadrant.go | 2 +- share/eds/rsmt2d.go | 2 +- share/empty.go | 2 +- share/root.go | 4 ++-- share/shwap/eds.go | 2 +- share/shwap/p2p/shrex/doc.go | 2 +- share/shwap/p2p/shrex/shrexeds/doc.go | 2 +- share/shwap/p2p/shrex/shrexsub/doc.go | 2 +- 20 files changed, 24 insertions(+), 24 deletions(-) diff --git a/blob/blob.go b/blob/blob.go index dbf9e7475e..0debff3294 100644 --- a/blob/blob.go +++ b/blob/blob.go @@ -74,13 +74,13 @@ func NewBlobV0(namespace gosquare.Namespace, data []byte) (*Blob, error) { return NewBlob(gosquare.ShareVersionZero, namespace, data, nil) } -// NewBlobV1 constructs a new blob from the provided Namespace and data. -// The blob will be formatted as v0 shares. +// NewBlobV1 constructs a new blob from the provided Namespace, data, and signer. +// The blob will be formatted as v1 shares. func NewBlobV1(namespace gosquare.Namespace, data, signer []byte) (*Blob, error) { return NewBlob(gosquare.ShareVersionOne, namespace, data, signer) } -// NewBlob constructs a new blob from the provided Namespace, data and share version. +// NewBlob constructs a new blob from the provided Namespace, data, signer, and share version. func NewBlob(shareVersion uint8, namespace gosquare.Namespace, data, signer []byte) (*Blob, error) { if len(data) == 0 || len(data) > appconsts.DefaultMaxBytes { return nil, fmt.Errorf("blob data must be > 0 && <= %d, but it was %d bytes", appconsts.DefaultMaxBytes, len(data)) diff --git a/blob/commitment_proof.go b/blob/commitment_proof.go index 68fbc33c28..fd9a758989 100644 --- a/blob/commitment_proof.go +++ b/blob/commitment_proof.go @@ -81,7 +81,7 @@ func (commitmentProof *CommitmentProof) Validate() error { } // Verify verifies that a commitment proof is valid, i.e., the subtree roots commit -// to some data that was posted to a share. +// to some data that was posted to a square. // Expects the commitment proof to be properly formulated and validated // using the Validate() function. func (commitmentProof *CommitmentProof) Verify(root []byte, subtreeRootThreshold int) (bool, error) { diff --git a/nodebuilder/store.go b/nodebuilder/store.go index 61048c41b3..dbd323d1ba 100644 --- a/nodebuilder/store.go +++ b/nodebuilder/store.go @@ -276,7 +276,7 @@ func dataPath(base string) string { func constraintBadgerConfig() *dsbadger.Options { opts := dsbadger.DefaultOptions // this must be copied // ValueLog: - // 2mib default => gosquare.Size - makes sure headers and samples are stored in value log + // 2mib default => gosquare.ShareSize - makes sure headers and samples are stored in value log // This *tremendously* reduces the amount of memory used by the node, up to 10 times less during // compaction opts.ValueThreshold = gosquare.ShareSize diff --git a/nodebuilder/tests/blob_test.go b/nodebuilder/tests/blob_test.go index ba949a7aa4..4d39588b0f 100644 --- a/nodebuilder/tests/blob_test.go +++ b/nodebuilder/tests/blob_test.go @@ -201,7 +201,7 @@ func TestBlobModule(t *testing.T) { } } -// convert converts a squareblob.Blob to a blob.Blob. +// convert converts a gosquare.Blob to a blob.Blob. // convert may be deduplicated with convertBlobs from the blob package. func convert(squareBlob *gosquare.Blob) (nodeBlob *blob.Blob, err error) { return blob.NewBlob(squareBlob.ShareVersion(), squareBlob.Namespace(), squareBlob.Data(), squareBlob.Signer()) diff --git a/share/availability/full/availability.go b/share/availability/full/availability.go index 32d889ff67..91550849c8 100644 --- a/share/availability/full/availability.go +++ b/share/availability/full/availability.go @@ -20,7 +20,7 @@ var log = logging.Logger("share/full") // ShareAvailability implements share.Availability using the full data square // recovery technique. It is considered "full" because it is required -// to download enough shares to fully reconstruct the data share. +// to download enough shares to fully reconstruct the data square. type ShareAvailability struct { store *store.Store getter shwap.Getter diff --git a/share/availability/light/sample.go b/share/availability/light/sample.go index c3021b2e1f..c8061cdb1e 100644 --- a/share/availability/light/sample.go +++ b/share/availability/light/sample.go @@ -8,7 +8,7 @@ import ( "math/big" ) -// Sample is a point in 2D space over share. +// Sample is a point in 2D space over square. type Sample struct { Row, Col uint16 } diff --git a/share/availability/light/testing.go b/share/availability/light/testing.go index a777a6ac9e..8f48c98716 100644 --- a/share/availability/light/testing.go +++ b/share/availability/light/testing.go @@ -20,7 +20,7 @@ package light //) // //// GetterWithRandSquare provides a gosquare.Getter filled with 'n' NMT trees of 'n' random shares, -//// essentially storing a whole share. +//// essentially storing a whole square. // func GetterWithRandSquare(t *testing.T, n int) (gosquare.Getter, *header.ExtendedHeader) { // bServ := ipld.NewMemBlockservice() // getter := getters.NewIPLDGetter(bServ) diff --git a/share/eds/byzantine/bad_encoding.go b/share/eds/byzantine/bad_encoding.go index 8b4586d83c..ab07c335e4 100644 --- a/share/eds/byzantine/bad_encoding.go +++ b/share/eds/byzantine/bad_encoding.go @@ -152,7 +152,7 @@ func (p *BadEncodingProof) Validate(hdr *header.ExtendedHeader) error { // Since p.Shares should contain all the shares from either a row or a // column, it should exactly match the number of row roots. In this // context, the number of row roots is the width of the extended data - // share. + // square. log.Infof("%s: %s (%d >= %d)", invalidProofPrefix, errIncorrectAmountOfShares, int(p.Index), width, ) diff --git a/share/eds/byzantine/share_proof.go b/share/eds/byzantine/share_proof.go index 51cf4b9793..b3b0a94cac 100644 --- a/share/eds/byzantine/share_proof.go +++ b/share/eds/byzantine/share_proof.go @@ -70,7 +70,7 @@ func (s *ShareWithProof) ShareWithProofToProto() *pb.Share { } } -// GetShareWithProof attempts to get a share with proof for the given gosquare. It first tries to get +// GetShareWithProof attempts to get a share with proof for the given share. It first tries to get // a row proof and if that fails or proof is invalid, it tries to get a column proof. func GetShareWithProof( ctx context.Context, diff --git a/share/eds/edstest/testing.go b/share/eds/edstest/testing.go index a3e84073b6..9a655819d0 100644 --- a/share/eds/edstest/testing.go +++ b/share/eds/edstest/testing.go @@ -43,7 +43,7 @@ func RandByzantineEDS(t testing.TB, odsSize int, options ...nmt.Option) *rsmt2d. return eds } -// RandEDS generates EDS filled with the random data with the given size for original share. +// RandEDS generates EDS filled with the random data with the given size for original square. func RandEDS(t testing.TB, odsSize int) *rsmt2d.ExtendedDataSquare { shares := gosquare.RandShares(odsSize * odsSize) eds, err := rsmt2d.ComputeExtendedDataSquare( diff --git a/share/eds/proofs_cache.go b/share/eds/proofs_cache.go index 32af960ff6..28b570d3a4 100644 --- a/share/eds/proofs_cache.go +++ b/share/eds/proofs_cache.go @@ -55,7 +55,7 @@ type axisWithProofs struct { // root caches the root of the tree. It will be set only when proofs are calculated root []byte // proofs are stored in a blockservice.BlockGetter by their CID. It will be set only when proofs - // are calculated and will be used to get the proof for a specific gosquare. BlockGetter is used to + // are calculated and will be used to get the proof for a specific share. BlockGetter is used to // reuse ipld based proof generation logic, which traverses the tree from the root to the leafs and // collects the nodes on the path. This is temporary and will be replaced with a more efficient // proof caching mechanism in nmt package, once it is implemented. diff --git a/share/eds/retriever.go b/share/eds/retriever.go index d8111289af..2e23029584 100644 --- a/share/eds/retriever.go +++ b/share/eds/retriever.go @@ -41,7 +41,7 @@ var ( // ---- ---- // // Retriever randomly picks one of the data square quadrants and tries to request them one by one -// until it is able to reconstruct the whole share. +// until it is able to reconstruct the whole square. type Retriever struct { bServ blockservice.BlockService } @@ -283,7 +283,7 @@ func (rs *retrievalSession) doRequest(ctx context.Context, q *quadrant) { ipld.GetShares(ctx, rs.bget, nd.Links()[q.x].Cid, size, func(j int, rawShare []byte) { // NOTE: Each share can appear twice here, for a Row and Col, respectively. // These shares are always equal, and we allow only the first one to be written - // in the share. + // in the square. // NOTE-2: We may never actually fetch shares from the network *twice*. // Once a share is downloaded from the network it may be cached on the IPLD(blockservice) level. // diff --git a/share/eds/retriever_quadrant.go b/share/eds/retriever_quadrant.go index 0b5bffb311..97a5b332f2 100644 --- a/share/eds/retriever_quadrant.go +++ b/share/eds/retriever_quadrant.go @@ -87,7 +87,7 @@ func newQuadrants(roots *share.AxisRoots) []*quadrant { return quadrants } -// pos calculates position of a share in a data share. +// pos calculates position of a share in a data square. func (q *quadrant) pos(rootIdx, cellIdx int) (int, int) { cellIdx += len(q.roots) * q.x rootIdx += len(q.roots) * q.y diff --git a/share/eds/rsmt2d.go b/share/eds/rsmt2d.go index 39e2973a38..d74a0f4f3a 100644 --- a/share/eds/rsmt2d.go +++ b/share/eds/rsmt2d.go @@ -20,7 +20,7 @@ type Rsmt2D struct { *rsmt2d.ExtendedDataSquare } -// Size returns the size of the Extended Data share. +// Size returns the size of the Extended Data square. func (eds *Rsmt2D) Size(context.Context) int { return int(eds.Width()) } diff --git a/share/empty.go b/share/empty.go index ce82915180..04bf4a5dba 100644 --- a/share/empty.go +++ b/share/empty.go @@ -22,7 +22,7 @@ func EmptyEDSRoots() *AxisRoots { return emptyBlockRoots } -// EmptyEDS returns the EDS of the empty block data share. +// EmptyEDS returns the EDS of the empty block data square. func EmptyEDS() *rsmt2d.ExtendedDataSquare { initEmpty() return emptyBlockEDS diff --git a/share/root.go b/share/root.go index b0c2357a52..7d84101b6a 100644 --- a/share/root.go +++ b/share/root.go @@ -20,7 +20,7 @@ const ( ) // AxisRoots represents root commitment to multiple Shares. -// In practice, it is a commitment to all the Data in a share. +// In practice, it is a commitment to all the Data in a square. type AxisRoots = da.DataAvailabilityHeader // DataHash is a representation of the AxisRoots hash. @@ -48,7 +48,7 @@ func NewSHA256Hasher() hash.Hash { } // NewAxisRoots generates AxisRoots(DataAvailabilityHeader) using the -// provided extended data share. +// provided extended data square. func NewAxisRoots(eds *rsmt2d.ExtendedDataSquare) (*AxisRoots, error) { dah, err := da.NewDataAvailabilityHeader(eds) if err != nil { diff --git a/share/shwap/eds.go b/share/shwap/eds.go index 8ea8665507..2d856c5317 100644 --- a/share/shwap/eds.go +++ b/share/shwap/eds.go @@ -1,6 +1,6 @@ package shwap -// EDSName is the name identifier for the Extended Data share. +// EDSName is the name identifier for the Extended Data Square. const EDSName = "eds_v0" // NOTE: There is no EDS container as it's already defined by rsmt2d and eds.Accessor interface. diff --git a/share/shwap/p2p/shrex/doc.go b/share/shwap/p2p/shrex/doc.go index fee7a07c93..9654532842 100644 --- a/share/shwap/p2p/shrex/doc.go +++ b/share/shwap/p2p/shrex/doc.go @@ -8,7 +8,7 @@ // // - shrexeds: a request/response protocol that is used to request extended data square shares from peers. // This protocol exchanges the original data square in between the client and server, and it's up to the -// receiver to compute the extended data share. +// receiver to compute the extended data square. // // This package also defines a peer manager that is used to manage network peers that can be used to exchange // shares. The peer manager is primarily responsible for providing peers to request shares from, diff --git a/share/shwap/p2p/shrex/shrexeds/doc.go b/share/shwap/p2p/shrex/shrexeds/doc.go index 8272bd8470..6bad3061f9 100644 --- a/share/shwap/p2p/shrex/shrexeds/doc.go +++ b/share/shwap/p2p/shrex/shrexeds/doc.go @@ -3,7 +3,7 @@ // // This protocol is a request/response protocol that allows for sending requests for extended data squares by data root // to the peers in the network and receiving a response containing the original data square(s), which is used -// to recompute the extended data share. +// to recompute the extended data square. // // The streams are established using the protocol ID: // diff --git a/share/shwap/p2p/shrex/shrexsub/doc.go b/share/shwap/p2p/shrex/shrexsub/doc.go index 3ca4919581..95d08361a2 100644 --- a/share/shwap/p2p/shrex/shrexsub/doc.go +++ b/share/shwap/p2p/shrex/shrexsub/doc.go @@ -28,7 +28,7 @@ // // where `notification` is of type [shrexsub.Notification]. // -// and `DataHash` is the hash of the share that you want to broadcast, and `Height` is the height of the gosquare. +// and `DataHash` is the hash of the share that you want to broadcast, and `Height` is the height of the share. // // You can also subscribe to the pubsub topic by: // From 3125e4bba8ce7e359fbdc9b25f6254921e328b47 Mon Sep 17 00:00:00 2001 From: vgonkivs Date: Fri, 11 Oct 2024 13:59:54 +0300 Subject: [PATCH 09/21] fix nits --- blob/blob.go | 4 ++-- blob/helper.go | 2 +- core/eds.go | 6 +++--- nodebuilder/tests/da_test.go | 6 +++--- nodebuilder/tests/sync_test.go | 8 ++++---- share/shwap/sample.go | 2 +- store/file/ods.go | 4 ++-- store/file/q4.go | 2 +- store/file/square.go | 2 +- 9 files changed, 18 insertions(+), 18 deletions(-) diff --git a/blob/blob.go b/blob/blob.go index 0debff3294..e33b80b20a 100644 --- a/blob/blob.go +++ b/blob/blob.go @@ -7,7 +7,7 @@ import ( "fmt" "github.com/celestiaorg/celestia-app/v3/pkg/appconsts" - app "github.com/celestiaorg/celestia-app/v3/pkg/appconsts/v2" + v3 "github.com/celestiaorg/celestia-app/v3/pkg/appconsts/v3" "github.com/celestiaorg/go-square/merkle" "github.com/celestiaorg/go-square/v2/inclusion" gosquare "github.com/celestiaorg/go-square/v2/share" @@ -15,7 +15,7 @@ import ( ) // appVersion is the current application version of celestia-app. -const appVersion = app.Version +const appVersion = v3.Version var errEmptyShares = errors.New("empty shares") diff --git a/blob/helper.go b/blob/helper.go index bddefdbf52..95229502d8 100644 --- a/blob/helper.go +++ b/blob/helper.go @@ -10,7 +10,7 @@ import ( // BlobsToShares accepts blobs and convert them to the Shares. func BlobsToShares(nodeBlobs ...*Blob) ([]gosquare.Share, error) { sort.Slice(nodeBlobs, func(i, j int) bool { - return nodeBlobs[i].Blob.Namespace().Compare(nodeBlobs[j].Blob.Namespace()) < 0 + return nodeBlobs[i].Blob.Namespace().IsLessThan(nodeBlobs[j].Blob.Namespace()) }) splitter := gosquare.NewSparseShareSplitter() diff --git a/core/eds.go b/core/eds.go index 3104b70824..8fb8989239 100644 --- a/core/eds.go +++ b/core/eds.go @@ -10,7 +10,7 @@ import ( "github.com/celestiaorg/celestia-app/v3/pkg/appconsts" "github.com/celestiaorg/celestia-app/v3/pkg/wrapper" "github.com/celestiaorg/go-square/shares" - libSquare "github.com/celestiaorg/go-square/v2" + libsquare "github.com/celestiaorg/go-square/v2" gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt" "github.com/celestiaorg/rsmt2d" @@ -31,7 +31,7 @@ func extendBlock(data types.Data, appVersion uint64, options ...nmt.Option) (*rs } // Construct the data square from the block's transactions - square, err := libSquare.Construct( + square, err := libsquare.Construct( data.Txs.ToSliceOfBytes(), appconsts.SquareSizeUpperBound(appVersion), appconsts.SubtreeRootThreshold(appVersion), @@ -49,7 +49,7 @@ func extendShares(s [][]byte, options ...nmt.Option) (*rsmt2d.ExtendedDataSquare } // here we construct a tree // Note: uses the nmt wrapper to construct the tree. - squareSize := libSquare.Size(len(s)) + squareSize := libsquare.Size(len(s)) return rsmt2d.ComputeExtendedDataSquare(s, appconsts.DefaultCodec(), wrapper.NewConstructor(uint64(squareSize), diff --git a/nodebuilder/tests/da_test.go b/nodebuilder/tests/da_test.go index 77708e7c49..54221a1048 100644 --- a/nodebuilder/tests/da_test.go +++ b/nodebuilder/tests/da_test.go @@ -143,7 +143,7 @@ func TestDaModule(t *testing.T) { { name: "SubmitWithOptions - valid", doFn: func(t *testing.T) { - ids, err := fullClient.DA.SubmitWithOptions(ctx, daBlobs, -1, namespace, []byte(`{"key_name": "validator"}`)) + ids, err := fullClient.DA.SubmitWithOptions(ctx, daBlobs, -1, namespace.Bytes(), []byte(`{"key_name": "validator"}`)) require.NoError(t, err) require.NotEmpty(t, ids) }, @@ -151,7 +151,7 @@ func TestDaModule(t *testing.T) { { name: "SubmitWithOptions - invalid JSON", doFn: func(t *testing.T) { - ids, err := fullClient.DA.SubmitWithOptions(ctx, daBlobs, -1, namespace, []byte("not JSON")) + ids, err := fullClient.DA.SubmitWithOptions(ctx, daBlobs, -1, namespace.Bytes(), []byte("not JSON")) require.Error(t, err) require.Nil(t, ids) }, @@ -159,7 +159,7 @@ func TestDaModule(t *testing.T) { { name: "SubmitWithOptions - invalid key name", doFn: func(t *testing.T) { - ids, err := fullClient.DA.SubmitWithOptions(ctx, daBlobs, -1, namespace, []byte(`{"key_name": "invalid"}`)) + ids, err := fullClient.DA.SubmitWithOptions(ctx, daBlobs, -1, namespace.Bytes(), []byte(`{"key_name": "invalid"}`)) require.Error(t, err) require.Nil(t, ids) }, diff --git a/nodebuilder/tests/sync_test.go b/nodebuilder/tests/sync_test.go index 780619146c..90baabd218 100644 --- a/nodebuilder/tests/sync_test.go +++ b/nodebuilder/tests/sync_test.go @@ -77,7 +77,7 @@ func TestSyncAgainstBridge_NonEmptyChain(t *testing.T) { assert.EqualValues(t, h.Commit.BlockID.Hash, sw.GetCoreBlockHashByHeight(ctx, numBlocks)) // check that the light node has also sampled over the block at height 20 - err = lightClient.gosquare.SharesAvailable(ctx, h) + err = lightClient.Share.SharesAvailable(ctx, h) assert.NoError(t, err) // wait until the entire chain (up to network head) has been sampled @@ -97,7 +97,7 @@ func TestSyncAgainstBridge_NonEmptyChain(t *testing.T) { assert.EqualValues(t, h.Commit.BlockID.Hash, sw.GetCoreBlockHashByHeight(ctx, numBlocks)) // check to ensure the full node can sync the 20th block's data - err = fullClient.gosquare.SharesAvailable(ctx, h) + err = fullClient.Share.SharesAvailable(ctx, h) assert.NoError(t, err) // wait for full node to sync up the blocks from genesis -> network head. @@ -167,7 +167,7 @@ func TestSyncAgainstBridge_EmptyChain(t *testing.T) { assert.EqualValues(t, h.Commit.BlockID.Hash, sw.GetCoreBlockHashByHeight(ctx, numBlocks)) // check that the light node has also sampled over the block at height 20 - err = lightClient.gosquare.SharesAvailable(ctx, h) + err = lightClient.Share.SharesAvailable(ctx, h) assert.NoError(t, err) // wait until the entire chain (up to network head) has been sampled @@ -187,7 +187,7 @@ func TestSyncAgainstBridge_EmptyChain(t *testing.T) { assert.EqualValues(t, h.Commit.BlockID.Hash, sw.GetCoreBlockHashByHeight(ctx, numBlocks)) // check to ensure the full node can sync the 20th block's data - err = fullClient.gosquare.SharesAvailable(ctx, h) + err = fullClient.Share.SharesAvailable(ctx, h) assert.NoError(t, err) // wait for full node to sync up the blocks from genesis -> network head. diff --git a/share/shwap/sample.go b/share/shwap/sample.go index dd9e7cc1f9..be200d9c13 100644 --- a/share/shwap/sample.go +++ b/share/shwap/sample.go @@ -123,7 +123,7 @@ func (s Sample) verifyInclusion(roots *share.AxisRoots, rowIdx, colIdx int) bool // inclusionNamespace returns the namespace for the share based on its position in the share. // Shares from extended part of the square are considered parity shares. It means that -// parity shares are located outside of first quadrant of the share. According to the nmt +// parity shares are located outside of first quadrant of the square. According to the nmt // specification, the parity shares are prefixed with the namespace of the parity shares. func inclusionNamespace(sh gosquare.Share, rowIdx, colIdx, squareSize int) gosquare.Namespace { isParity := colIdx >= squareSize/2 || rowIdx >= squareSize/2 diff --git a/store/file/ods.go b/store/file/ods.go index 8ee29d2af0..5623740d99 100644 --- a/store/file/ods.go +++ b/store/file/ods.go @@ -97,7 +97,7 @@ func writeODSFile(f *os.File, axisRoots *share.AxisRoots, eds *rsmt2d.ExtendedDa // writeODS writes the first quadrant(ODS) of the square to the writer. It writes the quadrant in // row-major order. Write finishes once all the shares are written or on the first instance of tail -// padding gosquare. Tail padding share are constant and aren't stored. +// padding share. Tail padding share are constant and aren't stored. func writeODS(w io.Writer, eds *rsmt2d.ExtendedDataSquare) error { for i := range eds.Width() / 2 { for j := range eds.Width() / 2 { @@ -250,7 +250,7 @@ func (o *ODS) Sample(ctx context.Context, rowIdx, colIdx int) (shwap.Sample, err // implementation. Implementations should indicate the side in the returned AxisHalf. func (o *ODS) AxisHalf(_ context.Context, axisType rsmt2d.Axis, axisIdx int) (eds.AxisHalf, error) { // Read the axis from the file if the axis is a row and from the top half of the square, or if the - // axis is a column and from the left half of the share. + // axis is a column and from the left half of the square. if axisIdx < o.size()/2 { half, err := o.readAxisHalf(axisType, axisIdx) if err != nil { diff --git a/store/file/q4.go b/store/file/q4.go index a6f848c284..7025f8adb3 100644 --- a/store/file/q4.go +++ b/store/file/q4.go @@ -12,7 +12,7 @@ import ( "github.com/celestiaorg/celestia-node/share/eds" ) -// q4 stores the fourth quadrant of the share. +// q4 stores the fourth quadrant of the square. type q4 struct { hdr *headerV0 file *os.File diff --git a/store/file/square.go b/store/file/square.go index 5e9eb53786..6c2a50ebea 100644 --- a/store/file/square.go +++ b/store/file/square.go @@ -14,7 +14,7 @@ import ( type square [][]gosquare.Share -// readSquare reads Shares from the reader and returns a share. It assumes that the reader is +// readSquare reads Shares from the reader and returns a square. It assumes that the reader is // positioned at the beginning of the Shares. It knows the size of the Shares and the size of the // square, so reads from reader are limited to exactly the amount of data required. func readSquare(r io.Reader, shareSize, edsSize int) (square, error) { From faef8cc917ab928daac3c77ca490942b5ea75fcf Mon Sep 17 00:00:00 2001 From: vgonkivs Date: Mon, 14 Oct 2024 13:37:59 +0300 Subject: [PATCH 10/21] chore: move helper functions back to the node --- blob/service.go | 3 ++- share/eds/testing.go | 2 +- share/ipld/get_shares_test.go | 4 +-- share/ipld/namespace_data.go | 11 ++++---- share/ipld/utils.go | 2 +- share/root.go | 42 ++++++++++++++++++++++++++++++- share/shwap/row_namespace_data.go | 4 +-- 7 files changed, 55 insertions(+), 13 deletions(-) diff --git a/blob/service.go b/blob/service.go index 9ccf92825a..369775d373 100644 --- a/blob/service.go +++ b/blob/service.go @@ -25,6 +25,7 @@ import ( "github.com/celestiaorg/celestia-node/header" "github.com/celestiaorg/celestia-node/libs/utils" + "github.com/celestiaorg/celestia-node/share" "github.com/celestiaorg/celestia-node/share/shwap" "github.com/celestiaorg/celestia-node/state" ) @@ -358,7 +359,7 @@ func (s *Service) retrieve( rowIndex := -1 for i, row := range header.DAH.RowRoots { - if !namespace.IsOutsideRange(row, row) { + if !share.IsOutsideRange(namespace, row, row) { rowIndex = i break } diff --git a/share/eds/testing.go b/share/eds/testing.go index b6b448a075..26c4cd0364 100644 --- a/share/eds/testing.go +++ b/share/eds/testing.go @@ -228,7 +228,7 @@ func testAccessorRowNamespaceData( rowData, err := acc.RowNamespaceData(ctx, namespace, i) // namespace is not included in the row, so there should be no shares - if namespace.IsOutsideRange(root, root) { + if share.IsOutsideRange(namespace, root, root) { require.ErrorIs(t, err, shwap.ErrNamespaceOutsideRange) require.Len(t, rowData.Shares, 0) continue diff --git a/share/ipld/get_shares_test.go b/share/ipld/get_shares_test.go index 2c17790c36..d14302634f 100644 --- a/share/ipld/get_shares_test.go +++ b/share/ipld/get_shares_test.go @@ -362,7 +362,7 @@ func TestGetSharesWithProofsByNamespace(t *testing.T) { require.NoError(t, err) for _, row := range rowRoots { rowShares, proof, err := GetSharesByNamespace(ctx, bServ, row, namespace, len(rowRoots)) - if namespace.IsOutsideRange(row, row) { + if share.IsOutsideRange(namespace, row, row) { require.ErrorIs(t, err, ErrNamespaceOutsideRange) continue } @@ -465,7 +465,7 @@ func assertNoRowContainsNID( var absentCount, foundAbsenceRows int for _, rowRoot := range rowRoots { var outsideRange bool - if !namespace.IsOutsideRange(rowRoot, rowRoot) { + if !share.IsOutsideRange(namespace, rowRoot, rowRoot) { // namespace does belong to namespace range of the row absentCount++ } else { diff --git a/share/ipld/namespace_data.go b/share/ipld/namespace_data.go index 194b14dddd..3c69d2da94 100644 --- a/share/ipld/namespace_data.go +++ b/share/ipld/namespace_data.go @@ -14,6 +14,7 @@ import ( gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt" + "github.com/celestiaorg/celestia-node/share" "github.com/celestiaorg/celestia-node/share/shwap" ) @@ -80,7 +81,7 @@ func (n *NamespaceData) validate(rootCid cid.Cid) error { } root := NamespacedSha256FromCID(rootCid) - if n.namespace.IsOutsideRange(root, root) { + if share.IsOutsideRange(n.namespace, root, root) { return ErrNamespaceOutsideRange } return nil @@ -284,17 +285,17 @@ func (n *NamespaceData) collectNDWithProofs(j job, links []*ipld.Link) []job { var nextJobs []job // check if target namespace is outside of boundaries of both links - if n.namespace.IsOutsideRange(leftLink, rightLink) { + if share.IsOutsideRange(n.namespace, leftLink, rightLink) { log.Fatalf("target namespace outside of boundaries of links at depth: %v", j.depth) } - if !n.namespace.IsAboveMax(leftLink) { + if !share.IsAboveMax(n.namespace, leftLink) { // namespace is within the range of left link nextJobs = append(nextJobs, j.next(left, leftCid, false)) } else { // proof is on the left side, if the namespace is on the right side of the range of left link n.addProof(left, leftCid, j.depth) - if n.namespace.IsBelowMin(rightLink) { + if share.IsBelowMin(n.namespace, rightLink) { // namespace is not included in either links, convert to absence collector n.isAbsentNamespace.Store(true) nextJobs = append(nextJobs, j.next(right, rightCid, true)) @@ -302,7 +303,7 @@ func (n *NamespaceData) collectNDWithProofs(j job, links []*ipld.Link) []job { } } - if !n.namespace.IsBelowMin(rightLink) { + if !share.IsBelowMin(n.namespace, rightLink) { // namespace is within the range of right link nextJobs = append(nextJobs, j.next(right, rightCid, false)) } else { diff --git a/share/ipld/utils.go b/share/ipld/utils.go index 62acc24961..6c8d959182 100644 --- a/share/ipld/utils.go +++ b/share/ipld/utils.go @@ -13,7 +13,7 @@ import ( func FilterRootByNamespace(root *share.AxisRoots, namespace gosquare.Namespace) []cid.Cid { rowRootCIDs := make([]cid.Cid, 0, len(root.RowRoots)) for _, row := range root.RowRoots { - if !namespace.IsOutsideRange(row, row) { + if !share.IsOutsideRange(namespace, row, row) { rowRootCIDs = append(rowRootCIDs, MustCidFromNamespacedSha256(row)) } } diff --git a/share/root.go b/share/root.go index 7d84101b6a..9eb009728c 100644 --- a/share/root.go +++ b/share/root.go @@ -61,7 +61,7 @@ func NewAxisRoots(eds *rsmt2d.ExtendedDataSquare) (*AxisRoots, error) { // a slices of Row indexes containing the namespace. func RowsWithNamespace(root *AxisRoots, namespace gosquare.Namespace) (idxs []int) { for i, row := range root.RowRoots { - if !namespace.IsOutsideRange(row, row) { + if !IsOutsideRange(namespace, row, row) { idxs = append(idxs, i) } } @@ -88,3 +88,43 @@ func MustDataHashFromString(datahash string) DataHash { } return dh } + +// IsOutsideRange checks if the namespace is outside the min-max range of the given hashes. +func IsOutsideRange(namespace gosquare.Namespace, leftHash, rightHash []byte) bool { + if len(leftHash) < gosquare.NamespaceSize || len(rightHash) < 2*gosquare.NamespaceSize { + return false + } + ns1, err := gosquare.NewNamespaceFromBytes(leftHash[:gosquare.NamespaceSize]) + if err != nil { + return false + } + ns2, err := gosquare.NewNamespaceFromBytes(rightHash[gosquare.NamespaceSize : gosquare.NamespaceSize*2]) + if err != nil { + return false + } + return namespace.IsLessThan(ns1) || !namespace.IsLessOrEqualThan(ns2) +} + +// IsAboveMax checks if the namespace is above the maximum namespace of the given hash. +func IsAboveMax(namespace gosquare.Namespace, hash []byte) bool { + if len(hash) < 2*gosquare.NamespaceSize { + return false + } + ns, err := gosquare.NewNamespaceFromBytes(hash[gosquare.NamespaceSize : gosquare.NamespaceSize*2]) + if err != nil { + return false + } + return !namespace.IsLessOrEqualThan(ns) +} + +// IsBelowMin checks if the target namespace is below the minimum namespace of the given hash. +func IsBelowMin(namespace gosquare.Namespace, hash []byte) bool { + if len(hash) < gosquare.NamespaceSize { + return false + } + ns1, err := gosquare.NewNamespaceFromBytes(hash[:gosquare.NamespaceSize]) + if err != nil { + return false + } + return namespace.IsLessThan(ns1) +} diff --git a/share/shwap/row_namespace_data.go b/share/shwap/row_namespace_data.go index 294e0b4a9e..e463bd5150 100644 --- a/share/shwap/row_namespace_data.go +++ b/share/shwap/row_namespace_data.go @@ -55,7 +55,7 @@ func RowNamespaceDataFromShares( if err != nil { return RowNamespaceData{}, fmt.Errorf("failed to get root for row %d: %w", rowIndex, err) } - if namespace.IsOutsideRange(root, root) { + if share.IsOutsideRange(namespace, root, root) { return RowNamespaceData{}, ErrNamespaceOutsideRange } @@ -163,7 +163,7 @@ func (rnd RowNamespaceData) Verify(roots *share.AxisRoots, namespace gosquare.Na } rowRoot := roots.RowRoots[rowIdx] - if namespace.IsOutsideRange(rowRoot, rowRoot) { + if share.IsOutsideRange(namespace, rowRoot, rowRoot) { return fmt.Errorf("namespace out of range for row %d", rowIdx) } From 489fce5abfb9172f065eb1dd21205481408e8d23 Mon Sep 17 00:00:00 2001 From: vgonkivs Date: Tue, 15 Oct 2024 13:18:34 +0300 Subject: [PATCH 11/21] fix: fix nits found by @renaynay --- blob/blob.go | 6 +-- blob/parser.go | 7 +--- blob/service.go | 6 ++- share/doc.go | 2 +- share/eds/nd.go | 5 ++- share/eds/testing.go | 4 +- share/ipld/get_shares_test.go | 13 ++++--- share/ipld/namespace_data.go | 32 ++++++++++++--- share/ipld/utils.go | 12 ++++-- share/root.go | 39 +++++++++++-------- share/shwap/namespace_data.go | 5 ++- share/shwap/p2p/bitswap/getter.go | 10 +++-- .../bitswap/row_namespace_data_block_test.go | 5 ++- share/shwap/p2p/shrex/shrex_getter/shrex.go | 7 +++- .../p2p/shrex/shrex_getter/shrex_test.go | 12 ++++-- share/shwap/p2p/shrex/shrexnd/client.go | 2 +- share/shwap/p2p/shrex/shrexnd/doc.go | 2 +- .../p2p/shrex/shrexsub/pb/notification.pb.go | 2 +- .../p2p/shrex/shrexsub/pb/notification.proto | 2 +- share/shwap/row_namespace_data.go | 12 +++++- share/shwap/row_namespace_data_test.go | 3 +- 21 files changed, 127 insertions(+), 61 deletions(-) diff --git a/blob/blob.go b/blob/blob.go index e33b80b20a..d84deb1971 100644 --- a/blob/blob.go +++ b/blob/blob.go @@ -142,7 +142,7 @@ func (b *Blob) compareCommitments(com Commitment) bool { type jsonBlob struct { Namespace []byte `json:"namespace"` Data []byte `json:"data"` - ShareVersion uint32 `json:"share_version"` + ShareVersion uint8 `json:"share_version"` Commitment Commitment `json:"commitment"` Signer []byte `json:"signer,omitempty"` Index int `json:"index"` @@ -152,7 +152,7 @@ func (b *Blob) MarshalJSON() ([]byte, error) { blob := &jsonBlob{ Namespace: b.Namespace().Bytes(), Data: b.Data(), - ShareVersion: uint32(b.ShareVersion()), + ShareVersion: b.ShareVersion(), Commitment: b.Commitment, Signer: b.Signer(), Index: b.index, @@ -172,7 +172,7 @@ func (b *Blob) UnmarshalJSON(data []byte) error { return err } - blob, err := NewBlob(uint8(jsonBlob.ShareVersion), ns, jsonBlob.Data, jsonBlob.Signer) + blob, err := NewBlob(jsonBlob.ShareVersion, ns, jsonBlob.Data, jsonBlob.Signer) if err != nil { return err } diff --git a/blob/parser.go b/blob/parser.go index ad452329d2..a529374d14 100644 --- a/blob/parser.go +++ b/blob/parser.go @@ -80,11 +80,8 @@ func (p *parser) parse() (*Blob, error) { return nil, err } - if len(blobs) == 0 { - return nil, ErrBlobNotFound - } - if len(blobs) > 1 { - return nil, errors.New("unexpected amount of blobs") + if len(blobs) != 1 { + return nil, errors.New("unexpected amount of blobs during parsing") } com, err := inclusion.CreateCommitment(blobs[0], merkle.HashFromByteSlices, subtreeRootThreshold) diff --git a/blob/service.go b/blob/service.go index 369775d373..cfa13360ec 100644 --- a/blob/service.go +++ b/blob/service.go @@ -359,7 +359,11 @@ func (s *Service) retrieve( rowIndex := -1 for i, row := range header.DAH.RowRoots { - if !share.IsOutsideRange(namespace, row, row) { + outside, err := share.IsOutsideRange(namespace, row, row) + if err != nil { + return nil, nil, err + } + if !outside { rowIndex = i break } diff --git a/share/doc.go b/share/doc.go index 90dea3f243..6c6426472f 100644 --- a/share/doc.go +++ b/share/doc.go @@ -1,5 +1,5 @@ /* -package share contains logic related to the retrieval and random sampling of shares of +Package share contains logic related to the retrieval and random sampling of shares of block data. Though this package contains several useful methods for getting specific shares and/or diff --git a/share/eds/nd.go b/share/eds/nd.go index 6215493c68..c45ee4da20 100644 --- a/share/eds/nd.go +++ b/share/eds/nd.go @@ -22,7 +22,10 @@ func NamespaceData( if err != nil { return nil, fmt.Errorf("failed to get AxisRoots: %w", err) } - rowIdxs := share.RowsWithNamespace(roots, namespace) + rowIdxs, err := share.RowsWithNamespace(roots, namespace) + if err != nil { + return nil, fmt.Errorf("failed to get row indexes: %w", err) + } rows := make(shwap.NamespaceData, len(rowIdxs)) for i, idx := range rowIdxs { rows[i], err = eds.RowNamespaceData(ctx, namespace, idx) diff --git a/share/eds/testing.go b/share/eds/testing.go index 26c4cd0364..273e810c61 100644 --- a/share/eds/testing.go +++ b/share/eds/testing.go @@ -228,7 +228,9 @@ func testAccessorRowNamespaceData( rowData, err := acc.RowNamespaceData(ctx, namespace, i) // namespace is not included in the row, so there should be no shares - if share.IsOutsideRange(namespace, root, root) { + outside, outsideErr := share.IsOutsideRange(namespace, root, root) + require.NoError(t, outsideErr) + if outside { require.ErrorIs(t, err, shwap.ErrNamespaceOutsideRange) require.Len(t, rowData.Shares, 0) continue diff --git a/share/ipld/get_shares_test.go b/share/ipld/get_shares_test.go index d14302634f..61705042ef 100644 --- a/share/ipld/get_shares_test.go +++ b/share/ipld/get_shares_test.go @@ -362,7 +362,9 @@ func TestGetSharesWithProofsByNamespace(t *testing.T) { require.NoError(t, err) for _, row := range rowRoots { rowShares, proof, err := GetSharesByNamespace(ctx, bServ, row, namespace, len(rowRoots)) - if share.IsOutsideRange(namespace, row, row) { + outside, outsideErr := share.IsOutsideRange(namespace, row, row) + require.NoError(t, outsideErr) + if outside { require.ErrorIs(t, err, ErrNamespaceOutsideRange) continue } @@ -464,16 +466,15 @@ func assertNoRowContainsNID( // for each row root cid check if the min namespace exists var absentCount, foundAbsenceRows int for _, rowRoot := range rowRoots { - var outsideRange bool - if !share.IsOutsideRange(namespace, rowRoot, rowRoot) { + outsideRange, err := share.IsOutsideRange(namespace, rowRoot, rowRoot) + require.NoError(t, err) + if !outsideRange { // namespace does belong to namespace range of the row absentCount++ - } else { - outsideRange = true } data := NewNamespaceData(rowRootCount, namespace, WithProofs()) rootCID := MustCidFromNamespacedSha256(rowRoot) - err := data.CollectLeavesByNamespace(ctx, bServ, rootCID) + err = data.CollectLeavesByNamespace(ctx, bServ, rootCID) if outsideRange { require.ErrorIs(t, err, ErrNamespaceOutsideRange) continue diff --git a/share/ipld/namespace_data.go b/share/ipld/namespace_data.go index 3c69d2da94..cafec83cb2 100644 --- a/share/ipld/namespace_data.go +++ b/share/ipld/namespace_data.go @@ -81,7 +81,11 @@ func (n *NamespaceData) validate(rootCid cid.Cid) error { } root := NamespacedSha256FromCID(rootCid) - if share.IsOutsideRange(n.namespace, root, root) { + outside, err := share.IsOutsideRange(n.namespace, root, root) + if err != nil { + return err + } + if outside { return ErrNamespaceOutsideRange } return nil @@ -284,18 +288,31 @@ func (n *NamespaceData) collectNDWithProofs(j job, links []*ipld.Link) []job { rightLink := NamespacedSha256FromCID(rightCid) var nextJobs []job + outside, err := share.IsOutsideRange(n.namespace, leftLink, rightLink) + if err != nil { + log.Fatalf("invalid hashes provided: %v", err) + } // check if target namespace is outside of boundaries of both links - if share.IsOutsideRange(n.namespace, leftLink, rightLink) { + if outside { log.Fatalf("target namespace outside of boundaries of links at depth: %v", j.depth) } - if !share.IsAboveMax(n.namespace, leftLink) { + above, err := share.IsAboveMax(n.namespace, leftLink) + if err != nil { + log.Fatal(err) + } + + if above { // namespace is within the range of left link nextJobs = append(nextJobs, j.next(left, leftCid, false)) } else { // proof is on the left side, if the namespace is on the right side of the range of left link n.addProof(left, leftCid, j.depth) - if share.IsBelowMin(n.namespace, rightLink) { + below, err := share.IsBelowMin(n.namespace, rightLink) + if err != nil { + log.Fatal(err) + } + if below { // namespace is not included in either links, convert to absence collector n.isAbsentNamespace.Store(true) nextJobs = append(nextJobs, j.next(right, rightCid, true)) @@ -303,7 +320,12 @@ func (n *NamespaceData) collectNDWithProofs(j job, links []*ipld.Link) []job { } } - if !share.IsBelowMin(n.namespace, rightLink) { + below, err := share.IsBelowMin(n.namespace, rightLink) + if err != nil { + log.Fatal(err) + } + + if !below { // namespace is within the range of right link nextJobs = append(nextJobs, j.next(right, rightCid, false)) } else { diff --git a/share/ipld/utils.go b/share/ipld/utils.go index 6c8d959182..e2443d357f 100644 --- a/share/ipld/utils.go +++ b/share/ipld/utils.go @@ -10,12 +10,18 @@ import ( // FilterRootByNamespace returns the row roots from the given share.AxisRoots that contain the // namespace. -func FilterRootByNamespace(root *share.AxisRoots, namespace gosquare.Namespace) []cid.Cid { +func FilterRootByNamespace(root *share.AxisRoots, namespace gosquare.Namespace) ([]cid.Cid, error) { rowRootCIDs := make([]cid.Cid, 0, len(root.RowRoots)) for _, row := range root.RowRoots { - if !share.IsOutsideRange(namespace, row, row) { + outside, err := share.IsOutsideRange(namespace, row, row) + if err != nil { + return nil, err + + } + + if !outside { rowRootCIDs = append(rowRootCIDs, MustCidFromNamespacedSha256(row)) } } - return rowRootCIDs + return rowRootCIDs, nil } diff --git a/share/root.go b/share/root.go index 9eb009728c..4016e8d473 100644 --- a/share/root.go +++ b/share/root.go @@ -59,9 +59,13 @@ func NewAxisRoots(eds *rsmt2d.ExtendedDataSquare) (*AxisRoots, error) { // RowsWithNamespace inspects the AxisRoots for the Namespace and provides // a slices of Row indexes containing the namespace. -func RowsWithNamespace(root *AxisRoots, namespace gosquare.Namespace) (idxs []int) { +func RowsWithNamespace(root *AxisRoots, namespace gosquare.Namespace) (idxs []int, err error) { for i, row := range root.RowRoots { - if !IsOutsideRange(namespace, row, row) { + outside, err := IsOutsideRange(namespace, row, row) + if err != nil { + return nil, err + } + if !outside { idxs = append(idxs, i) } } @@ -90,41 +94,44 @@ func MustDataHashFromString(datahash string) DataHash { } // IsOutsideRange checks if the namespace is outside the min-max range of the given hashes. -func IsOutsideRange(namespace gosquare.Namespace, leftHash, rightHash []byte) bool { - if len(leftHash) < gosquare.NamespaceSize || len(rightHash) < 2*gosquare.NamespaceSize { - return false +func IsOutsideRange(namespace gosquare.Namespace, leftHash, rightHash []byte) (bool, error) { + if len(leftHash) < gosquare.NamespaceSize { + return false, fmt.Errorf("left can't be less than %d", gosquare.NamespaceSize) + } + if len(rightHash) < 2*gosquare.NamespaceSize { + return false, fmt.Errorf("rightHash can't be less than %d", 2*gosquare.NamespaceSize) } ns1, err := gosquare.NewNamespaceFromBytes(leftHash[:gosquare.NamespaceSize]) if err != nil { - return false + return false, err } ns2, err := gosquare.NewNamespaceFromBytes(rightHash[gosquare.NamespaceSize : gosquare.NamespaceSize*2]) if err != nil { - return false + return false, err } - return namespace.IsLessThan(ns1) || !namespace.IsLessOrEqualThan(ns2) + return namespace.IsLessThan(ns1) || !namespace.IsLessOrEqualThan(ns2), nil } // IsAboveMax checks if the namespace is above the maximum namespace of the given hash. -func IsAboveMax(namespace gosquare.Namespace, hash []byte) bool { +func IsAboveMax(namespace gosquare.Namespace, hash []byte) (bool, error) { if len(hash) < 2*gosquare.NamespaceSize { - return false + return false, fmt.Errorf("hash can't be less than: %d", 2*gosquare.NamespaceSize) } ns, err := gosquare.NewNamespaceFromBytes(hash[gosquare.NamespaceSize : gosquare.NamespaceSize*2]) if err != nil { - return false + return false, err } - return !namespace.IsLessOrEqualThan(ns) + return !namespace.IsLessOrEqualThan(ns), nil } // IsBelowMin checks if the target namespace is below the minimum namespace of the given hash. -func IsBelowMin(namespace gosquare.Namespace, hash []byte) bool { +func IsBelowMin(namespace gosquare.Namespace, hash []byte) (bool, error) { if len(hash) < gosquare.NamespaceSize { - return false + return false, fmt.Errorf("hash can't be less than: %d", gosquare.NamespaceSize) } ns1, err := gosquare.NewNamespaceFromBytes(hash[:gosquare.NamespaceSize]) if err != nil { - return false + return false, err } - return namespace.IsLessThan(ns1) + return namespace.IsLessThan(ns1), nil } diff --git a/share/shwap/namespace_data.go b/share/shwap/namespace_data.go index b98c210656..785d0c0dbe 100644 --- a/share/shwap/namespace_data.go +++ b/share/shwap/namespace_data.go @@ -30,7 +30,10 @@ func (nd NamespaceData) Flatten() []gosquare.Share { // Verify checks the integrity of the NamespaceData against a provided root and namespace. func (nd NamespaceData) Verify(root *share.AxisRoots, namespace gosquare.Namespace) error { - rowIdxs := share.RowsWithNamespace(root, namespace) + rowIdxs, err := share.RowsWithNamespace(root, namespace) + if err != nil { + return err + } if len(rowIdxs) != len(nd) { return fmt.Errorf("expected %d rows, found %d rows", len(rowIdxs), len(nd)) } diff --git a/share/shwap/p2p/bitswap/getter.go b/share/shwap/p2p/bitswap/getter.go index 86ce510cb6..9f0c97ec03 100644 --- a/share/shwap/p2p/bitswap/getter.go +++ b/share/shwap/p2p/bitswap/getter.go @@ -23,7 +23,7 @@ import ( var tracer = otel.Tracer("shwap/bitswap") -// Getter implements gosquare.Getter. +// Getter implements share.Getter. type Getter struct { exchange exchange.SessionExchange bstore blockstore.Blockstore @@ -194,7 +194,10 @@ func (g *Getter) GetSharesByNamespace( ctx, span := tracer.Start(ctx, "get-shares-by-namespace") defer span.End() - rowIdxs := share.RowsWithNamespace(hdr.DAH, ns) + rowIdxs, err := share.RowsWithNamespace(hdr.DAH, ns) + if err != nil { + return nil, err + } blks := make([]Block, len(rowIdxs)) for i, rowNdIdx := range rowIdxs { rndblk, err := NewEmptyRowNamespaceDataBlock(hdr.Height(), rowNdIdx, ns, len(hdr.DAH.RowRoots)) @@ -207,8 +210,7 @@ func (g *Getter) GetSharesByNamespace( } ses := g.session(ctx, hdr) - err := Fetch(ctx, g.exchange, hdr.DAH, blks, WithFetcher(ses)) - if err != nil { + if err = Fetch(ctx, g.exchange, hdr.DAH, blks, WithFetcher(ses)); err != nil { span.RecordError(err) span.SetStatus(codes.Error, "Fetch") return nil, err diff --git a/share/shwap/p2p/bitswap/row_namespace_data_block_test.go b/share/shwap/p2p/bitswap/row_namespace_data_block_test.go index 552c0d31fe..9cfe45da4f 100644 --- a/share/shwap/p2p/bitswap/row_namespace_data_block_test.go +++ b/share/shwap/p2p/bitswap/row_namespace_data_block_test.go @@ -21,7 +21,8 @@ func TestRowNamespaceData_FetchRoundtrip(t *testing.T) { eds, root := edstest.RandEDSWithNamespace(t, namespace, 64, 16) exchange := newExchangeOverEDS(ctx, t, eds) - rowIdxs := share.RowsWithNamespace(root, namespace) + rowIdxs, err := share.RowsWithNamespace(root, namespace) + require.NoError(t, err) blks := make([]Block, len(rowIdxs)) for i, rowIdx := range rowIdxs { blk, err := NewEmptyRowNamespaceDataBlock(1, rowIdx, namespace, len(root.RowRoots)) @@ -29,7 +30,7 @@ func TestRowNamespaceData_FetchRoundtrip(t *testing.T) { blks[i] = blk } - err := Fetch(ctx, exchange, root, blks) + err = Fetch(ctx, exchange, root, blks) require.NoError(t, err) for _, blk := range blks { diff --git a/share/shwap/p2p/shrex/shrex_getter/shrex.go b/share/shwap/p2p/shrex/shrex_getter/shrex.go index c87b6990a5..1f6a3a0031 100644 --- a/share/shwap/p2p/shrex/shrex_getter/shrex.go +++ b/share/shwap/p2p/shrex/shrex_getter/shrex.go @@ -91,7 +91,7 @@ func (sg *Getter) WithMetrics() error { return nil } -// Getter is a gosquare.Getter that uses the shrex/eds and shrex/nd protocol to retrieve shares. +// Getter is a share.Getter that uses the shrex/eds and shrex/nd protocol to retrieve shares. type Getter struct { edsClient *shrexeds.Client ndClient *shrexnd.Client @@ -235,7 +235,10 @@ func (sg *Getter) GetSharesByNamespace( // verify that the namespace could exist inside the roots before starting network requests dah := header.DAH - rowIdxs := share.RowsWithNamespace(dah, namespace) + rowIdxs, err := share.RowsWithNamespace(dah, namespace) + if err != nil { + return nil, err + } if len(rowIdxs) == 0 { return shwap.NamespaceData{}, nil } diff --git a/share/shwap/p2p/shrex/shrex_getter/shrex_test.go b/share/shwap/p2p/shrex/shrex_getter/shrex_test.go index 10e151fe6f..dc6f0817ca 100644 --- a/share/shwap/p2p/shrex/shrex_getter/shrex_test.go +++ b/share/shwap/p2p/shrex/shrex_getter/shrex_test.go @@ -127,7 +127,9 @@ func TestShrexGetter(t *testing.T) { nID, err := gosquare.AddInt(maxNamespace, -1) require.NoError(t, err) // check for namespace to be between max and min namespace in root - require.Len(t, share.RowsWithNamespace(roots, nID), 1) + rows, err := share.RowsWithNamespace(roots, nID) + require.NoError(t, err) + require.Len(t, rows, 1) emptyShares, err := getter.GetSharesByNamespace(ctx, eh, nID) require.NoError(t, err) @@ -139,7 +141,9 @@ func TestShrexGetter(t *testing.T) { nID, err = gosquare.AddInt(maxNamespace, 1) require.NoError(t, err) // check for namespace to be not in root - require.Len(t, share.RowsWithNamespace(roots, nID), 0) + rows, err = share.RowsWithNamespace(roots, nID) + require.NoError(t, err) + require.Len(t, rows, 0) emptyShares, err = getter.GetSharesByNamespace(ctx, eh, nID) require.NoError(t, err) @@ -168,7 +172,9 @@ func TestShrexGetter(t *testing.T) { namespace, err := gosquare.AddInt(maxNamespace, 1) require.NoError(t, err) // check for namespace to be not in root - require.Len(t, share.RowsWithNamespace(roots, namespace), 0) + rows, err := share.RowsWithNamespace(roots, namespace) + require.NoError(t, err) + require.Len(t, rows, 0) emptyShares, err := getter.GetSharesByNamespace(ctx, eh, namespace) require.NoError(t, err) diff --git a/share/shwap/p2p/shrex/shrexnd/client.go b/share/shwap/p2p/shrex/shrexnd/client.go index d5c1938f9f..e22dec736b 100644 --- a/share/shwap/p2p/shrex/shrexnd/client.go +++ b/share/shwap/p2p/shrex/shrexnd/client.go @@ -46,7 +46,7 @@ func NewClient(params *Parameters, host host.Host) (*Client, error) { } // RequestND requests namespaced data from the given peer. -// Returns NamespaceData with unverified inclusion proofs against the gosquare.Root. +// Returns NamespaceData with unverified inclusion proofs against the share.Root. func (c *Client) RequestND( ctx context.Context, height uint64, diff --git a/share/shwap/p2p/shrex/shrexnd/doc.go b/share/shwap/p2p/shrex/shrexnd/doc.go index 251a86dcb0..e31abaeb80 100644 --- a/share/shwap/p2p/shrex/shrexnd/doc.go +++ b/share/shwap/p2p/shrex/shrexnd/doc.go @@ -31,7 +31,7 @@ // // server, err := shrexnd.NewServer(params, host, store, storeShareGetter) // -// where store is of type [gosquare.Store] and storeShareGetter is of type [gosquare.Getter] +// where store is of type [share.Store] and storeShareGetter is of type [share.Getter] // // 2. Start the server by calling `Start` on the server: // diff --git a/share/shwap/p2p/shrex/shrexsub/pb/notification.pb.go b/share/shwap/p2p/shrex/shrexsub/pb/notification.pb.go index 939e4774e3..0be95ead3d 100644 --- a/share/shwap/p2p/shrex/shrexsub/pb/notification.pb.go +++ b/share/shwap/p2p/shrex/shrexsub/pb/notification.pb.go @@ -75,7 +75,7 @@ func (m *RecentEDSNotification) GetDataHash() []byte { } func init() { - proto.RegisterType((*RecentEDSNotification)(nil), "gosquare.p2p.shrex.sub.RecentEDSNotification") + proto.RegisterType((*RecentEDSNotification)(nil), "share.p2p.shrex.sub.RecentEDSNotification") } func init() { diff --git a/share/shwap/p2p/shrex/shrexsub/pb/notification.proto b/share/shwap/p2p/shrex/shrexsub/pb/notification.proto index c2aa88b70f..d96cf3369e 100644 --- a/share/shwap/p2p/shrex/shrexsub/pb/notification.proto +++ b/share/shwap/p2p/shrex/shrexsub/pb/notification.proto @@ -1,6 +1,6 @@ syntax = "proto3"; -package gosquare.p2p.shrex.sub; +package share.p2p.shrex.sub; message RecentEDSNotification { uint64 height = 1; diff --git a/share/shwap/row_namespace_data.go b/share/shwap/row_namespace_data.go index e463bd5150..b0620450a7 100644 --- a/share/shwap/row_namespace_data.go +++ b/share/shwap/row_namespace_data.go @@ -55,7 +55,11 @@ func RowNamespaceDataFromShares( if err != nil { return RowNamespaceData{}, fmt.Errorf("failed to get root for row %d: %w", rowIndex, err) } - if share.IsOutsideRange(namespace, root, root) { + outside, err := share.IsOutsideRange(namespace, root, root) + if err != nil { + return RowNamespaceData{}, err + } + if outside { return RowNamespaceData{}, ErrNamespaceOutsideRange } @@ -163,7 +167,11 @@ func (rnd RowNamespaceData) Verify(roots *share.AxisRoots, namespace gosquare.Na } rowRoot := roots.RowRoots[rowIdx] - if share.IsOutsideRange(namespace, rowRoot, rowRoot) { + outside, err := share.IsOutsideRange(namespace, rowRoot, rowRoot) + if err != nil { + return err + } + if outside { return fmt.Errorf("namespace out of range for row %d", rowIdx) } diff --git a/share/shwap/row_namespace_data_test.go b/share/shwap/row_namespace_data_test.go index b0c9110347..7b136ffa49 100644 --- a/share/shwap/row_namespace_data_test.go +++ b/share/shwap/row_namespace_data_test.go @@ -77,7 +77,8 @@ func TestValidateNamespacedRow(t *testing.T) { require.NoError(t, err) require.True(t, len(nd) > 0) - rowIdxs := share.RowsWithNamespace(root, namespace) + rowIdxs, err := share.RowsWithNamespace(root, namespace) + require.NoError(t, err) require.Len(t, nd, len(rowIdxs)) for i, rowIdx := range rowIdxs { From 53e6c4222af6e947451a3f7561be132ecd2eb5ce Mon Sep 17 00:00:00 2001 From: vgonkivs Date: Tue, 15 Oct 2024 13:47:26 +0300 Subject: [PATCH 12/21] rename gosquare go libshare import --- api/docgen/examples.go | 4 +- api/gateway/share.go | 24 ++-- api/gateway/share_test.go | 10 +- blob/blob.go | 30 ++--- blob/blob_fuzz_test.go | 4 +- blob/blob_test.go | 16 +-- blob/blobtest/testing.go | 16 +-- blob/commitment_proof.go | 4 +- blob/helper.go | 16 +-- blob/helper_test.go | 24 ++-- blob/parser.go | 14 +- blob/service.go | 50 +++---- blob/service_test.go | 126 +++++++++--------- cmd/util.go | 8 +- cmd/util_test.go | 4 +- core/eds.go | 4 +- nodebuilder/blob/blob.go | 38 +++--- nodebuilder/blob/cmd/blob.go | 4 +- nodebuilder/da/service.go | 14 +- nodebuilder/share/cmd/share.go | 4 +- nodebuilder/share/share.go | 30 ++--- nodebuilder/state/state.go | 8 +- nodebuilder/state/stub.go | 4 +- nodebuilder/store.go | 6 +- nodebuilder/tests/api_test.go | 10 +- nodebuilder/tests/blob_test.go | 32 ++--- nodebuilder/tests/da_test.go | 22 +-- nodebuilder/tests/nd_test.go | 10 +- nodebuilder/tests/prune_test.go | 4 +- share/availability/full/testing.go | 2 +- share/availability/light/availability_test.go | 20 +-- share/availability/light/testing.go | 20 +-- share/availability/test/testing.go | 6 +- share/eds/accessor.go | 6 +- share/eds/axis_half.go | 22 +-- share/eds/axis_half_test.go | 4 +- share/eds/byzantine/bad_encoding_test.go | 10 +- share/eds/byzantine/byzantine.go | 6 +- share/eds/byzantine/share_proof.go | 10 +- share/eds/close_once.go | 6 +- share/eds/close_once_test.go | 10 +- share/eds/edstest/testing.go | 36 ++--- share/eds/nd.go | 4 +- share/eds/nd_test.go | 4 +- share/eds/proof.go | 6 +- share/eds/proofs_cache.go | 12 +- share/eds/read.go | 12 +- share/eds/retriever.go | 4 +- share/eds/retriever_no_race_test.go | 4 +- share/eds/retriever_test.go | 6 +- share/eds/rsmt2d.go | 22 +-- share/eds/rsmt2d_test.go | 4 +- share/eds/share_reader_test.go | 4 +- share/eds/testing.go | 16 +-- share/eds/validation.go | 4 +- share/eds/validation_test.go | 4 +- share/empty.go | 12 +- share/ipld/add.go | 6 +- share/ipld/delete_test.go | 6 +- share/ipld/get_shares.go | 20 +-- share/ipld/get_shares_test.go | 60 ++++----- share/ipld/namespace_data.go | 8 +- share/ipld/nmt.go | 8 +- share/ipld/proofs_test.go | 6 +- share/ipld/utils.go | 4 +- share/root.go | 34 ++--- share/share.go | 6 +- share/shwap/getter.go | 6 +- share/shwap/getters/cascade.go | 10 +- share/shwap/getters/testing.go | 12 +- share/shwap/namespace_data.go | 8 +- share/shwap/namespace_data_id.go | 12 +- share/shwap/namespace_data_id_test.go | 6 +- share/shwap/p2p/bitswap/getter.go | 20 +-- share/shwap/p2p/bitswap/getter_test.go | 4 +- .../p2p/bitswap/row_namespace_data_block.go | 4 +- .../bitswap/row_namespace_data_block_test.go | 4 +- share/shwap/p2p/shrex/shrex_getter/shrex.go | 10 +- .../p2p/shrex/shrex_getter/shrex_test.go | 16 +-- share/shwap/p2p/shrex/shrexnd/client.go | 8 +- share/shwap/p2p/shrex/shrexnd/doc.go | 2 +- .../shwap/p2p/shrex/shrexnd/exchange_test.go | 10 +- .../p2p/shrex/shrexsub/pb/notification.pb.go | 2 +- share/shwap/row.go | 18 +-- share/shwap/row_namespace_data.go | 16 +-- share/shwap/row_namespace_data_id.go | 12 +- share/shwap/row_namespace_data_id_test.go | 6 +- share/shwap/row_namespace_data_test.go | 20 +-- share/shwap/row_test.go | 20 +-- share/shwap/sample.go | 10 +- share/shwap/sample_test.go | 4 +- share/shwap/share.go | 16 +-- state/core_access.go | 12 +- state/core_access_test.go | 12 +- store/cache/accessor_cache_test.go | 6 +- store/cache/noop.go | 8 +- store/file/codec_test.go | 8 +- store/file/ods.go | 30 ++--- store/file/ods_q4.go | 6 +- store/file/ods_q4_test.go | 4 +- store/file/ods_test.go | 6 +- store/file/square.go | 18 +-- store/getter.go | 12 +- store/getter_test.go | 6 +- store/store_test.go | 2 +- 105 files changed, 680 insertions(+), 680 deletions(-) diff --git a/api/docgen/examples.go b/api/docgen/examples.go index dff8e0baa8..e6ea79710c 100644 --- a/api/docgen/examples.go +++ b/api/docgen/examples.go @@ -22,7 +22,7 @@ import ( "github.com/celestiaorg/go-fraud" libhead "github.com/celestiaorg/go-header" - gosquare "github.com/celestiaorg/go-square/v2/share" + libshare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" "github.com/celestiaorg/celestia-node/blob" @@ -166,7 +166,7 @@ func init() { // randomly generated namespace that's used in the blob example above // (AAAAAAAAAAAAAAAAAAAAAAAAAAAAAMJ/xGlNMdE=) - namespace, err := gosquare.NewV0Namespace([]byte{0xc2, 0x7f, 0xc4, 0x69, 0x4d, 0x31, 0xd1}) + namespace, err := libshare.NewV0Namespace([]byte{0xc2, 0x7f, 0xc4, 0x69, 0x4d, 0x31, 0xd1}) if err != nil { panic(err) } diff --git a/api/gateway/share.go b/api/gateway/share.go index 9de2f104d9..9b47b6efb7 100644 --- a/api/gateway/share.go +++ b/api/gateway/share.go @@ -9,7 +9,7 @@ import ( "github.com/gorilla/mux" - gosquare "github.com/celestiaorg/go-square/v2/share" + libshare "github.com/celestiaorg/go-square/v2/share" ) const ( @@ -22,7 +22,7 @@ var namespaceKey = "nid" // NamespacedSharesResponse represents the response to a // SharesByNamespace request. type NamespacedSharesResponse struct { - Shares []gosquare.Share `json:"shares"` + Shares []libshare.Share `json:"shares"` Height uint64 `json:"height"` } @@ -91,8 +91,8 @@ func (h *Handler) handleDataByNamespaceRequest(w http.ResponseWriter, r *http.Re func (h *Handler) getShares( ctx context.Context, height uint64, - namespace gosquare.Namespace, -) ([]gosquare.Share, error) { + namespace libshare.Namespace, +) ([]libshare.Share, error) { header, err := h.header.GetByHeight(ctx, height) if err != nil { return nil, err @@ -106,8 +106,8 @@ func (h *Handler) getShares( return shares.Flatten(), nil } -func dataFromShares(input []gosquare.Share) (data [][]byte, err error) { - sequences, err := gosquare.ParseShares(input, false) +func dataFromShares(input []libshare.Share) (data [][]byte, err error) { + sequences, err := libshare.ParseShares(input, false) if err != nil { return nil, err } @@ -121,24 +121,24 @@ func dataFromShares(input []gosquare.Share) (data [][]byte, err error) { return data, nil } -func parseGetByNamespaceArgs(r *http.Request) (height uint64, namespace gosquare.Namespace, err error) { +func parseGetByNamespaceArgs(r *http.Request) (height uint64, namespace libshare.Namespace, err error) { vars := mux.Vars(r) // if a height was given, parse it, otherwise get namespaced shares/data from the latest header if strHeight, ok := vars[heightKey]; ok { height, err = strconv.ParseUint(strHeight, 10, 64) if err != nil { - return 0, gosquare.Namespace{}, err + return 0, libshare.Namespace{}, err } } hexNamespace := vars[namespaceKey] nsString, err := hex.DecodeString(hexNamespace) if err != nil { - return 0, gosquare.Namespace{}, err + return 0, libshare.Namespace{}, err } - ns, err := gosquare.NewNamespaceFromBytes(nsString) + ns, err := libshare.NewNamespaceFromBytes(nsString) if err != nil { - return 0, gosquare.Namespace{}, err + return 0, libshare.Namespace{}, err } namespace = ns - return height, namespace, gosquare.ValidateForData(namespace) + return height, namespace, libshare.ValidateForData(namespace) } diff --git a/api/gateway/share_test.go b/api/gateway/share_test.go index 53c20bdbb6..1096287ffc 100644 --- a/api/gateway/share_test.go +++ b/api/gateway/share_test.go @@ -6,7 +6,7 @@ import ( "github.com/stretchr/testify/require" - gosquare "github.com/celestiaorg/go-square/v2/share" + libshare "github.com/celestiaorg/go-square/v2/share" ) func Test_dataFromShares(t *testing.T) { @@ -16,10 +16,10 @@ func Test_dataFromShares(t *testing.T) { []byte("BEEEEAHP"), } - ns := gosquare.RandomNamespace() - sss := gosquare.NewSparseShareSplitter() + ns := libshare.RandomNamespace() + sss := libshare.NewSparseShareSplitter() for _, data := range testData { - b, err := gosquare.NewBlob(ns, data, gosquare.ShareVersionZero, nil) + b, err := libshare.NewBlob(ns, data, libshare.ShareVersionZero, nil) require.NoError(t, err) require.NoError(t, sss.Write(b)) } @@ -32,7 +32,7 @@ func Test_dataFromShares(t *testing.T) { rawSSSShares[i] = d } - shrs, err := gosquare.FromBytes(rawSSSShares) + shrs, err := libshare.FromBytes(rawSSSShares) require.NoError(t, err) parsedSSSShares, err := dataFromShares(shrs) require.NoError(t, err) diff --git a/blob/blob.go b/blob/blob.go index d84deb1971..c054bd76d3 100644 --- a/blob/blob.go +++ b/blob/blob.go @@ -10,7 +10,7 @@ import ( v3 "github.com/celestiaorg/celestia-app/v3/pkg/appconsts/v3" "github.com/celestiaorg/go-square/merkle" "github.com/celestiaorg/go-square/v2/inclusion" - gosquare "github.com/celestiaorg/go-square/v2/share" + libshare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt" ) @@ -59,7 +59,7 @@ func (p Proof) equal(input Proof) error { // Blob represents any application-specific binary data that anyone can submit to Celestia. type Blob struct { - *gosquare.Blob `json:"blob"` + *libshare.Blob `json:"blob"` Commitment Commitment `json:"commitment"` @@ -70,44 +70,44 @@ type Blob struct { // NewBlobV0 constructs a new blob from the provided Namespace and data. // The blob will be formatted as v0 shares. -func NewBlobV0(namespace gosquare.Namespace, data []byte) (*Blob, error) { - return NewBlob(gosquare.ShareVersionZero, namespace, data, nil) +func NewBlobV0(namespace libshare.Namespace, data []byte) (*Blob, error) { + return NewBlob(libshare.ShareVersionZero, namespace, data, nil) } // NewBlobV1 constructs a new blob from the provided Namespace, data, and signer. // The blob will be formatted as v1 shares. -func NewBlobV1(namespace gosquare.Namespace, data, signer []byte) (*Blob, error) { - return NewBlob(gosquare.ShareVersionOne, namespace, data, signer) +func NewBlobV1(namespace libshare.Namespace, data, signer []byte) (*Blob, error) { + return NewBlob(libshare.ShareVersionOne, namespace, data, signer) } // NewBlob constructs a new blob from the provided Namespace, data, signer, and share version. -func NewBlob(shareVersion uint8, namespace gosquare.Namespace, data, signer []byte) (*Blob, error) { +func NewBlob(shareVersion uint8, namespace libshare.Namespace, data, signer []byte) (*Blob, error) { if len(data) == 0 || len(data) > appconsts.DefaultMaxBytes { return nil, fmt.Errorf("blob data must be > 0 && <= %d, but it was %d bytes", appconsts.DefaultMaxBytes, len(data)) } - if err := gosquare.ValidateForData(namespace); err != nil { + if err := libshare.ValidateForData(namespace); err != nil { return nil, fmt.Errorf("invalid user namespace: %w", err) } - if !gosquare.IsBlobNamespace(namespace) { + if !libshare.IsBlobNamespace(namespace) { return nil, fmt.Errorf("namespace %s is not a blob namespace", namespace) } - squareBlob, err := gosquare.NewBlob(namespace, data, shareVersion, signer) + libBlob, err := libshare.NewBlob(namespace, data, shareVersion, signer) if err != nil { return nil, err } - com, err := inclusion.CreateCommitment(squareBlob, merkle.HashFromByteSlices, subtreeRootThreshold) + com, err := inclusion.CreateCommitment(libBlob, merkle.HashFromByteSlices, subtreeRootThreshold) if err != nil { return nil, err } - return &Blob{Blob: squareBlob, Commitment: com, index: -1}, nil + return &Blob{Blob: libBlob, Commitment: com, index: -1}, nil } // Namespace returns blob's namespace. -func (b *Blob) Namespace() gosquare.Namespace { +func (b *Blob) Namespace() libshare.Namespace { return b.Blob.Namespace() } @@ -127,7 +127,7 @@ func (b *Blob) Length() (int, error) { if len(s) == 0 { return 0, errors.New("blob with zero shares received") } - return gosquare.SparseSharesNeeded(s[0].SequenceLen()), nil + return libshare.SparseSharesNeeded(s[0].SequenceLen()), nil } // Signer returns blob's author. @@ -167,7 +167,7 @@ func (b *Blob) UnmarshalJSON(data []byte) error { return err } - ns, err := gosquare.NewNamespaceFromBytes(jsonBlob.Namespace) + ns, err := libshare.NewNamespaceFromBytes(jsonBlob.Namespace) if err != nil { return err } diff --git a/blob/blob_fuzz_test.go b/blob/blob_fuzz_test.go index 77be61a946..16981335c8 100644 --- a/blob/blob_fuzz_test.go +++ b/blob/blob_fuzz_test.go @@ -15,12 +15,12 @@ func FuzzProofEqual(f *testing.F) { } // 1. Generate the corpus. - squareBlobs, err := blobtest.GenerateV0Blobs([]int{16}, false) + libBlobs, err := blobtest.GenerateV0Blobs([]int{16}, false) if err != nil { f.Fatal(err) } - blobs, err := convertBlobs(squareBlobs...) + blobs, err := convertBlobs(libBlobs...) if err != nil { f.Fatal(err) } diff --git a/blob/blob_test.go b/blob/blob_test.go index 9ea7dcf49a..ee28d88353 100644 --- a/blob/blob_test.go +++ b/blob/blob_test.go @@ -9,16 +9,16 @@ import ( "github.com/celestiaorg/go-square/merkle" "github.com/celestiaorg/go-square/v2/inclusion" - gosquare "github.com/celestiaorg/go-square/v2/share" + libshare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/celestia-node/blob/blobtest" ) func TestBlob(t *testing.T) { length := 16 - appBlobs, err := blobtest.GenerateV0Blobs([]int{length}, false) + libBlobs, err := blobtest.GenerateV0Blobs([]int{length}, false) require.NoError(t, err) - blob, err := convertBlobs(appBlobs...) + blob, err := convertBlobs(libBlobs...) require.NoError(t, err) test := []struct { @@ -50,7 +50,7 @@ func TestBlob(t *testing.T) { name: "verify namespace", expectedRes: func(t *testing.T) { ns := blob[0].Namespace() - require.NoError(t, gosquare.ValidateUserNamespace(ns.Version(), ns.ID())) + require.NoError(t, libshare.ValidateUserNamespace(ns.Version(), ns.ID())) }, }, { @@ -91,10 +91,10 @@ func TestBlob(t *testing.T) { } } -func convertBlobs(appBlobs ...*gosquare.Blob) ([]*Blob, error) { - blobs := make([]*Blob, 0, len(appBlobs)) - for _, appBlob := range appBlobs { - blob, err := NewBlob(appBlob.ShareVersion(), appBlob.Namespace(), appBlob.Data(), appBlob.Signer()) +func convertBlobs(libBlobs ...*libshare.Blob) ([]*Blob, error) { + blobs := make([]*Blob, 0, len(libBlobs)) + for _, libBlob := range libBlobs { + blob, err := NewBlob(libBlob.ShareVersion(), libBlob.Namespace(), libBlob.Data(), libBlob.Signer()) if err != nil { return nil, err } diff --git a/blob/blobtest/testing.go b/blob/blobtest/testing.go index 6443ae1c9a..40c086ce47 100644 --- a/blob/blobtest/testing.go +++ b/blob/blobtest/testing.go @@ -7,31 +7,31 @@ import ( tmrand "github.com/tendermint/tendermint/libs/rand" "github.com/celestiaorg/celestia-app/v3/test/util/testfactory" - gosquare "github.com/celestiaorg/go-square/v2/share" + libshare "github.com/celestiaorg/go-square/v2/share" ) // GenerateV0Blobs is a test utility producing v0 share formatted blobs with the // requested size and random namespaces. -func GenerateV0Blobs(sizes []int, sameNamespace bool) ([]*gosquare.Blob, error) { - blobs := make([]*gosquare.Blob, 0, len(sizes)) +func GenerateV0Blobs(sizes []int, sameNamespace bool) ([]*libshare.Blob, error) { + blobs := make([]*libshare.Blob, 0, len(sizes)) for _, size := range sizes { - size := RawBlobSize(gosquare.FirstSparseShareContentSize * size) - appBlob := testfactory.GenerateRandomBlob(size) + size := RawBlobSize(libshare.FirstSparseShareContentSize * size) + libBlob := testfactory.GenerateRandomBlob(size) if !sameNamespace { - namespace, err := gosquare.NewV0Namespace(tmrand.Bytes(7)) + namespace, err := libshare.NewV0Namespace(tmrand.Bytes(7)) if err != nil { return nil, err } if namespace.IsReserved() { return nil, fmt.Errorf("reserved namespace") } - appBlob, err = gosquare.NewV0Blob(namespace, appBlob.Data()) + libBlob, err = libshare.NewV0Blob(namespace, libBlob.Data()) if err != nil { return nil, err } } - blobs = append(blobs, appBlob) + blobs = append(blobs, libBlob) } return blobs, nil } diff --git a/blob/commitment_proof.go b/blob/commitment_proof.go index fd9a758989..887f420552 100644 --- a/blob/commitment_proof.go +++ b/blob/commitment_proof.go @@ -8,7 +8,7 @@ import ( "github.com/celestiaorg/celestia-app/v3/pkg/appconsts" "github.com/celestiaorg/celestia-app/v3/pkg/proof" "github.com/celestiaorg/go-square/v2/inclusion" - gosquare "github.com/celestiaorg/go-square/v2/share" + libshare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt" "github.com/celestiaorg/nmt/namespace" ) @@ -94,7 +94,7 @@ func (commitmentProof *CommitmentProof) Verify(root []byte, subtreeRootThreshold return false, err } - nmtHasher := nmt.NewNmtHasher(appconsts.NewBaseHashFunc(), gosquare.NamespaceSize, true) + nmtHasher := nmt.NewNmtHasher(appconsts.NewBaseHashFunc(), libshare.NamespaceSize, true) // computes the total number of shares proven. numberOfShares := 0 diff --git a/blob/helper.go b/blob/helper.go index 95229502d8..ce66aced25 100644 --- a/blob/helper.go +++ b/blob/helper.go @@ -4,16 +4,16 @@ import ( "fmt" "sort" - gosquare "github.com/celestiaorg/go-square/v2/share" + libshare "github.com/celestiaorg/go-square/v2/share" ) // BlobsToShares accepts blobs and convert them to the Shares. -func BlobsToShares(nodeBlobs ...*Blob) ([]gosquare.Share, error) { +func BlobsToShares(nodeBlobs ...*Blob) ([]libshare.Share, error) { sort.Slice(nodeBlobs, func(i, j int) bool { return nodeBlobs[i].Blob.Namespace().IsLessThan(nodeBlobs[j].Blob.Namespace()) }) - splitter := gosquare.NewSparseShareSplitter() + splitter := libshare.NewSparseShareSplitter() for i, nodeBlob := range nodeBlobs { err := splitter.Write(nodeBlob.Blob) if err != nil { @@ -23,13 +23,13 @@ func BlobsToShares(nodeBlobs ...*Blob) ([]gosquare.Share, error) { return splitter.Export(), nil } -// ToAppBlobs converts node's blob type to the blob type from go-square. -func ToAppBlobs(blobs ...*Blob) []*gosquare.Blob { - appBlobs := make([]*gosquare.Blob, len(blobs)) +// ToLibBlobs converts node's blob type to the blob type from go-square. +func ToLibBlobs(blobs ...*Blob) []*libshare.Blob { + libBlobs := make([]*libshare.Blob, len(blobs)) for i := range blobs { - appBlobs[i] = blobs[i].Blob + libBlobs[i] = blobs[i].Blob } - return appBlobs + return libBlobs } func calculateIndex(rowLength, blobIndex int) (row, col int) { diff --git a/blob/helper_test.go b/blob/helper_test.go index 9fb6992d67..7af9336fae 100644 --- a/blob/helper_test.go +++ b/blob/helper_test.go @@ -7,17 +7,17 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - gosquare "github.com/celestiaorg/go-square/v2/share" + libshare "github.com/celestiaorg/go-square/v2/share" ) func TestBlobsToShares(t *testing.T) { t.Run("should sort blobs by namespace in ascending order", func(t *testing.T) { - namespaceA := gosquare.MustNewV0Namespace(bytes.Repeat([]byte{0xa}, 10)) - namespaceB := gosquare.MustNewV0Namespace(bytes.Repeat([]byte{0xb}, 10)) + namespaceA := libshare.MustNewV0Namespace(bytes.Repeat([]byte{0xa}, 10)) + namespaceB := libshare.MustNewV0Namespace(bytes.Repeat([]byte{0xb}, 10)) - blobA, err := NewBlob(gosquare.ShareVersionZero, namespaceA, []byte("dataA"), nil) + blobA, err := NewBlob(libshare.ShareVersionZero, namespaceA, []byte("dataA"), nil) require.NoError(t, err) - blobB, err := NewBlob(gosquare.ShareVersionZero, namespaceB, []byte("dataB"), nil) + blobB, err := NewBlob(libshare.ShareVersionZero, namespaceB, []byte("dataB"), nil) require.NoError(t, err) got, err := BlobsToShares(blobB, blobA) @@ -28,16 +28,16 @@ func TestBlobsToShares(t *testing.T) { }) } -func TestToAppBlobs(t *testing.T) { - namespaceA := gosquare.MustNewV0Namespace(bytes.Repeat([]byte{0xa}, 10)) - namespaceB := gosquare.MustNewV0Namespace(bytes.Repeat([]byte{0xb}, 10)) +func TestToLibBlobs(t *testing.T) { + namespaceA := libshare.MustNewV0Namespace(bytes.Repeat([]byte{0xa}, 10)) + namespaceB := libshare.MustNewV0Namespace(bytes.Repeat([]byte{0xb}, 10)) - blobA, err := NewBlob(gosquare.ShareVersionZero, namespaceA, []byte("dataA"), nil) + blobA, err := NewBlob(libshare.ShareVersionZero, namespaceA, []byte("dataA"), nil) require.NoError(t, err) - blobB, err := NewBlob(gosquare.ShareVersionZero, namespaceB, []byte("dataB"), nil) + blobB, err := NewBlob(libshare.ShareVersionZero, namespaceB, []byte("dataB"), nil) require.NoError(t, err) - got := ToAppBlobs(blobA, blobB) + got := ToLibBlobs(blobA, blobB) - assert.Equal(t, []*gosquare.Blob{blobA.Blob, blobB.Blob}, got) + assert.Equal(t, []*libshare.Blob{blobA.Blob, blobB.Blob}, got) } diff --git a/blob/parser.go b/blob/parser.go index a529374d14..977bb2dfd9 100644 --- a/blob/parser.go +++ b/blob/parser.go @@ -6,7 +6,7 @@ import ( "github.com/celestiaorg/go-square/merkle" "github.com/celestiaorg/go-square/v2/inclusion" - gosquare "github.com/celestiaorg/go-square/v2/share" + libshare "github.com/celestiaorg/go-square/v2/share" ) // parser helps to collect shares and transform them into a blob. @@ -17,13 +17,13 @@ type parser struct { // length is an amount of the shares needed to build the blob. length int // shares is a set of shares to build the blob. - shares []gosquare.Share + shares []libshare.Share verifyFn func(blob *Blob) bool } // set tries to find the first blob's share by skipping padding shares and // sets the metadata of the blob(index and length) -func (p *parser) set(index int, shrs []gosquare.Share) ([]gosquare.Share, error) { +func (p *parser) set(index int, shrs []libshare.Share) ([]libshare.Share, error) { if len(shrs) == 0 { return nil, errEmptyShares } @@ -40,14 +40,14 @@ func (p *parser) set(index int, shrs []gosquare.Share) ([]gosquare.Share, error) // `+=` as index could be updated in `skipPadding` p.index += index length := shrs[0].SequenceLen() - p.length = gosquare.SparseSharesNeeded(length) + p.length = libshare.SparseSharesNeeded(length) return shrs, nil } // addShares sets shares until the blob is completed and extra remaining shares back. // It assumes that the remaining shares required for blob completeness are correct and // do not include padding shares. -func (p *parser) addShares(shares []gosquare.Share) (shrs []gosquare.Share, isComplete bool) { +func (p *parser) addShares(shares []libshare.Share) (shrs []libshare.Share, isComplete bool) { index := -1 for i, sh := range shares { p.shares = append(p.shares, sh) @@ -75,7 +75,7 @@ func (p *parser) parse() (*Blob, error) { return nil, fmt.Errorf("invalid shares amount. want:%d, have:%d", p.length, len(p.shares)) } - blobs, err := gosquare.ParseBlobs(p.shares) + blobs, err := libshare.ParseBlobs(p.shares) if err != nil { return nil, err } @@ -95,7 +95,7 @@ func (p *parser) parse() (*Blob, error) { // skipPadding iterates through the shares until non-padding share will be found. It guarantees that // the returned set of shares will start with non-padding share(or empty set of shares). -func (p *parser) skipPadding(shares []gosquare.Share) ([]gosquare.Share, error) { +func (p *parser) skipPadding(shares []libshare.Share) ([]libshare.Share, error) { if len(shares) == 0 { return nil, errEmptyShares } diff --git a/blob/service.go b/blob/service.go index cfa13360ec..c6c6aeb42e 100644 --- a/blob/service.go +++ b/blob/service.go @@ -19,7 +19,7 @@ import ( "github.com/celestiaorg/celestia-app/v3/pkg/appconsts" pkgproof "github.com/celestiaorg/celestia-app/v3/pkg/proof" "github.com/celestiaorg/go-square/v2/inclusion" - gosquare "github.com/celestiaorg/go-square/v2/share" + libshare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt" "github.com/celestiaorg/rsmt2d" @@ -46,7 +46,7 @@ type SubmitOptions = state.TxConfig // avoid a circular dependency between the blob and the state package, since the state package needs // the blob.Blob type for this signature. type Submitter interface { - SubmitPayForBlob(context.Context, []*gosquare.Blob, *state.TxConfig) (*types.TxResponse, error) + SubmitPayForBlob(context.Context, []*libshare.Blob, *state.TxConfig) (*types.TxResponse, error) } type Service struct { @@ -99,7 +99,7 @@ type SubscriptionResponse struct { // The channel will be closed when the context is canceled or the service is stopped. // Please note that no errors are returned: underlying operations are retried until successful. // Additionally, not reading from the returned channel will cause the stream to close after 16 messages. -func (s *Service) Subscribe(ctx context.Context, ns gosquare.Namespace) (<-chan *SubscriptionResponse, error) { +func (s *Service) Subscribe(ctx context.Context, ns libshare.Namespace) (<-chan *SubscriptionResponse, error) { if s.ctx == nil { return nil, fmt.Errorf("service has not been started") } @@ -133,7 +133,7 @@ func (s *Service) Subscribe(ctx context.Context, ns gosquare.Namespace) (<-chan var blobs []*Blob var err error for { - blobs, err = s.getAll(ctx, header, []gosquare.Namespace{ns}) + blobs, err = s.getAll(ctx, header, []libshare.Namespace{ns}) if ctx.Err() != nil { // context canceled, continuing would lead to unexpected missed heights for the client log.Debugw("blobsub: canceling subscription due to user ctx closing", "namespace", ns.ID()) @@ -170,20 +170,20 @@ func (s *Service) Subscribe(ctx context.Context, ns gosquare.Namespace) (<-chan func (s *Service) Submit(ctx context.Context, blobs []*Blob, txConfig *SubmitOptions) (uint64, error) { log.Debugw("submitting blobs", "amount", len(blobs)) - squareBlobs := make([]*gosquare.Blob, len(blobs)) + libBlobs := make([]*libshare.Blob, len(blobs)) for i := range blobs { namespace := blobs[i].Namespace() - if err := gosquare.ValidateForData(namespace); err != nil { + if err := libshare.ValidateForData(namespace); err != nil { return 0, err } - if !gosquare.IsBlobNamespace(namespace) { + if !libshare.IsBlobNamespace(namespace) { return 0, fmt.Errorf("not allowed namespace %s were used to build the blob", namespace.ID()) } - squareBlobs[i] = blobs[i].Blob + libBlobs[i] = blobs[i].Blob } - resp, err := s.blobSubmitter.SubmitPayForBlob(ctx, squareBlobs, txConfig) + resp, err := s.blobSubmitter.SubmitPayForBlob(ctx, libBlobs, txConfig) if err != nil { return 0, err } @@ -197,7 +197,7 @@ func (s *Service) Submit(ctx context.Context, blobs []*Blob, txConfig *SubmitOpt func (s *Service) Get( ctx context.Context, height uint64, - namespace gosquare.Namespace, + namespace libshare.Namespace, commitment Commitment, ) (blob *Blob, err error) { ctx, span := tracer.Start(ctx, "get") @@ -223,7 +223,7 @@ func (s *Service) Get( func (s *Service) GetProof( ctx context.Context, height uint64, - namespace gosquare.Namespace, + namespace libshare.Namespace, commitment Commitment, ) (proof *Proof, err error) { ctx, span := tracer.Start(ctx, "get-proof") @@ -252,7 +252,7 @@ func (s *Service) GetProof( // the user will receive all found blobs along with a combined error message. // // All blobs will preserve the order of the namespaces that were requested. -func (s *Service) GetAll(ctx context.Context, height uint64, namespaces []gosquare.Namespace) ([]*Blob, error) { +func (s *Service) GetAll(ctx context.Context, height uint64, namespaces []libshare.Namespace) ([]*Blob, error) { header, err := s.headerGetter(ctx, height) if err != nil { return nil, err @@ -264,7 +264,7 @@ func (s *Service) GetAll(ctx context.Context, height uint64, namespaces []gosqua func (s *Service) getAll( ctx context.Context, header *header.ExtendedHeader, - namespaces []gosquare.Namespace, + namespaces []libshare.Namespace, ) ([]*Blob, error) { height := header.Height() var ( @@ -274,7 +274,7 @@ func (s *Service) getAll( ) for i, namespace := range namespaces { wg.Add(1) - go func(i int, namespace gosquare.Namespace) { + go func(i int, namespace libshare.Namespace) { log.Debugw("retrieving all blobs from", "namespace", namespace.String(), "height", height) defer wg.Done() @@ -303,7 +303,7 @@ func (s *Service) getAll( func (s *Service) Included( ctx context.Context, height uint64, - namespace gosquare.Namespace, + namespace libshare.Namespace, proof *Proof, commitment Commitment, ) (_ bool, err error) { @@ -338,7 +338,7 @@ func (s *Service) Included( func (s *Service) retrieve( ctx context.Context, height uint64, - namespace gosquare.Namespace, + namespace libshare.Namespace, sharesParser *parser, ) (_ *Blob, _ *Proof, err error) { log.Infow("requesting blob", @@ -386,7 +386,7 @@ func (s *Service) retrieve( attribute.Int64("eds-size", int64(len(header.DAH.RowRoots))))) var ( - appShares = make([]gosquare.Share, 0) + appShares = make([]libshare.Share, 0) proofs = make(Proof, 0) ) @@ -405,7 +405,7 @@ func (s *Service) retrieve( for { var ( isComplete bool - shrs []gosquare.Share + shrs []libshare.Share wasEmpty = sharesParser.isEmpty() ) @@ -476,7 +476,7 @@ func (s *Service) retrieve( // them to Blobs. func (s *Service) getBlobs( ctx context.Context, - namespace gosquare.Namespace, + namespace libshare.Namespace, header *header.ExtendedHeader, ) (_ []*Blob, err error) { ctx, span := tracer.Start(ctx, "get-blobs") @@ -502,7 +502,7 @@ func (s *Service) getBlobs( func (s *Service) GetCommitmentProof( ctx context.Context, height uint64, - namespace gosquare.Namespace, + namespace libshare.Namespace, shareCommitment []byte, ) (*CommitmentProof, error) { log.Debugw("proving share commitment", "height", height, "commitment", shareCommitment, "namespace", namespace) @@ -564,8 +564,8 @@ func (s *Service) GetCommitmentProof( func ProveCommitment( eds *rsmt2d.ExtendedDataSquare, - namespace gosquare.Namespace, - blobShares []gosquare.Share, + namespace libshare.Namespace, + blobShares []libshare.Share, ) (*CommitmentProof, error) { // find the blob shares in the EDS blobSharesStartIndex := -1 @@ -588,7 +588,7 @@ func ProveCommitment( sharesProof, err := pkgproof.NewShareInclusionProofFromEDS( eds, namespace, - gosquare.NewRange(blobSharesStartIndex, blobSharesStartIndex+len(blobShares)), + libshare.NewRange(blobSharesStartIndex, blobSharesStartIndex+len(blobShares)), ) if err != nil { return nil, err @@ -649,7 +649,7 @@ func ProveCommitment( // computeSubtreeRoots takes a set of shares and ranges and returns the corresponding subtree roots. // the offset is the number of shares that are before the subtree roots we're calculating. -func computeSubtreeRoots(shares []gosquare.Share, ranges []nmt.LeafRange, offset int) ([][]byte, error) { +func computeSubtreeRoots(shares []libshare.Share, ranges []nmt.LeafRange, offset int) ([][]byte, error) { if len(shares) == 0 { return nil, fmt.Errorf("cannot compute subtree roots for an empty shares list") } @@ -664,7 +664,7 @@ func computeSubtreeRoots(shares []gosquare.Share, ranges []nmt.LeafRange, offset tree := nmt.New( appconsts.NewBaseHashFunc(), nmt.IgnoreMaxNamespace(true), - nmt.NamespaceIDSize(gosquare.NamespaceSize), + nmt.NamespaceIDSize(libshare.NamespaceSize), ) for _, sh := range shares { leafData := make([]byte, 0) diff --git a/blob/service_test.go b/blob/service_test.go index fe61b49c08..473b9d457e 100644 --- a/blob/service_test.go +++ b/blob/service_test.go @@ -26,7 +26,7 @@ import ( squarens "github.com/celestiaorg/go-square/namespace" appshares "github.com/celestiaorg/go-square/shares" "github.com/celestiaorg/go-square/v2/inclusion" - gosquare "github.com/celestiaorg/go-square/v2/share" + libshare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt" "github.com/celestiaorg/rsmt2d" @@ -52,14 +52,14 @@ func TestBlobService_Get(t *testing.T) { blobSize3 = 12 ) - appBlobs, err := blobtest.GenerateV0Blobs([]int{blobSize0, blobSize1}, false) + libBlobs, err := blobtest.GenerateV0Blobs([]int{blobSize0, blobSize1}, false) require.NoError(t, err) - blobsWithDiffNamespaces, err := convertBlobs(appBlobs...) + blobsWithDiffNamespaces, err := convertBlobs(libBlobs...) require.NoError(t, err) - appBlobs, err = blobtest.GenerateV0Blobs([]int{blobSize2, blobSize3}, true) + libBlobs, err = blobtest.GenerateV0Blobs([]int{blobSize2, blobSize3}, true) require.NoError(t, err) - blobsWithSameNamespace, err := convertBlobs(appBlobs...) + blobsWithSameNamespace, err := convertBlobs(libBlobs...) require.NoError(t, err) blobs := slices.Concat(blobsWithDiffNamespaces, blobsWithSameNamespace) @@ -94,7 +94,7 @@ func TestBlobService_Get(t *testing.T) { { name: "get all with the same namespace", doFn: func() (interface{}, error) { - return service.GetAll(ctx, 1, []gosquare.Namespace{blobsWithSameNamespace[0].Namespace()}) + return service.GetAll(ctx, 1, []libshare.Namespace{blobsWithSameNamespace[0].Namespace()}) }, expectedResult: func(res interface{}, err error) { require.NoError(t, err) @@ -123,7 +123,7 @@ func TestBlobService_Get(t *testing.T) { blobsWithDiffNamespaces[1].Commitment, ) require.NoError(t, err) - b23, err := service.GetAll(ctx, 1, []gosquare.Namespace{blobsWithSameNamespace[0].Namespace()}) + b23, err := service.GetAll(ctx, 1, []libshare.Namespace{blobsWithSameNamespace[0].Namespace()}) require.NoError(t, err) return []*Blob{b0, b1, b23[0], b23[1]}, nil }, @@ -159,10 +159,10 @@ func TestBlobService_Get(t *testing.T) { { name: "get all with different namespaces", doFn: func() (interface{}, error) { - nid, err := gosquare.NewV0Namespace(tmrand.Bytes(7)) + nid, err := libshare.NewV0Namespace(tmrand.Bytes(7)) require.NoError(t, err) b, err := service.GetAll(ctx, 1, - []gosquare.Namespace{ + []libshare.Namespace{ blobsWithDiffNamespaces[0].Namespace(), nid, blobsWithDiffNamespaces[1].Namespace(), }, @@ -202,9 +202,9 @@ func TestBlobService_Get(t *testing.T) { { name: "get invalid blob", doFn: func() (interface{}, error) { - appBlob, err := blobtest.GenerateV0Blobs([]int{10}, false) + libBlob, err := blobtest.GenerateV0Blobs([]int{10}, false) require.NoError(t, err) - blob, err := convertBlobs(appBlob...) + blob, err := convertBlobs(libBlob...) require.NoError(t, err) b, err := service.Get(ctx, 1, blob[0].Namespace(), blob[0].Commitment) @@ -236,7 +236,7 @@ func TestBlobService_Get(t *testing.T) { proof, ok := res.(*Proof) assert.True(t, ok) - verifyFn := func(t *testing.T, rawShares [][]byte, proof *Proof, namespace gosquare.Namespace) { + verifyFn := func(t *testing.T, rawShares [][]byte, proof *Proof, namespace libshare.Namespace) { for _, row := range header.DAH.RowRoots { to := 0 for _, p := range *proof { @@ -253,7 +253,7 @@ func TestBlobService_Get(t *testing.T) { rawShares, err := BlobsToShares(blobsWithDiffNamespaces[1]) require.NoError(t, err) - verifyFn(t, gosquare.ToBytes(rawShares), proof, blobsWithDiffNamespaces[1].Namespace()) + verifyFn(t, libshare.ToBytes(rawShares), proof, blobsWithDiffNamespaces[1].Namespace()) }, }, { @@ -302,9 +302,9 @@ func TestBlobService_Get(t *testing.T) { { name: "not included", doFn: func() (interface{}, error) { - appBlob, err := blobtest.GenerateV0Blobs([]int{10}, false) + libBlob, err := blobtest.GenerateV0Blobs([]int{10}, false) require.NoError(t, err) - blob, err := convertBlobs(appBlob...) + blob, err := convertBlobs(libBlob...) require.NoError(t, err) proof, err := service.GetProof(ctx, 1, @@ -358,9 +358,9 @@ func TestBlobService_Get(t *testing.T) { { name: "empty result and err when blobs were not found ", doFn: func() (interface{}, error) { - nid, err := gosquare.NewV0Namespace(tmrand.Bytes(squarens.NamespaceVersionZeroIDSize)) + nid, err := libshare.NewV0Namespace(tmrand.Bytes(squarens.NamespaceVersionZeroIDSize)) require.NoError(t, err) - return service.GetAll(ctx, 1, []gosquare.Namespace{nid}) + return service.GetAll(ctx, 1, []libshare.Namespace{nid}) }, expectedResult: func(i interface{}, err error) { blobs, ok := i.([]*Blob) @@ -417,7 +417,7 @@ func TestBlobService_Get(t *testing.T) { GetSharesByNamespace(gomock.Any(), gomock.Any(), gomock.Any()). DoAndReturn( func( - ctx context.Context, h *header.ExtendedHeader, ns gosquare.Namespace, + ctx context.Context, h *header.ExtendedHeader, ns libshare.Namespace, ) (shwap.NamespaceData, error) { if ns.Equals(blobsWithDiffNamespaces[0].Namespace()) { return nil, errors.New("internal error") @@ -427,7 +427,7 @@ func TestBlobService_Get(t *testing.T) { service.shareGetter = getterWrapper return service.GetAll(ctx, 1, - []gosquare.Namespace{ + []libshare.Namespace{ blobsWithDiffNamespaces[0].Namespace(), blobsWithSameNamespace[0].Namespace(), }, @@ -460,21 +460,21 @@ func TestService_GetSingleBlobWithoutPadding(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), time.Second*5) t.Cleanup(cancel) - appBlob, err := blobtest.GenerateV0Blobs([]int{9, 5}, true) + libBlob, err := blobtest.GenerateV0Blobs([]int{9, 5}, true) require.NoError(t, err) - blobs, err := convertBlobs(appBlob...) + blobs, err := convertBlobs(libBlob...) require.NoError(t, err) - padding0, err := gosquare.NamespacePaddingShare(blobs[0].Namespace(), gosquare.ShareVersionZero) + padding0, err := libshare.NamespacePaddingShare(blobs[0].Namespace(), libshare.ShareVersionZero) require.NoError(t, err) - padding1, err := gosquare.NamespacePaddingShare(blobs[1].Namespace(), gosquare.ShareVersionZero) + padding1, err := libshare.NamespacePaddingShare(blobs[1].Namespace(), libshare.ShareVersionZero) require.NoError(t, err) rawShares0, err := BlobsToShares(blobs[0]) require.NoError(t, err) rawShares1, err := BlobsToShares(blobs[1]) require.NoError(t, err) - rawShares := make([]gosquare.Share, 0) + rawShares := make([]libshare.Share, 0) rawShares = append(rawShares, append(rawShares0, padding0)...) rawShares = append(rawShares, append(rawShares1, padding1)...) service := createService(ctx, t, rawShares) @@ -501,9 +501,9 @@ func TestService_Get(t *testing.T) { sizes := []int{1, 6, 3, 2, 4, 6, 8, 2, 15, 17} - appBlobs, err := blobtest.GenerateV0Blobs(sizes, true) + libBlobs, err := blobtest.GenerateV0Blobs(sizes, true) require.NoError(t, err) - blobs, err := convertBlobs(appBlobs...) + blobs, err := convertBlobs(libBlobs...) require.NoError(t, err) shares, err := BlobsToShares(blobs...) @@ -538,15 +538,15 @@ func TestService_GetAllWithoutPadding(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), time.Second*5) t.Cleanup(cancel) - appBlob, err := blobtest.GenerateV0Blobs([]int{9, 5, 15, 4, 24}, true) + libBlob, err := blobtest.GenerateV0Blobs([]int{9, 5, 15, 4, 24}, true) require.NoError(t, err) - blobs, err := convertBlobs(appBlob...) + blobs, err := convertBlobs(libBlob...) require.NoError(t, err) - rawShares := make([]gosquare.Share, 0) + rawShares := make([]libshare.Share, 0) require.NoError(t, err) - padding, err := gosquare.NamespacePaddingShare(blobs[0].Namespace(), gosquare.ShareVersionZero) + padding, err := libshare.NamespacePaddingShare(blobs[0].Namespace(), libshare.ShareVersionZero) require.NoError(t, err) for i := 0; i < 2; i++ { @@ -568,7 +568,7 @@ func TestService_GetAllWithoutPadding(t *testing.T) { rawShares = append(rawShares, sh...) service := createService(ctx, t, rawShares) - newBlobs, err := service.GetAll(ctx, 1, []gosquare.Namespace{blobs[0].Namespace()}) + newBlobs, err := service.GetAll(ctx, 1, []libshare.Namespace{blobs[0].Namespace()}) require.NoError(t, err) assert.Equal(t, len(newBlobs), len(blobs)) @@ -591,13 +591,13 @@ func TestService_GetAllWithoutPadding(t *testing.T) { } func TestAllPaddingSharesInEDS(t *testing.T) { - nid, err := gosquare.NewV0Namespace(tmrand.Bytes(7)) + nid, err := libshare.NewV0Namespace(tmrand.Bytes(7)) require.NoError(t, err) - padding, err := gosquare.NamespacePaddingShare(nid, gosquare.ShareVersionZero) + padding, err := libshare.NamespacePaddingShare(nid, libshare.ShareVersionZero) require.NoError(t, err) - rawShares := make([]gosquare.Share, 16) + rawShares := make([]libshare.Share, 16) for i := 0; i < 16; i++ { rawShares[i] = padding } @@ -606,29 +606,29 @@ func TestAllPaddingSharesInEDS(t *testing.T) { t.Cleanup(cancel) service := createService(ctx, t, rawShares) - newBlobs, err := service.GetAll(ctx, 1, []gosquare.Namespace{nid}) + newBlobs, err := service.GetAll(ctx, 1, []libshare.Namespace{nid}) require.NoError(t, err) assert.Empty(t, newBlobs) } func TestSkipPaddingsAndRetrieveBlob(t *testing.T) { - nid := gosquare.RandomBlobNamespace() - padding, err := gosquare.NamespacePaddingShare(nid, gosquare.ShareVersionZero) + nid := libshare.RandomBlobNamespace() + padding, err := libshare.NamespacePaddingShare(nid, libshare.ShareVersionZero) require.NoError(t, err) - rawShares := make([]gosquare.Share, 0, 64) + rawShares := make([]libshare.Share, 0, 64) for i := 0; i < 58; i++ { rawShares = append(rawShares, padding) } - size := blobtest.RawBlobSize(gosquare.FirstSparseShareContentSize * 6) - ns, err := gosquare.NewNamespace(nid.Version(), nid.ID()) + size := blobtest.RawBlobSize(libshare.FirstSparseShareContentSize * 6) + ns, err := libshare.NewNamespace(nid.Version(), nid.ID()) require.NoError(t, err) data := tmrand.Bytes(size) - appBlob, err := gosquare.NewBlob(ns, data, gosquare.ShareVersionZero, nil) + libBlob, err := libshare.NewBlob(ns, data, libshare.ShareVersionZero, nil) require.NoError(t, err) - blobs, err := convertBlobs(appBlob) + blobs, err := convertBlobs(libBlob) require.NoError(t, err) sh, err := BlobsToShares(blobs[0]) require.NoError(t, err) @@ -639,7 +639,7 @@ func TestSkipPaddingsAndRetrieveBlob(t *testing.T) { t.Cleanup(cancel) service := createService(ctx, t, rawShares) - newBlob, err := service.GetAll(ctx, 1, []gosquare.Namespace{nid}) + newBlob, err := service.GetAll(ctx, 1, []libshare.Namespace{nid}) require.NoError(t, err) require.Len(t, newBlob, 1) require.True(t, newBlob[0].compareCommitments(blobs[0].Commitment)) @@ -649,9 +649,9 @@ func TestService_Subscribe(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), time.Second*10) t.Cleanup(cancel) - appBlobs, err := blobtest.GenerateV0Blobs([]int{16, 16, 16}, true) + libBlobs, err := blobtest.GenerateV0Blobs([]int{16, 16, 16}, true) require.NoError(t, err) - blobs, err := convertBlobs(appBlobs...) + blobs, err := convertBlobs(libBlobs...) require.NoError(t, err) service := createServiceWithSub(ctx, t, blobs) @@ -675,7 +675,7 @@ func TestService_Subscribe(t *testing.T) { }) t.Run("subscription with no matching blobs", func(t *testing.T) { - ns, err := gosquare.NewV0Namespace([]byte("nonexist")) + ns, err := libshare.NewV0Namespace([]byte("nonexist")) require.NoError(t, err) subCh, err := service.Subscribe(ctx, ns) @@ -754,18 +754,18 @@ func TestService_Subscribe_MultipleNamespaces(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), time.Second*10) t.Cleanup(cancel) - appBlobs1, err := blobtest.GenerateV0Blobs([]int{100, 100}, true) + libBlobs1, err := blobtest.GenerateV0Blobs([]int{100, 100}, true) require.NoError(t, err) - appBlobs2, err := blobtest.GenerateV0Blobs([]int{100, 100}, true) - for i := range appBlobs2 { - // if we don't do this, appBlobs1 and appBlobs2 will share a NS - appBlobs2[i].Namespace().ID()[len(appBlobs2[i].Namespace().ID())-1] = 0xDE + libBlobs2, err := blobtest.GenerateV0Blobs([]int{100, 100}, true) + for i := range libBlobs2 { + // if we don't do this, libBlobs1 and libBlobs2 will share a NS + libBlobs2[i].Namespace().ID()[len(libBlobs2[i].Namespace().ID())-1] = 0xDE } require.NoError(t, err) - blobs1, err := convertBlobs(appBlobs1...) + blobs1, err := convertBlobs(libBlobs1...) require.NoError(t, err) - blobs2, err := convertBlobs(appBlobs2...) + blobs2, err := convertBlobs(libBlobs2...) require.NoError(t, err) //nolint: gocritic @@ -815,10 +815,10 @@ func TestService_Subscribe_MultipleNamespaces(t *testing.T) { func BenchmarkGetByCommitment(b *testing.B) { ctx, cancel := context.WithTimeout(context.Background(), time.Second*5) b.Cleanup(cancel) - appBlobs, err := blobtest.GenerateV0Blobs([]int{32, 32}, true) + libBlobs, err := blobtest.GenerateV0Blobs([]int{32, 32}, true) require.NoError(b, err) - blobs, err := convertBlobs(appBlobs...) + blobs, err := convertBlobs(libBlobs...) require.NoError(b, err) shares, err := BlobsToShares(blobs...) @@ -879,7 +879,7 @@ func createServiceWithSub(ctx context.Context, t testing.TB, blobs []*Blob) *Ser shareGetter := mock.NewMockGetter(ctrl) shareGetter.EXPECT().GetSharesByNamespace(gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes(). - DoAndReturn(func(ctx context.Context, h *header.ExtendedHeader, ns gosquare.Namespace) (shwap.NamespaceData, error) { + DoAndReturn(func(ctx context.Context, h *header.ExtendedHeader, ns libshare.Namespace) (shwap.NamespaceData, error) { idx := int(h.Height()) - 1 accessor := &eds.Rsmt2D{ExtendedDataSquare: edsses[idx]} nd, err := eds.NamespaceData(ctx, accessor, ns) @@ -888,10 +888,10 @@ func createServiceWithSub(ctx context.Context, t testing.TB, blobs []*Blob) *Ser return NewService(nil, shareGetter, fn, fn2) } -func createService(ctx context.Context, t testing.TB, shares []gosquare.Share) *Service { +func createService(ctx context.Context, t testing.TB, shares []libshare.Share) *Service { odsSize := int(utils.SquareSize(len(shares))) square, err := rsmt2d.ComputeExtendedDataSquare( - gosquare.ToBytes(shares), + libshare.ToBytes(shares), share.DefaultRSMT2DCodec(), wrapper.NewConstructor(uint64(odsSize))) require.NoError(t, err) @@ -900,12 +900,12 @@ func createService(ctx context.Context, t testing.TB, shares []gosquare.Share) * ctrl := gomock.NewController(t) shareGetter := mock.NewMockGetter(ctrl) shareGetter.EXPECT().GetSharesByNamespace(gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes(). - DoAndReturn(func(ctx context.Context, h *header.ExtendedHeader, ns gosquare.Namespace) (shwap.NamespaceData, error) { + DoAndReturn(func(ctx context.Context, h *header.ExtendedHeader, ns libshare.Namespace) (shwap.NamespaceData, error) { nd, err := eds.NamespaceData(ctx, accessor, ns) return nd, err }) shareGetter.EXPECT().GetShare(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes(). - DoAndReturn(func(ctx context.Context, h *header.ExtendedHeader, row, col int) (gosquare.Share, error) { + DoAndReturn(func(ctx context.Context, h *header.ExtendedHeader, row, col int) (libshare.Share, error) { s, err := accessor.Sample(ctx, row, col) return s.Share, err }) @@ -996,8 +996,8 @@ func proveAndVerifyShareCommitments(t *testing.T, blobSize int) { func generateCommitmentProofFromBlock( t *testing.T, eds *rsmt2d.ExtendedDataSquare, - ns gosquare.Namespace, - blob *gosquare.Blob, + ns libshare.Namespace, + blob *libshare.Blob, dataRoot []byte, ) CommitmentProof { // create the blob from the data @@ -1026,7 +1026,7 @@ func generateCommitmentProofFromBlock( sharesProof, err := pkgproof.NewShareInclusionProofFromEDS( eds, ns, - gosquare.NewRange(startShareIndex, startShareIndex+len(blobShares)), + libshare.NewRange(startShareIndex, startShareIndex+len(blobShares)), ) require.NoError(t, err) require.NoError(t, sharesProof.Validate(dataRoot)) diff --git a/cmd/util.go b/cmd/util.go index c2609b1266..9e280eeeee 100644 --- a/cmd/util.go +++ b/cmd/util.go @@ -11,7 +11,7 @@ import ( "github.com/spf13/cobra" flag "github.com/spf13/pflag" - gosquare "github.com/celestiaorg/go-square/v2/share" + libshare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/celestia-node/nodebuilder/core" "github.com/celestiaorg/celestia-node/nodebuilder/gateway" @@ -48,14 +48,14 @@ func PrintOutput(data interface{}, err error, formatData func(interface{}) inter // ParseV0Namespace parses a namespace from a base64 or hex string. The param // is expected to be the user-specified portion of a v0 namespace ID (i.e. the // last 10 bytes). -func ParseV0Namespace(param string) (gosquare.Namespace, error) { +func ParseV0Namespace(param string) (libshare.Namespace, error) { userBytes, err := DecodeToBytes(param) if err != nil { - return gosquare.Namespace{}, err + return libshare.Namespace{}, err } // if the namespace ID is <= 10 bytes, left pad it with 0s - return gosquare.NewV0Namespace(userBytes) + return libshare.NewV0Namespace(userBytes) } // DecodeToBytes decodes a Base64 or hex input string into a byte slice. diff --git a/cmd/util_test.go b/cmd/util_test.go index 05f6226639..68464ec32d 100644 --- a/cmd/util_test.go +++ b/cmd/util_test.go @@ -6,7 +6,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - gosquare "github.com/celestiaorg/go-square/v2/share" + libshare "github.com/celestiaorg/go-square/v2/share" ) func Test_parseNamespaceID(t *testing.T) { @@ -77,7 +77,7 @@ func Test_parseNamespaceID(t *testing.T) { } assert.NoError(t, err) - ns, err := gosquare.NewNamespaceFromBytes(tc.want) + ns, err := libshare.NewNamespaceFromBytes(tc.want) require.NoError(t, err) assert.Equal(t, ns, got) }) diff --git a/core/eds.go b/core/eds.go index 8fb8989239..ec4b333830 100644 --- a/core/eds.go +++ b/core/eds.go @@ -11,7 +11,7 @@ import ( "github.com/celestiaorg/celestia-app/v3/pkg/wrapper" "github.com/celestiaorg/go-square/shares" libsquare "github.com/celestiaorg/go-square/v2" - gosquare "github.com/celestiaorg/go-square/v2/share" + libshare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt" "github.com/celestiaorg/rsmt2d" @@ -39,7 +39,7 @@ func extendBlock(data types.Data, appVersion uint64, options ...nmt.Option) (*rs if err != nil { return nil, err } - return extendShares(gosquare.ToBytes(square), options...) + return extendShares(libshare.ToBytes(square), options...) } func extendShares(s [][]byte, options ...nmt.Option) (*rsmt2d.ExtendedDataSquare, error) { diff --git a/nodebuilder/blob/blob.go b/nodebuilder/blob/blob.go index f89b58a29e..b8069f82b5 100644 --- a/nodebuilder/blob/blob.go +++ b/nodebuilder/blob/blob.go @@ -3,7 +3,7 @@ package blob import ( "context" - gosquare "github.com/celestiaorg/go-square/v2/share" + libshare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/celestia-node/blob" ) @@ -19,7 +19,7 @@ type Module interface { // Uses default wallet registered on the Node. Submit(_ context.Context, _ []*blob.Blob, _ *blob.SubmitOptions) (height uint64, _ error) // Get retrieves the blob by commitment under the given namespace and height. - Get(_ context.Context, height uint64, _ gosquare.Namespace, _ blob.Commitment) (*blob.Blob, error) + Get(_ context.Context, height uint64, _ libshare.Namespace, _ blob.Commitment) (*blob.Blob, error) // GetAll returns all blobs under the given namespaces at the given height. // If all blobs were found without any errors, the user will receive a list of blobs. // If the BlobService couldn't find any blobs under the requested namespaces, @@ -29,21 +29,21 @@ type Module interface { // the user will receive all found blobs along with a combined error message. // // All blobs will preserve the order of the namespaces that were requested. - GetAll(_ context.Context, height uint64, _ []gosquare.Namespace) ([]*blob.Blob, error) + GetAll(_ context.Context, height uint64, _ []libshare.Namespace) ([]*blob.Blob, error) // GetProof retrieves proofs in the given namespaces at the given height by commitment. - GetProof(_ context.Context, height uint64, _ gosquare.Namespace, _ blob.Commitment) (*blob.Proof, error) + GetProof(_ context.Context, height uint64, _ libshare.Namespace, _ blob.Commitment) (*blob.Proof, error) // Included checks whether a blob's given commitment(Merkle subtree root) is included at // given height and under the namespace. - Included(_ context.Context, height uint64, _ gosquare.Namespace, _ *blob.Proof, _ blob.Commitment) (bool, error) + Included(_ context.Context, height uint64, _ libshare.Namespace, _ *blob.Proof, _ blob.Commitment) (bool, error) // GetCommitmentProof generates a commitment proof for a share commitment. GetCommitmentProof( ctx context.Context, height uint64, - namespace gosquare.Namespace, + namespace libshare.Namespace, shareCommitment []byte, ) (*blob.CommitmentProof, error) // Subscribe to published blobs from the given namespace as they are included. - Subscribe(_ context.Context, _ gosquare.Namespace) (<-chan *blob.SubscriptionResponse, error) + Subscribe(_ context.Context, _ libshare.Namespace) (<-chan *blob.SubscriptionResponse, error) } type API struct { @@ -56,36 +56,36 @@ type API struct { Get func( context.Context, uint64, - gosquare.Namespace, + libshare.Namespace, blob.Commitment, ) (*blob.Blob, error) `perm:"read"` GetAll func( context.Context, uint64, - []gosquare.Namespace, + []libshare.Namespace, ) ([]*blob.Blob, error) `perm:"read"` GetProof func( context.Context, uint64, - gosquare.Namespace, + libshare.Namespace, blob.Commitment, ) (*blob.Proof, error) `perm:"read"` Included func( context.Context, uint64, - gosquare.Namespace, + libshare.Namespace, *blob.Proof, blob.Commitment, ) (bool, error) `perm:"read"` GetCommitmentProof func( ctx context.Context, height uint64, - namespace gosquare.Namespace, + namespace libshare.Namespace, shareCommitment []byte, ) (*blob.CommitmentProof, error) `perm:"read"` Subscribe func( context.Context, - gosquare.Namespace, + libshare.Namespace, ) (<-chan *blob.SubscriptionResponse, error) `perm:"read"` } } @@ -97,20 +97,20 @@ func (api *API) Submit(ctx context.Context, blobs []*blob.Blob, options *blob.Su func (api *API) Get( ctx context.Context, height uint64, - namespace gosquare.Namespace, + namespace libshare.Namespace, commitment blob.Commitment, ) (*blob.Blob, error) { return api.Internal.Get(ctx, height, namespace, commitment) } -func (api *API) GetAll(ctx context.Context, height uint64, namespaces []gosquare.Namespace) ([]*blob.Blob, error) { +func (api *API) GetAll(ctx context.Context, height uint64, namespaces []libshare.Namespace) ([]*blob.Blob, error) { return api.Internal.GetAll(ctx, height, namespaces) } func (api *API) GetProof( ctx context.Context, height uint64, - namespace gosquare.Namespace, + namespace libshare.Namespace, commitment blob.Commitment, ) (*blob.Proof, error) { return api.Internal.GetProof(ctx, height, namespace, commitment) @@ -119,7 +119,7 @@ func (api *API) GetProof( func (api *API) GetCommitmentProof( ctx context.Context, height uint64, - namespace gosquare.Namespace, + namespace libshare.Namespace, shareCommitment []byte, ) (*blob.CommitmentProof, error) { return api.Internal.GetCommitmentProof(ctx, height, namespace, shareCommitment) @@ -128,7 +128,7 @@ func (api *API) GetCommitmentProof( func (api *API) Included( ctx context.Context, height uint64, - namespace gosquare.Namespace, + namespace libshare.Namespace, proof *blob.Proof, commitment blob.Commitment, ) (bool, error) { @@ -137,7 +137,7 @@ func (api *API) Included( func (api *API) Subscribe( ctx context.Context, - namespace gosquare.Namespace, + namespace libshare.Namespace, ) (<-chan *blob.SubscriptionResponse, error) { return api.Internal.Subscribe(ctx, namespace) } diff --git a/nodebuilder/blob/cmd/blob.go b/nodebuilder/blob/cmd/blob.go index 2be5df5c0c..504533d2fc 100644 --- a/nodebuilder/blob/cmd/blob.go +++ b/nodebuilder/blob/cmd/blob.go @@ -11,7 +11,7 @@ import ( "github.com/spf13/cobra" - gosquare "github.com/celestiaorg/go-square/v2/share" + libshare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/celestia-node/blob" cmdnode "github.com/celestiaorg/celestia-node/cmd" @@ -106,7 +106,7 @@ var getAllCmd = &cobra.Command{ return fmt.Errorf("error parsing a namespace: %w", err) } - blobs, err := client.Blob.GetAll(cmd.Context(), height, []gosquare.Namespace{namespace}) + blobs, err := client.Blob.GetAll(cmd.Context(), height, []libshare.Namespace{namespace}) return cmdnode.PrintOutput(blobs, err, formatData(args[1])) }, } diff --git a/nodebuilder/da/service.go b/nodebuilder/da/service.go index ed8e5054b2..aded1f0ea9 100644 --- a/nodebuilder/da/service.go +++ b/nodebuilder/da/service.go @@ -11,7 +11,7 @@ import ( "github.com/rollkit/go-da" "github.com/celestiaorg/celestia-app/v3/pkg/appconsts" - gosquare "github.com/celestiaorg/go-square/v2/share" + libshare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/celestia-node/blob" "github.com/celestiaorg/celestia-node/header" @@ -68,7 +68,7 @@ func (s *Service) Get(ctx context.Context, ids []da.ID, ns da.Namespace) ([]da.B blobs := make([]da.Blob, 0, len(ids)) for _, id := range ids { height, commitment := SplitID(id) - namespace, err := gosquare.NewNamespaceFromBytes(ns) + namespace, err := libshare.NewNamespaceFromBytes(ns) if err != nil { return nil, err } @@ -85,14 +85,14 @@ func (s *Service) Get(ctx context.Context, ids []da.ID, ns da.Namespace) ([]da.B // GetIDs returns IDs of all Blobs located in DA at given height. func (s *Service) GetIDs(ctx context.Context, height uint64, namespace da.Namespace) (*da.GetIDsResult, error) { - ns, err := gosquare.NewNamespaceFromBytes(namespace) + ns, err := libshare.NewNamespaceFromBytes(namespace) if err != nil { return nil, err } var ids []da.ID //nolint:prealloc log.Debugw("getting ids", "height", height, "namespace", ns) - blobs, err := s.blobServ.GetAll(ctx, height, []gosquare.Namespace{ns}) + blobs, err := s.blobServ.GetAll(ctx, height, []libshare.Namespace{ns}) log.Debugw("got ids", "height", height, "namespace", ns) if err != nil { if strings.Contains(err.Error(), blob.ErrBlobNotFound.Error()) { @@ -114,7 +114,7 @@ func (s *Service) GetIDs(ctx context.Context, height uint64, namespace da.Namesp func (s *Service) GetProofs(ctx context.Context, ids []da.ID, namespace da.Namespace) ([]da.Proof, error) { proofs := make([]da.Proof, len(ids)) for i, id := range ids { - ns, err := gosquare.NewNamespaceFromBytes(namespace) + ns, err := libshare.NewNamespaceFromBytes(namespace) if err != nil { return nil, err } @@ -213,7 +213,7 @@ func (s *Service) blobsAndCommitments( blobs := make([]*blob.Blob, 0, len(daBlobs)) commitments := make([]da.Commitment, 0, len(daBlobs)) for _, daBlob := range daBlobs { - ns, err := gosquare.NewNamespaceFromBytes(namespace) + ns, err := libshare.NewNamespaceFromBytes(namespace) if err != nil { return nil, nil, err } @@ -247,7 +247,7 @@ func (s *Service) Validate( proofs[i] = blobProof } for i, id := range ids { - ns, err := gosquare.NewNamespaceFromBytes(namespace) + ns, err := libshare.NewNamespaceFromBytes(namespace) if err != nil { return nil, err } diff --git a/nodebuilder/share/cmd/share.go b/nodebuilder/share/cmd/share.go index b4abbabc52..41fb9bd8f8 100644 --- a/nodebuilder/share/cmd/share.go +++ b/nodebuilder/share/cmd/share.go @@ -8,7 +8,7 @@ import ( "github.com/spf13/cobra" - gosquare "github.com/celestiaorg/go-square/v2/share" + libshare "github.com/celestiaorg/go-square/v2/share" rpc "github.com/celestiaorg/celestia-node/api/rpc/client" cmdnode "github.com/celestiaorg/celestia-node/cmd" @@ -123,7 +123,7 @@ var getShare = &cobra.Command{ s, err := client.Share.GetShare(cmd.Context(), eh, int(row), int(col)) formatter := func(data interface{}) interface{} { - sh, ok := data.(gosquare.Share) + sh, ok := data.(libshare.Share) if !ok { return data } diff --git a/nodebuilder/share/share.go b/nodebuilder/share/share.go index 891198687a..81546ca673 100644 --- a/nodebuilder/share/share.go +++ b/nodebuilder/share/share.go @@ -5,7 +5,7 @@ import ( "github.com/tendermint/tendermint/types" - gosquare "github.com/celestiaorg/go-square/v2/share" + libshare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt" "github.com/celestiaorg/rsmt2d" @@ -21,14 +21,14 @@ var _ Module = (*API)(nil) // GetRangeResult wraps the return value of the GetRange endpoint // because Json-RPC doesn't support more than two return values. type GetRangeResult struct { - Shares []gosquare.Share + Shares []libshare.Share Proof *types.ShareProof } // Module provides access to any data square or block share on the network. // // All Get methods provided on Module follow the following flow: -// 1. Check local storage for the requested gosquare. +// 1. Check local storage for the requested libshare. // 2. If exists // * Load from disk // * Return @@ -46,13 +46,13 @@ type Module interface { // ExtendedHeader are available on the Network. SharesAvailable(context.Context, *header.ExtendedHeader) error // GetShare gets a Share by coordinates in EDS. - GetShare(ctx context.Context, header *header.ExtendedHeader, row, col int) (gosquare.Share, error) + GetShare(ctx context.Context, header *header.ExtendedHeader, row, col int) (libshare.Share, error) // GetEDS gets the full EDS identified by the given extended header. GetEDS(ctx context.Context, header *header.ExtendedHeader) (*rsmt2d.ExtendedDataSquare, error) // GetSharesByNamespace gets all shares from an EDS within the given namespace. // Shares are returned in a row-by-row order if the namespace spans multiple rows. GetSharesByNamespace( - ctx context.Context, header *header.ExtendedHeader, namespace gosquare.Namespace, + ctx context.Context, header *header.ExtendedHeader, namespace libshare.Namespace, ) (NamespacedShares, error) // GetRange gets a list of shares and their corresponding proof. GetRange(ctx context.Context, height uint64, start, end int) (*GetRangeResult, error) @@ -66,7 +66,7 @@ type API struct { ctx context.Context, header *header.ExtendedHeader, row, col int, - ) (gosquare.Share, error) `perm:"read"` + ) (libshare.Share, error) `perm:"read"` GetEDS func( ctx context.Context, header *header.ExtendedHeader, @@ -74,7 +74,7 @@ type API struct { GetSharesByNamespace func( ctx context.Context, header *header.ExtendedHeader, - namespace gosquare.Namespace, + namespace libshare.Namespace, ) (NamespacedShares, error) `perm:"read"` GetRange func( ctx context.Context, @@ -88,7 +88,7 @@ func (api *API) SharesAvailable(ctx context.Context, header *header.ExtendedHead return api.Internal.SharesAvailable(ctx, header) } -func (api *API) GetShare(ctx context.Context, header *header.ExtendedHeader, row, col int) (gosquare.Share, error) { +func (api *API) GetShare(ctx context.Context, header *header.ExtendedHeader, row, col int) (libshare.Share, error) { return api.Internal.GetShare(ctx, header, row, col) } @@ -103,7 +103,7 @@ func (api *API) GetRange(ctx context.Context, height uint64, start, end int) (*G func (api *API) GetSharesByNamespace( ctx context.Context, header *header.ExtendedHeader, - namespace gosquare.Namespace, + namespace libshare.Namespace, ) (NamespacedShares, error) { return api.Internal.GetSharesByNamespace(ctx, header, namespace) } @@ -133,7 +133,7 @@ func (m module) GetRange(ctx context.Context, height uint64, start, end int) (*G return nil, err } - shares, err := gosquare.FromBytes(extendedDataSquare.FlattenedODS()[start:end]) + shares, err := libshare.FromBytes(extendedDataSquare.FlattenedODS()[start:end]) if err != nil { return nil, err } @@ -146,7 +146,7 @@ func (m module) GetRange(ctx context.Context, height uint64, start, end int) (*G func (m module) GetSharesByNamespace( ctx context.Context, header *header.ExtendedHeader, - namespace gosquare.Namespace, + namespace libshare.Namespace, ) (NamespacedShares, error) { nd, err := m.Getter.GetSharesByNamespace(ctx, header, namespace) if err != nil { @@ -156,19 +156,19 @@ func (m module) GetSharesByNamespace( } // NamespacedShares represents all shares with proofs within a specific namespace of an EDS. -// This is a copy of the gosquare.NamespacedShares type, that is used to avoid breaking changes +// This is a copy of the libshare.NamespacedShares type, that is used to avoid breaking changes // in the API. type NamespacedShares []NamespacedRow // NamespacedRow represents all shares with proofs within a specific namespace of a single EDS row. type NamespacedRow struct { - Shares []gosquare.Share `json:"shares"` + Shares []libshare.Share `json:"shares"` Proof *nmt.Proof `json:"proof"` } // Flatten returns the concatenated slice of all NamespacedRow shares. -func (ns NamespacedShares) Flatten() []gosquare.Share { - var shares []gosquare.Share +func (ns NamespacedShares) Flatten() []libshare.Share { + var shares []libshare.Share for _, row := range ns { shares = append(shares, row.Shares...) } diff --git a/nodebuilder/state/state.go b/nodebuilder/state/state.go index d1c2193a33..89365aec90 100644 --- a/nodebuilder/state/state.go +++ b/nodebuilder/state/state.go @@ -5,7 +5,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/staking/types" - gosquare "github.com/celestiaorg/go-square/v2/share" + libshare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/celestia-node/state" ) @@ -39,7 +39,7 @@ type Module interface { // SubmitPayForBlob builds, signs and submits a PayForBlob transaction. SubmitPayForBlob( ctx context.Context, - blobs []*gosquare.Blob, + blobs []*libshare.Blob, config *state.TxConfig, ) (*state.TxResponse, error) // CancelUnbondingDelegation cancels a user's pending undelegation from a validator. @@ -114,7 +114,7 @@ type API struct { ) (*state.TxResponse, error) `perm:"write"` SubmitPayForBlob func( ctx context.Context, - blobs []*gosquare.Blob, + blobs []*libshare.Blob, config *state.TxConfig, ) (*state.TxResponse, error) `perm:"write"` CancelUnbondingDelegation func( @@ -188,7 +188,7 @@ func (api *API) Transfer( func (api *API) SubmitPayForBlob( ctx context.Context, - blobs []*gosquare.Blob, + blobs []*libshare.Blob, config *state.TxConfig, ) (*state.TxResponse, error) { return api.Internal.SubmitPayForBlob(ctx, blobs, config) diff --git a/nodebuilder/state/stub.go b/nodebuilder/state/stub.go index fb8a1402f2..530d42441c 100644 --- a/nodebuilder/state/stub.go +++ b/nodebuilder/state/stub.go @@ -6,7 +6,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/staking/types" - gosquare "github.com/celestiaorg/go-square/v2/share" + libshare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/celestia-node/state" ) @@ -44,7 +44,7 @@ func (s stubbedStateModule) Transfer( func (s stubbedStateModule) SubmitPayForBlob( context.Context, - []*gosquare.Blob, + []*libshare.Blob, *state.TxConfig, ) (*state.TxResponse, error) { return nil, ErrNoStateAccess diff --git a/nodebuilder/store.go b/nodebuilder/store.go index dbd323d1ba..ead6645c5f 100644 --- a/nodebuilder/store.go +++ b/nodebuilder/store.go @@ -17,7 +17,7 @@ import ( dsbadger "github.com/ipfs/go-ds-badger4" "github.com/mitchellh/go-homedir" - gosquare "github.com/celestiaorg/go-square/v2/share" + libshare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/celestia-node/libs/keystore" nodemod "github.com/celestiaorg/celestia-node/nodebuilder/node" @@ -276,10 +276,10 @@ func dataPath(base string) string { func constraintBadgerConfig() *dsbadger.Options { opts := dsbadger.DefaultOptions // this must be copied // ValueLog: - // 2mib default => gosquare.ShareSize - makes sure headers and samples are stored in value log + // 2mib default => libshare.ShareSize - makes sure headers and samples are stored in value log // This *tremendously* reduces the amount of memory used by the node, up to 10 times less during // compaction - opts.ValueThreshold = gosquare.ShareSize + opts.ValueThreshold = libshare.ShareSize // make sure we don't have any limits for stored headers opts.ValueLogMaxEntries = 100000000 // run value log GC more often to spread the work over time diff --git a/nodebuilder/tests/api_test.go b/nodebuilder/tests/api_test.go index 09318988fd..524c9f310f 100644 --- a/nodebuilder/tests/api_test.go +++ b/nodebuilder/tests/api_test.go @@ -107,14 +107,14 @@ func TestBlobRPC(t *testing.T) { rpcClient := getAdminClient(ctx, bridge, t) - appBlobs, err := blobtest.GenerateV0Blobs([]int{8}, false) + libBlobs, err := blobtest.GenerateV0Blobs([]int{8}, false) require.NoError(t, err) newBlob, err := blob.NewBlob( - appBlobs[0].ShareVersion(), - appBlobs[0].Namespace(), - appBlobs[0].Data(), - appBlobs[0].Signer(), + libBlobs[0].ShareVersion(), + libBlobs[0].Namespace(), + libBlobs[0].Data(), + libBlobs[0].Signer(), ) require.NoError(t, err) diff --git a/nodebuilder/tests/blob_test.go b/nodebuilder/tests/blob_test.go index 4d39588b0f..7e83ddf5b6 100644 --- a/nodebuilder/tests/blob_test.go +++ b/nodebuilder/tests/blob_test.go @@ -13,7 +13,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - gosquare "github.com/celestiaorg/go-square/v2/share" + libshare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/celestia-node/blob" "github.com/celestiaorg/celestia-node/blob/blobtest" @@ -27,14 +27,14 @@ func TestBlobModule(t *testing.T) { t.Cleanup(cancel) sw := swamp.NewSwamp(t, swamp.WithBlockTime(time.Second*1)) - appBlobs0, err := blobtest.GenerateV0Blobs([]int{8, 4}, true) + libBlobs0, err := blobtest.GenerateV0Blobs([]int{8, 4}, true) require.NoError(t, err) - appBlobs1, err := blobtest.GenerateV0Blobs([]int{4}, false) + libBlobs1, err := blobtest.GenerateV0Blobs([]int{4}, false) require.NoError(t, err) - blobs := make([]*blob.Blob, 0, len(appBlobs0)+len(appBlobs1)) + blobs := make([]*blob.Blob, 0, len(libBlobs0)+len(libBlobs1)) - for _, squareBlob := range append(appBlobs0, appBlobs1...) { - blob, err := convert(squareBlob) + for _, libBlob := range append(libBlobs0, libBlobs1...) { + blob, err := convert(libBlob) require.NoError(t, err) blobs = append(blobs, blob) } @@ -87,9 +87,9 @@ func TestBlobModule(t *testing.T) { doFn: func(t *testing.T) { // https://github.com/celestiaorg/celestia-node/issues/2915 time.Sleep(time.Second) - newBlobs, err := fullClient.Blob.GetAll(ctx, height, []gosquare.Namespace{blobs[0].Namespace()}) + newBlobs, err := fullClient.Blob.GetAll(ctx, height, []libshare.Namespace{blobs[0].Namespace()}) require.NoError(t, err) - require.Len(t, newBlobs, len(appBlobs0)) + require.Len(t, newBlobs, len(libBlobs0)) require.True(t, bytes.Equal(blobs[0].Commitment, newBlobs[0].Commitment)) require.True(t, bytes.Equal(blobs[1].Commitment, newBlobs[1].Commitment)) }, @@ -116,9 +116,9 @@ func TestBlobModule(t *testing.T) { { name: "Not Found", doFn: func(t *testing.T) { - appBlob, err := blobtest.GenerateV0Blobs([]int{4}, false) + libBlob, err := blobtest.GenerateV0Blobs([]int{4}, false) require.NoError(t, err) - newBlob, err := convert(appBlob[0]) + newBlob, err := convert(libBlob[0]) require.NoError(t, err) b, err := fullClient.Blob.Get(ctx, height, newBlob.Namespace(), newBlob.Commitment) @@ -126,7 +126,7 @@ func TestBlobModule(t *testing.T) { require.Error(t, err) require.ErrorContains(t, err, blob.ErrBlobNotFound.Error()) - blobs, err := fullClient.Blob.GetAll(ctx, height, []gosquare.Namespace{newBlob.Namespace()}) + blobs, err := fullClient.Blob.GetAll(ctx, height, []libshare.Namespace{newBlob.Namespace()}) require.NoError(t, err) assert.Empty(t, blobs) }, @@ -134,9 +134,9 @@ func TestBlobModule(t *testing.T) { { name: "Submit equal blobs", doFn: func(t *testing.T) { - appBlob, err := blobtest.GenerateV0Blobs([]int{8, 4}, true) + libBlob, err := blobtest.GenerateV0Blobs([]int{8, 4}, true) require.NoError(t, err) - b, err := convert(appBlob[0]) + b, err := convert(libBlob[0]) require.NoError(t, err) height, err := fullClient.Blob.Submit(ctx, []*blob.Blob{b, b}, state.NewTxConfig()) @@ -201,8 +201,8 @@ func TestBlobModule(t *testing.T) { } } -// convert converts a gosquare.Blob to a blob.Blob. +// convert converts a libshare.Blob to a blob.Blob. // convert may be deduplicated with convertBlobs from the blob package. -func convert(squareBlob *gosquare.Blob) (nodeBlob *blob.Blob, err error) { - return blob.NewBlob(squareBlob.ShareVersion(), squareBlob.Namespace(), squareBlob.Data(), squareBlob.Signer()) +func convert(libBlob *libshare.Blob) (nodeBlob *blob.Blob, err error) { + return blob.NewBlob(libBlob.ShareVersion(), libBlob.Namespace(), libBlob.Data(), libBlob.Signer()) } diff --git a/nodebuilder/tests/da_test.go b/nodebuilder/tests/da_test.go index 54221a1048..ecca83ae81 100644 --- a/nodebuilder/tests/da_test.go +++ b/nodebuilder/tests/da_test.go @@ -13,7 +13,7 @@ import ( "github.com/stretchr/testify/require" "github.com/celestiaorg/celestia-app/v3/pkg/appconsts" - gosquare "github.com/celestiaorg/go-square/v2/share" + libshare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/celestia-node/blob" "github.com/celestiaorg/celestia-node/blob/blobtest" @@ -27,23 +27,23 @@ func TestDaModule(t *testing.T) { t.Cleanup(cancel) sw := swamp.NewSwamp(t, swamp.WithBlockTime(time.Second)) - namespace, err := gosquare.NewV0Namespace([]byte("namespace")) + namespace, err := libshare.NewV0Namespace([]byte("namespace")) require.NoError(t, err) require.False(t, namespace.IsReserved()) - appBlobs0, err := blobtest.GenerateV0Blobs([]int{8, 4}, true) + libBlobs0, err := blobtest.GenerateV0Blobs([]int{8, 4}, true) require.NoError(t, err) - appBlobs1, err := blobtest.GenerateV0Blobs([]int{4}, false) + libBlobs1, err := blobtest.GenerateV0Blobs([]int{4}, false) require.NoError(t, err) - blobs := make([]*blob.Blob, 0, len(appBlobs0)+len(appBlobs1)) - daBlobs := make([][]byte, 0, len(appBlobs0)+len(appBlobs1)) + blobs := make([]*blob.Blob, 0, len(libBlobs0)+len(libBlobs1)) + daBlobs := make([][]byte, 0, len(libBlobs0)+len(libBlobs1)) - for _, squareBlob := range append(appBlobs0, appBlobs1...) { + for _, libBlob := range append(libBlobs0, libBlobs1...) { blob, err := blob.NewBlob( - squareBlob.ShareVersion(), - squareBlob.Namespace(), - squareBlob.Data(), - squareBlob.Signer(), + libBlob.ShareVersion(), + libBlob.Namespace(), + libBlob.Data(), + libBlob.Signer(), ) require.NoError(t, err) blobs = append(blobs, blob) diff --git a/nodebuilder/tests/nd_test.go b/nodebuilder/tests/nd_test.go index 04cac8195b..85956ab58d 100644 --- a/nodebuilder/tests/nd_test.go +++ b/nodebuilder/tests/nd_test.go @@ -12,7 +12,7 @@ import ( "github.com/stretchr/testify/require" "go.uber.org/fx" - gosquare "github.com/celestiaorg/go-square/v2/share" + libshare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/celestia-node/nodebuilder" "github.com/celestiaorg/celestia-node/nodebuilder/node" @@ -68,8 +68,8 @@ func TestShrexNDFromLights(t *testing.T) { reqCtx, cancel := context.WithTimeout(ctx, time.Second*5) // ensure to fetch random namespace (not the reserved namespace) - namespace := h.DAH.RowRoots[1][:gosquare.NamespaceSize] - ns, err := gosquare.NewNamespaceFromBytes(namespace) + namespace := h.DAH.RowRoots[1][:libshare.NamespaceSize] + ns, err := libshare.NewNamespaceFromBytes(namespace) require.NoError(t, err) expected, err := bridgeClient.Share.GetSharesByNamespace(reqCtx, h, ns) @@ -144,8 +144,8 @@ func TestShrexNDFromLightsWithBadFulls(t *testing.T) { reqCtx, cancel := context.WithTimeout(ctx, time.Second*5) // ensure to fetch random namespace (not the reserved namespace) - namespace := h.DAH.RowRoots[1][:gosquare.NamespaceSize] - ns, err := gosquare.NewNamespaceFromBytes(namespace) + namespace := h.DAH.RowRoots[1][:libshare.NamespaceSize] + ns, err := libshare.NewNamespaceFromBytes(namespace) expected, err := bridgeClient.Share.GetSharesByNamespace(reqCtx, h, ns) require.NoError(t, err) require.True(t, len(expected[0].Shares) > 0) diff --git a/nodebuilder/tests/prune_test.go b/nodebuilder/tests/prune_test.go index 047981102c..8541649f5a 100644 --- a/nodebuilder/tests/prune_test.go +++ b/nodebuilder/tests/prune_test.go @@ -13,7 +13,7 @@ import ( "github.com/stretchr/testify/require" "go.uber.org/fx" - gosquare "github.com/celestiaorg/go-square/v2/share" + libshare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/celestia-node/blob" "github.com/celestiaorg/celestia-node/libs/fxutil" @@ -135,7 +135,7 @@ func TestArchivalBlobSync(t *testing.T) { shr, err := archivalFN.ShareServ.GetShare(ctx, eh, 2, 2) require.NoError(t, err) - blobs, err := archivalFN.BlobServ.GetAll(ctx, uint64(i), []gosquare.Namespace{shr.Namespace()}) + blobs, err := archivalFN.BlobServ.GetAll(ctx, uint64(i), []libshare.Namespace{shr.Namespace()}) require.NoError(t, err) archivalBlobs = append(archivalBlobs, &archivalBlob{ diff --git a/share/availability/full/testing.go b/share/availability/full/testing.go index b43f767c89..b0bc7595c0 100644 --- a/share/availability/full/testing.go +++ b/share/availability/full/testing.go @@ -17,7 +17,7 @@ package full // "github.com/celestiaorg/celestia-node/share/p2p/discovery" //) // -//// GetterWithRandSquare provides a gosquare.Getter filled with 'n' NMT +//// GetterWithRandSquare provides a libshare.Getter filled with 'n' NMT //// trees of 'n' random shares, essentially storing a whole share. // func GetterWithRandSquare(t *testing.T, n int) (share.Getter, *share.AxisRoots) { // bServ := ipld.NewMemBlockservice() diff --git a/share/availability/light/availability_test.go b/share/availability/light/availability_test.go index 190aa2f7a6..3da6cea83d 100644 --- a/share/availability/light/availability_test.go +++ b/share/availability/light/availability_test.go @@ -10,7 +10,7 @@ import ( "github.com/ipfs/go-datastore" "github.com/stretchr/testify/require" - gosquare "github.com/celestiaorg/go-square/v2/share" + libshare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" "github.com/celestiaorg/celestia-node/header" @@ -35,11 +35,11 @@ func TestSharesAvailableCaches(t *testing.T) { getter.EXPECT(). GetShare(gomock.Any(), eh, gomock.Any(), gomock.Any()). DoAndReturn( - func(_ context.Context, _ *header.ExtendedHeader, row, col int) (gosquare.Share, error) { + func(_ context.Context, _ *header.ExtendedHeader, row, col int) (libshare.Share, error) { rawSh := eds.GetCell(uint(row), uint(col)) - sh, err := gosquare.NewShare(rawSh) + sh, err := libshare.NewShare(rawSh) if err != nil { - return gosquare.Share{}, err + return libshare.Share{}, err } return *sh, nil }). @@ -72,7 +72,7 @@ func TestSharesAvailableHitsCache(t *testing.T) { getter := mock.NewMockGetter(gomock.NewController(t)) getter.EXPECT(). GetShare(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()). - Return(gosquare.Share{}, shrex.ErrNotFound). + Return(libshare.Share{}, shrex.ErrNotFound). AnyTimes() ds := datastore.NewMapDatastore() @@ -126,7 +126,7 @@ func TestSharesAvailableFailed(t *testing.T) { // getter doesn't have the eds, so it should fail getter.EXPECT(). GetShare(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()). - Return(gosquare.Share{}, shrex.ErrNotFound). + Return(libshare.Share{}, shrex.ErrNotFound). AnyTimes() err = avail.SharesAvailable(ctx, eh) require.ErrorIs(t, err, share.ErrNotAvailable) @@ -175,15 +175,15 @@ func (m onceGetter) AddSamples(samples []Sample) { } } -func (m onceGetter) GetShare(_ context.Context, _ *header.ExtendedHeader, row, col int) (gosquare.Share, error) { +func (m onceGetter) GetShare(_ context.Context, _ *header.ExtendedHeader, row, col int) (libshare.Share, error) { m.Lock() defer m.Unlock() s := Sample{Row: uint16(row), Col: uint16(col)} if _, ok := m.available[s]; ok { delete(m.available, s) - return gosquare.Share{}, nil + return libshare.Share{}, nil } - return gosquare.Share{}, share.ErrNotAvailable + return libshare.Share{}, share.ErrNotAvailable } func (m onceGetter) GetEDS(_ context.Context, _ *header.ExtendedHeader) (*rsmt2d.ExtendedDataSquare, error) { @@ -193,7 +193,7 @@ func (m onceGetter) GetEDS(_ context.Context, _ *header.ExtendedHeader) (*rsmt2d func (m onceGetter) GetSharesByNamespace( _ context.Context, _ *header.ExtendedHeader, - _ gosquare.Namespace, + _ libshare.Namespace, ) (shwap.NamespaceData, error) { panic("not implemented") } diff --git a/share/availability/light/testing.go b/share/availability/light/testing.go index 8f48c98716..2b454dbda0 100644 --- a/share/availability/light/testing.go +++ b/share/availability/light/testing.go @@ -19,9 +19,9 @@ package light // "github.com/celestiaorg/celestia-node/share/ipld" //) // -//// GetterWithRandSquare provides a gosquare.Getter filled with 'n' NMT trees of 'n' random shares, +//// GetterWithRandSquare provides a libshare.Getter filled with 'n' NMT trees of 'n' random shares, //// essentially storing a whole square. -// func GetterWithRandSquare(t *testing.T, n int) (gosquare.Getter, *header.ExtendedHeader) { +// func GetterWithRandSquare(t *testing.T, n int) (libshare.Getter, *header.ExtendedHeader) { // bServ := ipld.NewMemBlockservice() // getter := getters.NewIPLDGetter(bServ) // root := availability_test.RandFillBS(t, n, bServ) @@ -31,9 +31,9 @@ package light // return getter, eh //} // -//// EmptyGetter provides an unfilled gosquare.Getter with corresponding blockservice.BlockService than +//// EmptyGetter provides an unfilled libshare.Getter with corresponding blockservice.BlockService than //// can be filled by the test. -// func EmptyGetter() (gosquare.Getter, blockservice.BlockService) { +// func EmptyGetter() (libshare.Getter, blockservice.BlockService) { // bServ := ipld.NewMemBlockservice() // getter := getters.NewIPLDGetter(bServ) // return getter, bServ @@ -53,7 +53,7 @@ package light // return nd //} // -// func TestAvailability(getter gosquare.Getter) *ShareAvailability { +// func TestAvailability(getter libshare.Getter) *ShareAvailability { // ds := datastore.NewMapDatastore() // return NewShareAvailability(getter, ds) //} @@ -84,15 +84,15 @@ package light // } //} // -// func (m onceGetter) GetShare(_ context.Context, _ *header.ExtendedHeader, row, col int) (gosquare.Share, error) { +// func (m onceGetter) GetShare(_ context.Context, _ *header.ExtendedHeader, row, col int) (libshare.Share, error) { // m.Lock() // defer m.Unlock() // s := Sample{Row: uint16(row), Col: uint16(col)} // if _, ok := m.available[s]; ok { // delete(m.available, s) -// return gosquare.Share{}, nil +// return libshare.Share{}, nil // } -// return gosquare.Share{}, share.ErrNotAvailable +// return libshare.Share{}, share.ErrNotAvailable //} // // func (m onceGetter) GetEDS(_ context.Context, _ *header.ExtendedHeader) (*rsmt2d.ExtendedDataSquare, error) { @@ -102,7 +102,7 @@ package light // func (m onceGetter) GetSharesByNamespace( // _ context.Context, // _ *header.ExtendedHeader, -// _ gosquare.Namespace, -// ) (gosquare.NamespacedShares, error) { +// _ libshare.Namespace, +// ) (libshare.NamespacedShares, error) { // panic("not implemented") // } diff --git a/share/availability/test/testing.go b/share/availability/test/testing.go index 1db8a5433b..affd541d64 100644 --- a/share/availability/test/testing.go +++ b/share/availability/test/testing.go @@ -17,7 +17,7 @@ import ( mocknet "github.com/libp2p/go-libp2p/p2p/net/mock" "github.com/stretchr/testify/require" - gosquare "github.com/celestiaorg/go-square/v2/share" + libshare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/celestia-node/share" "github.com/celestiaorg/celestia-node/share/ipld" @@ -26,12 +26,12 @@ import ( // RandFillBS fills the given BlockService with a random block of a given size. func RandFillBS(t *testing.T, n int, bServ blockservice.BlockService) *share.AxisRoots { - shares := gosquare.RandShares(n * n) + shares := libshare.RandShares(n * n) return FillBS(t, bServ, shares) } // FillBS fills the given BlockService with the given shares. -func FillBS(t *testing.T, bServ blockservice.BlockService, shares []gosquare.Share) *share.AxisRoots { +func FillBS(t *testing.T, bServ blockservice.BlockService, shares []libshare.Share) *share.AxisRoots { eds, err := ipld.AddShares(context.TODO(), shares, bServ) require.NoError(t, err) roots, err := share.NewAxisRoots(eds) diff --git a/share/eds/accessor.go b/share/eds/accessor.go index 4dc4732a1e..07eb6db542 100644 --- a/share/eds/accessor.go +++ b/share/eds/accessor.go @@ -4,7 +4,7 @@ import ( "context" "io" - gosquare "github.com/celestiaorg/go-square/v2/share" + libshare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" "github.com/celestiaorg/celestia-node/share" @@ -30,9 +30,9 @@ type Accessor interface { // implementation. Implementations should indicate the side in the returned AxisHalf. AxisHalf(ctx context.Context, axisType rsmt2d.Axis, axisIdx int) (AxisHalf, error) // RowNamespaceData returns data for the given namespace and row index. - RowNamespaceData(ctx context.Context, namespace gosquare.Namespace, rowIdx int) (shwap.RowNamespaceData, error) + RowNamespaceData(ctx context.Context, namespace libshare.Namespace, rowIdx int) (shwap.RowNamespaceData, error) // Shares returns data (ODS) shares extracted from the Accessor. - Shares(ctx context.Context) ([]gosquare.Share, error) + Shares(ctx context.Context) ([]libshare.Share, error) } // AccessorStreamer is an interface that groups Accessor and Streamer interfaces. diff --git a/share/eds/axis_half.go b/share/eds/axis_half.go index 37ad7dede6..83b1f4d2f3 100644 --- a/share/eds/axis_half.go +++ b/share/eds/axis_half.go @@ -3,7 +3,7 @@ package eds import ( "fmt" - gosquare "github.com/celestiaorg/go-square/v2/share" + libshare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/celestia-node/share" "github.com/celestiaorg/celestia-node/share/shwap" @@ -13,7 +13,7 @@ var codec = share.DefaultRSMT2DCodec() // AxisHalf represents a half of data for a row or column in the EDS. type AxisHalf struct { - Shares []gosquare.Share + Shares []libshare.Share // IsParity indicates whether the half is parity or data. IsParity bool } @@ -28,7 +28,7 @@ func (a AxisHalf) ToRow() shwap.Row { } // Extended returns full axis shares from half axis shares. -func (a AxisHalf) Extended() ([]gosquare.Share, error) { +func (a AxisHalf) Extended() ([]libshare.Share, error) { if a.IsParity { return reconstructShares(a.Shares) } @@ -36,42 +36,42 @@ func (a AxisHalf) Extended() ([]gosquare.Share, error) { } // extendShares constructs full axis shares from original half axis shares. -func extendShares(original []gosquare.Share) ([]gosquare.Share, error) { +func extendShares(original []libshare.Share) ([]libshare.Share, error) { if len(original) == 0 { return nil, fmt.Errorf("original shares are empty") } - parity, err := codec.Encode(gosquare.ToBytes(original)) + parity, err := codec.Encode(libshare.ToBytes(original)) if err != nil { return nil, fmt.Errorf("encoding: %w", err) } - parityShrs, err := gosquare.FromBytes(parity) + parityShrs, err := libshare.FromBytes(parity) if err != nil { return nil, err } sqLen := len(original) * 2 - shares := make([]gosquare.Share, sqLen) + shares := make([]libshare.Share, sqLen) copy(shares, original) copy(shares[sqLen/2:], parityShrs) return shares, nil } -func reconstructShares(parity []gosquare.Share) ([]gosquare.Share, error) { +func reconstructShares(parity []libshare.Share) ([]libshare.Share, error) { if len(parity) == 0 { return nil, fmt.Errorf("parity shares are empty") } sqLen := len(parity) * 2 - shares := make([]gosquare.Share, sqLen) + shares := make([]libshare.Share, sqLen) for i := sqLen / 2; i < sqLen; i++ { shares[i] = parity[i-sqLen/2] } - shrs, err := codec.Decode(gosquare.ToBytes(shares)) + shrs, err := codec.Decode(libshare.ToBytes(shares)) if err != nil { return nil, fmt.Errorf("reconstructing: %w", err) } - return gosquare.FromBytes(shrs) + return libshare.FromBytes(shrs) } diff --git a/share/eds/axis_half_test.go b/share/eds/axis_half_test.go index 77165eabce..8b339a2afb 100644 --- a/share/eds/axis_half_test.go +++ b/share/eds/axis_half_test.go @@ -5,11 +5,11 @@ import ( "github.com/stretchr/testify/require" - gosquare "github.com/celestiaorg/go-square/v2/share" + libshare "github.com/celestiaorg/go-square/v2/share" ) func TestExtendAxisHalf(t *testing.T) { - shares := gosquare.RandShares(16) + shares := libshare.RandShares(16) original := AxisHalf{ Shares: shares, diff --git a/share/eds/byzantine/bad_encoding_test.go b/share/eds/byzantine/bad_encoding_test.go index 4a849aaaa0..57fc84bfe3 100644 --- a/share/eds/byzantine/bad_encoding_test.go +++ b/share/eds/byzantine/bad_encoding_test.go @@ -14,7 +14,7 @@ import ( core "github.com/tendermint/tendermint/types" "github.com/celestiaorg/celestia-app/v3/test/util/malicious" - gosquare "github.com/celestiaorg/go-square/v2/share" + libshare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt" "github.com/celestiaorg/rsmt2d" @@ -89,7 +89,7 @@ func TestBEFP_Validate(t *testing.T) { name: "incorrect share with Proof", prepareFn: func() error { // break the first shareWithProof to test negative case - sh := gosquare.RandShares(2) + sh := libshare.RandShares(2) nmtProof := nmt.NewInclusionProof(0, 1, nil, false) befp.Shares[0] = &ShareWithProof{sh[0], &nmtProof, rsmt2d.Row} return proof.Validate(&header.ExtendedHeader{DAH: roots}) @@ -160,7 +160,7 @@ func TestIncorrectBadEncodingFraudProof(t *testing.T) { bServ := ipld.NewMemBlockservice() squareSize := 8 - shares := gosquare.RandShares(squareSize * squareSize) + shares := libshare.RandShares(squareSize * squareSize) eds, err := ipld.AddShares(ctx, shares, bServ) require.NoError(t, err) @@ -252,7 +252,7 @@ func newNamespacedBlockService() *namespacedBlockService { sha256NamespaceFlagged := uint64(0x7701) // register the nmt hasher to validate the order of namespaces mhcore.Register(sha256NamespaceFlagged, func() hash.Hash { - nh := nmt.NewNmtHasher(share.NewSHA256Hasher(), gosquare.NamespaceSize, true) + nh := nmt.NewNmtHasher(share.NewSHA256Hasher(), libshare.NamespaceSize, true) nh.Reset() return nh }) @@ -265,7 +265,7 @@ func newNamespacedBlockService() *namespacedBlockService { Codec: sha256NamespaceFlagged, MhType: sha256NamespaceFlagged, // equals to NmtHasher.Size() - MhLength: share.NewSHA256Hasher().Size() + 2*gosquare.NamespaceSize, + MhLength: share.NewSHA256Hasher().Size() + 2*libshare.NamespaceSize, } return bs } diff --git a/share/eds/byzantine/byzantine.go b/share/eds/byzantine/byzantine.go index cd0c54b9fc..7a35b05511 100644 --- a/share/eds/byzantine/byzantine.go +++ b/share/eds/byzantine/byzantine.go @@ -6,7 +6,7 @@ import ( "github.com/ipfs/boxo/blockstore" - gosquare "github.com/celestiaorg/go-square/v2/share" + libshare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" "github.com/celestiaorg/celestia-node/share" @@ -17,7 +17,7 @@ import ( // (merkle proofs do not match parity erasure-coding data). // // It is converted from rsmt2d.ByzantineRow/Col + -// Merkle Proof for each gosquare. +// Merkle Proof for each libshare. type ErrByzantine struct { Index uint32 Shares []*ShareWithProof @@ -43,7 +43,7 @@ func NewErrByzantine( if len(shr) == 0 { continue } - sh, err := gosquare.NewShare(shr) + sh, err := libshare.NewShare(shr) if err != nil { log.Warn("failed to create share", "index", index, "err", err) continue diff --git a/share/eds/byzantine/share_proof.go b/share/eds/byzantine/share_proof.go index b3b0a94cac..4b3ae592db 100644 --- a/share/eds/byzantine/share_proof.go +++ b/share/eds/byzantine/share_proof.go @@ -7,7 +7,7 @@ import ( "github.com/ipfs/boxo/blockservice" logging "github.com/ipfs/go-log/v2" - gosquare "github.com/celestiaorg/go-square/v2/share" + libshare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt" nmt_pb "github.com/celestiaorg/nmt/pb" "github.com/celestiaorg/rsmt2d" @@ -22,7 +22,7 @@ var log = logging.Logger("share/byzantine") // ShareWithProof contains data with corresponding Merkle Proof type ShareWithProof struct { // Share is a full data including namespace - gosquare.Share + libshare.Share // Proof is a Merkle Proof of current share Proof *nmt.Proof // Axis is a proof axis @@ -41,7 +41,7 @@ func (s *ShareWithProof) Validate(roots *share.AxisRoots, axisType rsmt2d.Axis, edsSize := len(roots.RowRoots) isParity := shrIdx >= edsSize/2 || axisIdx >= edsSize/2 - namespace := gosquare.ParitySharesNamespace + namespace := libshare.ParitySharesNamespace if !isParity { namespace = s.Share.Namespace() } @@ -76,7 +76,7 @@ func GetShareWithProof( ctx context.Context, bGetter blockservice.BlockGetter, roots *share.AxisRoots, - share gosquare.Share, + share libshare.Share, axisType rsmt2d.Axis, axisIdx, shrIdx int, ) (*ShareWithProof, error) { if axisType == rsmt2d.Col { @@ -121,7 +121,7 @@ func ProtoToShare(protoShares []*pb.Share) ([]*ShareWithProof, error) { continue } proof := ProtoToProof(protoSh.Proof) - sh, err := gosquare.NewShare(protoSh.Data) + sh, err := libshare.NewShare(protoSh.Data) if err != nil { return nil, err } diff --git a/share/eds/close_once.go b/share/eds/close_once.go index 773eea2be9..cc217710ce 100644 --- a/share/eds/close_once.go +++ b/share/eds/close_once.go @@ -6,7 +6,7 @@ import ( "io" "sync/atomic" - gosquare "github.com/celestiaorg/go-square/v2/share" + libshare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" "github.com/celestiaorg/celestia-node/share" @@ -77,7 +77,7 @@ func (c *closeOnce) AxisHalf( func (c *closeOnce) RowNamespaceData( ctx context.Context, - namespace gosquare.Namespace, + namespace libshare.Namespace, rowIdx int, ) (shwap.RowNamespaceData, error) { if c.closed.Load() { @@ -86,7 +86,7 @@ func (c *closeOnce) RowNamespaceData( return c.f.RowNamespaceData(ctx, namespace, rowIdx) } -func (c *closeOnce) Shares(ctx context.Context) ([]gosquare.Share, error) { +func (c *closeOnce) Shares(ctx context.Context) ([]libshare.Share, error) { if c.closed.Load() { return nil, errAccessorClosed } diff --git a/share/eds/close_once_test.go b/share/eds/close_once_test.go index cc41954ef5..d515ac7bda 100644 --- a/share/eds/close_once_test.go +++ b/share/eds/close_once_test.go @@ -8,7 +8,7 @@ import ( "github.com/stretchr/testify/require" - gosquare "github.com/celestiaorg/go-square/v2/share" + libshare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" "github.com/celestiaorg/celestia-node/share" @@ -24,7 +24,7 @@ func TestWithClosedOnce(t *testing.T) { require.NoError(t, err) _, err = closedOnce.AxisHalf(ctx, rsmt2d.Row, 0) require.NoError(t, err) - _, err = closedOnce.RowNamespaceData(ctx, gosquare.Namespace{}, 0) + _, err = closedOnce.RowNamespaceData(ctx, libshare.Namespace{}, 0) require.NoError(t, err) _, err = closedOnce.Shares(ctx) require.NoError(t, err) @@ -37,7 +37,7 @@ func TestWithClosedOnce(t *testing.T) { require.ErrorIs(t, err, errAccessorClosed) _, err = closedOnce.AxisHalf(ctx, rsmt2d.Row, 0) require.ErrorIs(t, err, errAccessorClosed) - _, err = closedOnce.RowNamespaceData(ctx, gosquare.Namespace{}, 0) + _, err = closedOnce.RowNamespaceData(ctx, libshare.Namespace{}, 0) require.ErrorIs(t, err, errAccessorClosed) _, err = closedOnce.Shares(ctx) require.ErrorIs(t, err, errAccessorClosed) @@ -69,13 +69,13 @@ func (s *stubEdsAccessorCloser) AxisHalf(context.Context, rsmt2d.Axis, int) (Axi func (s *stubEdsAccessorCloser) RowNamespaceData( context.Context, - gosquare.Namespace, + libshare.Namespace, int, ) (shwap.RowNamespaceData, error) { return shwap.RowNamespaceData{}, nil } -func (s *stubEdsAccessorCloser) Shares(context.Context) ([]gosquare.Share, error) { +func (s *stubEdsAccessorCloser) Shares(context.Context) ([]libshare.Share, error) { return nil, nil } diff --git a/share/eds/edstest/testing.go b/share/eds/edstest/testing.go index 9a655819d0..818e7b7596 100644 --- a/share/eds/edstest/testing.go +++ b/share/eds/edstest/testing.go @@ -18,7 +18,7 @@ import ( blobtypes "github.com/celestiaorg/celestia-app/v3/x/blob/types" appshares "github.com/celestiaorg/go-square/shares" libSquare "github.com/celestiaorg/go-square/square" - gosquare "github.com/celestiaorg/go-square/v2/share" + libshare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt" "github.com/celestiaorg/rsmt2d" @@ -33,7 +33,7 @@ const ( func RandByzantineEDS(t testing.TB, odsSize int, options ...nmt.Option) *rsmt2d.ExtendedDataSquare { eds := RandEDS(t, odsSize) shares := eds.Flattened() - copy(shares[0][gosquare.NamespaceSize:], shares[1][gosquare.NamespaceSize:]) // corrupting eds + copy(shares[0][libshare.NamespaceSize:], shares[1][libshare.NamespaceSize:]) // corrupting eds eds, err := rsmt2d.ImportExtendedDataSquare( shares, share.DefaultRSMT2DCodec(), @@ -45,9 +45,9 @@ func RandByzantineEDS(t testing.TB, odsSize int, options ...nmt.Option) *rsmt2d. // RandEDS generates EDS filled with the random data with the given size for original square. func RandEDS(t testing.TB, odsSize int) *rsmt2d.ExtendedDataSquare { - shares := gosquare.RandShares(odsSize * odsSize) + shares := libshare.RandShares(odsSize * odsSize) eds, err := rsmt2d.ComputeExtendedDataSquare( - gosquare.ToBytes(shares), + libshare.ToBytes(shares), share.DefaultRSMT2DCodec(), wrapper.NewConstructor(uint64(odsSize)), ) @@ -57,14 +57,14 @@ func RandEDS(t testing.TB, odsSize int) *rsmt2d.ExtendedDataSquare { // RandEDSWithTailPadding generates EDS of given ODS size filled with randomized and tail padding shares. func RandEDSWithTailPadding(t testing.TB, odsSize, padding int) *rsmt2d.ExtendedDataSquare { - shares := gosquare.RandShares(odsSize * odsSize) + shares := libshare.RandShares(odsSize * odsSize) for i := len(shares) - padding; i < len(shares); i++ { - paddingShare := gosquare.TailPaddingShare() + paddingShare := libshare.TailPaddingShare() shares[i] = paddingShare } eds, err := rsmt2d.ComputeExtendedDataSquare( - gosquare.ToBytes(shares), + libshare.ToBytes(shares), share.DefaultRSMT2DCodec(), wrapper.NewConstructor(uint64(odsSize)), ) @@ -76,12 +76,12 @@ func RandEDSWithTailPadding(t testing.TB, odsSize, padding int) *rsmt2d.Extended // namespacedAmount of shares with the given namespace. func RandEDSWithNamespace( t testing.TB, - namespace gosquare.Namespace, + namespace libshare.Namespace, namespacedAmount, odsSize int, ) (*rsmt2d.ExtendedDataSquare, *share.AxisRoots) { - shares := gosquare.RandSharesWithNamespace(namespace, namespacedAmount, odsSize*odsSize) + shares := libshare.RandSharesWithNamespace(namespace, namespacedAmount, odsSize*odsSize) eds, err := rsmt2d.ComputeExtendedDataSquare( - gosquare.ToBytes(shares), + libshare.ToBytes(shares), share.DefaultRSMT2DCodec(), wrapper.NewConstructor(uint64(odsSize)), ) @@ -116,8 +116,8 @@ func GenerateTestBlock( blobSize, numberOfTransactions int, ) ( []*blobtypes.MsgPayForBlobs, - []*gosquare.Blob, - []gosquare.Namespace, + []*libshare.Blob, + []libshare.Namespace, *rsmt2d.ExtendedDataSquare, coretypes.Txs, *da.DataAvailabilityHeader, @@ -157,10 +157,10 @@ func GenerateTestBlock( func createTestBlobTransactions( t *testing.T, numberOfTransactions, size int, -) ([]gosquare.Namespace, []*blobtypes.MsgPayForBlobs, []*gosquare.Blob, []coretypes.Tx) { - nss := make([]gosquare.Namespace, 0) +) ([]libshare.Namespace, []*blobtypes.MsgPayForBlobs, []*libshare.Blob, []coretypes.Tx) { + nss := make([]libshare.Namespace, 0) msgs := make([]*blobtypes.MsgPayForBlobs, 0) - blobs := make([]*gosquare.Blob, 0) + blobs := make([]*libshare.Blob, 0) coreTxs := make([]coretypes.Tx, 0) config := encoding.MakeConfig(app.ModuleEncodingRegisters...) keyring := testfactory.TestKeyring(config.Codec, accountName) @@ -185,11 +185,11 @@ func createTestBlobTransaction( t *testing.T, signer *user.Signer, size int, -) (gosquare.Namespace, *blobtypes.MsgPayForBlobs, *gosquare.Blob, coretypes.Tx) { - ns := gosquare.RandomBlobNamespace() +) (libshare.Namespace, *blobtypes.MsgPayForBlobs, *libshare.Blob, coretypes.Tx) { + ns := libshare.RandomBlobNamespace() account := signer.Account(accountName) msg, b := blobfactory.RandMsgPayForBlobsWithNamespaceAndSigner(account.Address().String(), ns, size) - cTx, _, err := signer.CreatePayForBlobs(accountName, []*gosquare.Blob{b}) + cTx, _, err := signer.CreatePayForBlobs(accountName, []*libshare.Blob{b}) require.NoError(t, err) return ns, msg, b, cTx } diff --git a/share/eds/nd.go b/share/eds/nd.go index c45ee4da20..7c41655898 100644 --- a/share/eds/nd.go +++ b/share/eds/nd.go @@ -4,7 +4,7 @@ import ( "context" "fmt" - gosquare "github.com/celestiaorg/go-square/v2/share" + libshare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/celestia-node/share" "github.com/celestiaorg/celestia-node/share/shwap" @@ -16,7 +16,7 @@ import ( func NamespaceData( ctx context.Context, eds Accessor, - namespace gosquare.Namespace, + namespace libshare.Namespace, ) (shwap.NamespaceData, error) { roots, err := eds.AxisRoots(ctx) if err != nil { diff --git a/share/eds/nd_test.go b/share/eds/nd_test.go index 63c1883bf2..457e331219 100644 --- a/share/eds/nd_test.go +++ b/share/eds/nd_test.go @@ -7,7 +7,7 @@ import ( "github.com/stretchr/testify/require" - gosquare "github.com/celestiaorg/go-square/v2/share" + libshare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/celestia-node/share/eds/edstest" ) @@ -18,7 +18,7 @@ func TestNamespaceData(t *testing.T) { const odsSize = 8 sharesAmount := odsSize * odsSize - namespace := gosquare.RandomNamespace() + namespace := libshare.RandomNamespace() for amount := 1; amount < sharesAmount; amount++ { eds, root := edstest.RandEDSWithNamespace(t, namespace, amount, odsSize) rsmt2d := &Rsmt2D{ExtendedDataSquare: eds} diff --git a/share/eds/proof.go b/share/eds/proof.go index d649ed7772..f7e0f71136 100644 --- a/share/eds/proof.go +++ b/share/eds/proof.go @@ -7,7 +7,7 @@ import ( "github.com/tendermint/tendermint/types" pkgproof "github.com/celestiaorg/celestia-app/v3/pkg/proof" - gosquare "github.com/celestiaorg/go-square/v2/share" + libshare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" ) @@ -16,7 +16,7 @@ import ( func ProveShares(eds *rsmt2d.ExtendedDataSquare, start, end int) (*types.ShareProof, error) { log.Debugw("proving share range", "start", start, "end", end) - odsShares, err := gosquare.FromBytes(eds.FlattenedODS()) + odsShares, err := libshare.FromBytes(eds.FlattenedODS()) if err != nil { return nil, err } @@ -25,7 +25,7 @@ func ProveShares(eds *rsmt2d.ExtendedDataSquare, start, end int) (*types.SharePr return nil, err } log.Debugw("generating the share proof", "start", start, "end", end) - proof, err := pkgproof.NewShareInclusionProofFromEDS(eds, nID, gosquare.NewRange(start, end)) + proof, err := pkgproof.NewShareInclusionProofFromEDS(eds, nID, libshare.NewRange(start, end)) if err != nil { return nil, err } diff --git a/share/eds/proofs_cache.go b/share/eds/proofs_cache.go index 28b570d3a4..e0fb55404b 100644 --- a/share/eds/proofs_cache.go +++ b/share/eds/proofs_cache.go @@ -13,7 +13,7 @@ import ( "github.com/ipfs/go-cid" "github.com/celestiaorg/celestia-app/v3/pkg/wrapper" - gosquare "github.com/celestiaorg/go-square/v2/share" + libshare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt" "github.com/celestiaorg/rsmt2d" @@ -51,7 +51,7 @@ type proofsCache struct { type axisWithProofs struct { half AxisHalf // shares are the extended axis Shares - shares []gosquare.Share + shares []libshare.Share // root caches the root of the tree. It will be set only when proofs are calculated root []byte // proofs are stored in a blockservice.BlockGetter by their CID. It will be set only when proofs @@ -213,7 +213,7 @@ func (c *proofsCache) AxisHalf(ctx context.Context, axisType rsmt2d.Axis, axisId func (c *proofsCache) RowNamespaceData( ctx context.Context, - namespace gosquare.Namespace, + namespace libshare.Namespace, rowIdx int, ) (shwap.RowNamespaceData, error) { ax, err := c.axisWithProofs(ctx, rsmt2d.Row, rowIdx) @@ -232,9 +232,9 @@ func (c *proofsCache) RowNamespaceData( }, nil } -func (c *proofsCache) Shares(ctx context.Context) ([]gosquare.Share, error) { +func (c *proofsCache) Shares(ctx context.Context) ([]libshare.Share, error) { odsSize := c.Size(ctx) / 2 - shares := make([]gosquare.Share, 0, odsSize*odsSize) + shares := make([]libshare.Share, 0, odsSize*odsSize) for i := 0; i < c.Size(ctx)/2; i++ { ax, err := c.AxisHalf(ctx, rsmt2d.Row, i) if err != nil { @@ -265,7 +265,7 @@ func (c *proofsCache) Close() error { return c.inner.Close() } -func (c *proofsCache) axisShares(ctx context.Context, axisType rsmt2d.Axis, axisIdx int) ([]gosquare.Share, error) { +func (c *proofsCache) axisShares(ctx context.Context, axisType rsmt2d.Axis, axisIdx int) ([]libshare.Share, error) { ax, ok := c.getAxisFromCache(axisType, axisIdx) if ok && len(ax.shares) != 0 { return ax.shares, nil diff --git a/share/eds/read.go b/share/eds/read.go index 38afba4199..26d1b9e237 100644 --- a/share/eds/read.go +++ b/share/eds/read.go @@ -7,7 +7,7 @@ import ( "fmt" "io" - gosquare "github.com/celestiaorg/go-square/v2/share" + libshare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/celestia-node/share" ) @@ -15,7 +15,7 @@ import ( // ReadAccessor reads up EDS out of the io.Reader until io.EOF and provides. func ReadAccessor(ctx context.Context, reader io.Reader, root *share.AxisRoots) (*Rsmt2D, error) { odsSize := len(root.RowRoots) / 2 - shares, err := ReadShares(reader, gosquare.ShareSize, odsSize) + shares, err := ReadShares(reader, libshare.ShareSize, odsSize) if err != nil { return nil, fmt.Errorf("failed to read eds from ods bytes: %w", err) } @@ -41,22 +41,22 @@ func ReadAccessor(ctx context.Context, reader io.Reader, root *share.AxisRoots) // ReadShares reads shares from the provided io.Reader until EOF. If EOF is reached, the remaining shares // are populated as tail padding shares. Provided reader must contain shares in row-major order. -func ReadShares(r io.Reader, shareSize, odsSize int) ([]gosquare.Share, error) { - shares := make([]gosquare.Share, odsSize*odsSize) +func ReadShares(r io.Reader, shareSize, odsSize int) ([]libshare.Share, error) { + shares := make([]libshare.Share, odsSize*odsSize) var total int for i := range shares { shr := make([]byte, shareSize) n, err := io.ReadFull(r, shr) if errors.Is(err, io.EOF) { for ; i < len(shares); i++ { - shares[i] = gosquare.TailPaddingShare() + shares[i] = libshare.TailPaddingShare() } return shares, nil } if err != nil { return nil, fmt.Errorf("reading shares: %w, bytes read: %v", err, total+n) } - newShare, err := gosquare.NewShare(shr) + newShare, err := libshare.NewShare(shr) if err != nil { return nil, err } diff --git a/share/eds/retriever.go b/share/eds/retriever.go index 2e23029584..926aa2ed9a 100644 --- a/share/eds/retriever.go +++ b/share/eds/retriever.go @@ -16,7 +16,7 @@ import ( "go.opentelemetry.io/otel/trace" "github.com/celestiaorg/celestia-app/v3/pkg/wrapper" - gosquare "github.com/celestiaorg/go-square/v2/share" + libshare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt" "github.com/celestiaorg/rsmt2d" @@ -143,7 +143,7 @@ func (r *Retriever) newSession(ctx context.Context, roots *share.AxisRoots) (*re return &tree } - square, err := rsmt2d.NewExtendedDataSquare(share.DefaultRSMT2DCodec(), treeFn, uint(size), gosquare.ShareSize) + square, err := rsmt2d.NewExtendedDataSquare(share.DefaultRSMT2DCodec(), treeFn, uint(size), libshare.ShareSize) if err != nil { return nil, err } diff --git a/share/eds/retriever_no_race_test.go b/share/eds/retriever_no_race_test.go index b27d9c5264..abe44220b4 100644 --- a/share/eds/retriever_no_race_test.go +++ b/share/eds/retriever_no_race_test.go @@ -10,7 +10,7 @@ import ( "github.com/stretchr/testify/require" "github.com/celestiaorg/celestia-app/v3/pkg/wrapper" - gosquare "github.com/celestiaorg/go-square/v2/share" + libshare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt" "github.com/celestiaorg/rsmt2d" @@ -31,7 +31,7 @@ func TestRetriever_ByzantineError(t *testing.T) { require.NoError(t, err) // corrupt shares so that eds erasure coding does not match - copy(shares[14][gosquare.NamespaceSize:], shares[15][gosquare.NamespaceSize:]) + copy(shares[14][libshare.NamespaceSize:], shares[15][libshare.NamespaceSize:]) // import corrupted eds batchAdder := ipld.NewNmtNodeAdder(ctx, bserv, ipld.MaxSizeBatchOption(width*2)) diff --git a/share/eds/retriever_test.go b/share/eds/retriever_test.go index 69980dcfc1..5fe7bf4038 100644 --- a/share/eds/retriever_test.go +++ b/share/eds/retriever_test.go @@ -11,7 +11,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - gosquare "github.com/celestiaorg/go-square/v2/share" + libshare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" "github.com/celestiaorg/celestia-node/header" @@ -46,7 +46,7 @@ func TestRetriever_Retrieve(t *testing.T) { for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { // generate EDS - shares := gosquare.RandShares(tc.squareSize * tc.squareSize) + shares := libshare.RandShares(tc.squareSize * tc.squareSize) in, err := ipld.AddShares(ctx, shares, bServ) require.NoError(t, err) @@ -75,7 +75,7 @@ func TestRetriever_MultipleRandQuadrants(t *testing.T) { r := NewRetriever(bServ) // generate EDS - shares := gosquare.RandShares(squareSize * squareSize) + shares := libshare.RandShares(squareSize * squareSize) in, err := ipld.AddShares(ctx, shares, bServ) require.NoError(t, err) diff --git a/share/eds/rsmt2d.go b/share/eds/rsmt2d.go index d74a0f4f3a..eb61947f42 100644 --- a/share/eds/rsmt2d.go +++ b/share/eds/rsmt2d.go @@ -6,7 +6,7 @@ import ( "io" "github.com/celestiaorg/celestia-app/v3/pkg/wrapper" - gosquare "github.com/celestiaorg/go-square/v2/share" + libshare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" "github.com/celestiaorg/celestia-node/share" @@ -100,7 +100,7 @@ func (eds *Rsmt2D) AxisHalf(_ context.Context, axisType rsmt2d.Axis, axisIdx int // side. func (eds *Rsmt2D) HalfRow(idx int, side shwap.RowSide) (shwap.Row, error) { shares := eds.ExtendedDataSquare.Row(uint(idx)) - sh, err := gosquare.FromBytes(shares) + sh, err := libshare.FromBytes(shares) if err != nil { return shwap.Row{}, fmt.Errorf("while converting shares from bytes: %w", err) } @@ -110,11 +110,11 @@ func (eds *Rsmt2D) HalfRow(idx int, side shwap.RowSide) (shwap.Row, error) { // RowNamespaceData returns data for the given namespace and row index. func (eds *Rsmt2D) RowNamespaceData( _ context.Context, - namespace gosquare.Namespace, + namespace libshare.Namespace, rowIdx int, ) (shwap.RowNamespaceData, error) { shares := eds.Row(uint(rowIdx)) - sh, err := gosquare.FromBytes(shares) + sh, err := libshare.FromBytes(shares) if err != nil { return shwap.RowNamespaceData{}, fmt.Errorf("while converting shares from bytes: %w", err) } @@ -123,8 +123,8 @@ func (eds *Rsmt2D) RowNamespaceData( // Shares returns data (ODS) shares extracted from the EDS. It returns new copy of the shares each // time. -func (eds *Rsmt2D) Shares(_ context.Context) ([]gosquare.Share, error) { - return gosquare.FromBytes(eds.ExtendedDataSquare.FlattenedODS()) +func (eds *Rsmt2D) Shares(_ context.Context) ([]libshare.Share, error) { + return libshare.FromBytes(eds.ExtendedDataSquare.FlattenedODS()) } func (eds *Rsmt2D) Close() error { @@ -142,9 +142,9 @@ func (eds *Rsmt2D) Reader() (io.Reader, error) { } // Rsmt2DFromShares constructs an Extended Data Square from shares. -func Rsmt2DFromShares(shares []gosquare.Share, odsSize int) (*Rsmt2D, error) { +func Rsmt2DFromShares(shares []libshare.Share, odsSize int) (*Rsmt2D, error) { treeFn := wrapper.NewConstructor(uint64(odsSize)) - eds, err := rsmt2d.ComputeExtendedDataSquare(gosquare.ToBytes(shares), share.DefaultRSMT2DCodec(), treeFn) + eds, err := rsmt2d.ComputeExtendedDataSquare(libshare.ToBytes(shares), share.DefaultRSMT2DCodec(), treeFn) if err != nil { return &Rsmt2D{}, fmt.Errorf("computing extended data square: %w", err) } @@ -152,13 +152,13 @@ func Rsmt2DFromShares(shares []gosquare.Share, odsSize int) (*Rsmt2D, error) { return &Rsmt2D{eds}, nil } -func getAxis(eds *rsmt2d.ExtendedDataSquare, axisType rsmt2d.Axis, axisIdx int) ([]gosquare.Share, error) { +func getAxis(eds *rsmt2d.ExtendedDataSquare, axisType rsmt2d.Axis, axisIdx int) ([]libshare.Share, error) { switch axisType { case rsmt2d.Row: - sh, err := gosquare.FromBytes(eds.Row(uint(axisIdx))) + sh, err := libshare.FromBytes(eds.Row(uint(axisIdx))) return sh, err case rsmt2d.Col: - sh, err := gosquare.FromBytes(eds.Col(uint(axisIdx))) + sh, err := libshare.FromBytes(eds.Col(uint(axisIdx))) return sh, err default: panic("unknown axis") diff --git a/share/eds/rsmt2d_test.go b/share/eds/rsmt2d_test.go index fa76b03a09..96bde8c2ab 100644 --- a/share/eds/rsmt2d_test.go +++ b/share/eds/rsmt2d_test.go @@ -7,7 +7,7 @@ import ( "github.com/stretchr/testify/require" - gosquare "github.com/celestiaorg/go-square/v2/share" + libshare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" "github.com/celestiaorg/celestia-node/share" @@ -43,7 +43,7 @@ func TestRsmt2dHalfRow(t *testing.T) { want := eds.Row(uint(rowIdx)) shares, err := row.Shares() require.NoError(t, err) - require.Equal(t, want, gosquare.ToBytes(shares)) + require.Equal(t, want, libshare.ToBytes(shares)) } } } diff --git a/share/eds/share_reader_test.go b/share/eds/share_reader_test.go index 165cc25f42..60eae13b1c 100644 --- a/share/eds/share_reader_test.go +++ b/share/eds/share_reader_test.go @@ -8,7 +8,7 @@ import ( "github.com/stretchr/testify/require" - gosquare "github.com/celestiaorg/go-square/v2/share" + libshare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/celestia-node/share/eds/edstest" ) @@ -24,7 +24,7 @@ func TestShareReader(t *testing.T) { reader := NewShareReader(odsSize, getShare) readBytes, err := readWithRandomBuffer(reader, 1024) require.NoError(t, err) - expected := make([]byte, 0, odsSize*odsSize*gosquare.ShareSize) + expected := make([]byte, 0, odsSize*odsSize*libshare.ShareSize) for _, share := range eds.FlattenedODS() { expected = append(expected, share...) } diff --git a/share/eds/testing.go b/share/eds/testing.go index 273e810c61..90404a1277 100644 --- a/share/eds/testing.go +++ b/share/eds/testing.go @@ -10,7 +10,7 @@ import ( "github.com/stretchr/testify/require" - gosquare "github.com/celestiaorg/go-square/v2/share" + libshare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt" "github.com/celestiaorg/rsmt2d" @@ -214,7 +214,7 @@ func testAccessorRowNamespaceData( t.Parallel() // generate EDS with random data and some Shares with the same namespace sharesAmount := odsSize * odsSize - namespace := gosquare.RandomNamespace() + namespace := libshare.RandomNamespace() // test with different amount of shares for amount := 1; amount < sharesAmount; amount++ { // select random amount of shares, but not less than 1 @@ -259,11 +259,11 @@ func testAccessorRowNamespaceData( // namespaced shares for i, root := range roots.RowRoots[:odsSize] { // select namespace that within the range of root namespaces, but is not included - maxNs := nmt.MaxNamespace(root, gosquare.NamespaceSize) - ns, err := gosquare.NewNamespaceFromBytes(maxNs) + maxNs := nmt.MaxNamespace(root, libshare.NamespaceSize) + ns, err := libshare.NewNamespaceFromBytes(maxNs) require.NoError(t, err) - absentNs, err := gosquare.AddInt(ns, -1) + absentNs, err := libshare.AddInt(ns, -1) require.NoError(t, err) acc := createAccessor(t, eds) @@ -296,7 +296,7 @@ func testAccessorAxisHalf( require.NoError(t, err) require.Len(t, half.Shares, odsSize) - var expected []gosquare.Share + var expected []libshare.Share if half.IsParity { expected, err = getAxis(eds, axisType, axisIdx) require.NoError(t, err) @@ -324,7 +324,7 @@ func testAccessorAxisHalf( require.NoError(t, err) require.Len(t, half.Shares, odsSize) - var expected []gosquare.Share + var expected []libshare.Share if half.IsParity { expected, err = getAxis(eds, axisType, idx) require.NoError(t, err) @@ -359,7 +359,7 @@ func testAccessorShares( shares, err := acc.Shares(ctx) require.NoError(t, err) expected := eds.FlattenedODS() - sh, err := gosquare.FromBytes(expected) + sh, err := libshare.FromBytes(expected) require.NoError(t, err) require.Equal(t, sh, shares) }() diff --git a/share/eds/validation.go b/share/eds/validation.go index eca404ab99..5064b7dbea 100644 --- a/share/eds/validation.go +++ b/share/eds/validation.go @@ -6,7 +6,7 @@ import ( "fmt" "sync/atomic" - gosquare "github.com/celestiaorg/go-square/v2/share" + libshare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" "github.com/celestiaorg/celestia-node/share/shwap" @@ -56,7 +56,7 @@ func (f validation) AxisHalf(ctx context.Context, axisType rsmt2d.Axis, axisIdx func (f validation) RowNamespaceData( ctx context.Context, - namespace gosquare.Namespace, + namespace libshare.Namespace, rowIdx int, ) (shwap.RowNamespaceData, error) { _, err := shwap.NewRowNamespaceDataID(1, rowIdx, namespace, f.Size(ctx)) diff --git a/share/eds/validation_test.go b/share/eds/validation_test.go index f5ac0d5588..3e645cbfb3 100644 --- a/share/eds/validation_test.go +++ b/share/eds/validation_test.go @@ -7,7 +7,7 @@ import ( "github.com/stretchr/testify/require" - gosquare "github.com/celestiaorg/go-square/v2/share" + libshare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" "github.com/celestiaorg/celestia-node/share/eds/edstest" @@ -91,7 +91,7 @@ func TestValidation_RowNamespaceData(t *testing.T) { accessor := &Rsmt2D{ExtendedDataSquare: randEDS} validation := WithValidation(AccessorAndStreamer(accessor, nil)) - ns := gosquare.RandomNamespace() + ns := libshare.RandomNamespace() _, err := validation.RowNamespaceData(context.Background(), ns, tt.rowIdx) if tt.expectFail { require.ErrorIs(t, err, shwap.ErrInvalidID) diff --git a/share/empty.go b/share/empty.go index 04bf4a5dba..1b294d5888 100644 --- a/share/empty.go +++ b/share/empty.go @@ -6,7 +6,7 @@ import ( "sync" "github.com/celestiaorg/celestia-app/v3/pkg/da" - gosquare "github.com/celestiaorg/go-square/v2/share" + libshare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" ) @@ -29,7 +29,7 @@ func EmptyEDS() *rsmt2d.ExtendedDataSquare { } // EmptyBlockShares returns the shares of the empty block. -func EmptyBlockShares() []gosquare.Share { +func EmptyBlockShares() []libshare.Share { initEmpty() return emptyBlockShares } @@ -39,7 +39,7 @@ var ( emptyBlockDataHash DataHash emptyBlockRoots *AxisRoots emptyBlockEDS *rsmt2d.ExtendedDataSquare - emptyBlockShares []gosquare.Share + emptyBlockShares []libshare.Share ) // initEmpty enables lazy initialization for constant empty block data. @@ -49,8 +49,8 @@ func initEmpty() { func computeEmpty() { // compute empty block EDS and DAH for it - result := gosquare.TailPaddingShares(gosquare.MinShareCount) - rawEmptyBlockShares := gosquare.ToBytes(result) + result := libshare.TailPaddingShares(libshare.MinShareCount) + rawEmptyBlockShares := libshare.ToBytes(result) eds, err := da.ExtendShares(rawEmptyBlockShares) if err != nil { @@ -69,7 +69,7 @@ func computeEmpty() { } sh := eds.FlattenedODS() - emptyBlockShares, err = gosquare.FromBytes(sh) + emptyBlockShares, err = libshare.FromBytes(sh) if err != nil { panic(fmt.Errorf("failed to create shares: %w", err)) } diff --git a/share/ipld/add.go b/share/ipld/add.go index 8a182bce2f..39e3cbba80 100644 --- a/share/ipld/add.go +++ b/share/ipld/add.go @@ -7,7 +7,7 @@ import ( "github.com/ipfs/boxo/blockservice" "github.com/celestiaorg/celestia-app/v3/pkg/wrapper" - gosquare "github.com/celestiaorg/go-square/v2/share" + libshare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt" "github.com/celestiaorg/rsmt2d" @@ -19,7 +19,7 @@ import ( // ipld.NodeAdder. func AddShares( ctx context.Context, - shares []gosquare.Share, + shares []libshare.Share, adder blockservice.BlockService, ) (*rsmt2d.ExtendedDataSquare, error) { if len(shares) == 0 { @@ -31,7 +31,7 @@ func AddShares( // create the nmt wrapper to generate row and col commitments // recompute the eds eds, err := rsmt2d.ComputeExtendedDataSquare( - gosquare.ToBytes(shares), + libshare.ToBytes(shares), share.DefaultRSMT2DCodec(), wrapper.NewConstructor(uint64(squareSize), nmt.NodeVisitor(batchAdder.Visit)), diff --git a/share/ipld/delete_test.go b/share/ipld/delete_test.go index ff879a10b8..033d856355 100644 --- a/share/ipld/delete_test.go +++ b/share/ipld/delete_test.go @@ -12,7 +12,7 @@ import ( "github.com/ipfs/go-datastore/sync" "github.com/stretchr/testify/require" - gosquare "github.com/celestiaorg/go-square/v2/share" + libshare "github.com/celestiaorg/go-square/v2/share" ) func TestDeleteNode_FullSquare(t *testing.T) { @@ -21,7 +21,7 @@ func TestDeleteNode_FullSquare(t *testing.T) { defer cancel() bServ := NewMemBlockservice() - shares := gosquare.RandShares(size * size) + shares := libshare.RandShares(size * size) eds, err := AddShares(ctx, shares, bServ) require.NoError(t, err) @@ -63,7 +63,7 @@ func TestDeleteNode_Sample(t *testing.T) { defer cancel() full := NewMemBlockservice() - shares := gosquare.RandShares(size * size) + shares := libshare.RandShares(size * size) eds, err := AddShares(ctx, shares, full) require.NoError(t, err) diff --git a/share/ipld/get_shares.go b/share/ipld/get_shares.go index 172a576834..e76a54ee7c 100644 --- a/share/ipld/get_shares.go +++ b/share/ipld/get_shares.go @@ -7,7 +7,7 @@ import ( "github.com/ipfs/go-cid" format "github.com/ipfs/go-ipld-format" - gosquare "github.com/celestiaorg/go-square/v2/share" + libshare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt" ) @@ -18,15 +18,15 @@ func GetShare( rootCid cid.Cid, leafIndex int, totalLeafs int, // this corresponds to the extended square width -) (gosquare.Share, error) { +) (libshare.Share, error) { nd, err := GetLeaf(ctx, bGetter, rootCid, leafIndex, totalLeafs) if err != nil { - return gosquare.Share{}, err + return libshare.Share{}, err } - sh, err := gosquare.NewShare(nd.RawData()[gosquare.NamespaceSize:]) + sh, err := libshare.NewShare(nd.RawData()[libshare.NamespaceSize:]) if err != nil { - return gosquare.Share{}, err + return libshare.Share{}, err } return *sh, nil } @@ -36,7 +36,7 @@ func GetShare( // (got all shares) or on context cancellation. func GetShares(ctx context.Context, bg blockservice.BlockGetter, root cid.Cid, shares int, put func(int, []byte)) { putNode := func(i int, leaf format.Node) { - put(i, leaf.RawData()[gosquare.NamespaceSize:]) + put(i, leaf.RawData()[libshare.NamespaceSize:]) } GetLeaves(ctx, bg, root, shares, putNode) } @@ -48,9 +48,9 @@ func GetSharesByNamespace( ctx context.Context, bGetter blockservice.BlockGetter, root []byte, - namespace gosquare.Namespace, + namespace libshare.Namespace, maxShares int, -) ([]gosquare.Share, *nmt.Proof, error) { +) ([]libshare.Share, *nmt.Proof, error) { rootCid := MustCidFromNamespacedSha256(root) data := NewNamespaceData(maxShares, namespace, WithLeaves(), WithProofs()) err := data.CollectLeavesByNamespace(ctx, bGetter, rootCid) @@ -63,10 +63,10 @@ func GetSharesByNamespace( return nil, data.Proof(), nil } - shares := make([]gosquare.Share, len(leaves)) + shares := make([]libshare.Share, len(leaves)) for i, leaf := range leaves { if leaf != nil { - sh, err := gosquare.NewShare(leaf.RawData()[gosquare.NamespaceSize:]) + sh, err := libshare.NewShare(leaf.RawData()[libshare.NamespaceSize:]) if err != nil { return nil, nil, err } diff --git a/share/ipld/get_shares_test.go b/share/ipld/get_shares_test.go index 61705042ef..71856ce373 100644 --- a/share/ipld/get_shares_test.go +++ b/share/ipld/get_shares_test.go @@ -15,7 +15,7 @@ import ( "github.com/stretchr/testify/require" "github.com/celestiaorg/celestia-app/v3/pkg/wrapper" - gosquare "github.com/celestiaorg/go-square/v2/share" + libshare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" "github.com/celestiaorg/celestia-node/libs/utils" @@ -31,7 +31,7 @@ func TestGetShare(t *testing.T) { bServ := NewMemBlockservice() // generate random shares for the nmt - shares := gosquare.RandShares(size * size) + shares := libshare.RandShares(size * size) eds, err := AddShares(ctx, shares, bServ) require.NoError(t, err) @@ -53,12 +53,12 @@ func TestBlockRecovery(t *testing.T) { extendedShareCount := extendedSquareWidth * extendedSquareWidth // generate test data - quarterShares := gosquare.RandShares(shareCount) - allShares := gosquare.RandShares(shareCount) + quarterShares := libshare.RandShares(shareCount) + allShares := libshare.RandShares(shareCount) testCases := []struct { name string - shares []gosquare.Share + shares []libshare.Share expectErr bool errString string d int // number of shares to delete @@ -73,7 +73,7 @@ func TestBlockRecovery(t *testing.T) { squareSize := utils.SquareSize(len(tc.shares)) testEds, err := rsmt2d.ComputeExtendedDataSquare( - gosquare.ToBytes(tc.shares), + libshare.ToBytes(tc.shares), share.DefaultRSMT2DCodec(), wrapper.NewConstructor(squareSize), ) @@ -114,18 +114,18 @@ func TestBlockRecovery(t *testing.T) { func Test_ConvertEDStoShares(t *testing.T) { squareWidth := 16 - shares := gosquare.RandShares(squareWidth * squareWidth) + shares := libshare.RandShares(squareWidth * squareWidth) // compute extended square testEds, err := rsmt2d.ComputeExtendedDataSquare( - gosquare.ToBytes(shares), + libshare.ToBytes(shares), share.DefaultRSMT2DCodec(), wrapper.NewConstructor(uint64(squareWidth)), ) require.NoError(t, err) resshares := testEds.FlattenedODS() - require.Equal(t, gosquare.ToBytes(shares), resshares) + require.Equal(t, libshare.ToBytes(shares), resshares) } // removes d shares from data @@ -149,10 +149,10 @@ func TestGetSharesByNamespace(t *testing.T) { bServ := NewMemBlockservice() tests := []struct { - rawData []gosquare.Share + rawData []libshare.Share }{ - {rawData: gosquare.RandShares(4)}, - {rawData: gosquare.RandShares(16)}, + {rawData: libshare.RandShares(4)}, + {rawData: libshare.RandShares(16)}, } for i, tt := range tests { @@ -167,7 +167,7 @@ func TestGetSharesByNamespace(t *testing.T) { eds, err := AddShares(ctx, tt.rawData, bServ) require.NoError(t, err) - var shares []gosquare.Share + var shares []libshare.Share rowRoots, err := eds.RowRoots() require.NoError(t, err) for _, row := range rowRoots { @@ -193,7 +193,7 @@ func TestCollectLeavesByNamespace_IncompleteData(t *testing.T) { t.Cleanup(cancel) bServ := NewMemBlockservice() - shares := gosquare.RandShares(16) + shares := libshare.RandShares(16) // set all shares to the same namespace id namespace := shares[0].Namespace() @@ -237,7 +237,7 @@ func TestCollectLeavesByNamespace_AbsentNamespaceId(t *testing.T) { t.Cleanup(cancel) bServ := NewMemBlockservice() - shares := gosquare.RandShares(1024) + shares := libshare.RandShares(1024) // set all shares to the same namespace namespaces, err := randomNamespaces(5) @@ -259,8 +259,8 @@ func TestCollectLeavesByNamespace_AbsentNamespaceId(t *testing.T) { tests := []struct { name string - data []gosquare.Share - missingNamespace gosquare.Namespace + data []libshare.Share + missingNamespace libshare.Namespace isAbsence bool }{ {name: "Namespace less than the minimum namespace in data", data: shares, missingNamespace: minNamespace}, @@ -282,7 +282,7 @@ func TestCollectLeavesByNamespace_MultipleRowsContainingSameNamespaceId(t *testi t.Cleanup(cancel) bServ := NewMemBlockservice() - shares := gosquare.RandShares(16) + shares := libshare.RandShares(16) // set all shares to the same namespace and data but the last one namespace := shares[0].Namespace() @@ -314,7 +314,7 @@ func TestCollectLeavesByNamespace_MultipleRowsContainingSameNamespaceId(t *testi for _, node := range leaves { // test that the data returned by collectLeavesByNamespace for nid // matches the commonNamespaceData that was copied across almost all data - sh, err := gosquare.NewShare(node.RawData()[gosquare.NamespaceSize:]) + sh, err := libshare.NewShare(node.RawData()[libshare.NamespaceSize:]) require.NoError(t, err) assert.Equal(t, commonNamespaceData, *sh) } @@ -327,11 +327,11 @@ func TestGetSharesWithProofsByNamespace(t *testing.T) { bServ := NewMemBlockservice() tests := []struct { - rawData []gosquare.Share + rawData []libshare.Share }{ - {rawData: gosquare.RandShares(4)}, - {rawData: gosquare.RandShares(16)}, - {rawData: gosquare.RandShares(64)}, + {rawData: libshare.RandShares(4)}, + {rawData: libshare.RandShares(16)}, + {rawData: libshare.RandShares(64)}, } for i, tt := range tests { @@ -357,7 +357,7 @@ func TestGetSharesWithProofsByNamespace(t *testing.T) { eds, err := AddShares(ctx, tt.rawData, bServ) require.NoError(t, err) - var shares []gosquare.Share + var shares []libshare.Share rowRoots, err := eds.RowRoots() require.NoError(t, err) for _, row := range rowRoots { @@ -392,7 +392,7 @@ func TestGetSharesWithProofsByNamespace(t *testing.T) { verified = proof.VerifyInclusion( share.NewSHA256Hasher(), namespace.Bytes(), - gosquare.ToBytes(rowShares), + libshare.ToBytes(rowShares), row) require.True(t, verified) } @@ -428,7 +428,7 @@ func TestBatchSize(t *testing.T) { randEds := edstest.RandEDS(t, tt.origWidth) - shrs, err := gosquare.FromBytes(randEds.FlattenedODS()) + shrs, err := libshare.FromBytes(randEds.FlattenedODS()) require.NoError(t, err) _, err = AddShares(ctx, shrs, bs) require.NoError(t, err) @@ -451,7 +451,7 @@ func assertNoRowContainsNID( t *testing.T, bServ blockservice.BlockService, eds *rsmt2d.ExtendedDataSquare, - namespace gosquare.Namespace, + namespace libshare.Namespace, isAbsent bool, ) { rowRoots, err := eds.RowRoots() @@ -494,10 +494,10 @@ func assertNoRowContainsNID( } } -func randomNamespaces(total int) ([]gosquare.Namespace, error) { - namespaces := make([]gosquare.Namespace, total) +func randomNamespaces(total int) ([]libshare.Namespace, error) { + namespaces := make([]libshare.Namespace, total) for i := range namespaces { - namespaces[i] = gosquare.RandomNamespace() + namespaces[i] = libshare.RandomNamespace() } sort.Slice(namespaces, func(i, j int) bool { return namespaces[i].IsLessThan(namespaces[j]) }) return namespaces, nil diff --git a/share/ipld/namespace_data.go b/share/ipld/namespace_data.go index cafec83cb2..bfbd4cf1ab 100644 --- a/share/ipld/namespace_data.go +++ b/share/ipld/namespace_data.go @@ -11,7 +11,7 @@ import ( "github.com/ipfs/go-cid" ipld "github.com/ipfs/go-ipld-format" - gosquare "github.com/celestiaorg/go-square/v2/share" + libshare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt" "github.com/celestiaorg/celestia-node/share" @@ -47,13 +47,13 @@ type NamespaceData struct { bounds fetchedBounds maxShares int - namespace gosquare.Namespace + namespace libshare.Namespace isAbsentNamespace atomic.Bool absenceProofLeaf ipld.Node } -func NewNamespaceData(maxShares int, namespace gosquare.Namespace, options ...Option) *NamespaceData { +func NewNamespaceData(maxShares int, namespace libshare.Namespace, options ...Option) *NamespaceData { data := &NamespaceData{ maxShares: maxShares, namespace: namespace, @@ -72,7 +72,7 @@ func NewNamespaceData(maxShares int, namespace gosquare.Namespace, options ...Op } func (n *NamespaceData) validate(rootCid cid.Cid) error { - if err := gosquare.ValidateUserNamespace(n.namespace.Version(), n.namespace.ID()); err != nil { + if err := libshare.ValidateUserNamespace(n.namespace.Version(), n.namespace.ID()); err != nil { return err } diff --git a/share/ipld/nmt.go b/share/ipld/nmt.go index 4dad93df36..5db626a27a 100644 --- a/share/ipld/nmt.go +++ b/share/ipld/nmt.go @@ -16,7 +16,7 @@ import ( mh "github.com/multiformats/go-multihash" mhcore "github.com/multiformats/go-multihash/core" - gosquare "github.com/celestiaorg/go-square/v2/share" + libshare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt" "github.com/celestiaorg/celestia-node/share" @@ -36,13 +36,13 @@ const ( sha256NamespaceFlagged = 0x7701 // NmtHashSize is the size of a digest created by an NMT in bytes. - NmtHashSize = 2*gosquare.NamespaceSize + sha256.Size + NmtHashSize = 2*libshare.NamespaceSize + sha256.Size // InnerNodeSize is the size of data in inner nodes. InnerNodeSize = NmtHashSize * 2 // LeafNodeSize is the size of data in leaf nodes. - LeafNodeSize = gosquare.NamespaceSize + gosquare.ShareSize + LeafNodeSize = libshare.NamespaceSize + libshare.ShareSize // cidPrefixSize is the size of the prepended buffer of the CID encoding // for NamespacedSha256. For more information, see: @@ -58,7 +58,7 @@ const ( func init() { // required for Bitswap to hash and verify inbound data correctly mhcore.Register(sha256NamespaceFlagged, func() hash.Hash { - nh := nmt.NewNmtHasher(share.NewSHA256Hasher(), gosquare.NamespaceSize, true) + nh := nmt.NewNmtHasher(share.NewSHA256Hasher(), libshare.NamespaceSize, true) nh.Reset() return nh }) diff --git a/share/ipld/proofs_test.go b/share/ipld/proofs_test.go index d7185d886e..51b3f82bea 100644 --- a/share/ipld/proofs_test.go +++ b/share/ipld/proofs_test.go @@ -7,7 +7,7 @@ import ( "github.com/stretchr/testify/require" - gosquare "github.com/celestiaorg/go-square/v2/share" + libshare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" "github.com/celestiaorg/celestia-node/share" @@ -21,7 +21,7 @@ func TestGetProof(t *testing.T) { defer cancel() bServ := NewMemBlockservice() - shares := gosquare.RandShares(width * width) + shares := libshare.RandShares(width * width) in, err := AddShares(ctx, shares, bServ) require.NoError(t, err) @@ -45,7 +45,7 @@ func TestGetProof(t *testing.T) { node, err := GetLeaf(ctx, bServ, rootCid, shrIdx, int(in.Width())) require.NoError(t, err) - sh, err := gosquare.NewShare(node.RawData()[gosquare.NamespaceSize:]) + sh, err := libshare.NewShare(node.RawData()[libshare.NamespaceSize:]) require.NoError(t, err) sample := shwap.Sample{ Share: *sh, diff --git a/share/ipld/utils.go b/share/ipld/utils.go index e2443d357f..a619c44ee3 100644 --- a/share/ipld/utils.go +++ b/share/ipld/utils.go @@ -3,14 +3,14 @@ package ipld import ( "github.com/ipfs/go-cid" - gosquare "github.com/celestiaorg/go-square/v2/share" + libshare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/celestia-node/share" ) // FilterRootByNamespace returns the row roots from the given share.AxisRoots that contain the // namespace. -func FilterRootByNamespace(root *share.AxisRoots, namespace gosquare.Namespace) ([]cid.Cid, error) { +func FilterRootByNamespace(root *share.AxisRoots, namespace libshare.Namespace) ([]cid.Cid, error) { rowRootCIDs := make([]cid.Cid, 0, len(root.RowRoots)) for _, row := range root.RowRoots { outside, err := share.IsOutsideRange(namespace, row, row) diff --git a/share/root.go b/share/root.go index 4016e8d473..1571a5f38f 100644 --- a/share/root.go +++ b/share/root.go @@ -8,7 +8,7 @@ import ( "hash" "github.com/celestiaorg/celestia-app/v3/pkg/da" - gosquare "github.com/celestiaorg/go-square/v2/share" + libshare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" ) @@ -59,7 +59,7 @@ func NewAxisRoots(eds *rsmt2d.ExtendedDataSquare) (*AxisRoots, error) { // RowsWithNamespace inspects the AxisRoots for the Namespace and provides // a slices of Row indexes containing the namespace. -func RowsWithNamespace(root *AxisRoots, namespace gosquare.Namespace) (idxs []int, err error) { +func RowsWithNamespace(root *AxisRoots, namespace libshare.Namespace) (idxs []int, err error) { for i, row := range root.RowRoots { outside, err := IsOutsideRange(namespace, row, row) if err != nil { @@ -94,18 +94,18 @@ func MustDataHashFromString(datahash string) DataHash { } // IsOutsideRange checks if the namespace is outside the min-max range of the given hashes. -func IsOutsideRange(namespace gosquare.Namespace, leftHash, rightHash []byte) (bool, error) { - if len(leftHash) < gosquare.NamespaceSize { - return false, fmt.Errorf("left can't be less than %d", gosquare.NamespaceSize) +func IsOutsideRange(namespace libshare.Namespace, leftHash, rightHash []byte) (bool, error) { + if len(leftHash) < libshare.NamespaceSize { + return false, fmt.Errorf("left can't be less than %d", libshare.NamespaceSize) } - if len(rightHash) < 2*gosquare.NamespaceSize { - return false, fmt.Errorf("rightHash can't be less than %d", 2*gosquare.NamespaceSize) + if len(rightHash) < 2*libshare.NamespaceSize { + return false, fmt.Errorf("rightHash can't be less than %d", 2*libshare.NamespaceSize) } - ns1, err := gosquare.NewNamespaceFromBytes(leftHash[:gosquare.NamespaceSize]) + ns1, err := libshare.NewNamespaceFromBytes(leftHash[:libshare.NamespaceSize]) if err != nil { return false, err } - ns2, err := gosquare.NewNamespaceFromBytes(rightHash[gosquare.NamespaceSize : gosquare.NamespaceSize*2]) + ns2, err := libshare.NewNamespaceFromBytes(rightHash[libshare.NamespaceSize : libshare.NamespaceSize*2]) if err != nil { return false, err } @@ -113,11 +113,11 @@ func IsOutsideRange(namespace gosquare.Namespace, leftHash, rightHash []byte) (b } // IsAboveMax checks if the namespace is above the maximum namespace of the given hash. -func IsAboveMax(namespace gosquare.Namespace, hash []byte) (bool, error) { - if len(hash) < 2*gosquare.NamespaceSize { - return false, fmt.Errorf("hash can't be less than: %d", 2*gosquare.NamespaceSize) +func IsAboveMax(namespace libshare.Namespace, hash []byte) (bool, error) { + if len(hash) < 2*libshare.NamespaceSize { + return false, fmt.Errorf("hash can't be less than: %d", 2*libshare.NamespaceSize) } - ns, err := gosquare.NewNamespaceFromBytes(hash[gosquare.NamespaceSize : gosquare.NamespaceSize*2]) + ns, err := libshare.NewNamespaceFromBytes(hash[libshare.NamespaceSize : libshare.NamespaceSize*2]) if err != nil { return false, err } @@ -125,11 +125,11 @@ func IsAboveMax(namespace gosquare.Namespace, hash []byte) (bool, error) { } // IsBelowMin checks if the target namespace is below the minimum namespace of the given hash. -func IsBelowMin(namespace gosquare.Namespace, hash []byte) (bool, error) { - if len(hash) < gosquare.NamespaceSize { - return false, fmt.Errorf("hash can't be less than: %d", gosquare.NamespaceSize) +func IsBelowMin(namespace libshare.Namespace, hash []byte) (bool, error) { + if len(hash) < libshare.NamespaceSize { + return false, fmt.Errorf("hash can't be less than: %d", libshare.NamespaceSize) } - ns1, err := gosquare.NewNamespaceFromBytes(hash[:gosquare.NamespaceSize]) + ns1, err := libshare.NewNamespaceFromBytes(hash[:libshare.NamespaceSize]) if err != nil { return false, err } diff --git a/share/share.go b/share/share.go index 3fb654a1a0..d7f0bb2ca5 100644 --- a/share/share.go +++ b/share/share.go @@ -2,7 +2,7 @@ package share import ( "github.com/celestiaorg/celestia-app/v3/pkg/appconsts" - gosquare "github.com/celestiaorg/go-square/v2/share" + libshare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt" "github.com/celestiaorg/rsmt2d" ) @@ -17,7 +17,7 @@ var MaxSquareSize = appconsts.SquareSizeUpperBound(appconsts.LatestVersion) // ShareWithProof contains data with corresponding Merkle Proof type ShareWithProof struct { //nolint: revive // Share is a full data including namespace - gosquare.Share + libshare.Share // Proof is a Merkle Proof of current share Proof *nmt.Proof // Axis is a type of axis against which the share proof is computed @@ -27,7 +27,7 @@ type ShareWithProof struct { //nolint: revive // Validate validates inclusion of the share under the given root CID. func (s *ShareWithProof) Validate(rootHash []byte, x, y, edsSize int) bool { isParity := x >= edsSize/2 || y >= edsSize/2 - namespace := gosquare.ParitySharesNamespace + namespace := libshare.ParitySharesNamespace if !isParity { namespace = s.Share.Namespace() } diff --git a/share/shwap/getter.go b/share/shwap/getter.go index fbb1050e63..a4cc00ae06 100644 --- a/share/shwap/getter.go +++ b/share/shwap/getter.go @@ -5,7 +5,7 @@ import ( "errors" "fmt" - gosquare "github.com/celestiaorg/go-square/v2/share" + libshare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" "github.com/celestiaorg/celestia-node/header" @@ -30,7 +30,7 @@ var ( //go:generate mockgen -destination=getters/mock/getter.go -package=mock . Getter type Getter interface { // GetShare gets a Share by coordinates in EDS. - GetShare(ctx context.Context, header *header.ExtendedHeader, row, col int) (gosquare.Share, error) + GetShare(ctx context.Context, header *header.ExtendedHeader, row, col int) (libshare.Share, error) // GetEDS gets the full EDS identified by the given extended header. GetEDS(context.Context, *header.ExtendedHeader) (*rsmt2d.ExtendedDataSquare, error) @@ -40,5 +40,5 @@ type Getter interface { // Inclusion of returned data could be verified using Verify method on NamespacedShares. // If no shares are found for target namespace non-inclusion could be also verified by calling // Verify method. - GetSharesByNamespace(context.Context, *header.ExtendedHeader, gosquare.Namespace) (NamespaceData, error) + GetSharesByNamespace(context.Context, *header.ExtendedHeader, libshare.Namespace) (NamespaceData, error) } diff --git a/share/shwap/getters/cascade.go b/share/shwap/getters/cascade.go index 80736198e6..510773008f 100644 --- a/share/shwap/getters/cascade.go +++ b/share/shwap/getters/cascade.go @@ -10,7 +10,7 @@ import ( "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/trace" - gosquare "github.com/celestiaorg/go-square/v2/share" + libshare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" "github.com/celestiaorg/celestia-node/header" @@ -44,7 +44,7 @@ func NewCascadeGetter(getters []shwap.Getter) *CascadeGetter { // GetShare gets a share from any of registered shwap.Getters in cascading order. func (cg *CascadeGetter) GetShare( ctx context.Context, header *header.ExtendedHeader, row, col int, -) (gosquare.Share, error) { +) (libshare.Share, error) { ctx, span := tracer.Start(ctx, "cascade/get-share", trace.WithAttributes( attribute.Int("row", row), attribute.Int("col", col), @@ -55,9 +55,9 @@ func (cg *CascadeGetter) GetShare( if row >= upperBound || col >= upperBound { err := shwap.ErrOutOfBounds span.RecordError(err) - return gosquare.Share{}, err + return libshare.Share{}, err } - get := func(ctx context.Context, get shwap.Getter) (gosquare.Share, error) { + get := func(ctx context.Context, get shwap.Getter) (libshare.Share, error) { return get.GetShare(ctx, header, row, col) } @@ -83,7 +83,7 @@ func (cg *CascadeGetter) GetEDS( func (cg *CascadeGetter) GetSharesByNamespace( ctx context.Context, header *header.ExtendedHeader, - namespace gosquare.Namespace, + namespace libshare.Namespace, ) (shwap.NamespaceData, error) { ctx, span := tracer.Start(ctx, "cascade/get-shares-by-namespace", trace.WithAttributes( attribute.String("namespace", namespace.String()), diff --git a/share/shwap/getters/testing.go b/share/shwap/getters/testing.go index 55a5580a90..6759246d25 100644 --- a/share/shwap/getters/testing.go +++ b/share/shwap/getters/testing.go @@ -8,7 +8,7 @@ import ( "github.com/stretchr/testify/require" "github.com/celestiaorg/celestia-app/v3/pkg/da" - gosquare "github.com/celestiaorg/go-square/v2/share" + libshare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" "github.com/celestiaorg/celestia-node/header" @@ -40,15 +40,15 @@ func (seg *SingleEDSGetter) GetShare( _ context.Context, header *header.ExtendedHeader, row, col int, -) (gosquare.Share, error) { +) (libshare.Share, error) { err := seg.checkRoots(header.DAH) if err != nil { - return gosquare.Share{}, err + return libshare.Share{}, err } rawSh := seg.EDS.GetCell(uint(row), uint(col)) - sh, err := gosquare.NewShare(rawSh) + sh, err := libshare.NewShare(rawSh) if err != nil { - return gosquare.Share{}, err + return libshare.Share{}, err } return *sh, nil } @@ -66,7 +66,7 @@ func (seg *SingleEDSGetter) GetEDS( } // GetSharesByNamespace returns NamespacedShares from a kept EDS if the correct root is given. -func (seg *SingleEDSGetter) GetSharesByNamespace(context.Context, *header.ExtendedHeader, gosquare.Namespace, +func (seg *SingleEDSGetter) GetSharesByNamespace(context.Context, *header.ExtendedHeader, libshare.Namespace, ) (shwap.NamespaceData, error) { panic("SingleEDSGetter: GetSharesByNamespace is not implemented") } diff --git a/share/shwap/namespace_data.go b/share/shwap/namespace_data.go index 785d0c0dbe..1cc9078d18 100644 --- a/share/shwap/namespace_data.go +++ b/share/shwap/namespace_data.go @@ -5,7 +5,7 @@ import ( "fmt" "io" - gosquare "github.com/celestiaorg/go-square/v2/share" + libshare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/celestia-node/share" ) @@ -20,8 +20,8 @@ const NamespaceDataName = "nd_v0" type NamespaceData []RowNamespaceData // Flatten combines all shares from all rows within the namespace into a single slice. -func (nd NamespaceData) Flatten() []gosquare.Share { - var shares []gosquare.Share +func (nd NamespaceData) Flatten() []libshare.Share { + var shares []libshare.Share for _, row := range nd { shares = append(shares, row.Shares...) } @@ -29,7 +29,7 @@ func (nd NamespaceData) Flatten() []gosquare.Share { } // Verify checks the integrity of the NamespaceData against a provided root and namespace. -func (nd NamespaceData) Verify(root *share.AxisRoots, namespace gosquare.Namespace) error { +func (nd NamespaceData) Verify(root *share.AxisRoots, namespace libshare.Namespace) error { rowIdxs, err := share.RowsWithNamespace(root, namespace) if err != nil { return err diff --git a/share/shwap/namespace_data_id.go b/share/shwap/namespace_data_id.go index 3e4b288c3f..cb3baa30bd 100644 --- a/share/shwap/namespace_data_id.go +++ b/share/shwap/namespace_data_id.go @@ -4,24 +4,24 @@ import ( "fmt" "io" - gosquare "github.com/celestiaorg/go-square/v2/share" + libshare "github.com/celestiaorg/go-square/v2/share" ) // NamespaceDataIDSize defines the total size of a NamespaceDataID in bytes, combining the // size of a EdsID and the size of a Namespace. -const NamespaceDataIDSize = EdsIDSize + gosquare.NamespaceSize +const NamespaceDataIDSize = EdsIDSize + libshare.NamespaceSize // NamespaceDataID filters the data in the EDS by a specific namespace. type NamespaceDataID struct { // Embedding EdsID to include the block height. EdsID // DataNamespace will be used to identify the data within the EDS. - DataNamespace gosquare.Namespace + DataNamespace libshare.Namespace } // NewNamespaceDataID creates a new NamespaceDataID with the specified parameters. It // validates the namespace and returns an error if it is invalid. -func NewNamespaceDataID(height uint64, namespace gosquare.Namespace) (NamespaceDataID, error) { +func NewNamespaceDataID(height uint64, namespace libshare.Namespace) (NamespaceDataID, error) { ndid := NamespaceDataID{ EdsID: EdsID{ Height: height, @@ -48,7 +48,7 @@ func NamespaceDataIDFromBinary(data []byte) (NamespaceDataID, error) { return NamespaceDataID{}, fmt.Errorf("error unmarshaling EDSID: %w", err) } - ns, err := gosquare.NewNamespaceFromBytes(data[EdsIDSize:]) + ns, err := libshare.NewNamespaceFromBytes(data[EdsIDSize:]) if err != nil { return NamespaceDataID{}, fmt.Errorf("error unmarshaling namespace: %w", err) } @@ -112,7 +112,7 @@ func (ndid NamespaceDataID) Validate() error { return fmt.Errorf("validating RowID: %w", err) } - if err := gosquare.ValidateForData(ndid.DataNamespace); err != nil { + if err := libshare.ValidateForData(ndid.DataNamespace); err != nil { return fmt.Errorf("%w: validating DataNamespace: %w", ErrInvalidID, err) } return nil diff --git a/share/shwap/namespace_data_id_test.go b/share/shwap/namespace_data_id_test.go index c978db85a4..c30f75b3bc 100644 --- a/share/shwap/namespace_data_id_test.go +++ b/share/shwap/namespace_data_id_test.go @@ -7,11 +7,11 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - gosquare "github.com/celestiaorg/go-square/v2/share" + libshare "github.com/celestiaorg/go-square/v2/share" ) func TestNamespaceDataID(t *testing.T) { - ns := gosquare.RandomNamespace() + ns := libshare.RandomNamespace() id, err := NewNamespaceDataID(1, ns) require.NoError(t, err) @@ -29,7 +29,7 @@ func TestNamespaceDataID(t *testing.T) { } func TestNamespaceDataIDReaderWriter(t *testing.T) { - ns := gosquare.RandomNamespace() + ns := libshare.RandomNamespace() id, err := NewNamespaceDataID(1, ns) require.NoError(t, err) diff --git a/share/shwap/p2p/bitswap/getter.go b/share/shwap/p2p/bitswap/getter.go index 9f0c97ec03..7717fcbb4f 100644 --- a/share/shwap/p2p/bitswap/getter.go +++ b/share/shwap/p2p/bitswap/getter.go @@ -12,7 +12,7 @@ import ( "go.opentelemetry.io/otel/trace" "github.com/celestiaorg/celestia-app/v3/pkg/wrapper" - gosquare "github.com/celestiaorg/go-square/v2/share" + libshare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" "github.com/celestiaorg/celestia-node/header" @@ -72,7 +72,7 @@ func (g *Getter) GetShares( ctx context.Context, hdr *header.ExtendedHeader, rowIdxs, colIdxs []int, -) ([]gosquare.Share, error) { +) ([]libshare.Share, error) { if len(rowIdxs) != len(colIdxs) { return nil, fmt.Errorf("row indecies and col indices must be same length") } @@ -104,7 +104,7 @@ func (g *Getter) GetShares( return nil, err } - shares := make([]gosquare.Share, len(blks)) + shares := make([]libshare.Share, len(blks)) for i, blk := range blks { shares[i] = blk.(*SampleBlock).Container.Share } @@ -118,14 +118,14 @@ func (g *Getter) GetShare( ctx context.Context, hdr *header.ExtendedHeader, row, col int, -) (gosquare.Share, error) { +) (libshare.Share, error) { shrs, err := g.GetShares(ctx, hdr, []int{row}, []int{col}) if err != nil { - return gosquare.Share{}, err + return libshare.Share{}, err } if len(shrs) != 1 { - return gosquare.Share{}, fmt.Errorf("expected 1 share row, got %d", len(shrs)) + return libshare.Share{}, fmt.Errorf("expected 1 share row, got %d", len(shrs)) } return shrs[0], nil @@ -185,9 +185,9 @@ func (g *Getter) GetEDS( func (g *Getter) GetSharesByNamespace( ctx context.Context, hdr *header.ExtendedHeader, - ns gosquare.Namespace, + ns libshare.Namespace, ) (shwap.NamespaceData, error) { - if err := gosquare.ValidateForData(ns); err != nil { + if err := libshare.ValidateForData(ns); err != nil { return nil, err } @@ -245,7 +245,7 @@ func (g *Getter) session(ctx context.Context, hdr *header.ExtendedHeader) exchan // edsFromRows imports given Rows and computes EDS out of them, assuming enough Rows were provided. // It is designed to reuse Row halves computed during verification on [Fetch] level. func edsFromRows(roots *share.AxisRoots, rows []shwap.Row) (*rsmt2d.ExtendedDataSquare, error) { - shrs := make([]gosquare.Share, len(roots.RowRoots)*len(roots.RowRoots)) + shrs := make([]libshare.Share, len(roots.RowRoots)*len(roots.RowRoots)) for i, row := range rows { rowShrs, err := row.Shares() if err != nil { @@ -258,7 +258,7 @@ func edsFromRows(roots *share.AxisRoots, rows []shwap.Row) (*rsmt2d.ExtendedData } square, err := rsmt2d.ImportExtendedDataSquare( - gosquare.ToBytes(shrs), + libshare.ToBytes(shrs), share.DefaultRSMT2DCodec(), wrapper.NewConstructor(uint64(len(roots.RowRoots)/2)), ) diff --git a/share/shwap/p2p/bitswap/getter_test.go b/share/shwap/p2p/bitswap/getter_test.go index e543e0f76f..cdabcb73be 100644 --- a/share/shwap/p2p/bitswap/getter_test.go +++ b/share/shwap/p2p/bitswap/getter_test.go @@ -5,7 +5,7 @@ import ( "github.com/stretchr/testify/require" - gosquare "github.com/celestiaorg/go-square/v2/share" + libshare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/celestia-node/share" "github.com/celestiaorg/celestia-node/share/eds/edstest" @@ -19,7 +19,7 @@ func TestEDSFromRows(t *testing.T) { rows := make([]shwap.Row, edsIn.Width()/2) for i := range edsIn.Width() / 2 { - rowShrs, err := gosquare.FromBytes(edsIn.Row(i)[:edsIn.Width()/2]) + rowShrs, err := libshare.FromBytes(edsIn.Row(i)[:edsIn.Width()/2]) require.NoError(t, err) rows[i] = shwap.NewRow(rowShrs, shwap.Left) } diff --git a/share/shwap/p2p/bitswap/row_namespace_data_block.go b/share/shwap/p2p/bitswap/row_namespace_data_block.go index 704ad3f616..52ddbd9520 100644 --- a/share/shwap/p2p/bitswap/row_namespace_data_block.go +++ b/share/shwap/p2p/bitswap/row_namespace_data_block.go @@ -6,7 +6,7 @@ import ( "github.com/ipfs/go-cid" - gosquare "github.com/celestiaorg/go-square/v2/share" + libshare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/celestia-node/share" "github.com/celestiaorg/celestia-node/share/eds" @@ -44,7 +44,7 @@ type RowNamespaceDataBlock struct { func NewEmptyRowNamespaceDataBlock( height uint64, rowIdx int, - namespace gosquare.Namespace, + namespace libshare.Namespace, edsSize int, ) (*RowNamespaceDataBlock, error) { id, err := shwap.NewRowNamespaceDataID(height, rowIdx, namespace, edsSize) diff --git a/share/shwap/p2p/bitswap/row_namespace_data_block_test.go b/share/shwap/p2p/bitswap/row_namespace_data_block_test.go index 9cfe45da4f..c4cd00999c 100644 --- a/share/shwap/p2p/bitswap/row_namespace_data_block_test.go +++ b/share/shwap/p2p/bitswap/row_namespace_data_block_test.go @@ -7,7 +7,7 @@ import ( "github.com/stretchr/testify/require" - gosquare "github.com/celestiaorg/go-square/v2/share" + libshare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/celestia-node/share" "github.com/celestiaorg/celestia-node/share/eds/edstest" @@ -17,7 +17,7 @@ func TestRowNamespaceData_FetchRoundtrip(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), time.Second*5) defer cancel() - namespace := gosquare.RandomNamespace() + namespace := libshare.RandomNamespace() eds, root := edstest.RandEDSWithNamespace(t, namespace, 64, 16) exchange := newExchangeOverEDS(ctx, t, eds) diff --git a/share/shwap/p2p/shrex/shrex_getter/shrex.go b/share/shwap/p2p/shrex/shrex_getter/shrex.go index 1f6a3a0031..bed2880458 100644 --- a/share/shwap/p2p/shrex/shrex_getter/shrex.go +++ b/share/shwap/p2p/shrex/shrex_getter/shrex.go @@ -13,7 +13,7 @@ import ( "go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/trace" - gosquare "github.com/celestiaorg/go-square/v2/share" + libshare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" "github.com/celestiaorg/celestia-node/header" @@ -146,8 +146,8 @@ func (sg *Getter) Stop(ctx context.Context) error { return sg.archivalPeerManager.Stop(ctx) } -func (sg *Getter) GetShare(context.Context, *header.ExtendedHeader, int, int) (gosquare.Share, error) { - return gosquare.Share{}, fmt.Errorf("getter/shrex: GetShare %w", shwap.ErrOperationNotSupported) +func (sg *Getter) GetShare(context.Context, *header.ExtendedHeader, int, int) (libshare.Share, error) { + return libshare.Share{}, fmt.Errorf("getter/shrex: GetShare %w", shwap.ErrOperationNotSupported) } func (sg *Getter) GetEDS(ctx context.Context, header *header.ExtendedHeader) (*rsmt2d.ExtendedDataSquare, error) { @@ -217,9 +217,9 @@ func (sg *Getter) GetEDS(ctx context.Context, header *header.ExtendedHeader) (*r func (sg *Getter) GetSharesByNamespace( ctx context.Context, header *header.ExtendedHeader, - namespace gosquare.Namespace, + namespace libshare.Namespace, ) (shwap.NamespaceData, error) { - if err := gosquare.ValidateForData(namespace); err != nil { + if err := libshare.ValidateForData(namespace); err != nil { return nil, err } var ( diff --git a/share/shwap/p2p/shrex/shrex_getter/shrex_test.go b/share/shwap/p2p/shrex/shrex_getter/shrex_test.go index dc6f0817ca..dcf81fbac1 100644 --- a/share/shwap/p2p/shrex/shrex_getter/shrex_test.go +++ b/share/shwap/p2p/shrex/shrex_getter/shrex_test.go @@ -15,7 +15,7 @@ import ( "github.com/stretchr/testify/require" libhead "github.com/celestiaorg/go-header" - gosquare "github.com/celestiaorg/go-square/v2/share" + libshare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt" "github.com/celestiaorg/rsmt2d" @@ -69,7 +69,7 @@ func TestShrexGetter(t *testing.T) { // generate test data size := 64 - namespace := gosquare.RandomNamespace() + namespace := libshare.RandomNamespace() height := height.Add(1) randEDS, roots := edstest.RandEDSWithNamespace(t, namespace, size*size, size) eh := headertest.RandExtendedHeaderWithRoot(t, roots) @@ -124,7 +124,7 @@ func TestShrexGetter(t *testing.T) { }) // namespace inside root range - nID, err := gosquare.AddInt(maxNamespace, -1) + nID, err := libshare.AddInt(maxNamespace, -1) require.NoError(t, err) // check for namespace to be between max and min namespace in root rows, err := share.RowsWithNamespace(roots, nID) @@ -138,7 +138,7 @@ func TestShrexGetter(t *testing.T) { require.Nil(t, emptyShares.Verify(roots, nID)) // namespace outside root range - nID, err = gosquare.AddInt(maxNamespace, 1) + nID, err = libshare.AddInt(maxNamespace, 1) require.NoError(t, err) // check for namespace to be not in root rows, err = share.RowsWithNamespace(roots, nID) @@ -169,7 +169,7 @@ func TestShrexGetter(t *testing.T) { Height: height, }) - namespace, err := gosquare.AddInt(maxNamespace, 1) + namespace, err := libshare.AddInt(maxNamespace, 1) require.NoError(t, err) // check for namespace to be not in root rows, err := share.RowsWithNamespace(roots, namespace) @@ -281,12 +281,12 @@ func newStore(t *testing.T) (*store.Store, error) { return store.NewStore(store.DefaultParameters(), t.TempDir()) } -func generateTestEDS(t *testing.T) (*rsmt2d.ExtendedDataSquare, *share.AxisRoots, gosquare.Namespace) { +func generateTestEDS(t *testing.T) (*rsmt2d.ExtendedDataSquare, *share.AxisRoots, libshare.Namespace) { eds := edstest.RandEDS(t, 4) roots, err := share.NewAxisRoots(eds) require.NoError(t, err) - max := nmt.MaxNamespace(roots.RowRoots[(len(roots.RowRoots))/2-1], gosquare.NamespaceSize) - ns, err := gosquare.NewNamespaceFromBytes(max) + max := nmt.MaxNamespace(roots.RowRoots[(len(roots.RowRoots))/2-1], libshare.NamespaceSize) + ns, err := libshare.NewNamespaceFromBytes(max) require.NoError(t, err) return eds, roots, ns } diff --git a/share/shwap/p2p/shrex/shrexnd/client.go b/share/shwap/p2p/shrex/shrexnd/client.go index e22dec736b..9a3780b325 100644 --- a/share/shwap/p2p/shrex/shrexnd/client.go +++ b/share/shwap/p2p/shrex/shrexnd/client.go @@ -14,7 +14,7 @@ import ( "github.com/libp2p/go-libp2p/core/protocol" "github.com/celestiaorg/go-libp2p-messenger/serde" - gosquare "github.com/celestiaorg/go-square/v2/share" + libshare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/celestia-node/libs/utils" "github.com/celestiaorg/celestia-node/share/shwap" @@ -50,10 +50,10 @@ func NewClient(params *Parameters, host host.Host) (*Client, error) { func (c *Client) RequestND( ctx context.Context, height uint64, - namespace gosquare.Namespace, + namespace libshare.Namespace, peer peer.ID, ) (shwap.NamespaceData, error) { - if err := gosquare.ValidateForData(namespace); err != nil { + if err := libshare.ValidateForData(namespace); err != nil { return nil, err } @@ -83,7 +83,7 @@ func (c *Client) RequestND( func (c *Client) doRequest( ctx context.Context, height uint64, - namespace gosquare.Namespace, + namespace libshare.Namespace, peerID peer.ID, ) (shwap.NamespaceData, error) { streamOpenCtx, cancel := context.WithTimeout(ctx, c.params.ServerReadTimeout) diff --git a/share/shwap/p2p/shrex/shrexnd/doc.go b/share/shwap/p2p/shrex/shrexnd/doc.go index e31abaeb80..63daf6d0b2 100644 --- a/share/shwap/p2p/shrex/shrexnd/doc.go +++ b/share/shwap/p2p/shrex/shrexnd/doc.go @@ -22,7 +22,7 @@ // // data, err := client.RequestND(ctx, dataRoot, peerID, namespaceID) // -// where data is of type [gosquare.NamespacedShares] +// where data is of type [libshare.NamespacedShares] // // To use a shrexnd server to respond to requests from peers, you must first create a new `shrexnd.Server` instance by: // diff --git a/share/shwap/p2p/shrex/shrexnd/exchange_test.go b/share/shwap/p2p/shrex/shrexnd/exchange_test.go index 5414d781e5..450e8c2058 100644 --- a/share/shwap/p2p/shrex/shrexnd/exchange_test.go +++ b/share/shwap/p2p/shrex/shrexnd/exchange_test.go @@ -12,7 +12,7 @@ import ( mocknet "github.com/libp2p/go-libp2p/p2p/net/mock" "github.com/stretchr/testify/require" - gosquare "github.com/celestiaorg/go-square/v2/share" + libshare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/celestia-node/share" "github.com/celestiaorg/celestia-node/share/eds/edstest" @@ -33,7 +33,7 @@ func TestExchange_RequestND_NotFound(t *testing.T) { ctx, cancel := context.WithTimeout(ctx, time.Second) t.Cleanup(cancel) - namespace := gosquare.RandomNamespace() + namespace := libshare.RandomNamespace() height := height.Add(1) _, err := client.RequestND(ctx, height, namespace, server.host.ID()) require.ErrorIs(t, err, shrex.ErrNotFound) @@ -51,7 +51,7 @@ func TestExchange_RequestND_NotFound(t *testing.T) { err = edsStore.PutODSQ4(ctx, roots, height, eds) require.NoError(t, err) - namespace := gosquare.RandomNamespace() + namespace := libshare.RandomNamespace() emptyShares, err := client.RequestND(ctx, height, namespace, server.host.ID()) require.NoError(t, err) require.Empty(t, emptyShares.Flatten()) @@ -95,13 +95,13 @@ func TestExchange_RequestND(t *testing.T) { // take server concurrency slots with blocked requests for i := 0; i < rateLimit; i++ { go func(i int) { - client.RequestND(ctx, 1, gosquare.RandomNamespace(), server.host.ID()) //nolint:errcheck + client.RequestND(ctx, 1, libshare.RandomNamespace(), server.host.ID()) //nolint:errcheck }(i) } // wait until all server slots are taken wg.Wait() - _, err = client.RequestND(ctx, 1, gosquare.RandomNamespace(), server.host.ID()) + _, err = client.RequestND(ctx, 1, libshare.RandomNamespace(), server.host.ID()) require.ErrorIs(t, err, shrex.ErrRateLimited) }) } diff --git a/share/shwap/p2p/shrex/shrexsub/pb/notification.pb.go b/share/shwap/p2p/shrex/shrexsub/pb/notification.pb.go index 0be95ead3d..6102251ff1 100644 --- a/share/shwap/p2p/shrex/shrexsub/pb/notification.pb.go +++ b/share/shwap/p2p/shrex/shrexsub/pb/notification.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-gogo. DO NOT EDIT. // source: share/shwap/p2p/shrex/shrexsub/pb/notification.proto -package gosquare_p2p_shrex_sub +package libshare_p2p_shrex_sub import ( fmt "fmt" diff --git a/share/shwap/row.go b/share/shwap/row.go index 013dd3d2bf..ba2c0d0b82 100644 --- a/share/shwap/row.go +++ b/share/shwap/row.go @@ -5,7 +5,7 @@ import ( "fmt" "github.com/celestiaorg/celestia-app/v3/pkg/wrapper" - gosquare "github.com/celestiaorg/go-square/v2/share" + libshare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/celestia-node/share" "github.com/celestiaorg/celestia-node/share/shwap/pb" @@ -24,12 +24,12 @@ const ( // Row represents a portion of a row in an EDS, either left or right half. type Row struct { - halfShares []gosquare.Share // halfShares holds the shares of either the left or right half of a row. + halfShares []libshare.Share // halfShares holds the shares of either the left or right half of a row. side RowSide // side indicates whether the row half is left or right. } // NewRow creates a new Row with the specified shares and side. -func NewRow(halfShares []gosquare.Share, side RowSide) Row { +func NewRow(halfShares []libshare.Share, side RowSide) Row { return Row{ halfShares: halfShares, side: side, @@ -38,8 +38,8 @@ func NewRow(halfShares []gosquare.Share, side RowSide) Row { // RowFromShares constructs a new Row from an Extended Data Square based on the specified index and // side. -func RowFromShares(shares []gosquare.Share, side RowSide) Row { - var halfShares []gosquare.Share +func RowFromShares(shares []libshare.Share, side RowSide) Row { + var halfShares []libshare.Share if side == Right { halfShares = shares[len(shares)/2:] // Take the right half of the shares. } else { @@ -63,8 +63,8 @@ func RowFromProto(r *pb.Row) (Row, error) { // Shares reconstructs the complete row shares from the half provided, using RSMT2D for data // recovery if needed. -func (r Row) Shares() ([]gosquare.Share, error) { - shares := make([]gosquare.Share, len(r.halfShares)*2) +func (r Row) Shares() ([]libshare.Share, error) { + shares := make([]libshare.Share, len(r.halfShares)*2) offset := 0 if r.side == Right { offset = len(r.halfShares) // Position the halfShares in the second half if it's the right side. @@ -73,11 +73,11 @@ func (r Row) Shares() ([]gosquare.Share, error) { shares[i+offset] = share } - rowShares, err := share.DefaultRSMT2DCodec().Decode(gosquare.ToBytes(shares)) + rowShares, err := share.DefaultRSMT2DCodec().Decode(libshare.ToBytes(shares)) if err != nil { return nil, err } - return gosquare.FromBytes(rowShares) + return libshare.FromBytes(rowShares) } // ToProto converts the Row to its protobuf representation. diff --git a/share/shwap/row_namespace_data.go b/share/shwap/row_namespace_data.go index b0620450a7..aeebdfdb28 100644 --- a/share/shwap/row_namespace_data.go +++ b/share/shwap/row_namespace_data.go @@ -8,7 +8,7 @@ import ( "github.com/celestiaorg/celestia-app/v3/pkg/appconsts" "github.com/celestiaorg/celestia-app/v3/pkg/wrapper" "github.com/celestiaorg/go-libp2p-messenger/serde" - gosquare "github.com/celestiaorg/go-square/v2/share" + libshare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt" nmt_pb "github.com/celestiaorg/nmt/pb" @@ -26,21 +26,21 @@ var ErrNamespaceOutsideRange = errors.New("target namespace is outside of namesp // RowNamespaceData holds shares and their corresponding proof for a single row within a namespace. type RowNamespaceData struct { - Shares []gosquare.Share `json:"shares"` // Shares within the namespace. + Shares []libshare.Share `json:"shares"` // Shares within the namespace. Proof *nmt.Proof `json:"proof"` // Proof of the shares' inclusion in the namespace. } // RowNamespaceDataFromShares extracts and constructs a RowNamespaceData from shares within the // specified namespace. func RowNamespaceDataFromShares( - shares []gosquare.Share, - namespace gosquare.Namespace, + shares []libshare.Share, + namespace libshare.Namespace, rowIndex int, ) (RowNamespaceData, error) { tree := wrapper.NewErasuredNamespacedMerkleTree(uint64(len(shares)/2), uint(rowIndex)) nmtTree := nmt.New( appconsts.NewBaseHashFunc(), - nmt.NamespaceIDSize(gosquare.NamespaceSize), + nmt.NamespaceIDSize(libshare.NamespaceSize), nmt.IgnoreMaxNamespace(true), ) tree.SetTree(nmtTree) @@ -89,7 +89,7 @@ func RowNamespaceDataFromShares( }, nil } - namespacedShares := make([]gosquare.Share, count) + namespacedShares := make([]libshare.Share, count) copy(namespacedShares, shares[from:from+count]) proof, err := tree.ProveRange(from, from+count) @@ -154,7 +154,7 @@ func (rnd RowNamespaceData) IsEmpty() bool { } // Verify checks validity of the RowNamespaceData against the AxisRoots, Namespace and Row index. -func (rnd RowNamespaceData) Verify(roots *share.AxisRoots, namespace gosquare.Namespace, rowIdx int) error { +func (rnd RowNamespaceData) Verify(roots *share.AxisRoots, namespace libshare.Namespace, rowIdx int) error { if rnd.Proof == nil || rnd.Proof.IsEmptyProof() { return fmt.Errorf("nil proof") } @@ -182,7 +182,7 @@ func (rnd RowNamespaceData) Verify(roots *share.AxisRoots, namespace gosquare.Na } // verifyInclusion checks the inclusion of the row's shares in the provided root using NMT. -func (rnd RowNamespaceData) verifyInclusion(rowRoot []byte, namespace gosquare.Namespace) bool { +func (rnd RowNamespaceData) verifyInclusion(rowRoot []byte, namespace libshare.Namespace) bool { leaves := make([][]byte, 0, len(rnd.Shares)) for _, sh := range rnd.Shares { namespaceBytes := sh.Namespace().Bytes() diff --git a/share/shwap/row_namespace_data_id.go b/share/shwap/row_namespace_data_id.go index c9c8050b6c..eec3d2935d 100644 --- a/share/shwap/row_namespace_data_id.go +++ b/share/shwap/row_namespace_data_id.go @@ -4,19 +4,19 @@ import ( "fmt" "io" - gosquare "github.com/celestiaorg/go-square/v2/share" + libshare "github.com/celestiaorg/go-square/v2/share" ) // RowNamespaceDataIDSize defines the total size of a RowNamespaceDataID in bytes, combining the // size of a RowID and the size of a Namespace. -const RowNamespaceDataIDSize = RowIDSize + gosquare.NamespaceSize +const RowNamespaceDataIDSize = RowIDSize + libshare.NamespaceSize // RowNamespaceDataID uniquely identifies a piece of namespaced data within a row of an Extended // Data Square (EDS). type RowNamespaceDataID struct { RowID // Embedded RowID representing the specific row in the EDS. // DataNamespace is a string representation of the namespace to facilitate comparisons. - DataNamespace gosquare.Namespace + DataNamespace libshare.Namespace } // NewRowNamespaceDataID creates a new RowNamespaceDataID with the specified parameters. It @@ -24,7 +24,7 @@ type RowNamespaceDataID struct { func NewRowNamespaceDataID( height uint64, rowIdx int, - namespace gosquare.Namespace, + namespace libshare.Namespace, edsSize int, ) (RowNamespaceDataID, error) { did := RowNamespaceDataID{ @@ -56,7 +56,7 @@ func RowNamespaceDataIDFromBinary(data []byte) (RowNamespaceDataID, error) { return RowNamespaceDataID{}, fmt.Errorf("unmarshaling RowID: %w", err) } - ns, err := gosquare.NewNamespaceFromBytes(data[RowIDSize:]) + ns, err := libshare.NewNamespaceFromBytes(data[RowIDSize:]) if err != nil { return RowNamespaceDataID{}, fmt.Errorf("invalid namespace format: %w", err) } @@ -127,7 +127,7 @@ func (rndid RowNamespaceDataID) Validate() error { if err := rndid.RowID.Validate(); err != nil { return fmt.Errorf("validating RowID: %w", err) } - if err := gosquare.ValidateForData(rndid.DataNamespace); err != nil { + if err := libshare.ValidateForData(rndid.DataNamespace); err != nil { return fmt.Errorf("%w: validating DataNamespace: %w", ErrInvalidID, err) } diff --git a/share/shwap/row_namespace_data_id_test.go b/share/shwap/row_namespace_data_id_test.go index c59e34753f..114e220f9b 100644 --- a/share/shwap/row_namespace_data_id_test.go +++ b/share/shwap/row_namespace_data_id_test.go @@ -7,12 +7,12 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - gosquare "github.com/celestiaorg/go-square/v2/share" + libshare "github.com/celestiaorg/go-square/v2/share" ) func TestRowNamespaceDataID(t *testing.T) { edsSize := 4 - ns := gosquare.RandomNamespace() + ns := libshare.RandomNamespace() id, err := NewRowNamespaceDataID(1, 1, ns, edsSize) require.NoError(t, err) @@ -31,7 +31,7 @@ func TestRowNamespaceDataID(t *testing.T) { func TestRowNamespaceDataIDReaderWriter(t *testing.T) { edsSize := 4 - ns := gosquare.RandomNamespace() + ns := libshare.RandomNamespace() id, err := NewRowNamespaceDataID(1, 1, ns, edsSize) require.NoError(t, err) diff --git a/share/shwap/row_namespace_data_test.go b/share/shwap/row_namespace_data_test.go index 7b136ffa49..1fe7264081 100644 --- a/share/shwap/row_namespace_data_test.go +++ b/share/shwap/row_namespace_data_test.go @@ -9,7 +9,7 @@ import ( "github.com/stretchr/testify/require" - gosquare "github.com/celestiaorg/go-square/v2/share" + libshare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/celestia-node/share" "github.com/celestiaorg/celestia-node/share/eds" @@ -20,17 +20,17 @@ import ( func TestNamespacedRowFromShares(t *testing.T) { const odsSize = 8 - minNamespace, err := gosquare.NewV0Namespace(slices.Concat(bytes.Repeat([]byte{0}, 8), []byte{1, 0})) + minNamespace, err := libshare.NewV0Namespace(slices.Concat(bytes.Repeat([]byte{0}, 8), []byte{1, 0})) require.NoError(t, err) - err = gosquare.ValidateForData(minNamespace) + err = libshare.ValidateForData(minNamespace) require.NoError(t, err) for namespacedAmount := 1; namespacedAmount < odsSize; namespacedAmount++ { - shares := gosquare.RandSharesWithNamespace(minNamespace, namespacedAmount, odsSize) - parity, err := share.DefaultRSMT2DCodec().Encode(gosquare.ToBytes(shares)) + shares := libshare.RandSharesWithNamespace(minNamespace, namespacedAmount, odsSize) + parity, err := share.DefaultRSMT2DCodec().Encode(libshare.ToBytes(shares)) require.NoError(t, err) - paritySh, err := gosquare.FromBytes(parity) + paritySh, err := libshare.FromBytes(parity) require.NoError(t, err) extended := slices.Concat(shares, paritySh) @@ -46,7 +46,7 @@ func TestNamespacedRowFromShares(t *testing.T) { // // const odsSize = 8 // //Test absent namespace -// shares := gosquare.RandShares( odsSize) +// shares := libshare.RandShares( odsSize) // absentNs, err := share.GetNamespace(shares[0]).AddInt(1) // require.NoError(t, err) // @@ -54,7 +54,7 @@ func TestNamespacedRowFromShares(t *testing.T) { // require.NoError(t, err) // extended := slices.Concat(shares, parity) // -// shrs, err := gosquare.FromBytes(extended) +// shrs, err := libshare.FromBytes(extended) // require.NoError(t, err) // // nr, err := shwap.RowNamespaceDataFromShares(shrs, absentNs, 0) @@ -69,7 +69,7 @@ func TestValidateNamespacedRow(t *testing.T) { const odsSize = 8 sharesAmount := odsSize * odsSize - namespace := gosquare.RandomNamespace() + namespace := libshare.RandomNamespace() for amount := 1; amount < sharesAmount; amount++ { randEDS, root := edstest.RandEDSWithNamespace(t, namespace, amount, odsSize) rsmt2d := &eds.Rsmt2D{ExtendedDataSquare: randEDS} @@ -93,7 +93,7 @@ func TestNamespacedRowProtoEncoding(t *testing.T) { t.Cleanup(cancel) const odsSize = 8 - namespace := gosquare.RandomNamespace() + namespace := libshare.RandomNamespace() randEDS, _ := edstest.RandEDSWithNamespace(t, namespace, odsSize, odsSize) rsmt2d := &eds.Rsmt2D{ExtendedDataSquare: randEDS} nd, err := eds.NamespaceData(ctx, rsmt2d, namespace) diff --git a/share/shwap/row_test.go b/share/shwap/row_test.go index e2936ab245..9249ea87f4 100644 --- a/share/shwap/row_test.go +++ b/share/shwap/row_test.go @@ -5,7 +5,7 @@ import ( "github.com/stretchr/testify/require" - gosquare "github.com/celestiaorg/go-square/v2/share" + libshare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/celestia-node/share" "github.com/celestiaorg/celestia-node/share/eds/edstest" @@ -18,14 +18,14 @@ func TestRowFromShares(t *testing.T) { for rowIdx := 0; rowIdx < odsSize*2; rowIdx++ { for _, side := range []RowSide{Left, Right} { shrs := eds.Row(uint(rowIdx)) - shares, err := gosquare.FromBytes(shrs) + shares, err := libshare.FromBytes(shrs) require.NoError(t, err) row := RowFromShares(shares, side) extended, err := row.Shares() require.NoError(t, err) require.Equal(t, shares, extended) - var half []gosquare.Share + var half []libshare.Share if side == Right { half = shares[odsSize:] } else { @@ -46,7 +46,7 @@ func TestRowValidate(t *testing.T) { for rowIdx := 0; rowIdx < odsSize*2; rowIdx++ { for _, side := range []RowSide{Left, Right} { shrs := eds.Row(uint(rowIdx)) - shares, err := gosquare.FromBytes(shrs) + shares, err := libshare.FromBytes(shrs) require.NoError(t, err) row := RowFromShares(shares, side) @@ -63,7 +63,7 @@ func TestRowValidateNegativeCases(t *testing.T) { root, err := share.NewAxisRoots(eds) require.NoError(t, err) shrs := eds.Row(0) - shares, err := gosquare.FromBytes(shrs) + shares, err := libshare.FromBytes(shrs) require.NoError(t, err) row := RowFromShares(shares, Left) @@ -73,9 +73,9 @@ func TestRowValidateNegativeCases(t *testing.T) { require.Error(t, err, "should error on invalid row side") // Test with invalid shares (more shares than expected) - incorrectShares := make([]gosquare.Share, (eds.Width()/2)+1) // Adding an extra share + incorrectShares := make([]libshare.Share, (eds.Width()/2)+1) // Adding an extra share for i := range incorrectShares { - shr, err := gosquare.NewShare(eds.GetCell(uint(i), 0)) + shr, err := libshare.NewShare(eds.GetCell(uint(i), 0)) require.NoError(t, err) incorrectShares[i] = *shr } @@ -84,7 +84,7 @@ func TestRowValidateNegativeCases(t *testing.T) { require.Error(t, err, "should error on incorrect number of shares") // Test with empty shares - emptyRow := Row{halfShares: []gosquare.Share{}, side: Left} + emptyRow := Row{halfShares: []libshare.Share{}, side: Left} err = emptyRow.Verify(root, 0) require.Error(t, err, "should error on empty halfShares") @@ -101,7 +101,7 @@ func TestRowProtoEncoding(t *testing.T) { for rowIdx := 0; rowIdx < odsSize*2; rowIdx++ { for _, side := range []RowSide{Left, Right} { shrs := eds.Row(uint(rowIdx)) - shares, err := gosquare.FromBytes(shrs) + shares, err := libshare.FromBytes(shrs) require.NoError(t, err) row := RowFromShares(shares, side) @@ -121,7 +121,7 @@ func BenchmarkRowValidate(b *testing.B) { root, err := share.NewAxisRoots(eds) require.NoError(b, err) shrs := eds.Row(0) - shares, err := gosquare.FromBytes(shrs) + shares, err := libshare.FromBytes(shrs) require.NoError(b, err) row := RowFromShares(shares, Left) diff --git a/share/shwap/sample.go b/share/shwap/sample.go index be200d9c13..1a51c63520 100644 --- a/share/shwap/sample.go +++ b/share/shwap/sample.go @@ -5,7 +5,7 @@ import ( "fmt" "github.com/celestiaorg/celestia-app/v3/pkg/wrapper" - gosquare "github.com/celestiaorg/go-square/v2/share" + libshare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt" nmt_pb "github.com/celestiaorg/nmt/pb" "github.com/celestiaorg/rsmt2d" @@ -24,14 +24,14 @@ var ErrFailedVerification = errors.New("failed to verify inclusion") // Sample represents a data share along with its Merkle proof, used to validate the share's // inclusion in a data share. type Sample struct { - gosquare.Share // Embeds the Share which includes the data with namespace. + libshare.Share // Embeds the Share which includes the data with namespace. Proof *nmt.Proof // Proof is the Merkle Proof validating the share's inclusion. ProofType rsmt2d.Axis // ProofType indicates whether the proof is against a row or a column. } // SampleFromShares creates a Sample from a list of shares, using the specified proof type and // the share index to be included in the sample. -func SampleFromShares(shares []gosquare.Share, proofType rsmt2d.Axis, axisIdx, shrIdx int) (Sample, error) { +func SampleFromShares(shares []libshare.Share, proofType rsmt2d.Axis, axisIdx, shrIdx int) (Sample, error) { tree := wrapper.NewErasuredNamespacedMerkleTree(uint64(len(shares)/2), uint(axisIdx)) for _, shr := range shares { err := tree.Push(shr.ToBytes()) @@ -125,10 +125,10 @@ func (s Sample) verifyInclusion(roots *share.AxisRoots, rowIdx, colIdx int) bool // Shares from extended part of the square are considered parity shares. It means that // parity shares are located outside of first quadrant of the square. According to the nmt // specification, the parity shares are prefixed with the namespace of the parity shares. -func inclusionNamespace(sh gosquare.Share, rowIdx, colIdx, squareSize int) gosquare.Namespace { +func inclusionNamespace(sh libshare.Share, rowIdx, colIdx, squareSize int) libshare.Namespace { isParity := colIdx >= squareSize/2 || rowIdx >= squareSize/2 if isParity { - return gosquare.ParitySharesNamespace + return libshare.ParitySharesNamespace } return sh.Namespace() } diff --git a/share/shwap/sample_test.go b/share/shwap/sample_test.go index 031bec7834..030eeb4677 100644 --- a/share/shwap/sample_test.go +++ b/share/shwap/sample_test.go @@ -6,7 +6,7 @@ import ( "github.com/stretchr/testify/require" - gosquare "github.com/celestiaorg/go-square/v2/share" + libshare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" "github.com/celestiaorg/celestia-node/share" @@ -54,7 +54,7 @@ func TestSampleNegativeVerifyInclusion(t *testing.T) { // Corrupt the share b := sample.Share.ToBytes() b[0] ^= 0xFF - shr, err := gosquare.NewShare(b) + shr, err := libshare.NewShare(b) require.NoError(t, err) sample.Share = *shr err = sample.Verify(root, 0, 0) diff --git a/share/shwap/share.go b/share/shwap/share.go index f10048636e..3f8205498c 100644 --- a/share/shwap/share.go +++ b/share/shwap/share.go @@ -3,7 +3,7 @@ package shwap import ( "fmt" - gosquare "github.com/celestiaorg/go-square/v2/share" + libshare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/celestia-node/share/shwap/pb" ) @@ -11,13 +11,13 @@ import ( // ShareFromProto converts a protobuf Share object to the application's internal share // representation. It returns nil if the input protobuf Share is nil, ensuring safe handling of nil // values. -func ShareFromProto(s *pb.Share) (gosquare.Share, error) { +func ShareFromProto(s *pb.Share) (libshare.Share, error) { if s == nil { - return gosquare.Share{}, nil + return libshare.Share{}, nil } - sh, err := gosquare.NewShare(s.Data) + sh, err := libshare.NewShare(s.Data) if err != nil { - return gosquare.Share{}, err + return libshare.Share{}, err } return *sh, err } @@ -25,7 +25,7 @@ func ShareFromProto(s *pb.Share) (gosquare.Share, error) { // SharesToProto converts a slice of Shares from the application's internal representation to a // slice of protobuf Share objects. This function allocates memory for the protobuf objects and // copies data from the input slice. -func SharesToProto(shrs []gosquare.Share) []*pb.Share { +func SharesToProto(shrs []libshare.Share) []*pb.Share { protoShares := make([]*pb.Share, len(shrs)) for i, shr := range shrs { protoShares[i] = &pb.Share{Data: shr.ToBytes()} @@ -35,8 +35,8 @@ func SharesToProto(shrs []gosquare.Share) []*pb.Share { // SharesFromProto converts a slice of protobuf Share objects to the application's internal slice // of Shares. It ensures that each Share is correctly transformed using the ShareFromProto function. -func SharesFromProto(shrs []*pb.Share) ([]gosquare.Share, error) { - shares := make([]gosquare.Share, len(shrs)) +func SharesFromProto(shrs []*pb.Share) ([]libshare.Share, error) { + shares := make([]libshare.Share, len(shrs)) var err error for i, shr := range shrs { shares[i], err = ShareFromProto(shr) diff --git a/state/core_access.go b/state/core_access.go index 4fbeb52326..8d89db0fd0 100644 --- a/state/core_access.go +++ b/state/core_access.go @@ -27,7 +27,7 @@ import ( apperrors "github.com/celestiaorg/celestia-app/v3/app/errors" "github.com/celestiaorg/celestia-app/v3/pkg/user" libhead "github.com/celestiaorg/go-header" - gosquare "github.com/celestiaorg/go-square/v2/share" + libshare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/celestia-node/header" ) @@ -201,10 +201,10 @@ func (ca *CoreAccessor) cancelCtx() { // TxResponse. The user can specify additional options that can bee applied to the Tx. func (ca *CoreAccessor) SubmitPayForBlob( ctx context.Context, - appblobs []*gosquare.Blob, + libBlobs []*libshare.Blob, cfg *TxConfig, ) (*TxResponse, error) { - if len(appblobs) == 0 { + if len(libBlobs) == 0 { return nil, errors.New("state: no blobs provided") } @@ -219,8 +219,8 @@ func (ca *CoreAccessor) SubmitPayForBlob( gas := cfg.GasLimit() if gas == 0 { - blobSizes := make([]uint32, len(appblobs)) - for i, blob := range appblobs { + blobSizes := make([]uint32, len(libBlobs)) + for i, blob := range libBlobs { blobSizes[i] = uint32(len(blob.Data())) } gas = estimateGasForBlobs(blobSizes) @@ -252,7 +252,7 @@ func (ca *CoreAccessor) SubmitPayForBlob( opts = append(opts, feeGrant) } - response, err := ca.client.SubmitPayForBlobWithAccount(ctx, accName, appblobs, opts...) + response, err := ca.client.SubmitPayForBlobWithAccount(ctx, accName, libBlobs, opts...) // Network min gas price can be updated through governance in app // If that's the case, we parse the insufficient min gas price error message and update the gas price if apperrors.IsInsufficientMinGasPrice(err) { diff --git a/state/core_access_test.go b/state/core_access_test.go index 684d1963ac..c487944749 100644 --- a/state/core_access_test.go +++ b/state/core_access_test.go @@ -19,7 +19,7 @@ import ( "github.com/celestiaorg/celestia-app/v3/test/util/genesis" "github.com/celestiaorg/celestia-app/v3/test/util/testnode" apptypes "github.com/celestiaorg/celestia-app/v3/x/blob/types" - gosquare "github.com/celestiaorg/go-square/v2/share" + libshare "github.com/celestiaorg/go-square/v2/share" ) func TestSubmitPayForBlob(t *testing.T) { @@ -32,31 +32,31 @@ func TestSubmitPayForBlob(t *testing.T) { _ = ca.Stop(ctx) }) - ns, err := gosquare.NewV0Namespace([]byte("namespace")) + ns, err := libshare.NewV0Namespace([]byte("namespace")) require.NoError(t, err) require.False(t, ns.IsReserved()) require.NoError(t, err) - blobbyTheBlob, err := gosquare.NewV0Blob(ns, []byte("data")) + blobbyTheBlob, err := libshare.NewV0Blob(ns, []byte("data")) require.NoError(t, err) testcases := []struct { name string - blobs []*gosquare.Blob + blobs []*libshare.Blob gasPrice float64 gasLim uint64 expErr error }{ { name: "empty blobs", - blobs: []*gosquare.Blob{}, + blobs: []*libshare.Blob{}, gasPrice: DefaultGasPrice, gasLim: 0, expErr: errors.New("state: no blobs provided"), }, { name: "good blob with user provided gas and fees", - blobs: []*gosquare.Blob{blobbyTheBlob}, + blobs: []*libshare.Blob{blobbyTheBlob}, gasPrice: 0.005, gasLim: apptypes.DefaultEstimateGas([]uint32{uint32(blobbyTheBlob.DataLen())}), expErr: nil, diff --git a/store/cache/accessor_cache_test.go b/store/cache/accessor_cache_test.go index d1847dd6da..9c7104fbe7 100644 --- a/store/cache/accessor_cache_test.go +++ b/store/cache/accessor_cache_test.go @@ -11,7 +11,7 @@ import ( "github.com/stretchr/testify/require" - gosquare "github.com/celestiaorg/go-square/v2/share" + libshare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" "github.com/celestiaorg/celestia-node/share" @@ -323,11 +323,11 @@ func (m *mockAccessor) AxisHalf(context.Context, rsmt2d.Axis, int) (eds.AxisHalf panic("implement me") } -func (m *mockAccessor) RowNamespaceData(context.Context, gosquare.Namespace, int) (shwap.RowNamespaceData, error) { +func (m *mockAccessor) RowNamespaceData(context.Context, libshare.Namespace, int) (shwap.RowNamespaceData, error) { panic("implement me") } -func (m *mockAccessor) Shares(context.Context) ([]gosquare.Share, error) { +func (m *mockAccessor) Shares(context.Context) ([]libshare.Share, error) { panic("implement me") } diff --git a/store/cache/noop.go b/store/cache/noop.go index ad98c4d98d..d777fdb2e4 100644 --- a/store/cache/noop.go +++ b/store/cache/noop.go @@ -4,7 +4,7 @@ import ( "context" "io" - gosquare "github.com/celestiaorg/go-square/v2/share" + libshare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" "github.com/celestiaorg/celestia-node/share" @@ -67,12 +67,12 @@ func (n NoopFile) AxisHalf(context.Context, rsmt2d.Axis, int) (eds.AxisHalf, err return eds.AxisHalf{}, nil } -func (n NoopFile) RowNamespaceData(context.Context, gosquare.Namespace, int) (shwap.RowNamespaceData, error) { +func (n NoopFile) RowNamespaceData(context.Context, libshare.Namespace, int) (shwap.RowNamespaceData, error) { return shwap.RowNamespaceData{}, nil } -func (n NoopFile) Shares(context.Context) ([]gosquare.Share, error) { - return []gosquare.Share{}, nil +func (n NoopFile) Shares(context.Context) ([]libshare.Share, error) { + return []libshare.Share{}, nil } func (n NoopFile) Close() error { diff --git a/store/file/codec_test.go b/store/file/codec_test.go index 7a0489e4d5..654d72f069 100644 --- a/store/file/codec_test.go +++ b/store/file/codec_test.go @@ -7,7 +7,7 @@ import ( "github.com/klauspost/reedsolomon" "github.com/stretchr/testify/require" - gosquare "github.com/celestiaorg/go-square/v2/share" + libshare "github.com/celestiaorg/go-square/v2/share" ) func BenchmarkCodec(b *testing.B) { @@ -70,13 +70,13 @@ func BenchmarkCodec(b *testing.B) { func newShards(b testing.TB, size int, fillParity bool) [][]byte { shards := make([][]byte, size) - original := gosquare.RandShares(size / 2) - copy(shards, gosquare.ToBytes(original)) + original := libshare.RandShares(size / 2) + copy(shards, libshare.ToBytes(original)) if fillParity { // fill with parity empty Shares for j := len(original); j < len(shards); j++ { - shards[j] = make([]byte, gosquare.ShareSize) + shards[j] = make([]byte, libshare.ShareSize) } } return shards diff --git a/store/file/ods.go b/store/file/ods.go index 5623740d99..7d07ca5b9d 100644 --- a/store/file/ods.go +++ b/store/file/ods.go @@ -9,7 +9,7 @@ import ( "os" "sync" - gosquare "github.com/celestiaorg/go-square/v2/share" + libshare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" "github.com/celestiaorg/celestia-node/share" @@ -102,11 +102,11 @@ func writeODS(w io.Writer, eds *rsmt2d.ExtendedDataSquare) error { for i := range eds.Width() / 2 { for j := range eds.Width() / 2 { shr := eds.GetCell(i, j) // TODO: Avoid copying inside GetCell - ns, err := gosquare.NewNamespace(shr[gosquare.VersionIndex], shr[gosquare.VersionIndex:gosquare.NamespaceIDSize]) + ns, err := libshare.NewNamespace(shr[libshare.VersionIndex], shr[libshare.VersionIndex:libshare.NamespaceIDSize]) if err != nil { return fmt.Errorf("creating namespace: %w", err) } - if ns.Equals(gosquare.TailPaddingNamespace) { + if ns.Equals(libshare.TailPaddingNamespace) { return nil } @@ -275,7 +275,7 @@ func (o *ODS) AxisHalf(_ context.Context, axisType rsmt2d.Axis, axisIdx int) (ed // RowNamespaceData returns data for the given namespace and row index. func (o *ODS) RowNamespaceData( ctx context.Context, - namespace gosquare.Namespace, + namespace libshare.Namespace, rowIdx int, ) (shwap.RowNamespaceData, error) { shares, err := o.axis(ctx, rsmt2d.Row, rowIdx) @@ -286,7 +286,7 @@ func (o *ODS) RowNamespaceData( } // Shares returns data shares extracted from the Accessor. -func (o *ODS) Shares(context.Context) ([]gosquare.Share, error) { +func (o *ODS) Shares(context.Context) ([]libshare.Share, error) { ods, err := o.readODS() if err != nil { return nil, err @@ -310,7 +310,7 @@ func (o *ODS) Reader() (io.Reader, error) { return reader, nil } -func (o *ODS) axis(ctx context.Context, axisType rsmt2d.Axis, axisIdx int) ([]gosquare.Share, error) { +func (o *ODS) axis(ctx context.Context, axisType rsmt2d.Axis, axisIdx int) ([]libshare.Share, error) { half, err := o.AxisHalf(ctx, axisType, axisIdx) if err != nil { return nil, err @@ -373,7 +373,7 @@ func (o *ODS) readODS() (square, error) { return ods, nil } -func readAxisHalf(r io.ReaderAt, axisTp rsmt2d.Axis, axisIdx int, hdr *headerV0, offset int) ([]gosquare.Share, error) { +func readAxisHalf(r io.ReaderAt, axisTp rsmt2d.Axis, axisIdx int, hdr *headerV0, offset int) ([]libshare.Share, error) { switch axisTp { case rsmt2d.Row: return readRowHalf(r, axisIdx, hdr, offset) @@ -386,12 +386,12 @@ func readAxisHalf(r io.ReaderAt, axisTp rsmt2d.Axis, axisIdx int, hdr *headerV0, // readRowHalf reads specific Row half from the file in a single IO operation. // If some or all shares are missing, tail padding shares are returned instead. -func readRowHalf(r io.ReaderAt, rowIdx int, hdr *headerV0, offset int) ([]gosquare.Share, error) { +func readRowHalf(r io.ReaderAt, rowIdx int, hdr *headerV0, offset int) ([]libshare.Share, error) { odsLn := hdr.SquareSize() / 2 rowOffset := rowIdx * odsLn * hdr.ShareSize() offset += rowOffset - shares := make([]gosquare.Share, odsLn) + shares := make([]libshare.Share, odsLn) axsData := make([]byte, odsLn*hdr.ShareSize()) n, err := r.ReadAt(axsData, int64(offset)) if err != nil && !errors.Is(err, io.EOF) { @@ -404,10 +404,10 @@ func readRowHalf(r io.ReaderAt, rowIdx int, hdr *headerV0, offset int) ([]gosqua if i > shrsRead-1 { // partial or empty row was read // fill the rest with tail padding it - shares[i] = gosquare.TailPaddingShare() + shares[i] = libshare.TailPaddingShare() continue } - sh, err := gosquare.NewShare(axsData[i*hdr.ShareSize() : (i+1)*hdr.ShareSize()]) + sh, err := libshare.NewShare(axsData[i*hdr.ShareSize() : (i+1)*hdr.ShareSize()]) if err != nil { return nil, err } @@ -418,9 +418,9 @@ func readRowHalf(r io.ReaderAt, rowIdx int, hdr *headerV0, offset int) ([]gosqua // readColHalf reads specific Col half from the file in a single IO operation. // If some or all shares are missing, tail padding shares are returned instead. -func readColHalf(r io.ReaderAt, colIdx int, hdr *headerV0, offset int) ([]gosquare.Share, error) { +func readColHalf(r io.ReaderAt, colIdx int, hdr *headerV0, offset int) ([]libshare.Share, error) { odsLn := hdr.SquareSize() / 2 - shares := make([]gosquare.Share, odsLn) + shares := make([]libshare.Share, odsLn) for i := range shares { pos := colIdx + i*odsLn offset := offset + pos*hdr.ShareSize() @@ -435,12 +435,12 @@ func readColHalf(r io.ReaderAt, colIdx int, hdr *headerV0, offset int) ([]gosqua // no shares left // fill the rest with tail padding for ; i < len(shares); i++ { - shares[i] = gosquare.TailPaddingShare() + shares[i] = libshare.TailPaddingShare() } return shares, nil } - sh, err := gosquare.NewShare(shr) + sh, err := libshare.NewShare(shr) if err != nil { return nil, err } diff --git a/store/file/ods_q4.go b/store/file/ods_q4.go index 6c50b39823..06b255cae9 100644 --- a/store/file/ods_q4.go +++ b/store/file/ods_q4.go @@ -9,7 +9,7 @@ import ( "sync" "sync/atomic" - gosquare "github.com/celestiaorg/go-square/v2/share" + libshare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" "github.com/celestiaorg/celestia-node/share" @@ -149,7 +149,7 @@ func (odsq4 *ODSQ4) AxisHalf(ctx context.Context, axisType rsmt2d.Axis, axisIdx } func (odsq4 *ODSQ4) RowNamespaceData(ctx context.Context, - namespace gosquare.Namespace, + namespace libshare.Namespace, rowIdx int, ) (shwap.RowNamespaceData, error) { half, err := odsq4.AxisHalf(ctx, rsmt2d.Row, rowIdx) @@ -163,7 +163,7 @@ func (odsq4 *ODSQ4) RowNamespaceData(ctx context.Context, return shwap.RowNamespaceDataFromShares(shares, namespace, rowIdx) } -func (odsq4 *ODSQ4) Shares(ctx context.Context) ([]gosquare.Share, error) { +func (odsq4 *ODSQ4) Shares(ctx context.Context) ([]libshare.Share, error) { return odsq4.ods.Shares(ctx) } diff --git a/store/file/ods_q4_test.go b/store/file/ods_q4_test.go index 8795ca9cd4..6e37e843b4 100644 --- a/store/file/ods_q4_test.go +++ b/store/file/ods_q4_test.go @@ -12,7 +12,7 @@ import ( "github.com/stretchr/testify/require" "github.com/tendermint/tendermint/libs/rand" - gosquare "github.com/celestiaorg/go-square/v2/share" + libshare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" "github.com/celestiaorg/celestia-node/share" @@ -30,7 +30,7 @@ func TestCreateODSQ4File(t *testing.T) { shares, err := odsq4.Shares(ctx) require.NoError(t, err) expected := edsIn.FlattenedODS() - require.Equal(t, expected, gosquare.ToBytes(shares)) + require.Equal(t, expected, libshare.ToBytes(shares)) require.NoError(t, odsq4.Close()) } diff --git a/store/file/ods_test.go b/store/file/ods_test.go index b5b7deed21..fe4c7cd456 100644 --- a/store/file/ods_test.go +++ b/store/file/ods_test.go @@ -12,7 +12,7 @@ import ( "github.com/stretchr/testify/require" "github.com/tendermint/tendermint/libs/rand" - gosquare "github.com/celestiaorg/go-square/v2/share" + libshare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" "github.com/celestiaorg/celestia-node/share" @@ -33,7 +33,7 @@ func TestCreateODSFile(t *testing.T) { require.NoError(t, err) expected := edsIn.FlattenedODS() - require.Equal(t, expected, gosquare.ToBytes(shares)) + require.Equal(t, expected, libshare.ToBytes(shares)) roots, err := f.AxisRoots(ctx) require.NoError(t, err) @@ -51,7 +51,7 @@ func TestReadODSFromFile(t *testing.T) { for i, row := range ods { original := eds.Row(uint(i))[:eds.Width()/2] require.True(t, len(original) == len(row)) - require.Equal(t, original, gosquare.ToBytes(row)) + require.Equal(t, original, libshare.ToBytes(row)) } } diff --git a/store/file/square.go b/store/file/square.go index 6c2a50ebea..ef5b67010c 100644 --- a/store/file/square.go +++ b/store/file/square.go @@ -6,13 +6,13 @@ import ( "golang.org/x/sync/errgroup" - gosquare "github.com/celestiaorg/go-square/v2/share" + libshare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" "github.com/celestiaorg/celestia-node/share/eds" ) -type square [][]gosquare.Share +type square [][]libshare.Share // readSquare reads Shares from the reader and returns a square. It assumes that the reader is // positioned at the beginning of the Shares. It knows the size of the Shares and the size of the @@ -46,8 +46,8 @@ func (s square) size() int { return len(s) } -func (s square) shares() ([]gosquare.Share, error) { - shares := make([]gosquare.Share, 0, s.size()*s.size()) +func (s square) shares() ([]libshare.Share, error) { + shares := make([]libshare.Share, 0, s.size()*s.size()) for _, row := range s { shares = append(shares, row...) } @@ -73,7 +73,7 @@ func (s square) axisHalf(axisType rsmt2d.Axis, axisIdx int) (eds.AxisHalf, error } // construct half column from row ordered square - col := make([]gosquare.Share, s.size()) + col := make([]libshare.Share, s.size()) for i := 0; i < s.size(); i++ { col[i] = s[i][axisIdx] } @@ -87,7 +87,7 @@ func (s square) computeAxisHalf( axisType rsmt2d.Axis, axisIdx int, ) (eds.AxisHalf, error) { - shares := make([]gosquare.Share, s.size()) + shares := make([]libshare.Share, s.size()) // extend opposite half of the square while collecting Shares for the first half of required axis g := errgroup.Group{} @@ -106,9 +106,9 @@ func (s square) computeAxisHalf( shards := make([][]byte, s.size()*2) if half.IsParity { - copy(shards[s.size():], gosquare.ToBytes(half.Shares)) + copy(shards[s.size():], libshare.ToBytes(half.Shares)) } else { - copy(shards, gosquare.ToBytes(half.Shares)) + copy(shards, libshare.ToBytes(half.Shares)) } target := make([]bool, s.size()*2) @@ -119,7 +119,7 @@ func (s square) computeAxisHalf( return fmt.Errorf("reconstruct some: %w", err) } - shard, err := gosquare.NewShare(shards[axisIdx]) + shard, err := libshare.NewShare(shards[axisIdx]) if err != nil { return fmt.Errorf("creating share: %w", err) } diff --git a/store/getter.go b/store/getter.go index 96b9d37d10..05148a205f 100644 --- a/store/getter.go +++ b/store/getter.go @@ -5,7 +5,7 @@ import ( "errors" "fmt" - gosquare "github.com/celestiaorg/go-square/v2/share" + libshare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" "github.com/celestiaorg/celestia-node/header" @@ -24,13 +24,13 @@ func NewGetter(store *Store) *Getter { return &Getter{store: store} } -func (g *Getter) GetShare(ctx context.Context, h *header.ExtendedHeader, row, col int) (gosquare.Share, error) { +func (g *Getter) GetShare(ctx context.Context, h *header.ExtendedHeader, row, col int) (libshare.Share, error) { acc, err := g.store.GetByHeight(ctx, h.Height()) if err != nil { if errors.Is(err, ErrNotFound) { - return gosquare.Share{}, shwap.ErrNotFound + return libshare.Share{}, shwap.ErrNotFound } - return gosquare.Share{}, fmt.Errorf("get accessor from store:%w", err) + return libshare.Share{}, fmt.Errorf("get accessor from store:%w", err) } logger := log.With( "height", h.Height(), @@ -41,7 +41,7 @@ func (g *Getter) GetShare(ctx context.Context, h *header.ExtendedHeader, row, co sample, err := acc.Sample(ctx, row, col) if err != nil { - return gosquare.Share{}, fmt.Errorf("get sample from accessor:%w", err) + return libshare.Share{}, fmt.Errorf("get sample from accessor:%w", err) } return sample.Share, nil } @@ -71,7 +71,7 @@ func (g *Getter) GetEDS(ctx context.Context, h *header.ExtendedHeader) (*rsmt2d. func (g *Getter) GetSharesByNamespace( ctx context.Context, h *header.ExtendedHeader, - ns gosquare.Namespace, + ns libshare.Namespace, ) (shwap.NamespaceData, error) { acc, err := g.store.GetByHeight(ctx, h.Height()) if err != nil { diff --git a/store/getter_test.go b/store/getter_test.go index 9d6defea45..a87e0b2c98 100644 --- a/store/getter_test.go +++ b/store/getter_test.go @@ -7,7 +7,7 @@ import ( "github.com/stretchr/testify/require" - gosquare "github.com/celestiaorg/go-square/v2/share" + libshare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/celestia-node/header/headertest" "github.com/celestiaorg/celestia-node/share/eds/edstest" @@ -67,7 +67,7 @@ func TestStoreGetter(t *testing.T) { }) t.Run("GetSharesByNamespace", func(t *testing.T) { - ns := gosquare.RandomNamespace() + ns := libshare.RandomNamespace() eds, roots := edstest.RandEDSWithNamespace(t, ns, 8, 16) eh := headertest.RandExtendedHeaderWithRoot(t, roots) height := height.Add(1) @@ -80,7 +80,7 @@ func TestStoreGetter(t *testing.T) { require.NoError(t, shares.Verify(eh.DAH, ns)) // namespace not found - randNamespace := gosquare.RandomNamespace() + randNamespace := libshare.RandomNamespace() emptyShares, err := sg.GetSharesByNamespace(ctx, eh, randNamespace) require.NoError(t, err) require.Empty(t, emptyShares.Flatten()) diff --git a/store/store_test.go b/store/store_test.go index dbf44928a2..85a116f5e3 100644 --- a/store/store_test.go +++ b/store/store_test.go @@ -10,7 +10,7 @@ import ( "github.com/stretchr/testify/require" - gosquare "github.com/celestiaorg/go-square/v2/share" + libshare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" "github.com/celestiaorg/celestia-node/share" From a0f1007c34677b3a9818b84f2b5ed356dc1cc814 Mon Sep 17 00:00:00 2001 From: vgonkivs Date: Tue, 15 Oct 2024 16:38:51 +0300 Subject: [PATCH 13/21] fixes --- blob/blob.go | 3 +-- blob/blobtest/testing.go | 6 +++--- nodebuilder/tests/nd_test.go | 1 + share/availability/full/testing.go | 2 +- share/eds/byzantine/byzantine.go | 2 +- share/eds/rsmt2d.go | 8 +++----- share/eds/testing.go | 1 - share/ipld/add.go | 2 +- share/ipld/namespace_data.go | 2 +- share/ipld/utils.go | 1 - share/shwap/row_namespace_data_id.go | 12 ++++-------- share/shwap/sample.go | 2 +- 12 files changed, 17 insertions(+), 25 deletions(-) diff --git a/blob/blob.go b/blob/blob.go index c054bd76d3..4ddd62aada 100644 --- a/blob/blob.go +++ b/blob/blob.go @@ -7,7 +7,6 @@ import ( "fmt" "github.com/celestiaorg/celestia-app/v3/pkg/appconsts" - v3 "github.com/celestiaorg/celestia-app/v3/pkg/appconsts/v3" "github.com/celestiaorg/go-square/merkle" "github.com/celestiaorg/go-square/v2/inclusion" libshare "github.com/celestiaorg/go-square/v2/share" @@ -15,7 +14,7 @@ import ( ) // appVersion is the current application version of celestia-app. -const appVersion = v3.Version +const appVersion = appconsts.LatestVersion var errEmptyShares = errors.New("empty shares") diff --git a/blob/blobtest/testing.go b/blob/blobtest/testing.go index 40c086ce47..b65877e96b 100644 --- a/blob/blobtest/testing.go +++ b/blob/blobtest/testing.go @@ -2,7 +2,6 @@ package blobtest import ( "encoding/binary" - "fmt" tmrand "github.com/tendermint/tendermint/libs/rand" @@ -22,8 +21,9 @@ func GenerateV0Blobs(sizes []int, sameNamespace bool) ([]*libshare.Blob, error) if err != nil { return nil, err } - if namespace.IsReserved() { - return nil, fmt.Errorf("reserved namespace") + for namespace.IsReserved() { + continue + } libBlob, err = libshare.NewV0Blob(namespace, libBlob.Data()) if err != nil { diff --git a/nodebuilder/tests/nd_test.go b/nodebuilder/tests/nd_test.go index 85956ab58d..07d6fcc496 100644 --- a/nodebuilder/tests/nd_test.go +++ b/nodebuilder/tests/nd_test.go @@ -146,6 +146,7 @@ func TestShrexNDFromLightsWithBadFulls(t *testing.T) { // ensure to fetch random namespace (not the reserved namespace) namespace := h.DAH.RowRoots[1][:libshare.NamespaceSize] ns, err := libshare.NewNamespaceFromBytes(namespace) + require.NoError(t, err) expected, err := bridgeClient.Share.GetSharesByNamespace(reqCtx, h, ns) require.NoError(t, err) require.True(t, len(expected[0].Shares) > 0) diff --git a/share/availability/full/testing.go b/share/availability/full/testing.go index b0bc7595c0..e3f1d64831 100644 --- a/share/availability/full/testing.go +++ b/share/availability/full/testing.go @@ -21,7 +21,7 @@ package full //// trees of 'n' random shares, essentially storing a whole share. // func GetterWithRandSquare(t *testing.T, n int) (share.Getter, *share.AxisRoots) { // bServ := ipld.NewMemBlockservice() -// getter := shwap.NewIPLDGetter(bServ) +// getter := getters.NewIPLDGetter(bServ) // return getter, availability_test.RandFillBS(t, n, bServ) //} // diff --git a/share/eds/byzantine/byzantine.go b/share/eds/byzantine/byzantine.go index 7a35b05511..28c0bf2413 100644 --- a/share/eds/byzantine/byzantine.go +++ b/share/eds/byzantine/byzantine.go @@ -17,7 +17,7 @@ import ( // (merkle proofs do not match parity erasure-coding data). // // It is converted from rsmt2d.ByzantineRow/Col + -// Merkle Proof for each libshare. +// Merkle Proof for each share. type ErrByzantine struct { Index uint32 Shares []*ShareWithProof diff --git a/share/eds/rsmt2d.go b/share/eds/rsmt2d.go index eb61947f42..a26a2d2c0c 100644 --- a/share/eds/rsmt2d.go +++ b/share/eds/rsmt2d.go @@ -20,7 +20,7 @@ type Rsmt2D struct { *rsmt2d.ExtendedDataSquare } -// Size returns the size of the Extended Data square. +// Size returns the size of the Extended Data Square. func (eds *Rsmt2D) Size(context.Context) int { return int(eds.Width()) } @@ -155,11 +155,9 @@ func Rsmt2DFromShares(shares []libshare.Share, odsSize int) (*Rsmt2D, error) { func getAxis(eds *rsmt2d.ExtendedDataSquare, axisType rsmt2d.Axis, axisIdx int) ([]libshare.Share, error) { switch axisType { case rsmt2d.Row: - sh, err := libshare.FromBytes(eds.Row(uint(axisIdx))) - return sh, err + return libshare.FromBytes(eds.Row(uint(axisIdx))) case rsmt2d.Col: - sh, err := libshare.FromBytes(eds.Col(uint(axisIdx))) - return sh, err + return libshare.FromBytes(eds.Col(uint(axisIdx))) default: panic("unknown axis") } diff --git a/share/eds/testing.go b/share/eds/testing.go index 90404a1277..247324b1b4 100644 --- a/share/eds/testing.go +++ b/share/eds/testing.go @@ -334,7 +334,6 @@ func testAccessorAxisHalf( require.NoError(t, err) expected = expected[:odsSize] } - require.NoError(t, err) require.Equal(t, expected, half.Shares) }(axisType, i) } diff --git a/share/ipld/add.go b/share/ipld/add.go index 39e3cbba80..0e0b6346dc 100644 --- a/share/ipld/add.go +++ b/share/ipld/add.go @@ -48,7 +48,7 @@ func AddShares( return eds, batchAdder.Commit() } -// ImportShares imports flattened pieces of data into Extended Data square and saves it in +// ImportShares imports flattened pieces of data into Extended Data Square and saves it in // blockservice.BlockService func ImportShares( ctx context.Context, diff --git a/share/ipld/namespace_data.go b/share/ipld/namespace_data.go index bfbd4cf1ab..b71ca86544 100644 --- a/share/ipld/namespace_data.go +++ b/share/ipld/namespace_data.go @@ -302,7 +302,7 @@ func (n *NamespaceData) collectNDWithProofs(j job, links []*ipld.Link) []job { log.Fatal(err) } - if above { + if !above { // namespace is within the range of left link nextJobs = append(nextJobs, j.next(left, leftCid, false)) } else { diff --git a/share/ipld/utils.go b/share/ipld/utils.go index a619c44ee3..99feead860 100644 --- a/share/ipld/utils.go +++ b/share/ipld/utils.go @@ -16,7 +16,6 @@ func FilterRootByNamespace(root *share.AxisRoots, namespace libshare.Namespace) outside, err := share.IsOutsideRange(namespace, row, row) if err != nil { return nil, err - } if !outside { diff --git a/share/shwap/row_namespace_data_id.go b/share/shwap/row_namespace_data_id.go index eec3d2935d..26a8605caf 100644 --- a/share/shwap/row_namespace_data_id.go +++ b/share/shwap/row_namespace_data_id.go @@ -15,7 +15,7 @@ const RowNamespaceDataIDSize = RowIDSize + libshare.NamespaceSize // Data Square (EDS). type RowNamespaceDataID struct { RowID // Embedded RowID representing the specific row in the EDS. - // DataNamespace is a string representation of the namespace to facilitate comparisons. + // DataNamespace is used to facilitate comparisons. DataNamespace libshare.Namespace } @@ -60,15 +60,11 @@ func RowNamespaceDataIDFromBinary(data []byte) (RowNamespaceDataID, error) { if err != nil { return RowNamespaceDataID{}, fmt.Errorf("invalid namespace format: %w", err) } - rndid := RowNamespaceDataID{ + + return RowNamespaceDataID{ RowID: rid, DataNamespace: ns, - } - if err := rndid.Validate(); err != nil { - return RowNamespaceDataID{}, fmt.Errorf("validating RowNamespaceDataID: %w", err) - } - - return rndid, nil + }, nil } // Equals checks equality of RowNamespaceDataID. diff --git a/share/shwap/sample.go b/share/shwap/sample.go index 1a51c63520..ab07d2f5de 100644 --- a/share/shwap/sample.go +++ b/share/shwap/sample.go @@ -22,7 +22,7 @@ const SampleName = "sample_v0" var ErrFailedVerification = errors.New("failed to verify inclusion") // Sample represents a data share along with its Merkle proof, used to validate the share's -// inclusion in a data share. +// inclusion in a data square. type Sample struct { libshare.Share // Embeds the Share which includes the data with namespace. Proof *nmt.Proof // Proof is the Merkle Proof validating the share's inclusion. From 545cd1a1175c071f55f8187a44b58e1dfcae940e Mon Sep 17 00:00:00 2001 From: vgonkivs Date: Thu, 17 Oct 2024 20:00:28 +0300 Subject: [PATCH 14/21] bump go-square --- api/gateway/share.go | 2 +- blob/blob.go | 6 +-- blob/blob_fuzz_test.go | 5 +- blob/blob_test.go | 6 +-- blob/blobtest/testing.go | 47 ------------------- blob/service.go | 8 +--- blob/service_test.go | 46 ++++++++++-------- core/eds.go | 3 +- go.mod | 5 +- go.sum | 11 ++--- nodebuilder/tests/api_test.go | 3 +- nodebuilder/tests/blob_test.go | 9 ++-- nodebuilder/tests/da_test.go | 5 +- share/availability/test/testing.go | 3 +- share/eds/axis_half_test.go | 3 +- share/eds/byzantine/bad_encoding_test.go | 7 +-- share/eds/edstest/testing.go | 14 +++--- share/eds/retriever_test.go | 6 ++- share/eds/testing.go | 2 +- share/ipld/delete_test.go | 6 ++- share/ipld/get_shares_test.go | 44 +++++++++++------ share/ipld/namespace_data.go | 2 +- share/ipld/proofs_test.go | 3 +- share/shwap/namespace_data_id.go | 2 +- share/shwap/p2p/bitswap/getter.go | 2 +- share/shwap/p2p/shrex/shrex_getter/shrex.go | 2 +- .../p2p/shrex/shrex_getter/shrex_test.go | 6 +-- share/shwap/p2p/shrex/shrexnd/client.go | 2 +- share/shwap/row_namespace_data_id.go | 2 +- share/shwap/row_namespace_data_test.go | 9 ++-- store/file/codec_test.go | 3 +- 31 files changed, 123 insertions(+), 151 deletions(-) delete mode 100644 blob/blobtest/testing.go diff --git a/api/gateway/share.go b/api/gateway/share.go index 9b47b6efb7..25fcac8480 100644 --- a/api/gateway/share.go +++ b/api/gateway/share.go @@ -140,5 +140,5 @@ func parseGetByNamespaceArgs(r *http.Request) (height uint64, namespace libshare return 0, libshare.Namespace{}, err } namespace = ns - return height, namespace, libshare.ValidateForData(namespace) + return height, namespace, namespace.ValidateForData() } diff --git a/blob/blob.go b/blob/blob.go index 4ddd62aada..9536734809 100644 --- a/blob/blob.go +++ b/blob/blob.go @@ -85,14 +85,10 @@ func NewBlob(shareVersion uint8, namespace libshare.Namespace, data, signer []by return nil, fmt.Errorf("blob data must be > 0 && <= %d, but it was %d bytes", appconsts.DefaultMaxBytes, len(data)) } - if err := libshare.ValidateForData(namespace); err != nil { + if err := namespace.ValidateForBlob(); err != nil { return nil, fmt.Errorf("invalid user namespace: %w", err) } - if !libshare.IsBlobNamespace(namespace) { - return nil, fmt.Errorf("namespace %s is not a blob namespace", namespace) - } - libBlob, err := libshare.NewBlob(namespace, data, shareVersion, signer) if err != nil { return nil, err diff --git a/blob/blob_fuzz_test.go b/blob/blob_fuzz_test.go index 16981335c8..f3b8f221f3 100644 --- a/blob/blob_fuzz_test.go +++ b/blob/blob_fuzz_test.go @@ -2,11 +2,10 @@ package blob import ( "encoding/json" + libshare "github.com/celestiaorg/go-square/v2/share" "os" "path/filepath" "testing" - - "github.com/celestiaorg/celestia-node/blob/blobtest" ) func FuzzProofEqual(f *testing.F) { @@ -15,7 +14,7 @@ func FuzzProofEqual(f *testing.F) { } // 1. Generate the corpus. - libBlobs, err := blobtest.GenerateV0Blobs([]int{16}, false) + libBlobs, err := libshare.GenerateV0Blobs([]int{16}, false) if err != nil { f.Fatal(err) } diff --git a/blob/blob_test.go b/blob/blob_test.go index ee28d88353..221e2d8395 100644 --- a/blob/blob_test.go +++ b/blob/blob_test.go @@ -10,13 +10,11 @@ import ( "github.com/celestiaorg/go-square/merkle" "github.com/celestiaorg/go-square/v2/inclusion" libshare "github.com/celestiaorg/go-square/v2/share" - - "github.com/celestiaorg/celestia-node/blob/blobtest" ) func TestBlob(t *testing.T) { length := 16 - libBlobs, err := blobtest.GenerateV0Blobs([]int{length}, false) + libBlobs, err := libshare.GenerateV0Blobs([]int{length}, false) require.NoError(t, err) blob, err := convertBlobs(libBlobs...) require.NoError(t, err) @@ -50,7 +48,7 @@ func TestBlob(t *testing.T) { name: "verify namespace", expectedRes: func(t *testing.T) { ns := blob[0].Namespace() - require.NoError(t, libshare.ValidateUserNamespace(ns.Version(), ns.ID())) + require.NoError(t, ns.ValidateForBlob()) }, }, { diff --git a/blob/blobtest/testing.go b/blob/blobtest/testing.go deleted file mode 100644 index b65877e96b..0000000000 --- a/blob/blobtest/testing.go +++ /dev/null @@ -1,47 +0,0 @@ -package blobtest - -import ( - "encoding/binary" - - tmrand "github.com/tendermint/tendermint/libs/rand" - - "github.com/celestiaorg/celestia-app/v3/test/util/testfactory" - libshare "github.com/celestiaorg/go-square/v2/share" -) - -// GenerateV0Blobs is a test utility producing v0 share formatted blobs with the -// requested size and random namespaces. -func GenerateV0Blobs(sizes []int, sameNamespace bool) ([]*libshare.Blob, error) { - blobs := make([]*libshare.Blob, 0, len(sizes)) - for _, size := range sizes { - size := RawBlobSize(libshare.FirstSparseShareContentSize * size) - libBlob := testfactory.GenerateRandomBlob(size) - if !sameNamespace { - namespace, err := libshare.NewV0Namespace(tmrand.Bytes(7)) - if err != nil { - return nil, err - } - for namespace.IsReserved() { - continue - - } - libBlob, err = libshare.NewV0Blob(namespace, libBlob.Data()) - if err != nil { - return nil, err - } - } - - blobs = append(blobs, libBlob) - } - return blobs, nil -} - -func RawBlobSize(totalSize int) int { - return totalSize - delimLen(uint64(totalSize)) -} - -// delimLen calculates the length of the delimiter for a given unit size -func delimLen(size uint64) int { - lenBuf := make([]byte, binary.MaxVarintLen64) - return binary.PutUvarint(lenBuf, size) -} diff --git a/blob/service.go b/blob/service.go index c6c6aeb42e..915d17b509 100644 --- a/blob/service.go +++ b/blob/service.go @@ -172,12 +172,8 @@ func (s *Service) Submit(ctx context.Context, blobs []*Blob, txConfig *SubmitOpt libBlobs := make([]*libshare.Blob, len(blobs)) for i := range blobs { - namespace := blobs[i].Namespace() - if err := libshare.ValidateForData(namespace); err != nil { - return 0, err - } - if !libshare.IsBlobNamespace(namespace) { - return 0, fmt.Errorf("not allowed namespace %s were used to build the blob", namespace.ID()) + if err := blobs[i].Namespace().ValidateForBlob(); err != nil { + return 0, fmt.Errorf("not allowed namespace %s were used to build the blob", blobs[i].Namespace().ID()) } libBlobs[i] = blobs[i].Blob diff --git a/blob/service_test.go b/blob/service_test.go index 473b9d457e..8e7c3aa644 100644 --- a/blob/service_test.go +++ b/blob/service_test.go @@ -3,6 +3,7 @@ package blob import ( "bytes" "context" + "encoding/binary" "encoding/json" "errors" "fmt" @@ -23,14 +24,11 @@ import ( "github.com/celestiaorg/celestia-app/v3/pkg/wrapper" "github.com/celestiaorg/go-header/store" "github.com/celestiaorg/go-square/merkle" - squarens "github.com/celestiaorg/go-square/namespace" - appshares "github.com/celestiaorg/go-square/shares" "github.com/celestiaorg/go-square/v2/inclusion" libshare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt" "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/blob/blobtest" "github.com/celestiaorg/celestia-node/header" "github.com/celestiaorg/celestia-node/header/headertest" "github.com/celestiaorg/celestia-node/libs/utils" @@ -52,12 +50,12 @@ func TestBlobService_Get(t *testing.T) { blobSize3 = 12 ) - libBlobs, err := blobtest.GenerateV0Blobs([]int{blobSize0, blobSize1}, false) + libBlobs, err := libshare.GenerateV0Blobs([]int{blobSize0, blobSize1}, false) require.NoError(t, err) blobsWithDiffNamespaces, err := convertBlobs(libBlobs...) require.NoError(t, err) - libBlobs, err = blobtest.GenerateV0Blobs([]int{blobSize2, blobSize3}, true) + libBlobs, err = libshare.GenerateV0Blobs([]int{blobSize2, blobSize3}, true) require.NoError(t, err) blobsWithSameNamespace, err := convertBlobs(libBlobs...) require.NoError(t, err) @@ -152,7 +150,7 @@ func TestBlobService_Get(t *testing.T) { require.True(t, bytes.Equal(sh.ToBytes(), resultShares[shareOffset].ToBytes()), fmt.Sprintf("issue on %d attempt. ROW:%d, COL: %d, blobIndex:%d", i, row, col, blobs[i].index), ) - shareOffset += appshares.SparseSharesNeeded(uint32(len(blobs[i].Data()))) + shareOffset += libshare.SparseSharesNeeded(uint32(len(blobs[i].Data()))) } }, }, @@ -202,7 +200,7 @@ func TestBlobService_Get(t *testing.T) { { name: "get invalid blob", doFn: func() (interface{}, error) { - libBlob, err := blobtest.GenerateV0Blobs([]int{10}, false) + libBlob, err := libshare.GenerateV0Blobs([]int{10}, false) require.NoError(t, err) blob, err := convertBlobs(libBlob...) require.NoError(t, err) @@ -302,7 +300,7 @@ func TestBlobService_Get(t *testing.T) { { name: "not included", doFn: func() (interface{}, error) { - libBlob, err := blobtest.GenerateV0Blobs([]int{10}, false) + libBlob, err := libshare.GenerateV0Blobs([]int{10}, false) require.NoError(t, err) blob, err := convertBlobs(libBlob...) require.NoError(t, err) @@ -358,7 +356,7 @@ func TestBlobService_Get(t *testing.T) { { name: "empty result and err when blobs were not found ", doFn: func() (interface{}, error) { - nid, err := libshare.NewV0Namespace(tmrand.Bytes(squarens.NamespaceVersionZeroIDSize)) + nid, err := libshare.NewV0Namespace(tmrand.Bytes(libshare.NamespaceVersionZeroIDSize)) require.NoError(t, err) return service.GetAll(ctx, 1, []libshare.Namespace{nid}) }, @@ -460,7 +458,7 @@ func TestService_GetSingleBlobWithoutPadding(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), time.Second*5) t.Cleanup(cancel) - libBlob, err := blobtest.GenerateV0Blobs([]int{9, 5}, true) + libBlob, err := libshare.GenerateV0Blobs([]int{9, 5}, true) require.NoError(t, err) blobs, err := convertBlobs(libBlob...) require.NoError(t, err) @@ -501,7 +499,7 @@ func TestService_Get(t *testing.T) { sizes := []int{1, 6, 3, 2, 4, 6, 8, 2, 15, 17} - libBlobs, err := blobtest.GenerateV0Blobs(sizes, true) + libBlobs, err := libshare.GenerateV0Blobs(sizes, true) require.NoError(t, err) blobs, err := convertBlobs(libBlobs...) require.NoError(t, err) @@ -527,7 +525,7 @@ func TestService_Get(t *testing.T) { require.NoError(t, err) assert.Equal(t, sh, resultShares[shareOffset], fmt.Sprintf("issue on %d attempt", i)) - shareOffset += appshares.SparseSharesNeeded(uint32(len(blob.Data()))) + shareOffset += libshare.SparseSharesNeeded(uint32(len(blob.Data()))) } } @@ -538,7 +536,7 @@ func TestService_GetAllWithoutPadding(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), time.Second*5) t.Cleanup(cancel) - libBlob, err := blobtest.GenerateV0Blobs([]int{9, 5, 15, 4, 24}, true) + libBlob, err := libshare.GenerateV0Blobs([]int{9, 5, 15, 4, 24}, true) require.NoError(t, err) blobs, err := convertBlobs(libBlob...) require.NoError(t, err) @@ -586,7 +584,7 @@ func TestService_GetAllWithoutPadding(t *testing.T) { require.NoError(t, err) assert.Equal(t, sh, resultShares[shareOffset]) - shareOffset += appshares.SparseSharesNeeded(uint32(len(blob.Data()))) + shareOffset += libshare.SparseSharesNeeded(uint32(len(blob.Data()))) } } @@ -621,7 +619,7 @@ func TestSkipPaddingsAndRetrieveBlob(t *testing.T) { rawShares = append(rawShares, padding) } - size := blobtest.RawBlobSize(libshare.FirstSparseShareContentSize * 6) + size := rawBlobSize(libshare.FirstSparseShareContentSize * 6) ns, err := libshare.NewNamespace(nid.Version(), nid.ID()) require.NoError(t, err) data := tmrand.Bytes(size) @@ -649,7 +647,7 @@ func TestService_Subscribe(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), time.Second*10) t.Cleanup(cancel) - libBlobs, err := blobtest.GenerateV0Blobs([]int{16, 16, 16}, true) + libBlobs, err := libshare.GenerateV0Blobs([]int{16, 16, 16}, true) require.NoError(t, err) blobs, err := convertBlobs(libBlobs...) require.NoError(t, err) @@ -754,9 +752,9 @@ func TestService_Subscribe_MultipleNamespaces(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), time.Second*10) t.Cleanup(cancel) - libBlobs1, err := blobtest.GenerateV0Blobs([]int{100, 100}, true) + libBlobs1, err := libshare.GenerateV0Blobs([]int{100, 100}, true) require.NoError(t, err) - libBlobs2, err := blobtest.GenerateV0Blobs([]int{100, 100}, true) + libBlobs2, err := libshare.GenerateV0Blobs([]int{100, 100}, true) for i := range libBlobs2 { // if we don't do this, libBlobs1 and libBlobs2 will share a NS libBlobs2[i].Namespace().ID()[len(libBlobs2[i].Namespace().ID())-1] = 0xDE @@ -815,7 +813,7 @@ func TestService_Subscribe_MultipleNamespaces(t *testing.T) { func BenchmarkGetByCommitment(b *testing.B) { ctx, cancel := context.WithTimeout(context.Background(), time.Second*5) b.Cleanup(cancel) - libBlobs, err := blobtest.GenerateV0Blobs([]int{32, 32}, true) + libBlobs, err := libshare.GenerateV0Blobs([]int{32, 32}, true) require.NoError(b, err) blobs, err := convertBlobs(libBlobs...) @@ -1068,3 +1066,13 @@ func generateCommitmentProofFromBlock( return commitmentProof } + +func rawBlobSize(totalSize int) int { + return totalSize - delimLen(uint64(totalSize)) +} + +// delimLen calculates the length of the delimiter for a given unit size +func delimLen(size uint64) int { + lenBuf := make([]byte, binary.MaxVarintLen64) + return binary.PutUvarint(lenBuf, size) +} diff --git a/core/eds.go b/core/eds.go index ec4b333830..e2cb6fef4d 100644 --- a/core/eds.go +++ b/core/eds.go @@ -9,7 +9,6 @@ import ( "github.com/celestiaorg/celestia-app/v3/app" "github.com/celestiaorg/celestia-app/v3/pkg/appconsts" "github.com/celestiaorg/celestia-app/v3/pkg/wrapper" - "github.com/celestiaorg/go-square/shares" libsquare "github.com/celestiaorg/go-square/v2" libshare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt" @@ -44,7 +43,7 @@ func extendBlock(data types.Data, appVersion uint64, options ...nmt.Option) (*rs func extendShares(s [][]byte, options ...nmt.Option) (*rsmt2d.ExtendedDataSquare, error) { // Check that the length of the square is a power of 2. - if !shares.IsPowerOfTwo(len(s)) { + if !libsquare.IsPowerOfTwo(len(s)) { return nil, fmt.Errorf("number of shares is not a power of 2: got %d", len(s)) } // here we construct a tree diff --git a/go.mod b/go.mod index bea5484afa..5e2dc3029f 100644 --- a/go.mod +++ b/go.mod @@ -11,9 +11,8 @@ require ( github.com/celestiaorg/go-fraud v0.2.1 github.com/celestiaorg/go-header v0.6.2 github.com/celestiaorg/go-libp2p-messenger v0.2.0 - github.com/celestiaorg/go-square v1.1.0 github.com/celestiaorg/go-square/merkle v0.0.0-20240117232118-fd78256df076 - github.com/celestiaorg/go-square/v2 v2.0.0 + github.com/celestiaorg/go-square/v2 v2.1.0-rc0 github.com/celestiaorg/nmt v0.22.2 github.com/celestiaorg/rsmt2d v0.14.0 github.com/cosmos/cosmos-sdk v0.46.16 @@ -101,6 +100,7 @@ require ( github.com/bits-and-blooms/bitset v1.13.0 // indirect github.com/btcsuite/btcd/btcec/v2 v2.3.4 // indirect github.com/celestiaorg/blobstream-contracts/v3 v3.1.0 // indirect + github.com/celestiaorg/go-square v1.1.0 // indirect github.com/celestiaorg/merkletree v0.0.0-20230308153949-c33506a7aa26 // indirect github.com/cenkalti/backoff/v4 v4.3.0 // indirect github.com/cespare/xxhash v1.1.0 // indirect @@ -344,7 +344,6 @@ require ( ) replace ( - github.com/celestiaorg/go-square/v2 v2.0.0 => github.com/celestiaorg/go-square/v2 v2.0.1-0.20241007123147-1359db0f487c github.com/cosmos/cosmos-sdk => github.com/celestiaorg/cosmos-sdk v1.25.0-sdk-v0.46.16 github.com/filecoin-project/dagstore => github.com/celestiaorg/dagstore v0.0.0-20230824094345-537c012aa403 github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1 diff --git a/go.sum b/go.sum index e5d95552b5..8e88162857 100644 --- a/go.sum +++ b/go.sum @@ -361,12 +361,11 @@ github.com/celestiaorg/go-square v1.1.0 h1:K4tBL5PCJwDtpBfyDxxZ3N962aC9VYb5/bw3L github.com/celestiaorg/go-square v1.1.0/go.mod h1:1EXMErhDrWJM8B8V9hN7dqJ2kUTClfwdqMOmF9yQUa0= github.com/celestiaorg/go-square/merkle v0.0.0-20240117232118-fd78256df076 h1:PYInrsYzrDIsZW9Yb86OTi2aEKuPcpgJt6Mc0Jlc/yg= github.com/celestiaorg/go-square/merkle v0.0.0-20240117232118-fd78256df076/go.mod h1:hlidgivKyvv7m4Yl2Fdf2mSTmazZYxX8+bnr5IQrI98= -github.com/celestiaorg/go-square/v2 v2.0.1-0.20241007123147-1359db0f487c h1:HOXirS9jNTqKSz/Iv7PauWuaC6Dt5RIPg95xhP2q5Mw= -github.com/celestiaorg/go-square/v2 v2.0.1-0.20241007123147-1359db0f487c/go.mod h1:y0BolG0tRM7UN1sAQyDDUkT+aMJPwFIjviVvnCB62C0= +github.com/celestiaorg/go-square/v2 v2.1.0-rc0 h1:Ra6bp+mVUXmUT1KYMiOCmW4tBK6EIknpP10uhPngOR8= +github.com/celestiaorg/go-square/v2 v2.1.0-rc0/go.mod h1:n3ztrh8CBjWOD6iWYMo3pPOlQIgzLK9yrnqMPcNo6g8= github.com/celestiaorg/merkletree v0.0.0-20230308153949-c33506a7aa26 h1:P2RI1xJ49EZ8cuHMcH+ZSBonfRDtBS8OS9Jdt1BWX3k= github.com/celestiaorg/merkletree v0.0.0-20230308153949-c33506a7aa26/go.mod h1:2m8ukndOegwB0PU0AfJCwDUQHqd7QQRlSXvQL5VToVY= -github.com/celestiaorg/nmt v0.22.1 h1:t7fqoP5MJ8mBns5DB2XjfcPxQpS3CKMkY+v+BEkDxYc= -github.com/celestiaorg/nmt v0.22.1/go.mod h1:ia/EpCk0enD5yO5frcxoNoFToz2Ghtk2i+blmCRjIY8= +github.com/celestiaorg/nmt v0.22.2 h1:JmOMtZL9zWAed1hiwb9DDs+ELcKp/ZQZ3rPverge/V8= github.com/celestiaorg/nmt v0.22.2/go.mod h1:/7huDiSRL/d2EGhoiKctgSzmLOJoWG8yEfbFtY1+Mow= github.com/celestiaorg/rsmt2d v0.14.0 h1:L7XJ3tRJDY8sQcvCjzHq0L7JmsmaSD+VItymIYFLqYc= github.com/celestiaorg/rsmt2d v0.14.0/go.mod h1:4kxqiTdFev49sGiKXTDjohbWYOG5GlcIfftTgaBJnpc= @@ -1815,8 +1814,8 @@ github.com/tidwall/btree v1.5.0/go.mod h1:LGm8L/DZjPLmeWGjv5kFrY8dL4uVhMmzmmLYms github.com/tidwall/gjson v1.6.0/go.mod h1:P256ACg0Mn+j1RXIDXoss50DeIABTYK1PULOJHhxOls= github.com/tidwall/gjson v1.12.1/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= github.com/tidwall/gjson v1.14.0/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= -github.com/tidwall/gjson v1.17.1 h1:wlYEnwqAHgzmhNUFfw7Xalt2JzQvsMx2Se4PcoFCT/U= -github.com/tidwall/gjson v1.17.1/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= +github.com/tidwall/gjson v1.18.0 h1:FIDeeyB800efLX89e5a8Y0BNH+LOngJyGrIWxG2FKQY= +github.com/tidwall/gjson v1.18.0/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= github.com/tidwall/match v1.0.1/go.mod h1:LujAq0jyVjBy028G1WhWfIzbpQfMO8bBZ6Tyb0+pL9E= github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA= github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM= diff --git a/nodebuilder/tests/api_test.go b/nodebuilder/tests/api_test.go index 524c9f310f..19bf117ec5 100644 --- a/nodebuilder/tests/api_test.go +++ b/nodebuilder/tests/api_test.go @@ -14,7 +14,6 @@ import ( "github.com/celestiaorg/celestia-node/api/rpc/client" "github.com/celestiaorg/celestia-node/blob" - "github.com/celestiaorg/celestia-node/blob/blobtest" "github.com/celestiaorg/celestia-node/nodebuilder" "github.com/celestiaorg/celestia-node/nodebuilder/node" "github.com/celestiaorg/celestia-node/nodebuilder/tests/swamp" @@ -107,7 +106,7 @@ func TestBlobRPC(t *testing.T) { rpcClient := getAdminClient(ctx, bridge, t) - libBlobs, err := blobtest.GenerateV0Blobs([]int{8}, false) + libBlobs, err := libshare.GenerateV0Blobs([]int{8}, false) require.NoError(t, err) newBlob, err := blob.NewBlob( diff --git a/nodebuilder/tests/blob_test.go b/nodebuilder/tests/blob_test.go index 7e83ddf5b6..c8042d08d7 100644 --- a/nodebuilder/tests/blob_test.go +++ b/nodebuilder/tests/blob_test.go @@ -16,7 +16,6 @@ import ( libshare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/celestia-node/blob" - "github.com/celestiaorg/celestia-node/blob/blobtest" "github.com/celestiaorg/celestia-node/nodebuilder/node" "github.com/celestiaorg/celestia-node/nodebuilder/tests/swamp" "github.com/celestiaorg/celestia-node/state" @@ -27,9 +26,9 @@ func TestBlobModule(t *testing.T) { t.Cleanup(cancel) sw := swamp.NewSwamp(t, swamp.WithBlockTime(time.Second*1)) - libBlobs0, err := blobtest.GenerateV0Blobs([]int{8, 4}, true) + libBlobs0, err := libshare.GenerateV0Blobs([]int{8, 4}, true) require.NoError(t, err) - libBlobs1, err := blobtest.GenerateV0Blobs([]int{4}, false) + libBlobs1, err := libshare.GenerateV0Blobs([]int{4}, false) require.NoError(t, err) blobs := make([]*blob.Blob, 0, len(libBlobs0)+len(libBlobs1)) @@ -116,7 +115,7 @@ func TestBlobModule(t *testing.T) { { name: "Not Found", doFn: func(t *testing.T) { - libBlob, err := blobtest.GenerateV0Blobs([]int{4}, false) + libBlob, err := libshare.GenerateV0Blobs([]int{4}, false) require.NoError(t, err) newBlob, err := convert(libBlob[0]) require.NoError(t, err) @@ -134,7 +133,7 @@ func TestBlobModule(t *testing.T) { { name: "Submit equal blobs", doFn: func(t *testing.T) { - libBlob, err := blobtest.GenerateV0Blobs([]int{8, 4}, true) + libBlob, err := libshare.GenerateV0Blobs([]int{8, 4}, true) require.NoError(t, err) b, err := convert(libBlob[0]) require.NoError(t, err) diff --git a/nodebuilder/tests/da_test.go b/nodebuilder/tests/da_test.go index ecca83ae81..c9973f4540 100644 --- a/nodebuilder/tests/da_test.go +++ b/nodebuilder/tests/da_test.go @@ -16,7 +16,6 @@ import ( libshare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/celestia-node/blob" - "github.com/celestiaorg/celestia-node/blob/blobtest" "github.com/celestiaorg/celestia-node/nodebuilder/da" "github.com/celestiaorg/celestia-node/nodebuilder/node" "github.com/celestiaorg/celestia-node/nodebuilder/tests/swamp" @@ -31,9 +30,9 @@ func TestDaModule(t *testing.T) { require.NoError(t, err) require.False(t, namespace.IsReserved()) - libBlobs0, err := blobtest.GenerateV0Blobs([]int{8, 4}, true) + libBlobs0, err := libshare.GenerateV0Blobs([]int{8, 4}, true) require.NoError(t, err) - libBlobs1, err := blobtest.GenerateV0Blobs([]int{4}, false) + libBlobs1, err := libshare.GenerateV0Blobs([]int{4}, false) require.NoError(t, err) blobs := make([]*blob.Blob, 0, len(libBlobs0)+len(libBlobs1)) daBlobs := make([][]byte, 0, len(libBlobs0)+len(libBlobs1)) diff --git a/share/availability/test/testing.go b/share/availability/test/testing.go index affd541d64..e9bee74357 100644 --- a/share/availability/test/testing.go +++ b/share/availability/test/testing.go @@ -26,7 +26,8 @@ import ( // RandFillBS fills the given BlockService with a random block of a given size. func RandFillBS(t *testing.T, n int, bServ blockservice.BlockService) *share.AxisRoots { - shares := libshare.RandShares(n * n) + shares, err := libshare.RandShares(n * n) + require.NoError(t, err) return FillBS(t, bServ, shares) } diff --git a/share/eds/axis_half_test.go b/share/eds/axis_half_test.go index 8b339a2afb..643dd85af3 100644 --- a/share/eds/axis_half_test.go +++ b/share/eds/axis_half_test.go @@ -9,7 +9,8 @@ import ( ) func TestExtendAxisHalf(t *testing.T) { - shares := libshare.RandShares(16) + shares, err := libshare.RandShares(16) + require.NoError(t, err) original := AxisHalf{ Shares: shares, diff --git a/share/eds/byzantine/bad_encoding_test.go b/share/eds/byzantine/bad_encoding_test.go index 57fc84bfe3..6b3940ba4a 100644 --- a/share/eds/byzantine/bad_encoding_test.go +++ b/share/eds/byzantine/bad_encoding_test.go @@ -89,7 +89,8 @@ func TestBEFP_Validate(t *testing.T) { name: "incorrect share with Proof", prepareFn: func() error { // break the first shareWithProof to test negative case - sh := libshare.RandShares(2) + sh, err := libshare.RandShares(2) + require.NoError(t, err) nmtProof := nmt.NewInclusionProof(0, 1, nil, false) befp.Shares[0] = &ShareWithProof{sh[0], &nmtProof, rsmt2d.Row} return proof.Validate(&header.ExtendedHeader{DAH: roots}) @@ -160,8 +161,8 @@ func TestIncorrectBadEncodingFraudProof(t *testing.T) { bServ := ipld.NewMemBlockservice() squareSize := 8 - shares := libshare.RandShares(squareSize * squareSize) - + shares, err := libshare.RandShares(squareSize * squareSize) + require.NoError(t, err) eds, err := ipld.AddShares(ctx, shares, bServ) require.NoError(t, err) diff --git a/share/eds/edstest/testing.go b/share/eds/edstest/testing.go index 818e7b7596..a022087978 100644 --- a/share/eds/edstest/testing.go +++ b/share/eds/edstest/testing.go @@ -16,8 +16,7 @@ import ( "github.com/celestiaorg/celestia-app/v3/test/util/blobfactory" "github.com/celestiaorg/celestia-app/v3/test/util/testfactory" blobtypes "github.com/celestiaorg/celestia-app/v3/x/blob/types" - appshares "github.com/celestiaorg/go-square/shares" - libSquare "github.com/celestiaorg/go-square/square" + libSquare "github.com/celestiaorg/go-square/v2" libshare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt" "github.com/celestiaorg/rsmt2d" @@ -45,7 +44,8 @@ func RandByzantineEDS(t testing.TB, odsSize int, options ...nmt.Option) *rsmt2d. // RandEDS generates EDS filled with the random data with the given size for original square. func RandEDS(t testing.TB, odsSize int) *rsmt2d.ExtendedDataSquare { - shares := libshare.RandShares(odsSize * odsSize) + shares, err := libshare.RandShares(odsSize * odsSize) + require.NoError(t, err) eds, err := rsmt2d.ComputeExtendedDataSquare( libshare.ToBytes(shares), share.DefaultRSMT2DCodec(), @@ -57,7 +57,8 @@ func RandEDS(t testing.TB, odsSize int) *rsmt2d.ExtendedDataSquare { // RandEDSWithTailPadding generates EDS of given ODS size filled with randomized and tail padding shares. func RandEDSWithTailPadding(t testing.TB, odsSize, padding int) *rsmt2d.ExtendedDataSquare { - shares := libshare.RandShares(odsSize * odsSize) + shares, err := libshare.RandShares(odsSize * odsSize) + require.NoError(t, err) for i := len(shares) - padding; i < len(shares); i++ { paddingShare := libshare.TailPaddingShare() shares[i] = paddingShare @@ -79,7 +80,8 @@ func RandEDSWithNamespace( namespace libshare.Namespace, namespacedAmount, odsSize int, ) (*rsmt2d.ExtendedDataSquare, *share.AxisRoots) { - shares := libshare.RandSharesWithNamespace(namespace, namespacedAmount, odsSize*odsSize) + shares, err := libshare.RandSharesWithNamespace(namespace, namespacedAmount, odsSize*odsSize) + require.NoError(t, err) eds, err := rsmt2d.ComputeExtendedDataSquare( libshare.ToBytes(shares), share.DefaultRSMT2DCodec(), @@ -139,7 +141,7 @@ func GenerateTestBlock( require.NoError(t, err) // erasure the data square which we use to create the data root. - eds, err := da.ExtendShares(appshares.ToBytes(square)) + eds, err := da.ExtendShares(libshare.ToBytes(square)) require.NoError(t, err) // create the new data root by creating the data availability header (merkle diff --git a/share/eds/retriever_test.go b/share/eds/retriever_test.go index 5fe7bf4038..b9bcb4f74f 100644 --- a/share/eds/retriever_test.go +++ b/share/eds/retriever_test.go @@ -46,7 +46,8 @@ func TestRetriever_Retrieve(t *testing.T) { for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { // generate EDS - shares := libshare.RandShares(tc.squareSize * tc.squareSize) + shares, err := libshare.RandShares(tc.squareSize * tc.squareSize) + require.NoError(t, err) in, err := ipld.AddShares(ctx, shares, bServ) require.NoError(t, err) @@ -75,7 +76,8 @@ func TestRetriever_MultipleRandQuadrants(t *testing.T) { r := NewRetriever(bServ) // generate EDS - shares := libshare.RandShares(squareSize * squareSize) + shares, err := libshare.RandShares(squareSize * squareSize) + require.NoError(t, err) in, err := ipld.AddShares(ctx, shares, bServ) require.NoError(t, err) diff --git a/share/eds/testing.go b/share/eds/testing.go index 247324b1b4..388544bc00 100644 --- a/share/eds/testing.go +++ b/share/eds/testing.go @@ -263,7 +263,7 @@ func testAccessorRowNamespaceData( ns, err := libshare.NewNamespaceFromBytes(maxNs) require.NoError(t, err) - absentNs, err := libshare.AddInt(ns, -1) + absentNs, err := ns.AddInt(-1) require.NoError(t, err) acc := createAccessor(t, eds) diff --git a/share/ipld/delete_test.go b/share/ipld/delete_test.go index 033d856355..08ca6f8ad5 100644 --- a/share/ipld/delete_test.go +++ b/share/ipld/delete_test.go @@ -21,7 +21,8 @@ func TestDeleteNode_FullSquare(t *testing.T) { defer cancel() bServ := NewMemBlockservice() - shares := libshare.RandShares(size * size) + shares, err := libshare.RandShares(size * size) + require.NoError(t, err) eds, err := AddShares(ctx, shares, bServ) require.NoError(t, err) @@ -63,7 +64,8 @@ func TestDeleteNode_Sample(t *testing.T) { defer cancel() full := NewMemBlockservice() - shares := libshare.RandShares(size * size) + shares, err := libshare.RandShares(size * size) + require.NoError(t, err) eds, err := AddShares(ctx, shares, full) require.NoError(t, err) diff --git a/share/ipld/get_shares_test.go b/share/ipld/get_shares_test.go index 71856ce373..5732e5565e 100644 --- a/share/ipld/get_shares_test.go +++ b/share/ipld/get_shares_test.go @@ -31,7 +31,8 @@ func TestGetShare(t *testing.T) { bServ := NewMemBlockservice() // generate random shares for the nmt - shares := libshare.RandShares(size * size) + shares, err := libshare.RandShares(size * size) + require.NoError(t, err) eds, err := AddShares(ctx, shares, bServ) require.NoError(t, err) @@ -53,8 +54,10 @@ func TestBlockRecovery(t *testing.T) { extendedShareCount := extendedSquareWidth * extendedSquareWidth // generate test data - quarterShares := libshare.RandShares(shareCount) - allShares := libshare.RandShares(shareCount) + quarterShares, err := libshare.RandShares(shareCount) + require.NoError(t, err) + allShares, err := libshare.RandShares(shareCount) + require.NoError(t, err) testCases := []struct { name string @@ -114,7 +117,8 @@ func TestBlockRecovery(t *testing.T) { func Test_ConvertEDStoShares(t *testing.T) { squareWidth := 16 - shares := libshare.RandShares(squareWidth * squareWidth) + shares, err := libshare.RandShares(squareWidth * squareWidth) + require.NoError(t, err) // compute extended square testEds, err := rsmt2d.ComputeExtendedDataSquare( @@ -147,12 +151,17 @@ func TestGetSharesByNamespace(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) t.Cleanup(cancel) bServ := NewMemBlockservice() + sh0, err := libshare.RandShares(4) + require.NoError(t, err) + + sh1, err := libshare.RandShares(4) + require.NoError(t, err) tests := []struct { rawData []libshare.Share }{ - {rawData: libshare.RandShares(4)}, - {rawData: libshare.RandShares(16)}, + {rawData: sh0}, + {rawData: sh1}, } for i, tt := range tests { @@ -193,7 +202,8 @@ func TestCollectLeavesByNamespace_IncompleteData(t *testing.T) { t.Cleanup(cancel) bServ := NewMemBlockservice() - shares := libshare.RandShares(16) + shares, err := libshare.RandShares(16) + require.NoError(t, err) // set all shares to the same namespace id namespace := shares[0].Namespace() @@ -237,8 +247,8 @@ func TestCollectLeavesByNamespace_AbsentNamespaceId(t *testing.T) { t.Cleanup(cancel) bServ := NewMemBlockservice() - shares := libshare.RandShares(1024) - + shares, err := libshare.RandShares(1024) + require.NoError(t, err) // set all shares to the same namespace namespaces, err := randomNamespaces(5) require.NoError(t, err) @@ -282,8 +292,8 @@ func TestCollectLeavesByNamespace_MultipleRowsContainingSameNamespaceId(t *testi t.Cleanup(cancel) bServ := NewMemBlockservice() - shares := libshare.RandShares(16) - + shares, err := libshare.RandShares(16) + require.NoError(t, err) // set all shares to the same namespace and data but the last one namespace := shares[0].Namespace() commonNamespaceData := shares[0] @@ -326,12 +336,18 @@ func TestGetSharesWithProofsByNamespace(t *testing.T) { t.Cleanup(cancel) bServ := NewMemBlockservice() + sh0, err := libshare.RandShares(4) + require.NoError(t, err) + sh1, err := libshare.RandShares(16) + require.NoError(t, err) + sh2, err := libshare.RandShares(64) + require.NoError(t, err) tests := []struct { rawData []libshare.Share }{ - {rawData: libshare.RandShares(4)}, - {rawData: libshare.RandShares(16)}, - {rawData: libshare.RandShares(64)}, + {rawData: sh0}, + {rawData: sh1}, + {rawData: sh2}, } for i, tt := range tests { diff --git a/share/ipld/namespace_data.go b/share/ipld/namespace_data.go index b71ca86544..2afc13c05a 100644 --- a/share/ipld/namespace_data.go +++ b/share/ipld/namespace_data.go @@ -72,7 +72,7 @@ func NewNamespaceData(maxShares int, namespace libshare.Namespace, options ...Op } func (n *NamespaceData) validate(rootCid cid.Cid) error { - if err := libshare.ValidateUserNamespace(n.namespace.Version(), n.namespace.ID()); err != nil { + if err := n.namespace.ValidateForData(); err != nil { return err } diff --git a/share/ipld/proofs_test.go b/share/ipld/proofs_test.go index 51b3f82bea..a17c14697d 100644 --- a/share/ipld/proofs_test.go +++ b/share/ipld/proofs_test.go @@ -21,7 +21,8 @@ func TestGetProof(t *testing.T) { defer cancel() bServ := NewMemBlockservice() - shares := libshare.RandShares(width * width) + shares, err := libshare.RandShares(width * width) + require.NoError(t, err) in, err := AddShares(ctx, shares, bServ) require.NoError(t, err) diff --git a/share/shwap/namespace_data_id.go b/share/shwap/namespace_data_id.go index cb3baa30bd..2af86858c0 100644 --- a/share/shwap/namespace_data_id.go +++ b/share/shwap/namespace_data_id.go @@ -112,7 +112,7 @@ func (ndid NamespaceDataID) Validate() error { return fmt.Errorf("validating RowID: %w", err) } - if err := libshare.ValidateForData(ndid.DataNamespace); err != nil { + if err := ndid.DataNamespace.ValidateForData(); err != nil { return fmt.Errorf("%w: validating DataNamespace: %w", ErrInvalidID, err) } return nil diff --git a/share/shwap/p2p/bitswap/getter.go b/share/shwap/p2p/bitswap/getter.go index 7717fcbb4f..0c5fd5d51d 100644 --- a/share/shwap/p2p/bitswap/getter.go +++ b/share/shwap/p2p/bitswap/getter.go @@ -187,7 +187,7 @@ func (g *Getter) GetSharesByNamespace( hdr *header.ExtendedHeader, ns libshare.Namespace, ) (shwap.NamespaceData, error) { - if err := libshare.ValidateForData(ns); err != nil { + if err := ns.ValidateForData(); err != nil { return nil, err } diff --git a/share/shwap/p2p/shrex/shrex_getter/shrex.go b/share/shwap/p2p/shrex/shrex_getter/shrex.go index bed2880458..2131c2f9e8 100644 --- a/share/shwap/p2p/shrex/shrex_getter/shrex.go +++ b/share/shwap/p2p/shrex/shrex_getter/shrex.go @@ -219,7 +219,7 @@ func (sg *Getter) GetSharesByNamespace( header *header.ExtendedHeader, namespace libshare.Namespace, ) (shwap.NamespaceData, error) { - if err := libshare.ValidateForData(namespace); err != nil { + if err := namespace.ValidateForData(); err != nil { return nil, err } var ( diff --git a/share/shwap/p2p/shrex/shrex_getter/shrex_test.go b/share/shwap/p2p/shrex/shrex_getter/shrex_test.go index dcf81fbac1..bbee85eb38 100644 --- a/share/shwap/p2p/shrex/shrex_getter/shrex_test.go +++ b/share/shwap/p2p/shrex/shrex_getter/shrex_test.go @@ -124,7 +124,7 @@ func TestShrexGetter(t *testing.T) { }) // namespace inside root range - nID, err := libshare.AddInt(maxNamespace, -1) + nID, err := maxNamespace.AddInt(-1) require.NoError(t, err) // check for namespace to be between max and min namespace in root rows, err := share.RowsWithNamespace(roots, nID) @@ -138,7 +138,7 @@ func TestShrexGetter(t *testing.T) { require.Nil(t, emptyShares.Verify(roots, nID)) // namespace outside root range - nID, err = libshare.AddInt(maxNamespace, 1) + nID, err = maxNamespace.AddInt(1) require.NoError(t, err) // check for namespace to be not in root rows, err = share.RowsWithNamespace(roots, nID) @@ -169,7 +169,7 @@ func TestShrexGetter(t *testing.T) { Height: height, }) - namespace, err := libshare.AddInt(maxNamespace, 1) + namespace, err := maxNamespace.AddInt(1) require.NoError(t, err) // check for namespace to be not in root rows, err := share.RowsWithNamespace(roots, namespace) diff --git a/share/shwap/p2p/shrex/shrexnd/client.go b/share/shwap/p2p/shrex/shrexnd/client.go index 9a3780b325..54d2baaccb 100644 --- a/share/shwap/p2p/shrex/shrexnd/client.go +++ b/share/shwap/p2p/shrex/shrexnd/client.go @@ -53,7 +53,7 @@ func (c *Client) RequestND( namespace libshare.Namespace, peer peer.ID, ) (shwap.NamespaceData, error) { - if err := libshare.ValidateForData(namespace); err != nil { + if err := namespace.ValidateForData(); err != nil { return nil, err } diff --git a/share/shwap/row_namespace_data_id.go b/share/shwap/row_namespace_data_id.go index 26a8605caf..2d0444e1ea 100644 --- a/share/shwap/row_namespace_data_id.go +++ b/share/shwap/row_namespace_data_id.go @@ -123,7 +123,7 @@ func (rndid RowNamespaceDataID) Validate() error { if err := rndid.RowID.Validate(); err != nil { return fmt.Errorf("validating RowID: %w", err) } - if err := libshare.ValidateForData(rndid.DataNamespace); err != nil { + if err := rndid.DataNamespace.ValidateForData(); err != nil { return fmt.Errorf("%w: validating DataNamespace: %w", ErrInvalidID, err) } diff --git a/share/shwap/row_namespace_data_test.go b/share/shwap/row_namespace_data_test.go index 1fe7264081..cdc383f2e6 100644 --- a/share/shwap/row_namespace_data_test.go +++ b/share/shwap/row_namespace_data_test.go @@ -22,11 +22,11 @@ func TestNamespacedRowFromShares(t *testing.T) { minNamespace, err := libshare.NewV0Namespace(slices.Concat(bytes.Repeat([]byte{0}, 8), []byte{1, 0})) require.NoError(t, err) - err = libshare.ValidateForData(minNamespace) - require.NoError(t, err) + require.NoError(t, minNamespace.ValidateForData()) for namespacedAmount := 1; namespacedAmount < odsSize; namespacedAmount++ { - shares := libshare.RandSharesWithNamespace(minNamespace, namespacedAmount, odsSize) + shares, err := libshare.RandSharesWithNamespace(minNamespace, namespacedAmount, odsSize) + require.NoError(t, err) parity, err := share.DefaultRSMT2DCodec().Encode(libshare.ToBytes(shares)) require.NoError(t, err) @@ -46,7 +46,8 @@ func TestNamespacedRowFromShares(t *testing.T) { // // const odsSize = 8 // //Test absent namespace -// shares := libshare.RandShares( odsSize) +// shares,err := libshare.RandShares( odsSize) +// require.NoError(t, err) // absentNs, err := share.GetNamespace(shares[0]).AddInt(1) // require.NoError(t, err) // diff --git a/store/file/codec_test.go b/store/file/codec_test.go index 654d72f069..eabb125c8e 100644 --- a/store/file/codec_test.go +++ b/store/file/codec_test.go @@ -70,7 +70,8 @@ func BenchmarkCodec(b *testing.B) { func newShards(b testing.TB, size int, fillParity bool) [][]byte { shards := make([][]byte, size) - original := libshare.RandShares(size / 2) + original, err := libshare.RandShares(size / 2) + require.NoError(b, err) copy(shards, libshare.ToBytes(original)) if fillParity { From 1486b2fe1c933925131af29dcdb532018add743a Mon Sep 17 00:00:00 2001 From: vgonkivs Date: Thu, 17 Oct 2024 20:40:48 +0300 Subject: [PATCH 15/21] rework BlobsToShares --- blob/helper.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/blob/helper.go b/blob/helper.go index ce66aced25..d764e827e9 100644 --- a/blob/helper.go +++ b/blob/helper.go @@ -1,7 +1,6 @@ package blob import ( - "fmt" "sort" libshare "github.com/celestiaorg/go-square/v2/share" @@ -13,14 +12,15 @@ func BlobsToShares(nodeBlobs ...*Blob) ([]libshare.Share, error) { return nodeBlobs[i].Blob.Namespace().IsLessThan(nodeBlobs[j].Blob.Namespace()) }) - splitter := libshare.NewSparseShareSplitter() - for i, nodeBlob := range nodeBlobs { - err := splitter.Write(nodeBlob.Blob) + shares := make([]libshare.Share, 0) + for _, nodeBlob := range nodeBlobs { + sh, err := nodeBlob.ToShares() if err != nil { - return nil, fmt.Errorf("failed to split blob at index: %d: %w", i, err) + return nil, err } + shares = append(shares, sh...) } - return splitter.Export(), nil + return shares, nil } // ToLibBlobs converts node's blob type to the blob type from go-square. From cea9ec76895452e9aef56e89f55b6a2307fc3647 Mon Sep 17 00:00:00 2001 From: vgonkivs Date: Thu, 17 Oct 2024 20:53:20 +0300 Subject: [PATCH 16/21] add more fixes --- blob/blob_fuzz_test.go | 3 ++- nodebuilder/share/share.go | 2 +- share/availability/full/testing.go | 2 +- share/availability/light/testing.go | 10 +++++----- store/file/ods.go | 2 +- 5 files changed, 10 insertions(+), 9 deletions(-) diff --git a/blob/blob_fuzz_test.go b/blob/blob_fuzz_test.go index f3b8f221f3..1927ff3d46 100644 --- a/blob/blob_fuzz_test.go +++ b/blob/blob_fuzz_test.go @@ -2,10 +2,11 @@ package blob import ( "encoding/json" - libshare "github.com/celestiaorg/go-square/v2/share" "os" "path/filepath" "testing" + + libshare "github.com/celestiaorg/go-square/v2/share" ) func FuzzProofEqual(f *testing.F) { diff --git a/nodebuilder/share/share.go b/nodebuilder/share/share.go index 81546ca673..79812a9fb6 100644 --- a/nodebuilder/share/share.go +++ b/nodebuilder/share/share.go @@ -28,7 +28,7 @@ type GetRangeResult struct { // Module provides access to any data square or block share on the network. // // All Get methods provided on Module follow the following flow: -// 1. Check local storage for the requested libshare. +// 1. Check local storage for the requested share. // 2. If exists // * Load from disk // * Return diff --git a/share/availability/full/testing.go b/share/availability/full/testing.go index e3f1d64831..626de5e3d6 100644 --- a/share/availability/full/testing.go +++ b/share/availability/full/testing.go @@ -17,7 +17,7 @@ package full // "github.com/celestiaorg/celestia-node/share/p2p/discovery" //) // -//// GetterWithRandSquare provides a libshare.Getter filled with 'n' NMT +//// GetterWithRandSquare provides a share.Getter filled with 'n' NMT //// trees of 'n' random shares, essentially storing a whole share. // func GetterWithRandSquare(t *testing.T, n int) (share.Getter, *share.AxisRoots) { // bServ := ipld.NewMemBlockservice() diff --git a/share/availability/light/testing.go b/share/availability/light/testing.go index 2b454dbda0..239bfa1ba3 100644 --- a/share/availability/light/testing.go +++ b/share/availability/light/testing.go @@ -19,9 +19,9 @@ package light // "github.com/celestiaorg/celestia-node/share/ipld" //) // -//// GetterWithRandSquare provides a libshare.Getter filled with 'n' NMT trees of 'n' random shares, +//// GetterWithRandSquare provides a share.Getter filled with 'n' NMT trees of 'n' random shares, //// essentially storing a whole square. -// func GetterWithRandSquare(t *testing.T, n int) (libshare.Getter, *header.ExtendedHeader) { +// func GetterWithRandSquare(t *testing.T, n int) (share.Getter, *header.ExtendedHeader) { // bServ := ipld.NewMemBlockservice() // getter := getters.NewIPLDGetter(bServ) // root := availability_test.RandFillBS(t, n, bServ) @@ -31,9 +31,9 @@ package light // return getter, eh //} // -//// EmptyGetter provides an unfilled libshare.Getter with corresponding blockservice.BlockService than +//// EmptyGetter provides an unfilled share.Getter with corresponding blockservice.BlockService than //// can be filled by the test. -// func EmptyGetter() (libshare.Getter, blockservice.BlockService) { +// func EmptyGetter() (share.Getter, blockservice.BlockService) { // bServ := ipld.NewMemBlockservice() // getter := getters.NewIPLDGetter(bServ) // return getter, bServ @@ -53,7 +53,7 @@ package light // return nd //} // -// func TestAvailability(getter libshare.Getter) *ShareAvailability { +// func TestAvailability(getter share.Getter) *ShareAvailability { // ds := datastore.NewMapDatastore() // return NewShareAvailability(getter, ds) //} diff --git a/store/file/ods.go b/store/file/ods.go index 7d07ca5b9d..2feacde227 100644 --- a/store/file/ods.go +++ b/store/file/ods.go @@ -102,7 +102,7 @@ func writeODS(w io.Writer, eds *rsmt2d.ExtendedDataSquare) error { for i := range eds.Width() / 2 { for j := range eds.Width() / 2 { shr := eds.GetCell(i, j) // TODO: Avoid copying inside GetCell - ns, err := libshare.NewNamespace(shr[libshare.VersionIndex], shr[libshare.VersionIndex:libshare.NamespaceIDSize]) + ns, err := libshare.NewNamespaceFromBytes(shr[:libshare.NamespaceSize]) if err != nil { return fmt.Errorf("creating namespace: %w", err) } From fca91157d5ef4cc58328d86c23156b86e1749786 Mon Sep 17 00:00:00 2001 From: vgonkivs Date: Thu, 17 Oct 2024 20:57:29 +0300 Subject: [PATCH 17/21] bump celestia-app and celestia-core --- go.mod | 30 ++++++++++++++++++++---------- go.sum | 51 ++++++++++++++++++++++++++++----------------------- 2 files changed, 48 insertions(+), 33 deletions(-) diff --git a/go.mod b/go.mod index 5e2dc3029f..3d2dfcd93a 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/BurntSushi/toml v1.4.1-0.20240526193622-a339e1f7089c github.com/alecthomas/jsonschema v0.0.0-20220216202328-9eeeec9d044b github.com/benbjohnson/clock v1.3.5 - github.com/celestiaorg/celestia-app/v3 v3.0.0-alpha + github.com/celestiaorg/celestia-app/v3 v3.0.0-rc0 github.com/celestiaorg/go-fraud v0.2.1 github.com/celestiaorg/go-header v0.6.2 github.com/celestiaorg/go-libp2p-messenger v0.2.0 @@ -17,7 +17,7 @@ require ( github.com/celestiaorg/rsmt2d v0.14.0 github.com/cosmos/cosmos-sdk v0.46.16 github.com/cristalhq/jwt/v5 v5.4.0 - github.com/dgraph-io/badger/v4 v4.2.1-0.20240106094458-1c417aa3799c + github.com/dgraph-io/badger/v4 v4.3.0 github.com/etclabscore/go-openrpc-reflect v0.0.37 github.com/filecoin-project/go-jsonrpc v0.6.0 github.com/gammazero/workerpool v1.1.3 @@ -88,6 +88,7 @@ require ( github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect github.com/99designs/keyring v1.2.2 // indirect github.com/ChainSafe/go-schnorrkel v1.0.0 // indirect + github.com/DataDog/zstd v1.5.0 // indirect github.com/Jorropo/jsync v1.0.1 // indirect github.com/Microsoft/go-winio v0.6.2 // indirect github.com/StackExchange/wmi v1.2.1 // indirect @@ -100,15 +101,21 @@ require ( github.com/bits-and-blooms/bitset v1.13.0 // indirect github.com/btcsuite/btcd/btcec/v2 v2.3.4 // indirect github.com/celestiaorg/blobstream-contracts/v3 v3.1.0 // indirect - github.com/celestiaorg/go-square v1.1.0 // indirect + github.com/celestiaorg/go-square v1.1.1 // indirect github.com/celestiaorg/merkletree v0.0.0-20230308153949-c33506a7aa26 // indirect github.com/cenkalti/backoff/v4 v4.3.0 // indirect github.com/cespare/xxhash v1.1.0 // indirect github.com/cespare/xxhash/v2 v2.3.0 // indirect github.com/chzyer/readline v1.5.1 // indirect github.com/cockroachdb/apd/v2 v2.0.2 // indirect + github.com/cockroachdb/errors v1.11.3 // indirect + github.com/cockroachdb/fifo v0.0.0-20240606204812-0bbfbd93a7ce // indirect + github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b // indirect + github.com/cockroachdb/pebble v1.1.2 // indirect + github.com/cockroachdb/redact v1.1.5 // indirect + github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 // indirect github.com/coinbase/rosetta-sdk-go v0.7.9 // indirect - github.com/cometbft/cometbft-db v0.7.0 // indirect + github.com/cometbft/cometbft-db v1.0.1 // indirect github.com/confio/ics23/go v0.9.1 // indirect github.com/consensys/bavard v0.1.13 // indirect github.com/consensys/gnark-crypto v0.12.1 // indirect @@ -134,7 +141,7 @@ require ( github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 // indirect github.com/desertbit/timer v0.0.0-20180107155436-c41aec40b27f // indirect github.com/dgraph-io/badger/v2 v2.2007.4 // indirect - github.com/dgraph-io/ristretto v0.1.1 // indirect + github.com/dgraph-io/ristretto v0.1.2-0.20240116140435-c67e07994f91 // indirect github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13 // indirect github.com/docker/go-connections v0.4.1-0.20210727194412-58542c764a11 // indirect github.com/docker/go-units v0.5.0 // indirect @@ -150,6 +157,7 @@ require ( github.com/francoispqt/gojay v1.2.13 // indirect github.com/fsnotify/fsnotify v1.7.0 // indirect github.com/gammazero/deque v0.2.0 // indirect + github.com/getsentry/sentry-go v0.27.0 // indirect github.com/go-kit/kit v0.12.0 // indirect github.com/go-kit/log v0.2.1 // indirect github.com/go-logfmt/logfmt v0.6.0 // indirect @@ -164,11 +172,10 @@ require ( github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 // indirect github.com/godbus/dbus/v5 v5.1.0 // indirect github.com/gogo/gateway v1.1.0 // indirect - github.com/golang/glog v1.2.2 // indirect github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect github.com/golang/protobuf v1.5.4 // indirect github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb // indirect - github.com/google/btree v1.1.2 // indirect + github.com/google/btree v1.1.3 // indirect github.com/google/flatbuffers v1.12.1 // indirect github.com/google/go-cmp v0.6.0 // indirect github.com/google/gopacket v1.1.19 // indirect @@ -220,6 +227,8 @@ require ( github.com/klauspost/compress v1.17.9 // indirect github.com/klauspost/cpuid/v2 v2.2.8 // indirect github.com/koron/go-ssdp v0.0.4 // indirect + github.com/kr/pretty v0.3.1 // indirect + github.com/kr/text v0.2.0 // indirect github.com/lib/pq v1.10.9 // indirect github.com/libp2p/go-buffer-pool v0.1.0 // indirect github.com/libp2p/go-cidranger v1.1.0 // indirect @@ -231,6 +240,7 @@ require ( github.com/libp2p/go-netroute v0.2.1 // indirect github.com/libp2p/go-reuseport v0.4.0 // indirect github.com/libp2p/go-yamux/v4 v4.0.1 // indirect + github.com/linxGnu/grocksdb v1.9.3 // indirect github.com/magiconair/properties v1.8.7 // indirect github.com/mailru/easyjson v0.7.7 // indirect github.com/manifoldco/promptui v0.9.0 // indirect @@ -290,6 +300,7 @@ require ( github.com/raulk/go-watchdog v1.3.0 // indirect github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect github.com/regen-network/cosmos-proto v0.3.1 // indirect + github.com/rogpeppe/go-internal v1.12.0 // indirect github.com/rs/cors v1.8.3 // indirect github.com/rs/zerolog v1.33.0 // indirect github.com/sasha-s/go-deadlock v0.3.1 // indirect @@ -302,7 +313,6 @@ require ( github.com/subosito/gotenv v1.6.0 // indirect github.com/supranational/blst v0.3.13 // indirect github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d // indirect - github.com/tecbot/gorocksdb v0.0.0-20191217155057-f0fad39f321c // indirect github.com/tendermint/go-amino v0.16.0 // indirect github.com/tendermint/tm-db v0.6.7 // indirect github.com/tidwall/btree v1.5.0 // indirect @@ -313,7 +323,7 @@ require ( github.com/wlynxg/anet v0.0.4 // indirect github.com/zondax/hid v0.9.2 // indirect github.com/zondax/ledger-go v0.14.3 // indirect - go.etcd.io/bbolt v1.3.10 // indirect + go.etcd.io/bbolt v1.3.11 // indirect go.opencensus.io v0.24.0 // indirect go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.49.0 // indirect go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.52.0 // indirect @@ -349,5 +359,5 @@ replace ( github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1 // broken goleveldb needs to be replaced for the cosmos-sdk and celestia-app github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 - github.com/tendermint/tendermint => github.com/celestiaorg/celestia-core v1.42.0-tm-v0.34.35 + github.com/tendermint/tendermint => github.com/celestiaorg/celestia-core v1.43.0-tm-v0.34.35 ) diff --git a/go.sum b/go.sum index 8e88162857..b9e579f4ed 100644 --- a/go.sum +++ b/go.sum @@ -345,10 +345,10 @@ github.com/c-bata/go-prompt v0.2.2/go.mod h1:VzqtzE2ksDBcdln8G7mk2RX9QyGjH+OVqOC github.com/casbin/casbin/v2 v2.1.2/go.mod h1:YcPU1XXisHhLzuxH9coDNf2FbKpjGlbCg3n9yuLkIJQ= github.com/celestiaorg/blobstream-contracts/v3 v3.1.0 h1:h1Y4V3EMQ2mFmNtWt2sIhZIuyASInj1a9ExI8xOsTOw= github.com/celestiaorg/blobstream-contracts/v3 v3.1.0/go.mod h1:x4DKyfKOSv1ZJM9NwV+Pw01kH2CD7N5zTFclXIVJ6GQ= -github.com/celestiaorg/celestia-app/v3 v3.0.0-alpha h1:byrIhd4DJvNeayhs3zuHxpDO5AdM3WX5Wlp2sNO+OBo= -github.com/celestiaorg/celestia-app/v3 v3.0.0-alpha/go.mod h1:Tohj2wSurPa7rVqzC/nvhxMs7GvXKzYiy03cuuGpPIo= -github.com/celestiaorg/celestia-core v1.42.0-tm-v0.34.35 h1:bWy5XOgeuuSLe0Lc/htL9/QLEURBjA1JTvEko6bEBhg= -github.com/celestiaorg/celestia-core v1.42.0-tm-v0.34.35/go.mod h1:/fK0n3ps09t5uErBQe1QZbrE81L81MNUzWpFyWQLDT0= +github.com/celestiaorg/celestia-app/v3 v3.0.0-rc0 h1:cfZVxldi5u/vGZPdFvW95quUmcg307v44PndjYwEOR4= +github.com/celestiaorg/celestia-app/v3 v3.0.0-rc0/go.mod h1:K8U6TRHgofz0y5UcvlOL+CuNLbx4jeZrZF7HZdf+Rgs= +github.com/celestiaorg/celestia-core v1.43.0-tm-v0.34.35 h1:L4GTm+JUXhB0a/nGPMq6jEqqe6THuYSQ8m2kUCtZYqw= +github.com/celestiaorg/celestia-core v1.43.0-tm-v0.34.35/go.mod h1:bFr0lAGwaJ0mOHSBmib5/ca5pbBf1yKWGPs93Td0HPw= github.com/celestiaorg/cosmos-sdk v1.25.0-sdk-v0.46.16 h1:f+fTe7GGk0/qgdzyqB8kk8EcDf9d6MC22khBTQiDXsU= github.com/celestiaorg/cosmos-sdk v1.25.0-sdk-v0.46.16/go.mod h1:07Z8HJqS8Rw4XlZ+ok3D3NM/X/in8mvcGLvl0Zb5wrA= github.com/celestiaorg/go-fraud v0.2.1 h1:oYhxI0gM/EpGRgbVQdRI/LSlqyT65g/WhQGSVGfx09w= @@ -357,8 +357,8 @@ github.com/celestiaorg/go-header v0.6.2 h1:qgWyJQg+/x6k4QAfN1rPt2HXHZjQOmCqD0ct4 github.com/celestiaorg/go-header v0.6.2/go.mod h1:Az4S4NxMOJ1eAzOaF8u5AZt5UzsSzg92uqpdXS3yOZE= github.com/celestiaorg/go-libp2p-messenger v0.2.0 h1:/0MuPDcFamQMbw9xTZ73yImqgTO3jHV7wKHvWD/Irao= github.com/celestiaorg/go-libp2p-messenger v0.2.0/go.mod h1:s9PIhMi7ApOauIsfBcQwbr7m+HBzmVfDIS+QLdgzDSo= -github.com/celestiaorg/go-square v1.1.0 h1:K4tBL5PCJwDtpBfyDxxZ3N962aC9VYb5/bw3LjagEtY= -github.com/celestiaorg/go-square v1.1.0/go.mod h1:1EXMErhDrWJM8B8V9hN7dqJ2kUTClfwdqMOmF9yQUa0= +github.com/celestiaorg/go-square v1.1.1 h1:Cy3p8WVspVcyOqHM8BWFuuYPwMitO1pYGe+ImILFZRA= +github.com/celestiaorg/go-square v1.1.1/go.mod h1:1EXMErhDrWJM8B8V9hN7dqJ2kUTClfwdqMOmF9yQUa0= github.com/celestiaorg/go-square/merkle v0.0.0-20240117232118-fd78256df076 h1:PYInrsYzrDIsZW9Yb86OTi2aEKuPcpgJt6Mc0Jlc/yg= github.com/celestiaorg/go-square/merkle v0.0.0-20240117232118-fd78256df076/go.mod h1:hlidgivKyvv7m4Yl2Fdf2mSTmazZYxX8+bnr5IQrI98= github.com/celestiaorg/go-square/v2 v2.1.0-rc0 h1:Ra6bp+mVUXmUT1KYMiOCmW4tBK6EIknpP10uhPngOR8= @@ -413,6 +413,8 @@ github.com/cncf/xds/go v0.0.0-20211011173535-cb28da3451f1/go.mod h1:eXthEFrGJvWH github.com/cockroachdb/apd/v2 v2.0.2 h1:weh8u7Cneje73dDh+2tEVLUvyBc89iwepWCD8b8034E= github.com/cockroachdb/apd/v2 v2.0.2/go.mod h1:DDxRlzC2lo3/vSlmSoS7JkqbbrARPuFOGr0B9pvN3Gw= github.com/cockroachdb/datadriven v0.0.0-20190809214429-80d97fb3cbaa/go.mod h1:zn76sxSg3SzpJ0PPJaLDCu+Bu0Lg3sKTORVIj19EIF8= +github.com/cockroachdb/datadriven v1.0.3-0.20230413201302-be42291fc80f h1:otljaYPt5hWxV3MUfO5dFPFiOXg9CyG5/kCfayTqsJ4= +github.com/cockroachdb/datadriven v1.0.3-0.20230413201302-be42291fc80f/go.mod h1:a9RdTaap04u637JoCzcUoIcDmvwSUtcUFtT/C3kJlTU= github.com/cockroachdb/errors v1.11.3 h1:5bA+k2Y6r+oz/6Z/RFlNeVCesGARKuC6YymtcDrbC/I= github.com/cockroachdb/errors v1.11.3/go.mod h1:m4UIW4CDjx+R5cybPsNrRbreomiFqt8o1h1wUVazSd8= github.com/cockroachdb/fifo v0.0.0-20240606204812-0bbfbd93a7ce h1:giXvy4KSc/6g/esnpM7Geqxka4WSqI1SZc7sMJFd3y4= @@ -430,8 +432,8 @@ github.com/codegangsta/cli v1.20.0/go.mod h1:/qJNoX69yVSKu5o4jLyXAENLRyk1uhi7zkb github.com/coinbase/kryptology v1.8.0/go.mod h1:RYXOAPdzOGUe3qlSFkMGn58i3xUA8hmxYHksuq+8ciI= github.com/coinbase/rosetta-sdk-go v0.7.9 h1:lqllBjMnazTjIqYrOGv8h8jxjg9+hJazIGZr9ZvoCcA= github.com/coinbase/rosetta-sdk-go v0.7.9/go.mod h1:0/knutI7XGVqXmmH4OQD8OckFrbQ8yMsUZTG7FXCR2M= -github.com/cometbft/cometbft-db v0.7.0 h1:uBjbrBx4QzU0zOEnU8KxoDl18dMNgDh+zZRUE0ucsbo= -github.com/cometbft/cometbft-db v0.7.0/go.mod h1:yiKJIm2WKrt6x8Cyxtq9YTEcIMPcEe4XPxhgX59Fzf0= +github.com/cometbft/cometbft-db v1.0.1 h1:SylKuLseMLQKw3+i8y8KozZyJcQSL98qEe2CGMCGTYE= +github.com/cometbft/cometbft-db v1.0.1/go.mod h1:EBrFs1GDRiTqrWXYi4v90Awf/gcdD5ExzdPbg4X8+mk= github.com/confio/ics23/go v0.9.1 h1:3MV46eeWwO3xCauKyAtuAdJYMyPnnchW4iLr2bTw6/U= github.com/confio/ics23/go v0.9.1/go.mod h1:4LPZ2NYqnYIVRklaozjNR1FScgDJ2s5Xrp+e/mYVRak= github.com/consensys/bavard v0.1.8-0.20210406032232-f3452dc9b572/go.mod h1:Bpd0/3mZuaj6Sj+PqrmIquiOKy397AKGThQPaGzNXAQ= @@ -527,13 +529,13 @@ github.com/dgraph-io/badger v1.6.2 h1:mNw0qs90GVgGGWylh0umH5iag1j6n/PeJtNvL6KY/x github.com/dgraph-io/badger v1.6.2/go.mod h1:JW2yswe3V058sS0kZ2h/AXeDSqFjxnZcRrVH//y2UQE= github.com/dgraph-io/badger/v2 v2.2007.4 h1:TRWBQg8UrlUhaFdco01nO2uXwzKS7zd+HVdwV/GHc4o= github.com/dgraph-io/badger/v2 v2.2007.4/go.mod h1:vSw/ax2qojzbN6eXHIx6KPKtCSHJN/Uz0X0VPruTIhk= -github.com/dgraph-io/badger/v4 v4.2.1-0.20240106094458-1c417aa3799c h1:Z9rm0wkQBM+VF7vpyrbKnCcSbww0PKygLoptTpkX3d4= -github.com/dgraph-io/badger/v4 v4.2.1-0.20240106094458-1c417aa3799c/go.mod h1:T/uWAYxrXdaXw64ihI++9RMbKTCpKd/yE9+saARew7k= +github.com/dgraph-io/badger/v4 v4.3.0 h1:lcsCE1/1qrRhqP+zYx6xDZb8n7U+QlwNicpc676Ub40= +github.com/dgraph-io/badger/v4 v4.3.0/go.mod h1:Sc0T595g8zqAQRDf44n+z3wG4BOqLwceaFntt8KPxUM= github.com/dgraph-io/ristretto v0.0.2/go.mod h1:KPxhHT9ZxKefz+PCeOGsrHpl1qZ7i70dGTu2u+Ahh6E= github.com/dgraph-io/ristretto v0.0.3-0.20200630154024-f66de99634de/go.mod h1:KPxhHT9ZxKefz+PCeOGsrHpl1qZ7i70dGTu2u+Ahh6E= github.com/dgraph-io/ristretto v0.0.3/go.mod h1:KPxhHT9ZxKefz+PCeOGsrHpl1qZ7i70dGTu2u+Ahh6E= -github.com/dgraph-io/ristretto v0.1.1 h1:6CWw5tJNgpegArSHpNHJKldNeq03FQCwYvfMVWajOK8= -github.com/dgraph-io/ristretto v0.1.1/go.mod h1:S1GPSBCYCIhmVNfcth17y2zZtQT6wzkzgwUve0VDWWA= +github.com/dgraph-io/ristretto v0.1.2-0.20240116140435-c67e07994f91 h1:Pux6+xANi0I7RRo5E1gflI4EZ2yx3BGZ75JkAIvGEOA= +github.com/dgraph-io/ristretto v0.1.2-0.20240116140435-c67e07994f91/go.mod h1:swkazRqnUf1N62d0Nutz7KIj2UKqsm/H8tD0nBJAXqM= github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= github.com/dgryski/go-bitstream v0.0.0-20180413035011-3522498ce2c8/go.mod h1:VMaSuZ+SZcx/wljOQKvp5srsbCiKDEb6K2wC4+PiBmQ= github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw= @@ -640,6 +642,8 @@ github.com/glycerine/go-unsnap-stream v0.0.0-20180323001048-9f0cb55181dd/go.mod github.com/glycerine/goconvey v0.0.0-20190410193231-58a59202ab31/go.mod h1:Ogl1Tioa0aV7gstGFO7KhffUsb9M4ydbEbbxpcEDc24= github.com/go-chi/chi/v5 v5.0.0/go.mod h1:BBug9lr0cqtdAhsu6R4AAdvufI0/XBzAQSsUqJpoZOs= github.com/go-errors/errors v1.0.1/go.mod h1:f4zRHt4oKfwPJE5k8C9vpYG+aDHdBFUsgrm6/TyX73Q= +github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxIA= +github.com/go-errors/errors v1.4.2/go.mod h1:sIVyrIiJhuEF+Pj9Ebtd6P/rEYROXFi3BopGUQ5a5Og= github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= @@ -721,8 +725,6 @@ github.com/golang-jwt/jwt/v4 v4.5.0/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k= github.com/golang/geo v0.0.0-20190916061304-5b978397cfec/go.mod h1:QZ0nwyI2jOfgRAoBvP+ab5aRr7c9x7lhGEJrKvBwjWI= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= -github.com/golang/glog v1.2.2 h1:1+mZ9upx1Dh6FmUTFR1naJ77miKiXgALjWOZ3NVFPmY= -github.com/golang/glog v1.2.2/go.mod h1:6AhwSGph0fcJtXVM/PEHPqZlFeoLxhs7/t5UDAwmO+w= github.com/golang/groupcache v0.0.0-20160516000752-02826c3e7903/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= @@ -768,8 +770,8 @@ github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb/go.mod h1:/XxbfmMg github.com/golangci/lint-1 v0.0.0-20181222135242-d2cdd8c08219/go.mod h1:/X8TswGSh1pIozq4ZwCfxS0WA5JGXguxk94ar/4c87Y= github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= -github.com/google/btree v1.1.2 h1:xf4v41cLI2Z6FxbKm+8Bu+m8ifhj15JuZ9sa0jZCMUU= -github.com/google/btree v1.1.2/go.mod h1:qOPhT0dTNdNzV6Z/lhRX0YXUafgPLFUh+gZMl761Gm4= +github.com/google/btree v1.1.3 h1:CVpQJjYgC4VbzxeGVHfvZrv1ctoYCAI8vbl07Fcxlyg= +github.com/google/btree v1.1.3/go.mod h1:qOPhT0dTNdNzV6Z/lhRX0YXUafgPLFUh+gZMl761Gm4= github.com/google/flatbuffers v1.11.0/go.mod h1:1AeVuKshWv4vARoZatz6mlQ0JxURH0Kv5+zNeJKJCa8= github.com/google/flatbuffers v1.12.1 h1:MVlul7pQNoDzWRLTw5imwYsl+usrS1TXG2H4jg6ImGw= github.com/google/flatbuffers v1.12.1/go.mod h1:1AeVuKshWv4vARoZatz6mlQ0JxURH0Kv5+zNeJKJCa8= @@ -1270,6 +1272,8 @@ github.com/libp2p/go-yamux/v4 v4.0.1/go.mod h1:NWjl8ZTLOGlozrXSOZ/HlfG++39iKNnM5 github.com/libp2p/zeroconf/v2 v2.1.1/go.mod h1:fuJqLnUwZTshS3U/bMRJ3+ow/v9oid1n0DmyYyNO1Xs= github.com/lightstep/lightstep-tracer-common/golang/gogo v0.0.0-20190605223551-bc2310a04743/go.mod h1:qklhhLq1aX+mtWk9cPHPzaBjWImj5ULL6C7HFJtXQMM= github.com/lightstep/lightstep-tracer-go v0.18.1/go.mod h1:jlF1pusYV4pidLvZ+XD0UBX0ZE6WURAspgAczcDHrL4= +github.com/linxGnu/grocksdb v1.9.3 h1:s1cbPcOd0cU2SKXRG1nEqCOWYAELQjdqg3RVI2MH9ik= +github.com/linxGnu/grocksdb v1.9.3/go.mod h1:QYiYypR2d4v63Wj1adOOfzglnoII0gLj3PNh4fZkcFA= github.com/lucas-clemente/quic-go v0.23.0/go.mod h1:paZuzjXCE5mj6sikVLMvqXk8lJV2AsqtJ6bDhjEfxx0= github.com/lucas-clemente/quic-go v0.25.0/go.mod h1:YtzP8bxRVCBlO77yRanE264+fY/T2U9ZlW1AaHOsMOg= github.com/lucas-clemente/quic-go v0.27.0/go.mod h1:AzgQoPda7N+3IqMMMkywBKggIFo2KT6pfnlrQ2QieeI= @@ -1542,6 +1546,8 @@ github.com/philhofer/fwd v1.0.0/go.mod h1:gk3iGcWd9+svBvR0sR+KPcfE+RNWozjowpeBVG github.com/philhofer/fwd v1.1.1/go.mod h1:gk3iGcWd9+svBvR0sR+KPcfE+RNWozjowpeBVG3ZVNU= github.com/pierrec/lz4 v1.0.2-0.20190131084431-473cd7ce01a1/go.mod h1:3/3N9NVKO0jef7pBehbT1qWhCMrIgbYNnFAZCqQ5LRc= github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY= +github.com/pingcap/errors v0.11.4 h1:lFuQV/oaUMGcD2tqt+01ROSmJs75VG1ToEOkZIZ4nE4= +github.com/pingcap/errors v0.11.4/go.mod h1:Oi8TUi2kEtXXLMJk9l1cGmz20kV3TaQ0usTwv5KuLY8= github.com/pion/datachannel v1.5.8 h1:ph1P1NsGkazkjrvyMfhRBUAWMxugJjq2HfQifaOoSNo= github.com/pion/datachannel v1.5.8/go.mod h1:PgmdpoaNBLX9HNzNClmdki4DYW5JtI7Yibu8QzbL3tI= github.com/pion/dtls/v2 v2.2.7/go.mod h1:8WiMkebSHFD0T+dIU+UeBaoV7kDhOW5oDCzZ7WZ/F9s= @@ -1584,6 +1590,7 @@ github.com/pion/turn/v2 v2.1.6 h1:Xr2niVsiPTB0FPtt+yAWKFUkU1eotQbGgpTIld4x1Gc= github.com/pion/turn/v2 v2.1.6/go.mod h1:huEpByKKHix2/b9kmTAM3YoX6MKP+/D//0ClgUYR2fY= github.com/pion/webrtc/v3 v3.3.0 h1:Rf4u6n6U5t5sUxhYPQk/samzU/oDv7jk6BA5hyO2F9I= github.com/pion/webrtc/v3 v3.3.0/go.mod h1:hVmrDJvwhEertRWObeb1xzulzHGeVUoPlWvxdGzcfU0= +github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= @@ -1668,12 +1675,13 @@ github.com/regen-network/cosmos-proto v0.3.1/go.mod h1:jO0sVX6a1B36nmE8C9xBFXpNw github.com/regen-network/protobuf v1.3.3-alpha.regen.1 h1:OHEc+q5iIAXpqiqFKeLpu5NwTIkVXUs48vFMwzqpqY4= github.com/regen-network/protobuf v1.3.3-alpha.regen.1/go.mod h1:2DjTFR1HhMQhiWC5sZ4OhQ3+NtdbZ6oBDKQwq5Ou+FI= github.com/retailnext/hllpp v1.0.1-0.20180308014038-101a6d2f8b52/go.mod h1:RDpi1RftBQPUCDRw6SmxeaREsAaRKnOclghuzp/WRzc= -github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY= -github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= +github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis= +github.com/rivo/uniseg v0.4.4/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= github.com/rjeczalik/notify v0.9.1/go.mod h1:rKwnCoCGeuQnwBtTSPL9Dad03Vh2n40ePRrjvIXnJho= github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= +github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8= github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4= github.com/rollkit/go-da v0.8.0 h1:oJKojC421eRC4mNqbujf40GzLFNp7HapgeB7Z/r0tyc= @@ -1803,8 +1811,6 @@ github.com/supranational/blst v0.3.13/go.mod h1:jZJtfjgudtNl4en1tzwPIV3KjUnQUvG3 github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 h1:epCh84lMvA70Z7CTTCmYQn2CKbY8j86K7/FAIr141uY= github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7/go.mod h1:q4W45IWZaF22tdD+VEXcAWRA037jwmWEB5VWYORlTpc= github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07/go.mod h1:kDXzergiv9cbyO7IOYJZWg1U88JhDg3PB6klq9Hg2pA= -github.com/tecbot/gorocksdb v0.0.0-20191217155057-f0fad39f321c h1:g+WoO5jjkqGAzHWCjJB1zZfXPIAaDpzXIEJ0eS6B5Ok= -github.com/tecbot/gorocksdb v0.0.0-20191217155057-f0fad39f321c/go.mod h1:ahpPrc7HpcfEWDQRZEmnXMzHY03mLDYMCxeDzy46i+8= github.com/tendermint/go-amino v0.16.0 h1:GyhmgQKvqF82e2oZeuMSp9JTN0N09emoSZlb2lyGa2E= github.com/tendermint/go-amino v0.16.0/go.mod h1:TQU0M1i/ImAo+tYpZi73AU3V/dKeCoMC9Sphe2ZwGME= github.com/tendermint/tm-db v0.6.7 h1:fE00Cbl0jayAoqlExN6oyQJ7fR/ZtoVOmvPJ//+shu8= @@ -1896,8 +1902,8 @@ gitlab.com/NebulousLabs/errors v0.0.0-20200929122200-06c536cf6975/go.mod h1:ZkMZ gitlab.com/NebulousLabs/fastrand v0.0.0-20181126182046-603482d69e40 h1:dizWJqTWjwyD8KGcMOwgrkqu1JIkofYgKkmDeNE7oAs= gitlab.com/NebulousLabs/fastrand v0.0.0-20181126182046-603482d69e40/go.mod h1:rOnSnoRyxMI3fe/7KIbVcsHRGxe30OONv8dEgo+vCfA= go.etcd.io/bbolt v1.3.3/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= -go.etcd.io/bbolt v1.3.10 h1:+BqfJTcCzTItrop8mq/lbzL8wSGtj94UO/3U31shqG0= -go.etcd.io/bbolt v1.3.10/go.mod h1:bK3UQLPJZly7IlNmV7uVHJDxfe5aK9Ll93e/74Y9oEQ= +go.etcd.io/bbolt v1.3.11 h1:yGEzV1wPz2yVCLsD8ZAiGHhHVlczyC9d1rP43/VCRJ0= +go.etcd.io/bbolt v1.3.11/go.mod h1:dksAq7YMXoljX0xu6VF5DMZGbhYYoLUalEiSySYAS4I= go.etcd.io/etcd v0.0.0-20191023171146-3cf2f69b5738/go.mod h1:dnLIgRNXwCJa5e+c6mIZCrds/GIG4ncV9HhK5PX7jPg= go.opencensus.io v0.18.0/go.mod h1:vKdFvxhtzZ9onBp9VKHK8z/sRpBMnKAsufL7wlDrCOA= go.opencensus.io v0.20.1/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk= @@ -2315,7 +2321,6 @@ golang.org/x/sys v0.0.0-20220624220833-87e55d714810/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20221010170243-090e33056c14/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= From 63d0ee94854df4d478c73aead0b3a69ea586d3aa Mon Sep 17 00:00:00 2001 From: vgonkivs Date: Fri, 18 Oct 2024 13:00:08 +0300 Subject: [PATCH 18/21] rework getProofsCache --- share/eds/proofs_cache.go | 10 +++++----- share/eds/rsmt2d.go | 10 ++++++++-- share/eds/share_reader.go | 17 +++++++++-------- share/eds/share_reader_test.go | 9 +++++++-- store/file/square.go | 4 ++-- 5 files changed, 31 insertions(+), 19 deletions(-) diff --git a/share/eds/proofs_cache.go b/share/eds/proofs_cache.go index e0fb55404b..e777b82962 100644 --- a/share/eds/proofs_cache.go +++ b/share/eds/proofs_cache.go @@ -305,12 +305,12 @@ func (c *proofsCache) getAxisFromCache(axisType rsmt2d.Axis, axisIdx int) (axisW return ax, ok } -func (c *proofsCache) getShare(rowIdx, colIdx int) ([]byte, error) { +func (c *proofsCache) getShare(rowIdx, colIdx int) (libshare.Share, error) { ctx := context.TODO() odsSize := c.Size(ctx) / 2 half, err := c.AxisHalf(ctx, rsmt2d.Row, rowIdx) if err != nil { - return nil, fmt.Errorf("reading axis half: %w", err) + return libshare.Share{}, fmt.Errorf("reading axis half: %w", err) } // if share is from the same side of axis return share right away @@ -318,15 +318,15 @@ func (c *proofsCache) getShare(rowIdx, colIdx int) ([]byte, error) { if half.IsParity { colIdx -= odsSize } - return half.Shares[colIdx].ToBytes(), nil + return half.Shares[colIdx], nil } // if share index is from opposite part of axis, obtain full axis shares shares, err := c.axisShares(ctx, rsmt2d.Row, rowIdx) if err != nil { - return nil, fmt.Errorf("reading axis shares: %w", err) + return libshare.Share{}, fmt.Errorf("reading axis shares: %w", err) } - return shares[colIdx].ToBytes(), nil + return shares[colIdx], nil } // rowProofsGetter implements blockservice.BlockGetter interface diff --git a/share/eds/rsmt2d.go b/share/eds/rsmt2d.go index a26a2d2c0c..e0e945fccb 100644 --- a/share/eds/rsmt2d.go +++ b/share/eds/rsmt2d.go @@ -133,8 +133,14 @@ func (eds *Rsmt2D) Close() error { // Reader returns binary reader for the file. func (eds *Rsmt2D) Reader() (io.Reader, error) { - getShare := func(rowIdx, colIdx int) ([]byte, error) { - return eds.GetCell(uint(rowIdx), uint(colIdx)), nil + getShare := func(rowIdx, colIdx int) (libshare.Share, error) { + rawShare := eds.GetCell(uint(rowIdx), uint(colIdx)) + + sh, err := libshare.NewShare(rawShare) + if err != nil { + return libshare.Share{}, fmt.Errorf("while creating share: %w", err) + } + return *sh, nil } odsSize := int(eds.Width() / 2) reader := NewShareReader(odsSize, getShare) diff --git a/share/eds/share_reader.go b/share/eds/share_reader.go index 84ab1dffe7..5bc55ac03c 100644 --- a/share/eds/share_reader.go +++ b/share/eds/share_reader.go @@ -4,6 +4,7 @@ import ( "bytes" "errors" "fmt" + libshare "github.com/celestiaorg/go-square/v2/share" "io" ) @@ -12,7 +13,7 @@ import ( // It enables share streaming over arbitrary storages. type ShareReader struct { // getShare general share getting function for share retrieval - getShare func(rowIdx, colIdx int) ([]byte, error) + getShare func(rowIdx, colIdx int) (libshare.Share, error) // buf buffers shares from partial reads with default size buf *bytes.Buffer @@ -22,7 +23,7 @@ type ShareReader struct { } // NewShareReader constructs a new ShareGetter from underlying ODS size and general share getting function. -func NewShareReader(odsSize int, getShare func(rowIdx, colIdx int) ([]byte, error)) *ShareReader { +func NewShareReader(odsSize int, getShare func(rowIdx, colIdx int) (libshare.Share, error)) *ShareReader { return &ShareReader{ getShare: getShare, buf: bytes.NewBuffer(nil), @@ -54,24 +55,24 @@ func (r *ShareReader) Read(p []byte) (int, error) { if err != nil { return 0, fmt.Errorf("get share: %w", err) } - + rawShare := share.ToBytes() // copy share to provided buffer emptySpace := len(p) - written r.current++ - if len(share) < emptySpace { - n := copy(p[written:], share) + if len(rawShare) < emptySpace { + n := copy(p[written:], rawShare) written += n continue } // if share didn't fit into buffer fully, store remaining bytes into inner buf - n := copy(p[written:], share[:emptySpace]) + n := copy(p[written:], rawShare[:emptySpace]) written += n - n, err = r.buf.Write(share[emptySpace:]) + n, err = r.buf.Write(rawShare[emptySpace:]) if err != nil { return 0, fmt.Errorf("write share to inner buffer: %w", err) } - if n != len(share)-emptySpace { + if n != len(rawShare)-emptySpace { return 0, fmt.Errorf("share was not written fully: %w", io.ErrShortWrite) } return written, nil diff --git a/share/eds/share_reader_test.go b/share/eds/share_reader_test.go index 60eae13b1c..ea2fba7cda 100644 --- a/share/eds/share_reader_test.go +++ b/share/eds/share_reader_test.go @@ -17,8 +17,13 @@ func TestShareReader(t *testing.T) { // create io.Writer that write random data odsSize := 16 eds := edstest.RandEDS(t, odsSize) - getShare := func(rowIdx, colIdx int) ([]byte, error) { - return eds.GetCell(uint(rowIdx), uint(colIdx)), nil + getShare := func(rowIdx, colIdx int) (libshare.Share, error) { + rawShare := eds.GetCell(uint(rowIdx), uint(colIdx)) + sh, err := libshare.NewShare(rawShare) + if err != nil { + return libshare.Share{}, err + } + return *sh, nil } reader := NewShareReader(odsSize, getShare) diff --git a/store/file/square.go b/store/file/square.go index ef5b67010c..fc6bdbbaf9 100644 --- a/store/file/square.go +++ b/store/file/square.go @@ -35,8 +35,8 @@ func (s square) reader() (io.Reader, error) { if s == nil { return nil, fmt.Errorf("ods file not cached") } - getShare := func(rowIdx, colIdx int) ([]byte, error) { - return s[rowIdx][colIdx].ToBytes(), nil + getShare := func(rowIdx, colIdx int) (libshare.Share, error) { + return s[rowIdx][colIdx], nil } reader := eds.NewShareReader(s.size(), getShare) return reader, nil From fce70e87f5935926889a22656679b02bff3a9a62 Mon Sep 17 00:00:00 2001 From: vgonkivs Date: Fri, 18 Oct 2024 13:08:38 +0300 Subject: [PATCH 19/21] remove NamespaceShares --- nodebuilder/share/mocks/api.go | 5 ++-- nodebuilder/share/share.go | 46 ++++------------------------------ nodebuilder/tests/api_test.go | 2 ++ share/eds/share_reader.go | 3 ++- 4 files changed, 12 insertions(+), 44 deletions(-) diff --git a/nodebuilder/share/mocks/api.go b/nodebuilder/share/mocks/api.go index e2d201757a..64a607d495 100644 --- a/nodebuilder/share/mocks/api.go +++ b/nodebuilder/share/mocks/api.go @@ -10,6 +10,7 @@ import ( header "github.com/celestiaorg/celestia-node/header" share "github.com/celestiaorg/celestia-node/nodebuilder/share" + shwap "github.com/celestiaorg/celestia-node/share/shwap" share0 "github.com/celestiaorg/go-square/v2/share" rsmt2d "github.com/celestiaorg/rsmt2d" gomock "github.com/golang/mock/gomock" @@ -84,10 +85,10 @@ func (mr *MockModuleMockRecorder) GetShare(arg0, arg1, arg2, arg3 interface{}) * } // GetSharesByNamespace mocks base method. -func (m *MockModule) GetSharesByNamespace(arg0 context.Context, arg1 *header.ExtendedHeader, arg2 share0.Namespace) (share.NamespacedShares, error) { +func (m *MockModule) GetSharesByNamespace(arg0 context.Context, arg1 *header.ExtendedHeader, arg2 share0.Namespace) (shwap.NamespaceData, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetSharesByNamespace", arg0, arg1, arg2) - ret0, _ := ret[0].(share.NamespacedShares) + ret0, _ := ret[0].(shwap.NamespaceData) ret1, _ := ret[1].(error) return ret0, ret1 } diff --git a/nodebuilder/share/share.go b/nodebuilder/share/share.go index 79812a9fb6..c2eaf28137 100644 --- a/nodebuilder/share/share.go +++ b/nodebuilder/share/share.go @@ -6,7 +6,6 @@ import ( "github.com/tendermint/tendermint/types" libshare "github.com/celestiaorg/go-square/v2/share" - "github.com/celestiaorg/nmt" "github.com/celestiaorg/rsmt2d" "github.com/celestiaorg/celestia-node/header" @@ -53,7 +52,7 @@ type Module interface { // Shares are returned in a row-by-row order if the namespace spans multiple rows. GetSharesByNamespace( ctx context.Context, header *header.ExtendedHeader, namespace libshare.Namespace, - ) (NamespacedShares, error) + ) (shwap.NamespaceData, error) // GetRange gets a list of shares and their corresponding proof. GetRange(ctx context.Context, height uint64, start, end int) (*GetRangeResult, error) } @@ -75,7 +74,7 @@ type API struct { ctx context.Context, header *header.ExtendedHeader, namespace libshare.Namespace, - ) (NamespacedShares, error) `perm:"read"` + ) (shwap.NamespaceData, error) `perm:"read"` GetRange func( ctx context.Context, height uint64, @@ -104,7 +103,7 @@ func (api *API) GetSharesByNamespace( ctx context.Context, header *header.ExtendedHeader, namespace libshare.Namespace, -) (NamespacedShares, error) { +) (shwap.NamespaceData, error) { return api.Internal.GetSharesByNamespace(ctx, header, namespace) } @@ -147,41 +146,6 @@ func (m module) GetSharesByNamespace( ctx context.Context, header *header.ExtendedHeader, namespace libshare.Namespace, -) (NamespacedShares, error) { - nd, err := m.Getter.GetSharesByNamespace(ctx, header, namespace) - if err != nil { - return nil, err - } - return convertToNamespacedShares(nd), nil -} - -// NamespacedShares represents all shares with proofs within a specific namespace of an EDS. -// This is a copy of the libshare.NamespacedShares type, that is used to avoid breaking changes -// in the API. -type NamespacedShares []NamespacedRow - -// NamespacedRow represents all shares with proofs within a specific namespace of a single EDS row. -type NamespacedRow struct { - Shares []libshare.Share `json:"shares"` - Proof *nmt.Proof `json:"proof"` -} - -// Flatten returns the concatenated slice of all NamespacedRow shares. -func (ns NamespacedShares) Flatten() []libshare.Share { - var shares []libshare.Share - for _, row := range ns { - shares = append(shares, row.Shares...) - } - return shares -} - -func convertToNamespacedShares(nd shwap.NamespaceData) NamespacedShares { - ns := make(NamespacedShares, 0, len(nd)) - for _, row := range nd { - ns = append(ns, NamespacedRow{ - Shares: row.Shares, - Proof: row.Proof, - }) - } - return ns +) (shwap.NamespaceData, error) { + return m.Getter.GetSharesByNamespace(ctx, header, namespace) } diff --git a/nodebuilder/tests/api_test.go b/nodebuilder/tests/api_test.go index 19bf117ec5..7582ddf6f3 100644 --- a/nodebuilder/tests/api_test.go +++ b/nodebuilder/tests/api_test.go @@ -12,6 +12,8 @@ import ( "github.com/libp2p/go-libp2p/core/peer" "github.com/stretchr/testify/require" + libshare "github.com/celestiaorg/go-square/v2/share" + "github.com/celestiaorg/celestia-node/api/rpc/client" "github.com/celestiaorg/celestia-node/blob" "github.com/celestiaorg/celestia-node/nodebuilder" diff --git a/share/eds/share_reader.go b/share/eds/share_reader.go index 5bc55ac03c..9fdd83e393 100644 --- a/share/eds/share_reader.go +++ b/share/eds/share_reader.go @@ -4,8 +4,9 @@ import ( "bytes" "errors" "fmt" - libshare "github.com/celestiaorg/go-square/v2/share" "io" + + libshare "github.com/celestiaorg/go-square/v2/share" ) // ShareReader implement io.Reader over general function that gets shares by From 3ca89160ab4c86b0082e2ac6de756f99b2487d97 Mon Sep 17 00:00:00 2001 From: vgonkivs Date: Mon, 21 Oct 2024 12:55:31 +0300 Subject: [PATCH 20/21] fix tests after rebase --- store/store_test.go | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/store/store_test.go b/store/store_test.go index 85a116f5e3..4374e01bbf 100644 --- a/store/store_test.go +++ b/store/store_test.go @@ -123,15 +123,8 @@ func TestEDSStore(t *testing.T) { require.NoError(t, err) require.NoError(t, f.Close()) expected := eds.FlattenedODS() - require.Equal(t, expected, share.ToBytes(fromFile)) + require.Equal(t, expected, libshare.ToBytes(fromFile)) }) - - // check that cached file is the same eds - fromFile, err := f.Shares(ctx) - require.NoError(t, err) - require.NoError(t, f.Close()) - expected := eds.FlattenedODS() - require.Equal(t, expected, fromFile) }) t.Run("Second Put should be noop", func(t *testing.T) { @@ -249,7 +242,7 @@ func TestEDSStore(t *testing.T) { require.NoError(t, err) require.NoError(t, f.Close()) expected := eds.FlattenedODS() - require.Equal(t, expected, fromFile) + require.Equal(t, expected, libshare.ToBytes(fromFile)) }) t.Run("GetByHash", func(t *testing.T) { @@ -271,7 +264,7 @@ func TestEDSStore(t *testing.T) { require.NoError(t, err) require.NoError(t, f.Close()) expected := eds.FlattenedODS() - require.Equal(t, expected, fromFile) + require.Equal(t, expected, libshare.ToBytes(fromFile)) }) } From 97d79be73b57f1dd36dcb1a5333fd359107b8b16 Mon Sep 17 00:00:00 2001 From: vgonkivs Date: Tue, 22 Oct 2024 15:35:56 +0300 Subject: [PATCH 21/21] fix build after applying new changes --- store/file/ods.go | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/store/file/ods.go b/store/file/ods.go index 2feacde227..3ec5082b83 100644 --- a/store/file/ods.go +++ b/store/file/ods.go @@ -143,7 +143,10 @@ func ValidateODSSize(path string, eds *rsmt2d.ExtendedDataSquare) error { return fmt.Errorf("opening file: %w", err) } - shares := filledSharesAmount(eds) + shares, err := filledSharesAmount(eds) + if err != nil { + return fmt.Errorf("calculating shares amount: %w", err) + } shareSize := len(eds.GetCell(0, 0)) expectedSize := ods.hdr.OffsetWithRoots() + shares*shareSize @@ -451,16 +454,20 @@ func readColHalf(r io.ReaderAt, colIdx int, hdr *headerV0, offset int) ([]libsha } // filledSharesAmount returns the amount of shares in the ODS that are not tail padding. -func filledSharesAmount(eds *rsmt2d.ExtendedDataSquare) int { +func filledSharesAmount(eds *rsmt2d.ExtendedDataSquare) (int, error) { var amount int for i := range eds.Width() / 2 { for j := range eds.Width() / 2 { - shr := eds.GetCell(i, j) - if share.GetNamespace(shr).Equals(share.TailPaddingNamespace) { + rawShr := eds.GetCell(i, j) + shr, err := libshare.NewShare(rawShr) + if err != nil { + return 0, fmt.Errorf("creating share at(%d,%d): %w", i, j, err) + } + if shr.Namespace().Equals(libshare.TailPaddingNamespace) { break } amount++ } } - return amount + return amount, nil }