Skip to content

Commit

Permalink
Upgrade go-sqlite to the latest version (#784)
Browse files Browse the repository at this point in the history
* Add Sqlite changes

* Pass log.db path as argument, update go version

* Upgrade minimum go version

* Add logDb changes for SQlite 3.45

* Fix Github Acions

* Upate golangci-lint vesion to 1.59.0

* Format with goimports

* Update logdb/logdb_test.go

Yes since its only used in that test

Co-authored-by: Pedro Gomes <[email protected]>

* Update logdb/logdb_test.go

Co-authored-by: Pedro Gomes <[email protected]>

* Added comments

* Move Benchmarks into separate file

* Fix: Make queries that result in non-empty responses

* updating table tests

* review benchmark file

* Update Dockerfile

Co-authored-by: libotony <[email protected]>

* pr comments

* fixing test.yml

---------

Co-authored-by: Makis Christou <[email protected]>
Co-authored-by: Makis Christou <[email protected]>
Co-authored-by: libotony <[email protected]>
  • Loading branch information
4 people authored Jul 10, 2024
1 parent bfa83f3 commit 830b1a6
Show file tree
Hide file tree
Showing 8 changed files with 327 additions and 29 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint-go.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: v1.55.2
version: v1.59.1
# use the default if on main branch, otherwise use the pull request config
args: --timeout=30m --config=.golangci.yml
only-new-issues: true
Expand Down
7 changes: 0 additions & 7 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,6 @@ jobs:
matrix:
go-version: [1.22.x]
os: [ubuntu-latest, macos-latest, windows-latest]
include:
- go-version: 1.19.x
os: ubuntu-latest
- go-version: 1.20.x
os: ubuntu-latest
- go-version: 1.21.x
os: ubuntu-latest
runs-on: ${{ matrix.os }}
steps:
- name: Checkout code
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Build thor in a stock Go builder container
FROM golang:1.21.9-alpine3.18 as builder
FROM golang:1.22-alpine3.20 as builder

RUN apk add --no-cache make gcc musl-dev linux-headers git
WORKDIR /go/thor
COPY . /go/thor
RUN make all

# Pull thor into a second stage deploy alpine container
FROM alpine:latest
FROM alpine:3.20

RUN apk add --no-cache ca-certificates
RUN apk upgrade libssl3 libcrypto3
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/vechain/thor/v2

go 1.19
go 1.22

require (
github.com/beevik/ntp v0.2.0
Expand All @@ -16,7 +16,7 @@ require (
github.com/holiman/uint256 v1.2.0
github.com/inconshreveable/log15 v0.0.0-20171019012758-0decfc6c20d9
github.com/mattn/go-isatty v0.0.3
github.com/mattn/go-sqlite3 v1.14.9
github.com/mattn/go-sqlite3 v1.14.22
github.com/mattn/go-tty v0.0.0-20180219170247-931426f7535a
github.com/pborman/uuid v0.0.0-20170612153648-e790cca94e6c
github.com/pkg/errors v0.8.0
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
Expand All @@ -102,8 +103,8 @@ github.com/mattn/go-isatty v0.0.3 h1:ns/ykhmWi7G9O+8a448SecJU3nSMBXJfqQkl0upE1jI
github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
github.com/mattn/go-runewidth v0.0.4 h1:2BvfKmzob6Bmd4YsL0zygOqfdFnK7GR4QL06Do4/p7Y=
github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
github.com/mattn/go-sqlite3 v1.14.9 h1:10HX2Td0ocZpYEjhilsuo6WWtUqttj2Kb0KtD86/KYA=
github.com/mattn/go-sqlite3 v1.14.9/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
github.com/mattn/go-sqlite3 v1.14.22 h1:2gZY6PC6kBnID23Tichd1K+Z0oS6nE/XwU+Vz/5o4kU=
github.com/mattn/go-sqlite3 v1.14.22/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
github.com/mattn/go-tty v0.0.0-20180219170247-931426f7535a h1:8TGB3DFRNl06DB1Q6zBX+I7FDoCUZY2fmMS9WGUIIpw=
github.com/mattn/go-tty v0.0.0-20180219170247-931426f7535a/go.mod h1:XPvLUNfbS4fJH25nqRHfWLMa1ONC8Amw+mIA639KxkE=
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 h1:jWpvCLoY8Z/e3VKvlsiIGKtc+UG6U5vzxaoagmhXfyg=
Expand Down Expand Up @@ -142,6 +143,7 @@ github.com/rjeczalik/notify v0.9.3 h1:6rJAzHTGKXGj76sbRgDiDcYj/HniypXmSJo1SWakZe
github.com/rjeczalik/notify v0.9.3/go.mod h1:gF3zSOrafR9DQEWSE8TjfI9NkooDxbyT4UgRGKZA0lc=
github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
Expand Down
45 changes: 30 additions & 15 deletions logdb/logdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,21 +139,29 @@ FROM (%v) e
subQuery += ")"
}

if filter.Order == DESC {
subQuery += " ORDER BY seq DESC "
} else {
subQuery += " ORDER BY seq ASC "
}

// if there is limit option, set order inside subquery
if filter.Options != nil {
if filter.Order == DESC {
subQuery += " ORDER BY seq DESC "
} else {
subQuery += " ORDER BY seq ASC "
}
subQuery += " LIMIT ?, ?"
args = append(args, filter.Options.Offset, filter.Options.Limit)
}

subQuery = "SELECT e.* FROM (" + subQuery + ") s LEFT JOIN event e ON s.seq = e.seq"

return db.queryEvents(ctx, fmt.Sprintf(query, subQuery), args...)
eventQuery := fmt.Sprintf(query, subQuery)
// if there is no limit option, set order outside
if filter.Options == nil {
if filter.Order == DESC {
eventQuery += " ORDER BY seq DESC "
} else {
eventQuery += " ORDER BY seq ASC "
}
}
return db.queryEvents(ctx, eventQuery, args...)
}

func (db *LogDB) FilterTransfers(ctx context.Context, filter *TransferFilter) ([]*Transfer, error) {
Expand Down Expand Up @@ -196,21 +204,28 @@ FROM (%v) t
subQuery += ")"
}

if filter.Order == DESC {
subQuery += " ORDER BY seq DESC "
} else {
subQuery += " ORDER BY seq ASC "
}

// if there is limit option, set order inside subquery
if filter.Options != nil {
if filter.Order == DESC {
subQuery += " ORDER BY seq DESC"
} else {
subQuery += " ORDER BY seq ASC"
}
subQuery += " LIMIT ?, ?"
args = append(args, filter.Options.Offset, filter.Options.Limit)
}

subQuery = "SELECT e.* FROM (" + subQuery + ") s LEFT JOIN transfer e ON s.seq = e.seq"

return db.queryTransfers(ctx, fmt.Sprintf(query, subQuery), args...)
transferQuery := fmt.Sprintf(query, subQuery)
// if there is no limit option, set order outside
if filter.Options == nil {
if filter.Order == DESC {
transferQuery += " ORDER BY seq DESC "
} else {
transferQuery += " ORDER BY seq ASC "
}
}
return db.queryTransfers(ctx, transferQuery, args...)
}

func (db *LogDB) queryEvents(ctx context.Context, query string, args ...interface{}) ([]*Event, error) {
Expand Down
Loading

0 comments on commit 830b1a6

Please sign in to comment.