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

feat!: remove libsodium vrf library. #1098

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions .github/workflows/check-generated.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Verify that generated code is up-to-date.

name: Check generated code
on:
workflow_dispatch:
pull_request:
branches:
- '*'

permissions:
contents: read

jobs:
check-error-doc:
runs-on: ubuntu-latest
steps:
- name: Setup Golang
uses: actions/setup-go@v4
with:
go-version: '1.20'

- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 1

- name: Check generated error docs
run: |
make error-doc-gen
if ! git diff --stat --exit-code ; then
echo ">> ERROR:"
echo ">>"
echo ">> Error documents require update (source files in x folder may have changed)."
echo ">> Ensure your tools are up-to-date, re-run 'make error-doc' and update this PR."
echo ">>"
exit 1
fi
16 changes: 2 additions & 14 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -134,18 +134,12 @@ jobs:
with:
name: "${{ github.sha }}-${{ matrix.part }}"
if: env.GIT_DIFF
- name: install libsodium
run: |
make libsodium
if: env.GIT_DIFF
- name: test & coverage report creation
env:
USE_PRELOAD: 1,4
SAVE_BRANCH_LAUNCH_DEPTH: 1
CGO_CFLAGS: "-I${{ github.workspace }}/tools/sodium/linux_amd64/include"
CGO_LDFLAGS: "-L${{ github.workspace }}/tools/sodium/linux_amd64/lib -lsodium"
run: |
cat pkgs.txt.part.${{ matrix.part }} | xargs go test -mod=readonly -timeout 30m -coverprofile=${{ matrix.part }}profile.out -covermode=atomic -tags='norace ledger test_ledger_mock goleveldb gcc libsodium'
cat pkgs.txt.part.${{ matrix.part }} | xargs go test -mod=readonly -timeout 30m -coverprofile=${{ matrix.part }}profile.out -covermode=atomic -tags='norace ledger test_ledger_mock goleveldb'
if: env.GIT_DIFF
- uses: actions/upload-artifact@v3
with:
Expand Down Expand Up @@ -222,19 +216,13 @@ jobs:
with:
name: "${{ github.sha }}-${{ matrix.part }}"
if: env.GIT_DIFF
- name: install libsodium
run: |
make libsodium
if: env.GIT_DIFF
- name: test & coverage report creation
env:
USE_PREFETCH: NO
USE_PRELOAD: 1,4
SAVE_BRANCH_LAUNCH_DEPTH: 1
CGO_CFLAGS: "-I${{ github.workspace }}/tools/sodium/linux_amd64/include"
CGO_LDFLAGS: "-L${{ github.workspace }}/tools/sodium/linux_amd64/lib -lsodium"
run: |
xargs --arg-file=pkgs.txt.part.${{ matrix.part }} go test -mod=readonly -timeout 30m -race -tags='cgo ledger test_ledger_mock goleveldb gcc libsodium'
xargs --arg-file=pkgs.txt.part.${{ matrix.part }} go test -mod=readonly -timeout 30m -race -tags='cgo ledger test_ledger_mock goleveldb'
if: env.GIT_DIFF
- uses: actions/upload-artifact@v3
with:
Expand Down
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
[submodule "tools/libsodium"]
path = tools/libsodium
url = https://github.com/algorand/libsodium.git
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,12 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (x/foundation) [\#999](https://github.com/Finschia/finschia-sdk/pull/999) migrate x/foundation FoundationTax into x/params
* (refactor) [\#1090](https://github.com/Finschia/finschia-sdk/pull/1090) Automate EventTypeMessage inclusion in every message execution (backport #1063)
* (x/bank) [#1093](https://github.com/Finschia/finschia-sdk/pull/1093) Remove message events including `sender` attribute whose information is already present in the relevant events (backport #1066)
* (ostracon) [\#1098](https://github.com/Finschia/finschia-sdk/pull/1098) feat!: remove libsodium vrf library.

### Build, CI
* (build,ci) [\#1043](https://github.com/Finschia/finschia-sdk/pull/1043) Update golang version to 1.20

### Document Updates
* (readme) [\#997](https://github.com/finschia/finschia-sdk/pull/997) fix swagger url
* (docs) [\#1094](https://github.com/Finschia/finschia-sdk/pull/1094) Document default events (backport #1081)

33 changes: 4 additions & 29 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,6 @@ else
endif
endif

# VRF library selection
ifeq (libsodium,$(findstring libsodium,$(LBM_BUILD_OPTIONS)))
CGO_ENABLED=1
BUILD_TAGS += gcc libsodium
LIBSODIUM_TARGET = libsodium
CGO_CFLAGS += "-I$(LIBSODIUM_OS)/include"
CGO_LDFLAGS += "-L$(LIBSODIUM_OS)/lib -lsodium"
endif

# secp256k1 implementation selection
ifeq (libsecp256k1,$(findstring libsecp256k1,$(LBM_BUILD_OPTIONS)))
CGO_ENABLED=1
Expand Down Expand Up @@ -132,7 +123,7 @@ build-docker: go.sum $(BUILDDIR)/
build-linux:
GOOS=linux GOARCH=$(if $(findstring aarch64,$(shell uname -m)) || $(findstring arm64,$(shell uname -m)),arm64,amd64) LEDGER_ENABLED=false $(MAKE) build

$(BUILD_TARGETS): go.sum $(BUILDDIR)/ $(LIBSODIUM_TARGET)
$(BUILD_TARGETS): go.sum $(BUILDDIR)/
CGO_CFLAGS=$(CGO_CFLAGS) CGO_LDFLAGS=$(CGO_LDFLAGS) CGO_ENABLED=$(CGO_ENABLED) go $@ -mod=readonly $(BUILD_FLAGS) $(BUILD_ARGS) ./...

$(BUILDDIR)/:
Expand Down Expand Up @@ -550,25 +541,9 @@ rosetta-data:
### tools ###
###############################################################################

VRF_ROOT = $(shell pwd)/tools
LIBSODIUM_ROOT = $(VRF_ROOT)/libsodium
LIBSODIUM_OS = $(VRF_ROOT)/sodium/$(shell go env GOOS)_$(shell go env GOARCH)
ifneq ($(TARGET_HOST), "")
LIBSODIUM_HOST = "--host=$(TARGET_HOST)"
endif

libsodium:
@if [ ! -f $(LIBSODIUM_OS)/lib/libsodium.a ]; then \
rm -rf $(LIBSODIUM_ROOT) && \
mkdir $(LIBSODIUM_ROOT) && \
git submodule update --init --recursive && \
cd $(LIBSODIUM_ROOT) && \
./autogen.sh && \
./configure --disable-shared --prefix="$(LIBSODIUM_OS)" $(LIBSODIUM_HOST) && \
$(MAKE) && \
$(MAKE) install; \
fi
.PHONY: libsodium
error-doc-gen:
cd ./tools/error_doc && go run ./
.PHONY: error-doc-gen

###############################################################################
### release ###
Expand Down
175 changes: 175 additions & 0 deletions tools/error_doc/generator/error_docs_generator.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
package generator

import (
"errors"
"fmt"
"os"
"path/filepath"
"sort"
"strings"

"golang.org/x/text/cases"
"golang.org/x/text/language"
)

type ErrorDocumentGenerator struct {
targetPath string
errorsFiles []string
modules []string
errorDocument map[string][]*moduleInfo
}

type moduleInfo struct {
filepath string
codespace string
constDict map[string]string
errorDict []errorInfo
}

type sortByCodespace []*moduleInfo

func (b sortByCodespace) Len() int { return len(b) }
func (b sortByCodespace) Less(i, j int) bool { return b[i].codespace < b[j].codespace }
func (b sortByCodespace) Swap(i, j int) { b[i], b[j] = b[j], b[i] }

func NewErrorDocumentGenerator(p string) *ErrorDocumentGenerator {
return &ErrorDocumentGenerator{
targetPath: p,
errorDocument: make(map[string][]*moduleInfo),
}
}

func (edg *ErrorDocumentGenerator) listUpErrorsGoFiles(startPath, errorsFileName string) error {
err := filepath.Walk(startPath, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if !info.IsDir() && info.Name() == errorsFileName {
edg.errorsFiles = append(edg.errorsFiles, path)
}
return nil
})
if err != nil {
return err
}
return nil
}

func (edg *ErrorDocumentGenerator) extractModuleName() error {
for _, filepath := range edg.errorsFiles {
var moduleName string
startIndex := strings.Index(filepath, "/x/") + len("/x/")
endIndex := strings.Index(filepath[startIndex:], "/")
if startIndex != -1 && endIndex != -1 {
moduleName = filepath[startIndex : startIndex+endIndex]
}
if moduleName == "" {
return errors.New("failed to get module name for " + filepath)
}
edg.errorDocument[moduleName] = append(edg.errorDocument[moduleName], &moduleInfo{
filepath: filepath,
codespace: "",
constDict: make(map[string]string),
errorDict: []errorInfo{},
})
}
// sort by key and codespace
for moduleName := range edg.errorDocument {
edg.modules = append(edg.modules, moduleName)
sort.Sort(sortByCodespace(edg.errorDocument[moduleName]))
}
sort.Strings(edg.modules)
return nil
}

func (edg ErrorDocumentGenerator) outputCategory(file *os.File) {
file.WriteString("<!-- TOC -->\n")
file.WriteString("# Category\n")
columnTemplate := " * [%s](#%s)\n"
for _, moduleName := range edg.modules {
file.WriteString(fmt.Sprintf(columnTemplate, cases.Title(language.Und).String(moduleName), moduleName))
}
file.WriteString("<!-- TOC -->\n")
}

func (edg *ErrorDocumentGenerator) generateContent() error {
// generate errors in each module
for _, moduleName := range edg.modules {
mods := edg.errorDocument[moduleName]
for _, mod := range mods {
if err := mod.parseErrorsFile(); err != nil {
return err
}
if err := mod.parseKeysFile(); err != nil {
return err
}
}
}
return nil
}

func (edg ErrorDocumentGenerator) outputContent(file *os.File) error {
extraInfoTemplate := " * [%s](%s)\n"
for _, moduleName := range edg.modules {
// module name
file.WriteString("\n")
file.WriteString("## " + cases.Title(language.Und).String(moduleName) + "\n")
// table header
file.WriteString("\n")
file.WriteString("|Error Name|Codespace|Code|Description|\n")
file.WriteString("|:-|:-|:-|:-|\n")
// table contents
mods := edg.errorDocument[moduleName]
for _, mod := range mods {
for _, errInfo := range mod.errorDict {
// assign value to field "codespace"
if s, err := errInfo.toString(mod.codespace); err != nil {
return err
} else {
file.WriteString(s)
}
}
}
// extract infomation
file.WriteString("\n>You can also find detailed information in the following Errors.go files:\n")
for _, mod := range mods {
relPath, err := filepath.Rel(edg.targetPath, mod.filepath)
if err != nil {
return err
}
file.WriteString(fmt.Sprintf(extraInfoTemplate, relPath, relPath))
}
}
return nil
}

func (edg ErrorDocumentGenerator) AutoGenerate() error {
// get all errors.go in x folder
errorsFileName := "errors.go"
err := edg.listUpErrorsGoFiles(edg.targetPath, errorsFileName)
if len(edg.errorsFiles) == 0 || err != nil {
return errors.New("not find target files in x folder")
}
// get each module name and bind it to paths (one module may have multiple errors.go)
if err := edg.extractModuleName(); err != nil {
return err
}
// generate content
if err := edg.generateContent(); err != nil {
return err
}
// prepare the file for writing
filepath := edg.targetPath + "/ERRORS.md"
file, err := os.Create(filepath)
if err != nil {
return err
}
defer file.Close()
// output category
edg.outputCategory(file)
// output content
if err := edg.outputContent(file); err != nil {
return err
}
return nil
}
Loading