Finschia/ostracon

How to check the db type and VRF library by command or config file

ulbqb opened this issue · 1 comments

ulbqb commented

Summary

I want to check the db type and VRF library that the generated binary uses.

Problem Definition

Current version cannot check the db type and VRF library that the generated binary uses.

Proposal

I want version command like this.

$ ostracon version
v1.0.0-0-xxxxxxxxx
db leveldb
vrf r2ishiguro

For Admin Use

  • Not duplicate issue
  • Appropriate labels applied
  • Appropriate contributors tagged
  • Contributor assigned/self-assigned
torao commented

Just an idea I came up with, but the first approach is:

  1. For KVS implementation, It probably can obtain from the value of ctx.Config.DBBackend.
  2. For VRF, add a method to vrfEd25519 in crypto/vrf/vrf.go that returns the implementation name. Then each subclass should return a fixed value representing its implementation.
  3. If they should be displayed with version numbers:
    1. Embed the output of the dependent package into a variable with the version by go command in Makefile.
    2. Create a function that returns a version for the argument package name. This function parses the variable embedded in the Makefile to find the corresponding package.

There may be a more formal method, but a version-numbered list of the packages on which the project depends can be obtained as follows.

% go mod graph | awk '{print $2}' | sort | uniq
cloud.google.com/go/bigquery@v1.0.1
cloud.google.com/go/bigquery@v1.3.0
...

For dependent libraries that aren't part of the golang package, such as libsodium, a git commit hash could be used instead.

% cd crypto/vrf/internal/vrf/libsodium
% git rev-parse --short HEAD
004952bb

Modify the Makefile so that these outputs are set in a variable of Ostracon during make (the following results are unconfirmed).

LD_FLAGS += -X github.com/line/ostracon/version.DependentPackageVersion=
LD_FLAGS += $(shell go mod graph | awk '{print $2}' | sort | uniq)
LD_FLAGS += libsodium@$(shell cd crypto/vrf/internal/vrf/libsodium & git rev-parse --short HEAD)
... other non-golang libraries

Finally, implement a function that parses the string embedded by Makefile and returns the version number for the package name:

package version
var DependentPackageVersion string
func GetDependentPackageVersion(pkg string) string {
  pkgs := // split DependentPackageVersion by a new line
  for _, p := range pkgs {
    name, ver := // split @ by an '@'
    if name == pkg {
      return ver
    }
  }
  return nil
}