From 5ffa157a771f74f3b62d1a39fcdd1b7c926d1e1a Mon Sep 17 00:00:00 2001 From: Ekaterina Pavlova Date: Mon, 21 Oct 2024 23:49:09 +0300 Subject: [PATCH] BlockFetcher/BlockUploader: fix and add additional attributes Capitalize block objects and index file objects attributes. Add network magic attribute to both block and index file objects. Close #3631 Signed-off-by: Ekaterina Pavlova --- cli/util/uploader.go | 24 +++++++++++++++--------- config/protocol.testnet.yml | 4 ++-- docs/neofs-blockstorage.md | 18 ++++++++++-------- 3 files changed, 27 insertions(+), 19 deletions(-) diff --git a/cli/util/uploader.go b/cli/util/uploader.go index 70b44e92f8..134f50b041 100644 --- a/cli/util/uploader.go +++ b/cli/util/uploader.go @@ -82,7 +82,11 @@ func uploadBin(ctx *cli.Context) error { if err != nil { return cli.Exit(fmt.Sprintf("failed to create RPC client: %v", err), 1) } - + vrs, err := rpc.GetVersion() + if err != nil { + return cli.Exit(fmt.Sprintf("failed to get version from RPC: %v", err), 1) + } + magic := vrs.Protocol.Network.String() currentBlockHeight, err := rpc.GetBlockCount() if err != nil { return cli.Exit(fmt.Sprintf("failed to get current block height from RPC: %v", err), 1) @@ -158,10 +162,11 @@ func uploadBin(ctx *cli.Context) error { } attrs := []object.Attribute{ *object.NewAttribute(attr, strconv.Itoa(int(blk.Index))), - *object.NewAttribute("primary", strconv.Itoa(int(blk.PrimaryIndex))), - *object.NewAttribute("hash", blk.Hash().StringLE()), - *object.NewAttribute("prevHash", blk.PrevHash.StringLE()), - *object.NewAttribute("timestamp", strconv.FormatUint(blk.Timestamp, 10)), + *object.NewAttribute("Primary", strconv.Itoa(int(blk.PrimaryIndex))), + *object.NewAttribute("Hash", blk.Hash().StringLE()), + *object.NewAttribute("PrevHash", blk.PrevHash.StringLE()), + *object.NewAttribute("Timestamp", strconv.FormatUint(blk.Timestamp, 10)), + *object.NewAttribute("Magic", magic), } err = retry(func() error { @@ -192,7 +197,7 @@ func uploadBin(ctx *cli.Context) error { fmt.Fprintf(ctx.App.Writer, "Successfully uploaded batch of blocks: from %d to %d\n", batchStart, batchEnd-1) } - err = updateIndexFiles(ctx, p, containerID, *acc, signer, uint(currentBlockHeight), attr, homomorphicHashingDisabled) + err = updateIndexFiles(ctx, p, containerID, *acc, signer, uint(currentBlockHeight), attr, magic, homomorphicHashingDisabled) if err != nil { return cli.Exit(fmt.Errorf("failed to update index files after upload: %w", err), 1) } @@ -284,7 +289,7 @@ func fetchLatestMissingBlockIndex(ctx context.Context, p *pool.Pool, containerID } // updateIndexFiles updates the index files in the container. -func updateIndexFiles(ctx *cli.Context, p *pool.Pool, containerID cid.ID, account wallet.Account, signer user.Signer, currentHeight uint, blockAttributeKey string, homomorphicHashingDisabled bool) error { +func updateIndexFiles(ctx *cli.Context, p *pool.Pool, containerID cid.ID, account wallet.Account, signer user.Signer, currentHeight uint, blockAttributeKey string, magic string, homomorphicHashingDisabled bool) error { attributeKey := ctx.String("index-attribute") indexFileSize := ctx.Uint("index-file-size") fmt.Fprintln(ctx.App.Writer, "Updating index files...") @@ -292,7 +297,7 @@ func updateIndexFiles(ctx *cli.Context, p *pool.Pool, containerID cid.ID, accoun prm := client.PrmObjectSearch{} filters := object.NewSearchFilters() filters.AddFilter(attributeKey, fmt.Sprintf("%d", 0), object.MatchNumGE) - filters.AddFilter("size", fmt.Sprintf("%d", indexFileSize), object.MatchStringEqual) + filters.AddFilter("Size", fmt.Sprintf("%d", indexFileSize), object.MatchStringEqual) prm.SetFilters(filters) var ( objectIDs []oid.ID @@ -394,7 +399,8 @@ func updateIndexFiles(ctx *cli.Context, p *pool.Pool, containerID cid.ID, accoun } attrs := []object.Attribute{ *object.NewAttribute(attributeKey, strconv.Itoa(int(i))), - *object.NewAttribute("size", strconv.Itoa(int(indexFileSize))), + *object.NewAttribute("Size", strconv.Itoa(int(indexFileSize))), + *object.NewAttribute("Magic", magic), } err = uploadObj(ctx.Context, p, signer, account.PrivateKey().GetScriptHash(), containerID, buffer, attrs, homomorphicHashingDisabled) if err != nil { diff --git a/config/protocol.testnet.yml b/config/protocol.testnet.yml index ecdfd6eed6..62ec63ddc6 100644 --- a/config/protocol.testnet.yml +++ b/config/protocol.testnet.yml @@ -111,5 +111,5 @@ ApplicationConfiguration: SkipIndexFilesSearch: false IndexFileSize: 128000 ContainerID: "EPGuD26wYgQJbmDdVBoYoNZiMKHwFMJT3A5WqPjdUHxH" - BlockAttribute: "block" - IndexFileAttribute: "index" + BlockAttribute: "Block" + IndexFileAttribute: "Index" diff --git a/docs/neofs-blockstorage.md b/docs/neofs-blockstorage.md index b57dda11c8..2a734ca5e4 100644 --- a/docs/neofs-blockstorage.md +++ b/docs/neofs-blockstorage.md @@ -12,17 +12,19 @@ efficiency and reduce node storage size. A single NeoFS container is used to store blocks and index files. Each block is stored in a binary form as a separate object with a unique OID and a set of attributes: - - block object identifier with block index value (`block:1`) - - primary node index (`primary:0`) - - block hash in the LE form (`hash:5412a781caf278c0736556c0e544c7cfdbb6e3c62ae221ef53646be89364566b`) - - previous block hash in the LE form (`prevHash:3654a054d82a8178c7dfacecc2c57282e23468a42ee407f14506368afe22d929`) - - millisecond-precision block timestamp (`timestamp:1627894840919`) + - block object identifier with block index value (`Block:1`) + - primary node index (`Primary:0`) + - block hash in the LE form (`Hash:5412a781caf278c0736556c0e544c7cfdbb6e3c62ae221ef53646be89364566b`) + - previous block hash in the LE form (`PrevHash:3654a054d82a8178c7dfacecc2c57282e23468a42ee407f14506368afe22d929`) + - millisecond-precision block timestamp (`Timestamp:1627894840919`) + - network magic (`Magic:privnet`) Each index file is an object containing a constant-sized batch of raw block object IDs in binary form ordered by block index. Each index file is marked with the following attributes: - - index file identifier with consecutive file index value (`index:0`) - - the number of OIDs included into index file (`size:128000`) + - index file identifier with consecutive file index value (`Index:0`) + - the number of OIDs included into index file (`Size:128000`) + - network magic (`Magic:privnet`) ### NeoFS BlockFetcher @@ -79,7 +81,7 @@ them to the NeoFS container. It also creates and uploads index files. Below is an example usage of the command: ```shell -./bin/neo-go util upload-bin --cid 9iVfUg8aDHKjPC4LhQXEkVUM4HDkR7UCXYLs8NQwYfSG --wallet-config ./wallet-config.yml --block-attribute block --index-attribute index --rpc-endpoint https://rpc.t5.n3.nspcc.ru:20331 -fsr st1.t5.fs.neo.org:8080 -fsr st2.t5.fs.neo.org:8080 -fsr st3.t5.fs.neo.org:8080 +./bin/neo-go util upload-bin --cid 9iVfUg8aDHKjPC4LhQXEkVUM4HDkR7UCXYLs8NQwYfSG --wallet-config ./wallet-config.yml --block-attribute Block --index-attribute Index --rpc-endpoint https://rpc.t5.n3.nspcc.ru:20331 -fsr st1.t5.fs.neo.org:8080 -fsr st2.t5.fs.neo.org:8080 -fsr st3.t5.fs.neo.org:8080 ``` The command supports the following options: ```