Skip to content

Commit

Permalink
fix: (re)split execution path to avoid breaking changes with 0 amounts (
Browse files Browse the repository at this point in the history
  • Loading branch information
Antoine Gelloz authored Feb 6, 2023
1 parent 1345154 commit e3f04fb
Show file tree
Hide file tree
Showing 17 changed files with 1,091 additions and 1,018 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ jobs:
with:
go-version-file: 'go.mod'
cache: true
- name: Run bench
run: task install:perf bench:ledger
- name: Run ledger package benchmarks
run: task install:perf bench PKG=./pkg/ledger RUN=BenchmarkLedger

GoReleaserBuild:
if: github.event_name != 'release'
Expand Down
4 changes: 0 additions & 4 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,16 @@ linters-settings:
linters:
disable-all: true
enable:
- deadcode #Default linter
- errcheck #Default linter
- gosimple #Default linter
- govet #Default linter
- ineffassign #Default linter
- staticcheck #Default linter
- structcheck #Default linter
- typecheck #Default linter
- unused #Default linter
- varcheck #Default linter
- gofmt
- gci
- goimports

run:
timeout: 5m
go: '1.18'
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ repos:
- id: check-added-large-files
- id: check-merge-conflict
- repo: https://github.com/golangci/golangci-lint
rev: v1.46.2
rev: v1.51.0
hooks:
- id: golangci-lint
28 changes: 6 additions & 22 deletions Taskfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ vars:
TIMEOUT: "10m"
RUN: ".*"
TAGS: "-tags json1,netgo"
BENCH_TIME: "30s"
BENCH_RESULTS_DIR: "/tmp/benchmarks"
BENCH_RESULTS_FILE: "/tmp/benchmarks/ledger.txt"
BENCH_CPU_PROFILE: "/tmp/benchmarks/ledger.cpu.prof"
Expand All @@ -29,7 +30,9 @@ tasks:

tests:
cmds:
- go test {{.TAGS}} {{if eq .VERBOSE "true"}}-v{{end}} -coverpkg {{.PKG}} -coverprofile coverage.out -covermode atomic {{.PKG}}
- >
go test {{.TAGS}} {{if eq .VERBOSE "true"}}-v{{end}} -coverpkg {{.PKG}}
-coverprofile coverage.out -covermode atomic {{.PKG}}
tests:local:
cmds:
Expand Down Expand Up @@ -76,22 +79,8 @@ tasks:
cmds:
- mkdir -p {{.BENCH_RESULTS_DIR}}
- >
go test {{.TAGS}} ./pkg/storage/sqlstorage
-run=XXX -bench={{.RUN}} -benchmem -timeout 1h
-cpuprofile {{.BENCH_CPU_PROFILE}} -memprofile {{.BENCH_MEM_PROFILE}}
| tee {{.BENCH_RESULTS_FILE}}
- benchstat {{.BENCH_RESULTS_FILE}}
env:
NUMARY_STORAGE_DRIVER: "postgres"
NUMARY_STORAGE_POSTGRES_CONN_STRING: "postgresql://ledger:[email protected]/ledger"

bench:ledger:
deps: [postgres]
cmds:
- mkdir -p {{.BENCH_RESULTS_DIR}}
- >
go test {{.TAGS}} ./pkg/ledger
-run=XXX -bench=BenchmarkLedger_{{.RUN}} -benchmem -benchtime=30s -timeout 1h
go test {{.TAGS}} {{if eq .VERBOSE "true"}}-v{{end}} {{.PKG}}
-run=XXX -bench={{.RUN}} -benchmem -benchtime={{.BENCH_TIME}} -timeout {{.TIMEOUT}}
-cpuprofile {{.BENCH_CPU_PROFILE}} -memprofile {{.BENCH_MEM_PROFILE}}
| tee {{.BENCH_RESULTS_FILE}}
- benchstat {{.BENCH_RESULTS_FILE}}
Expand All @@ -110,7 +99,6 @@ tasks:
install:
deps:
- install:golangci-lint
- install:cov-report
- install:perf

install:golangci-lint:
Expand All @@ -120,10 +108,6 @@ tasks:
sh -s -- -b $(go env GOPATH)/bin latest
- golangci-lint --version

install:cov-report:
cmds:
- go install github.com/go-phorce/cov-report/cmd/cov-report

install:perf:
- go install golang.org/x/perf/cmd/...@latest

Expand Down
Empty file modified go.sum
100755 → 100644
Empty file.
6 changes: 2 additions & 4 deletions pkg/api/controllers/script_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (ctl *ScriptController) PostScript(c *gin.Context) {
preview := ok && (strings.ToUpper(value) == "YES" || strings.ToUpper(value) == "TRUE" || value == "1")

res := ScriptResponse{}
execRes, err := l.(*ledger.Ledger).Execute(c.Request.Context(), false, preview, script)
execRes, err := l.(*ledger.Ledger).ExecuteScript(c.Request.Context(), preview, script)
if err != nil {
var (
code = apierrors.ErrInternal
Expand All @@ -62,9 +62,7 @@ func (ctl *ScriptController) PostScript(c *gin.Context) {
res.Details = apierrors.EncodeLink(message)
}
}
if len(execRes) > 0 {
res.Transaction = &execRes[0]
}
res.Transaction = &execRes

c.JSON(http.StatusOK, res)
}
33 changes: 17 additions & 16 deletions pkg/api/controllers/transaction_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,6 @@ func (ctl *TransactionController) PostTransaction(c *gin.Context) {
return
}

var res []core.ExpandedTransaction
var err error

if len(payload.Postings) > 0 && payload.Script.Plain != "" ||
len(payload.Postings) == 0 && payload.Script.Plain == "" {
apierrors.ResponseError(c, ledger.NewValidationError(
Expand All @@ -276,24 +273,29 @@ func (ctl *TransactionController) PostTransaction(c *gin.Context) {
Reference: payload.Reference,
Metadata: payload.Metadata,
}
res, err = l.(*ledger.Ledger).Execute(c.Request.Context(),
true, preview, core.TxsToScriptsData(txData)...)
} else {
script := core.ScriptData{
Script: payload.Script,
Timestamp: payload.Timestamp,
Reference: payload.Reference,
Metadata: payload.Metadata,
res, err := l.(*ledger.Ledger).ExecuteTxsData(c.Request.Context(), preview, txData)
if err != nil {
apierrors.ResponseError(c, err)
return
}
res, err = l.(*ledger.Ledger).Execute(c.Request.Context(),
false, preview, script)

respondWithData[[]core.ExpandedTransaction](c, http.StatusOK, res)
return
}

script := core.ScriptData{
Script: payload.Script,
Timestamp: payload.Timestamp,
Reference: payload.Reference,
Metadata: payload.Metadata,
}
res, err := l.(*ledger.Ledger).ExecuteScript(c.Request.Context(), preview, script)
if err != nil {
apierrors.ResponseError(c, err)
return
}

respondWithData[[]core.ExpandedTransaction](c, http.StatusOK, res)
respondWithData[[]core.ExpandedTransaction](c, http.StatusOK, []core.ExpandedTransaction{res})
}

func (ctl *TransactionController) GetTransaction(c *gin.Context) {
Expand Down Expand Up @@ -389,8 +391,7 @@ func (ctl *TransactionController) PostTransactionsBatch(c *gin.Context) {
}
}

res, err := l.(*ledger.Ledger).Execute(c.Request.Context(), true, false,
core.TxsToScriptsData(txs.Transactions...)...)
res, err := l.(*ledger.Ledger).ExecuteTxsData(c.Request.Context(), false, txs.Transactions...)
if err != nil {
apierrors.ResponseError(c, err)
return
Expand Down
120 changes: 0 additions & 120 deletions pkg/core/numscript.go

This file was deleted.

63 changes: 0 additions & 63 deletions pkg/core/numscript_test.go

This file was deleted.

Loading

0 comments on commit e3f04fb

Please sign in to comment.