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

✨ introduce: Libplanet.Store.Remote #3688

Merged

Conversation

riemannulus
Copy link
Member

@riemannulus riemannulus commented Mar 5, 2024

Context

Since Libplanet 4.0, we decided to use the Trie base state machine. As a side-effect, ActionEvaluator has StateStore, and BlockChain asks if it wants some State.

It makes the Libplanet architecture clear, but some 2nd party services which dependent on BlockChainStates. Especially RemoteBlockChainStates.

So, we make Libplanet.Store.Remote, to support remote state machines.

Rationale

In Libplanet.Store.Remote, have one server and one client. it shares .proto schema for communicating as a gRPC.

  • RemoteKeyValueStore: Client side of RemoteKeyValueStore.
  • RemoteKeyValueService: Server side of RemoteKeyValueStore.

Run

Server

First, we need to make a server project.

using Libplanet.Store.Remote.Server;
using Libplanet.Store.Trie;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
builder.Services.AddGrpc();
builder.Services.AddSingleton<IKeyValueStore, MemoryKeyValueStore>();

// If use `RocksDBStore`, try this:
// builder.Services.AddSingleton<IKeyValueStore>(_ => new RocksDBKeyValueStore("path/to/rocksdb"));

var app = builder.Build();

// Configure the HTTP request pipeline.
app.MapGrpcService<RemoteKeyValueService>();
app.MapGet("/", () => "Communication with gRPC endpoints must be made through a gRPC client. To learn how to create a client, visit: https://go.microsoft.com/fwlink/?linkid=2086909");

app.Run();

Then you can test with any other gRPC client tool.
GRPC localhost:5239/libplanet.rpc.v1.KeyValueStore/Get is return some value

Client

Just use any project if you want to use the remote store.

Async example:

using Libplanet.Store.Remote.Client;
using Libplanet.Store.Trie;

var channel = GrpcChannel.ForAddress("https://localhost:5239");
var kvStore = new RemoteKeyValueStore(channel);
var stateStore = new TrieStateStore(client);

stateStore.GetStateRoot(new HashDigest<SHA256>());

Sync example:

using Libplanet.Store.Remote.Client;
using Libplanet.Store.Trie;

var channel = GrpcChannel.ForAddress("https://localhost:5239");
var client = new RemoteKeyValueStoreClient(channel);

client.Set("key", new byte[] { 1, 2, 3, 4, 5 });

var value = client.Get("key");

@riemannulus riemannulus requested a review from a team March 5, 2024 07:04
@riemannulus riemannulus self-assigned this Mar 5, 2024
@riemannulus riemannulus requested review from eseiker, s2quake and OnedgeLee and removed request for a team March 5, 2024 07:04
@riemannulus riemannulus requested review from greymistcube, moreal and limebell and removed request for eseiker March 5, 2024 07:04
@riemannulus riemannulus force-pushed the introduce/libplanet.store.remote branch 4 times, most recently from a654cdd to 264c739 Compare March 5, 2024 08:46

This PR has 823 quantified lines of changes. In general, a change size of upto 200 lines is ideal for the best PR experience!


Quantification details

Label      : Extra Large
Size       : +823 -0
Percentile : 94.1%

Total files changed: 25

Change summary by file extension:
.sh : +1 -0
.md : +61 -0
.json : +1 -0
.cs : +646 -0
.csproj : +62 -0
.proto : +52 -0
.sln : +0 -0

Change counts above are quantified counts, based on the PullRequestQuantifier customizations.

Why proper sizing of changes matters

Optimal pull request sizes drive a better predictable PR flow as they strike a
balance between between PR complexity and PR review overhead. PRs within the
optimal size (typical small, or medium sized PRs) mean:

  • Fast and predictable releases to production:
    • Optimal size changes are more likely to be reviewed faster with fewer
      iterations.
    • Similarity in low PR complexity drives similar review times.
  • Review quality is likely higher as complexity is lower:
    • Bugs are more likely to be detected.
    • Code inconsistencies are more likely to be detected.
  • Knowledge sharing is improved within the participants:
    • Small portions can be assimilated better.
  • Better engineering practices are exercised:
    • Solving big problems by dividing them in well contained, smaller problems.
    • Exercising separation of concerns within the code changes.

