Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Abstractions and API for querying to storages #12

Merged
merged 1 commit into from
Apr 25, 2022

Conversation

vnabiev
Copy link
Collaborator

@vnabiev vnabiev commented Mar 31, 2022

There is added interface StorageNMap that represents a storage of data in blockchain.
Added corresponding abstractions and entites such KeyHashingAlgorithm, Blake2B128Concat, Identity, TwoX64Concat and etc.
Added appropriate methods to section State.

@vnabiev vnabiev force-pushed the feature/storage-api branch 2 times, most recently from 67065db to 511a756 Compare April 6, 2022 19:40
(byte) ((hash >> 32) & 0xff),
(byte) ((hash >> 40) & 0xff),
(byte) ((hash >> 48) & 0xff),
(byte) ((hash >> 56) & 0xff)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return new byte[]{
        (byte) hash,
        (byte) (hash >> 8),
        (byte) (hash >> 16),
        (byte) (hash >> 24),
        (byte) (hash >> 32),
        (byte) (hash >> 40),
        (byte) (hash >> 48),
        (byte) (hash >> 56)
};

var key = new byte[0];
var keyLength = 0;

while (!Arrays.equals(hash, blake2_128(key))) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as far as I remember we discussed that here might be a better approach

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not needed more, I used that for tests and forgot to delete. Will remove.

private DiverseKeyValueCollection(List<Pair<StorageKey, StorageData>> pairs,
List<ScaleReader<Object>> valueReaders,
List<Function<StorageKey, List<Object>>> keyExtractors) {
if (pairs.size() != valueReaders.size()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can use preconditions for this
Preconditions.checkArgument(pairs.size() == valueReaders.size(), "Number of value readers doesn't match number of pairs.");

val blockHash = new AtomicReference<BlockHash>();
val value = new AtomicReference<BlockHash>();
val argument = new AtomicInteger();
storage.subscribe((exception, block, v, keys) -> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't the test unsubscribe in the end?

}

public StorageKeyProvider with(@NonNull KeyHasher<?>... hashers) {
if (keyHashers.size() > 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Preconditions.checkState(keyHashers.isEmpty(), "Key hashers are already set.");

return task
.thenApplyAsync(storageKeys -> {
if ((size = storageKeys.size()) > 0) {
hasNext = true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like it shows if 'current' exists (not 'next')

@vnabiev vnabiev force-pushed the feature/storage-api branch from 511a756 to 871ff7b Compare April 19, 2022 20:16

/**
* TwoX 64 Concat hash algorithm.
* That's a non-cryptographic and transparent.
Copy link

@Ishinka Ishinka Apr 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This algorithm is non-cryptographic and transparent.

PagedKeyValueIterator<V> entriesPaged(int pageSize, @NonNull Object... keys);

/**
* Returns collection of key-values each item of which
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Returns a collection of key-values, each item of which


/**
* Returns collection of key-values each item of which
* contains the all keys of the entry and the value.
Copy link

@Ishinka Ishinka Apr 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

contains all the keys of the entry and its value.

CompletableFuture<KeyValueCollection<V>> entries(@NonNull Object... keys);

/**
* Returns iterator of collection of key-values each item of which
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Returns an iterator of a key-value collection, each item of which


/**
* Returns iterator of collection of key-values each item of which
* contains the rest keys of the entry and the value.
Copy link

@Ishinka Ishinka Apr 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

contains the remaining keys and the value.

/**
* @param keys the keys of the storage's entry.
* @return the queryable key that allows to request value.
* The queryable key can also be joined to other keys for multi query.
Copy link

@Ishinka Ishinka Apr 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The queryable key can also be joined to other keys for forming a multi query.

CompletableFuture<List<Pair<BlockHash, List<V>>>> history(@NonNull Object... keys);

/**
* Returns collection of key-values each item of which
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Returns a key-value collection, each item of which


/**
* Returns collection of key-values each item of which
* contains the rest keys of the entry and the value.
Copy link

@Ishinka Ishinka Apr 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

contains the remaining keys of the entry and its value.

* Returns collection of key-values each item of which
* contains the rest keys of the entry and the value.
* @param keys some keys of the storage's entry.
* Note: each key must follow the other in the strict order as
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: all the keys must follow the same strict order as

* contains the rest keys of the entry and the value.
* @param keys some keys of the storage's entry.
* Note: each key must follow the other in the strict order as
* they represented in the storage.
Copy link

@Ishinka Ishinka Apr 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

they appear in the storage.
OR
their sequence in the storage.

* @param queryKey StorageKey that contains pallet and storage names
* and may contain some keys of the entry.
* Note: each key follows the other in the strict order as
* they set in the storage.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

they appear in the storage.
OR
their sequence in the storage.

* Note: each key follows the other in the strict order as
* they set in the storage.
* @param countOfKeysInQuery number of keys that involved in queryKey.
* @return the rest keys of the entry which don't contain in the queryKey.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@return the remaining keys of the entry which are not included in the queryKey.

* and may contain some keys of the entry.
* Note: each key follows the other in the strict order as
* they set in the storage.
* @param countOfKeysInQuery number of keys that involved in queryKey.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@param countOfKeysInQuery number of keys included in the queryKey.


/**
* @param keys values of the keys for request to the entry
* Note: each key must follow the other in the strict order as
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: all the keys must follow the same exact order as

/**
* @param keys values of the keys for request to the entry
* Note: each key must follow the other in the strict order as
* they represented in the storage.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

they appear in the storage.
OR
their sequence in the storage.

import java.util.function.Function;

/**
* Collection that contains entries of different kinds of storage.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Collection that contains entries from various storage types.


/**
* @return the queryable key that allows to request value.
* The queryable key can also be joined to other keys for multi query.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The queryable key can also be joined to other keys for forming a multi query.


/**
* An algorithm that's used to generate storage map's key.
* As a general rule it should be a transparent algorithm as so
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a general rule it should be a transparent algorithm since

* @param exception happened on event.
* @param block hash of the block where the change happened.
* @param value new value of the storage's entry.
* @param keys list of the keys of the storage's entry.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@param keys list of the storage entry's keys.

* of the entry.
* @param queryKey StorageKey that contains pallet and storage names
* and may contain some keys of the entry.
* Note: each key follows the other in the strict order as
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: all the keys must follow the same exact order as

@@ -10,7 +10,10 @@
import static com.strategyobject.substrateclient.rpc.codegen.sections.Constants.CLASS_NAME_TEMPLATE;

public class RpcGeneratedSectionFactory {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this class doesn't seem to be anyhow involved in code generation. What do you think about moving it to rpc-sections or rpc-core?

There is added interface `StorageNMap` that represents a storage of data in blockchain.
Added corresponding abstractions and entites such `KeyHashingAlgorithm`, `Blake2B128Concat`, `Identity`, `TwoX64Concat` and etc.
Added appropriate methods to section `State`.
@vnabiev vnabiev force-pushed the feature/storage-api branch from 871ff7b to d2811c1 Compare April 22, 2022 13:49
@vnabiev vnabiev changed the title [WIP] abstractions and API for querying to storages Abstractions and API for querying to storages Apr 22, 2022
@vnabiev vnabiev merged commit e47b33e into develop Apr 25, 2022
@vnabiev vnabiev deleted the feature/storage-api branch April 25, 2022 12:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants