Skip to content

Commit

Permalink
Merge branch 'master' into darren/enhancement/use-slog
Browse files Browse the repository at this point in the history
  • Loading branch information
darrenvechain committed Jul 10, 2024
2 parents f4226dd + 830b1a6 commit fe34118
Show file tree
Hide file tree
Showing 12 changed files with 372 additions and 38 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/go-mod-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ jobs:
name: ensure go mod is tidy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: '1.22'
cache: false

- name: go mod tidy
run: |
go mod tidy
- name: check go module
run: |
if ! git diff --exit-code --quiet; then
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/lint-go.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ jobs:
name: golangci-lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: '1.22'
cache: false
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
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
2 changes: 1 addition & 1 deletion .github/workflows/on-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
uses: actions/checkout@v4

- name: Setup Node
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: '20'

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
uses: docker/setup-buildx-action@v3

- name: Build and export
uses: docker/build-push-action@v5
uses: docker/build-push-action@v6
with:
context: .
tags: vechain/thor:${{ github.sha }}
Expand Down
11 changes: 4 additions & 7 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,13 @@ jobs:
matrix:
go-version: [1.22.x]
os: [ubuntu-latest, macos-latest, windows-latest]
include:
- go-version: 1.21.x
os: ubuntu-latest
runs-on: ${{ matrix.os }}
steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Install Go
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}

Expand All @@ -37,10 +34,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Install Go
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version: 1.22.x

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
36 changes: 35 additions & 1 deletion consensus/consensus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ func newTestConsensus() (*testConsensus, error) {
}

forkConfig := thor.NoFork
forkConfig.VIP191 = 1
forkConfig.BLOCKLIST = 0
forkConfig.VIP214 = 2

Expand All @@ -95,6 +96,16 @@ func newTestConsensus() (*testConsensus, error) {
return nil, err
}

addr := thor.BytesToAddress([]byte("to"))
cla := tx.NewClause(&addr).WithValue(big.NewInt(10000))
txBuilder := txBuilder(repo.ChainTag()).Clause(cla)
transaction := txSign(txBuilder)

err = flow.Adopt(transaction)
if err != nil {
return nil, err
}

b1, stage, receipts, err := flow.Pack(proposer.PrivateKey, 0, false)
if err != nil {
return nil, err
Expand Down Expand Up @@ -194,7 +205,7 @@ func (tc *testConsensus) signWithKey(builder *block.Builder, pk *ecdsa.PrivateKe
}

func (tc *testConsensus) builder(header *block.Header) *block.Builder {
return new(block.Builder).
builder := new(block.Builder).
ParentID(header.ParentID()).
Timestamp(header.Timestamp()).
TotalScore(header.TotalScore()).
Expand All @@ -203,6 +214,8 @@ func (tc *testConsensus) builder(header *block.Header) *block.Builder {
Beneficiary(header.Beneficiary()).
StateRoot(header.StateRoot()).
ReceiptsRoot(header.ReceiptsRoot())
builder.TransactionFeatures(tc.original.Header().TxsFeatures())
return builder
}

func (tc *testConsensus) consent(blk *block.Block) error {
Expand Down Expand Up @@ -666,6 +679,27 @@ func TestValidateProposer(t *testing.T) {
assert.Equal(t, expected, err)
},
},
{
"ErrInvalidFeatures", func(t *testing.T) {
header := tc.original.Header()
builder := new(block.Builder).
ParentID(header.ParentID()).
Timestamp(header.Timestamp()).
TotalScore(header.TotalScore()).
GasLimit(header.GasLimit()).
GasUsed(header.GasUsed()).
Beneficiary(header.Beneficiary()).
StateRoot(header.StateRoot()).
ReceiptsRoot(header.ReceiptsRoot())

blk := builder.Build()

err = tc.consent(blk)
expected := consensusError("block txs features invalid: want 1, have 0")

assert.Equal(t, expected, err)
},
},
{
"ErrSignerInvalid", func(t *testing.T) {
pk, _ := crypto.GenerateKey()
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.21
go 1.22

require (
github.com/beevik/ntp v0.2.0
Expand All @@ -15,7 +15,7 @@ require (
github.com/hashicorp/golang-lru v0.0.0-20160813221303-0a025b7e63ad
github.com/holiman/uint256 v1.2.4
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
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,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
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 fe34118

Please sign in to comment.