What can I do to optimize my changes

  • Use the PullRequestQuantifier to quantify your PR accurately
    • Create a context profile for your repo using the context generator
    • Exclude files that are not necessary to be reviewed or do not increase the review complexity. Example: Autogenerated code, docs, project IDE setting files, binaries, etc. Check out the Excluded section from your prquantifier.yaml context profile.
    • Understand your typical change complexity, drive towards the desired complexity by adjusting the label mapping in your prquantifier.yaml context profile.
    • Only use the labels that matter to you, see context specification to customize your prquantifier.yaml context profile.
  • Change your engineering behaviors
    • For PRs that fall outside of the desired spectrum, review the details and check if:
      • Your PR could be split in smaller, self-contained PRs instead
      • Your PR only solves one particular issue. (For example, don't refactor and code new features in the same PR).

How to interpret the change counts in git diff output

  • One line was added: +1 -0
  • One line was deleted: +0 -1
  • One line was modified: +1 -1 (git diff doesn't know about modified, it will
    interpret that line like one addition plus one deletion)
  • Change percentiles: Change characteristics (addition, deletion, modification)
    of this PR in relation to all other PRs within the repository.


Was this comment helpful? 👍  :ok_hand:  :thumbsdown: (Email)
Customize PullRequestQuantifier for this repository.

@riemannulus riemannulus force-pushed the introduce/libplanet.store.remote branch from da6ffe4 to 894292b Compare March 8, 2024 07:33

This PR has 823 quantified lines of changes. In general, a change size of upto 200 lines is ideal for the best PR experience!


Quantification details

Label      : Extra Large
Size       : +823 -0
Percentile : 94.1%

Total files changed: 25

Change summary by file extension:
.sh : +1 -0
.md : +61 -0
.json : +1 -0
.cs : +646 -0
.csproj : +62 -0
.proto : +52 -0
.sln : +0 -0

Change counts above are quantified counts, based on the PullRequestQuantifier customizations.

Why proper sizing of changes matters

Optimal pull request sizes drive a better predictable PR flow as they strike a
balance between between PR complexity and PR review overhead. PRs within the
optimal size (typical small, or medium sized PRs) mean:

  • Fast and predictable releases to production:
    • Optimal size changes are more likely to be reviewed faster with fewer
      iterations.
    • Similarity in low PR complexity drives similar review times.
  • Review quality is likely higher as complexity is lower:
    • Bugs are more likely to be detected.
    • Code inconsistencies are more likely to be detected.
  • Knowledge sharing is improved within the participants:
    • Small portions can be assimilated better.
  • Better engineering practices are exercised:
    • Solving big problems by dividing them in well contained, smaller problems.
    • Exercising separation of concerns within the code changes.

What can I do to optimize my changes

  • Use the PullRequestQuantifier to quantify your PR accurately
    • Create a context profile for your repo using the context generator
    • Exclude files that are not necessary to be reviewed or do not increase the review complexity. Example: Autogenerated code, docs, project IDE setting files, binaries, etc. Check out the Excluded section from your prquantifier.yaml context profile.
    • Understand your typical change complexity, drive towards the desired complexity by adjusting the label mapping in your prquantifier.yaml context profile.
    • Only use the labels that matter to you, see context specification to customize your prquantifier.yaml context profile.
  • Change your engineering behaviors
    • For PRs that fall outside of the desired spectrum, review the details and check if:
      • Your PR could be split in smaller, self-contained PRs instead
      • Your PR only solves one particular issue. (For example, don't refactor and code new features in the same PR).

How to interpret the change counts in git diff output

  • One line was added: +1 -0
  • One line was deleted: +0 -1
  • One line was modified: +1 -1 (git diff doesn't know about modified, it will
    interpret that line like one addition plus one deletion)
  • Change percentiles: Change characteristics (addition, deletion, modification)
    of this PR in relation to all other PRs within the repository.


Was this comment helpful? 👍  :ok_hand:  :thumbsdown: (Email)
Customize PullRequestQuantifier for this repository.

This PR has 823 quantified lines of changes. In general, a change size of upto 200 lines is ideal for the best PR experience!


Quantification details

Label      : Extra Large
Size       : +823 -0
Percentile : 94.1%

Total files changed: 25

Change summary by file extension:
.sh : +1 -0
.md : +61 -0
.json : +1 -0
.cs : +645 -0
.csproj : +63 -0
.proto : +52 -0
.sln : +0 -0

Change counts above are quantified counts, based on the PullRequestQuantifier customizations.

Why proper sizing of changes matters

Optimal pull request sizes drive a better predictable PR flow as they strike a
balance between between PR complexity and PR review overhead. PRs within the
optimal size (typical small, or medium sized PRs) mean:

  • Fast and predictable releases to production:
    • Optimal size changes are more likely to be reviewed faster with fewer
      iterations.
    • Similarity in low PR complexity drives similar review times.
  • Review quality is likely higher as complexity is lower:
    • Bugs are more likely to be detected.
    • Code inconsistencies are more likely to be detected.
  • Knowledge sharing is improved within the participants:
    • Small portions can be assimilated better.
  • Better engineering practices are exercised:
    • Solving big problems by dividing them in well contained, smaller problems.
    • Exercising separation of concerns within the code changes.

What can I do to optimize my changes

  • Use the PullRequestQuantifier to quantify your PR accurately
    • Create a context profile for your repo using the context generator
    • Exclude files that are not necessary to be reviewed or do not increase the review complexity. Example: Autogenerated code, docs, project IDE setting files, binaries, etc. Check out the Excluded section from your prquantifier.yaml context profile.
    • Understand your typical change complexity, drive towards the desired complexity by adjusting the label mapping in your prquantifier.yaml context profile.
    • Only use the labels that matter to you, see context specification to customize your prquantifier.yaml context profile.
  • Change your engineering behaviors
    • For PRs that fall outside of the desired spectrum, review the details and check if:
      • Your PR could be split in smaller, self-contained PRs instead
      • Your PR only solves one particular issue. (For example, don't refactor and code new features in the same PR).

How to interpret the change counts in git diff output

  • One line was added: +1 -0
  • One line was deleted: +0 -1
  • One line was modified: +1 -1 (git diff doesn't know about modified, it will
    interpret that line like one addition plus one deletion)
  • Change percentiles: Change characteristics (addition, deletion, modification)
    of this PR in relation to all other PRs within the repository.


Was this comment helpful? 👍  :ok_hand:  :thumbsdown: (Email)
Customize PullRequestQuantifier for this repository.

@riemannulus riemannulus merged commit b571603 into planetarium:main Mar 8, 2024
21 checks passed
@riemannulus riemannulus mentioned this pull request Mar 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants